Browse Source

编辑管理员地区优化与校验

huangqizheng/feature-20250717200321-优化导出
lijianlin 1 month ago
parent
commit
07530f1976
  1. 14
      src/main/java/com/example/demo/serviceImpl/PermissionServiceImpl.java
  2. 2
      src/main/resources/mapper/PermissionMapper.xml

14
src/main/java/com/example/demo/serviceImpl/PermissionServiceImpl.java

@ -71,7 +71,8 @@ public class PermissionServiceImpl implements PermissionService {
throw new Exception("地区为空!"); throw new Exception("地区为空!");
} }
if (admin.getMarket().contains("总部") && admin.getMarket().size() > 1) { if (admin.getMarket().contains("总部") && admin.getMarket().size() > 1) {
throw new Exception("总部不可与其他地区共存");}
throw new Exception("总部不可与其他地区共存");
}
if (ObjectUtils.isEmpty(admin.getPostiton())) { if (ObjectUtils.isEmpty(admin.getPostiton())) {
throw new Exception("职位为空!"); throw new Exception("职位为空!");
} }
@ -142,14 +143,14 @@ public class PermissionServiceImpl implements PermissionService {
if (ObjectUtils.isEmpty(adminVo.getMarket())) { if (ObjectUtils.isEmpty(adminVo.getMarket())) {
throw new Exception("地区为空!"); throw new Exception("地区为空!");
} }
if (adminVo.getMarket().contains("总部") && adminVo.getMarket().size() > 1) {
throw new Exception("总部不可与其他地区共存");
}
// 校验职位是否为空管理员职位为必填项 // 校验职位是否为空管理员职位为必填项
if (ObjectUtils.isEmpty(adminVo.getPostiton())) { if (ObjectUtils.isEmpty(adminVo.getPostiton())) {
throw new Exception("职位为空!"); throw new Exception("职位为空!");
} }
// 校验机器编号是否为空机器编号为必填项
if (ObjectUtils.isEmpty(adminVo.getMachineId())) {
throw new Exception("机器编号为空!");
}
// 校验机器编号格式不允许包含逗号避免与后续拼接逻辑冲突 // 校验机器编号格式不允许包含逗号避免与后续拼接逻辑冲突
if (adminVo.getMachineId().contains(",")) { if (adminVo.getMachineId().contains(",")) {
throw new Exception("机器编号格式错误"); throw new Exception("机器编号格式错误");
@ -159,6 +160,9 @@ public class PermissionServiceImpl implements PermissionService {
admin.setAdminName(adminVo.getAdminName()); admin.setAdminName(adminVo.getAdminName());
admin.setMarket(adminVo.getMarket()); admin.setMarket(adminVo.getMarket());
admin.setPostiton(adminVo.getPostiton()); admin.setPostiton(adminVo.getPostiton());
// 将地区列表转换为逗号分隔的字符串
String markets = String.join(",", admin.getMarket());
admin.setMarket(Collections.singletonList(markets));
// 处理机器编号若存在额外机器编号machineIds则与原编号拼接用逗号分隔 // 处理机器编号若存在额外机器编号machineIds则与原编号拼接用逗号分隔
if (adminVo.getMachineIds() == null) { if (adminVo.getMachineIds() == null) {
admin.setMachineId(adminVo.getMachineId()); admin.setMachineId(adminVo.getMachineId());

2
src/main/resources/mapper/PermissionMapper.xml

@ -43,7 +43,7 @@
<if test="remark!=null"> <if test="remark!=null">
remark= #{remark}, remark= #{remark},
</if> </if>
market= #{market}
market= #{market[0]}
</set> </set>
where account= #{account} where account= #{account}
</update> </update>

Loading…
Cancel
Save