|
|
@@ -12,10 +12,13 @@ import com.kym.entity.queryParams.DeviceQueryParams;
|
|
|
import com.kym.entity.vo.WashDeviceVo;
|
|
|
import com.kym.mapper.WashDeviceMapper;
|
|
|
import com.kym.service.DeviceConfigService;
|
|
|
+import com.kym.service.DeviceRelationService;
|
|
|
import com.kym.service.WashDeviceService;
|
|
|
import com.kym.service.WashOrderService;
|
|
|
+import com.kym.service.aliyun.lot.AliyunLotClient;
|
|
|
import com.kym.service.cache.KymCache;
|
|
|
import com.kym.service.mybatisplus.MyBaseServiceImpl;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -32,17 +35,20 @@ import java.util.stream.Collectors;
|
|
|
* @author skyline
|
|
|
* @since 2024-10-09
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class WashDeviceServiceImpl extends MyBaseServiceImpl<WashDeviceMapper, WashDevice> implements WashDeviceService {
|
|
|
|
|
|
private WashOrderService washOrderService;
|
|
|
|
|
|
-
|
|
|
private DeviceConfigService deviceConfigService;
|
|
|
|
|
|
- public WashDeviceServiceImpl(WashOrderService washOrderService, DeviceConfigService deviceConfigService) {
|
|
|
+ private DeviceRelationService deviceRelationService;
|
|
|
+
|
|
|
+ public WashDeviceServiceImpl(WashOrderService washOrderService, DeviceConfigService deviceConfigService, DeviceRelationService deviceRelationService) {
|
|
|
this.washOrderService = washOrderService;
|
|
|
this.deviceConfigService = deviceConfigService;
|
|
|
+ this.deviceRelationService = deviceRelationService;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -132,7 +138,17 @@ public class WashDeviceServiceImpl extends MyBaseServiceImpl<WashDeviceMapper, W
|
|
|
|
|
|
@Override
|
|
|
public void remove(long id) {
|
|
|
+ var device = getById(id);
|
|
|
+ CommUtil.asserts(device != null, "设备不存在");
|
|
|
|
|
|
+ try {
|
|
|
+ AliyunLotClient.deleteDevice(device.getProductKey(), device.getDeviceName());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("阿里云IoT删除设备失败(已忽略,继续清理本地数据): productKey={}, deviceName={}", device.getProductKey(), device.getDeviceName(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ deviceRelationService.removeByDevice(device.getProductKey(), device.getDeviceName());
|
|
|
+ super.removeById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -160,6 +176,10 @@ public class WashDeviceServiceImpl extends MyBaseServiceImpl<WashDeviceMapper, W
|
|
|
|
|
|
@Override
|
|
|
public void add(WashDevice device) {
|
|
|
+ // productKey 统一使用配置文件中的值,不接受前端传入
|
|
|
+ device.setProductKey(AliyunLotClient.getProductKey());
|
|
|
+ CommUtil.asserts(CommUtil.isNotEmptyAndNull(device.getDeviceName()), "设备名称不能为空");
|
|
|
+
|
|
|
Long count = lambdaQuery()
|
|
|
.eq(WashDevice::getStationId, device.getStationId())
|
|
|
.eq(WashDevice::getDeviceName, device.getDeviceName())
|
|
|
@@ -172,8 +192,15 @@ public class WashDeviceServiceImpl extends MyBaseServiceImpl<WashDeviceMapper, W
|
|
|
.count();
|
|
|
CommUtil.asserts(seqCount == 0, "该站点下工位序号已存在");
|
|
|
}
|
|
|
- save(device);
|
|
|
|
|
|
+ try {
|
|
|
+ AliyunLotClient.registerDevice(device.getProductKey(), device.getDeviceName());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("阿里云IoT注册设备失败: productKey={}, deviceName={}", device.getProductKey(), device.getDeviceName(), e);
|
|
|
+ throw new BusinessException("阿里云物联网平台注册设备失败: " + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ save(device);
|
|
|
}
|
|
|
|
|
|
@Override
|