|
|
@@ -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);
|
|
|
}
|
|
|
}
|