zss
2023-07-27 0e1722e96e5483d560eda8f1cf96282955d4f224
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
package com.yuanchu.limslaboratory.service.impl;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yuanchu.limslaboratory.mapper.InspectionMaterialListMapper;
import com.yuanchu.limslaboratory.mapper.InspectionProductListMapper;
import com.yuanchu.limslaboratory.mapper.PlanMapper;
import com.yuanchu.limslaboratory.pojo.Inspection;
import com.yuanchu.limslaboratory.mapper.InspectionMapper;
import com.yuanchu.limslaboratory.pojo.InspectionMaterialList;
import com.yuanchu.limslaboratory.pojo.InspectionProductList;
import com.yuanchu.limslaboratory.pojo.Plan;
import com.yuanchu.limslaboratory.pojo.dto.InspectionDto;
import com.yuanchu.limslaboratory.service.InspectionProductListService;
import com.yuanchu.limslaboratory.service.InspectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
 
/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-17
 */
@Service
public class InspectionServiceImpl extends ServiceImpl<InspectionMapper, Inspection> implements InspectionService {
 
    @Resource
    private InspectionMapper inspectionMapper;
 
    @Resource
    private PlanMapper planMapper;
 
    @Resource
    InspectionMaterialListMapper inspectionMaterialListMapper;
 
    @Resource
    InspectionProductListService inspectionProductListService;
 
    //添加检验申请单
    @Override
    public Inspection addInspection(String userName, int type) {
        Inspection inspection = new Inspection(type, 0, 1, 1, userName);
        int judge = inspectionMapper.insert(inspection);
        return judge > 0 ? inspection : null;
    }
 
    //查询所有检验单列表
    @Override
    public List<InspectionDto> selectAllInspection(int pageSize, int countSize, Integer state) {
        return inspectionMapper.selectAllInspection((pageSize - 1) * countSize, pageSize * countSize, state);
    }
 
    //作废申请检验单
    @Override
    public void delInspectionByInsId(String inspectionId) {
        /*检验单作废*/
        Inspection inspection = inspectionMapper.selectById(inspectionId);
        inspection.setState(0);
        inspectionMapper.updateById(inspection);
        /*检验计划作废*/
        UpdateWrapper<Plan> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("inspection_id", inspectionId).set("state", 0);
        planMapper.update(new Plan(), updateWrapper);
        /*检验样品作废(根据报检单id删除样品信息)*/
        UpdateWrapper<InspectionMaterialList> wrapper1 = new UpdateWrapper<>();
        wrapper1.eq("inspection_id", inspectionId).set("state", 0);
        inspectionMaterialListMapper.update(new InspectionMaterialList(), wrapper1);
        /*检验样品中的检验项目作废*/
        //查出检验样品id
        LambdaQueryWrapper<InspectionMaterialList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(InspectionMaterialList::getInspectionId,inspectionId);
        List<InspectionMaterialList> inspectionMaterialLists = inspectionMaterialListMapper.selectList(queryWrapper);
        for (InspectionMaterialList inspectionMaterialList : inspectionMaterialLists) {
            UpdateWrapper<InspectionProductList> wrapper = new UpdateWrapper<>();
            wrapper.eq("inspection_material_list_id", inspectionMaterialList.getId()).set("state", 0);
            inspectionProductListService.update(new InspectionProductList(), wrapper);
        }
    }
 
    //提交申请检验单
    @Override
    public void subInspectionByInsId(String inspectionId) {
        Inspection inspection = inspectionMapper.selectById(inspectionId);
        //状态改为已提交2
        inspection.setState(2);
        inspectionMapper.updateById(inspection);
        //计划表新增
        Plan plan = Plan.builder().inspectionId(inspectionId).state(1).userId(inspection.getInspectUserId()).createTime(new Date()).build();
        planMapper.insert(plan);
    }
}