无关风月
2025-06-10 d066ff34d052bd0597c69fec0b6bd3460bd0ac2b
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
package com.ruoyi.web.controller.api;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.domain.BaseModel;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.system.dto.TConfirmBreedingAndPreservationDTO;
import com.ruoyi.system.model.*;
 
import java.util.List;
 
 
import com.alibaba.fastjson.JSON;
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.TBreedingAndPreservationDTO;
import com.ruoyi.system.dto.TTrainLibraryDTO;
import com.ruoyi.system.query.TBreedingAndPreservationQuery;
import com.ruoyi.system.query.TPedigreeChartConfirmQuery;
import com.ruoyi.system.query.TPedigreeChartQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TBreedingAndPreservationDetailVO;
import com.ruoyi.system.vo.TBreedingAndPreservationVO;
import com.ruoyi.system.vo.TPedigreeChartVO;
import com.ruoyi.system.vo.TProjectTeamVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Random;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 菌种选育保藏记录 前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2025-04-12
 */
@RestController
@RequestMapping("")
@Api(tags = "菌种选育保藏记录")
public class TBreedingAndPreservationController {
    @Resource
    private TBreedingAndPreservationService breedingAndPreservationService;
    @Resource
    private TCulturePreservationService culturePreservationService;
    @Resource
    private TObservationOfPetriDishesService observationOfPetriDishesService;
    @Resource
    private TVaccinationSlopeService vaccinationSlopeService;
    @Resource
    private TSeparationOfCultureDishesService separationOfCultureDishesService;
    @Resource
    private TokenService tokenService;
    @Resource
    private ISysUserService sysUserService;
 
