fix:设备管理模块-新增编码重复问题

main
HuangHuiKang 23 hours ago
parent 50081338d9
commit 628311098b

@ -38,9 +38,15 @@ public interface ErrorCodeConstants {
//======================================数据采集相关=================================================
ErrorCode DEVICE_MODEL_NOT_EXISTS = new ErrorCode(1_003_000_001, "采集设备模型不存在");
ErrorCode DEVICE_MODEL_CODE_EXISTS = new ErrorCode(1_003_000_002, "采集设备模型编码已存在");
ErrorCode DEVICE_CODE_ALREADY_EXISTS = new ErrorCode(1_003_000_002, "采集设备编码已存在");
ErrorCode DEVICE_ID_MODEL_NOT_EXISTS = new ErrorCode(1_003_000_003, "该设备模型ID不能为空");
ErrorCode POINT_ID_MODEL_NOT_EXISTS = new ErrorCode(1_003_000_004, "该点位参数ID不能为空");
ErrorCode DEVICE_MODEL_ATTRIBUTE_NOT_EXISTS = new ErrorCode(1_003_000_005, "采集设备模型点位不存在");
ErrorCode DEVICE_MODEL_POINT_CODE_EXISTS = new ErrorCode(1_003_000_005, "采集设备采集点位编码已存在");
ErrorCode DEVICE_MODEL_ATTRIBUTE_POTIN_CODE_EXISTS = new ErrorCode(1_003_000_005, "采集设备模型点位编码已存在");
ErrorCode DEVICE_ATTRIBUTE_NOT_EXISTS = new ErrorCode(1_003_000_006, "设备属性不存在");
ErrorCode DEVICE_ATTRIBUTE_TYPE_NOT_EXISTS = new ErrorCode(1_003_000_007, "采集点分类不存在");
ErrorCode DEVICE_CODE_EXISTS = new ErrorCode(1_003_000_000, "采集点编码已存在");

@ -111,13 +111,23 @@ public class DeviceServiceImpl implements DeviceService {
@Override
@Transactional(rollbackFor = Exception.class)
public DeviceDO createDevice(DeviceSaveReqVO createReqVO) {
if(StringUtils.isNotBlank(createReqVO.getReadTopic())){
DeviceDO temp = deviceMapper.selectByTopic(createReqVO.getReadTopic());
if (temp!=null){
throw exception(DEVICE_EXISTS);
}
// if(StringUtils.isNotBlank(createReqVO.getReadTopic())){
// DeviceDO temp = deviceMapper.selectByTopic(createReqVO.getReadTopic());
// if (temp!=null){
// throw exception(DEVICE_EXISTS);
// }
// }
//判断编码是否唯一
boolean exists = deviceMapper.exists(
Wrappers.<DeviceDO>lambdaQuery()
.eq(DeviceDO::getDeviceCode, createReqVO.getDeviceCode()));
if (exists) {
throw exception(DEVICE_CODE_ALREADY_EXISTS);
}
DeviceModelDO deviceModelDO = deviceModelMapper.selectById(createReqVO.getDeviceModelId());
// 插入

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.iot.service.devicecontactmodel;
import cn.iocoder.yudao.module.iot.dal.dataobject.devicecontactmodel.DeviceContactModelDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.devicemodelattribute.DeviceModelAttributeDO;
import cn.iocoder.yudao.module.iot.dal.mysql.deviceattributetype.DeviceAttributeTypeMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
@ -17,6 +18,8 @@ import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.DEVICE_CONTACT_MODEL_NOT_EXISTS;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_MODEL_ATTRIBUTE_POTIN_CODE_EXISTS;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_MODEL_POINT_CODE_EXISTS;
/**
* - Service
@ -34,6 +37,18 @@ public class DeviceContactModelServiceImpl implements DeviceContactModelService
@Override
public Long createDeviceContactModel(DeviceContactModelSaveReqVO createReqVO) {
//判断编码是否唯一
boolean exists = deviceContactModelMapper.exists(
Wrappers.<DeviceContactModelDO>lambdaQuery()
.eq(DeviceContactModelDO::getDeviceId, createReqVO.getDeviceId())
.eq(DeviceContactModelDO::getAttributeCode, createReqVO.getAttributeCode()));
if (exists) {
throw exception(DEVICE_MODEL_POINT_CODE_EXISTS);
}
// 插入
DeviceContactModelDO deviceContactModel = BeanUtils.toBean(createReqVO, DeviceContactModelDO.class);
// deviceContactModel.setTypeName(deviceAttributeTypeMapper.selectById(createReqVO.getAttributeCode()).getName());

@ -50,7 +50,18 @@ public class DeviceModelAttributeServiceImpl implements DeviceModelAttributeServ
@Override
public Long createDeviceModelAttribute(DeviceModelAttributeSaveReqVO createReqVO) {
// 插入
//判断编码是否唯一
boolean exists = deviceModelAttributeMapper.exists(
Wrappers.<DeviceModelAttributeDO>lambdaQuery()
.eq(DeviceModelAttributeDO::getDeviceModelId, createReqVO.getDeviceModelId())
.eq(DeviceModelAttributeDO::getAttributeCode, createReqVO.getAttributeCode()));
if (exists) {
throw exception(DEVICE_MODEL_ATTRIBUTE_POTIN_CODE_EXISTS);
}
// 插入
DeviceModelAttributeDO deviceModelAttribute = BeanUtils.toBean(createReqVO, DeviceModelAttributeDO.class);
// deviceModelAttribute.setTypeName(deviceAttributeTypeMapper.selectById(createReqVO.getAttributeCode()).getName());
deviceModelAttributeMapper.insert(deviceModelAttribute);

@ -147,6 +147,8 @@ public interface ErrorCodeConstants {
ErrorCode TICKET_RESULTS_NOT_EXISTS = new ErrorCode(1002000013, "工单检验结果不存在");
ErrorCode TICKET_RESULTS_ID_NOT_NULL = new ErrorCode(1002000014, "工单检验结果Id不存在");
ErrorCode CRITICAL_COMPONENT_NOT_EXISTS = new ErrorCode(1002000015, "设备关键件不存在");
ErrorCode CRITICAL_COMPONENT_CODE_EXISTS = new ErrorCode(1002000015, "设备关键件编码已存在");
ErrorCode CRITICAL_COMPONENT_REFERENCES= new ErrorCode(1002000015, "存在设备关键件已被引用,请先删除引用");
ErrorCode REPAIR_TEMS_NOT_EXISTS = new ErrorCode(1002000016, "维修项目不存在");

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.mes.service.criticalcomponent;
import cn.iocoder.yudao.module.iot.dal.dataobject.devicemodelattribute.DeviceModelAttributeDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.repairtems.RepairTemsDO;
import cn.iocoder.yudao.module.mes.dal.mysql.deviceledger.DeviceLedgerMapper;
@ -22,6 +23,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.dal.mysql.criticalcomponent.CriticalComponentMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_MODEL_ATTRIBUTE_POTIN_CODE_EXISTS;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
/**
@ -45,6 +47,18 @@ public class CriticalComponentServiceImpl implements CriticalComponentService {
@Override
public Long createCriticalComponent(CriticalComponentSaveReqVO createReqVO) {
//判断编码是否唯一
boolean exists = criticalComponentMapper.exists(
Wrappers.<CriticalComponentDO>lambdaQuery()
.eq(CriticalComponentDO::getCode, createReqVO.getCode()));
if (exists) {
throw exception(CRITICAL_COMPONENT_CODE_EXISTS);
}
// 插入
CriticalComponentDO criticalComponent = BeanUtils.toBean(createReqVO, CriticalComponentDO.class);
criticalComponentMapper.insert(criticalComponent);

@ -56,11 +56,12 @@ public class DvRepairServiceImpl implements DvRepairService {
createReqVO.setRepairCode(autoCodeUtil.genSerialCode("DVR_CODE",null));
} else {
//编码重复判断
Long count = dvRepairMapper.selectCount(new LambdaQueryWrapper<DvRepairDO>()
boolean exists = dvRepairMapper.exists(
Wrappers.<DvRepairDO>lambdaQuery()
.eq(DvRepairDO::getRepairCode, createReqVO.getRepairCode())
);
if (count > 0) {
if (exists) {
throw exception(DV_REPAIR_CODE_EXISTS);
}
}

@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.mes.dal.mysql.deviceledger.DeviceLedgerMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -52,11 +53,11 @@ public class RepairTemsServiceImpl implements RepairTemsService {
@Override
public Long createRepairTems(RepairTemsSaveReqVO createReqVO) {
//编码重复判断
Long count = repairTemsMapper.selectCount(new LambdaQueryWrapper<RepairTemsDO>()
boolean exists = repairTemsMapper.exists(Wrappers.<RepairTemsDO>lambdaQuery()
.eq(RepairTemsDO::getSubjectCode, createReqVO.getSubjectCode())
);
if (count > 0) {
if (exists) {
throw exception(REPAIR_TEMS_CODE_EXISTS);
}

Loading…
Cancel
Save