|
@@ -1,23 +1,34 @@
|
|
|
package com.github.jfcloud.gene.flow.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.crypto.digest.DigestUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.jfcloud.common.data.datascope.DataScope;
|
|
|
+import com.github.jfcloud.common.holder.RequestHolder;
|
|
|
import com.github.jfcloud.gene.cache.UserIdNameCache;
|
|
|
import com.github.jfcloud.gene.common.constant.StrConstant;
|
|
|
import com.github.jfcloud.gene.common.constant.WhetherEnum;
|
|
|
import com.github.jfcloud.gene.common.util.CustomIdGenerator;
|
|
|
import com.github.jfcloud.gene.constants.GeneStatusEnum;
|
|
|
import com.github.jfcloud.gene.constants.GeneTargetEnum;
|
|
|
+import com.github.jfcloud.gene.file.service.FileInfoService;
|
|
|
+import com.github.jfcloud.gene.file.vo.FileVo;
|
|
|
import com.github.jfcloud.gene.flow.dto.FlowDetailDto;
|
|
|
import com.github.jfcloud.gene.flow.dto.FlowPageDto;
|
|
|
import com.github.jfcloud.gene.flow.entity.FlowAudit;
|
|
|
+import com.github.jfcloud.gene.flow.entity.FlowFileVersion;
|
|
|
import com.github.jfcloud.gene.flow.entity.FlowInfo;
|
|
|
import com.github.jfcloud.gene.flow.mapper.FlowInfoMapper;
|
|
|
+import com.github.jfcloud.gene.flow.service.FlowFileVersionService;
|
|
|
import com.github.jfcloud.gene.flow.service.FlowInfoService;
|
|
|
import com.github.jfcloud.gene.flow.service.NotifyService;
|
|
|
import com.github.jfcloud.gene.flow.vo.FlowAuditVo;
|
|
@@ -27,10 +38,20 @@ import com.github.jfcloud.gene.form.entity.StrainCustomInfo;
|
|
|
import com.github.jfcloud.gene.form.entity.StrainPurificationInfo;
|
|
|
import com.github.jfcloud.gene.form.service.StrainCustomInfoService;
|
|
|
import com.github.jfcloud.gene.form.service.StrainPurificationInfoService;
|
|
|
+import com.github.jfcloud.gene.util.WordDataService;
|
|
|
+import com.github.jfcloud.gene.util.WordUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.docx4j.Docx4J;
|
|
|
+import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
@@ -43,6 +64,9 @@ public class FlowInfoServiceImpl extends ServiceImpl<FlowInfoMapper, FlowInfo> i
|
|
|
private final StrainCustomInfoService customInfoService;
|
|
|
private final StrainPurificationInfoService purificationInfoService;
|
|
|
private final NotifyService notifyService;
|
|
|
+ private final WordDataService wordDataService;
|
|
|
+ private final FileInfoService fileInfoService;
|
|
|
+ private final FlowFileVersionService fileVersionService;
|
|
|
|
|
|
@Override
|
|
|
public Page<FlowPageDto> getPage(FlowPageVo vo) {
|
|
@@ -68,8 +92,13 @@ public class FlowInfoServiceImpl extends ServiceImpl<FlowInfoMapper, FlowInfo> i
|
|
|
}
|
|
|
|
|
|
List<FlowPageDto> records = BeanUtil.copyToList(page.getRecords(), FlowPageDto.class);
|
|
|
- //补充申请人姓名
|
|
|
- records.forEach(item -> item.setCreateByName(userIdNameCache.getNicknameByUserId(Long.parseLong(item.getCreateBy()))));
|
|
|
+
|
|
|
+ records.forEach(item -> {
|
|
|
+ //补充申请人姓名
|
|
|
+ item.setCreateByName(userIdNameCache.getNicknameByUserId(Long.parseLong(item.getCreateBy())));
|
|
|
+ //查询下载链接
|
|
|
+ item.setFileUrl(fileVersionService.getLatestFileUrl(item.getId()));
|
|
|
+ });
|
|
|
|
|
|
Page<FlowPageDto> pageDto = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
|
|
|
return pageDto.setRecords(records);
|
|
@@ -84,9 +113,14 @@ public class FlowInfoServiceImpl extends ServiceImpl<FlowInfoMapper, FlowInfo> i
|
|
|
detail.setStatusLabel(Objects.requireNonNull(GeneStatusEnum.getByStatus(detail.getStatus())).getDescription());
|
|
|
detail.setCustom(customInfoService.getByFlowId(id));
|
|
|
detail.setPurification(purificationInfoService.getByFlowId(id));
|
|
|
+
|
|
|
+ //查询下载链接
|
|
|
+ detail.setFileUrl(fileVersionService.getLatestFileUrl(id));
|
|
|
+
|
|
|
return detail;
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void saveFlow(FlowDetailVo vo) {
|
|
|
log.info("保存流程 项目名称:{}", vo.getProjectName());
|
|
@@ -114,8 +148,11 @@ public class FlowInfoServiceImpl extends ServiceImpl<FlowInfoMapper, FlowInfo> i
|
|
|
}
|
|
|
flowInfo.setStatus(GeneStatusEnum.DRAFT.getStatus());
|
|
|
flowInfo.insert();
|
|
|
+
|
|
|
+ geneWord(flowInfo.getId());
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void updateFlow(Long id, FlowDetailVo vo) {
|
|
|
log.info("编辑流程 项目名称:{}", vo.getProjectName());
|
|
@@ -124,7 +161,6 @@ public class FlowInfoServiceImpl extends ServiceImpl<FlowInfoMapper, FlowInfo> i
|
|
|
Assert.notNull(flowInfo, "基因定制流程不存在");
|
|
|
BeanUtil.copyProperties(vo, flowInfo);
|
|
|
|
|
|
-
|
|
|
StringBuilder target = new StringBuilder();
|
|
|
if (vo.getCustom() == null) {
|
|
|
customInfoService.remove(new LambdaQueryWrapper<>(StrainCustomInfo.class).eq(StrainCustomInfo::getFlowId, id));
|
|
@@ -148,6 +184,8 @@ public class FlowInfoServiceImpl extends ServiceImpl<FlowInfoMapper, FlowInfo> i
|
|
|
|
|
|
flowInfo.setTarget(target.toString());
|
|
|
flowInfo.updateById();
|
|
|
+
|
|
|
+ geneWord(flowInfo.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -233,4 +271,51 @@ public class FlowInfoServiceImpl extends ServiceImpl<FlowInfoMapper, FlowInfo> i
|
|
|
public void execute(Long id) {
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成word
|
|
|
+ */
|
|
|
+ @SneakyThrows
|
|
|
+ public void geneWord(Long flowId) {
|
|
|
+ FlowDetailDto detail = getDetail(flowId);
|
|
|
+ FlowInfo flowInfo = getById(flowId);
|
|
|
+
|
|
|
+ //文件名称:项目名称-负责人-申请日期-随机四位.docx
|
|
|
+ String createDate = DateUtil.format(flowInfo.getCreateTime(), DatePattern.CHINESE_DATE_PATTERN);
|
|
|
+ String fileName = String.format("%s-%s-%s-%s.docx", detail.getProjectName(), detail.getProjectLeaderName(), createDate,
|
|
|
+ RandomUtil.randomString(RandomUtil.BASE_CHAR_NUMBER_LOWER, 4));
|
|
|
+ log.info("生成word 项目名称:{} 文件名称:{}", detail.getProjectName(), fileName);
|
|
|
+
|
|
|
+ JSONObject dataMap = JSON.parseObject(JSON.toJSONString(detail));
|
|
|
+ wordDataService.fillDocCreator(dataMap);
|
|
|
+
|
|
|
+ String modelName = "geneCustom.ftl";
|
|
|
+
|
|
|
+ try (InputStream inputStream = WordUtil.exportWord(modelName, dataMap);
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
|
+ //转化为docx文件
|
|
|
+ WordprocessingMLPackage pkg = Docx4J.load(inputStream);
|
|
|
+ Docx4J.save(pkg, out);
|
|
|
+
|
|
|
+ //上传至文件服务器
|
|
|
+ byte[] byteArray = out.toByteArray();
|
|
|
+ try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray)) {
|
|
|
+ FileVo fileVo = fileInfoService.uploadFileWithFileName(byteArrayInputStream, fileName);
|
|
|
+
|
|
|
+ HttpServletRequest request = RequestHolder.getRequest();
|
|
|
+ String uri = request.getMethod() + " " + request.getRequestURI();
|
|
|
+
|
|
|
+ new FlowFileVersion()
|
|
|
+ .setFlowId(flowInfo.getId())
|
|
|
+ .setFlowStatus(flowInfo.getStatus())
|
|
|
+ .setDataMap(dataMap.toJSONString())
|
|
|
+ .setFileMd5(DigestUtil.md5Hex(byteArray))
|
|
|
+ .setFilename(fileVo.getName())
|
|
|
+ .setFilepath(fileVo.getUrl())
|
|
|
+ .setUri(uri)
|
|
|
+ .setTemplateName(modelName)
|
|
|
+ .insert();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|