Commit b1c76b4b authored by taabe's avatar taabe

交接班-接警情况接口

parent 2f01b626
......@@ -2,6 +2,9 @@ package com.yeejoin.amos.boot.module.jcs.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.jcs.api.entity.AlertCalled;
import org.apache.ibatis.annotations.Param;
import java.util.Map;
/**
* 警情接警记录 Mapper 接口
......@@ -11,4 +14,5 @@ import com.yeejoin.amos.boot.module.jcs.api.entity.AlertCalled;
*/
public interface AlertCalledMapper extends BaseMapper<AlertCalled> {
Map<String, Integer> queryAlertStatusCount(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
}
......@@ -23,10 +23,12 @@ public interface AlertFormValueMapper extends BaseMapper<AlertFormValue> {
*
* @param fieldCodes 列
* @param groupCode 分组code
* @param params 查询参数
* @return List<Map>
*/
List<Map<String, Object>> listAll(
@Param("fieldCodes") List<String> fieldCodes,
@Param("groupCode") String groupCode
@Param("groupCode") String groupCode,
@Param("params") Map<String, String> params
);
}
......@@ -2,4 +2,14 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.amos.boot.module.jcs.api.mapper.AlertCalledMapper">
<select id="queryAlertStatusCount" resultType="java.util.Map">
SELECT
count( 1 ) calledCount,
sum( CASE WHEN alert_status = 1 THEN 1 ELSE 0 END ) finishedCount,
sum( CASE WHEN alert_type_code = 230 THEN 1 ELSE 0 END ) majorAlertCount
FROM
jc_alert_called
WHERE
call_time BETWEEN #{beginDate} AND #{endDate}
</select>
</mapper>
......@@ -30,14 +30,26 @@
select
i.alert_called_id instanceId,
i.alert_type_code groupCode,
i.rec_date recDate,
<foreach collection="fieldCodes" item="item" index="key" separator=",">
MAX(CASE WHEN i.FIELD_CODE = #{item} THEN i.FIELD_VALUE END) as ${item}
MAX(CASE WHEN i.FIELD_CODE = #{item} THEN i.FIELD_VALUE ELSE '' END) as ${item}
</foreach>
from
jc_alert_form_value i
where i.alert_type_code = #{groupCode}
GROUP by
i.alert_called_id)d
<if test="params != null and params.size > 0 ">
where 1=1
<foreach collection="params" index="key" item="value">
<if test="key != null and key == 'beginDate'">
and d.recDate >= #{value}
</if>
<if test="key != null and key == 'endDate'">
and d.recDate <![CDATA[<=]]> #{value}
</if>
</foreach>
</if>
order by instanceId
</select>
</mapper>
......@@ -303,8 +303,8 @@ public class AlertCalledController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/dateRange/list")
@ApiOperation(httpMethod = "GET", value = "查询指定日期内警情列表", notes = "查询指定日期内警情列表")
public ResponseModel<List<Map<String, Object>>> listByDateRange(@RequestParam("beginDate") String beginDate,
public ResponseModel<Map<String, Object>> listByDateRange(@RequestParam("beginDate") String beginDate,
@RequestParam("endDate") String endDate) {
return ResponseHelper.buildResponse(iAlertCalledService.listByDateRange(beginDate, endDate));
return ResponseHelper.buildResponse(iAlertCalledService.getAlertInfoList(beginDate, endDate));
}
}
\ No newline at end of file
......@@ -2,24 +2,34 @@ package com.yeejoin.amos.boot.module.jcs.biz.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.jcs.api.dto.AlertCalledDto;
import com.yeejoin.amos.boot.module.jcs.api.dto.AlertCalledObjsDto;
import com.yeejoin.amos.boot.module.jcs.api.entity.AlertCalled;
import com.yeejoin.amos.boot.module.jcs.api.entity.AlertFormValue;
import com.yeejoin.amos.boot.module.jcs.api.entity.Template;
import com.yeejoin.amos.boot.module.jcs.api.enums.AlertStageEnums;
import com.yeejoin.amos.boot.module.jcs.api.enums.DutyInfoEnum;
import com.yeejoin.amos.boot.module.jcs.api.mapper.AlertCalledMapper;
import com.yeejoin.amos.boot.module.jcs.api.mapper.TemplateMapper;
import com.yeejoin.amos.boot.module.jcs.api.service.IAlertCalledService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
......@@ -45,7 +55,11 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
@Autowired
RuleAlertCalledService ruleAlertCalledService;
public static String GROUP_CODE = "229";
@Autowired
TemplateServiceImpl templateService;
@Autowired
TemplateMapper templateMapper;
/**
*
......@@ -56,7 +70,7 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
* @param alertCalledObjsDto
* @return
*/
@Transactional
@Transactional(rollbackFor = RuntimeException.class)
public AlertCalledObjsDto createAlertCalled(AlertCalledObjsDto alertCalledObjsDto) {
try {
// 警情基本信息
......@@ -170,11 +184,77 @@ public class AlertCalledServiceImpl extends BaseService<AlertCalledDto,AlertCall
* @param endDate 结束时间
*/
public List<Map<String, Object>> listByDateRange(String beginDate, String endDate) {
List<AlertCalled> alertCalledDtoList =
// 查询指定日期内的警情列表
List<AlertCalled> alertCalledList =
this.list(new LambdaQueryWrapper<AlertCalled>().between(AlertCalled::getCallTime, beginDate, endDate));
Map<String, String> queryParams = Maps.newHashMap();
queryParams.put("beginDate", beginDate);
queryParams.put("endDate", endDate);
List<Map<String, Object>> allList = Lists.newArrayList();
if (!ValidationUtil.isEmpty(alertCalledList)) {
Map<String, List<AlertCalled>> alertCalledMap =
alertCalledDtoList.stream().collect(Collectors.groupingBy(AlertCalled::getAlertTypeCode));
List<Map<String, Object>> formValueList = iAlertFormValueService.listAll(GROUP_CODE);
return null;
alertCalledList.stream().collect(Collectors.groupingBy(AlertCalled::getAlertTypeCode));
Map<Long, AlertCalled> calledMap =
alertCalledList.stream().collect(Collectors.toMap(AlertCalled::getSequenceNbr, Function.identity()));
alertCalledMap.forEach((alert, list) -> {
allList.addAll(iAlertFormValueService.listAll(alert, queryParams));
});
allList.forEach(i -> {
AlertCalled alertCalled = calledMap.get(Long.parseLong(i.get("instanceId").toString()));
i.putAll(Bean.BeantoMap(alertCalled));
});
}
return allList;
}
public Map<String, Object> getAlertInfoList(String beginDate, String endDate) {
Map<String, Object> result = Maps.newHashMap();
List<Map<String, Object>> list = listByDateRange(beginDate, endDate);
// 获取接警情况模板
List<Template> templateList =
templateMapper.selectList(new LambdaQueryWrapper<Template>().eq(Template::getFormat, false).like(Template::getTypeCode,
DutyInfoEnum.接警情况.getKey() + "-"));
Map<String, Template> templateMap = templateList.stream().collect(Collectors.toMap(Template::getTypeCode,
Function.identity()));
List<String> contentList = Lists.newArrayList();
list.forEach(i -> {
String tempContent =
templateMap.get(DutyInfoEnum.接警情况.getKey() + "-" + i.get("alertTypeCode")).getContent();
contentList.add(replaceTemplate(tempContent, i));
});
Map<String, Integer> statusCountMap = alertCalledMapper.queryAlertStatusCount(beginDate, endDate);
Integer unFinishedCount =
this.count(new LambdaQueryWrapper<AlertCalled>().eq(AlertCalled::getAlertStatus, "0"));
result.put("alertInfoList", contentList);
result.putAll(statusCountMap);
result.put("unFinishedCount", unFinishedCount);
return result;
}
/**
* 替换模板
*
* @param tempContent 模板
* @param objMap 对象map
* @return
*/
private String replaceTemplate(String tempContent, Map<String, Object> objMap) {
int size = objMap.size();
String[] keys = objMap.keySet().toArray(new String[size]);
Object[] values = objMap.values().toArray(new Object[size]);
List<String> strList = Lists.newArrayList();
for (Object obj : values) {
if (!ValidationUtil.isEmpty(obj)) {
if (obj instanceof Date) {
obj = DateUtils.date2LongStr((Date) obj);
}
strList.add(obj.toString());
} else {
strList.add("");
}
}
return StringUtils.replaceEach(tempContent, keys, strList.toArray(new String[strList.size()]));
}
}
......@@ -46,10 +46,10 @@ public class AlertFormValueServiceImpl extends BaseService<AlertFormValueDto,Al
* @param groupCode
* @return List<Map <String, Object>>
*/
public List<Map<String, Object>> listAll(String groupCode) {
public List<Map<String, Object>> listAll(String groupCode, Map<String, String> queryParams) {
List<AlertForm> columns =
alertFormService.list(new LambdaQueryWrapper<AlertForm>().eq(AlertForm::getAlertTypeCode, groupCode));
List<String> fieldCodes = Lists.transform(columns, AlertForm::getFieldCode);
return this.baseMapper.listAll(fieldCodes, groupCode);
return this.baseMapper.listAll(fieldCodes, groupCode, queryParams);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment