xuhy
1 天以前 b7ec3aff011f05e236e76be844540dbe776f7353
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
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.core.exception.ServiceException;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TProjectTeamDTO;
import com.ruoyi.system.dto.UpAndDownDTO;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TProjectTeamQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TProjectTeamVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
 
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 TProjectTeamController {
 
    private final TProjectTeamService projectTeamService;
    private final TProjectTeamStaffService projectTeamStaffService;
    private final ISysUserService sysUserService;
    private final TokenService tokenService;
    private final TProjectProposalService projectProposalService;
    private final TExperimentDispatchService experimentDispatchService;
    private final TTestMethodConfirmSheetService testMethodConfirmSheetService;
    private final TExperimentSchemeService experimentSchemeService;
    private final TSamplingRecordService samplingRecordService;
    private final TExperimentResultReportService experimentResultReportService;
    private final TQaTestItemService qaTestItemService;
    private final TQaProduceReportService qaProduceReportService;
    private final TFeasibilityStudyReportService feasibilityStudyReportService;
    private final TInspectionReportService inspectionReportService;
    private final TProjectApprovalReportService projectApprovalReportService;
    private final TTesterOtherTaskService testerOtherTaskService;
    private final TTestMethodConfirmSheetOriginalService testMethodConfirmSheetOriginalService;
    @Autowired
    public TProjectTeamController(TProjectTeamService projectTeamService, TProjectTeamStaffService projectTeamStaffService, ISysUserService sysUserService, TokenService tokenService, TProjectProposalService projectProposalService, TExperimentDispatchService experimentDispatchService, TTestMethodConfirmSheetService testMethodConfirmSheetService, TExperimentSchemeService experimentSchemeService, TSamplingRecordService samplingRecordService, TExperimentResultReportService experimentResultReportService, TQaTestItemService qaTestItemService, TQaProduceReportService qaProduceReportService, TFeasibilityStudyReportService feasibilityStudyReportService, TInspectionReportService inspectionReportService, TProjectApprovalReportService projectApprovalReportService, TTesterOtherTaskService testerOtherTaskService, TTestMethodConfirmSheetOriginalService testMethodConfirmSheetOriginalService) {
        this.projectTeamService = projectTeamService;
        this.projectTeamStaffService = projectTeamStaffService;
        this.sysUserService = sysUserService;
        this.tokenService = tokenService;
        this.projectProposalService = projectProposalService;
        this.experimentDispatchService = experimentDispatchService;
        this.testMethodConfirmSheetService = testMethodConfirmSheetService;
        this.experimentSchemeService = experimentSchemeService;
        this.samplingRecordService = samplingRecordService;
        this.experimentResultReportService = experimentResultReportService;
        this.qaTestItemService = qaTestItemService;
        this.qaProduceReportService = qaProduceReportService;
        this.feasibilityStudyReportService = feasibilityStudyReportService;
        this.inspectionReportService = inspectionReportService;
        this.projectApprovalReportService = projectApprovalReportService;
        this.testerOtherTaskService = testerOtherTaskService;
        this.testMethodConfirmSheetOriginalService = testMethodConfirmSheetOriginalService;
    }
 
    /**
     * 获取项目组管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:projectTeam:list')")
    @ApiOperation(value = "获取项目组分页列表",response = TProjectTeamQuery.class)
    @PostMapping(value = "/api/t-project-team/pageList")
    public R<PageInfo<TProjectTeamVO>> pageList(@RequestBody String param) {
        TProjectTeamQuery query = JSON.parseObject(param, TProjectTeamQuery.class);
        PageInfo<TProjectTeamVO> tProjectTeamVOPageInfo = projectTeamService.pageList(query);
        return R.ok(tProjectTeamVOPageInfo);
    }
 
    /**
     * 添加项目组管理
     */
    //@PreAuthorize("@ss.hasPermi('system:projectTeam:add')")
    @Log(title = "项目组信息-新增项目组", businessType = BusinessType.INSERT)
    @ApiOperation(value = "添加项目组",response = TProjectTeamDTO.class)
    @PostMapping(value = "/api/t-project-team/add")
    public R<Boolean> add(@RequestBody String param) {
        TProjectTeamDTO dto = JSON.parseObject(param,TProjectTeamDTO.class);
        List<TProjectTeamStaff> staffs = dto.getStaffs();
        // 判断工艺工程师是否存在其他项目组中
        staffs.stream().filter(staff -> staff.getRoleType() == 3).forEach(staff -> {
            long count = projectTeamStaffService.count(Wrappers.lambdaQuery(TProjectTeamStaff.class).eq(TProjectTeamStaff::getUserId, staff.getUserId()));
            if(count > 0){
                throw new ServiceException("该工艺工程师已存在项目组");
            }
        });
        staffs.stream().filter(staff -> staff.getRoleType() == 2).forEach(staff -> {
            long count = projectTeamStaffService.count(Wrappers.lambdaQuery(TProjectTeamStaff.class).eq(TProjectTeamStaff::getUserId, staff.getUserId()));
            if(count > 0){
                throw new ServiceException("该审批人已存在项目组");
            }
        });
        projectTeamService.save(dto);
        // 保存项目组成员
        for (TProjectTeamStaff staff : staffs) {
            staff.setTeamId(dto.getId());
        }
        projectTeamStaffService.saveBatch(staffs);
        return R.ok();
    }
 
    /**
     * 修改项目组
     */
    //@PreAuthorize("@ss.hasPermi('system:projectTeam:edit')")
    @Log(title = "项目组信息-修改项目组", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改项目组")
    @PostMapping(value = "/api/t-project-team/update")
    public R<Boolean> update(@RequestBody String param) {
        TProjectTeamDTO dto = JSON.parseObject(param,TProjectTeamDTO.class);
        List<TProjectTeamStaff> staffs = dto.getStaffs();
        // 判断工艺工程师是否存在其他项目组中
        staffs.stream().filter(staff -> staff.getRoleType() == 3).forEach(staff -> {
            long count = projectTeamStaffService.count(Wrappers.lambdaQuery(TProjectTeamStaff.class)
                    .ne(TProjectTeamStaff::getTeamId, dto.getId())
                    .eq(TProjectTeamStaff::getUserId, staff.getUserId()));
            if(count > 0){
                throw new ServiceException("该工艺工程师已存在项目组");
            }
        });
        staffs.stream().filter(staff -> staff.getRoleType() == 2).forEach(staff -> {
            long count = projectTeamStaffService.count(Wrappers.lambdaQuery(TProjectTeamStaff.class)
                    .ne(TProjectTeamStaff::getTeamId, dto.getId())
                    .eq(TProjectTeamStaff::getUserId, staff.getUserId()));
            if(count > 0){
                throw new ServiceException("该工艺工程师已存在项目组");
            }
        });
        projectTeamService.updateById(dto);
        // 删除项目组成员
        projectTeamStaffService.remove(Wrappers.lambdaQuery(TProjectTeamStaff.class).eq(TProjectTeamStaff::getTeamId, dto.getId()));
        // 保存项目组成员
        for (TProjectTeamStaff staff : staffs) {
            staff.setTeamId(dto.getId());
        }
        projectTeamStaffService.saveBatch(staffs);
        return R.ok();
    }
 
    /**
     * 查看项目组详情
     */
    //@PreAuthorize("@ss.hasPermi('system:projectTeam:detail')")
    @ApiOperation(value = "查看项目组详情")
    @GetMapping(value = "/open/t-project-team/getDetailById")
    public R<TProjectTeamVO> getDetailById(@RequestParam String id) {
        TProjectTeam projectTeam = projectTeamService.getById(id);
        TProjectTeamVO projectTeamVO = new TProjectTeamVO();
        BeanUtils.copyProperties(projectTeam, projectTeamVO);
        // 查询项目组人员
        List<TProjectTeamStaff> list = projectTeamStaffService.list(Wrappers.lambdaQuery(TProjectTeamStaff.class).eq(TProjectTeamStaff::getTeamId, id));
        // 查询所有人员
        List<SysUser> sysUsers = sysUserService.selectList();
        for (TProjectTeamStaff tProjectTeamStaff : list) {
            sysUsers.stream().filter(sysUser -> sysUser.getUserId().equals(tProjectTeamStaff.getUserId())).forEach(sysUser -> {
                tProjectTeamStaff.setNickName(sysUser.getNickName());
                tProjectTeamStaff.setAvatar(sysUser.getAvatar());
            });
        }
        projectTeamVO.setStaffs(list);
        return R.ok(projectTeamVO);
    }
 
    /**
     * 删除项目组
     */
    //@PreAuthorize("@ss.hasPermi('system:projectTeam:delete')")
    @Log(title = "项目组信息-删除项目组", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除项目组")
    @DeleteMapping(value = "/open/t-project-team/deleteById")
    public R<Boolean> deleteById(@RequestParam String id) {
        // 删除项目组成员
        projectTeamStaffService.remove(Wrappers.lambdaQuery(TProjectTeamStaff.class).eq(TProjectTeamStaff::getTeamId, id));
        return R.ok(projectTeamService.removeById(id));
    }
 
    /**
     * 批量删除项目组
     */
    //@PreAuthorize("@ss.hasPermi('system:projectTeam:delete')")
    @Log(title = "项目组信息-删除项目组", businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量删除项目组")
    @DeleteMapping(value = "/open/t-project-team/deleteByIds")
    public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
        // 删除项目组成员
        projectTeamStaffService.remove(Wrappers.lambdaQuery(TProjectTeamStaff.class).in(TProjectTeamStaff::getTeamId, ids));
        return R.ok(projectTeamService.removeByIds(ids));
    }
 
    /**
     * 修改项目组
     */
    //@PreAuthorize("@ss.hasPermi('system:projectTeam:upAndDown')")
    @Log(title = "项目组信息-修改项目组状态", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改项目组状态",response = UpAndDownDTO.class)
    @PostMapping(value = "/api/t-project-team/upAndDown")
    public R<Boolean> upAndDown(@RequestBody String param) {
        UpAndDownDTO dto = JSON.parseObject(param,UpAndDownDTO.class);
        TProjectTeam projectTeam = projectTeamService.getById(dto.getId());
        projectTeam.setStatus(dto.getStatus());
        projectTeamService.updateById(projectTeam);
 
        if(dto.getStatus() == 2){
            // 封存项目课题方案
            List<TProjectProposal> projectProposals = projectProposalService.list(Wrappers.lambdaQuery(TProjectProposal.class)
                    .eq(TProjectProposal::getTeamId, dto.getId()));
            if(!CollectionUtils.isEmpty(projectProposals)){
                for (TProjectProposal projectProposal : projectProposals) {
                    projectProposal.setOldStatus(projectProposal.getAuditStatus());
                    projectProposal.setAuditStatus(5);
                }
                projectProposalService.updateBatchById(projectProposals);
                List<String> projectIds = projectProposals.stream().map(TProjectProposal::getId).collect(Collectors.toList());
                // 封存实验调度
                List<TExperimentDispatch> experimentDispatches = experimentDispatchService.list(Wrappers.lambdaQuery(TExperimentDispatch.class)
                        .in(TExperimentDispatch::getProposalId, projectIds));
                if(!CollectionUtils.isEmpty(experimentDispatches)){
                    experimentDispatches.forEach(experimentDispatch -> {
                        experimentDispatch.setOldStatus(experimentDispatch.getStatus());
                        experimentDispatch.setStatus(3);
                    });
                    experimentDispatchService.updateBatchById(experimentDispatches);
 
                    // 封存检验方法
                    List<String> dispatchIds = experimentDispatches.stream().map(TExperimentDispatch::getId).collect(Collectors.toList());
                    List<TTestMethodConfirmSheet> testMethodConfirmSheets = testMethodConfirmSheetService.list(Wrappers.lambdaQuery(TTestMethodConfirmSheet.class)
                            .in(TTestMethodConfirmSheet::getDispatchId, dispatchIds));
                    if(!CollectionUtils.isEmpty(testMethodConfirmSheets)){
                        testMethodConfirmSheets.forEach(testMethodConfirmSheet -> {
                            testMethodConfirmSheet.setOldStatus(testMethodConfirmSheet.getAuditStatus());
                            testMethodConfirmSheet.setAuditStatus(5);
                        });
                        testMethodConfirmSheetService.updateBatchById(testMethodConfirmSheets);
                    }
 
                    // 封存试验方案
                    List<TExperimentScheme> experimentSchemes = experimentSchemeService.list(Wrappers.lambdaQuery(TExperimentScheme.class)
                            .in(TExperimentScheme::getDispatchId, dispatchIds));
                    if(!CollectionUtils.isEmpty(experimentSchemes)){
                        experimentSchemes.forEach(experimentScheme -> {
                            experimentScheme.setOldStatus(experimentScheme.getStatus());
                            experimentScheme.setStatus(5);
                        });
                        experimentSchemeService.updateBatchById(experimentSchemes);
                    }
 
                    // 封存取样记录
                    List<TSamplingRecord> samplingRecords = samplingRecordService.list(Wrappers.lambdaQuery(TSamplingRecord.class)
                            .in(TSamplingRecord::getDispatchId, dispatchIds));
                    if(!CollectionUtils.isEmpty(samplingRecords)){
                        samplingRecords.forEach(samplingRecord -> {
                            samplingRecord.setOldStatus(samplingRecord.getStatus());
                            samplingRecord.setStatus(3);
                        });
                        samplingRecordService.updateBatchById(samplingRecords);
                    }
 
                    // 封存结果汇报
                    List<TExperimentResultReport> experimentResultReports = experimentResultReportService.list(Wrappers.lambdaQuery(TExperimentResultReport.class)
                            .in(TExperimentResultReport::getDispatchId, dispatchIds));
                    if(!CollectionUtils.isEmpty(experimentResultReports)){
                        experimentResultReports.forEach(experimentResultReport -> {
                            experimentResultReport.setOldStatus(experimentResultReport.getStatus());
                            experimentResultReport.setStatus(4);
                        });
                        experimentResultReportService.updateBatchById(experimentResultReports);
                    }
 
                }
            }
        }else {
            // 解封项目课题方案
            List<TProjectProposal> projectProposals = projectProposalService.list(Wrappers.lambdaQuery(TProjectProposal.class)
                    .eq(TProjectProposal::getTeamId, dto.getId()));
            if(!CollectionUtils.isEmpty(projectProposals)){
                for (TProjectProposal projectProposal : projectProposals) {
                    projectProposal.setAuditStatus(projectProposal.getOldStatus());
                }
                projectProposalService.updateBatchById(projectProposals);
                List<String> projectIds = projectProposals.stream().map(TProjectProposal::getId).collect(Collectors.toList());
                // 封存实验调度
                List<TExperimentDispatch> experimentDispatches = experimentDispatchService.list(Wrappers.lambdaQuery(TExperimentDispatch.class)
                        .in(TExperimentDispatch::getProposalId, projectIds));
                if(!CollectionUtils.isEmpty(experimentDispatches)){
                    experimentDispatches.forEach(experimentDispatch -> {
                        experimentDispatch.setStatus(experimentDispatch.getOldStatus());
                    });
                    experimentDispatchService.updateBatchById(experimentDispatches);
 
                    // 封存检验方法
                    List<String> dispatchIds = experimentDispatches.stream().map(TExperimentDispatch::getId).collect(Collectors.toList());
                    List<TTestMethodConfirmSheet> testMethodConfirmSheets = testMethodConfirmSheetService.list(Wrappers.lambdaQuery(TTestMethodConfirmSheet.class)
                            .in(TTestMethodConfirmSheet::getDispatchId, dispatchIds));
                    if(!CollectionUtils.isEmpty(testMethodConfirmSheets)){
                        testMethodConfirmSheets.forEach(testMethodConfirmSheet -> {
                            testMethodConfirmSheet.setAuditStatus(testMethodConfirmSheet.getAuditStatus());
                        });
                        testMethodConfirmSheetService.updateBatchById(testMethodConfirmSheets);
                    }
 
                    // 封存试验方案
                    List<TExperimentScheme> experimentSchemes = experimentSchemeService.list(Wrappers.lambdaQuery(TExperimentScheme.class)
                            .in(TExperimentScheme::getDispatchId, dispatchIds));
                    if(!CollectionUtils.isEmpty(experimentSchemes)){
                        experimentSchemes.forEach(experimentScheme -> {
                            experimentScheme.setStatus(experimentScheme.getOldStatus());
                        });
                        experimentSchemeService.updateBatchById(experimentSchemes);
                    }
 
                    // 封存取样记录
                    List<TSamplingRecord> samplingRecords = samplingRecordService.list(Wrappers.lambdaQuery(TSamplingRecord.class)
                            .in(TSamplingRecord::getDispatchId, dispatchIds));
                    if(!CollectionUtils.isEmpty(samplingRecords)){
                        samplingRecords.forEach(samplingRecord -> {
                            samplingRecord.setStatus(samplingRecord.getOldStatus());
                        });
                        samplingRecordService.updateBatchById(samplingRecords);
                    }
 
                    // 封存结果汇报
                    List<TExperimentResultReport> experimentResultReports = experimentResultReportService.list(Wrappers.lambdaQuery(TExperimentResultReport.class)
                            .in(TExperimentResultReport::getDispatchId, dispatchIds));
                    if(!CollectionUtils.isEmpty(experimentResultReports)){
                        experimentResultReports.forEach(experimentResultReport -> {
                            experimentResultReport.setStatus(experimentResultReport.getOldStatus());
                        });
                        experimentResultReportService.updateBatchById(experimentResultReports);
                    }
                }
            }
        }
 
        return R.ok();
    }
 
    /**
     * 查看项目组详情
     */
    @ApiOperation(value = "查询当前用户项目组信息")
    @GetMapping(value = "/open/t-project-team/getDetailByUserId")
    public R<TProjectTeamVO> getDetailByUserId() {
        Long userId = tokenService.getLoginUser().getUserId();
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        TProjectTeamStaff projectTeamStaff = projectTeamStaffService.getOne(Wrappers.lambdaQuery(TProjectTeamStaff.class)
                .eq(TProjectTeamStaff::getUserId, userId)
                .eq(TProjectTeamStaff::getRoleType, roleType)
                .last("LIMIT 1"));
        if(Objects.isNull(projectTeamStaff)){
            return R.fail("当前用户未分配项目组,无法查看项目组信息");
        }
        TProjectTeam projectTeam = projectTeamService.getById(projectTeamStaff.getTeamId());
        TProjectTeamVO projectTeamVO = new TProjectTeamVO();
        BeanUtils.copyProperties(projectTeam, projectTeamVO);
        // 查询项目组人员
        List<TProjectTeamStaff> list = projectTeamStaffService.list(Wrappers.lambdaQuery(TProjectTeamStaff.class).eq(TProjectTeamStaff::getTeamId, projectTeamStaff.getTeamId()));
        // 查询所有人员
        List<SysUser> sysUsers = sysUserService.selectList();
        for (TProjectTeamStaff tProjectTeamStaff : list) {
            sysUsers.stream().filter(sysUser -> sysUser.getUserId().equals(tProjectTeamStaff.getUserId())).forEach(sysUser -> {
                tProjectTeamStaff.setNickName(sysUser.getNickName());
                tProjectTeamStaff.setAvatar(sysUser.getAvatar());
            });
        }
        projectTeamVO.setStaffs(list);
        projectTeamVO.setStaffName(list.stream().map(TProjectTeamStaff::getNickName).collect(Collectors.joining(",")));
        return R.ok(projectTeamVO);
    }
 
}