CalcExportController.java 9.97 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 com.bsth.util.I18n;
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", I18n.getInstance().getMessage("txt-3934"));
		temp.put("jName", empnames);
		temp.put("jhyybc", I18n.getInstance().getMessage("txt-1496"));
		temp.put("jhfyybc", I18n.getInstance().getMessage("txt-4377"));
		temp.put("sjyybc", I18n.getInstance().getMessage("txt-1489"));
		temp.put("sjfyybc", I18n.getInstance().getMessage("txt-1532"));
		temp.put("lbbc", I18n.getInstance().getMessage("txt-2707"));
		temp.put("ljbc", I18n.getInstance().getMessage("txt-2705"));
		temp.put("jhzlc", I18n.getInstance().getMessage("txt-2003"));
		temp.put("jhyylc", I18n.getInstance().getMessage("txt-1495"));
		temp.put("jhfyylc", I18n.getInstance().getMessage("txt-1497"));
		temp.put("sjzlc", I18n.getInstance().getMessage("txt-2001"));
		temp.put("sjyylc", I18n.getInstance().getMessage("txt-1488"));
		temp.put("sjfyylc", I18n.getInstance().getMessage("txt-1490"));
		temp.put("lblc", I18n.getInstance().getMessage("txt-2706"));
		temp.put("ljyylc", I18n.getInstance().getMessage("txt-1494"));
		temp.put("ljfyylc", I18n.getInstance().getMessage("txt-4375"));
		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+"-" + I18n.getInstance().getMessage("txt-735") + ".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", I18n.getInstance().getMessage("txt-3934"));
		temp.put("gS", I18n.getInstance().getMessage("txt-2686"));
		temp.put("xlName", I18n.getInstance().getMessage("txt-3815"));
		temp.put("jName", tjtype);
		temp.put("jhzlc", I18n.getInstance().getMessage("txt-3185"));
		temp.put("sjzlc", I18n.getInstance().getMessage("txt-4363"));
		temp.put("sjfyylc", I18n.getInstance().getMessage("txt-2913"));
		temp.put("hyl", I18n.getInstance().getMessage("txt-3438"));
		temp.put("jzl", I18n.getInstance().getMessage("txt-3436"));
		temp.put("sh", I18n.getInstance().getMessage("txt-1913"));
		
		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+"-" + I18n.getInstance().getMessage("txt-4362") + ".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+"-" + I18n.getInstance().getMessage("txt-1005") + ".xls");
			resMap.put("status", ResponseCode.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
			resMap.put("status", ResponseCode.ERROR);
		}
		return resMap;
	}
	
}