无关风月
3 天以前 20739d95d85d5d6744690093a061292325ce4a9b
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package com.ruoyi.web.controller.api;
 
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.QATestItemReportStatusEnum;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TTestMethodConfirmSheetDTO;
import com.ruoyi.system.dto.TestMethodConfirmSheetSignDTO;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TTestMethodConfirmSheetQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TTestMethodConfirmSheetVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
 
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 检验方法确认单 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-04-08
 */
@Api(tags = "检验方法确认单管理")
@RestController
@RequestMapping("")
public class TTestMethodConfirmSheetController {
    private final TTestMethodConfirmSheetService testMethodConfirmSheetService;
    private final TokenService tokenService;
    private final ISysUserService sysUserService;
    private final SysUserMapper sysUserMapper;
    private final TTestMethodConfirmSheetTermService testMethodConfirmSheetTermService;
    private final TTestMethodConfirmSheetOriginalService testMethodConfirmSheetOriginalService;
    private final TProjectTeamService projectTeamService;
    private final TProjectTeamStaffService projectTeamStaffService;
    private final TExperimentDispatchService experimentDispatchService;
    private final TProjectProposalService projectProposalService;
    @Autowired
    public TTestMethodConfirmSheetController(TTestMethodConfirmSheetService testMethodConfirmSheetService, TokenService tokenService, ISysUserService sysUserService, SysUserMapper sysUserMapper, TTestMethodConfirmSheetTermService testMethodConfirmSheetTermService, TTestMethodConfirmSheetOriginalService testMethodConfirmSheetOriginalService, TProjectTeamService projectTeamService, TProjectTeamStaffService projectTeamStaffService, TExperimentDispatchService experimentDispatchService, TProjectProposalService projectProposalService) {
        this.testMethodConfirmSheetService = testMethodConfirmSheetService;
        this.tokenService = tokenService;
        this.sysUserService = sysUserService;
        this.sysUserMapper = sysUserMapper;
        this.testMethodConfirmSheetTermService = testMethodConfirmSheetTermService;
        this.testMethodConfirmSheetOriginalService = testMethodConfirmSheetOriginalService;
        this.projectTeamService = projectTeamService;
        this.projectTeamStaffService = projectTeamStaffService;
        this.experimentDispatchService = experimentDispatchService;
        this.projectProposalService = projectProposalService;
    }
 
