|
|
@@ -1,8 +1,16 @@
|
|
|
package com.yingpaipay.business.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.yingpaipay.business.constant.DictTypeConst;
|
|
|
-import com.yingpaipay.business.domain.bo.DocumentMarkBo;
|
|
|
+import com.yingpaipay.business.constant.DocumentAuditorTypeConst;
|
|
|
+import com.yingpaipay.business.constant.DocumentStatusConst;
|
|
|
+import com.yingpaipay.business.domain.DocumentAuditLog;
|
|
|
+import com.yingpaipay.business.domain.bo.*;
|
|
|
+import com.yingpaipay.business.domain.vo.DocumentAuditLogVo;
|
|
|
+import com.yingpaipay.business.mapper.DocumentAuditLogMapper;
|
|
|
+import org.dromara.common.core.exception.BusinessException;
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.MessageUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
@@ -11,17 +19,19 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
+import org.dromara.common.tenant.helper.TenantHelper;
|
|
|
import org.dromara.system.domain.vo.SysOssVo;
|
|
|
import org.dromara.system.service.ISysDictDataService;
|
|
|
import org.dromara.system.service.ISysDictTypeService;
|
|
|
import org.dromara.system.service.ISysOssService;
|
|
|
import org.dromara.system.service.ISysUserService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.yingpaipay.business.domain.bo.DocumentBo;
|
|
|
import com.yingpaipay.business.domain.vo.DocumentVo;
|
|
|
import com.yingpaipay.business.domain.Document;
|
|
|
import com.yingpaipay.business.mapper.DocumentMapper;
|
|
|
import com.yingpaipay.business.service.IDocumentService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
@@ -37,6 +47,7 @@ import java.util.*;
|
|
|
public class DocumentServiceImpl implements IDocumentService {
|
|
|
|
|
|
private final DocumentMapper baseMapper;
|
|
|
+ private final DocumentAuditLogMapper auditLogMapper;
|
|
|
|
|
|
private final ISysDictTypeService dictTypeService;
|
|
|
private final ISysOssService ossService;
|
|
|
@@ -190,4 +201,108 @@ public class DocumentServiceImpl implements IDocumentService {
|
|
|
.set(Document::getType, bo.getType())
|
|
|
) > 0;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean submit(DocumentSubmitBo bo) {
|
|
|
+ return baseMapper.update(
|
|
|
+ Wrappers.lambdaUpdate(Document.class)
|
|
|
+ .eq(Document::getId, bo.getDocumentId())
|
|
|
+ .set(Document::getOssId, bo.getOssId())
|
|
|
+ .set(Document::getSubmitterId, LoginHelper.getUserId())
|
|
|
+ .set(Document::getStatus, DocumentStatusConst.UN_AUDIT)
|
|
|
+ ) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean audit(DocumentAuditBo bo) {
|
|
|
+
|
|
|
+ Document document = baseMapper.selectById(bo.getDocumentId());
|
|
|
+ if (document == null) {
|
|
|
+ throw new BusinessException(MessageUtils.message("document.document.audit.documentnotfound"));
|
|
|
+ }
|
|
|
+ document.setStatus(bo.getResult());
|
|
|
+ boolean documentFlag = baseMapper.updateById(document) == 0;
|
|
|
+ if (documentFlag) {
|
|
|
+ throw new RuntimeException("修改文档状态失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean logFlag = auditLogMapper.insert(buildLog(document, DocumentAuditorTypeConst.MANUAL, bo)) == 0;
|
|
|
+ if (logFlag) {
|
|
|
+ throw new RuntimeException("新增审核日志失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean confirmSubmit(Long id) {
|
|
|
+ return baseMapper.deleteById(id) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<DocumentAuditLogVo> logAudit(DocumentAuditLogBo bo, PageQuery pageQuery) {
|
|
|
+ if (bo.getDocumentId() == null) {
|
|
|
+ return TableDataInfo.build();
|
|
|
+ }
|
|
|
+ IPage<DocumentAuditLogVo> page = auditLogMapper.selectVoPage(
|
|
|
+ pageQuery.build(),
|
|
|
+ Wrappers.lambdaQuery(DocumentAuditLog.class)
|
|
|
+ .orderByDesc(DocumentAuditLog::getId)
|
|
|
+ .eq(DocumentAuditLog::getDocumentId, bo.getDocumentId())
|
|
|
+ .eq(bo.getResult() != null, DocumentAuditLog::getResult, bo.getResult())
|
|
|
+ .ge(bo.getParams().containsKey("earliestTime"), DocumentAuditLog::getAuditTime, bo.getParams().get("earliestTime"))
|
|
|
+ .le(bo.getParams().containsKey("lagtestTime"), DocumentAuditLog::getAuditTime, bo.getParams().get("lagtestTime"))
|
|
|
+ );
|
|
|
+ buildLogVos(page.getRecords());
|
|
|
+ return TableDataInfo.build(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void buildLogVos(List<DocumentAuditLogVo> vos) {
|
|
|
+ List<Long> documentIds = new ArrayList<>();
|
|
|
+ Map<Long, Document> documentMap = new HashMap<>();
|
|
|
+ List<Long> ossIds = new ArrayList<>();
|
|
|
+ Map<Long, SysOssVo> ossMap = new HashMap<>();
|
|
|
+ vos.forEach(e -> {
|
|
|
+ documentIds.add(e.getDocumentId());
|
|
|
+ ossIds.add(e.getOssId());
|
|
|
+ });
|
|
|
+ ossService.queryListByIds(ossIds).forEach(e -> ossMap.put(e.getOssId(), e));
|
|
|
+ if (!documentIds.isEmpty()) {
|
|
|
+ baseMapper.selectByIds(documentIds).forEach(e -> documentMap.put(e.getId(), e));
|
|
|
+ }
|
|
|
+ vos.forEach(e -> {
|
|
|
+ SysOssVo ossVo = ossMap.get(e.getOssId());
|
|
|
+ Document document = documentMap.get(e.getDocumentId());
|
|
|
+ e.setOssUrl(Optional.ofNullable(ossVo).map(SysOssVo::getUrl).orElse(null));
|
|
|
+ e.setDocumentName(Optional.ofNullable(document).map(Document::getName).orElse(null));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean filing(DocumentFilingBo bo) {
|
|
|
+ return baseMapper.update(
|
|
|
+ Wrappers.lambdaUpdate(Document.class)
|
|
|
+ .eq(Document::getId, bo.getDocumentId())
|
|
|
+ .set(Document::getStatus, DocumentStatusConst.FILING)
|
|
|
+ ) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private DocumentAuditLog buildLog(Document document, String type, DocumentAuditBo bo) {
|
|
|
+ DocumentAuditLog log = new DocumentAuditLog();
|
|
|
+ log.setDocumentId(document.getId());
|
|
|
+ log.setOssId(document.getOssId());
|
|
|
+ log.setAuditorType(type);
|
|
|
+ log.setAuditorId(LoginHelper.getUserId());
|
|
|
+ log.setResult(bo.getResult());
|
|
|
+ log.setRejectReason(bo.getRejectReason());
|
|
|
+ log.setAuditTime(new Date());
|
|
|
+ log.setTenantId(TenantHelper.getTenantId());
|
|
|
+ log.setCreateDept(LoginHelper.getDeptId());
|
|
|
+ log.setCreateBy(LoginHelper.getUserId());
|
|
|
+ log.setCreateTime(new Date());
|
|
|
+ log.setUpdateBy(LoginHelper.getUserId());
|
|
|
+ log.setUpdateTime(new Date());
|
|
|
+ return log;
|
|
|
+ }
|
|
|
}
|