|
@@ -1,8 +1,10 @@
|
|
|
package com.hfln.portal.infrastructure.gateway.impl;
|
|
|
|
|
|
import cn.hfln.framework.extension.BizException;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.hfln.portal.common.dto.data.event.*;
|
|
|
import com.hfln.portal.common.request.event.*;
|
|
|
+import com.hfln.portal.common.vo.PageRecord;
|
|
|
import com.hfln.portal.domain.customer.OprLogType;
|
|
|
import com.hfln.portal.domain.customer.util.CopyUtils;
|
|
|
import com.hfln.portal.domain.exception.ErrorEnum;
|
|
@@ -19,11 +21,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
@@ -81,9 +86,12 @@ public class AlarmGatewayImpl implements AlarmGateway {
|
|
|
throw new BizException(ErrorEnum.ALARM_PLAN_NOT_EXIST.getErrorCode(), ErrorEnum.ALARM_PLAN_NOT_EXIST.getErrorMessage());
|
|
|
}
|
|
|
}
|
|
|
- BeanUtils.copyProperties(req, alarmPlan);
|
|
|
+ BeanUtils.copyProperties(req, alarmPlan, "uuid");
|
|
|
alarmPlan.setUpdateTime(LocalDateTime.now());
|
|
|
alarmPlan.setCreateTime(LocalDateTime.now());
|
|
|
+ if (! StringUtils.hasText(alarmPlan.getUuid())) {
|
|
|
+ alarmPlan.setUuid(UUID.randomUUID().toString());
|
|
|
+ }
|
|
|
alarmPlanService.saveOrUpdate(alarmPlan);
|
|
|
|
|
|
AlarmTimePlan alarmTimePlan = new AlarmTimePlan();
|
|
@@ -148,23 +156,31 @@ public class AlarmGatewayImpl implements AlarmGateway {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<AlarmPlanTplDTO> queryPlanTpl(AlarmPlanTplQueryReq req) {
|
|
|
+ public PageRecord<AlarmPlanTplDTO> queryPlanTpl(AlarmPlanTplQueryReq req) {
|
|
|
|
|
|
- List<AlarmPlanTpl> list = alarmPlanTplService.queryPlan(req);
|
|
|
- if (CollectionUtils.isEmpty(list)) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
|
|
|
- List<AlarmPlanTplDTO> resList = new ArrayList<>();
|
|
|
- for (AlarmPlanTpl alarmPlanTpl : list) {
|
|
|
+ // 2.执行分页查询
|
|
|
+ Page<AlarmPlanTpl> pageResult = alarmPlanTplService.queryPlan(req);
|
|
|
+
|
|
|
+ // 3.当前页数据转换为DTO
|
|
|
+ List<AlarmPlanTplDTO> resList = pageResult.getRecords().stream().map(alarmPlanTpl -> {
|
|
|
AlarmPlanTplDTO copy = CopyUtils.copy(alarmPlanTpl, AlarmPlanTplDTO.class);
|
|
|
if (alarmPlanTpl.getAlarmTimePlanTplId() != null) {
|
|
|
AlarmTimePlanTpl byId = alarmTimePlanTplService.getById(copy.getAlarmTimePlanTplId());
|
|
|
copy.setAlarmTimePlanTpl(CopyUtils.copy(byId, AlarmTimePlanTplDTO.class));
|
|
|
- resList.add(copy);
|
|
|
}
|
|
|
- }
|
|
|
- return resList;
|
|
|
+ return copy;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 4. 封装 PageRecord 返回
|
|
|
+ PageRecord<AlarmPlanTplDTO> record = new PageRecord<>();
|
|
|
+ record.setRows(resList);
|
|
|
+ record.setTotal(pageResult.getTotal());
|
|
|
+ record.setPageNum((int) pageResult.getCurrent());
|
|
|
+ record.setPageSize((int) pageResult.getSize());
|
|
|
+ record.setTotalPageNum((int) pageResult.getPages());
|
|
|
+
|
|
|
+ return record;
|
|
|
}
|
|
|
|
|
|
@Override
|