mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
5.0
This commit is contained in:
@@ -24,7 +24,16 @@ public enum YesOrNoEnum implements IntEnum {
|
||||
return Objects.equals(value.intValue(), YES.value) ? YES : NO;
|
||||
}
|
||||
|
||||
public static boolean yes(Number value) {
|
||||
return of(value) == YES;
|
||||
}
|
||||
|
||||
public static YesOrNoEnum of(Boolean value) {
|
||||
return Objects.equals(value, true) ? YES : NO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,17 @@
|
||||
package com.gitee.sop.adminbackend.controller.doc;
|
||||
|
||||
import com.gitee.sop.adminbackend.common.req.IdParam;
|
||||
import com.gitee.sop.adminbackend.common.resp.Result;
|
||||
import com.gitee.sop.adminbackend.common.util.CopyUtil;
|
||||
import com.gitee.sop.adminbackend.controller.doc.param.DocAppAddParam;
|
||||
import com.gitee.sop.adminbackend.controller.doc.param.DocInfoUpdateParam;
|
||||
import com.gitee.sop.adminbackend.controller.doc.vo.DocAppVO;
|
||||
import com.gitee.sop.adminbackend.controller.doc.vo.DocInfoTreeVO;
|
||||
import com.gitee.sop.adminbackend.service.doc.DocService;
|
||||
import com.gitee.sop.adminbackend.service.doc.DocAppService;
|
||||
import com.gitee.sop.adminbackend.service.doc.DocInfoService;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocAppDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoTreeDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoPublishUpdateDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoTreeDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -29,31 +31,39 @@ import java.util.List;
|
||||
public class DocController {
|
||||
|
||||
@Autowired
|
||||
private DocService docService;
|
||||
private DocInfoService docInfoService;
|
||||
@Autowired
|
||||
private DocAppService docAppService;
|
||||
|
||||
@GetMapping("app/list")
|
||||
public Result<List<DocAppVO>> listApp() {
|
||||
List<DocAppDTO> docAppDTOS = docService.listDocApp();
|
||||
List<DocAppDTO> docAppDTOS = docAppService.listDocApp();
|
||||
List<DocAppVO> docAppVOS = CopyUtil.copyList(docAppDTOS, DocAppVO::new);
|
||||
return Result.ok(docAppVOS);
|
||||
}
|
||||
|
||||
@PostMapping("app/add")
|
||||
public Result<Long> addApp(@Validated @RequestBody DocAppAddParam param) {
|
||||
Long docAppId = docService.addDocApp(param.getTornaToken());
|
||||
Long docAppId = docAppService.addDocApp(param.getTornaToken());
|
||||
return Result.ok(docAppId);
|
||||
}
|
||||
|
||||
@PostMapping("app/syncDoc")
|
||||
public Result<Integer> syncDocInfo(@Validated @RequestBody IdParam param) {
|
||||
docInfoService.syncDocInfo(param.getId());
|
||||
return Result.ok(1);
|
||||
}
|
||||
|
||||
@GetMapping("info/tree")
|
||||
public Result<List<DocInfoTreeVO>> docTree(@RequestParam Long docAppId) {
|
||||
List<DocInfoTreeDTO> docInfoTreeDTOS = docService.listDocTree(docAppId);
|
||||
List<DocInfoTreeDTO> docInfoTreeDTOS = docInfoService.listDocTree(docAppId);
|
||||
List<DocInfoTreeVO> docInfoTreeVOS = CopyUtil.deepCopyList(docInfoTreeDTOS, DocInfoTreeVO.class);
|
||||
return Result.ok(docInfoTreeVOS);
|
||||
}
|
||||
|
||||
@PostMapping("info/publish")
|
||||
public Result<Integer> publish(@Validated @RequestBody DocInfoUpdateParam param) {
|
||||
int cnt = docService.publish(CopyUtil.copyBean(param, DocInfoPublishUpdateDTO::new));
|
||||
int cnt = docInfoService.publish(CopyUtil.copyBean(param, DocInfoPublishUpdateDTO::new));
|
||||
return Result.ok(cnt);
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@ package com.gitee.sop.adminbackend.controller.doc;
|
||||
import com.gitee.sop.adminbackend.common.resp.Result;
|
||||
import com.gitee.sop.adminbackend.common.util.CopyUtil;
|
||||
import com.gitee.sop.adminbackend.controller.doc.vo.DocSettingVO;
|
||||
import com.gitee.sop.adminbackend.service.doc.DocService;
|
||||
import com.gitee.sop.adminbackend.service.doc.DocSettingService;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocSettingDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -23,18 +23,18 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class DocSettingController {
|
||||
|
||||
@Autowired
|
||||
private DocService docService;
|
||||
private DocSettingService docSettingService;
|
||||
|
||||
@GetMapping("get")
|
||||
public Result<DocSettingVO> get() {
|
||||
DocSettingDTO docSetting = docService.getDocSetting();
|
||||
DocSettingDTO docSetting = docSettingService.getDocSetting();
|
||||
DocSettingVO docSettingVO = CopyUtil.copyBean(docSetting, DocSettingVO::new);
|
||||
return Result.ok(docSettingVO);
|
||||
}
|
||||
|
||||
@PostMapping("save")
|
||||
public Result<Integer> save(@Validated @RequestBody DocSettingDTO docSettingVO) {
|
||||
docService.save(docSettingVO);
|
||||
docSettingService.save(docSettingVO);
|
||||
return Result.ok(1);
|
||||
}
|
||||
|
||||
|
@@ -57,6 +57,11 @@ public class DocInfoTreeVO implements TreeNode<DocInfoTreeVO, Long> {
|
||||
*/
|
||||
private String docName;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
private String docVersion;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
@@ -67,35 +72,11 @@ public class DocInfoTreeVO implements TreeNode<DocInfoTreeVO, Long> {
|
||||
*/
|
||||
private Integer isFolder;
|
||||
|
||||
/**
|
||||
* 状态, 0-未发布,1-已发布
|
||||
*/
|
||||
private Integer isPublish;
|
||||
|
||||
/**
|
||||
* 父节点id
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 添加时间
|
||||
*/
|
||||
private LocalDateTime addTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人id
|
||||
*/
|
||||
private Long addBy;
|
||||
|
||||
/**
|
||||
* 修改人id
|
||||
*/
|
||||
private Long updateBy;
|
||||
|
||||
private List<DocInfoTreeVO> children;
|
||||
|
||||
|
@@ -5,9 +5,10 @@ import com.gitee.sop.adminbackend.common.resp.Result;
|
||||
import com.gitee.sop.adminbackend.common.util.CopyUtil;
|
||||
import com.gitee.sop.adminbackend.controller.doc.vo.DocAppVO;
|
||||
import com.gitee.sop.adminbackend.controller.doc.vo.DocInfoTreeVO;
|
||||
import com.gitee.sop.adminbackend.service.website.WebsiteService;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocAppDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoTreeDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoViewDTO;
|
||||
import com.gitee.sop.adminbackend.service.website.WebsiteService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -28,11 +29,10 @@ public class WebsiteController {
|
||||
@Autowired
|
||||
private WebsiteService websiteService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取文档应用列表
|
||||
*/
|
||||
@GetMapping("listDocApp")
|
||||
@GetMapping("docapp/list")
|
||||
public Result<List<DocAppVO>> listDocApp() {
|
||||
List<DocAppDTO> docAppDTOS = websiteService.listDocApp();
|
||||
List<DocAppVO> docAppVOS = CopyUtil.deepCopyList(docAppDTOS, DocAppVO.class);
|
||||
@@ -44,11 +44,22 @@ public class WebsiteController {
|
||||
*
|
||||
* @param docAppId 应用id
|
||||
*/
|
||||
@GetMapping("listDocMenuTree")
|
||||
@GetMapping("docinfo/tree")
|
||||
public Result<List<DocInfoTreeVO>> listDocMenuTree(Long docAppId) {
|
||||
List<DocInfoTreeDTO> docInfoTreeDTOS = websiteService.listDocMenuTree(docAppId);
|
||||
List<DocInfoTreeVO> docAppVOS = CopyUtil.deepCopyList(docInfoTreeDTOS, DocInfoTreeVO.class);
|
||||
return Result.ok(docAppVOS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文档详情
|
||||
*
|
||||
* @param id id
|
||||
*/
|
||||
@GetMapping("docinfo/detail")
|
||||
public Result<DocInfoViewDTO> getDocDetail(Long id) {
|
||||
DocInfoViewDTO docDetail = websiteService.getDocDetail(id);
|
||||
return Result.ok(docDetail);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -34,6 +34,11 @@ public class DocApp {
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 状态, 0-未发布,1-已发布
|
||||
*/
|
||||
private Integer isPublish;
|
||||
|
||||
/**
|
||||
* 添加时间
|
||||
*/
|
||||
|
@@ -9,5 +9,9 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
*/
|
||||
@Mapper
|
||||
public interface DocAppMapper extends BaseMapper<DocApp> {
|
||||
|
||||
default String getToken(Long id) {
|
||||
return this.query()
|
||||
.eq(DocApp::getId, id)
|
||||
.getValue(DocApp::getToken);
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,16 @@
|
||||
package com.gitee.sop.adminbackend.service.doc;
|
||||
|
||||
import com.gitee.fastmybatis.core.support.LambdaService;
|
||||
import com.gitee.sop.adminbackend.common.util.CopyUtil;
|
||||
import com.gitee.sop.adminbackend.dao.entity.DocApp;
|
||||
import com.gitee.sop.adminbackend.dao.mapper.DocAppMapper;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocAppDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.torna.TornaModuleDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
@@ -12,5 +18,32 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class DocAppService implements LambdaService<DocApp, DocAppMapper> {
|
||||
|
||||
@Autowired
|
||||
private TornaClient tornaClient;
|
||||
|
||||
@Autowired
|
||||
private DocInfoService docInfoService;
|
||||
|
||||
public Long addDocApp(String token) {
|
||||
TornaModuleDTO tornaModuleDTO = tornaClient.execute("module.get", null, token, TornaModuleDTO.class);
|
||||
DocApp docApp = this.get(DocApp::getToken, token);
|
||||
if (docApp == null) {
|
||||
docApp = new DocApp();
|
||||
docApp.setAppName(tornaModuleDTO.getName());
|
||||
docApp.setToken(token);
|
||||
this.save(docApp);
|
||||
} else {
|
||||
docApp.setAppName(tornaModuleDTO.getName());
|
||||
this.update(docApp);
|
||||
}
|
||||
// 同步文档
|
||||
docInfoService.syncDocInfo(docApp);
|
||||
return docApp.getId();
|
||||
}
|
||||
|
||||
public List<DocAppDTO> listDocApp() {
|
||||
List<DocApp> docApps = this.listAll();
|
||||
return CopyUtil.copyList(docApps, DocAppDTO::new);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,14 +1,22 @@
|
||||
package com.gitee.sop.adminbackend.service.doc;
|
||||
|
||||
import com.gitee.fastmybatis.core.support.LambdaService;
|
||||
import com.gitee.fastmybatis.core.util.TreeUtil;
|
||||
import com.gitee.sop.adminbackend.common.enums.DocSourceTypeEnum;
|
||||
import com.gitee.sop.adminbackend.common.enums.YesOrNoEnum;
|
||||
import com.gitee.sop.adminbackend.common.exception.BizException;
|
||||
import com.gitee.sop.adminbackend.common.util.CopyUtil;
|
||||
import com.gitee.sop.adminbackend.dao.entity.DocApp;
|
||||
import com.gitee.sop.adminbackend.dao.entity.DocInfo;
|
||||
import com.gitee.sop.adminbackend.dao.mapper.DocAppMapper;
|
||||
import com.gitee.sop.adminbackend.dao.mapper.DocInfoMapper;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.TornaDocDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.TornaDocInfoDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoPublishUpdateDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoTreeDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.torna.DocIdParam;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.torna.TornaDocDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.torna.TornaDocInfoDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.torna.TornaDocInfoViewDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.torna.TornaDocParamDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -16,6 +24,7 @@ import org.springframework.util.CollectionUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -37,11 +46,16 @@ public class DocInfoService implements LambdaService<DocInfo, DocInfoMapper> {
|
||||
}
|
||||
|
||||
public void syncDocInfo(Long docAppId) {
|
||||
Map<Object, DocInfo> nameVersionMap = this.list(DocInfo::getDocAppId, docAppId)
|
||||
DocApp docApp = docAppMapper.getById(docAppId);
|
||||
this.syncDocInfo(docApp);
|
||||
}
|
||||
|
||||
public void syncDocInfo(DocApp docApp) {
|
||||
Long docAppId = docApp.getId();
|
||||
Map<String, DocInfo> nameVersionMap = this.list(DocInfo::getDocAppId, docAppId)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(docInfo -> docInfo.getDocName() + ":" + docInfo.getDocVersion(), Function.identity(), (v1, v2) -> v2));
|
||||
|
||||
DocApp docApp = docAppMapper.getById(docAppId);
|
||||
String token = docApp.getToken();
|
||||
// add doc
|
||||
TornaDocDTO tornaDocDTO = tornaClient.execute("doc.list", null, token, TornaDocDTO.class);
|
||||
@@ -50,7 +64,7 @@ public class DocInfoService implements LambdaService<DocInfo, DocInfoMapper> {
|
||||
if (!CollectionUtils.isEmpty(docList)) {
|
||||
List<DocInfo> updateList = new ArrayList<>();
|
||||
for (TornaDocInfoDTO tornaDocInfoDTO : docList) {
|
||||
String key = tornaDocInfoDTO.getUrl() + ":" + tornaDocInfoDTO.getVersion();
|
||||
String key = buildKey(tornaDocInfoDTO);
|
||||
DocInfo docInfo = nameVersionMap.get(key);
|
||||
// 需要修改的文档
|
||||
if (docInfo != null) {
|
||||
@@ -75,7 +89,7 @@ public class DocInfoService implements LambdaService<DocInfo, DocInfoMapper> {
|
||||
// 新增的文档
|
||||
List<DocInfo> saveList = docList.stream()
|
||||
.filter(tornaDocInfoDTO -> {
|
||||
String key = tornaDocInfoDTO.getUrl() + ":" + tornaDocInfoDTO.getVersion();
|
||||
String key = buildKey(tornaDocInfoDTO);
|
||||
return !nameVersionMap.containsKey(key);
|
||||
})
|
||||
.map(tornaDocInfoDTO -> {
|
||||
@@ -87,14 +101,15 @@ public class DocInfoService implements LambdaService<DocInfo, DocInfoMapper> {
|
||||
docInfo.setDocType(tornaDocInfoDTO.getType().intValue());
|
||||
docInfo.setSourceType(DocSourceTypeEnum.TORNA.getValue());
|
||||
if (YesOrNoEnum.of(tornaDocInfoDTO.getIsFolder()) == YesOrNoEnum.YES) {
|
||||
docInfo.setIsPublish(YesOrNoEnum.YES.getValue());
|
||||
docInfo.setDocName(tornaDocInfoDTO.getName());
|
||||
} else {
|
||||
docInfo.setIsPublish(YesOrNoEnum.NO.getValue());
|
||||
docInfo.setDocName(tornaDocInfoDTO.getUrl());
|
||||
}
|
||||
docInfo.setDocVersion(tornaDocInfoDTO.getVersion());
|
||||
docInfo.setDescription(tornaDocInfoDTO.getDescription());
|
||||
docInfo.setIsFolder(tornaDocInfoDTO.getIsFolder().intValue());
|
||||
docInfo.setIsPublish(YesOrNoEnum.NO.getValue());
|
||||
docInfo.setParentId(tornaDocInfoDTO.getParentId());
|
||||
return docInfo;
|
||||
})
|
||||
@@ -103,5 +118,66 @@ public class DocInfoService implements LambdaService<DocInfo, DocInfoMapper> {
|
||||
}
|
||||
}
|
||||
|
||||
private String buildKey(TornaDocInfoDTO tornaDocInfoDTO) {
|
||||
return YesOrNoEnum.yes(tornaDocInfoDTO.getIsFolder()) ?
|
||||
tornaDocInfoDTO.getName() + ":" + tornaDocInfoDTO.getVersion()
|
||||
: tornaDocInfoDTO.getUrl() + ":" + tornaDocInfoDTO.getVersion();
|
||||
}
|
||||
|
||||
public List<DocInfoTreeDTO> listDocTree(Long docAppId) {
|
||||
List<DocInfo> list = this.list(DocInfo::getDocAppId, docAppId);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
List<DocInfoTreeDTO> docInfoTreeDTOS = CopyUtil.copyList(list, DocInfoTreeDTO::new);
|
||||
return TreeUtil.convertTree(docInfoTreeDTOS, 0L);
|
||||
}
|
||||
|
||||
public int publish(DocInfoPublishUpdateDTO docInfoUpdateDTO) {
|
||||
DocInfo docInfo = this.getById(docInfoUpdateDTO.getId());
|
||||
// 如果是文件夹,发布下面所有的文档
|
||||
if (YesOrNoEnum.of(docInfo.getIsFolder()) == YesOrNoEnum.YES) {
|
||||
List<DocInfo> children = this.listChildDoc(docInfo.getDocId());
|
||||
Set<Long> ids = children.stream().map(DocInfo::getId).collect(Collectors.toSet());
|
||||
return this.query()
|
||||
.in(DocInfo::getId, ids)
|
||||
.set(DocInfo::getIsPublish, docInfoUpdateDTO.getIsPublish())
|
||||
.update();
|
||||
} else {
|
||||
// 发布单个文档
|
||||
return this.query()
|
||||
.eq(DocInfo::getId, docInfoUpdateDTO.getId())
|
||||
.set(DocInfo::getIsPublish, docInfoUpdateDTO.getIsPublish())
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public TornaDocInfoViewDTO getDocDetail(Long id) {
|
||||
DocInfo docInfo = this.getById(id);
|
||||
if (docInfo == null) {
|
||||
throw new BizException("文档不存在");
|
||||
}
|
||||
// 获取torna文档信息
|
||||
String token = docAppMapper.getToken(docInfo.getDocAppId());
|
||||
TornaDocInfoViewDTO tornaDocInfoViewDTO = tornaClient.execute(
|
||||
"doc.detail",
|
||||
new DocIdParam(docInfo.getDocId()),
|
||||
token,
|
||||
TornaDocInfoViewDTO.class
|
||||
);
|
||||
convertTree(tornaDocInfoViewDTO);
|
||||
return tornaDocInfoViewDTO;
|
||||
}
|
||||
|
||||
private void convertTree(TornaDocInfoViewDTO tornaDocInfoViewDTO) {
|
||||
List<TornaDocParamDTO> requestParams = tornaDocInfoViewDTO.getRequestParams();
|
||||
List<TornaDocParamDTO> responseParams = tornaDocInfoViewDTO.getResponseParams();
|
||||
List<TornaDocParamDTO> requestTree = TreeUtil.convertTree(requestParams, 0L);
|
||||
List<TornaDocParamDTO> responseTree = TreeUtil.convertTree(responseParams, 0L);
|
||||
|
||||
tornaDocInfoViewDTO.setRequestParams(requestTree);
|
||||
tornaDocInfoViewDTO.setResponseParams(responseTree);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,111 +0,0 @@
|
||||
package com.gitee.sop.adminbackend.service.doc;
|
||||
|
||||
import com.gitee.fastmybatis.core.util.TreeUtil;
|
||||
import com.gitee.sop.adminbackend.common.enums.ConfigKeyEnum;
|
||||
import com.gitee.sop.adminbackend.common.enums.YesOrNoEnum;
|
||||
import com.gitee.sop.adminbackend.common.util.CopyUtil;
|
||||
import com.gitee.sop.adminbackend.dao.entity.DocApp;
|
||||
import com.gitee.sop.adminbackend.dao.entity.DocInfo;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocAppDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoPublishUpdateDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoTreeDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocSettingDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.TornaModuleDTO;
|
||||
import com.gitee.sop.adminbackend.service.sys.SysConfigService;
|
||||
import com.gitee.sop.adminbackend.service.sys.dto.SystemConfigDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Service
|
||||
public class DocService {
|
||||
|
||||
@Autowired
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
@Autowired
|
||||
private DocAppService docAppService;
|
||||
|
||||
@Autowired
|
||||
private TornaClient tornaClient;
|
||||
@Autowired
|
||||
private DocInfoService docInfoService;
|
||||
|
||||
public DocSettingDTO getDocSetting() {
|
||||
DocSettingDTO docSettingDTO = new DocSettingDTO();
|
||||
docSettingDTO.setTornaServerAddr(ConfigKeyEnum.TORNA_SERVER_ADDR.getValue());
|
||||
docSettingDTO.setOpenProdUrl(ConfigKeyEnum.OPEN_PROD_URL.getValue());
|
||||
docSettingDTO.setOpenSandboxUrl(ConfigKeyEnum.OPEN_SANDBOX_URL.getValue());
|
||||
return docSettingDTO;
|
||||
}
|
||||
|
||||
public void save(DocSettingDTO docSettingDTO) {
|
||||
Collection<SystemConfigDTO> systemConfigDTOS = new ArrayList<>();
|
||||
systemConfigDTOS.add(new SystemConfigDTO(ConfigKeyEnum.TORNA_SERVER_ADDR.getKey(), docSettingDTO.getTornaServerAddr(), "Torna服务器地址"));
|
||||
systemConfigDTOS.add(new SystemConfigDTO(ConfigKeyEnum.OPEN_PROD_URL.getKey(), docSettingDTO.getOpenProdUrl(), "开放平台线上地址"));
|
||||
systemConfigDTOS.add(new SystemConfigDTO(ConfigKeyEnum.OPEN_SANDBOX_URL.getKey(), docSettingDTO.getOpenSandboxUrl(), "开放平台沙箱地址"));
|
||||
sysConfigService.save(systemConfigDTOS);
|
||||
}
|
||||
|
||||
public Long addDocApp(String token) {
|
||||
TornaModuleDTO tornaModuleDTO = tornaClient.execute("module.get", null, token, TornaModuleDTO.class);
|
||||
DocApp docApp = docAppService.get(DocApp::getToken, token);
|
||||
if (docApp == null) {
|
||||
docApp = new DocApp();
|
||||
docApp.setAppName(tornaModuleDTO.getName());
|
||||
docApp.setToken(token);
|
||||
docAppService.save(docApp);
|
||||
} else {
|
||||
docApp.setAppName(tornaModuleDTO.getName());
|
||||
docAppService.update(docApp);
|
||||
}
|
||||
// 同步文档
|
||||
docInfoService.syncDocInfo(docApp.getId());
|
||||
return docApp.getId();
|
||||
}
|
||||
|
||||
public List<DocAppDTO> listDocApp() {
|
||||
List<DocApp> docApps = docAppService.listAll();
|
||||
return CopyUtil.copyList(docApps, DocAppDTO::new);
|
||||
}
|
||||
|
||||
public List<DocInfoTreeDTO> listDocTree(Long docAppId) {
|
||||
List<DocInfo> list = docInfoService.list(DocInfo::getDocAppId, docAppId);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
List<DocInfoTreeDTO> docInfoTreeDTOS = CopyUtil.copyList(list, DocInfoTreeDTO::new);
|
||||
return TreeUtil.convertTree(docInfoTreeDTOS, 0L);
|
||||
}
|
||||
|
||||
public int publish(DocInfoPublishUpdateDTO docInfoUpdateDTO) {
|
||||
DocInfo docInfo = docInfoService.getById(docInfoUpdateDTO.getId());
|
||||
// 如果是文件夹,发布下面所有的文档
|
||||
if (YesOrNoEnum.of(docInfo.getIsFolder()) == YesOrNoEnum.YES) {
|
||||
List<DocInfo> children = this.docInfoService.listChildDoc(docInfo.getDocId());
|
||||
Set<Long> ids = children.stream().map(DocInfo::getId).collect(Collectors.toSet());
|
||||
return docInfoService.query()
|
||||
.in(DocInfo::getId, ids)
|
||||
.set(DocInfo::getIsPublish, docInfoUpdateDTO.getIsPublish())
|
||||
.update();
|
||||
} else {
|
||||
// 发布单个文档
|
||||
return docInfoService.query()
|
||||
.eq(DocInfo::getId, docInfoUpdateDTO.getId())
|
||||
.set(DocInfo::getIsPublish, docInfoUpdateDTO.getIsPublish())
|
||||
.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package com.gitee.sop.adminbackend.service.doc;
|
||||
|
||||
import com.gitee.sop.adminbackend.common.enums.ConfigKeyEnum;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocSettingDTO;
|
||||
import com.gitee.sop.adminbackend.service.sys.SysConfigService;
|
||||
import com.gitee.sop.adminbackend.service.sys.dto.SystemConfigDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Service
|
||||
public class DocSettingService {
|
||||
|
||||
@Autowired
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
public DocSettingDTO getDocSetting() {
|
||||
DocSettingDTO docSettingDTO = new DocSettingDTO();
|
||||
docSettingDTO.setTornaServerAddr(ConfigKeyEnum.TORNA_SERVER_ADDR.getValue());
|
||||
docSettingDTO.setOpenProdUrl(ConfigKeyEnum.OPEN_PROD_URL.getValue());
|
||||
docSettingDTO.setOpenSandboxUrl(ConfigKeyEnum.OPEN_SANDBOX_URL.getValue());
|
||||
return docSettingDTO;
|
||||
}
|
||||
|
||||
public void save(DocSettingDTO docSettingDTO) {
|
||||
Collection<SystemConfigDTO> systemConfigDTOS = new ArrayList<>();
|
||||
systemConfigDTOS.add(new SystemConfigDTO(ConfigKeyEnum.TORNA_SERVER_ADDR.getKey(), docSettingDTO.getTornaServerAddr(), "Torna服务器地址"));
|
||||
systemConfigDTOS.add(new SystemConfigDTO(ConfigKeyEnum.OPEN_PROD_URL.getKey(), docSettingDTO.getOpenProdUrl(), "开放平台线上地址"));
|
||||
systemConfigDTOS.add(new SystemConfigDTO(ConfigKeyEnum.OPEN_SANDBOX_URL.getKey(), docSettingDTO.getOpenSandboxUrl(), "开放平台沙箱地址"));
|
||||
sysConfigService.save(systemConfigDTOS);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.gitee.sop.adminbackend.service.doc.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class DocInfoConfigDTO {
|
||||
|
||||
private String openProdUrl;
|
||||
private String openSandboxUrl;
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package com.gitee.sop.adminbackend.service.doc.dto;
|
||||
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.torna.TornaDocInfoViewDTO;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class DocInfoViewDTO {
|
||||
|
||||
private TornaDocInfoViewDTO docInfoView;
|
||||
|
||||
private DocInfoConfigDTO docInfoConfig;
|
||||
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
package com.gitee.sop.adminbackend.service.doc.dto.torna;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DocIdParam {
|
||||
|
||||
private Long docId;
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package com.gitee.sop.adminbackend.service.doc.dto;
|
||||
package com.gitee.sop.adminbackend.service.doc.dto.torna;
|
||||
|
||||
import lombok.Data;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package com.gitee.sop.adminbackend.service.doc.dto;
|
||||
package com.gitee.sop.adminbackend.service.doc.dto.torna;
|
||||
|
||||
import lombok.Data;
|
||||
|
@@ -0,0 +1,178 @@
|
||||
package com.gitee.sop.adminbackend.service.doc.dto.torna;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class TornaDocInfoViewDTO {
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 文档名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 文档概述
|
||||
*/
|
||||
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 0:http,1:dubbo
|
||||
*/
|
||||
private Byte type;
|
||||
|
||||
/**
|
||||
* 访问URL
|
||||
*/
|
||||
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 版本号
|
||||
*/
|
||||
private String version = "";
|
||||
|
||||
private String docKey;
|
||||
|
||||
/**
|
||||
* http方法
|
||||
*/
|
||||
|
||||
private String httpMethod;
|
||||
|
||||
/**
|
||||
* contentType
|
||||
*/
|
||||
|
||||
private String contentType;
|
||||
|
||||
|
||||
/**
|
||||
* 是否是分类,0:不是,1:是
|
||||
*/
|
||||
private Byte isFolder;
|
||||
|
||||
/**
|
||||
* 父节点
|
||||
*/
|
||||
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 模块id,module.id
|
||||
*/
|
||||
|
||||
private Long moduleId;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* 是否使用全局请求参数
|
||||
*/
|
||||
|
||||
private Byte isUseGlobalHeaders;
|
||||
|
||||
/**
|
||||
* 是否使用全局请求参数
|
||||
*/
|
||||
|
||||
private Byte isUseGlobalParams;
|
||||
|
||||
/**
|
||||
* 是否使用全局返回参数
|
||||
*/
|
||||
|
||||
private Byte isUseGlobalReturns;
|
||||
|
||||
/**
|
||||
* 是否请求数组
|
||||
*/
|
||||
|
||||
private Byte isRequestArray;
|
||||
|
||||
/**
|
||||
* 是否返回数组
|
||||
*/
|
||||
|
||||
private Byte isResponseArray;
|
||||
|
||||
/**
|
||||
* 请求数组时元素类型
|
||||
*/
|
||||
|
||||
private String requestArrayType;
|
||||
|
||||
/**
|
||||
* 返回数组时元素类型
|
||||
*/
|
||||
|
||||
private String responseArrayType;
|
||||
|
||||
/**
|
||||
* 文档状态
|
||||
*/
|
||||
|
||||
private Byte status;
|
||||
|
||||
private String remark;
|
||||
|
||||
private Integer orderIndex;
|
||||
|
||||
/**
|
||||
* 数据库字段:gmt_create
|
||||
*/
|
||||
private LocalDateTime gmtCreate;
|
||||
|
||||
/**
|
||||
* 数据库字段:gmt_modified
|
||||
*/
|
||||
private LocalDateTime gmtModified;
|
||||
|
||||
|
||||
private List<TornaDocParamDTO> pathParams = Collections.emptyList();
|
||||
|
||||
|
||||
private List<TornaDocParamDTO> headerParams = Collections.emptyList();
|
||||
|
||||
private List<TornaDocParamDTO> headerParamsRaw = Collections.emptyList();
|
||||
|
||||
|
||||
private List<TornaDocParamDTO> queryParams = Collections.emptyList();
|
||||
|
||||
|
||||
private List<TornaDocParamDTO> requestParams = Collections.emptyList();
|
||||
|
||||
|
||||
private List<TornaDocParamDTO> responseParams = Collections.emptyList();
|
||||
|
||||
private List<TornaDocParamDTO> errorCodeParams = Collections.emptyList();
|
||||
|
||||
private List<TornaDocParamDTO> globalHeaders = Collections.emptyList();
|
||||
private List<TornaDocParamDTO> globalParams = Collections.emptyList();
|
||||
private List<TornaDocParamDTO> globalReturns = Collections.emptyList();
|
||||
|
||||
private String errorCodeInfo;
|
||||
|
||||
private List<TornaDocInfoViewDTO> children = Collections.emptyList();
|
||||
|
||||
public String getDocName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDocTitle() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,128 @@
|
||||
package com.gitee.sop.adminbackend.service.doc.dto.torna;
|
||||
|
||||
import com.gitee.fastmybatis.core.support.TreeNode;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class TornaDocParamDTO implements TreeNode<TornaDocParamDTO, Long> {
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 字段名称
|
||||
*/
|
||||
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 字段类型
|
||||
*/
|
||||
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 是否必须,1:是,0:否
|
||||
*/
|
||||
|
||||
private Byte required;
|
||||
|
||||
/**
|
||||
* 最大长度
|
||||
*/
|
||||
|
||||
private String maxLength;
|
||||
|
||||
/**
|
||||
* 示例值
|
||||
*/
|
||||
private String example;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
|
||||
private String description;
|
||||
|
||||
|
||||
private Long enumId;
|
||||
|
||||
/**
|
||||
* doc_info.id
|
||||
*/
|
||||
|
||||
private Long docId;
|
||||
|
||||
/**
|
||||
* 父节点
|
||||
*/
|
||||
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 0:header, 1:请求参数,2:返回参数,3:错误码
|
||||
*/
|
||||
private Byte style;
|
||||
|
||||
/**
|
||||
* 新增操作方式,0:人工操作,1:开放平台推送
|
||||
*/
|
||||
private Byte createMode;
|
||||
|
||||
/**
|
||||
* 修改操作方式,0:人工操作,1:开放平台推送
|
||||
*/
|
||||
private Byte modifyMode;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String creatorName;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String modifierName;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer orderIndex;
|
||||
|
||||
private Byte isDeleted;
|
||||
|
||||
/**
|
||||
* 数据库字段:gmt_create
|
||||
*/
|
||||
private LocalDateTime gmtCreate;
|
||||
|
||||
/**
|
||||
* 数据库字段:gmt_modified
|
||||
*/
|
||||
private LocalDateTime gmtModified;
|
||||
|
||||
private boolean global;
|
||||
|
||||
private List<TornaDocParamDTO> children;
|
||||
|
||||
|
||||
public boolean getRequire() {
|
||||
return Objects.equals(this.required, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long takeId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long takeParentId() {
|
||||
return parentId;
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
package com.gitee.sop.adminbackend.service.doc.dto;
|
||||
package com.gitee.sop.adminbackend.service.doc.dto.torna;
|
||||
|
||||
import lombok.Data;
|
||||
|
@@ -1,13 +1,19 @@
|
||||
package com.gitee.sop.adminbackend.service.website;
|
||||
|
||||
import com.gitee.fastmybatis.core.util.TreeUtil;
|
||||
import com.gitee.sop.adminbackend.common.enums.YesOrNoEnum;
|
||||
import com.gitee.sop.adminbackend.common.util.CopyUtil;
|
||||
import com.gitee.sop.adminbackend.dao.entity.DocApp;
|
||||
import com.gitee.sop.adminbackend.dao.entity.DocInfo;
|
||||
import com.gitee.sop.adminbackend.dao.mapper.DocAppMapper;
|
||||
import com.gitee.sop.adminbackend.dao.mapper.DocInfoMapper;
|
||||
import com.gitee.sop.adminbackend.service.doc.DocAppService;
|
||||
import com.gitee.sop.adminbackend.service.doc.DocInfoService;
|
||||
import com.gitee.sop.adminbackend.service.doc.DocSettingService;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocAppDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoConfigDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoTreeDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocInfoViewDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.DocSettingDTO;
|
||||
import com.gitee.sop.adminbackend.service.doc.dto.torna.TornaDocInfoViewDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -20,19 +26,39 @@ import java.util.List;
|
||||
public class WebsiteService {
|
||||
|
||||
@Autowired
|
||||
private DocAppMapper docAppMapper;
|
||||
private DocAppService docAppService;
|
||||
@Autowired
|
||||
private DocInfoMapper docInfoMapper;
|
||||
private DocInfoService docInfoService;
|
||||
@Autowired
|
||||
private DocSettingService docSettingService;
|
||||
|
||||
public List<DocAppDTO> listDocApp() {
|
||||
List<DocApp> docApps = docAppMapper.listAll();
|
||||
List<DocApp> docApps = docAppService.list(DocApp::getIsPublish, YesOrNoEnum.YES.getValue());
|
||||
return CopyUtil.copyList(docApps, DocAppDTO::new);
|
||||
}
|
||||
|
||||
public List<DocInfoTreeDTO> listDocMenuTree(Long docAppId) {
|
||||
List<DocInfo> list = docInfoMapper.list(DocInfo::getDocAppId, docAppId);
|
||||
List<DocInfo> list = docInfoService.query()
|
||||
.eq(DocInfo::getDocAppId, docAppId)
|
||||
.eq(DocInfo::getIsPublish, YesOrNoEnum.YES.getValue())
|
||||
.list();
|
||||
List<DocInfoTreeDTO> treeList = CopyUtil.copyList(list, DocInfoTreeDTO::new);
|
||||
return TreeUtil.convertTree(treeList, 0L);
|
||||
}
|
||||
|
||||
public DocInfoViewDTO getDocDetail(Long id) {
|
||||
TornaDocInfoViewDTO tornaDocInfoViewDTO = docInfoService.getDocDetail(id);
|
||||
DocInfoConfigDTO docInfoConfigDTO = buildDocInfoConfig();
|
||||
|
||||
DocInfoViewDTO docInfoViewDTO = new DocInfoViewDTO();
|
||||
docInfoViewDTO.setDocInfoView(tornaDocInfoViewDTO);
|
||||
docInfoViewDTO.setDocInfoConfig(docInfoConfigDTO);
|
||||
return docInfoViewDTO;
|
||||
}
|
||||
|
||||
|
||||
private DocInfoConfigDTO buildDocInfoConfig() {
|
||||
DocSettingDTO docSetting = docSettingService.getDocSetting();
|
||||
return CopyUtil.copyBean(docSetting, DocInfoConfigDTO::new);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user