/***文档注释***********************************************
 * 作者               :                   易鑫
 * 创建日期      :                   2017.10.24
 * 描述               :        			合同指定产线信息
 * 注意事项      :                   无
 * 遗留BUG :                   无
 * 修改日期      :                   
 * 修改人员      :                   
 * 修改内容      :                   
***********************************************************/
package market.Slm.ContractManagement.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import market.Com.pb.PbMethod;
import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Slm.ContractManagement.mapper.SlmContractLineInfoMapper;
import market.Slm.ContractManagement.mapper.SlmCustAlphaSpecMapper;
import market.Slm.ContractManagement.service.SlmCustAlphaSpecService;
import market.Slm.ContractManagement.vo.SlmContractLineInfo;
import market.Slm.ContractManagement.vo.SlmCustAlphaSpec;
import market.Slm.OrderManagement.mapper.SlmProcessPlanMapper;
import market.Slm.OrderManagement.vo.SlmProcessPlan;

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

@RemoteService(path="SlmCustAlphaSpecService")
public class SlmCustAlphaSpecServiceImpl extends BaseServiceImpl<SlmCustAlphaSpec,Object> implements SlmCustAlphaSpecService {
	
	/**
	 * 通过加工计划号查询具体的公差要求
	 * */
	public ResultModel doQueryByPlanWeb(SlmProcessPlan plan){
		ResultModel rm=new ResultModel();
		try{
			plan=this.getMapper(SlmProcessPlanMapper.class).findById(plan.getPlan_no());
			if(plan==null){
				rm.setState("500");
				rm.setMsgInfo("未找到对应的加工计划，请检查加工计划号plan_no");
				return rm;
			}
			SlmContractLineInfo line=this.getMapper(SlmContractLineInfoMapper.class).findById(plan.getContract_line_no());
			if(line==null){
				rm.setState("500");
				rm.setMsgInfo("未找到对应的合同行信息");
				return rm;
			}
			SlmCustAlphaSpec spec=new SlmCustAlphaSpec();
			spec.setCust_alpha_no(line.getCustomer_alpha_no());
			List<SlmCustAlphaSpec> list=this.getMapper(SlmCustAlphaSpecMapper.class).find(spec, 0, 0);
			rm.setState("200");
			rm.setData(list);
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败!"+ex.getMessage());
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 公差要求 - 新增
	 * */
	public ResultModel doAddWeb(CommonPage<SlmCustAlphaSpec> sum){
		ResultModel rm=new ResultModel();
		SlmCustAlphaSpec spec=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
//		try{
			String seq=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+PbMethod.RandomCreate(3);
			spec.setSpec_seq(seq);
			spec.setCreate_no(userId);
			spec.setCreate_name(userName);
			spec.setCreate_time(new Date());
			if(spec.getValidflag()==null)
				spec.setValidflag("1");
			this.getMapper(SlmCustAlphaSpecMapper.class).insert(spec);
			rm.setState("200");
//		}catch(Exception ex){
//			rm.setState("500");
//			rm.setMsgInfo("新增失败!");
//			ex.printStackTrace();
//		}
		return rm;
	}
	
	/**
	 * 公差要求 - 编辑
	 * */
	public ResultModel doUpdateWeb(CommonPage<SlmCustAlphaSpec> sum){
		ResultModel rm=new ResultModel();
		SlmCustAlphaSpec spec=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			spec.setUpdate_no(userId);
			spec.setUpdate_name(userName);
			spec.setUpdate_time(new Date());
			this.getMapper(SlmCustAlphaSpecMapper.class).update(spec);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("编辑失败!");
			ex.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 公差要求 - 详情
	 * */
	public ResultModel doQueryDetailWeb(CommonPage<SlmCustAlphaSpec> sum){
		ResultModel rm=new ResultModel();
		SlmCustAlphaSpec spec=sum.getObject();
		try{
			spec=this.getMapper(SlmCustAlphaSpecMapper.class).findById(spec.getSpec_seq());
			rm.setState("200");
			rm.setData(spec);
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("查询失败!");
			ex.printStackTrace();
		}
		return rm;
	}
}
