/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-03-27
 * 描述            ：岗位交接班消耗记录表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Mes.Shift.impl;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Mes.Shift.mapper.MesShiftDCsmMapper;
import market.Mes.Shift.mapper.MesShiftMMapper;
import market.Mes.Shift.service.MesShiftDCsmService;
import market.Mes.Shift.vo.MesReportWrite;
import market.Mes.Shift.vo.MesShiftDCsm;
import market.Mes.Shift.vo.MesShiftM;

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="MesShiftDCsmService")
public class MesShiftDCsmServiceImpl extends BaseServiceImpl<MesShiftDCsm,Object> implements MesShiftDCsmService {
	
	//=====================纵剪机组生产统计日志（2018年） -报表=========================
		/**
		 * memo1:机台代码
		 * memo2:日期   2018-12
		 * @param sum
		 * @return
		 */
		public ResultModel doQuery4mm12mm_reportWeb(CommonPage<MesShiftM> sum){
			ResultModel rm=new ResultModel();
			try{
				if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
					rm.setState("500");
					rm.setMsgInfo("参数错误：请输入机台代码");
					return rm;
				}
				if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
					rm.setState("500");
					rm.setMsgInfo("参数错误：请输入日期");
					return rm;
				}
				rm.setData(this.getMapper(MesShiftDCsmMapper.class).doQuery4mm12mm_reportWeb(sum.getMemo1(),sum.getMemo2()));
				rm.setState("200");
			}catch(Exception ex){
				rm.setState("500");
				rm.setMsgInfo("查询失败！\n"+ex.getMessage());
			}
			return rm;
		}
		
		/**
		 * 查询其他消耗信息
		 * memo1:机台代码
		 * memo2:日期   2018-12
		 * @param sum
		 * @return
		 */
		public ResultModel doQuery4mm12mm_qtWeb(CommonPage<MesShiftM> sum){
			ResultModel rm=new ResultModel();
			try{
				if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
					rm.setState("500");
					rm.setMsgInfo("参数错误：请输入机台代码");
					return rm;
				}
				if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
					rm.setState("500");
					rm.setMsgInfo("参数错误：请输入日期");
					return rm;
				}
				rm.setData(this.getMapper(MesShiftDCsmMapper.class).doQuery4mm12mm_qtWeb(sum.getMemo1(),sum.getMemo2()));
				rm.setState("200");
			}catch(Exception ex){
				rm.setState("500");
				rm.setMsgInfo("查询失败！\n"+ex.getMessage());
			}
			return rm;
		}
		
		
		/**
		 * 纵剪机组生产统计日志（2018年）
		 * 修改按钮
		 * objectList:
		 * 		machine_code:机台代码
		 * 		wrk_date:作业日期
		 *      wrk_ord：作业班次
		 *      fault_time：当班故障时间（h）
		 *      fault_unit：当班故障责任单位
		 *      pln_thr_wgt：当班计划产量（t）
		 *      mtr_act_wgt：当班实际产量（t）
		 *      unexec_reason：未执行原因
		 *      private Double C001;//电耗
				private Double C003;//水
				private Double C004;//煤气
				private Double C005;//氢气
				private Double C006;//氮气
		 * */
		@Transactional(value="tm", rollbackFor=Exception.class)
		public ResultModel doUpdateWeb(CommonPage<MesReportWrite> sum) throws Exception{
			ResultModel rm=new ResultModel();
			try{
				String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
				if(userName==null){
					userName="";
				}
				List<MesReportWrite> dbg = sum.getObjectList();
				for(MesReportWrite msm:dbg){
					if(msm.getMachine_code()==null || "".equals(msm.getMachine_code().trim())
							|| msm.getWrk_date()==null || "".equals(msm.getWrk_date().trim())
							|| msm.getWrk_ord()==null || "".equals(msm.getWrk_ord().trim())
							){
						continue;
					}
					List<MesShiftM> list = this.getMapper(MesShiftMMapper.class).findWithCondition(null, "machine_code='"+msm.getMachine_code()+"' and wrk_date='"+msm.getWrk_date()+"' and wrk_ord='"+msm.getWrk_ord()+"'", null, 0, 0);
					if(list==null || list.size()<=0){
						continue;
					}
					MesShiftM msm_new=new MesShiftM();
					msm_new.setMachine_code(msm.getMachine_code());
					msm_new.setWrk_date(msm.getWrk_date());
					msm_new.setWrk_ord(msm.getWrk_ord());
					msm_new.setFault_time(msm.getFault_time());
					msm_new.setFault_unit(msm.getFault_unit());
					msm_new.setPln_thr_wgt(msm.getPln_thr_wgt());
					msm_new.setMtr_act_wgt(msm.getMtr_act_wgt());
					msm_new.setUnexec_reason(msm.getUnexec_reason());
					this.getMapper(MesShiftMMapper.class).update(msm_new);
					//if(msm.getC001()!=null)
						this.getMapper(MesShiftDCsmMapper.class).doUpdate(msm.getMachine_code(),msm.getWrk_date(),msm.getWrk_ord(),userName,"C001",msm.getC001());
					//}
					//if(msm.getC003()!=null){
						this.getMapper(MesShiftDCsmMapper.class).doUpdate(msm.getMachine_code(),msm.getWrk_date(),msm.getWrk_ord(),userName,"C003",msm.getC003());
					//}
					//if(msm.getC004()!=null){
						this.getMapper(MesShiftDCsmMapper.class).doUpdate(msm.getMachine_code(),msm.getWrk_date(),msm.getWrk_ord(),userName,"C004",msm.getC004());
					//}
					//if(msm.getC005()!=null){
						this.getMapper(MesShiftDCsmMapper.class).doUpdate(msm.getMachine_code(),msm.getWrk_date(),msm.getWrk_ord(),userName,"C005",msm.getC005());
					//}
					//if(msm.getC006()!=null){
						this.getMapper(MesShiftDCsmMapper.class).doUpdate(msm.getMachine_code(),msm.getWrk_date(),msm.getWrk_ord(),userName,"C006",msm.getC006());
					//}
					
				}
				//提交事务
				rm.setMsgInfo("修改成功");
				rm.setState("200");
			}catch(Exception ex){
				ex.printStackTrace();
				rm.setState("500");
				throw new Exception("修改失败!"+ex.getMessage());
			}
			return rm;
		}
		
		//========================================================================
		
		
		//=====================横剪机组生产统计日志（2018年） -报表=========================
		/**
		 * memo1:机台代码
		 * memo2:日期   2018-12
		 * @param sum
		 * @return
		 */
		public ResultModel doQuery3mm_reportWeb(CommonPage<MesShiftM> sum){
			ResultModel rm=new ResultModel();
			try{
				if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
					rm.setState("500");
					rm.setMsgInfo("参数错误：请输入机台代码");
					return rm;
				}
				if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
					rm.setState("500");
					rm.setMsgInfo("参数错误：请输入日期");
					return rm;
				}
				rm.setData(this.getMapper(MesShiftDCsmMapper.class).doQuery3mm_reportWeb(sum.getMemo1(),sum.getMemo2()));
				rm.setState("200");
			}catch(Exception ex){
				rm.setState("500");
				rm.setMsgInfo("查询失败！\n"+ex.getMessage());
			}
			return rm;
		}
		
		/**
		 * 查询其他消耗信息
		 * memo1:机台代码
		 * memo2:日期   2018-12
		 * @param sum
		 * @return
		 */
