/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-01-09
 * 描述            ：加工计划信息表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
 ***********************************************************/
package market.Slm.ServiceManagement.impl;
import java.util.Calendar;
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.ServiceManagement.mapper.SlmServiceObjDeclareHeatMapper;
import market.Slm.ServiceManagement.service.SlmServiceObjDeclareHeatService;
import market.Slm.ServiceManagement.vo.SlmServiceObjDeclareHeat;

import com.hnshituo.basic.service.impl.BaseServiceImpl;
import com.hnshituo.basic.service.support.PageModel;
import com.hnshituo.basic.spring.remoting.annotation.RemoteService;
import com.hnshituo.core.auth.service.HomeService;
import com.ibm.icu.text.SimpleDateFormat;

@RemoteService(path="SlmServiceObjDeclareHeatService")
public class SlmServiceObjDeclareHeatServiceImpl extends BaseServiceImpl<SlmServiceObjDeclareHeat,Object> implements SlmServiceObjDeclareHeatService {

	/**
	 * 查询
	 * */
	public ResultModel doQueryWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		int pageIndex=sum.getPageIndex();
		int pageSize=sum.getPageSize();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		String flag=sum.getMemo1();			//0查询包含无效的
		try{
			String sWhere=" 1=1 ";
			if(startTime!=null&&!"".equals(startTime)){		
				sWhere+=" and to_char(declare_time, 'yyyy-mm-dd hh24:mi:ss') >='"+startTime+"'";
			}
			if(endTime!=null&&!"".equals(endTime)){
				endTime+=" 23:59:59";
				sWhere+=" and to_char(declare_time, 'yyyy-mm-dd hh24:mi:ss') <= '"+endTime+"'";
			}
			if(!"0".equals(flag)){
				sWhere+=" and objection_flag!='9'";
			}
			List<SlmServiceObjDeclareHeat> list=this.getMapper(SlmServiceObjDeclareHeatMapper.class).findWithCondition(heat, sWhere, " declare_time desc", pageSize*(pageIndex-1), pageSize);
			rm.setData(list);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("查询失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 新增
	 * */
	public ResultModel doAddWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			String id=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+PbMethod.RandomCreate(3);
			heat.setHeat_no(id);
			heat.setDeclare_time(new Date());
			heat.setDeclarer_no(userId);
			heat.setDeclarer_name(userName);
			heat.setObjection_flag("0");     //0:待提交
			this.getMapper(SlmServiceObjDeclareHeatMapper.class).insert(heat);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("新增失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 提交，状态0→1：异议提案；
	 * */
	public ResultModel doSubmitWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();
			if("0".equals(heat.getObjection_flag())){
				heat.setObjection_flag("1");
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择待提交的数据进行操作");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("提交失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}


	/**
	 * 提案→立案，状态1→2：异议立案；
	 * */
	public ResultModel doCaseSetWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();	
			if("1".equals(heat.getObjection_flag())){
				heat.setObjection_flag("2");
				heat.setRecord_man_no(userId);
				heat.setRecord_man_name(userName);
				heat.setRecord_time(new Date());
				heat.setEstart_time(new Date());
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择已提交的数据进行操作");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("提交失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 撤销 立案→提案，状态2→1：异议提案；
	 * */
	public ResultModel doRevokeCaseWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();		
			if("2".equals(heat.getObjection_flag())){
				heat.setObjection_flag("1");
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择立案的数据进行撤销");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("提交失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 提交，状态2→10：异议驳回；
	 * */
	public ResultModel doRejectWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			String rejectContext=heat.getReject_context();
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();
			String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
			String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
			if("2".equals(heat.getObjection_flag())){
				heat.setObjection_flag("10");
				heat.setReject_time(new Date());
				heat.setReject_man_no(userId);
				heat.setReject_man_name(userName);
				heat.setReject_context(rejectContext);
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选立案的数据进行操作");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("驳回失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}
	
//	/**
//	 * 核实，状态2→3：异议核实；
//	 * */
//	public ResultModel doCheckWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
//		ResultModel rm=new ResultModel();
//		SlmServiceObjDeclareHeat heat=sum.getObject();
//		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
//		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
//		try{
//			ResultModel checkRm=checkNull(heat);
//			if("500".equals(checkRm.getState())) return checkRm;
//			SlmServiceObjDeclareHeat check=(SlmServiceObjDeclareHeat) checkRm.getData();		
//			if("2".equals(check.getObjection_flag())){
//				heat.setObjection_flag("3");
//				heat.setCheck_man_no(userId);
//				heat.setCheck_man_name(userName);
//				heat.setCheck_time(new Date());
//				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
//			}else{
//				rm.setState("500");
//				rm.setMsgInfo("请选择待核实的数据进行操作");
//				return rm;
//			}
//			rm.setState("200");
//		}catch(Exception e){
//			rm.setState("500");
//			rm.setMsgInfo("提交失败"+e.getMessage());
//			e.printStackTrace();
//		}
//		return rm;
//	}

	/**
	 * 核实→待处理，状态3→4：异议待处理；
	 * */
	public ResultModel doPendingWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();		
			if("3".equals(heat.getObjection_flag())){
				heat.setObjection_flag("4");
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择已核实的数据进行操作");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("提交失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 撤销 核实→立案，状态3→2：异议立案；
	 * */
	public ResultModel doRevokeCheckWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();		
			if("3".equals(heat.getObjection_flag())){
				heat.setObjection_flag("2");
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择已核实的数据进行撤销");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("提交失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 处理→待审批，状态5→6：异议待审批；
	 * */
	public ResultModel doApprovingWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();		
			if("5".equals(heat.getObjection_flag())){
				heat.setObjection_flag("6");
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择已处理的数据进行操作");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("提交失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 待审批→审批，状态6→7：异议审批；
	 * */
	public ResultModel doApprovalWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();		
			if("6".equals(heat.getObjection_flag())){
				heat.setObjection_flag("7");
				heat.setApproval_man_no(userId);
				heat.setApproval_man_name(userName);
				heat.setApproval_time(new Date());
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择待审批的数据进行操作");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("审批失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 审批不同意 审批→处理，状态6→5：异议审批；
	 * */
	public ResultModel doApprovalNotWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();		
			if("6".equals(heat.getObjection_flag())){
				heat.setObjection_flag("5");
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择待审批的数据进行操作");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("审批失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 审批→结案，状态7→8：异议结案；
	 * */
	public ResultModel doCloseWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();		
			if("7".equals(heat.getObjection_flag())){
				Date now=new Date();
				heat.setObjection_flag("8");
				heat.setClose_man_no(userId);
				heat.setClose_man_name(userName);
				heat.setClose_time(now);
				heat.setEend_time(now);
				//计算天数
				int day=countDay(heat.getEstart_time(),now);
				heat.setEstart_eend_days(day);
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择待审批的数据进行操作");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("审批失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 取消结案，结案→已审批，状态8→7：异议审批；
	 * */
	public ResultModel doCancelCloseWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();		
			if("8".equals(heat.getObjection_flag())){
				heat.setObjection_flag("7");
				heat.setEend_time(null);
				heat.setEstart_eend_days(0);
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择已结案的数据进行操作");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("审批失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 异议评价
	 * */
	public ResultModel doEvaluateWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			SlmServiceObjDeclareHeat check=this.getMapper(SlmServiceObjDeclareHeatMapper.class).findById(heat.getHeat_no());
			if(check==null){
				rm.setState("500");
				rm.setMsgInfo("未找到异议信息");
				return rm;
			}
			if("8".equals(check.getObjection_flag())){ 
				SlmServiceObjDeclareHeat h=new SlmServiceObjDeclareHeat();
				h.setHeat_no(heat.getHeat_no());
				h.setCustomer_review(heat.getCustomer_review());
				h.setCustomer_review_value(heat.getCustomer_review_value());
				h.setCustomer_review_time(new Date());
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择已结案的数据进行操作");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("审批失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 编辑  状态为 0 3 时方可编辑
	 * */
	public ResultModel doUpdateWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			SlmServiceObjDeclareHeat check=(SlmServiceObjDeclareHeat) checkRm.getData();	
			if("03".contains(check.getObjection_flag())){
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("该数据已无法修改，请选择待提交和已核实的数据进行修改");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("编辑失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}

	/**
	 * 删除 逻辑删除
	 * 作废 flag =9
	 * */
	public ResultModel doDeleteWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			ResultModel checkRm=checkNull(heat);
			if("500".equals(checkRm.getState())) return checkRm;
			heat=(SlmServiceObjDeclareHeat) checkRm.getData();		
			if("0".equals(heat.getObjection_flag())){
				heat.setObjection_flag("9");
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("只能删除待提交的数据");
				return rm;
			}
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("失败"+ex.getMessage());
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 异议客户统计
	 * */
	public ResultModel doQueryCustomerCensusWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		try{
			if(startTime!=null&&!"".equals(startTime)){
				startTime+=" 00:00:00";
			}
			if(endTime!=null&&!"".equals(endTime)){
				endTime+=" 23:59:59";
			}
			List<SlmServiceObjDeclareHeat> heat_list=this.getMapper(SlmServiceObjDeclareHeatMapper.class).doQueryCustomerCensus(heat,startTime,endTime);
			rm.setData(heat_list);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("失败"+ex.getMessage());
			ex.printStackTrace();
		}
		return rm;
	}

	/**
	 * 异议性质统计
	 * */
	public ResultModel doQueryNatureCensusWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		try{
			if(startTime!=null&&!"".equals(startTime)){
				startTime+=" 00:00:00";
			}
			if(endTime!=null&&!"".equals(endTime)){
				endTime+=" 23:59:59";
			}
			List<SlmServiceObjDeclareHeat> heat_list=this.getMapper(SlmServiceObjDeclareHeatMapper.class).doQueryNatureCensus(heat,startTime,endTime);
			rm.setData(heat_list);
			rm.setState("200");
		}catch(Exception ex){
			rm.setState("500");
			rm.setMsgInfo("失败"+ex.getMessage());
			ex.printStackTrace();
		}
		return rm;
	}

	private ResultModel checkNull(SlmServiceObjDeclareHeat heat){
		ResultModel rm=new ResultModel();
		rm.setState("200");
		if(heat==null){
			rm.setState("500");
			rm.setMsgInfo("请传入参数");
			return rm;
		}
		if(heat.getHeat_no()==null){
			rm.setState("500");
			rm.setMsgInfo("请传入异议编号heat_no");
			return rm;
		}
		SlmServiceObjDeclareHeat check=this.getMapper(SlmServiceObjDeclareHeatMapper.class).findById(heat.getHeat_no());
		if(check==null){
			rm.setState("500");
			rm.setMsgInfo("未找到异议信息");
			return rm;
		}	
		rm.setData(check);
		return rm;
	}

	public int countDay(Date sDate,Date eDate){
		Calendar cal = Calendar.getInstance();    
		cal.setTime(sDate);      
		long time1 = cal.getTimeInMillis();   
		cal.setTime(eDate);    
		long time2 = cal.getTimeInMillis();     
		long between_days=(time2-time1)/(1000*3600*24);       
		return Integer.parseInt(String.valueOf(between_days));  
	}
	
	//=========================APP eason add 2019-07-15 ================================
	/**
	 * 查询
	 * */
	public ResultModel doQueryApp(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject()==null?new SlmServiceObjDeclareHeat():sum.getObject();
		int pageIndex=sum.getPageIndex();
		int pageSize=sum.getPageSize();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		String flag=sum.getMemo1();			//0查询包含无效的
		
		try{
			heat.setCustomer_no((String)this.getSession().getAttribute(HomeService.SESSION_DEPT_ID));
			String sWhere=" 1=1 ";
			if(startTime!=null&&!"".equals(startTime)){		
				sWhere+=" and to_char(declare_time, 'yyyy-mm-dd hh24:mi:ss') >='"+startTime+"'";
			}
			if(endTime!=null&&!"".equals(endTime)){
				endTime+=" 23:59:59";
				sWhere+=" and to_char(declare_time, 'yyyy-mm-dd hh24:mi:ss') <= '"+endTime+"'";
			}
			if(!"0".equals(flag)){
				sWhere+=" and objection_flag!='9'";
			}
			if(sum.getMemo2()!=null&&!"".equals(sum.getMemo2())){
				if("1".equals(sum.getMemo2().trim())){
					sWhere+=" and customer_review_time is null ";
				} else if("2".equals(sum.getMemo2().trim())){
					sWhere+=" and customer_review_time is not null ";
				}
			}
			List<SlmServiceObjDeclareHeat> list=this.getMapper(SlmServiceObjDeclareHeatMapper.class).findWithCondition(heat, sWhere, " declare_time desc", pageSize*(pageIndex-1), pageSize);
			rm.setData(list);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("查询失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 新增
	 * */
	public ResultModel doAddApp(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		String userId=(String) this.getSession().getAttribute(HomeService.SESSION_USER_ID);
		String userName=(String) this.getSession().getAttribute(HomeService.SESSION_USER_NAME);
		try{
			String id=new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+PbMethod.RandomCreate(3);
			heat.setHeat_no(id);
			heat.setDeclare_time(new Date());
			heat.setDeclarer_no(userId);
			heat.setDeclarer_name(userName);
			heat.setObjection_flag("0");     //0:待提交
			this.getMapper(SlmServiceObjDeclareHeatMapper.class).insert(heat);
			rm.setState("200");
			rm.setData(id);
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("新增失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 异议评价
	 */
	public ResultModel doEvaluateApp(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		SlmServiceObjDeclareHeat heat=sum.getObject();
		try{
			SlmServiceObjDeclareHeat check=this.getMapper(SlmServiceObjDeclareHeatMapper.class).findById(heat.getHeat_no());
			if(check==null){
				rm.setState("500");
				rm.setMsgInfo("未找到异议信息");
				return rm;
			}
			if("8".equals(check.getObjection_flag())){ 
				SlmServiceObjDeclareHeat h=new SlmServiceObjDeclareHeat();
				h.setHeat_no(heat.getHeat_no());
				h.setCustomer_review(heat.getCustomer_review());
				h.setCustomer_review_value(heat.getCustomer_review_value());
				h.setCustomer_review_time(new Date());
				this.getMapper(SlmServiceObjDeclareHeatMapper.class).update(heat);
			}else{
				rm.setState("500");
				rm.setMsgInfo("请选择已结案的数据进行操作");
				return rm;
			}
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("审批失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 查询异议统计
	 * @param sum
	 * @return
	 */
	public ResultModel doTotalWeb(){
		ResultModel rm=new ResultModel();
		try{
			List<SlmServiceObjDeclareHeat> check=this.getMapper(SlmServiceObjDeclareHeatMapper.class).doTotal();
			rm.setData(check);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("查询失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}
	
	/**
	 * 查询异议统计
	 * @param sum
	 * @return
	 */
	public ResultModel doTotalQueryWeb(CommonPage<SlmServiceObjDeclareHeat> sum){
		ResultModel rm=new ResultModel();
		
		int pageIndex=sum.getPageIndex();
		int pageSize=sum.getPageSize();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		try{
			String sWhere="";
			if("0".equals(sum.getMemo1())){
				sWhere="objection_flag not in('9','10')";
			}else if("1".equals(sum.getMemo1())){
				sWhere="objection_flag='10'";
			}else if("2".equals(sum.getMemo1())){
				sWhere="objection_flag in('4','5','6','7','8')";
			}else{
				rm.setState("500");
				rm.setMsgInfo("传值错误");
				return rm;
			}
			
			if(startTime!=null&&!"".equals(startTime)){		
				sWhere+=" and to_char(declare_time, 'yyyy-mm-dd hh24:mi:ss') >='"+startTime+"'";
			}
			if(endTime!=null&&!"".equals(endTime)){
				endTime+=" 23:59:59";
				sWhere+=" and to_char(declare_time, 'yyyy-mm-dd hh24:mi:ss') <= '"+endTime+"'";
			}
			
			List<SlmServiceObjDeclareHeat> check=this.getMapper(SlmServiceObjDeclareHeatMapper.class).findWithCondition(null, sWhere, "", pageSize*(pageIndex-1), pageSize);
			PageModel<SlmServiceObjDeclareHeat> pg=new PageModel<>(pageIndex, pageSize);
			pg.setRows(check);
			pg.setTotal(this.getMapper(SlmServiceObjDeclareHeatMapper.class).countWithCondition(null, sWhere));
			
			rm.setData(pg);
			rm.setState("200");
		}catch(Exception e){
			rm.setState("500");
			rm.setMsgInfo("查询失败"+e.getMessage());
			e.printStackTrace();
		}
		return rm;
	}
}

