zss
2023-08-17 4c521b8f1fcc538f59cc0001dcf6649b0dee4880
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
package com.yuanchu.mom.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.LambdaUpdateWrapper;
import com.yuanchu.mom.pojo.Device;
import com.yuanchu.mom.mapper.DeviceMapper;
import com.yuanchu.mom.pojo.RawInsProduct;
import com.yuanchu.mom.service.DeviceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.mom.service.RawInsProductService;
import com.yuanchu.mom.utils.MyUtil;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2023-07-31
 */
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService {
 
    @Resource
    private DeviceMapper deviceMapper;
 
    @Resource
    private RawInsProductService rawInsProductService;
 
    @Override
    public Map<String, Object> selectTechnology(String deviceGroup) {
        String[] split = deviceGroup.split("\\+");
        Map<String, Object> map = new HashMap<>();
        for (String str : split){
            LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(Device::getFather, str);
            wrapper.select(Device::getId, Device::getName);
            List<Map<String, Object>> maps = deviceMapper.selectMaps(wrapper);
            map.put("first", str);
            map.put("children", maps);
        }
        return map;
    }
 
    //查询所有设备
    @Override
    public List<Device> selectDevice() {
        return deviceMapper.selectList(new QueryWrapper<>());
    }
 
    //根据设备id获取设备名称
    @Override
    public String getDeviceNameById(Integer id) {
        Device device = deviceMapper.selectById(id);
       return device.getName();
    }
 
    @Override
    public Boolean addDevice(Device device) {
        int insert = deviceMapper.insert(device);
        if (insert == 1){
            LambdaUpdateWrapper<RawInsProduct> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(RawInsProduct::getId, device.getRawInsProductId());
            updateWrapper.set(RawInsProduct::getDeviceId, device.getId());
            return rawInsProductService.update(updateWrapper);
        }
 
        return false;
    }
 
    @Override
    public List<Map<String, Object>> deviceTwoTree(Integer type, String search_class) {
        return deviceMapper.deviceTwoTree(type, search_class);
    }
 
    @Override
    public List<Map<String, Object>> DevicePageList(String codeNameModel,Integer type, Integer deviceStatue, Integer deviceId, String fatherName) {
        return deviceMapper.DevicePageList(codeNameModel, type, deviceStatue, deviceId, fatherName);
    }
 
    @Override
    public Integer deviceDelete(Integer deviceId) {
        LambdaUpdateWrapper<Device> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(Device::getId, deviceId);
        updateWrapper.set(Device::getState, 0);
        return deviceMapper.update(new Device(), updateWrapper);
    }
 
    @Override
    public Integer deviceDeleteIdOrFather(Integer id, String deviceFather) {
        LambdaUpdateWrapper<Device> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(Device::getState, 0);
        if (id != null) {
            updateWrapper.eq(Device::getId, id);
        } else if (deviceFather != null) {
            updateWrapper.eq(Device::getFather, deviceFather);
        }
        return deviceMapper.update(new Device(), updateWrapper);
    }
 
    //根据分组查询设备名
    @Override
    public List<Map<String, Object>> getDeviceNameByGroup(String deviceGroup) {
        return deviceMapper.getDeviceNameByGroup(deviceGroup);
    }
}