|
@@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
@@ -55,6 +56,8 @@ public class PaymentService {
|
|
|
BigDecimal earnestMoney = null;
|
|
|
// 单价租金
|
|
|
BigDecimal unitPrice = null;
|
|
|
+ // 按全年多少天
|
|
|
+ String yearDays = "365";
|
|
|
|
|
|
JSONArray earnestMoneyArray = new JSONArray();
|
|
|
|
|
@@ -63,6 +66,7 @@ public class PaymentService {
|
|
|
for (Clause clause : clauseList) {
|
|
|
// 租赁条款
|
|
|
if (clause.getType() == 1) {
|
|
|
+ yearDays = clause.getYearDays();
|
|
|
start = clause.getStartTime();
|
|
|
end = clause.getEndTime();
|
|
|
reminder = map.get(clause.getPayTime());
|
|
@@ -134,6 +138,55 @@ public class PaymentService {
|
|
|
payment.setPhase(b + i);
|
|
|
list.add(payment);
|
|
|
}
|
|
|
+
|
|
|
+ // 不足一期的按天计算
|
|
|
+ Payment last = list.getLast();
|
|
|
+ LocalDate lastDate = LocalDate.parse(last.getEndDate());
|
|
|
+
|
|
|
+ if (lastDate.isBefore(endDate)) {
|
|
|
+ // 计算两个日期之间的天数差异
|
|
|
+ long daysBetween = ChronoUnit.DAYS.between(lastDate, endDate);
|
|
|
+
|
|
|
+ BigDecimal ds = new BigDecimal(daysBetween);
|
|
|
+ BigDecimal m = new BigDecimal(12);
|
|
|
+ BigDecimal t = unitPrice.multiply(m);
|
|
|
+
|
|
|
+ BigDecimal d = new BigDecimal(yearDays);
|
|
|
+ // 结果的小数点后保留的位数
|
|
|
+ int scale = 2;
|
|
|
+ // 舍入模式
|
|
|
+ RoundingMode roundingMode = RoundingMode.HALF_UP;
|
|
|
+
|
|
|
+ // 计算一天租金
|
|
|
+ BigDecimal rent = t.divide(d, scale, roundingMode);
|
|
|
+ // 计算剩余天数总租金
|
|
|
+ BigDecimal tt = rent.multiply(ds).setScale(scale, roundingMode);
|
|
|
+
|
|
|
+ Payment payment = new Payment();
|
|
|
+ payment.setProjectId(contract.getProjectId());
|
|
|
+ payment.setContractCode(contract.getCode());
|
|
|
+ payment.setContractId(clauseId);
|
|
|
+ payment.setPayMerchantId(contract.getMerchantId());
|
|
|
+ payment.setOrganizationId(contract.getOrganizationId());
|
|
|
+ payment.setPayClientId(contract.getClientId());
|
|
|
+
|
|
|
+ JSONArray unitPriceArray = new JSONArray();
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+
|
|
|
+ payment.setReminderDate(endDate.minusDays(reminder).toString());
|
|
|
+ payment.setStartDate(last.getEndDate());
|
|
|
+ payment.setEndDate(endDate.toString());
|
|
|
+
|
|
|
+ payment.setAmount(tt);
|
|
|
+ json.put("dailyPrice", rent);
|
|
|
+ json.put("yearDays", yearDays);
|
|
|
+ json.put("days", daysBetween);
|
|
|
+ unitPriceArray.add(json);
|
|
|
+ payment.setData(unitPriceArray.toJSONString());
|
|
|
+ payment.setPhase(last.getPhase() + 1);
|
|
|
+ list.add(payment);
|
|
|
+ }
|
|
|
+
|
|
|
paymentDao.batchInsert(list);
|
|
|
}
|
|
|
|