瀏覽代碼

中期计量

chenr 5 天之前
父節點
當前提交
04b116e928

+ 3 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTreePrivate.java

@@ -23,6 +23,9 @@ public class WbsTreePrivate extends BaseEntity {
     @JsonProperty(value = "pKeyId")
     private Long pKeyId;
 
+    @ApiModelProperty(value = "pid")
+    private Long pId;
+
     /**
      * 项目Id
      */

+ 42 - 1
blade-service-api/blade-meter-api/src/main/java/org/springblade/meter/vo/MeterInventoryVO1.java

@@ -23,7 +23,7 @@ public class MeterInventoryVO1 {
     private String unit;
 
     @ApiModelProperty(value = "原合同工程量")
-    private BigDecimal currentTotal;
+    private BigDecimal currentMeterTotal;
 
     @ApiModelProperty(value = "原合同单价")
     private BigDecimal currentMeterPrice;
@@ -31,6 +31,47 @@ public class MeterInventoryVO1 {
     @ApiModelProperty(value = "原合同金额")
     private BigDecimal currentMeterMoney;
 
+    @ApiModelProperty(value = "工程变更工程量")
+    private BigDecimal changeTotal;
 
+    @ApiModelProperty(value = "工程变更单价")
+    private BigDecimal changeMeterPrice;
+
+    @ApiModelProperty(value = "工程变更金额")
+    private BigDecimal changeMeterMoney;
+
+    @ApiModelProperty(value = "变更后合同工程量")
+    private BigDecimal afterCurrentTotal;
+
+    @ApiModelProperty(value = "变更后合同金额")
+    private BigDecimal afterCurrentMeterMoney;
+
+    @ApiModelProperty(value = "到上期末完成工程量")
+    private BigDecimal beforeEndTotal;
+
+    @ApiModelProperty(value = "到上期末完成金额")
+    private BigDecimal beforeEndMoney;
+
+    @ApiModelProperty(value = "本期完成工程量")
+    private BigDecimal nowTotal;
+
+    @ApiModelProperty(value = "本期完成金额")
+    private BigDecimal nowMoney;
+
+    @ApiModelProperty(value = "到本期末完成工程量")
+    private BigDecimal nowEndTotal;
+
+    @ApiModelProperty(value = "到本期末完成金额")
+    private BigDecimal nowEndMoney;
+
+
+   public static int getFirstThreeCharsAsInt(MeterInventoryVO1 vo1) {
+        String name = vo1.getFormNumber();
+        if (name.length() < 3) {
+            throw new IllegalArgumentException("Name must be at least 3 characters long");
+        }
+        String firstThreeChars = name.substring(0, 3);
+        return Integer.parseInt(firstThreeChars);
+    }
 
 }

+ 25 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ScheduledTasks1.java

@@ -0,0 +1,25 @@
+package org.springblade.manager.controller;
+
+import org.springblade.manager.service.IWbsTreePrivateService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ScheduledTasks1 {
+    private int i = 0;
+    private final IWbsTreePrivateService iWbsTreePrivateService;
+
+    @Autowired
+    public ScheduledTasks1(IWbsTreePrivateService iWbsTreePrivateService) {
+        this.iWbsTreePrivateService = iWbsTreePrivateService;
+    }
+
+    //@Scheduled(fixedDelay = 5000) // 上一次任务执行完毕后等待5秒再执行下一次
+    public void runTask() {
+        if(i==99){
+            return;
+        }
+        iWbsTreePrivateService.diGuiWbs(i);
+        i++;
+    }
+}

+ 2 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IWbsTreePrivateService.java

@@ -105,4 +105,6 @@ public interface IWbsTreePrivateService extends BaseService<WbsTreePrivate> {
     List<Long> linkNodeTreeBynodeId(String pkeyId);
 
     List<ArchiveSyncLogVO> getContractAllLog(Long contractId);
+
+    void diGuiWbs(int i);
 }

+ 179 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -44,6 +44,7 @@ import org.springblade.manager.mapper.WbsTreePrivateMapper;
 import org.springblade.manager.service.*;
 import org.springblade.manager.utils.FileUtils;
 import org.springblade.manager.vo.*;
+import org.springblade.meter.entity.ContractInventoryForm;
 import org.springblade.meter.entity.ContractMeterPeriod;
 import org.springblade.meter.entity.InterimPayCertificateItem;
 import org.springblade.meter.entity.MiddleMeterApply;
@@ -68,6 +69,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.constraints.NotNull;
 import java.io.*;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -2299,6 +2301,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
         return reportResult;
     }
 
+
     /**
      * 清单支付报表获取PDF CR3
      * @param url
@@ -2340,10 +2343,184 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                 }
             }
         }
-        //清单支付报表对象
-        MeterInventoryVO1  vo=new MeterInventoryVO1();
+        List<MeterInventoryVO1>list1=new ArrayList<>();
+        String sql="SELECT * FROM s_contract_inventory_form WHERE project_id="+projectId+" and contract_id="+contractId+" and is_deleted=0";
+        //合同清单的对应明细
+        List<ContractInventoryForm> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ContractInventoryForm.class));
+        for (MeterInventoryDetailVO detailVO : formDetail) {
+           //清单支付报表对象
+            MeterInventoryVO1  vo=new MeterInventoryVO1();
+            for (ContractInventoryForm form : query) {
+                if(ObjectUtil.isNotEmpty(form.getFormNumber())&&detailVO.getFormNumber().equals(form.getFormNumber())){
+                    //原合同工程量
+                    vo.setCurrentMeterTotal(form.getContractTotal());
+                    //原合同单价
+                    vo.setCurrentMeterPrice(form.getBidPrice());
+                    //原合同金额
+                    vo.setCurrentMeterMoney(form.getContractMoney());
+                    break;
+                }
+            }
+            vo.setId(detailVO.getId());
+            vo.setFormNumber(detailVO.getFormNumber());
+            vo.setFormName(detailVO.getFormName());
+            //变更后工程量
+            vo.setAfterCurrentTotal(detailVO.getChangeTotal());
+            //变更后金额 变更后工程量*单价
+            vo.setAfterCurrentMeterMoney(vo.getAfterCurrentTotal().multiply(detailVO.getCurrentPrice()));
+            //工程变更工程量 变更后工程量-原合同工程量
+            BigDecimal subtract = vo.getAfterCurrentTotal().subtract(vo.getCurrentMeterTotal());
+            if(subtract==BigDecimal.ZERO){
+                subtract=null;
+            }
+            vo.setChangeTotal(subtract);
+            //工程变更金额 变更后金额-原合同金额
+            BigDecimal subtract1 = vo.getAfterCurrentMeterMoney().subtract(vo.getCurrentMeterMoney());
+            if(subtract1==BigDecimal.ZERO){
+                subtract1=null;
+            }
+            vo.setChangeMeterMoney(subtract1);
+            //工程变更单价
+            if(vo.getChangeMeterMoney()==null&&vo.getChangeTotal()==null){
+                vo.setChangeMeterPrice(null);
+            }else {
+                vo.setChangeMeterPrice(detailVO.getCurrentPrice());
+            }
+            //本期完成工程量
+            vo.setNowTotal(detailVO.getCurrentMeterTotal());
+            //本期完成金额
+            vo.setNowMoney(detailVO.getAllMeterMoney());
+            //大于0表示有上期的 需要添加上期末数据
+            if(changeFormDetail.size()>0){
+               for (MeterInventoryDetailVO changevo : changeFormDetail) {
+                if(changevo.getFormNumber().equals(vo.getFormNumber())){
+                    //到上期末完成工程量
+                    vo.setBeforeEndTotal(changevo.getAllMeterTotal());
+                    //到上期末完成金额
+                    vo.setBeforeEndMoney(changevo.getAllMeterMoney());
+                    break;
+                }
+              }
+            }
+            //到本期末完成工程量
+            if(vo.getBeforeEndTotal()!=null){
+                vo.setNowEndTotal(vo.getBeforeEndTotal().add(vo.getNowTotal()));
+            }else {
+                vo.setNowEndTotal(vo.getNowTotal());
+            }
+            //到本期末完成金额
+            if(vo.getBeforeEndMoney()!=null){
+                vo.setNowEndMoney(vo.getBeforeEndMoney().add(vo.getNowMoney()));
+            }else {
+                vo.setNowEndMoney(vo.getNowMoney());
+            }
+            list1.add(vo);
+        }
+        if(list1.size()>0){
+            //先根据根据前三个字符排序
+             list1.sort(Comparator.comparingInt(MeterInventoryVO1::getFirstThreeCharsAsInt));
+             //根据编号的第一个字符,分类
+         Map<Character, List<MeterInventoryVO1>> groupedMeter = new HashMap<>();
+           for (MeterInventoryVO1 vo1 : list1) {
+           char firstChar = vo1.getFormNumber().charAt(0);
+           groupedMeter.computeIfAbsent(firstChar, k -> new ArrayList<>()).add(vo1);
+          }
+           //根据编号的不同建立不同的excel
+            for (Map.Entry<Character, List<MeterInventoryVO1>> listEntry : groupedMeter.entrySet()) {
+                List<MeterInventoryVO1> value = listEntry.getValue();
+                //编号来划分
+                for (int i = 0; i < value.size(); i+=16) {
+                     int endIndex = Math.min(i + 16, list.size());
+                      List<MeterInventoryVO1> subList = value.subList(i, endIndex);
+                      InputStream modInput = null;
+                      FileInputStream excelFileInput = null;
+                      FileOutputStream outputStream = null;
+                      Workbook workbook = null;
+                      MultipartFile files = null;
+                    try {
+                        modInput = CommonUtil.getOSSInputStream(url);
+                        workbook = WorkbookFactory.create(modInput);
+                        Sheet sheet = workbook.getSheetAt(0);
+                            // 起始行号
+                            int startRow = 8;
+                            int endRow = 23;
+                           for (int ii = 0; ii < subList.size() && startRow <= endRow; ii++, startRow++) {
+                                Row row = sheet.createRow(startRow - 1); // 行号从0开始
+                                MeterInventoryVO1 obj = subList.get(ii);
+                                for (int j = 0; j < 17; j++) {
+                                    Cell cell = row.createCell(j);
+                                    String attributeValue = getAttributeValue(obj, j);
+                                    if(StringUtil.isNotBlank(attributeValue)){
+                                        cell.setCellValue(attributeValue);
+                                    }
+
+                                }
+                            }
+                        String file_path = FileUtils.getSysLocalFileUrl();
+                        String locationFile = file_path + SnowFlakeUtil.getId() + ".xlsx";
+                        outputStream = new FileOutputStream(locationFile);
+                        //生成一份新的excel
+                        workbook.write(outputStream);
+                        //将excel转PDF
+                        File excelFile = new File(locationFile);
+                        excelFileInput = new FileInputStream(excelFile);
+                        files = new MockMultipartFile("file", excelFile.getName(), "text/plain", IOUtils.toByteArray(excelFileInput));
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                    NewBladeFile bladeFile = this.commonFileClient.excelToPdf(files);
+                    ReportResult reportResult = new ReportResult();
+                    CompletableFuture<String> stringCompletableFuture = new CompletableFuture<>();
+                    stringCompletableFuture.complete(bladeFile.getLink());
+                    reportResult.setPdfOssPath(stringCompletableFuture);
+                    return reportResult;
+                }
+            }
+
+        }
         return null;
     }
+    private static String getAttributeValue(MeterInventoryVO1 obj, int index) {
+         switch (index) {
+             case 0:
+                 return obj.getFormNumber();
+             case 1:
+                 return obj.getFormName();
+             case 2:
+                 return obj.getUnit();
+             case 3:
+                 return obj.getCurrentMeterTotal().toString();
+             case 4:
+                 return obj.getCurrentMeterPrice().toString();
+             case 5:
+                 return obj.getCurrentMeterMoney().toString();
+             case 6:
+                 return obj.getChangeTotal().toString();
+             case 7:
+                 return obj.getChangeMeterPrice().toString();
+             case 8:
+                 return obj.getChangeMeterMoney().toString();
+             case 9:
+                 return obj.getAfterCurrentTotal().toString();
+             case 10:
+                 return obj.getAfterCurrentMeterMoney().toString();
+             case 11:
+                 return obj.getBeforeEndTotal().toString();
+             case 12:
+                 return obj.getBeforeEndMoney().toString();
+             case 13:
+                 return obj.getNowTotal().toString();
+             case 14:
+                 return obj.getNowMoney().toString();
+             case 15:
+                 return obj.getNowEndTotal().toString();
+             case 16:
+                 return obj.getNowEndMoney().toString();
+             default:
+                 return "";
+         }
+     }
+
     //根据单元格地址获取单元格对象
     private static Cell getCellByAddress(Sheet sheet, String cellAddress) {
         CellReference cellRef = new CellReference(cellAddress);

+ 62 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreePrivateServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.log.StaticLog;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
@@ -37,6 +38,8 @@ import org.springblade.manager.service.IElementFormulaMappingService;
 import org.springblade.manager.service.IFormulaService;
 import org.springblade.manager.service.ITableInfoService;
 import org.springblade.manager.service.IWbsTreePrivateService;
+import org.springblade.manager.utils.CompositeKey;
+import org.springblade.manager.utils.CompositeKey1;
 import org.springblade.manager.utils.FileUtils;
 import org.springblade.manager.vo.*;
 import org.springblade.system.cache.ParamCache;
@@ -2974,4 +2977,63 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
         return baseMapper.getContractAllLog(contractId);
     }
 
+    public void diGuiWbs(int i) {
+        QueryWrapper<WbsTreePrivate> wbsTreePrivateQueryWrapper = new QueryWrapper<>();
+        wbsTreePrivateQueryWrapper.select("p_key_id","id","p_id","wbs_id","parent_id","ancestors");
+        wbsTreePrivateQueryWrapper.eq("parent_id",0);
+        wbsTreePrivateQueryWrapper.eq("is_deleted",0);
+        wbsTreePrivateQueryWrapper.isNotNull("project_id");
+        wbsTreePrivateQueryWrapper.isNotNull("wbs_id");
+        List<WbsTreePrivate> list = this.list(wbsTreePrivateQueryWrapper);
+        if(!list.isEmpty()){
+            WbsTreePrivate wbsTreePrivate = list.get(i);
+            //通过parentID,contractID,wbsId分组,映射map
+            Map<CompositeKey1, List<WbsTreePrivate>> map = findAllContract(wbsTreePrivate).stream()
+                .collect(Collectors.groupingBy(
+                    item -> new CompositeKey1(item.getParentId(),item.getProjectId(),item.getWbsId())
+                ));
+            List<WbsTreePrivate>updateList=new ArrayList<>();
+
+            //递归设置pid和ancestors
+            setPidAndAncestors(map,wbsTreePrivate,updateList);
+            System.out.println("第"+i+"次递归:"+updateList.size());
+            for (WbsTreePrivate wbsTreePrivate1 : updateList) {
+               UpdateWrapper<WbsTreePrivate>wrapper=new UpdateWrapper<>();
+                wrapper.set("p_id",wbsTreePrivate1.getPId());
+                wrapper.set("ancestors",wbsTreePrivate1.getAncestors());
+                wrapper.eq("p_key_id",wbsTreePrivate1.getPKeyId());
+                this.update(wrapper);
+            }
+        }
+        System.out.println("第"+i+"次递归完成");
+
+
+    }
+    public  List<WbsTreePrivate> findAllContract(WbsTreePrivate wbsTreePrivate){
+        QueryWrapper<WbsTreePrivate> wbsTreeContractQueryWrapper = new QueryWrapper<>();
+        wbsTreeContractQueryWrapper.select("p_key_id","id","p_id","wbs_id","project_id","parent_id","ancestors");
+        wbsTreeContractQueryWrapper.eq("project_id",wbsTreePrivate.getProjectId());
+        wbsTreeContractQueryWrapper.eq("wbs_id",wbsTreePrivate.getWbsId());
+        return this.list(wbsTreeContractQueryWrapper);
+    }
+    public  void setPidAndAncestors(Map<CompositeKey1, List<WbsTreePrivate>> map,WbsTreePrivate wbsTreePrivate,List<WbsTreePrivate>updateList){
+        CompositeKey1 key = new CompositeKey1(wbsTreePrivate.getId(),wbsTreePrivate.getProjectId(),wbsTreePrivate.getWbsId());
+        //拿到当前节点的子节点
+        List<WbsTreePrivate> childrens = map.get(key);
+        if(ObjectUtil.isNotEmpty(childrens)){
+            for (WbsTreePrivate children : childrens) {
+                if(children.getParentId().equals(wbsTreePrivate.getId())){
+                    //设置祖级节点和pid
+                    String ancestors=wbsTreePrivate.getAncestors()+",";
+                    ancestors=ancestors+wbsTreePrivate.getPKeyId();
+                    children.setAncestors(ancestors);
+                    children.setPId(wbsTreePrivate.getPKeyId());
+                    updateList.add(children);
+                    //递归调用自己继续将一个合同段的子节点设置完
+                    setPidAndAncestors(map,children,updateList);
+                }
+            }
+        }
+    }
+
 }

+ 16 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/utils/CompositeKey1.java

@@ -0,0 +1,16 @@
+package org.springblade.manager.utils;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+@Data
+@EqualsAndHashCode
+@AllArgsConstructor
+@NoArgsConstructor
+public class CompositeKey1 {
+    private Long id;
+    private String projectId;
+    private String wbsId;
+}