数据字典重复值问题
This commit is contained in:
parent
c2bee1ceb9
commit
a45180e16d
|
|
@ -117,9 +117,8 @@ public class SysDictDataController extends BaseController
|
|||
return toAjax(dictDataService.insertDictData(dict));
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
return error("系统错误, " + e.getMessage());
|
||||
}
|
||||
return error("系统错误");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,9 +133,8 @@ public class SysDictDataController extends BaseController
|
|||
return toAjax(dictDataService.updateDictData(dict));
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
return error("系统错误, " + e.getMessage());
|
||||
}
|
||||
return error("系统错误");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.bonus.system.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.bonus.common.security.utils.DictUtils;
|
||||
|
|
@ -82,6 +84,9 @@ public class SysDictDataServiceImpl implements ISysDictDataService
|
|||
@Override
|
||||
public int insertDictData(SysDictData data)
|
||||
{
|
||||
if (checkIfDictValueOrLabelAreRepeat(data)) {
|
||||
throw new ServiceException("发现重复字典标签或字典键值");
|
||||
}
|
||||
int row = dictDataMapper.insertDictData(data);
|
||||
if (row > 0)
|
||||
{
|
||||
|
|
@ -100,6 +105,9 @@ public class SysDictDataServiceImpl implements ISysDictDataService
|
|||
@Override
|
||||
public int updateDictData(SysDictData data)
|
||||
{
|
||||
if (checkIfDictValueOrLabelAreRepeat(data)) {
|
||||
throw new ServiceException("发现重复字典标签或字典键值");
|
||||
}
|
||||
int row = dictDataMapper.updateDictData(data);
|
||||
if (row > 0)
|
||||
{
|
||||
|
|
@ -108,4 +116,21 @@ public class SysDictDataServiceImpl implements ISysDictDataService
|
|||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查同一个字典类型里是否有相同的字典键值和字典标签
|
||||
*
|
||||
* @param data 字典数据信息
|
||||
* @return 结果
|
||||
*/
|
||||
boolean checkIfDictValueOrLabelAreRepeat(SysDictData data) {
|
||||
boolean result = false;
|
||||
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
|
||||
for (SysDictData dictData : dictDatas) {
|
||||
if (dictData.getDictLabel().equals(data.getDictLabel()) || dictData.getDictValue().equals(data.getDictValue())) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue