This commit is contained in:
sunhaoyuan 2025-11-04 14:45:29 +08:00
parent e05da6f0a6
commit 9255543120
6 changed files with 157 additions and 65 deletions

View File

@ -83,7 +83,6 @@ public class RescueBusinessStatisticsController extends BaseController {
/**
* 救援类型
* 实际上是故障类型展示道路救援事故救援
* 数据字典
*/
@GetMapping("/rescueType")
public CommonResult<RescueBusinessStatisticsVO> rescueType(@RequestParam String timeType,

View File

@ -459,6 +459,9 @@ public class RescueInfo extends TenantBaseDO
/** 二级调度名字集合 */
@TableField(exist = false)
private Set<String> secondDispatcherNames;
/** 移交事由 */
@TableField(exist = false)
private String transferReason;
/**
* 调度等级
*/

View File

@ -145,6 +145,7 @@ public class RescueBusinessStatisticsServiceImpl implements RescueBusinessStatis
i.setName("未知");
} else {
i.setName(dict.getOrDefault(code, code)); // 找不到字典就保留原值
i.setValue(code);
}
});
@ -189,32 +190,38 @@ public class RescueBusinessStatisticsServiceImpl implements RescueBusinessStatis
// 1. 取原始分组结果可能出现 null''、'0'、'1' 四种
List<RescueBusinessStatisticsVO.Item> raw = mapper.groupNewEnergy(s, e, driverName, secondDispatchName, driverCarNum);
// 2. code 中文并把相同中文归并求和
Map<String, Long> merged = new HashMap<>(4);
// 2. code -> Item同时做数量汇总
Map<String, RescueBusinessStatisticsVO.Item> merged = new HashMap<>(4);
for (RescueBusinessStatisticsVO.Item it : raw) {
String code = it.getName(); // '1' / '0' / null / ''
long cnt = it.getCount() == null ? 0 : it.getCount();
long count = it.getCount() == null ? 0 : it.getCount();
String key;
// 2-1. 计算中文标签
String label;
if ("1".equals(code)) {
key = "";
label = "";
} else if ("0".equals(code)) {
key = "";
label = "";
} else { // null空串其它
key = "未知";
}
merged.merge(key, cnt, Long::sum); // 汇总
label = "未知";
code = ""; // 给未知一个空串防止 NPE
}
// 3. 转回 List<Item>按数量倒序可选
return merged.entrySet().stream()
.sorted((a, b) -> Long.compare(b.getValue(), a.getValue()))
.map(e1 -> {
RescueBusinessStatisticsVO.Item i = new RescueBusinessStatisticsVO.Item();
i.setName(e1.getKey());
i.setCount(e1.getValue());
return i;
})
// 2-2. 汇总到同一个 Item
RescueBusinessStatisticsVO.Item agg =
merged.computeIfAbsent(code, k -> {
RescueBusinessStatisticsVO.Item tmp = new RescueBusinessStatisticsVO.Item();
tmp.setName(label); // 中文展示
tmp.setValue(k); // 前端真正要用的字典值
tmp.setCount(0L);
return tmp;
});
agg.setCount(agg.getCount() + count);
}
// 3. List<Item>按数量倒序可微调
return merged.values().stream()
.sorted((a, b) -> Long.compare(b.getCount(), a.getCount()))
.collect(Collectors.toList());
}
@ -235,17 +242,28 @@ public class RescueBusinessStatisticsServiceImpl implements RescueBusinessStatis
// 3. 批量翻译字典dict_type = dljy_type
Map<String, String> dict = dictDataService.getDictDataLabels("dljy_type", codes);
// 4. 置中文兜底空值
items.forEach(i -> {
String code = i.getName();
if (StringUtils.isBlank(code)) {
i.setName("未知");
} else {
i.setName(dict.getOrDefault(code, code));
}
});
// 4. 逐条转换
return items.stream()
.map(it -> {
String code = it.getName(); // 原始 code
String label; // 中文标签
return items;
if (StringUtils.isBlank(code)) {
label = "未知";
code = ""; // 避免 null
} else {
// 若字典缺失则直接显示原 code
label = dict.getOrDefault(code, code);
}
RescueBusinessStatisticsVO.Item vo = new RescueBusinessStatisticsVO.Item();
vo.setName(label); // 展示
vo.setValue(code); // 查询用
vo.setCount(it.getCount() == null ? 0 : it.getCount());
return vo;
})
.sorted((a, b) -> Long.compare(b.getCount(), a.getCount())) // 可选数量倒序
.collect(Collectors.toList());
}
@Override
@ -256,53 +274,84 @@ public class RescueBusinessStatisticsServiceImpl implements RescueBusinessStatis
return raw;
}
// 2. 批量翻译
// 2. 一次性取出所有 code 中文
List<String> codes = raw.stream()
.map(RescueBusinessStatisticsVO.Item::getName)
.collect(Collectors.toList());
Map<String, String> dict = dictDataService.getDictDataLabels("fee_type", codes);
// 3. 合并相同中文对未配置的 code -> 未知
Map<String, Long> merged = new HashMap<>();
for (RescueBusinessStatisticsVO.Item it : raw) {
String code = it.getName();
Long count = it.getCount() == null ? 0 : it.getCount();
// 3. 逐条转换缺失的 code 显示未知
return raw.stream()
.map(it -> {
String code = it.getName(); // 原始 code
String label = dict.getOrDefault(code, "未知"); // 中文
String label = dict.get(code); // 可能为 null
String key = StringUtils.isBlank(label) ? "未知" : label;
merged.merge(key, count, Long::sum);
}
// 4. 转回 List<Item>数量倒序可选
return merged.entrySet().stream()
.sorted((a, b) -> Long.compare(b.getValue(), a.getValue()))
.map(e1 -> {
RescueBusinessStatisticsVO.Item item = new RescueBusinessStatisticsVO.Item();
item.setName(e1.getKey());
item.setCount(e1.getValue());
return item;
RescueBusinessStatisticsVO.Item vo = new RescueBusinessStatisticsVO.Item();
vo.setName(label); // 展示
vo.setValue(code); // 前端查询用
vo.setCount(it.getCount() == null ? 0 : it.getCount());
return vo;
})
.sorted((a, b) -> Long.compare(b.getCount(), a.getCount())) // 按量倒序可选
.collect(Collectors.toList());
// 3. 合并相同中文对未配置的 code -> 未知
// Map<String, Long> merged = new HashMap<>();
// for (RescueBusinessStatisticsVO.Item it : raw) {
// String code = it.getName();
// Long count = it.getCount() == null ? 0 : it.getCount();
//
// String label = dict.get(code); // 可能为 null
// String key = StringUtils.isBlank(label) ? "未知" : label;
//
// merged.merge(key, count, Long::sum);
// }
//
// // 4. 转回 List<Item>数量倒序可选
// return merged.entrySet().stream()
// .sorted((a, b) -> Long.compare(b.getValue(), a.getValue()))
// .map(e1 -> {
// RescueBusinessStatisticsVO.Item item = new RescueBusinessStatisticsVO.Item();
// item.setName(e1.getKey());
// item.setCount(e1.getValue());
// return item;
// })
// .collect(Collectors.toList());
}
@Override
public List<RescueBusinessStatisticsVO.Item> listKouChe(String s, String e, String driverName,String secondDispatchName,String driverCarNum) {
List<RescueBusinessStatisticsVO.Item> items = mapper.groupKouChe(s, e, driverName, secondDispatchName, driverCarNum);
items.forEach(i -> {
String code = i.getName();
if ("1".equals(code)) {
i.setName(""); // 已扣车
} else if ("0".equals(code)) {
i.setName(""); // 未扣车
} else {
i.setName("未知"); // 兜底
}
});
if (items.isEmpty()) {
return items;
}
// 2. 逐条翻译 & 填充 value
return items.stream()
.map(it -> {
String code = it.getName(); // 原始 code1 / 0 / null / ""
String label; // 中文标签
if ("1".equals(code)) {
label = "";
} else if ("0".equals(code)) {
label = "";
} else {
label = "未知";
code = ""; // 给未知一个空串防止 NPE
}
RescueBusinessStatisticsVO.Item vo = new RescueBusinessStatisticsVO.Item();
vo.setName(label); // 展示
vo.setValue(code); // 查询用
vo.setCount(it.getCount() == null ? 0 : it.getCount());
return vo;
})
.sorted((a, b) -> Long.compare(b.getCount(), a.getCount())) // 可选按数量倒序
.collect(Collectors.toList());
}
@Override
public List<RescueBusinessStatisticsVO.WaitPickUp> listWaitPickUp(String s, String e, String driverName,String secondDispatchName,String driverCarNum) {
return mapper.listWaitPickUp(s, e, driverName, secondDispatchName, driverCarNum);

View File

@ -12,6 +12,7 @@ public class RescueBusinessStatisticsVO {
public static class Item {
private String name;
private Long count;
private String value; //字典值
}
/* 10 个统计维度 */

View File

@ -104,6 +104,46 @@
<if test="map.secondDispatchName!=null and map.secondDispatchName!='' ">
AND ri.second_dispatch_name = #{map.secondDispatchName}
</if>
<if test="map.faultType!=null and map.faultType!='' ">
AND ri.fault_type = #{map.faultType}
</if>
<if test="map.rescuePosition!=null and map.rescuePosition!='' ">
AND ri.rescue_position like concat('%', #{map.rescuePosition}, '%')
</if>
<if test="map.carBrand!=null and map.carBrand!='' ">
AND ri.car_brand = #{map.carBrand}
</if>
<if test="map.carType!=null and map.carType!='' ">
AND ri.car_type = #{map.carType}
</if>
<if test="map.estimateDownCar!=null and map.estimateDownCar!='' ">
AND ri.estimate_down_car = #{map.estimateDownCar}
</if>
<if test="map.ifNewEnergy!=null and map.ifNewEnergy!='' ">
AND ri.if_new_energy = #{map.ifNewEnergy}
</if>
<if test="map.rescueType!=null and map.rescueType!='' ">
AND ri.rescue_type = #{map.rescueType}
</if>
<if test="map.feeType!=null and map.feeType!='' ">
AND ri.fee_type = #{map.feeType}
</if>
<if test="map.isKouChe!=null and map.isKouChe!='' ">
AND ri.is_kou_che = #{map.isKouChe}
</if>
<if test="map.transferReason != null and map.transferReason != '' ">
AND EXISTS (
SELECT 1
FROM rescue_info_detail rd
WHERE rd.rescue_info_id = ri.id AND rd.deleted = '0'
AND rd.title = '车辆移交'
AND rd.auto_remark LIKE '%移交事由:%'
AND TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(
rd.auto_remark, '移交事由:', -1), ',', 1))
= #{map.transferReason}
)
</if>
</where>
order by ri.create_time desc
</select>

View File

@ -46,9 +46,9 @@ spring:
primary: master
datasource:
master:
url: jdbc:mysql://122.51.230.86:3306/lanan_platform_dev?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://122.51.230.86:3306/lanan_platform_dev?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://localhost:3306/lanan_new?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://122.51.230.86:3306/lanan_platform?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
url: jdbc:mysql://122.51.230.86:3306/lanan_platform?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
@ -56,12 +56,12 @@ spring:
# url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例
# url: jdbc:kingbase8://127.0.0.1:54321/test # 人大金仓 KingbaseES 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/postgres # OpenGauss 连接的示例
username: lanan_dev
password: lighting@2024
# username: lanan_dev
# password: lighting@2024
# username: root
# password: 12345678
# username: lanan
# password: 123456
username: lanan
password: 123456
# username: sa # SQL Server 连接的示例
# password: Yudao@2024 # SQL Server 连接的示例
# username: SYSDBA # DM 连接的示例