无关风月
3 天以前 7289189c907038db99d41aefcd9e12dce5077d3e
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
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.framework.web.service.TokenService;
import com.ruoyi.system.dto.ApplicationTerminationAuditDTO;
import com.ruoyi.system.dto.ApplicationTerminationDTO;
import com.ruoyi.system.dto.TExperimentSchemeDTO;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TExperimentSchemeQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TExperimentSchemeVO;
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.time.LocalDateTime;
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 TExperimentSchemeController {
 
    private final TExperimentSchemeService experimentSchemeService;
    private final TokenService tokenService;
    private final ISysUserService sysUserService;
    private final SysUserMapper sysUserMapper;
    private final TExperimentSchemePersonService experimentSchemePersonService;
    private final TExperimentDispatchParticipantsService experimentDispatchParticipantsService;
    private final TExperimentDispatchService experimentDispatchService;
    private final TProjectProposalService projectProposalService;
    private final TExperimentDispatchGroupService experimentDispatchGroupService;
    @Autowired
    public TExperimentSchemeController(TExperimentSchemeService experimentSchemeService, TokenService tokenService, ISysUserService sysUserService, SysUserMapper sysUserMapper, TExperimentSchemePersonService experimentSchemePersonService, TExperimentDispatchParticipantsService experimentDispatchParticipantsService, TExperimentDispatchService experimentDispatchService, TProjectProposalService projectProposalService, TExperimentDispatchGroupService experimentDispatchGroupService) {
        this.experimentSchemeService = experimentSchemeService;
        this.tokenService = tokenService;
        this.sysUserService = sysUserService;
        this.sysUserMapper = sysUserMapper;
        this.experimentSchemePersonService = experimentSchemePersonService;
        this.experimentDispatchParticipantsService = experimentDispatchParticipantsService;
        this.experimentDispatchService = experimentDispatchService;
        this.projectProposalService = projectProposalService;
        this.experimentDispatchGroupService = experimentDispatchGroupService;
    }
 
    /**
     * 获取实验方案管理列表
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:list')")
    @ApiOperation(value = "获取实验方案分页列表",response = TExperimentSchemeQuery.class)
    @PostMapping(value = "/api/t-experiment-scheme/pageList")
    public R<PageInfo<TExperimentSchemeVO>> pageList(@RequestBody String param) {
        TExperimentSchemeQuery query = JSON.parseObject(param, TExperimentSchemeQuery.class);
        return R.ok(experimentSchemeService.pageList(query));
    }
    /**
     * 获取实验方案管理列表-中止审批列表
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:list')")
    @ApiOperation(value = "获取实验方案分页列表-中止审批列表",response = TExperimentSchemeQuery.class)
    @PostMapping(value = "/api/t-experiment-scheme/auditPageList")
    public R<PageInfo<TExperimentSchemeVO>> auditPageList(@RequestBody String param) {
        TExperimentSchemeQuery query = JSON.parseObject(param, TExperimentSchemeQuery.class);
        return R.ok(experimentSchemeService.auditPageList(query));
    }
 
    /**
     * 通过实验调度查询查询组别列表
     */
    @ApiOperation(value = "通过实验调度查询实验人员")
    @GetMapping(value = "/open/t-experiment-scheme/getParticipantsByDispatchId")
    public R<List<TExperimentDispatchParticipants>> getParticipantsByDispatchId(@RequestParam String dispatchId) {
        List<TExperimentDispatchParticipants> list = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                .eq(TExperimentDispatchParticipants::getDispatchId, dispatchId)
                .eq(TExperimentDispatchParticipants::getRoleType,5));
        if(!CollectionUtils.isEmpty(list)){
            List<Long> userIds = list.stream().map(TExperimentDispatchParticipants::getUserId).collect(Collectors.toList());
            List<SysUser> sysUsers = sysUserMapper.selectUserByIds(userIds);
            list.forEach(tExperimentDispatchParticipant -> {
                SysUser sysUser = sysUsers.stream().filter(user -> user.getUserId().equals(tExperimentDispatchParticipant.getUserId())).findFirst().orElse(null);
                if(sysUser != null){
                    tExperimentDispatchParticipant.setNickName(sysUser.getNickName());
                    tExperimentDispatchParticipant.setAvatar(sysUser.getAvatar());
                }
            });
        }
        return R.ok(list);
    }
    /**
     * 通过实验调度查询查询组别列表
     */
    @ApiOperation(value = "通过实验调度查询查询组别列表")
    @GetMapping(value = "/open/t-experiment-scheme/getGroupByDispatchId")
    public R<List<TExperimentDispatchGroup>> getGroupByDispatchId(@RequestParam String dispatchId) {
        List<TExperimentDispatchGroup> list = experimentDispatchGroupService.list(Wrappers.lambdaQuery(TExperimentDispatchGroup.class)
                .eq(TExperimentDispatchGroup::getDispatchId, dispatchId));
        return R.ok(list);
    }
 
    /**
     * 添加实验方案管理
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:add')")
    @Log(title = "实验方案信息-新增实验方案", businessType = BusinessType.INSERT)
    @ApiOperation(value = "添加实验方案",response = TExperimentSchemeDTO.class)
    @PostMapping(value = "/api/t-experiment-scheme/add")
    public R<Boolean> add(@RequestBody String param) {
        TExperimentSchemeDTO dto = JSON.parseObject(param,TExperimentSchemeDTO.class);
        experimentSchemeService.save(dto);
        List<TExperimentSchemePerson> experimentSchemePersons = dto.getExperimentSchemePersons();
        experimentSchemePersons.forEach(experimentSchemePerson -> {
            experimentSchemePerson.setSchemeId(dto.getId());
            experimentSchemePerson.setCommitTime(LocalDateTime.now());
        });
        experimentSchemePersonService.saveBatch(experimentSchemePersons);
        return R.ok();
    }
 
    /**
     * 修改实验方案
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:edit')")
    @Log(title = "实验方案信息-修改实验方案", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改实验方案")
    @PostMapping(value = "/api/t-experiment-scheme/update")
    public R<Boolean> update(@RequestBody String param) {
        TExperimentSchemeDTO dto = JSON.parseObject(param,TExperimentSchemeDTO.class);
        experimentSchemeService.updateById(dto);
        experimentSchemePersonService.remove(Wrappers.lambdaQuery(TExperimentSchemePerson.class).eq(TExperimentSchemePerson::getSchemeId,dto.getId()));
        List<TExperimentSchemePerson> experimentSchemePersons = dto.getExperimentSchemePersons();
        experimentSchemePersons.forEach(experimentSchemePerson -> {
            experimentSchemePerson.setSchemeId(dto.getId());
            experimentSchemePerson.setCommitTime(LocalDateTime.now());
        });
        experimentSchemePersonService.saveBatch(experimentSchemePersons);
        return R.ok();
    }
 
    /**
     * 修改实验方案
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:edit')")
    @Log(title = "实验方案信息-修改实验方案-实验员提交", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改实验方案-实验员提交")
    @PostMapping(value = "/api/t-experiment-scheme/updateTester")
    public R<Boolean> updateTester(@RequestBody String param) {
        TExperimentSchemeDTO dto = JSON.parseObject(param,TExperimentSchemeDTO.class);
        dto.setStatus(6);
        experimentSchemeService.updateById(dto);
        return R.ok();
    }
 
    /**
     * 查看实验方案详情
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:detail')")
    @ApiOperation(value = "查看实验方案详情")
    @GetMapping(value = "/open/t-experiment-scheme/getDetailById")
    public R<TExperimentSchemeVO> getDetailById(@RequestParam String id) {
        TExperimentScheme experimentScheme = experimentSchemeService.getById(id);
        TExperimentSchemeVO experimentSchemeVO = new TExperimentSchemeVO();
        BeanUtils.copyProperties(experimentScheme, experimentSchemeVO);
 
        // 查询实验调度信息
        TExperimentDispatch experimentDispatch = experimentDispatchService.getById(experimentSchemeVO.getDispatchId());
        if(Objects.nonNull(experimentDispatch)){
            // 查询课题方案名称
            TProjectProposal projectProposal = projectProposalService.getById(experimentDispatch.getProposalId());
            if(Objects.nonNull(projectProposal)){
                experimentDispatch.setProjectName(projectProposal.getProjectName());
                experimentDispatch.setProjectCode(projectProposal.getProjectCode());
            }
        }
        experimentSchemeVO.setExperimentDispatch(experimentDispatch);
 
        // 查询组别
        List<TExperimentDispatchParticipants> list = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                .eq(TExperimentDispatchParticipants::getDispatchId, experimentSchemeVO.getDispatchId()));
        experimentSchemeVO.setExperimentDispatchParticipants(list);
 
        // 获取实验人员
        List<TExperimentSchemePerson> experimentSchemePersons = experimentSchemePersonService.list(Wrappers.lambdaQuery(TExperimentSchemePerson.class)
                .eq(TExperimentSchemePerson::getSchemeId, id));
        List<Long> userIds = experimentSchemePersons.stream().map(TExperimentSchemePerson::getUserId).collect(Collectors.toList());
        List<SysUser> sysUsers = sysUserMapper.selectUserByIds(userIds);
        sysUsers.forEach(sysUser -> {
            experimentSchemePersons.stream().filter(experimentSchemePerson -> experimentSchemePerson.getUserId().equals(sysUser.getUserId())).forEach(experimentSchemePerson -> {
                experimentSchemePerson.setNickName(sysUser.getNickName());
                experimentSchemePerson.setAvatar(sysUser.getAvatar());
            });
        });
        experimentSchemeVO.setExperimentSchemePersons(experimentSchemePersons);
 
        // 查询审核人姓名
        SysUser sysUser = sysUserService.selectUserById(experimentScheme.getAuditPersonId());
        if(Objects.nonNull(sysUser)){
            experimentSchemeVO.setAuditPersonName(sysUser.getNickName());
        }
 
        return R.ok(experimentSchemeVO);
    }
 
    /**
     * 删除实验方案
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:delete')")
    @Log(title = "实验方案信息-删除实验方案", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除实验方案")
    @DeleteMapping(value = "/open/t-experiment-scheme/deleteById")
    public R<Boolean> deleteById(@RequestParam String id) {
        // 删除试验方案人员
        experimentSchemePersonService.remove(Wrappers.lambdaQuery(TExperimentSchemePerson.class).eq(TExperimentSchemePerson::getSchemeId, id));
        return R.ok(experimentSchemeService.removeById(id));
    }
 
    /**
     * 批量删除实验方案
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:delete')")
    @Log(title = "实验方案信息-删除实验方案", businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量删除实验方案")
    @DeleteMapping(value = "/open/t-experiment-scheme/deleteByIds")
    public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
        // 删除试验方案人员
        experimentSchemePersonService.remove(Wrappers.lambdaQuery(TExperimentSchemePerson.class).in(TExperimentSchemePerson::getSchemeId, ids));
        return R.ok(experimentSchemeService.removeByIds(ids));
    }
 
    /**
     * 批量删除实验方案
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:sign')")
    @Log(title = "实验方案信息-申请中止实验", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "申请中止实验",response = ApplicationTerminationDTO.class)
    @PostMapping(value = "/api/t-experiment-scheme/applicationTermination")
    public R<Boolean> applicationTermination(@RequestBody String param) {
        ApplicationTerminationDTO applicationTerminationDTO = JSON.parseObject(param, ApplicationTerminationDTO.class);
        experimentSchemeService.update(Wrappers.lambdaUpdate(TExperimentScheme.class)
                .eq(TExperimentScheme::getId, applicationTerminationDTO.getId())
                .set(TExperimentScheme::getStatus, 2)
                .set(TExperimentScheme::getStopReason, applicationTerminationDTO.getStopReason())
                .set(TExperimentScheme::getStopFile, applicationTerminationDTO.getStopFile())
                .set(TExperimentScheme::getStopFileName, applicationTerminationDTO.getStopFileName())
                .set(TExperimentScheme::getCommitSign, applicationTerminationDTO.getCommitSign()));
        return R.ok();
    }
 
    /**
     * 批量删除实验方案
     */
    //@PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:audit')")
    @Log(title = "实验方案信息-申请中止实验审核", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "申请中止实验审核")
    @PostMapping(value = "/api/t-experiment-scheme/audit")
    public R<Boolean> audit(@RequestBody String param) {
        ApplicationTerminationAuditDTO applicationTerminationAuditDTO = JSON.parseObject(param, ApplicationTerminationAuditDTO.class);
        Long userId = tokenService.getLoginUser().getUserId();
        experimentSchemeService.update(Wrappers.lambdaUpdate(TExperimentScheme.class)
                .eq(TExperimentScheme::getId, applicationTerminationAuditDTO.getId())
                .set(TExperimentScheme::getStatus, applicationTerminationAuditDTO.getStatus())
                .set(TExperimentScheme::getAuditRemark, applicationTerminationAuditDTO.getAuditRemark())
                .set(TExperimentScheme::getAuditPersonId, userId)
                .set(TExperimentScheme::getAuditTime, LocalDateTime.now()));
        return R.ok();
    }
    
}