@@ -3,6 +3,7 @@ package com.tuoheng.admin.service.warning; | |||
import com.tuoheng.admin.entity.domain.Warning; | |||
import com.tuoheng.admin.entity.query.WarningQuery; | |||
import com.tuoheng.admin.entity.request.warning.QueryWarningListRequest; | |||
import com.tuoheng.admin.entity.request.warning.WarningConfirmRequest; | |||
import com.tuoheng.common.common.IBaseService; | |||
import com.tuoheng.common.utils.JsonResult; | |||
@@ -38,4 +39,22 @@ public interface IWarningService extends IBaseService<Warning> { | |||
*/ | |||
JsonResult index(WarningQuery query); | |||
/** | |||
* | |||
* 确认 | |||
* | |||
* @param request | |||
* @return | |||
*/ | |||
JsonResult confirm(WarningConfirmRequest request); | |||
/** | |||
* | |||
* 忽略 | |||
* | |||
* @param id | |||
* @return | |||
*/ | |||
JsonResult ignore(Integer id); | |||
} |
@@ -3,7 +3,11 @@ package com.tuoheng.admin.service.warning; | |||
import com.tuoheng.admin.entity.domain.Warning; | |||
import com.tuoheng.admin.entity.query.WarningQuery; | |||
import com.tuoheng.admin.entity.request.warning.QueryWarningListRequest; | |||
import com.tuoheng.admin.entity.request.warning.WarningConfirmRequest; | |||
import com.tuoheng.admin.mapper.WarningMapper; | |||
import com.tuoheng.admin.service.warning.confirm.WarningConfirmService; | |||
import com.tuoheng.admin.service.warning.ignore.WarningIgnoreService; | |||
import com.tuoheng.admin.service.warning.query.QueryWarningByIdService; | |||
import com.tuoheng.admin.service.warning.query.QueryWarningListService; | |||
import com.tuoheng.admin.service.warning.query.QueryWarningPageListService; | |||
import com.tuoheng.common.common.BaseServiceImpl; | |||
@@ -26,9 +30,18 @@ public class WarningServiceImpl extends BaseServiceImpl<WarningMapper, Warning> | |||
@Autowired | |||
private QueryWarningListService queryWarningListService; | |||
@Autowired | |||
private QueryWarningByIdService queryWarningByIdService; | |||
@Autowired | |||
private QueryWarningPageListService queryWarningPageListService; | |||
@Autowired | |||
private WarningConfirmService warningConfirmService; | |||
@Autowired | |||
private WarningIgnoreService warningIgnoreService; | |||
/** | |||
* 查询预警列表 | |||
* | |||
@@ -51,14 +64,19 @@ public class WarningServiceImpl extends BaseServiceImpl<WarningMapper, Warning> | |||
return null; | |||
} | |||
/** | |||
* 告警列表查询 分页 | |||
* @param query | |||
* @return | |||
*/ | |||
@Override | |||
public JsonResult index(WarningQuery query) { | |||
return queryWarningPageListService.index(query); | |||
} | |||
@Override | |||
public JsonResult confirm(WarningConfirmRequest request) { | |||
return warningConfirmService.confirm(request); | |||
} | |||
@Override | |||
public JsonResult ignore(Integer id) { | |||
return warningIgnoreService.ignore(id); | |||
} | |||
} |
@@ -36,7 +36,8 @@ public class WarningConfirmService { | |||
public JsonResult confirm(WarningConfirmRequest request) { | |||
log.info("进入预警确认业务, request:{}", request); | |||
User user = ShiroUtils.getUserInfo(); | |||
JsonResult result = this.check(request); | |||
Integer tenantId = user.getTenantId(); | |||
JsonResult result = this.check(tenantId, request); | |||
if (0 != result.getCode()) { | |||
log.info("进入任务问题确认业务:校验失败:{}", result.getMsg()); | |||
return result; | |||
@@ -50,20 +51,25 @@ public class WarningConfirmService { | |||
/** | |||
* 检查参数 | |||
* | |||
* @param tenantId | |||
* @param request | |||
* @return | |||
*/ | |||
private JsonResult check(WarningConfirmRequest request) { | |||
private JsonResult check(Integer tenantId, WarningConfirmRequest request) { | |||
// 判断预警id是否为空 | |||
if (ObjectUtil.isNotNull(request.getId())) { | |||
throw new ServiceException(0, "预警为空"); | |||
throw new ServiceException(0, "预警ID为空"); | |||
} | |||
Warning warning = warningMapper.selectOne(new LambdaQueryWrapper<Warning>() | |||
.in(Warning::getId, request.getId()) | |||
.eq(Warning::getMark, MarkEnum.VALID.getCode())); | |||
.eq(Warning::getId, request.getId()) | |||
.eq(Warning::getTenantId, tenantId) | |||
.eq(Warning::getMark, MarkEnum.VALID.getCode())); | |||
if (ObjectUtil.isNull(warning)) { | |||
throw new ServiceException(0, "预警信息不存在"); | |||
} | |||
if (!tenantId.equals(warning.getTenantId())) { | |||
throw new ServiceException(0, "该租户没有查询该预警信息的权限"); | |||
} | |||
return JsonResult.success(warning); | |||
} | |||
@@ -71,7 +77,7 @@ public class WarningConfirmService { | |||
* 预警状态,改为确认 | |||
* | |||
* @param user | |||
* @param id | |||
* @param request | |||
*/ | |||
private JsonResult updateStatus(User user, WarningConfirmRequest request) { | |||
Map<String, Object> map = new HashMap<>(); |
@@ -35,7 +35,8 @@ public class WarningIgnoreService { | |||
public JsonResult ignore(Integer id) { | |||
log.info("进入预警忽略业务, id:{}", id); | |||
User user = ShiroUtils.getUserInfo(); | |||
JsonResult result = this.check(id); | |||
Integer tenantId = user.getTenantId(); | |||
JsonResult result = this.check(tenantId, id); | |||
if (0 != result.getCode()) { | |||
log.info("进入预警忽略业务:校验失败:{}", result.getMsg()); | |||
return result; | |||
@@ -50,13 +51,14 @@ public class WarningIgnoreService { | |||
/** | |||
* 检查参数 | |||
* | |||
* @param tenantId | |||
* @param id | |||
* @return | |||
*/ | |||
private JsonResult check(Integer id) { | |||
private JsonResult check(Integer tenantId, Integer id) { | |||
// 判断预警id是否为空 | |||
if (ObjectUtil.isNotNull(id)) { | |||
throw new ServiceException(0, "预警为空"); | |||
throw new ServiceException(0, "预警ID为空"); | |||
} | |||
Warning warning = warningMapper.selectOne(new LambdaQueryWrapper<Warning>() | |||
.in(Warning::getId, id) | |||
@@ -64,6 +66,9 @@ public class WarningIgnoreService { | |||
if (ObjectUtil.isNull(warning)) { | |||
throw new ServiceException(0, "预警信息不存在"); | |||
} | |||
if (!tenantId.equals(warning.getTenantId())) { | |||
throw new ServiceException(0, "该租户没有查询该预警信息的权限"); | |||
} | |||
return JsonResult.success(warning); | |||
} | |||
@@ -1,8 +1,20 @@ | |||
package com.tuoheng.admin.service.warning.query; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import cn.hutool.core.util.ObjectUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.admin.conver.WarningConverMapper; | |||
import com.tuoheng.admin.entity.domain.Goods; | |||
import com.tuoheng.admin.entity.domain.Question; | |||
import com.tuoheng.admin.entity.domain.Warning; | |||
import com.tuoheng.admin.entity.request.goods.QueryGoodsListRequest; | |||
import com.tuoheng.admin.entity.request.warning.QueryWarningListRequest; | |||
import com.tuoheng.admin.entity.vo.warning.WarningListVo; | |||
import com.tuoheng.admin.enums.MarkEnum; | |||
import com.tuoheng.admin.mapper.GoodsMapper; | |||
import com.tuoheng.admin.mapper.QuestionMapper; | |||
import com.tuoheng.admin.mapper.WarningMapper; | |||
import com.tuoheng.common.utils.JsonResult; | |||
import com.tuoheng.system.entity.User; | |||
@@ -11,7 +23,10 @@ import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.stream.Collectors; | |||
/** | |||
* 查询预警业务层处理 | |||
@@ -27,6 +42,9 @@ public class QueryWarningListService { | |||
@Autowired | |||
private WarningMapper warningMapper; | |||
@Autowired | |||
private QuestionMapper questionMapper; | |||
public JsonResult getList(QueryWarningListRequest request) { | |||
// log.info("进入查询预警列表业务"); | |||
User user = ShiroUtils.getUserInfo(); | |||
@@ -42,7 +60,11 @@ public class QueryWarningListService { | |||
if (CollectionUtil.isEmpty(warningList)) { | |||
log.info("预警列表数据为空"); | |||
} | |||
return JsonResult.success(warningList); | |||
// 构造返回结果对象 | |||
List<WarningListVo> warningListVoList = this.buildWarningListVo(warningList); | |||
return JsonResult.success(warningListVoList); | |||
} | |||
/** | |||
@@ -57,4 +79,45 @@ public class QueryWarningListService { | |||
return JsonResult.success(); | |||
} | |||
/** | |||
* 1)、完善经纬度坐标字段 | |||
* | |||
* @param warningList | |||
* @return | |||
*/ | |||
private List<WarningListVo> buildWarningListVo(List<Warning> warningList) { | |||
List<WarningListVo> warningListVoList = WarningConverMapper.INSTANCE.fromWarningListToWarningListVoList(warningList); | |||
Map<Integer, Question> questionMap = this.getQuestionMap( warningList); | |||
Question question; | |||
for (WarningListVo warningListVo : warningListVoList) { | |||
question = questionMap.get(warningListVo.getQuestionId()); | |||
if (ObjectUtil.isNotNull(question)) { | |||
warningListVo.setLng(question.getLng()); | |||
warningListVo.setLat(question.getLat()); | |||
} | |||
} | |||
return warningListVoList; | |||
} | |||
/** | |||
* 查询到的任务列表,放到map中 | |||
* | |||
* @param warningList | |||
* @return | |||
*/ | |||
private Map<Integer, Question> getQuestionMap(List<Warning> warningList) { | |||
Map<Integer, Question> map = new HashMap<>(); | |||
List<Integer> questionIdList = warningList.stream().map(o -> o.getQuestionId()).collect(Collectors.toList()); | |||
if (CollectionUtil.isEmpty(questionIdList)) { | |||
log.info("questionIdList为空"); | |||
return null; | |||
} | |||
List<Question> questionList = questionMapper.selectList(new LambdaQueryWrapper<Question>() | |||
.in(Question::getId, questionIdList) | |||
.eq(Question::getMark, MarkEnum.VALID.getCode())); | |||
for (Question question : questionList) { | |||
map.put(question.getId(), question); | |||
} | |||
return map; | |||
} | |||
} |