/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-11-29
 * 描述            ：工器具-轧辊配辊从表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Mes.Dev.impl;
import java.util.Date;
import java.util.List;

import market.Api.Mes.impl.MesApiRollPdiPdoImpl;
import market.Api.Mes.impl.MesApiTpmPdiPdoImpl;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Mes.Dev.mapper.DevRollerInfoMapper;
import market.Mes.Dev.mapper.DevRollerPairDMapper;
import market.Mes.Dev.mapper.DevRollerPairMMapper;
import market.Mes.Dev.service.DevRollerPairDService;
import market.Mes.Dev.vo.DevRollerInfo;
import market.Mes.Dev.vo.DevRollerPairD;
import market.Mes.Dev.vo.DevRollerPairM;
import market.Mes.Tpm.mapper.IfTpm01LogMapper;

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="DevRollerPairDService")
public class DevRollerPairDServiceImpl extends BaseServiceImpl<DevRollerPairD,Object> implements DevRollerPairDService {


	/**
	 * 根据轧辊配辊主表查询轧辊配辊从表
	 * memo1：配辊记录号(serial_no)
	 */
	public ResultModel doQueryWeb(CommonPage<DevRollerPairD> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(DevRollerPairDMapper.class).doQueryWeb(oci.getMemo1()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 动作处理_配辊按钮
	 * object:
	 * rollers_gap：辊缝     pair_memo:备注
	 * //memo1:配辊记录号    暂时不需要
 	 * memo2:机架号
	 * memo3:上辊编号
	 * memo4:下辊编号
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doRollerPairWeb(CommonPage<DevRollerInfo> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(userName==null){
				userName="";
			}
			String wrk_ord = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
			String wrk_grp = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
			//String wrk_date = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_TIME);
			if(wrk_ord==null){
				wrk_ord="";
			}
			if(wrk_grp==null){
				wrk_grp="";
			}
			DevRollerInfo dri = sum.getObject();//rollers_gap   pair_memo
			

			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;
			}
			if(sum.getMemo4()==null || "".equals(sum.getMemo4())){
				rm.setState("500");
				rm.setMsgInfo("未指定下辊编号！");
				return rm;
			}
			if(sum.getMemo3().equals(sum.getMemo4())){
				rm.setState("500");
				rm.setMsgInfo("上辊编号与下辊编号相同，不允许此操作！");
				return rm;
			}
			
			//  --(2)、验证刀片编号存在
			List<DevRollerInfo> t_dri_list=this.getMapper(DevRollerInfoMapper.class).findWithCondition(null, "roller_no='"+sum.getMemo3()+"'", null, 0, 0);
			if(t_dri_list==null || t_dri_list.size()<=0){
				rm.setState("500");
				rm.setMsgInfo("轧辊编号{"+sum.getMemo3()+"} 系统中不存在此轧辊编号！");
				return rm;
			}
			List<DevRollerInfo> b_dri_list=this.getMapper(DevRollerInfoMapper.class).findWithCondition(null, "roller_no='"+sum.getMemo4()+"'", null, 0, 0);
			if(b_dri_list==null || b_dri_list.size()<=0){
				rm.setState("500");
				rm.setMsgInfo("轧辊编号{"+sum.getMemo3()+"} 系统中不存在此轧辊编号！");
				return rm;
			}
//			if(!"T".equals(t_dri_list.get(0).getRoller_position())){
//				rm.setState("500");
//				rm.setMsgInfo("轧辊编号{"+sum.getMemo3()+"} 基础信息中轧辊位置为下辊，配辊方式错误！");
//				return rm;
//			}
//			if(!"B".equals(b_dri_list.get(0).getRoller_position())){
//				rm.setState("500");
//				rm.setMsgInfo("轧辊编号{"+sum.getMemo4()+"} 基础信息中轧辊位置为上辊，配辊方式错误！");
//				return rm;
//			}
			
			DevRollerPairM  drpm=new DevRollerPairM();
			//  --(3)、修磨记录号：'G' + YYYYMMDD + 3位流水
			String v_serial_no="M"+new SimpleDateFormat("yyyyMMdd").format(new Date());
			//  --(3.1)、获取当前起始流水号
			Integer v_cnt1=this.getMapper(DevRollerPairMMapper.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");
			drpm.setSerial_no(v_serial_no);
			drpm.setMachine_code(t_dri_list.get(0).getMachine_code());
			drpm.setRoller_type(t_dri_list.get(0).getRoller_type());
			drpm.setStand_id(sum.getMemo2());
			drpm.setT_roller_no(t_dri_list.get(0).getRoller_no());
			drpm.setT_manufacturer_no(t_dri_list.get(0).getManufacturer_no());
			drpm.setB_roller_no(b_dri_list.get(0).getRoller_no());
			drpm.setB_manufacturer_no(b_dri_list.get(0).getManufacturer_no());
			drpm.setRollers_gap(dri==null?null:dri.getRollers_gap());
			drpm.setRollers_dia_diff((t_dri_list.get(0).getDia_current()-b_dri_list.get(0).getDia_current())+"");
			drpm.setPair_ord(wrk_ord);
			drpm.setPair_grp(wrk_grp);
			drpm.setPair_time(new Date());
			//??? 当前使用次数（轧制卷数，修磨后清零）
			//drpm.setRll_num(rll_num);//轧制卷数
			//drpm.setRll_len(rll_len);//轧制里程数（km）
			//drpm.setRll_wgt(rll_wgt);//轧制吨数（吨）
			drpm.setStatus("1");
			drpm.setSend_l2("0");
			drpm.setPair_memo(dri==null?null:dri.getPair_memo());
			drpm.setCreate_opr(userName);
			drpm.setCreate_time(new Date());
			//PAIR_OPR01 PAIR_OPR02 PAIR_OPR03 MOUNT_REASON_CODE MOUNT_REASON_DESC
			this.getMapper(DevRollerPairMMapper.class).insert(drpm);
			
			
			DevRollerPairD t_drpd=new DevRollerPairD();
			t_drpd.setSerial_no(v_serial_no);
			t_drpd.setRoller_position("T");
			t_drpd.setMachine_code(t_dri_list.get(0).getMachine_code());
			t_drpd.setRoller_type(t_dri_list.get(0).getRoller_type());
			t_drpd.setRoller_no(t_dri_list.get(0).getRoller_no());
			t_drpd.setManufacturer_no(t_dri_list.get(0).getManufacturer_no());
			t_drpd.setStand_id(sum.getMemo2());
			t_drpd.setMaterial_code(t_dri_list.get(0).getMaterial_code());
			t_drpd.setMaterial_name(t_dri_list.get(0).getMaterial_name());
			t_drpd.setDia_current(t_dri_list.get(0).getDia_current());
			t_drpd.setWgt_current(t_dri_list.get(0).getWgt_current());
			t_drpd.setDensity(t_dri_list.get(0).getDensity());
			t_drpd.setRoughness(t_dri_list.get(0).getRoughness());
			t_drpd.setHardness(t_dri_list.get(0).getHardness());
			t_drpd.setRoll_profile(t_dri_list.get(0).getRoll_profile());
			t_drpd.setRoundness(t_dri_list.get(0).getRoundness());
			t_drpd.setRunout(t_dri_list.get(0).getRunout());
			t_drpd.setConvexity(t_dri_list.get(0).getConvexity());
			t_drpd.setConvexity_max(t_dri_list.get(0).getConvexity_max());
			t_drpd.setConvexity_min(t_dri_list.get(0).getConvexity_min());
			t_drpd.setCone_len(t_dri_list.get(0).getCone_len());
			t_drpd.setCone_hgt(t_dri_list.get(0).getCone_hgt());
			t_drpd.setBrollc_length(t_dri_list.get(0).getBrollc_length());
			t_drpd.setBrollc_deepth(t_dri_list.get(0).getBrollc_deepth());
			t_drpd.setSoft_point(t_dri_list.get(0).getSoft_point());
			t_drpd.setCrack(t_dri_list.get(0).getCrack());
			t_drpd.setCur_use_times(t_dri_list.get(0).getCur_use_times());
			t_drpd.setCur_rll_len(t_dri_list.get(0).getCur_rll_len());
			t_drpd.setCur_rll_wgt(t_dri_list.get(0).getCur_rll_wgt());
			t_drpd.setTtl_use_times(t_dri_list.get(0).getTtl_use_times());
			t_drpd.setTtl_rll_len(t_dri_list.get(0).getTtl_rll_len());
			t_drpd.setTtl_rll_wgt(t_dri_list.get(0).getTtl_rll_wgt());
			t_drpd.setTtl_grd_times(t_dri_list.get(0).getTtl_grd_times());
			t_drpd.setMemo(t_dri_list.get(0).getMemo());
			t_drpd.setCreate_opr(userName);
			t_drpd.setCreate_time(new Date());
			this.getMapper(DevRollerPairDMapper.class).insert(t_drpd);
			
			DevRollerPairD b_drpd=new DevRollerPairD();
			b_drpd.setSerial_no(v_serial_no);
			b_drpd.setRoller_position("B");
			b_drpd.setMachine_code(b_dri_list.get(0).getMachine_code());
			b_drpd.setRoller_type(b_dri_list.get(0).getRoller_type());
			b_drpd.setRoller_no(b_dri_list.get(0).getRoller_no());
			b_drpd.setManufacturer_no(b_dri_list.get(0).getManufacturer_no());
			b_drpd.setStand_id(sum.getMemo2());
			b_drpd.setMaterial_code(b_dri_list.get(0).getMaterial_code());
			b_drpd.setMaterial_name(b_dri_list.get(0).getMaterial_name());
			b_drpd.setDia_current(b_dri_list.get(0).getDia_current());
			b_drpd.setWgt_current(b_dri_list.get(0).getWgt_current());
			b_drpd.setDensity(b_dri_list.get(0).getDensity());
			b_drpd.setRoughness(b_dri_list.get(0).getRoughness());
			b_drpd.setHardness(b_dri_list.get(0).getHardness());
			b_drpd.setRoll_profile(b_dri_list.get(0).getRoll_profile());
			b_drpd.setRoundness(b_dri_list.get(0).getRoundness());
			b_drpd.setRunout(b_dri_list.get(0).getRunout());
			b_drpd.setConvexity(b_dri_list.get(0).getConvexity());
			b_drpd.setConvexity_max(b_dri_list.get(0).getConvexity_max());
			b_drpd.setConvexity_min(b_dri_list.get(0).getConvexity_min());
			b_drpd.setCone_len(b_dri_list.get(0).getCone_len());
			b_drpd.setCone_hgt(b_dri_list.get(0).getCone_hgt());
			b_drpd.setBrollc_length(b_dri_list.get(0).getBrollc_length());
			b_drpd.setBrollc_deepth(b_dri_list.get(0).getBrollc_deepth());
			b_drpd.setSoft_point(b_dri_list.get(0).getSoft_point());
			b_drpd.setCrack(b_dri_list.get(0).getCrack());
			b_drpd.setCur_use_times(b_dri_list.get(0).getCur_use_times());
			b_drpd.setCur_rll_len(b_dri_list.get(0).getCur_rll_len());
			b_drpd.setCur_rll_wgt(b_dri_list.get(0).getCur_rll_wgt());
			b_drpd.setTtl_use_times(b_dri_list.get(0).getTtl_use_times());
			b_drpd.setTtl_rll_len(b_dri_list.get(0).getTtl_rll_len());
			b_drpd.setTtl_rll_wgt(b_dri_list.get(0).getTtl_rll_wgt());
			b_drpd.setTtl_grd_times(b_dri_list.get(0).getTtl_grd_times());
			b_drpd.setMemo(b_dri_list.get(0).getMemo());
			b_drpd.setCreate_opr(userName);
			b_drpd.setCreate_time(new Date());
			this.getMapper(DevRollerPairDMapper.class).insert(b_drpd);
			
			//轧辊状态（0：可配辊、1：待修磨、2：修磨中、3：已配辊、4：在线、5：报废）
			DevRollerInfo dri_t=new DevRollerInfo();
			dri_t.setRoller_no(t_dri_list.get(0).getRoller_no());
			dri_t.setStatus("3");
			dri_t.setUpdate_opr(userName);
			dri_t.setUpdate_time(new Date());
			dri_t.setStand_id(sum.getMemo2());//机架号
			dri_t.setRoller_position("T");
			dri_t.setPair_roller_no(b_dri_list.get(0).getRoller_no());
			this.getMapper(DevRollerInfoMapper.class).update(dri_t);
			DevRollerInfo dri_b=new DevRollerInfo();
			dri_b.setRoller_no(b_dri_list.get(0).getRoller_no());
			dri_b.setStatus("3");
			dri_b.setUpdate_opr(userName);
			dri_b.setUpdate_time(new Date());
			dri_b.setStand_id(sum.getMemo2());//机架号
			dri_b.setRoller_position("B");
			dri_b.setPair_roller_no(t_dri_list.get(0).getRoller_no());
			this.getMapper(DevRollerInfoMapper.class).update(dri_b);
			
			//提交事务
			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<DevRollerPairM> 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(DevRollerPairMMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("配辊记录号{"+sum.getMemo1()+"} 配辊记录不存在！");
				return rm;
			}
			List<DevRollerPairM> ldbgg = this.getMapper(DevRollerPairMMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
			DevRollerPairM v_rec_grd = ldbgg.get(0);
			//状态（1：配对、2：上机、3：下机、0：拆卸）
			if("2".equals(v_rec_grd.getStatus())){
				rm.setState("500");
				rm.setMsgInfo("配辊记录号{"+sum.getMemo1()+"} 已上机，记录不允许删除！");
				return rm;
			}else if("3".equals(v_rec_grd.getStatus())){
				rm.setState("500");
				rm.setMsgInfo("配辊记录号{"+sum.getMemo1()+"} 已下机，记录不允许删除！");
				return rm;
			}else if("0".equals(v_rec_grd.getStatus())){
				rm.setState("500");
				rm.setMsgInfo("配辊记录号{"+sum.getMemo1()+"} 已拆卸，记录不允许删除！");
				return rm;
			}
			
			if(!"1".equals(v_rec_grd.getStatus())){
				rm.setState("500");
				rm.setMsgInfo("只有配对状态的数据允许删除！");
				return rm;
			}
			if(v_rec_grd.getT_roller_no()==null){
				rm.setState("500");
				rm.setMsgInfo("上辊轧辊编号为空，信息出错！");
				return rm;
			}
			if(v_rec_grd.getB_roller_no()==null){
				rm.setState("500");
				rm.setMsgInfo("下辊轧辊编号为空，信息出错！");
				return rm;
			}
			
			//轧辊状态（0：可配辊、1：待修磨、2：修磨中、3：已配辊、4：在线、5：报废）
			DevRollerInfo dri_t=new DevRollerInfo();
			dri_t.setRoller_no(v_rec_grd.getT_roller_no());
			dri_t.setStatus("0");
			dri_t.setUpdate_opr(userName);
			dri_t.setUpdate_time(new Date());
			dri_t.setStand_id("");//机架号
			dri_t.setRoller_position("");
			dri_t.setPair_roller_no("");
			this.getMapper(DevRollerInfoMapper.class).update(dri_t);
			DevRollerInfo dri_b=new DevRollerInfo();
			dri_b.setRoller_no(v_rec_grd.getB_roller_no());
			dri_b.setStatus("0");
			dri_b.setUpdate_opr(userName);
			dri_b.setUpdate_time(new Date());
			dri_b.setStand_id("");//机架号
			dri_b.setRoller_position("");
			dri_b.setPair_roller_no("");
			this.getMapper(DevRollerInfoMapper.class).update(dri_b);
			
			
			this.getMapper(DevRollerPairMMapper.class).delete(sum.getMemo1());
			this.getMapper(DevRollerPairDMapper.class).doDelete(sum.getMemo1());
			
			//提交事务
			rm.setMsgInfo("删除成功");
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			throw new Exception("删除失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 动作处理_发送到L2
	 * memo1:配辊记录号
	 * memo2:mch_code机台代码
	 * @throws Exception 
	 * */
	public ResultModel Roller01L3SendPdi(CommonPage<DevRollerPairM> sum) throws Exception{
		ResultModel rm=new ResultModel();
		if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
			rm.setState("500");
			rm.setMsgInfo("参数错误：机台代码不能为空！");
			return rm;
		}
		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(DevRollerPairMMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
		if(v_cnt<=0){
			rm.setState("500");
			rm.setMsgInfo("配辊记录号{"+sum.getMemo1()+"} 配辊记录不存在！");
			return rm;
		}
		List<DevRollerPairM> ldbgg = this.getMapper(DevRollerPairMMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
		DevRollerPairM v_rec_grd = ldbgg.get(0);
		//状态（1：配对、2：上机、3：下机、0：拆卸）
		if("3".equals(v_rec_grd.getStatus())){
			rm.setState("500");
			rm.setMsgInfo("配辊记录号{"+sum.getMemo1()+"} 已下机。");
			return rm;
		}else if("0".equals(v_rec_grd.getStatus())){
			rm.setState("500");
			rm.setMsgInfo("配辊记录号{"+sum.getMemo1()+"} 已拆卸。");
			return rm;
		}
		if(v_rec_grd.getT_roller_no()==null){
			rm.setState("500");
			rm.setMsgInfo("上辊轧辊编号为空，信息出错！");
			return rm;
		}
		if(v_rec_grd.getB_roller_no()==null){
			rm.setState("500");
			rm.setMsgInfo("下辊轧辊编号为空，信息出错！");
			return rm;
		}
		
		//  --(2)、轧辊配辊管理-【发送配辊信息至L2】
		String v_message="";
		try{
			if(sum.getMemo2().equals("M0007")){
				v_message=this.getBean(MesApiTpmPdiPdoImpl.class).Tpm01L3Roller_d(sum.getMemo2(),sum.getMemo1(), v_rec_grd.getRoller_type(), userName, v_message);
			}else if(sum.getMemo2().equals("M0008")){
				v_message=this.getBean(MesApiRollPdiPdoImpl.class).Roll01L3Roller_d(sum.getMemo2(),sum.getMemo1(), v_rec_grd.getRoller_type(), userName, v_message);
			}
			
		}catch(Exception e){
			e.printStackTrace();
			v_message=e.getMessage();
		}
		String v_param="机台代码 {"+sum.getMemo2()+"} 配辊记录号 {"+sum.getMemo1()+"} 操作人 {"+userName+"}";
		// --(3)、写接口日志：与业务处理分开，单独的事务
		try{
			this.getMapper(IfTpm01LogMapper.class).doInsert("","Tpm01L3Roller",v_param,v_message);
		}catch(Exception e){
			e.printStackTrace();
		}
		rm.setMsgInfo(v_message);
		rm.setState("200");
		return rm;
	}
	
	/**
	 * 动作处理_拆辊按钮
	 * memo1:配辊记录号
	 * */
	@Transactional(value="tm", rollbackFor=Exception.class)
	public ResultModel doRemovalWeb(CommonPage<DevRollerPairM> sum) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(userName==null){
				userName="";
			}
			String wrk_ord = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_ORD);
			String wrk_grp = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_GRP);
			if(wrk_ord==null){
				wrk_ord="";
			}
			if(wrk_grp==null){
				wrk_grp="";
			}
			
			//String wrk_date = (String) this.getSession().getAttribute(HomeService.SESSION_WORK_TIME);
			if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
				rm.setState("500");
				rm.setMsgInfo("未指定配辊记录号！");
				return rm;
			}
			
			Integer v_cnt=this.getMapper(DevRollerPairMMapper.class).countWithCondition(null, "serial_no='"+sum.getMemo1()+"'");
			if(v_cnt<=0){
				rm.setState("500");
				rm.setMsgInfo("配辊记录号{"+sum.getMemo1()+"} 配辊记录不存在！");
				return rm;
			}
			List<DevRollerPairM> ldbgg = this.getMapper(DevRollerPairMMapper.class).findWithCondition(null, "serial_no='"+sum.getMemo1()+"'", null, 0, 0);
			DevRollerPairM v_rec_grd = ldbgg.get(0);
			//状态（1：配对、2：上机、3：下机、0：拆卸）
			if("0".equals(v_rec_grd.getStatus())){
				rm.setState("500");
				rm.setMsgInfo("配辊记录号{"+sum.getMemo1()+"} 已拆卸！");
				return rm;
			}else if("1".equals(v_rec_grd.getStatus())){
				rm.setState("500");
				rm.setMsgInfo("配辊记录号{"+sum.getMemo1()+"} 配对状态，暂不允许此操作！！");
				return rm;
			}else if("2".equals(v_rec_grd.getStatus())){
				rm.setState("500");
				rm.setMsgInfo("配辊记录号{"+sum.getMemo1()+"} 上机状态，暂不允许此操作！！");
				return rm;
			}
			if(!"3".equals(v_rec_grd.getStatus())){
				rm.setState("500");
				rm.setMsgInfo("只有下机状态的数据允许拆辊！");
				return rm;
			}
			
			if(v_rec_grd.getT_roller_no()==null){
				rm.setState("500");
				rm.setMsgInfo("上辊轧辊编号为空，信息出错！");
				return rm;
			}
			if(v_rec_grd.getB_roller_no()==null){
				rm.setState("500");
				rm.setMsgInfo("下辊轧辊编号为空，信息出错！");
				return rm;
			}
			
			//轧辊状态（0：可配辊、1：待修磨、2：修磨中、3：已配辊、4：在线、5：报废）
			DevRollerInfo dri_t=new DevRollerInfo();
			dri_t.setRoller_no(v_rec_grd.getT_roller_no());
			dri_t.setStatus("1");
			this.getMapper(DevRollerInfoMapper.class).update(dri_t);
			DevRollerInfo dri_b=new DevRollerInfo();
			dri_b.setRoller_no(v_rec_grd.getB_roller_no());
			dri_b.setStatus("1");
			this.getMapper(DevRollerInfoMapper.class).update(dri_b);
			//状态（1：配对、2：上机、3：下机、0：拆卸）
			DevRollerPairM drpm=new DevRollerPairM();
			drpm.setSerial_no(sum.getMemo1());
			drpm.setUnpair_ord(wrk_ord);
			drpm.setUnpair_grp(wrk_grp);
			drpm.setUnpair_time(new Date());
			drpm.setStatus("0");
			drpm.setUpdate_opr(userName);
			drpm.setUpdate_time(new Date());
			this.getMapper(DevRollerPairMMapper.class).update(drpm);
			
			DevRollerPairD t_drpd=new DevRollerPairD();
			t_drpd.setSerial_no(v_rec_grd.getSerial_no());
			//轧辊位置（T：上辊、B：下辊）
			t_drpd.setRoller_position("T");
			t_drpd.setUpdate_opr(userName);
			t_drpd.setUpdate_time(new Date());
			this.getMapper(DevRollerPairDMapper.class).update(t_drpd);
			
			DevRollerPairD b_drpd=new DevRollerPairD();
			b_drpd.setSerial_no(v_rec_grd.getSerial_no());
			//轧辊位置（T：上辊、B：下辊）
			b_drpd.setRoller_position("B");
			b_drpd.setUpdate_opr(userName);
			b_drpd.setUpdate_time(new Date());
			this.getMapper(DevRollerPairDMapper.class).update(b_drpd);
			
			//提交事务
			rm.setMsgInfo("拆辊成功");
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			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;
	}
	
}
