/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-01-30
 * 描述            ：质量设计-制程(适用所有类型的产品，设计的产品必须有制程)
获取制程信息与钢种对应的表是：COM_MSC_BACKLOG、COM_MSC_GRADE，根据MSC（冶金规范码）获取制程
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Qms.slmord.impl;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlGxPrlMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlGzMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlPrcMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlStiMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlStiMcMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlStiTcMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscTicMapper;
import market.Qms.slmord.service.SlmOrdDesignMscPlService;
import market.Qms.slmord.vo.SlmOrdDesignMscPl;
import market.Qms.slmord.vo.SlmOrdDesignMscPlGz;
import market.Qms.slmord.vo.SlmOrdDesignMscPlSti;

import org.springframework.transaction.annotation.Transactional;

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

@RemoteService(path="SlmOrdDesignMscPlService")
public class SlmOrdDesignMscPlServiceImpl extends BaseServiceImpl<SlmOrdDesignMscPl,Object> implements SlmOrdDesignMscPlService {

	@Transactional(value="tm",rollbackFor=Exception.class)
	public ResultModel DelOrdDesignMscPl(List<SlmOrdDesignMscPl> listPl){
		ResultModel rm=new ResultModel("200","删除成功");
		SlmOrdDesignMscPl _mscPl=new SlmOrdDesignMscPl();
		_mscPl.setDesign_key(listPl.get(0).getDesign_key());
		List<SlmOrdDesignMscPl> list=this.getMapper(SlmOrdDesignMscPlMapper.class).find(_mscPl, 0, 0);
		if(listPl.size()>=list.size()){
			rm.setState("500");
			rm.setMsgInfo("不能删除全部制程");
			return rm;
		}
		
		for(SlmOrdDesignMscPl mscPl : listPl){
			String designKey=mscPl.getDesign_key(), mscPline=mscPl.getMsc_pline();
			this.getMapper(SlmOrdDesignMscPlMapper.class).delete(designKey,mscPline);
			this.getMapper(SlmOrdDesignMscPlGxPrlMapper.class).DelByKeyAndMscPline(designKey, mscPline);
			this.getMapper(SlmOrdDesignMscPlGzMapper.class).DelByKeyAndMscPline(designKey, mscPline);
			this.getMapper(SlmOrdDesignMscPlPrcMapper.class).DelByKeyAndMscPline(designKey, mscPline);
			//this.getMapper(SlmOrdDesignMscPlPrcCicMapper.)
			this.getMapper(SlmOrdDesignMscPlStiMapper.class).DelByKeyAndMscPline(designKey, mscPline);
			this.getMapper(SlmOrdDesignMscPlStiMcMapper.class).DelByKeyAndMscPline(designKey, mscPline);
			this.getMapper(SlmOrdDesignMscPlStiTcMapper.class).DelByKeyAndMscPline(designKey, mscPline);
			this.getMapper(SlmOrdDesignMscTicMapper.class).DelByKeyAndMscPline(designKey, mscPline);
			//下面表设计有问题，无法删除
			//this.getMapper(SlmOrdDesignMscTicItemMapper.class);
		}
		return rm;
	}
	
	
	@Override
	public ResultModel  GetOrdDesignMscPl(CommonPage<SlmOrdDesignMscPl> com) {

		// TODO Auto-generated method stub
		ResultModel rm=new ResultModel();
		try{
			SlmOrdDesignMscPl mscPl=com.getObject();
			List<SlmOrdDesignMscPl> listMscPl=this.getMapper(SlmOrdDesignMscPlMapper.class).find(mscPl, 0, 0);
			SlmOrdDesignMscPlStiMapper stiMapper=this.getMapper(SlmOrdDesignMscPlStiMapper.class);
			SlmOrdDesignMscPlGzMapper gzMapper=this.getMapper(SlmOrdDesignMscPlGzMapper.class);
			for (SlmOrdDesignMscPl slmOrdDesignMscPl : listMscPl) {
				SlmOrdDesignMscPlSti _sti=new SlmOrdDesignMscPlSti();
				_sti.setDesign_key(mscPl.getDesign_key());
				_sti.setMsc_pline(slmOrdDesignMscPl.getMsc_pline());
				List<SlmOrdDesignMscPlSti> stiList=stiMapper.findWithCondition(_sti, null, "BACKLOG_SEQ,PROCESS_POINT_SEQ", 0, 0);
				String stations="";
				for (SlmOrdDesignMscPlSti plSti : stiList) {
					stations+=plSti.getProcess_point_desc()+"->";
				}
				if (stations!=null && !"".equals(stations)) {
					slmOrdDesignMscPl.setStations_desc(stations.substring(0, stations.length()-2));
				}	
				SlmOrdDesignMscPlGz _gz=new SlmOrdDesignMscPlGz();
				_gz.setDesign_key(slmOrdDesignMscPl.getDesign_key());
				_gz.setMsc_pline(slmOrdDesignMscPl.getMsc_pline());
				List<SlmOrdDesignMscPlGz> listGZ=gzMapper.find(_gz, 0, 0);
				slmOrdDesignMscPl.setListGrade(listGZ);
			}
			rm.setState("200");
			rm.setData(listMscPl);
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("获取技术评审制程出错");	
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
		
		/*
		// TODO Auto-generated method stub
		ResultModel rm=new ResultModel();
		try{
			SlmOrdDesignMscPl mscPl=com.getObject();
			List<SlmOrdDesignMscPl> listMscPl=this.getMapper(SlmOrdDesignMscPlMapper.class).find(mscPl, 0, 0);
			SlmOrdDesignMscPlStiMapper stiMapper=this.getMapper(SlmOrdDesignMscPlStiMapper.class);
			SlmOrdDesignMscPlGzMapper gzMapper=this.getMapper(SlmOrdDesignMscPlGzMapper.class);
			for (SlmOrdDesignMscPl slmOrdDesignMscPl : listMscPl) {
				SlmOrdDesignMscPlSti _sti=new SlmOrdDesignMscPlSti();
				_sti.setDesign_key(mscPl.getDesign_key());
				_sti.setMsc_pline(slmOrdDesignMscPl.getMsc_pline());
				List<SlmOrdDesignMscPlSti> stiList=stiMapper.findWithCondition(_sti, null, "PROCESS_POINT_SEQ", 0, 0);
				StringBuilder stations=new StringBuilder();
				for (SlmOrdDesignMscPlSti plSti : stiList) {
					stations.append(plSti.getProcess_point_desc()+",");
				}
				slmOrdDesignMscPl.setStations_desc(stations.substring(0, stations.length()-1));
				SlmOrdDesignMscPlGz _gz=new SlmOrdDesignMscPlGz();
				_gz.setDesign_key(slmOrdDesignMscPl.getDesign_key());
				_gz.setMsc_pline(slmOrdDesignMscPl.getMsc_pline());
				List<SlmOrdDesignMscPlGz> listGZ=gzMapper.find(_gz, 0, 0);
				slmOrdDesignMscPl.setListGrade(listGZ);
			}
			rm.setState("200");
			rm.setData(listMscPl);
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("获取技术评审制程出错");	
			rm.setErrorInfo(ex.getMessage());
		}
		return rm;
	*/}
	
}
