吉安感知网项目-后端
linwei
5 days ago 8edf0004e4bd8b758b0fc5940a8a83f0f7948f74
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.sxkj.gd.workorder.service.impl;
 
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.utils.AuthUtil;
import org.sxkj.gd.workorder.entity.GdClueEventStatusFlowEntity;
import org.sxkj.gd.workorder.enums.EventStatusEnum;
import org.sxkj.gd.workorder.mapper.GdClueEventStatusFlowMapper;
import org.sxkj.gd.workorder.service.IGdClueEventStatusFlowService;
import org.sxkj.gd.workorder.vo.GdClueEventStatusFlowVO;
import org.springframework.stereotype.Service;
import org.springblade.core.mp.base.BaseServiceImpl;
 
import java.util.Date;
import java.util.List;
 
/**
 * 事件状态流转履历表 服务实现类
 *
 * @author system
 * @since 2026-07-29
 */
@Slf4j
@Service
@AllArgsConstructor
public class GdClueEventStatusFlowServiceImpl extends BaseServiceImpl<GdClueEventStatusFlowMapper, GdClueEventStatusFlowEntity> implements IGdClueEventStatusFlowService {
 
    /**
     * 根据事件ID查询状态流转记录列表
     * <p>
     * 步骤:
     * 1. 参数校验
     * 2. 查询状态流转记录列表
     * 3. 补充状态名称
     * </p>
     *
     * @param eventId 事件ID
     * @return 状态流转记录列表
     */
    @Override
    public List<GdClueEventStatusFlowVO> getStatusFlowsByEventId(Long eventId) {
        // 1. 参数校验
        if (eventId == null) {
            throw new RuntimeException("事件ID不能为空");
        }
 
        // 2. 查询状态流转记录列表
        List<GdClueEventStatusFlowVO> flows = baseMapper.selectStatusFlowsByEventId(eventId);
 
        // 3. 补充状态名称
        if (flows != null && !flows.isEmpty()) {
            flows.forEach(flow -> {
                // 补充变更前状态名称
                if (flow.getOldStatus() != null) {
                    flow.setOldStatusName(EventStatusEnum.getNameByCode(flow.getOldStatus()));
                }
                // 补充变更后状态名称
                if (flow.getNewStatus() != null) {
                    flow.setNewStatusName(EventStatusEnum.getNameByCode(flow.getNewStatus()));
                }
            });
        }
 
        return flows;
    }
 
    /**
     * 插入状态流转记录
     * <p>
     * 步骤:
     * 1. 参数校验
     * 2. 构建状态流转记录实体
     * 3. 保存状态流转记录
     * </p>
     *
     * @param eventId        事件ID
     * @param oldStatus      变更前状态
     * @param newStatus      变更后状态
     * @param operateContent 操作备注
     * @param operateTime    操作时间
     * @return 是否成功
     */
    @Override
    public boolean insertStatusFlow(Long eventId, Integer oldStatus, Integer newStatus, String operateContent, Date operateTime) {
        // 1. 参数校验
        if (eventId == null) {
            throw new RuntimeException("事件ID不能为空");
        }
        if (newStatus == null) {
            throw new RuntimeException("目标状态不能为空");
        }
 
        // 2. 构建状态流转记录实体
        GdClueEventStatusFlowEntity flowEntity = new GdClueEventStatusFlowEntity();
        flowEntity.setEventId(eventId);
        flowEntity.setOldStatus(oldStatus);
        flowEntity.setNewStatus(newStatus);
        flowEntity.setOperateContent(operateContent);
        flowEntity.setOperateTime(operateTime != null ? operateTime : new Date());
        flowEntity.setOperateUser(AuthUtil.getUserId());
        flowEntity.setOperateDept(Long.valueOf(AuthUtil.getDeptId()));
        flowEntity.setCreateUser(AuthUtil.getUserId());
        flowEntity.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
        flowEntity.setCreateTime(new Date());
 
        // 3. 保存状态流转记录
        return save(flowEntity);
    }
 
}