/***文档注释***********************************************
 * 作者            ：
 * 创建日期     ：2018-09-11
 * 描述            ：计量单接口表
 * 注意事项     ：
 * 遗留BUG   ：
 * 修改日期     ：
 * 修改人员     ：
 * 修改内容     ：
***********************************************************/
package market.Pms.Settlement.impl;
import java.util.List;

import market.Com.vo.CommonPage;
import market.Com.vo.ResultModel;
import market.Pms.Settlement.mapper.PurInterfaceMeasureMapper;
import market.Pms.Settlement.service.PurInterfaceMeasureService;
import market.Pms.Settlement.vo.PurInterfaceMeasure;

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

@RemoteService(path="PurInterfaceMeasureService")
public class PurInterfaceMeasureServiceImpl extends BaseServiceImpl<PurInterfaceMeasure,Object> implements PurInterfaceMeasureService {
	/***
	 * 
	 * 计量信息查询
	 * */
	public ResultModel  doQueryWeb(CommonPage<PurInterfaceMeasure> sum){
		ResultModel rm=new ResultModel();
		PurInterfaceMeasure  pfb=sum.getObject();
		try {
//			String swhere="1=1 and VALIDFLAG='00'";//查询初始数据
//			if(pfb.getContract_pk()!=null&&!"".equals(pfb.getContract_pk())){
//				swhere+=" and  Contract_pk  like "+pfb.getContract_pk()+"";
//			}
//			if(pfb.getContract_no()!=null&&!"".equals(pfb.getContract_no())){
//				swhere+=" and  Contract_no  like "+pfb.getContract_no()+"";
//			}//合同号
//			List<PurInterfaceMeasure>  list =this.getMapper(PurInterfaceMeasureMapper.class).findWithCondition(null, swhere, "CREATE_TIME desc", 0, 0);			
			List<PurInterfaceMeasure>  list =this.getMapper(PurInterfaceMeasureMapper.class).findPurInterfaceMeasure(pfb);
			rm.setData(list);;
			rm.setState("200");
			rm.setMsgInfo("查询成功");		
		} catch (Exception e) {
			// TODO: handle exception
			rm.setState("500");
			rm.setMsgInfo("查询失败，请联系管理员！");
			throw e;
		}
		return rm;
		
	}
	
	/***
	 * 
	 * 计量信息查询
	 * */
	public ResultModel  doQueryException(CommonPage<PurInterfaceMeasure> sum){
		ResultModel rm=new ResultModel();
		PurInterfaceMeasure  pfb=sum.getObject();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime();
		try {
			List<PurInterfaceMeasure>  list =this.getMapper(PurInterfaceMeasureMapper.class).findExceptionMeasure(pfb,startTime,endTime);
			rm.setData(list);;
			rm.setState("200");
			rm.setMsgInfo("查询成功");		
		} catch (Exception e) {
			// TODO: handle exception
			rm.setState("500");
			rm.setMsgInfo("查询失败，请联系管理员！");
			throw e;
		}
		return rm;
	}
	
	/**
	 * 
	 * @author 赵淋支
	 * @date   2018年10月16日
	 * @parameter  [{"object":{"supp_name":"","contract_no":"","measure_no":""},"startTime":"2018-10-09 00:00:00","endTime":"2018-10-17 23:59:59"}]
	 * @return 
	 * @description 异议单编制界面：查询计量单信息
	 */
	public ResultModel  doQueryMeasure(CommonPage<PurInterfaceMeasure> sum){
		ResultModel rm=new ResultModel();
		PurInterfaceMeasure  pfb=sum.getObject();
		String startTime=sum.getStartTime();
		String endTime=sum.getEndTime(); 
		try {
			String condition = "1=1 and validflag = '00'";
			if (pfb.getContract_no()!=null && !"".equals(pfb.getContract_no())) {
				condition += " and contract_no like '%"+ pfb.getContract_no()+"%'";
			}
			if (pfb.getMeasure_no()!=null && !"".equals(pfb.getMeasure_no())) {
				condition += " and measure_no like '%"+ pfb.getMeasure_no()+"%'";
			}
			if (startTime!=null && !"".equals(startTime)) {
				condition += " and to_char(create_time, 'yyyy-mm-dd hh24:mi:ss') >='"+startTime+"'";			
			}
			if (endTime!=null && !"".equals(endTime)) {
				condition += " and to_char(create_time, 'yyyy-mm-dd hh24:mi:ss') <='"+endTime+"'";			
			}
			List<PurInterfaceMeasure> list =this.getMapper(PurInterfaceMeasureMapper.class).findWithCondition(null, condition, "create_time desc", 0, 0);
			rm.setData(list);;
			rm.setState("200");
			rm.setMsgInfo("查询成功");		
		} catch (Exception e) {
			rm.setState("500");
			rm.setMsgInfo("查询失败，请联系管理员！");
			throw e;
		}
		return rm;
	}
	
	
}
