skyline пре 2 година
родитељ
комит
d6d7f7e3bb

+ 16 - 9
admin/src/main/java/com/kym/admin/controller/StatementsController.java

@@ -2,10 +2,7 @@ package com.kym.admin.controller;
 
 import com.kym.common.R;
 import com.kym.service.admin.StatementsService;
-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;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * <p>
@@ -27,15 +24,25 @@ public class StatementsController {
 
     /**
      * 生成对账单(创建前先录入抄表电量和电费金额)
+     * 一次性生成对应站点投资者和物业的对账单
      *
-     * @param stationId
-     * @param statMonth
+     * @param statMonthId 月统计记录id
      * @return
      */
-    @GetMapping("/create")
-    R<?> create(@RequestParam("stationId") String stationId, @RequestParam("statMonth") String statMonth) {
-        statementsService.createStatements(stationId, statMonth);
+    @GetMapping("/create/{statMonthId}")
+    R<?> create(@PathVariable("statMonthId") String statMonthId) {
+        statementsService.createStatements(statMonthId);
         return R.success();
     }
 
+    /**
+     * 预览
+     * @param statId
+     * @return
+     */
+    @GetMapping("/preview/{statId}")
+    R<?> preview(@PathVariable("statId") String statId) {
+        return R.success(statementsService.getById(statId));
+    }
+
 }

+ 5 - 0
entity/src/main/java/com/kym/entity/admin/InvestorInfo.java

@@ -46,6 +46,11 @@ public class InvestorInfo extends BaseEntity {
      */
     private Double splittingProportion;
 
+    /**
+     * 分成比例 0.30表示30%
+     */
+    private Double elecLossProportion;
+
     /**
      * 账户名
      */

+ 2 - 1
mapper/src/main/resources/mappers/admin/InvestorInfoMapper.xml

@@ -10,6 +10,7 @@
         <result column="station_id" property="stationId" />
         <result column="vat_rate" property="vatRate" />
         <result column="splitting_proportion" property="splittingProportion" />
+        <result column="elec_loss_proportion" property="elecLossProportion" />
         <result column="account_name" property="accountName" />
         <result column="telephone" property="telephone" />
         <result column="bank_name" property="bankName" />
@@ -22,7 +23,7 @@
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id,admin_user_id, admin_user_name, station_id, vat_rate, splitting_proportion, account_name, telephone, bank_name, bank_card_no, status, remark,create_time,update_time
+        id,admin_user_id, admin_user_name, station_id, vat_rate, splitting_proportion, elec_loss_proportion,account_name, telephone, bank_name, bank_card_no, status, remark,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(String stationId, String statMonth);
+    void createStatements(String statMonthId);
 }

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

@@ -36,21 +36,23 @@ public class StatementsServiceImpl extends ServiceImpl<StatementsMapper, Stateme
 
     @Override
     @Transactional
-    public void createStatements(String stationId, String statMonth) {
+    public void createStatements(String statMonthId) {
         // 站点统计信息
         var statMonthInfo = stationStatMonthService.lambdaQuery()
-                .eq(StationStatMonth::getStationId, stationId)
-                .eq(StationStatMonth::getStatMonth, statMonth)
+                .eq(StationStatMonth::getId, statMonthId)
                 .one();
         // 站点关联客户和物业信息
         var investorInfoList = investorInfoService.lambdaQuery()
-                .eq(InvestorInfo::getStationId, stationId)
+                .eq(InvestorInfo::getStationId, statMonthInfo.getStationId())
                 .list();
 
         // 创建客户对账单
         var res = investorInfoList.stream().map(investorInfo -> {
-            var actualServiceMoney = statMonthInfo.getServiceMoney() - statMonthInfo.getDiscountAmount() - (statMonthInfo.getActualElecMoney() - statMonthInfo.getElecMoney());
-            var vatAmount = (int) (actualServiceMoney * investorInfo.getVatRate());
+            // 实际参与分成的服务费=总服务费-优惠金额-电损电费
+            var actualServiceMoney = statMonthInfo.getServiceMoney()
+                    - statMonthInfo.getDiscountAmount()
+                    - (int) ((statMonthInfo.getActualElecMoney() - statMonthInfo.getElecMoney()) * investorInfo.getElecLossProportion());
+            var splittingAmount = (int) (actualServiceMoney * investorInfo.getSplittingProportion());
             return new Statements()
                     .setAdminUserId(investorInfo.getAdminUserId())
                     .setAdminUserName(investorInfo.getAdminUserName())
@@ -62,16 +64,17 @@ public class StatementsServiceImpl extends ServiceImpl<StatementsMapper, Stateme
                     .setElecLossPower(statMonthInfo.getActualPower() - statMonthInfo.getTotalPower()) // 电损电量
                     .setTotalMoney(statMonthInfo.getTotalMoney())
                     .setElecMoney(statMonthInfo.getElecMoney())
+                    .setActualElecMoney(statMonthInfo.getActualElecMoney())// 实际抄表电费
                     .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()))  // 分成金额(分)
+                    .setSplittingAmount(splittingAmount)  // 分成金额(分)
                     .setVatRate(investorInfo.getVatRate()) // 增值税率 0.06表示6%
-                    .setVatAmount(vatAmount) // 增值税额(分)
-                    .setActualSplittingAmount(actualServiceMoney - vatAmount); // 实际分成金额(分)
+                    .setVatAmount((int) (splittingAmount * investorInfo.getVatRate())) // 增值税额(分)
+                    .setActualSplittingAmount(splittingAmount - (int) (splittingAmount * investorInfo.getVatRate())); // 实际分成金额(分)
         }).toList();
         saveBatch(res);
     }