瀏覽代碼

feat:缺失数据中间表更新优化,每次清表更新

chenjianhua 4 天之前
父節點
當前提交
9ae316ce2f

+ 2 - 0
service-base/src/main/java/com/simuwang/base/mapper/DeletionTypeStatisticsMapper.java

@@ -8,4 +8,6 @@ import org.apache.ibatis.annotations.Param;
 @Mapper
 public interface DeletionTypeStatisticsMapper extends BaseMapper<DeletionTypeStatisticsDO> {
     DeletionTypeStatisticsDO getDeletionTypeStatistics(@Param("fundId") String fundId, @Param("deletionType")Integer deletionType);
+
+    void truncateTable();
 }

+ 3 - 0
service-base/src/main/resources/mapper/DeletionTypeStatisticsMapper.xml

@@ -14,6 +14,9 @@
         <result column="updaterid" property="updaterId"/>
         <result column="updatetime" property="updateTime"/>
     </resultMap>
+    <delete id="truncateTable">
+        truncate table ppw_email.deletion_type_statistics
+    </delete>
     <select id="getDeletionTypeStatistics" resultMap="StatisticsResultMap">
         select id,fund_id,deletion_type,last_deletion_date,deletion_num,processed_num,creatorid,isvalid,createtime,updaterid,updatetime
         from ppw_email.deletion_type_statistics where isvalid=1 and fund_id=#{fundId} and deletion_type=#{deletionType}

+ 25 - 20
service-manage/src/main/java/com/simuwang/manage/service/impl/DeletionServiceImpl.java

@@ -17,6 +17,8 @@ import com.simuwang.base.pojo.dto.query.FundDeletionPageQuery;
 import com.simuwang.base.pojo.vo.*;
 import com.simuwang.manage.service.DeletionService;
 import com.simuwang.shiro.utils.UserUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
@@ -34,6 +36,7 @@ import java.util.stream.Collectors;
 @Service
 public class DeletionServiceImpl implements DeletionService {
 
+    private static final Logger log = LoggerFactory.getLogger(DeletionServiceImpl.class);
     @Autowired
     private DeletionInfoMapper deletionInfoMapper;
 
@@ -176,30 +179,32 @@ public class DeletionServiceImpl implements DeletionService {
 
     @Override
     public void computeDeletionTypeNum(List<FundDeletionTypeDO> fundDeletionTypeList) {
+        //清空deletion_type_statistics
+        deletionTypeStatisticsMapper.truncateTable();
         List<DeletionTypeStatisticsDO> deletionTypeStatisticsDOList = new ArrayList<>();
         for (FundDeletionTypeDO fundDeletionType : fundDeletionTypeList) {
-            String fundId = fundDeletionType.getFundId();
-            Integer deletionType = fundDeletionType.getDeletionType();
-            Integer deletionNum = deletionInfoMapper.countFundDeletion(fundId,deletionType,1);
-            Integer processedNum = deletionInfoMapper.countFundDeletion(fundId,deletionType,0);
-            String lastDeletionDate = deletionInfoMapper.getLastDeletionDate(fundId,deletionType);
-            DeletionTypeStatisticsDO deletionTypeStatisticsDO = new DeletionTypeStatisticsDO();
-            deletionTypeStatisticsDO.setFundId(fundId);
-            deletionTypeStatisticsDO.setIsvalid(1);
-            deletionTypeStatisticsDO.setCreateTime(new Date());
-            deletionTypeStatisticsDO.setCreatorId(999999);
-            deletionTypeStatisticsDO.setUpdaterId(999999);
-            deletionTypeStatisticsDO.setUpdateTime(new Date());
-            deletionTypeStatisticsDO.setLastDeletionDate(lastDeletionDate);
-            deletionTypeStatisticsDO.setDeletionType(Integer.valueOf(deletionType));
-            deletionTypeStatisticsDO.setDeletionNum(deletionNum);
-            deletionTypeStatisticsDO.setProcessedNum(processedNum);
-            DeletionTypeStatisticsDO oldDeletionTypeStatisticsDO = deletionTypeStatisticsMapper.getDeletionTypeStatistics(fundId,deletionType);
-            if(oldDeletionTypeStatisticsDO != null){
-                deletionTypeStatisticsDO.setId(oldDeletionTypeStatisticsDO.getId());
+            try{
+                String fundId = fundDeletionType.getFundId();
+                Integer deletionType = fundDeletionType.getDeletionType();
+                Integer deletionNum = deletionInfoMapper.countFundDeletion(fundId,deletionType,1);
+                Integer processedNum = deletionInfoMapper.countFundDeletion(fundId,deletionType,0);
+                String lastDeletionDate = deletionInfoMapper.getLastDeletionDate(fundId,deletionType);
+                DeletionTypeStatisticsDO deletionTypeStatisticsDO = new DeletionTypeStatisticsDO();
+                deletionTypeStatisticsDO.setFundId(fundId);
+                deletionTypeStatisticsDO.setIsvalid(1);
+                deletionTypeStatisticsDO.setCreateTime(new Date());
+                deletionTypeStatisticsDO.setCreatorId(999999);
+                deletionTypeStatisticsDO.setUpdaterId(999999);
                 deletionTypeStatisticsDO.setUpdateTime(new Date());
+                deletionTypeStatisticsDO.setLastDeletionDate(lastDeletionDate);
+                deletionTypeStatisticsDO.setDeletionType(deletionType);
+                deletionTypeStatisticsDO.setDeletionNum(deletionNum);
+                deletionTypeStatisticsDO.setProcessedNum(processedNum);
+                deletionTypeStatisticsMapper.insertOrUpdate(deletionTypeStatisticsDO);
+            }catch (Exception e){
+                log.error(e.getMessage(),e);
             }
-            deletionTypeStatisticsMapper.insertOrUpdate(deletionTypeStatisticsDO);
+
         }
     }