/***文档注释***********************************************
 * 作者               :                   易鑫
 * 创建日期      :                   2017.11.21
 * 描述               :        			分条主实绩
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
***********************************************************/

package market.Mes.Lengthwise.Performance.impl;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import market.Api.Lms.impl.LmsApiServiceImpl;
import market.Api.Mes.impl.MesApiServiceImpl;
import market.Com.impl.ComBaseMachineServiceImpl;
import market.Com.impl.PbModelDbServiceImpl;
import market.Com.mapper.ComBaseInfoMapper;
import market.Com.mapper.ComBaseMachineMapper;
import market.Com.mapper.ComBaseSteelMapper;
import market.Com.pb.DoubleUtil;
import market.Com.vo.ComBaseCbYdd;
import market.Com.vo.ComBaseMachine;
import market.Com.vo.ComBaseSteel;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Lms.Warehouse.mapper.YdmProductDetailMapper;
import market.Lms.Warehouse.service.YdmProductInlistService;
import market.Lms.Warehouse.vo.YdmProductDetail;
import market.Mes.Lengthwise.Performance.mapper.MesCrSlittingDMapper;
import market.Mes.Lengthwise.Performance.mapper.MesCrSlittingMMapper;
import market.Mes.Lengthwise.Performance.service.MesCrSlittingMService;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingD;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingM;
import market.Mes.Lengthwise.Performance.vo.MesCrSlittingSum;
import market.Mes.Lengthwise.Performance.vo.MesPrdDetailReport;
import market.Mes.Lengthwise.Performance.vo.MesSteelCodeTemp;
import market.Mes.Lengthwise.Plan.mapper.PlnLengthwisePlanDetailMapper;
import market.Mes.Lengthwise.Plan.mapper.PlnLengthwisePlanMapper;
import market.Mes.Lengthwise.Plan.vo.PlnLengthwisePlan;
import market.Mes.Lengthwise.Plan.vo.PlnLengthwisePlanDetail;
import market.Mes.Lengthwise.Plan.vo.PlnLengthwisePlanSum;
import market.Mes.Lengthwise.Plan.vo.PlnProcessPlan;
import market.Mes.Opr.mapper.MesOprLogMapper;
import market.Mes.Opr.vo.MesOprLog;
import market.Mes.OrderManager.Plan.impl.PlnProdorderStatisticServiceImpl;
import market.Mes.Shift.mapper.MesShiftMMapper;
import market.Mes.Shift.vo.MesShiftM;
import market.Mes.util.DateUtil;
import market.Slm.FundManagement.service.SlmFundFirstDetailService;

import org.apache.commons.lang.StringUtils;
import org.springframework.transaction.annotation.Transactional;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;
import com.hnshituo.core.auth.service.HomeService;

