|
@@ -16,29 +16,49 @@
|
|
|
*/
|
|
|
package org.springblade.business.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.date.DateField;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.spire.pdf.PdfPageBase;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springblade.business.dto.StartTimeAndEndTime;
|
|
|
import org.springblade.business.entity.ContractLog;
|
|
|
+import org.springblade.business.entity.ContractLogMonthPack;
|
|
|
import org.springblade.business.entity.Task;
|
|
|
import org.springblade.business.entity.TaskParallel;
|
|
|
import org.springblade.business.mapper.ContractLogMapper;
|
|
|
+import org.springblade.business.service.ContractLogMonthPackService;
|
|
|
import org.springblade.business.service.IContractLogService;
|
|
|
+import org.springblade.business.utils.FileUtils;
|
|
|
import org.springblade.business.vo.ContractLogVO;
|
|
|
import org.springblade.business.vo.FileUserVO;
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.core.mp.support.Condition;
|
|
|
import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.oss.model.BladeFile;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
-import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.utils.*;
|
|
|
import org.springblade.manager.feign.ExcelTabClient;
|
|
|
+import org.springblade.resource.feign.NewIOSSClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.dao.DataAccessException;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -55,6 +75,14 @@ public class ContractLogServiceImpl extends BaseServiceImpl<ContractLogMapper, C
|
|
|
|
|
|
@Autowired
|
|
|
private ExcelTabClient excelTabClient;
|
|
|
+ /**
|
|
|
+ * 按月封装对象
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private ContractLogMonthPackService contractLogMonthPackService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private NewIOSSClient newIOSSClient;
|
|
|
|
|
|
|
|
|
public ContractLogServiceImpl(JdbcTemplate jdbcTemplate) {
|
|
@@ -207,4 +235,139 @@ public class ContractLogServiceImpl extends BaseServiceImpl<ContractLogMapper, C
|
|
|
return iPage.setRecords(deduplicatedList);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean byMonthPack(ContractLogVO logVo) {
|
|
|
+ //获取当前用户id
|
|
|
+ Long userId = SecureUtil.getUserId();
|
|
|
+
|
|
|
+ //所有月份
|
|
|
+ List<DateTime> monthAll = new ArrayList<>();
|
|
|
+
|
|
|
+ logVo.getStartTimeAndEndTimes().forEach(f -> {
|
|
|
+ List<DateTime> dateTimes = DateUtil.rangeToList(DateUtil.parse(f.getStartTime(),"yyyy-MM"), DateUtil.parse(f.getEndTime(),"yyyy-MM"), DateField.MONTH);
|
|
|
+ monthAll.addAll(dateTimes);
|
|
|
+ });
|
|
|
+
|
|
|
+ //查询所有数据
|
|
|
+ List<ContractLog> contractLogs = baseMapper.selectList(Wrappers.<ContractLog>lambdaQuery()
|
|
|
+ .eq(ContractLog::getContractId, logVo.getContractId())
|
|
|
+ .eq(ContractLog::getWbsNodeId, logVo.getWbsNodeId())
|
|
|
+ .isNotNull(ContractLog::getPdfUrl)
|
|
|
+ .orderByAsc(ContractLog::getRecordTime)
|
|
|
+ );
|
|
|
+ if(CollectionUtil.isEmpty(contractLogs)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //按月分组
|
|
|
+ Map<String, List<ContractLog>> collect = contractLogs.stream().filter(f -> StringUtil.isNotBlank(f.getRecordTime())).collect(Collectors.groupingBy(log -> {
|
|
|
+ String dateStr = log.getRecordTime();
|
|
|
+ // 提取年月部分
|
|
|
+ return dateStr.substring(0, 7);
|
|
|
+ }));
|
|
|
+ //对分组中的数据按时间排序
|
|
|
+ List<ContractLogMonthPack> contractLogMonthPacks = new ArrayList<>();
|
|
|
+
|
|
|
+ monthAll.forEach(f -> {
|
|
|
+
|
|
|
+ //根据月份获取数据
|
|
|
+ List<ContractLog> monthLogs = collect.get(DateUtil.format(f, "yyyy-MM"));
|
|
|
+
|
|
|
+ if(CollectionUtil.isNotEmpty(monthLogs)){
|
|
|
+ ContractLog contractLog = monthLogs.get(0);
|
|
|
+
|
|
|
+ String nodeName = null;
|
|
|
+ String contractName = null;
|
|
|
+ try {
|
|
|
+ //查询节点名称
|
|
|
+ nodeName = jdbcTemplate.queryForObject("select node_name from m_wbs_tree_private where p_key_id = " + contractLog.getWbsNodeId(), String.class);
|
|
|
+ contractName = jdbcTemplate.queryForObject("select case when contract_type = 1 then construction_unit_name else supervision_unit_name end from m_contract_info where id = " + contractLog.getContractId(), String.class);
|
|
|
+ } catch (DataAccessException e) {}
|
|
|
+ if(nodeName != null && contractName != null){
|
|
|
+ ContractLogMonthPack contractLogMonthPack = new ContractLogMonthPack();
|
|
|
+ contractLogMonthPack.setId(SnowFlakeUtil.getId());
|
|
|
+ contractLogMonthPack.setContractId(contractLog.getContractId());
|
|
|
+ contractLogMonthPack.setProjectId(contractLog.getProjectId());
|
|
|
+ contractLogMonthPack.setWbsNodeId(contractLog.getWbsNodeId());
|
|
|
+ contractLogMonthPack.setWbsNodeType(contractLog.getWbsNodeType());
|
|
|
+ contractLogMonthPack.setFileName(DateUtil.format(f, "yyyy年MM月") + nodeName);
|
|
|
+ contractLogMonthPack.setRecordTime(monthLogs.get(monthLogs.size()-1).getRecordTime().replaceAll("-",""));
|
|
|
+ contractLogMonthPack.setContractName(contractName);
|
|
|
+ contractLogMonthPack.setCreateUser(userId);
|
|
|
+
|
|
|
+ //排序
|
|
|
+ monthLogs.sort(Comparator.comparing(ContractLog::getRecordTime));
|
|
|
+ List<String> pdfFiles = monthLogs.stream().map(m -> {
|
|
|
+ if(StringUtil.isNotBlank(m.getEVisaPdfUrl())){
|
|
|
+ return m.getEVisaPdfUrl();
|
|
|
+ }
|
|
|
+ return m.getPdfUrl();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ try {
|
|
|
+ String filePath = FileUtils.getSysLocalFileUrl();
|
|
|
+ Long id = SnowFlakeUtil.getId();
|
|
|
+ String trialPdf = filePath + "pdf/" + id + ".pdf";
|
|
|
+ File trialPdf2 = ResourceUtil.getFile(trialPdf);
|
|
|
+ if (trialPdf2.exists()) {
|
|
|
+ trialPdf2.delete();
|
|
|
+ }
|
|
|
+ //合并日志pdf
|
|
|
+ int page = FileUtils.mergePdfPublicMethods(pdfFiles, trialPdf);
|
|
|
+ contractLogMonthPack.setPage(page);
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFile(id + ".pdf", trialPdf);
|
|
|
+ if (bladeFile != null && ObjectUtils.isNotEmpty(bladeFile.getLink())) {
|
|
|
+ contractLogMonthPack.setPdfUrl(bladeFile.getLink());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ServiceException("文件加载错误,请检查文件是否正常");
|
|
|
+ }
|
|
|
+ contractLogMonthPacks.add(contractLogMonthPack);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(CollectionUtil.isNotEmpty(contractLogMonthPacks)){
|
|
|
+ List<String> collect1 = contractLogMonthPacks.stream().map(ContractLogMonthPack::getRecordTime).collect(Collectors.toList());
|
|
|
+ //删除文件
|
|
|
+ List<ContractLogMonthPack> list = contractLogMonthPackService.list(Wrappers.<ContractLogMonthPack>lambdaQuery()
|
|
|
+ .eq(ContractLogMonthPack::getContractId, logVo.getContractId())
|
|
|
+ .eq(ContractLogMonthPack::getWbsNodeId, logVo.getWbsNodeId())
|
|
|
+ .in(ContractLogMonthPack::getRecordTime, collect1));
|
|
|
+
|
|
|
+ if(CollectionUtil.isNotEmpty(list)){
|
|
|
+ //删除文件
|
|
|
+ list.forEach(f -> {
|
|
|
+ if(StringUtil.isNotBlank(f.getPdfUrl())){
|
|
|
+ String pdfName = f.getPdfUrl().split("upload")[1];
|
|
|
+ this.newIOSSClient.removeFile("upload" + pdfName);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //删除数据
|
|
|
+ contractLogMonthPackService.removeBatchByIds(list);
|
|
|
+ }
|
|
|
+ return contractLogMonthPackService.saveBatch(contractLogMonthPacks);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ContractLogMonthPack> selectByMonthPack(ContractLogVO logVo) {
|
|
|
+ return contractLogMonthPackService.page(new Page<>(logVo.getCurrent(), logVo.getSize()), Wrappers.<ContractLogMonthPack>lambdaQuery()
|
|
|
+ .eq(ContractLogMonthPack::getContractId, logVo.getContractId())
|
|
|
+ .eq(ContractLogMonthPack::getWbsNodeId, logVo.getWbsNodeId())
|
|
|
+ .orderByDesc(ContractLogMonthPack::getRecordTime));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteByMonthPack(Long id) {
|
|
|
+ ContractLogMonthPack byId = contractLogMonthPackService.getById(id);
|
|
|
+ if(byId != null && StringUtil.isNotBlank(byId.getPdfUrl())){
|
|
|
+ String pdfName = byId.getPdfUrl().split("upload")[1];
|
|
|
+ this.newIOSSClient.removeFile("upload" + pdfName);
|
|
|
+ }
|
|
|
+ return contractLogMonthPackService.removeById(id);
|
|
|
+ }
|
|
|
}
|