更新统计相关内容

This commit is contained in:
xuyuncong 2025-11-04 15:17:20 +08:00
parent b938f36e9d
commit 3dbb29ea39
9 changed files with 228 additions and 4 deletions

View File

@ -328,4 +328,17 @@ public class RepairStatisticsController {
return CommonResult.success(statisticsService.workTypeStatistics(reqVO));
}
/**
* 根据班组工种类型统计班组下员工的工作量
*
* @param workType 工种类型
* @param reqVO 查询条件
* @return 员工工作量统计列表
*/
@GetMapping("/workerStatisticsByWorkType")
@Operation(summary = "根据班组统计班组下员工的工作量")
public CommonResult<?> workerStatisticsByWorkType(@RequestParam String workType, QueryBusinessReqVO reqVO) {
return CommonResult.success(statisticsService.workerStatisticsByWorkType(workType, reqVO));
}
}

View File

@ -275,4 +275,15 @@ public interface RepairStatisticsMapper {
List<Map<String, Object>> selectSumAmountByWorkType(@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("workType") String workType);
/**
* 根据员工ID列表查询员工工作量统计
* @param userIds 员工ID列表
* @param startDate 开始日期
* @param endDate 结束日期
* @return 员工工作量统计数据列表
*/
List<Map<String, Object>> selectWorkerStatisticsByUserIds(@Param("userIds") List<Long> userIds,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
}

View File

@ -52,4 +52,11 @@ public interface RepairWorkerMapper extends BaseMapper<RepairWorker> {
* @return cn.iocoder.yudao.module.base.vo.RepairWorkerRespVO
**/
List<RepairWorkerRespVO> listAllWorker();
}
/**
* 根据工种类型查询维修工信息
* @param workType 工种类型
* @return 维修工列表
*/
List<RepairWorkerRespVO> listByWorkType(String workType);
}

View File

@ -217,4 +217,12 @@ public interface RepairStatisticsService {
* @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
**/
List<Map<String, Object>> workTypeStatistics(QueryBusinessReqVO reqVO);
/**
* 根据班组工种类型统计班组下员工的工作量
* @param workType 工种类型
* @param reqVO 查询条件
* @return 员工工作量统计列表
*/
List<Map<String, Object>> workerStatisticsByWorkType(String workType, QueryBusinessReqVO reqVO);
}

View File

@ -121,4 +121,11 @@ public interface RepairWorkerService extends IService<RepairWorker> {
* @return boolean
**/
boolean getIfLeader();
/**
* 根据工种类型查询维修工信息
* @param workType 工种类型
* @return 维修工列表
*/
List<RepairWorkerRespVO> listByWorkType(String workType);
}

View File