    /**
     * 获取检验方法确认单管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:list')")
    @ApiOperation(value = "获取检验方法确认单分页列表",response = TTestMethodConfirmSheetQuery.class)
    @PostMapping(value = "/api/t-test-method-confirm-sheet/pageList")
    public R<PageInfo<TTestMethodConfirmSheetVO>> pageList(@RequestBody String param) {
        TTestMethodConfirmSheetQuery query = JSON.parseObject(param, TTestMethodConfirmSheetQuery.class);
        return R.ok(testMethodConfirmSheetService.pageList(query));
    }
 
    /**
     * 添加检验方法确认单管理
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:add')")
    @Log(title = "检验方法确认单信息-新增检验方法确认单", businessType = BusinessType.INSERT)
    @ApiOperation(value = "添加检验方法确认单",response = TTestMethodConfirmSheetDTO.class)
    @PostMapping(value = "/api/t-test-method-confirm-sheet/add")
    public R<Boolean> add(@RequestBody String param) {
        TTestMethodConfirmSheetDTO dto = JSON.parseObject(param,TTestMethodConfirmSheetDTO.class);
        testMethodConfirmSheetService.save(dto);
        List<TTestMethodConfirmSheetTerm> testMethodConfirmSheetTerms = dto.getTestMethodConfirmSheetTerms();
        testMethodConfirmSheetTerms.forEach(testMethodConfirmSheetTerm -> {
            testMethodConfirmSheetTerm.setTestId(dto.getId());
            testMethodConfirmSheetTerm.setStatus(1);
        });
        testMethodConfirmSheetTermService.saveBatch(testMethodConfirmSheetTerms);
 
        // 通过当前用户查询项目组
        Long userId = tokenService.getLoginUser().getUserId();
        TProjectTeamStaff projectTeamStaff = projectTeamStaffService.getOne(Wrappers.lambdaQuery(TProjectTeamStaff.class)
                .eq(TProjectTeamStaff::getUserId, userId)
                .last("LIMIT 1"));
        if(Objects.isNull(projectTeamStaff)){
            return R.fail("当前用户未分配项目组,无法创建项目课题方案");
        }
        // 查询项目组
        TProjectTeam projectTeam = projectTeamService.getById(projectTeamStaff.getTeamId());
        if(Objects.isNull(projectTeam)){
            return R.fail("项目组不存在");
        }
        if(projectTeam.getStatus() == 2){
            return R.fail("项目组已封存,无法创建项目课题方案");
        }
        // 生成原始记录编号
        String format = new SimpleDateFormat("yyyyMMdd").format(new Date());
        String originalCode = projectTeam.getTeamName() + format.substring(2) + "-JL";
        for (TTestMethodConfirmSheetTerm testMethodConfirmSheetTerm : testMethodConfirmSheetTerms) {
            // 添加原始记录
            TTestMethodConfirmSheetOriginal testMethodConfirmSheetOriginal = new TTestMethodConfirmSheetOriginal();
            testMethodConfirmSheetOriginal.setTermId(testMethodConfirmSheetTerm.getId());
            // 查询上个项目课题方案的序号
            long count = testMethodConfirmSheetOriginalService.count(Wrappers.lambdaQuery(TTestMethodConfirmSheetOriginal.class)
                    .like(TTestMethodConfirmSheetOriginal::getOriginalCode, originalCode));
            originalCode = originalCode + String.format("%02d", count+1);
            testMethodConfirmSheetOriginal.setOriginalCode(originalCode);
            testMethodConfirmSheetOriginal.setStatus(1);
            testMethodConfirmSheetOriginalService.save(testMethodConfirmSheetOriginal);
        }
        return R.ok();
    }
 
    /**
     * 修改检验方法确认单
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:edit')")
    @Log(title = "检验方法确认单信息-修改检验方法确认单", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改检验方法确认单")
    @PostMapping(value = "/api/t-test-method-confirm-sheet/update")
    public R<Boolean> update(@RequestBody String param) {
        TTestMethodConfirmSheetDTO dto = JSON.parseObject(param,TTestMethodConfirmSheetDTO.class);
        testMethodConfirmSheetService.updateById(dto);
        testMethodConfirmSheetTermService.remove(Wrappers.lambdaQuery(TTestMethodConfirmSheetTerm.class).eq(TTestMethodConfirmSheetTerm::getTestId,dto.getId()));
        List<TTestMethodConfirmSheetTerm> testMethodConfirmSheetTerms = dto.getTestMethodConfirmSheetTerms();
        testMethodConfirmSheetTerms.forEach(testMethodConfirmSheetTerm -> {
            testMethodConfirmSheetTerm.setTestId(dto.getId());
            testMethodConfirmSheetTerm.setStatus(1);
        });
        testMethodConfirmSheetTermService.saveBatch(testMethodConfirmSheetTerms);
        return R.ok();
    }
 
    /**
     * 查看检验方法确认单详情
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:detail')")
    @ApiOperation(value = "查看检验方法确认单详情")
    @GetMapping(value = "/open/t-test-method-confirm-sheet/getDetailById")
    public R<TTestMethodConfirmSheetVO> getDetailById(@RequestParam String id) {
        TTestMethodConfirmSheet testMethodConfirmSheet = testMethodConfirmSheetService.getById(id);
        TTestMethodConfirmSheetVO testMethodConfirmSheetVO = new TTestMethodConfirmSheetVO();
        BeanUtils.copyProperties(testMethodConfirmSheet, testMethodConfirmSheetVO);
 
        // 获取检测项
        List<TTestMethodConfirmSheetTerm> testMethodConfirmSheetTerms = testMethodConfirmSheetTermService.list(Wrappers.lambdaQuery(TTestMethodConfirmSheetTerm.class)
                .eq(TTestMethodConfirmSheetTerm::getTestId, id));
        testMethodConfirmSheetVO.setTestMethodConfirmSheetTerms(testMethodConfirmSheetTerms);
 
        // 查询实验调度信息
        TExperimentDispatch experimentDispatch = experimentDispatchService.getById(testMethodConfirmSheetVO.getDispatchId());
        if(Objects.nonNull(experimentDispatch)){
            testMethodConfirmSheetVO.setExperimentName(experimentDispatch.getExperimentName());
            testMethodConfirmSheetVO.setExperimentCode(experimentDispatch.getExperimentCode());
            // 查询项目课题方案
            TProjectProposal projectProposal = projectProposalService.getById(experimentDispatch.getProposalId());
            if(Objects.nonNull(projectProposal)){
                testMethodConfirmSheetVO.setProjectName(projectProposal.getProjectName());
            }
        }
 
        // 查询审核人姓名
        SysUser sysUser = sysUserService.selectUserById(testMethodConfirmSheet.getAuditPersonId());
        if(Objects.nonNull(sysUser)){
            testMethodConfirmSheetVO.setAuditPersonName(sysUser.getNickName());
        }
 
        return R.ok(testMethodConfirmSheetVO);
    }
 
    /**
     * 删除检验方法确认单
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:delete')")
    @Log(title = "检验方法确认单信息-删除检验方法确认单", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除检验方法确认单")
    @DeleteMapping(value = "/open/t-test-method-confirm-sheet/deleteById")
    public R<Boolean> deleteById(@RequestParam String id) {
        // 删除检测项
        testMethodConfirmSheetTermService.remove(Wrappers.lambdaQuery(TTestMethodConfirmSheetTerm.class).eq(TTestMethodConfirmSheetTerm::getTestId, id));
        return R.ok(testMethodConfirmSheetService.removeById(id));
    }
 
    /**
     * 批量删除检验方法确认单
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:delete')")
    @Log(title = "检验方法确认单信息-删除检验方法确认单", businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量删除检验方法确认单")
    @DeleteMapping(value = "/open/t-test-method-confirm-sheet/deleteByIds")
    public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
        // 删除检测项
        testMethodConfirmSheetTermService.remove(Wrappers.lambdaQuery(TTestMethodConfirmSheetTerm.class).in(TTestMethodConfirmSheetTerm::getTestId, ids));
        return R.ok(testMethodConfirmSheetService.removeByIds(ids));
    }
 
    /**
     * 批量删除检验方法确认单
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:sign')")
    @Log(title = "检验方法确认单信息-检验方法确认单签字", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "检验方法确认单签字",response = TestMethodConfirmSheetSignDTO.class)
    @PostMapping(value = "/api/t-test-method-confirm-sheet/sign")
    public R<Boolean> sign(@RequestBody String param) {
        TestMethodConfirmSheetSignDTO testMethodConfirmSheetSign = JSON.parseObject(param, TestMethodConfirmSheetSignDTO.class);
        Long userId = tokenService.getLoginUser().getUserId();
        testMethodConfirmSheetService.update(Wrappers.lambdaUpdate(TTestMethodConfirmSheet.class)
                .eq(TTestMethodConfirmSheet::getId, testMethodConfirmSheetSign.getTestMethodConfirmSheetId())
                .set(TTestMethodConfirmSheet::getAuditStatus, 2)
                .set(TTestMethodConfirmSheet::getAuditTime, LocalDateTime.now())
                .set(TTestMethodConfirmSheet::getAuditPersonId, userId)
                .set(TTestMethodConfirmSheet::getAuditSign, testMethodConfirmSheetSign.getConfirmSign()));
        return R.ok();
    }
 
    /**
     * 撤销QA检测项报告管理
     */
    //@PreAuthorize("@ss.hasPermi('system:qaTestItemReport:revokedReport')")
    @Log(title = "检验方法确认单信息-撤销检验方法确认单信息状态", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "撤销检验方法确认单信息状态")
    @PutMapping(value = "/open/t-test-method-confirm-sheet/revokedSheet")
    public R<Boolean> revokedSheet(@RequestParam String id) {
        TTestMethodConfirmSheet testMethodConfirmSheet = testMethodConfirmSheetService.getById(id);
        testMethodConfirmSheet.setAuditStatus(QATestItemReportStatusEnum.REVOKED.getCode());
        testMethodConfirmSheetService.updateById(testMethodConfirmSheet);
        return R.ok();
    }
}