|
|
@@ -1,7 +1,5 @@
|
|
|
package com.zhongshu.card.server.core.service.dictionary;
|
|
|
|
|
|
-import ch.qos.logback.core.joran.conditional.IfAction;
|
|
|
-import com.github.microservice.auth.security.helper.AuthHelper;
|
|
|
import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
import com.github.microservice.components.data.mongo.mongo.domain.SuperEntity;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
@@ -14,14 +12,12 @@ import com.zhongshu.card.server.core.dao.dictionary.DictionaryItemDao;
|
|
|
import com.zhongshu.card.server.core.dataConfig.DictionaryInitConfig;
|
|
|
import com.zhongshu.card.server.core.domain.dictionary.Dictionary;
|
|
|
import com.zhongshu.card.server.core.domain.dictionary.DictionaryItem;
|
|
|
-import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
-import com.zhongshu.card.server.core.model.dictionary.DItemChildrenResult;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.bson.types.ObjectId;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.KeysetScrollPosition;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -44,24 +40,25 @@ public class DictionaryService extends SuperService {
|
|
|
@Autowired
|
|
|
DictionaryInitConfig dictionaryInitConfig;
|
|
|
|
|
|
- public ResultContent init(){
|
|
|
+ public ResultContent init() {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加字典
|
|
|
+ *
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultContent addDictionary(AddDictionaryParam param){
|
|
|
- if (StringUtils.isNotBlank(param.getId())){
|
|
|
+ public ResultContent addDictionary(AddDictionaryParam param) {
|
|
|
+ if (StringUtils.isNotBlank(param.getId())) {
|
|
|
UpdateDictionaryParam updateParam = new UpdateDictionaryParam();
|
|
|
BeanUtils.copyProperties(param, updateParam);
|
|
|
return updateDictionary(updateParam);
|
|
|
}
|
|
|
|
|
|
Dictionary byProjectIdAndKey = dictionaryDao.findTopByProjectIdAndKey(param.getProjectId(), param.getKey());
|
|
|
- if (byProjectIdAndKey != null){
|
|
|
+ if (byProjectIdAndKey != null) {
|
|
|
return ResultContent.buildFail("字典编码已存在");
|
|
|
}
|
|
|
|
|
|
@@ -76,27 +73,27 @@ public class DictionaryService extends SuperService {
|
|
|
/**
|
|
|
* 编辑字典
|
|
|
*/
|
|
|
- public ResultContent updateDictionary(UpdateDictionaryParam param){
|
|
|
+ public ResultContent updateDictionary(UpdateDictionaryParam param) {
|
|
|
Dictionary dictionary = dictionaryDao.findTopById(param.getId());
|
|
|
- if (dictionary == null){
|
|
|
+ if (dictionary == null) {
|
|
|
return ResultContent.buildFail("数据不存在");
|
|
|
}
|
|
|
|
|
|
DictionaryType type = dictionary.getType();
|
|
|
- if (DictionaryType.Standard.equals(type)){//如果为标准类型
|
|
|
- if (StringUtils.isNotBlank(param.getKey())){
|
|
|
+ if (DictionaryType.Standard.equals(type)) {//如果为标准类型
|
|
|
+ if (StringUtils.isNotBlank(param.getKey())) {
|
|
|
return ResultContent.buildFail("标准类型字典编码不允许修改");
|
|
|
}
|
|
|
- if (param.isDisabled()){
|
|
|
+ if (param.isDisabled()) {
|
|
|
return ResultContent.buildFail("标准类型字典不允许禁用");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Dictionary byProjectIdAndKey = dictionaryDao.findTopByProjectIdAndKey(dictionary.getProjectId(), param.getKey());
|
|
|
- if (byProjectIdAndKey != null && !byProjectIdAndKey.getId().equals(param.getId())){
|
|
|
+ if (byProjectIdAndKey != null && !byProjectIdAndKey.getId().equals(param.getId())) {
|
|
|
return ResultContent.buildFail("字典编码已存在");
|
|
|
}
|
|
|
- com.zhongshu.card.server.core.util.BeanUtils.copyProperties(param, dictionary,"id");
|
|
|
+ com.zhongshu.card.server.core.util.BeanUtils.copyProperties(param, dictionary, "id");
|
|
|
dictionaryDao.save(dictionary);
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
@@ -104,13 +101,13 @@ public class DictionaryService extends SuperService {
|
|
|
/**
|
|
|
* 删除字典
|
|
|
*/
|
|
|
- public ResultContent deleteDictionary(String id){
|
|
|
+ public ResultContent deleteDictionary(String id) {
|
|
|
Dictionary dictionary = dictionaryDao.findTopById(id);
|
|
|
- if (dictionary == null){
|
|
|
+ if (dictionary == null) {
|
|
|
return ResultContent.buildFail("数据不存在");
|
|
|
}
|
|
|
- if (DictionaryType.Standard.equals(dictionary.getType())){
|
|
|
- if (dictionary.getPermission() == null || !dictionary.getPermission().contains(DictionaryPermission.delete)){
|
|
|
+ if (DictionaryType.Standard.equals(dictionary.getType())) {
|
|
|
+ if (dictionary.getPermission() == null || !dictionary.getPermission().contains(DictionaryPermission.delete)) {
|
|
|
return ResultContent.buildFail("标准字典不允许删除");
|
|
|
}
|
|
|
}
|
|
|
@@ -119,22 +116,23 @@ public class DictionaryService extends SuperService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
- public Object page(Pageable pageable, DictionaryQueryParam param){
|
|
|
+ public Object page(Pageable pageable, DictionaryQueryParam param) {
|
|
|
String projectId = param.getProjectId();
|
|
|
- if (StringUtils.isBlank(projectId)){
|
|
|
+ if (StringUtils.isBlank(projectId)) {
|
|
|
projectId = getCurrentProjectOid();
|
|
|
}
|
|
|
- if (StringUtils.isBlank(projectId)){
|
|
|
+ if (StringUtils.isBlank(projectId)) {
|
|
|
return ResultContent.buildFail("项目id不能为空");
|
|
|
- };
|
|
|
+ }
|
|
|
+ ;
|
|
|
|
|
|
Page<Dictionary> page = dictionaryDao.page(pageable, param.getProjectId(), param.getName(), param.getType());
|
|
|
return ResultContent.buildContent(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
}
|
|
|
|
|
|
- private DictionaryModel toModel(Dictionary dictionary){
|
|
|
+ private DictionaryModel toModel(Dictionary dictionary) {
|
|
|
DictionaryModel dictionaryModel = new DictionaryModel();
|
|
|
- if (dictionary != null){
|
|
|
+ if (dictionary != null) {
|
|
|
BeanUtils.copyProperties(dictionary, dictionaryModel);
|
|
|
}
|
|
|
return dictionaryModel;
|
|
|
@@ -143,35 +141,35 @@ public class DictionaryService extends SuperService {
|
|
|
/**
|
|
|
* 添加项
|
|
|
*/
|
|
|
- public ResultContent addItem(AddDictionaryItemParam param){
|
|
|
+ public ResultContent addItem(AddDictionaryItemParam param) {
|
|
|
|
|
|
|
|
|
- if (StringUtils.isNotBlank(param.getId())){
|
|
|
+ if (StringUtils.isNotBlank(param.getId())) {
|
|
|
return updateItem(param);
|
|
|
}
|
|
|
Dictionary dictionary = dictionaryDao.findTopById(param.getDictionaryId());
|
|
|
- if (dictionary == null){
|
|
|
+ if (dictionary == null) {
|
|
|
return ResultContent.buildFail("字典不存在");
|
|
|
}
|
|
|
|
|
|
- if (dictionary.getType().equals(DictionaryType.Standard)){
|
|
|
+ if (dictionary.getType().equals(DictionaryType.Standard)) {
|
|
|
List<DictionaryPermission> permission = dictionary.getPermission();
|
|
|
- if (permission==null || !permission.contains(DictionaryPermission.add)){
|
|
|
+ if (permission == null || !permission.contains(DictionaryPermission.add)) {
|
|
|
return ResultContent.buildFail("该字典不允许添加项");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (param.getParentId()!=null){
|
|
|
+ if (param.getParentId() != null) {
|
|
|
DictionaryItem parentItem = dictionaryItemDao.findTopById(param.getParentId());
|
|
|
- if (parentItem != null && parentItem.getType().equals(DictionaryType.Standard)){
|
|
|
- if (parentItem.getPermission() == null || !parentItem.getPermission().contains(DictionaryPermission.add)){
|
|
|
+ if (parentItem != null && parentItem.getType().equals(DictionaryType.Standard)) {
|
|
|
+ if (parentItem.getPermission() == null || !parentItem.getPermission().contains(DictionaryPermission.add)) {
|
|
|
return ResultContent.buildFail("该项不允许添加下级");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
DictionaryItem updateItem = dictionaryItemDao.findTopByDictionary_IdAndKey(param.getDictionaryId(), param.getKey());
|
|
|
- if (updateItem != null && !updateItem.getId().equals(param.getId())){
|
|
|
+ if (updateItem != null && !updateItem.getId().equals(param.getId())) {
|
|
|
return ResultContent.buildFail("项编码已存在");
|
|
|
}
|
|
|
|
|
|
@@ -184,7 +182,7 @@ public class DictionaryService extends SuperService {
|
|
|
dictionaryItem.setIdString(id);
|
|
|
dictionaryItem.setCreateTime(System.currentTimeMillis());
|
|
|
|
|
|
- if (StringUtils.isEmpty(param.getParentId())){
|
|
|
+ if (StringUtils.isEmpty(param.getParentId())) {
|
|
|
dictionaryItem.setParentId(null);
|
|
|
}
|
|
|
dictionaryItemDao.save(dictionaryItem);
|
|
|
@@ -194,23 +192,23 @@ public class DictionaryService extends SuperService {
|
|
|
/**
|
|
|
* 编辑项
|
|
|
*/
|
|
|
- public ResultContent updateItem(AddDictionaryItemParam param){
|
|
|
- if (StringUtils.isBlank(param.getId())){
|
|
|
+ public ResultContent updateItem(AddDictionaryItemParam param) {
|
|
|
+ if (StringUtils.isBlank(param.getId())) {
|
|
|
return ResultContent.buildFail("id不能为null");
|
|
|
}
|
|
|
DictionaryItem dictionaryItem = dictionaryItemDao.findTopById(param.getId());
|
|
|
- if (dictionaryItem == null){
|
|
|
+ if (dictionaryItem == null) {
|
|
|
return ResultContent.buildFail("数据不存在");
|
|
|
}
|
|
|
|
|
|
- if (dictionaryItem.getType().equals(DictionaryType.Standard)){//标准
|
|
|
- if (StringUtils.isNotBlank(param.getKey())){
|
|
|
+ if (dictionaryItem.getType().equals(DictionaryType.Standard)) {//标准
|
|
|
+ if (StringUtils.isNotBlank(param.getKey())) {
|
|
|
return ResultContent.buildFail("标准字典的项编码不允许修改");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
DictionaryItem updateItem = dictionaryItemDao.findTopByDictionary_IdAndKey(param.getDictionaryId(), param.getKey());
|
|
|
- if (updateItem != null && !updateItem.getId().equals(param.getId())){
|
|
|
+ if (updateItem != null && !updateItem.getId().equals(param.getId())) {
|
|
|
return ResultContent.buildFail("项编码已存在");
|
|
|
}
|
|
|
|
|
|
@@ -222,13 +220,13 @@ public class DictionaryService extends SuperService {
|
|
|
/**
|
|
|
* 删除项
|
|
|
*/
|
|
|
- public ResultContent deleteItem(String id){
|
|
|
+ public ResultContent deleteItem(String id) {
|
|
|
DictionaryItem dictionaryItem = dictionaryItemDao.findTopById(id);
|
|
|
- if (dictionaryItem == null){
|
|
|
+ if (dictionaryItem == null) {
|
|
|
return ResultContent.buildFail("数据不存在");
|
|
|
}
|
|
|
- if (DictionaryType.Standard.equals(dictionaryItem.getType())){
|
|
|
- if (dictionaryItem.getPermission() == null || dictionaryItem.getPermission().contains(DictionaryPermission.delete)){
|
|
|
+ if (DictionaryType.Standard.equals(dictionaryItem.getType())) {
|
|
|
+ if (dictionaryItem.getPermission() == null || dictionaryItem.getPermission().contains(DictionaryPermission.delete)) {
|
|
|
return ResultContent.buildFail("标准字典的项不允许删除");
|
|
|
}
|
|
|
}
|
|
|
@@ -236,7 +234,7 @@ public class DictionaryService extends SuperService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
- public Object pageItem(Pageable pageable, DictionaryItemQueryParam param){
|
|
|
+ public Object pageItem(Pageable pageable, DictionaryItemQueryParam param) {
|
|
|
Page<DictionaryItem> page = dictionaryItemDao.page(pageable, param.getDictionaryId(), param.getName(), param.getParentId());
|
|
|
Page<DictionaryItemModel> pageModel = PageEntityUtil.concurrent2PageModel(page, it -> {
|
|
|
return toItemModel(it);
|
|
|
@@ -244,8 +242,8 @@ public class DictionaryService extends SuperService {
|
|
|
|
|
|
List<DictionaryItemModel> dItemChildrenResults = dictionaryItemDao.deepAggregate(param.getDictionaryId(), pageModel.getContent().stream().map(DictionaryItemModel::getKey).toList());
|
|
|
List<DictionaryItemModel> ret = new ArrayList<>();
|
|
|
- dItemChildrenResults.forEach(it->{
|
|
|
- if (it.getChildren()!=null && it.getChildren().size() > 0){
|
|
|
+ dItemChildrenResults.forEach(it -> {
|
|
|
+ if (it.getChildren() != null && it.getChildren().size() > 0) {
|
|
|
ret.addAll(it.getChildren());
|
|
|
}
|
|
|
it.setChildren(new ArrayList<>());
|
|
|
@@ -271,6 +269,7 @@ public class DictionaryService extends SuperService {
|
|
|
}
|
|
|
return root;
|
|
|
}
|
|
|
+
|
|
|
// 递归构建子树
|
|
|
private static void buildSubTree(Map<String, DictionaryItemModel> itemMap, DictionaryItemModel parent) {
|
|
|
// 遍历所有节点,查找当前parent的子节点
|
|
|
@@ -284,9 +283,9 @@ public class DictionaryService extends SuperService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private DictionaryItemModel toItemModel(DictionaryItem dictionaryItem){
|
|
|
+ private DictionaryItemModel toItemModel(DictionaryItem dictionaryItem) {
|
|
|
DictionaryItemModel dictionaryItemModel = new DictionaryItemModel();
|
|
|
- if (dictionaryItem != null){
|
|
|
+ if (dictionaryItem != null) {
|
|
|
BeanUtils.copyProperties(dictionaryItem, dictionaryItemModel);
|
|
|
dictionaryItemModel.setDictionaryId(dictionaryItem.getDictionary().getId());
|
|
|
}
|
|
|
@@ -295,20 +294,22 @@ public class DictionaryService extends SuperService {
|
|
|
|
|
|
/**
|
|
|
* 根据字典编码获取字典
|
|
|
+ *
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultContent listDictionary(ListDictionaryParam param){
|
|
|
+ public ResultContent listDictionary(ListDictionaryParam param) {
|
|
|
|
|
|
String projectId = param.getProjectId();
|
|
|
- if (StringUtils.isBlank(projectId)){
|
|
|
+ if (StringUtils.isBlank(projectId)) {
|
|
|
projectId = getCurrentProjectOid();
|
|
|
}
|
|
|
- if (StringUtils.isBlank(projectId)){
|
|
|
+ if (StringUtils.isBlank(projectId)) {
|
|
|
return ResultContent.buildFail("项目id不能为空");
|
|
|
- };
|
|
|
+ }
|
|
|
+ ;
|
|
|
|
|
|
- if (param.getKeys()==null || param.getKeys().isEmpty()){
|
|
|
+ if (param.getKeys() == null || param.getKeys().isEmpty()) {
|
|
|
return ResultContent.buildFail("字典编码不能为null或空");
|
|
|
}
|
|
|
|
|
|
@@ -322,48 +323,49 @@ public class DictionaryService extends SuperService {
|
|
|
|
|
|
/**
|
|
|
* 根据项编码获取项
|
|
|
+ *
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultContent listItem(ListDictionaryParam param){
|
|
|
+ public ResultContent listItem(ListDictionaryParam param) {
|
|
|
|
|
|
- if (StringUtils.isBlank(param.getDictionaryKey())){
|
|
|
+ if (StringUtils.isBlank(param.getDictionaryKey())) {
|
|
|
return ResultContent.buildFail("字典编码不能为空");
|
|
|
}
|
|
|
|
|
|
|
|
|
Dictionary dictionary = dictionaryDao.findTopByProjectIdAndKey(param.getProjectId(), param.getDictionaryKey());
|
|
|
- if (dictionary == null){
|
|
|
+ if (dictionary == null) {
|
|
|
return ResultContent.buildFail("字典不存在");
|
|
|
}
|
|
|
|
|
|
List<DictionaryItem> dictionaryItemList = new ArrayList<>();
|
|
|
|
|
|
- if (param.getKeys()==null || param.getKeys().isEmpty()){
|
|
|
+ if (param.getKeys() == null || param.getKeys().isEmpty()) {
|
|
|
dictionaryItemList = dictionaryItemDao.findByDictionary_Id(dictionary.getId());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
dictionaryItemList = dictionaryItemDao.findTopByDictionary_IdAndKeyIn(dictionary.getId(), param.getKeys());
|
|
|
}
|
|
|
return ResultContent.buildContent(dictionaryItemList.stream().map(this::toItemModel).toList());
|
|
|
}
|
|
|
|
|
|
- public Object deepTreeItem(String projectId, String dictionaryKey, String dictionaryId){
|
|
|
- if (StringUtils.isBlank(dictionaryKey) && StringUtils.isBlank(dictionaryId)){
|
|
|
+ public Object deepTreeItem(String projectId, String dictionaryKey, String dictionaryId) {
|
|
|
+ if (StringUtils.isBlank(dictionaryKey) && StringUtils.isBlank(dictionaryId)) {
|
|
|
return ResultContent.buildFail("字典编码和字典id不能为空");
|
|
|
}
|
|
|
|
|
|
Dictionary dictionary = null;
|
|
|
|
|
|
- if (StringUtils.isNotBlank(dictionaryId)){
|
|
|
+ if (StringUtils.isNotBlank(dictionaryId)) {
|
|
|
dictionary = dictionaryDao.findTopById(dictionaryId);
|
|
|
- }else if (StringUtils.isNotBlank(dictionaryKey)){
|
|
|
+ } else if (StringUtils.isNotBlank(dictionaryKey)) {
|
|
|
dictionary = dictionaryDao.findTopByProjectIdAndKey(projectId, dictionaryKey);
|
|
|
}
|
|
|
|
|
|
- if (dictionary == null){
|
|
|
+ if (dictionary == null) {
|
|
|
return ResultContent.buildFail("字典不存在");
|
|
|
}
|
|
|
- if (dictionary.isDisabled()){
|
|
|
+ if (dictionary.isDisabled()) {
|
|
|
return ResultContent.buildFail("字典已被禁用");
|
|
|
}
|
|
|
|
|
|
@@ -373,9 +375,9 @@ public class DictionaryService extends SuperService {
|
|
|
return ResultContent.buildContent(buildTree(modelList, null));
|
|
|
}
|
|
|
|
|
|
- private List<DictionaryItemModel> buildTree(List<DictionaryItemModel> list, String parentId){
|
|
|
+ private List<DictionaryItemModel> buildTree(List<DictionaryItemModel> list, String parentId) {
|
|
|
Map<String, DictionaryItemModel> itemMap = new HashMap<>();
|
|
|
- itemMap = list.stream().collect(Collectors.toMap(DictionaryItemModel::getId, it->it));
|
|
|
+ itemMap = list.stream().collect(Collectors.toMap(DictionaryItemModel::getId, it -> it));
|
|
|
|
|
|
List<DictionaryItemModel> rootItems = new ArrayList<>();
|
|
|
|
|
|
@@ -392,7 +394,7 @@ public class DictionaryService extends SuperService {
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
- if (StringUtils.isNotBlank(parentId)){
|
|
|
+ if (StringUtils.isNotBlank(parentId)) {
|
|
|
for (DictionaryItemModel item : list) {
|
|
|
if (item.getId().equals(parentId)) {
|
|
|
// 没有父节点的项是根节点
|
|
|
@@ -405,7 +407,7 @@ public class DictionaryService extends SuperService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
for (DictionaryItemModel item : list) {
|
|
|
if (item.getParentId() == null || item.getParentId().isEmpty()) {
|
|
|
// 没有父节点的项是根节点
|
|
|
@@ -425,26 +427,26 @@ public class DictionaryService extends SuperService {
|
|
|
/**
|
|
|
* 更新检查
|
|
|
*/
|
|
|
- public ResultContent<DictionaryUpdateStatus> updateCheck(String projectId){
|
|
|
- if (StringUtils.isBlank(projectId)){
|
|
|
+ public ResultContent<DictionaryUpdateStatus> updateCheck(String projectId) {
|
|
|
+ if (StringUtils.isBlank(projectId)) {
|
|
|
projectId = getCurrentProjectOid();
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isBlank(projectId)){
|
|
|
+ if (StringUtils.isBlank(projectId)) {
|
|
|
return ResultContent.buildFail("项目id不能未空");
|
|
|
}
|
|
|
return ResultContent.buildContent(getUpdateStatus(projectId));
|
|
|
}
|
|
|
|
|
|
|
|
|
- public DictionaryUpdateStatus getUpdateStatus(String projectId){
|
|
|
+ public DictionaryUpdateStatus getUpdateStatus(String projectId) {
|
|
|
List<DictionaryInitConfig.Dictionary> initDicList = dictionaryInitConfig.getDictionaryList();
|
|
|
List<String> initDictKeys = new ArrayList<>();
|
|
|
List<String> initItemKeys = new ArrayList<>();
|
|
|
getConfigKey(initDicList, initDictKeys, initItemKeys);
|
|
|
|
|
|
List<Dictionary> dic = dictionaryDao.findByProjectId(projectId);
|
|
|
- if (dic.isEmpty()){//未初始化
|
|
|
+ if (dic.isEmpty()) {//未初始化
|
|
|
return DictionaryUpdateStatus.NoInit;
|
|
|
}
|
|
|
List<String> dictKeys = new ArrayList<>(dic.stream().map(Dictionary::getKey).toList());
|
|
|
@@ -452,27 +454,27 @@ public class DictionaryService extends SuperService {
|
|
|
List<DictionaryItem> item = dictionaryItemDao.findByDictionary_IdIn(dic.stream().map(SuperEntity::getId).toList());
|
|
|
List<String> itemKeys = item.stream().map(DictionaryItem::getKey).toList();
|
|
|
|
|
|
- if (initDictKeys.size() != dictKeys.size() || initItemKeys != itemKeys){//需要更新
|
|
|
+ if (initDictKeys.size() != dictKeys.size() || initItemKeys != itemKeys) {//需要更新
|
|
|
return DictionaryUpdateStatus.Update;
|
|
|
}
|
|
|
//无需更新
|
|
|
return DictionaryUpdateStatus.LastVersion;
|
|
|
}
|
|
|
|
|
|
- private void getConfigKey(List<DictionaryInitConfig.Dictionary> dictionaryList, List<String> dictKeys, List<String> itemKeys){
|
|
|
+ private void getConfigKey(List<DictionaryInitConfig.Dictionary> dictionaryList, List<String> dictKeys, List<String> itemKeys) {
|
|
|
|
|
|
for (DictionaryInitConfig.Dictionary dictionary : dictionaryList) {
|
|
|
dictKeys.add(dictionary.getKey());
|
|
|
- if (dictionary.getItem() != null && !dictionary.getItem().isEmpty()){
|
|
|
+ if (dictionary.getItem() != null && !dictionary.getItem().isEmpty()) {
|
|
|
getConfigItemKey(dictionary.getItem(), itemKeys);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void getConfigItemKey(List<DictionaryInitConfig.Dictionary> dictionaryList, List<String> keys){
|
|
|
+ private void getConfigItemKey(List<DictionaryInitConfig.Dictionary> dictionaryList, List<String> keys) {
|
|
|
for (DictionaryInitConfig.Dictionary dictionary : dictionaryList) {
|
|
|
keys.add(dictionary.getKey());
|
|
|
- if (dictionary.getItem() != null && !dictionary.getItem().isEmpty()){
|
|
|
+ if (dictionary.getItem() != null && !dictionary.getItem().isEmpty()) {
|
|
|
getConfigItemKey(dictionary.getItem(), keys);
|
|
|
}
|
|
|
}
|
|
|
@@ -480,12 +482,13 @@ public class DictionaryService extends SuperService {
|
|
|
|
|
|
/**
|
|
|
* 更新标签字典初始化数据
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultContent updateInit(String projectId, boolean coverName, boolean coverCustomize){
|
|
|
+ public ResultContent updateInit(String projectId, boolean coverName, boolean coverCustomize) {
|
|
|
DictionaryUpdateStatus updateStatus = getUpdateStatus(projectId);
|
|
|
|
|
|
- if (updateStatus.equals(DictionaryUpdateStatus.LastVersion)){
|
|
|
+ if (updateStatus.equals(DictionaryUpdateStatus.LastVersion)) {
|
|
|
return ResultContent.buildFail("已是最新版本,无需修复或更新");
|
|
|
}
|
|
|
//TODO 更新至最新版本
|
|
|
@@ -497,7 +500,7 @@ public class DictionaryService extends SuperService {
|
|
|
|
|
|
List<DictionaryType> typeList = new ArrayList<>(List.of(DictionaryType.Standard));
|
|
|
|
|
|
- if (coverCustomize){
|
|
|
+ if (coverCustomize) {
|
|
|
typeList.add(DictionaryType.Customize);
|
|
|
}
|
|
|
|
|
|
@@ -515,12 +518,12 @@ public class DictionaryService extends SuperService {
|
|
|
|
|
|
|
|
|
public void updateInitDictionary(String projectId, List<DictionaryInitConfig.Dictionary> dictionaryList, boolean coverName, List<DictionaryType> typeList) {
|
|
|
- for(DictionaryInitConfig.Dictionary dict : dictionaryList){
|
|
|
+ for (DictionaryInitConfig.Dictionary dict : dictionaryList) {
|
|
|
Dictionary dictionary = syncDictionary(projectId, dict, coverName);
|
|
|
if (dict.getItem() != null) {
|
|
|
List<String> itemKeys = dict.getItem().stream().map(DictionaryInitConfig.Dictionary::getKey).toList();
|
|
|
dictionaryItemDao.deleteByDictionary_IdAndKeyNotInAndTypeIn(dictionary.getId(), itemKeys, typeList);
|
|
|
- for (DictionaryInitConfig.Dictionary item : dict.getItem()){
|
|
|
+ for (DictionaryInitConfig.Dictionary item : dict.getItem()) {
|
|
|
syncDictionaryItem(item, null, dictionary, coverName);
|
|
|
}
|
|
|
}
|
|
|
@@ -537,7 +540,7 @@ public class DictionaryService extends SuperService {
|
|
|
dictionary.setDisabled(false);
|
|
|
dictionary.setId(new ObjectId().toHexString());
|
|
|
dictionaryDao.save(dictionary);
|
|
|
- }else if (coverName){
|
|
|
+ } else if (coverName) {
|
|
|
dictionary.setName(dict.getName());
|
|
|
dictionary.setDescription(dict.getDescription());
|
|
|
dictionaryDao.save(dictionary);
|
|
|
@@ -562,19 +565,32 @@ public class DictionaryService extends SuperService {
|
|
|
item.setCreateTime(System.currentTimeMillis());
|
|
|
item.setDisable(false);
|
|
|
dictionaryItemDao.save(item);
|
|
|
- }else if (coverName){
|
|
|
+ } else if (coverName) {
|
|
|
item.setName(dict.getName());
|
|
|
item.setDescription(dict.getDescription());
|
|
|
|
|
|
}
|
|
|
|
|
|
- if (dict.getItem() !=null && !dict.getItem().isEmpty()){
|
|
|
- for (DictionaryInitConfig.Dictionary children: dict.getItem()){
|
|
|
+ if (dict.getItem() != null && !dict.getItem().isEmpty()) {
|
|
|
+ for (DictionaryInitConfig.Dictionary children : dict.getItem()) {
|
|
|
syncDictionaryItem(children, item, dictionary, coverName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public String queryItemName(String projectOid, String visitorType, String key) {
|
|
|
+ if (StringUtils.isNotEmpty(visitorType) && StringUtils.isNotEmpty(projectOid)) {
|
|
|
+ Dictionary dictionary = dictionaryDao.findTopByProjectIdAndKey(projectOid, visitorType);
|
|
|
+ if (ObjectUtils.isNotEmpty(dictionary)) {
|
|
|
+ DictionaryItem item = dictionaryItemDao.findTopByDictionary_IdAndKey(dictionary.getId(), key);
|
|
|
+ if (item != null) {
|
|
|
+ return item.getName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
// /**
|
|
|
// * 字典项向下查询
|
|
|
// */
|