刘光辉
8 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package jnpf.tmsController;
 
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.annotation.HandleLog;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.tmsEntity.record.TmsQuizAnswerPaperVO;
import jnpf.tmsEntity.record.TmsRecordForm;
import jnpf.tmsEntity.record.TmsRecordIncompleteVO;
import jnpf.tmsEntity.record.TmsRecordProgressVO;
import jnpf.tmsEntity.record.TmsRecordQuery;
import jnpf.tmsEntity.record.TmsRecordScanSignForm;
import jnpf.tmsEntity.record.TmsRecordSignQrVO;
import jnpf.tmsEntity.person.TmsPersonTaskSignResult;
import jnpf.tmsService.TmsRecordService;
import jnpf.util.JsonUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.Map;
 
/**
 * 培训记录。网关 {@code /api/tms/record/**} → {@code /record/**}。
 *
 * <p>状态流转:open → pending → ready → archived;或 invalid。
 * 归档接口会触发写入个人培训档案目录(tms_person_train)。</p>
 */
@Tag(name = "TMS培训记录", description = "Record")
@RestController
@RequestMapping("/record")
@RequiredArgsConstructor
public class TmsRecordController {
 
    private final TmsRecordService recordService;
 
    @Operation(summary = "培训记录分页列表")
    @GetMapping("/list")
    public ActionResult<PageListVO<TmsRecordForm>> list(TmsRecordQuery query) {
        List<TmsRecordForm> list = recordService.getList(query);
        PageListVO<TmsRecordForm> vo = new PageListVO<>();
        vo.setList(list);
        vo.setPagination(JsonUtil.getJsonToBean(query, PaginationVO.class));
        return ActionResult.success(vo);
    }
 
    @Operation(summary = "培训记录详情")
    @GetMapping("/{id}")
    public ActionResult<TmsRecordForm> info(@PathVariable("id") String id) {
        return ActionResult.success(recordService.getInfo(id));
    }
 
    @Operation(summary = "生成签到二维码")
    @GetMapping("/{id}/sign-qr")
    public ActionResult<TmsRecordSignQrVO> signQr(@PathVariable("id") String id) {
        return ActionResult.success(recordService.getSignQr(id));
    }
 
    @HandleLog(moduleName = "培训记录", requestMethod = "签到")
    @Operation(summary = "扫码签到落库")
    @PostMapping("/scan-sign")
    public ActionResult<TmsPersonTaskSignResult> scanSign(@RequestBody TmsRecordScanSignForm form) {
        return ActionResult.success(recordService.scanSign(form));
    }
 
    @HandleLog(moduleName = "培训记录", requestMethod = "修改")
    @Operation(summary = "更新培训记录")
    @PutMapping("/{id}")
    public ActionResult<String> update(@PathVariable("id") String id, @RequestBody TmsRecordForm form) {
        recordService.update(id, form);
        return ActionResult.success("更新成功");
    }
 
    @HandleLog(moduleName = "培训记录", requestMethod = "状态变更")
    @Operation(summary = "关闭时间到期转入待归档(临时按钮 / 后续 XXL-JOB)")
    @PostMapping("/mark-ready-by-close")
    public ActionResult<Integer> markReadyByClose() {
        return ActionResult.success(recordService.markReadyByCloseTime());
    }
 
    @HandleLog(moduleName = "培训记录", requestMethod = "状态变更")
    @Operation(summary = "待归档转入可归档(可选中间态)")
    @PostMapping("/promote-ready")
    public ActionResult<Integer> promoteReady(@RequestBody Map<String, List<String>> body) {
        return ActionResult.success(recordService.promoteToReady(body == null ? null : body.get("ids")));
    }
 
    @HandleLog(moduleName = "培训记录", requestMethod = "恢复")
    @Operation(summary = "可归档恢复为待归档(临时联调)")
    @PostMapping("/restore-pending")
    public ActionResult<Integer> restorePending(@RequestBody Map<String, List<String>> body) {
        return ActionResult.success(recordService.restoreToPending(body == null ? null : body.get("ids")));
    }
 
    @HandleLog(moduleName = "培训记录", requestMethod = "归档")
    @Operation(summary = "归档培训记录")
    @PostMapping("/archive")
    public ActionResult<Integer> archive(@RequestBody Map<String, List<String>> body) {
        int count = recordService.archive(body == null ? null : body.get("ids"));
        return ActionResult.success(count);
    }
 
    @HandleLog(moduleName = "培训记录", requestMethod = "作废")
    @Operation(summary = "作废培训记录(无人完成 → invalid + 生成再维护草稿)")
    @PostMapping("/mark-invalid")
    public ActionResult<Integer> markInvalid(@RequestBody Map<String, List<String>> body) {
        return ActionResult.success(recordService.markInvalid(body == null ? null : body.get("ids")));
    }
 
    @Operation(summary = "实时参与进度")
    @GetMapping("/{id}/progress")
    public ActionResult<TmsRecordProgressVO> progress(@PathVariable("id") String id) {
        return ActionResult.success(recordService.getProgress(id));
    }
 
    @Operation(summary = "未完成人员清单(按部门排序)")
    @GetMapping("/{id}/incomplete")
    public ActionResult<List<TmsRecordIncompleteVO>> incomplete(@PathVariable("id") String id) {
        return ActionResult.success(recordService.listIncomplete(id));
    }
 
    @Operation(summary = "计算提问人数")
    @GetMapping("/{id}/quiz-count")
    public ActionResult<Integer> quizCount(@PathVariable("id") String id) {
        return ActionResult.success(recordService.calcQuizCount(id));
    }
 
    @Operation(summary = "查看学员提问答卷")
    @GetMapping("/{id}/quiz-answers")
    public ActionResult<TmsQuizAnswerPaperVO> quizAnswers(
            @PathVariable("id") String id,
            @RequestParam("userId") String userId) {
        return ActionResult.success(recordService.getQuizAnswers(id, userId));
    }
 
    @HandleLog(moduleName = "培训记录", requestMethod = "删除")
    @Operation(summary = "删除培训记录")
    @DeleteMapping
    public ActionResult<String> delete(@RequestBody Map<String, List<String>> body) {
        recordService.delete(body == null ? null : body.get("ids"));
        return ActionResult.success("删除成功");
    }
}