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
package com.yuanchu.limslaboratory.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.limslaboratory.mapper.*;
import com.yuanchu.limslaboratory.pojo.*;
import com.yuanchu.limslaboratory.pojo.dto.InspectionMaterialListDto;
import com.yuanchu.limslaboratory.service.InspectionMaterialListService;
import com.yuanchu.limslaboratory.service.InspectionProductListService;
import com.yuanchu.limslaboratory.service.PlanService;
import com.yuanchu.limslaboratory.vo.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-17
 */
@Service
public class InspectionMaterialListServiceImpl extends ServiceImpl<InspectionMaterialListMapper, InspectionMaterialList> implements InspectionMaterialListService {
 
    @Resource
    InspectionMaterialListMapper inspectionMaterialListMapper;
 
    @Resource
    ProductMapper productMapper;
 
    @Resource
    InspectionProductListService inspectionProductListService;
 
 
    //查询检验单里面的样品信息
    @Override
    public List<InspectionMaterialList> selectInspectionMaterialListByInsId(String insId) {
        return inspectionMaterialListMapper.selectInspectionMaterialListByInsId(insId);
    }
 
    //添加检验单中的检验样品
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addInspectionMaterialList(InspectionMaterialList inspectionMaterialList, String userId) {
           inspectionMaterialListMapper.insert(inspectionMaterialList);
            List<Product> list = productMapper.selectProductByMaterialId(inspectionMaterialList.getMaterialId());
            List<InspectionProductList> list1 = new ArrayList<>();
            list.forEach(a -> {
                InspectionProductList inspectionProductList = new InspectionProductList();
                inspectionProductList.setName(a.getName())
                        .setMethod(a.getMethod())
                        .setUnit(a.getUnit())
                        .setRequired(a.getRequired())
                        .setInternal(a.getInternal())
                        .setState(1)
                        .setInspectionMaterialListId(inspectionMaterialList.getId())
                        .setUserId(Integer.parseInt(userId));
                    list1.add(inspectionProductList);
            });
            //添加检验项目
            inspectionProductListService.saveBatch(list1);
    }
 
    //根据样品id删除检验样品
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delInspectionMaterialListByInsId(int inspectionMaterialListId) {
        //删除检验样品
        InspectionMaterialList list = new InspectionMaterialList();
        list.setState(0);
        list.setId(inspectionMaterialListId);
        inspectionMaterialListMapper.updateById(list);
        //根据样品id删除检验样品中的检验项目
        UpdateWrapper<InspectionProductList> wrapper = new UpdateWrapper<>();
        wrapper.eq("inspection_material_list_id", inspectionMaterialListId).set("state", 0);
        inspectionProductListService.update(new InspectionProductList(), wrapper);
    }
 
    //根据样品id修改样品信息
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateInspectionMaterialList(Integer inspectionMaterialListId, InspectionMaterialListDto inspectionMaterialListDto) {
        InspectionMaterialList inspectionMaterialList = new InspectionMaterialList();
        BeanUtils.copyProperties(inspectionMaterialListDto,inspectionMaterialList);
        LambdaUpdateWrapper<InspectionMaterialList> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(InspectionMaterialList::getId, inspectionMaterialListId);
        inspectionMaterialListMapper.update(inspectionMaterialList, updateWrapper);
    }
}