Przeglądaj źródła

optimize report

java110 2 lat temu
rodzic
commit
63bfc2543e

+ 163 - 1
java110-db/src/main/resources/mapper/report/ReportFeeStatisticsServiceDaoImplMapper.xml

@@ -346,7 +346,7 @@
 
     <select id="getFloorFeeSummary" parameterType="Map" resultType="Map">
 
-        select a.floor_id floorId,a.floor_num floorNum,
+        select a.floor_id floorId,a.floor_num floorNum,a.name floorName
         (
         select count(1) from (
         select t.obj_id from pay_fee_detail_month t
@@ -496,5 +496,167 @@
         order by a.seq
     </select>
 
+    <select id="getConfigFeeSummary" parameterType="Map" resultType="Map">
+        select a.name,
+        (
+        select count(1) from (
+        select t.obj_id from pay_fee_detail_month t
+        INNER JOIN pay_fee pf on t.fee_id = pf.fee_id and pf.status_cd = '0'
+        <if test="floorId != null and floorId != ''">
+            LEFT JOIN building_room br on t.obj_id = br.room_id and br.status_cd = '0'
+            left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+        </if>
+        where
+        1=1
+        <if test="floorId != null and floorId != ''">
+            and bu.floor_id = a.floor_id
+        </if>
+        and t.status_cd = '0'
+        and pf.payer_obj_type = '3333'
+        and t.community_id=  #{communityId}
+        and t.cur_month_time &lt; #{endDate}
+        and (t.receivable_amount - t.received_amount - t.discount_amount) > 0
+        <if test="configIds !=null ">
+            and t.config_id in
+            <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        and pf.fee_type_cd = a.status_cd
+        group by t.obj_id) b
+        ) oweRoomCount,-- 欠费户
+        (
+        select count(1) from (
+        select t.obj_id
+        from pay_fee_detail_month t
+        INNER JOIN pay_fee pf on t.fee_id = pf.fee_id and pf.status_cd = '0'
+        <if test="floorId != null and floorId != ''">
+            LEFT JOIN building_room br on t.obj_id = br.room_id and br.status_cd = '0'
+            left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+        </if>
+        where
+        1=1
+        <if test="floorId != null and floorId != ''">
+            and bu.floor_id = a.floor_id
+        </if>
+        and t.status_cd = '0'
+        and pf.payer_obj_type = '3333'
+        and t.community_id=  #{communityId}
+        and t.cur_month_time &lt; #{endDate}
+        <if test="configIds !=null ">
+            and t.config_id in
+            <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        and pf.fee_type_cd = a.status_cd
+        group by t.obj_id) b
+        ) feeRoomCount, -- 收费户
+        (
+        select ifnull(sum(t.received_amount),0.0) receivedFee
+        from pay_fee_detail_month t
+        INNER JOIN pay_fee pf on t.fee_id = pf.fee_id and pf.status_cd = '0'
+        <if test="floorId != null and floorId != ''">
+            LEFT JOIN building_room br on t.obj_id = br.room_id and br.status_cd = '0'
+            left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+        </if>
+        where
+        1=1
+        <if test="floorId != null and floorId != ''">
+            and bu.floor_id = a.floor_id
+        </if>
+        and t.status_cd = '0'
+        and t.community_id=  #{communityId}
+        and t.pay_fee_time &gt; #{startDate}
+        and t.pay_fee_time &lt; #{endDate}
+        <if test="configIds !=null ">
+            and t.config_id in
+            <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        and pf.fee_type_cd = a.status_cd
+        ) receivedFee, -- 实收
+        (
+        select ifnull(sum(t.received_amount),0.0) preReceivedFee
+        from pay_fee_detail_month t
+        INNER JOIN pay_fee pf on t.fee_id = pf.fee_id and pf.status_cd = '0'
+        <if test="floorId != null and floorId != ''">
+            LEFT JOIN building_room br on t.obj_id = br.room_id and br.status_cd = '0'
+            left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+        </if>
+        where
+        1=1
+        <if test="floorId != null and floorId != ''">
+            and bu.floor_id = a.floor_id
+        </if>
+        and t.status_cd = '0'
+        and t.community_id=  #{communityId}
+        and t.pay_fee_time &gt; #{startDate}
+        and t.pay_fee_time &lt; #{endDate}
+        and t.cur_month_time &gt; #{endDate}
+        <if test="configIds !=null ">
+            and t.config_id in
+            <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        and pf.fee_type_cd = a.status_cd
+        ) preReceivedFee, -- 预收
+        (
+        select ifnull(sum(t.receivable_amount - t.received_amount - t.discount_amount),0.0) hisOweFee
+        from pay_fee_detail_month t
+        INNER JOIN pay_fee pf on t.fee_id = pf.fee_id and pf.status_cd = '0'
+        <if test="floorId != null and floorId != ''">
+            LEFT JOIN building_room br on t.obj_id = br.room_id and br.status_cd = '0'
+            left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+        </if>
+        where
+        1=1
+        <if test="floorId != null and floorId != ''">
+            and bu.floor_id = a.floor_id
+        </if>
+        and t.status_cd = '0'
+        and t.community_id=  #{communityId}
+        and t.cur_month_time &lt; #{startDate}
+        <if test="configIds !=null ">
+            and t.config_id in
+            <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        and pf.fee_type_cd = a.status_cd
+        ) hisOweFee, -- 历史欠费
+        (
+        select ifnull(sum(t.receivable_amount),0.0) curReceivableFee
+        from pay_fee_detail_month t
+        INNER JOIN pay_fee pf on t.fee_id = pf.fee_id and pf.status_cd = '0'
+        <if test="floorId != null and floorId != ''">
+            LEFT JOIN building_room br on t.obj_id = br.room_id and br.status_cd = '0'
+            left join building_unit bu on br.unit_id = bu.unit_id and bu.status_cd = '0'
+        </if>
+        where
+        1=1
+        <if test="floorId != null and floorId != ''">
+            and bu.floor_id = a.floor_id
+        </if>
+        and t.status_cd = '0'
+        and t.community_id= #{communityId}
+        and t.cur_month_time  &gt; #{startDate}
+        and t.cur_month_time &lt; #{endDate}
+        <if test="configIds !=null ">
+            and t.config_id in
+            <foreach collection="configIds" item="item" index="index" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        and pf.fee_type_cd = a.status_cd
+        ) curReceivableFee -- 当期应收
+        from t_dict a
+        where 1=1
+        and a.table_name = 'pay_fee_config'
+        and a.table_columns = 'fee_type_cd'
+    </select>
+
 
 </mapper>

+ 8 - 0
java110-interface/src/main/java/com/java110/intf/report/IReportFeeStatisticsInnerServiceSMO.java

@@ -89,4 +89,12 @@ public interface IReportFeeStatisticsInnerServiceSMO {
      */
     @RequestMapping(value = "/getFloorFeeSummary", method = RequestMethod.POST)
     List<Map> getFloorFeeSummary(@RequestBody QueryStatisticsDto queryStatisticsDto);
+
+    /**
+     * 费用项收费率统计
+     * @param queryStatisticsDto
+     * @return
+     */
+    @RequestMapping(value = "/getConfigFeeSummary", method = RequestMethod.POST)
+    List<Map> getConfigFeeSummary(@RequestBody QueryStatisticsDto queryStatisticsDto);
 }

+ 88 - 0
service-report/src/main/java/com/java110/report/cmd/reportFeeMonthStatistics/QueryReportConfigFeeSummaryCmd.java

@@ -0,0 +1,88 @@
+package com.java110.report.cmd.reportFeeMonthStatistics;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.dto.report.QueryStatisticsDto;
+import com.java110.report.statistics.IFeeStatistics;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.Assert;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.math.BigDecimal;
+import java.text.ParseException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 费用项费用统计
+ */
+@Java110Cmd(serviceCode = "reportFeeMonthStatistics.queryReportConfigFeeSummary")
+public class QueryReportConfigFeeSummaryCmd extends Cmd {
+
+    @Autowired
+    private IFeeStatistics feeStatisticsImpl;
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        Assert.hasKeyAndValue(reqJson, "startDate", "未包含开始日期");
+        Assert.hasKeyAndValue(reqJson, "endDate", "未包含结束日期");
+        Assert.hasKeyAndValue(reqJson, "communityId", "未包含小区信息");
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        QueryStatisticsDto queryStatisticsDto = new QueryStatisticsDto();
+        queryStatisticsDto.setCommunityId(reqJson.getString("communityId"));
+        queryStatisticsDto.setStartDate(reqJson.getString("startDate"));
+        queryStatisticsDto.setEndDate(reqJson.getString("endDate"));
+        queryStatisticsDto.setFloorId(reqJson.getString("floorId"));
+        if (reqJson.containsKey("configIds")) {
+            queryStatisticsDto.setConfigIds(reqJson.getString("configIds").split(","));
+        }
+
+        List<Map> datas = feeStatisticsImpl.getConfigFeeSummary(queryStatisticsDto);
+
+        if (datas == null || datas.size() < 1) {
+            context.setResponseEntity(ResultVo.createResponseEntity(datas));
+            return;
+        }
+        BigDecimal feeRoomCountDec = null;
+        BigDecimal oweRoomCountDec = null;
+        BigDecimal feeRoomRate = null;
+        BigDecimal hisOweFee = null;
+        BigDecimal curReceivableFee = null;
+        BigDecimal receivedFee = null;
+        BigDecimal preReceivedFee = null;
+        for (Map data : datas) {
+            //todo 计算 户收费率
+            if (Double.parseDouble(data.get("feeRoomCount").toString()) > 0) {
+                feeRoomCountDec = new BigDecimal(Double.parseDouble(data.get("feeRoomCount").toString()));
+                oweRoomCountDec = new BigDecimal(Double.parseDouble(data.get("oweRoomCount").toString()));
+                feeRoomRate = feeRoomCountDec.subtract(oweRoomCountDec).divide(feeRoomCountDec, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
+                data.put("feeRoomRate", feeRoomRate.doubleValue());
+            } else {
+                data.put("feeRoomRate", 0.0);
+            }
+
+            //todo 计算 收费率
+            hisOweFee = new BigDecimal(Double.parseDouble(data.get("hisOweFee").toString()));
+            curReceivableFee = new BigDecimal(Double.parseDouble(data.get("curReceivableFee").toString()));
+            hisOweFee = curReceivableFee.add(hisOweFee);
+
+            if (hisOweFee.doubleValue() > 0) {
+                receivedFee = new BigDecimal(Double.parseDouble(data.get("receivedFee").toString()));
+                preReceivedFee = new BigDecimal(Double.parseDouble(data.get("preReceivedFee").toString()));
+                feeRoomRate = receivedFee.subtract(preReceivedFee).divide(hisOweFee, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
+                data.put("feeRate", feeRoomRate.doubleValue());
+            } else {
+                data.put("feeRate", 0.0);
+            }
+        }
+
+        context.setResponseEntity(ResultVo.createResponseEntity(datas));
+    }
+}

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

@@ -74,4 +74,11 @@ public interface IReportFeeStatisticsServiceDao {
      * @return
      */
     List<Map> getFloorFeeSummary(Map info);
+
+    /**
+     * 统计费用项 收费率信息
+     * @param info
+     * @return
+     */
+    List<Map> getConfigFeeSummary(Map info);
 }

+ 10 - 0
service-report/src/main/java/com/java110/report/dao/impl/ReportFeeStatisticsServiceDaoImpl.java

@@ -157,5 +157,15 @@ public class ReportFeeStatisticsServiceDaoImpl extends BaseServiceDao implements
         return infos;
     }
 
+    @Override
+    public List<Map> getConfigFeeSummary(Map info) {
+        logger.debug("查询 费用项收费率 入参 info : {}", JSONObject.toJSONString(info));
+
+        List<Map> infos = sqlSessionTemplate.selectList("reportFeeStatisticsServiceDaoImpl.getConfigFeeSummary", info);
+
+
+        return infos;
+    }
+
 
 }

+ 13 - 0
service-report/src/main/java/com/java110/report/smo/impl/ReportFeeStatisticsInnerServiceSMOImpl.java

@@ -111,4 +111,17 @@ public class ReportFeeStatisticsInnerServiceSMOImpl extends BaseServiceSMO imple
         List<Map> info = reportFeeStatisticsServiceDaoImpl.getFloorFeeSummary(BeanConvertUtil.beanCovertMap(queryStatisticsDto));
         return info;
     }
+
+    /**
+     * 费用项收费率信息统计
+     *
+     * @param queryStatisticsDto
+     * @return
+     */
+    @Override
+    public List<Map> getConfigFeeSummary(QueryStatisticsDto queryStatisticsDto) {
+
+        List<Map> info = reportFeeStatisticsServiceDaoImpl.getConfigFeeSummary(BeanConvertUtil.beanCovertMap(queryStatisticsDto));
+        return info;
+    }
 }

+ 7 - 0
service-report/src/main/java/com/java110/report/statistics/IFeeStatistics.java

@@ -74,4 +74,11 @@ public interface IFeeStatistics {
      * @return
      */
     List<Map> getFloorFeeSummary(QueryStatisticsDto queryStatisticsDto);
+
+    /**
+     * 费用项 费用统计信息
+     * @param queryStatisticsDto
+     * @return
+     */
+    List<Map> getConfigFeeSummary(QueryStatisticsDto queryStatisticsDto);
 }

+ 10 - 0
service-report/src/main/java/com/java110/report/statistics/impl/FeeStatisticsImpl.java

@@ -103,4 +103,14 @@ public class FeeStatisticsImpl implements IFeeStatistics {
         return reportFeeStatisticsInnerServiceSMOImpl.getFloorFeeSummary(queryStatisticsDto);
     }
 
+    /**
+     * 费用项收费率信息统计
+     * @param queryStatisticsDto
+     * @return
+     */
+    @Override
+    public List<Map> getConfigFeeSummary(QueryStatisticsDto queryStatisticsDto) {
+        return reportFeeStatisticsInnerServiceSMOImpl.getConfigFeeSummary(queryStatisticsDto);
+    }
+
 }