    /**
     * 菌种选育保藏记录分页列表
     */
    //@PreAuthorize("@ss.hasPermi('system:breedingAndPreservation:list')")
    @ApiOperation(value = "菌种选育保藏记录-获取菌种选育保藏记录分页列表",response = TBreedingAndPreservationQuery.class)
    @PostMapping(value = "/api/t-breeding-and-preservation/pageList")
    public R<PageInfo<TBreedingAndPreservationVO>> pageList(@RequestBody String param) {
        LoginUser loginUser = tokenService.getLoginUser();
        if (loginUser==null){
            return R.fail(401,"登录失效");
        }
        SysUser sysUser = sysUserService.selectUserById(loginUser.getUserId());
        TBreedingAndPreservationQuery query = JSON.parseObject(param, TBreedingAndPreservationQuery.class);
        return R.ok(breedingAndPreservationService.pageList(query));
    }
    /**
     * 新增菌种库
     */
    //@PreAuthorize("@ss.hasPermi('system:breedingAndPreservation:add')")
    @Log(title = "菌种选育保藏记录-新增选育保藏记录", businessType = BusinessType.INSERT)
    @ApiOperation(value = "菌种选育保藏记录-新增选育保藏记录",response = TBreedingAndPreservationDTO.class)
    @PostMapping(value = "/api/t-breeding-and-preservation/add")
    public R<Boolean> add(@RequestBody String param) {
        if (tokenService.getLoginUser()==null){
            return R.fail(401,"登陆失效");
        }
        TBreedingAndPreservationDTO dto = JSON.parseObject(param,TBreedingAndPreservationDTO.class);
        if (dto.getStatus()==3){
            dto.setIsDraft(1);
        }
        breedingAndPreservationService.save(dto);
        List<TSeparationOfCultureDishes> separationOfCultureDishesList = dto.getSeparationOfCultureDishesList();
        for (TSeparationOfCultureDishes tSeparationOfCultureDishes : separationOfCultureDishesList) {
            tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
        }
        separationOfCultureDishesService.saveBatch(separationOfCultureDishesList);
        List<TObservationOfPetriDishes> observationOfPetriDishes = dto.getObservationOfPetriDishes();
        for (TObservationOfPetriDishes tSeparationOfCultureDishes : observationOfPetriDishes) {
            tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
        }
        observationOfPetriDishesService.saveBatch(observationOfPetriDishes);
        List<TVaccinationSlope> vaccinationSlopes = dto.getVaccinationSlopes();
        for (TVaccinationSlope tSeparationOfCultureDishes : vaccinationSlopes) {
            tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
        }
        vaccinationSlopeService.saveBatch(vaccinationSlopes);
        List<TCulturePreservation> culturePreservations = dto.getCulturePreservations();
        for (TCulturePreservation tSeparationOfCultureDishes : culturePreservations) {
            tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
        }
        culturePreservationService.saveBatch(culturePreservations);
        if (dto.getStatus()!=null&&dto.getStatus()==2){
            // 新增消息
            TNotice tNotice = new TNotice();
            List<String> collect = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getUserId, tokenService.getLoginUser().getUserId())
                    .eq(TProjectTeamStaff::getRoleType, 2)
                    .list().stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
            TProjectTeam one = projectTeamService.lambdaQuery().in(TProjectTeam::getId, collect)
                    .eq(TProjectTeam::getStatus, 1)
                    .orderByDesc(BaseModel::getCreateTime).last("limit 1").one();
            TProjectTeamStaff one1 = projectTeamStaffService.lambdaQuery()
                    .eq(TProjectTeamStaff::getTeamId, one.getId()).eq(TProjectTeamStaff::getRoleType, 2).one();
            tNotice.setUserId(one1.getUserId());
 
            tNotice.setCommitId(tokenService.getLoginUser().getUserId()+"");
            tNotice.setStatus(1);
            tNotice.setNoticeContent("您有【1】条【菌种选育保藏记录】等待签字入库确认;");
            tNotice.setDataId(dto.getId());
            tNotice.setNoticeType(5);
            noticeService.save(tNotice);
        }
        return R.ok();
    }
    @Resource
    private TProjectTeamService projectTeamService;
    @Resource
    private TProjectTeamStaffService projectTeamStaffService;
    @Resource
    private TNoticeService noticeService;
    //@PreAuthorize("@ss.hasPermi('system:breedingAndPreservation:update')")
    @Log(title = "菌种选育保藏记录-编辑选育保藏记录", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "菌种选育保藏记录-编辑选育保藏记录",response = TBreedingAndPreservationDTO.class)
    @PostMapping(value = "/api/t-breeding-and-preservation/update")
    public R<Boolean> update(@RequestBody String param) {
        if (tokenService.getLoginUser()==null){
            return R.fail(401,"登陆失效");
        }
        TBreedingAndPreservationDTO dto = JSON.parseObject(param,TBreedingAndPreservationDTO.class);
        if (dto.getStatus()==3){
            dto.setIsDraft(1);
        }else{
            dto.setIsDraft(0);
        }
        breedingAndPreservationService.updateById(dto);
        List<TSeparationOfCultureDishes> separationOfCultureDishesList = dto.getSeparationOfCultureDishesList();
        for (TSeparationOfCultureDishes tSeparationOfCultureDishes : separationOfCultureDishesList) {
            tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
        }
        separationOfCultureDishesService.remove(new LambdaQueryWrapper<TSeparationOfCultureDishes>().eq(TSeparationOfCultureDishes::getBreedingPreserveId, dto.getId()));
        separationOfCultureDishesService.saveBatch(separationOfCultureDishesList);
        List<TObservationOfPetriDishes> observationOfPetriDishes = dto.getObservationOfPetriDishes();
        for (TObservationOfPetriDishes observationOfPetriDish : observationOfPetriDishes) {
            observationOfPetriDish.setBreedingPreserveId(dto.getId());
        }
        observationOfPetriDishesService.remove(new LambdaQueryWrapper<TObservationOfPetriDishes>().eq(TObservationOfPetriDishes::getBreedingPreserveId, dto.getId()));
        observationOfPetriDishesService.saveBatch(observationOfPetriDishes);
        List<TVaccinationSlope> vaccinationSlopes = dto.getVaccinationSlopes();
        for (TVaccinationSlope vaccinationSlope : vaccinationSlopes) {
            vaccinationSlope.setBreedingPreserveId(dto.getId());
        }
        vaccinationSlopeService.remove(new LambdaQueryWrapper<TVaccinationSlope>().eq(TVaccinationSlope::getBreedingPreserveId, dto.getId()));
        vaccinationSlopeService.saveBatch(vaccinationSlopes);
        List<TCulturePreservation> culturePreservations = dto.getCulturePreservations();
        for (TCulturePreservation tSeparationOfCultureDishes : culturePreservations) {
            tSeparationOfCultureDishes.setBreedingPreserveId(dto.getId());
        }
        culturePreservationService.remove(new LambdaQueryWrapper<TCulturePreservation>().eq(TCulturePreservation::getBreedingPreserveId, dto.getId()));
        culturePreservationService.saveBatch(culturePreservations);
        if (dto.getStatus()==2){
            // 新增消息
            TNotice tNotice = new TNotice();
            List<String> collect = projectTeamStaffService.lambdaQuery().eq(TProjectTeamStaff::getUserId, tokenService.getLoginUser().getUserId())
                    .eq(TProjectTeamStaff::getRoleType, 2)
                    .list().stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList());
            TProjectTeam one = projectTeamService.lambdaQuery().in(TProjectTeam::getId, collect)
                    .eq(TProjectTeam::getStatus, 1)
                    .orderByDesc(BaseModel::getCreateTime).last("limit 1").one();
            TProjectTeamStaff one1 = projectTeamStaffService.lambdaQuery()
                    .eq(TProjectTeamStaff::getTeamId, one.getId()).eq(TProjectTeamStaff::getRoleType, 2).one();
            tNotice.setUserId(one1.getUserId());
 
            tNotice.setCommitId(tokenService.getLoginUser().getUserId()+"");
            tNotice.setStatus(1);
            tNotice.setNoticeContent("您有【1】条【菌种选育保藏记录】等待签字入库确认;");
            tNotice.setDataId(dto.getId());
            tNotice.setNoticeType(6);
            noticeService.save(tNotice);
        }
        return R.ok();
    }
    @Log(title = "接种斜面记录确认入库", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "接种斜面记录确认入库",response = TConfirmBreedingAndPreservationDTO.class)
    @PostMapping(value = "/api/t-breeding-and-preservation/vaccinationSlopesConfirm")
    public R<Boolean> vaccinationSlopesConfirm(@RequestBody String param) {
        Long userId = tokenService.getLoginUser().getUserId();
 
        TConfirmBreedingAndPreservationDTO dto = JSON.parseObject(param,TConfirmBreedingAndPreservationDTO.class);
        TVaccinationSlope byId = vaccinationSlopeService.getById(dto.getId());
        byId.setPreserveId(userId+"");
        byId.setPreserveTime(LocalDateTime.now());
        byId.setPreserveSignature(dto.getPreserveSignature());
        vaccinationSlopeService.updateById(byId);
        return R.ok();
    }
    @Log(title = "菌种保藏记录确认入库", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "菌种保藏记录确认入库",response = TConfirmBreedingAndPreservationDTO.class)
    @PostMapping(value = "/api/t-breeding-and-preservation/culturePreservationsConfirm")
    public R<Boolean> culturePreservationsConfirm(@RequestBody String param) {
        Long userId = tokenService.getLoginUser().getUserId();
        TConfirmBreedingAndPreservationDTO dto = JSON.parseObject(param,TConfirmBreedingAndPreservationDTO.class);
        TCulturePreservation byId = culturePreservationService.getById(dto.getId());
        byId.setPreserveId(userId+"");
        byId.setPreserveTime(LocalDateTime.now());
        byId.setPreserveSignature(dto.getPreserveSignature());
        culturePreservationService.updateById(byId);
        return R.ok();
    }
    //@PreAuthorize("@ss.hasPermi('system:breedingAndPreservation:detail')")
    @ApiOperation(value = "选育保藏记录详情")
    @GetMapping(value = "/open/t-breeding-and-preservation/getDetailById")
    public R<TBreedingAndPreservationDetailVO> getDetailById(@RequestParam String id) {
        TBreedingAndPreservationDetailVO res = new TBreedingAndPreservationDetailVO();
        TBreedingAndPreservation breedingAndPreservation = breedingAndPreservationService.getById(id);
        BeanUtils.copyProperties(breedingAndPreservation, res);
        List<TSeparationOfCultureDishes> separationOfCultureDishesList = separationOfCultureDishesService.lambdaQuery().eq(TSeparationOfCultureDishes::getBreedingPreserveId, id).list();
        List<TObservationOfPetriDishes> observationOfPetriDishes = observationOfPetriDishesService.lambdaQuery().eq(TObservationOfPetriDishes::getBreedingPreserveId, id).list();
        List<TVaccinationSlope> vaccinationSlopes = vaccinationSlopeService.lambdaQuery().eq(TVaccinationSlope::getBreedingPreserveId, id).list();
        List<TCulturePreservation> culturePreservations = culturePreservationService.lambdaQuery().eq(TCulturePreservation::getBreedingPreserveId, id).list();
        res.setSeparationOfCultureDishesList(separationOfCultureDishesList);
        res.setObservationOfPetriDishes(observationOfPetriDishes);
        res.setVaccinationSlopes(vaccinationSlopes);
        res.setCulturePreservations(culturePreservations);
        return R.ok(res);
    }
