Przeglądaj źródła

优化清理垃圾数据问题

java110 3 lat temu
rodzic
commit
7a97003f4c

+ 12 - 6
java110-db/src/main/resources/mapper/report/ReportFeeMonthStatisticsServiceDaoImplMapper.xml

@@ -2600,15 +2600,21 @@
         </foreach>
     </select>
 
+    <!-- 查询无效费用 add by wuxw 2018-07-03 -->
+    <select id="queryInvalidFeeMonthStatistics" parameterType="Map" resultType="Map">
+        select t.fee_id feeId from pay_fee t
+        inner join pay_fee_config pfc on t.config_id = pfc.config_id
+        inner join report_fee_month_statistics rfms on t.fee_id = rfms.fee_id and rfms.status_cd = '0'
+        where (t.status_cd = '1' or pfc.status_cd = '1')
+        and t.community_id= #{communityId}
+    </select>
 
     <!--清理报表 无效数据-->
     <update id="deleteInvalidFee" parameterType="Map">
-        delete from report_fee_month_statistics where fee_id not in (
-        select t.fee_id from pay_fee t
-        inner join pay_fee_config pfc on t.config_id = pfc.config_id and pfc.status_cd = '0'
-        where t.status_cd = '0'
-        and t.community_id= #{communityId}
-        )
+        delete from report_fee_month_statistics where fee_id  in
+        <foreach collection="feeIds" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
         and community_id = #{communityId}
     </update>
 </mapper>

+ 14 - 7
java110-db/src/main/resources/mapper/report/ReportOweFeeServiceDaoImplMapper.xml

@@ -172,7 +172,6 @@
     </update>
 
 
-
     <!-- 查询欠费统计数量 add by wuxw 2018-07-03 -->
     <select id="queryReportOweFeesCount" parameterType="Map" resultType="Map">
         select count(distinct(t.payer_obj_id)) count
@@ -664,13 +663,21 @@
     </select>
 
 
-    <update id="deleteInvalidFee" parameterType="Map">
-        delete from report_owe_fee where fee_id not exists (
-        select t.fee_id from pay_fee t
-        inner join pay_fee_config pfc on t.config_id = pfc.config_id and pfc.status_cd = '0'
-        where t.status_cd = '0'
+    <!-- 查询无效费用 add by wuxw 2018-07-03 -->
+    <select id="queryInvalidOweFee" parameterType="Map" resultType="Map">
+        select t.fee_id feeId from pay_fee t
+        inner join pay_fee_config pfc on t.config_id = pfc.config_id
+        inner join report_owe_fee rof on t.fee_id = rof.fee_id
+        where (t.status_cd = '1' or pfc.status_cd = '1')
         and t.community_id= #{communityId}
-        )
+    </select>
+
+
+    <update id="deleteInvalidFee" parameterType="Map">
+        delete from report_owe_fee where fee_id in
+        <foreach collection="feeIds" item="item" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
         and community_id = #{communityId}
     </update>
 

+ 7 - 0
service-report/src/main/java/com/java110/report/dao/IReportFeeMonthStatisticsServiceDao.java

@@ -343,4 +343,11 @@ public interface IReportFeeMonthStatisticsServiceDao {
     List<Map> queryRoomAndParkingSpace(Map info);
 
     int deleteInvalidFee(Map info);
+
+    /**
+     * 查询无效的数据
+     * @param reportFeeDto
+     * @return
+     */
+    List<Map> queryInvalidFeeMonthStatistics(Map reportFeeDto);
 }

+ 2 - 0
service-report/src/main/java/com/java110/report/dao/IReportOweFeeServiceDao.java

@@ -84,4 +84,6 @@ public interface IReportOweFeeServiceDao {
     List<Map> computeReportOweFeeItemAmount(Map beanCovertMap);
 
     int deleteInvalidFee(Map reportFeeDto);
+
+    List<Map> queryInvalidOweFee(Map reportFeeDto);
 }

+ 9 - 0
service-report/src/main/java/com/java110/report/dao/impl/ReportFeeMonthStatisticsServiceDaoImpl.java

@@ -606,5 +606,14 @@ public class ReportFeeMonthStatisticsServiceDaoImpl extends BaseServiceDao imple
         return saveFlag;
     }
 
+    @Override
+    public List<Map> queryInvalidFeeMonthStatistics(Map info) {
+        logger.debug("查询押金退费总金额信息 入参 info : {}", info);
+
+        List<Map> deposits = sqlSessionTemplate.selectList("reportFeeMonthStatisticsServiceDaoImpl.queryInvalidFeeMonthStatistics", info);
+
+        return deposits;
+    }
+
 
 }

+ 6 - 0
service-report/src/main/java/com/java110/report/dao/impl/ReportOweFeeServiceDaoImpl.java

@@ -161,5 +161,11 @@ public class ReportOweFeeServiceDaoImpl extends BaseServiceDao implements IRepor
         return saveFlag;
     }
 
+    @Override
+    public List<Map> queryInvalidOweFee(Map info) {
+        List<Map> businessReportOweFeeInfos = sqlSessionTemplate.selectList("reportOweFeeServiceDaoImpl.queryInvalidOweFee", info);
+        return businessReportOweFeeInfos;
+    }
+
 
 }

+ 23 - 4
service-report/src/main/java/com/java110/report/smo/impl/GeneratorFeeMonthStatisticsInnerServiceSMOImpl.java

