/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2019-05-20
 * 描述            ：调度日志-产量完成情况
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Mes.anneal.impl;
import java.util.Date;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Mes.anneal.mapper.PlnSchedulingProductMapper;
import market.Mes.anneal.mapper.PlnSchedulingProjectMapper;
import market.Mes.anneal.mapper.PlnSchedulingStockMapper;
import market.Mes.anneal.mapper.PlnSchedulingWorkMapper;
import market.Mes.anneal.service.PlnSchedulingProductService;
import market.Mes.anneal.vo.PlnSchedulingProduct;
import market.Mes.anneal.vo.PlnSchedulingProject;
import market.Mes.anneal.vo.PlnSchedulingStock;
import market.Mes.anneal.vo.PlnSchedulingWork;

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="PlnSchedulingProductService")
public class PlnSchedulingProductServiceImpl extends BaseServiceImpl<PlnSchedulingProduct,Object> implements PlnSchedulingProductService {

	/**
	 * 调度日志
	 * 查询产量完成情况
	 * memo1:日期字符串   比如："2019-05-13"
	 * */
	public ResultModel doDiaoduQueryWeb(CommonPage<PlnSchedulingProduct> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(PlnSchedulingProductMapper.class).doDiaoduQueryWeb(oci.getObject(),oci.getMemo1()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 调度日志
	 * 修改产量完成情况
	 * objectList:
	 * pline_code:产线
	 * machine_code：机台号代码
	 * planed_cnt：计划产量
	 * demo：备注
	 * 。。。。
	 * memo1:日期字符串   比如："2019-05-13"
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doDiaoduUpdate(CommonPage<PlnSchedulingProduct> oci) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String vOprName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(vOprName==null){
				vOprName="";
			}
			if(oci.getObjectList()==null || oci.getObjectList().size()<=0){
				rm.setState("500");
				rm.setMsgInfo("请输入参数");
				return rm;
			}
			for(PlnSchedulingProduct pscp:oci.getObjectList()){
				PlnSchedulingProduct pscp11=new PlnSchedulingProduct();
				pscp11.setCreate_time(pscp.getCreate_time());
				pscp11.setMachine_code(pscp.getMachine_code());
				pscp11.setPline_code(pscp.getPline_code());
				List<PlnSchedulingProduct> list = this.getMapper(PlnSchedulingProductMapper.class).find(pscp11,0,0);
				if(list!=null && list.size()>0){
					try{
						this.getMapper(PlnSchedulingProductMapper.class).update(pscp);
					}catch(Exception ex){
						
					}
				}else{
					this.getMapper(PlnSchedulingProductMapper.class).doDelete(pscp11,"");
					pscp.setCreate_opr(vOprName);
					//this.getMapper(PlnSchedulingProductMapper.class).doInsertDiaodu(pscp);
					this.getMapper(PlnSchedulingProductMapper.class).insert(pscp);
				}
			}
			rm.setMsgInfo("保存产量完成情况成功！");
			rm.setState("200");
		}catch(Exception ex){
			throw new Exception(ex.getMessage());
		}
		return rm;
	}
	
	
	/**
	 * 调度日志
	 * 查询项目调试进度
	 * memo1:日期字符串   比如："2019-05-13"
	 * */
	public ResultModel doDiaoduJinduQueryWeb(CommonPage<PlnSchedulingProject> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(PlnSchedulingProjectMapper.class).doDiaoduJinduQueryWeb(oci.getObject(),oci.getMemo1()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 调度日志
	 * 修改项目调试进度
	 * objectList:
	 * pline_code:产线
	 * machine_code：机台号代码
	 * 。。。。.。。
	 * memo1:日期字符串   比如："2019-05-13"
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doDiaoduJinduUpdate(CommonPage<PlnSchedulingProject> oci) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String vOprName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(vOprName==null){
				vOprName="";
			}
			if(oci.getObjectList()==null || oci.getObjectList().size()<=0){
				rm.setState("500");
				rm.setMsgInfo("请输入参数");
				return rm;
			}
			for(PlnSchedulingProject pscp:oci.getObjectList()){
				PlnSchedulingProject pscp11=new PlnSchedulingProject();
				pscp11.setCreate_time(pscp.getCreate_time());
				pscp11.setMachine_code(pscp.getMachine_code());
				pscp11.setPline_code(pscp.getPline_code());
				List<PlnSchedulingProject> list = this.getMapper(PlnSchedulingProjectMapper.class).find(pscp11,0,0);
				if(list!=null && list.size()>0){
					try{
						this.getMapper(PlnSchedulingProjectMapper.class).update(pscp);
					}catch(Exception e){
						
					}
					
				}else{
					this.getMapper(PlnSchedulingProjectMapper.class).doDeleteJindu(pscp11,"");
					pscp.setCreate_opr(vOprName);
					//this.getMapper(PlnSchedulingProjectMapper.class).doInsertDiaoduJindu(pscp);
					this.getMapper(PlnSchedulingProjectMapper.class).insert(pscp);
				}
				
			}
			rm.setMsgInfo("保存项目调试进度成功！");
			rm.setState("200");
		}catch(Exception ex){
			throw new Exception(ex.getMessage());
		}
		return rm;
	}


