龙伟 пре 1 година
родитељ
комит
9d6945400e

+ 66 - 0
base/src/main/java/com/ruoyi/Installationcost/domain/MesInfoInstallationcost.java

@@ -0,0 +1,66 @@
+package com.ruoyi.Installationcost.domain;
+
+import java.math.BigDecimal;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+
+/**
+ * Installationcost对象 mes_info_installationcost
+ * 
+ * @author ruoyi
+ * @date 2023-08-16
+ */
+public class MesInfoInstallationcost extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** 主键 */
+    private Long id;
+
+    /** 任务号 */
+    @Excel(name = "任务号")
+    private String taskno;
+
+    /** 装机成本值 */
+    @Excel(name = "装机成本值")
+    private BigDecimal value;
+
+    public void setId(Long id) 
+    {
+        this.id = id;
+    }
+
+    public Long getId() 
+    {
+        return id;
+    }
+    public void setTaskno(String taskno)
+    {
+        this.taskno = taskno;
+    }
+
+    public String getTaskno()
+    {
+        return taskno;
+    }
+    public void setValue(BigDecimal value) 
+    {
+        this.value = value;
+    }
+
+    public BigDecimal getValue() 
+    {
+        return value;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
+            .append("id", getId())
+            .append("taskno", getTaskno())
+            .append("value", getValue())
+            .toString();
+    }
+}

+ 70 - 0
base/src/main/java/com/ruoyi/Installationcost/mapper/MesInfoInstallationcostMapper.java

@@ -0,0 +1,70 @@
+package com.ruoyi.Installationcost.mapper;
+
+import java.util.ArrayList;
+import java.util.List;
+import com.ruoyi.Installationcost.domain.MesInfoInstallationcost;
+
+/**
+ * InstallationcostMapper接口
+ * 
+ * @author ruoyi
+ * @date 2023-08-16
+ */
+public interface MesInfoInstallationcostMapper 
+{
+    /**
+     * 查询Installationcost
+     * 
+     * @param id Installationcost主键
+     * @return Installationcost
+     */
+    public MesInfoInstallationcost selectMesInfoInstallationcostById(Long id);
+
+    /**
+     * 查询Installationcost列表
+     * 
+     * @param mesInfoInstallationcost Installationcost
+     * @return Installationcost集合
+     */
+    public List<MesInfoInstallationcost> selectMesInfoInstallationcostList(MesInfoInstallationcost mesInfoInstallationcost);
+
+    /**
+     * 新增Installationcost
+     * 
+     * @param mesInfoInstallationcost Installationcost
+     * @return 结果
+     */
+    public int insertMesInfoInstallationcost(MesInfoInstallationcost mesInfoInstallationcost);
+
+    /**
+     * 修改Installationcost
+     * 
+     * @param mesInfoInstallationcost Installationcost
+     * @return 结果
+     */
+    public int updateMesInfoInstallationcost(MesInfoInstallationcost mesInfoInstallationcost);
+
+    /**
+     * 删除Installationcost
+     * 
+     * @param id Installationcost主键
+     * @return 结果
+     */
+    public int deleteMesInfoInstallationcostById(Long id);
+
+    /**
+     * 批量删除Installationcost
+     * 
+     * @param ids 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteMesInfoInstallationcostByIds(Long[] ids);
+
+    /**
+     * 批量插入或更新装机成本
+     *
+     * @param costs 装机成本对象
+     * @return 结果
+     */
+    int insertOrUpdateBatchMesInfoInstallationcost(ArrayList<MesInfoInstallationcost> costs);
+}

+ 70 - 0
base/src/main/java/com/ruoyi/Installationcost/service/IMesInfoInstallationcostService.java

