|
|
@@ -9,6 +9,7 @@ import com.zhongshu.card.server.core.dao.dictionary.DictionaryDao;
|
|
|
import com.zhongshu.card.server.core.dao.dictionary.DictionaryItemDao;
|
|
|
import com.zhongshu.card.server.core.domain.dictionary.Dictionary;
|
|
|
import com.zhongshu.card.server.core.domain.dictionary.DictionaryItem;
|
|
|
+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;
|
|
|
@@ -18,6 +19,9 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
@Service
|
|
|
public class DictionaryService extends SuperService {
|
|
|
|
|
|
@@ -106,7 +110,7 @@ public class DictionaryService extends SuperService {
|
|
|
};
|
|
|
|
|
|
Page<Dictionary> page = dictionaryDao.page(pageable, param.getProjectId(), param.getName(), param.getType());
|
|
|
- return PageEntityUtil.concurrent2PageModel(page, this::toModel);
|
|
|
+ return ResultContent.buildContent(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
}
|
|
|
|
|
|
private DictionaryModel toModel(Dictionary dictionary){
|
|
|
@@ -134,6 +138,9 @@ public class DictionaryService extends SuperService {
|
|
|
dictionaryItem.setId(id);
|
|
|
dictionaryItem.setIdString(id);
|
|
|
dictionaryItem.setCreateTime(System.currentTimeMillis());
|
|
|
+ if (StringUtils.isBlank(param.getKey())){
|
|
|
+ dictionaryItem.setParentId(param.getDictionaryId());
|
|
|
+ }
|
|
|
dictionaryItemDao.save(dictionaryItem);
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
@@ -182,8 +189,8 @@ public class DictionaryService extends SuperService {
|
|
|
}
|
|
|
|
|
|
public Object pageItem(Pageable pageable, DictionaryItemQueryParam param){
|
|
|
- Page<DictionaryItem> page = dictionaryItemDao.page(pageable, param.getDictionaryId(), param.getName());
|
|
|
- return PageEntityUtil.concurrent2PageModel(page, this::toItemModel);
|
|
|
+ Page<DictionaryItem> page = dictionaryItemDao.page(pageable, param.getDictionaryId(), param.getName(), param.getParentId());
|
|
|
+ return ResultContent.buildContent(PageEntityUtil.concurrent2PageModel(page, this::toItemModel));
|
|
|
}
|
|
|
|
|
|
private DictionaryItemModel toItemModel(DictionaryItem dictionaryItem){
|
|
|
@@ -195,4 +202,80 @@ public class DictionaryService extends SuperService {
|
|
|
return dictionaryItemModel;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据字典编码获取字典
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent listDictionary(ListDictionaryParam param){
|
|
|
+
|
|
|
+ String projectId = param.getProjectId();
|
|
|
+ if (StringUtils.isBlank(projectId)){
|
|
|
+ projectId = getCurrentProjectOid();
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(projectId)){
|
|
|
+ return ResultContent.buildFail("项目id不能为空");
|
|
|
+ };
|
|
|
+
|
|
|
+ if (param.getKeys()==null || param.getKeys().isEmpty()){
|
|
|
+ return ResultContent.buildFail("字典编码不能为null或空");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Dictionary> dictionaryList = dictionaryDao.findTopByProjectIdAndKeyIn(projectId, param.getKeys());
|
|
|
+ return ResultContent.buildContent(dictionaryList.stream().map(this::toModel).toList());
|
|
|
+ }
|
|
|
+
|
|
|
+// public ResultContent listItem(String projectId,String dictionary, String key){
|
|
|
+// dictionaryItemDao.findTopByDictionary_IdAndKeyIn()
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据项编码获取项
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent listItem(ListDictionaryParam param){
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(param.getDictionaryKey())){
|
|
|
+ return ResultContent.buildFail("字典编码不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Dictionary dictionary = dictionaryDao.findTopByProjectIdAndKey(param.getProjectId(), param.getDictionaryKey());
|
|
|
+ if (dictionary == null){
|
|
|
+ return ResultContent.buildFail("字典不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<DictionaryItem> dictionaryItemList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (param.getKeys()==null || param.getKeys().isEmpty()){
|
|
|
+ dictionaryItemList = dictionaryItemDao.findByDictionary_Id(dictionary.getId());
|
|
|
+ }else {
|
|
|
+ dictionaryItemList = dictionaryItemDao.findTopByDictionary_IdAndKeyIn(dictionary.getId(), param.getKeys());
|
|
|
+ }
|
|
|
+ return ResultContent.buildContent(dictionaryItemList.stream().map(this::toItemModel).toList());
|
|
|
+ }
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 字典项向下查询
|
|
|
+// */
|
|
|
+// public Object deepListItem(DeepQueryParam queryParam){
|
|
|
+//
|
|
|
+// List<DeepQueryParam.KeyFilter> keyFilters = queryParam.getKeyFilters();
|
|
|
+//
|
|
|
+// keyFilters.stream().map(keyFilter -> {
|
|
|
+// Dictionary dictionary = dictionaryDao.findTopByProjectIdAndKey(queryParam.getProjectId(), keyFilter.getDictionaryKey());
|
|
|
+//
|
|
|
+// if (queryParam.isDeep() && !keyFilter.getKeys().isEmpty()){
|
|
|
+// List<DItemChildrenResult> itemList = dictionaryItemDao.deepAggregate(dictionary.getId(), keyFilter.getKeys());
|
|
|
+// }
|
|
|
+//
|
|
|
+// }).toList();
|
|
|
+//
|
|
|
+// Dictionary dictionary = dictionaryDao.findTopByProjectIdAndKey(projectId, dictionaryKey);
|
|
|
+//
|
|
|
+// dictionaryItemDao.f
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
}
|