xuhy
2 天以前 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
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.enums.BusinessType;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.TTestMethodConfirmSheetOriginalDTO;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TTestMethodConfirmSheetOriginalQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TTestMethodConfirmSheetOriginalVO;
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.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 原始检测项 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-04-08
 */
@Api(tags = "原始检测项管理")
@RestController
@RequestMapping("")
public class TTestMethodConfirmSheetOriginalController {
 
    private final TokenService tokenService;
    private final ISysUserService sysUserService;
    private final SysUserMapper sysUserMapper;
    private final TTestMethodConfirmSheetOriginalService testMethodConfirmSheetOriginalService;
    private final TTestMethodConfirmSheetOriginalDataService testMethodConfirmSheetOriginalDataService;
    private final TTestMethodConfirmSheetTermService testMethodConfirmSheetTermService;
    private final TProjectTeamStaffService projectTeamStaffService;
    private final TExperimentDispatchParticipantsService experimentDispatchParticipantsService;
    private final TInspectionReportService inspectionReportService;
    @Autowired
    public TTestMethodConfirmSheetOriginalController(TokenService tokenService, ISysUserService sysUserService, SysUserMapper sysUserMapper, TTestMethodConfirmSheetOriginalService testMethodConfirmSheetOriginalService, TTestMethodConfirmSheetOriginalDataService testMethodConfirmSheetOriginalDataService, TTestMethodConfirmSheetTermService testMethodConfirmSheetTermService, TProjectTeamStaffService projectTeamStaffService, TExperimentDispatchParticipantsService experimentDispatchParticipantsService, TInspectionReportService inspectionReportService) {
        this.tokenService = tokenService;
        this.sysUserService = sysUserService;
        this.sysUserMapper = sysUserMapper;
        this.testMethodConfirmSheetOriginalService = testMethodConfirmSheetOriginalService;
        this.testMethodConfirmSheetOriginalDataService = testMethodConfirmSheetOriginalDataService;
        this.testMethodConfirmSheetTermService = testMethodConfirmSheetTermService;
        this.projectTeamStaffService = projectTeamStaffService;
        this.experimentDispatchParticipantsService = experimentDispatchParticipantsService;
        this.inspectionReportService = inspectionReportService;
    }
 
