CwjyController.java 3.67 KB
package com.bsth.controller.oil;


import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.bsth.common.ResponseCode;
import com.bsth.controller.BaseController;
import com.bsth.data.BasicData;
import com.bsth.entity.Line;
import com.bsth.entity.oil.Cwjy;
import com.bsth.entity.oil.Ylxxb;
import com.bsth.entity.sys.SysUser;
import com.bsth.security.util.SecurityUtils;
import com.bsth.service.oil.CwjyService;
import com.bsth.util.PageObject;
import com.google.common.io.Files;

@RestController
@RequestMapping("cwjy")
public class CwjyController extends BaseController<Cwjy, Integer>{
	@Autowired
	private CwjyService service;
	@RequestMapping(method = RequestMethod.POST)
	public Map<String, Object> save(Cwjy t){
		SysUser sysUser = SecurityUtils.getCurrentUser();
		t.setCreateDate(new Date());
		t.setXgr(sysUser.getUserName());
		t.setNbbm(t.getNbbm().trim().toUpperCase());
		Line line=BasicData.nbbm2LineMap.get(t.getNbbm());
		t.setLine(line == null?"" : line.getLineCode());
		Map<String, Object> map = new HashMap<>();
		try {
		 map=service.save(t);
		}catch (Exception e) {
			// TODO: handle exception
			if(e.getMessage().indexOf("PK_CWJYUK")>0){
				map.put("fage", "存在相同数据,数据已经过滤");
			}
		}
		return map;
	}
	
	@RequestMapping(value = "/checkNbbm",method = RequestMethod.GET)
	public int checkNbbm(Cwjy t){
		return service.checkNbbm(t);
	}
	
	@RequestMapping(value = "/queryList",method = RequestMethod.GET)
	public List<Ylxxb> queryList(@RequestParam Map<String, Object> map){
		List<Ylxxb> pagequery=null;
		map.put("curPage", map.get("page").toString());
		map.put("pageData","10");
		pagequery=service.Pagequery(map);
		return pagequery;
	}
	
	@RequestMapping(value = "/cwjyList",method = RequestMethod.GET)
	public List<Ylxxb> cwjyList(@RequestParam Map<String, Object> map){
		List<Ylxxb> cwjyList=service.cwjyList(map);
		return cwjyList;
	}
	
	@RequestMapping(value="/bynbbm",method = RequestMethod.GET)
	public Ylxxb bynbbm(@RequestParam Map<String, Object> map){
		
		return service.bynbbm(map);
	}
	
	/**
	 * 
	 * @Title: save 
	 * @Description: TODO(持久化对象) 
	 * @param @param t
	 * @param @return    设定文件 
	 * @return Map<String,Object>  {status: 1(成功),-1(失败)}
	 * @throws
	 */
	@RequestMapping(value="/savejzl",method = RequestMethod.POST)
	public Map<String, Object> savejzl(@RequestParam Map<String, Object> map){
		Map<String, Object> maps=new HashMap<>();
		try {
			maps = service.savejzl(map);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return maps;
	}
	
	/*
	 * 场外加油导入
	 */
	@RequestMapping(value = "/uploadFile",method = RequestMethod.POST)
	public String uploadFile(MultipartFile file, String gsbm_, String gsName,
											String fgsbm_, String fgsName) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
        File newFile = new File(
        		getDataImportClasspath() + File.separator +
                        file.getOriginalFilename());
        Files.write(file.getBytes(), newFile);
		String result = service.importExcel(newFile, gsbm_, gsName);
		return "{\"result\":" + "\""+result+"\"}";
	}

	public String getDataImportClasspath(){
		return this.getClass().getResource("/").getPath() + "/static/pages/oil";
	}
	
}