|
|
@@ -1,21 +1,26 @@
|
|
|
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;
|
|
|
import com.zhongshu.card.client.model.dictionary.*;
|
|
|
import com.zhongshu.card.client.type.DictionaryType;
|
|
|
+import com.zhongshu.card.client.type.DictionaryUpdateStatus;
|
|
|
import com.zhongshu.card.server.core.dao.dictionary.DictionaryDao;
|
|
|
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.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;
|
|
|
@@ -36,7 +41,7 @@ public class DictionaryService extends SuperService {
|
|
|
private DictionaryItemDao dictionaryItemDao;
|
|
|
|
|
|
@Autowired
|
|
|
- AuthHelper authHelper;
|
|
|
+ DictionaryInitConfig dictionaryInitConfig;
|
|
|
|
|
|
public ResultContent init(){
|
|
|
return null;
|
|
|
@@ -52,6 +57,13 @@ public class DictionaryService extends SuperService {
|
|
|
if (byProjectIdAndKey != null){
|
|
|
return ResultContent.buildFail("字典编码已存在");
|
|
|
}
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(param.getId())){
|
|
|
+ UpdateDictionaryParam updateParam = new UpdateDictionaryParam();
|
|
|
+ BeanUtils.copyProperties(param, updateParam);
|
|
|
+ return updateDictionary(updateParam);
|
|
|
+ }
|
|
|
+
|
|
|
Dictionary dictionary = new Dictionary();
|
|
|
|
|
|
BeanUtils.copyProperties(param, dictionary);
|
|
|
@@ -134,6 +146,10 @@ public class DictionaryService extends SuperService {
|
|
|
return ResultContent.buildFail("字典不存在");
|
|
|
}
|
|
|
|
|
|
+ if (dictionary.getType().equals(DictionaryType.Standard)){
|
|
|
+ return ResultContent.buildFail("标准字典不允许添加项");
|
|
|
+ }
|
|
|
+
|
|
|
DictionaryItem dictionaryItem = new DictionaryItem();
|
|
|
BeanUtils.copyProperties(param, dictionaryItem, "id");
|
|
|
dictionaryItem.setType(DictionaryType.Customize);
|
|
|
@@ -375,6 +391,159 @@ public class DictionaryService extends SuperService {
|
|
|
return rootItems;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新检查
|
|
|
+ */
|
|
|
+ public ResultContent<DictionaryUpdateStatus> updateCheck(String projectId){
|
|
|
+ if (StringUtils.isBlank(projectId)){
|
|
|
+ projectId = getCurrentProjectOid();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(projectId)){
|
|
|
+ return ResultContent.buildFail("项目id不能未空");
|
|
|
+ }
|
|
|
+ return ResultContent.buildContent(getUpdateStatus(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()){//未初始化
|
|
|
+ return DictionaryUpdateStatus.NoInit;
|
|
|
+ }
|
|
|
+ List<String> dictKeys = new ArrayList<>(dic.stream().map(Dictionary::getKey).toList());
|
|
|
+
|
|
|
+ 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){//需要更新
|
|
|
+ return DictionaryUpdateStatus.Update;
|
|
|
+ }
|
|
|
+ //无需更新
|
|
|
+ return DictionaryUpdateStatus.LastVersion;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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()){
|
|
|
+ getConfigItemKey(dictionary.getItem(), itemKeys);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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()){
|
|
|
+ getConfigItemKey(dictionary.getItem(), keys);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新标签字典初始化数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent updateInit(String projectId, boolean coverName, boolean coverCustomize){
|
|
|
+ DictionaryUpdateStatus updateStatus = getUpdateStatus(projectId);
|
|
|
+
|
|
|
+ if (updateStatus.equals(DictionaryUpdateStatus.LastVersion)){
|
|
|
+ return ResultContent.buildFail("已是最新版本,无需修复或更新");
|
|
|
+ }
|
|
|
+ //TODO 更新至最新版本
|
|
|
+
|
|
|
+ List<DictionaryInitConfig.Dictionary> dictionaryList = dictionaryInitConfig.getDictionaryList();
|
|
|
+ if (dictionaryList == null || dictionaryList.isEmpty()) {
|
|
|
+ return ResultContent.buildFail("初始化数据不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<DictionaryType> typeList = new ArrayList<>(List.of(DictionaryType.Standard));
|
|
|
+
|
|
|
+ if (coverCustomize){
|
|
|
+ typeList.add(DictionaryType.Customize);
|
|
|
+ }
|
|
|
+
|
|
|
+ updateInitDictionary(projectId, dictionaryList, coverName, typeList);
|
|
|
+
|
|
|
+ List<String> initDictKeys = new ArrayList<>();
|
|
|
+ List<String> initItemKeys = new ArrayList<>();
|
|
|
+
|
|
|
+ getConfigKey(dictionaryList, initDictKeys, initItemKeys);
|
|
|
+
|
|
|
+ dictionaryDao.deleteByProjectIdAndKeyNotInAndTypeIn(projectId, initDictKeys, typeList);
|
|
|
+
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void updateInitDictionary(String projectId, List<DictionaryInitConfig.Dictionary> dictionaryList, boolean coverName, List<DictionaryType> typeList) {
|
|
|
+ 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()){
|
|
|
+ syncDictionaryItem(item, null, dictionary, coverName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Dictionary syncDictionary(String projectId, DictionaryInitConfig.Dictionary dict, boolean coverName) {
|
|
|
+ Dictionary dictionary = dictionaryDao.findTopByProjectIdAndKey(projectId, dict.getKey());
|
|
|
+ if (dictionary == null) {
|
|
|
+ dictionary = new Dictionary();
|
|
|
+ BeanUtils.copyProperties(dict, dictionary);
|
|
|
+ dictionary.setProjectId(projectId);
|
|
|
+ dictionary.setType(DictionaryType.Standard);
|
|
|
+ dictionary.setDisabled(false);
|
|
|
+ dictionary.setId(new ObjectId().toHexString());
|
|
|
+ dictionaryDao.save(dictionary);
|
|
|
+ }else if (coverName){
|
|
|
+ dictionary.setName(dict.getName());
|
|
|
+ dictionary.setDescription(dict.getDescription());
|
|
|
+ dictionaryDao.save(dictionary);
|
|
|
+ }
|
|
|
+ return dictionary;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void syncDictionaryItem(DictionaryInitConfig.Dictionary dict, DictionaryItem parent, Dictionary dictionary, boolean coverName) {
|
|
|
+ DictionaryItem item = dictionaryItemDao.findTopByDictionary_IdAndKey(dictionary.getId(), dict.getKey());
|
|
|
+
|
|
|
+ if (item == null) {
|
|
|
+ item = new DictionaryItem();
|
|
|
+ BeanUtils.copyProperties(dict, item);
|
|
|
+ if (parent != null) {
|
|
|
+ item.setParentId(parent.getId());
|
|
|
+ }
|
|
|
+ item.setDictionary(dictionary);
|
|
|
+ item.setType(DictionaryType.Standard);
|
|
|
+ String id = new ObjectId().toHexString();
|
|
|
+ item.setId(id);
|
|
|
+ item.setIdString(id);
|
|
|
+ item.setCreateTime(System.currentTimeMillis());
|
|
|
+ item.setDisable(false);
|
|
|
+ dictionaryItemDao.save(item);
|
|
|
+ }else if (coverName){
|
|
|
+ item.setName(dict.getName());
|
|
|
+ item.setDescription(dict.getDescription());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dict.getItem() !=null && !dict.getItem().isEmpty()){
|
|
|
+ for (DictionaryInitConfig.Dictionary children: dict.getItem()){
|
|
|
+ syncDictionaryItem(children, item, dictionary, coverName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// /**
|
|
|
// * 字典项向下查询
|
|
|
// */
|