Commit de994bbd authored by 李秀明's avatar 李秀明

fix: BUG#21844 业务管理>消防巡查>二级页面,巡查未开展换流站、无漏检记录换流站的数据不正确;巡检记录列表的数据不正确

parent eff9924d
...@@ -346,22 +346,16 @@ public interface PlanTaskMapper extends BaseMapper { ...@@ -346,22 +346,16 @@ public interface PlanTaskMapper extends BaseMapper {
@Param(value="offset") long offset, @Param(value="offset") long offset,
@Param(value="pageSize") long pageSize, @Param(value="pageSize") long pageSize,
@Param(value="bizOrgCode") String bizOrgCode, @Param(value="bizOrgCode") String bizOrgCode,
@Param(value="patrolStatus") String patrolStatus,
@Param(value="missStatus") String missStatus, @Param(value="missStatus") String missStatus,
@Param(value="date") String date, @Param(value="date") String date
@Param(value="sortField") String sortField,
@Param(value="sortOrder") String sortOrder
); );
Long selectPatrolRecordTotal( Long selectPatrolRecordTotal(
@Param(value="bizOrgCode") String bizOrgCode, @Param(value="bizOrgCode") String bizOrgCode,
@Param(value="patrolStatus") String patrolStatus,
@Param(value="missStatus") String missStatus, @Param(value="missStatus") String missStatus,
@Param(value="date") String date, @Param(value="date") String date
@Param(value="sortField") String sortField,
@Param(value="sortOrder") String sortOrder
); );
Map<String, Number> selectPatrolActivityStats( List<Map<String, String>> selectPatrolActivityStats(
@Param(value="bizOrgCode") String bizOrgCode, @Param(value="bizOrgCode") String bizOrgCode,
@Param(value="date") String date @Param(value="date") String date
); );
......
...@@ -2,11 +2,13 @@ package com.yeejoin.amos.patrol.business.feign; ...@@ -2,11 +2,13 @@ package com.yeejoin.amos.patrol.business.feign;
import com.yeejoin.amos.component.feign.model.FeignClientResult; import com.yeejoin.amos.component.feign.model.FeignClientResult;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
...@@ -33,4 +35,7 @@ public interface IdxFeign { ...@@ -33,4 +35,7 @@ public interface IdxFeign {
@PostMapping(value = "/defect/check/listNew") @PostMapping(value = "/defect/check/listNew")
FeignClientResult queryDefectByIdList(@RequestBody List<String> checkIdList); FeignClientResult queryDefectByIdList(@RequestBody List<String> checkIdList);
@GetMapping(value = "/station-info-online/list")
FeignClientResult<List<Map<String, Object>>> queryStationInfoOnlineList(@RequestParam("bizOrgCode") String bizOrgCode);
} }
...@@ -85,6 +85,7 @@ import java.text.SimpleDateFormat; ...@@ -85,6 +85,7 @@ import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -2157,23 +2158,117 @@ public class PlanTaskServiceImpl implements IPlanTaskService { ...@@ -2157,23 +2158,117 @@ public class PlanTaskServiceImpl implements IPlanTaskService {
*/ */
@Override @Override
public Map<String, Number> getPatrolActivityStats(String bizOrgCode, String date) { public Map<String, Number> getPatrolActivityStats(String bizOrgCode, String date) {
return planTaskMapper.selectPatrolActivityStats(bizOrgCode, date); FeignClientResult<List<Map<String, Object>>> response = idxFeign.queryStationInfoOnlineList(bizOrgCode);
if (response.getStatus() != 200) {
throw new RuntimeException("获取idx服务异常");
}
List<Map<String, Object>> stations = response.getResult();
AtomicInteger doneNum = new AtomicInteger(); // 已开展
AtomicInteger missNum = new AtomicInteger(); // 漏检
List<Map<String, String>> queryMaps = planTaskMapper.selectPatrolActivityStats(bizOrgCode, date);
for (Map<String, String> queryMap : queryMaps) {
String missStatus = queryMap.get("missStatus");
if (Objects.equals(missStatus, "有漏检")) {
missNum.incrementAndGet();
}
doneNum.incrementAndGet();
}
return new HashMap<String, Number>() {{
this.put("done", doneNum.intValue());
this.put("undone", stations.size() - doneNum.intValue());
this.put("miss", missNum);
this.put("noMiss", doneNum.intValue() - missNum.intValue());
}};
} }
@Override @Override
public Page<HashMap<String, Object>> getPatrolRecordPage(Integer pageNumber, Integer pageSize, String bizOrgCode, String patrolStatus, String missStatus, String date, String sorter) { public Page<HashMap<String, Object>> getPatrolRecordPage(Integer pageNumber, Integer pageSize, String bizOrgCode, String patrolStatus, String missStatus, String date, String sorter) {
long offset = pageNumber - 1; long offset = (long) (pageNumber - 1) * pageSize;
if (StringUtils.isEmpty(date)) { if (StringUtils.isEmpty(date)) {
date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
} }
String sortField = "", sortOrder = ""; FeignClientResult<List<Map<String, Object>>> response = idxFeign.queryStationInfoOnlineList(bizOrgCode);
if (response.getStatus() != 200) {
throw new RuntimeException("获取idx服务异常");
}
List<Map<String, Object>> stations = response.getResult();
List<HashMap<String, Object>> records = new ArrayList<>(pageSize);
long total = 0;
if (Objects.equals(patrolStatus, "undone")) {
// 未开展 & (有漏检 || 无漏检) 直接返回空
if (Objects.nonNull(missStatus)) {
return new PageImpl<>(records, new CommonPageable(), total);
}
// 未开展
List<HashMap<String, Object>> queryMaps = planTaskMapper.selectPatrolRecordPage(offset, pageSize, bizOrgCode, missStatus, date);
List<String> doneStations = queryMaps.stream().map(record -> record.get("bizOrgCode").toString()).collect(Collectors.toList());
stations = stations.stream().filter(station -> !doneStations.contains(station.get("bizOrgCode").toString())).collect(Collectors.toList());
for (Map<String, Object> station : stations) {
HashMap<String, Object> record = new HashMap<>();
record.put("bizOrgCode", station.get("bizOrgCode"));
record.put("bizOrgName", station.get("bizOrgName"));
record.put("time", date);
record.put("patrolStatus", "未开展");
record.put("allCount", 0);
record.put("missPointCount", 0);
record.put("missPointRate", 0);
record.put("finishRate", 0);
record.put("totalTime", 0);
records.add(record);
total++;
}
} else {
List<HashMap<String, Object>> queryMaps = planTaskMapper.selectPatrolRecordPage(offset, pageSize, bizOrgCode, missStatus, date);
List<String> doneStations = new ArrayList<>(queryMaps.size());
for (HashMap<String, Object> queryMap : queryMaps) {
queryMap.put("patrolStatus", "已开展");
int totalValue = Integer.parseInt(queryMap.getOrDefault("allCount", "0").toString());
int missPointCount = Integer.parseInt(queryMap.getOrDefault("missPointCount", "0").toString());
int finishCount = Integer.parseInt(queryMap.getOrDefault("finishCount", "0").toString());
// 获取漏检率:missPointCount / totalValue
queryMap.put("missPointRate", getPercent((float) missPointCount, (float) totalValue));
// 执行进度:finishCount / totalValue
queryMap.put("finishRate", getPercent((float) finishCount, (float) totalValue));
doneStations.add(queryMap.get("bizOrgCode").toString());
}
records.addAll(queryMaps);
total = queryMaps.size();
if (!Objects.equals(patrolStatus, "done")) {
List<Map<String, Object>> undoneStations = stations.stream().filter(station -> !doneStations.contains(station.get("bizOrgCode").toString())).collect(Collectors.toList());
for (Map<String, Object> station : undoneStations) {
HashMap<String, Object> record = new HashMap<>();
record.put("bizOrgCode", station.get("bizOrgCode"));
record.put("bizOrgName", station.get("bizOrgName"));
record.put("time", date);
record.put("patrolStatus", "未开展");
record.put("allCount", 0);
record.put("missPointCount", 0);
record.put("missPointRate", 0);
record.put("finishRate", 0);
record.put("totalTime", 0);
records.add(record);
total++;
}
}
}
// 排序
if (org.springframework.util.StringUtils.hasText(sorter)) { if (org.springframework.util.StringUtils.hasText(sorter)) {
sortField = sorter.split("@")[0]; String sortField = sorter.split("@")[0];
sortOrder = sorter.split("@")[1]; String sortOrder = sorter.split("@")[1];
if ("ascend".equals(sortOrder)) {
records.sort(Comparator.comparing(o -> o.get(sortField).toString()));
} else {
records.sort(Comparator.comparing(o -> ((Map) o).get(sortField).toString()).reversed());
}
} else {
records.sort(Comparator.comparing(o -> ((Map) o).get("time").toString()).reversed());
} }
List<HashMap<String, Object>> maps = planTaskMapper.selectPatrolRecordPage(offset, pageSize, bizOrgCode, patrolStatus, missStatus, date, sortField, sortOrder); int startIndex = (pageNumber - 1) * pageSize;
Long total = planTaskMapper.selectPatrolRecordTotal(bizOrgCode, patrolStatus, missStatus, date, sortField, sortOrder); int size = Math.min(pageSize, records.size());
return new PageImpl<>(maps, new CommonPageable(), total); int endIndex = Math.min(startIndex + size, records.size());
List<HashMap<String, Object>> finalRecords = records.subList(startIndex, endIndex);
return new PageImpl<>(finalRecords, new CommonPageable(), total);
} }
@Override @Override
......
...@@ -1475,7 +1475,7 @@ ...@@ -1475,7 +1475,7 @@
UNION ALL UNION ALL
SELECT SELECT
count(1) AS value, IFNULL(SUM(point_num), 0) AS value,
'合格' AS name, '合格' AS name,
'HG' AS code 'HG' AS code
FROM FROM
...@@ -1491,7 +1491,7 @@ ...@@ -1491,7 +1491,7 @@
UNION ALL UNION ALL
SELECT SELECT
count(1) AS value, IFNULL(SUM(point_num), 0) AS value,
'不合格' AS name, '不合格' AS name,
'BHG' AS code 'BHG' AS code
FROM FROM
...@@ -1781,58 +1781,31 @@ ...@@ -1781,58 +1781,31 @@
FROM ( FROM (
SELECT SELECT
LEFT(t.org_code, 18) AS bizOrgCode, LEFT(t.org_code, 18) AS bizOrgCode,
u.biz_org_name bizOrgName, u.biz_org_name AS bizOrgName,
DATE_FORMAT( t.check_date, '%Y-%m-%d' ) AS time, DATE_FORMAT( t.check_date, '%Y-%m-%d' ) AS time,
IF(SUM(IF(t.finish_status = 2 , 1, 0)) > 0, '已开展', '未开展') AS patrolStatus,
IFNULL(SUM( t.point_num ), 0) AS allCount, IFNULL(SUM( t.point_num ), 0) AS allCount,
IFNULL(SUM(IF(t.finish_status = 3, t.point_num, 0)), 0) AS missPointCount, IFNULL(SUM(IF(t.finish_status = 3, t.point_num, 0)), 0) AS missPointCount,
IFNULL(SUM(IF(t.finish_status = 2, t.point_num, 0)), 0) AS finishCount, IFNULL(SUM(IF(t.finish_status = 2, t.point_num, 0)), 0) AS finishCount,
-- 漏查率 missPointCount / allCount IFNULL((SELECT SUM(TIMESTAMPDIFF(MINUTE, t.begin_time, d.executor_date)) FROM p_plan_task_detail d where d.task_no = t.id and t.org_code LIKE LEFT(t.org_code, 18)), 0) AS totalTime
CONCAT(ROUND(IFNULL(SUM(IF(t.finish_status = 3, t.point_num, 0)), 0) / IFNULL(SUM( t.point_num ), 0), 2), '%') AS missPointRate, FROM
-- 执行进度 finishCount / allCount p_plan_task t
CONCAT(ROUND(IFNULL(SUM(IF(t.finish_status = 2, t.point_num, 0)), 0) / IFNULL(SUM( t.point_num ), 0), 2), '%') AS finishRate,
-- 总耗时
SUM(TIMESTAMPDIFF(MINUTE, t.begin_time, d.executor_date)) AS totalTime
FROM p_plan_task t
LEFT JOIN p_plan_task_detail d on t.id = d.task_no
LEFT JOIN cb_org_usr u on u.biz_org_code = left(t.org_code, 18) LEFT JOIN cb_org_usr u on u.biz_org_code = left(t.org_code, 18)
WHERE WHERE
DATE_FORMAT( t.check_date, '%Y-%m-%d' ) = #{date} DATE_FORMAT( t.check_date, '%Y-%m-%d' ) = #{date}
<if test="bizOrgCode != null and bizOrgCode != ''"> <if test="bizOrgCode != null and bizOrgCode != ''">
AND u.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%') AND t.org_code LIKE CONCAT(#{bizOrgCode}, '%')
</if> </if>
GROUP BY GROUP BY
LEFT(t.org_code, 18) LEFT(t.org_code, 18)
) t ) t
<where> <where>
<if test="patrolStatus == 'done'"> <if test="missStatus == 'miss'">
AND patrolStatus = '已开展'
</if>
<if test="patrolStatus == 'undone'">
AND patrolStatus = '未开展'
</if>
<if test="missStatus == 'true'">
AND missPointCount > 0 AND missPointCount > 0
</if> </if>
<if test="missStatus == 'false'"> <if test="missStatus == 'noMiss'">
AND missPointCount = 0 AND missPointCount = 0
</if> </if>
</where> </where>
ORDER BY
<if test="sortField != null and sortField != ''">
<choose>
<when test="sortOrder == 'ascend'">
${sortField} ASC
</when>
<otherwise>
${sortField} DESC
</otherwise>
</choose>
</if>
<if test="sortField == null or sortField == ''">
time DESC
</if>
LIMIT #{offset}, #{pageSize}
</select> </select>
<select id="selectPatrolRecordTotal" resultType="long"> <select id="selectPatrolRecordTotal" resultType="long">
...@@ -1840,37 +1813,19 @@ ...@@ -1840,37 +1813,19 @@
COUNT(t.bizOrgCode) COUNT(t.bizOrgCode)
FROM ( FROM (
SELECT SELECT
LEFT(t.org_code, 18) AS bizOrgCode, LEFT(t.org_code, 18) AS bizOrgCode
u.biz_org_name bizOrgName, FROM
DATE_FORMAT( t.check_date, '%Y-%m-%d' ) AS time, p_plan_task t
IF(SUM(IF(t.finish_status = 2 , 1, 0)) > 0, '已开展', '未开展') AS patrolStatus,
IFNULL(SUM( t.point_num ), 0) AS allCount,
IFNULL(SUM(IF(t.finish_status = 3, t.point_num, 0)), 0) AS missPointCount,
IFNULL(SUM(IF(t.finish_status = 2, t.point_num, 0)), 0) AS finishCount,
-- 漏查率 missPointCount / allCount
CONCAT(ROUND(IFNULL(SUM(IF(t.finish_status = 3, t.point_num, 0)), 0) / IFNULL(SUM( t.point_num ), 0), 2), '%') AS missPointRate,
-- 执行进度 finishCount / allCount
CONCAT(ROUND(IFNULL(SUM(IF(t.finish_status = 2, t.point_num, 0)), 0) / IFNULL(SUM( t.point_num ), 0), 2), '%') AS finishRate,
-- 总耗时
SUM(TIMESTAMPDIFF(MINUTE, t.begin_time, d.executor_date)) AS totalTime
FROM p_plan_task t
LEFT JOIN p_plan_task_detail d on t.id = d.task_no
LEFT JOIN cb_org_usr u on u.biz_org_code = left(t.org_code, 18) LEFT JOIN cb_org_usr u on u.biz_org_code = left(t.org_code, 18)
WHERE WHERE
DATE_FORMAT( t.check_date, '%Y-%m-%d' ) = #{date} DATE_FORMAT( t.check_date, '%Y-%m-%d' ) = #{date}
<if test="bizOrgCode != null and bizOrgCode != ''"> <if test="bizOrgCode != null and bizOrgCode != ''">
AND u.biz_org_code LIKE CONCAT(#{bizOrgCode}, '%') AND t.org_code LIKE CONCAT(#{bizOrgCode}, '%')
</if> </if>
GROUP BY GROUP BY
LEFT(t.org_code, 18) LEFT(t.org_code, 18)
) t ) t
<where> <where>
<if test="patrolStatus == 'done'">
AND patrolStatus = '已开展'
</if>
<if test="patrolStatus == 'undone'">
AND patrolStatus = '未开展'
</if>
<if test="missStatus == 'true'"> <if test="missStatus == 'true'">
AND missPointCount > 0 AND missPointCount > 0
</if> </if>
...@@ -1882,16 +1837,10 @@ ...@@ -1882,16 +1837,10 @@
<select id="selectPatrolActivityStats" resultType="Map"> <select id="selectPatrolActivityStats" resultType="Map">
SELECT SELECT
IFNULL(SUM(IF(patrolStatus = '已开展', 1, 0)), 0) AS done, LEFT(t.org_code, 18) AS bizOrgCode,
IFNULL(SUM(IF(patrolStatus = '未开展', 1, 0)), 0) AS undone, IF(SUM(IF(t.finish_status = 3, t.point_num, 0)) > 0, '有漏检', '无漏检') AS missStatus
IFNULL(SUM(IF(missStatus = '无漏检', 1, 0)), 0) AS noMiss, FROM
IFNULL(SUM(IF(missStatus = '有漏检', 1, 0)), 0) AS miss p_plan_task t
FROM (
SELECT
IF(SUM(IF(t.finish_status = 2 , 1, 0)) > 0, '已开展', '未开展') AS patrolStatus,
IF(SUM(IF(t.finish_status = 3, t.point_num, 0)) > 0, '有漏检', '无漏检') AS missStatus
FROM
p_plan_task t
<where> <where>
<if test="date != null and date != ''"> <if test="date != null and date != ''">
AND DATE_FORMAT( t.check_date, '%Y-%m-%d' ) = #{date} AND DATE_FORMAT( t.check_date, '%Y-%m-%d' ) = #{date}
...@@ -1900,8 +1849,7 @@ ...@@ -1900,8 +1849,7 @@
AND t.org_code LIKE CONCAT(#{bizOrgCode}, '%') AND t.org_code LIKE CONCAT(#{bizOrgCode}, '%')
</if> </if>
</where> </where>
GROUP BY GROUP BY
LEFT(t.org_code, 18) LEFT(t.org_code, 18)
) t
</select> </select>
</mapper> </mapper>
\ No newline at end of file
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