CalcExportController.java 9.56 KB
package com.bsth.controller.calc;

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.common.ResponseCode;
import com.bsth.entity.calc.CalcWaybill;
import com.bsth.entity.mcy_forms.Waybillday;
import com.bsth.service.calc.CalcLbStatuAnalyService;
import com.bsth.service.calc.CalcMixService;
import com.bsth.service.calc.CalcWaybillService;
import com.bsth.util.ReportUtils;

@RestController
@RequestMapping("calc_export")
public class CalcExportController {
	
	@Autowired
	CalcWaybillService service;
	
	@Autowired
	CalcLbStatuAnalyService lbService;

	@Autowired
	CalcMixService clacMixService;

	@RequestMapping(value = "/waybilldayExport", method = RequestMethod.GET)
	public Map<String, Object> calcjsyspyExport(@RequestParam Map<String, Object> map) {
		
		String line="";
		if(map.get("line")!=null){
			line=map.get("line").toString().trim();
		}
		String lineName="";
		if(map.get("lineName")!=null){
			lineName=map.get("lineName").toString().trim();
		}
		String startDate="";
		if(map.get("startDate")!=null){
			startDate=map.get("startDate").toString().trim();
		}
		String endDate="";
		if(map.get("endDate")!=null){
			endDate=map.get("endDate").toString().trim();
		}
		String cont="";
		if(map.get("cont")!=null){
			cont=map.get("cont").toString().trim();
		}
		String empnames="";
		if(map.get("empnames")!=null){
			empnames=map.get("empnames").toString().trim();
		}
		String gsdmManth="";
		if(map.get("gsdmManth")!=null){
			gsdmManth=map.get("gsdmManth").toString().trim();
		}
		String fgsdmManth="";
		if(map.get("fgsdmManth")!=null){
			fgsdmManth=map.get("fgsdmManth").toString().trim();
		}

		Map<String, Object> resMap = new HashMap<String, Object>();
		List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
		List<Map<String, Object>> list = clacMixService.calcjsyspy(line, startDate, endDate, empnames, cont, gsdmManth, fgsdmManth);
		
		Map<String, Object> temp = new HashMap<String, Object>();
		temp.put("i", "序号");
		temp.put("jName", empnames);
		temp.put("jhyybc", "计划营运班次");
		temp.put("jhfyybc", "计划空驶班次");
		temp.put("sjyybc", "实际营运班次");
		temp.put("sjfyybc", "实际空驶班次");
		temp.put("lbbc", "烂班班次");
		temp.put("ljbc", "临加班次");
		temp.put("jhzlc", "计划总里程");
		temp.put("jhyylc", "计划营运里程");
		temp.put("jhfyylc", "计划空驶里程");
		temp.put("sjzlc", "实际总里程");
		temp.put("sjyylc", "实际营运里程");
		temp.put("sjfyylc", "实际空驶里程");
		temp.put("lblc", "烂班里程");
		temp.put("ljyylc", "临加营运里程");
		temp.put("ljfyylc", "临加空驶里程");
		resList.add(temp);
		for(int i = 0; i < list.size(); i++){
			temp = list.get(i);
			temp.put("i", i+1);
			resList.add(temp);
		}
		
		String date = startDate.replaceAll("-", "");
		if(!startDate.equals(endDate)){
			date = startDate.replaceAll("-", "") + "-" + endDate.replaceAll("-", "");
		}
		
		SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"),
				sdfSimple = new SimpleDateFormat("yyyyMMdd");
		List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
		Map<String,Object> mm = new HashMap<String, Object>();
		ReportUtils ee = new ReportUtils();
		
		try {
			listI.add(resList.iterator());
			String path = this.getClass().getResource("/").getPath()+"static/pages/forms/";
			ee.excelReplace(listI, new Object[] { mm }, path+"mould/calcjsyspy.xls",
					path+"export/"+date+"-"+lineName+"-人车班次公里统计.xls");
			resMap.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			resMap.put("status", ResponseCode.ERROR);
		}
		return resMap;
	}

	@RequestMapping(value = "/singledataExportTj", method = RequestMethod.GET)
	public Map<String, Object> singledataExportTj(@RequestParam Map<String, Object> map) {
		
		String line="";
		if(map.get("line")!=null){
			line=map.get("line").toString().trim();
		}
		String lineName="";
		if(map.get("lineName")!=null){
			lineName=map.get("lineName").toString().trim();
		}
		String startDate="";
		if(map.get("startDate")!=null){
			startDate=map.get("startDate").toString().trim();
		}
		String endDate="";
		if(map.get("endDate")!=null){
			endDate=map.get("endDate").toString().trim();
		}
		String tjtype="";
		if(map.get("tjtype")!=null){
			tjtype=map.get("tjtype").toString().trim();
		}
		String cont="";
		if(map.get("cont")!=null){
			cont=map.get("cont").toString().trim();
		}
		String gsdmSing="";
		if(map.get("gsdmSing")!=null){
			gsdmSing=map.get("gsdmSing").toString().trim();
		}
		String fgsdmSing="";
		if(map.get("fgsdmSing")!=null){
			fgsdmSing=map.get("fgsdmSing").toString().trim();
		}
		String sfdc="";
		if(map.get("sfdc")!=null){
			sfdc=map.get("sfdc").toString().trim();
		}

		Map<String, Object> resMap = new HashMap<String, Object>();
		List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
		List<Map<String, Object>> list = clacMixService.singledatatj(line, startDate, endDate, tjtype, cont, gsdmSing, fgsdmSing, sfdc);
		
		Map<String, Object> temp = new HashMap<String, Object>();
		temp.put("i", "序号");
		temp.put("gS", "所属公司");
		temp.put("xlName", "线路");
		temp.put("jName", tjtype);
		temp.put("jhzlc", "计划公里");
		temp.put("sjzlc", "行驶里程(包括空放)");
		temp.put("sjfyylc", "空驶里程");
		temp.put("hyl", "耗油量");
		temp.put("jzl", "加注量");
		temp.put("sh", "非营业用油");
		
		resList.add(temp);
		for(int i = 0; i < list.size(); i++){
			temp = list.get(i);
			temp.put("i", i+1);
			if(temp.get("xlName") == null){
				temp.put("xlName", "");
			}
			resList.add(temp);
		}
		
		String date = startDate.replaceAll("-", "");
		if(!startDate.equals(endDate)){
			date = startDate.replaceAll("-", "") + "-" + endDate.replaceAll("-", "");
		}
		
		SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"),
				sdfSimple = new SimpleDateFormat("yyyyMMdd");
		List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
		Map<String,Object> mm = new HashMap<String, Object>();
		ReportUtils ee = new ReportUtils();
		
		try {
			listI.add(resList.iterator());
			String path = this.getClass().getResource("/").getPath()+"static/pages/forms/";
			ee.excelReplace(listI, new Object[] { mm }, path+"mould/calcsingledata.xls",
					path+"export/"+date+"-"+lineName+"-路单数据(统计).xls");
			resMap.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			resMap.put("status", ResponseCode.ERROR);
		}
		return resMap;
	}

	@RequestMapping(value = "/lbStatuAnalyExport", method = RequestMethod.GET)
	public Map<String, Object> lbStatuAnalyExport(@RequestParam Map<String, Object> map) {
		
		String gsdm="";
		if(map.get("company")!=null){
			gsdm=map.get("company").toString().trim();
		}
		String fgsdm="";
		if(map.get("subCompany")!=null){
			fgsdm=map.get("subCompany").toString().trim();
		}
		String line="";
		if(map.get("line")!=null){
			line=map.get("line").toString().trim();
		}
		String lineName="";
		if(map.get("lineName")!=null){
			lineName=map.get("lineName").toString().trim();
		}
		String date="";
		if(map.get("startDate")!=null){
			date=map.get("startDate").toString().trim();
		}
		String date2="";
		if(map.get("endDate")!=null){
			date2=map.get("endDate").toString().trim();
		}
		String sfyy="";
		if(map.get("sfyy")!=null){
			sfyy=map.get("sfyy").toString().trim();
		}
		String type="";
		if(map.get("type")!=null){
			type=map.get("type").toString().trim();
		}

		Map<String, Object> resMap = new HashMap<String, Object>();
		List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
		List<Map<String, Object>> list = lbService.lbStatuAnaly(gsdm, fgsdm, line, date, date2, sfyy, type);
		
		for(int i = 0; i < list.size(); i++){
			Map<String, Object> temp = list.get(i);
			temp.put("i", i+1);
			if(!temp.containsKey("date") || temp.get("date") == null){
				temp.put("date", "");
			}
			if(!temp.containsKey("company") || temp.get("company") == null){
				temp.put("company", "");
			}
			if(!temp.containsKey("subCompany") || temp.get("subCompany") == null){
				temp.put("subCompany", "");
			}
			resList.add(temp);
		}
		
		String Data = date.replaceAll("-", "");
		if(!date.equals(date2)){
			Data = date.replaceAll("-", "") + "-" + date2.replaceAll("-", "");
		}
		
		SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"),
				sdfSimple = new SimpleDateFormat("yyyyMMdd");
		List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
		Map<String,Object> mm = new HashMap<String, Object>();
		ReportUtils ee = new ReportUtils();
		
		try {
			listI.add(resList.iterator());
			String path = this.getClass().getResource("/").getPath()+"static/pages/forms/";
			ee.excelReplace(listI, new Object[] { mm }, path+"mould/calcLbStatuAnaly.xls",
					path+"export/"+Data+"-"+lineName+"-烂班情况分析表(统计).xls");
			resMap.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			resMap.put("status", ResponseCode.ERROR);
		}
		return resMap;
	}
	
}