提交 45045129 编写于 作者: sq3536's avatar sq3536

codelist接管

上级 ce59407e
......@@ -42,8 +42,10 @@ public class CacheRefreshAspect
if(obj instanceof DictCatalog)
{
String code=((DictCatalog) obj).getCode();
if(!StringUtils.isEmpty(code))
if(!StringUtils.isEmpty(code)) {
dictCoreService.resetDictCatalog(code);
dictCoreService.resetCodeListCatalog(code);
}
}
}
......
......@@ -3,6 +3,8 @@ package cn.ibizlab.core.dict.extensions.service;
import cn.ibizlab.core.dict.domain.DictCatalog;
import cn.ibizlab.core.dict.domain.DictOption;
import cn.ibizlab.core.dict.extensions.vo.Catalog;
import cn.ibizlab.core.dict.extensions.vo.CodeItem;
import cn.ibizlab.core.dict.extensions.vo.CodeList;
import cn.ibizlab.core.dict.extensions.vo.Option;
import cn.ibizlab.core.dict.service.IDictCatalogService;
import cn.ibizlab.core.dict.service.IDictOptionService;
......@@ -65,6 +67,39 @@ public class DictCoreService
}
@Cacheable( value="dictcatalog",key = "'codelist:'+#p0")
public CodeList getCodeListCatalog(String code)
{
CodeList catalog = new CodeList();
DictCatalog dictCatalog = dictCatalogService.getOne(Wrappers.<DictCatalog>query().eq("ccode",code));
catalog.setCode(dictCatalog.getCode()).setName(dictCatalog.getName());
List<CodeItem> list = new ArrayList<>();
optionService.list(Wrappers.<DictOption>query().eq("catalog_id",dictCatalog.getId()).orderByAsc("showorder")).forEach(item->{
Map<String,Object> extension = new HashMap<>();
if(!StringUtils.isEmpty(item.getExtension()))
extension = JSONObject.parseObject(item.getExtension(),Map.class);
list.add(new CodeItem().setValue(item.getValue()).setId(item.getValue())
.setDisabled(((item.getDisabled()!=null && item.getDisabled()==1)||(item.getExpired()!=null && item.getExpired()==1))?true:false)
.setFilter(item.getFilter()).setIconClass(item.getIconClass()).setLabel(item.getLabel()).setParent(item.getParent()).setExtension(extension)
);
});
List<CodeItem> codeItemTreeList = new ArrayList<CodeItem>();
codeItemTreeList = loopCodeItem(list, "");
catalog.setOptions(codeItemTreeList);
return catalog;
}
@CacheEvict(value="dictcatalog",key = "'codelist:'+#p0")
public void resetCodeListCatalog(String code)
{
}
public List<Option> loop(List<Option> listCodeItem, Object parentValue) {
List<Option> trees = new ArrayList<Option>();
for (Option codeItem : listCodeItem) {
......@@ -83,4 +118,22 @@ public class DictCoreService
return trees;
}
public List<CodeItem> loopCodeItem(List<CodeItem> listCodeItem, Object parentValue) {
List<CodeItem> trees = new ArrayList<CodeItem>();
for (CodeItem codeItem : listCodeItem) {
String codeItemParentValue = codeItem.getParent();
if (StringUtils.isEmpty(codeItemParentValue)) {
codeItemParentValue = "";
}
if (parentValue.equals(codeItemParentValue)) {
List<CodeItem> childCodeItem = loopCodeItem(listCodeItem, codeItem.getValue());
if (childCodeItem.size() > 0) {
codeItem.setChildren(childCodeItem);
}
trees.add(codeItem);
}
}
return trees;
}
}
......@@ -25,20 +25,8 @@ public class Catalog
private String code;
private String name;
@JSONField(name = "srfkey")
@JsonProperty("srfkey")
public String getSrfkey()
{
return code;
}
@JSONField(name = "emptytext")
@JsonProperty("emptytext")
public String getEmptytext()
{
return "";
}
@JSONField(name = "items")
@JsonProperty("items")
private List<Option> options = new ArrayList<>();
}
package cn.ibizlab.core.dict.extensions.vo;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.List;
import java.util.Map;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class CodeItem
{
private String id;
private Object value;
private String label;
@JSONField(name = "items")
@JsonProperty("items")
private List<CodeItem> children;
private String iconClass;
private String filter;
private Boolean disabled;
@JsonIgnore
@JSONField(serialize = false)
private String parent;
private Map<String,Object> extension;
@JSONField(name = "text")
@JsonProperty("text")
public String getText()
{
return label;
}
}
package cn.ibizlab.core.dict.extensions.vo;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.ArrayList;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class CodeList
{
@JSONField(name = "srfkey")
@JsonProperty("srfkey")
private String code;
private String name;
@JSONField(name = "emptytext")
@JsonProperty("emptytext")
public String getEmptytext()
{
return "";
}
@JSONField(name = "items")
@JsonProperty("items")
private List<CodeItem> options = new ArrayList<>();
}
......@@ -31,10 +31,4 @@ public class Option
private String parent;
private Map<String,Object> extension;
@JSONField(name = "text")
@JsonProperty("text")
public String getText()
{
return label;
}
}
......@@ -5,10 +5,12 @@ import cn.ibizlab.api.mapping.DictCatalogMapping;
import cn.ibizlab.core.dict.domain.DictCatalog;
import cn.ibizlab.core.dict.extensions.service.DictCoreService;
import cn.ibizlab.core.dict.extensions.vo.Catalog;
import cn.ibizlab.core.dict.extensions.vo.CodeList;
import cn.ibizlab.core.dict.extensions.vo.Option;
import cn.ibizlab.core.dict.filter.DictCatalogSearchContext;
import cn.ibizlab.core.dict.service.IDictCatalogService;
import cn.ibizlab.util.annotation.VersionCheck;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
......@@ -53,6 +55,13 @@ public class DictCoreResource {
return ResponseEntity.status(HttpStatus.OK).body(catalog.getOptions());
}
@RequestMapping(method = RequestMethod.GET, value = "/dictionarys/codelist/{code}")
public ResponseEntity<CodeList> getCodeList(@PathVariable("code") String code) {
CodeList catalog = dictCoreService.getCodeListCatalog(code);
return ResponseEntity.status(HttpStatus.OK).body(catalog);
}
@RequestMapping(method = RequestMethod.POST, value = "/dictionarys/catalogs")
public ResponseEntity<Boolean> save(@RequestBody DictCatalogDTO dictcatalogdto) {
return ResponseEntity.status(HttpStatus.OK).body(dictcatalogService.save(dictcatalogMapping.toDomain(dictcatalogdto)));
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册