	/**
	 * 调度日志
	 * 查询各作业区情况
	 * memo1:日期字符串   比如："2019-05-13"
	 * */
	public ResultModel doDiaoduWorkQueryWeb(CommonPage<PlnSchedulingWork> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(PlnSchedulingWorkMapper.class).doDiaoduWorkQueryWeb(oci.getObject(),oci.getMemo1()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}
	
	/**
	 * 调度日志
	 * 修改各作业区情况
	 * objectList:
	 * pline_code:产线
	 * machine_code：机台号代码
	 * create_time:
	 * wrk_ord:
	 * 。。。。.。。
	 * memo1:日期字符串   比如："2019-05-13"
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doDiaoduWorkUpdate(CommonPage<PlnSchedulingWork> oci) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String vOprName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(vOprName==null){
				vOprName="";
			}
			if(oci.getObjectList()==null || oci.getObjectList().size()<=0){
				rm.setState("500");
				rm.setMsgInfo("请输入参数");
				return rm;
			}
			for(PlnSchedulingWork pscp:oci.getObjectList()){
				PlnSchedulingWork pscp11=new PlnSchedulingWork();
				pscp11.setCreate_time(pscp.getCreate_time());
				pscp11.setMachine_code(pscp.getMachine_code());
				pscp11.setPline_code(pscp.getPline_code());
				pscp11.setWrk_ord(pscp.getWrk_ord());
				List<PlnSchedulingWork> list = this.getMapper(PlnSchedulingWorkMapper.class).find(pscp11,0,0);
				if(list!=null && list.size()>0){
					try{
						this.getMapper(PlnSchedulingWorkMapper.class).update(pscp);
					}catch(Exception e){
						
					}
					
				}else{
					this.getMapper(PlnSchedulingWorkMapper.class).doDeleteJindu(pscp11,"");
					pscp.setCreate_opr(vOprName);
					//this.getMapper(PlnSchedulingWorkMapper.class).doInsertDiaoduJindu(pscp);
					this.getMapper(PlnSchedulingWorkMapper.class).insert(pscp);
				}
				
			}
			rm.setMsgInfo("保存各作业区情况成功！");
			rm.setState("200");
		}catch(Exception ex){
			throw new Exception(ex.getMessage());
		}
		return rm;
	}
	
	
	
	/**
	 * 调度日志
	 * 查询调度日志-库存发运情况
	 * memo1:日期字符串   比如："2019-05-13"
	 * */
	public ResultModel doDiaoduKucunQueryWeb(CommonPage<PlnSchedulingProject> oci){
		ResultModel rm=new ResultModel();
		try{
			rm.setData(this.getMapper(PlnSchedulingStockMapper.class).doDiaoduKucunQueryWeb(oci.getObject(),oci.getMemo1()));
			rm.setState("200");
		}catch(Exception ex){
			ex.printStackTrace();
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
		}
		return rm;
	}


	/**
	 * 调度日志
	 * 修改库存发运情况
	 * objectList:
	 * storage_code:仓库名称
	 * 。。。。.。。
	 * memo1:日期字符串   比如："2019-05-13"
	 * */
	@Transactional(value = "tm", rollbackFor = Exception.class)
	public ResultModel doDiaoduKucunUpdate(CommonPage<PlnSchedulingStock> oci) throws Exception{
		ResultModel rm=new ResultModel();
		try{
			String vOprName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if(vOprName==null){
				vOprName="";
			}
			if(oci.getObjectList()==null || oci.getObjectList().size()<=0){
				rm.setState("500");
				rm.setMsgInfo("请输入参数");
				return rm;
			}
			for(PlnSchedulingStock pscp:oci.getObjectList()){
				PlnSchedulingStock pscp11=new PlnSchedulingStock();
				pscp11.setRecord_time(pscp.getRecord_time());
				pscp11.setStorage_code(pscp.getStorage_code());
				List<PlnSchedulingStock> list = this.getMapper(PlnSchedulingStockMapper.class).find(pscp11,0,0);
				if(list!=null && list.size()>0){
					try{
						this.getMapper(PlnSchedulingStockMapper.class).update(pscp);
					}catch(Exception e){
						
					}
					
				}else{
					this.getMapper(PlnSchedulingStockMapper.class).doDeleteJindu(pscp11,"");
					pscp.setStocked_time(new Date());
					pscp.setTransport_time(new Date());
					this.getMapper(PlnSchedulingStockMapper.class).insert(pscp);
				}
				
			}
			rm.setMsgInfo("保存库存发运情况成功！");
			rm.setState("200");
		}catch(Exception ex){
			throw new Exception(ex.getMessage());
		}
		return rm;
	}


}
