remove: 祛除attachMore相关处理
This commit is contained in:
parent
fbe3c40a79
commit
89e860c704
|
@ -31,11 +31,6 @@ public class CoreProperties {
|
|||
*/
|
||||
private boolean initSql = true;
|
||||
|
||||
/**
|
||||
* kv查询的长度
|
||||
*/
|
||||
private Integer kvLimitCount = 100;
|
||||
|
||||
public boolean isInitSql() {
|
||||
return initSql;
|
||||
}
|
||||
|
@ -43,12 +38,4 @@ public class CoreProperties {
|
|||
public void setInitSql(boolean initSql) {
|
||||
this.initSql = initSql;
|
||||
}
|
||||
|
||||
public Integer getKvLimitCount() {
|
||||
return kvLimitCount;
|
||||
}
|
||||
|
||||
public void setKvLimitCount(Integer kvLimitCount) {
|
||||
this.kvLimitCount = kvLimitCount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
package com.diboot.core.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.diboot.core.binding.parser.ParserCache;
|
||||
import com.diboot.core.config.BaseConfig;
|
||||
import com.diboot.core.dto.AttachMoreDTO;
|
||||
import com.diboot.core.entity.Dictionary;
|
||||
import com.diboot.core.entity.ValidList;
|
||||
import com.diboot.core.service.BaseService;
|
||||
import com.diboot.core.service.DictionaryService;
|
||||
import com.diboot.core.util.BeanUtils;
|
||||
import com.diboot.core.util.ContextHelper;
|
||||
import com.diboot.core.util.S;
|
||||
import com.diboot.core.util.V;
|
||||
import com.diboot.core.vo.JsonResult;
|
||||
import com.diboot.core.vo.KeyValue;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 获取附加属性的通用接口
|
||||
*
|
||||
* @author : uu
|
||||
* @version : v2.0
|
||||
* @Date 2020/6/11 16:02
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/attachMore")
|
||||
public class AttachMoreController {
|
||||
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(AttachMoreController.class);
|
||||
|
||||
/**
|
||||
* 获取kvList的通用接口
|
||||
*
|
||||
* @param attachMoreDTOList
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
public JsonResult attachMore(@Valid @RequestBody ValidList<AttachMoreDTO> attachMoreDTOList) {
|
||||
Map<String, Object> result = new HashMap<>(16);
|
||||
String kvLimitCountStr = BaseConfig.getProperty("diboot.core.kv-limit-count", "100");
|
||||
Integer kvLimitCount = 100;
|
||||
try {
|
||||
kvLimitCount = Integer.valueOf(kvLimitCountStr);
|
||||
} catch (Exception e) {
|
||||
log.warn("diboot.core.kvLimitCount配置只能为整数,当前使用默认配置长度【100】", e);
|
||||
}
|
||||
for (AttachMoreDTO attachMoreDTO : attachMoreDTOList) {
|
||||
AttachMoreDTO.REF_TYPE type = attachMoreDTO.getType();
|
||||
if (type.equals(AttachMoreDTO.REF_TYPE.D)) {
|
||||
List<KeyValue> keyValueList = dictionaryService.getKeyValueList(
|
||||
Wrappers.query()
|
||||
.select(S.toSnakeCase(BeanUtils.convertToFieldName(Dictionary::getItemName)), S.toSnakeCase(BeanUtils.convertToFieldName(Dictionary::getItemValue)))
|
||||
.eq(S.toSnakeCase(BeanUtils.convertToFieldName(Dictionary::getType)), attachMoreDTO.getTarget())
|
||||
.gt(S.toSnakeCase(BeanUtils.convertToFieldName(Dictionary::getParentId)), 0)
|
||||
.last("limit " + kvLimitCount)
|
||||
);
|
||||
result.put(S.toLowerCaseCamel(attachMoreDTO.getTarget()) + "KvList", keyValueList);
|
||||
} else if (type.equals(AttachMoreDTO.REF_TYPE.T)) {
|
||||
String entityName = attachMoreDTO.getTarget();
|
||||
String entityClassName = S.capFirst(entityName);
|
||||
Class<?> entityClass = ParserCache.getEntityClassByEntityLowerCaseCamel(entityClassName);
|
||||
if (V.isEmpty(entityClass)) {
|
||||
log.warn("传递错误的实体类型:{}", attachMoreDTO.getTarget());
|
||||
continue;
|
||||
}
|
||||
String value = V.isEmpty(attachMoreDTO.getValue()) ? ContextHelper.getPrimaryKey(entityClass) : attachMoreDTO.getValue();
|
||||
String key = attachMoreDTO.getKey();
|
||||
if (V.isEmpty(key)) {
|
||||
for (Field field : entityClass.getDeclaredFields()) {
|
||||
if (V.equals(field.getType().getName(), String.class.getName())) {
|
||||
key = field.getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
BaseService baseService = ContextHelper.getBaseServiceByEntity(entityClass);
|
||||
List<KeyValue> keyValueList = baseService.getKeyValueList(
|
||||
Wrappers.query()
|
||||
.select(key, value)
|
||||
.last("limit " + kvLimitCount)
|
||||
);
|
||||
result.put(S.uncapFirst(entityName) + "KvList", keyValueList);
|
||||
} else {
|
||||
log.error("错误的加载绑定类型:{}", attachMoreDTO.getType());
|
||||
}
|
||||
}
|
||||
return JsonResult.OK(result);
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
package com.diboot.core.dto;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* attachMore 根据传递的格式,自动加载相关的kvList
|
||||
* <p>
|
||||
* [{type: 'T', target: 'category', value: 'id', key: 'name’}, {type: 'D', target: 'GENDER'}]
|
||||
*
|
||||
* @author : uu
|
||||
* @version : v2.0
|
||||
* @Date 2020/6/11 15:42
|
||||
*/
|
||||
public class AttachMoreDTO implements Serializable {
|
||||
/**
|
||||
* 关联类型
|
||||
*/
|
||||
public enum REF_TYPE {
|
||||
/**
|
||||
* 绑定的是对象
|
||||
*/
|
||||
T,
|
||||
/**
|
||||
* 绑定的是字典
|
||||
*/
|
||||
D
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的类型
|
||||
*/
|
||||
@NotNull(message = "绑定类型不能为空,且只能为:T或D类型!")
|
||||
private REF_TYPE type;
|
||||
|
||||
/**
|
||||
* 指向的实体类 或者 字典的type
|
||||
* <p>
|
||||
* 当{@link REF_TYPE#T} target指向实体的小驼峰命名
|
||||
* 当{@link REF_TYPE#D} target指向{@link com.diboot.core.entity.Dictionary#type}
|
||||
*/
|
||||
@NotNull(message = "查询类型不能为空!")
|
||||
private String target;
|
||||
|
||||
/**
|
||||
* 需要的key字段
|
||||
* 当{@link REF_TYPE#T} key为表中字段名称
|
||||
* 当{@link REF_TYPE#D} key为表中{@link com.diboot.core.entity.Dictionary#itemName}
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 需要查询的value字段
|
||||
* 当{@link REF_TYPE#T} key为表中字段名称
|
||||
* 当{@link REF_TYPE#D} key为表中{@link com.diboot.core.entity.Dictionary#itemValue}
|
||||
*/
|
||||
private String value;
|
||||
|
||||
public REF_TYPE getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(REF_TYPE type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(String target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue