feat: 批量新增字典数据
This commit is contained in:
@@ -46,6 +46,14 @@ public class DictDataController {
|
||||
return success(dictDataId);
|
||||
}
|
||||
|
||||
@PostMapping("/create-list")
|
||||
@Operation(summary = "批量新增字典数据")
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:create')")
|
||||
public CommonResult<List<Long>> createDictDataList(@Valid @RequestBody List<DictDataSaveReqVO> createReqVOList) {
|
||||
List<Long> dictDataIds = dictDataService.createDictDataList(createReqVOList);
|
||||
return success(dictDataIds);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "修改字典数据")
|
||||
@PreAuthorize("@ss.hasPermission('system:dict:update')")
|
||||
|
||||
@@ -24,6 +24,14 @@ public interface DictDataService {
|
||||
*/
|
||||
Long createDictData(DictDataSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 批量创建字典数据
|
||||
*
|
||||
* @param createReqVOList 字典数据信息列表
|
||||
* @return 字典数据编号列表
|
||||
*/
|
||||
List<Long> createDictDataList(List<DictDataSaveReqVO> createReqVOList);
|
||||
|
||||
/**
|
||||
* 更新字典数据
|
||||
*
|
||||
|
||||
@@ -14,11 +14,14 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.code.nl.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.code.nl.module.system.enums.ErrorCodeConstants.*;
|
||||
@@ -75,6 +78,27 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
return dictData.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<Long> createDictDataList(List<DictDataSaveReqVO> createReqVOList) {
|
||||
Set<String> valueSet = new HashSet<>();
|
||||
createReqVOList.forEach(createReqVO -> {
|
||||
// 校验字典类型有效
|
||||
validateDictTypeExists(createReqVO.getDictType());
|
||||
String valueKey = createReqVO.getDictType() + ":" + createReqVO.getValue();
|
||||
if (!valueSet.add(valueKey)) {
|
||||
throw exception(DICT_DATA_VALUE_DUPLICATE);
|
||||
}
|
||||
// 校验字典数据的值的唯一性
|
||||
validateDictDataValueUnique(null, createReqVO.getDictType(), createReqVO.getValue());
|
||||
});
|
||||
|
||||
// 批量插入字典数据
|
||||
List<DictDataDO> dictDataList = BeanUtils.toBean(createReqVOList, DictDataDO.class);
|
||||
dictDataMapper.insertBatch(dictDataList);
|
||||
return CollectionUtils.convertList(dictDataList, DictDataDO::getId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDictData(DictDataSaveReqVO updateReqVO) {
|
||||
// 校验自己存在
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
spring:
|
||||
cloud:
|
||||
nacos:
|
||||
server-addr: http://192.168.10.29:8848 # Nacos 服务器地址
|
||||
server-addr: http://192.168.81.193:8848 # Nacos 服务器地址
|
||||
username: # Nacos 账号
|
||||
password: # Nacos 密码
|
||||
discovery: # 【配置中心】配置项
|
||||
@@ -57,14 +57,14 @@ spring:
|
||||
primary: master
|
||||
datasource:
|
||||
master:
|
||||
url: jdbc:mysql://127.0.0.1:3306/huachuang_lms?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
|
||||
url: jdbc:mysql://192.168.81.193:3306/huachuang_lms_dev?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
|
||||
username: root
|
||||
password: 12356
|
||||
password: root123
|
||||
slave: # 模拟从库,可根据自己需要修改 # 模拟从库,可根据自己需要修改
|
||||
lazy: true # 开启懒加载,保证启动速度
|
||||
url: jdbc:mysql://127.0.0.1:3306/huachuang_lms?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
|
||||
url: jdbc:mysql://192.168.81.193:3306/huachuang_lms_dev?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
|
||||
username: root
|
||||
password: 12356
|
||||
password: root123
|
||||
|
||||
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
|
||||
data:
|
||||
@@ -95,9 +95,9 @@ spring:
|
||||
xxl:
|
||||
job:
|
||||
admin:
|
||||
addresses: http://192.168.10.29:8080/xxl-job-admin # 调度中心部署跟地址
|
||||
addresses: http://192.168.81.193:8080/xxl-job-admin # 调度中心部署跟地址
|
||||
executor:
|
||||
ip: 192.168.10.29
|
||||
ip: 192.168.81.193
|
||||
port: 9992
|
||||
|
||||
--- #################### 服务保障相关配置 ####################
|
||||
|
||||
Reference in New Issue
Block a user