Merge branch 'hhk' into main

main
HuangHuiKang 6 days ago
commit 3337c09132

@ -10,6 +10,8 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
public interface ErrorCodeConstants {
ErrorCode DEVICE_NOT_EXISTS = new ErrorCode(1_003_000_000, "设备不存在");
ErrorCode DEVICE_REFERENCES_EXIST = new ErrorCode(1_003_000_000, "存在设备已被引用,请先删除引用。");
ErrorCode DEVICE_EXISTS = new ErrorCode(1_003_000_000, "同名或同主题设备已存在");

@ -101,4 +101,7 @@ public interface DeviceMapper extends BaseMapperX<DeviceDO> {
DeviceOperationStatusRespVO getDeviceOperationalStatus();
int selectIsReference(@Param("deviceId") Long deviceId);
}

@ -108,8 +108,6 @@ public class DeviceServiceImpl implements DeviceService {
@Resource
private DeviceOperationRecordMapper deviceOperationRecordMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public DeviceDO createDevice(DeviceSaveReqVO createReqVO) {
@ -213,14 +211,26 @@ public class DeviceServiceImpl implements DeviceService {
for (Long id : ids) {
// 校验存在
validateDeviceExists(id);
//是否有引用
validateReference(id);
// // 删除
// deviceMapper.deleteById(id);
// 删除子表
deleteDeviceConcatByDeviceId(id);
}
deviceMapper.deleteByIds(ids);
}
private void validateReference(Long deviceId) {
int count = deviceMapper.selectIsReference(deviceId);
if (count > 0){
throw exception(DEVICE_REFERENCES_EXIST);
}
}
private void deleteDeviceConcatByDeviceId(Long id) {
LambdaQueryWrapper<DeviceContactModelDO> deviceContactModelDOLambdaQueryWrapper = new LambdaQueryWrapper<>();
deviceContactModelDOLambdaQueryWrapper.eq(DeviceContactModelDO::getDeviceId,id);

@ -122,4 +122,11 @@
order by mo.id desc
</select>
<select id="selectIsReference" resultType="java.lang.Integer">
select
count(1)
from mes_organization
where machine_id = #{deviceId}
and deleted = 0
</select>
</mapper>
Loading…
Cancel
Save