@RemoteService(path="MesCrSlittingMService")
public class MesCrSlittingMServiceImpl extends BaseServiceImpl<MesCrSlittingM,Object> implements MesCrSlittingMService {
	
	
	/**
	 * 4mm机组、12mm机组 生产明细报表
	 * object里面放一些查询字段：比如合同号、订单号、原料卷号等等
	 * memo1:机台代码
	 * startTime:计划下发时间开始
	 * endTime:计划下发时间结束
	 * startTime2:交工时间开始
	 * endTime2:交工时间结束
	 * memo2:生产时间开始
	 * meme3:生产时间结束
	 * memo4:交货时间开始
	 * memo5:交货时间结束
	 * */
	public ResultModel doPrdDetailWeb_4mm(CommonPage<MesPrdDetailReport> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesCrSlittingMMapper.class).doPrdDetailWeb_4mm(oci.getObject(),oci.getMemo1(),oci.getStartTime(),oci.getEndTime(),
					oci.getStartTime2(),oci.getEndTime2(),oci.getMemo2(),oci.getMemo3(),oci.getMemo4(),oci.getMemo5()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 作业实绩数据查询
	 * */
	public ResultModel doQueryWeb(CommonPage<MesCrSlittingM> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesCrSlittingMMapper.class).doQuery(oci.getObject()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 当班汇总信息查询
	 * */
	public ResultModel doQueryWrkSumInfoWeb(CommonPage<MesCrSlittingM> oci){
		ResultModel rm=new ResultModel();
		try{
			String wrk_ord = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
			String wrk_grp = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
			String wrk_date = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_TIME);
			if(wrk_ord==null){
				wrk_ord="";
			}
			if(wrk_grp==null){
				wrk_grp="";
			}
			if(wrk_date==null){
				wrk_date="";
			}
			oci.getObject().setWrk_ord(wrk_ord);
			oci.getObject().setWrk_grp(wrk_grp);
			oci.getObject().setWrk_date(wrk_date);
			
			rm.setData(this.getMapper(MesCrSlittingMMapper.class).doQueryWrkSumInfo(oci.getObject()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	
	
	/**
	 * 上料处理:4mm机组
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAddWeb_43(CommonPage<PlnLengthwisePlanSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(now);
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		String wrk_ord = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
		String wrk_grp = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
		String wrk_date = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_TIME);
		PlnLengthwisePlanSum m=oci.getObject();
				
		//“交工”的这个处理转移到“上料”按钮中
		ResultModel rmDb=this.getBean(PbModelDbServiceImpl.class).findDbTime();
		if("200".equals(rmDb.getState())){
			String dbTime=rmDb.getData().toString().substring(11);
			wrk_date=rmDb.getData().toString().substring(0,10);
			
			if(dbTime.compareTo("00:00:00")>-1&&dbTime.compareTo("08:00:00")<0){
				wrk_ord="1";
			}else if(dbTime.compareTo("08:00:00")>-1&&dbTime.compareTo("16:00:00")<0){
				wrk_ord="2";
			}else if(dbTime.compareTo("16:00:00")>-1&&dbTime.compareTo("24:00:00")<0){
				wrk_ord="3";
			}						
		}else{
			throw new Exception("获取数据库时间失败！请稍后重试");
		}
		MesShiftM Mesm = new MesShiftM();
		Mesm.setMachine_code(m.getMachine_code());
		Mesm.setWrk_date(wrk_date);
		Mesm.setWrk_ord(wrk_ord);
		int v_cnt = this.getMapper(MesShiftMMapper.class).count(Mesm);
		// 获取班组(暂无交接班记录，则使用前端传入的班组代码)
		// 否则获取 交接班记录 (newlsitmMesm)中的班组
		if (v_cnt <= 0) {
			//vGrp = vWrkGrp;
		} else {
			List<MesShiftM> newlsitmMesm = this.getMapper(
					MesShiftMMapper.class).findWithCondition(Mesm, null,
							null, 0, 0);
			if(newlsitmMesm.get(0).getWrk_grp()!=null && !newlsitmMesm.get(0).getWrk_grp().equals("")){
				wrk_grp = newlsitmMesm.get(0).getWrk_grp();
			}
		}
		
		
		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(m.getMachine_code());//机台号
		pp.setLw_plan_no(m.getLw_plan_no());//作业计划号
		List<PlnLengthwisePlan> lpp=this.getMapper(PlnLengthwisePlanMapper.class).find(pp, 0, 0);
		
		CommonPage<YdmProductDetail> cp=new CommonPage<YdmProductDetail>();
		
		if(lpp!=null&&lpp.size()>0){
			//验证选中的作业计划明细表记录存在
			PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
			ppd.setMachine_code(m.getMachine_code());//机台号
			ppd.setLw_plan_no(m.getLw_plan_no());//作业计划号
			ppd.setObject_no_vt(m.getObject_no_vt());//虚拟卷号
			ppd.setObject_no(m.getMaterial_no());//投料卷号
			List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
			if(lppd!=null&&lppd.size()>0){
				//验证选中的作业计划对应的分条主实绩不存在
				MesCrSlittingM mcsm=new MesCrSlittingM();
				mcsm.setMachine_code(m.getMachine_code());//机台号
				mcsm.setSchedule_no(m.getLw_plan_no());//作业计划号
				mcsm.setMaterial_no(m.getMaterial_no());//投料卷号
				mcsm.setMaterial_no_vt(m.getObject_no_vt());//虚拟卷号 
				int icount=this.getMapper(MesCrSlittingMMapper.class).count(mcsm);
				if(icount>0){
					rm.setState("500");
					rm.setMsgInfo("已存在分条主实绩!");
					return rm;
				}
				
				//2018-11-29 只有是已下发状态的钢卷才能下发
				if(!"5BLW02".equals(lppd.get(0).getStatus())){
					rm.setState("500");
					rm.setMsgInfo("当前状态{"+lppd.get(0).getStatus()+"}不为已下发");
					return rm;
				}
				
				//调用生产管理接口验证作业计划状态能执行此操作
				List<MesCrSlittingM> lmcsm=new ArrayList<MesCrSlittingM>();
				// 传入带毫秒的字符串
				mcsm.setMemo(createTime);
				lmcsm.add(mcsm);
				this.getBean(MesApiServiceImpl.class).MesCrSlittingMAddValid(lmcsm);
				
				//验证选中的原料卷库存明细为在库状态
				YdmProductDetail ypd=new YdmProductDetail(); 
				ypd.setCoilno(m.getMaterial_no());//卷号对应投料卷号
				ypd.setState("0");
				List<YdmProductDetail> lypd = this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 1);
				if(lypd==null||lypd.size()==0){
					rm.setState("500");
					rm.setMsgInfo("未找到库存明细信息!");
					return rm;
				}
				
				//------------开始事务------------------
				String sDate="S"+ new SimpleDateFormat("yyMMdd").format(now);
				ComBaseMachine cbm=this.getBean(ComBaseMachineServiceImpl.class).doGetMark(m.getMachine_code());
				if(cbm==null||cbm.getMachine_mark()==null){
					rm.setState("500");
					rm.setMsgInfo("机台代号获取失败！");
					return rm;
				}
				//这里还需要获取机器，根据机器的机台号得到机器的编号 1,2
				sDate+=cbm.getMachine_mark();
				
				
				mcsm.setProcess_no(sDate);
				if(sDate.length()==9){
					icount=this.getMapper(MesCrSlittingMMapper.class).doQueryMaxProcessNo(mcsm);
				}else if(sDate.length()==10){
					icount=this.getMapper(MesCrSlittingMMapper.class).doQueryMaxProcessNo1(mcsm);
				}
								
				MesCrSlittingM mcm=new MesCrSlittingM();
				mcm.setProcess_no(sDate+String.format("%03d", icount+1));
				
				mcm.setSchedule_no(lppd.get(0).getLw_plan_no());//作业计划号
				mcm.setMachine_code(lppd.get(0).getMachine_code());
				mcm.setInner_seq(lppd.get(0).getLw_seq());
				mcm.setMaterial_no_vt(lppd.get(0).getObject_no_vt());
				mcm.setPln_mtr_inn_dia(lppd.get(0).getMat_diameter_inn());
				mcm.setPln_mtr_len(lppd.get(0).getMat_length());
				mcm.setPln_mtr_out_dia(lppd.get(0).getMat_diameter_out());
				mcm.setPln_mtr_thk(lppd.get(0).getMat_thick());
				mcm.setPln_mtr_thr_wgt(lppd.get(0).getMat_single_weight());
				mcm.setPln_mtr_wdt(lppd.get(0).getMat_width());
				mcm.setPln_steel_code(lppd.get(0).getSteel_code());
				
				mcm.setMaterial_no(lypd.get(0).getCoilno());
				mcm.setSteel_code(lypd.get(0).getSteelcode());
				mcm.setMtr_act_wgt(lypd.get(0).getFactweight());
				mcm.setMtr_inn_dia(lypd.get(0).getDiameter_inn());
				mcm.setMtr_len(lypd.get(0).getLength());
				mcm.setMtr_out_dia(lypd.get(0).getDiameter_out());
				mcm.setMtr_thk(lypd.get(0).getThick());
				if(lypd.get(0).getTheoryweight()!=null){
					mcm.setMtr_thr_wgt(lypd.get(0).getTheoryweight());
					//如果是酸洗后进行分条，取酸洗的实重当做理重，二次分条的也是一样20240626刘侣
					if (lypd.get(0).getMachine_code()!=null && ("M0010".equals(lypd.get(0).getMachine_code()) || "M0001".equals(lypd.get(0).getMachine_code()))) {
						mcm.setMtr_thr_wgt(lypd.get(0).getFactweight());
					}
				}else{
					mcm.setMtr_thr_wgt(lypd.get(0).getFactweight());
				}
				
				mcm.setMtr_wdt(lypd.get(0).getWidth());
				//mcm.setMtr_act_wgt(lppd.get(0).getMtr_act_wgt());
				if(username==null){
					username="";
				}
				mcm.setChief_opr(username);
				mcm.setWrk_date(wrk_date);
				mcm.setWrk_grp(wrk_grp);
				mcm.setWrk_ord(wrk_ord);
				mcm.setFeeding_time(now);			
				mcm.setCreate_opr(username);
				mcm.setCreate_time(now);
				
				//横切方式（CRS_CUT_MODE）：通过生产订单号为条件，关联 pln_process_plan 表获取 CROSSCUT_STYLE 字段，详细截图；
				List<PlnProcessPlan> lppp=this.getMapper(PlnLengthwisePlanDetailMapper.class).doQueryCrs(m.getObject_no_vt());
				if(lppp!=null && lppp.size()>0){
					String crs_cut_mode = lppp.get(0).getCrosscut_style();
					mcm.setCrs_cut_mode(crs_cut_mode);
				}
				
				this.getMapper(MesCrSlittingMMapper.class).insert(mcm);
			
				//调用生产管理接口，更改业计划状态（主表、从表）、原料虚拟物料进程状态
				this.getBean(MesApiServiceImpl.class).MesCrSlittingMAdd(lmcsm);
				
				//调用物流模块（仓库管理）接口，对原料卷进行生产投料出库操作（接口由物流模块提供）；																																							
				YdmProductDetail ypdu=new YdmProductDetail();
				ypdu.setCoilno(m.getMaterial_no());
				// 传入操作时间字符串带毫秒
				ypdu.setMemo(createTime);
				cp.setObject(ypdu);
				this.getBean(LmsApiServiceImpl.class).doOutStorage(cp);
				
				try{
					this.getBean(PlnProdorderStatisticServiceImpl.class).updateProdSta(lypd.get(0).getCoilno(),true);
				}catch(Exception e){
					e.printStackTrace();
				}
				
				String isOpen = this.getMapper(ComBaseInfoMapper.class).findById("9512").getMemo();
				if ("1".equals(isOpen)) {
				
					// 记录成本异动点：20230811刘侣
					ComBaseCbYdd cd = new ComBaseCbYdd();
					cd.setCoilStus("0"); // 综判前算半成品0，综判入库后算成品1
					cd.setInstDisp("01");
					cd.setDataTypeIdx("O");
					// 当前产线：
					String currentMachine = lypd.get(0).getCoilno().contains("S") ? "YTSX" : lypd.get(0).getCoilno().contains("L") ? "YTZZ" : lypd.get(0).getCoilno().contains("P") ? "YTPZ" : lypd.get(0).getCoilno().contains("T") ? "YTTH" : lypd.get(0).getCoilno().contains("K") ? "YTHJ" : lypd.get(0).getCoilno().contains("F") ? "YTZJ" : "YT1";
					cd.setLocNo(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setInvQtyUnit("块");
					cd.setInvWidth(lypd.get(0).getWidth() != null ? String.valueOf(lypd.get(0).getWidth()) : "0");
					cd.setCreateId(userId);
					cd.setActivityId("41A");
					cd.setInvLength(lypd.get(0).getLength() != null ? String.valueOf(lypd.get(0).getLength()) : "0");
					cd.setManageip(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setProdName(lypd.get(0).getProd_name());
					cd.setInvThick(lypd.get(0).getThick() != null ? String.valueOf(lypd.get(0).getThick()) : "0");
					
					
					String prevcoil = lypd.get(0).getCoilno();
					// 上道产线：
					String prevMachine = prevcoil.contains("S") ? "YTSX" : prevcoil.contains("L") ? "YTZZ" : prevcoil.contains("P") ? "YTPZ" : prevcoil.contains("T") ? "YTTH" : prevcoil.contains("K") ? "YTHJ" : prevcoil.contains("F") ? "YTZJ" : "YT1";
					cd.setRefnoA("YT1".equals(prevMachine) ? lypd.get(0).getMaterailcoilno() : prevcoil); // 投料卷号
					cd.setSysId("IA");
					cd.setOrderItem(lypd.get(0).getOrderno());
					cd.setCrntMill(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setBeTransUnit("t");
					cd.setExecJobFunc("N");
					ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(lypd.get(0).getSteelcode());
					if (cbs != null) {
						cd.setAlloyNo(cbs.getSteel_name()); // 牌号
					}
					
					cd.setAcctDate(new SimpleDateFormat("yyyyMMdd").format(now));
					cd.setLastMill(prevMachine); // 填上道工序产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setBeTransWgt(lypd.get(0).getFactweight() != null ? lypd.get(0).getFactweight() / 1000 : lypd.get(0).getFactweight());
					cd.setProdTypeNo("CTR");
					cd.setAppId("优特钢小纵剪上料");
					cd.setInvId("YT1".equals(currentMachine) ? lypd.get(0).getMaterailcoilno() : lypd.get(0).getCoilno());
					cd.setInvQty("1");

					// setSrcFac根据卷的物料属性去判断：20231031刘侣
					cd.setSrcFac("507101".equals(lypd.get(0).getObject_attr()) ? "1" : "3");
					
					cd.setGrade("40740801".equals(lypd.get(0).getJudgeresult()) ? "1" : "1"); // 正品　1　协议　3　次品　5
					cd.setProdClassNo("H");

					// 存入表：1、上料一抛：原料转库（47）（原料上料准备生产时抛送）
					cd.setActivityId("55A");
					cd.setExecJobFunc("N");
					cd.setDataTypeIdx("O");
					cd.setProdTypeNo("YT1".equals(prevMachine) && cd.getInvId().startsWith("L") ? "CCR" : "YT1".equals(prevMachine) ? "HCR" : "CTR");
					cd.setCoilStus("0"); // 综判前算半成品0，综判入库后算成品1
					cd.setCrntMill(prevMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setManageip(prevMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setLocNo(prevMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//					String currentMName = ypd.getCoilno().contains("S") ? "酸洗" : ypd.getCoilno().contains("L") ? "冷轧" : ypd.getCoilno().contains("P") ? "平整" : ypd.getCoilno().contains("T") ? "退火" : ypd.getCoilno().contains("K") ? "横剪" : ypd.getCoilno().contains("F") ? "分条" : "原料";
					String prevMName = prevcoil.contains("S") ? "酸洗" : prevcoil.contains("L") ? "冷轧" : prevcoil.contains("P") ? "平整" : prevcoil.contains("T") ? "退火" : prevcoil.contains("K") ? "开平" : prevcoil.contains("F") ? "分条" : "原料";
					cd.setAppId("优特" + prevMName + "转库");
					
					// 一次结算后第一次生产点上料的时候，不抛 转库和接收原料  改抛 12AB
					// 该卷是否刚刚一次结算完：可以根据提单里是否有这卷的一次结算数据进行判断：
//					int isYcJs = this.getMapper(YdmProductDetailMapper.class).isHasYcJs(lypd.get(0).getCoilno());
//					if (isYcJs <= 0) {
						this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), lypd.get(0).getMaterailcoilno());
//					}
					
					// 二抛：酸洗接收原料（17）(此时原料还未上酸洗产线) 
					// 对已有数据进行修改：
					cd.setDataTypeIdx("N");
//					cd.setProdTypeNo("CTR");
					cd.setManageip("YTZJ");
					cd.setLocNo("YTZJ");
					cd.setAppId("分条接收原料");
					
					// 20231130刘侣
//					if (isYcJs > 0) {
//						cd.setActivityId("12AB");
//						cd.setAppId("来料加工");
//					}
					// end
					this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), lypd.get(0).getMaterailcoilno());
					// 三抛：酸洗上料（41，开始生产
					cd.setActivityId("41A");
					cd.setDataTypeIdx("O");
					cd.setAppId("分条上料");
					cd.setLastMill("YTZJ");
					this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), lypd.get(0).getMaterailcoilno());
					// end
				}
				
				//日志
				MesOprLog mol = new MesOprLog("车间MES", "4mm分条机作业管理", "上料", username, opr_time, mcm.getMaterial_no(), null, null, null, "投料卷号："+m.getMaterial_no()+mcm.getMachine_code());
				this.getMapper(MesOprLogMapper.class).insert(mol);				
				//------------结束事务--------------------
				rm.setState("200");
			}else{
				rm.setState("500");
				rm.setMsgInfo("未找到作业计划明细信息!");
				return rm;
			}
		}else{
			rm.setState("500");
			rm.setMsgInfo("未找到作业计划主表记录信息!");
			return rm;
		}
		return rm;
	}
	
	
	
	/**
	 * 上料处理 :12mm分条机组作业管理
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAddWeb(CommonPage<PlnLengthwisePlanSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(now);; 
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		String wrk_ord = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
		String wrk_grp = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
		String wrk_date = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_TIME);
		PlnLengthwisePlanSum m=oci.getObject();			
		
		//“交工”的这个处理转移到“上料”按钮中
		ResultModel rmDb=this.getBean(PbModelDbServiceImpl.class).findDbTime();
		if("200".equals(rmDb.getState())){
			String dbTime=rmDb.getData().toString().substring(11);
			wrk_date=rmDb.getData().toString().substring(0,10);		
			if(dbTime.compareTo(DateUtil.NBeginTime)>-1 && dbTime.compareTo(DateUtil.BeginTime)<0){
				wrk_ord="1";
			}else if(dbTime.compareTo(DateUtil.BeginTime)>-1 && dbTime.compareTo(DateUtil.EndTime)<0){
				wrk_ord="2";
			}else if(dbTime.compareTo(DateUtil.EndTime)>-1 && dbTime.compareTo(DateUtil.NEndTime)<0){
				wrk_ord="1";
				SimpleDateFormat formatYmd = new SimpleDateFormat("yyyy-MM-dd");
				Date date = formatYmd.parse(wrk_date);
				Calendar c = Calendar.getInstance();  
				c.setTime(date);  
				c.add(Calendar.DAY_OF_MONTH, 1);//日期+1 
				wrk_date=formatYmd.format(c.getTime());
			}			
		}else{
			throw new Exception("获取数据库时间失败！请稍后重试");
		}
		MesShiftM Mesm = new MesShiftM();
		Mesm.setMachine_code(m.getMachine_code());
		Mesm.setWrk_date(wrk_date);
		Mesm.setWrk_ord(wrk_ord);
		int v_cnt = this.getMapper(MesShiftMMapper.class).count(Mesm);
		// 获取班组(暂无交接班记录，则使用前端传入的班组代码)
		// 否则获取 交接班记录 (newlsitmMesm)中的班组
		if (v_cnt <= 0) {
			//vGrp = vWrkGrp;
		} else {
			List<MesShiftM> newlsitmMesm = this.getMapper(MesShiftMMapper.class).findWithCondition(Mesm, null, null, 0, 0);
			if(newlsitmMesm.get(0).getWrk_grp()!=null && !newlsitmMesm.get(0).getWrk_grp().equals("")){
				wrk_grp = newlsitmMesm.get(0).getWrk_grp();
			}
		}	
		
		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(m.getMachine_code());//机台号
		pp.setLw_plan_no(m.getLw_plan_no());//作业计划号
		List<PlnLengthwisePlan> lpp=this.getMapper(PlnLengthwisePlanMapper.class).find(pp, 0, 0);
		
		CommonPage<YdmProductDetail> cp=new CommonPage<YdmProductDetail>();	
		if(lpp!=null&&lpp.size()>0){
			//验证选中的作业计划明细表记录存在
			PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
			ppd.setMachine_code(m.getMachine_code());//机台号
			ppd.setLw_plan_no(m.getLw_plan_no());//作业计划号
			ppd.setObject_no_vt(m.getObject_no_vt());//虚拟卷号
			ppd.setObject_no(m.getMaterial_no());//投料卷号
			List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
			if(lppd!=null&&lppd.size()>0){
				//验证选中的作业计划对应的分条主实绩不存在
				MesCrSlittingM mcsm=new MesCrSlittingM();
				mcsm.setMachine_code(m.getMachine_code());//机台号
				mcsm.setSchedule_no(m.getLw_plan_no());//作业计划号
				mcsm.setMaterial_no(m.getMaterial_no());//投料卷号
				mcsm.setMaterial_no_vt(m.getObject_no_vt());//虚拟卷号 
				int icount=this.getMapper(MesCrSlittingMMapper.class).count(mcsm);
				if(icount>0){
					rm.setState("500");
					rm.setMsgInfo("已存在分条主实绩!");
					return rm;
				}
				
				//2018-11-29 只有是已下发状态的钢卷才能下发
				if(!"5BLW02".equals(lppd.get(0).getStatus())){
					rm.setState("500");
					rm.setMsgInfo("当前状态{"+lppd.get(0).getStatus()+"}不为已下发");
					return rm;
				}
				
				//调用生产管理接口验证作业计划状态能执行此操作
				List<MesCrSlittingM> lmcsm=new ArrayList<MesCrSlittingM>();
				// 传入带毫秒的字符串
				mcsm.setMemo(createTime);
				lmcsm.add(mcsm);
				this.getBean(MesApiServiceImpl.class).MesCrSlittingMAddValid(lmcsm);
				
				//验证选中的原料卷库存明细为在库状态
				YdmProductDetail ypd=new YdmProductDetail(); 
				ypd.setCoilno(m.getMaterial_no());//卷号对应投料卷号
				ypd.setState("0");
				List<YdmProductDetail> lypd = this.getMapper(YdmProductDetailMapper.class).find(ypd, 0, 1);
				if(lypd==null||lypd.size()==0){
					rm.setState("500");
					rm.setMsgInfo("未找到库存明细信息!");
					return rm;
				}
				
				//------------开始事务------------------
				String sDate="S"+ new SimpleDateFormat("yyMMdd").format(now);
				ComBaseMachine cbm=this.getBean(ComBaseMachineServiceImpl.class).doGetMark(m.getMachine_code());
				if(cbm==null||cbm.getMachine_mark()==null){
					rm.setState("500");
					rm.setMsgInfo("机台代号获取失败！");
					return rm;
				}
				//这里还需要获取机器，根据机器的机台号得到机器的编号 1,2
				sDate+=cbm.getMachine_mark();								
				mcsm.setProcess_no(sDate);
				if(sDate.length()==9){
					icount=this.getMapper(MesCrSlittingMMapper.class).doQueryMaxProcessNo(mcsm);
				}else if(sDate.length()==10){
					icount=this.getMapper(MesCrSlittingMMapper.class).doQueryMaxProcessNo1(mcsm);
				}
								
				MesCrSlittingM mcm=new MesCrSlittingM();
				mcm.setProcess_no(sDate+String.format("%03d", icount+1));				
				mcm.setSchedule_no(lppd.get(0).getLw_plan_no());//作业计划号
				mcm.setMachine_code(lppd.get(0).getMachine_code());
				mcm.setInner_seq(lppd.get(0).getLw_seq());
				mcm.setMaterial_no_vt(lppd.get(0).getObject_no_vt());
				mcm.setPln_mtr_inn_dia(lppd.get(0).getMat_diameter_inn());
				mcm.setPln_mtr_len(lppd.get(0).getMat_length());
				mcm.setPln_mtr_out_dia(lppd.get(0).getMat_diameter_out());
				mcm.setPln_mtr_thk(lppd.get(0).getMat_thick());
				mcm.setPln_mtr_thr_wgt(lppd.get(0).getMat_single_weight());
				mcm.setPln_mtr_wdt(lppd.get(0).getMat_width());
				mcm.setPln_steel_code(lppd.get(0).getSteel_code());				
				mcm.setMaterial_no(lypd.get(0).getCoilno());
				mcm.setSteel_code(lypd.get(0).getSteelcode());
				mcm.setMtr_act_wgt(lypd.get(0).getFactweight());
				mcm.setMtr_inn_dia(lypd.get(0).getDiameter_inn());
				mcm.setMtr_len(lypd.get(0).getLength());
				mcm.setMtr_out_dia(lypd.get(0).getDiameter_out());
				mcm.setMtr_thk(lypd.get(0).getThick());
				if(lypd.get(0).getTheoryweight()!=null){
					mcm.setMtr_thr_wgt(lypd.get(0).getTheoryweight());
					
					//如果是二次分条，取投料分条的实重当做理重
					if (lypd.get(0).getMachine_code()!=null && "M0002".equals(lypd.get(0).getMachine_code())) {
						mcm.setMtr_thr_wgt(lypd.get(0).getFactweight());
					}
					
				}else{
					mcm.setMtr_thr_wgt(lypd.get(0).getFactweight());
				}
				
				
				mcm.setMtr_wdt(lypd.get(0).getWidth());
				mcm.setChief_opr(username);
				mcm.setWrk_date(wrk_date);
				mcm.setWrk_grp(wrk_grp);
				mcm.setWrk_ord(wrk_ord);
				mcm.setFeeding_time(now);			
				mcm.setCreate_opr(username);
				mcm.setCreate_time(now);
				
				//横切方式（CRS_CUT_MODE）：通过生产订单号为条件，关联 pln_process_plan 表获取 CROSSCUT_STYLE 字段，详细截图；
				List<PlnProcessPlan> lppp=this.getMapper(PlnLengthwisePlanDetailMapper.class).doQueryCrs(m.getObject_no_vt());
				if(lppp!=null && lppp.size()>0){
					String crs_cut_mode = lppp.get(0).getCrosscut_style();
					mcm.setCrs_cut_mode(crs_cut_mode);
				}
				
				this.getMapper(MesCrSlittingMMapper.class).insert(mcm);
			
				//调用生产管理接口，更改业计划状态（主表、从表）、原料虚拟物料进程状态
				this.getBean(MesApiServiceImpl.class).MesCrSlittingMAdd(lmcsm);
				
				//调用物流模块（仓库管理）接口，对原料卷进行生产投料出库操作（接口由物流模块提供）；																																							
				YdmProductDetail ypdu = new YdmProductDetail();
				ypdu.setCoilno(m.getMaterial_no());
				// 传入操作时间字符串带毫秒
				ypdu.setMemo(createTime);
				cp.setObject(ypdu);
				this.getBean(LmsApiServiceImpl.class).doOutStorage(cp);
				
				try{
					this.getBean(PlnProdorderStatisticServiceImpl.class).updateProdSta(lypd.get(0).getCoilno(),true);
				}catch(Exception e){
					e.printStackTrace();
				}		
				
				String isOpen = this.getMapper(ComBaseInfoMapper.class).findById("9512").getMemo();
				if ("1".equals(isOpen)) {
				
					// 记录成本异动点：20230811刘侣
					ComBaseCbYdd cd = new ComBaseCbYdd();
					cd.setCoilStus("0"); // 综判前算半成品0，综判入库后算成品1
					cd.setInstDisp("01");
					cd.setDataTypeIdx("O");
					// 当前产线：
					String currentMachine = lypd.get(0).getCoilno().contains("S") ? "YTSX" : lypd.get(0).getCoilno().contains("L") ? "YTZZ" : lypd.get(0).getCoilno().contains("P") ? "YTPZ" : lypd.get(0).getCoilno().contains("T") ? "YTTH" : lypd.get(0).getCoilno().contains("K") ? "YTHJ" : lypd.get(0).getCoilno().contains("F") ? "YTZJ" : "YT1";
					cd.setLocNo(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setInvQtyUnit("块");
					cd.setInvWidth(lypd.get(0).getWidth() != null ? String.valueOf(lypd.get(0).getWidth()) : "0");
					cd.setCreateId(userId);
					cd.setActivityId("41A");
					cd.setInvLength(lypd.get(0).getLength() != null ? String.valueOf(lypd.get(0).getLength()) : "0");
					cd.setManageip(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setProdName(lypd.get(0).getProd_name());
					cd.setInvThick(lypd.get(0).getThick() != null ? String.valueOf(lypd.get(0).getThick()) : "0");
					
					
					String prevcoil = lypd.get(0).getCoilno();
					// 上道产线：
					String prevMachine = prevcoil.contains("S") ? "YTSX" : prevcoil.contains("L") ? "YTZZ" : prevcoil.contains("P") ? "YTPZ" : prevcoil.contains("T") ? "YTTH" : prevcoil.contains("K") ? "YTHJ" : prevcoil.contains("F") ? "YTZJ" : "YT1";
					cd.setRefnoA("YT1".equals(prevMachine) ? lypd.get(0).getMaterailcoilno() : prevcoil); // 投料卷号
					cd.setSysId("IA");
					cd.setOrderItem(lypd.get(0).getOrderno());
					cd.setCrntMill(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setBeTransUnit("t");
					cd.setExecJobFunc("N");
					ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(lypd.get(0).getSteelcode());
					if (cbs != null) {
						cd.setAlloyNo(cbs.getSteel_name()); // 牌号
					}
					
					cd.setAcctDate(new SimpleDateFormat("yyyyMMdd").format(now));
					cd.setLastMill(prevMachine); // 填上道工序产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setBeTransWgt(lypd.get(0).getFactweight() != null ? lypd.get(0).getFactweight() / 1000 : lypd.get(0).getFactweight());
					cd.setProdTypeNo("CTR");
					cd.setAppId("优特钢大纵剪上料");
					cd.setInvId("YT1".equals(currentMachine) ? lypd.get(0).getMaterailcoilno() : lypd.get(0).getCoilno());
					cd.setInvQty("1");

					// setSrcFac根据卷的物料属性去判断：20231031刘侣
					cd.setSrcFac("507101".equals(lypd.get(0).getObject_attr()) ? "1" : "3");
					
					cd.setGrade("40740801".equals(lypd.get(0).getJudgeresult()) ? "1" : "1"); // 正品　1　协议　3　次品　5
					cd.setProdClassNo("H");
					
					// 存入表：1、上料一抛：原料转库（47）（原料上料准备生产时抛送）
					cd.setActivityId("55A");
					cd.setExecJobFunc("N");
					cd.setDataTypeIdx("O");
					cd.setProdTypeNo("YT1".equals(prevMachine) && cd.getInvId().startsWith("L") ? "CCR" : "YT1".equals(prevMachine) ? "HCR" : "CTR");
					cd.setCoilStus("0"); // 综判前算半成品0，综判入库后算成品1
					cd.setCrntMill(prevMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setManageip(prevMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setLocNo(prevMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//					String currentMName = ypd.getCoilno().contains("S") ? "酸洗" : ypd.getCoilno().contains("L") ? "冷轧" : ypd.getCoilno().contains("P") ? "平整" : ypd.getCoilno().contains("T") ? "退火" : ypd.getCoilno().contains("K") ? "横剪" : ypd.getCoilno().contains("F") ? "分条" : "原料";
					String prevMName = prevcoil.contains("S") ? "酸洗" : prevcoil.contains("L") ? "冷轧" : prevcoil.contains("P") ? "平整" : prevcoil.contains("T") ? "退火" : prevcoil.contains("K") ? "开平" : prevcoil.contains("F") ? "分条" : "原料";
					cd.setAppId("优特" + prevMName + "转库");
					
					// 一次结算后第一次生产点上料的时候，不抛 转库和接收原料  改抛 12AB
					// 该卷是否刚刚一次结算完：可以根据提单里是否有这卷的一次结算数据进行判断：
//					int isYcJs = this.getMapper(YdmProductDetailMapper.class).isHasYcJs(lypd.get(0).getCoilno());
//					if (isYcJs <= 0) {
						this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), lypd.get(0).getMaterailcoilno());
//					}
					
					// 二抛：酸洗接收原料（17）(此时原料还未上酸洗产线) 
					// 对已有数据进行修改：
					cd.setDataTypeIdx("N");
//					cd.setProdTypeNo("CTR");
					cd.setManageip("YTZJ");
					cd.setLocNo("YTZJ");
					cd.setAppId("分条接收原料");
					
					// 20231130刘侣 废掉 xuli 20231229 来刘侣
//					if (isYcJs > 0) {
//						cd.setActivityId("12AB");
//						cd.setAppId("来料加工");
//					}
					// end
					this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), lypd.get(0).getMaterailcoilno());
					// 三抛：酸洗上料（41，开始生产
					cd.setActivityId("41A");
					cd.setDataTypeIdx("O");
					cd.setAppId("分条上料");
					cd.setLastMill("YTZJ");
					this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), lypd.get(0).getMaterailcoilno());
					// end
				}
				
				//日志
				MesOprLog mol = new MesOprLog("车间MES", "12mm分条机作业管理", "上料", username, opr_time, mcm.getMaterial_no(), null, null, null, "投料卷号："+m.getMaterial_no()+mcm.getMachine_code());
				this.getMapper(MesOprLogMapper.class).insert(mol);				
				//------------结束事务--------------------
				rm.setState("200");
			}else{
				rm.setState("500");
				rm.setMsgInfo("未找到作业计划明细信息!");
				return rm;
			}
		}else{
			rm.setState("500");
			rm.setMsgInfo("未找到作业计划主表记录信息!");
			return rm;
		}
		
		return rm;
	}
	
	/**
	 * 恢复计划
	 * @throws Exception 
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdateWeb(CommonPage<PlnLengthwisePlanSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		PlnLengthwisePlanSum m=oci.getObject();
		
		//验证选中的作业计划主表记录存在
		PlnLengthwisePlan pp=new PlnLengthwisePlan();
		pp.setMachine_code(m.getMachine_code());//机台号
		pp.setLw_plan_no(m.getLw_plan_no());//作业计划号
		List<PlnLengthwisePlan> lpp=this.getMapper(PlnLengthwisePlanMapper.class).find(null, 0, 0);
		
		CommonPage<YdmProductDetail> cp=new CommonPage<YdmProductDetail>();
		if(lpp!=null&&lpp.size()>0){
			//验证选中的作业计划明细表记录存在
			PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
			ppd.setMachine_code(m.getMachine_code());//机台号
			ppd.setLw_plan_no(m.getLw_plan_no());//作业计划号
			ppd.setObject_no_vt(m.getObject_no_vt());//虚拟卷号
			ppd.setObject_no(m.getMaterial_no());//投料卷号
			List<PlnLengthwisePlanDetail> lppd=this.getMapper(PlnLengthwisePlanDetailMapper.class).find(ppd, 0, 0);
			if(lppd!=null&&lppd.size()>0){
				//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
				MesCrSlittingM mcsm=new MesCrSlittingM();
				mcsm.setMachine_code(m.getMachine_code());//机台号
				mcsm.setSchedule_no(m.getLw_plan_no());//作业计划号
				mcsm.setMaterial_no(m.getMaterial_no());//投料卷号
				mcsm.setMaterial_no_vt(m.getObject_no_vt());//虚拟卷号 
				//mcsm.setHand_over_status("0");//未交工
				List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm,0,0);
				if(lmcsm==null||lmcsm.size()==0){
					rm.setState("500");
					rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
					return rm;
				}
				if(!"0".equals(lmcsm.get(0).getHand_over_status())
						&&lmcsm.get(0).getHand_over_status()!=null){
					rm.setState("500");
					rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条已生产交工！");
					return rm;
				}
				
				//验证选中的作业计划无对应的子卷实绩
				MesCrSlittingD mcsd=new MesCrSlittingD();
				mcsd.setProcess_no(lmcsm.get(0).getProcess_no());
				int icount=this.getMapper(MesCrSlittingDMapper.class).count(mcsd);
				if(icount>0){
					rm.setState("500");
					rm.setMsgInfo("分条实绩存在子卷信息,如有必要请先删除子卷信息!");
					return rm;
				}
				
				//调用生产管理接口，验证作业计划状态能执行此操作，否则，返回错误信息并提示
				List<MesCrSlittingM> lmcsmq=new ArrayList<MesCrSlittingM>();
				lmcsmq.add(mcsm);
				this.getBean(MesApiServiceImpl.class).MesCrSlittingMCancelValid(lmcsmq);
				
				//*******调用物流模块（仓库管理）接口，验证原料卷可以进行撤销出库操作（接口由物流模块提供）
				YdmProductDetail ypdu=new YdmProductDetail();
				ypdu.setCoilno(m.getMaterial_no());
				// 传入操作时间
				ypdu.setCreatedate(now);
				cp.setObject(ypdu);
				ResultModel rmInfo = this.getBean(LmsApiServiceImpl.class).doDepend(cp);
				if("500".equals(rmInfo.getState())){
					return rmInfo;
				}
				
				//------------开始事务------------------
				//删除分条实绩主记录   这里实际上应该只有一条
				for(MesCrSlittingM mc:lmcsm){
					this.getMapper(MesCrSlittingMMapper.class).doDeleteId(mc);
				}
				
				//调用生产管理接口，更改业计划状态（主表、从表）、原料虚拟物料进程状态
				this.getBean(MesApiServiceImpl.class).MesCrSlittingMCancel(lmcsmq);
				
				//*******调用物流模块（仓库管理）接口，将原料卷进行出库撤销操作*
				this.getBean(LmsApiServiceImpl.class).doCancelOut(cp);
				
				try{
					this.getBean(PlnProdorderStatisticServiceImpl.class).updateProdSta(m.getMaterial_no(),false);
				}catch(Exception e){
					e.printStackTrace();
				}
				
				String isOpen = this.getMapper(ComBaseInfoMapper.class).findById("9512").getMemo();
				if ("1".equals(isOpen)) {
				
					// 记录成本异动点：20230811刘侣
					YdmProductDetail ypd = this.getMapper(YdmProductDetailMapper.class).doFind(m.getMaterial_no(), null);
					ComBaseCbYdd cd = new ComBaseCbYdd();
					cd.setCoilStus("0"); // 综判前算半成品0，综判入库后算成品1
					cd.setInstDisp("01");
					cd.setDataTypeIdx("O");
					// 当前产线：
					String currentMachine = ypd.getCoilno().contains("S") ? "YTSX" : ypd.getCoilno().contains("L") ? "YTZZ" : ypd.getCoilno().contains("P") ? "YTPZ" : ypd.getCoilno().contains("T") ? "YTTH" : ypd.getCoilno().contains("K") ? "YTHJ" : ypd.getCoilno().contains("F") ? "YTZJ" : "YT1";
					cd.setLocNo(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setInvQtyUnit("块");
					cd.setInvWidth(ypd.getWidth() != null ? String.valueOf(ypd.getWidth()) : "0");
					cd.setCreateId(userId);
					cd.setActivityId("41A");
					cd.setInvLength(ypd.getLength() != null ? String.valueOf(ypd.getLength()) : "0");
					cd.setManageip(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setProdName(ypd.getProd_name());
					cd.setInvThick(ypd.getThick() != null ? String.valueOf(ypd.getThick()) : "0");
					
					
					String prevcoil = ypd.getCoilno();
					// 上道产线：
					String prevMachine = prevcoil.contains("S") ? "YTSX" : prevcoil.contains("L") ? "YTZZ" : prevcoil.contains("P") ? "YTPZ" : prevcoil.contains("T") ? "YTTH" : prevcoil.contains("K") ? "YTHJ" : prevcoil.contains("F") ? "YTZJ" : "YT1";
					cd.setRefnoA("YT1".equals(prevMachine) ? ypd.getMaterailcoilno() : prevcoil); // 投料卷号
					cd.setSysId("IA");
					cd.setOrderItem(ypd.getOrderno());
					cd.setCrntMill(currentMachine); // 填当前产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setBeTransUnit("t");
					cd.setExecJobFunc("D");
					ComBaseSteel cbs = this.getMapper(ComBaseSteelMapper.class).findById(ypd.getSteelcode());
					if (cbs != null) {
						cd.setAlloyNo(cbs.getSteel_name()); // 牌号
					}
					
					cd.setAcctDate(new SimpleDateFormat("yyyyMMdd").format(now));
					cd.setLastMill(prevMachine); // 填上道工序产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setBeTransWgt(ypd.getFactweight() != null ? ypd.getFactweight() / 1000 : ypd.getFactweight());
					cd.setProdTypeNo("CTR");
					cd.setAppId("优特钢纵剪取消上料");
					cd.setInvId("YT1".equals(currentMachine) ? ypd.getMaterailcoilno() : ypd.getCoilno());
					cd.setInvQty("1");

					// setSrcFac根据卷的物料属性去判断：20231031刘侣
					cd.setSrcFac("507101".equals(ypd.getObject_attr()) ? "1" : "3");
					
					cd.setGrade("40740801".equals(ypd.getJudgeresult()) ? "1" : "1"); // 正品　1　协议　3　次品　5
					cd.setProdClassNo("H");
					
					// 存入表：1、上料一抛：原料转库（47）（原料上料准备生产时抛送）
					cd.setActivityId("55A");
					cd.setExecJobFunc("D");
					cd.setDataTypeIdx("O");
					cd.setProdTypeNo("YT1".equals(prevMachine) && cd.getInvId().startsWith("L") ? "CCR" : "YT1".equals(prevMachine) ? "HCR" : "CTR");
					cd.setCoilStus("0"); // 综判前算半成品0，综判入库后算成品1
					cd.setCrntMill(prevMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setManageip(prevMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
					cd.setLocNo(prevMachine); // 填上道产线：优特酸选 YTSX,优特轧制YTZZ,优特平整YTPZ,优特退火YTTH,优特横剪YTHJ,优特纵剪YTZJ
//					String currentMName = ypd.getCoilno().contains("S") ? "酸洗" : ypd.getCoilno().contains("L") ? "冷轧" : ypd.getCoilno().contains("P") ? "平整" : ypd.getCoilno().contains("T") ? "退火" : ypd.getCoilno().contains("K") ? "横剪" : ypd.getCoilno().contains("F") ? "分条" : "原料";
					String prevMName = prevcoil.contains("S") ? "酸洗" : prevcoil.contains("L") ? "冷轧" : prevcoil.contains("P") ? "平整" : prevcoil.contains("T") ? "退火" : prevcoil.contains("K") ? "开平" : prevcoil.contains("F") ? "分条" : "原料";
					cd.setAppId("优特" + prevMName + "取消转库");
					
					// 一次结算后第一次生产点上料的时候，不抛 转库和接收原料  改抛 12AB
					// 该卷是否刚刚一次结算完：可以根据提单里是否有这卷的一次结算数据进行判断：
//					int isYcJs = this.getMapper(YdmProductDetailMapper.class).isHasYcJs(ypd.getCoilno());
//					if (isYcJs <= 0) {
						this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd.getMaterailcoilno());
//					}
					
					// 二抛：酸洗接收原料（17）(此时原料还未上酸洗产线) 
					// 对已有数据进行修改：
					cd.setDataTypeIdx("N");
//					cd.setProdTypeNo("CTR");
					cd.setManageip("YTZJ");
					cd.setLocNo("YTZJ");
					cd.setAppId("分条取消接收原料");
					
					// 20231130刘侣
//					if (isYcJs > 0) {
//						cd.setActivityId("12AB");
//						cd.setAppId("取消来料加工");
//					}
					// end
					this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd.getMaterailcoilno());
					// 三抛：酸洗上料（41，开始生产
					cd.setActivityId("41A");
					cd.setDataTypeIdx("O");
					cd.setAppId("分条取消上料");
					cd.setLastMill("YTZJ");
					this.getBean(SlmFundFirstDetailService.class).doCbDataIns(cd, cd.getActivityId(), ypd.getMaterailcoilno());
					// end
				}
				
				//日志
				MesOprLog mol = new MesOprLog("车间MES", m.getMachine_name()+"作业管理", "恢复计划", username, opr_time, m.getMaterial_no(), null, null, null, "投料卷号："+m.getMaterial_no()+m.getMachine_code());
				this.getMapper(MesOprLogMapper.class).insert(mol);
				//------------结束事务--------------------
			}else{
				rm.setState("500");
				rm.setMsgInfo("未找到作业计划明细信息!");
				return rm;
			}
		}else{
			rm.setState("500");
			rm.setMsgInfo("未找到作业计划主表记录信息!");
			return rm;
		}				
		rm.setState("200");		
		return rm;
	}
	
	/**
	 * 保存:4mm作业管理
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doSaveWeb(CommonPage<MesCrSlittingSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		PlnLengthwisePlanSum pps=oci.getObject().getSum();
		
		try{
			MesCrSlittingM msm=oci.getObject().getMain();			
			msm.setCrs_cut_len1(msm.getCrs_cut_len1());
			msm.setCrs_cut_len2(msm.getCrs_cut_len2());
			msm.setCrs_cut_len3(msm.getCrs_cut_len3());
			
			//验证选中的作业计划主表记录存在
			PlnLengthwisePlan pp=new PlnLengthwisePlan();
			pp.setMachine_code(pps.getMachine_code());
			pp.setLw_plan_no(pps.getLw_plan_no());
			int icount=this.getMapper(PlnLengthwisePlanMapper.class).count(pp);
			if(icount==0){
				rm.setState("500");
				rm.setMsgInfo("作业计划主表记录不存在");
				return rm;
			}
			
			//验证选中的作业计划明细表记录存在
			PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
			ppd.setMachine_code(pps.getMachine_code());
			ppd.setLw_plan_no(pps.getLw_plan_no());
			ppd.setObject_no_vt(pps.getObject_no_vt());
			ppd.setObject_no(pps.getMaterial_no());
			icount=this.getMapper(PlnLengthwisePlanDetailMapper.class).count(ppd);
			if(icount==0){
				rm.setState("500");
				rm.setMsgInfo("作业计划明细记录不存在");
				return rm;
			}
			
			//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
			MesCrSlittingM mcsm=new MesCrSlittingM();
			mcsm.setMachine_code(pps.getMachine_code());
			mcsm.setSchedule_no(pps.getLw_plan_no());
			mcsm.setMaterial_no_vt(pps.getObject_no_vt());
			mcsm.setMaterial_no(pps.getMaterial_no());
			List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);
			
			if(lmcsm==null||lmcsm.size()==0){
				rm.setState("500");
				rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
				return rm;
			}
			if(!"0".equals(lmcsm.get(0).getHand_over_status())
					&&lmcsm.get(0).getHand_over_status()!=null){
				rm.setState("500");
				rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条已生产交工！");
				return rm;
			}		
		
			//修改分条实绩主记录
			msm.setProcess_no(lmcsm.get(0).getProcess_no());
			msm.setUpdate_opr(username);
			msm.setUpdate_time(now);
			//部分卷吊销
			if("1".equals(msm.getPartial_rejected()) &&(msm.getRejected_coil_no()==null ||"".equals(msm.getRejected_coil_no()))){
				//***************************后续根据机台编号，查询ComBaseMachine表得到机器号左补零1为(F后2位)*******
				//验证机台基础信息存在
				int v_cnt = this.getMapper(ComBaseMachineMapper.class).countWithCondition(null,"machine_code='"+pps.getMachine_code()+"'");
				if(v_cnt<=0){
					throw new Exception("机台代码{"+pps.getMachine_code()+"} 机台基础信息不存在！");
				}
				//获取机台基础信息表中，配置的机台设备代号（设备编号，如1,2,3）
				List<ComBaseMachine> lcbm = this.getMapper(ComBaseMachineMapper.class).findWithCondition(null,
						"machine_code='"+pps.getMachine_code()+"'", null, 0, 0);
				String v_machine_mark=lcbm.get(0).getMachine_mark();
				if(v_machine_mark==null){
					throw new Exception("机台代码{"+pps.getMachine_code()+"} 设备编号未配置，无法创建作业记录号！");
				}
				String sNo=msm.getMaterial_no().substring(0,8)+"F"+lpad(v_machine_mark,2,"0")+"R_";
				
				List<MesCrSlittingM> lcount=this.getMapper(MesCrSlittingMMapper.class).findWithCondition(null, " rejected_coil_no like '"+sNo+"'", "", 0, 0);
				icount=0;
				if(lcount==null||lcount.size()==0){
					icount=1;
				}else{
					if(lcount.size()>=9){
						rm.setState("500");
						rm.setMsgInfo("投料卷号["+lmcsm.get(0).getMaterial_no()+"]：\n 吊销卷卷数超出规则范围");
						return rm;
					}
					ArrayList<Integer> ai=new ArrayList<Integer>();
					for(int i=0;i<lcount.size();i++){
						String rej_str=lcount.get(i).getRejected_coil_no().substring(
								lcount.get(i).getRejected_coil_no().length()-1,lcount.get(i).getRejected_coil_no().length());
						ai.add(i, Integer.parseInt(rej_str));
					}
					for(int i=1;i<=9;i++){
						if(!ai.contains(i)){
							icount=i;
							break;
						}
					}
				}
				//根据机器编号查询机器信息
				ComBaseMachine cbm=this.getBean(ComBaseMachineServiceImpl.class).doGetMark(pps.getMachine_code());
				if(cbm==null||cbm.getMachine_mark()==null){
					rm.setState("500");
					rm.setMsgInfo("机台代号获取失败！");
					return rm;
				}
				
				msm.setRejected_coil_no(msm.getMaterial_no().substring(0,8)+"F"+cbm.getMachine_mark()+"R"+icount);
			}
			
			if("0".equals(msm.getPartial_rejected())){
				msm.setRejected_coil_act_wgt(null);
				msm.setRejected_coil_len(null);
				msm.setRejected_coil_no(null);
				msm.setRejected_coil_out_dia(null);
				msm.setRejected_coil_thr_wgt(null);
			}
			
			this.getMapper(MesCrSlittingMMapper.class).doUpdate(msm);
			//同步子卷实绩的作业日期，班次，班组。
			if(StringUtils.isNotEmpty(msm.getWrk_date()) && 
					StringUtils.isNotEmpty(msm.getWrk_ord()) && StringUtils.isNotEmpty(msm.getWrk_grp())){
				this.getMapper(MesCrSlittingDMapper.class).doUpdateWrk(lmcsm.get(0).getProcess_no(),msm.getWrk_date(),msm.getWrk_ord(),msm.getWrk_grp());
			}
			//日志
			MesOprLog mol = new MesOprLog("车间MES", "4mm作业管理", "保存", username, opr_time, msm.getMaterial_no(), null, null, null, "投料卷号："+pps.getMaterial_no()+msm.getMachine_code());
			this.getMapper(MesOprLogMapper.class).insert(mol);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			ex.printStackTrace();
			rm.setMsgInfo("服务端异常:"+ex.getMessage());
			throw new Exception("服务端异常:"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 保存：12mm作业管理
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doSaveWeb_12mm(CommonPage<MesCrSlittingSum> oci) throws Exception{
		ResultModel rm=new ResultModel();
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		PlnLengthwisePlanSum pps=oci.getObject().getSum();
		try{
			MesCrSlittingM msm=oci.getObject().getMain();			
			msm.setCrs_cut_len1(msm.getCrs_cut_len1());
			msm.setCrs_cut_len2(msm.getCrs_cut_len2());
			msm.setCrs_cut_len3(msm.getCrs_cut_len3());
			
			//验证选中的作业计划主表记录存在
			PlnLengthwisePlan pp=new PlnLengthwisePlan();
			pp.setMachine_code(pps.getMachine_code());
			pp.setLw_plan_no(pps.getLw_plan_no());
			int icount=this.getMapper(PlnLengthwisePlanMapper.class).count(pp);
			if(icount==0){
				rm.setState("500");
				rm.setMsgInfo("作业计划主表记录不存在");
				return rm;
			}
			
			//验证选中的作业计划明细表记录存在
			PlnLengthwisePlanDetail ppd=new PlnLengthwisePlanDetail();
			ppd.setMachine_code(pps.getMachine_code());
			ppd.setLw_plan_no(pps.getLw_plan_no());
			ppd.setObject_no_vt(pps.getObject_no_vt());
			ppd.setObject_no(pps.getMaterial_no());
			icount=this.getMapper(PlnLengthwisePlanDetailMapper.class).count(ppd);
			if(icount==0){
				rm.setState("500");
				rm.setMsgInfo("作业计划明细记录不存在");
				return rm;
			}
			
			//验证选中的作业计划对应的分条主实绩存在，且为未交工状态
			MesCrSlittingM mcsm=new MesCrSlittingM();
			mcsm.setMachine_code(pps.getMachine_code());
			mcsm.setSchedule_no(pps.getLw_plan_no());
			mcsm.setMaterial_no_vt(pps.getObject_no_vt());
			mcsm.setMaterial_no(pps.getMaterial_no());
			List<MesCrSlittingM> lmcsm=this.getMapper(MesCrSlittingMMapper.class).find(mcsm, 0, 0);
			
			if(lmcsm==null||lmcsm.size()==0){
				rm.setState("500");
				rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条主实绩不存在！");
				return rm;
			}
			if(!"0".equals(lmcsm.get(0).getHand_over_status())
					&&lmcsm.get(0).getHand_over_status()!=null){
				rm.setState("500");
				rm.setMsgInfo("["+mcsm.getMaterial_no()+"]分条已生产交工！");
				return rm;
			}
					
			//修改分条实绩主记录
			msm.setProcess_no(lmcsm.get(0).getProcess_no());
			msm.setUpdate_opr(username);
			msm.setUpdate_time(now);
			//部分卷吊销
			if("1".equals(msm.getPartial_rejected()) &&(msm.getRejected_coil_no()==null ||"".equals(msm.getRejected_coil_no()))){
				//***************************后续根据机台编号，查询ComBaseMachine表得到机器号左补零1为(F后2位)*******
				//验证机台基础信息存在
				int v_cnt = this.getMapper(ComBaseMachineMapper.class).countWithCondition(null,"machine_code='"+pps.getMachine_code()+"'");
				if(v_cnt<=0){
					throw new Exception("机台代码{"+pps.getMachine_code()+"} 机台基础信息不存在！");
				}
				//获取机台基础信息表中，配置的机台设备代号（设备编号，如1,2,3）
				List<ComBaseMachine> lcbm = this.getMapper(ComBaseMachineMapper.class).findWithCondition(null,
						"machine_code='"+pps.getMachine_code()+"'", null, 0, 0);
				String v_machine_mark=lcbm.get(0).getMachine_mark();
				if(v_machine_mark==null){
					throw new Exception("机台代码{"+pps.getMachine_code()+"} 设备编号未配置，无法创建作业记录号！");
				}
				String sNo=msm.getMaterial_no().substring(0,8)+"F"+lpad(v_machine_mark,2,"0")+"R_";
				
				List<MesCrSlittingM> lcount=this.getMapper(MesCrSlittingMMapper.class).findWithCondition(null, " rejected_coil_no like '"+sNo+"'", "", 0, 0);
				icount=0;
				if(lcount==null||lcount.size()==0){
					icount=1;
				}else{
					if(lcount.size()>=9){
						rm.setState("500");
						rm.setMsgInfo("投料卷号["+lmcsm.get(0).getMaterial_no()+"]：\n 吊销卷卷数超出规则范围");
						return rm;
					}
					ArrayList<Integer> ai=new ArrayList<Integer>();
					for(int i=0;i<lcount.size();i++){
						ai.set(i, Integer.parseInt(lcount.get(i).getRejected_coil_no().substring(lcount.get(i).getRejected_coil_no().length()-1,lcount.get(i).getRejected_coil_no().length())));
					}
					for(int i=1;i<=9;i++){
						if(!ai.contains(i)){
							icount=i;
							break;
						}
					}
				}
				//根据机器编号查询机器信息
				ComBaseMachine cbm=this.getBean(ComBaseMachineServiceImpl.class).doGetMark(pps.getMachine_code());
				if(cbm==null||cbm.getMachine_mark()==null){
					rm.setState("500");
					rm.setMsgInfo("机台代号获取失败！");
					return rm;
				}
				
				msm.setRejected_coil_no(msm.getMaterial_no().substring(0,8)+"F"+cbm.getMachine_mark()+"R"+icount);
			}
			
			if("0".equals(msm.getPartial_rejected())){
				msm.setRejected_coil_act_wgt(null);
				msm.setRejected_coil_len(null);
				msm.setRejected_coil_no(null);
				msm.setRejected_coil_out_dia(null);
				msm.setRejected_coil_thr_wgt(null);
			}
			//2018-12-11对大纵剪边丝的处理
			double mdcoil_sumwgt=0;//除边丝以外的子卷磅重之和
			
			if(msm.getWire_wdt()!=null && lmcsm.get(0).getMtr_len()!=null){
				List<MesCrSlittingD> md_list = this.getMapper(MesCrSlittingDMapper.class).findWithCondition(null, "process_no='"+lmcsm.get(0).getProcess_no()+"'", null, 0, 0);
				if(md_list!=null && md_list.size()>0){
					for(MesCrSlittingD mcsd:md_list){
						if (mcsd.getCoil_no() !=null && "B".equals(mcsd.getCoil_no().substring(mcsd.getCoil_no().length()-1))) {
								continue;
						}
						if(mcsd.getCoil_act_wgt() == null){
							mdcoil_sumwgt=0;
							break;
						}
						mdcoil_sumwgt+= mcsd.getCoil_act_wgt() == null ? 0 : mcsd.getCoil_act_wgt();
					}
				}
				if(mdcoil_sumwgt>0){
					//边丝磅重                   主表的mtr_thr_wgt等于mtr_act_wgt
					msm.setWire_act_wgt(DoubleUtil.round((lmcsm.get(0).getMtr_thr_wgt()==null?0:lmcsm.get(0).getMtr_thr_wgt())-mdcoil_sumwgt, 0));
					if(msm.getWire_act_wgt()<0){
						msm.setWire_act_wgt(0d);
					}
				}
				//计算边丝理重
				double dtemp=0;
				double wire_thr_wgt=0;
				if(lmcsm.get(0).getMtr_thk()!=null && lmcsm.get(0).getMtr_len()!=null){
					dtemp=7.85*(lmcsm.get(0).getMtr_thk())*(msm.getWire_wdt()/1000)*(lmcsm.get(0).getMtr_len()/1000);
				}
				if(dtemp>0){
					wire_thr_wgt=DoubleUtil.round(dtemp, 0);
				}
				if(wire_thr_wgt>0){
					msm.setWire_thr_wgt(wire_thr_wgt);
				}
			}
			this.getMapper(MesCrSlittingMMapper.class).doUpdate_12mm(msm);
			//同步子卷实绩的作业日期，班次，班组。
			if(StringUtils.isNotEmpty(msm.getWrk_date()) && 
					StringUtils.isNotEmpty(msm.getWrk_ord()) && StringUtils.isNotEmpty(msm.getWrk_grp())){
				this.getMapper(MesCrSlittingDMapper.class).doUpdateWrk(lmcsm.get(0).getProcess_no(),msm.getWrk_date(),msm.getWrk_ord(),msm.getWrk_grp());
			}
			//日志
			MesOprLog mol = new MesOprLog("车间MES", "12mm分条机作业管理", "保存", username, opr_time, msm.getMaterial_no(), null, null, null, "投料卷号："+msm.getMaterial_no());
			this.getMapper(MesOprLogMapper.class).insert(mol);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("服务端异常:"+ex.getMessage());
			throw new Exception("服务端异常:"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 分条产量报表
	 * 根据班次统计报表
	 * */
	public ResultModel doProductionWrkReportWeb(CommonPage<MesCrSlittingM> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesCrSlittingMMapper.class).doProductionWrkReport3(oci.getObject()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 分条产量报表   导出Excel
	 * 根据班次统计报表
	 * */
	@SuppressWarnings("rawtypes")
	public ResultModel doProductionWrkReportWeb_Excel(CommonPage<MesCrSlittingM> oci){
		ResultModel rm=new ResultModel();
		try{
			if(oci==null || "".equals(oci.getObject().getWrk_date())){
				rm.setState("500");
				rm.setMsgInfo("请输入参数!");
				return rm;
			}
			List<HashMap> lhap = this.getMapper(MesCrSlittingMMapper.class).doProductionWrkReport3(oci.getObject());
			// 1，创建一个webbook，对应一个Excel文件
			//WritableWorkbook workbook;
			// 2,设置用户下载路径
			String path = this.getRequest().getServletContext().getRealPath("/")+ "excel" + File.separator;  //临时保存路径
			File dir = new File(path);
			if(!dir.exists()) {
				new File(path).mkdir();
			}
			generateExcelProduWrk3(rm, lhap, path,oci.getObject().getWrk_date(),oci.getObject().getMachine_code());
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("导出失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 分条产量报表   导出Excel
	 * @param rm
	 * @param lhap
	 * @param path
	 * @param wrk_date 
	 * @throws Exception 
	 */
	@SuppressWarnings("rawtypes")
	private void generateExcelProduWrk3(ResultModel rm, List<HashMap> lhap, String path, String wrk_date,String machine_code) throws Exception {
		String machine_name="";
		if("M0001".equals(machine_code)){
			machine_name="4mm";
		}else if("M0002".equals(machine_code)){
			machine_name="12mm";
		}
		String curDate = DateUtil.formatDate(new Date(), "yyMMdd");
		String str=wrk_date.substring(0, 4)+"年"+wrk_date.substring(5, 7)+"月";
		String filename = str +machine_name+ "分条产量报表_"+curDate;
    	WritableWorkbook workbook;
    	String file=filename+".xls";  //文件名
    	//3. 操作EXCEL文件
    	workbook = Workbook.createWorkbook(new File(path+file));
    	WritableSheet sheet = workbook.createSheet(str +machine_name+"分条产量报表", 1);
    	//行高
    	sheet.getSettings().setDefaultRowHeight(300);
		//字体  参数可自行配置
		WritableFont font1 = new WritableFont(WritableFont.ARIAL,11,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE);  
		WritableCellFormat cellFormat1 = new WritableCellFormat(font1); 
		cellFormat1.setAlignment(Alignment.CENTRE);
		cellFormat1.setVerticalAlignment(VerticalAlignment.CENTRE);
		//表头
		/*
		 * //sheet.mergeCells(int m,int n,int p,int q);
           //作用是从(m,n)到(p,q)的单元格全部合并[我的理解：m列、n行和p列、q行合并]
          sheet.addCell(new Label(i, 0, tittles[i],wcf));//i列，1行，title内容，wcf样式
		 */
		sheet.mergeCells(0, 0, 0, 2);//设置第一列、第一行和 第一列、第三行合并
		sheet.addCell(new Label(0,0,"日期",cellFormat1));
		
		sheet.mergeCells(1, 0, 6, 0);
		sheet.addCell(new Label(1,0,"常白班",cellFormat1));
		sheet.mergeCells(1,1,3,1);
		sheet.addCell(new Label(1,1,"当日",cellFormat1));
		sheet.mergeCells(4,1,6,1);
		sheet.addCell(new Label(4,1,"月累",cellFormat1));
		
		sheet.addCell(new Label(1,2,"投入",cellFormat1));
		sheet.addCell(new Label(2,2,"产出",cellFormat1));
		sheet.addCell(new Label(3,2,"成材率(%)",cellFormat1));
		sheet.addCell(new Label(4,2,"投入",cellFormat1));
		sheet.addCell(new Label(5,2,"产出",cellFormat1));
		sheet.addCell(new Label(6,2,"成材率(%)",cellFormat1));
		
		sheet.mergeCells(7, 0, 12, 0);
		sheet.addCell(new Label(7,0,"甲班",cellFormat1));
		sheet.mergeCells(7,1,9,1);
		sheet.addCell(new Label(7,1,"当日",cellFormat1));
		sheet.mergeCells(10,1,12,1);
		sheet.addCell(new Label(10,1,"月累",cellFormat1));
		
		sheet.addCell(new Label(7,2,"投入",cellFormat1));
		sheet.addCell(new Label(8,2,"产出",cellFormat1));
		sheet.addCell(new Label(9,2,"成材率(%)",cellFormat1));
		sheet.addCell(new Label(10,2,"投入",cellFormat1));
		sheet.addCell(new Label(11,2,"产出",cellFormat1));
		sheet.addCell(new Label(12,2,"成材率(%)",cellFormat1));
		
		
		sheet.mergeCells(13, 0, 18, 0);
		sheet.addCell(new Label(13,0,"乙班",cellFormat1));
		sheet.mergeCells(13,1,15,1);
		sheet.addCell(new Label(13,1,"当日",cellFormat1));
		sheet.mergeCells(16,1,18,1);
		sheet.addCell(new Label(16,1,"月累",cellFormat1));
		
		sheet.addCell(new Label(13,2,"投入",cellFormat1));
		sheet.addCell(new Label(14,2,"产出",cellFormat1));
		sheet.addCell(new Label(15,2,"成材率(%)",cellFormat1));
		sheet.addCell(new Label(16,2,"投入",cellFormat1));
		sheet.addCell(new Label(17,2,"产出",cellFormat1));
		sheet.addCell(new Label(18,2,"成材率(%)",cellFormat1));
		
		sheet.mergeCells(19, 0, 24, 0);
		sheet.addCell(new Label(19,0,"丙班",cellFormat1));
		sheet.mergeCells(19,1,21,1);
		sheet.addCell(new Label(19,1,"当日",cellFormat1));
		sheet.mergeCells(22,1,24,1);
		sheet.addCell(new Label(22,1,"月累",cellFormat1));
		
		sheet.addCell(new Label(19,2,"投入",cellFormat1));
		sheet.addCell(new Label(20,2,"产出",cellFormat1));
		sheet.addCell(new Label(21,2,"成材率(%)",cellFormat1));
		sheet.addCell(new Label(22,2,"投入",cellFormat1));
		sheet.addCell(new Label(23,2,"产出",cellFormat1));
		sheet.addCell(new Label(24,2,"成材率(%)",cellFormat1));
		
		sheet.mergeCells(25, 0, 30, 0);
		sheet.addCell(new Label(25,0,"丁班",cellFormat1));
		sheet.mergeCells(25,1,27,1);
		sheet.addCell(new Label(25,1,"当日",cellFormat1));
		sheet.mergeCells(28,1,30,1);
		sheet.addCell(new Label(28,1,"月累",cellFormat1));
		
		sheet.addCell(new Label(25,2,"投入",cellFormat1));
		sheet.addCell(new Label(26,2,"产出",cellFormat1));
		sheet.addCell(new Label(27,2,"成材率(%)",cellFormat1));
		sheet.addCell(new Label(28,2,"投入",cellFormat1));
		sheet.addCell(new Label(29,2,"产出",cellFormat1));
		sheet.addCell(new Label(30,2,"成材率(%)",cellFormat1));
						
		sheet.mergeCells(31, 0, 39, 0);
		sheet.addCell(new Label(31,0,"合计",cellFormat1));
		sheet.mergeCells(31,1,33,1);
		sheet.addCell(new Label(31,1,"当日",cellFormat1));
		sheet.mergeCells(34,1,36,1);
		sheet.addCell(new Label(34,1,"月累",cellFormat1));
		sheet.mergeCells(37,1,39,1);
		sheet.addCell(new Label(37,1,"年累",cellFormat1));		
		
		sheet.addCell(new Label(31,2,"投入",cellFormat1));
		sheet.addCell(new Label(32,2,"产出",cellFormat1));
		sheet.addCell(new Label(33,2,"成材率(%)",cellFormat1));
		sheet.addCell(new Label(34,2,"投入",cellFormat1));
		sheet.addCell(new Label(35,2,"产出",cellFormat1));
		sheet.addCell(new Label(36,2,"成材率(%)",cellFormat1));
		sheet.addCell(new Label(37,2,"投入",cellFormat1));
		sheet.addCell(new Label(38,2,"产出",cellFormat1));
		sheet.addCell(new Label(39,2,"成材率(%)",cellFormat1));
				
		WritableFont font = new WritableFont(WritableFont.ARIAL,11,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE);  
		WritableCellFormat cellFormat = new WritableCellFormat(font); 
		cellFormat.setAlignment(Alignment.CENTRE);
		cellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
		int i=1;
		for(HashMap hm:lhap){
			//日期
			if(hm.get("WRK_DATE_2")!=null){
				sheet.addCell(new Label(0,i+2,""+hm.get("WRK_DATE_2"),cellFormat));
			}
			//常白班 -当日-投入
			if(hm.get("DAILY_0_IN")!=null){
				sheet.addCell(new Label(1,i+2,""+hm.get("DAILY_0_IN"),cellFormat));
			}
			//常白班 -当日-产出
			if(hm.get("DAILY_0")!=null){
				sheet.addCell(new Label(2,i+2,""+hm.get("DAILY_0"),cellFormat));
			}
			if(hm.get("RATE_DAILY_0")!=null){
				sheet.addCell(new Label(3,i+2,""+hm.get("RATE_DAILY_0"),cellFormat));
			}
			//常白班 -月累-投入
			if(hm.get("MONTH_0_IN")!=null){
				sheet.addCell(new Label(4,i+2,""+hm.get("MONTH_0_IN"),cellFormat));
			}
			//常白班 -月累-产出
			if(hm.get("MONTH_0")!=null){
				sheet.addCell(new Label(5,i+2,""+hm.get("MONTH_0"),cellFormat));
			}
			if(hm.get("RATE_MONTH_0")!=null){
				sheet.addCell(new Label(6,i+2,""+hm.get("RATE_MONTH_0"),cellFormat));
			}
			//甲班 -当日-投入
			if(hm.get("DAILY_1_IN")!=null){
				sheet.addCell(new Label(7,i+2,""+hm.get("DAILY_1_IN"),cellFormat));
			}
			//甲班 -当日-产出
			if(hm.get("DAILY_1")!=null){
				sheet.addCell(new Label(8,i+2,""+hm.get("DAILY_1"),cellFormat));
			}
			if(hm.get("RATE_DAILY_1")!=null){
				sheet.addCell(new Label(9,i+2,""+hm.get("RATE_DAILY_1"),cellFormat));
			}
			//甲班 -月累-投入
			if(hm.get("MONTH_1_IN")!=null){
				sheet.addCell(new Label(10,i+2,""+hm.get("MONTH_1_IN"),cellFormat));
			}
			//甲班 -月累-产出
			if(hm.get("MONTH_1")!=null){
				sheet.addCell(new Label(11,i+2,""+hm.get("MONTH_1"),cellFormat));
			}
			if(hm.get("RATE_MONTH_1")!=null){
				sheet.addCell(new Label(12,i+2,""+hm.get("RATE_MONTH_1"),cellFormat));
			}
						
			//乙班 -当日-投入
			if(hm.get("DAILY_2_IN")!=null){
				sheet.addCell(new Label(13,i+2,""+hm.get("DAILY_2_IN"),cellFormat));
			}
			//乙班 -当日-产出
			if(hm.get("DAILY_2")!=null){
				sheet.addCell(new Label(14,i+2,""+hm.get("DAILY_2"),cellFormat));
			}
			if(hm.get("RATE_DAILY_2")!=null){
				sheet.addCell(new Label(15,i+2,""+hm.get("RATE_DAILY_2"),cellFormat));
			}
			//乙班 -月累-投入
			if(hm.get("MONTH_2_IN")!=null){
				sheet.addCell(new Label(16,i+2,""+hm.get("MONTH_2_IN"),cellFormat));
			}
			//乙班 -月累-产出
			if(hm.get("MONTH_2")!=null){
				sheet.addCell(new Label(17,i+2,""+hm.get("MONTH_2"),cellFormat));
			}
			if(hm.get("RATE_MONTH_2")!=null){
				sheet.addCell(new Label(18,i+2,""+hm.get("RATE_MONTH_2"),cellFormat));
			}
			
			//丙班 -当日-投入
			if(hm.get("DAILY_3_IN")!=null){
				sheet.addCell(new Label(19,i+2,""+hm.get("DAILY_3_IN"),cellFormat));
			}
			//丙班 -当日-产出
			if(hm.get("DAILY_3")!=null){
				sheet.addCell(new Label(20,i+2,""+hm.get("DAILY_3"),cellFormat));
			}
			if(hm.get("RATE_DAILY_3")!=null){
				sheet.addCell(new Label(21,i+2,""+hm.get("RATE_DAILY_3"),cellFormat));
			}
			
			//丙班-月累-投入
			if(hm.get("MONTH_3_IN")!=null){
				sheet.addCell(new Label(22,i+2,""+hm.get("MONTH_3_IN"),cellFormat));
			}
			//丙班-月累-产出
			if(hm.get("MONTH_3")!=null){
				sheet.addCell(new Label(23,i+2,""+hm.get("MONTH_3"),cellFormat));
			}
			if(hm.get("RATE_MONTH_3")!=null){
				sheet.addCell(new Label(24,i+2,""+hm.get("RATE_MONTH_3"),cellFormat));
			}
			
			//丁班 -当日-投入
			if(hm.get("DAILY_4_IN")!=null){
				sheet.addCell(new Label(25,i+2,""+hm.get("DAILY_4_IN"),cellFormat));
			}
			//丁班 -当日-产出
			if(hm.get("DAILY_4")!=null){
				sheet.addCell(new Label(26,i+2,""+hm.get("DAILY_4"),cellFormat));
			}
			if(hm.get("RATE_DAILY_4")!=null){
				sheet.addCell(new Label(27,i+2,""+hm.get("RATE_DAILY_4"),cellFormat));
			}			
			
			//丁班 -月累-投入
			if(hm.get("MONTH_4_IN")!=null){
				sheet.addCell(new Label(28,i+2,""+hm.get("MONTH_4_IN"),cellFormat));
			}
			//丁班 -月累-产出
			if(hm.get("MONTH_4")!=null){
				sheet.addCell(new Label(29,i+2,""+hm.get("MONTH_4"),cellFormat));
			}
			if(hm.get("RATE_MONTH_4")!=null){
				sheet.addCell(new Label(30,i+2,""+hm.get("RATE_MONTH_4"),cellFormat));
			}
			
			//合计-当日-投入
			if(hm.get("DAILY_ALL_IN")!=null){
				sheet.addCell(new Label(31,i+2,""+hm.get("DAILY_ALL_IN"),cellFormat));
			}
			//合计-当日-产出
			if(hm.get("DAILY_ALL")!=null){
				sheet.addCell(new Label(32,i+2,""+hm.get("DAILY_ALL"),cellFormat));
			}
			if(hm.get("RATE_DAILY_ALL")!=null){
				sheet.addCell(new Label(33,i+2,""+hm.get("RATE_DAILY_ALL"),cellFormat));
			}
			
			//合计-月累-投入
			if(hm.get("MONTH_ALL_IN")!=null){
				sheet.addCell(new Label(34,i+2,""+hm.get("MONTH_ALL_IN"),cellFormat));
			}
			//合计-月累-产出
			if(hm.get("MONTH_ALL")!=null){
				sheet.addCell(new Label(35,i+2,""+hm.get("MONTH_ALL"),cellFormat));
			}
			if(hm.get("RATE_MONTH_ALL")!=null){
				sheet.addCell(new Label(36,i+2,""+hm.get("RATE_MONTH_ALL"),cellFormat));
			}
			
			//合计-年累-投入
			if(hm.get("YEAR_ALL_IN")!=null){
				sheet.addCell(new Label(37,i+2,""+hm.get("YEAR_ALL_IN"),cellFormat));
			}
			//合计-年累-产出
			if(hm.get("YEAR_ALL")!=null){
				sheet.addCell(new Label(38,i+2,""+hm.get("YEAR_ALL"),cellFormat));
			}
			if(hm.get("RATE_YEAR_ALL")!=null){
				sheet.addCell(new Label(39,i+2,""+hm.get("RATE_YEAR_ALL"),cellFormat));
			}
			i++;
		}
		sheet.getSettings().setVerticalFreeze(1);  		//首行冻结
		sheet.getSettings().setVerticalFreeze(2);
		sheet.getSettings().setVerticalFreeze(3);
		//关闭
		workbook.write();
		workbook.close();
		rm.setData("/download?filename="+file);
	}
	
	/**
	 * 各牌号分条产量报表
	 * */
	public ResultModel doProductionSteelReportWeb(CommonPage<MesCrSlittingM> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesCrSlittingMMapper.class).doProductionSteelReport3(oci.getObject()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 各牌号分条产量报表    导出Excel
	 * */
	@SuppressWarnings("rawtypes")
	public ResultModel doProductionSteelReportWeb_Excel(CommonPage<MesCrSlittingM> oci){
		ResultModel rm=new ResultModel();
		try{
			if(oci==null || "".equals(oci.getObject().getWrk_date())){
				rm.setState("500");
				rm.setMsgInfo("请输入参数!");
				return rm;
			}
			List<HashMap> lhap = this.getMapper(MesCrSlittingMMapper.class).doProductionSteelReport3(oci.getObject());
			// 2,设置用户下载路径
			String path = this.getRequest().getServletContext().getRealPath("/")+ "excel" + File.separator;  //临时保存路径
			File dir = new File(path);
			if(!dir.exists()) {
				new File(path).mkdir();
			}
			generateExcelProduSteel3(rm, lhap, path,oci.getObject().getWrk_date(),oci.getObject().getMachine_code());
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("导出失败!"+ex.getMessage());
		}
		return rm;
	}
	
	@SuppressWarnings("rawtypes")
	private void generateExcelProduSteel3(ResultModel rm, List<HashMap> lhap, String path, String wrk_date,String machine_code) throws Exception {
		//数据处理===============================
		//存储各牌号
		List<String> lstr=new ArrayList<>();
		//获取日期，各牌号日，月，年累集合
		Map<String,List<MesSteelCodeTemp>> maptp=new HashMap<String,List<MesSteelCodeTemp>>();
		List<MesSteelCodeTemp> lmsct=new ArrayList<>();
		for(HashMap hm:lhap){
			MesSteelCodeTemp msct=new MesSteelCodeTemp();
			if(!lstr.contains((""+hm.get("STEEL_CODE")))){
				lstr.add(""+hm.get("STEEL_CODE"));
			}
			msct.setSteel_code(""+hm.get("STEEL_CODE"));
			msct.setWrk_date(""+hm.get("WRK_DATE"));
			msct.setStl_daily(""+hm.get("STL_DAILY"));
			msct.setStl_month(""+hm.get("STL_MONTH"));
			msct.setStl_year(""+hm.get("STL_YEAR"));
			msct.setStl_daily_in(""+hm.get("STL_DAILY_IN"));
			msct.setStl_month_in(""+hm.get("STL_MONTH_IN"));
			msct.setStl_year_in(""+hm.get("STL_YEAR_IN"));
			msct.setRate_daily(""+hm.get("RATE_DAILY"));
			msct.setRate_month(""+hm.get("RATE_MONTH"));
			msct.setRate_year(""+hm.get("RATE_YEAR"));
			lmsct.add(msct);
		}
		if(lstr.size()<=0){
			rm.setMsgInfo("无对应的牌号");
			return ;
		}
		//对List集合中对象元素中的wrk_date分组  重要
		for(MesSteelCodeTemp tmExcpNew : lmsct){
			if(maptp.containsKey(tmExcpNew.getWrk_date())){//map中异常批次已存在，将该数据存放到同一个key（key存放的是异常批次）的map中
				maptp.get(tmExcpNew.getWrk_date()).add(tmExcpNew);
			}else{//map中不存在，新建key，用来存放数据
				List<MesSteelCodeTemp> tmpList = new ArrayList<MesSteelCodeTemp>();
				tmpList.add(tmExcpNew);
				maptp.put(tmExcpNew.getWrk_date(), tmpList);
			}
		}
		//====================================
		String machine_name="";
		if("M0001".equals(machine_code)){
			machine_name="4mm";
		}else if("M0002".equals(machine_code)){
			machine_name="12mm";
		}
		String curDate = DateUtil.formatDate(new Date(), "yyMMdd");
		String str=wrk_date.substring(0, 4)+"年"+wrk_date.substring(5, 7)+"月";
		String filename = str + machine_name+"各牌号分条产量报表_"+curDate;
    	WritableWorkbook workbook;
    	String file=filename+".xls";  //文件名
    	//3. 操作EXCEL文件
    	workbook = Workbook.createWorkbook(new File(path+file));
    	WritableSheet sheet = workbook.createSheet(machine_name+"各牌号分条产量报表", 1);
    	//行高
    	sheet.getSettings().setDefaultRowHeight(300);
		//字体  参数可自行配置
		WritableFont font1 = new WritableFont(WritableFont.ARIAL,11,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE);  
		WritableCellFormat cellFormat1 = new WritableCellFormat(font1); 
		cellFormat1.setAlignment(Alignment.CENTRE);
		cellFormat1.setVerticalAlignment(VerticalAlignment.CENTRE);
		
		//表头
		/*
		 * //sheet.mergeCells(int m,int n,int p,int q);
           //作用是从(m,n)到(p,q)的单元格全部合并[我的理解：m列、n行和p列、q行合并]
          sheet.addCell(new Label(i, 0, tittles[i],wcf));//i列，1行，title内容，wcf样式
		 */
		sheet.mergeCells(0, 0, 0, 2);//设置第一列、第一行和 第一列、第三行合并
		sheet.addCell(new Label(0,0,"日期",cellFormat1));
		//各牌号对应的月累，年累。
		Map<String,MesSteelCodeTemp> mapSteelC=new HashMap<>();
		int i=1;
		for(String steel_code:lstr){
			MesSteelCodeTemp ms=new MesSteelCodeTemp();
			sheet.mergeCells(i, 0, i+8, 0);
			sheet.addCell(new Label(i,0,steel_code,cellFormat1));
			sheet.mergeCells(i, 1, i+2, 0);
			sheet.addCell(new Label(i,1,"当日",cellFormat1));
			sheet.mergeCells(i+3, 1, i+5, 0);
			sheet.addCell(new Label(i+3,1,"月累",cellFormat1));
			sheet.mergeCells(i+6, 1, i+8, 0);
			sheet.addCell(new Label(i+6,1,"年累",cellFormat1));
			sheet.addCell(new Label(i,2,"投入",cellFormat1));
			sheet.addCell(new Label(i+1,2,"产出",cellFormat1));
			sheet.addCell(new Label(i+2,2,"成材率(%)",cellFormat1));
			sheet.addCell(new Label(i+3,2,"投入",cellFormat1));
			sheet.addCell(new Label(i+4,2,"产出",cellFormat1));
			sheet.addCell(new Label(i+5,2,"成材率(%)",cellFormat1));
			sheet.addCell(new Label(i+6,2,"投入",cellFormat1));
			sheet.addCell(new Label(i+7,2,"产出",cellFormat1));
			sheet.addCell(new Label(i+8,2,"成材率(%)",cellFormat1));
			i=i+9;
			mapSteelC.put(steel_code, ms);
		}
		
		sheet.mergeCells(i, 0, i+8, 0);
		sheet.addCell(new Label(i,0,"合计",cellFormat1));
		sheet.mergeCells(i, 1, i+2, 0);
		sheet.addCell(new Label(i,1,"当日",cellFormat1));
		sheet.mergeCells(i+3, 1, i+5, 0);
		sheet.addCell(new Label(i+3,1,"月累",cellFormat1));
		sheet.mergeCells(i+6, 1, i+8, 0);
		sheet.addCell(new Label(i+6,1,"年累",cellFormat1));
		sheet.addCell(new Label(i,2,"投入",cellFormat1));
		sheet.addCell(new Label(i+1,2,"产出",cellFormat1));
		sheet.addCell(new Label(i+2,2,"成材率(%)",cellFormat1));
		sheet.addCell(new Label(i+3,2,"投入",cellFormat1));
		sheet.addCell(new Label(i+4,2,"产出",cellFormat1));
		sheet.addCell(new Label(i+5,2,"成材率(%)",cellFormat1));
		sheet.addCell(new Label(i+6,2,"投入",cellFormat1));
		sheet.addCell(new Label(i+7,2,"产出",cellFormat1));
		sheet.addCell(new Label(i+8,2,"成材率(%)",cellFormat1));
		
		
		WritableFont font = new WritableFont(WritableFont.ARIAL,11,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE);  
		WritableCellFormat cellFormat = new WritableCellFormat(font); 
		cellFormat.setAlignment(Alignment.CENTRE);
		cellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
		
		//合计对应的月累，年累。
		Map<String,MesSteelCodeTemp> mapSteelC_Total=new HashMap<>();
		MesSteelCodeTemp mt2=new MesSteelCodeTemp();
		mapSteelC_Total.put("total_mes", mt2);
		double all_day=0;
		double all_month=0;
		double all_year=0;
		double all_day_in=0;
		double all_month_in=0;
		double all_year_in=0;
		//wrk_date的天数
		int monthLastDay = DateUtil.getMonthLastDay(Integer.parseInt(wrk_date.substring(0, 4)), Integer.parseInt(wrk_date.substring(5, 7)));
		//2018-06-形式
		String wrkdate_temp=wrk_date+"-";
		int j=1;
		for(int day=1;day<=monthLastDay;day++){
			all_day=0;
			all_month=0;
			all_year=0;
			all_day_in=0;
			all_month_in=0;
			all_year_in=0;
			//日期
			sheet.addCell(new Label(0,j+2,String.format("%02d", day)+"日",cellFormat));
			i=1;
			
			if(maptp.containsKey(wrkdate_temp+String.format("%02d", day))){
				List<MesSteelCodeTemp> list = maptp.get(wrkdate_temp+String.format("%02d", day));
				
				for(String steel_code:lstr){
					MesSteelCodeTemp mt=new MesSteelCodeTemp();
					mt.setSteel_code(steel_code);
					if(list.contains(mt)){
						mt = list.get(list.indexOf(mt));
						//sheet.mergeCells(i, j+2, i+2, 0);
						//sheet.addCell(new Label(i,j+2,steel_code,cellFormat1));
						sheet.addCell(new Label(i,j+2,"0.0".equals(mt.getStl_daily_in())?"0":mt.getStl_daily_in(),cellFormat));
						sheet.addCell(new Label(i+1,j+2,"0.0".equals(mt.getStl_daily())?"0":mt.getStl_daily(),cellFormat));
						sheet.addCell(new Label(i+2,j+2,"0.0".equals(mt.getRate_daily())?"0":mt.getRate_daily(),cellFormat));
						sheet.addCell(new Label(i+3,j+2,"0.0".equals(mt.getStl_month_in())?"0":mt.getStl_month_in(),cellFormat));
						sheet.addCell(new Label(i+4,j+2,"0.0".equals(mt.getStl_month())?"0":mt.getStl_month(),cellFormat));
						sheet.addCell(new Label(i+5,j+2,"0.0".equals(mt.getRate_month())?"0":mt.getRate_month(),cellFormat));
						sheet.addCell(new Label(i+6,j+2,"0.0".equals(mt.getStl_year_in())?"0":mt.getStl_year_in(),cellFormat));
						sheet.addCell(new Label(i+7,j+2,"0.0".equals(mt.getStl_year())?"0":mt.getStl_year(),cellFormat));
						sheet.addCell(new Label(i+8,j+2,"0.0".equals(mt.getRate_year())?"0":mt.getRate_year(),cellFormat));
						
						all_day=DoubleUtil.add(all_day, Double.parseDouble(mt.getStl_daily()));
						all_day_in=DoubleUtil.add(all_day_in, Double.parseDouble(mt.getStl_daily_in()));
//						all_month=DoubleUtil.add(all_month, Double.parseDouble(mt.getStl_month()));
//						all_year=DoubleUtil.add(all_year, Double.parseDouble(mt.getStl_year()));
						mapSteelC.get(steel_code).setStl_month(mt.getStl_month());
						mapSteelC.get(steel_code).setStl_month_in(mt.getStl_month_in());
						mapSteelC.get(steel_code).setStl_year(mt.getStl_year());
						mapSteelC.get(steel_code).setStl_year_in(mt.getStl_year_in());
					}else{
						//sheet.mergeCells(i, j+2, i+2, 0);
						//sheet.addCell(new Label(i,j+2,steel_code,cellFormat1));
						sheet.addCell(new Label(i,j+2,"0",cellFormat));
						sheet.addCell(new Label(i+1,j+2,"0",cellFormat));
						sheet.addCell(new Label(i+2,j+2,"0",cellFormat));
//						sheet.addCell(new Label(i+1,j+2,"0",cellFormat));
//						sheet.addCell(new Label(i+2,j+2,"0",cellFormat));
						if(mapSteelC.get(steel_code).getStl_month()==null || "".equals(mapSteelC.get(steel_code).getStl_month())){
							sheet.addCell(new Label(i+4,j+2,"0",cellFormat));
						}else{
							sheet.addCell(new Label(i+4,j+2,mapSteelC.get(steel_code).getStl_month(),cellFormat));
						}
						if(mapSteelC.get(steel_code).getStl_year()==null || "".equals(mapSteelC.get(steel_code).getStl_year())){
							sheet.addCell(new Label(i+7,j+2,"0",cellFormat));
						}else{
							sheet.addCell(new Label(i+7,j+2,mapSteelC.get(steel_code).getStl_year(),cellFormat));
						}
						
						if(mapSteelC.get(steel_code).getStl_month_in()==null || "".equals(mapSteelC.get(steel_code).getStl_month_in())){
							sheet.addCell(new Label(i+3,j+2,"0",cellFormat));
							sheet.addCell(new Label(i+5,j+2,"0",cellFormat));
						}else{
							sheet.addCell(new Label(i+3,j+2,mapSteelC.get(steel_code).getStl_month_in(),cellFormat));
							Double stl_month_in=Double.parseDouble(mapSteelC.get(steel_code).getStl_month_in()+"");
							Double stl_month=Double.parseDouble(mapSteelC.get(steel_code).getStl_month()+"");
							if(stl_month_in==0){
								sheet.addCell(new Label(i+5,j+2,"0",cellFormat));
							}else{
								if("0.0".equals((""+DoubleUtil.round((stl_month/stl_month_in)*100, 2)))){
									sheet.addCell(new Label(i+5,j+2,"0",cellFormat));
								}else{
									sheet.addCell(new Label(i+5,j+2,""+DoubleUtil.round((stl_month/stl_month_in)*100, 2),cellFormat));
								}
							}
							
						}
						if(mapSteelC.get(steel_code).getStl_year_in()==null || "".equals(mapSteelC.get(steel_code).getStl_year_in())){
							sheet.addCell(new Label(i+6,j+2,"0",cellFormat));
							sheet.addCell(new Label(i+8,j+2,"0",cellFormat));
						}else{
							sheet.addCell(new Label(i+6,j+2,mapSteelC.get(steel_code).getStl_year_in(),cellFormat));
							Double stl_year_in=Double.parseDouble(mapSteelC.get(steel_code).getStl_year_in()+"");
							Double stl_year=Double.parseDouble(mapSteelC.get(steel_code).getStl_year()+"");
							if(stl_year_in==0){
								sheet.addCell(new Label(i+8,j+2,"0",cellFormat));
							}else{
								if("0.0".equals((""+DoubleUtil.round((stl_year/stl_year_in)*100, 2)))){
									sheet.addCell(new Label(i+8,j+2,"0",cellFormat));
								}else{
									sheet.addCell(new Label(i+8,j+2,""+DoubleUtil.round((stl_year/stl_year_in)*100, 2),cellFormat));
								}
							}
							
						}
						
					}
					i=i+9;
					if(mapSteelC.get(steel_code).getStl_month()!=null && !"".equals(mapSteelC.get(steel_code).getStl_month())){
						all_month=DoubleUtil.add(all_month, Double.parseDouble(mapSteelC.get(steel_code).getStl_month()));
					}
					if(mapSteelC.get(steel_code).getStl_year()!=null && !"".equals(mapSteelC.get(steel_code).getStl_year())){
						all_year=DoubleUtil.add(all_year, Double.parseDouble(mapSteelC.get(steel_code).getStl_year()));
					}
					if(mapSteelC.get(steel_code).getStl_month_in()!=null && !"".equals(mapSteelC.get(steel_code).getStl_month_in())){
						all_month_in=DoubleUtil.add(all_month_in, Double.parseDouble(mapSteelC.get(steel_code).getStl_month_in()));
					}
					if(mapSteelC.get(steel_code).getStl_year_in()!=null && !"".equals(mapSteelC.get(steel_code).getStl_year_in())){
						all_year_in=DoubleUtil.add(all_year_in, Double.parseDouble(mapSteelC.get(steel_code).getStl_year_in()));
					}
					
					
					mapSteelC_Total.get("total_mes").setStl_month(""+all_month);
					mapSteelC_Total.get("total_mes").setStl_year(""+all_year);
					
					mapSteelC_Total.get("total_mes").setStl_month_in(""+all_month_in);
					mapSteelC_Total.get("total_mes").setStl_year_in(""+all_year_in);
				}
			}else{
				for(String steel_code:lstr){
					//sheet.mergeCells(i, j+2, i+2, 0);
					//sheet.addCell(new Label(i,j+2,steel_code,cellFormat1));
					sheet.addCell(new Label(i,j+2,"0",cellFormat));
					sheet.addCell(new Label(i+1,j+2,"0",cellFormat));
					sheet.addCell(new Label(i+2,j+2,"0",cellFormat));
//					sheet.addCell(new Label(i+1,j+2,"0",cellFormat));
//					sheet.addCell(new Label(i+2,j+2,"0",cellFormat));
					if(mapSteelC.get(steel_code).getStl_month()==null || "".equals(mapSteelC.get(steel_code).getStl_month())){
						sheet.addCell(new Label(i+4,j+2,"0",cellFormat));
					}else{
						sheet.addCell(new Label(i+4,j+2,mapSteelC.get(steel_code).getStl_month(),cellFormat));
					}
					if(mapSteelC.get(steel_code).getStl_year()==null || "".equals(mapSteelC.get(steel_code).getStl_year())){
						sheet.addCell(new Label(i+7,j+2,"0",cellFormat));
					}else{
						sheet.addCell(new Label(i+7,j+2,mapSteelC.get(steel_code).getStl_year(),cellFormat));
					}
					
					if(mapSteelC.get(steel_code).getStl_month_in()==null || "".equals(mapSteelC.get(steel_code).getStl_month_in())){
						sheet.addCell(new Label(i+3,j+2,"0",cellFormat));
						sheet.addCell(new Label(i+5,j+2,"0",cellFormat));
					}else{
						sheet.addCell(new Label(i+3,j+2,mapSteelC.get(steel_code).getStl_month_in(),cellFormat));
						Double stl_month_in=Double.parseDouble(mapSteelC.get(steel_code).getStl_month_in()+"");
						Double stl_month=Double.parseDouble(mapSteelC.get(steel_code).getStl_month()+"");
						if(stl_month_in==0){
							sheet.addCell(new Label(i+5,j+2,"0",cellFormat));
						}else{
							if("0.0".equals((""+DoubleUtil.round((stl_month/stl_month_in)*100, 2)))){
								sheet.addCell(new Label(i+5,j+2,"0",cellFormat));
							}else{
								sheet.addCell(new Label(i+5,j+2,""+DoubleUtil.round((stl_month/stl_month_in)*100, 2),cellFormat));
							}
						}
					}
					if(mapSteelC.get(steel_code).getStl_year_in()==null || "".equals(mapSteelC.get(steel_code).getStl_year_in())){
						sheet.addCell(new Label(i+6,j+2,"0",cellFormat));
						sheet.addCell(new Label(i+8,j+2,"0",cellFormat));
					}else{
						sheet.addCell(new Label(i+6,j+2,mapSteelC.get(steel_code).getStl_year_in(),cellFormat));
						Double stl_year_in=Double.parseDouble(mapSteelC.get(steel_code).getStl_year_in()+"");
						Double stl_year=Double.parseDouble(mapSteelC.get(steel_code).getStl_year()+"");
						if(stl_year_in==0){
							sheet.addCell(new Label(i+8,j+2,"0",cellFormat));
						}else{
							if("0.0".equals((""+DoubleUtil.round((stl_year/stl_year_in)*100, 2)))){
								sheet.addCell(new Label(i+8,j+2,"0",cellFormat));
							}else{
								sheet.addCell(new Label(i+8,j+2,""+DoubleUtil.round((stl_year/stl_year_in)*100, 2),cellFormat));
							}
						}
					}
					
					i=i+9;
				}
			}
			//all_day==0?"0":all_day这种形式是为了防止在excel中显示0.0的情况
			
			sheet.addCell(new Label(i,j+2,""+(all_day_in==0?"0":all_day_in),cellFormat));
			sheet.addCell(new Label(i+1,j+2,""+(all_day==0?"0":all_day),cellFormat));
			//日成材率
			if(all_day_in==0){
				sheet.addCell(new Label(i+2,j+2,0+"",cellFormat));
			}else{
				//sheet.addCell(new Label(i+2,j+2,""+DoubleUtil.round((all_day/all_day_in)*100, 2),cellFormat));
				if("0.0".equals((""+DoubleUtil.round((all_day/all_day_in)*100, 2)))){
					sheet.addCell(new Label(i+2,j+2,0+"",cellFormat));
				}else{
					sheet.addCell(new Label(i+2,j+2,""+DoubleUtil.round((all_day/all_day_in)*100, 2),cellFormat));
				}
			}
			sheet.addCell(new Label(i+3,j+2,("0.0".equals(mapSteelC_Total.get("total_mes").getStl_month_in())?"0":mapSteelC_Total.get("total_mes").getStl_month_in()),cellFormat));
			sheet.addCell(new Label(i+4,j+2,("0.0".equals(mapSteelC_Total.get("total_mes").getStl_month())?"0":mapSteelC_Total.get("total_mes").getStl_month()),cellFormat));
			//月成材率
//			if(all_month_in==0){
//				sheet.addCell(new Label(i+5,j+2,0+"",cellFormat));
//			}else{
//				
//				sheet.addCell(new Label(i+5,j+2,""+DoubleUtil.round((all_month/all_month_in)*100, 2),cellFormat));
//			}
			if(mapSteelC_Total.get("total_mes").getStl_month_in()==null){
				mapSteelC_Total.get("total_mes").setStl_month_in("0");
			}
			if(mapSteelC_Total.get("total_mes").getStl_month()==null){
				mapSteelC_Total.get("total_mes").setStl_month("0");
			}
			Double stl_month_in=Double.parseDouble(mapSteelC_Total.get("total_mes").getStl_month_in()+"");
			Double stl_month=Double.parseDouble(mapSteelC_Total.get("total_mes").getStl_month()+"");
			if(stl_month_in==0){
				sheet.addCell(new Label(i+5,j+2,0+"",cellFormat));
			}else{
				//sheet.addCell(new Label(i+5,j+2,""+DoubleUtil.round((stl_month/stl_month_in)*100, 2),cellFormat));
				if("0.0".equals((""+DoubleUtil.round((stl_month/stl_month_in)*100, 2)))){
					sheet.addCell(new Label(i+5,j+2,0+"",cellFormat));
				}else{
					sheet.addCell(new Label(i+5,j+2,""+DoubleUtil.round((stl_month/stl_month_in)*100, 2),cellFormat));
				}
			}
			
			
			
			sheet.addCell(new Label(i+6,j+2,("0.0".equals(mapSteelC_Total.get("total_mes").getStl_year_in())?"0":mapSteelC_Total.get("total_mes").getStl_year_in()),cellFormat));
			sheet.addCell(new Label(i+7,j+2,("0.0".equals(mapSteelC_Total.get("total_mes").getStl_year())?"0":mapSteelC_Total.get("total_mes").getStl_year()),cellFormat));
			//年成材率
//			if(all_year_in==0){
//				sheet.addCell(new Label(i+8,j+2,0+"",cellFormat));
//			}else{
//				
//				sheet.addCell(new Label(i+8,j+2,""+DoubleUtil.round((all_year/all_year_in)*100, 2),cellFormat));
//			}
			if(mapSteelC_Total.get("total_mes").getStl_year_in()==null){
				mapSteelC_Total.get("total_mes").setStl_year_in("0");
			}
			if(mapSteelC_Total.get("total_mes").getStl_year_in()==null){
				mapSteelC_Total.get("total_mes").setStl_year("0");
			}
			Double stl_year_in=Double.parseDouble(mapSteelC_Total.get("total_mes").getStl_year_in()+"");
			Double stl_year=Double.parseDouble(mapSteelC_Total.get("total_mes").getStl_year()+"");
			if(stl_year_in==0){
				sheet.addCell(new Label(i+8,j+2,"0",cellFormat));
			}else{
				//sheet.addCell(new Label(i+8,j+2,""+DoubleUtil.round((stl_year/stl_year_in)*100, 2),cellFormat));
				if("0.0".equals((""+DoubleUtil.round((stl_year/stl_year_in)*100, 2)))){
					sheet.addCell(new Label(i+8,j+2,"0",cellFormat));
				}else{
					sheet.addCell(new Label(i+8,j+2,""+DoubleUtil.round((stl_year/stl_year_in)*100, 2),cellFormat));
				}
			}
			j++;
		}
		
		sheet.getSettings().setVerticalFreeze(1);  		//首行冻结
		sheet.getSettings().setVerticalFreeze(2);
		sheet.getSettings().setVerticalFreeze(3);
		//关闭
		workbook.write();
		workbook.close();
		rm.setData("/download?filename="+file);
	}

	/**
	 * 分条综合产量报表
	 * @param oci
	 * [{"object":{"wrk_date":"2018-03","machine_code":"M0001"}}]格式
	 * @return
	 */
	public ResultModel doProductionMultReportWeb(CommonPage<MesCrSlittingM> oci){
		ResultModel rm=new ResultModel();
		try {
			rm.setData(this.getMapper(MesCrSlittingMMapper.class).doProductionMultReport1(oci.getObject()));
			rm.setState("200");
		} catch (Exception ex) {
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 分条综合产量报表 导出Excel
	 * @param oci
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public ResultModel doProductionMultReportWeb_Excel(CommonPage<MesCrSlittingM> oci){
		ResultModel rm=new ResultModel();
		try{
			if(oci==null || "".equals(oci.getObject().getWrk_date())){
				rm.setState("500");
				rm.setMsgInfo("请输入参数!");
				return rm;
			}
			List<HashMap> lhap = this.getMapper(MesCrSlittingMMapper.class).doProductionMultReport1(oci.getObject());
			// 1，创建一个webbook，对应一个Excel文件
			// 2,设置用户下载路径
			String path = this.getRequest().getServletContext().getRealPath("/")+ "excel" + File.separator;  //临时保存路径
			File dir = new File(path);
			if(!dir.exists()) {
				new File(path).mkdir();
			}
			generateExcelProduMultReport(rm, lhap, path,oci.getObject().getWrk_date());
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("导出失败!"+ex.getMessage());
		}
		return rm;
	}

	@SuppressWarnings("rawtypes")
	private void generateExcelProduMultReport(ResultModel rm, List<HashMap> lhap, String path, String wrk_date) throws Exception{
		String curDate = DateUtil.formatDate(new Date(), "yyMMdd");
		String str=wrk_date.substring(0, 4)+"年"+wrk_date.substring(5, 7)+"月";
		String filename = str + "分条综合产量报表_"+curDate;
    	WritableWorkbook workbook;
    	String file=filename+".xls";  //文件名
    	//3. 操作EXCEL文件
    	workbook = Workbook.createWorkbook(new File(path+file));
    	WritableSheet sheet = workbook.createSheet(str + "分条综合产量报表", 1);
    	//行高
    	sheet.getSettings().setDefaultRowHeight(300);
		//字体  参数可自行配置
		WritableFont font1 = new WritableFont(WritableFont.ARIAL,11,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE);  
		WritableCellFormat cellFormat1 = new WritableCellFormat(font1); 
		cellFormat1.setAlignment(Alignment.CENTRE);
		cellFormat1.setVerticalAlignment(VerticalAlignment.CENTRE);
		//表头
		/*
		 * //sheet.mergeCells(int m,int n,int p,int q);
           //作用是从(m,n)到(p,q)的单元格全部合并[我的理解：m列、n行和p列、q行合并]
          sheet.addCell(new Label(i, 0, tittles[i],wcf));//i列，1行，title内容，wcf样式
		 */
		//sheet.mergeCells(0, 0, 0, 0);
		sheet.addCell(new Label(0,0,"日期",cellFormat1));
		
		//sheet.mergeCells(1, 0, 1, 1);
		sheet.addCell(new Label(1,0,"常白班",cellFormat1));
		
		//sheet.mergeCells(2, 0, 2, 1);
		sheet.addCell(new Label(2,0,"甲班",cellFormat1));
		
		//sheet.mergeCells(3, 0, 3, 1);
		sheet.addCell(new Label(3,0,"乙班",cellFormat1));
		
		//sheet.mergeCells(4, 0, 4, 1);
		sheet.addCell(new Label(4,0,"丙班",cellFormat1));
		
		//sheet.mergeCells(5, 0, 5, 1);
		sheet.addCell(new Label(5,0,"丁班",cellFormat1));
		
		WritableFont font = new WritableFont(WritableFont.ARIAL,11,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE);  
		WritableCellFormat cellFormat = new WritableCellFormat(font); 
		cellFormat.setAlignment(Alignment.CENTRE);
		cellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
		int i=-1;
		Double total_wgt_0=null;
		Double total_wgt_1=null;
		Double total_wgt_2=null;
		Double total_wgt_3=null;
		Double total_wgt_4=null;
		double wgt_0_count=0;
		double wgt_1_count=0;
		double wgt_2_count=0;
		double wgt_3_count=0;
		double wgt_4_count=0;
		for(HashMap hm:lhap){
			//日期
			if(hm.get("WRK_DATE")!=null){
				String date=hm.get("WRK_DATE").toString().substring(8, 10)+"日";
				sheet.addCell(new Label(0,i+2,date,cellFormat));
			}
			//常白班
			sheet.addCell(new Label(1,i+2,""+(hm.get("WGT_0")==null?"/":hm.get("WGT_0")),cellFormat));
			//甲班
			sheet.addCell(new Label(2,i+2,""+(hm.get("WGT_1")==null?"/":hm.get("WGT_1")),cellFormat));
			//乙班
			sheet.addCell(new Label(3,i+2,""+(hm.get("WGT_2")==null?"/":hm.get("WGT_2")),cellFormat));
			//丙班 
			sheet.addCell(new Label(4,i+2,""+(hm.get("WGT_3")==null?"/":hm.get("WGT_3")),cellFormat));
			//丁班
			sheet.addCell(new Label(5,i+2,""+(hm.get("WGT_4")==null?"/":hm.get("WGT_4")),cellFormat));
			if(hm.get("WGT_0")!=null){
				if(total_wgt_0==null){
					total_wgt_0=0d;
				}
				total_wgt_0=DoubleUtil.add(total_wgt_0, Double.parseDouble(hm.get("WGT_0")+""));
				wgt_0_count++;
			}
			if(hm.get("WGT_1")!=null){
				if(total_wgt_1==null){
					total_wgt_1=0d;
				}
				total_wgt_1=DoubleUtil.add(total_wgt_1, Double.parseDouble(hm.get("WGT_1")+""));
				wgt_1_count++;
			}
			if(hm.get("WGT_2")!=null){
				if(total_wgt_2==null){
					total_wgt_2=0d;
				}
				total_wgt_2=DoubleUtil.add(total_wgt_2, Double.parseDouble(hm.get("WGT_2")+""));
				wgt_2_count++;
			}
			if(hm.get("WGT_3")!=null){
				if(total_wgt_3==null){
					total_wgt_3=0d;
				}
				total_wgt_3=DoubleUtil.add(total_wgt_3, Double.parseDouble(hm.get("WGT_3")+""));
				wgt_3_count++;
			}
			if(hm.get("WGT_4")!=null){
				if(total_wgt_4==null){
					total_wgt_4=0d;
				}
				total_wgt_4=DoubleUtil.add(total_wgt_4, Double.parseDouble(hm.get("WGT_4")+""));
				wgt_4_count++;
			}
			i++;
		}
		//合计
		sheet.addCell(new Label(0,i+2,"合计",cellFormat));
		//常白班
		sheet.addCell(new Label(1,i+2,""+(total_wgt_0==null?"/":total_wgt_0),cellFormat));
		//甲班
		sheet.addCell(new Label(2,i+2,""+(total_wgt_1==null?"/":total_wgt_1),cellFormat));
		//乙班
		sheet.addCell(new Label(3,i+2,""+(total_wgt_2==null?"/":total_wgt_2),cellFormat));
		//丙班 
		sheet.addCell(new Label(4,i+2,""+(total_wgt_3==null?"/":total_wgt_3),cellFormat));
		//丁班
		sheet.addCell(new Label(5,i+2,""+(total_wgt_4==null?"/":total_wgt_4),cellFormat));
		i++;
		
		//日平均
		sheet.addCell(new Label(0,i+2,"日平均",cellFormat));
		//常白班
		sheet.addCell(new Label(1,i+2,""+(wgt_0_count==0?"/":DoubleUtil.div(total_wgt_0, wgt_0_count, 3)),cellFormat));
		//甲班
		sheet.addCell(new Label(2,i+2,""+(wgt_1_count==0?"/":DoubleUtil.div(total_wgt_1, wgt_1_count, 3)),cellFormat));
		//乙班
		sheet.addCell(new Label(3,i+2,""+(wgt_2_count==0?"/":DoubleUtil.div(total_wgt_2, wgt_2_count, 3)),cellFormat));
		//丙班 
		sheet.addCell(new Label(4,i+2,""+(wgt_3_count==0?"/":DoubleUtil.div(total_wgt_3, wgt_3_count, 3)),cellFormat));
		//丁班
		sheet.addCell(new Label(5,i+2,""+(wgt_4_count==0?"/":DoubleUtil.div(total_wgt_4, wgt_4_count, 3)),cellFormat));
		
		sheet.getSettings().setVerticalFreeze(1);  		//首行冻结
		//sheet.getSettings().setVerticalFreeze(2);
		//关闭
		workbook.write();
		workbook.close();
		rm.setData("/download?filename="+file);	
	}
	
	// 补零
	public static String lpad(String str, int num, String pad) {
		String n_str = str;
		if (str == null && "".equals(str))
			n_str = " ";
		for (int i = str.length(); i < num; i++) {
			n_str = pad + n_str;
		}
		return n_str;
	}
	
}
