package market.Mes.Lengthwise.Plan.impl;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Mes.Lengthwise.Plan.mapper.PlnMatReplaceLogMapper;
import market.Mes.Lengthwise.Plan.service.PlnMatReplaceLogService;
import market.Mes.Lengthwise.Plan.vo.PlnMatReplaceLog;
import market.Mes.OrderManager.Plan.vo.PlnProdorder;

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

@RemoteService(path="MilMatReplaceLogService")
public class PlnMatReplaceLogServiceImpl extends BaseServiceImpl<PlnMatReplaceLog,Object> implements PlnMatReplaceLogService {
	/** 
	 * 计划管理
	 * 挂单历史查询
	 * @param sum
	 * memo1 卷号
	 * memo2 原始卷号
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public ResultModel doQueryWeb(CommonPage<PlnProdorder> sum){
		ResultModel rm=new ResultModel();
		try{
			PageModel<HashMap> pm=new PageModel<HashMap>(sum.getPageIndex(), sum.getPageSize());
			pm.setRows(this.getMapper(PlnMatReplaceLogMapper.class).doQuery(sum.getObject(),sum.getStartTime(),sum.getEndTime(),sum.getMemo1(), (sum.getPageIndex()-1)*sum.getPageSize(), sum.getPageIndex()*sum.getPageSize(),sum.getMemo2()));
			pm.setTotal(this.getMapper(PlnMatReplaceLogMapper.class).doQueryCount(sum.getObject(),sum.getStartTime(),sum.getEndTime(),sum.getMemo1(),sum.getMemo2()));
			rm.setData(pm);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询出错！"+ex.getMessage());
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 20200909 脱单记录查询
	 * @param cp
	 * @return
	 */
	public ResultModel doQueryTuoDanInfo(CommonPage<PlnProdorder> cp){
		ResultModel rm=new ResultModel();
		try{
			PlnProdorder pp = cp.getObject();
			String condition = " and pmrl.opt_type = '0'";
			if (StringUtils.isNotEmpty(pp.getSteel_name())) { //牌号
				condition += " and pp.steel_name like '%"+pp.getSteel_name()+"%'";
			}
			if (StringUtils.isNotEmpty(pp.getOrder_no())) { //订单号
				condition += " and pp.order_no like '%"+pp.getOrder_no()+"%'";
			}
			if (StringUtils.isNotEmpty(pp.getOrder_nature())) { //订单属性
				condition += " and pp.order_nature = '"+pp.getOrder_nature()+"'";
			}
			if (StringUtils.isNotEmpty(cp.getMemo2())) { //原料卷号
				condition += " and ypd.materailcoilno like '%"+cp.getMemo2()+"%'";
			}
			if (StringUtils.isNotEmpty(cp.getMemo1())) { //子卷号
				condition += " and ypd.coilno like '%"+cp.getMemo1()+"%'";
			}
			if (StringUtils.isNotEmpty(cp.getStartTime())) {
				condition += " and pmrl.create_time >= to_date('"+cp.getStartTime()+"','yyyy-MM-dd HH24:mi:ss')";
			}
			if (StringUtils.isNotEmpty(cp.getEndTime())) {
				condition += " and pmrl.create_time <= to_date('"+cp.getEndTime()+"','yyyy-MM-dd HH24:mi:ss')";
			}
			rm.setData(this.getMapper(PlnMatReplaceLogMapper.class).doQueryTuoDanInfo(pp,condition));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询出错！"+ex.getMessage());
			ex.printStackTrace();
		}
		return rm;
	}
	
	
	/**
	 * 20231005 脱单记录查询
	 * @param cp
	 * @return
	 */
	public ResultModel doQueryTuoDanInfoLYS(CommonPage<PlnProdorder> cp){
		ResultModel rm=new ResultModel();
		try{
			PlnProdorder pp = cp.getObject();
			String condition = " and pmrl.opt_type = '0'";
			if (StringUtils.isNotEmpty(pp.getSteel_name())) { //牌号
				condition += " and pp.steel_name like '%"+pp.getSteel_name()+"%'";
			}
			if (StringUtils.isNotEmpty(pp.getOrder_no())) { //订单号
				condition += " and pp.order_no like '%"+pp.getOrder_no()+"%'";
			}
			if (StringUtils.isNotEmpty(pp.getOrder_nature())) { //订单属性
				condition += " and pp.order_nature = '"+pp.getOrder_nature()+"'";
			}
			if (StringUtils.isNotEmpty(cp.getMemo2())) { //原料卷号
				condition += " and ypd.materailcoilno like '%"+cp.getMemo2()+"%'";
			}
			if (StringUtils.isNotEmpty(cp.getMemo1())) { //子卷号
				condition += " and ypd.coilno like '%"+cp.getMemo1()+"%'";
			}
			if (StringUtils.isNotEmpty(cp.getStartTime())) {
				condition += " and pmrl.create_time >= to_date('"+cp.getStartTime()+"','yyyy-MM-dd HH24:mi:ss')";
			}
			if (StringUtils.isNotEmpty(cp.getEndTime())) {
				condition += " and pmrl.create_time <= to_date('"+cp.getEndTime()+"','yyyy-MM-dd HH24:mi:ss')";
			}
			rm.setData(this.getMapper(PlnMatReplaceLogMapper.class).doQueryTuoDanInfo(pp,condition));
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询出错！"+ex.getMessage());
			ex.printStackTrace();
		}
		return rm;
	}
	
	
}
