|  | @@ -1,8 +1,14 @@
 | 
												
													
														
															|  |  package com.persagy.apm.energyalarmstarter.alarmdata.service;
 |  |  package com.persagy.apm.energyalarmstarter.alarmdata.service;
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | 
 |  | +import java.util.Date;
 | 
												
													
														
															|  | 
 |  | +import java.util.List;
 | 
												
													
														
															|  | 
 |  | +import java.util.Set;
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
												
													
														
															|  | 
 |  | +import org.springframework.stereotype.Service;
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  |  import com.alibaba.fastjson.JSONArray;
 |  |  import com.alibaba.fastjson.JSONArray;
 | 
												
													
														
															|  |  import com.alibaba.fastjson.JSONObject;
 |  |  import com.alibaba.fastjson.JSONObject;
 | 
												
													
														
															|  | -import com.google.common.collect.Lists;
 |  | 
 | 
												
													
														
															|  |  import com.google.common.collect.Sets;
 |  |  import com.google.common.collect.Sets;
 | 
												
													
														
															|  |  import com.persagy.apm.energyalarmstarter.alarmdata.feign.DmpResult;
 |  |  import com.persagy.apm.energyalarmstarter.alarmdata.feign.DmpResult;
 | 
												
													
														
															|  |  import com.persagy.apm.energyalarmstarter.alarmdata.feign.client.AlarmClient;
 |  |  import com.persagy.apm.energyalarmstarter.alarmdata.feign.client.AlarmClient;
 | 
												
											
												
													
														
															|  | @@ -16,12 +22,6 @@ import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.DmpBatchUpsertVO;
 | 
												
													
														
															|  |  import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.DmpUpsertVO;
 |  |  import com.persagy.apm.energyalarmstarter.alarmdata.model.vo.DmpUpsertVO;
 | 
												
													
														
															|  |  import com.persagy.apm.energyalarmstarter.alarmdata.utils.DmpResultUtil;
 |  |  import com.persagy.apm.energyalarmstarter.alarmdata.utils.DmpResultUtil;
 | 
												
													
														
															|  |  import com.persagy.apm.energyalarmstarter.alarmdata.utils.Obj2JSONObject;
 |  |  import com.persagy.apm.energyalarmstarter.alarmdata.utils.Obj2JSONObject;
 | 
												
													
														
															|  | -import org.springframework.beans.factory.annotation.Autowired;
 |  | 
 | 
												
													
														
															|  | -import org.springframework.stereotype.Service;
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -import java.util.Date;
 |  | 
 | 
												
													
														
															|  | -import java.util.List;
 |  | 
 | 
												
													
														
															|  | -import java.util.Set;
 |  | 
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |  /**
 |  |  /**
 | 
												
													
														
															|  |   * 报警记录service类
 |  |   * 报警记录service类
 | 
												
											
												
													
														
															|  | @@ -32,99 +32,107 @@ import java.util.Set;
 | 
												
													
														
															|  |  @Service
 |  |  @Service
 | 
												
													
														
															|  |  public class AlarmRecordServiceImpl {
 |  |  public class AlarmRecordServiceImpl {
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    @Autowired
 |  | 
 | 
												
													
														
															|  | -    AlarmClient alarmClient;
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -    /**
 |  | 
 | 
												
													
														
															|  | -     * 查询报警记录条数
 |  | 
 | 
												
													
														
															|  | -     * @param queryAlarmRecordDTO 入参
 |  | 
 | 
												
													
														
															|  | -     * @return 报警记录列表
 |  | 
 | 
												
													
														
															|  | -     * @throws Exception
 |  | 
 | 
												
													
														
															|  | -     */
 |  | 
 | 
												
													
														
															|  | -    public Integer queryCount(QueryAlarmRecordDTO queryAlarmRecordDTO) throws Exception {
 |  | 
 | 
												
													
														
															|  | -        QueryDTO<QueryAlarmRecordDTO> queryDTO = new QueryDTO<>();
 |  | 
 | 
												
													
														
															|  | -        queryDTO.initUrlParams(queryAlarmRecordDTO.fetchParams());
 |  | 
 | 
												
													
														
															|  | -        queryDTO.setOnlyCount(true);
 |  | 
 | 
												
													
														
															|  | -        queryDTO.setCriteria(queryAlarmRecordDTO);
 |  | 
 | 
												
													
														
															|  | 
 |  | +	@Autowired
 | 
												
													
														
															|  | 
 |  | +	AlarmClient alarmClient;
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -        DmpResult<List<AlarmRecordItem>> dmpResult = query(queryDTO);
 |  | 
 | 
												
													
														
															|  | -        return dmpResult.getCount();
 |  | 
 | 
												
													
														
															|  | -    }
 |  | 
 | 
												
													
														
															|  | 
 |  | +	/**
 | 
												
													
														
															|  | 
 |  | +	 * 查询报警记录条数
 | 
												
													
														
															|  | 
 |  | +	 * 
 | 
												
													
														
															|  | 
 |  | +	 * @param queryAlarmRecordDTO 入参
 | 
												
													
														
															|  | 
 |  | +	 * @return 报警记录列表
 | 
												
													
														
															|  | 
 |  | +	 * @throws Exception
 | 
												
													
														
															|  | 
 |  | +	 */
 | 
												
													
														
															|  | 
 |  | +	public Integer queryCount(QueryAlarmRecordDTO queryAlarmRecordDTO) throws Exception {
 | 
												
													
														
															|  | 
 |  | +		QueryDTO<QueryAlarmRecordDTO> queryDTO = new QueryDTO<>();
 | 
												
													
														
															|  | 
 |  | +		queryDTO.initUrlParams(queryAlarmRecordDTO.fetchParams());
 | 
												
													
														
															|  | 
 |  | +		queryDTO.setOnlyCount(true);
 | 
												
													
														
															|  | 
 |  | +		queryDTO.setCriteria(queryAlarmRecordDTO);
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | 
 |  | +		DmpResult<List<AlarmRecordItem>> dmpResult = query(queryDTO);
 | 
												
													
														
															|  | 
 |  | +		return dmpResult.getCount();
 | 
												
													
														
															|  | 
 |  | +	}
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    /**
 |  | 
 | 
												
													
														
															|  | -     * 查询报警记录
 |  | 
 | 
												
													
														
															|  | -     * @param queryAlarmRecordDTO 入参
 |  | 
 | 
												
													
														
															|  | -     * @return 报警记录列表
 |  | 
 | 
												
													
														
															|  | -     * @throws Exception
 |  | 
 | 
												
													
														
															|  | -     */
 |  | 
 | 
												
													
														
															|  | -    public DmpResult<List<AlarmRecordItem>> query(QueryAlarmRecordDTO queryAlarmRecordDTO) throws Exception {
 |  | 
 | 
												
													
														
															|  | -        QueryDTO<QueryAlarmRecordDTO> queryDTO = new QueryDTO<>();
 |  | 
 | 
												
													
														
															|  | -        queryDTO.initUrlParams(queryAlarmRecordDTO.fetchParams());
 |  | 
 | 
												
													
														
															|  | -        queryDTO.setCriteria(queryAlarmRecordDTO);
 |  | 
 | 
												
													
														
															|  | -        return query(queryDTO);
 |  | 
 | 
												
													
														
															|  | -    }
 |  | 
 | 
												
													
														
															|  | 
 |  | +	/**
 | 
												
													
														
															|  | 
 |  | +	 * 查询报警记录
 | 
												
													
														
															|  | 
 |  | +	 * 
 | 
												
													
														
															|  | 
 |  | +	 * @param queryAlarmRecordDTO 入参
 | 
												
													
														
															|  | 
 |  | +	 * @return 报警记录列表
 | 
												
													
														
															|  | 
 |  | +	 * @throws Exception
 | 
												
													
														
															|  | 
 |  | +	 */
 | 
												
													
														
															|  | 
 |  | +	public DmpResult<List<AlarmRecordItem>> query(QueryAlarmRecordDTO queryAlarmRecordDTO) throws Exception {
 | 
												
													
														
															|  | 
 |  | +		QueryDTO<QueryAlarmRecordDTO> queryDTO = new QueryDTO<>();
 | 
												
													
														
															|  | 
 |  | +		queryDTO.initUrlParams(queryAlarmRecordDTO.fetchParams());
 | 
												
													
														
															|  | 
 |  | +		queryDTO.setCriteria(queryAlarmRecordDTO);
 | 
												
													
														
															|  | 
 |  | +		return query(queryDTO);
 | 
												
													
														
															|  | 
 |  | +	}
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    /**
 |  | 
 | 
												
													
														
															|  | -     * 查询报警记录
 |  | 
 | 
												
													
														
															|  | -     * @param queryDTO 入参
 |  | 
 | 
												
													
														
															|  | -     * @return 报警记录列表
 |  | 
 | 
												
													
														
															|  | -     * @throws Exception
 |  | 
 | 
												
													
														
															|  | -     */
 |  | 
 | 
												
													
														
															|  | -    public DmpResult<List<AlarmRecordItem>> query(QueryDTO<QueryAlarmRecordDTO> queryDTO) throws Exception {
 |  | 
 | 
												
													
														
															|  | -        // 查询结果中带上忽略时间和处理结束时间
 |  | 
 | 
												
													
														
															|  | -        Set<String> withColumns = Sets.newHashSet("ignoreTime", "treatEndTime");
 |  | 
 | 
												
													
														
															|  | -        queryDTO.setWithColumns(withColumns);
 |  | 
 | 
												
													
														
															|  | -        JSONObject jsonObject = Obj2JSONObject.convert(queryDTO);
 |  | 
 | 
												
													
														
															|  | -        DmpResult<JSONArray> result = alarmClient.queryAlarmRecord(queryDTO.fetchParams(), jsonObject);
 |  | 
 | 
												
													
														
															|  | 
 |  | +	/**
 | 
												
													
														
															|  | 
 |  | +	 * 查询报警记录
 | 
												
													
														
															|  | 
 |  | +	 * 
 | 
												
													
														
															|  | 
 |  | +	 * @param queryDTO 入参
 | 
												
													
														
															|  | 
 |  | +	 * @return 报警记录列表
 | 
												
													
														
															|  | 
 |  | +	 * @throws Exception
 | 
												
													
														
															|  | 
 |  | +	 */
 | 
												
													
														
															|  | 
 |  | +	public DmpResult<List<AlarmRecordItem>> query(QueryDTO<QueryAlarmRecordDTO> queryDTO) throws Exception {
 | 
												
													
														
															|  | 
 |  | +		// 查询结果中带上忽略时间和处理结束时间
 | 
												
													
														
															|  | 
 |  | +//        Set<String> withColumns = Sets.newHashSet("ignoreTime", "treatEndTime");
 | 
												
													
														
															|  | 
 |  | +//        queryDTO.setWithColumns(withColumns);
 | 
												
													
														
															|  | 
 |  | +		JSONObject jsonObject = Obj2JSONObject.convert(queryDTO);
 | 
												
													
														
															|  | 
 |  | +		DmpResult<JSONArray> result = alarmClient.queryAlarmRecord(queryDTO.fetchParams(), jsonObject);
 | 
												
													
														
															|  |  //        DmpResult<JSONArray> result = alarmClient.queryAlarmRecord(queryDTO.fetchParams(), Obj2JSONObject.convert2Str(queryDTO));
 |  |  //        DmpResult<JSONArray> result = alarmClient.queryAlarmRecord(queryDTO.fetchParams(), Obj2JSONObject.convert2Str(queryDTO));
 | 
												
													
														
															|  | -        return DmpResultUtil.multiConvert(result, AlarmRecordItem.class);
 |  | 
 | 
												
													
														
															|  | -    }
 |  | 
 | 
												
													
														
															|  | 
 |  | +		return DmpResultUtil.multiConvert(result, AlarmRecordItem.class);
 | 
												
													
														
															|  | 
 |  | +	}
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    /**
 |  | 
 | 
												
													
														
															|  | -     * 创建报警记录
 |  | 
 | 
												
													
														
															|  | -     * @param addAlarmRecordDTO 入参
 |  | 
 | 
												
													
														
															|  | -     * @return 报警记录id
 |  | 
 | 
												
													
														
															|  | -     * @throws Exception
 |  | 
 | 
												
													
														
															|  | -     */
 |  | 
 | 
												
													
														
															|  | -    public DmpResult<DmpUpsertVO> create(AddAlarmRecordDTO addAlarmRecordDTO) throws Exception{
 |  | 
 | 
												
													
														
															|  | -        JSONObject jsonObject = Obj2JSONObject.convert(addAlarmRecordDTO);
 |  | 
 | 
												
													
														
															|  | -        DmpResult<JSONObject> alarmRecord = alarmClient.createAlarmRecord(addAlarmRecordDTO.fetchParams(), jsonObject);
 |  | 
 | 
												
													
														
															|  | -        return DmpResultUtil.singleConvert(alarmRecord, DmpUpsertVO.class);
 |  | 
 | 
												
													
														
															|  | -    }
 |  | 
 | 
												
													
														
															|  | 
 |  | +	/**
 | 
												
													
														
															|  | 
 |  | +	 * 创建报警记录
 | 
												
													
														
															|  | 
 |  | +	 * 
 | 
												
													
														
															|  | 
 |  | +	 * @param addAlarmRecordDTO 入参
 | 
												
													
														
															|  | 
 |  | +	 * @return 报警记录id
 | 
												
													
														
															|  | 
 |  | +	 * @throws Exception
 | 
												
													
														
															|  | 
 |  | +	 */
 | 
												
													
														
															|  | 
 |  | +	public DmpResult<DmpUpsertVO> create(AddAlarmRecordDTO addAlarmRecordDTO) throws Exception {
 | 
												
													
														
															|  | 
 |  | +		JSONObject jsonObject = Obj2JSONObject.convert(addAlarmRecordDTO);
 | 
												
													
														
															|  | 
 |  | +		DmpResult<JSONObject> alarmRecord = alarmClient.createAlarmRecord(addAlarmRecordDTO.fetchParams(), jsonObject);
 | 
												
													
														
															|  | 
 |  | +		return DmpResultUtil.singleConvert(alarmRecord, DmpUpsertVO.class);
 | 
												
													
														
															|  | 
 |  | +	}
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    /**
 |  | 
 | 
												
													
														
															|  | -     * 更新报警记录
 |  | 
 | 
												
													
														
															|  | -     * @param updateAlarmRecordDTO 入参
 |  | 
 | 
												
													
														
															|  | -     * @return 报警记录id
 |  | 
 | 
												
													
														
															|  | -     * @throws Exception
 |  | 
 | 
												
													
														
															|  | -     */
 |  | 
 | 
												
													
														
															|  | -    public DmpResult<DmpUpsertVO> update(UpdateAlarmRecordDTO updateAlarmRecordDTO) throws Exception{
 |  | 
 | 
												
													
														
															|  | -        JSONObject jsonObject = Obj2JSONObject.convert(updateAlarmRecordDTO);
 |  | 
 | 
												
													
														
															|  | -        DmpResult<JSONObject> alarmRecord = alarmClient.updateAlarmRecord(updateAlarmRecordDTO.fetchParams(), jsonObject);
 |  | 
 | 
												
													
														
															|  | -        return DmpResultUtil.singleConvert(alarmRecord, DmpUpsertVO.class);
 |  | 
 | 
												
													
														
															|  | -    }
 |  | 
 | 
												
													
														
															|  | 
 |  | +	/**
 | 
												
													
														
															|  | 
 |  | +	 * 更新报警记录
 | 
												
													
														
															|  | 
 |  | +	 * 
 | 
												
													
														
															|  | 
 |  | +	 * @param updateAlarmRecordDTO 入参
 | 
												
													
														
															|  | 
 |  | +	 * @return 报警记录id
 | 
												
													
														
															|  | 
 |  | +	 * @throws Exception
 | 
												
													
														
															|  | 
 |  | +	 */
 | 
												
													
														
															|  | 
 |  | +	public DmpResult<DmpUpsertVO> update(UpdateAlarmRecordDTO updateAlarmRecordDTO) throws Exception {
 | 
												
													
														
															|  | 
 |  | +		JSONObject jsonObject = Obj2JSONObject.convert(updateAlarmRecordDTO);
 | 
												
													
														
															|  | 
 |  | +		DmpResult<JSONObject> alarmRecord = alarmClient.updateAlarmRecord(updateAlarmRecordDTO.fetchParams(),
 | 
												
													
														
															|  | 
 |  | +				jsonObject);
 | 
												
													
														
															|  | 
 |  | +		return DmpResultUtil.singleConvert(alarmRecord, DmpUpsertVO.class);
 | 
												
													
														
															|  | 
 |  | +	}
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    /**
 |  | 
 | 
												
													
														
															|  | -     * 批量更新报警记录
 |  | 
 | 
												
													
														
															|  | -     * @param batchUpdateAlarmRecordDTO 入参
 |  | 
 | 
												
													
														
															|  | -     * @return 报警记录ids
 |  | 
 | 
												
													
														
															|  | -     * @throws Exception
 |  | 
 | 
												
													
														
															|  | -     */
 |  | 
 | 
												
													
														
															|  | -    public DmpResult<DmpBatchUpsertVO> batchUpdate(BatchUpdateAlarmRecordDTO batchUpdateAlarmRecordDTO) throws Exception {
 |  | 
 | 
												
													
														
															|  | -        JSONObject jsonObject = Obj2JSONObject.convert(batchUpdateAlarmRecordDTO);
 |  | 
 | 
												
													
														
															|  | -        DmpResult<JSONObject> result = alarmClient.batchUpdateAlarmRecord(batchUpdateAlarmRecordDTO.fetchParams(), jsonObject);
 |  | 
 | 
												
													
														
															|  | -        return DmpResultUtil.singleConvert(result, DmpBatchUpsertVO.class);
 |  | 
 | 
												
													
														
															|  | -    }
 |  | 
 | 
												
													
														
															|  | 
 |  | +	/**
 | 
												
													
														
															|  | 
 |  | +	 * 批量更新报警记录
 | 
												
													
														
															|  | 
 |  | +	 * 
 | 
												
													
														
															|  | 
 |  | +	 * @param batchUpdateAlarmRecordDTO 入参
 | 
												
													
														
															|  | 
 |  | +	 * @return 报警记录ids
 | 
												
													
														
															|  | 
 |  | +	 * @throws Exception
 | 
												
													
														
															|  | 
 |  | +	 */
 | 
												
													
														
															|  | 
 |  | +	public DmpResult<DmpBatchUpsertVO> batchUpdate(BatchUpdateAlarmRecordDTO batchUpdateAlarmRecordDTO)
 | 
												
													
														
															|  | 
 |  | +			throws Exception {
 | 
												
													
														
															|  | 
 |  | +		JSONObject jsonObject = Obj2JSONObject.convert(batchUpdateAlarmRecordDTO);
 | 
												
													
														
															|  | 
 |  | +		DmpResult<JSONObject> result = alarmClient.batchUpdateAlarmRecord(batchUpdateAlarmRecordDTO.fetchParams(),
 | 
												
													
														
															|  | 
 |  | +				jsonObject);
 | 
												
													
														
															|  | 
 |  | +		return DmpResultUtil.singleConvert(result, DmpBatchUpsertVO.class);
 | 
												
													
														
															|  | 
 |  | +	}
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    public static void main(String[] args) {
 |  | 
 | 
												
													
														
															|  | -        AddAlarmRecordDTO addAlarmRecordDTO = new AddAlarmRecordDTO();
 |  | 
 | 
												
													
														
															|  | -        addAlarmRecordDTO.setTriggerTime(new Date());
 |  | 
 | 
												
													
														
															|  | -        try {
 |  | 
 | 
												
													
														
															|  | -            JSONObject convert = Obj2JSONObject.convert(addAlarmRecordDTO);
 |  | 
 | 
												
													
														
															|  | -            System.out.println(convert);
 |  | 
 | 
												
													
														
															|  | -        } catch (Exception e) {
 |  | 
 | 
												
													
														
															|  | -            e.printStackTrace();
 |  | 
 | 
												
													
														
															|  | -        }
 |  | 
 | 
												
													
														
															|  | -    }
 |  | 
 | 
												
													
														
															|  | 
 |  | +	public static void main(String[] args) {
 | 
												
													
														
															|  | 
 |  | +		AddAlarmRecordDTO addAlarmRecordDTO = new AddAlarmRecordDTO();
 | 
												
													
														
															|  | 
 |  | +		addAlarmRecordDTO.setTriggerTime(new Date());
 | 
												
													
														
															|  | 
 |  | +		try {
 | 
												
													
														
															|  | 
 |  | +			JSONObject convert = Obj2JSONObject.convert(addAlarmRecordDTO);
 | 
												
													
														
															|  | 
 |  | +			System.out.println(convert);
 | 
												
													
														
															|  | 
 |  | +		} catch (Exception e) {
 | 
												
													
														
															|  | 
 |  | +			e.printStackTrace();
 | 
												
													
														
															|  | 
 |  | +		}
 | 
												
													
														
															|  | 
 |  | +	}
 | 
												
													
														
															|  |  }
 |  |  }
 |