XiaoRuby
2023-07-20 5341b151ccf051862c8f2adbeb02e82535a77d5e
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
package com.yuanchu.limslaboratory.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.limslaboratory.pojo.Standards;
import com.yuanchu.limslaboratory.mapper.StandardsMapper;
import com.yuanchu.limslaboratory.pojo.User;
import com.yuanchu.limslaboratory.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.limslaboratory.utils.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-11
 */
@Service
public class StandardsServiceImpl extends ServiceImpl<StandardsMapper, Standards> implements StandardsService {
 
    @Resource
    private StandardsMapper standardsMapper;
 
    @Autowired
    private UserService userService;
 
    @Lazy
    @Autowired
    private SerialNumberService serialNumberService;
 
    @Lazy
    @Autowired
    private SpecificationsService specificationsService;
 
    @Autowired
    private MaterialService materialService;
 
    @Autowired
    private ProductService productService;
 
    @Override
    public Integer addStandardsInformation(Standards standards) {
        Boolean userIsNull = userService.userIsNull(standards.getUserId());
        if (userIsNull){
            return standardsMapper.insert(standards);
        }
        return 0;
    }
 
    @Override
    public List<Map<String, Object>> listStandardsInformation() {
        LambdaQueryWrapper<Standards> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(Standards::getId, Standards::getName);
        List<Map<String, Object>> maps = standardsMapper.selectMaps(wrapper);
        for (Map<String, Object> map : maps){
            String id = map.get("id").toString();
            List<Map<String, Object>> serialNumberList = serialNumberService.selectIdSerialNumberInformation(id);
            if (ObjectUtils.isEmpty(serialNumberList)){
                map.put("serialNumber", null);
            } else {
                map.put("serialNumber", serialNumberList);
            }
        }
        return maps;
    }
 
    @Override
    public Boolean standardsIsNull(String Id) {
        LambdaQueryWrapper<Standards> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Standards::getId, Id);
        Standards standardsIsNull = standardsMapper.selectOne(wrapper);
        return !ObjectUtils.isEmpty(standardsIsNull);
    }
 
    @Override
    public IPage<Map<String, Object>> listPageStandardsInformation(Page<Object> page, String idOrNameOfStandards) {
        return standardsMapper.listPageStandardsInformation(page, idOrNameOfStandards);
    }
 
    @Override
    public Integer updateStandardsInformation(Standards standards) {
        return standardsMapper.updateById(standards);
    }
 
    @Override
    public Integer deleteStandardsInformation(String standardsId) {
        LambdaUpdateWrapper<Standards> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(Standards::getId, standardsId);
        updateWrapper.set(Standards::getState, 0);
        int isDeleteSuccess = standardsMapper.update(new Standards(), updateWrapper);
        if (isDeleteSuccess == 1){
            List<String> deleteSerialNumberId = serialNumberService.StandardsIdDeleteSerialNumber(standardsId);
            if (!ObjectUtils.isEmpty(deleteSerialNumberId)){
                List<Integer> deleteSpecificationsId = specificationsService.SerialNumberIdDeleteSpecifications(deleteSerialNumberId);
                if (!ObjectUtils.isEmpty(deleteSpecificationsId)){
                    List<String> deleteMaterialId = materialService.specificationsIdDeleteMaterial(deleteSpecificationsId);
                    if (!ObjectUtils.isEmpty(deleteMaterialId)){
                        productService.MaterialIdDeleteProduct(deleteMaterialId);
                    }
                }
            }
            return 1;
        }
        return 0;
    }
}