/***文档注释***********************************************
 * 作者            ：宋燕辉
 * 创建日期     ：2018-03-26
 * 描述            ：岗位交接班记录主表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Mes.Shift.impl;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import market.Com.mapper.ComBaseMachineMapper;
import market.Com.vo.ComBaseMachine;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Mes.Dev.mapper.DevBladeGrindingMapper;
import market.Mes.Dev.mapper.DevBladeGrpMapper;
import market.Mes.Dev.mapper.DevBladeInfoMapper;
import market.Mes.Dev.mapper.DevBladeUseBldMapper;
import market.Mes.Dev.mapper.DevBladeUseCoilsMapper;
import market.Mes.Dev.mapper.DevBladeUseDBldMapper;
import market.Mes.Dev.mapper.DevBladeUseDGrpMapper;
import market.Mes.Dev.mapper.DevBladeUseGrpMapper;
import market.Mes.Dev.vo.DevBladeGrp;
import market.Mes.Dev.vo.DevBladeInfo;
import market.Mes.Dev.vo.DevBladeSum;
import market.Mes.Dev.vo.DevBladeUseBld;
import market.Mes.Dev.vo.DevBladeUseCoils;
import market.Mes.Dev.vo.DevBladeUseDBld;
import market.Mes.Dev.vo.DevBladeUseDGrp;
import market.Mes.Dev.vo.DevBladeUseGrp;
import market.Mes.Shift.mapper.MesShiftMMapper;
import market.Mes.Shift.service.MesShiftMService;
import market.Mes.Shift.vo.MesShiftDBldRmv;
import market.Mes.Shift.vo.MesShiftDBldSet;
import market.Mes.Shift.vo.MesShiftDCheck;
import market.Mes.Shift.vo.MesShiftDCsm;
import market.Mes.Shift.vo.MesShiftDEmp;
import market.Mes.Shift.vo.MesShiftDNotes;
import market.Mes.Shift.vo.MesShiftM;
import market.Mes.Shift.vo.MesShiftMSum;
import market.Mes.util.DateUtil;
import market.Mes.util.MesUtil;

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="MesShiftMService")
public class MesShiftMServiceImpl extends BaseServiceImpl<MesShiftM,Object> implements MesShiftMService {

	
	//=========================排刀管理开始=============================
	 
	/**
	 * 刀片管理_刀片使用记录
		动作处理_保存按钮
	 * @param sum
     
	 * @return
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doSaveDevWeb(CommonPage<DevBladeSum> sum) throws Exception{
		ResultModel rm=new ResultModel();
		DevBladeSum dbs = sum.getObject();
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		if(userName==null){
			userName="";
		}
		if(dbs==null){
			rm.setState("500");
			rm.setMsgInfo("请输入参数");
			return rm;
		}
		if(dbs.getMachine_code()==null || "".equals(dbs.getMachine_code())){
			rm.setState("500");
			rm.setMsgInfo("未指定机台代码！");
			return rm;
		}
		if(dbs.getWrk_date()==null || "".equals(dbs.getWrk_date())){
			rm.setState("500");
			rm.setMsgInfo("未指定作业日期！");
			return rm;
		}
		if(dbs.getWrk_ord()==null || "".equals(dbs.getWrk_ord())){
			rm.setState("500");
			rm.setMsgInfo("未指定班次！");
			return rm;
		}
		if(dbs.getDbuc()==null){
			rm.setState("500");
			rm.setMsgInfo("参数错误：请输入钢卷信息！");
			return rm;
		}
	    for(DevBladeUseCoils dbuc: dbs.getDbuc()){
	    	if(dbuc.getSqc_no()==null || dbuc.getCoil_no()==null || dbuc.getCoil_no_etn()==null 
	    			|| "".equals(dbuc.getSqc_no().toString().trim()) || "".equals(dbuc.getCoil_no().trim()) || "".equals(dbuc.getCoil_no_etn().trim())
	    			){
	    		rm.setState("500");
				rm.setMsgInfo("参数错误：钢卷信息参数个数不匹配，请输入钢卷信息！");
				return rm;
	    	}
	    }
	    if(dbs.getDbudg()==null){
			rm.setState("500");
			rm.setMsgInfo("参数错误：请输入分组使用信息！");
			return rm;
		}
	    for(DevBladeUseDGrp dbudg: dbs.getDbudg()){
	    	if(dbudg.getSqc_no()==null || dbudg.getGrp_code()==null 
	    			|| "".equals(dbudg.getSqc_no().toString().trim()) || "".equals(dbudg.getGrp_code().trim())){
	    		rm.setState("500");
				rm.setMsgInfo("参数错误：分组使用信息参数个数不匹配，请输入分组使用信息！");
				return rm;
	    	}
	    }
	    if(dbs.getDbudb()==null){
			rm.setState("500");
			rm.setMsgInfo("参数错误：请输入刀片使用信息！");
			return rm;
		}
	    for(DevBladeUseDBld dbudb: dbs.getDbudb()){
	    	if(dbudb.getSqc_no()==null || dbudb.getBlade_no()==null
	    			|| "".equals(dbudb.getSqc_no().toString().trim()) || "".equals(dbudb.getBlade_no().trim())){
	    		rm.setState("500");
				rm.setMsgInfo("参数错误：刀片使用信息参数个数不匹配，请输入刀片使用信息！");
				return rm;
	    	}
	    }
	   
		//验证机台基础信息存在
		ComBaseMachine machine = new ComBaseMachine();
		machine.setMachine_code(dbs.getMachine_code());
		int v_cnt = this.getMapper(ComBaseMachineMapper.class).count(machine);
		if (v_cnt <= 0) {
			rm.setState("500");
			rm.setMsgInfo("机台代码{"+dbs.getMachine_code()+"} 机台基础信息不存在！");
			return rm;
		}
		for(DevBladeUseDGrp dd:dbs.getDbudg()){
			DevBladeUseGrp dbug=new DevBladeUseGrp();
			dbug.setMachine_code(dbs.getMachine_code());
			dbug.setWrk_date(dbs.getWrk_date());
			dbug.setWrk_ord(dbs.getWrk_ord());
			dbug.setGrp_code(dd.getGrp_code());
			int count = this.getMapper(DevBladeUseGrpMapper.class).count(dbug);
			if(count<=0){
				rm.setState("500");
				rm.setMsgInfo("分组代码{"+dd.getGrp_code()+"} 当前班组未指定此刀片分组！");
				return rm;
			}
		}
		for(DevBladeUseDBld dd:dbs.getDbudb()){
			DevBladeUseBld dbub=new DevBladeUseBld();
			dbub.setMachine_code(dbs.getMachine_code());
			dbub.setWrk_date(dbs.getWrk_date());
			dbub.setWrk_ord(dbs.getWrk_ord());
			//注意
			//dbub.setGrp_code(dd.getBlade_no());
			dbub.setBlade_no(dd.getBlade_no());
			int count = this.getMapper(DevBladeUseBldMapper.class).count(dbub);
			if(count<=0){
				rm.setState("500");
				rm.setMsgInfo("刀片编号{"+dd.getBlade_no()+"} 当前班组未指定此刀片编号！");
				return rm;
			}
		}
		//开始事务
		//  --(2.1)、还原先前保存的各刀片的使用次数
		DevBladeUseBld dbub=new DevBladeUseBld();
		dbub.setMachine_code(dbs.getMachine_code());
		dbub.setWrk_date(dbs.getWrk_date());
		dbub.setWrk_ord(dbs.getWrk_ord());
		List<DevBladeUseBld> listDblade = this.getMapper(DevBladeUseBldMapper.class).find(dbub, 0, 0);
		if(listDblade!=null && listDblade.size()>0){
			for(DevBladeUseBld cur_01:listDblade){
				if(cur_01.getUse_times()==null){
					cur_01.setUse_times(0l);
				}
				this.getMapper(DevBladeInfoMapper.class).doUpdate(cur_01);
			}
		}
		//this.getMapper(DevBladeUseBldMapper.class).doUpdate(machine_code, wrk_date, wrk_ord, blade_no);
		this.getMapper(DevBladeUseBldMapper.class).doUpdate3(dbs.getMachine_code(), dbs.getWrk_date(), 
				dbs.getWrk_ord());
		this.getMapper(DevBladeUseGrpMapper.class).doUpdate3(dbs.getMachine_code(), dbs.getWrk_date(), 
				dbs.getWrk_ord());
		
		
		//  --(2.2)、删除“刀片使用-刀片明细”
		DevBladeUseDBld dbu=new DevBladeUseDBld();
		dbu.setMachine_code(dbs.getMachine_code());
		dbu.setWrk_date(dbs.getWrk_date());
		dbu.setWrk_ord(dbs.getWrk_ord());
		this.getMapper(DevBladeUseDBldMapper.class).doDelete(dbu);
		//  --(2.3)、删除“刀片使用-刀片组明细”
		DevBladeUseDGrp  devb=new DevBladeUseDGrp();
		devb.setMachine_code(dbs.getMachine_code());
		devb.setWrk_date(dbs.getWrk_date());
		devb.setWrk_ord(dbs.getWrk_ord());
		this.getMapper(DevBladeUseDGrpMapper.class).doDelete(devb);
		//  --(2.4)、删除“刀片使用-钢卷号”
		DevBladeUseCoils dbuci=new DevBladeUseCoils();
		dbuci.setMachine_code(dbs.getMachine_code());
		dbuci.setWrk_date(dbs.getWrk_date());
		dbuci.setWrk_ord(dbs.getWrk_ord());
		this.getMapper(DevBladeUseCoilsMapper.class).doDelete(dbuci);
		//  --(2.5)、循环插入新的记录“刀片使用-钢卷号”
		for(DevBladeUseCoils dbuc: dbs.getDbuc()){
			DevBladeUseCoils dbcoil=new DevBladeUseCoils();
			dbcoil.setMachine_code(dbs.getMachine_code());
			dbcoil.setWrk_date(dbs.getWrk_date());
			dbcoil.setWrk_ord(dbs.getWrk_ord());
			dbcoil.setSqc_no(dbuc.getSqc_no());
			dbcoil.setCoil_no(dbuc.getCoil_no());
			dbcoil.setCoil_no_etn(dbuc.getCoil_no_etn());
			this.getMapper(DevBladeUseCoilsMapper.class).insert(dbcoil);
		}
		//  --(2.6)、循环插入新的记录“刀片使用-刀片组明细”
		for(DevBladeUseDGrp dbudg: dbs.getDbudg()){
			DevBladeUseDGrp dbcoil=new DevBladeUseDGrp();
			dbcoil.setMachine_code(dbs.getMachine_code());
			dbcoil.setWrk_date(dbs.getWrk_date());
			dbcoil.setWrk_ord(dbs.getWrk_ord());
			dbcoil.setSqc_no(dbudg.getSqc_no());
			dbcoil.setGrp_code(dbudg.getGrp_code());
			this.getMapper(DevBladeUseDGrpMapper.class).insert(dbcoil);
			//    --(2.6.1)、更新指定分组使用次数
			this.getMapper(DevBladeUseGrpMapper.class).doUpdate(dbs.getMachine_code(),dbs.getWrk_date(),dbs.getWrk_ord(),dbudg.getGrp_code(),userName);
		}
		//  --(2.7)、循环插入新的记录“刀片使用-刀片明细”
		for(DevBladeUseDBld dbudb: dbs.getDbudb()){
			DevBladeUseDBld ddd=new DevBladeUseDBld();
			ddd.setMachine_code(dbs.getMachine_code());
			ddd.setWrk_date(dbs.getWrk_date());
			ddd.setWrk_ord(dbs.getWrk_ord());
			ddd.setSqc_no(dbudb.getSqc_no());
			ddd.setBlade_no(dbudb.getBlade_no());
			this.getMapper(DevBladeUseDBldMapper.class).insert(ddd);
			//   --(2.7.1)、更新指定刀片使用次数
			this.getMapper(DevBladeUseBldMapper.class).doUpdate(dbs.getMachine_code(),dbs.getWrk_date(),dbs.getWrk_ord(),dbudb.getBlade_no());
			//    --(2.7.2)、更新指定刀片使用次数
			this.getMapper(DevBladeInfoMapper.class).doUpdate1(dbudb.getBlade_no(),userName);
		}
		rm.setState("200");
		rm.setMsgInfo("保存成功");
		return rm;
	}
	
	
	/**
	 * 刀片管理_刀片使用记录
	 * 动作处理_刷新（使用实绩）按钮
	 * 动作处理_日期班次记录双击
	 * “使用明细”处理：
	 * 刀片分组（生成刀片分组表格固定列）
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD
	 * @return
	 */
	public ResultModel doQueryGrpnWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入机台代码");
				return rm;
			}
			if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入日期");
				return rm;
			}
			if(sum.getMemo3()==null || "".equals(sum.getMemo3())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入班次");
				return rm;
			}
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryGrpnWeb(sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 刀片管理_刀片使用记录
	 * 动作处理_刷新（使用实绩）按钮
	 * 动作处理_日期班次记录双击
	 * “使用明细”处理：
	 * 刀片编号（生成刀片编号表格固定列）
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD
	 * @return
	 */
	public ResultModel doQueryGrpbldWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入机台代码");
				return rm;
			}
			if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入日期");
				return rm;
			}
			if(sum.getMemo3()==null || "".equals(sum.getMemo3())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入班次");
				return rm;
			}
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryGrpbldWeb(sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 刀片管理_刀片使用记录
	 * 动作处理_刷新（使用实绩）按钮
	 * 动作处理_日期班次记录双击
	 * “使用明细”处理：
	 *钢卷明细（生成钢卷明细、刀片分组、刀片编号三个表格的动态列，按SQC_NO排序生成列）
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD
	 * @return
	 */
	public ResultModel doQueryGrpcoilWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入机台代码");
				return rm;
			}
			if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入日期");
				return rm;
			}
			if(sum.getMemo3()==null || "".equals(sum.getMemo3())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入班次");
				return rm;
			}
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryGrpcoilWeb(sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 刀片管理_刀片使用记录
	 * 动作处理_刷新（使用实绩）按钮
	 * 动作处理_日期班次记录双击
	 * “使用明细”处理：
	 * 刀片分组使用情况（刀片分组表格，对应钢卷是否勾上）
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD
	 * @return
	 */
	public ResultModel doQuerydGrpWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入机台代码");
				return rm;
			}
			if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入日期");
				return rm;
			}
			if(sum.getMemo3()==null || "".equals(sum.getMemo3())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入班次");
				return rm;
			}
			rm.setData(this.getMapper(MesShiftMMapper.class).doQuerydGrpWeb(sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 刀片管理_刀片使用记录
	 * 动作处理_刷新（使用实绩）按钮
	 * 动作处理_日期班次记录双击
	 * “使用明细”处理：
	 *刀片编号使用情况（刀片编号表格，对应钢卷是否勾上）
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD
	 * @return
	 */
	public ResultModel doQuerydBldWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入机台代码");
				return rm;
			}
			if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入日期");
				return rm;
			}
			if(sum.getMemo3()==null || "".equals(sum.getMemo3())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入班次");
				return rm;
			}
			rm.setData(this.getMapper(MesShiftMMapper.class).doQuerydBldWeb(sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 刀片管理_刀片使用记录
	 * 动作处理_刷新（钢卷信息）按钮
	 * 动作处理_日期班次记录双击：“当班加工钢卷信息”处理：
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD
	 * @return
	 */
	public ResultModel doQueryMesCrMWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入机台代码");
				return rm;
			}
			if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入日期");
				return rm;
			}
			if(sum.getMemo3()==null || "".equals(sum.getMemo3())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入班次");
				return rm;
			}
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryMesCrMWeb(sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 刀片管理_刀片使用记录
	 * 刀片管理_刀片生产指定
	 * 查询
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_MONTH  
	 * @return
	 */
	public ResultModel doQueryDevWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入机台代码");
				return rm;
			}
			if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入月份【yyyy-MM】");
				return rm;
			}
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryDev(sum.getMemo1(),sum.getMemo2()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 刀片管理_刀片使用记录
	 * 刀片管理_刀片生产指定
	 * 查询
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_MONTH  
	 * @return
	 */
	public ResultModel doQueryDevWeb_43(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入机台代码");
				return rm;
			}
			if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入月份【yyyy-MM】");
				return rm;
			}
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryDev43(sum.getMemo1(),sum.getMemo2()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 动作处理_刷新（使用实绩）按钮
	 * 动作处理_日期班次记录双击
	 * 动作处理_刷新指定刀片组按钮
	 *“接班信息”处理：
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD
	 * @return
	 */
	public ResultModel doQueryRecWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入机台代码");
				return rm;
			}
			if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入日期");
				return rm;
			}
			if(sum.getMemo3()==null || "".equals(sum.getMemo3())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入班次");
				return rm;
			}
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryRecWeb(sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 动作处理_刷新指定刀片组按钮
	 * 动作处理_日期班次记录双击
	 *“指定刀片组”处理：
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD
	 * @return
	 */
	public ResultModel doQueryBladeWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入机台代码");
				return rm;
			}
			if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入日期");
				return rm;
			}
			if(sum.getMemo3()==null || "".equals(sum.getMemo3())){
				rm.setState("500");
				rm.setMsgInfo("参数错误：请输入班次");
				return rm;
			}
			List<DevBladeUseGrp> dbws = this.getMapper(MesShiftMMapper.class).doQueryBladeWeb(sum.getMemo1(),sum.getMemo2(),sum.getMemo3());
			if(sum.getMemo3().equals("1")){
				for(DevBladeUseGrp dbw:dbws){
					DevBladeUseGrp dbug=new DevBladeUseGrp();
					dbug.setMachine_code(sum.getMemo1());
					dbug.setWrk_date(sum.getMemo2());
					dbug.setWrk_ord("2");
					dbug.setGrp_code(dbw.getGrp_code());
					List<DevBladeUseGrp> ldbug = this.getMapper(DevBladeUseGrpMapper.class).find(dbug, 0, 0);
					if(ldbug!=null && ldbug.size()>0){
						dbw.setAcm_use_times(dbw.getAcm_use_times()-(ldbug.get(0).getUse_times()==null?0:ldbug.get(0).getUse_times()));
					}
				}
			}
			//rm.setData(this.getMapper(MesShiftMMapper.class).doQueryBladeWeb(sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setData(dbws);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	动作处理_保存按钮
	objectList:
	  grp_code（刀片分组编号集合）
	memo1:机台代码
	memo2:作业日期
	memo3:班次
	 * @return
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doSave2Web(CommonPage<DevBladeGrp> sum) throws  Exception{
		ResultModel rm=new ResultModel();
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		if(userName==null){
			userName="";
		}
		if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
			rm.setState("500");
			rm.setMsgInfo("参数错误：请输入机台代码");
			return rm;
		}
		if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
			rm.setState("500");
			rm.setMsgInfo("参数错误：请输入作业日期");
			return rm;
		}
		if(sum.getMemo3()==null || "".equals(sum.getMemo3())){
			rm.setState("500");
			rm.setMsgInfo("参数错误：请输入班次");
			return rm;
		}
		//验证机台基础信息存在
		ComBaseMachine machine = new ComBaseMachine();
		machine.setMachine_code(sum.getMemo1());
		int v_cnt = this.getMapper(ComBaseMachineMapper.class).count(machine);
		if (v_cnt <= 0) {
			rm.setState("500");
			rm.setMsgInfo("机台代码{"+sum.getMemo1()+"} 机台基础信息不存在！");
			return rm;
		}
		//  --(1.14)、验证刀片分组存在
		List<DevBladeGrp> ldbg = sum.getObjectList();
		//按照序号排序
		MesUtil.sortIntMethod2(ldbg);
		
		if(ldbg!=null && ldbg.size()>0){
			for(DevBladeGrp dbi:ldbg){
				v_cnt = this.getMapper(DevBladeGrpMapper.class).countWithCondition(null, "grp_code='"+dbi.getGrp_code()+"'");
				if(v_cnt<=0){
					rm.setState("500");
					rm.setMsgInfo("分组代码{"+dbi.getGrp_code()+"} 刀片分组信息不存在！");
					return rm;
				}
				DevBladeGrp v_rec_grp = this.getMapper(DevBladeGrpMapper.class).findById(dbi.getGrp_code());
				if(!sum.getMemo1().equals(v_rec_grp.getMachine_code())){
					rm.setState("500");
					rm.setMsgInfo("机台代码{"+sum.getMemo1()+"} 与刀片分组{"+v_rec_grp.getGrp_name()+"}所属机台代码{"+v_rec_grp.getMachine_code()+"} 不一致！");
					return rm;
				}
			    v_cnt = this.getMapper(DevBladeInfoMapper.class).countWithCondition(null, "grp_code='"+dbi.getGrp_code()+"'");
			    if(v_cnt<=0){
					rm.setState("500");
					rm.setMsgInfo("刀片分组{"+v_rec_grp.getGrp_name()+"} 系统中暂无此分组的刀片信息，请先维护刀片信息！");
					return rm;
				}
			    //    --(1.5.1)、验证刀片组无待处置的修磨记录
			    v_cnt=this.getMapper(DevBladeGrindingMapper.class).doCount5(sum.getMemo1(),dbi.getGrp_code());
			    if(v_cnt>0){
					rm.setState("500");
					rm.setMsgInfo("刀片分组{"+v_rec_grp.getGrp_name()+"} 存在未处置结束的修磨记录，暂不允许此操作！");
					return rm;
				}
			    String status="2";
			    //    --(1.5.2)、验证刀片组中无“修磨”刀片
			    v_cnt=this.getMapper(DevBladeInfoMapper.class).doCount1(dbi.getGrp_code(),status);
			    if(v_cnt>0){
					rm.setState("500");
					rm.setMsgInfo("刀片分组{"+v_rec_grp.getGrp_name()+"} 存在“修磨”刀片，暂不允许此操作！");
					return rm;
				}
			    status="1";
			    //   --(1.5.3)、验证刀片组中无“待磨”刀片
			    v_cnt=this.getMapper(DevBladeInfoMapper.class).doCount1(dbi.getGrp_code(),status);
			    if(v_cnt>0){
					rm.setState("500");
					rm.setMsgInfo("刀片分组{"+v_rec_grp.getGrp_name()+"} 存在“待磨”刀片，暂不允许此操作！");
					return rm;
				}
			    
			}
		}
		//  --(2)、验证当班是否已有使用实绩
		DevBladeUseDGrp  dbgu=new DevBladeUseDGrp();
		dbgu.setMachine_code(sum.getMemo1());
		dbgu.setWrk_date(sum.getMemo2());
		dbgu.setWrk_ord(sum.getMemo3());
	    v_cnt = this.getMapper(DevBladeUseDGrpMapper.class).count(dbgu);
	    if(v_cnt>0){
			rm.setState("500");
			rm.setMsgInfo("当前班次已填写刀片使用实绩信息，不允许此操作！");
			return rm;
		}
		this.getMapper(DevBladeUseBldMapper.class).doDelete(sum.getMemo1(),sum.getMemo2(),sum.getMemo3());
		this.getMapper(DevBladeUseGrpMapper.class).doDelete(sum.getMemo1(),sum.getMemo2(),sum.getMemo3());
		
		if(ldbg!=null && ldbg.size()>0){
			int idx=0;
			for(DevBladeGrp dbig:ldbg){
				idx++;
				//    --(3.3.0)、获取刀片分组记录对象
				DevBladeGrp v_rec_grp = this.getMapper(DevBladeGrpMapper.class).findById(dbig.getGrp_code());
				List<DevBladeInfo> cur_01 = this.getMapper(DevBladeInfoMapper.class).findWithCondition(null, "grp_code='"+dbig.getGrp_code()+"' and status <> '9' ", "dsp_order", 0, 0);
				if(cur_01!=null && cur_01.size()>0){
					for(DevBladeInfo dbb:cur_01){
						DevBladeUseBld dbub=new DevBladeUseBld();
						dbub.setMachine_code(sum.getMemo1());
						dbub.setWrk_date(sum.getMemo2());
						dbub.setWrk_ord(sum.getMemo3());
						dbub.setBlade_no(dbb.getBlade_no());
						dbub.setGrp_code(dbig.getGrp_code());
						dbub.setStatus(dbb.getStatus());
						dbub.setDsp_order(dbb.getDsp_order());
						dbub.setUse_times(0l);
						dbub.setAcm_use_times(dbb.getCur_use_times());
						this.getMapper(DevBladeUseBldMapper.class).insert(dbub);
					}
				}
				//    --(3.3.2)、再插入分组信息记录
				DevBladeUseGrp dbug=new  DevBladeUseGrp();
				dbug.setMachine_code(sum.getMemo1());
				dbug.setWrk_date(sum.getMemo2());
				dbug.setWrk_ord(sum.getMemo3());
				dbug.setGrp_code(dbig.getGrp_code());
				dbug.setGrp_name(v_rec_grp.getGrp_name());
				dbug.setDsp_order((long)idx);
				dbug.setUse_times(0l);
				v_cnt=this.getMapper(DevBladeInfoMapper.class).doCount4(dbig.getGrp_code());
				//查询最近的检修日期
				String max_str_date = this.getMapper(DevBladeGrindingMapper.class).doQuery5(sum.getMemo1(),dbug.getGrp_code(),sum.getMemo2());
				if(max_str_date==null){
					max_str_date="0";
				}
				Long acmusetimes=getMapper(DevBladeUseGrpMapper.class).doQuery(dbug.getMachine_code(),dbug.getWrk_date(),max_str_date,dbug.getGrp_code());
				dbug.setAcm_use_times(acmusetimes);
				dbug.setCreate_opr(userName);
				dbug.setCreate_time(new Date());
				this.getMapper(DevBladeUseGrpMapper.class).insert(dbug);
			}
		}
		rm.setState("200");
		rm.setMsgInfo("保存成功");
		return rm;
	}
	
	
	//=========================排刀管理结束=============================
	
	
	
	/**
	 * 查询
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_MONTH  
	 * @return
	 */
	public ResultModel doQueryWeb_SUANXI(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQuery_SUANXI(sum.getObject(),sum.getMemo1(),sum.getMemo2()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 查询
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V_MONTH  
	 * @return
	 */
	public ResultModel doQueryWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQuery(sum.getObject(),sum.getMemo1(),sum.getMemo2()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 查询  “接班信息”、“交班信息”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryClassWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryClassWeb(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 查询  “作业人员名单”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryEmpWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryEmpWeb(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 查询  “班中情况记录”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryClassRecordWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryClassRecordWeb(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 查询  “工具及卫生交接记录”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryCheckWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryCheckWeb(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 查询  “排刀拆刀记录”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	/*
	public ResultModel doQuerySlittingWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQuerySlittingWeb(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	*/
	//查询  “排刀记录”
	public ResultModel doQuerySlitting1Web(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQuerySlitting1Web(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
		
	}
	
	//查询“拆刀记录”
	public ResultModel doQuerySlitting2Web(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQuerySlitting2Web(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	
	
	/**
	 * 查询  “消耗记录”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryDcsmWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryDcsmWeb(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 平整机
	 * 查询  “投入产出汇总”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutTotalWeb_tpm(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutTotalWebTpm(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 平整机
	 * 查询  “投入产出明细”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutDetailWeb_tpm(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutDetailWeb_tpm(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 轧机
	 * 查询  “投入产出汇总”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutTotalWeb_rcm(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutTotalWebRcm(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 轧机
	 * 查询  “投入产出明细”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutDetailWeb_rcm(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutDetailWeb_rcm(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	
	/**
	 * 酸洗
	 * 查询  “投入产出汇总”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutTotalWeb_plm(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutTotalWebPlm(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 酸洗
	 * 查询  “投入产出明细”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutDetailWeb_plm(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutDetailWeb_plm(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 宝信罩退
	 * 查询  “投入产出汇总”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutTotalWeb_anneal(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutTotalWeb3(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 南方D,南方G 
	 * 查询  “投入产出汇总”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutTotalWeb_anneal_DG(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutTotalWeb_anneal_DG(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 查询  “投入产出汇总”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutTotalWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutTotalWeb(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	/**
	 * 横剪-开平
	 * 查询  “投入产出汇总”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutTotalWeb2(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutTotalWeb2(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 宝信罩退       投入
	 * 查询  “投入产出明细”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutDetailWeb_anneal_in(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutDetailWeb3(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 宝信罩退       产出
	 * 查询  “投入产出明细”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutDetailWeb_anneal_out(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutDetailWeb4(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 南方D，南方G  投入
	 * 查询  “投入产出明细”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutDetailWeb_Dg_in(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutDetailWeb_Dg_in(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 南方D，南方G  产出
	 * 查询  “投入产出明细”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutDetailWeb_Dg_out(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutDetailWeb_Dg_out(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	
	
	/**
	 * 查询  “投入产出明细”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutDetailWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutDetailWeb(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 横剪-开平
	 * 查询  “投入产出明细”
	 * @param sum
	 * memo1: V_MCH_CODE 机台代码
	 * memo2: V1 日期
	 * memo3: V2班次代码  
	 * @return
	 */
	public ResultModel doQueryInOutDetailWeb2(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(MesShiftMMapper.class).doQueryInOutDetailWeb2(sum.getObject(),sum.getMemo1(),sum.getMemo2(),sum.getMemo3()));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 获取“排刀”、“拆刀”操作人员列表
	 * @param sum
	 * memo1:  “接班信息”、“交班信息”返回的“班组”代码 V_WRK_GRP
	 * @return
	 */
	public ResultModel doQuerySlittingEmpWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try{
			if(sum!=null && sum.getMemo1()!=null && sum.getMemo1()!=""){
				rm.setData(this.getMapper(MesShiftMMapper.class).doQuerySlittingEmpWeb(sum.getObject(),sum.getMemo1()));
			}
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 *动作处理-接班按钮
	 *
	 * @param sum
	 * memo1: V_MCH_CODE  
	 * memo2: V_WRK_DATE
	 *  // memo3: 登录用户名
	 * memo4: V_WRK_ORD代表的班次名称
	 * @return
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doTurnWeb(CommonPage<MesShiftM> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{	
				String wrk_ord=sum.getObject().getWrk_ord();
//				if(!"1".equals(wrk_ord)&&!"2".equals(wrk_ord)){
//					rm.setState("500");
//					rm.setMsgInfo("班次代码无效！");
//					return rm;
//				}
				String wrk_grp=sum.getObject().getWrk_grp();
//				if(!"1".equals(wrk_grp)&&!"2".equals(wrk_grp)&&!"3".equals(wrk_grp)&&!"4".equals(wrk_grp)){
//					rm.setState("500");
//					rm.setMsgInfo("班组代码无效！");
//					return rm;
//				}
				List<HashMap> lhm=this.getMapper(MesShiftMMapper.class).doQuery1(sum.getMemo1(),sum.getMemo2(),sum.getObject().getWrk_ord());
				if(lhm!=null && lhm.size()>0){
					Object object = lhm.get(0).get("CNT");
					//int ob=(int) object;
					int ob=Integer.parseInt( object.toString());
					if(ob>0){
						rm.setState("500");
						rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo4()+"\n已接班，不能重复操作！");
						return rm;
					}
				}
				this.getMapper(MesShiftMMapper.class).doDelete(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				
				String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
				
				this.getMapper(MesShiftMMapper.class).doInsert(sum.getMemo1(),sum.getMemo2(),wrk_ord,wrk_grp,userName);
				
				//2.读取岗位配置表、人员信息表（MES_SHIFT_CONFIG_POST、MES_SHIFT_BASE_EMP），获取当前机台交接班配置的岗位名称及人数，根据此配置自动创建“岗位交接班作业人员记录”
				long idx=1;
				//先删除可能存在的人员记录
				this.getMapper(MesShiftMMapper.class).doDeleteEmp(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的交接班岗位信息（代码、名称、配置人数），按显示顺序排序进入循环
				List<HashMap> lhm1=this.getMapper(MesShiftMMapper.class).doQueryPost(sum.getMemo1());
				for (HashMap hashMap : lhm1) {
					//根据岗位配置人数，从1开始循环，匹配人员基础信息表当前机台、班次的人员（编号、姓名）
					List<HashMap> lhm2=this.getMapper(MesShiftMMapper.class).doQueryEmp2Web( sum.getMemo1(),hashMap.get("POST_CODE"),wrk_grp,hashMap.get("POST_EMP_NUM"));
					for (HashMap hashMap2 : lhm2) {
						//插入记录到作业人员情况表
						this.getMapper(MesShiftMMapper.class).doInsert2(sum.getMemo1(), sum.getMemo2(), wrk_ord, idx, hashMap2.get("EMP_NO"),
								hashMap2.get("EMP_NAME"),hashMap.get("POST_CODE"),hashMap.get("POST_DESC"),userName);
						idx++;
					}
				}
				
				//3.根据当前接班“班次”，计算班次开始、结束时间，并按一个小时的间隔创建“岗位交接班班中情况记录”
				Date v_from;
				Integer v_hour=12;
				String v_time="";
				
				//页面
				String page=sum.getMemo1();
				//根据传入的日期、班次，计算班次的开始时间
				String date="";
				if("1".equals(wrk_ord)){
					//剪切区改为18点
//					if(page.equals("M0001")||page.equals("M0002")||page.equals("M0003")){
//						//晚班从前一天18点开始
//						date=sum.getMemo2()+" 18:00:00";
//					}else{
//						//晚班从前一天20点开始
						date=sum.getMemo2()+" "+DateUtil.EndTime;
//					}
					
					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
					Long ti=(long) (24*60*60*1000);
					v_from=new Date(v_from.getTime()-ti);
				}else if("2".equals(wrk_ord)){
					//剪切区改为06点
//					if(page.equals("M0001")||page.equals("M0002")||page.equals("M0003")){
//						//白班从当天06点开始
//						date=sum.getMemo2()+" 06:00:00";
//					}else{
						//白班从当天08点开始
						date=sum.getMemo2()+" "+DateUtil.BeginTime;
//					}
					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
				}else{
					rm.setState("500");
					rm.setMsgInfo("班次代码无效！");
					return rm;
				}
//				if("1".equals(wrk_ord)){
//					//晚班从前一天20点开始
//					date=sum.getMemo2()+" 20:00:00";
//					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
//					Long ti=(long) (24*60*60*1000);
//				    v_from=new Date(v_from.getTime()-ti);
//				}else if("2".equals(wrk_ord)){
//					//白班从当天08点开始
//					date=sum.getMemo2()+" 08:00:00";
//					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
//				}else{
//					rm.setState("500");
//					rm.setMsgInfo("班次代码无效！");
//					return rm;
//				}
				//先删除可能存在的班中情况记录
				this.getMapper(MesShiftMMapper.class).doDeleteNotes(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//根据计算出的班次开始时间，按一个小时的间隔，生成报告时段（格式如：20:00 - 20:59），按顺序插入班中情况记录表
				for(int i=1;i<=v_hour;i++){
					Long tii=(long) (60*60*1000-1000);
					v_time=new SimpleDateFormat("HH:mm").format(v_from)+"-"+
						new SimpleDateFormat("HH:mm").format(new Date(v_from.getTime()+tii));
					this.getMapper(MesShiftMMapper.class).doInsertNodes(sum.getMemo1(),sum.getMemo2(),wrk_ord,i,v_time,userName);
					v_from=new Date(v_from.getTime()+(60*60*1000));
				}
				
				//4.根据当前机台配置的点检项目，自动创建“岗位交接班点检记录”
				int idxx=1;
				//先删除可能存在的（工具及卫生）点检记录
				this.getMapper(MesShiftMMapper.class).doDeleteCheck(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的点检项目，循环插入记录
				List<HashMap> lhm3=this.getMapper(MesShiftMMapper.class).doQueryConfiCheck(sum.getMemo1());
				for (HashMap hashMap : lhm3) {
					this.getMapper(MesShiftMMapper.class).doInsertCheck(sum.getMemo1(),sum.getMemo2(),wrk_ord,hashMap.get("CHECK_ITEM_CODE"),
							hashMap.get("CHECK_ITEM_NAME"),hashMap.get("CHECK_ITEM_TYPE_C"),hashMap.get("CHECK_ITEM_TYPE_N"),idxx,userName);
					idxx++;
				}
				
				//5.自动创建“岗位交接班排刀记录”
				//（1）、先删除可能存在的排刀记录
				this.getMapper(MesShiftMMapper.class).doDeleteBld(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				
				for(int icnt=1;icnt<=3;icnt++){
					this.getMapper(MesShiftMMapper.class).doInsertBld(sum.getMemo1(),sum.getMemo2(),wrk_ord,icnt,userName);
				}
				
				//6.自动创建“岗位交接班拆刀记录”、
				//（1）、先删除可能存在的拆刀记录
				this.getMapper(MesShiftMMapper.class).doDeleteRmv(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				
				for(int i=1;i<=3;i++){
					this.getMapper(MesShiftMMapper.class).doInsertRmv(sum.getMemo1(),sum.getMemo2(),wrk_ord,i,userName);
				}
				
				//5.根据当前机台配置的消耗项目，自动创建“岗位交接班消耗记录”
				int idxxx=1;
				//先删除可能存在的消耗记录
				this.getMapper(MesShiftMMapper.class).doDeleteCsm(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的消耗项目，循环插入记录
				List<HashMap> lhm4=this.getMapper(MesShiftMMapper.class).doQueryCsm(sum.getMemo1());
				for (HashMap hashMap : lhm4) {
					this.getMapper(MesShiftMMapper.class).doInsertCsm(sum.getMemo1(),sum.getMemo2(),wrk_ord,
							hashMap.get("CSM_ITEM_CODE"),hashMap.get("CSM_ITEM_NAME"),
							hashMap.get("CSM_ITEM_UNIT"),idxxx,userName);
					idxxx++;
				}
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("接班失败！\n"+ex.getMessage());
			throw new Exception("接班失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 *动作处理-接班按钮
	 *
	 * @param sum
	 * memo1: V_MCH_CODE  
	 * memo2: V_WRK_DATE
	 *  // memo3: 登录用户名
	 * memo4: V_WRK_ORD代表的班次名称
	 * @return
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doTurnWeb_SUANXI(CommonPage<MesShiftM> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{	
				String wrk_ord=sum.getObject().getWrk_ord();
//				if(!"1".equals(wrk_ord)&&!"2".equals(wrk_ord)&&!"3".equals(wrk_ord)){
//					rm.setState("500");
//					rm.setMsgInfo("班次代码无效！");
//					return rm;
//				}
				String wrk_grp=sum.getObject().getWrk_grp();
//				if(!"1".equals(wrk_grp)&&!"2".equals(wrk_grp)&&!"3".equals(wrk_grp)&&!"4".equals(wrk_grp)){
//					rm.setState("500");
//					rm.setMsgInfo("班组代码无效！");
//					return rm;
//				}
				List<HashMap> lhm=this.getMapper(MesShiftMMapper.class).doQuery1(sum.getMemo1(),sum.getMemo2(),sum.getObject().getWrk_ord());
				if(lhm!=null && lhm.size()>0){
					Object object = lhm.get(0).get("CNT");
					//int ob=(int) object;
					int ob=Integer.parseInt( object.toString());
					if(ob>0){
						rm.setState("500");
						rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo4()+"\n已接班，不能重复操作！");
						return rm;
					}
				}
				this.getMapper(MesShiftMMapper.class).doDelete(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				
				String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
				
				this.getMapper(MesShiftMMapper.class).doInsert(sum.getMemo1(),sum.getMemo2(),wrk_ord,wrk_grp,userName);
				
				//2.读取岗位配置表、人员信息表（MES_SHIFT_CONFIG_POST、MES_SHIFT_BASE_EMP），获取当前机台交接班配置的岗位名称及人数，根据此配置自动创建“岗位交接班作业人员记录”
				long idx=1;
				//先删除可能存在的人员记录
				this.getMapper(MesShiftMMapper.class).doDeleteEmp(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的交接班岗位信息（代码、名称、配置人数），按显示顺序排序进入循环
				List<HashMap> lhm1=this.getMapper(MesShiftMMapper.class).doQueryPost(sum.getMemo1());
				for (HashMap hashMap : lhm1) {
					//根据岗位配置人数，从1开始循环，匹配人员基础信息表当前机台、班次的人员（编号、姓名）
					List<HashMap> lhm2=this.getMapper(MesShiftMMapper.class).doQueryEmp2Web( sum.getMemo1(),hashMap.get("POST_CODE"),wrk_grp,hashMap.get("POST_EMP_NUM"));
					for (HashMap hashMap2 : lhm2) {
						//插入记录到作业人员情况表
						this.getMapper(MesShiftMMapper.class).doInsert2(sum.getMemo1(), sum.getMemo2(), wrk_ord, idx, hashMap2.get("EMP_NO"),
								hashMap2.get("EMP_NAME"),hashMap.get("POST_CODE"),hashMap.get("POST_DESC"),userName);
						idx++;
					}
				}
				
				//3.根据当前接班“班次”，计算班次开始、结束时间，并按一个小时的间隔创建“岗位交接班班中情况记录”
				Date v_from;
				Integer v_hour=8;
				String v_time="";
				
				//页面
				String page=sum.getMemo1();
				//根据传入的日期、班次，计算班次的开始时间
				String date="";
				if("1".equals(wrk_ord)){
					//剪切区改为18点
//					if(page.equals("M0001")||page.equals("M0002")||page.equals("M0003")){
//						//晚班从前一天18点开始
//						date=sum.getMemo2()+" 18:00:00";
//					}else{
//						//晚班从前一天20点开始
						date=sum.getMemo2()+" "+"00:00:00";
//					}
					
					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
					//Long ti=(long) (24*60*60*1000);
					//v_from=new Date(v_from.getTime());
				}else if("2".equals(wrk_ord)){
					//剪切区改为06点
//					if(page.equals("M0001")||page.equals("M0002")||page.equals("M0003")){
//						//白班从当天06点开始
//						date=sum.getMemo2()+" 06:00:00";
//					}else{
						//白班从当天08点开始
						date=sum.getMemo2()+" "+"08:00:00";
//					}
					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
				}else if("3".equals(wrk_ord)){
					//剪切区改为06点
//					if(page.equals("M0001")||page.equals("M0002")||page.equals("M0003")){
//						//白班从当天06点开始
//						date=sum.getMemo2()+" 06:00:00";
//					}else{
						//白班从当天08点开始
						date=sum.getMemo2()+" "+"16:00:00";
//					}
					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
				}else{
					rm.setState("500");
					rm.setMsgInfo("班次代码无效！");
					return rm;
				}
				
//				if("1".equals(wrk_ord)){
//					//晚班从前一天20点开始
//					date=sum.getMemo2()+" 20:00:00";
//					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
//					Long ti=(long) (24*60*60*1000);
//				    v_from=new Date(v_from.getTime()-ti);
//				}else if("2".equals(wrk_ord)){
//					//白班从当天08点开始
//					date=sum.getMemo2()+" 08:00:00";
//					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
//				}else{
//					rm.setState("500");
//					rm.setMsgInfo("班次代码无效！");
//					return rm;
//				}
				//先删除可能存在的班中情况记录
				this.getMapper(MesShiftMMapper.class).doDeleteNotes(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//根据计算出的班次开始时间，按一个小时的间隔，生成报告时段（格式如：20:00 - 20:59），按顺序插入班中情况记录表
				for(int i=1;i<=v_hour;i++){
					Long tii=(long) (60*60*1000-1000);
					v_time=new SimpleDateFormat("HH:mm").format(v_from)+"-"+
						new SimpleDateFormat("HH:mm").format(new Date(v_from.getTime()+tii));
					this.getMapper(MesShiftMMapper.class).doInsertNodes(sum.getMemo1(),sum.getMemo2(),wrk_ord,i,v_time,userName);
					v_from=new Date(v_from.getTime()+(60*60*1000));
				}
				
				//4.根据当前机台配置的点检项目，自动创建“岗位交接班点检记录”
				int idxx=1;
				//先删除可能存在的（工具及卫生）点检记录
				this.getMapper(MesShiftMMapper.class).doDeleteCheck(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的点检项目，循环插入记录
				List<HashMap> lhm3=this.getMapper(MesShiftMMapper.class).doQueryConfiCheck(sum.getMemo1());
				for (HashMap hashMap : lhm3) {
					this.getMapper(MesShiftMMapper.class).doInsertCheck(sum.getMemo1(),sum.getMemo2(),wrk_ord,hashMap.get("CHECK_ITEM_CODE"),
							hashMap.get("CHECK_ITEM_NAME"),hashMap.get("CHECK_ITEM_TYPE_C"),hashMap.get("CHECK_ITEM_TYPE_N"),idxx,userName);
					idxx++;
				}
				
				//5.自动创建“岗位交接班排刀记录”
				//（1）、先删除可能存在的排刀记录
				this.getMapper(MesShiftMMapper.class).doDeleteBld(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				
				for(int icnt=1;icnt<=3;icnt++){
					this.getMapper(MesShiftMMapper.class).doInsertBld(sum.getMemo1(),sum.getMemo2(),wrk_ord,icnt,userName);
				}
				
				//6.自动创建“岗位交接班拆刀记录”、
				//（1）、先删除可能存在的拆刀记录
				this.getMapper(MesShiftMMapper.class).doDeleteRmv(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				
				for(int i=1;i<=3;i++){
					this.getMapper(MesShiftMMapper.class).doInsertRmv(sum.getMemo1(),sum.getMemo2(),wrk_ord,i,userName);
				}
				
				//5.根据当前机台配置的消耗项目，自动创建“岗位交接班消耗记录”
				int idxxx=1;
				//先删除可能存在的消耗记录
				this.getMapper(MesShiftMMapper.class).doDeleteCsm(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的消耗项目，循环插入记录
				List<HashMap> lhm4=this.getMapper(MesShiftMMapper.class).doQueryCsm(sum.getMemo1());
				for (HashMap hashMap : lhm4) {
					this.getMapper(MesShiftMMapper.class).doInsertCsm(sum.getMemo1(),sum.getMemo2(),wrk_ord,
							hashMap.get("CSM_ITEM_CODE"),hashMap.get("CSM_ITEM_NAME"),
							hashMap.get("CSM_ITEM_UNIT"),idxxx,userName);
					idxxx++;
				}
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("接班失败！\n"+ex.getMessage());
			throw new Exception("接班失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	
	
	
	
	/**
	 * 开平-横剪
	 *动作处理-接班按钮
	 *
	 * @param sum
	 * memo1: V_MCH_CODE  
	 * memo2: V_WRK_DATE
	 *  // memo3: 登录用户名
	 * memo4: V_WRK_ORD代表的班次名称
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doTurnWeb2(CommonPage<MesShiftM> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{	
				String wrk_ord=sum.getObject().getWrk_ord();
				String wrk_grp=sum.getObject().getWrk_grp();
				List<HashMap> lhm=this.getMapper(MesShiftMMapper.class).doQuery1(sum.getMemo1(),sum.getMemo2(),sum.getObject().getWrk_ord());
				if(lhm!=null && lhm.size()>0){
					Object object = lhm.get(0).get("CNT");
					//int ob=(int) object;
					int ob=Integer.parseInt( object.toString());
					if(ob>0){
						rm.setState("500");
						rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo4()+"\n已接班，不能重复操作！");
						return rm;
					}
				}
				this.getMapper(MesShiftMMapper.class).doDelete(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				
				String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
				//userName="测试";
				
				this.getMapper(MesShiftMMapper.class).doInsert(sum.getMemo1(),sum.getMemo2(),wrk_ord,wrk_grp,userName);
				
				//2.读取岗位配置表、人员信息表（MES_SHIFT_CONFIG_POST、MES_SHIFT_BASE_EMP），获取当前机台交接班配置的岗位名称及人数，根据此配置自动创建“岗位交接班作业人员记录”
				long idx=1;
				//先删除可能存在的人员记录
				this.getMapper(MesShiftMMapper.class).doDeleteEmp(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的交接班岗位信息（代码、名称、配置人数），按显示顺序排序进入循环
				List<HashMap> lhm1=this.getMapper(MesShiftMMapper.class).doQueryPost(sum.getMemo1());
				for (HashMap hashMap : lhm1) {
					//根据岗位配置人数，从1开始循环，匹配人员基础信息表当前机台、班次的人员（编号、姓名）
					List<HashMap> lhm2=this.getMapper(MesShiftMMapper.class).doQueryEmp2Web( sum.getMemo1(),hashMap.get("POST_CODE"),wrk_grp,hashMap.get("POST_EMP_NUM"));
					for (HashMap hashMap2 : lhm2) {
						//插入记录到作业人员情况表
						this.getMapper(MesShiftMMapper.class).doInsert2(sum.getMemo1(), sum.getMemo2(), wrk_ord, idx, hashMap2.get("EMP_NO"),
								hashMap2.get("EMP_NAME"),hashMap.get("POST_CODE"),hashMap.get("POST_DESC"),userName);
						idx++;
					}
				}
				
				//3.根据当前接班“班次”，计算班次开始、结束时间，并按一个小时的间隔创建“岗位交接班班中情况记录”
				Date v_from;
				Integer v_hour=0;
				if ("1".equals(wrk_ord)) {
					v_hour = 8;
				}else if ("2".equals(wrk_ord)) {
					v_hour = 10;
				}else if ("3".equals(wrk_ord)) {
					v_hour = 6;
				}
				String v_time="";
				
				//页面
				String page=sum.getMemo1();
				//根据传入的日期、班次，计算班次的开始时间
				String date="";
				if("1".equals(wrk_ord)){
					date=sum.getMemo2()+" "+"00:00:00";
					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
					Long ti=(long) (24*60*60*1000);
					v_from=new Date(v_from.getTime()-ti);
				}else if("2".equals(wrk_ord)){
					//剪切区改为06点
					date=sum.getMemo2()+" "+"08:00:00";
					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
				}else if("3".equals(wrk_ord)){
					//剪切区改为06点
					date=sum.getMemo2()+" "+"18:00:00";
					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
				}else{
					rm.setState("500");
					rm.setMsgInfo("班次代码无效！");
					return rm;
				}
				//先删除可能存在的班中情况记录
				this.getMapper(MesShiftMMapper.class).doDeleteNotes(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//根据计算出的班次开始时间，按一个小时的间隔，生成报告时段（格式如：20:00 - 20:59），按顺序插入班中情况记录表
				for(int i=1;i<=v_hour;i++){
					Long tii=(long) (60*60*1000-1000);
					v_time=new SimpleDateFormat("HH:mm").format(v_from)+"-"+ new SimpleDateFormat("HH:mm").format(new Date(v_from.getTime()+tii));
					this.getMapper(MesShiftMMapper.class).doInsertNodes(sum.getMemo1(),sum.getMemo2(),wrk_ord,i,v_time,userName);
					v_from=new Date(v_from.getTime()+(60*60*1000));
				}
				
				//4.根据当前机台配置的点检项目，自动创建“岗位交接班点检记录”
				int idxx=1;
				//先删除可能存在的（工具及卫生）点检记录
				this.getMapper(MesShiftMMapper.class).doDeleteCheck(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的点检项目，循环插入记录
				List<HashMap> lhm3=this.getMapper(MesShiftMMapper.class).doQueryConfiCheck(sum.getMemo1());
				for (HashMap hashMap : lhm3) {
					this.getMapper(MesShiftMMapper.class).doInsertCheck(sum.getMemo1(),sum.getMemo2(),wrk_ord,hashMap.get("CHECK_ITEM_CODE"),
							hashMap.get("CHECK_ITEM_NAME"),hashMap.get("CHECK_ITEM_TYPE_C"),hashMap.get("CHECK_ITEM_TYPE_N"),idxx,userName);
					idxx++;
				}
				
				
				//5.根据当前机台配置的消耗项目，自动创建“岗位交接班消耗记录”
				int idxxx=1;
				//先删除可能存在的消耗记录
				this.getMapper(MesShiftMMapper.class).doDeleteCsm(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的消耗项目，循环插入记录
				List<HashMap> lhm4=this.getMapper(MesShiftMMapper.class).doQueryCsm(sum.getMemo1());
				for (HashMap hashMap : lhm4) {
					this.getMapper(MesShiftMMapper.class).doInsertCsm(sum.getMemo1(),sum.getMemo2(),wrk_ord,
							hashMap.get("CSM_ITEM_CODE"),hashMap.get("CSM_ITEM_NAME"),
							hashMap.get("CSM_ITEM_UNIT"),idxxx,userName);
					idxxx++;
				}
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("接班失败！\n"+ex.getMessage());
			throw new Exception("接班失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 退火炉
	 *动作处理-接班按钮
	 *
	 * @param sum
	 * memo1: V_MCH_CODE  
	 * memo2: V_WRK_DATE
	 *  // memo3: 登录用户名
	 * memo4: V_WRK_ORD代表的班次名称
	 * @return
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doTurnWeb_tuihuo(CommonPage<MesShiftM> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{	
				String wrk_ord=sum.getObject().getWrk_ord();
//				if(!"1".equals(wrk_ord)&&!"2".equals(wrk_ord)){
//					rm.setState("500");
//					rm.setMsgInfo("班次代码无效！");
//					return rm;
//				}
				String wrk_grp=sum.getObject().getWrk_grp();
//				if(!"1".equals(wrk_grp)&&!"2".equals(wrk_grp)&&!"3".equals(wrk_grp)&&!"4".equals(wrk_grp)){
//					rm.setState("500");
//					rm.setMsgInfo("班组代码无效！");
//					return rm;
//				}
				List<HashMap> lhm=this.getMapper(MesShiftMMapper.class).doQuery1(sum.getMemo1(),sum.getMemo2(),sum.getObject().getWrk_ord());
				if(lhm!=null && lhm.size()>0){
					Object object = lhm.get(0).get("CNT");
					//int ob=(int) object;
					int ob=Integer.parseInt( object.toString());
					if(ob>0){
						rm.setState("500");
						rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo4()+"\n已接班，不能重复操作！");
						return rm;
					}
				}
				this.getMapper(MesShiftMMapper.class).doDelete(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				
				String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
				//userName="测试";
				
				this.getMapper(MesShiftMMapper.class).doInsert(sum.getMemo1(),sum.getMemo2(),wrk_ord,wrk_grp,userName);
				
				//2.读取岗位配置表、人员信息表（MES_SHIFT_CONFIG_POST、MES_SHIFT_BASE_EMP），获取当前机台交接班配置的岗位名称及人数，根据此配置自动创建“岗位交接班作业人员记录”
				long idx=1;
				//先删除可能存在的人员记录
				this.getMapper(MesShiftMMapper.class).doDeleteEmp(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的交接班岗位信息（代码、名称、配置人数），按显示顺序排序进入循环
				List<HashMap> lhm1=this.getMapper(MesShiftMMapper.class).doQueryPost(sum.getMemo1());
				for (HashMap hashMap : lhm1) {
					//根据岗位配置人数，从1开始循环，匹配人员基础信息表当前机台、班次的人员（编号、姓名）
					List<HashMap> lhm2=this.getMapper(MesShiftMMapper.class).doQueryEmp2Web( sum.getMemo1(),hashMap.get("POST_CODE"),wrk_grp,hashMap.get("POST_EMP_NUM"));
					for (HashMap hashMap2 : lhm2) {
						//插入记录到作业人员情况表
						this.getMapper(MesShiftMMapper.class).doInsert2(sum.getMemo1(), sum.getMemo2(), wrk_ord, idx, hashMap2.get("EMP_NO"),
								hashMap2.get("EMP_NAME"),hashMap.get("POST_CODE"),hashMap.get("POST_DESC"),userName);
						idx++;
					}
				}
				
				//3.根据当前接班“班次”，计算班次开始、结束时间，并按一个小时的间隔创建“岗位交接班班中情况记录”
				Date v_from;
				Integer v_bai_hour=10;
				Integer v_wan_hour=14;
				String v_time="";
				
				//根据传入的日期、班次，计算班次的开始时间
				String date="";
				if("1".equals(wrk_ord)){
					//晚班从前一天18点开始
					date=sum.getMemo2()+" "+DateUtil.EndTime;
					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
					Long ti=(long) (24*60*60*1000);
					v_from=new Date(v_from.getTime()-ti);
				}else if("2".equals(wrk_ord)){
					//白班从当天08点开始
					date=sum.getMemo2()+" "+DateUtil.BeginTime;
					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
				}else{
					rm.setState("500");
					rm.setMsgInfo("班次代码无效！");
					return rm;
				}
//				if("1".equals(wrk_ord)){
//					//晚班从前一天20点开始
//					date=sum.getMemo2()+" 20:00:00";
//					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
//					Long ti=(long) (24*60*60*1000);
//				    v_from=new Date(v_from.getTime()-ti);
//				}else if("2".equals(wrk_ord)){
//					//白班从当天08点开始
//					date=sum.getMemo2()+" 08:00:00";
//					v_from=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
//				}else{
//					rm.setState("500");
//					rm.setMsgInfo("班次代码无效！");
//					return rm;
//				}
				//先删除可能存在的班中情况记录
				this.getMapper(MesShiftMMapper.class).doDeleteNotes(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//根据计算出的班次开始时间，按一个小时的间隔，生成报告时段（格式如：20:00 - 20:59），按顺序插入班中情况记录表
				if("2".equals(wrk_ord)){//早班
					for(int i=1;i<=v_bai_hour;i++){
						Long tii=(long) (60*60*1000-1000);
						v_time=new SimpleDateFormat("HH:mm").format(v_from)+"-"+
							new SimpleDateFormat("HH:mm").format(new Date(v_from.getTime()+tii));
						this.getMapper(MesShiftMMapper.class).doInsertNodes(sum.getMemo1(),sum.getMemo2(),wrk_ord,i,v_time,userName);
						v_from=new Date(v_from.getTime()+(60*60*1000));
					}
				}else if("1".equals(wrk_ord)){//晚班
					for(int i=1;i<=v_wan_hour;i++){
						Long tii=(long) (60*60*1000-1000);
						v_time=new SimpleDateFormat("HH:mm").format(v_from)+"-"+
							new SimpleDateFormat("HH:mm").format(new Date(v_from.getTime()+tii));
						this.getMapper(MesShiftMMapper.class).doInsertNodes(sum.getMemo1(),sum.getMemo2(),wrk_ord,i,v_time,userName);
						v_from=new Date(v_from.getTime()+(60*60*1000));
					}
				}
				
				
				//4.根据当前机台配置的点检项目，自动创建“岗位交接班点检记录”
				int idxx=1;
				//先删除可能存在的（工具及卫生）点检记录
				this.getMapper(MesShiftMMapper.class).doDeleteCheck(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的点检项目，循环插入记录
				List<HashMap> lhm3=this.getMapper(MesShiftMMapper.class).doQueryConfiCheck(sum.getMemo1());
				for (HashMap hashMap : lhm3) {
					this.getMapper(MesShiftMMapper.class).doInsertCheck(sum.getMemo1(),sum.getMemo2(),wrk_ord,hashMap.get("CHECK_ITEM_CODE"),
							hashMap.get("CHECK_ITEM_NAME"),hashMap.get("CHECK_ITEM_TYPE_C"),hashMap.get("CHECK_ITEM_TYPE_N"),idxx,userName);
					idxx++;
				}
				
				
				//5.根据当前机台配置的消耗项目，自动创建“岗位交接班消耗记录”
				int idxxx=1;
				//先删除可能存在的消耗记录
				this.getMapper(MesShiftMMapper.class).doDeleteCsm(sum.getMemo1(),sum.getMemo2(),wrk_ord);
				//找到当前机台配置的消耗项目，循环插入记录
				List<HashMap> lhm4=this.getMapper(MesShiftMMapper.class).doQueryCsm(sum.getMemo1());
				for (HashMap hashMap : lhm4) {
					this.getMapper(MesShiftMMapper.class).doInsertCsm(sum.getMemo1(),sum.getMemo2(),wrk_ord,
							hashMap.get("CSM_ITEM_CODE"),hashMap.get("CSM_ITEM_NAME"),
							hashMap.get("CSM_ITEM_UNIT"),idxxx,userName);
					idxxx++;
				}
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("接班失败！\n"+ex.getMessage());
			throw new Exception("接班失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	
	
	/**
	 *动作处理-取消接班按钮
	 * @param sum
	 * memo1: V_MCH_CODE  
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD代表的班次名称  班次名称
	 * @return
	 * 
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doTurnCancelWeb(CommonPage<MesShiftM> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try {
			String wrk_ord=sum.getObject().getWrk_ord();
//			if(!"1".equals(wrk_ord)&&!"2".equals(wrk_ord) &&!"3".equals(wrk_ord) ){
//				rm.setState("500");
//				rm.setMsgInfo("班次代码无效！");
//				return rm;
//			}
			Integer icount;
			String condition="machine_code='"+sum.getMemo1()+"' and wrk_date='"+sum.getMemo2()+"' and wrk_ord='"+wrk_ord+"'";
			List<MesShiftM> lmsm = this.getMapper(MesShiftMMapper.class).findWithCondition(null, condition, null, 0, 0);
			icount=lmsm.size();
			if(icount<=0){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo3()+"\n暂无交接班记录！");
				return rm;
			}
			MesShiftM msm = lmsm.get(0);
			if(!"1".equals(msm.getCarry_on())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo3()+"\n还未接班，无法取消！");
				return rm;
			}
			if("1".equals(msm.getTurn_off())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo3()+"\n已交班，不能取消接班，如有必要，请取消交班再操作！");
				return rm;
			}
			this.getMapper(MesShiftMMapper.class).doDelete(sum.getMemo1(), sum.getMemo2(), wrk_ord);
			this.getMapper(MesShiftMMapper.class).doDeleteEmp(sum.getMemo1(), sum.getMemo2(), wrk_ord);
			this.getMapper(MesShiftMMapper.class).doDeleteNotes(sum.getMemo1(), sum.getMemo2(), wrk_ord);
			this.getMapper(MesShiftMMapper.class).doDeleteCheck(sum.getMemo1(), sum.getMemo2(), wrk_ord);
			this.getMapper(MesShiftMMapper.class).doDeleteCsm(sum.getMemo1(), sum.getMemo2(), wrk_ord);
			this.getMapper(MesShiftMMapper.class).doDeleteBld(sum.getMemo1(),sum.getMemo2(),wrk_ord);
			this.getMapper(MesShiftMMapper.class).doDeleteRmv(sum.getMemo1(),sum.getMemo2(),wrk_ord);
			
			
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("取消接班失败！\n"+ex.getMessage());
			throw new Exception("取消接班失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 开平-横剪
	 *动作处理-取消接班按钮
	 * @param sum
	 * memo1: V_MCH_CODE  
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD代表的班次名称  班次名称
	 * @return
	 * 
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doTurnCancelWeb2(CommonPage<MesShiftM> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try {
			String wrk_ord=sum.getObject().getWrk_ord();
//			if(!"1".equals(wrk_ord)&&!"2".equals(wrk_ord)){
//				rm.setState("500");
//				rm.setMsgInfo("班次代码无效！");
//				return rm;
//			}
			Integer icount;
			String condition="machine_code='"+sum.getMemo1()+"' and wrk_date='"+sum.getMemo2()+"' and wrk_ord='"+wrk_ord+"'";
			List<MesShiftM> lmsm = this.getMapper(MesShiftMMapper.class).findWithCondition(null, condition, null, 0, 0);
			icount=lmsm.size();
			if(icount<=0){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo3()+"\n暂无交接班记录！");
				return rm;
			}
			MesShiftM msm = lmsm.get(0);
			if(!"1".equals(msm.getCarry_on())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo3()+"\n还未接班，无法取消！");
				return rm;
			}
			if("1".equals(msm.getTurn_off())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo3()+"\n已交班，不能取消接班，如有必要，请取消交班再操作！");
				return rm;
			}
			this.getMapper(MesShiftMMapper.class).doDelete(sum.getMemo1(), sum.getMemo2(), wrk_ord);
			this.getMapper(MesShiftMMapper.class).doDeleteEmp(sum.getMemo1(), sum.getMemo2(), wrk_ord);
			this.getMapper(MesShiftMMapper.class).doDeleteNotes(sum.getMemo1(), sum.getMemo2(), wrk_ord);
			this.getMapper(MesShiftMMapper.class).doDeleteCheck(sum.getMemo1(), sum.getMemo2(), wrk_ord);
			this.getMapper(MesShiftMMapper.class).doDeleteCsm(sum.getMemo1(), sum.getMemo2(), wrk_ord);
			//this.getMapper(MesShiftMMapper.class).doDeleteBld(sum.getMemo1(),sum.getMemo2(),wrk_ord);
			//this.getMapper(MesShiftMMapper.class).doDeleteRmv(sum.getMemo1(),sum.getMemo2(),wrk_ord);
			
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("取消接班失败！\n"+ex.getMessage());
			throw new Exception("取消接班失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 *动作处理-保存按钮
	 * @param sum
	 *  //memo1: 登录用户名
	 * @return
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doSaveWeb(CommonPage<MesShiftMSum> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try {
			String wrk_ord=sum.getObject().getV_wrk_ord();
//			if(!"1".equals(wrk_ord)&&!"2".equals(wrk_ord)){
//				rm.setState("500");
//				rm.setMsgInfo("班次代码无效！");
//				return rm;
//			}
			Integer icount;
			String condition="machine_code='"+sum.getObject().getV_mch_code()+"' and wrk_date='"+sum.getObject().getV_wrk_date()+"' and wrk_ord='"+wrk_ord+"'";
			List<MesShiftM> lmsm = this.getMapper(MesShiftMMapper.class).findWithCondition(null, condition, null, 0, 0);
			icount=lmsm.size();
			if(icount<=0){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getObject().getV_wrk_date()+"\n班次："+sum.getObject().getWrk_ord_name()+"\n暂无交接班记录！");
				return rm;
			}
			MesShiftM msm = lmsm.get(0);
			if(!"1".equals(msm.getCarry_on())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getObject().getV_wrk_date()+"\n班次："+sum.getObject().getWrk_ord_name()+"\n还未接班，无法保存数据！");
				return rm;
			}
			if("1".equals(msm.getTurn_off())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getObject().getV_wrk_date()+"\n班次："+sum.getObject().getWrk_ord_name()+"\n已交班，不能保存数据，如有必要，请取消交班再操作！");
				return rm;
			}
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			List<MesShiftDEmp> lmsde = sum.getObject().getLmsde();
			if(lmsde!=null && lmsde.size()>0){
				for (MesShiftDEmp mesShiftDEmp : lmsde) {
					if(mesShiftDEmp.getDisplay_order()!=null){
						this.getMapper(MesShiftMMapper.class).doUpdateEmp(mesShiftDEmp.getEmp_no(),mesShiftDEmp.getEmp_name(),
								userName,sum.getObject().getV_mch_code(),sum.getObject().getV_wrk_date(),
								sum.getObject().getV_wrk_ord(),mesShiftDEmp.getDisplay_order());
					}
				}
			}
			
			List<MesShiftDNotes> lmsdn = sum.getObject().getLmsdn();
			if(lmsdn!=null && lmsdn.size()>0){
				for (MesShiftDNotes m : lmsdn) {
					if(m.getDisplay_order()!=null){
						this.getMapper(MesShiftMMapper.class).doUpdateDnotes(m.getProduce_notes(),userName,
								sum.getObject().getV_mch_code(),sum.getObject().getV_wrk_date(),
								sum.getObject().getV_wrk_ord(),m.getDisplay_order());
					}
				}
			}
			List<MesShiftDCheck> lmsdc = sum.getObject().getLmsdc();
			if(lmsdc!=null && lmsdc.size()>0){
				for (MesShiftDCheck m : lmsdc) {
					if(m.getDisplay_order()!=null){
						this.getMapper(MesShiftMMapper.class).doUpdateCheck(m.getCheck_result(),m.getCheck_desc(),
								userName,sum.getObject().getV_mch_code(),
								sum.getObject().getV_wrk_date(),sum.getObject().getV_wrk_ord(),m.getDisplay_order());
					}
				}
			}
			
			List<MesShiftDCsm> lmsdcm = sum.getObject().getLmsdcm();
			if(lmsdcm !=null && lmsdcm.size()>0){
				for (MesShiftDCsm m : lmsdcm) {
					if(m.getDisplay_order()!=null){
						this.getMapper(MesShiftMMapper.class).doUpdateCsm(m.getConsumption(),userName,
								sum.getObject().getV_mch_code(),sum.getObject().getV_wrk_date(),
								sum.getObject().getV_wrk_ord(),m.getDisplay_order());
					}
				}
			}
			
//			List<MesCrSlittingMTemp> lmcsm = sum.getObject().getLmcsm();
//			if(lmcsm!=null && lmcsm.size()>0){
//				for (MesCrSlittingMTemp m : lmcsm) {
//					if(m.getProcess_no()!=null){
//						this.getMapper(MesShiftMMapper.class).doUpdateCrSlit(m.getSet_str_time(),
//								m.getSet_end_time(),m.getSet_opr1(),m.getSet_opr2(),
//								m.getSet_opr3(),m.getRmv_str_time(),m.getRmv_end_time(),
//								m.getRmv_opr1(),m.getRmv_opr2(),m.getRmv_opr3(),userName,
//								m.getProcess_no());
//					}
//				}
//			}
			
			List<MesShiftDBldSet> lmsdbs = sum.getObject().getLmsdbs();
			this.getMapper(MesShiftMMapper.class).doDeleteBld(sum.getObject().getV_mch_code(),sum.getObject().getV_wrk_date(), sum.getObject().getV_wrk_ord());
			int idddd=0;
			if(lmsdbs!=null && lmsdbs.size()>0){
				for(MesShiftDBldSet m:lmsdbs){
					idddd++;
					this.getMapper(MesShiftMMapper.class).doInsertBld1(sum.getObject().getV_mch_code(),sum.getObject().getV_wrk_date(), 
							sum.getObject().getV_wrk_ord(),idddd,m.getSet_str_time(),m.getSet_end_time(),
							m.getSet_opr1(),m.getSet_opr2(),m.getSet_opr3(),userName
							);
				}
			}
			
			List<MesShiftDBldRmv> lmsdbr = sum.getObject().getLmsdbr();
			this.getMapper(MesShiftMMapper.class).doDeleteRmv(sum.getObject().getV_mch_code(),sum.getObject().getV_wrk_date(), sum.getObject().getV_wrk_ord());
			int ddxdd=0;
			if(lmsdbr!=null && lmsdbr.size()>0){
				for(MesShiftDBldRmv m:lmsdbr){
					ddxdd++;
					this.getMapper(MesShiftMMapper.class).doInsertRmv1(sum.getObject().getV_mch_code(),sum.getObject().getV_wrk_date()
							,sum.getObject().getV_wrk_ord(),ddxdd,m.getRmv_str_time(),m.getRmv_end_time(),
							m.getRmv_opr1(),m.getRmv_opr2(),m.getRmv_opr3(),userName);
				}
			}
			
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("保存失败！\n"+ex.getMessage());
			throw new Exception("保存失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 开平-横剪
	 *动作处理-保存按钮
	 * @param sum
	 *  //memo1: 登录用户名
	 * @return
	 */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doSaveWeb2(CommonPage<MesShiftMSum> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try {
			String wrk_ord=sum.getObject().getV_wrk_ord();
//			if(!"1".equals(wrk_ord)&&!"2".equals(wrk_ord)){
//				rm.setState("500");
//				rm.setMsgInfo("班次代码无效！");
//				return rm;
//			}
			Integer icount;
			String condition="machine_code='"+sum.getObject().getV_mch_code()+"' and wrk_date='"+sum.getObject().getV_wrk_date()+"' and wrk_ord='"+wrk_ord+"'";
			List<MesShiftM> lmsm = this.getMapper(MesShiftMMapper.class).findWithCondition(null, condition, null, 0, 0);
			icount=lmsm.size();
			if(icount<=0){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getObject().getV_wrk_date()+"\n班次："+sum.getObject().getWrk_ord_name()+"\n暂无交接班记录！");
				return rm;
			}
			MesShiftM msm = lmsm.get(0);
			if(!"1".equals(msm.getCarry_on())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getObject().getV_wrk_date()+"\n班次："+sum.getObject().getWrk_ord_name()+"\n还未接班，无法保存数据！");
				return rm;
			}
			if("1".equals(msm.getTurn_off())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getObject().getV_wrk_date()+"\n班次："+sum.getObject().getWrk_ord_name()+"\n已交班，不能保存数据，如有必要，请取消交班再操作！");
				return rm;
			}
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			List<MesShiftDEmp> lmsde = sum.getObject().getLmsde();
			if(lmsde!=null && lmsde.size()>0){
				for (MesShiftDEmp mesShiftDEmp : lmsde) {
					if(mesShiftDEmp.getDisplay_order()!=null){
						this.getMapper(MesShiftMMapper.class).doUpdateEmp(mesShiftDEmp.getEmp_no(),mesShiftDEmp.getEmp_name(),
								userName,sum.getObject().getV_mch_code(),sum.getObject().getV_wrk_date(),
								sum.getObject().getV_wrk_ord(),mesShiftDEmp.getDisplay_order());
					}
				}
			}
			
			List<MesShiftDNotes> lmsdn = sum.getObject().getLmsdn();
			if(lmsdn!=null && lmsdn.size()>0){
				for (MesShiftDNotes m : lmsdn) {
					if(m.getDisplay_order()!=null){
						this.getMapper(MesShiftMMapper.class).doUpdateDnotes(m.getProduce_notes(),userName,
								sum.getObject().getV_mch_code(),sum.getObject().getV_wrk_date(),
								sum.getObject().getV_wrk_ord(),m.getDisplay_order());
					}
				}
			}
			List<MesShiftDCheck> lmsdc = sum.getObject().getLmsdc();
			if(lmsdc!=null && lmsdc.size()>0){
				for (MesShiftDCheck m : lmsdc) {
					if(m.getDisplay_order()!=null){
						this.getMapper(MesShiftMMapper.class).doUpdateCheck(m.getCheck_result(),m.getCheck_desc(),
								userName,sum.getObject().getV_mch_code(),
								sum.getObject().getV_wrk_date(),sum.getObject().getV_wrk_ord(),m.getDisplay_order());
					}
				}
			}
			
			List<MesShiftDCsm> lmsdcm = sum.getObject().getLmsdcm();
			if(lmsdcm !=null && lmsdcm.size()>0){
				for (MesShiftDCsm m : lmsdcm) {
					if(m.getDisplay_order()!=null){
						this.getMapper(MesShiftMMapper.class).doUpdateCsm(m.getConsumption(),userName,
								sum.getObject().getV_mch_code(),sum.getObject().getV_wrk_date(),
								sum.getObject().getV_wrk_ord(),m.getDisplay_order());
					}
				}
			}
			
			
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("保存失败！\n"+ex.getMessage());
			throw new Exception("保存失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	
	
	
	
	/**
	 * 动作处理-交班按钮
	 * @param sum
	 * memo1: V_MCH_CODE
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD
	 * memo4: V_WRK_ORD代表的班次名称  班次名称
	 * @return
	 */
	public ResultModel doWorkWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try {
			String wrk_ord=sum.getMemo3();
//			if(!"1".equals(wrk_ord)&&!"2".equals(wrk_ord)){
//				rm.setState("500");
//				rm.setMsgInfo("班次代码无效！");
//				return rm;
//			}
			Integer icount;
			String condition="machine_code='"+sum.getMemo1()+"' and wrk_date='"+sum.getMemo2()+"' and wrk_ord='"+wrk_ord+"'";
			List<MesShiftM> lmsm = this.getMapper(MesShiftMMapper.class).findWithCondition(null, condition, null, 0, 0);
			icount=lmsm.size();
			if(icount<=0){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo4()+"\n暂无交接班记录！");
				return rm;
			}
			MesShiftM msm = lmsm.get(0);
			if(!"1".equals(msm.getCarry_on())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo4()+"\n还未接班，无法交班！");
				return rm;
			}
			if("1".equals(msm.getTurn_off())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo4()+"\n已交班，不能重复操作！");
				return rm;
			}
			
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			this.getMapper(MesShiftMMapper.class).doUpdateM(userName,sum.getMemo1(),sum.getMemo2(),sum.getMemo3());
			rm.setState("200");
		} catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("交班失败！\n"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 动作处理-取消交班按钮
	 * @param sum
	 * memo1: V_MCH_CODE
	 * memo2: V_WRK_DATE
	 * memo3: V_WRK_ORD
	 * memo4: V_WRK_ORD代表的班次名称  班次名称
	 * @return
	 */
	public ResultModel doWorkCancelWeb(CommonPage<MesShiftM> sum){
		ResultModel rm=new ResultModel();
		try {
			String wrk_ord=sum.getMemo3();
//			if(!"1".equals(wrk_ord)&&!"2".equals(wrk_ord)){
//				rm.setState("500");
//				rm.setMsgInfo("班次代码无效！");
//				return rm;
//			}
			Integer icount;
			String condition="machine_code='"+sum.getMemo1()+"' and wrk_date='"+sum.getMemo2()+"' and wrk_ord='"+wrk_ord+"'";
			List<MesShiftM> lmsm = this.getMapper(MesShiftMMapper.class).findWithCondition(null, condition, null, 0, 0);
			icount=lmsm.size();
			if(icount<=0){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo4()+"\n暂无交接班记录！");
				return rm;
			}
			MesShiftM msm = lmsm.get(0);
			if(!"1".equals(msm.getCarry_on())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo4()+"\n还未接班！");
				return rm;
			}
			if(!"1".equals(msm.getTurn_off())){
				rm.setState("500");
				rm.setMsgInfo("日期："+sum.getMemo2()+"\n班次："+sum.getMemo4()+"\n还未交班！");
				return rm;
			}
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			this.getMapper(MesShiftMMapper.class).doUpdateM2(userName,sum.getMemo1(),sum.getMemo2(),sum.getMemo3());
			rm.setState("200");
		}
		catch (Exception ex) {
			rm.setState("500");
			rm.setMsgInfo("取消交班失败！\n"+ex.getMessage());
		}	
		return rm;
	}
	
}



