车辆编号重复性校验

This commit is contained in:
cbs 2025-06-20 16:18:06 +08:00
parent a049eae075
commit 1ab7083c9e
3 changed files with 50 additions and 28 deletions

View File

@ -88,4 +88,8 @@ public interface RobotInformationMapper extends BaseMapperX<RobotInformationDO>
* @return
*/
List<RobotInformationDO> getListByMapId(@Param("mapId") Long mapId);
RobotInformationDO selectByRobotNoAndIdNotIn(@Param("robotNo") String robotNo, @Param("id") Long id);
RobotInformationDO selectByMacAndIdNotIn(@Param("macAddress") String macAddress,@Param("id") Long id);
}

View File

@ -184,20 +184,17 @@ public class RobotInformationServiceImpl extends ServiceImpl<RobotInformationMap
@Override
@Transactional(rollbackFor = Exception.class)
public Long createInformation(RobotInformationSaveReqVO createReqVO) {
//判断mac地址是否重复
RobotInformationDO existRobotMac = informationMapper.selectOne(new LambdaQueryWrapper<RobotInformationDO>()
.eq(RobotInformationDO::getMacAddress, createReqVO.getMacAddress())
.last("limit 1"));
if (ObjectUtil.isNotEmpty(existRobotMac)) {
RobotInformationDO existRobotInformationDO =
informationMapper.selectByMacAndIdNotIn(createReqVO.getMacAddress(),null);
if (ObjectUtil.isNotEmpty(existRobotInformationDO)) {
throw exception(ROBOT_MAC_ADDRESS_EXISTS);
}
//判断机器人编号
RobotInformationDO existRobotNo = informationMapper.selectOne(new LambdaQueryWrapper<RobotInformationDO>()
.eq(RobotInformationDO::getRobotNo, createReqVO.getRobotNo())
.last("limit 1"));
if (ObjectUtil.isNotEmpty(existRobotNo)) {
HashSet<String> set = new HashSet<>();
set.add(createReqVO.getRobotNo());
List<RobotInformationDO> robots = informationMapper.selectByRobotNos(set);
if (ObjectUtil.isNotEmpty(robots)) {
throw exception(ROBOT_ROBOT_NO_EXISTS);
}
@ -393,24 +390,22 @@ public class RobotInformationServiceImpl extends ServiceImpl<RobotInformationMap
}
}
//校验MAC地址
RobotInformationDO query = new RobotInformationDO();
query.setMacAddress(updateReqVO.getMacAddress());
List<RobotInformationDO> existRobot = informationMapper.queryAllByLimit(query);
boolean exist = existRobot.stream().anyMatch(v -> (v.getMacAddress().equals(updateReqVO.getMacAddress())
&& !v.getId().equals(updateReqVO.getId())));
if (exist) {
throw exception(ROBOT_MAC_ADDRESS_EXISTS);
if (!updateReqVO.getRobotNo().equals(robotInformationDO.getRobotNo())) {
RobotInformationDO existRobotInformationDO =
informationMapper.selectByRobotNoAndIdNotIn(updateReqVO.getRobotNo(),updateReqVO.getId());
if (ObjectUtil.isNotEmpty(existRobotInformationDO)) {
throw exception(ROBOT_ROBOT_NO_EXISTS);
}
}
//校验机器人编号
query.setMacAddress(null);
query.setRobotNo(updateReqVO.getRobotNo());
List<RobotInformationDO> existRobotNo = informationMapper.queryAllByLimit(query);
boolean robotNoExist = existRobotNo.stream().anyMatch(v -> (v.getRobotNo().equals(updateReqVO.getRobotNo())
&& !v.getId().equals(updateReqVO.getId())));
if (robotNoExist) {
throw exception(ROBOT_ROBOT_NO_EXISTS);
if (!updateReqVO.getMacAddress().equals(robotInformationDO.getMacAddress())) {
RobotInformationDO existRobotInformationDO =
informationMapper.selectByMacAndIdNotIn(updateReqVO.getMacAddress(),updateReqVO.getId());
if (ObjectUtil.isNotEmpty(existRobotInformationDO)) {
throw exception(ROBOT_MAC_ADDRESS_EXISTS);
}
}
//校验IP
RobotInformationDO existRobotIp = informationMapper.selectOne(new LambdaQueryWrapper<RobotInformationDO>()
.eq(RobotInformationDO::getRobotIp, updateReqVO.getRobotIp())

View File

@ -160,8 +160,7 @@
from
robot_information
where
deleted = '0'
and robot_no in
robot_no in
<foreach collection="robotNos" item="robotNo" index="index" open="(" close=")"
separator=",">
#{robotNo}
@ -199,4 +198,28 @@
</if>
</where>
</select>
<select id="selectByRobotNoAndIdNotIn"
resultType="cn.iocoder.yudao.module.system.dal.dataobject.robot.RobotInformationDO">
select
<include refid="base_sql"></include>
from
robot_information
where
robot_no = #{robotNo}
and id != #{id}
limit 1
</select>
<select id="selectByMacAndIdNotIn"
resultType="cn.iocoder.yudao.module.system.dal.dataobject.robot.RobotInformationDO">
select
<include refid="base_sql"></include>
from
robot_information
where
mac_address = #{macAddress}
<if test="id != null">
and id != #{id}
</if>
limit 1
</select>
</mapper>