/***文档注释***********************************************
 * 作者               :                   易鑫
 * 创建日期      :                   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.SlmContractModelHeatMapper;
import market.Slm.ContractManagement.service.SlmContractModelHeatService;
import market.Slm.ContractManagement.vo.SlmContractModelHeat;

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

@RemoteService(path="SlmContractModelHeatService")
public class SlmContractModelHeatServiceImpl extends BaseServiceImpl<SlmContractModelHeat,Object> implements SlmContractModelHeatService {

	/**
	 * 合同范本 - 查询
	 * contract_model_name,unit_name模糊查询
	 * is_common_use(1：通用；0:专用
	 * */
	public ResultModel doQueryWeb(CommonPage<SlmContractModelHeat> sum) {
		ResultModel rm=new ResultModel();
		SlmContractModelHeat heat=sum.getObject();
		try{
			String sWhere=" 1=1 ";
			if(heat.getContract_model_name()!=null)
				sWhere+=" contract_model_name like CONCAT('%','"+heat.getContract_model_name()+"','%') ";
			if(heat.getUnit_name()!=null)
				sWhere+=" unit_name like CONCAT('%','"+heat.getUnit_name()+"','%') ";
			List<SlmContractModelHeat> list=this.getMapper(SlmContractModelHeatMapper.class).findWithCondition(heat, sWhere, null, 0, 0);
			rm.setData(list);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("查询失败");
		}
		return rm;
	}
	
	/**
	 * 合同范本-新增
	 * */
	public ResultModel doAddWeb(CommonPage<SlmContractModelHeat> sum) {
		ResultModel rm=new ResultModel();
		String userId = (String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName = (String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		SlmContractModelHeat heat=sum.getObject();
		try {
			String strPk=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+PbMethod.RandomCreate(3);
			heat.setContract_model_no(strPk);
			heat.setCreate_man_no(userId);
			heat.setCreate_man_name(userName);
			heat.setCreate_time(new Date());
			this.getMapper(SlmContractModelHeatMapper.class).insert(heat);

			rm.setState("200");
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("服务端异常，新增失败!");
			e.printStackTrace();
		}
		return rm;
	}
}
