/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2021-09-01
 * 描述            ：系统操作日志表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Mes.Opr.impl;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import market.Com.mapper.PbModelDbMapper;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Mes.Opr.mapper.MesOprDelayMapper;
import market.Mes.Opr.service.MesOprDelayService;
import market.Mes.Opr.vo.MesOprDelay;

import org.apache.commons.collections.CollectionUtils;

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

@RemoteService(path="MesOprDelayService")
public class MesOprDelayServiceImpl extends BaseServiceImpl<MesOprDelay,Object> implements MesOprDelayService {
	
	@SuppressWarnings("rawtypes")
	public String doJudegeRole(CommonPage<User> sum) throws Exception{
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String sql = "select t.org_code from sso.sys_user t where t.user_code = '"+userId+"'";
		List<HashMap> hmList = this.getMapper(PbModelDbMapper.class).doQueryHashMap(sql);
		if (CollectionUtils.isNotEmpty(hmList)) {
			if ("2020091817520000007".equals(hmList.get(0).get("ORG_CODE"))) {//判断操作人员是不是【计划调度】
				return "1";
			}			 
		}		
		return "0";
	}
	
	/**
	 * 
	 * @param cp
	 * @return
	 * @throws Exception
	 */
	public ResultModel doQueryMesOprDelay(CommonPage<MesOprDelay> cp) throws Exception{
		ResultModel rm = new ResultModel();
		MesOprDelay mod = cp.getObject();
		mod = this.getMapper(MesOprDelayMapper.class).findById(mod.getMaterial_no());				
		rm.setState("200");
		rm.setData(mod);
		return rm;
	}
	
	/**
	 * 各机组生产明细报表:超交货期保存功能：双击
	 * @param cp
	 * @return
	 * @throws Exception
	 */
	public ResultModel doSaveMesOprDelay(CommonPage<MesOprDelay> cp) throws Exception{
		ResultModel rm = new ResultModel();
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		Date now = new Date();
		String opr_time = new SimpleDateFormat("yyyyMMddHHmmss").format(now); //操作时间
		MesOprDelay mod = cp.getObject();
		mod.setOpr_man(userName);
		mod.setOpr_time(opr_time);
		
		//判断是否存在保存记录
		MesOprDelay m = this.getMapper(MesOprDelayMapper.class).findById(mod.getMaterial_no());
		if (m!=null) { //存在进行调整
			this.getMapper(MesOprDelayMapper.class).update(mod);
		}else { //不存在进行新增
			this.getMapper(MesOprDelayMapper.class).insert(mod);
		}
		//调整计划完成时间
		String sqlSx = "update pln_pickle_plan_detail t set t.plan_hand_time = '"+mod.getPlan_sign_date()+"' where t.object_no = '"+mod.getMaterial_no()+"'";
		String sqlZj = "update pln_rolling_plan_detail t set t.plan_hand_time = '"+mod.getPlan_sign_date()+"' where t.object_no = '"+mod.getMaterial_no()+"'";
		String sqlPz = "update pln_skinrolling_plan_detail t set t.plan_hand_time = '"+mod.getPlan_sign_date()+"' where t.object_no = '"+mod.getMaterial_no()+"'";
		String sqlFt = "update pln_lengthwise_plan_detail t set t.plan_hand_time = '"+mod.getPlan_sign_date()+"' where t.object_no = '"+mod.getMaterial_no()+"'";
		String sqlTh = "update pln_anneal_plan_detail t set t.plan_hand_time = '"+mod.getPlan_sign_date()+"' where t.object_no = '"+mod.getMaterial_no()+"'";
		String sqlHj = "update pln_cuttolength_plan_detail t set t.plan_hand_time = '"+mod.getPlan_sign_date()+"' where t.object_no = '"+mod.getMaterial_no()+"'";
		this.getMapper(PbModelDbMapper.class).doUpdateSql(sqlSx);//酸洗
		this.getMapper(PbModelDbMapper.class).doUpdateSql(sqlZj);//轧机
		this.getMapper(PbModelDbMapper.class).doUpdateSql(sqlPz);//平整
		this.getMapper(PbModelDbMapper.class).doUpdateSql(sqlFt);//分条
		this.getMapper(PbModelDbMapper.class).doUpdateSql(sqlTh);//退火
		this.getMapper(PbModelDbMapper.class).doUpdateSql(sqlHj);//横剪3mm
		
		rm.setState("200");
		rm.setMsgInfo("保存成功");
		return rm;
	}
	
}
