|
@@ -23,6 +23,8 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -54,16 +56,16 @@ public class BillGenerationServiceImpl {
|
|
|
}
|
|
|
|
|
|
@Async(value = "zhswThreadPool")
|
|
|
- public void generateBill(List<SwWaterUsageEntryDo> swWaterUsageEntryDoList,ServletRequestAttributes attributes) {
|
|
|
+ public void generateBill(List<SwWaterUsageEntryDo> swWaterUsageEntryDoList, ServletRequestAttributes attributes) {
|
|
|
RequestContextHolder.setRequestAttributes(attributes);
|
|
|
SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
|
|
|
|
|
|
- log.info("当前生成账单的用户:{},所属的租户库为:{}",currentUser.getAccount(),currentUser.getTenantDo().getDskey());
|
|
|
+ log.info("当前生成账单的用户:{},所属的租户库为:{}", currentUser.getAccount(), currentUser.getTenantDo().getDskey());
|
|
|
if (swWaterUsageEntryDoList == null || swWaterUsageEntryDoList.isEmpty()) {
|
|
|
log.error("暂无需要生成账单的信息");
|
|
|
return;
|
|
|
}
|
|
|
- log.debug("需要生成账单的抄表记录为:{}",swWaterUsageEntryDoList);
|
|
|
+ log.debug("需要生成账单的抄表记录为:{}", swWaterUsageEntryDoList);
|
|
|
// 对数据按照抄表日期排序
|
|
|
List<SwWaterUsageEntryDo> collect = swWaterUsageEntryDoList.stream()
|
|
|
.sorted(Comparator.comparing(SwWaterUsageEntryDo::getCurrentreadingdate))
|
|
@@ -153,20 +155,20 @@ public class BillGenerationServiceImpl {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void generateBill(String id,ServletRequestAttributes attributes) {
|
|
|
- log.info("开始给抄表记录:{},生成账单信息",id);
|
|
|
+ public void generateBill(String id, ServletRequestAttributes attributes) {
|
|
|
+ log.info("开始给抄表记录:{},生成账单信息", id);
|
|
|
SwWaterUsageEntryDo swWaterUsageEntryDo = swWaterUsageEntryService.getById(id);
|
|
|
- this.generateBill(Collections.singletonList(swWaterUsageEntryDo),attributes);
|
|
|
+ this.generateBill(Collections.singletonList(swWaterUsageEntryDo), attributes);
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void generateBill(List<String> ids, boolean a,ServletRequestAttributes attributes) {
|
|
|
+ public void generateBill(List<String> ids, boolean a, ServletRequestAttributes attributes) {
|
|
|
if (ids.isEmpty()) {
|
|
|
log.error("抄表记录ID为空");
|
|
|
return;
|
|
|
}
|
|
|
- log.info("开始给抄表记录:{},生成账单信息",ids);
|
|
|
- this.generateBill(swWaterUsageEntryService.getBaseMapper().selectBatchIds(ids),attributes);
|
|
|
+ log.info("开始给抄表记录:{},生成账单信息", ids);
|
|
|
+ this.generateBill(swWaterUsageEntryService.getBaseMapper().selectBatchIds(ids), attributes);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -175,8 +177,8 @@ public class BillGenerationServiceImpl {
|
|
|
List<SwWaterUsageEntryDo> list = swWaterUsageEntryService.list(new LambdaQueryWrapper<SwWaterUsageEntryDo>()
|
|
|
.eq(SwWaterUsageEntryDo::getDeleted, "0")
|
|
|
.eq(SwWaterUsageEntryDo::getState, 0));
|
|
|
- log.info("开始给抄表记录:{},生成账单信息",list.stream().map(SwWaterUsageEntryDo::getId).collect(Collectors.toList()));
|
|
|
- this.generateBill(list,attributes);
|
|
|
+ log.info("开始给抄表记录:{},生成账单信息", list.stream().map(SwWaterUsageEntryDo::getId).collect(Collectors.toList()));
|
|
|
+ this.generateBill(list, attributes);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -246,7 +248,7 @@ public class BillGenerationServiceImpl {
|
|
|
|
|
|
String dateStr = formatDate(currentreadingdate);
|
|
|
// 抄表日期+-+户号
|
|
|
- swBillManagementUnpaidDo.setBillnumber(dateStr.replaceAll("-","") + "-" + swWaterUsageEntryDo.getUsernumber());
|
|
|
+ swBillManagementUnpaidDo.setBillnumber(dateStr.replaceAll("-", "") + "-" + swWaterUsageEntryDo.getUsernumber());
|
|
|
swBillManagementUnpaidDo.setYear(Integer.parseInt(dateStr.substring(0, 4)));
|
|
|
swBillManagementUnpaidDo.setMonth(Integer.parseInt(dateStr.substring(5, 7)));
|
|
|
swBillManagementUnpaidDo.setVillagename(swUserManagementDo.getVillagename());
|
|
@@ -257,17 +259,42 @@ public class BillGenerationServiceImpl {
|
|
|
swBillManagementUnpaidDo.setUnitprice(waterprice);
|
|
|
swBillManagementUnpaidDo.setCurrentwateruse(waterConsumption);
|
|
|
|
|
|
+ swBillManagementUnpaidDo.setLastmeterreadingdate(swWaterUsageEntryDo.getLastreadingdate());
|
|
|
+ swBillManagementUnpaidDo.setLastmeterreading(swWaterUsageEntryDo.getLastreading());
|
|
|
+ swBillManagementUnpaidDo.setThismeterreadingdate(swWaterUsageEntryDo.getCurrentreadingdate());
|
|
|
+ swBillManagementUnpaidDo.setThismeterreading(swWaterUsageEntryDo.getThisreading());
|
|
|
+ long monthDiff;
|
|
|
+ // 根据两次抄表日期 计算 共计减免金额
|
|
|
+ if (swBillManagementUnpaidDo.getLastmeterreadingdate() == null) {
|
|
|
+ monthDiff = 1L;
|
|
|
+ } else {
|
|
|
+ LocalDate localDate1 = swBillManagementUnpaidDo.getLastmeterreadingdate().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
|
|
|
+ LocalDate localDate2 = swBillManagementUnpaidDo.getThismeterreadingdate().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
|
|
|
+ // 计算月份差(不考虑天数)
|
|
|
+ monthDiff = ChronoUnit.MONTHS.between(localDate1, localDate2);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//减免计算方式减免金额
|
|
|
BigDecimal exemptionAmount = swUserManagementDo.getExemptionamount() == null ? BigDecimal.ZERO : swUserManagementDo.getExemptionamount();
|
|
|
// 减免用水
|
|
|
BigDecimal exemptionWater = swUserManagementDo.getExemptionwater() == null ? BigDecimal.ZERO : swUserManagementDo.getExemptionwater();
|
|
|
- // 优先金额减免
|
|
|
- if (exemptionAmount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- // 计算减免用水
|
|
|
- exemptionWater = exemptionAmount.divide(waterprice, 2, RoundingMode.HALF_UP);
|
|
|
+ // 不做减免
|
|
|
+ if (monthDiff == 0) {
|
|
|
+ exemptionAmount = BigDecimal.ZERO;
|
|
|
+ exemptionWater = BigDecimal.ZERO;
|
|
|
} else {
|
|
|
- exemptionAmount = exemptionWater.multiply(waterprice);
|
|
|
+ exemptionAmount=exemptionAmount.multiply(BigDecimal.valueOf(monthDiff));
|
|
|
+ exemptionWater=exemptionWater.multiply(BigDecimal.valueOf(monthDiff));
|
|
|
+ // 优先金额减免
|
|
|
+ if (exemptionAmount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ // 计算减免用水
|
|
|
+ exemptionWater = exemptionAmount.divide(waterprice, 2, RoundingMode.HALF_UP);
|
|
|
+ } else {
|
|
|
+ exemptionAmount = exemptionWater.multiply(waterprice);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
swBillManagementUnpaidDo.setReducedwateruse(exemptionWater);
|
|
|
swBillManagementUnpaidDo.setFeewaiver(exemptionAmount);
|
|
|
swBillManagementUnpaidDo.setOughttohavepaid(waterprice.multiply(waterConsumption));
|
|
@@ -275,14 +302,10 @@ public class BillGenerationServiceImpl {
|
|
|
// 实际应缴=原应缴-减免
|
|
|
BigDecimal subtract = swBillManagementUnpaidDo.getOughttohavepaid().subtract(swBillManagementUnpaidDo.getFeewaiver());
|
|
|
swBillManagementUnpaidDo.setActualdue(subtract.compareTo(BigDecimal.ZERO) > 0 ? subtract : BigDecimal.ZERO);
|
|
|
- swBillManagementUnpaidDo.setLastmeterreadingdate(swWaterUsageEntryDo.getLastreadingdate());
|
|
|
- swBillManagementUnpaidDo.setLastmeterreading(swWaterUsageEntryDo.getLastreading());
|
|
|
- swBillManagementUnpaidDo.setThismeterreadingdate(swWaterUsageEntryDo.getCurrentreadingdate());
|
|
|
- swBillManagementUnpaidDo.setThismeterreading(swWaterUsageEntryDo.getThisreading());
|
|
|
+
|
|
|
swBillManagementUnpaidDo.setStatus(1 + "");
|
|
|
ZHSWCommonUtils.initModelGeneralParameters(swBillManagementUnpaidDo, null);
|
|
|
swBillManagementUnpaidDo.setWaterusageid(swWaterUsageEntryDo.getId());
|
|
|
return swBillManagementUnpaidDo;
|
|
|
}
|
|
|
-
|
|
|
}
|