xuhy
2025-04-25 b2690b02f12d529ec7bb45e059c6d2eef59b7f2c
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
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.ApplicationTerminationAuditDTO;
import com.ruoyi.system.dto.ApplicationTerminationDTO;
import com.ruoyi.system.dto.TExperimentSchemeDTO;
import com.ruoyi.system.dto.TestMethodConfirmSheetSignDTO;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
 
/**
 * <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;
    @Autowired
    public TExperimentSchemeController(TExperimentSchemeService experimentSchemeService, TokenService tokenService, ISysUserService sysUserService, SysUserMapper sysUserMapper, TExperimentSchemePersonService experimentSchemePersonService, TExperimentDispatchParticipantsService experimentDispatchParticipantsService, TExperimentDispatchService experimentDispatchService, TProjectProposalService projectProposalService) {
        this.experimentSchemeService = experimentSchemeService;
        this.tokenService = tokenService;
        this.sysUserService = sysUserService;
        this.sysUserMapper = sysUserMapper;
        this.experimentSchemePersonService = experimentSchemePersonService;
        this.experimentDispatchParticipantsService = experimentDispatchParticipantsService;
        this.experimentDispatchService = experimentDispatchService;
        this.projectProposalService = projectProposalService;
    }
 
    /**
     * 获取实验方案管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:testMethodConfirmSheet:list')")
    @ApiOperation(value = "获取实验方案分页列表")
    @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));
    }
 
    /**
     * 通过实验调度查询查询组别列表
     */
    @ApiOperation(value = "通过实验调度查询查询组别列表")
    @GetMapping(value = "/open/t-experiment-scheme/getGroupByDispatchId")
    public R<List<TExperimentDispatchParticipants>> getGroupByDispatchId(@RequestParam String dispatchId) {
        List<TExperimentDispatchParticipants> list = experimentDispatchParticipantsService.list(Wrappers.lambdaQuery(TExperimentDispatchParticipants.class)
                .eq(TExperimentDispatchParticipants::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: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());
            }
        }
        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));
        experimentSchemeVO.setExperimentSchemePersons(experimentSchemePersons);
 
        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 = "申请中止实验")
    @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();
    }
    
}