Bladeren bron

对账单生成

skyline 2 jaren geleden
bovenliggende
commit
ed45b44bad

+ 13 - 7
admin/src/main/java/com/kym/admin/controller/StatementsController.java

@@ -1,11 +1,10 @@
 package com.kym.admin.controller;
 
 import com.kym.common.R;
-import com.kym.entity.admin.Statements;
 import com.kym.service.admin.StatementsService;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
@@ -20,15 +19,22 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("/statements")
 public class StatementsController {
 
-    private  final StatementsService statementsService;
+    private final StatementsService statementsService;
 
     public StatementsController(StatementsService statementsService) {
         this.statementsService = statementsService;
     }
 
-    @PostMapping("/create")
-    R<?> create(@RequestBody Statements statements) {
-        statementsService.createStatements(statements);
+    /**
+     * 生成对账单(创建前先录入抄表电量和电费金额)
+     *
+     * @param stationId
+     * @param statMonth
+     * @return
+     */
+    @GetMapping("/create")
+    R<?> create(@RequestParam("stationId") String stationId, @RequestParam("statMonth") String statMonth) {
+        statementsService.createStatements(stationId, statMonth);
         return R.success();
     }
 

+ 2 - 7
entity/src/main/java/com/kym/entity/admin/Statements.java

@@ -45,14 +45,9 @@ public class Statements extends BaseEntity {
     private String stationName;
 
     /**
-     * 开始时间
+     * 统计时间(月)
      */
-    private LocalDateTime startTime;
-
-    /**
-     * 结束时间
-     */
-    private LocalDateTime endTime;
+    private String statMonth;
 
     /**
      * 订单电量

+ 12 - 0
entity/src/main/java/com/kym/entity/admin/StationStatMonth.java

@@ -93,4 +93,16 @@ public class StationStatMonth extends BaseEntity {
      * 设备使用率
      */
     private Double connectorUsageRate;
+
+    /**
+     * 实际抄表电量
+     */
+    private Double actualPower;
+
+    /**
+     * 实际抄表电费金额(分)
+     */
+    private Integer actualElecMoney;
+
+
 }

+ 3 - 1
mapper/src/main/resources/mappers/admin/StationStatMonthMapper.xml

@@ -19,13 +19,15 @@
         <result column="avg_order_money" property="avgOrderMoney" />
         <result column="avg_connector_elec" property="avgConnectorElec" />
         <result column="connector_usage_rate" property="connectorUsageRate" />
+        <result column="actual_power" property="actualPower" />
+        <result column="actual_elec_money" property="actualElecMoney" />
         <result column="create_time" property="createTime" />
         <result column="update_time" property="updateTime" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id,station_id, stat_month, charge_users, valid_orders, total_power, total_money, elec_money, service_money,service_money_discount,discount_amount, avg_order_elec, avg_order_money, avg_connector_elec,connector_usage_rate,create_time, update_time
+        id,station_id, stat_month, charge_users, valid_orders, total_power, total_money, elec_money, service_money,service_money_discount,discount_amount, avg_order_elec, avg_order_money, avg_connector_elec,connector_usage_rate,actual_power,actual_elec_money,create_time,update_time,create_time, update_time
     </sql>
 
 </mapper>

+ 1 - 1
service/src/main/java/com/kym/service/admin/StatementsService.java

@@ -13,5 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface StatementsService extends IService<Statements> {
 
-    void createStatements(Statements statements);
+    void createStatements(String stationId, String statMonth);
 }

+ 47 - 9
service/src/main/java/com/kym/service/admin/impl/StatementsServiceImpl.java

@@ -4,10 +4,14 @@ import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.kym.entity.admin.InvestorInfo;
 import com.kym.entity.admin.Statements;
+import com.kym.entity.admin.StationStatMonth;
 import com.kym.mapper.admin.StatementsMapper;
 import com.kym.service.admin.InvestorInfoService;
 import com.kym.service.admin.StatementsService;
+import com.kym.service.admin.StationStatMonthService;
+import com.kym.service.cache.KymCache;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * <p>
@@ -23,18 +27,52 @@ public class StatementsServiceImpl extends ServiceImpl<StatementsMapper, Stateme
 
     private final InvestorInfoService investorInfoService;
 
-    public StatementsServiceImpl(InvestorInfoService investorInfoService) {
+    private final StationStatMonthService stationStatMonthService;
+
+    public StatementsServiceImpl(InvestorInfoService investorInfoService, StationStatMonthService stationStatMonthService) {
         this.investorInfoService = investorInfoService;
+        this.stationStatMonthService = stationStatMonthService;
     }
 
     @Override
-    public void createStatements(Statements statements) {
-        var investmentInfo = investorInfoService.lambdaQuery().eq(InvestorInfo::getAdminUserId, statements.getAdminUserId()).one();
-        statements.setAdminUserName(investmentInfo.getAdminUserName())
-               .setStationId(statements.getStationId())
-                .setStationName(statements.getStationName())
-                .setVatRate(investmentInfo.getVatRate())
-                .setSplittingProportion(investmentInfo.getSplittingProportion());
-        // TODO: 2023-12-28 其他数据字段填充 
+    @Transactional
+    public void createStatements(String stationId, String statMonth) {
+        // 站点统计信息
+        var statMonthInfo = stationStatMonthService.lambdaQuery()
+                .eq(StationStatMonth::getStationId, stationId)
+                .eq(StationStatMonth::getStatMonth, statMonth)
+                .one();
+        // 站点关联客户和物业信息
+        var investorInfoList = investorInfoService.lambdaQuery()
+                .eq(InvestorInfo::getStationId, stationId)
+                .list();
+
+        // 创建客户对账单
+        var res = investorInfoList.stream().map(investorInfo -> {
+            var actualServiceMoney = statMonthInfo.getServiceMoney() - statMonthInfo.getDiscountAmount() - (statMonthInfo.getActualElecMoney() - statMonthInfo.getElecMoney());
+            var vatAmount = (int) (actualServiceMoney * investorInfo.getVatRate());
+            return new Statements()
+                    .setAdminUserId(investorInfo.getAdminUserId())
+                    .setAdminUserName(investorInfo.getAdminUserName())
+                    .setStationId(investorInfo.getStationId())
+                    .setStationName(KymCache.INSTANCE.getStationNameById(investorInfo.getStationId()))
+                    .setStatMonth(statMonthInfo.getStatMonth())
+                    .setTotalPower(statMonthInfo.getTotalPower())
+                    .setActualPower(statMonthInfo.getActualPower()) // 实际抄表电量
+                    .setElecLossPower(statMonthInfo.getActualPower() - statMonthInfo.getTotalPower()) // 电损电量
+                    .setTotalMoney(statMonthInfo.getTotalMoney())
+                    .setElecMoney(statMonthInfo.getElecMoney())
+                    .setElecLossMoney(statMonthInfo.getActualElecMoney() - statMonthInfo.getElecMoney()) // 电损电费(分)
+                    .setServiceMoney(statMonthInfo.getServiceMoney())
+                    .setDiscountAmount(statMonthInfo.getDiscountAmount())
+                    .setServiceMoneyDiscount(statMonthInfo.getServiceMoneyDiscount())
+                    .setActualServiceMoney(actualServiceMoney) // 实际参与分成的服务费(分)
+                    .setSplittingProportion(investorInfo.getSplittingProportion()) // 分成比例 0.45表示45%
+                    .setSplittingAmount((int) (actualServiceMoney * investorInfo.getSplittingProportion()))  // 分成金额(分)
+                    .setVatRate(investorInfo.getVatRate()) // 增值税率 0.06表示6%
+                    .setVatAmount(vatAmount) // 增值税额(分)
+                    .setActualSplittingAmount(actualServiceMoney - vatAmount); // 实际分成金额(分)
+        }).toList();
+        saveBatch(res);
     }
 }