@@ -0,0 +1,70 @@
+package com.ruoyi.Installationcost.service;
+
+import java.util.ArrayList;
+import java.util.List;
+import com.ruoyi.Installationcost.domain.MesInfoInstallationcost;
+
+/**
+ * InstallationcostService接口
+ * 
+ * @author ruoyi
+ * @date 2023-08-16
+ */
+public interface IMesInfoInstallationcostService 
+{
+    /**
+     * 查询Installationcost
+     * 
+     * @param id Installationcost主键
+     * @return Installationcost
+     */
+    public MesInfoInstallationcost selectMesInfoInstallationcostById(Long id);
+
+    /**
+     * 查询Installationcost列表
+     * 
+     * @param mesInfoInstallationcost Installationcost
+     * @return Installationcost集合
+     */
+    public List<MesInfoInstallationcost> selectMesInfoInstallationcostList(MesInfoInstallationcost mesInfoInstallationcost);
+
+    /**
+     * 新增Installationcost
+     * 
+     * @param mesInfoInstallationcost Installationcost
+     * @return 结果
+     */
+    public int insertMesInfoInstallationcost(MesInfoInstallationcost mesInfoInstallationcost);
+
+    /**
+     * 修改Installationcost
+     * 
+     * @param mesInfoInstallationcost Installationcost
+     * @return 结果
+     */
+    public int updateMesInfoInstallationcost(MesInfoInstallationcost mesInfoInstallationcost);
+
+    /**
+     * 批量删除Installationcost
+     * 
+     * @param ids 需要删除的Installationcost主键集合
+     * @return 结果
+     */
+    public int deleteMesInfoInstallationcostByIds(Long[] ids);
+
+    /**
+     * 删除Installationcost信息
+     * 
+     * @param id Installationcost主键
+     * @return 结果
+     */
+    public int deleteMesInfoInstallationcostById(Long id);
+
+    /**
+     * 批量插入或更新装机成本
+     *
+     * @param costs 装机成本对象
+     * @return 结果
+     */
+    int insertOrUpdateBatchMesInfoInstallationcost(ArrayList<MesInfoInstallationcost> costs);
+}

+ 106 - 0
base/src/main/java/com/ruoyi/Installationcost/service/impl/MesInfoInstallationcostServiceImpl.java

@@ -0,0 +1,106 @@
+package com.ruoyi.Installationcost.service.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.Installationcost.mapper.MesInfoInstallationcostMapper;
+import com.ruoyi.Installationcost.domain.MesInfoInstallationcost;
+import com.ruoyi.Installationcost.service.IMesInfoInstallationcostService;
+
+/**
+ * InstallationcostService业务层处理
+ * 
+ * @author ruoyi
+ * @date 2023-08-16
+ */
+@Service
+public class MesInfoInstallationcostServiceImpl implements IMesInfoInstallationcostService 
+{
+    @Autowired
+    private MesInfoInstallationcostMapper mesInfoInstallationcostMapper;
+
+    /**
+     * 查询Installationcost
+     * 
+     * @param id Installationcost主键
+     * @return Installationcost
+     */
+    @Override
+    public MesInfoInstallationcost selectMesInfoInstallationcostById(Long id)
+    {
+        return mesInfoInstallationcostMapper.selectMesInfoInstallationcostById(id);
+    }
+
+    /**
+     * 查询Installationcost列表
+     * 
+     * @param mesInfoInstallationcost Installationcost
+     * @return Installationcost
+     */
+    @Override
+    public List<MesInfoInstallationcost> selectMesInfoInstallationcostList(MesInfoInstallationcost mesInfoInstallationcost)
+    {
+        return mesInfoInstallationcostMapper.selectMesInfoInstallationcostList(mesInfoInstallationcost);
+    }
+
+    /**
+     * 新增Installationcost
+     * 
+     * @param mesInfoInstallationcost Installationcost
+     * @return 结果
+     */
+    @Override
+    public int insertMesInfoInstallationcost(MesInfoInstallationcost mesInfoInstallationcost)
+    {
+        return mesInfoInstallationcostMapper.insertMesInfoInstallationcost(mesInfoInstallationcost);
+    }
+
+    /**
+     * 修改Installationcost
+     * 
+     * @param mesInfoInstallationcost Installationcost
+     * @return 结果
+     */
+    @Override
+    public int updateMesInfoInstallationcost(MesInfoInstallationcost mesInfoInstallationcost)
+    {
+        return mesInfoInstallationcostMapper.updateMesInfoInstallationcost(mesInfoInstallationcost);
+    }
+
+    /**
+     * 批量删除Installationcost
+     * 
+     * @param ids 需要删除的Installationcost主键
+     * @return 结果
+     */
+    @Override
+    public int deleteMesInfoInstallationcostByIds(Long[] ids)
+    {
+        return mesInfoInstallationcostMapper.deleteMesInfoInstallationcostByIds(ids);
+    }
+
+    /**
+     * 删除Installationcost信息
+     * 
+     * @param id Installationcost主键
+     * @return 结果
+     */
+    @Override
+    public int deleteMesInfoInstallationcostById(Long id)
+    {
+        return mesInfoInstallationcostMapper.deleteMesInfoInstallationcostById(id);
+    }
+
+    /**
+     * 批量插入或更新装机成本
+     *
+     * @param costs 装机成本对象
+     * @return 结果
+     */
+    @Override
+    public int insertOrUpdateBatchMesInfoInstallationcost(ArrayList<MesInfoInstallationcost> costs) {
+
+        return mesInfoInstallationcostMapper.insertOrUpdateBatchMesInfoInstallationcost(costs);
+    }
+}

