优化全局配置表的增删改查操作

This commit is contained in:
liuchengqian 2022-09-01 11:39:14 +08:00
parent f58dfb5274
commit 45d82fa088
3 changed files with 30 additions and 9 deletions

View File

@ -41,9 +41,10 @@ public class GlobalConfigurationController {
* 查询全局配置
*/
@GetMapping("/query")
public String queryGlobalConfiguration(@RequestParam(required = false, value = "id") Long id, @RequestParam(required = false, value = "key") String key, @RequestParam(required = false, value = "value") String value, @RequestParam(required = false, value = "remark") String remark) {
public String queryGlobalConfiguration(@RequestParam(required = false, value = "id") Long id, @RequestParam(required = false, value = "group") String group, @RequestParam(required = false, value = "key") String key, @RequestParam(required = false, value = "value") String value, @RequestParam(required = false, value = "remark") String remark) {
GlobalConfigurationEntity globalConfiguration = new GlobalConfigurationEntity();
globalConfiguration.setId(id);
globalConfiguration.setBelongGroup(group);
globalConfiguration.setKey(key);
globalConfiguration.setValue(value);
globalConfiguration.setRemark(remark);

View File

@ -18,6 +18,11 @@ public class GlobalConfigurationEntity implements Serializable {
@SequenceGenerator(name = "global_configuration_seq_gen", sequenceName = "global_configuration_id_seq", allocationSize = 1)
private Long id;
/**
* 全局配置项所属的组
*/
private String belongGroup;
/**
* 全局配置项的键
*/
@ -44,6 +49,14 @@ public class GlobalConfigurationEntity implements Serializable {
this.id = id;
}
public String getBelongGroup() {
return belongGroup;
}
public void setBelongGroup(String belongGroup) {
this.belongGroup = belongGroup;
}
public String getKey() {
return key;
}
@ -72,6 +85,7 @@ public class GlobalConfigurationEntity implements Serializable {
public String toString() {
return "GlobalConfigurationEntity{" +
"id=" + id +
", belongGroup='" + belongGroup + '\'' +
", key='" + key + '\'' +
", value='" + value + '\'' +
", remark='" + remark + '\'' +

View File

@ -33,20 +33,21 @@ public class GlobalConfigurationServiceImpl implements GlobalConfigurationServic
*/
@Override
public String insertGlobalConfiguration(GlobalConfigurationEntity globalConfiguration) {
final String belongGroup = LocalNullUtils.formatNullValue(globalConfiguration.getBelongGroup());
final String key = LocalNullUtils.formatNullValue(globalConfiguration.getKey());
final String value = LocalNullUtils.formatNullValue(globalConfiguration.getValue());
final String remark = LocalNullUtils.formatNullValue(globalConfiguration.getRemark());
if (TextUtils.isEmpty(belongGroup)) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "belongGroup不可为空", locale);
}
if (TextUtils.isEmpty(key)) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "key不可为空", locale);
}
if (TextUtils.isEmpty(value)) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "value不可为空", locale);
}
List<GlobalConfigurationEntity> duplicatedEntityList = globalConfigurationDao.findByKey(key);
if (duplicatedEntityList != null && duplicatedEntityList.size() > 0) {
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "key已存在", locale);
}
GlobalConfigurationEntity globalConfigurationEntity = new GlobalConfigurationEntity();
globalConfigurationEntity.setBelongGroup(belongGroup);
globalConfigurationEntity.setKey(key);
globalConfigurationEntity.setValue(value);
globalConfigurationEntity.setRemark(remark);
@ -84,20 +85,21 @@ public class GlobalConfigurationServiceImpl implements GlobalConfigurationServic
if (targetEntityOptional.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "id不存在", locale);
}
final String belongGroup = LocalNullUtils.formatNullValue(globalConfiguration.getBelongGroup());
final String key = LocalNullUtils.formatNullValue(globalConfiguration.getKey());
final String value = LocalNullUtils.formatNullValue(globalConfiguration.getValue());
final String remark = LocalNullUtils.formatNullValue(globalConfiguration.getRemark());
if (TextUtils.isEmpty(belongGroup)) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "belongGroup不可为空", locale);
}
if (TextUtils.isEmpty(key)) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "key不可为空", locale);
}
if (TextUtils.isEmpty(value)) {
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "value不可为空", locale);
}
List<GlobalConfigurationEntity> duplicatedEntityList = globalConfigurationDao.findByKey(key);
if (duplicatedEntityList != null && duplicatedEntityList.size() > 0) {
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "key已存在", locale);
}
GlobalConfigurationEntity targetEntity = targetEntityOptional.get();
targetEntity.setBelongGroup(belongGroup);
targetEntity.setKey(key);
targetEntity.setValue(value);
if (!TextUtils.isEmpty(remark)) {
@ -113,6 +115,7 @@ public class GlobalConfigurationServiceImpl implements GlobalConfigurationServic
@Override
public String queryGlobalConfiguration(GlobalConfigurationEntity globalConfiguration) {
final Long id = globalConfiguration.getId();
final String belongGroup = globalConfiguration.getBelongGroup();
final String key = globalConfiguration.getKey();
final String value = globalConfiguration.getValue();
final String remark = globalConfiguration.getRemark();
@ -121,6 +124,9 @@ public class GlobalConfigurationServiceImpl implements GlobalConfigurationServic
if (null != id) {
predicateList.add(criteriaBuilder.equal(root.get("id").as(Long.class), id));
}
if (!TextUtils.isEmpty(belongGroup)) {
predicateList.add(criteriaBuilder.like(root.get("belongGroup").as(String.class), "%" + belongGroup + "%"));
}
if (!TextUtils.isEmpty(key)) {
predicateList.add(criteriaBuilder.like(root.get("key").as(String.class), "%" + key + "%"));
}