/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-11-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.pb.DoubleUtil;
import market.Com.vo.ComBaseMachine;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Mes.Dev.mapper.DevRollerGrindingCdMapper;
import market.Mes.Dev.mapper.DevRollerGrindingMapper;
import market.Mes.Dev.mapper.DevRollerInfoMapper;
import market.Mes.Dev.service.DevRollerGrindingService;
import market.Mes.Dev.vo.DevRollerGrinding;
import market.Mes.Dev.vo.DevRollerGrindingCd;
import market.Mes.Dev.vo.DevRollerInfo;

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

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

@RemoteService(path="DevRollerGrindingService")
public class DevRollerGrindingServiceImpl extends BaseServiceImpl<DevRollerGrinding,Object> implements DevRollerGrindingService {
	
	/**
	 * 相关说明：
      bfr_roller_dia :修磨前辊径（mm）	
      aft_roller_dia :修磨后辊径（mm）
	 */
	
	/**
	 * 根据轧辊类型查询轧辊编号
	 * object:
	 * roller_type:选中节点表示的轧辊类型   轧辊类型（W：工作辊、B：支承辊、I：中间辊）
	 * machine_code:机台代码
	 * */
	public ResultModel doQueryWeb(CommonPage<DevRollerInfo> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(DevRollerInfoMapper.class).doQueryGrindWeb(oci.getObject()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 根据轧辊编号查询修磨记录
	 * object:
	 * roller_no:轧辊编号
	 * machine_code:机台代码
	 * memo1:送修日期开始
	 * memo2:送修日期结束
	 * memo3:返回日期开始
	 * memo4:返回日期结束
	 * */
	public ResultModel doQuery2Web(CommonPage<DevRollerGrinding> oci){
		ResultModel rm=new ResultModel();
		try{
			String startTime = null;
			String endTime = null;
			String startTime2 = null;
			String endTime2 = null;
			if (StringUtils.isNotEmpty(oci.getMemo1())) {
				startTime = oci.getMemo1().substring(0, 10);
			}
			if (StringUtils.isNotEmpty(oci.getMemo2())) {
				endTime = oci.getMemo2().substring(0, 10);
			}
			if (StringUtils.isNotEmpty(oci.getMemo3())) {
				startTime2 = oci.getMemo3().substring(0, 10);
			}
			if (StringUtils.isNotEmpty(oci.getMemo4())) {
				endTime2 = oci.getMemo4().substring(0, 10);
			} 
			rm.setData(this.getMapper(DevRollerGrindingMapper.class).doQuery2Web(oci.getObject(),startTime,endTime,startTime2,endTime2));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 动作处理_修磨记录行选中
	 * “处置过程”处理：
	  memo1：修磨记录号，赋值为修磨记录表格选中行的修磨记录号，并传入后台；
	 * */
	public ResultModel doQuery3Web(CommonPage<DevRollerGrinding> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(DevRollerGrindingCdMapper.class).doQueryWeb(oci.getMemo1()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 动作处理_新增（修磨记录）按钮
	  memo1：机台代码
	  memo2: 轧辊编号（roller_no）
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doAddWeb(CommonPage<DevRollerGrinding> 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(DevRollerInfoMapper.class).countWithCondition(null, "roller_no='"+sum.getMemo2()+"'");
		    if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("轧辊编号{"+sum.getMemo2()+"} 系统中暂无此信息，请先维护轧辊信息！");
				return rm;
			}
			//  --(1.6)、验证存在待磨刀片
			DevRollerInfo dbi=new DevRollerInfo();
			dbi.setRoller_no(sum.getMemo2());
			dbi.setStatus("1");
			v_cnt=this.getMapper(DevRollerInfoMapper.class).count(dbi);
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("轧辊编号{"+sum.getMemo2()+"} 不是待磨状态，请在基础信息中指定！");
				return rm;
			}
			List<DevRollerInfo> ldbitt=this.getMapper(DevRollerInfoMapper.class).findWithCondition(null, "roller_no='"+sum.getMemo2()+"'", null, 0, 0);
			
			
			//  --(2)、验证当班刀片组无待处置的修磨记录
			v_cnt=this.getMapper(DevRollerGrindingMapper.class).doCount(sum.getMemo1(),sum.getMemo2());
			if(v_cnt>0){
				rm.setState("500");
				rm.setMsgInfo("轧辊编号{"+sum.getMemo2()+"} 存在未处置结束的修磨记录，暂不允许此操作！");
				return rm;
			}
			//  --(3)、修磨记录号：'G' + YYMMDD + 3位流水
			String v_serial_no="R"+new SimpleDateFormat("yyMMdd").format(new Date());
			//  --(3.1)、获取当前起始流水号
			Integer v_cnt1=this.getMapper(DevRollerGrindingMapper.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(DevRollerGrindingMapper.class).doCount3(sum.getMemo1(),sum.getMemo2());
			Long grd_sqc=Long.parseLong(v_cnt+"");
			//  --(5)、开始事物																																							
			//  --(5.1)、新增修磨主记录（未指定的字段，全为NULL）																																							
			DevRollerGrinding dbg=new DevRollerGrinding();
			dbg.setSerial_no(v_serial_no);
			dbg.setMachine_code(sum.getMemo1());
			dbg.setRoller_no(sum.getMemo2());
			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());
			//==============修磨主记录赋值==========================
			dbg.setRoller_type(ldbitt.get(0).getRoller_type());
			dbg.setAmount_money(ldbitt.get(0).getAmount_money());
			dbg.setResidual_value(ldbitt.get(0).getResidual_value());
			
			dbg.setCur_use_times(ldbitt.get(0).getCur_use_times());
			dbg.setCur_rll_len(ldbitt.get(0).getCur_rll_len());
			dbg.setCur_rll_wgt(ldbitt.get(0).getCur_rll_wgt());
			dbg.setBfr_roller_dia(ldbitt.get(0).getDia_current());
			dbg.setBfr_roller_wgt(ldbitt.get(0).getWgt_current());//修磨前辊重（kg） ==  当前辊重（kg）
			dbg.setBfr_density(ldbitt.get(0).getDensity());
			dbg.setBfr_roughness(ldbitt.get(0).getRoughness());
			dbg.setBfr_hardness(ldbitt.get(0).getHardness());
			dbg.setBfr_roll_profile(ldbitt.get(0).getRoll_profile());
			dbg.setBfr_roundness(ldbitt.get(0).getRoundness());
			dbg.setBfr_runout(ldbitt.get(0).getRunout());
			dbg.setBfr_convexity(ldbitt.get(0).getConvexity());
			dbg.setBfr_convexity_max(ldbitt.get(0).getConvexity_max());
			dbg.setBfr_convexity_min(ldbitt.get(0).getConvexity_min());
			dbg.setBfr_cone_len(ldbitt.get(0).getCone_len());
			dbg.setBfr_cone_hgt(ldbitt.get(0).getCone_hgt());
			dbg.setBfr_brollc_length(ldbitt.get(0).getBrollc_length());
			dbg.setBfr_brollc_deepth(ldbitt.get(0).getBrollc_deepth());
			dbg.setBfr_soft_point(ldbitt.get(0).getSoft_point());
			dbg.setBfr_crack(ldbitt.get(0).getCrack());
			dbg.setDia_init(ldbitt.get(0).getDia_init());
			dbg.setDia_scrap(ldbitt.get(0).getDia_scrap());
			//========================================
			
			this.getMapper(DevRollerGrindingMapper.class).insert(dbg);
			//  --(5.2)、新增修磨刀片明细记录（未指定的字段，全为NULL）																																							
			//  --(5.2.1)、刀片当前状体为待磨时（status = '1'），自动设置为本次修磨（grd_flag := '1'）																																							
			List<DevRollerInfo> ldbi=this.getMapper(DevRollerInfoMapper.class).findWithCondition(null, "roller_no='"+sum.getMemo2()+"'", null, 0, 0);
			for(DevRollerInfo cur_01:ldbi){
				//    --(5.2.2)、同时，将待磨刀片置为修磨状态
				if("1".equals(cur_01.getStatus())){ 
					this.getMapper(DevRollerInfoMapper.class).doUpdate3(cur_01.getRoller_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<DevRollerGrinding> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(userName==null){
				userName="";
			}
			DevRollerGrinding 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(DevRollerGrindingMapper.class).countWithCondition(null, "serial_no='"+dbg.getSerial_no()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+dbg.getSerial_no()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevRollerGrinding> ldbgg = this.getMapper(DevRollerGrindingMapper.class).findWithCondition(null, "serial_no='"+dbg.getSerial_no()+"'", null, 0, 0);
			DevRollerGrinding v_rec_grd = ldbgg.get(0);
//			if("1".equals(v_rec_grd.getDisposal_done())){
//				rm.setState("500");
//				rm.setMsgInfo("修磨记录号{"+dbg.getSerial_no()+"} 已处置完毕，信息不允许修改！");
//				return rm;
//			}
			DevRollerGrinding dbgding=new DevRollerGrinding();
			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(DevRollerGrindingMapper.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<DevRollerGrinding> 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(DevRollerGrindingMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevRollerGrinding> ldbgg = this.getMapper(DevRollerGrindingMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
			DevRollerGrinding v_rec_grd = ldbgg.get(0);
			if("1".equals(v_rec_grd.getDisposal_done())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 已处置完毕，记录不允许删除！");
				return rm;
			}
			
			//  --(5.2.1)、刀片当前状体为修磨时，自动设置为本次待磨																																					
			List<DevRollerInfo> ldbi=this.getMapper(DevRollerInfoMapper.class).findWithCondition(null, "roller_no='"+v_rec_grd.getRoller_no()+"'", null, 0, 0);
			for(DevRollerInfo cur_01:ldbi){
				//    --(5.2.2)、同时，将待磨刀片置为待磨状态
				if("2".equals(cur_01.getStatus())){ 
					DevRollerInfo dbi=new DevRollerInfo();
					dbi.setStatus("1");// --恢复为待修磨的状态
					dbi.setUpdate_opr(userName);
					dbi.setUpdate_time(new Date());
					dbi.setRoller_no(cur_01.getRoller_no());
					this.getMapper(DevRollerInfoMapper.class).update(dbi);
				}
			}
			
			this.getMapper(DevRollerGrindingCdMapper.class).doDelete(sum.getMemo1());
			this.getMapper(DevRollerGrindingMapper.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<DevRollerGrinding> 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(DevRollerGrindingMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 修磨记录不存在！");
				return rm;
			}
		    v_cnt=this.getMapper(DevRollerGrindingCdMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 无鉴定处置记录，不允许此操作！");
				return rm;
			}
			
			List<DevRollerGrinding> ldbgg = this.getMapper(DevRollerGrindingMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
			DevRollerGrinding 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.getAft_roller_dia()==null){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 未指定修磨后辊径，不允许此操作！");
				return rm;
			}
			if(v_rec_grd.getAft_roller_dia()<=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)+"】已经进行轧辊成本审核");
			}
			
			
			
			
			//  --(5.2)、新增修磨刀片明细记录（未指定的字段，全为NULL）																																							
			//  --(5.2.1)、刀片当前状体为待磨时（status = '1'），自动设置为本次修磨（grd_flag := '1'）																																							
			List<DevRollerInfo> ldbi=this.getMapper(DevRollerInfoMapper.class).findWithCondition(null, "roller_no='"+v_rec_grd.getRoller_no()+"'", null, 0, 0);
			for(DevRollerInfo cur_01:ldbi){
				this.getMapper(DevRollerInfoMapper.class).doUpdate2(v_rec_grd,userName);
			}
			
			//  --(3.2)、修改修磨主记录处置完毕状态
			DevRollerGrinding dbgd=new DevRollerGrinding();
			dbgd.setDisposal_done("1");
			dbgd.setSerial_no(sum.getMemo1());
			dbgd.setUpdate_opr(userName);
			dbgd.setUpdate_time(new Date());
			this.getMapper(DevRollerGrindingMapper.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<DevRollerGrinding> 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(DevRollerGrindingMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevRollerGrinding> ldbgg = this.getMapper(DevRollerGrindingMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
			DevRollerGrinding 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(DevRollerGrindingMapper.class).doCount1(v_rec_grd.getMachine_code(),v_rec_grd.getRoller_no(),v_rec_grd.getGrd_sqc());
			if(v_cnt>0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 此次修磨后已有新的修磨记录，不允许此操作！");
				return rm;
			}
			
			//  --(5.2)、新增修磨刀片明细记录（未指定的字段，全为NULL）																																							
			//  --(5.2.1)、刀片当前状体为待磨时（status = '1'），自动设置为本次修磨（grd_flag := '1'）																																							
			List<DevRollerInfo> ldbi=this.getMapper(DevRollerInfoMapper.class).findWithCondition(null, "roller_no='"+v_rec_grd.getRoller_no()+"'", null, 0, 0);
			for(DevRollerInfo cur_01:ldbi){
				//this.getMapper(DevRollerInfoMapper.class).doUpdate4(v_rec_grd.getDia_outer_bfr(),v_rec_grd.getCur_use_times(),userName,cur_01.getBlade_no());
				/**
				 * <update id="doUpdate4" parameterType="HashMap">
						    update dev_blade_info t																																							
				       set t.status        = '2', --状态 恢复为 修磨																																							
				           t.dia_outer_cur = #{param1}, --当前辊径 恢复为 修磨前辊径																																							
				           t.cur_use_times = #{param2}, --当前使用次数 恢复为 修磨前使用次数																																							
				           t.ttl_grd_times = case when t.ttl_grd_times > 0 then t.ttl_grd_times - 1 else 0 end, --累计修磨次数 -1																																							
				           t.update_opr    = #{param3},																																							
				           t.update_time   = sysdate																																							
				     where t.blade_no = #{param4}																																						
					</update>
				 */
			
				DevRollerInfo dri=new  DevRollerInfo();
				dri.setRoller_no(v_rec_grd.getRoller_no());
				dri.setStatus("2");
				
				//==============轧辊基础信息赋值==========================
				dri.setCur_use_times(v_rec_grd.getCur_use_times());
				dri.setCur_rll_len(v_rec_grd.getCur_rll_len());
				
				dri.setCur_rll_wgt(v_rec_grd.getCur_rll_wgt());
				dri.setDia_current(v_rec_grd.getBfr_roller_dia());
				dri.setWgt_current(v_rec_grd.getBfr_roller_wgt());
				dri.setDensity(v_rec_grd.getBfr_density());
				dri.setRoughness(v_rec_grd.getBfr_roughness());
				dri.setHardness(v_rec_grd.getBfr_hardness());
				dri.setRoll_profile(v_rec_grd.getBfr_roll_profile());
				dri.setRoundness(v_rec_grd.getBfr_roundness());
				dri.setRunout(v_rec_grd.getBfr_runout());
				dri.setConvexity(v_rec_grd.getBfr_convexity());
				dri.setConvexity_max(v_rec_grd.getBfr_convexity_max());
				dri.setConvexity_min(v_rec_grd.getBfr_convexity_min());
				dri.setCone_len(v_rec_grd.getBfr_cone_len());
				dri.setCone_hgt(v_rec_grd.getBfr_cone_hgt());
				dri.setBrollc_length(v_rec_grd.getBfr_brollc_length());
				dri.setBrollc_deepth(v_rec_grd.getBfr_brollc_deepth());
				dri.setSoft_point(v_rec_grd.getBfr_soft_point());
				dri.setCrack(v_rec_grd.getBfr_crack());
				
				//========================================
				this.getMapper(DevRollerInfoMapper.class).update(dri);
			}
			
			//   --(3.2)、修改修磨主记录处置完毕状态为否
			DevRollerGrinding dbgd=new DevRollerGrinding();
			dbgd.setDisposal_done("0");
			dbgd.setSerial_no(sum.getMemo1());
			dbgd.setUpdate_opr(userName);
			dbgd.setUpdate_time(new Date());
			this.getMapper(DevRollerGrindingMapper.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<DevRollerGrindingCd> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(userName==null){
				userName="";
			}
			DevRollerGrindingCd 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.getAft_roller_dia()==null){
				rm.setState("500");
				rm.setMsgInfo("未指定修磨后辊径（mm）");
				return rm;
			}
			if(dbgc.getAft_roller_dia()<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨后辊径（mm）必须大于零！");
				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(DevRollerGrindingMapper.class).countWithCondition(null, "serial_no='"+dbgc.getSerial_no()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+dbgc.getSerial_no()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevRollerGrinding> ldbgg = this.getMapper(DevRollerGrindingMapper.class).findWithCondition(null, "serial_no='"+dbgc.getSerial_no()+"'", null, 0, 0);
			DevRollerGrinding 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 bfr_roller_dia = v_rec_grd.getBfr_roller_dia();//修磨前辊径（mm）
			if(dbgc.getAft_roller_dia()>bfr_roller_dia){
					rm.setState("500");
					rm.setMsgInfo("修磨后辊径（mm）不能大于修磨前辊径（mm）【"+bfr_roller_dia+"】");
					return rm;
			}
//			if(dbgc.getAft_roller_wgt()>v_rec_grd.getBfr_roller_wgt()){
//				rm.setState("500");
//				rm.setMsgInfo("修磨后辊重（kg）不能大于修磨前辊重（kg）【"+v_rec_grd.getBfr_roller_wgt()+"】");
//				return rm;
//			}
			
			if(dbgc.getAft_roller_dia()<v_rec_grd.getDia_scrap()){
					rm.setState("500");
					rm.setMsgInfo("修磨后辊径（mm）不能小于报废辊径（mm）【"+v_rec_grd.getDia_scrap()+"】");
					return rm;
			}
			//  --(3)、处置序号
			v_cnt=this.getMapper(DevRollerGrindingCdMapper.class).doCount4(dbgc.getSerial_no());
			//  --(4)、开始事物  																																							
			//  --(4.1)、插入鉴定处置过程记录																																							
//			DevRollerGrindingCd dbgcc=new DevRollerGrindingCd();
//			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());
			Long cd_sql=Long.parseLong(v_cnt+"");
			dbgc.setCd_sqc(cd_sql);
			dbgc.setCreate_opr(userName);
			dbgc.setCreate_time(new Date());
			this.getMapper(DevRollerGrindingCdMapper.class).insert(dbgc);
			//  --(4.3)、修改修磨主记录
			DevRollerGrinding dbg=new DevRollerGrinding();
			
			//==============修磨主记录赋值==========================
//			dbg.setCur_use_times(ldbitt.get(0).getCur_use_times());
//			dbg.setCur_rll_len(ldbitt.get(0).getCur_rll_len());
//			dbg.setCur_rll_wgt(ldbitt.get(0).getCur_rll_wgt());
			dbg.setAft_roller_dia(dbgc.getAft_roller_dia());
			dbg.setAft_roller_wgt(dbgc.getAft_roller_wgt());//
			dbg.setAft_density(dbgc.getAft_density());
			dbg.setAft_roughness(dbgc.getAft_roughness());
			dbg.setAft_hardness(dbgc.getAft_hardness());
			dbg.setAft_roll_profile(dbgc.getAft_roll_profile());
			dbg.setAft_roundness(dbgc.getAft_roundness());
			dbg.setAft_runout(dbgc.getAft_runout());
			dbg.setAft_convexity(dbgc.getAft_convexity());
			dbg.setAft_convexity_max(dbgc.getAft_convexity_max());
			dbg.setAft_convexity_min(dbgc.getAft_convexity_min());
			dbg.setAft_cone_len(dbgc.getAft_cone_len());
			dbg.setAft_cone_hgt(dbgc.getAft_cone_hgt());
			dbg.setAft_brollc_length(dbgc.getAft_brollc_length());
			dbg.setAft_brollc_deepth(dbgc.getAft_brollc_deepth());
			dbg.setAft_soft_point(dbgc.getAft_soft_point());
			dbg.setAft_crack(dbgc.getAft_crack());
			
			dbg.setBfr_roller_dia(v_rec_grd.getBfr_roller_dia());//
			dbg.setDia_init(v_rec_grd.getDia_init());//
			dbg.setDia_scrap(v_rec_grd.getDia_scrap());//
			dbg.setAmount_money(v_rec_grd.getAmount_money());
			dbg.setResidual_value(v_rec_grd.getResidual_value());
			
			Double zhesuan=null;
			// --折算成本 = (金额 - 残值) * (修磨前外径 - 修磨后外径) / (原始外径 - 报废外径)
			if(dbg.getAmount_money()!=null && dbg.getAft_roller_dia()!=null && dbg.getAft_roller_dia()!=null 
				&& dbg.getBfr_roller_dia()!=null && dbg.getDia_init()!=null && dbg.getDia_scrap()!=null ){
				zhesuan=(dbg.getAmount_money()-(dbg.getResidual_value()==null?0:dbg.getResidual_value()))*(dbg.getBfr_roller_dia()-dbg.getAft_roller_dia())/(dbg.getDia_init()-dbg.getDia_scrap());
				if(zhesuan!=null){
					DoubleUtil.round(zhesuan, 1);
				}
			}
			dbg.setConverted_cost(zhesuan);
			//========================================
			
			dbg.setCheck_result(dbgc.getCheck_result());
			dbg.setCheck_opr(dbgc.getCheck_opr());
			dbg.setDisposal_result(dbgc.getDisposal_result());
			
			dbg.setMemo(dbgc.getMemo());
			dbg.setUpdate_opr(userName);
			dbg.setUpdate_time(new Date());
			dbg.setSerial_no(dbgc.getSerial_no());
			this.getMapper(DevRollerGrindingMapper.class).update(dbg);
			//提交事务
			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<DevRollerGrindingCd> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(userName==null){
				userName="";
			}
			DevRollerGrindingCd 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.getAft_roller_dia()==null){
				rm.setState("500");
				rm.setMsgInfo("未指定修磨后辊径（mm）");
				return rm;
			}
			if(dbgc.getAft_roller_dia()<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨后辊径（mm）必须大于零！");
				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(DevRollerGrindingMapper.class).countWithCondition(null, "serial_no='"+dbgc.getSerial_no()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+dbgc.getSerial_no()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevRollerGrinding> ldbgg = this.getMapper(DevRollerGrindingMapper.class).findWithCondition(null, "serial_no='"+dbgc.getSerial_no()+"'", null, 0, 0);
			DevRollerGrinding 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)、验证处置记录存在
			DevRollerGrindingCd db=new DevRollerGrindingCd();
			db.setSerial_no(dbgc.getSerial_no());
			db.setCd_sqc(dbgc.getCd_sqc());
			v_cnt = this.getMapper(DevRollerGrindingCdMapper.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(DevRollerGrindingCdMapper.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 bfr_roller_dia = v_rec_grd.getBfr_roller_dia();//修磨前辊径（mm）
			if(dbgc.getAft_roller_dia()>bfr_roller_dia){
					rm.setState("500");
					rm.setMsgInfo("修磨后辊径（mm）不能大于修磨前辊径（mm）【"+bfr_roller_dia+"】");
					return rm;
			}
//			if(dbgc.getAft_roller_wgt()>v_rec_grd.getBfr_roller_wgt()){
//				rm.setState("500");
//				rm.setMsgInfo("修磨后辊重（kg）不能大于修磨前辊重（kg）【"+v_rec_grd.getBfr_roller_wgt()+"】");
//				return rm;
//			}
			if(dbgc.getAft_roller_dia()<v_rec_grd.getDia_scrap()){
					rm.setState("500");
					rm.setMsgInfo("修磨后辊径（mm）不能小于报废辊径（mm）【"+v_rec_grd.getDia_scrap()+"】");
					return rm;
			}
			
			//  --(5)、开始事物  																																							
			//  --(5.1)、修改鉴定处置过程记录																																							
			dbgc.setUpdate_opr(userName);
			dbgc.setUpdate_time(new Date());
			this.getMapper(DevRollerGrindingCdMapper.class).update(dbgc);
			
			//  --(4.3)、修改修磨主记录
			DevRollerGrinding dbg=new DevRollerGrinding();
			
			//==============修磨主记录赋值==========================
//			dbg.setCur_use_times(ldbitt.get(0).getCur_use_times());
//			dbg.setCur_rll_len(ldbitt.get(0).getCur_rll_len());
//			dbg.setCur_rll_wgt(ldbitt.get(0).getCur_rll_wgt());
			dbg.setAft_roller_dia(dbgc.getAft_roller_dia());
			dbg.setAft_roller_wgt(dbgc.getAft_roller_wgt());//
			dbg.setAft_density(dbgc.getAft_density());
			dbg.setAft_roughness(dbgc.getAft_roughness());
			dbg.setAft_hardness(dbgc.getAft_hardness());
			dbg.setAft_roll_profile(dbgc.getAft_roll_profile());
			dbg.setAft_roundness(dbgc.getAft_roundness());
			dbg.setAft_runout(dbgc.getAft_runout());
			dbg.setAft_convexity(dbgc.getAft_convexity());
			dbg.setAft_convexity_max(dbgc.getAft_convexity_max());
			dbg.setAft_convexity_min(dbgc.getAft_convexity_min());
			dbg.setAft_cone_len(dbgc.getAft_cone_len());
			dbg.setAft_cone_hgt(dbgc.getAft_cone_hgt());
			dbg.setAft_brollc_length(dbgc.getAft_brollc_length());
			dbg.setAft_brollc_deepth(dbgc.getAft_brollc_deepth());
			dbg.setAft_soft_point(dbgc.getAft_soft_point());
			dbg.setAft_crack(dbgc.getAft_crack());
			dbg.setBfr_roller_dia(v_rec_grd.getBfr_roller_dia());//
			dbg.setDia_init(v_rec_grd.getDia_init());//
			dbg.setDia_scrap(v_rec_grd.getDia_scrap());//
			dbg.setAmount_money(v_rec_grd.getAmount_money());
			dbg.setResidual_value(v_rec_grd.getResidual_value());
			
			Double zhesuan=null;
			// --折算成本 = (金额 - 残值) * (修磨前外径 - 修磨后外径) / (原始外径 - 报废外径)
			if(dbg.getAmount_money()!=null && dbg.getAft_roller_dia()!=null && dbg.getAft_roller_dia()!=null 
				&& dbg.getBfr_roller_dia()!=null && dbg.getDia_init()!=null && dbg.getDia_scrap()!=null ){
				zhesuan=(dbg.getAmount_money()-(dbg.getResidual_value()==null?0:dbg.getResidual_value()))*(dbg.getBfr_roller_dia()-dbg.getAft_roller_dia())/(dbg.getDia_init()-dbg.getDia_scrap());
				if(zhesuan!=null){
					DoubleUtil.round(zhesuan, 1);
				}
			}
			dbg.setConverted_cost(zhesuan);
			//========================================
			
			dbg.setCheck_result(dbgc.getCheck_result());
			dbg.setCheck_opr(dbgc.getCheck_opr());
			dbg.setDisposal_result(dbgc.getDisposal_result());
			
			dbg.setMemo(dbgc.getMemo());
			dbg.setUpdate_opr(userName);
			dbg.setUpdate_time(new Date());
			dbg.setSerial_no(dbgc.getSerial_no());
			this.getMapper(DevRollerGrindingMapper.class).update(dbg);
			
			//提交事务
			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<DevRollerGrindingCd> 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(DevRollerGrindingMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 修磨记录不存在！");
				return rm;
			}
			List<DevRollerGrinding> ldbgg = this.getMapper(DevRollerGrindingMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
			DevRollerGrinding v_rec_grd = ldbgg.get(0);
			if("1".equals(v_rec_grd.getDisposal_done())){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 已处置完毕，不允许此操作！");
				return rm;
			}
			//  --(3)、验证处置记录存在
			DevRollerGrindingCd db=new DevRollerGrindingCd();
			db.setSerial_no(sum.getMemo1());
			db.setCd_sqc(Long.parseLong(sum.getMemo2()));
			v_cnt = this.getMapper(DevRollerGrindingCdMapper.class).count(db);
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("修磨记录号{"+sum.getMemo1()+"} 处置序号{"+sum.getMemo2()+"} 修磨处置记录不存在！");
				return rm;
			}
			v_cnt=this.getMapper(DevRollerGrindingCdMapper.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(DevRollerGrindingCdMapper.class).doCount2(sum.getMemo1(),Long.parseLong(sum.getMemo2()));
			DevRollerGrindingCd rec_grd_cd=new DevRollerGrindingCd();
			if(v_cnt>0){
				List<DevRollerGrindingCd> rec_grd_cd_list=this.getMapper(DevRollerGrindingCdMapper.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);
				}
			}
			DevRollerGrindingCd dbgc1=new DevRollerGrindingCd();
			dbgc1.setSerial_no(sum.getMemo1());
			dbgc1.setCd_sqc(Long.parseLong(sum.getMemo2()));
			//错误写法。  delete(object)  正确delete(id)
			//this.getMapper(DevRollerGrindingCdMapper.class).delete(dbgc1);
			//delete FROM DEV_BLADE_GRINDING_CD where SERIAL_NO=? AND CD_SQC=? 
			this.getMapper(DevRollerGrindingCdMapper.class).delete(dbgc1.getSerial_no(),dbgc1.getCd_sqc());
			if(rec_grd_cd.getSerial_no()!=null){
				//  --(4.3)、修改修磨主记录
				DevRollerGrinding dbg=new DevRollerGrinding();
				//==============修磨主记录赋值==========================
//				dbg.setCur_use_times(ldbitt.get(0).getCur_use_times());
//				dbg.setCur_rll_len(ldbitt.get(0).getCur_rll_len());
//				dbg.setCur_rll_wgt(ldbitt.get(0).getCur_rll_wgt());
				dbg.setAft_roller_dia(rec_grd_cd.getAft_roller_dia());
				dbg.setAft_roller_wgt(rec_grd_cd.getAft_roller_wgt());//
				dbg.setAft_density(rec_grd_cd.getAft_density());
				dbg.setAft_roughness(rec_grd_cd.getAft_roughness());
				dbg.setAft_hardness(rec_grd_cd.getAft_hardness());
				dbg.setAft_roll_profile(rec_grd_cd.getAft_roll_profile());
				dbg.setAft_roundness(rec_grd_cd.getAft_roundness());
				dbg.setAft_runout(rec_grd_cd.getAft_runout());
				dbg.setAft_convexity(rec_grd_cd.getAft_convexity());
				dbg.setAft_convexity_max(rec_grd_cd.getAft_convexity_max());
				dbg.setAft_convexity_min(rec_grd_cd.getAft_convexity_min());
				dbg.setAft_cone_len(rec_grd_cd.getAft_cone_len());
				dbg.setAft_cone_hgt(rec_grd_cd.getAft_cone_hgt());
				dbg.setAft_brollc_length(rec_grd_cd.getAft_brollc_length());
				dbg.setAft_brollc_deepth(rec_grd_cd.getAft_brollc_deepth());
				dbg.setAft_soft_point(rec_grd_cd.getAft_soft_point());
				dbg.setAft_crack(rec_grd_cd.getAft_crack());
				dbg.setBfr_roller_dia(v_rec_grd.getBfr_roller_dia());//
				dbg.setDia_init(v_rec_grd.getDia_init());//
				dbg.setDia_scrap(v_rec_grd.getDia_scrap());//
				dbg.setAmount_money(v_rec_grd.getAmount_money());
				dbg.setResidual_value(v_rec_grd.getResidual_value());
				Double zhesuan=null;
				// --折算成本 = (金额 - 残值) * (修磨前外径 - 修磨后外径) / (原始外径 - 报废外径)
				if(dbg.getAmount_money()!=null && dbg.getAft_roller_dia()!=null && dbg.getAft_roller_dia()!=null 
					&& dbg.getBfr_roller_dia()!=null && dbg.getDia_init()!=null && dbg.getDia_scrap()!=null ){
					zhesuan=(dbg.getAmount_money()-(dbg.getResidual_value()==null?0:dbg.getResidual_value()))*(dbg.getBfr_roller_dia()-dbg.getAft_roller_dia())/(dbg.getDia_init()-dbg.getDia_scrap());
					if(zhesuan!=null){
						DoubleUtil.round(zhesuan, 1);
					}
				}
				dbg.setConverted_cost(zhesuan);
				//========================================
				
				dbg.setCheck_result(rec_grd_cd.getCheck_result());
				dbg.setCheck_opr(rec_grd_cd.getCheck_opr());
				dbg.setDisposal_result(rec_grd_cd.getDisposal_result());
				
				dbg.setMemo(rec_grd_cd.getMemo());
				dbg.setUpdate_opr(userName);
				dbg.setUpdate_time(new Date());
				dbg.setSerial_no(rec_grd_cd.getSerial_no());
				this.getMapper(DevRollerGrindingMapper.class).update(dbg);
				
			}else{
				/**
				 * <update id="doUpdate1" parameterType="HashMap">
						    update dev_blade_grinding																																							
				       set dia_outer_aft   = null, --修磨后外径																																							
				           check_result    = null, --鉴定结果（1：合格、0：不合格）																																							
				           check_opr       = null, --鉴定人																																							
				           disposal_result = null, --处置结果（0：可用、1：重修、9：报废）	
				           grd_thick       = null, --磨削量																																							
				           converted_cost  = null, --折算成本																																							
				           memo            = null, --备注（可为空）																																							
				           update_opr      = #{param2},																																							
				           update_time     = sysdate																																							
				     where serial_no = #{param1}																																						
					</update>
				 */
				this.getMapper(DevRollerGrindingMapper.class).doUpdate1(sum.getMemo1(),userName);
			}
			//提交事务
			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;
	}
	
}