//		public ResultModel doQuery3mm_qtWeb(CommonPage<MesShiftM> sum){
//			ResultModel rm=new ResultModel();
//			try{
//				if(sum.getMemo1()==null || "".equals(sum.getMemo1())){
//					rm.setState("500");
//					rm.setMsgInfo("参数错误：请输入机台代码");
//					return rm;
//				}
//				if(sum.getMemo2()==null || "".equals(sum.getMemo2())){
//					rm.setState("500");
//					rm.setMsgInfo("参数错误：请输入日期");
//					return rm;
//				}
//				rm.setData(this.getMapper(MesShiftDCsmMapper.class).doQuery4mm12mm_qtWeb(sum.getMemo1(),sum.getMemo2()));
//				rm.setState("200");
//			}catch(Exception ex){
//				rm.setState("500");
//				rm.setMsgInfo("查询失败！\n"+ex.getMessage());
//			}
//			return rm;
//		}
		
		
		/**
		 * 横剪机组生产统计日志（2018年）
		 * 修改按钮
		 * objectList:
		 * 		machine_code:机台代码
		 * 		wrk_date:作业日期
		 *      wrk_ord：作业班次
		 *      fault_time：当班故障时间（h）
		 *      fault_unit：当班故障责任单位
		 *      pln_thr_wgt：当班计划产量（t）
		 *      mtr_act_wgt：当班实际产量（t）
		 *      unexec_reason：未执行原因
		 *      private Double C001;//电耗
				private Double C003;//水
				private Double C004;//煤气
				private Double C005;//氢气
				private Double C006;//氮气
		 * */
		@Transactional(value="tm", rollbackFor=Exception.class)
		public ResultModel doUpdate3mmWeb(CommonPage<MesReportWrite> sum) throws Exception{
			ResultModel rm=new ResultModel();
			try{
				String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
				if(userName==null){
					userName="";
				}
				List<MesReportWrite> dbg = sum.getObjectList();
				for(MesReportWrite msm:dbg){
					if(msm.getMachine_code()==null || "".equals(msm.getMachine_code().trim())
							|| msm.getWrk_date()==null || "".equals(msm.getWrk_date().trim())
							|| msm.getWrk_ord()==null || "".equals(msm.getWrk_ord().trim())
							){
						continue;
					}
					List<MesShiftM> list = this.getMapper(MesShiftMMapper.class).findWithCondition(null, "machine_code='"+msm.getMachine_code()+"' and wrk_date='"+msm.getWrk_date()+"' and wrk_ord='"+msm.getWrk_ord()+"'", null, 0, 0);
					if(list==null || list.size()<=0){
						continue;
					}
					MesShiftM msm_new=new MesShiftM();
					msm_new.setMachine_code(msm.getMachine_code());
					msm_new.setWrk_date(msm.getWrk_date());
					msm_new.setWrk_ord(msm.getWrk_ord());
					msm_new.setFault_time(msm.getFault_time());
					msm_new.setFault_unit(msm.getFault_unit());
					msm_new.setPln_thr_wgt(msm.getPln_thr_wgt());
					msm_new.setMtr_act_wgt(msm.getMtr_act_wgt());
					msm_new.setUnexec_reason(msm.getUnexec_reason());
					this.getMapper(MesShiftMMapper.class).update(msm_new);
					//if(msm.getC001()!=null)
						this.getMapper(MesShiftDCsmMapper.class).doUpdate(msm.getMachine_code(),msm.getWrk_date(),msm.getWrk_ord(),userName,"C001",msm.getC001());
					//}
					//if(msm.getC003()!=null){
						this.getMapper(MesShiftDCsmMapper.class).doUpdate(msm.getMachine_code(),msm.getWrk_date(),msm.getWrk_ord(),userName,"C003",msm.getC003());
					//}
					//if(msm.getC004()!=null){
						this.getMapper(MesShiftDCsmMapper.class).doUpdate(msm.getMachine_code(),msm.getWrk_date(),msm.getWrk_ord(),userName,"C004",msm.getC004());
					//}
					//if(msm.getC005()!=null){
						this.getMapper(MesShiftDCsmMapper.class).doUpdate(msm.getMachine_code(),msm.getWrk_date(),msm.getWrk_ord(),userName,"C005",msm.getC005());
					//}
					//if(msm.getC006()!=null){
						this.getMapper(MesShiftDCsmMapper.class).doUpdate(msm.getMachine_code(),msm.getWrk_date(),msm.getWrk_ord(),userName,"C006",msm.getC006());
					//}
					
				}
				//提交事务
				rm.setMsgInfo("修改成功");
				rm.setState("200");
			}catch(Exception ex){
				ex.printStackTrace();
				rm.setState("500");
				throw new Exception("修改失败!"+ex.getMessage());
			}
			return rm;
		}
		
		//========================================================================
		
		
		
		
		
}
