YlbController.java 10.4 KB
package com.bsth.controller.oil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.web.bind.annotation.PathVariable;
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 com.bsth.controller.BaseController;
import com.bsth.entity.oil.Ylb;
import com.bsth.entity.sys.SysUser;
import com.bsth.security.util.SecurityUtils;
import com.bsth.service.oil.YlbService;
import com.bsth.util.Arith;
import com.bsth.util.ReportUtils;
import com.google.common.base.Splitter;

@RestController
@RequestMapping("ylb")
public class YlbController extends BaseController<Ylb, Integer>{
	@Autowired
	YlbService ylbService;
	
	@RequestMapping(value = "/saveYlb",method = RequestMethod.POST)
	public Map<String, Object> saveYlb(Ylb t){
//		SysUser user = SecurityUtils.getCurrentUser();
		t.setCreatetime(new Date());
//		Ylb t=new Ylb();
		return ylbService.saveYlb(t);
	}
	
	@RequestMapping(value = "/updateJsy",method = RequestMethod.GET)
	public Map<String, Object> updateJsy(@RequestParam Map<String, Object> map){
		return ylbService.update(map);
	}
	
	
	/**
	 * 把加油(YLXXB)的数据加入
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "/obtain",method = RequestMethod.GET)
	public Map<String, Object> obtain(@RequestParam Map<String, Object> map) throws Exception{
		Map<String, Object> list =new HashMap<String, Object>();
		try {
			
			list = ylbService.obtain(map);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw e;
		}
		System.out.println();
		return list;
	}
	
	
	@RequestMapping(value = "/saveYlbList",method = RequestMethod.POST)
	public Map<String, Object> saveYlbList(@RequestParam Map<String, Object> map){
		Map<String, Object> list=new HashMap<String, Object>();
		try {
			list = ylbService.saveYlbList(map);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	/**
	 * 拆分油量
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "/sort",method = RequestMethod.POST)
	public Map<String, Object> sort(@RequestParam Map<String, Object> map){
		Map<String, Object> list=new HashMap<String, Object>();
		try {
			list=ylbService.sort(map);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return list;
	}
	
	/**
	 * 进场油量等于出场油量 
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "/outAndIn",method = RequestMethod.GET)
	public Map<String, Object> outAndIn(@RequestParam Map<String, Object> map) throws Exception{
		Map<String, Object> list=new HashMap<String, Object>();
		try {
			
			list=ylbService.outAndIn(map);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		return list;
	}
	
	/**
	 * 核对油量(有加油没里程)
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "/checkYl",method = RequestMethod.GET)
	public Map<String, Object> checkYl(@RequestParam Map<String, Object> map){
		Map<String, Object> list=new HashMap<String, Object>();
		try {
			list=ylbService.checkYl(map);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return list;
	}
	
	/**
	 * 
	 * @Title: list 
	 * @Description: TODO(多条件分页查询) 
	 * @param @param map 查询条件
	 * @param @param page 页码
	 * @param @param size 每页显示数量
	 * @throws
	 */
	@RequestMapping(method = RequestMethod.GET)
	public Page<Ylb> list(@RequestParam Map<String, Object> map,
			@RequestParam(defaultValue = "0") int page,
			@RequestParam(defaultValue = "10") int size,
			@RequestParam(defaultValue = "id") String order,
			@RequestParam(defaultValue = "DESC") String direction){

		Direction d;
		map.put("xlbm_like", map.get("xlbm_like").toString().trim());
		String rq=map.get("rq").toString();
		int lx=Integer.parseInt(map.get("sxtj").toString().trim());
		if(lx>0){
			map.put("nbbm_in", ylbService.checkNbmmNum(rq, map.get("ssgsdm_like").toString(),
					map.get("fgsdm_like").toString(), map.get("xlbm_like").toString(),
					map.get("nbbm_eq").toString(),lx));
		}
//		try {
		
		if(!(rq=="")){
//			
//			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
//			  Calendar   calendar   =   new   GregorianCalendar(); 
//			  calendar.setTime(sdf.parse(rq)); 
//			  calendar.add(calendar.DATE,1);
//			  Date date=calendar.getTime();
			map.put("rq_eq", rq);
//			map.put("rq_lt", sdf.format(date));
//			System.out.println(rq);
//			System.out.println(sdf.format(date));
		}
//		} catch (ParseException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		if(null != direction && direction.equals("ASC"))
			d = Direction.ASC;
		else
			d = Direction.DESC;

        // 允许多个字段排序,order可以写单个字段,也可以写多个字段
        // 多个字段格式:{col1},{col2},{col3},....,{coln}
        // 每个字段的排序方向都是一致,这个以后再看要不要改
        List<String> list = Splitter.on(",").trimResults().splitToList(order);
        return baseService.list(map, new PageRequest(page, size, new Sort(d, list)));
	}
	
	
	

	/**
	 * 
	 * @Title: list 
	 * @Description: TODO(多条件分页查询) 
	 * @param @param map 查询条件
	 * @param @param page 页码
	 * @param @param size 每页显示数量
	 * @throws
	 */
	@RequestMapping(value = "/ylbList",method = RequestMethod.GET)
	public List<Ylb> ylbList(@RequestParam Map<String, Object> map){
		List<Ylb> ylbList=ylbService.listYlb(map);
        return ylbList;
	}
	
