提交 958624c0 编写于 作者: ibiz4j's avatar ibiz4j

dict 自持

上级 3e494446
......@@ -36,10 +36,6 @@ zuul:
path: /dictionarys/**/SysOperator
serviceId: ${ibiz.ref.service.uaa:ibzuaa-api}
stripPrefix: false
dict:
path: /dictionarys/**
serviceId: ${ibiz.ref.service.dict:ibzdict-api}
stripPrefix: false
disk:
path: /net-disk/**
serviceId: ${ibiz.ref.service.disk:ibzdisk-api}
......
......@@ -129,7 +129,11 @@ public class DictCatalog extends EntityMP implements Serializable {
@ApiModelProperty("扩展参数")
private String extParams;
@JsonIgnore
@JSONField(serialize = false)
@TableField(exist = false)
@JsonProperty("items")
private List<DictOption> options;
/**
* 设置 [代码]
......
......@@ -281,4 +281,24 @@ public class DictDstService
}
return uri;
}
/**
* 同步预置代码表
* @param catalogs
*/
public void syncRuntimeDict(List<DictCatalog> catalogs){
List<DictOption> options=new ArrayList<>();
for(DictCatalog catalog : catalogs){
if(!ObjectUtils.isEmpty(catalog.getOptions()))
options.addAll(catalog.getOptions());
}
if(catalogs.size()>0){
dictCatalogService.saveBatch(catalogs);
}
if(options.size()>0){
optionService.saveBatch(options);
}
}
}
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.DictDstService;
import cn.ibizlab.core.dict.filter.DictOptionSearchContext;
import cn.ibizlab.core.dict.service.IDictCatalogService;
import cn.ibizlab.core.dict.service.IDictOptionService;
import cn.ibizlab.util.dict.Catalog;
import cn.ibizlab.util.dict.CodeItem;
import cn.ibizlab.util.dict.CodeList;
import cn.ibizlab.util.dict.Option;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("")
public class DictCoreResource {
@Autowired
private IDictCatalogService dictcatalogService;
@Autowired
private IDictOptionService optionService;
@Autowired
@Lazy
private DictCatalogMapping dictcatalogMapping;
@Autowired
@Lazy
private DictDstService dictCoreService;
@RequestMapping(method = {RequestMethod.GET}, value = "/dictionarys/catalogs/{code}")
public ResponseEntity<Catalog> getCatalogs(@PathVariable("code") String code,DictOptionSearchContext context) {
Catalog catalog = null;
if(context==null||StringUtils.isEmpty(context.getSelectCond().getSqlSegment()))
catalog = dictCoreService.getDictCatalog(code);
else
catalog = dictCoreService.getDictCatalog(code,context);
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, DictOptionSearchContext context) {
Catalog catalog = null;
if(context==null||StringUtils.isEmpty(context.getSelectCond().getSqlSegment()))
catalog = dictCoreService.getDictCatalog(code);
else
catalog = dictCoreService.getDictCatalog(code,context);
return ResponseEntity.status(HttpStatus.OK).body(catalog.getOptions());
}
@RequestMapping(method = {RequestMethod.GET}, value = "/dictionarys/codelist/{code}")
public ResponseEntity<CodeList> getCodeList(@PathVariable("code") String code,DictOptionSearchContext context) {
CodeList catalog = null;
if(context==null||StringUtils.isEmpty(context.getSelectCond().getSqlSegment()))
catalog = dictCoreService.getCodeListCatalog(code);
else
catalog = dictCoreService.getCodeListCatalog(code,context);
return ResponseEntity.status(HttpStatus.OK).body(catalog);
}
@RequestMapping(method = {RequestMethod.GET}, value = "/dictionarys/codelist/{code}/items")
public ResponseEntity<List<CodeItem>> getCodeItems(@PathVariable("code") String code, DictOptionSearchContext context) {
CodeList catalog = null;
if(context==null||StringUtils.isEmpty(context.getSelectCond().getSqlSegment()))
catalog = dictCoreService.getCodeListCatalog(code);
else
catalog = dictCoreService.getCodeListCatalog(code,context);
return ResponseEntity.status(HttpStatus.OK).body(catalog.getOptions());
}
@RequestMapping(method = {RequestMethod.POST}, value = "/dictionarys/catalogs/{code}")
public ResponseEntity<Catalog> catalogs(@PathVariable("code") String code, @RequestBody(required = false) DictOptionSearchContext context) {
Catalog catalog = null;
if(context==null||StringUtils.isEmpty(context.getSelectCond().getSqlSegment()))
catalog = dictCoreService.getDictCatalog(code);
else
catalog = dictCoreService.getDictCatalog(code,context);
return ResponseEntity.status(HttpStatus.OK).body(catalog);
}
@RequestMapping(method = {RequestMethod.POST}, value = "/dictionarys/catalogs/{code}/options")
public ResponseEntity<List<Option>> options(@PathVariable("code") String code,@RequestBody(required = false) DictOptionSearchContext context) {
Catalog catalog = null;
if(context==null||StringUtils.isEmpty(context.getSelectCond().getSqlSegment()))
catalog = dictCoreService.getDictCatalog(code);
else
catalog = dictCoreService.getDictCatalog(code,context);
return ResponseEntity.status(HttpStatus.OK).body(catalog.getOptions());
}
@RequestMapping(method = {RequestMethod.POST}, value = "/dictionarys/codelist/{code}")
public ResponseEntity<CodeList> codeList(@PathVariable("code") String code,@RequestBody(required = false) DictOptionSearchContext context) {
CodeList catalog = null;
if(context==null||StringUtils.isEmpty(context.getSelectCond().getSqlSegment()))
catalog = dictCoreService.getCodeListCatalog(code);
else
catalog = dictCoreService.getCodeListCatalog(code,context);
return ResponseEntity.status(HttpStatus.OK).body(catalog);
}
@RequestMapping(method = {RequestMethod.POST}, value = "/dictionarys/codelist/{code}/items")
public ResponseEntity<List<CodeItem>> codeItems(@PathVariable("code") String code, @RequestBody(required = false) DictOptionSearchContext context) {
CodeList catalog = null;
if(context==null||StringUtils.isEmpty(context.getSelectCond().getSqlSegment()))
catalog = dictCoreService.getCodeListCatalog(code);
else
catalog = dictCoreService.getCodeListCatalog(code,context);
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);
}
@RequestMapping(method = RequestMethod.POST, value = "/dictionarys/catalogs/sync")
public ResponseEntity<Boolean> syncRuntimeDict(@RequestBody List<DictCatalog> catalogs){
dictCoreService.syncRuntimeDict(catalogs);
return ResponseEntity.status(HttpStatus.OK).body(true);
}
}
......@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;
import java.util.Map;
@FeignClient(value = "${ibiz.ref.service.dict:ibzdict-api}",contextId = "dict",fallback = IBZDictFallback.class)
@FeignClient(value = "${ibiz.ref.service.dict:ibzdst-api}",contextId = "dict",fallback = IBZDictFallback.class)
public interface IBZDictFeignClient
{
@RequestMapping(method = RequestMethod.POST, value = "/dictionarys/catalogs/sync")
......
package cn.ibizlab.util.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@Service
public class LockService {
@Autowired
@Lazy
private LockService proxy;
@Cacheable( value="lock", key = "'key:'+#p0")
protected Long getLock(String key)
{
return System.currentTimeMillis();
}
@Cacheable( value="lock", key = "'key:'+#p0")
private Long resetLock(String key,Long newLockTime)
{
return newLockTime;
}
@CacheEvict( value="lock", key = "'key:'+#p0")
private void deleteLock(String key)
{
}
public boolean lock(String key,Long lockTimeMillis)
{
if(StringUtils.isEmpty(key))
return false;
Long now=System.currentTimeMillis();
Long lockTime=proxy.getLock(key);
if(lockTime>=now)
return true;
if(lockTime+lockTimeMillis>now)
{
proxy.deleteLock(key);
proxy.resetLock(key,now);
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
proxy.resetLock(key,now);
}
});
return true;
}
return false;
}
public void unLock(String key)
{
proxy.deleteLock(key);
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册