模版编制相关实现
This commit is contained in:
@@ -7,7 +7,7 @@ public enum DeleteStatusEnum {
|
||||
|
||||
STATUS_DRF(TmplStsEnum.DRAFT.getCode(), new HashSet<>() {{add(TmplStsEnum.DRAFT.getCode());}}),
|
||||
STATUS_PUB(TmplStsEnum.PUBLISHED.getCode(), new HashSet<>()),
|
||||
STATUS_STOP(TmplStsEnum.STOPPED.getCode(), new HashSet<>());
|
||||
STATUS_STOP(TmplStsEnum.STOPPED.getCode(), new HashSet<>(){{add(TmplStsEnum.STOPPED.getCode());}});
|
||||
|
||||
|
||||
private final String code;
|
||||
|
||||
@@ -59,11 +59,11 @@ public class TemplateInstanceController extends AbstractFileUploadController {
|
||||
private TemplateInstanceService templateInstanceService;
|
||||
|
||||
//上传文件
|
||||
@PostMapping("/save-file")
|
||||
@Operation(summary = "上传文件", description = "上传文件,传入文件对象和模版实例id")
|
||||
public CommonResult<Map<String, Object>> uploadFile(@NotEmpty(message = "文件不能为空") @RequestParam("file") MultipartFile file,@RequestParam("id") String id) {
|
||||
return success(templateInstanceService.saveFile(file,id));
|
||||
}
|
||||
// @PostMapping("/save-file")
|
||||
// @Operation(summary = "上传文件", description = "上传文件,传入文件对象和模版实例id")
|
||||
// public CommonResult<Map<String, Object>> uploadFile(@NotEmpty(message = "文件不能为空") @RequestParam("file") MultipartFile file,@RequestParam("id") String id) {
|
||||
// return success(templateInstanceService.saveFile(file,id));
|
||||
// }
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建模板实例")
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.zt.plat.module.base.controller.admin.templtp.onlyoffice.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import com.zt.plat.module.base.controller.admin.templtp.onlyoffice.pojo.Action;
|
||||
import com.zt.plat.module.base.controller.admin.templtp.onlyoffice.pojo.History;
|
||||
import com.zt.plat.module.base.controller.admin.templtp.onlyoffice.pojo.OnlyOfficeCallback;
|
||||
import com.zt.plat.module.base.service.tmpltp.TemplateInstanceService;
|
||||
import com.zt.plat.module.infra.api.file.FileApi;
|
||||
import com.zt.plat.module.infra.api.file.dto.FileCreateReqDTO;
|
||||
import com.zt.plat.module.infra.api.file.dto.FileRespDTO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -13,6 +16,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.zt.plat.module.base.controller.admin.templtp.onlyoffice.util.UrlFileDownloader.downloadFileAsMultipart;
|
||||
|
||||
@@ -23,6 +28,7 @@ import static com.zt.plat.module.base.controller.admin.templtp.onlyoffice.util.U
|
||||
public class OnlyOfficeCallbackServiceImpl implements OnlyOfficeCallbackService {
|
||||
|
||||
private final FileApi fileApi;
|
||||
private final TemplateInstanceService templateInstanceService;
|
||||
@Override
|
||||
public void processCallback(OnlyOfficeCallback callback,String id) {
|
||||
log.info("Received OnlyOffice callback for document: {}", callback.getKey());
|
||||
@@ -151,7 +157,21 @@ public class OnlyOfficeCallbackServiceImpl implements OnlyOfficeCallbackService
|
||||
fileCreateReqDTO.setDirectory(directory); // 设置文件存储目录
|
||||
|
||||
// 7. 调用文件服务创建文件
|
||||
CommonResult<String> result = fileApi.createFile(fileCreateReqDTO);
|
||||
CommonResult<FileRespDTO> result = fileApi.createFileWithReturn(fileCreateReqDTO);
|
||||
if (result.isSuccess()) {
|
||||
// 创建文件成功,处理结果
|
||||
log.info("文件创建成功,文件ID:{}", result.getData());
|
||||
// 创建文件成功,处理结果
|
||||
FileRespDTO fileRespDTO = result.getData();
|
||||
Map<String, Object> fileInfo = new HashMap<>();
|
||||
fileInfo.put("id", fileRespDTO.getId());
|
||||
fileInfo.put("name", fileRespDTO.getName());
|
||||
fileInfo.put("directory", fileRespDTO.getDirectory());
|
||||
templateInstanceService.updateTemplateInstanceFileUrlByInstanceId(id, JSONObject.toJSONString(fileInfo));
|
||||
} else {
|
||||
// 创建文件失败,处理错误
|
||||
log.error("文件创建失败,错误信息:{}", result.getMsg());
|
||||
}
|
||||
log.info("文件创建结果:{}", result);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
@Schema(description = "管理后台 - 实例启用与禁用 Request VO")
|
||||
@Data
|
||||
public class DisableEnableReqVO {
|
||||
@Schema(description = "实例主键(id)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@Schema(description = "实例主键(id)", requiredMode = Schema.RequiredMode.REQUIRED, example = "['1','2']")
|
||||
@NotEmpty(message = "实例主键不能为空")
|
||||
private List<String> ids;
|
||||
@Schema(description = "操作类型;操作类型type,type的值启用为enable,禁用为disable", requiredMode = Schema.RequiredMode.REQUIRED, example = "enable")
|
||||
|
||||
@@ -83,6 +83,8 @@ public interface TemplateInstanceService {
|
||||
Map<String, Object> getVersion(String id);
|
||||
|
||||
List<TemplateInstanceRespVO> listByCdg(String cdg);
|
||||
//
|
||||
// Map<String, Object> saveFile(MultipartFile file, String id);
|
||||
|
||||
Map<String, Object> saveFile(MultipartFile file, String id);
|
||||
boolean updateTemplateInstanceFileUrlByInstanceId(@Valid @NotEmpty(message = "模版实例id不能为空") String id, @Valid @NotEmpty(message = "文件参数不能为空") String params);
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ private String incrementVersion(String currentVersion) {
|
||||
throw exception(STATUS_OPERATION_FAIL);
|
||||
}
|
||||
});
|
||||
|
||||
log.info("发布模版实例【{}】", publishReqVOS.stream().map(PublishTemplateInstanceReqVO::getId));
|
||||
templateInstanceMapper.update(new LambdaUpdateWrapper<TemplateInstanceDO>()
|
||||
.in(TemplateInstanceDO::getId, publishReqVOS.stream()
|
||||
.map(PublishTemplateInstanceReqVO::getId)
|
||||
@@ -286,14 +286,18 @@ private String incrementVersion(String currentVersion) {
|
||||
@Override
|
||||
public void setDisableOrEnable(DisableEnableReqVO reqVO) {
|
||||
validateTemplateInstanceExists(reqVO.getIds().stream().map(Long::valueOf).toList());
|
||||
String code;
|
||||
String code = "";
|
||||
if (reqVO.getType().equals("disable")) {
|
||||
// 禁用
|
||||
code = TmplStsEnum.STOPPED.getCode();
|
||||
} else {
|
||||
} else if (reqVO.getType().equals("enable")) {
|
||||
// 启用
|
||||
code = TmplStsEnum.PUBLISHED.getCode();
|
||||
}
|
||||
if (code.isEmpty()) {
|
||||
throw exception(ILLEGAL_OPERATION_TYPE);
|
||||
}
|
||||
log.info("=============================当前操作记录为【{}】操作动作为:【{}】================================", reqVO.getIds(), reqVO.getType());
|
||||
templateInstanceMapper.update(new LambdaUpdateWrapper<TemplateInstanceDO>()
|
||||
.set(TemplateInstanceDO::getSts, code)
|
||||
.in(TemplateInstanceDO::getId, reqVO.getIds()));
|
||||
@@ -352,6 +356,7 @@ private String incrementVersion(String currentVersion) {
|
||||
departmentInstanceRelativityMapper.insertBatch(newDepartmentInstanceRelativityDOS);
|
||||
log.info("==================部门实例关系插入成功,共插入【{}】条记录==================", newDepartmentInstanceRelativityDOS.size());
|
||||
TemplateInstanceRespVO templateInstanceRespVO = BeanUtils.toBean(newTpInstanceDO, TemplateInstanceRespVO.class);
|
||||
log.info("==================模板实例插入成功==================");
|
||||
getDetailedInfo(templateInstanceRespVO);
|
||||
return templateInstanceRespVO;
|
||||
}
|
||||
@@ -378,11 +383,7 @@ private String incrementVersion(String currentVersion) {
|
||||
return templateInstanceRespVOS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> saveFile(MultipartFile file, String id) {
|
||||
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@@ -392,6 +393,13 @@ private String incrementVersion(String currentVersion) {
|
||||
templateInstanceRespVO.setTemplateInstanceDataRespVOS(setTemplateInstanceDataRespVOS(templateInstanceRespVO.getId())); // 实例字段
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateTemplateInstanceFileUrlByInstanceId(String id, String params) {
|
||||
validateTemplateInstanceExists(Long.valueOf(id));
|
||||
LambdaUpdateWrapper<TemplateInstanceDO> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(TemplateInstanceDO::getId, id).set(TemplateInstanceDO::getCntt, params);
|
||||
return templateInstanceMapper.update(updateWrapper)>0;
|
||||
}
|
||||
// 实例条款值
|
||||
private List<TemplateInstanceItemRespVO> setInstanceItemRespVOS(Long id) {
|
||||
List<TemplateInstanceItemDO> templateInstanceItemDOS = templateInstanceItemMapper.selectList(new LambdaQueryWrapper<TemplateInstanceItemDO>()
|
||||
@@ -428,6 +436,9 @@ private String incrementVersion(String currentVersion) {
|
||||
boolean transitionAllowed = false;
|
||||
if (deleteStatusEnum != null) {
|
||||
transitionAllowed = deleteStatusEnum.isTransitionAllowed(TmplStsEnum.DRAFT.getCode());
|
||||
if (!transitionAllowed) {
|
||||
transitionAllowed = deleteStatusEnum.isTransitionAllowed(TmplStsEnum.STOPPED.getCode());
|
||||
}
|
||||
}
|
||||
if (!transitionAllowed) {
|
||||
throw exception(STATUS_OPERATION_FAIL);
|
||||
@@ -458,6 +469,7 @@ private String incrementVersion(String currentVersion) {
|
||||
throw exception(STATUS_OPERATION_FAIL);
|
||||
}
|
||||
}
|
||||
|
||||
private String getCdg() {
|
||||
return "TP" + DateUtils.format(new Date(), "yyyyMMddHHmmssSSS") + RandomUtil.randomNumbers(4);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user