LsylbController.java 4.91 KB
package com.bsth.controller.oil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
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 com.bsth.controller.BaseController;
import com.bsth.entity.oil.Lsylb;
import com.bsth.entity.oil.Ylb;
import com.bsth.service.oil.LsylbService;
import com.bsth.util.Arith;
import com.bsth.util.ReportUtils;

@RestController
@RequestMapping("lsylb")
public class LsylbController extends BaseController<Ylb, Integer>{
	@Autowired
	LsylbService lsylbService;
	
	@RequestMapping(value = "/lsylbList",method = RequestMethod.GET)
	public List<Lsylb> lsylbList(@RequestParam Map<String, Object> map){
		List<Lsylb> ylbList=lsylbService.listYlb(map);
        return ylbList;
	}
	
	@RequestMapping(value = "/sumLsylb",method = RequestMethod.GET)
	public Map<String, Object> sumLsylb(@RequestParam Map<String, Object> map){
		Map<String, Object> list=lsylbService.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<Lsylb> lsylb= lsylbService.listYlb(map);
		String nylx=map.get("nylx").toString();
//		(new CustomerSpecs<Ylb>(map)).iterator();
		List<Map<String, Object>>  resList = new ArrayList<Map<String, Object>>();
		for (Lsylb y : lsylb) {
			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());
			m.put("xlname", y.getXlname()==null?"":y.getXlname());
			m.put("nbbm", y.getNbbm());
			m.put("jsy", y.getJsy());
			m.put("name", y.getName());
			m.put("czlc", "0");
			m.put("jzlc", "0");
			m.put("sh", y.getSh()==null?"0":y.getSh());
			
			String shyy ="无";
			
			if(nylx.equals("0")){
				m.put("jzl", y.getJzl()==null?"0":y.getJzl());
				m.put("czyl", y.getCzyl()==null?"0":y.getCzyl());
				m.put("jzyl", y.getJzyl()==null?"0":y.getJzyl());
				m.put("yh", y.getYh()==null?"0":y.getYh());
				
				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("zyh", Arith.add(m.get("sh"), m.get("yh")));
				
				String rylx="";
				if(y.getRylx()!=null){
					if(y.getRylx().equals("0")){rylx="0号柴油";}
					if(y.getRylx().equals("1")){rylx="负10号柴油";}
				}
				m.put("rylx", rylx);
			}else{
				m.put("cdl", y.getJzl()==null?"0":y.getJzl());
				m.put("czcd", y.getCzyl()==null?"0":y.getCzyl());
				m.put("jzcd", y.getJzyl()==null?"0":y.getJzyl());
				m.put("hd", y.getYh()==null?"0":y.getYh());
				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("zyh", Arith.add(m.get("sh"), m.get("hd")));
				m.put("rdlx", "");

			}
			m.put("shyy", shyy);
			m.put("ns", y.getNs()==null?"0":y.getNs());
			m.put("zlc", y.getZlc()==null?"0":y.getZlc());
			m.put("bglyh", y.getBglyh());
			resList.add(m);
		}
		try {
			map.put("sheetName", map.get("rq"));
			listI.add(resList.iterator());
			String xls="";
			String name="";

			if(nylx.equals("0")){
				xls="list.xls";
				name="进出场存油量.xls";
			}else{
				xls="listDl.xls";
				name="进出场存电量.xls";
			}
			String path = this.getClass().getResource("/").getPath()+"static/pages/forms/";
			ee.excelReplace(listI, new Object[] { map }, path+"mould/"+xls,
				path+"export/"+map.get("rq").toString()+ name);
			} catch (Exception e) {
				e.printStackTrace();
			}	
			
		return resList;
		
	}
}