Commit 20401a58 by xmh

<feat> 通道名称相同时加前缀

1 parent 8546da38
......@@ -58,7 +58,7 @@ public class ChannelController extends ChannelBaseController {
return JsonMessageUtil.getSuccessJsonMsg(channelService.add(channelVo));
} catch (DuplicateKeyException e) {
log.error("", e);
return JsonMessageUtil.getErrorJsonMsg("设备编号或名称重复");
return JsonMessageUtil.getErrorJsonMsg("设备编号重复");
}
}
......
package com.viontech.fanxing.ops.service.impl;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.base.BaseExample;
......@@ -72,6 +73,15 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
return insertSelective(channelVo);
}
@Override
public Channel insertSelective(Channel record) {
String name = record.getName();
while (duplicateName(record.getName())) {
record.setName(RandomUtil.randomString(6) + name);
}
return super.insertSelective(record);
}
@Transactional(rollbackFor = Exception.class)
@Override
public ChannelVo update(long id, ChannelVo vo) {
......@@ -213,6 +223,13 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
return false;
}
private boolean duplicateName(String name) {
ChannelExample channelExample = new ChannelExample();
channelExample.createCriteria().andNameEqualTo(name);
List<Channel> channels = selectByExample(channelExample);
return channels.size() > 0;
}
/**
* 拉取 nvs3000 视频资源
*/
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!