	@RequestMapping(value = "/deleteIds", method = RequestMethod.POST)
    public Map<String, Object> deleteIds(@RequestParam Map<String, Object> map) {
		Map<String, Object> maps=new HashMap<String, Object>();
        try {
        	maps= ylbService.deleteIds(map);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return maps;
    }
	@RequestMapping(value="/oilListMonth")
	public List<Map<String, Object>> oilListMonth(@RequestParam Map<String, Object> map){
		return ylbService.oilListMonth(map);
	}
	
	@RequestMapping(value = "/checkJsy",method = RequestMethod.GET)
	public String checkJsy(@RequestParam Map<String, Object> map){
		String list=ylbService.checkJsy(map);
		return list;
	}
	
	@RequestMapping(value = "/checkDate",method = RequestMethod.GET)
	public String checkDate(@RequestParam Map<String, Object> map){
		String list=ylbService.checkDate(map);
		return list;
	}
	
	@RequestMapping(value = "/sumYlb",method = RequestMethod.GET)
	public Map<String, Object> sumYlb(@RequestParam Map<String, Object> map){
		Map<String, Object> list=ylbService.sumYlb(map);
		return list;
	}
	
	@RequestMapping(value = "/listExport",method = RequestMethod.POST)
	public List<Map<String, Object>> listExport(@RequestParam Map<String, Object> map){
		SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"),
				sdfSimple = new SimpleDateFormat("yyyyMMdd");
		List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
		ReportUtils ee = new ReportUtils();
		List<Ylb> ylb= ylbService.listYlb(map);
//		(new CustomerSpecs<Ylb>(map)).iterator();
		List<Map<String, Object>>  resList = new ArrayList<Map<String, Object>>();
		for (Ylb y : ylb) {
			Map<String, Object> m = new HashMap<String, Object>();
			m.put("rq", sdfMonth.format(y.getRq()));
			m.put("gsname",y.getGsname() );
			m.put("fgsname", y.getFgsname());
			if(y.getLinename()==null){
				m.put("xlname", y.getXlname()==null?"":y.getXlname());
			}else{
				m.put("xlname", y.getLinename());
			}
			m.put("nbbm", y.getNbbm());
			m.put("jsy", y.getJsy());
			m.put("name", y.getName());
			m.put("jzl", y.getJzl()<=0?"0":y.getJzl());
			m.put("czlc", "0");
			m.put("jzlc", "0");
			m.put("czyl", y.getCzyl()<=0?"0":y.getCzyl());
			m.put("jzyl", y.getJzyl()<=0?"0":y.getJzyl());
			m.put("yh", y.getYh()<=0?"0":y.getYh());
			String rylx="";
			if(y.getRylx()!=null){
				if(y.getRylx().equals("0")){rylx="0号柴油";}
				if(y.getRylx().equals("1")){rylx="负10号柴油";}
			}
			m.put("rylx", rylx);
			m.put("ns", y.getNs()==null?"0":y.getNs());
			String shyy ="无";
			if(y.getShyy()!=null){
				shyy=y.getShyy();
				 if(shyy.equals("1")){shyy="票务用油";}
				 else if(shyy.equals("2")){shyy="保养用油";}
				 else if(shyy.equals("3")){shyy="报废车用油";}
				 else if(shyy.equals("4")){shyy="其它用油";}
				 else if(shyy.equals("5")){shyy="人保部";}
				 else if(shyy.equals("6")){shyy="车队";}
				 else if(shyy.equals("7")){shyy="车间(高保)";}
				 else if(shyy.equals("8")){shyy="车间(小修)";}
				 else{shyy ="无";}
			}
			m.put("shyy", shyy);
			m.put("sh", y.getSh()<=0?"0":y.getSh());
			m.put("zlc", y.getZlc()<=0?"0":y.getZlc());
			m.put("bglyh", y.getBglyh());
			m.put("zyh", Arith.add(y.getSh(), y.getYh()));
			resList.add(m);
		}
		try {
			map.put("sheetName", map.get("rq"));
			listI.add(resList.iterator());
			String path = this.getClass().getResource("/").getPath()+"static/pages/forms/";
			ee.excelReplace(listI, new Object[] { map }, path+"mould/list.xls",
				path+"export/"+map.get("rq").toString()+ "进出场存油量.xls");
			} catch (Exception e) {
				e.printStackTrace();
			}	
			
		return resList;
		
	}
	
	/*
	 *   历史修改行车路单后重新统计油量信息  (传参:line --线路编码   date --日期)
	 */
	
	@RequestMapping(value = "/updateHistory",method = RequestMethod.POST)
	public Map<String, Object> updateHistory(@RequestParam Map<String, Object> map) throws Exception{
		Map<String, Object> list =new HashMap<String, Object>();
		try {
			list = ylbService.updateHistory(map);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			throw e;
		}
		return list;
	}
	
	
}