@ -1,10 +1,14 @@
package cn.iocoder.yudao.module.base.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.common.RecordTypeEnum;
import cn.iocoder.yudao.common.TicketsStatusEnum;
import cn.iocoder.yudao.module.base.entity.RepairRecords;
import cn.iocoder.yudao.module.base.entity.StaffStatisticsResp;
import cn.iocoder.yudao.module.base.mapper.RepairStatisticsMapper;
import cn.iocoder.yudao.module.base.service.RepairRecordsService;
import cn.iocoder.yudao.module.base.service.RepairStatisticsService;
import cn.iocoder.yudao.module.base.service.RepairWorkerService;
import cn.iocoder.yudao.module.base.vo.*;
import cn.iocoder.yudao.module.business.entity.DlBusinessChannel;
import cn.iocoder.yudao.module.business.service.BusinessChannelService;
@ -59,6 +63,12 @@ public class RepairStatisticsServiceImpl implements RepairStatisticsService {
@Resource
private DictDataApi dictDataApi;
@Resource
private RepairRecordsService repairRecordsService;
@Resource
private RepairWorkerService workerService;
/**
* 将统计结果列表转换为Map格式
* @param list 统计结果列表每个元素包含key和value字段
@ -495,8 +505,8 @@ public class RepairStatisticsServiceImpl implements RepairStatisticsService {
String startDate = null;
String endDate = null;
if (dateRange != null && dateRange.size() >= 2 && dateRange.get(0) != null && dateRange.get(1) != null) {
startDate = dateRange.get(0);
endDate = dateRange.get(1);
startDate = dateRange.get(0) + " 00:00:00";
endDate = dateRange.get(1) + " 23:59:59";
}
/* 查询维修工类型的班组数据*/
@ -540,7 +550,22 @@ public class RepairStatisticsServiceImpl implements RepairStatisticsService {
}});
/*总检 合格了多少 返工了多少*/
//查询记录表 nfpg的数量
long nfpgCount = repairRecordsService.count(Wrappers.<RepairRecords>lambdaQuery()
.eq(RepairRecords::getType, RecordTypeEnum.NFPG.getCode())
.between(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate), RepairRecords::getCreateTime, startDate, endDate));
//查询记录表 zj的数量
long zjCount = repairRecordsService.count(Wrappers.<RepairRecords>lambdaQuery()
.eq(RepairRecords::getType, RecordTypeEnum.ZJ.getCode())
.between(StringUtils.isNotBlank(startDate) && StringUtils.isNotBlank(endDate), RepairRecords::getCreateTime, startDate, endDate));
resp.add(new HashMap<String, Object>() {{
put("name", "总检");
put("id", "zj");
put("count", nfpgCount);
put("count2", zjCount);
}});
return resp;
}
@ -653,4 +678,90 @@ public class RepairStatisticsServiceImpl implements RepairStatisticsService {
return node;
}
@Override
public List<Map<String, Object>> workerStatisticsByWorkType(String workType, QueryBusinessReqVO reqVO) {
// 检查日期范围是否有效
List<String> dateRange = reqVO.getDateRange();
String startDate = null;
String endDate = null;
if (dateRange != null && dateRange.size() >= 2 && dateRange.get(0) != null && dateRange.get(1) != null) {
startDate = dateRange.get(0) + " 00:00:00";
endDate = dateRange.get(1) + " 23:59:59";
}
List<Map<String, Object>> resp = new ArrayList<>();
// 根据workType查询该工种下的所有员工
List<RepairWorkerRespVO> workers = workerService.listByWorkType(workType);
// 如果没有员工直接返回空列表
if (workers == null || workers.isEmpty()) {
return resp;
}
// 对每个员工进行统计
for (RepairWorkerRespVO worker : workers) {
Long userId = worker.getUserId();
if (userId == null) {
continue;
}
List<Long> userIds = Collections.singletonList(userId);
try {
// 查询员工的统计数据
List<Map<String, Object>> workerStats = statisticsMapper.selectWorkerStatisticsByUserIds(userIds, startDate, endDate);
if (workerStats != null && !workerStats.isEmpty()) {
Map<String, Object> workerStat = workerStats.get(0);
Map<String, Object> respMap = new HashMap<>();
respMap.put("name", worker.getUserName());
respMap.put("id", userId);
// 构造与workTypeStatistics相同格式的数据
Map<String, Object> dataMap = new HashMap<>();
List<Map<String, Object>> statsList = new ArrayList<>();
// 添加进厂数统计
Map<String, Object> newOrderNode = new HashMap<>();
newOrderNode.put("code", "newOrderNum");
newOrderNode.put("name", "订单(进厂数)");
newOrderNode.put("selectType", "jinchang");
newOrderNode.put("total", workerStat.get("ticketCount"));
statsList.add(newOrderNode);
// 添加维修中统计
Map<String, Object> workingNode = new HashMap<>();
workingNode.put("code", "workingNum");
workingNode.put("name", "维修中");
workingNode.put("selectType", "weixiuzhong");
workingNode.put("total", workerStat.get("workingCount"));
statsList.add(workingNode);
// 添加已竣工统计
Map<String, Object> completedNode = new HashMap<>();
completedNode.put("code", "overNum");
completedNode.put("name", "已竣工");
completedNode.put("selectType", "yijungong");
completedNode.put("total", workerStat.get("completedCount"));
statsList.add(completedNode);
dataMap.put("stats", statsList);
respMap.put("data", dataMap);
resp.add(respMap);
}
} catch (Exception e) {
// 记录异常但不中断整个流程
log.warn("获取员工统计信息时发生异常员工ID: {}", userId, e);
// 添加一个默认的统计对象避免前端出现空值
Map<String, Object> defaultStats = new HashMap<>();
defaultStats.put("name", worker.getUserName());
defaultStats.put("id", userId);
resp.add(defaultStats);
}
}
return resp;
}
}