@@ -2,6 +2,7 @@ package com.java110.report.smo.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.log.LoggerFactory;
 import com.java110.core.smo.IComputeFeeSMO;
 import com.java110.dto.RoomDto;
 import com.java110.dto.fee.FeeDto;
@@ -19,7 +20,6 @@ import com.java110.report.dao.IReportFeeMonthStatisticsServiceDao;
 import com.java110.report.dao.IReportFeeServiceDao;
 import com.java110.utils.util.*;
 import org.slf4j.Logger;
-import com.java110.core.log.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -87,7 +87,26 @@ public class GeneratorFeeMonthStatisticsInnerServiceSMOImpl implements IGenerato
     private void feeDataFiltering(String communityId) {
         Map reportFeeDto = new HashMap();
         reportFeeDto.put("communityId", communityId);
-        reportFeeMonthStatisticsServiceDaoImpl.deleteInvalidFee(reportFeeDto);
+        List<Map> feeDtos = reportFeeMonthStatisticsServiceDaoImpl.queryInvalidFeeMonthStatistics(reportFeeDto);
+
+        List<String> feeIds = new ArrayList<>();
+        for (Map feeDto : feeDtos) {
+            if (!feeDto.containsKey("feeId") || StringUtil.isNullOrNone(feeDto.get("feeId"))) {
+                continue;
+            }
+
+            feeIds.add(feeDto.get("feeId").toString());
+
+            if (feeIds.size() >= 50) {
+                reportFeeDto.put("feeIds", feeIds);
+                reportFeeMonthStatisticsServiceDaoImpl.deleteInvalidFee(reportFeeDto);
+                feeIds = new ArrayList<>();
+            }
+        }
+        reportFeeDto.put("feeIds", feeIds);
+        if (feeIds.size() > 0) {
+            reportFeeMonthStatisticsServiceDaoImpl.deleteInvalidFee(reportFeeDto);
+        }
     }
 
     private void dealFinishFee(String communityId) {
@@ -786,7 +805,7 @@ public class GeneratorFeeMonthStatisticsInnerServiceSMOImpl implements IGenerato
         Date endTime = ownerCarDtos.get(0).getEndTime();
 
         Date maxEndDate = tmpReportFeeDto.getDeadlineTime();
-        if(FeeDto.FEE_FLAG_CYCLE.equals(tmpReportFeeDto.getFeeFlag())){
+        if (FeeDto.FEE_FLAG_CYCLE.equals(tmpReportFeeDto.getFeeFlag())) {
             maxEndDate = tmpReportFeeDto.getConfigEndTime();
         }
 
@@ -856,7 +875,7 @@ public class GeneratorFeeMonthStatisticsInnerServiceSMOImpl implements IGenerato
         }
 
         Date maxEndDate = tmpReportFeeDto.getDeadlineTime();
-        if(FeeDto.FEE_FLAG_CYCLE.equals(tmpReportFeeDto.getFeeFlag())){
+        if (FeeDto.FEE_FLAG_CYCLE.equals(tmpReportFeeDto.getFeeFlag())) {
             maxEndDate = tmpReportFeeDto.getConfigEndTime();
         }
 

+ 23 - 5
service-report/src/main/java/com/java110/report/smo/impl/GeneratorOweFeeInnerServiceSMOImpl.java

@@ -21,10 +21,7 @@ import com.java110.report.dao.IReportFeeYearCollectionDetailServiceDao;
 import com.java110.report.dao.IReportFeeYearCollectionServiceDao;
 import com.java110.report.dao.IReportOweFeeServiceDao;
 import com.java110.service.smo.ISaveSystemErrorSMO;
-import com.java110.utils.util.Assert;
-import com.java110.utils.util.BeanConvertUtil;
-import com.java110.utils.util.DateUtil;
-import com.java110.utils.util.ExceptionUtil;
+import com.java110.utils.util.*;
 import org.slf4j.Logger;
 import com.java110.core.log.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -32,6 +29,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -130,9 +128,29 @@ public class GeneratorOweFeeInnerServiceSMOImpl implements IGeneratorOweFeeInner
 
     }
     private void feeDataFiltering(String communityId) {
+
         Map reportFeeDto = new HashMap();
         reportFeeDto.put("communityId", communityId);
-        reportOweFeeServiceDaoImpl.deleteInvalidFee(reportFeeDto);
+        List<Map> feeDtos = reportOweFeeServiceDaoImpl.queryInvalidOweFee(reportFeeDto);
+
+        List<String> feeIds = new ArrayList<>();
+        for (Map feeDto : feeDtos) {
+            if (!feeDto.containsKey("feeId") || StringUtil.isNullOrNone(feeDto.get("feeId"))) {
+                continue;
+            }
+
+            feeIds.add(feeDto.get("feeId").toString());
+
+            if (feeIds.size() >= 50) {
+                reportFeeDto.put("feeIds", feeIds);
+                reportOweFeeServiceDaoImpl.deleteInvalidFee(reportFeeDto);
+                feeIds = new ArrayList<>();
+            }
+        }
+        reportFeeDto.put("feeIds", feeIds);
+        if (feeIds.size() > 0) {
+            reportOweFeeServiceDaoImpl.deleteInvalidFee(reportFeeDto);
+        }
     }