/***文档注释***********************************************
 * 作者            ：  周浴超
 * 创建日期     ：2018-02-06
 * 描述            ：冶金规范摘要表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Qms.metallurgy.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import market.Com.impl.ComBaseChemServiceImpl;
import market.Com.mapper.ComBasePhyMapper;
import market.Com.mapper.ComBaseProcessMapper;
import market.Com.mapper.ComBaseSampleMapper;
import market.Com.mapper.ComPscMapper;
import market.Com.mapper.ComPscRDeliveryMapper;
import market.Com.vo.ComBasePhy;
import market.Com.vo.ComBaseProcess;
import market.Com.vo.ComBaseSample;
import market.Com.vo.ComPsc;
import market.Com.vo.ComPscRDelivery;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.com.mapper.BaseDeliverystateMapper;
import market.Qms.com.vo.BaseDeliverystate;
import market.Qms.common.DataHelper;
import market.Qms.common.ReturnMsg;
import market.Qms.metallurgy.impl.ComMscStdSpecServiceImpl.Status;
import market.Qms.metallurgy.mapper.ComBaseStdMapper;
import market.Qms.metallurgy.mapper.ComMscBacklogMapper;
import market.Qms.metallurgy.mapper.ComMscCicSampleMapper;
import market.Qms.metallurgy.mapper.ComMscGradeMapper;
import market.Qms.metallurgy.mapper.ComMscMapper;
import market.Qms.metallurgy.mapper.ComMscPhySampleMapper;
import market.Qms.metallurgy.mapper.ComMscProcessMapper;
import market.Qms.metallurgy.mapper.ComMscStationMapper;
import market.Qms.metallurgy.mapper.ComMscStdChemMapper;
import market.Qms.metallurgy.mapper.ComMscStdCicMapper;
import market.Qms.metallurgy.mapper.ComMscStdDetectionCMapper;
import market.Qms.metallurgy.mapper.ComMscStdDetectionMapper;
import market.Qms.metallurgy.mapper.ComMscStdPhyMapper;
import market.Qms.metallurgy.mapper.ComMscStdPicMapper;
import market.Qms.metallurgy.mapper.ComMscStdSpecCMapper;
import market.Qms.metallurgy.mapper.ComMscStdSpecMapper;
import market.Qms.metallurgy.mapper.ComPscRMscMapper;
import market.Qms.metallurgy.service.ComMscService;
import market.Qms.metallurgy.vo.ComBaseStd;
import market.Qms.metallurgy.vo.ComMsc;
import market.Qms.metallurgy.vo.ComMscBacklog;
import market.Qms.metallurgy.vo.ComMscCicSample;
import market.Qms.metallurgy.vo.ComMscGrade;
import market.Qms.metallurgy.vo.ComMscPhySample;
import market.Qms.metallurgy.vo.ComMscProcess;
import market.Qms.metallurgy.vo.ComMscStation;
import market.Qms.metallurgy.vo.ComMscStdChem;
import market.Qms.metallurgy.vo.ComMscStdCic;
import market.Qms.metallurgy.vo.ComMscStdDetection;
import market.Qms.metallurgy.vo.ComMscStdDetectionC;
import market.Qms.metallurgy.vo.ComMscStdPhy;
import market.Qms.metallurgy.vo.ComMscStdPic;
import market.Qms.metallurgy.vo.ComMscStdSpec;
import market.Qms.metallurgy.vo.ComMscStdSpecC;
import market.Qms.metallurgy.vo.ComPscRMsc;
import market.Qms.metallurgy.vo.Composition_standard;
import market.Qms.metallurgy.vo.Material_standard;
import market.Qms.metallurgy.vo.Process;
import market.Qms.metallurgy.vo.Standard_detection;
import market.Qms.metallurgy.vo.Tolerance_standard;
import market.Qms.qcm.mapper.ComMscProcessRCraftMapper;
import market.Qms.qcm.mapper.ComMscStationRCraftMapper;

import org.springframework.transaction.annotation.Transactional;

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

@RemoteService(path = "ComMscService")
@Transactional(value = "tm", rollbackFor = Exception.class)
public class ComMscServiceImpl extends BaseServiceImpl<ComMsc, Object> implements ComMscService {

	/**
	 * 查询产品规范信息
	 * 
	 * @return
	 */
	public ResultModel doFindPsc(CommonPage<ComPsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			ComPsc psc = sm.getObject();
			rm.setData(this.getMapper(ComMscMapper.class).doFindPsc(psc.getProd_name(), psc.getSteel_name(),
					psc.getStd_name(), psc.getPsc(), psc.getMsc()));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 查询 msc
	 */
	public ResultModel doFindMsc(CommonPage<ComPsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			String code = sm.getObject().getPsc();
			String val = sm.getObject().getValidflag();
			String msc = sm.getMemo1();
			if (val.equals("D")) {
				val = "";
			}
			rm.setData(this.getMapper(ComMscMapper.class).doFindMsc(code, val, msc));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 查询msc
	 */
	public ResultModel doFindMscNk(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {

			ComMsc com = sm.getObject();
			rm.setData(this.getMapper(ComMscMapper.class).find(com, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败");
		}
		return rm;
	}

	/**
	 * 获取成分标准信息
	 */
	public ResultModel doFindStdCic(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			String val = sm.getMemo3();
			if (val.equals("1")) {
			} else {
				val = "";
			}
			rm.setData(this.getMapper(ComMscStdCicMapper.class).doFindCic(sm.getMemo1(), sm.getMemo2(), val));
			rm.setState("200");
		} catch (Exception e) {
			rm.setMsgInfo("获取成分标准信息失败");
			e.printStackTrace();
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 获取取样要求COM_BASE_SAMPLE
	 */
	public ResultModel doFindSample(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		ComBaseSample sa = new ComBaseSample();
		try {
			String smp = sm.getMemo1();
			sa.setSmp_type(smp);
			sa.setValidflag("1");
			rm.setData(this.getMapper(ComBaseSampleMapper.class).find(sa, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取取样要求失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 获取成品成分偏差标准COM_BASE_STD
	 */
	public ResultModel doFindStd() {
		ResultModel rm = new ResultModel();
		try {
			ComBaseStd std = new ComBaseStd();
			std.setStdType("P");
			std.setValidflag("1");
			rm.setData(this.getMapper(ComBaseStdMapper.class).find(std, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取成分偏差标准");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 获取交货状况COM_PSC_R_DELIVERY
	 */
	public ResultModel dofindDelivery(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			ComPscRDelivery del = new ComPscRDelivery();
			del.setPsc(sm.getMemo1());
			rm.setData(this.getMapper(ComPscRDeliveryMapper.class).find(del, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取交货状态失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 获取产品大类COM_BASE_PRODUCT
	 */
	public ResultModel doaFindProduct(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			String id = sm.getMemo1();
			rm.setData(this.getMapper(ComMscMapper.class).doFindLine(id));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取产品大类失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 材质标准
	 */
	/**
	 * 获取材质标准索引号COM_MSC_STD_PIC
	 */
	public ResultModel doFindPic(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			String val = sm.getMemo3();
			if (val.equals("1")) {
			} else {
				val = "";
			}
			rm.setData(this.getMapper(ComMscStdPicMapper.class).doFindPic(sm.getMemo1(), sm.getMemo2(), val));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取材质标准索引失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 查询产品规范定义表COM_PSC
	 */
	public ResultModel doFindpscs(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			ComPsc psc = new ComPsc();
			psc.setPsc(sm.getMemo1());
			rm.setData(this.getMapper(ComPscMapper.class).find(psc, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取产品规范失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	/**
	 * 查询产品规范定义表COM_PSC(分页)
	 */
	public ResultModel doFindpscsPage(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			ReturnMsg<List<ComPsc>> msg = new ReturnMsg<>();
			ComMscMapper mapper=this.getMapper(ComMscMapper.class);
			ComPsc psc = new ComPsc();
//			psc.setPsc(sm.getMemo1());
//			psc.setProd_name(sm.getObject().getProd_name());
//			psc.setSteel_name(sm.getObject().getSteel_name());
			String condition = "1=1";
			if (!DataHelper.IsNullOrSpace(sm.getObject().getProd_name())) {
				condition += "and LOWER(PROD_NAME) LIKE '%'||LOWER('"+sm.getObject().getProd_name()+"')||'%'";
			}
			if (!DataHelper.IsNullOrSpace(sm.getObject().getSteel_name())) {
				condition += "and LOWER(STEEL_NAME) LIKE '%'||LOWER('"+sm.getObject().getSteel_name()+"')||'%'";
			}
//			Integer pageSize= sm.getPageSize()*(sm.getPageIndex()-1);
//			Integer pageIndex=sm.getPageSize()*(sm.getPageIndex()-1)+sm.getPageSize();
			List<ComPsc> total = this.getMapper(ComPscMapper.class).findWithCondition(null, condition, null, (sm.getPageIndex()-1)*sm.getPageSize(), sm.getPageSize());
			int count=mapper.countWithCondition(sm.getObject(), condition);
			msg.setResult(total);
			msg.setSuccess(true);
			msg.setTotal(count);
			rm.setData(msg);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取产品规范失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	/**
	 * 查询产品规范定义表COM_PSC(免检信息配置界面调用)
	 */
	public ResultModel doFindpscs1(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		ComMsc cms=sm.getObject();
		try {
			String conn="1=1";
			if (!DataHelper.IsNullOrSpace(cms.getProd_name())) {
				conn+=" and prod_name like '%"+cms.getProd_name()+"%'";
			}
			if (!DataHelper.IsNullOrSpace(cms.getStd_name())) {
				conn+=" and std_name like '%"+cms.getStd_name()+"%'";
			}
			if (!DataHelper.IsNullOrSpace(cms.getSteel_name())) {
				conn+=" and steel_name like '%"+cms.getSteel_name()+"%'";
			}
			rm.setData(this.getMapper(ComPscMapper.class).findWithCondition(null, conn, null, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取产品规范失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	/**
	 * 获取标准类型COM_BASE_STD
	 */
	public ResultModel doFindBzlx(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			ComBaseStd std = new ComBaseStd();
			std.setStdCode(sm.getMemo1());
			rm.setData(this.getMapper(ComBaseStdMapper.class).find(std, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取标准类型失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 成分标准信息COM_MSC_STD_CHEM
	 */
	public ResultModel GetChem(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			ComMscStdChem chem = new ComMscStdChem();
			chem.setCic(sm.getMemo1());
			if (sm.getMemo2().equals("1")) {
				chem.setValidflag("1");
			}
			rm.setState("200");
			rm.setData(this.getMapper(ComMscStdChemMapper.class).findWithCondition(chem, null, "INDEX_SEQ", 0, 0));
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取成分标准类型失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 公差标准-查询
	 */
	public ResultModel doFindspec(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			String val = sm.getMemo3();
			if (val.equals("1")) {
			} else {
				val = "";
			}
			rm.setData(this.getMapper(ComMscStdSpecMapper.class).doFinidSpec(sm.getMemo2(), sm.getMemo1(), val));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取公差标准失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 获取探伤标准索引号COM_MSC_STD_DETECTION
	 */

	public ResultModel dofindDetection(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			String val = sm.getMemo3();
			if (val.equals("1")) {
			} else {
				val = "";
			}
			rm.setData(
					this.getMapper(ComMscStdDetectionMapper.class).doFindDetection(sm.getMemo2(), sm.getMemo1(), val));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取探伤标准失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 材质检验项下拉框COM_BASE_PHY
	 */

	public ResultModel doFindPhys() {
		ResultModel rm = new ResultModel();
		try {
			ComBasePhy phy = new ComBasePhy();
			phy.setValidflag("1");
			rm.setData(this.getMapper(ComBasePhyMapper.class).find(phy, 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取材质检验失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 成分标准-保存：成分标准：将获取的【成分标准索引信息】写入化学元素标准索引表（COM_MSC_STD_CIC），
	 * 取样要求信息写入成分标准取样要求表（COM_MSC_CIC_SAMPLE），
	 * 化学成分【标准信息】关联成分标准索引号写入化学元素标准表（COM_MSC_STD_CHEM）；
	 */
	public ResultModel DoAddCf(Composition_standard com) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscStdCic> cic = com.getObjectList1();
			// List<ComMscCicSample> sample =com.getObjectList2();
			List<ComMscStdChem> chem = com.getObjectList3();
			if (cic.size() > 0) {
				for (int i = 0; i < cic.size(); i++) {
					// 为空则新增
					String cinNo = this.getMapper(ComMscStdCicMapper.class).getmaxNOs();
					if (cic.get(i).getCic() == null || "".equals(cic.get(i).getCic())) {
						String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
						cic.get(i).setCreate_name(username);
						cic.get(i).setCreate_time(new Date());
						cic.get(i).setCic(cinNo);
						this.getMapper(ComMscStdCicMapper.class).insert(cic.get(i));
					} else {
						// 不为空为更新
						String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
						cic.get(i).setUpdate_name(username);
						cic.get(i).setUpdate_time(new Date());
						this.getMapper(ComMscStdCicMapper.class).update(cic.get(i));
					}
				}
			}
			if (chem.size() > 0) {
				for (ComMscStdChem ch : chem) {
					boolean b = true;
					if (ch.getChemType().equals("A")) {
					} else {
						b = this.getBean(ComBaseChemServiceImpl.class).complexIsValid(ch.getChemFormula());
					}
					if (b) {
						if (ch.getIndexSeq() == null) {
							String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
							ch.setCreateName(username);
							if (DataHelper.IsNullOrSpace(ch.getCic())) {
								ch.setCic(cic.get(0).getCic());
							}
							String seq = this.getMapper(ComMscStdChemMapper.class).GetMaxIndexSeq(ch.getCic());
							if (seq == null || "".equals(seq)) {
								ch.setIndexSeq(1);
							} else {
								ch.setIndexSeq(Integer.valueOf(seq).intValue());
							}
							ch.setCreateTime(new Date());
							this.getMapper(ComMscStdChemMapper.class).insert(ch);
						} else {
							String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
							ch.setUpdateName(username);
							ch.setUpdateTime(new Date());
							this.getMapper(ComMscStdChemMapper.class).update(ch);
						}
					} else {
						rm.setMsgInfo("化学元素项不存在");
					}
				}
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			e.printStackTrace();
			rm.setMsgInfo("保存失败：" + e.getMessage());
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 成分标准-作废成分内控： 通过成分标准索引号(CIC)更新化学元素标准索引表（COM_MSC_STD_CIC）、
	 * 成分标准取样要求表（COM_MSC_CIC_SAMPLE）及化学元素标准表（COM_MSC_STD_CHEM）中对应记录状态为无效（
	 * VALIDFLAG=0）；
	 * 通过选中记录成分标准索引号(CIC)及序号（INDEX_SEQ）更新化学元素标准表（COM_MSC_STD_CHEM）中对应记录状态为无效（
	 * VALIDFLAG=0）
	 */
	public ResultModel DoZfCf(Composition_standard com) {
		ResultModel rm = new ResultModel();
		List<ComMscStdCic> cic = com.getObjectList1();
		List<ComMscStdChem> chem = com.getObjectList3();
		String name = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try {
			for (ComMscStdCic c : cic) {
				if ("".equals(name) || name == null) {
					name = c.getCreate_name();
				}
				c.setValidflag("0");
				c.setDelete_name(name);
				c.setDelete_time(new Date());
				this.getMapper(ComMscStdCicMapper.class).update(c);
				// 同时作废子表
				this.getMapper(ComMscStdChemMapper.class).updatecicZf(c.getCic(), name);
			}
			if (chem.size() > 0) {
				this.getBean(ComMscStdChemServiceImpl.class).doInvalidB(chem);
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			e.printStackTrace();
			rm.setMsgInfo("作废成分标准失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 成分标准-恢复成分内控： A:成分内控：通过成分标准索引号(CIC)更新化学元素标准索引表（COM_MSC_STD_CIC）、
	 * 及化学元素标准表（COM_MSC_STD_CHEM）中对应记录状态为有效（VALIDFLAG=1）；
	 */
	public ResultModel doHfCf(Composition_standard com) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscStdCic> cic = com.getObjectList1();
			List<ComMscStdChem> chem = com.getObjectList3();
			this.getBean(ComMscStdCicServiceImpl.class).doRecoverCicAndChem(cic);
			if (cic.size() > 0) {
				for (ComMscStdCic c : cic) {
					this.getMapper(ComMscStdChemMapper.class).updatecicHf(c.getCic());
				}
			}
			this.getBean(ComMscStdChemServiceImpl.class).doRecoverB(chem);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			e.printStackTrace();
			rm.setMsgInfo("恢复成分内控失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	/**
	 * 材质标准：将获取的【材质标准索引信息】写入材质标准索引表（COM_MSC_STD_PIC），
	 * 获取材质【标准信息】关联材质标准索引号写入材质标准表（COM_MSC_STD_PHY）；
	 */
	public ResultModel doAddCz(Material_standard ms) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscStdPic> pic = ms.getObjectList1();
			List<ComMscStdPhy> phy = ms.getObjectList3();
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if (pic.size() > 0) {
				for (ComMscStdPic cms : pic) {
					if (cms.getPic() != null) {
						ComMscStdPic ComMscStdPic = this.getMapper(ComMscStdPicMapper.class).findById(cms.getPic());
						if (ComMscStdPic != null) {
							cms.setUpdateName(userName);
							cms.setUpdateTime(new Date());
							cms.setValidflag(Status.RECOVER.getValue());
							this.getMapper(ComMscStdPicMapper.class).update(cms);
							rm.setState("200");
							rm.setMsgInfo("更新成功!");
						}
					} else {
						String picNo = this.getMapper(ComMscStdPicMapper.class).getMaxs();
						cms.setPic(picNo);
						cms.setCreateName(userName);
						cms.setCreateTime(new Date());
						cms.setValidflag(Status.RECOVER.getValue());// 默认为 1
						this.getMapper(ComMscStdPicMapper.class).insert(cms);
						rm.setState("200");
						rm.setMsgInfo("新增成功!");
					}
				}
			}
			if (phy.size() > 0) {
				if (DataHelper.IsNullOrSpace(phy.get(0).getPic()) && pic.size() > 0) {
					for (ComMscStdPhy comMscStdPhy : phy) {
						comMscStdPhy.setPic(pic.get(0).getPic());
					}
				}
				this.getBean(ComMscStdPhyServiceImpl.class).doSaveComMscStdPhy(phy);
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 材质标准-作废
	 */
	public ResultModel doZfBz(Material_standard ms) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscStdPic> pic = ms.getObjectList1();
			List<ComMscStdPhy> phy = ms.getObjectList3();
			this.getBean(ComMscStdPicServiceImpl.class).doInvalid(pic);
			String name = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if (pic.size() > 0) {
				for (ComMscStdPic p : pic) {
					if ("".equals(name) || name == null) {
						name = p.getCreateName();
					}
					this.getMapper(ComMscStdPhyMapper.class).updateZf(p.getPic(), name);
				}
			}
			this.getBean(ComMscStdPhyServiceImpl.class).doInvalidB(phy);
			rm.setState("200");
		} catch (Exception e) {
			e.printStackTrace();
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 标准信息-恢复
	 */
	public ResultModel doHfBz(Material_standard ms) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscStdPic> pic = ms.getObjectList1();
			List<ComMscStdPhy> phy = ms.getObjectList3();
			this.getBean(ComMscStdPicServiceImpl.class).doRecover(pic);
			if (pic.size() > 0) {
				for (ComMscStdPic p : pic) {
					this.getMapper(ComMscStdPhyMapper.class).updateHf(p.getPic());
					;
				}
			}
			this.getBean(ComMscStdPhyServiceImpl.class).doRecoverB(phy);
			rm.setState("200");
		} catch (Exception e) {
			e.printStackTrace();
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * C：公差标准：将获取的【公差标准索引信息】写入公差标准表（COM_MSC_STD_SPEC），
	 * 获取公差【标准信息】关联公差标准索引号写入公差标准表（COM_MSC_STD_SPEC_C）；
	 */
	public ResultModel doAddGc(Tolerance_standard tol) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscStdSpec> spec = tol.getObjectList1();
			List<ComMscStdSpecC> specC = tol.getObjectList2();
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			Date date = new Date();
			if (spec.size() > 0) {
				for (ComMscStdSpec cms : spec) {
					if (cms.getSic() != null && !"".equals(cms.getSic())) {
						ComMscStdSpec com = this.getMapper(ComMscStdSpecMapper.class).findById(cms.getSic());
						if (com != null) {
							cms.setUpdateName(userName);
							cms.setUpdateTime(date);
							this.getMapper(ComMscStdSpecMapper.class).update(cms);
							rm.setState("200");
							rm.setMsgInfo("更新成功");
						}
					} else {
						// 获取主键
						String sic = this.getMapper(ComMscStdSpecMapper.class).getMaxs();
						cms.setSic(sic);
						cms.setCreateName(userName);
						cms.setCreateTime(new Date());
						cms.setValidflag(Status.RECOVER.getValue());
						if (sic != null) {
							this.getMapper(ComMscStdSpecMapper.class).insert(cms);
							rm.setState("200");
							rm.setMsgInfo("新增成功");
						}
					}
				}
			}
			if (specC.size() > 0) {
				if (DataHelper.IsNullOrSpace(specC.get(0).getSic()) && spec.size() > 0) {
					for (ComMscStdSpecC comMscStdSpecC : specC) {
						comMscStdSpecC.setSic(spec.get(0).getSic());
					}
				}
				this.getBean(ComMscStdSpecCServiceImpl.class).doSaveComMscStdSpecC(specC);
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 公差标准-废除
	 * 
	 * @param tol
	 * @return
	 */
	public ResultModel doFzGc(Tolerance_standard tol) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscStdSpec> spec = tol.getObjectList1();
			List<ComMscStdSpecC> specC = tol.getObjectList2();
			this.getBean(ComMscStdSpecServiceImpl.class).doInvalidA(spec);
			String name = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if (spec.size() > 0) {
				for (ComMscStdSpec s : spec) {
					if ("".equals(name) || name == null) {
						name = s.getCreateName();
					}
					this.getMapper(ComMscStdSpecCMapper.class).updateSicZf(s.getSic(), name);
				}
			}
			this.getBean(ComMscStdSpecCServiceImpl.class).doInvalidB(specC);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 公差标准-恢复
	 * 
	 * @param tol
	 * @return
	 */
	public ResultModel doHfGc(Tolerance_standard tol) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscStdSpec> spec = tol.getObjectList1();
			List<ComMscStdSpecC> specC = tol.getObjectList2();
			this.getBean(ComMscStdSpecServiceImpl.class).doRecoverA(spec);
			if (spec.size() > 0) {
				for (ComMscStdSpec s : spec) {
					this.getMapper(ComMscStdSpecCMapper.class).updateSicHf(s.getSic());
				}
			}
			this.getBean(ComMscStdSpecCServiceImpl.class).doRecoverB(specC);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 探伤标准-保存 探伤标准：将获取的【探伤标准索引信息】写入探伤要求主表（COM_MSC_STD_DETECTION），
	 * 获取探伤【标准信息】关联探伤标准索引号写入探伤要求从表（COM_MSC_STD_DETECTION_C）；
	 */
	public ResultModel doAddTs(Standard_detection sd) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscStdDetection> ction = sd.getObjectList1();
			List<ComMscStdDetectionC> ctionC = sd.getObjectList2();
			String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			Date date = new Date();
			if (ction.size() > 0) {
				for (ComMscStdDetection com : ction) {
					if (com.getDic() != null) {
						com.setUpdateName(userName);
						com.setUpdateTime(date);
						this.getMapper(ComMscStdDetectionMapper.class).update(com);

					} else {
						String dic = this.getMapper(ComMscStdDetectionMapper.class).getMaxs();
						com.setDic(dic);
						com.setCreateName(userName);
						com.setCreateTime(new Date());
						this.getMapper(ComMscStdDetectionMapper.class).insert(com);
						rm.setState("200");
					}
				}
			}
			if (ctionC.size() > 0) {
				if (DataHelper.IsNullOrSpace(ctionC.get(0).getDic()) && ction.size() > 0) {
					for (ComMscStdDetectionC comMscStdDetectionC : ctionC) {
						comMscStdDetectionC.setDic(ction.get(0).getDic());
					}
				}

				this.getBean(ComMscStdDetectionCServiceImpl.class).doSaveComMscStdDetectionC(ctionC);
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 探伤标准-废除
	 * 
	 * @param sd
	 * @return
	 */
	public ResultModel doFcTs(Standard_detection sd) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscStdDetection> ction = sd.getObjectList1();
			List<ComMscStdDetectionC> ctionC = sd.getObjectList2();
			this.getBean(ComMscStdDetectionServiceImpl.class).doInvalidA(ction);
			String name = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if (ction.size() > 0) {
				for (ComMscStdDetection c : ction) {
					if ("".equals(name) || name == null) {
						name = c.getCreateName();
					}
					this.getMapper(ComMscStdDetectionCMapper.class).updateDicZf(c.getDic(), name);
				}
			}
			this.getBean(ComMscStdDetectionCServiceImpl.class).doInvalidB(ctionC);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 探伤标准-恢复
	 * 
	 * @param sd
	 * @return
	 */
	public ResultModel doHfTs(Standard_detection sd) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscStdDetection> ction = sd.getObjectList1();
			List<ComMscStdDetectionC> ctionC = sd.getObjectList2();
			this.getBean(ComMscStdDetectionServiceImpl.class).doRecoverA(ction);
			if (ction.size() > 0) {
				for (ComMscStdDetection c : ction) {
					this.getMapper(ComMscStdDetectionCMapper.class).updateDicHf(c.getDic());
				}
			}
			this.getBean(ComMscStdDetectionCServiceImpl.class).doRecoverB(ctionC);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 制程-查询 冶金规范产线表COM_MSC_BACKLOG
	 */
	public ResultModel doFindBackLog(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			String msc = sm.getMemo1();
			String val = sm.getMemo2();
			if (sm.getMemo2().equals("1")) {
			} else {
				val = "";
			}
			List<ComMscBacklog> back = this.getMapper(ComMscBacklogMapper.class).doFindZc(msc, val);
			for (ComMscBacklog comMscBacklog : back) {
				if (comMscBacklog.getDelivery_state_code()!=null && !"".equals(comMscBacklog.getDelivery_state_code())) {
					String delivery_state_desc=null;
					String[] delivery=comMscBacklog.getDelivery_state_code().split(",");
					if (delivery!=null && delivery.length>0) {
						for (String d : delivery) {
							BaseDeliverystate base=this.getMapper(BaseDeliverystateMapper.class).findById(d);
							if (base!=null && base.getDeliveryStateDesc()!=null && !"".equals(base.getDeliveryStateDesc())) {
								if (delivery_state_desc==null || "".equals(delivery_state_desc)) {
									delivery_state_desc=base.getDeliveryStateDesc();
								}else {
									delivery_state_desc+=","+base.getDeliveryStateDesc();
								}
							}
						}
						comMscBacklog.setDelivery_state_desc(delivery_state_desc);
					}
					
				}
				
			}
			rm.setData(back);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 制程-新增
	 */

	public ResultModel doAddZc(Process ps) {
		ResultModel rm = new ResultModel();
		// 写入冶金规范产线表（COM_MSC_BACKLOG）
		ComMscBacklog log = ps.getObject1();
		// 获取全程产线号
		String mscpline = this.getMapper(ComMscBacklogMapper.class).GetMaxNo(log.getMsc());
		String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		log.setMsc_pline(mscpline);
		log.setValidflag("1");
		// 获取当前登录人
		log.setCreate_name(username);
		log.setCreate_time(new Date());
		this.getMapper(ComMscBacklogMapper.class).insert(log);
		// 写入冶金规范工序表（COM_MSC_PROCESS）
		List<ComMscProcess> cessList = ps.getObject2();
		if (cessList.size() > 0) {
			for (ComMscProcess cess : cessList) {
				cess.setMsc_pline(mscpline);
				cess.setValidflag("1");
				cess.setGuid(DataHelper.getUUID());
				cess.setCreate_name(username);
				cess.setCreate_time(new Date());
				this.getMapper(ComMscProcessMapper.class).insert(cess);
			}
		}
		// 写入冶金规范工序点表(制程)（COM_MSC_STATION）
		List<ComMscStation> stationList = ps.getObject3();
		if (stationList.size() > 0) {
			for (ComMscStation station : stationList) {
				station.setMsc_pline(mscpline);
				station.setValidflag("1");
				long seq = 1L;
				station.setGuid(DataHelper.getUUID());
				station.setProcess_seq(seq);
				station.setCreate_name(username);
				station.setCreate_time(new Date());
				this.getMapper(ComMscStationMapper.class).insert(station);
			}
		}
		rm.setState("200");
		return rm;

	}

	/**
	 * 制程-修改
	 */
	public ResultModel doUpdateZc(CommonPage<Process> sm) {
		ResultModel rm = new ResultModel();

		List<Process> pList = sm.getObjectList();
		for (Process ps : pList) {
			// 写入冶金规范产线表（COM_MSC_BACKLOG）
			ComMscBacklog log = ps.getObject1();
			String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			log.setUpdate_name(username);
			log.setUpdate_time(new Date());
			this.getMapper(ComMscBacklogMapper.class).UpdateLoG(log);
			if (log.getDelivery_state_code()==null || "".equals(log.getDelivery_state_code())) {
				this.getMapper(ComMscBacklogMapper.class).UpdateDelivery(log.getMsc(),log.getMsc_pline());
			}
			String mscpline = log.getMsc_pline();
			// 写入冶金规范工序表（COM_MSC_PROCESS）
			this.getMapper(ComMscProcessMapper.class).deletemsc(log.getMsc(), log.getMsc_pline());
			List<ComMscProcess> cessList = ps.getObject2();
			if (cessList != null && cessList.size() > 0) {
				for (ComMscProcess comMscProcess : cessList) {
					this.getMapper(ComMscProcessMapper.class).deletemsc(comMscProcess.getMsc(),
							comMscProcess.getMsc_pline());
				}
				for (ComMscProcess cess : cessList) {
					cess.setGuid(DataHelper.getUUID());
					cess.setMsc_pline(mscpline);
					// Long
					// seq=this.getMapper(ComMscProcessMapper.class).GetMaxNo(cess.getProcess_code(),cess.getProcess_code_c());
					cess.setValidflag("1");
					cess.setCreate_name(username);
					cess.setCreate_time(new Date());
					this.getMapper(ComMscProcessMapper.class).insert(cess);
				}
			}
			// 写入冶金规范工序点表(制程)（COM_MSC_STATION）
			List<ComMscStation> stationList = ps.getObject3();
			if (stationList != null && stationList.size() > 0) {
				for (ComMscStation comMscStation : stationList) {
					ComMscStation sta = new ComMscStation();
					sta.setMsc(comMscStation.getMsc());
					sta.setMsc_pline(comMscStation.getMsc_pline());
					this.getMapper(ComMscStationMapper.class).deleteStation(sta.getMsc(), sta.getMsc_pline());
				}
				for (ComMscStation station : stationList) {
					station.setGuid(DataHelper.getUUID());
					station.setMsc_pline(mscpline);
					station.setValidflag("1");
					long seq = 1L;
					station.setProcess_seq(seq);
					station.setCreate_name(username);
					station.setCreate_time(new Date());
					this.getMapper(ComMscStationMapper.class).insert(station);
				}
			}
		}
		rm.setState("200");
		return rm;
	}

	/**
	 * 修改修改制程逻辑
	 * @throws Exception 
	 */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doUpdateZc2(CommonPage<Process> sm) throws Exception {
		ResultModel rm = new ResultModel();

		List<Process> pList = sm.getObjectList();
		for (Process ps : pList) {
			// 写入冶金规范产线表（COM_MSC_BACKLOG）
			ComMscBacklog log = ps.getObject1();
			String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			log.setUpdate_name(username);
			log.setUpdate_time(new Date());
			this.getMapper(ComMscBacklogMapper.class).UpdateLoG(log);
			String mscpline = log.getMsc_pline();

			// 查询工序表，根据冶金规范码和全程产线号查询COM_MSC_PROCESS，查询制程下的所有工序
			List<ComMscProcess> oldProcess = this.getMapper(ComMscProcessMapper.class).findWithCondition(null,
					"MSC='" + log.getMsc() + "' and MSC_PLINE='" + log.getMsc_pline() + "'", null, 0, 0);
			// 修改后的目标工序集合
			List<ComMscProcess> cessList = ps.getObject2();

			// 如果目标工序集合存在，并且数据库中的该全程产线号向下存在工序
			if (cessList != null && cessList.size() > 0 && oldProcess != null && oldProcess.size() > 0) {

				// 遍历目标集合
				for (int i = 0; i < cessList.size(); i++) {

					// 目标工序对用的工序点
					List<ComMscStation> tarStation = cessList.get(i).getProcessPoint();
					// 如果当前的前台传入的工序的guid不存在，代表是新添加的工序
					if (cessList.get(i).getGuid() == null || "".equals(cessList.get(i).getGuid() )) {
						// 生成新的工序
						createNewProcess(cessList.get(i), mscpline, username);

						// 如果当前新增工序的工序点存在，新增该工序的工序点
						if (tarStation != null && tarStation.size() > 0) {
							// 新增工序点
							for (ComMscStation comMscStation : tarStation) {
								createStation(comMscStation, mscpline, username);
							}
						}
						// 跳出本次循环
						continue;
					}

					// 如果guid不是空，遍歷集合，查找匹配的guid進行更新
					for (int j = 0; j < oldProcess.size(); j++) {
						if (cessList.get(i).getGuid().equals( oldProcess.get(j).getGuid())) {

							// 删除工序表
							this.getMapper(ComMscProcessMapper.class).deleteByGuid(cessList.get(i).getGuid());
							//重新生成记录
							//createNewProcess(cessList.get(i), mscpline, username);66
							createOldProcess(cessList.get(i), mscpline, username);

							// 查询當前工序下是否存在工序点记录
							List<ComMscStation> stationList = this.getMapper(ComMscStationMapper.class)
									.findWithCondition(null,
											"MSC='" + cessList.get(i).getMsc() + "' and MSC_PLINE='"
													+ cessList.get(i).getMsc_pline() + "' and PROCESS_CODE='"
													+ cessList.get(i).getProcess_code() + "' and BACKLOG_SEQ='"+oldProcess.get(j).getBacklog_seq()+"'",
											null, 0, 0);

							// 如果該工序下的在数据库中存在工序点
							if (stationList != null && stationList.size() > 0) {
								// 如果目标工序点不为空，进行比较
								if (tarStation != null && tarStation.size() > 0) {
									// 遍历目标工序点
									for (ComMscStation comMscStation : tarStation) {

										// 如果当前工序点的guid为空，需要重新生成工序点
										if (comMscStation.getGuid() == null || "".equals(comMscStation.getGuid() )) {
											// 生成新的工序点
											createStation(comMscStation, mscpline, username);
											continue;
										}

										// 存在guid
										for (int k = 0; k < stationList.size(); k++) {
											// 当前工序点与数据库中的工序点的guid匹配时，更新当前guid对应的工序点
											if (stationList.get(k).getGuid().equals(comMscStation.getGuid())) {
												// 更新guid对应的工序点,工序点存在需要更新。
												//this.getMapper(ComMscStationMapper.class).update(tcomMscStation);
												//删除工序点表
												String guid=stationList.get(k).getGuid();
												this.getMapper(ComMscStationMapper.class)
												.deleteByGuid(stationList.get(k).getGuid());
												//重新新增工序点
												this.createOldStation(comMscStation, mscpline, username);
												//this.createStation(comMscStation, mscpline, username);
												break;

											}
										}
										

									}

									// 反向验证，删除数据库中存在，但目标集合中不存在的工序点
									/*stationList = this.getMapper(ComMscStationMapper.class).findWithCondition(null,
											"MSC='" + cessList.get(i).getMsc() + "' and MSC_PLINE='"
													+ cessList.get(i).getMsc_pline() + "' and PROCESS_CODE='"
													+ cessList.get(i).getProcess_code() + "'",
											null, 0, 0);*/

									for (int k = 0; k < stationList.size(); k++) {

										for (int k2 = 0; k2 < tarStation.size(); k2++) {
											if (stationList.get(k).getGuid().equals(tarStation.get(k2).getGuid())) {
												break;
											}

											if (k2 == tarStation.size() - 1) {
												// 删除该guid对应的工序点
												this.getMapper(ComMscStationMapper.class)
														.deleteByGuid(stationList.get(k).getGuid());
												//删除工艺标准
												this.getMapper(ComMscStationRCraftMapper.class).deleteByGuid(stationList.get(k).getGuid());
												
											}
										}

									}

								} else {
									// 删除数据库中对应的工序点
									for (ComMscStation comMscStation : stationList) {
										this.getMapper(ComMscStationMapper.class).deleteByGuid(comMscStation.getGuid());
										//删除工序点对应的工艺
										this.getMapper(ComMscStationRCraftMapper.class).deleteByGuid(comMscStation.getGuid());
									}

								}

							} else {

								// 当前工序对应的工序点在数据库中不存在数据时，判断工序点集合是否存在，如果存在，添加工序点
								if (tarStation != null && tarStation.size() > 0) {
									// 生成新的工序点
									for (ComMscStation station : tarStation) {
										this.createStation(station, mscpline, username);
									}
								}

							}

						}

						
						/* if (j == oldProcess.size() - 1) {
							 
							 //删除工序
							 
							 //删除工序点
							 
							 //删除工序对应的工艺标准
							 this.getMapper(ComMscProcessRCraftMapper.class).deleteByGuid(cessList.get(i).getGuid());
							 
							 
							 
							 
						  
						  }*/
						 

					}
					
					
					
					

				}
				
				//工序双向验证
				for (ComMscProcess old : oldProcess) {
					
					for (int i = 0; i < cessList.size(); i++) {
						
						if (cessList.get(i).getGuid()==null || "".equals(cessList.get(i).getGuid())) {
							break;
						}
						if (old.getGuid().equals(cessList.get(i).getGuid())) {
							break;
						}
						if (i == cessList.size()-1) {
							//查询工序点
							List<ComMscStation> tars = this.getMapper(ComMscStationMapper.class)
									.findWithCondition(null,
											"MSC='" + old.getMsc() + "' and MSC_PLINE='"
													+ old.getMsc_pline() + "' and PROCESS_CODE='"
													+ old.getProcess_code() + "' and BACKLOG_SEQ='"+old.getBacklog_seq()+"'",
											null, 0, 0);
							for (ComMscStation comMscStation : tars) {
								this.getMapper(ComMscStationMapper.class).deleteByGuid(comMscStation.getGuid());
								//删除工序点对应的工艺
								this.getMapper(ComMscStationRCraftMapper.class).deleteByGuid(comMscStation.getGuid());
							}
							// 删除工序表
							this.getMapper(ComMscProcessMapper.class).deleteByGuid(old.getGuid());
							//删除工艺表
							this.getMapper(ComMscProcessRCraftMapper.class).deleteByGuid(old.getGuid());
							//删除炼钢牌号表
							String cics=old.getCic();
							String[] cic=null;
							if (cics!=null && !"".equals(cics)) {
								cic=cics.split(",");
								for (String c : cic) {
									this.getMapper(ComMscGradeMapper.class).deleteByCondition(old.getMsc(),old.getMsc_pline(),c);			
								}
								
							}

						}
						
					}
					
				}

			} else {
				// 如果修改的目标集合为空，删除数据库中的该全程产线号下的工序
				if ((cessList == null || cessList.size() < 1) && (oldProcess != null && oldProcess.size() > 0)) {
					for (ComMscProcess comMscProcess : oldProcess) {
						// 删除工序
						this.getMapper(ComMscProcessMapper.class).deletemsc(comMscProcess.getMsc(),
								comMscProcess.getMsc_pline());
						//删除工艺表
						this.getMapper(ComMscProcessRCraftMapper.class).deleteByGuid(comMscProcess.getGuid());
						//删除炼钢牌号表
						String cics=comMscProcess.getCic();
						String[] cic=null;
						if (cics!=null && !"".equals(cics)) {
							cic=cics.split(",");
							for (String c : cic) {
								this.getMapper(ComMscGradeMapper.class).deleteByCondition(comMscProcess.getMsc(),comMscProcess.getMsc_pline(),c);			
							}
							
						}
						//删除工艺要求
						List<ComMscStation> tars = this.getMapper(ComMscStationMapper.class)
								.findWithCondition(null,
										"MSC='" + comMscProcess.getMsc() + "' and MSC_PLINE='"
												+ comMscProcess.getMsc_pline() + "' and PROCESS_CODE='"
												+ comMscProcess.getProcess_code() + "' and BACKLOG_SEQ='"+comMscProcess.getBacklog_seq()+"'",
										null, 0, 0);
						for (ComMscStation comMscStation : tars) {
							this.getMapper(ComMscStationMapper.class).deleteByGuid(comMscStation.getGuid());
							//删除工序点对应的工艺
							this.getMapper(ComMscStationRCraftMapper.class).deleteByGuid(comMscStation.getGuid());
						}
						

					}
					// 删除所有工序关联的工序点
					//this.getMapper(ComMscStationMapper.class).deleteStation(log.getMsc(), log.getMsc_pline());
				} else {
					// 如果修改的目标集合不为空，数据库中为空，将目标集合添加
					for (ComMscProcess cess : cessList) {
						createNewProcess(cess, mscpline, username);

						// 将工序点添加到表
						if (cess.getProcessPoint() != null && cess.getProcessPoint().size() > 0) {

							for (ComMscStation station : cess.getProcessPoint()) {
								this.createStation(station, mscpline, username);

							}

						}

					}

				}

			}

		}
		rm.setState("200");
		return rm;
	}
	
	
	/**
	 * 修改制程最新版
	 * @param cess
	 * @param mscpline
	 * @param username
	 */
	
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doUpdateZc3(CommonPage<Process> sm) throws Exception {

		ResultModel rm = new ResultModel();

		try {

			List<Process> pList = sm.getObjectList();
			// 数据验证
			for (Process ps : pList) {
				ComMscBacklog log = ps.getObject1();
				if (log == null) {
					rm.setMsgInfo("请传入全程产线号");
					rm.setState("500");
					return rm;
				}
				List<ComMscProcess> cessList = ps.getObject2();
				if (cessList == null || cessList.size() < 1) {
					rm.setMsgInfo("全程产线号[" + log.getMsc_pline() + "]向下的工序为空，请确认数据");
					rm.setState("500");
					return rm;
				}

				List<ComMscStation> tarStation = ps.getObject3();
				if (tarStation == null || tarStation.size() < 1) {
					rm.setMsgInfo("全程产线号[" + log.getMsc_pline() + "]向下的工序点为空，请确认数据");
					rm.setState("500");
					return rm;
				}

				// 验证每个工序是否存在工序点
				for (ComMscProcess process : cessList) {
					String proStation = DataHelper.Get00000(process.getMsc())
							+ DataHelper.Get00000(process.getMsc_pline())
							+ DataHelper.Get00000(process.getBacklog_seq().toString())
							+ DataHelper.Get00000(process.getProcess_code());
					for (int i = 0; i < tarStation.size(); i++) {
						String staStation = DataHelper.Get00000(tarStation.get(i).getMsc())
								+ DataHelper.Get00000(tarStation.get(i).getMsc_pline())
								+ DataHelper.Get00000(tarStation.get(i).getBacklog_seq().toString())
								+ DataHelper.Get00000(tarStation.get(i).getProcess_code());
						if (proStation.equals(staStation)) {
							break;
						}
						if (i == tarStation.size()-1) {
							rm.setMsgInfo("全程产线号[" + log.getMsc_pline() + "]向下的工序顺序号为[" + process.getBacklog_seq() + "]的工序["
									+ process.getProcess_desc() + "]向下的无工序点，请确认数据");
							rm.setState("500");
							return rm;
						}
					}
				}

				for (ComMscStation sti : tarStation) {
					if (sti.getBacklog_seq() == null) {
						rm.setMsgInfo("全程产线号[" + log.getMsc_pline() + "]向下的工序[" + sti.getProcess_desc() + "]向下的工序点["
								+ sti.getProcess_point_desc() + "]的工序顺序号为空，请确认数据");
						rm.setState("500");
						return rm;
					}
					if (sti.getProcess_point_seq() == null) {
						rm.setMsgInfo("全程产线号[" + log.getMsc_pline() + "]向下的工序顺序号为[" + sti.getBacklog_seq() + "]的工序["
								+ sti.getProcess_desc() + "]向下的工序点[" + sti.getProcess_point_desc()
								+ "]的工序点顺序号为空，请确认数据");
						rm.setState("500");
						return rm;
					}
				}

			}

			// 修改对象集合
			for (Process ps : pList) {
				// 写入冶金规范产线表（COM_MSC_BACKLOG）
				ComMscBacklog log = ps.getObject1();
				String username = this.getSession().getAttribute(HomeService.SESSION_USER_NAME).toString();;
				log.setUpdate_name(username);
				log.setUpdate_time(new Date());
				this.getMapper(ComMscBacklogMapper.class).UpdateLoG(log);
				String mscpline = log.getMsc_pline();

				// 修改后的目标工序集合
				List<ComMscProcess> cessList = ps.getObject2();

				// 查询工序表，根据冶金规范码和全程产线号查询COM_MSC_PROCESS，查询制程下的所有工序
				List<ComMscProcess> oldProcess = this.getMapper(ComMscProcessMapper.class).findWithCondition(null,
						"MSC='" + log.getMsc() + "' and MSC_PLINE='" + log.getMsc_pline() + "'", null, 0, 0);

				// 保存删除的工序集合
				List<ComMscProcess> delProcess = new ArrayList<ComMscProcess>();
				List<ComMscStation> delStation = new ArrayList<ComMscStation>();

				// 工序判断
				for (ComMscProcess old : oldProcess) {

					for (int i = 0; i < cessList.size(); i++) {

						if (old.getGuid().equals(cessList.get(i).getGuid())) {
							break;
						}
						if (i == cessList.size() - 1) {
							delProcess.add(old);
						}

					}

				}

				// 遍历工序集合，查询工序点
				List<ComMscStation> tarStation = ps.getObject3();
				List<ComMscStation> oldStation = this.getMapper(ComMscStationMapper.class).findWithCondition(null,
						"MSC='" + log.getMsc() + "' and MSC_PLINE='" + log.getMsc_pline() + "'", null, 0, 0);

				for (ComMscStation old : oldStation) {

					for (int i = 0; i < tarStation.size(); i++) {

						if (old.getGuid().equals(tarStation.get(i).getGuid())) {
							break;
						}
						if (i == cessList.size() - 1) {
							delStation.add(old);
						}
					}

				}

				// 删除工序
				this.getMapper(ComMscProcessMapper.class).deletemsc(log.getMsc(), log.getMsc_pline());

				// 删除工序点
				this.getMapper(ComMscStationMapper.class).deletemsc(log.getMsc(), log.getMsc_pline());

				// 删除关联项
				for (ComMscProcess del : delProcess) {
					// 删除工艺表
					this.getMapper(ComMscProcessRCraftMapper.class).deleteByGuid(del.getGuid());
					// 删除炼钢牌号表
					String cics = del.getCic();
					String[] cic = null;
					if (cics != null && !"".equals(cics)) {
						cic = cics.split(",");
						for (String c : cic) {
							this.getMapper(ComMscGradeMapper.class).deleteByCondition(del.getMsc(), del.getMsc_pline(),
									c);
						}

					}
				}

				for (ComMscStation del : delStation) {
					this.getMapper(ComMscStationRCraftMapper.class).deleteByGuid(del.getGuid());
				}

				// 新增工序
				for (ComMscProcess ne : cessList) {
					// 生成新的工序
					createNewProcess(ne, mscpline, username);
				}

				// 新增工序点
				for (ComMscStation ne : tarStation) {
					createStation(ne, mscpline, username);
				}
			}

			rm.setState("200");
			rm.setMsgInfo("修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			throw new Exception("修改失败");
		}

		return rm;

	}
	
	

	/**
	 * 创建新工序
	 */
	private void createNewProcess(ComMscProcess cess, String mscpline, String username) {
		
		
		cess.setMsc_pline(mscpline);
		if (cess.getGuid()==null ||"".equals(cess.getGuid())) {
			cess.setGuid(DataHelper.getUUID());
			cess.setValidflag("1");
			cess.setCreate_name(username);
			cess.setCreate_time(new Date());
		}else{
			cess.setUpdate_name(username);
			cess.setUpdate_time(new Date());
		}
		// Long
		// seq=this.getMapper(ComMscProcessMapper.class).GetMaxNo(cess.getProcess_code(),cess.getProcess_code_c());	
		
		this.getMapper(ComMscProcessMapper.class).insert(cess);
	}

	/**
	 * 制程-作废
	 */
	public ResultModel dozfZc(CommonPage<ComMscBacklog> sm) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscBacklog> logList = sm.getObjectList();
			for (ComMscBacklog log : logList) {
				String msc = log.getMsc();
				String msc_pline = log.getMsc_pline();
				// 涉及的表：COM_MSC_BACKLOG--冶金规范产线表
				this.getMapper(ComMscBacklogMapper.class).UpdateZf(msc, msc_pline);
				// COM_MSC_PROCESS--冶金规范工序表
				this.getMapper(ComMscProcessMapper.class).UpdateZf(msc, msc_pline);
				// COM_MSC_STATION--冶金规范工序点表(制程)
				this.getMapper(ComMscStationMapper.class).UpdateZf(msc, msc_pline);
				// COM_MSC_GRADE--全程产线号与钢种对应表
				this.getMapper(ComMscGradeMapper.class).doUpdateZf(msc, msc_pline);
				// COM_MSC_GRADE_R_SPEC--制程钢种与成品规格对应表将涉及的表中满足条件的记录状态更新为无效（VALIDFLAG=‘0’）
				this.getMapper(ComMscStationMapper.class).UpdateZfs(msc, msc_pline);
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 制程-恢复
	 */
	public ResultModel doHfZc(CommonPage<ComMscBacklog> sm) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMscBacklog> logList = sm.getObjectList();
			for (ComMscBacklog log : logList) {
				String msc = log.getMsc();
				String msc_pline = log.getMsc_pline();
				// 涉及的表：COM_MSC_BACKLOG--冶金规范产线表
				this.getMapper(ComMscBacklogMapper.class).UpdateHf(msc, msc_pline);
				// COM_MSC_PROCESS--冶金规范工序表
				this.getMapper(ComMscProcessMapper.class).UpdateHf(msc, msc_pline);
				// COM_MSC_STATION--冶金规范工序点表(制程)
				this.getMapper(ComMscStationMapper.class).UpdateHf(msc, msc_pline);
				// COM_MSC_GRADE--全程产线号与钢种对应表
				this.getMapper(ComMscGradeMapper.class).doUpdatehf(msc, msc_pline);
				// COM_MSC_GRADE_R_SPEC--制程钢种与成品规格对应表将涉及的表中满足条件的记录状态更新为无效（VALIDFLAG=‘0’）
				this.getMapper(ComMscStationMapper.class).UpdateHfs(msc, msc_pline);
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("恢复失败");
		}
		return rm;
	}

	/**
	 * 工序信息查询COM_MSC_PROCESS
	 */
	public ResultModel doFindProcess(CommonPage<ComMscProcess> cs) {
		ResultModel rm = new ResultModel();
		try {
			ComMscProcess process = cs.getObject();
			rm.setData(
					this.getMapper(ComMscProcessMapper.class).doFindProcess(process.getMsc(), process.getMsc_pline()));
			rm.setState("200");

		} catch (Exception e) {
			e.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询制程-工序信息出错：" + e.getMessage());
		}
		return rm;
	}

	/**
	 * 保存msc
	 */
	public ResultModel doAddmsc(CommonPage<ComMsc> commsc) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMsc> mscList = commsc.getObjectList();
			for (ComMsc msc : mscList) {
				if (msc.getMsc() == null) {
					String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
					msc.setCreate_name(username);
					msc.setCreate_time(new Date());
					msc.setMsc(this.getMapper(ComMscMapper.class).GetMaxNo(msc.getPsc()));
					this.getMapper(ComMscMapper.class).insert(msc);
					// COM_PSC_R_MSC
					ComPscRMsc rmsc = new ComPscRMsc();
					rmsc.setPsc(msc.getPsc());
					rmsc.setPsc_desc(msc.getPsc_desc());
					rmsc.setAlpha_code(msc.getAlpha_code());
					rmsc.setAlpha_name(msc.getAlpha_name());
					rmsc.setMsc_desc(msc.getMsc_desc());
					rmsc.setCreate_name(username);
					rmsc.setCreate_time(new Date());
					rmsc.setMsc(msc.getMsc());
					rmsc.setCust_alpha_no(msc.getCust_alpha_no());
					this.getMapper(ComPscRMscMapper.class).insert(rmsc);
				} else {
					String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
					msc.setUpdate_name(username);
					msc.setUpdate_time(new Date());
					this.getMapper(ComMscMapper.class).update(msc);
					ComPscRMsc rmsc = new ComPscRMsc();
					rmsc.setPsc(msc.getPsc());
					rmsc.setPsc_desc(msc.getPsc_desc());
					rmsc.setAlpha_code(msc.getAlpha_code());
					rmsc.setAlpha_name(msc.getAlpha_name());
					rmsc.setCust_alpha_no(msc.getCust_alpha_no());
					rmsc.setMsc_desc(msc.getMsc_desc());
					rmsc.setUpdate_name(username);
					rmsc.setUpdate_time(new Date());
					rmsc.setMsc(msc.getMsc());
					this.getMapper(ComPscRMscMapper.class).update(rmsc);
				}
			}
			rm.setState("200");
		} catch (Exception e) {
			e.printStackTrace();
			rm.setState("500");
			rm.setErrorInfo(e.getMessage());
			rm.setMsgInfo("保存失败");
		}
		return rm;
	}

	/**
	 * 作废msc
	 */
	public ResultModel doZfMsc(CommonPage<ComMsc> commsc) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMsc> mscList = commsc.getObjectList();
			for (ComMsc msc : mscList) {
				msc.setValidflag("D");
				String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
				msc.setDelete_name(username);
				msc.setDelete_time(new Date());
				this.getMapper(ComMscMapper.class).update(msc);
				// COM_PSC_R_MSC
				ComPscRMsc rmsc = new ComPscRMsc();
				rmsc.setValidflag("0");
				rmsc.setDelete_name(username);
				rmsc.setDelete_time(new Date());
				rmsc.setMsc(msc.getMsc());
				rmsc.setPsc(msc.getPsc());
				this.getMapper(ComPscRMscMapper.class).update(rmsc);
				// 成分内控：通过msc作废化学元素标准索引表（COM_MSC_STD_CIC)
				this.getMapper(ComMscStdCicMapper.class).doMscZf(msc.getMsc());
				// 材质内控:通过msc作废COM_MSC_STD_PIC）
				this.getMapper(ComMscStdPicMapper.class).updateZf(msc.getMsc());
				;
				// 公差内控：通过公msc作废公差标准表（COM_MSC_STD_SPEC）
				this.getMapper(ComMscStdSpecMapper.class).updateMscZf(msc.getMsc());
				// 探伤内控：通过msc废除探伤要求主表（COM_MSC_STD_DETECTION）
				this.getMapper(ComMscStdDetectionMapper.class).updateZf(msc.getMsc());
				// 制程
				this.getMapper(ComMscBacklogMapper.class).SubmitD(msc.getMsc());
				this.getMapper(ComMscProcessMapper.class).SubmitD(msc.getMsc());
				this.getMapper(ComMscStationMapper.class).SubmitD(msc.getMsc());
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 恢复msc
	 */
	public ResultModel doHFMsc(CommonPage<ComMsc> commsc) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMsc> mscList = commsc.getObjectList();
			for (ComMsc msc : mscList) {
				msc.setValidflag("A");
				this.getMapper(ComMscMapper.class).update(msc);
				// COM_PSC_R_MSC
				ComPscRMsc rmsc = new ComPscRMsc();
				rmsc.setValidflag("1");
				rmsc.setMsc(msc.getMsc());
				rmsc.setPsc(msc.getPsc());
				this.getMapper(ComPscRMscMapper.class).update(rmsc);
				// 成分内控：通过msc恢复化学元素标准索引表（COM_MSC_STD_CIC)
				this.getMapper(ComMscStdCicMapper.class).doMscHf(msc.getMsc());
				// 材质内控:通过msc恢复COM_MSC_STD_PIC）
				this.getMapper(ComMscStdPicMapper.class).updateHf(msc.getMsc());
				;
				// 公差内控：通过公msc恢复公差标准表（COM_MSC_STD_SPEC）
				this.getMapper(ComMscStdSpecMapper.class).updateMscHf(msc.getMsc());
				// 探伤内控：通过msc恢复探伤要求主表（COM_MSC_STD_DETECTION）
				this.getMapper(ComMscStdDetectionMapper.class).updateHf(msc.getMsc());
				// 制程
				this.getMapper(ComMscBacklogMapper.class).SubmitA(msc.getMsc());
				this.getMapper(ComMscProcessMapper.class).SubmitA(msc.getMsc());
				this.getMapper(ComMscStationMapper.class).SubmitA(msc.getMsc());
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * msc-提交审核
	 */
	public ResultModel Submissionofaudit(CommonPage<ComMsc> commsc) {
		ResultModel rm =new ResultModel();
		rm.setState("200");
		try {
				List<ComMsc> mscList =commsc.getObjectList();
				for (ComMsc msc : mscList) {
					CommonPage<ComMsc> com =new CommonPage<ComMsc>();
					List<ComMsc> list =new ArrayList<ComMsc>();
					list.add(0, msc);
					com.setObjectList(list);
					rm=this.Auditverification(com);
					if (rm.getState().equals("200")) {
						//3、通过选中记录的冶金规范码（MSC）将冶金规范摘要表COM_MSC中对应记录状态更新为提交审核（VALIDFLAG=‘B’）；
						this.getMapper(ComMscMapper.class).Submission(msc.getMsc());
						//4、通过选中记录的冶金规范码（MSC）+全程产线号（存在多个则循环）（MSC_PLINE）将冶金规范产线表COM_MSC_BACKLOG中对应记录状态更新为提交审核（VALIDFLAG=‘2’）；
						this.getMapper(ComMscBacklogMapper.class).Submission(msc.getMsc());;
						//5、通过选中记录的冶金规范码（MSC）+成分标准索引号（存在多个则循环）（CIC）将化学元素标准索引表COM_MSC_STD_CIC中对应记录状态更新为提交审核（VALIDFLAG=‘2’）；
						this.getMapper(ComMscStdCicMapper.class).Submission(msc.getMsc());
						//6、通过选中记录的冶金规范码（MSC）+材质标准索引号（存在多个则循环）（PIC）将材质标准索引表COM_MSC_STD_PIC中对应记录状态更新为提交审核（VALIDFLAG=‘2’）；
						this.getMapper(ComMscStdPicMapper.class).Submission(msc.getMsc());
						//7、通过选中记录的冶金规范码（MSC）+公差标准索引号（存在多个则循环）（SIC）将公差标准表(主表)COM_MSC_STD_SPEC中对应记录状态更新为提交审核（VALIDFLAG=‘2’）；
						this.getMapper(ComMscStdSpecMapper.class).Submission(msc.getMsc());
						//8、通过选中记录的冶金规范码（MSC）+探伤标准索引号（存在多个则循环）（DIC）将探伤要求主表COM_MSC_STD_DETECTION中对应记录状态更新为提交审核（VALIDFLAG=‘2’）；
						this.getMapper(ComMscStdDetectionMapper.class).Submission(msc.getMsc());
					}
				}
			
		} catch (Exception e) {
			e.printStackTrace();
			rm.setMsgInfo("提交审核失败");
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * msc-审核
	 */
	public ResultModel Toexamine(CommonPage<ComMsc> commsc) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMsc> mscList = commsc.getObjectList();
			String s = commsc.getMemo1();
			// 审核说明
			String shsm = commsc.getMemo2();
			String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if (s.equals("1")) {
				for (ComMsc msc : mscList) {
					if (msc.getValidflag().equals("B")) {
						this.getMapper(ComMscMapper.class).Submit(msc.getMsc(), shsm, username);
						this.getMapper(ComMscBacklogMapper.class).Submit(msc.getMsc());
						;
						this.getMapper(ComMscStdCicMapper.class).Submit(msc.getMsc());
						this.getMapper(ComMscStdPicMapper.class).Submit(msc.getMsc());
						this.getMapper(ComMscStdSpecMapper.class).Submit(msc.getMsc());
						this.getMapper(ComMscStdDetectionMapper.class).Submit(msc.getMsc());
					} else if (msc.getValidflag().equals("E")) {
						this.getMapper(ComMscMapper.class).SubmitA(msc.getMsc(), shsm, username);
						this.getMapper(ComMscBacklogMapper.class).SubmitA(msc.getMsc());
						;
						this.getMapper(ComMscStdCicMapper.class).SubmitA(msc.getMsc());
						this.getMapper(ComMscStdPicMapper.class).SubmitA(msc.getMsc());
						this.getMapper(ComMscStdSpecMapper.class).SubmitA(msc.getMsc());
						this.getMapper(ComMscStdDetectionMapper.class).SubmitA(msc.getMsc());
					}
				}
			} else {
				for (ComMsc msc : mscList) {
					if (msc.getValidflag().equals("B")) {
						this.getMapper(ComMscMapper.class).SubmitA(msc.getMsc(), shsm, username);
						this.getMapper(ComMscBacklogMapper.class).SubmitA(msc.getMsc());
						;
						this.getMapper(ComMscStdCicMapper.class).SubmitA(msc.getMsc());
						this.getMapper(ComMscStdPicMapper.class).SubmitA(msc.getMsc());
						this.getMapper(ComMscStdSpecMapper.class).SubmitA(msc.getMsc());
						this.getMapper(ComMscStdDetectionMapper.class).SubmitA(msc.getMsc());
					} else if (msc.getValidflag().equals("E")) {
						this.getMapper(ComMscMapper.class).Submit(msc.getMsc(), shsm, username);
					}
				}
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 申请修改
	 */
	public ResultModel sQupdate(CommonPage<ComMsc> commsc) {
		ResultModel rm = new ResultModel();
		try {
			List<ComMsc> mscList = commsc.getObjectList();
			for (ComMsc msc : mscList) {
				this.getMapper(ComMscMapper.class).SubmitE(msc.getMsc());
			}
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 审核验证
	 */
	public ResultModel Auditverification(CommonPage<ComMsc> commsc) {
		ResultModel rm = new ResultModel();
		rm.setState("200");
		try {
			// 1)：验证提交审核的MSC记录向下制程是否存在（通过MSC查询冶金规范产线表COM_MSC_BACKLOG，判断是否存在有效记录），如果不存在，弹出对话框提示：“制程未维护，请维护制程信息！“
			List<ComMsc> mscList = commsc.getObjectList();
			for (ComMsc msc : mscList) {
				ComMscBacklog log = new ComMscBacklog();
				log.setMsc(msc.getMsc());
				log.setValidflag("1");
				List<ComMscBacklog> logList = this.getMapper(ComMscBacklogMapper.class).find(log, 0, 0);
				if (logList == null || logList.size() == 0) {
					rm.setState("500");
					rm.setMsgInfo("当前msc下不存在制程，请维护制程");
					return rm;
				}
				boolean b = true;
				for (ComMscBacklog com : logList) {
					// 2)：验证提交审核的MSC记录向下制程信息是否完整（通过MSC+MSC_PLINE查询冶金规范工序表COM_MSC_PROCESS，
					// 判断是否存在>=1的有效记录），如果不存在，弹出对话框提示：”制程维护不完整，请维护工序信息！”
					ComMscProcess process = new ComMscProcess();
					process.setMsc(com.getMsc());
					process.setMsc_pline(com.getMsc_pline());
					int count = this.getMapper(ComMscProcessMapper.class).count(process);
					if (count == 0) {
						b = false;
					}
					// 3)：验证选中MSC记录向下制程对应的炼钢牌号信息是否维护完整（
					// 通过MSC+MSC_PLINE查询全程产线号与钢种对应表COM_MSC_GRADE，判断是否存在>=1的有效记录），
					// 如果不存在，弹出对话框提示：“制程维护不完整，请维护炼钢牌号信息！“；
					List<ComMscProcess> listProcess=this.getMapper(ComMscProcessMapper.class).find(process, 0, 0);
					
					ComMscGrade grade = new ComMscGrade();
					grade.setMsc(com.getMsc());
					grade.setMsc_pline(com.getMsc_pline());
					grade.setValidflag("1");
					int counts = this.getMapper(ComMscGradeMapper.class).count(grade);
					
					
					for (ComMscProcess comMscProcess : listProcess) {
						ComBaseProcess cp=this.getMapper(ComBaseProcessMapper.class).findById(comMscProcess.getProcess_code());
					
						if (cp==null) {
							rm.setState("500");
							rm.setMsgInfo("工序基础信息"+comMscProcess.getProcess_desc()+"不存在，请维护！");
							return rm;
						}
					
						if ("1".equals(cp.getIs_grade())) {
							if (counts == 0) {
								// b = false;
								rm.setState("500");
								rm.setMsgInfo("制程维护不完整，请维护炼钢牌号信息！");
								return rm;
							}
							
						}
					
					}
					/*ComMscGrade grade = new ComMscGrade();
					grade.setMsc(com.getMsc());
					grade.setMsc_pline(com.getMsc_pline());
					grade.setValidflag("1");
					int counts = this.getMapper(ComMscGradeMapper.class).count(grade);
					if (counts == 0) {
						// b = false;
						rm.setState("500");
						rm.setMsgInfo("制程维护不完整，请维护炼钢牌号信息！");
						return rm;
					}*/
					if (b) {
						for (ComMscBacklog coms : logList) {
							// 获取制程向下工序点类型（成分类403201、材质类403202、公差类403203、探伤类403204（取并集）通过MSC+MSC_PLINE查询冶金规范工序点表(制程)COM_MSC_STATION进行获取）对交付标准完整性进行验证（存在多个制程则循环验证
							ComMscStation station = new ComMscStation();
							station.setMsc(coms.getMsc());
							station.setMsc_pline(coms.getMsc_pline());
							station.setValidflag("1");
							List<ComMscStation> tionList = this.getMapper(ComMscStationMapper.class).find(station, 0,
									0);
							for (ComMscStation ation : tionList) {
								// 1)：如果制程中存在成分类工序点类型，则验证交付标准_成分标准向下是否存在有效的成分标准索引记录（通过MSC查询化学元素标准索引表COM_MSC_STD_CIC进行验证），如果不存在，弹出对话框提示：”交付标准维护不完整，请维护成分标准信息！“否则，验证成分取样要求是否存在（通过CIC查询成分标准取样要求表COM_MSC_CIC_SAMPLE进行验证），如果不存在，弹出对话框提示："取样要求不存在，请维护成分取样要求！"；
								if (ation.getProcess_point_type().equals("403201")) {
									/*
									 * ComMscStdCic cic = new ComMscStdCic();
									 * cic.setMsc(ation.getMsc());
									 * cic.setValidflag("1"); List<ComMscStdCic>
									 * cicList =
									 * this.getMapper(ComMscStdCicMapper.class).
									 * find(cic, 0, 0);
									 */
									List<ComMscStdCic> cicList = this.getMapper(ComMscStdCicMapper.class)
											.findWithCondition(null,
													"MSC='" + ation.getMsc()
															+ "' and VALIDFLAG='1' and (STD_TYPE='G' or STD_TYPE='X') and psc='"+msc.getPsc()+"'",
													null, 0, 0);
									if (cicList.size() == 0) {
										rm.setState("500");
										rm.setMsgInfo("交付标准维护不完整，请维护成分标准信息");
										return rm;
									} else {
										for (ComMscStdCic cics : cicList) {
											ComMscCicSample sample = new ComMscCicSample();
											sample.setCic(cics.getCic());
											sample.setValidflag("1");
											int count1 = this.getMapper(ComMscCicSampleMapper.class).count(sample);
											if (count1 == 0) {
												rm.setState("500");
												rm.setMsgInfo("取样要求不存在，请维护成分取样要求");
												return rm;
											} else {
												// 有交互标准，验证制程是否包含成分类的
												/*
												 * ComMscStdCic cic1 = new
												 * ComMscStdCic();
												 * cic1.setValidflag("1");
												 * cic1.setMsc(msc.getMsc());
												 * cic1.setPsc(msc.getPsc());
												 * cic1.setStd_type("G");
												 * List<ComMscStdCic> cicList1 =
												 * this.getMapper(
												 * ComMscStdCicMapper.class)
												 * .find(cic1, 0, 0); if
												 * (cicList1.size() > 0) {
												 */
												ComMscStation s = new ComMscStation();
												s.setMsc(msc.getMsc());
												s.setMsc_pline(coms.getMsc_pline());
												s.setProcess_point_type("403201");
												int sum = this.getMapper(ComMscStationMapper.class).count(s);
												if (sum == 0) {
													rm.setMsgInfo(coms.getMsc() + "存在成分交付标准但制程中" + coms.getMsc_pline()
															+ "不存在成分类工序点，请确认制程！");
													rm.setState("500");
													return rm;
												}
												/* } */
											}
										}
									}

								} else if (ation.getProcess_point_type().equals("403202")) {
									// 如果制程中存在材质类工序点类型，则验证交付标准_材质标准向下是否存在有效的材质标准索引记录（通过MSC查询材质标准索引表COM_MSC_STD_PIC进行验证），如果不存在，弹出对话框提示：”交付标准维护不完整，请维护材质标准信息！“否则，验证材质取样要求是否存在（通过PIC查询材质标准取样要求表COM_MSC_PHY_SAMPLE进行验证），如果不存在，弹出对话框提示："取样要求不存在，请维护材质取样要求！“；
									/*
									 * ComMscStdPic pic = new ComMscStdPic();
									 * pic.setMsc(ation.getMsc());
									 * pic.setValidflag("1"); List<ComMscStdPic>
									 * picList =
									 * this.getMapper(ComMscStdPicMapper.class).
									 * find(pic, 0, 0);
									 */
									List<ComMscStdPic> picList = this.getMapper(ComMscStdPicMapper.class)
											.findWithCondition(null,
													"MSC='" + ation.getMsc()
															+ "' and VALIDFLAG='1' and (STD_TYPE='G' or STD_TYPE='X') and psc='"+msc.getPsc()+"'",
													null, 0, 0);
									if (picList.size() == 0) {
										rm.setState("500");
										rm.setMsgInfo("交付标准维护不完整，请维护材质标准信息！");
										return rm;
									} else {
										for (ComMscStdPic pics : picList) {
											ComMscPhySample sample = new ComMscPhySample();
											sample.setPic(pics.getPic());
											sample.setValidflag("1");
											int count2 = this.getMapper(ComMscPhySampleMapper.class).count(sample);
											if (count2 == 0) {
												rm.setState("500");
												rm.setMsgInfo("取样要求不存在，请维护材质取样要求！");
												return rm;
											} else {
												/*
												 * ComMscStdPic pic1 = new
												 * ComMscStdPic();
												 * pic1.setPsc(msc.getPsc());
												 * pic1.setMsc(msc.getMsc());
												 * pic1.setValidflag("1");
												 * pic1.setStdType("G");
												 * List<ComMscStdPic> picList1 =
												 * this.getMapper(
												 * ComMscStdPicMapper.class)
												 * .find(pic1, 0, 0); if
												 * (picList1.size() > 0) {
												 */
												ComMscStation s = new ComMscStation();
												s.setMsc(msc.getMsc());
												s.setMsc_pline(coms.getMsc_pline());
												s.setProcess_point_type("403202");
												int sum = this.getMapper(ComMscStationMapper.class).count(s);
												if (sum == 0) {
													rm.setMsgInfo(coms.getMsc() + "存在材质交付标准但制程中" + coms.getMsc_pline()
															+ "不存在材质类工序点，请确认制程");
													rm.setState("500");
													return rm;
												}
												// }
											}
										}
									}
								} else if (ation.getProcess_point_type().equals("403203")) {
									// 3)：如果制程中存在公差类工序点类型，则验证公差标准向下是否存在有效的公差标准索引记录
									// （通过MSC查询公差标准表(主表)COM_MSC_STD_SPEC进行验证），
									// 如果不存在，弹出对话框提示：”交付标准维护不完整，请维护公差标准信息！“
									/*
									 * ComMscStdSpec spec = new ComMscStdSpec();
									 * spec.setMsc(ation.getMsc());
									 * spec.setValidflag("1"); int count3 =
									 * this.getMapper(ComMscStdSpecMapper.class)
									 * .count(spec);
									 */
									int count3 = this.getMapper(ComMscStdSpecMapper.class).countWithCondition(null,
											"VALIDFLAG='1' and (STD_TYPE='G' or STD_TYPE='X') and MSC='"
													+ ation.getMsc() + "' and psc='" + msc.getPsc() + "'");
									if (count3 == 0) {
										rm.setMsgInfo("交付标准维护不完整，请维护公差标准信息");
										rm.setState("500");
										return rm;
									} else {
										// COM_MSC_STD_SPEC
										/*
										 * ComMscStdSpec spec1 = new
										 * ComMscStdSpec();
										 * spec1.setMsc(msc.getMsc());
										 * spec1.setPsc(msc.getMsc());
										 * spec1.setValidflag("1");
										 * spec1.setStdType("G");
										 * List<ComMscStdSpec> specList =
										 * this.getMapper(ComMscStdSpecMapper.
										 * class) .find(spec1, 0, 0);
										 */
										List<ComMscStdSpec> specList = this.getMapper(ComMscStdSpecMapper.class)
												.findWithCondition(null,
														"VALIDFLAG='1' and (STD_TYPE='G' or STD_TYPE='X') and MSC='"
																+ ation.getMsc() + "' and PSC='" + msc.getPsc() + "'",
														null, 0, 0);
										if (specList.size() > 0) {
											ComMscStation s = new ComMscStation();
											s.setMsc(msc.getMsc());
											s.setMsc_pline(coms.getMsc_pline());
											s.setProcess_point_type("403203");
											int sum = this.getMapper(ComMscStationMapper.class).count(s);
											if (sum == 0) {
												rm.setMsgInfo(coms.getMsc() + "存在公差交付标准但制程中" + coms.getMsc_pline()
														+ "不存在公差类工序点，请确认制程");
												rm.setState("500");
												return rm;
											}
										}
									}
								} else if (ation.getProcess_point_type().equals("403204")) {
									// 如果制程中存在探伤类工序点类型，
									// 则验证探伤标准向下是否存在有效的探伤标准索引记录（通过MSC查询探伤要求主表COM_MSC_STD_DETECTION进行验证）
									// ，如果不存在，弹出对话框提示：”交付标准维护不完整，请维护探伤标准信息！“
									/*ComMscStdDetection ction = new ComMscStdDetection();
									ction.setMsc(ation.getMsc());
									ction.setValidflag("1");
									int count4 = this.getMapper(ComMscStdDetectionMapper.class).count(ction);*/
									int count4 = this.getMapper(ComMscStdDetectionMapper.class).countWithCondition(null,
											"VALIDFLAG='1' and (STD_TYPE='G' or STD_TYPE='X') and MSC='"
													+ ation.getMsc() + "' and psc='"+msc.getPsc()+"'");
									if (count4 == 0) {
										rm.setMsgInfo("交付标准维护不完整，请维护探伤标准信息");
										rm.setState("500");
										return rm;
									} else {
										// COM_MSC_STD_DETECTION
										/*ComMscStdDetection ction1 = new ComMscStdDetection();
										ction1.setStdType("G");
										ction1.setMsc(msc.getMsc());
										ction1.setPsc(msc.getPsc());
										ction1.setValidflag("1");
										List<ComMscStdDetection> ctionList = this
												.getMapper(ComMscStdDetectionMapper.class).find(ction1, 0, 0);*/
										List<ComMscStdDetection> ctionList = this
												.getMapper(ComMscStdDetectionMapper.class).findWithCondition(null,
														"PSC='" + msc.getPsc()
																+ "' and VALIDFLAG='1' and (STD_TYPE='G' or STD_TYPE='X') and MSC='"
																+ ation.getMsc() + "'",
														null, 0, 0);
										if (ctionList.size() > 0) {
											ComMscStation s = new ComMscStation();
											s.setMsc(msc.getMsc());
											s.setMsc_pline(coms.getMsc_pline());
											s.setProcess_point_type("403204");
											int sum = this.getMapper(ComMscStationMapper.class).count(s);
											if (sum == 0) {
												rm.setMsgInfo(coms.getMsc() + "存在公差交付标准但制程中" + coms.getMsc_pline()
														+ "不存在公差类工序点，请确认制程");
												rm.setState("500");
												return rm;
											}
										}
									}
								}
							}

						}
					} else {
						rm.setState("500");
						rm.setMsgInfo("制程维护不完整，请维护工序信息");
						return rm;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			rm.setMsgInfo("提交审核失败");
			rm.setState("500");
		}
		return rm;
	}

	/**
	 * 制程-复制基础MSC制程
	 */
	public ResultModel ReplicatingMScprocess(CommonPage<ComMsc> commsc) {
		ResultModel rm = new ResultModel();
		try {
			ComMsc msc = commsc.getObject();
			ComMscBacklog com = new ComMscBacklog();
			com.setMsc(msc.getMsc());
			int comCount = this.getMapper(ComMscBacklogMapper.class).count(com);
			if (comCount > 0) {
				rm.setState("500");
				rm.setMsgInfo("当前MSC下存在制程，不能使用复制功能！");
			} else {
				// 查询对应制程
				ComMscBacklog log = new ComMscBacklog();
				log.setMsc(msc.getMsc_seq());
				List<ComMscBacklog> backs = this.getMapper(ComMscBacklogMapper.class).doFindZc(msc.getMsc_seq(), "1");
				if (backs.size() > 0) {
					for (ComMscBacklog back : backs) {
						String mscpline = this.getMapper(ComMscBacklogMapper.class).GetMaxNo(msc.getMsc());
						String username = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
						// 查出对应工序信息COM_MSC_PROCESS
						ComMscProcess process = new ComMscProcess();
						process.setMsc(back.getMsc());
						process.setMsc_pline(back.getMsc_pline());
						List<ComMscProcess> processList = this.getMapper(ComMscProcessMapper.class).find(process, 0, 0);
						if (processList.size() > 0) {
							for (ComMscProcess pro : processList) {
								// 查出对应工序点信息COM_MSC_STATION
								ComMscStation station = new ComMscStation();
								station.setMsc(pro.getMsc());
								station.setMsc_pline(pro.getMsc_pline());
								station.setProcess_code(pro.getProcess_code());
								List<ComMscStation> stationList = this.getMapper(ComMscStationMapper.class)
										.find(station, 0, 0);
								for (ComMscStation comMscStation : stationList) {
									comMscStation.setMsc(msc.getMsc());
									comMscStation.setMsc_pline(mscpline);
								}
								pro.setMsc(msc.getMsc());
								pro.setMsc_pline(mscpline);
								// long
								// i=this.getMapper(ComMscProcessMapper.class).GetMaxNo(pro.getProcess_code(),pro.getProcess_code_c());
								// pro.setBacklog_seq(i);
								pro.setValidflag("1");
								pro.setCreate_name(username);
								pro.setCreate_time(new Date());
								this.getMapper(ComMscProcessMapper.class).insert(pro);
								if (stationList.size() > 0) {
									for (ComMscStation s : stationList) {
										s.setMsc_pline(mscpline);
										s.setBacklog_seq(pro.getBacklog_seq());
										s.setValidflag("1");
										long seq = 1L;
										s.setProcess_seq(seq);
										s.setCreate_name(username);
										s.setCreate_time(new Date());
										this.getMapper(ComMscStationMapper.class).insert(s);
									}
								}
							}
							back.setMsc(msc.getMsc());
							back.setMsc_pline(mscpline);
							back.setValidflag("1");
							// 获取当前登录人
							back.setCreate_name(username);
							back.setCreate_time(new Date());
							this.getMapper(ComMscBacklogMapper.class).insert(back);
						}
					}
					rm.setState("200");
				} else {
					rm.setMsgInfo("基础冶金规范码不存在有效制程，不能使用复制功能");
					rm.setState("403");
				}
			}
		} catch (Exception e) {
			rm.setState("500");
			rm.setErrorInfo(e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}
	
	
	
	/**
	 * 获取成分标准信息
	 */
	public ResultModel doFindCicAll(CommonPage<ComMscStdCic> sm) {
		ResultModel rm = new ResultModel();
		try {
			Integer pageSize= sm.getPageSize()*(sm.getPageIndex()-1);
			Integer pageIndex=sm.getPageSize()*(sm.getPageIndex()-1)+sm.getPageSize();
			ReturnMsg<List<ComMscStdCic>> msg = new ReturnMsg<>();
			ComMscStdCic cic=sm.getObject();
			String validflag=cic.getValidflag();
			String prod_code_nk=cic.getProd_code_nk();
			String steel_code_nk=cic.getSteel_code_nk();
			String delivery_state_code=cic.getDelivery_state_code();
			String std_code_nk=cic.getStd_code_nk();
			String std_type=cic.getStd_type();
			/*if (delivery_state_code!=null && !"".equals(delivery_state_code)) {
				delivery_state_code = delivery_state_code.replace(",", "','");
			}
			if (prod_code_nk!=null && !"".equals(prod_code_nk)) {
				prod_code_nk = "'"+prod_code_nk.replace(",", "','")+"'";
			}
			
			
			if (steel_code_nk!=null && !"".equals(steel_code_nk)) {
				steel_code_nk = "'"+steel_code_nk.replace(",", "','")+"'";
			}*/
				
			List<ComMscStdCic> cics=this.getMapper(ComMscStdCicMapper.class).findByPage(validflag,prod_code_nk,steel_code_nk,delivery_state_code,std_code_nk,std_type,pageSize,pageIndex);
			//List<ComMscStdCic> cics=this.getMapper(ComMscStdCicMapper.class).findWithCondition(null, "VALIDFLAG='1' and (STD_TYPE='G' or STD_TYPE='X')", null, 0, 0);
			
			/*if (cics!=null && cics.size()>0) {	
				removeCic(cics);
			}*/
			//总条数
			List<ComMscStdCic> totle=this.getMapper(ComMscStdCicMapper.class).findByPage(validflag,prod_code_nk,steel_code_nk,delivery_state_code,std_code_nk,std_type,null,null);
			/*if (totle!=null && totle.size()>0) {
				removeCic(totle);
			}*/
			msg.setResult(cics);
			msg.setTotal(totle.size());
			msg.setPageIndex(pageIndex);
			msg.setPageSize(pageSize);
			msg.setSuccess(true);
			rm.setData(msg);
			rm.setState("200");
		} catch (Exception e) {
			rm.setMsgInfo("获取成分标准信息失败");
			e.printStackTrace();
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 材质标准
	 */
	/**
	 * 获取材质标准索引号COM_MSC_STD_PIC
	 */
	public ResultModel doFindPicAll(CommonPage<ComMscStdPic> sm) {
		ResultModel rm = new ResultModel();
		try {
			Integer pageSize= sm.getPageSize()*(sm.getPageIndex()-1);
			Integer pageIndex=sm.getPageSize()*(sm.getPageIndex()-1)+sm.getPageSize();
			ReturnMsg<List<ComMscStdPic>> msg = new ReturnMsg<>();
			ComMscStdPic pic=sm.getObject();
			String validflag=pic.getValidflag();
			String prod_code_nk=pic.getProdCodeNk();
			String steel_code_nk=pic.getSteelCodeNk();
			String delivery_state_code=pic.getDeliveryStateCode();
			String std_code_nk=pic.getStdCodeNk();
			String std_type=pic.getStdType();
			/*if (delivery_state_code!=null && !"".equals(delivery_state_code)) {
				delivery_state_code = delivery_state_code.replace(",", "','");
			}
			if (prod_code_nk!=null && !"".equals(prod_code_nk)) {
				prod_code_nk = "'"+prod_code_nk.replace(",", "','")+"'";
			}
			
			
			if (steel_code_nk!=null && !"".equals(steel_code_nk)) {
				steel_code_nk = "'"+steel_code_nk.replace(",", "','")+"'";
			}
				*/
			
			List<ComMscStdPic> pics=new ArrayList<>();
			pics=this.getMapper(ComMscStdPicMapper.class).findByPage(validflag,prod_code_nk,steel_code_nk,delivery_state_code,std_code_nk,std_type,pageSize,pageIndex);
			
			
			//List<ComMscStdPic> pics=this.getMapper(ComMscStdPicMapper.class).findWithCondition(null, "VALIDFLAG='1' and (STD_TYPE='G' or STD_TYPE='X')", null, 0, 0);
			/*if (pics!=null && pics.size()>0) {
				//移除未关联标准信息的pic
				removePic(pics);
				
			}*/
			 List<ComMscStdPic> total=new ArrayList<>();
			 total=this.getMapper(ComMscStdPicMapper.class).findByPage(validflag,prod_code_nk,steel_code_nk,delivery_state_code,std_code_nk,std_type,null,null);
			
			/* if (total!=null && total.size()>0) {
					//移除未关联标准信息的pic
					removePic(total);
					
				}*/
			msg.setResult(pics);
			msg.setSuccess(true);
			msg.setPageIndex(pageIndex);
			msg.setPageSize(pageSize);
			msg.setTotal(total.size());
			rm.setData(msg);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取材质标准索引失败");
			e.printStackTrace();
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 公差标准-查询
	 */
	public ResultModel doFindspecAll(CommonPage<ComMscStdSpec> sm) {
		ResultModel rm = new ResultModel();
		try {
			ReturnMsg<List<ComMscStdSpec>> msg = new ReturnMsg<>();
			Integer pageSize= sm.getPageSize()*(sm.getPageIndex()-1);
			Integer pageIndex=sm.getPageSize()*(sm.getPageIndex()-1)+sm.getPageSize();
			ComMscStdSpec sic=sm.getObject();
			String validflag=sic.getValidflag();
			String prod_code_nk=sic.getProdCodeNk();
			String steel_code_nk=sic.getSteelCodeNk();
			String delivery_state_code=sic.getDeliveryStateCode();
			String std_code=sic.getStdCode();
			String std_type=sic.getStdType();
			/*if (delivery_state_code!=null && !"".equals(delivery_state_code)) {
				delivery_state_code = delivery_state_code.replace(",", "','");
			}
			if (prod_code_nk!=null && !"".equals(prod_code_nk)) {
				prod_code_nk = "'"+prod_code_nk.replace(",", "','")+"'";
			}
			
			
			if (steel_code_nk!=null && !"".equals(steel_code_nk)) {
				steel_code_nk = "'"+steel_code_nk.replace(",", "','")+"'";
			}*/
				
			List<ComMscStdSpec> spec=new ArrayList<>();
	        spec=this.getMapper(ComMscStdSpecMapper.class).findByPage(validflag,prod_code_nk,steel_code_nk,delivery_state_code,std_code,std_type,pageSize,pageIndex);
			
		  /*if (spec!=null && spec.size()>0) {
			   //移除未绑定公差项
			   removeSic(spec);
			
		  }*/
		  
		  
		  List<ComMscStdSpec> total=new ArrayList<>();
		  total=this.getMapper(ComMscStdSpecMapper.class).findByPage(validflag,prod_code_nk,steel_code_nk,delivery_state_code,std_code,std_type,null,null);
		 /* if (total!=null && total.size()>0) {
				   //移除未绑定公差项
				   removeSic(total);
				
	        }*/
		    msg.setTotal(total.size());
		    msg.setResult(spec);
		    msg.setPageIndex(pageIndex);
		    msg.setPageSize(pageSize);
		    msg.setSuccess(true);
			rm.setData(msg);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取公差标准失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}

	
	/**
	 * 查询所有探伤索引号
	 * @param sm
	 * @return
	 */
	public ResultModel dofindDetectionAll(CommonPage<ComMscStdDetection> sm) {
		ResultModel rm = new ResultModel();
		try {
			ReturnMsg<List<ComMscStdDetection>> msg = new ReturnMsg<>();
			Integer pageSize= sm.getPageSize()*(sm.getPageIndex()-1);
			Integer pageIndex=sm.getPageSize()*(sm.getPageIndex()-1)+sm.getPageSize();
			ComMscStdDetection dic=sm.getObject();
			String validflag=dic.getValidflag();
			String prod_code_nk=dic.getProdCodeNk();
			String steel_code_nk=dic.getSteelCodeNk();
			String delivery_state_code=dic.getDeliveryStateCode();
			String std_code=dic.getStdCodeNk();
			String std_type=dic.getStdType();
			/*if (delivery_state_code!=null && !"".equals(delivery_state_code)) {
				delivery_state_code = delivery_state_code.replace(",", "','");
			}
			if (prod_code_nk!=null && !"".equals(prod_code_nk)) {
				prod_code_nk = "'"+prod_code_nk.replace(",", "','")+"'";
			}
			
			
			if (steel_code_nk!=null && !"".equals(steel_code_nk)) {
				steel_code_nk = "'"+steel_code_nk.replace(",", "','")+"'";
			}*/
				
			List<ComMscStdDetection> dics=new ArrayList<>();
			dics=this.getMapper(ComMscStdDetectionMapper.class).findByPage(validflag,prod_code_nk,steel_code_nk,delivery_state_code,std_code,std_type,pageSize,pageIndex);
			/*if (dics!=null && dics.size()>0) {
				//移除探伤
				removeDic(dics);
					
			}*/
			List<ComMscStdDetection> total=new ArrayList<>();
			total=this.getMapper(ComMscStdDetectionMapper.class).findByPage(validflag,prod_code_nk,steel_code_nk,delivery_state_code,std_code,std_type,null,null);
			/*if (total!=null && total.size()>0) {
				removeDic(total);
			}
			*/
			msg.setPageIndex(pageIndex);
			msg.setPageSize(pageSize);
			msg.setResult(dics);
			msg.setSuccess(true);
			msg.setTotal(total.size());
			rm.setData(msg);
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取探伤标准失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	
	/**
	 * 公差标准-查询
	 */
	public ResultModel doFindSpecByMsc(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			String val = sm.getMemo3();
			String condition="1=1";
			if ("1".equals(val)) {
				condition+=" and VALIDFLAG!='0'";
			}
			if (sm.getMemo1()!=null && !"".equals(sm.getMemo1())) {
				condition+=" and MSC='"+sm.getMemo1()+"'";
			}
			rm.setData(this.getMapper(ComMscStdSpecMapper.class).findWithCondition(null, condition, "SIC", 0, 0));
		rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取公差标准失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	
	/**
	 * 获取探伤标准索引号COM_MSC_STD_DETECTION
	 */

	public ResultModel dofindDetectionByMsc(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			String val = sm.getMemo3();
			String condition="1=1";
			if ("1".equals(val)) {
				condition+=" and VALIDFLAG!='0'";
			}
			if (sm.getMemo1()!=null && !"".equals(sm.getMemo1())) {
				condition+=" and MSC='"+sm.getMemo1()+"'";
			}
			rm.setData(this.getMapper(ComMscStdDetectionMapper.class).findWithCondition(null, condition, "DIC", 0, 0));
		    rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取探伤标准失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	
	/**
	 * 材质标准
	 */
	/**
	 * 获取材质标准索引号COM_MSC_STD_PIC
	 */
	public ResultModel doFindPicByMsc(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			String val = sm.getMemo3();
			String condition="1=1";
			if ("1".equals(val)) {
				condition+=" and VALIDFLAG!='0'";
			}
			if (sm.getMemo1()!=null && !"".equals(sm.getMemo1())) {
				condition+=" and MSC='"+sm.getMemo1()+"'";
			}
			rm.setData(this.getMapper(ComMscStdPicMapper.class).findWithCondition(null, condition, "PIC", 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("获取材质标准索引失败");
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	
	/**
	 * 根据msc查询cic
	 */
	public ResultModel doFindCicByMsc(CommonPage<ComMsc> sm) {
		ResultModel rm = new ResultModel();
		try {
			String val = sm.getMemo3();
			String condition="1=1";
			
			if ("1".equals(val)) {
				condition+=" and VALIDFLAG!='0'";
			}
			if (sm.getMemo1()!=null && !"".equals(sm.getMemo1())) {
				condition+=" and MSC='"+sm.getMemo1()+"'";
			}
			rm.setData(this.getMapper(ComMscStdCicMapper.class).findWithCondition(null, condition, "CIC", 0, 0));
			rm.setState("200");
		} catch (Exception e) {
			rm.setMsgInfo("获取成分标准信息失败");
			e.printStackTrace();
			rm.setErrorInfo(e.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 查询产线接口
	 */
	public ResultModel doGetChemPline() {
		ResultModel rm = new ResultModel();
		List<ComMscStdChem> chemList=this.getMapper(ComMscStdChemMapper.class).findChemPline();
		//HashMap<String, String> map=this.getMapper(ComMscMapper.class).findChemPlline();
		rm.setData(chemList);
		rm.setState("200");
		return rm;
	}
	
	private void createOldProcess(ComMscProcess cess, String mscpline, String username) {
		cess.setMsc_pline(mscpline);
		// Long
		// seq=this.getMapper(ComMscProcessMapper.class).GetMaxNo(cess.getProcess_code(),cess.getProcess_code_c());
		cess.setValidflag("1");
		cess.setCreate_name(username);
		cess.setCreate_time(new Date());
		this.getMapper(ComMscProcessMapper.class).insert(cess);
		
	}
	
	/**
	 * 创建新的工序点
	 * 
	 * @param station
	 * @param mscpline
	 * @param username
	 * @throws Exception 
	 */
	private void createStation(ComMscStation station, String mscpline, String username) throws Exception {
		station.setMsc_pline(mscpline);	
		long seq = 1L;
		station.setProcess_seq(seq);
		if (station.getGuid()==null || "".equals(station.getGuid())) {
			station.setValidflag("1");
			station.setGuid(DataHelper.getUUID());	
			station.setCreate_name(username);
			station.setCreate_time(new Date());
		}else{
			station.setUpdate_name(username);
			station.setUpdate_time(new Date());
		}
		
		
		this.getMapper(ComMscStationMapper.class).insert(station);

	}
	
	
	private void createOldStation(ComMscStation station, String mscpline, String username) {
		station.setMsc_pline(mscpline);
		station.setValidflag("1");
		long seq = 1L;
		station.setProcess_seq(seq);
		station.setCreate_name(username);
		station.setCreate_time(new Date());
		this.getMapper(ComMscStationMapper.class).insert(station);
	}
	
	

	
}
