|
@@ -1,24 +1,310 @@
|
|
|
package org.springblade.land.service.impl;
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+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.Query;
|
|
|
+import org.springblade.core.oss.model.BladeFile;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
+import org.springblade.core.tool.utils.ResourceUtil;
|
|
|
import org.springblade.land.dto.SettlementIntervalDTO;
|
|
|
-import org.springblade.land.entity.ClearingAgreementInfo;
|
|
|
-import org.springblade.land.entity.SettlementInterval;
|
|
|
+import org.springblade.land.entity.*;
|
|
|
import org.springblade.land.mapper.ClearingAgreementInfoMapper;
|
|
|
import org.springblade.land.mapper.SettlementIntervalMapper;
|
|
|
+import org.springblade.land.service.IAgreementLinkTableService;
|
|
|
import org.springblade.land.service.IClearingAgreementInfoService;
|
|
|
+import org.springblade.land.service.ICompensationInfoService;
|
|
|
import org.springblade.land.service.ISettlementIntervalService;
|
|
|
+import org.springblade.land.utils.FileUtils;
|
|
|
+import org.springblade.land.vo.AreaPictureVO;
|
|
|
+import org.springblade.manager.entity.WbsTreePrivate;
|
|
|
+import org.springblade.resource.feign.NewIOSSClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class ClearingAgreementInfoServiceImpl extends BaseServiceImpl<ClearingAgreementInfoMapper, ClearingAgreementInfo> implements IClearingAgreementInfoService {
|
|
|
|
|
|
+ private final ICompensationInfoService compensationInfoService;
|
|
|
+ private final IAgreementLinkTableService linkTableService;
|
|
|
+ private final NewIOSSClient newIOSSClient;
|
|
|
|
|
|
+ /**
|
|
|
+ * 新增结算协议
|
|
|
+ * @param info
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void add(ClearingAgreementInfo info) {
|
|
|
+ //修改选择的补偿协议的引用状态
|
|
|
+ String agreementIds = info.getAgreementIds();
|
|
|
+ if (StringUtils.isBlank(agreementIds)){
|
|
|
+ throw new ServiceException("请选择补偿协议");
|
|
|
+ }
|
|
|
+ //是新增还是修改
|
|
|
+ Boolean isAdd = false;
|
|
|
+ List<Long> ids = Func.toLongList(agreementIds);
|
|
|
+ compensationInfoService.batchUpdateStatus(ids,1);
|
|
|
+ List<AgreementLinkTable> linkTables = new ArrayList<>();
|
|
|
+ if (info.getId() == null) {
|
|
|
+ isAdd = true;
|
|
|
+ //复制一份当前合同下对应的结算协议到中间表
|
|
|
+ Long agreeId = SnowFlakeUtil.getId();
|
|
|
+ //先新增中间表,
|
|
|
+ List<WbsTreePrivate> tables = compensationInfoService.getTables(info.getProjectId(), info.getType() + 3);
|
|
|
+ linkTables = tables.stream().map(l -> {
|
|
|
+ AgreementLinkTable table = new AgreementLinkTable();
|
|
|
+ table.setTableId(Long.parseLong(l.getInitTableId()));
|
|
|
+ table.setProjectId(info.getProjectId());
|
|
|
+// table.setTableDataId(SnowFlakeUtil.getId());
|
|
|
+// table.setId(SnowFlakeUtil.getId());
|
|
|
+ table.setAgreementId(agreeId);
|
|
|
+ table.setPrivateId(l.getId());
|
|
|
+ table.setSort(l.getSort());
|
|
|
+ table.setExcelId(l.getExcelId());
|
|
|
+ table.setHtmlUrl(l.getHtmlUrl());
|
|
|
+ table.setTableName(l.getNodeName());
|
|
|
+ return table;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ linkTableService.saveBatch(linkTables);
|
|
|
+ info.setId(agreeId);
|
|
|
+ }else {
|
|
|
+ linkTables = linkTableService.getByAgreementId(info.getId());
|
|
|
+ }
|
|
|
+ //获取所有选中的补偿协议
|
|
|
+ List<CompensationInfo> compensationInfos = compensationInfoService.listByIds(ids);
|
|
|
+ //统计补偿协议的统计字段
|
|
|
+ //总补偿金额
|
|
|
+ BigDecimal allCount = new BigDecimal(0);
|
|
|
+ //结算协议名称
|
|
|
+ StringBuilder str = new StringBuilder("");
|
|
|
+ for (CompensationInfo fo : compensationInfos) {
|
|
|
+ //金额统计
|
|
|
+ if (fo.getAllMoney() != null) {
|
|
|
+ allCount = allCount.add(fo.getAllMoney());
|
|
|
+ }
|
|
|
+ //名称拼接
|
|
|
+ str.append(fo.getName()+"、");
|
|
|
+ }
|
|
|
+ info.setAgreementMoney(allCount);
|
|
|
+ String names = str.toString();
|
|
|
+ if (StringUtils.isNotBlank(names)){
|
|
|
+ info.setName(names.substring(0, names.length() - 1)+"结算");
|
|
|
+ }else {
|
|
|
+ info.setName("未找到用户名称");
|
|
|
+ }
|
|
|
+ if (isAdd) {
|
|
|
+ this.save(info);
|
|
|
+ }else {
|
|
|
+ this.updateById(info);
|
|
|
+ }
|
|
|
+ //循环结算协议的统计字段,把补偿协议统计出来的字段设置到结算协议
|
|
|
+ //生成封面
|
|
|
+ //生成补偿结算表
|
|
|
+ //生成补偿费发放统计表
|
|
|
+ //生成补偿费明细表
|
|
|
+ //生成补偿资金数量分配表
|
|
|
+ //生成面积统计明细表
|
|
|
+ //合并PDF
|
|
|
+ try {
|
|
|
+ this.mergePdfs(info.getId());
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new ServiceException("合并PDF失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询结算周期
|
|
|
+ * @param query
|
|
|
+ * @param info
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<ClearingAgreementInfo> page(Query query, ClearingAgreementInfo info) {
|
|
|
+ IPage<ClearingAgreementInfo> iPage = new Page<>(query.getCurrent(),query.getSize());
|
|
|
+ return baseMapper.page(iPage,info);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据结算id查询下面的表单
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<AgreementLinkTable> getFileList(Long id) {
|
|
|
+ return linkTableService.getByAgreementId(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结算统计面积
|
|
|
+ * @param projectId
|
|
|
+ * @param areaId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R statArea(Long projectId, Long areaId) {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ //获取当前项目下,当前节点下所有补偿协议
|
|
|
+ List<CompensationInfo> infoList = compensationInfoService.getAllAgreementList(projectId, areaId);
|
|
|
+ if (infoList == null || infoList.size() == 0){
|
|
|
+ return R.data(list);
|
|
|
+ }
|
|
|
+ //已签协议面积
|
|
|
+ BigDecimal all = infoList.stream().map(l -> l.getAreaAll()).reduce(BigDecimal.valueOf(0), BigDecimal::add);
|
|
|
+ list.add(all+"");
|
|
|
+ //已签协议比例
|
|
|
+ list.add("0%");
|
|
|
+ //已结算面积
|
|
|
+ BigDecimal endAll = infoList.stream().filter(l->l.getIsQuote().equals(1)).map(l -> l.getAreaAll()).reduce(BigDecimal.valueOf(0), BigDecimal::add);
|
|
|
+ list.add(endAll+"");
|
|
|
+ //已结算比例
|
|
|
+ list.add("0%");
|
|
|
+ return R.data(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结算统计面积柱状图
|
|
|
+ * @param projectId
|
|
|
+ * @param areaId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R<List<AreaPictureVO>> statAreaPicture(Long projectId, Long areaId) {
|
|
|
+ List<AreaPictureVO> vo = new ArrayList<>();
|
|
|
+ //获取当前项目下,当前节点下所有补偿协议
|
|
|
+ List<CompensationInfo> infoList = compensationInfoService.getAllAgreementList(projectId, areaId);
|
|
|
+ if (infoList == null || infoList.size() == 0){
|
|
|
+ return R.data(vo);
|
|
|
+ }
|
|
|
+ //已签面积
|
|
|
+ AreaPictureVO vo1 = new AreaPictureVO();
|
|
|
+ vo1.setName("已签面积");
|
|
|
+ List<BigDecimal> ll = new ArrayList<>();
|
|
|
+ BigDecimal a1 = infoList.stream().map(l -> l.getAreaA()).reduce(BigDecimal.valueOf(0), BigDecimal::add);
|
|
|
+ BigDecimal a2 = infoList.stream().map(l -> l.getAreaB()).reduce(BigDecimal.valueOf(0), BigDecimal::add);
|
|
|
+ BigDecimal a3 = infoList.stream().map(l -> l.getAreaC()).reduce(BigDecimal.valueOf(0), BigDecimal::add);
|
|
|
+ ll.add(a1);
|
|
|
+ ll.add(a2);
|
|
|
+ ll.add(a3);
|
|
|
+ vo1.setValue(ll);
|
|
|
+ //设计面积
|
|
|
+ AreaPictureVO vo2 = new AreaPictureVO();
|
|
|
+ vo2.setName("设计面积");
|
|
|
+ List<BigDecimal> lb = new ArrayList<>();
|
|
|
+ lb.add(new BigDecimal(0));
|
|
|
+ lb.add(new BigDecimal(0));
|
|
|
+ lb.add(new BigDecimal(0));
|
|
|
+ vo2.setValue(lb);
|
|
|
+ vo.add(vo1);
|
|
|
+ vo.add(vo2);
|
|
|
+
|
|
|
+ return R.data(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结算统计-金额进度
|
|
|
+ * @param projectId
|
|
|
+ * @param areaId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R<List<AreaPictureVO>> statMoney(Long projectId, Long areaId) {
|
|
|
+ List<AreaPictureVO> vo = new ArrayList<>();
|
|
|
+ //获取当前项目下,当前节点下所有补偿协议
|
|
|
+ List<CompensationInfo> infoList = compensationInfoService.getAllAgreementList(projectId, areaId);
|
|
|
+ if (infoList == null || infoList.size() == 0){
|
|
|
+ return R.data(vo);
|
|
|
+ }
|
|
|
+ BigDecimal zero = new BigDecimal(0);
|
|
|
+ //补偿
|
|
|
+ List<CompensationInfo> l1 = infoList.stream().filter(l -> l.getIsQuote().equals(0)).collect(Collectors.toList());
|
|
|
+ //结算
|
|
|
+ List<CompensationInfo> l2 = infoList.stream().filter(l -> l.getIsQuote().equals(1)).collect(Collectors.toList());
|
|
|
+ //实际补助总金额
|
|
|
+ AreaPictureVO vo1 = new AreaPictureVO();
|
|
|
+ vo1.setName("实际补助总金额");
|
|
|
+ List<BigDecimal> ll = new ArrayList<>();
|
|
|
+ BigDecimal a1 = infoList.stream().filter(l->l.getType().equals(1)).map(l -> l.getAllMoney()).reduce(BigDecimal.valueOf(0), BigDecimal::add);
|
|
|
+ ll.add(a1);
|
|
|
+ ll.add(zero);
|
|
|
+ ll.add(zero);
|
|
|
+ ll.add(zero);
|
|
|
+ ll.add(zero);
|
|
|
+ vo1.setValue(ll);
|
|
|
+ //设计补助总金额
|
|
|
+ AreaPictureVO vo2 = new AreaPictureVO();
|
|
|
+ vo2.setName("设计补助总金额");
|
|
|
+ List<BigDecimal> lb = new ArrayList<>();
|
|
|
+ lb.add(zero);
|
|
|
+ lb.add(zero);
|
|
|
+ lb.add(zero);
|
|
|
+ lb.add(zero);
|
|
|
+ lb.add(zero);
|
|
|
+ vo2.setValue(lb);
|
|
|
+ //已结算总金额
|
|
|
+ AreaPictureVO vo3 = new AreaPictureVO();
|
|
|
+ vo3.setName("已结算总金额");
|
|
|
+ List<BigDecimal> lbl = new ArrayList<>();
|
|
|
+ BigDecimal c1 = l2.stream().filter(l->l.getType().equals(1)).map(l -> l.getAllMoney()).reduce(BigDecimal.valueOf(0), BigDecimal::add);
|
|
|
+ lbl.add(c1);
|
|
|
+ lbl.add(zero);
|
|
|
+ lbl.add(zero);
|
|
|
+ lbl.add(zero);
|
|
|
+ lbl.add(zero);
|
|
|
+ vo3.setValue(lbl);
|
|
|
+ //保存
|
|
|
+ vo.add(vo1);
|
|
|
+ vo.add(vo2);
|
|
|
+ vo.add(vo3);
|
|
|
+ return R.data(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ //合并pdf
|
|
|
+ public void mergePdfs(Long agreementId) throws Exception {
|
|
|
+ String file_path = FileUtils.getSysLocalFileUrl();
|
|
|
+ List<String> data = new ArrayList<>();
|
|
|
+ //获取协议所有的表单
|
|
|
+ List<AgreementLinkTable> list = linkTableService.list(new LambdaQueryWrapper<AgreementLinkTable>()
|
|
|
+ .eq(AgreementLinkTable::getAgreementId, agreementId));
|
|
|
+ for (AgreementLinkTable table : list) {
|
|
|
+ if (StringUtils.isNotEmpty(table.getPdfUrl())) {
|
|
|
+ data.add(table.getPdfUrl());
|
|
|
+ } else {
|
|
|
+ R bussPdfInfo = compensationInfoService.getBussPdfInfo(table.getId());
|
|
|
+ if (bussPdfInfo.getCode() == 200) {
|
|
|
+ if (StringUtils.isNotBlank(bussPdfInfo.getData() + "")) {
|
|
|
+ data.add(bussPdfInfo.getData() + "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String listPdf = file_path + "/pdf/" + agreementId + ".pdf";
|
|
|
+ File tabpdf2 = ResourceUtil.getFile(listPdf);
|
|
|
+ if (tabpdf2.exists()) {
|
|
|
+ tabpdf2.delete();
|
|
|
+ }
|
|
|
+ if (data.size() >= 1) {
|
|
|
+ //资料填报原始pdf合并
|
|
|
+ FileUtils.mergePdfPublicMethods(data, listPdf);
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFile(agreementId + ".pdf", listPdf);
|
|
|
+ ClearingAgreementInfo info = new ClearingAgreementInfo();
|
|
|
+ info.setId(agreementId);
|
|
|
+ info.setMergePdfUrl(bladeFile.getLink());
|
|
|
+ this.updateById(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|