    /**
     * 获取检验方法确认单管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheetOriginal:list')")
    @ApiOperation(value = "获取检验方法确认单分页列表",  notes = "获取检验方法确认单分页列表",response = TTestMethodConfirmSheetOriginalQuery.class)
    @PostMapping(value = "/api/t-test-method-confirm-sheet-original/pageList")
    public R<PageInfo<TTestMethodConfirmSheetOriginalVO>> pageList(@RequestBody String param) {
        TTestMethodConfirmSheetOriginalQuery query = JSON.parseObject(param, TTestMethodConfirmSheetOriginalQuery.class);
        // 获取当前用户
        Long userId = tokenService.getLoginUser().getUserId();
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        if (roleType != 1){
            query.setUserId(userId);
            if(roleType ==2){
                // 查询项目组
                TProjectTeamStaff projectTeamStaff = projectTeamStaffService.getOne(Wrappers.lambdaQuery(TProjectTeamStaff.class)
                        .eq(TProjectTeamStaff::getUserId, userId));
                // 查询项目的工艺工程师id
                TProjectTeamStaff teamStaff = projectTeamStaffService.getOne(Wrappers.lambdaQuery(TProjectTeamStaff.class)
                        .eq(TProjectTeamStaff::getTeamId, projectTeamStaff.getTeamId())
                        .eq(TProjectTeamStaff::getRoleType, 3)
                        .last("LIMIT 1"));
                // 查询实验参与人员
                List<TExperimentDispatchParticipants> experimentDispatchParticipants = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                        .eq(TExperimentDispatchParticipants::getUserId, teamStaff.getUserId()));
                if(!CollectionUtils.isEmpty(experimentDispatchParticipants)){
                    List<String> dispatchIds = experimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getDispatchId).distinct().collect(Collectors.toList());
                    query.setDispatchIds(dispatchIds);
                }
            }else {
                // 查询实验参与人员
                List<TExperimentDispatchParticipants> experimentDispatchParticipants = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                        .eq(TExperimentDispatchParticipants::getUserId, userId));
                if (!CollectionUtils.isEmpty(experimentDispatchParticipants)) {
                    List<String> dispatchIds = experimentDispatchParticipants.stream().map(TExperimentDispatchParticipants::getDispatchId).distinct().collect(Collectors.toList());
                    query.setDispatchIds(dispatchIds);
                }
            }
            if(roleType == 4){
                // 查询检验报告
                List<TInspectionReport> inspectionReports = inspectionReportService.list(Wrappers.lambdaQuery(TInspectionReport.class)
                        .eq(TInspectionReport::getStatus, 1));
                if (!CollectionUtils.isEmpty(inspectionReports)) {
                    List<String> dispatchIds = inspectionReports.stream().map(TInspectionReport::getDispatchId).distinct().collect(Collectors.toList());
                    List<String> dispatchIds1 = query.getDispatchIds();
                    Iterator<String> iterator = dispatchIds1.iterator();
                    while (iterator.hasNext()) {
                        String next = iterator.next();
                        if (!dispatchIds.contains(next)) {
                            iterator.remove();
                        }
                    }
                    if(CollectionUtils.isEmpty(dispatchIds1)){
                        List<String> id = new ArrayList<>();
                        id.add("-1");
                        query.setDispatchIds(id);
                    }else {
                        query.setDispatchIds(dispatchIds1);
                    }
                }
            }
        }
        return R.ok(testMethodConfirmSheetOriginalService.pageList(query));
    }
 
    /**
     * 修改检验方法确认单
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheetOriginal:edit')")
    @Log(title = "检验方法确认单信息-修改检验方法确认单", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改检验方法确认单")
    @PostMapping(value = "/api/t-test-method-confirm-sheet-original/update")
    public R<Boolean> update(@RequestBody String param) {
        TTestMethodConfirmSheetOriginalDTO dto = JSON.parseObject(param, TTestMethodConfirmSheetOriginalDTO.class);
        testMethodConfirmSheetOriginalService.updateById(dto);
        testMethodConfirmSheetOriginalDataService.remove(Wrappers.lambdaQuery(TTestMethodConfirmSheetOriginalData.class).eq(TTestMethodConfirmSheetOriginalData::getOriginalId, dto.getId()));
        List<TTestMethodConfirmSheetOriginalData> testMethodConfirmSheetOriginalDataList = dto.getTestMethodConfirmSheetOriginalDataList();
        testMethodConfirmSheetOriginalDataList.forEach(testMethodConfirmSheetOriginalData -> {
            testMethodConfirmSheetOriginalData.setOriginalId(dto.getId());
        });
        testMethodConfirmSheetOriginalDataService.saveBatch(testMethodConfirmSheetOriginalDataList);
        return R.ok();
    }
 
    /**
     * 查看检验方法确认单详情
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheetOriginal:detail')")
    @ApiOperation(value = "查看检验方法确认单详情")
    @GetMapping(value = "/open/t-test-method-confirm-sheet-original/getDetailById")
    public R<TTestMethodConfirmSheetOriginalVO> getDetailById(@RequestParam String id) {
        TTestMethodConfirmSheetOriginal testMethodConfirmSheetOriginal = testMethodConfirmSheetOriginalService.getById(id);
        TTestMethodConfirmSheetOriginalVO testMethodConfirmSheetOriginalVO = new TTestMethodConfirmSheetOriginalVO();
        BeanUtils.copyProperties(testMethodConfirmSheetOriginal, testMethodConfirmSheetOriginalVO);
 
        // 查询检测项数据
        TTestMethodConfirmSheetTerm testMethodConfirmSheetTerm = testMethodConfirmSheetTermService.getById(testMethodConfirmSheetOriginal.getTermId());
        testMethodConfirmSheetOriginalVO.setTestMethodConfirmSheetTerm(testMethodConfirmSheetTerm);
 
        // 查询检测数据
        List<TTestMethodConfirmSheetOriginalData> testMethodConfirmSheetOriginalDataList = testMethodConfirmSheetOriginalDataService.list(Wrappers.lambdaQuery(TTestMethodConfirmSheetOriginalData.class).eq(TTestMethodConfirmSheetOriginalData::getOriginalId, id));
        testMethodConfirmSheetOriginalVO.setTestMethodConfirmSheetOriginalDataList(testMethodConfirmSheetOriginalDataList);
        return R.ok(testMethodConfirmSheetOriginalVO);
    }
 
}