+ 73 - 0
base/src/main/resources/mapper/Installationcost/MesInfoInstallationcostMapper.xml

@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.Installationcost.mapper.MesInfoInstallationcostMapper">
+    
+    <resultMap type="MesInfoInstallationcost" id="MesInfoInstallationcostResult">
+        <result property="id"    column="id"    />
+        <result property="taskno"    column="taskno"    />
+        <result property="value"    column="value"    />
+    </resultMap>
+
+    <sql id="selectMesInfoInstallationcostVo">
+        select id, taskno, value from mes_info_installationcost
+    </sql>
+
+    <select id="selectMesInfoInstallationcostList" parameterType="MesInfoInstallationcost" resultMap="MesInfoInstallationcostResult">
+        <include refid="selectMesInfoInstallationcostVo"/>
+        <where>  
+            <if test="taskno != null "> and taskno = #{taskno}</if>
+            <if test="value != null "> and value = #{value}</if>
+        </where>
+    </select>
+    
+    <select id="selectMesInfoInstallationcostById" parameterType="Long" resultMap="MesInfoInstallationcostResult">
+        <include refid="selectMesInfoInstallationcostVo"/>
+        where id = #{id}
+    </select>
+        
+    <insert id="insertMesInfoInstallationcost" parameterType="MesInfoInstallationcost">
+        insert into mes_info_installationcost
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="id != null">id,</if>
+            <if test="taskno != null">taskno,</if>
+            <if test="value != null">value,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="id != null">#{id},</if>
+            <if test="taskno != null">#{taskno},</if>
+            <if test="value != null">#{value},</if>
+         </trim>
+    </insert>
+    <insert id="insertOrUpdateBatchMesInfoInstallationcost" parameterType="java.util.List">
+        INSERT INTO mes_info_installationcost (id, taskno, value)
+        VALUES
+        <foreach collection="list" item="item" separator=",">
+            (null, #{item.taskno}, #{item.value})
+        </foreach>
+        ON DUPLICATE KEY UPDATE
+        taskno = VALUES(taskno),
+        value = VALUES(value)
+    </insert>
+
+    <update id="updateMesInfoInstallationcost" parameterType="MesInfoInstallationcost">
+        update mes_info_installationcost
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="taskno != null">taskno = #{taskno},</if>
+            <if test="value != null">value = #{value},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteMesInfoInstallationcostById" parameterType="Long">
+        delete from mes_info_installationcost where id = #{id}
+    </delete>
+
+    <delete id="deleteMesInfoInstallationcostByIds" parameterType="String">
+        delete from mes_info_installationcost where id in 
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+</mapper>

+ 8 - 0
summary/src/main/java/com/ruoyi/projetctCost/beenfactory/ServiceBeenFactory.java

@@ -1,6 +1,7 @@
 package com.ruoyi.projetctCost.beenfactory;
 
 
+import com.ruoyi.Installationcost.service.IMesInfoInstallationcostService;
 import com.ruoyi.contractInfo.service.IComContractInfoExchangeService;
 import com.ruoyi.depart.service.ISysDepartService;
 import com.ruoyi.financeBudget.service.IFinanceBudgetService;
@@ -66,6 +67,13 @@ public class ServiceBeenFactory {
     @Autowired
     private IProjectCostService projectCostService;
 
+    @Autowired
+    private IMesInfoInstallationcostService installationcostService;
+
+    public IMesInfoInstallationcostService getInstallationcostService() {
+        return installationcostService;
+    }
+
     public IMesInfoService getMesInfoService() {
         return mesInfoService;
     }

+ 96 - 56
summary/src/main/java/com/ruoyi/projetctCost/task/projectCostTask.java

@@ -1,5 +1,9 @@
 package com.ruoyi.projetctCost.task;
 
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.TypeReference;
+import com.ruoyi.Installationcost.domain.MesInfoInstallationcost;
+import com.ruoyi.Installationcost.service.IMesInfoInstallationcostService;
 import com.ruoyi.common.constant.CacheConstants;
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.utils.StringUtils;
@@ -11,11 +15,14 @@ import com.ruoyi.projetctCost.beenfactory.ServiceBeenFactory;
 import com.ruoyi.projetctCost.run.InstallationCostSummaryCallable;
 import com.ruoyi.projetctCost.run.projectCostSummaryRunnable;
 import com.ruoyi.projetctCost.util.RedisLockMethodUtil;
+import lombok.val;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import springfox.documentation.spring.web.json.Json;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
+import java.math.BigDecimal;
+import java.util.*;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.ThreadPoolExecutor;
@@ -70,67 +77,100 @@ public class projectCostTask {
 
     /*计算项目成本内的装机成本*/
     public void InstallationCostSummaryTask() throws ExecutionException, InterruptedException {
+        try {
+            /*mes装机信息卡service*/
+            IMesInfoService mesInfoService = serviceBeenFactory.getMesInfoService();
+            /*装机成本计算专用线程池*/
+            ThreadPoolExecutor executor = InstallationCostSummaryThreadPool.getInstance().getExecutor();
 
-        /*mes装机信息卡service*/
-        IMesInfoService mesInfoService = serviceBeenFactory.getMesInfoService();
-        /*装机成本计算专用线程池*/
-        ThreadPoolExecutor executor = InstallationCostSummaryThreadPool.getInstance().getExecutor();
-
-        //一次while循环处理的数量
-        long size = 10000;
-
-        // 一个线程一次性处理2000条数据
-        long watermark = 2000;
-
-        while (true) {
-            //获取当前mesInfo表中最大的主键
-            Long MesInfoCount = mesInfoService.getMesInfoMaxKeyId();
-            //获取上次处理的装机信息卡最后一条数据的id
-            Long checkPoint = mesInfoService.selectCheckPoint();
-            //未处理的数量
-            long unprocessedQuantity = MesInfoCount - checkPoint;
-            //未处理的数据为0,结束计算
-            if (unprocessedQuantity == 0) {
-                break;
-            }
-            //未处理的数据量超过一万条,将其中一万条作为一个批次处理
-            if (unprocessedQuantity < 100000) size = unprocessedQuantity;
-
-            //起始id
-            long startId = checkPoint; //0
-            //终点ID
-            long endId;
-            //完整分片
-            long splitNum = size / watermark;
-            //余数
-            long remainder = size % watermark;
-            //有余数,就多开个线程处理
-            if (remainder != 0) splitNum = splitNum + 1;
-
-            ArrayList<Future<Boolean>> futures = new ArrayList<>();
-
-            for (long i = 0; i < splitNum; i++) {
-                startId = startId + (size * i); // 0 2000
-                endId = startId + watermark + 1; //2001 4001
-                Future<Boolean> future = executor.submit(new InstallationCostSummaryCallable(startId, endId, serviceBeenFactory, RedisLockMethodUtil.getInstance(), redisCache));
-                futures.add(future);
+            IMesInfoInstallationcostService installationcostService = serviceBeenFactory.getInstallationcostService();
+
+            List<MesInfoInstallationcost> mesInfoInstallationcosts = installationcostService.selectMesInfoInstallationcostList(new MesInfoInstallationcost());
+
+            HashMap<String, HashMap<String, Object>> putCacheMap = new HashMap<>();
+            for (MesInfoInstallationcost mesInfoInstallationcost : mesInfoInstallationcosts) {
+                HashMap<String, Object> value = new HashMap<>();
+                value.put(CacheConstants.VALUE, mesInfoInstallationcost.getValue());
+                putCacheMap.put(mesInfoInstallationcost.getTaskno(), value);
             }
-            boolean success = true;
-            for (Future<Boolean> future : futures) {
-                Boolean aBoolean = future.get();
-                if (!aBoolean) {
-                    success = aBoolean;
+            redisCache.setCacheMap(CacheConstants.INSTALLATION_COST, putCacheMap);
+
+            //一次while循环处理的数量
+            long size = 10000;
+
+            // 一个线程一次性处理2000条数据
+            long watermark = 2000;
+
+            while (true) {
+                //获取当前mesInfo表中最大的主键
+                Long MesInfoCount = mesInfoService.getMesInfoMaxKeyId();
+                //获取上次处理的装机信息卡最后一条数据的id
+                Long checkPoint = mesInfoService.selectCheckPoint();
+                //未处理的数量
+                long unprocessedQuantity = MesInfoCount - checkPoint;
+                //未处理的数据为0,结束计算
+                if (unprocessedQuantity == 0) {
+                    break;
                 }
+                //未处理的数据量超过一万条,将其中一万条作为一个批次处理
+                if (unprocessedQuantity < 100000) size = unprocessedQuantity;
+
+                //起始id
+                long startId = checkPoint; //0
+                //终点ID
+                long endId;
+                //完整分片
+                long splitNum = size / watermark;
+                //余数
+                long remainder = size % watermark;
+                //有余数,就多开个线程处理
+                if (remainder != 0) splitNum = splitNum + 1;
+
+                ArrayList<Future<Boolean>> futures = new ArrayList<>();
+
+                for (long i = 0; i < splitNum; i++) {
+                    startId = startId + (size * i); // 0 2000
+                    endId = startId + watermark + 1; //2001 4001
+                    Future<Boolean> future = executor.submit(new InstallationCostSummaryCallable(startId, endId, serviceBeenFactory, RedisLockMethodUtil.getInstance(), redisCache));
+                    futures.add(future);
+                }
+                boolean success = true;
+                for (Future<Boolean> future : futures) {
+                    Boolean aBoolean = future.get();
+                    if (!aBoolean) {
+                        success = aBoolean;
+                    }
+                }
+                if (!success) {
+                    break;
+                }
+
+                Map<String, Object> cacheMap = redisCache.getCacheMap(CacheConstants.INSTALLATION_COST);
+                MesInfoInstallationcost installationcost;
+
+                ArrayList<MesInfoInstallationcost> costs = new ArrayList<>();
+                Set<Map.Entry<String, Object>> entries = cacheMap.entrySet();
+                for (Map.Entry<String, Object> entry : entries) {
+                    Object value = entry.getValue();
+                    Map<String, Object> map = JSON.parseObject(JSON.toJSONString(value), new TypeReference<Map<String, Object>>() {
+                    });
+                    installationcost = new MesInfoInstallationcost();
+                    installationcost.setTaskno(entry.getKey());
+                    BigDecimal cacheValue = (BigDecimal) map.get(CacheConstants.VALUE);
+                    installationcost.setValue(cacheValue);
+                    costs.add(installationcost);
+                }
+
+                installationcostService.insertOrUpdateBatchMesInfoInstallationcost(costs);
+
+                long newCheckPoint = checkPoint + size;
+                int i = mesInfoService.recordCheckPoint(newCheckPoint);
+                if (i == 0) break;
             }
-            if (!success) {
-                break;
-            }
-            long newCheckPoint = checkPoint + size;
-            int i = mesInfoService.recordCheckPoint(newCheckPoint);
-            if (i == 0) break;
 
+        } finally {
+            redisCache.deleteObject(CacheConstants.INSTALLATION_COST);
         }
 
-        redisCache.deleteObject(CacheConstants.INSTALLATION_COST);
     }
 }