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

代码表

上级 1e074cf1
......@@ -117,6 +117,7 @@ public class webSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/"+downloadpath+"/**").permitAll()
.antMatchers("/"+uploadpath).permitAll()
.antMatchers("/"+previewpath+"/**").permitAll()
.antMatchers("/dictionarys/**").permitAll()
// 所有请求都需要认证
.anyRequest().authenticated()
// 防止iframe 造成跨域
......
......@@ -114,6 +114,7 @@ public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/"+downloadpath+"/**").permitAll()
.antMatchers("/"+uploadpath).permitAll()
.antMatchers("/"+previewpath+"/**").permitAll()
.antMatchers("/dictionarys/**").permitAll()
.anyRequest().authenticated()
// 防止iframe 造成跨域
.and().headers().frameOptions().disable();
......
package cn.ibizlab.core.dict.extensions.aspect;
import cn.ibizlab.core.dict.domain.DictCatalog;
import cn.ibizlab.core.dict.extensions.service.DictCoreService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@Aspect
@Order(0)
@Component
public class CacheRefreshAspect
{
@Autowired
@Lazy
private DictCoreService dictCoreService;
@Before(value = "execution(* cn.ibizlab.core.dict.service.IDictCatalogService.update(..))")
public void BeforeUpdateEmp(JoinPoint point) throws Exception {
refreshDictCache(point);
}
@Before(value = "execution(* cn.ibizlab.core.dict.service.IDictCatalogService.save(..))")
public void BeforeSaveEmp(JoinPoint point) throws Exception {
refreshDictCache(point);
}
private void refreshDictCache(JoinPoint point)
{
Object[] args = point.getArgs();
if (args.length > 0)
{
Object obj = args[0];
if(obj instanceof DictCatalog)
{
String code=((DictCatalog) obj).getCode();
if(!StringUtils.isEmpty(code))
dictCoreService.resetDictCatalog(code);
}
}
}
}
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.Option;
import cn.ibizlab.core.dict.service.IDictCatalogService;
import cn.ibizlab.core.dict.service.IDictOptionService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@Service
public class DictCoreService
{
@Autowired
private IDictCatalogService dictCatalogService;
@Autowired
private IDictOptionService optionService;
@Cacheable( value="dictcatalog",key = "'dict:'+#p0")
public Catalog getDictCatalog(String code)
{
Catalog catalog = new Catalog();
DictCatalog dictCatalog = dictCatalogService.getOne(Wrappers.<DictCatalog>query().eq("ccode",code));
catalog.setCode(dictCatalog.getCode()).setName(dictCatalog.getName());
List<Option> 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 Option().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<Option> codeItemTreeList = new ArrayList<Option>();
codeItemTreeList = loop(list, "");
catalog.setOptions(codeItemTreeList);
return catalog;
}
@CacheEvict(value="dictcatalog",key = "'dict:'+#p0")
public void resetDictCatalog(String code)
{
}
public List<Option> loop(List<Option> listCodeItem, Object parentValue) {
List<Option> trees = new ArrayList<Option>();
for (Option codeItem : listCodeItem) {
String codeItemParentValue = codeItem.getParent();
if (StringUtils.isEmpty(codeItemParentValue)) {
codeItemParentValue = "";
}
if (parentValue.equals(codeItemParentValue)) {
List<Option> childCodeItem = loop(listCodeItem, codeItem.getValue());
if (childCodeItem.size() > 0) {
codeItem.setChildren(childCodeItem);
}
trees.add(codeItem);
}
}
return trees;
}
}
package cn.ibizlab.core.dict.extensions.vo;
import cn.ibizlab.util.annotation.DEField;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
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;
import java.util.Map;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
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 "";
}
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;
......@@ -23,5 +26,15 @@ public class Option
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;
}
}
......@@ -119,6 +119,7 @@ public class apiSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/"+downloadpath+"/**").permitAll()
.antMatchers("/"+uploadpath).permitAll()
.antMatchers("/"+previewpath+"/**").permitAll()
.antMatchers("/dictionarys/**").permitAll()
// 所有请求都需要认证
.anyRequest().authenticated()
// 防止iframe 造成跨域
......
package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.api.dto.DictCatalogDTO;
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.Option;
import cn.ibizlab.core.dict.filter.DictCatalogSearchContext;
import cn.ibizlab.core.dict.service.IDictCatalogService;
import cn.ibizlab.util.annotation.VersionCheck;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("")
public class DictCoreResource {
@Autowired
private IDictCatalogService dictcatalogService;
@Autowired
@Lazy
private DictCatalogMapping dictcatalogMapping;
@Autowired
@Lazy
private DictCoreService dictCoreService;
@RequestMapping(method = RequestMethod.GET, value = "/dictionarys/catalogs/{code}")
public ResponseEntity<Catalog> getCatalogs(@PathVariable("code") String code) {
Catalog catalog = dictCoreService.getDictCatalog(code);
return ResponseEntity.status(HttpStatus.OK).body(catalog);
}
@RequestMapping(method = RequestMethod.GET, value = "/dictionarys/catalogs/{code}/options")
public ResponseEntity<List<Option>> getOptions(@PathVariable("code") String code) {
Catalog catalog = dictCoreService.getDictCatalog(code);
return ResponseEntity.status(HttpStatus.OK).body(catalog.getOptions());
}
@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)));
}
@RequestMapping(method = RequestMethod.POST, value = "/dictionarys/catalogs/savebatch")
public ResponseEntity<Boolean> saveBatch(@RequestBody List<DictCatalogDTO> dictcatalogdtos) {
dictcatalogService.saveBatch(dictcatalogMapping.toDomain(dictcatalogdtos));
return ResponseEntity.status(HttpStatus.OK).body(true);
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册