feat(base): 添加设备参数编号唯一性校验功能

- 在BaseDeviceParamMapper中新增countByParamCode方法用于校验参数编号唯一性
- 在BaseDeviceParamMapper.xml中添加对应的SQL查询语句
- 在insertBaseDeviceParam方法中添加参数编号唯一性校验逻辑
- 在updateBaseDeviceParam方法中添加参数编号唯一性校验逻辑
- 实现新增和更新时的参数编号重复检查机制
- 添加相应的异常处理和错误提示信息
master
zangch@mesnac.com 2 weeks ago
parent b8dda78f69
commit 4e8ab17d82

@ -1,6 +1,7 @@
package com.aucma.base.mapper; package com.aucma.base.mapper;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.aucma.base.domain.BaseDeviceParam; import com.aucma.base.domain.BaseDeviceParam;
/** /**
@ -67,6 +68,15 @@ public interface BaseDeviceParamMapper
*/ */
public List<BaseDeviceParam> selectByParamCodes(List<String> paramCodes); public List<BaseDeviceParam> selectByParamCodes(List<String> paramCodes);
/**
*
*
* @param paramCode
* @param excludeObjId 使
* @return
*/
public int countByParamCode(@Param("paramCode") String paramCode, @Param("excludeObjId") Long excludeObjId);
/** /**
* *
* *

@ -59,6 +59,14 @@ public class BaseDeviceParamServiceImpl implements IBaseDeviceParamService
@Override @Override
public int insertBaseDeviceParam(BaseDeviceParam baseDeviceParam) public int insertBaseDeviceParam(BaseDeviceParam baseDeviceParam)
{ {
String paramCode = baseDeviceParam.getParamCode();
int count = baseDeviceParamMapper.countByParamCode(paramCode, null);
System.out.println(count + paramCode);
// 校验参数编号唯一
if (count > 0)
{
throw new ServiceException("参数编号已存在:" + paramCode);
}
return baseDeviceParamMapper.insertBaseDeviceParam(baseDeviceParam); return baseDeviceParamMapper.insertBaseDeviceParam(baseDeviceParam);
} }
@ -71,6 +79,13 @@ public class BaseDeviceParamServiceImpl implements IBaseDeviceParamService
@Override @Override
public int updateBaseDeviceParam(BaseDeviceParam baseDeviceParam) public int updateBaseDeviceParam(BaseDeviceParam baseDeviceParam)
{ {
String paramCode = baseDeviceParam.getParamCode();
int count = baseDeviceParamMapper.countByParamCode(paramCode, baseDeviceParam.getObjId());
System.out.println(count + paramCode + baseDeviceParam.getObjId());
if (count > 0)
{
throw new ServiceException("参数编号已存在:" + baseDeviceParam.getParamCode());
}
return baseDeviceParamMapper.updateBaseDeviceParam(baseDeviceParam); return baseDeviceParamMapper.updateBaseDeviceParam(baseDeviceParam);
} }

@ -61,10 +61,26 @@
</where> </where>
</select> </select>
<select id="countByParamCode" resultType="int">
select count(1)
from base_deviceparam
where param_code = #{paramCode}
<if test="excludeObjId != null">
and obj_id &lt;&gt; #{excludeObjId}
</if>
</select>
<select id="selectBaseDeviceParamByObjId" parameterType="Long" resultMap="BaseDeviceParamResult"> <select id="selectBaseDeviceParamByObjId" parameterType="Long" resultMap="BaseDeviceParamResult">
<include refid="selectBaseDeviceParamVo"/> <include refid="selectBaseDeviceParamVo"/>
where dp.obj_id = #{objId} where dp.obj_id = #{objId}
</select> </select>
<select id="selectBaseDeviceParamByParamCode" parameterType="String" resultMap="BaseDeviceParamResult">
select dp.obj_id,
dp.param_code,
dp.param_name
from base_deviceparam dp
where dp.param_code = #{paramCode}
</select>
<insert id="insertBaseDeviceParam" parameterType="BaseDeviceParam"> <insert id="insertBaseDeviceParam" parameterType="BaseDeviceParam">
<selectKey keyProperty="objId" resultType="long" order="BEFORE"> <selectKey keyProperty="objId" resultType="long" order="BEFORE">

Loading…
Cancel
Save