医院废弃物信息化管理平台
“mitao”
2025-12-24 3763145f34d7706923d55edc32f5cfbc8bc08b92
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
package cn.besteam.modules.medical.service.impl;
 
import cn.besteam.common.constant.CacheKey;
import cn.besteam.common.constant.CommonConstant;
import cn.besteam.common.constant.ErrorCode;
import cn.besteam.common.exception.BusinessException;
import cn.besteam.common.util.RedisUtil;
import cn.besteam.modules.medical.entity.MwDeviceAgentDevice;
import cn.besteam.modules.medical.mapper.MwDeviceAgentDeviceMapper;
import cn.besteam.modules.medical.service.IMwDeviceAgentDeviceService;
import cn.besteam.modules.medical.vo.MwDeviceAgentDeviceAddBatchVO;
import cn.besteam.modules.medical.vo.MwDeviceAgentDeviceExcelVO;
import cn.besteam.modules.medical.vo.MwDeviceAgentDeviceVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @Description: 设备代理商-设备
 * @author: besteam
 * @date: 2020-04-25
 * @version: V1.0
 */
@Service
public class MwDeviceAgentDeviceServiceImpl extends ServiceImpl<MwDeviceAgentDeviceMapper, MwDeviceAgentDevice> implements IMwDeviceAgentDeviceService {
 
    @Autowired
    private RedisUtil redisUtil;
 
    @Override
    public IPage getDeviceList(String name, Integer pageNo, Integer pageSize) {
 
        Page<MwDeviceAgentDeviceVO> page = new Page<>(pageNo, pageSize);
        List<MwDeviceAgentDeviceVO> deviceList = baseMapper.getDeviceList(page, name);
        page.setRecords(deviceList);
        return page;
    }
 
    @Override
    public boolean move(Integer id, Integer deviceAgentId) {
 
        MwDeviceAgentDevice mwDeviceAgentDevice = getById(id);
        if (mwDeviceAgentDevice == null) {
            throw new BusinessException(ErrorCode.MW_DEVICE_NOT_FOUND);
        }
        mwDeviceAgentDevice.setDeviceAgentId(deviceAgentId);
        return updateById(mwDeviceAgentDevice);
    }
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean moveBatch(String ids, Integer deviceAgentId) {
 
        String[] idArray = ids.split(",");
        for (String id : idArray) {
            MwDeviceAgentDevice mwDeviceAgentDevice = getById(Integer.parseInt(id));
            if (mwDeviceAgentDevice == null) {
                continue;
            }
            mwDeviceAgentDevice.setDeviceAgentId(deviceAgentId);
            updateById(mwDeviceAgentDevice);
        }
        return true;
    }
 
    @Override
    public boolean updateStatus(Integer id, Integer status) {
 
        if (status == null || status < 1 || status > 2) {
            throw new BusinessException(ErrorCode.MW_DEVICE_STATUS_INVALID);
        }
        MwDeviceAgentDevice mwDeviceAgentDevice = getById(id);
        if (mwDeviceAgentDevice == null) {
            throw new BusinessException(ErrorCode.MW_DEVICE_NOT_FOUND);
        }
        mwDeviceAgentDevice.setStatus(status);
        return updateById(mwDeviceAgentDevice);
    }
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateStatusBatch(String ids, Integer status) {
 
        if (status == null || status < 1 || status > 2) {
            throw new BusinessException(ErrorCode.MW_DEVICE_STATUS_INVALID);
        }
        String[] idArray = ids.split(",");
        for (String id : idArray) {
            MwDeviceAgentDevice mwDeviceAgentDevice = getById(Integer.parseInt(id));
            if (mwDeviceAgentDevice == null) {
                continue;
            }
            mwDeviceAgentDevice.setStatus(status);
            updateById(mwDeviceAgentDevice);
        }
        return true;
    }
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public MwDeviceAgentDeviceAddBatchVO addBatch(Integer deviceAgentId, String sns) {
 
        MwDeviceAgentDeviceAddBatchVO vo = new MwDeviceAgentDeviceAddBatchVO();
        List<String> saveList = new ArrayList<>();
        List<String> replicateList = new ArrayList<>();
        String[] snArray = sns.split("\\n");
        for (String sn : snArray) {
            MwDeviceAgentDevice device = getOne(new QueryWrapper<MwDeviceAgentDevice>().lambda().eq(MwDeviceAgentDevice::getSn, sn));
            if (device != null) {
                replicateList.add(sn);
                continue;
            }
            if (saveList.contains(sn)) {
                replicateList.add(sn);
                continue;
            }
            device = new MwDeviceAgentDevice();
            device.setStatus(CommonConstant.STATUS_NORMAL);
            device.setDeviceAgentId(deviceAgentId);
            device.setSn(sn);
            save(device);
            //
            saveList.add(sn);
        }
        vo.setSaveList(saveList);
        vo.setReplicateList(replicateList);
        return vo;
    }
 
    @Override
    public List<MwDeviceAgentDeviceExcelVO> getDeviceExcelList(Integer deviceAgentId) {
 
        return baseMapper.getDeviceExcelList(deviceAgentId);
    }
 
    @Override
    public Integer getDeviceValidateStatus() {
 
        Integer status = 1;
        if (!redisUtil.hasKey(CacheKey.getGlobalDeviceValidateStatusKey())) {
            redisUtil.set(CacheKey.getGlobalDeviceValidateStatusKey(), status, -1);
        } else {
            status = redisUtil.get(CacheKey.getGlobalDeviceValidateStatusKey());
        }
        return status;
    }
 
    @Override
    public boolean setDeviceValidateStatus(Integer status) {
 
        return redisUtil.set(CacheKey.getGlobalDeviceValidateStatusKey(), status, -1);
    }
 
}