/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-09-29
 * 描述            ：工器具-刀片修磨记录
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Mes.Dev.impl;
import java.util.Date;
import java.util.List;

import market.Cm.mapper.CmCostDstGrindMapper;
import market.Cm.vo.CmCostDstGrind;
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.DevBladeGrindingBldMapper;
import market.Mes.Dev.mapper.DevBladeGrindingCdMapper;
import market.Mes.Dev.mapper.DevBladeGrindingMapper;
import market.Mes.Dev.mapper.DevBladeGrpMapper;
import market.Mes.Dev.mapper.DevBladeInfoMapper;
import market.Mes.Dev.service.DevBladeGrindingService;
import market.Mes.Dev.vo.DevBladeGrinding;
import market.Mes.Dev.vo.DevBladeGrindingBld;
import market.Mes.Dev.vo.DevBladeGrindingCd;
import market.Mes.Dev.vo.DevBladeGrp;
import market.Mes.Dev.vo.DevBladeInfo;

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;
import com.ibm.icu.text.SimpleDateFormat;

@RemoteService(path="DevBladeGrindingService")
public class DevBladeGrindingServiceImpl extends BaseServiceImpl<DevBladeGrinding,Object> implements DevBladeGrindingService {
	
	/**
	 * 动作处理_刷新（修磨记录）按钮
	  memo1：机台代码
	  memo2: 分组代码
	  startTime:送修日期的开始时间
	  endTime：送修日期的结束时间
	  startTime2：返回日期的开始时间
	  endTime2：返回日期的结束时间
	 * */
	public ResultModel doQueryWeb(CommonPage<DevBladeGrinding> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(DevBladeGrindingMapper.class).doQueryWeb(oci.getMemo1(),oci.getMemo2(),oci.getStartTime(),oci.getEndTime(),oci.getStartTime2(),oci.getEndTime2()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 动作处理_修磨记录行选中
	 * “处置过程”处理：
	  memo1：修磨记录号，赋值为修磨记录表格选中行的修磨记录号，并传入后台；
	 * */
	public ResultModel doQuery2Web(CommonPage<DevBladeGrinding> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(DevBladeGrindingCdMapper.class).doQueryWeb(oci.getMemo1()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 动作处理_修磨记录行选中
	 * “刀片明细”处理：
	  memo1：修磨记录号，赋值为修磨记录表格选中行的修磨记录号，并传入后台；
	 * */
	public ResultModel doQuery3Web(CommonPage<DevBladeGrinding> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(DevBladeGrindingBldMapper.class).doQueryWeb(oci.getMemo1()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 动作处理_新增（修磨记录）按钮
	  memo1：机台代码
	  memo2: 分组代码
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAddWeb(CommonPage<DevBladeInfo> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			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;
			}
		    //  --验证机台基础信息存在
			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.4)、验证刀片分组存在
			v_cnt = this.getMapper(DevBladeGrpMapper.class).countWithCondition(null, "grp_code='"+sum.getMemo2()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("分组代码{"+sum.getMemo2()+"} 刀片分组信息不存在！");
				return rm;
			}
			DevBladeGrp v_rec_grp = this.getMapper(DevBladeGrpMapper.class).findById(sum.getMemo2());
			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='"+sum.getMemo2()+"'");
		    if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("刀片分组{"+v_rec_grp.getGrp_name()+"} 系统中暂无此分组的刀片信息，请先维护刀片信息！");
				return rm;
			}
			//  --(1.6)、验证存在待磨刀片
			DevBladeInfo dbi=new DevBladeInfo();
			dbi.setGrp_code(sum.getMemo2());
			dbi.setStatus("1");
			v_cnt=this.getMapper(DevBladeInfoMapper.class).count(dbi);
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("刀片分组{"+v_rec_grp.getGrp_name()+"} 暂无待磨刀片，请在基础信息中指定！");
				return rm;
			}
			//  --(2)、验证当班刀片组无待处置的修磨记录
			v_cnt=this.getMapper(DevBladeGrindingMapper.class).doCount(sum.getMemo1(),sum.getMemo2());
			if(v_cnt>0){
				rm.setState("500");
				rm.setMsgInfo("刀片分组{"+v_rec_grp.getGrp_name()+"} 存在未处置结束的修磨记录，暂不允许此操作！");
				return rm;
			}
			//  --(3)、修磨记录号：'G' + YYMMDD + 3位流水
			String v_serial_no="G"+new SimpleDateFormat("yyMMdd").format(new Date());
			//  --(3.1)、获取当前起始流水号
			Integer v_cnt1=this.getMapper(DevBladeGrindingMapper.class).doCount2(v_serial_no);
			if(v_cnt1==null){
				v_cnt1=1;
			}else if(v_cnt1>999){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号超出规则范围，流水号超出最大值999！");
				return rm;
			}
			v_serial_no=v_serial_no+lpad(v_cnt1+"",3,"0");
			//  --(4)、修磨序号
			v_cnt=this.getMapper(DevBladeGrindingMapper.class).doCount3(sum.getMemo1(),sum.getMemo2());
			Long grd_sqc=Long.parseLong(v_cnt+"");
			//  --(5)、开始事物																																							
			//  --(5.1)、新增修磨主记录（未指定的字段，全为NULL）																																							
			DevBladeGrinding dbg=new DevBladeGrinding();
			dbg.setSerial_no(v_serial_no);
			dbg.setMachine_code(sum.getMemo1());
			dbg.setGrp_code(sum.getMemo2());
			dbg.setGrp_name(v_rec_grp.getGrp_name());
			dbg.setGrd_sqc(grd_sqc);
			dbg.setStr_date(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
			dbg.setCreate_opr(userName);
			dbg.setCreate_time(new Date());
			this.getMapper(DevBladeGrindingMapper.class).insert(dbg);
			//  --(5.2)、新增修磨刀片明细记录（未指定的字段，全为NULL）																																							
			//  --(5.2.1)、刀片当前状体为待磨时（status = '1'），自动设置为本次修磨（grd_flag := '1'）																																							
			List<DevBladeInfo> ldbi=this.getMapper(DevBladeInfoMapper.class).doQuery4(sum.getMemo2());
			for(DevBladeInfo cur_01:ldbi){
				DevBladeGrindingBld dbgb=new DevBladeGrindingBld();
				dbgb.setSerial_no(v_serial_no);
				dbgb.setBlade_no(cur_01.getBlade_no());
				dbgb.setStatus(cur_01.getStatus());
				dbgb.setCur_use_times(cur_01.getCur_use_times());
				dbgb.setDsp_order(cur_01.getDsp_order());
				if("1".equals(cur_01.getStatus())){
					dbgb.setGrd_flag("1");
				}else{
					dbgb.setGrd_flag("0");
				}
				dbgb.setDia_outer_bfr(cur_01.getDia_outer_cur());
				dbgb.setCreate_opr(userName);
				dbgb.setCreate_time(new Date());
				dbgb.setDia_outer_org(cur_01.getDia_outer_org());
				dbgb.setDia_outer_srp(cur_01.getDia_outer_srp());
				dbgb.setAmount_money(cur_01.getAmount_money());
				dbgb.setResidual_value(cur_01.getResidual_value());
				// 折算成本（(金额 - 残值) * (修磨前外径 - 修磨后外径) / (原始外径 - 报废外径)）
//				Double amount_money=dbgb.getAmount_money()==null?0:dbgb.getAmount_money();
//				Double residual_value=dbgb.getResidual_value()==null?0:dbgb.getResidual_value();
//				Double leo=(amount_money-residual_value)*(dbgb.getDia_outer_bfr()-dbgb.getDia_outer_aft())/(cur_01.getDia_outer_org()-cur_01.getDia_outer_srp());
//				leo=(leo==null?0:leo);
//				dbgb.setConverted_cost(DoubleUtil.round(leo, 2));
				this.getMapper(DevBladeGrindingBldMapper.class).insert(dbgb);
				//    --(5.2.2)、同时，将待磨刀片置为修磨状态
				if("1".equals(cur_01.getStatus())){ 
					this.getMapper(DevBladeInfoMapper.class).doUpdate3(cur_01.getBlade_no());
				}
			}
			//提交事务
			rm.setMsgInfo("新增成功");
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			throw new Exception("新增失败!"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 动作处理_修改（修磨记录）按钮
	 object:
	 相关信息
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdateWeb(CommonPage<DevBladeGrinding> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(userName==null){
				userName="";
			}
			DevBladeGrinding dbg = sum.getObject();
			if(dbg==null){
				rm.setState("500");
				rm.setMsgInfo("请输入参数！");
				return rm;
			}
			if(dbg.getSerial_no()==null || "".equals(dbg.getSerial_no())){
				rm.setState("500");
				rm.setMsgInfo("未指定修磨记录号！");
				return rm;
			}
			if(dbg.getStr_date()==null || "".equals(dbg.getStr_date())){
				rm.setState("500");
				rm.setMsgInfo("未指定送修日期！");
				return rm;
			}
			if(dbg.getConverted_cost()!=null){
				if(dbg.getConverted_cost()<0){
					rm.setState("500");
					rm.setMsgInfo("折算成本不能为负数！");
					return rm;
				}
			}
			
			//  --(1.3)、验证修磨费用
			if(dbg.getAmount_grd()!=null){
				if(dbg.getAmount_grd()<0){
					rm.setState("500");
					rm.setMsgInfo("修磨费用不能为负数！");
					return rm;
				}
			}
			if(dbg.getAmount_cps()!=null){
				if(dbg.getAmount_cps()<0){
					rm.setState("500");
					rm.setMsgInfo("赔偿金额不能为负数！");
					return rm;
				}
			}
			Integer v_cnt=this.getMapper(DevBladeGrindingMapper.class).countWithCondition(null, "serial_no='"+dbg.getSerial_no()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+dbg.getSerial_no()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevBladeGrinding> ldbgg = this.getMapper(DevBladeGrindingMapper.class).findWithCondition(null, "serial_no='"+dbg.getSerial_no()+"'", null, 0, 0);
			DevBladeGrinding v_rec_grd = ldbgg.get(0);
			if("1".equals(v_rec_grd.getDisposal_done())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+dbg.getSerial_no()+"} 已处置完毕，信息不允许修改！");
				return rm;
			}
			DevBladeGrinding dbgding=new DevBladeGrinding();
			dbgding.setStr_date(dbg.getStr_date());
			dbgding.setRtn_date(dbg.getRtn_date());
			dbgding.setConverted_cost(dbg.getConverted_cost());
			dbgding.setAmount_grd(dbg.getAmount_grd());
			dbgding.setAmount_cps(dbg.getAmount_cps());
			dbgding.setMemo(dbg.getMemo());
			dbgding.setUpdate_opr(userName);
			dbgding.setUpdate_time(new Date());
			dbgding.setSerial_no(dbg.getSerial_no());
		    this.getMapper(DevBladeGrindingMapper.class).update(dbgding);
			//提交事务
			rm.setMsgInfo("修改成功");
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			throw new Exception("修改失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 动作处理_删除（修磨记录）按钮
	 * memo1:修磨记录号
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doDeleteWeb(CommonPage<DevBladeGrinding> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			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;
			}
			
			Integer v_cnt=this.getMapper(DevBladeGrindingMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevBladeGrinding> ldbgg = this.getMapper(DevBladeGrindingMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
			DevBladeGrinding v_rec_grd = ldbgg.get(0);
			if("1".equals(v_rec_grd.getDisposal_done())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 已处置完毕，记录不允许删除！");
				return rm;
			}
			List<DevBladeGrindingBld> ldbgb = this.getMapper(DevBladeGrindingBldMapper.class).doQuery6Web(sum.getMemo1());
			for(DevBladeGrindingBld cur_01:ldbgb){
				DevBladeInfo dbi=new DevBladeInfo();
				dbi.setStatus(cur_01.getStatus());// --恢复为修磨前记录的状态
				dbi.setUpdate_opr(userName);
				dbi.setUpdate_time(new Date());
				dbi.setBlade_no(cur_01.getBlade_no());
				this.getMapper(DevBladeInfoMapper.class).update(dbi);
			}
			this.getMapper(DevBladeGrindingBldMapper.class).doDelete(sum.getMemo1());
			this.getMapper(DevBladeGrindingCdMapper.class).doDelete(sum.getMemo1());
			this.getMapper(DevBladeGrindingMapper.class).doDelete(sum.getMemo1());
			//提交事务
			rm.setMsgInfo("删除成功");
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			throw new Exception("删除失败!"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 动作处理_处置完毕按钮
	 * memo1:修磨记录号
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdate2Web(CommonPage<DevBladeGrinding> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			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;
			}
			
			Integer v_cnt=this.getMapper(DevBladeGrindingMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 修磨记录不存在！");
				return rm;
			}
		    v_cnt=this.getMapper(DevBladeGrindingCdMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 无鉴定处置记录，不允许此操作！");
				return rm;
			}
			
			List<DevBladeGrinding> ldbgg = this.getMapper(DevBladeGrindingMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
			DevBladeGrinding v_rec_grd = ldbgg.get(0);
			if(v_rec_grd.getRtn_date()==null || "".equals(v_rec_grd.getRtn_date())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 返回日期为空，不允许此操作！");
				return rm;
			}
			if("1".equals(v_rec_grd.getDisposal_done())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 已处置完毕，不允许此操作！");
				return rm;
			}
			if(v_rec_grd.getDisposal_result()==null){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 未知处置结果，不允许此操作！");
				return rm;
			}else if("1".equals(v_rec_grd.getDisposal_result())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 当前处置结果为“重修”，不允许此操作！");
				return rm;
			}else if(!"0".equals(v_rec_grd.getDisposal_result()) && !"9".equals(v_rec_grd.getDisposal_result())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 当前处置结果代码为{"+v_rec_grd.getDisposal_result()+"}，系统无法识别，不允许此操作！");
				return rm;
			}
			if(v_rec_grd.getDia_outer_aft()==null){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 未指定修磨后外径，不允许此操作！");
				return rm;
			}
			if(v_rec_grd.getDia_outer_aft()<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 修磨后外径必须大于零！");
				return rm;
			}
			if(v_rec_grd.getConverted_cost()==null){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 未填写折算成本，不允许此操作！");
				return rm;
			}
			if(v_rec_grd.getAmount_grd()==null){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 未填写修磨费用，不允许此操作！");
				return rm;
			}
			
			//判断成本期间内是否已经进行了归集
			CmCostDstGrind CCAP = new CmCostDstGrind();
			CCAP.setPrd_num(v_rec_grd.getRtn_date().substring(0,4)+v_rec_grd.getRtn_date().substring(5,7));//成本期间
			CCAP.setItem_name("刀片");
			CCAP.setAudit_flg("1");
			int count = this.getMapper(CmCostDstGrindMapper.class).count(CCAP);
			if (count > 0) {
				//throw new Exception("当前成本期间【"+sum.getMemo1().substring(0,4)+sum.getMemo1().substring(5,7)+"】已经进行刀片成本审核");
			}
			
			
			List<DevBladeGrindingBld> ldbgb = this.getMapper(DevBladeGrindingBldMapper.class).doQuery6Web(sum.getMemo1());
			for(DevBladeGrindingBld cur_01:ldbgb){
				if(cur_01.getDisposal_result()==null){
					rm.setState("500");
					rm.setMsgInfo("刀片编号{"+cur_01.getBlade_no()+"} 未知处置结果，不允许此操作！");
					return rm;
				}else if("1".equals(cur_01.getDisposal_result())){
					rm.setState("500");
					rm.setMsgInfo("刀片编号{"+cur_01.getBlade_no()+"} 当前处置结果为“重修”，不允许此操作！");
					return rm;
				}else if(!"0".equals(cur_01.getDisposal_result()) && !"9".equals(cur_01.getDisposal_result())){
					rm.setState("500");
					rm.setMsgInfo("刀片编号{"+cur_01.getBlade_no()+"} 当前处置结果代码为{"+cur_01.getDisposal_result()+"}，系统无法识别，不允许此操作！");
					return rm;
				}
				//    --(2.5.2)、验证修磨后外径
				if(cur_01.getDia_outer_aft()==null){
					rm.setState("500");
					rm.setMsgInfo("刀片编号{"+cur_01.getBlade_no()+"} 未指定修磨后外径，不允许此操作！");
					return rm;
				}
				if(cur_01.getDia_outer_aft()<=0){
					rm.setState("500");
					rm.setMsgInfo("刀片编号{"+cur_01.getBlade_no()+"} 修磨外径必须大于零！");
					return rm;
				}
			}
			for(DevBladeGrindingBld cur_01:ldbgb){
				this.getMapper(DevBladeInfoMapper.class).doUpdate2(cur_01,userName);
			}
			//  --(3.2)、修改修磨主记录处置完毕状态
			DevBladeGrinding dbgd=new DevBladeGrinding();
			dbgd.setDisposal_done("1");
			dbgd.setSerial_no(sum.getMemo1());
			dbgd.setUpdate_opr(userName);
			dbgd.setUpdate_time(new Date());
			this.getMapper(DevBladeGrindingMapper.class).update(dbgd);
			
			//提交事务
			rm.setMsgInfo("处置完毕成功");
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			throw new Exception("处置完毕失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 动作处理_撤销完毕按钮
	 * memo1:修磨记录号
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdate3Web(CommonPage<DevBladeGrinding> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			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;
			}
			
			Integer v_cnt=this.getMapper(DevBladeGrindingMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevBladeGrinding> ldbgg = this.getMapper(DevBladeGrindingMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
			DevBladeGrinding v_rec_grd = ldbgg.get(0);
			if(v_rec_grd.getDisposal_done()==null || !"1".equals(v_rec_grd.getDisposal_done())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 还未处置完毕，不允许此操作！");
				return rm;
			}
			v_cnt=this.getMapper(DevBladeGrindingMapper.class).doCount1(v_rec_grd.getMachine_code(),v_rec_grd.getGrp_code(),v_rec_grd.getGrd_sqc());
			if(v_cnt>0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 此次修磨后已有新的修磨记录，不允许此操作！");
				return rm;
			}
			
			List<DevBladeGrindingBld> ldbgb = this.getMapper(DevBladeGrindingBldMapper.class).doQuery6Web(sum.getMemo1());
			for(DevBladeGrindingBld cur_01:ldbgb){
				this.getMapper(DevBladeInfoMapper.class).doUpdate4(cur_01.getDia_outer_bfr(),cur_01.getCur_use_times(),userName,cur_01.getBlade_no());
			}
			//   --(3.2)、修改修磨主记录处置完毕状态为否
			DevBladeGrinding dbgd=new DevBladeGrinding();
			dbgd.setDisposal_done("0");
			dbgd.setSerial_no(sum.getMemo1());
			dbgd.setUpdate_opr(userName);
			dbgd.setUpdate_time(new Date());
			this.getMapper(DevBladeGrindingMapper.class).update(dbgd);
			//提交事务
			rm.setMsgInfo("撤销完毕成功");
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			throw new Exception("撤销完毕失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 *动作处理_新增（处置过程）按钮
	 * object:
	 * 相关信息
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAdd1Web(CommonPage<DevBladeGrindingCd> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(userName==null){
				userName="";
			}
			DevBladeGrindingCd dbgc = sum.getObject();
			if(dbgc==null){
				rm.setState("500");
				rm.setMsgInfo("请输入参数");
				return rm;
			}
			if(dbgc.getSerial_no()==null || "".equals(dbgc.getSerial_no())){
				rm.setState("500");
				rm.setMsgInfo("未指定修磨记录号！");
				return rm;
			}
			if(dbgc.getDia_outer_aft()==null){
				rm.setState("500");
				rm.setMsgInfo("未指定修磨后外径");
				return rm;
			}
			if(dbgc.getDia_outer_aft()<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨外径必须大于零！");
				return rm;
			}
			if(dbgc.getCheck_result()==null){
				rm.setState("500");
				rm.setMsgInfo("未指定鉴定结果！");
				return rm;
			}else if(!"0".equals(dbgc.getCheck_result()) && !"1".equals(dbgc.getCheck_result())){
				rm.setState("500");
				rm.setMsgInfo("鉴定结果代码{"+dbgc.getCheck_result()+"} 无法识别！代码说明：1：合格、0：不合格");
				return rm;
			}
			if(dbgc.getDisposal_result()==null){
				rm.setState("500");
				rm.setMsgInfo("未指定处置结果！");
				return rm;
			}else if(!"0".equals(dbgc.getDisposal_result()) && !"1".equals(dbgc.getDisposal_result()) &&
					!"9".equals(dbgc.getDisposal_result())){
				rm.setState("500");
				rm.setMsgInfo("处置结果代码{"+dbgc.getDisposal_result()+"} 无法识别！代码说明：0：可用、1：重修、9：报废");
				return rm;
			}
			
			Integer v_cnt=this.getMapper(DevBladeGrindingMapper.class).countWithCondition(null, "serial_no='"+dbgc.getSerial_no()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+dbgc.getSerial_no()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevBladeGrinding> ldbgg = this.getMapper(DevBladeGrindingMapper.class).findWithCondition(null, "serial_no='"+dbgc.getSerial_no()+"'", null, 0, 0);
			DevBladeGrinding v_rec_grd = ldbgg.get(0);
			if("1".equals(v_rec_grd.getDisposal_done())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+dbgc.getSerial_no()+"} 已处置完毕，不允许此操作！");
				return rm;
			}
			Double aia_outer_bfr = this.getMapper(DevBladeGrindingBldMapper.class).doQuery2Web(dbgc.getSerial_no());
			if(dbgc.getDia_outer_aft()>aia_outer_bfr){
					rm.setState("500");
					rm.setMsgInfo("修磨后外径不能大于刀片明细中修磨前外径最小值【"+aia_outer_bfr+"】");
					return rm;
			}
			Double dia_outer_srp = this.getMapper(DevBladeGrindingBldMapper.class).doQuery3Web(dbgc.getSerial_no());
			if(dbgc.getDia_outer_aft()<dia_outer_srp){
					rm.setState("500");
					rm.setMsgInfo("修磨后外径不能小于刀片明细中报废外径最大值【"+dia_outer_srp+"】");
					return rm;
			}
			//  --(3)、处置序号
			v_cnt=this.getMapper(DevBladeGrindingCdMapper.class).doCount4(dbgc.getSerial_no());
			//  --(4)、开始事物  																																							
			//  --(4.1)、插入鉴定处置过程记录																																							
			DevBladeGrindingCd dbgcc=new DevBladeGrindingCd();
			dbgcc.setSerial_no(dbgc.getSerial_no());
			Long cd_sql=Long.parseLong(v_cnt+"");
			dbgcc.setCd_sqc(cd_sql);
			dbgcc.setDia_outer_aft(dbgc.getDia_outer_aft());
			dbgcc.setCheck_result(dbgc.getCheck_result());
			dbgcc.setCheck_opr(dbgc.getCheck_opr());
			dbgcc.setDisposal_result(dbgc.getDisposal_result());
			dbgcc.setMemo(dbgc.getMemo());
			dbgcc.setCreate_opr(userName);
			dbgcc.setCreate_time(new Date());
			this.getMapper(DevBladeGrindingCdMapper.class).insert(dbgcc);
			if(dbgc.getMemo()==null){
				dbgc.setMemo("");
			}
			//  --(4.2)、修改修磨刀片明细记录（不管 GRD_FLAG 是否为1）
			//this.getMapper(DevBladeGrindingBldMapper.class).doUpdate(dbgc,userName);
			this.getMapper(DevBladeGrindingBldMapper.class).doUpdate3(dbgc,userName);
			//  --(4.3)、修改修磨主记录
			DevBladeGrinding dbgd=new DevBladeGrinding();
			dbgd.setDia_outer_aft(dbgc.getDia_outer_aft());
			dbgd.setCheck_result(dbgc.getCheck_result());
			dbgd.setCheck_opr(dbgc.getCheck_opr());
			dbgd.setDisposal_result(dbgc.getDisposal_result());
			
			dbgd.setMemo(dbgc.getMemo());
			dbgd.setUpdate_opr(userName);
			dbgd.setUpdate_time(new Date());
			dbgd.setSerial_no(dbgc.getSerial_no());
			//this.getMapper(DevBladeGrindingMapper.class).update(dbgd);
			this.getMapper(DevBladeGrindingMapper.class).doUpdate2(dbgd,"");
			//提交事务
			rm.setMsgInfo("新增处置过程成功");
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			throw new Exception("新增处置过程失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 *动作处理_修改（处置过程）
	 * object:
	 * 相关信息
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doUpdate1Web(CommonPage<DevBladeGrindingCd> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(userName==null){
				userName="";
			}
			DevBladeGrindingCd dbgc = sum.getObject();
			if(dbgc==null){
				rm.setState("500");
				rm.setMsgInfo("请输入参数");
				return rm;
			}
			if(dbgc.getSerial_no()==null || "".equals(dbgc.getSerial_no())){
				rm.setState("500");
				rm.setMsgInfo("未指定修磨记录号！");
				return rm;
			}
			if(dbgc.getCd_sqc()==null){
				rm.setState("500");
				rm.setMsgInfo("未指定处置序号！");
				return rm;
			}
			if(dbgc.getDia_outer_aft()==null){
				rm.setState("500");
				rm.setMsgInfo("未指定修磨后外径");
				return rm;
			}
			if(dbgc.getDia_outer_aft()<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨后外径必须大于零！");
				return rm;
			}
			if(dbgc.getCheck_result()==null){
				rm.setState("500");
				rm.setMsgInfo("未指定鉴定结果！");
				return rm;
			}else if(!"0".equals(dbgc.getCheck_result()) && !"1".equals(dbgc.getCheck_result())){
				rm.setState("500");
				rm.setMsgInfo("鉴定结果代码{"+dbgc.getCheck_result()+"} 无法识别！代码说明：1：合格、0：不合格");
				return rm;
			}
			if(dbgc.getDisposal_result()==null){
				rm.setState("500");
				rm.setMsgInfo("未指定处置结果！");
				return rm;
			}else if(!"0".equals(dbgc.getDisposal_result()) && !"1".equals(dbgc.getDisposal_result()) &&
					!"9".equals(dbgc.getDisposal_result())){
				rm.setState("500");
				rm.setMsgInfo("处置结果代码{"+dbgc.getDisposal_result()+"} 无法识别！代码说明：0：可用、1：重修、9：报废");
				return rm;
			}
			
			Integer v_cnt=this.getMapper(DevBladeGrindingMapper.class).countWithCondition(null, "serial_no='"+dbgc.getSerial_no()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+dbgc.getSerial_no()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevBladeGrinding> ldbgg = this.getMapper(DevBladeGrindingMapper.class).findWithCondition(null, "serial_no='"+dbgc.getSerial_no()+"'", null, 0, 0);
			DevBladeGrinding v_rec_grd = ldbgg.get(0);
			if("1".equals(v_rec_grd.getDisposal_done())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+dbgc.getSerial_no()+"} 已处置完毕，不允许此操作！");
				return rm;
			}
			//  --(3)、验证处置记录存在
			DevBladeGrindingCd db=new DevBladeGrindingCd();
			db.setSerial_no(dbgc.getSerial_no());
			db.setCd_sqc(dbgc.getCd_sqc());
			v_cnt = this.getMapper(DevBladeGrindingCdMapper.class).count(db);
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+dbgc.getSerial_no()+"} 处置序号{"+dbgc.getCd_sqc()+"} 修磨处置记录不存在！");
				return rm;
			}
			//  --(4)、只允许修改最后一条处置记录
			v_cnt=this.getMapper(DevBladeGrindingCdMapper.class).doCount1(dbgc.getSerial_no(),dbgc.getCd_sqc());
			if(v_cnt>0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+dbgc.getSerial_no()+"} 处置序号{"+dbgc.getCd_sqc()+"}  已有新的处置记录，不允许修改此记录！");
				return rm;
			}
			Double aia_outer_bfr = this.getMapper(DevBladeGrindingBldMapper.class).doQuery2Web(dbgc.getSerial_no());
			if(dbgc.getDia_outer_aft()>aia_outer_bfr){
					rm.setState("500");
					rm.setMsgInfo("修磨后外径不能大于刀片明细中修磨前外径最小值【"+aia_outer_bfr+"】");
					return rm;
			}
			Double dia_outer_srp = this.getMapper(DevBladeGrindingBldMapper.class).doQuery3Web(dbgc.getSerial_no());
			if(dbgc.getDia_outer_aft()<dia_outer_srp){
					rm.setState("500");
					rm.setMsgInfo("修磨后外径不能小于刀片明细中报废外径最大值【"+dia_outer_srp+"】");
					return rm;
			}
			//  --(5)、开始事物  																																							
			//  --(5.1)、修改鉴定处置过程记录																																							
			DevBladeGrindingCd dbgcc=new DevBladeGrindingCd();
			dbgcc.setSerial_no(dbgc.getSerial_no());
			dbgcc.setCd_sqc(dbgc.getCd_sqc());
			dbgcc.setDia_outer_aft(dbgc.getDia_outer_aft());
			dbgcc.setCheck_result(dbgc.getCheck_result());
			dbgcc.setCheck_opr(dbgc.getCheck_opr());
			dbgcc.setDisposal_result(dbgc.getDisposal_result());
			dbgcc.setMemo(dbgc.getMemo());
			dbgcc.setUpdate_opr(userName);
			dbgcc.setUpdate_time(new Date());
			this.getMapper(DevBladeGrindingCdMapper.class).update(dbgcc);
			if(dbgc.getMemo()==null){
				dbgc.setMemo("");
			}
			//  --(5.2)、修改修磨刀片明细记录（不管 GRD_FLAG 是否为1）
			//this.getMapper(DevBladeGrindingBldMapper.class).doUpdate(dbgc,userName);
		    this.getMapper(DevBladeGrindingBldMapper.class).doUpdate3(dbgc,userName);
			//  --(4.3)、修改修磨主记录
			DevBladeGrinding dbgd=new DevBladeGrinding();
			dbgd.setDia_outer_aft(dbgc.getDia_outer_aft());
			dbgd.setCheck_result(dbgc.getCheck_result());
			dbgd.setCheck_opr(dbgc.getCheck_opr());
			dbgd.setDisposal_result(dbgc.getDisposal_result());
			dbgd.setMemo(dbgc.getMemo());
			dbgd.setUpdate_opr(userName);
			dbgd.setUpdate_time(new Date());
			dbgd.setSerial_no(dbgc.getSerial_no());
			this.getMapper(DevBladeGrindingMapper.class).doUpdate2(dbgd,"");
			//提交事务
			rm.setMsgInfo("修改处置过程成功");
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			throw new Exception("修改处置过程失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 *动作处理_删除（处置过程）按钮
	 *memo1:修磨记录号
	 *memo2:序号,赋值为“处置过程”表格中选中行对应单元格的值（不能为空）；
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doDeleteBlWeb(CommonPage<DevBladeGrindingCd> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			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;
			}
			Integer v_cnt=this.getMapper(DevBladeGrindingMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevBladeGrinding> ldbgg = this.getMapper(DevBladeGrindingMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
			DevBladeGrinding v_rec_grd = ldbgg.get(0);
			if("1".equals(v_rec_grd.getDisposal_done())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 已处置完毕，不允许此操作！");
				return rm;
			}
			//  --(3)、验证处置记录存在
			DevBladeGrindingCd db=new DevBladeGrindingCd();
			db.setSerial_no(sum.getMemo1());
			db.setCd_sqc(Long.parseLong(sum.getMemo2()));
			v_cnt = this.getMapper(DevBladeGrindingCdMapper.class).count(db);
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 处置序号{"+sum.getMemo2()+"} 修磨处置记录不存在！");
				return rm;
			}
			v_cnt=this.getMapper(DevBladeGrindingCdMapper.class).doCount1(sum.getMemo1(),Long.parseLong(sum.getMemo2()));
			if(v_cnt>0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 处置序号{"+sum.getMemo2()+"} 只能删除最新处置记录！");
				return rm;
			}
			v_cnt=this.getMapper(DevBladeGrindingCdMapper.class).doCount2(sum.getMemo1(),Long.parseLong(sum.getMemo2()));
			DevBladeGrindingCd rec_grd_cd=new DevBladeGrindingCd();
			if(v_cnt>0){
				List<DevBladeGrindingCd> rec_grd_cd_list=this.getMapper(DevBladeGrindingCdMapper.class).doQuery2Web(sum.getMemo1(),Long.parseLong(sum.getMemo2()));
				if(rec_grd_cd_list!=null && rec_grd_cd_list.size()>0){
					rec_grd_cd=rec_grd_cd_list.get(0);
				}
			}
			DevBladeGrindingCd dbgc1=new DevBladeGrindingCd();
			dbgc1.setSerial_no(sum.getMemo1());
			dbgc1.setCd_sqc(Long.parseLong(sum.getMemo2()));
			//错误写法。  delete(object)  正确delete(id)
			//this.getMapper(DevBladeGrindingCdMapper.class).delete(dbgc1);
			//delete FROM DEV_BLADE_GRINDING_CD where SERIAL_NO=? AND CD_SQC=? 
			this.getMapper(DevBladeGrindingCdMapper.class).delete(dbgc1.getSerial_no(),dbgc1.getCd_sqc());
			if(rec_grd_cd.getSerial_no()!=null){
				if(rec_grd_cd.getMemo()==null){
					rec_grd_cd.setMemo("");
				}
				//  --(6.2.1)、修改修磨刀片明细记录（不管 GRD_FLAG 是否为1）
				//this.getMapper(DevBladeGrindingBldMapper.class).doUpdate(rec_grd_cd,userName);
				this.getMapper(DevBladeGrindingBldMapper.class).doUpdate3(rec_grd_cd,userName);
				//  --(4.3)、修改修磨主记录
				DevBladeGrinding dbgd=new DevBladeGrinding();
				dbgd.setDia_outer_aft(rec_grd_cd.getDia_outer_aft());
				dbgd.setCheck_result(rec_grd_cd.getCheck_result());
				dbgd.setCheck_opr(rec_grd_cd.getCheck_opr());
				dbgd.setDisposal_result(rec_grd_cd.getDisposal_result());
				dbgd.setMemo(rec_grd_cd.getMemo());
				dbgd.setUpdate_opr(userName);
				dbgd.setUpdate_time(new Date());
				dbgd.setSerial_no(rec_grd_cd.getSerial_no());
				//this.getMapper(DevBladeGrindingMapper.class).update(dbgd);
				this.getMapper(DevBladeGrindingMapper.class).doUpdate2(dbgd,"");
			}else{
				this.getMapper(DevBladeGrindingBldMapper.class).doUpdate2(sum.getMemo1(),userName);
				this.getMapper(DevBladeGrindingMapper.class).doUpdate1(sum.getMemo1(),userName);
			}
			//提交事务
			rm.setMsgInfo("删除处置过程成功");
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			throw new Exception("删除处置过程失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 *动作处理_保存（刀片明细）按钮
	 * objectList:
	 * 相关信息
	 * memo1:SERIAL_NO（修磨记录号），赋值为“修磨记录”表格中选中行对应单元格的值（不能为空）；
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doSaveWeb(CommonPage<DevBladeGrindingBld> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(userName==null){
				userName="";
			}
			List<DevBladeGrindingBld> ldbgb = sum.getObjectList();
			if(ldbgb==null){
				rm.setState("500");
				rm.setMsgInfo("请输入参数");
				return rm;
			}
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("未指定修磨记录号！");
				return rm;
			}
			for(DevBladeGrindingBld dbgb:ldbgb){
				if(dbgb.getBlade_no()==null || "".equals(dbgb.getBlade_no()) ||
						dbgb.getGrd_flag()==null || "".equals(dbgb.getGrd_flag())){
					rm.setState("500");
					rm.setMsgInfo("参数错误：刀片编号、修磨标识、修磨后外径、备注 集合元素个数不匹配！");
					return rm;
				}
				if(!"0".equals(dbgb.getGrd_flag()) && !"1".equals(dbgb.getGrd_flag())){
					rm.setState("500");
					rm.setMsgInfo("是否修磨代码{"+dbgb.getGrd_flag()+"} 无法识别！代码说明：1：是、0：否");
					return rm;
				}
				if("1".equals(dbgb.getGrd_flag())){
					if(dbgb.getDia_outer_aft()==null){
						rm.setState("500");
						rm.setMsgInfo("未指定修磨后外径！");
						return rm;
					}
					if(dbgb.getDia_outer_aft()<=0){
						rm.setState("500");
						rm.setMsgInfo("修磨后外径必须大于零！");
						return rm;
					}
				}
				//
				Integer v_cnt=this.getMapper(DevBladeGrindingBldMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"' and blade_no='"+dbgb.getBlade_no()+"'");
				if(v_cnt<=0){
					rm.setState("500");
					rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 刀片编号{"+dbgb.getBlade_no()+"} 修磨刀片明细记录不存在！");
					return rm;
				}
			}
			Integer v_cnt=this.getMapper(DevBladeGrindingMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevBladeGrinding> ldbgg = this.getMapper(DevBladeGrindingMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
			DevBladeGrinding v_rec_grd = ldbgg.get(0);
			if("1".equals(v_rec_grd.getDisposal_done())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 已处置完毕，不允许此操作！");
				return rm;
			}
			for(DevBladeGrindingBld dbgb:ldbgb){
				List<DevBladeGrindingBld> rec_grd_bld_list = this.getMapper(DevBladeGrindingBldMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"' and blade_no='"+dbgb.getBlade_no()+"'", null, 0, 0);
				DevBladeGrindingBld rec_grd_bld=rec_grd_bld_list.get(0);
				if(dbgb.getMemo()==null){
					dbgb.setMemo("");
				}
				this.getMapper(DevBladeGrindingBldMapper.class).doUpdate6(dbgb, sum.getMemo1(),userName);
				
				this.getMapper(DevBladeInfoMapper.class).doUpdate5(dbgb.getGrd_flag(),rec_grd_bld.getStatus(),userName,dbgb.getBlade_no());
				
			}
			//  --(3.4)、修改修磨主记录
			this.getMapper(DevBladeGrindingMapper.class).doUpdate3(userName,v_rec_grd.getSerial_no());
			
			
			//提交事务
			rm.setMsgInfo("保存刀片明细成功");
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			throw new Exception("保存刀片明细失败!"+ex.getMessage());
		}
		return rm;
	}
	
	
	// 补零
	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;
	}
}
