|
|
@@ -1,21 +1,25 @@
|
|
|
package com.zhongshu.card.server.core.service.dictionary;
|
|
|
|
|
|
+import com.github.microservice.auth.security.helper.AuthHelper;
|
|
|
+import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
-import com.zhongshu.card.client.model.dictionary.AddDictionaryItemParam;
|
|
|
-import com.zhongshu.card.client.model.dictionary.AddDictionaryParam;
|
|
|
-import com.zhongshu.card.client.model.dictionary.UpdateDictionaryParam;
|
|
|
+import com.zhongshu.card.client.model.dictionary.*;
|
|
|
import com.zhongshu.card.client.type.DictionaryType;
|
|
|
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.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.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@Service
|
|
|
-public class DictionaryService {
|
|
|
+public class DictionaryService extends SuperService {
|
|
|
|
|
|
@Autowired
|
|
|
private DictionaryDao dictionaryDao;
|
|
|
@@ -23,6 +27,9 @@ public class DictionaryService {
|
|
|
@Autowired
|
|
|
private DictionaryItemDao dictionaryItemDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ AuthHelper authHelper;
|
|
|
+
|
|
|
public ResultContent init(){
|
|
|
return null;
|
|
|
}
|
|
|
@@ -38,6 +45,7 @@ public class DictionaryService {
|
|
|
return ResultContent.buildFail("字典编码已存在");
|
|
|
}
|
|
|
Dictionary dictionary = new Dictionary();
|
|
|
+
|
|
|
BeanUtils.copyProperties(param, dictionary);
|
|
|
dictionary.setType(DictionaryType.Customize);
|
|
|
dictionaryDao.save(dictionary);
|
|
|
@@ -88,6 +96,27 @@ public class DictionaryService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ public Object page(Pageable pageable, DictionaryQueryParam param){
|
|
|
+ String projectId = param.getProjectId();
|
|
|
+ if (StringUtils.isBlank(projectId)){
|
|
|
+ projectId = getCurrentProjectOid();
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(projectId)){
|
|
|
+ return ResultContent.buildFail("项目id不能为空");
|
|
|
+ };
|
|
|
+
|
|
|
+ Page<Dictionary> page = dictionaryDao.page(pageable, param.getProjectId(), param.getName(), param.getType());
|
|
|
+ return PageEntityUtil.concurrent2PageModel(page, this::toModel);
|
|
|
+ }
|
|
|
+
|
|
|
+ private DictionaryModel toModel(Dictionary dictionary){
|
|
|
+ DictionaryModel dictionaryModel = new DictionaryModel();
|
|
|
+ if (dictionary != null){
|
|
|
+ BeanUtils.copyProperties(dictionary, dictionaryModel);
|
|
|
+ }
|
|
|
+ return dictionaryModel;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 添加项
|
|
|
*/
|
|
|
@@ -101,6 +130,10 @@ public class DictionaryService {
|
|
|
BeanUtils.copyProperties(param, dictionaryItem, "id");
|
|
|
dictionaryItem.setType(DictionaryType.Customize);
|
|
|
dictionaryItem.setDictionary(dictionary);
|
|
|
+ String id = new ObjectId().toHexString();
|
|
|
+ dictionaryItem.setId(id);
|
|
|
+ dictionaryItem.setIdString(id);
|
|
|
+ dictionaryItem.setCreateTime(System.currentTimeMillis());
|
|
|
dictionaryItemDao.save(dictionaryItem);
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
@@ -148,4 +181,18 @@ public class DictionaryService {
|
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
|
|
|
|
+ public Object pageItem(Pageable pageable, DictionaryItemQueryParam param){
|
|
|
+ Page<DictionaryItem> page = dictionaryItemDao.page(pageable, param.getDictionaryId(), param.getName());
|
|
|
+ return PageEntityUtil.concurrent2PageModel(page, this::toItemModel);
|
|
|
+ }
|
|
|
+
|
|
|
+ private DictionaryItemModel toItemModel(DictionaryItem dictionaryItem){
|
|
|
+ DictionaryItemModel dictionaryItemModel = new DictionaryItemModel();
|
|
|
+ if (dictionaryItem != null){
|
|
|
+ BeanUtils.copyProperties(dictionaryItem, dictionaryItemModel);
|
|
|
+ dictionaryItemModel.setDictionaryId(dictionaryItem.getDictionary().getId());
|
|
|
+ }
|
|
|
+ return dictionaryItemModel;
|
|
|
+ }
|
|
|
+
|
|
|
}
|