View File

@ -312,4 +312,9 @@ public class RepairWorkerServiceImpl extends ServiceImpl<RepairWorkerMapper, Rep
List<RepairWorker> list = this.list(queryWrapper);
return !list.isEmpty() && "1".equals(list.get(0).getIsLeads());
}
@Override
public List<RepairWorkerRespVO> listByWorkType(String workType) {
return workerMapper.listByWorkType(workType);
}
}

View File

@ -637,4 +637,54 @@
AND drt.create_time BETWEEN CONCAT(#{startDate}, ' 00:00:00') AND CONCAT(#{endDate}, ' 23:59:59')
</if>
</select>
<!-- 根据工种类型查询该工种下的所有员工及其工单统计 -->
<select id="selectWorkersByWorkType" resultType="java.util.Map">
SELECT
drw.user_id AS userId,
drw.user_name AS userName,
drw.work_type AS workType,
COUNT(DISTINCT drt.id) AS ticketCount,
SUM(COALESCE(drt.total_price, 0)) AS totalAmount,
COUNT(CASE WHEN drt.tickets_status = '05' THEN 1 END) AS workingCount,
COUNT(CASE WHEN drt.tickets_status = '03' THEN 1 END) AS completedCount
FROM dl_repair_worker drw
LEFT JOIN dl_repair_titem dri ON FIND_IN_SET(drw.user_id, dri.repair_ids) > 0
LEFT JOIN dl_repair_tickets drt ON dri.ticket_id = drt.id
WHERE drw.deleted = 0
AND drw.work_type = #{workType}
AND dri.deleted = 0
AND drt.deleted = 0
<if test="startDate != null and endDate != null">
AND drt.create_time BETWEEN CONCAT(#{startDate}, ' 00:00:00') AND CONCAT(#{endDate}, ' 23:59:59')
</if>
GROUP BY drw.user_id, drw.user_name, drw.work_type
ORDER BY ticketCount DESC
</select>
<!-- 根据员工ID列表查询员工工作量统计 -->
<select id="selectWorkerStatisticsByUserIds" resultType="java.util.Map">
SELECT
drw.user_id AS userId,
drw.user_name AS userName,
COUNT(DISTINCT drt.id) AS ticketCount,
SUM(COALESCE(drt.total_price, 0)) AS totalAmount,
COUNT(CASE WHEN drt.tickets_status = '05' THEN 1 END) AS workingCount,
COUNT(CASE WHEN drt.tickets_status = '03' THEN 1 END) AS completedCount
FROM dl_repair_worker drw
LEFT JOIN dl_repair_titem dri ON FIND_IN_SET(drw.user_id, dri.repair_ids) > 0
LEFT JOIN dl_repair_tickets drt ON dri.ticket_id = drt.id
WHERE drw.deleted = 0
AND drw.user_id IN
<foreach item="item" index="index" collection="userIds" open="(" separator="," close=")">
#{item}
</foreach>
AND dri.deleted = 0
AND drt.deleted = 0
<if test="startDate != null and endDate != null">
AND drt.create_time BETWEEN CONCAT(#{startDate}, ' 00:00:00') AND CONCAT(#{endDate}, ' 23:59:59')
</if>
GROUP BY drw.user_id, drw.user_name
ORDER BY ticketCount DESC
</select>
</mapper>

View File

@ -58,6 +58,18 @@
WHERE
main.deleted = 0
</select>
<select id="listByWorkType" resultType="cn.iocoder.yudao.module.base.vo.RepairWorkerRespVO">
SELECT
main.*,
sdd.label AS workerTypeStr
FROM
dl_repair_worker main
LEFT JOIN system_dict_data sdd ON sdd.dict_type = 'repair_work_type' AND main.work_type = sdd.`value`
WHERE
main.deleted = 0
AND main.work_type = #{workType}
</select>
</mapper>
</mapper>