package market.Qms.slmord.impl;
import java.util.List;

import market.Com.vo.ResultModel;
import market.Qms.slmord.mapper.SlmOrdDesignMscPlStiMcMapper;
import market.Qms.slmord.mapper.SlmOrdDesignMscTicMapper;
import market.Qms.slmord.service.SlmOrdDesignMscPlStiMcService;
import market.Qms.slmord.vo.SlmOrdDesignMscPlStiMc;

import org.springframework.transaction.annotation.Transactional;

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

@RemoteService(path="SlmOrdDesignMscPlStiMcService")
public class SlmOrdDesignMscPlStiMcServiceImpl extends BaseServiceImpl<SlmOrdDesignMscPlStiMc,Object> implements SlmOrdDesignMscPlStiMcService { 
	
	public ResultModel GetOrdDesignStiMc(SlmOrdDesignMscPlStiMc stiMc){
		ResultModel rm=new ResultModel("200","获取机台信息成功");
		try{
			List<SlmOrdDesignMscPlStiMc> list=this.getMapper(SlmOrdDesignMscPlStiMcMapper.class).find(stiMc, 0, 0);
			rm.setData(list);
		}catch(Exception ex){
			rm.setErrorInfo(ex.getMessage());
			rm.setState("500");
		}
		
		return rm;
	}
	
	
	@Transactional(value="tm",rollbackFor=Exception.class)
	public ResultModel DelOrdDesignStiMc(List<SlmOrdDesignMscPlStiMc> listMc){
		ResultModel rm=new ResultModel("200","删除机台成功");
		SlmOrdDesignMscPlStiMc _mc=new SlmOrdDesignMscPlStiMc();
		_mc.setDesign_key(listMc.get(0).getDesign_key());
		_mc.setMsc_pline(listMc.get(0).getMsc_pline());
		_mc.setProcess_code(listMc.get(0).getProcess_code());
		_mc.setPline_code(listMc.get(0).getPline_code());
		SlmOrdDesignMscPlStiMcMapper mcMapper=this.getMapper(SlmOrdDesignMscPlStiMcMapper.class);
		List<SlmOrdDesignMscPlStiMc> list=mcMapper.find(_mc, 0, 0);
		if(listMc.size()>=list.size()){
			rm.setState("500");
			rm.setMsgInfo("不能删除全部机台");
			return rm;
		}
		
		for (SlmOrdDesignMscPlStiMc stiMc : listMc) {
			mcMapper.DelOrdDesignStiMc(stiMc.getDesign_key(), stiMc.getMsc_pline(), stiMc.getProcess_code(), stiMc.getPline_code(),stiMc.getProcess_point_code(), stiMc.getMachine_code());
			this.getMapper(SlmOrdDesignMscTicMapper.class).DelOrdDesignMcTic(stiMc.getDesign_key(), stiMc.getMsc_pline(), stiMc.getProcess_code(),stiMc.getPline_code() ,stiMc.getProcess_point_code(), stiMc.getMachine_code());
			//下面表设计有问题，不能删除
			//this.getMapper(SlmOrdDesignMscTicItemMapper.class)
		}
		
		
		return rm;
	}
	
}