//
//    @Log(title = "培养皿分离记录删除", businessType = BusinessType.DELETE)
//    @ApiOperation(value = "培养皿分离记录删除")
//    @DeleteMapping(value = "/open/t_project_team/deleteSeparationOfCultureDishes")
//    public R<Boolean> deleteSeparationOfCultureDishes(@RequestParam String id) {
//        return R.ok(separationOfCultureDishesService.removeById(id));
//    }
//    @Log(title = "培养皿生物学形态观察记录", businessType = BusinessType.DELETE)
//    @ApiOperation(value = "培养皿生物学形态观察记录删除")
//    @DeleteMapping(value = "/open/t_project_team/deleteObservationOfPetriDishes")
//    public R<Boolean> deleteObservationOfPetriDishes(@RequestParam String id) {
//
//        return R.ok(observationOfPetriDishesService.removeById(id));
//    }
//    @Log(title = "接种斜面记录删除", businessType = BusinessType.DELETE)
//    @ApiOperation(value = "接种斜面记录删除")
//    @DeleteMapping(value = "/open/t_project_team/deleteVaccinationSlope")
//    public R<Boolean> deleteVaccinationSlope(@RequestParam String id) {
//        TVaccinationSlope byId = vaccinationSlopeService.getById(id);
//        if (byId.getPreserveSignature()!=null){
//            return R.fail("菌种保藏人签字确认之后,不可删除");
//        }
//        return R.ok(vaccinationSlopeService.removeById(id));
//    }
//    @Log(title = "菌种保藏记录删除", businessType = BusinessType.DELETE)
//    @ApiOperation(value = "菌种保藏记录删除")
//    @DeleteMapping(value = "/open/t_project_team/deleteCulturePreservation")
//    public R<Boolean> deleteCulturePreservation(@RequestParam String id) {
//        TCulturePreservation byId = culturePreservationService.getById(id);
//        if (byId.getPreserveSignature()!=null){
//            return R.fail("菌种保藏人签字确认之后,不可删除");
//        }
//        return R.ok(culturePreservationService.removeById(id));
//    }
    @Log(title = "菌种保藏记录删除", businessType = BusinessType.DELETE)
    @ApiOperation(value = "菌种保藏记录删除")
    @DeleteMapping(value = "/open/t_project_team/deleteBreedingAndPreservation")
    public R<Boolean> deleteCulturePreservation(@RequestParam String id) {
        return R.ok(breedingAndPreservationService.removeById(id));
    }
}