JdTestController.java 5.18 KB
package com.bsth.controller.jdtest;

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.data.BasicData;
import com.bsth.entity.oil.Ylb;
import com.bsth.entity.oil.Ylxxb;
import com.bsth.entity.sys.Dictionary;
import com.bsth.service.jdtest.JdtestService;
import com.bsth.service.oil.YlbService;
import com.bsth.service.sys.DictionaryService;
import com.bsth.util.Arith;
import com.bsth.util.ReportUtils;

@RestController
@RequestMapping("jdtest")
public class JdTestController extends BaseController<Ylb, Integer>{
	@Autowired
	YlbService ylbService;
	@Autowired
	DictionaryService dictionaryService;
	@Autowired
	JdtestService jdtestService;
	
	/*
	 * 油量平衡表导出
	 */
	@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");
		Map<String, Object> dMap=new HashMap<>();
		dMap.put("dGroup_eq", "oilType");
		Iterator<Dictionary> it= dictionaryService.list(dMap).iterator();
		while (it.hasNext()) {
			Dictionary d=it.next();
			dMap.put(d.getdCode(), d.getdName());
		}
		
		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());
			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("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(dMap.get(y.getRylx())==null){
					rylx="";
				}else{
					rylx=dMap.get(y.getRylx()).toString();
				}
			}
			m.put("rylx", rylx);
			m.put("ns", y.getNs()==null?"0":y.getNs());
			String shyy ="$$$$$${txt-4226}";
			if(y.getShyy()!=null){
				shyy=y.getShyy();
				 if(shyy.equals("1")){shyy="$$$$$${txt-2788}";}
				 else if(shyy.equals("2")){shyy="$$$$$${txt-2787}";}
				 else if(shyy.equals("3")){shyy="$$$$$${txt-2032}";}
				 else if(shyy.equals("4")){shyy="$$$$$${txt-2785}";}
				 else if(shyy.equals("5")){shyy="$$$$$${txt-3541}";}
				 else if(shyy.equals("6")){shyy="$$$$$${txt-3978}";}
				 else if(shyy.equals("7")){shyy="$$$$$${txt-3976}";}
				 else if(shyy.equals("8")){shyy="$$$$$${txt-3975}";}
				 else{shyy ="$$$$$${txt-4226}";}
			}
			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()+ "$$$$$${txt-1596}.xls");
			} catch (Exception e) {
				e.printStackTrace();
			}	
			
		return resList;
		
	}
	
	/*
	 * 场外加油匹配当天线路数据
	 */
	@RequestMapping(value = "/cwjyList",method = RequestMethod.GET)
	public List<Ylxxb> cwjyList(@RequestParam Map<String, Object> map){
		List<Ylxxb> cwjyList=jdtestService.cwjyList(map);
		return cwjyList;
	}
	
	/*
	 * 油量路单报表
	 */
	@RequestMapping(value="/daily",method = RequestMethod.GET)
	public List<Map<String, Object>> daily(@RequestParam Map<String, Object> map){
		List<Map<String, Object>> list=jdtestService.daily(map);
		
		if(map.get("type").toString().equals("export")){
			List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
			ReportUtils ee = new ReportUtils();
			Map<String, Object> m=new HashMap<>();
		
			try {
				String lineName = map.get("lineName").toString();
				String date = map.get("date").toString();
				m.put("line", lineName);
				m.put("date", date);
				listI.add(list.iterator());
				String path = this.getClass().getResource("/").getPath() + "static/pages/forms/";
				ee.excelReplace(listI, new Object[] { m }, path + "mould/jd_daily.xls",
						path + "export/" + date
						+ "-" + lineName + "-$$$$$${txt-1897}.xls");
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return list;
	}
	
}