Просмотр исходного кода

[账期优化][修改][修改账期生成逻辑]

release_toaliyun_real
luozukai 7 лет назад
Родитель
Сommit
769db7e3b6
3 измененных файлов: 142 добавлений и 89 удалений
  1. +89
    -35
      mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java
  2. +52
    -53
      mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java
  3. +1
    -1
      mallinkService/src/main/java/com/iformall/utils/Constant.java

+ 89
- 35
mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java Просмотреть файл

@@ -450,10 +450,22 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
List<WxBillProperty> resultList = new ArrayList<>();
for (int i = 0; i < size; i++) {
Calendar instance = Calendar.getInstance();
instance.setTime(rentalStartDate);
//开始时间
instance.add(Calendar.MONTH, month * i);
Map<String, Object> resultMap = buildRent(leaseArr[i], receivePeriod, priceArr[i], instance.getTime(), Calendar.MONTH, wxPropertyContract, userId, wxMerchant, billcount, isPreview, shopInfo);
Date startDate;
//自然月
if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){
if(i == 0){ //第一期
startDate = rentalStartDate;
}else{
instance.setTime(rentalStartDate);
instance.add(Calendar.MONTH, month * i);
startDate = DateUtils.getFirstDayForCurrMonth(instance.getTime());
}
}else{
instance.setTime(rentalStartDate);
instance.add(Calendar.MONTH, month * i);
startDate = instance.getTime();
}
Map<String, Object> resultMap = buildRent(leaseArr[i], receivePeriod, priceArr[i], startDate, Calendar.MONTH, wxPropertyContract, userId, wxMerchant, billcount, isPreview, shopInfo,i==size-1?true:false);
List<WxBillProperty> billRentList = (List<WxBillProperty>)resultMap.get("billList");
billcount = (Integer)resultMap.get("billcount");
resultList.addAll(billRentList);
@@ -461,7 +473,15 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
return resultList;
}

public Map<String, Object> buildRent(int lease, int receivePeriod, int price, Date startdate, int dayType, WxPropertyContract wxPropertyContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview, Map<String, Object> shopInfo) {
public boolean isFirstDay(Date date){
int dateInt = Integer.parseInt(new SimpleDateFormat("d").format(date));
if(dateInt == 1){
return true;
}
return false;
}

public Map<String, Object> buildRent(int lease, int receivePeriod, int price, Date startdate, int dayType, WxPropertyContract wxPropertyContract, Long userId, WxMerchant wxMerchant, int billcount, Integer isPreview, Map<String, Object> shopInfo,boolean isLastYesr) {
Map<String,Object> resultMap = new HashedMap();
List<WxBillProperty> resultList = new ArrayList<>();
int extralease = lease % receivePeriod;
@@ -469,11 +489,15 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
int paycount = lease / receivePeriod + extracount;
int index = paycount - 1;
final IdWorker idWorker = IdWorker.get();
//自然月,周期为一个月 n+1
if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode()) && receivePeriod <= 1){
//自然月,而且残月,周期整除,n+1,最后一个周期作为残月
if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())
&& !isFirstDay(wxPropertyContract.getRentalStartDate())
&& (wxPropertyContract.getLease() % wxPropertyContract.getReceivePeriod() == 0)
&& isLastYesr
){
paycount ++;
}
for (int i = 0; i < paycount; i++) {
for(int i = 0; i < paycount; i++){
WxBillProperty wxBillProperty = new WxBillProperty();
wxBillProperty.setIsPreview(isPreview);

@@ -486,14 +510,18 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
Calendar instance = Calendar.getInstance();
instance.setTime(startdate);
instance.add(dayType, receivePeriod * i);
instance.add(Calendar.DAY_OF_MONTH, -1);
if(!wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) {
instance.add(Calendar.DAY_OF_MONTH, -1);
}
Date time = instance.getTime();
wxBillProperty.setReceiveDate(time);

//账单开始时间
instance.clear();
instance.setTime(wxBillProperty.getReceiveDate());
instance.add(Calendar.DAY_OF_MONTH, 1);
if(!wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) {
instance.add(Calendar.DAY_OF_MONTH, 1);
}
wxBillProperty.setStarttime(instance.getTime());
//账单结束时间
instance.clear();
@@ -506,7 +534,9 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
//账单开始时间
instance.clear();
instance.setTime(wxBillProperty.getReceiveDate());
instance.add(Calendar.DAY_OF_MONTH, 1);
if(!wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) {
instance.add(Calendar.DAY_OF_MONTH, 1);
}
wxBillProperty.setStarttime(instance.getTime());
//账单结束时间
instance.clear();
@@ -519,26 +549,48 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService

//自然月,开始日期、缴款日,结束日期
if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){
int rentStartDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getRentalStartDate()));
int startDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxBillProperty.getStarttime()));
int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getRentalEndDate()));

if(i == 0){//第一周期
wxBillProperty.setReceiveDate(wxPropertyContract.getRentalStartDate());
wxBillProperty.setStarttime(wxPropertyContract.getRentalStartDate());
double oneDayProce = (double) price / DateUtils.getMonthDayCount(wxPropertyContract.getRentalStartDate());
int startDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getRentalStartDate()));
double oneDayProce = (double) price / DateUtils.getMonthDayCount(wxBillProperty.getStarttime());
double needPayDouble;

if(receivePeriod <= 1) {//周期为一个月
wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(wxPropertyContract.getRentalStartDate()));
needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxPropertyContract.getRentalStartDate())-startDateInt+1);
wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(wxBillProperty.getStarttime()));
needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxBillProperty.getStarttime())-startDateInt+1);
}else{ //周期大于一个月
wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(wxPropertyContract.getRentalStartDate(),receivePeriod - 1));
// [A/31 *(31-12+1)]+A+A
needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxPropertyContract.getRentalStartDate())-startDateInt+1);
needPayDouble += price * (receivePeriod - 1);
Date firstDay = DateUtils.getFirstDayForCurrMonth(wxBillProperty.getStarttime());
instance.clear();
instance.setTime(firstDay);
//最后一个期有余,加上残月,不整除时,最后一个月有余,否则为0
if(extralease > 0 && (i == paycount - 1)){
instance.add(dayType, extralease);
instance.add(Calendar.DAY_OF_MONTH, rentStartDateInt-1);
}else{
instance.add(dayType, receivePeriod);
}
instance.add(Calendar.DAY_OF_MONTH, -1);

wxBillProperty.setEndtime(instance.getTime());
if(isLastYesr && (i == paycount - 1)){ //最后一年 最后一期
needPayDouble = 0;
oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillProperty.getEndtime());
if(receivePeriod > 1) {
needPayDouble += price * extralease;
}
needPayDouble += oneDayProce * endDateInt;
}else{
//[A/31 *(31-12+1)]+A+A
needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxBillProperty.getStarttime())-startDateInt+1);
needPayDouble += price * (receivePeriod - 1);
}
}
DecimalFormat format = new DecimalFormat("0");
needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入
}else if(i < paycount - 1){//中间周期
Date receiveDate = DateUtils.getFirstDayOfNextMonth(wxPropertyContract.getRentalStartDate(),receivePeriod * i);
Date receiveDate = DateUtils.getFirstDayOfNextMonth(startdate,receivePeriod * i);
wxBillProperty.setReceiveDate(receiveDate);
wxBillProperty.setStarttime(receiveDate);
wxBillProperty.setEndtime(DateUtils.getLastDayForMonth(receiveDate,receivePeriod * i));
@@ -549,25 +601,27 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
instance.add(Calendar.DAY_OF_MONTH, -1);
wxBillProperty.setEndtime(instance.getTime());
}else if(i == paycount - 1) {//最后周期
Date receiveDate = DateUtils.getFirstDayOfNextMonth(wxPropertyContract.getRentalStartDate(),receivePeriod * i);
Date receiveDate = DateUtils.getFirstDayOfNextMonth(startdate,receivePeriod * i);
wxBillProperty.setReceiveDate(receiveDate);
wxBillProperty.setStarttime(receiveDate);

Date firstDay = DateUtils.getFirstDayForCurrMonth(wxBillProperty.getStarttime());
instance.clear();
instance.setTime(receiveDate);
instance.add(dayType, extracount>0?extralease:receivePeriod);//最后一期不足,一个完整周期
instance.setTime(firstDay);
//最后一期有余,加上残月,(不整除时,最后一个月有余,否则为0)
if(receivePeriod > 1) {
instance.add(dayType, extralease);
}
instance.add(Calendar.DAY_OF_MONTH, rentStartDateInt-1);
instance.add(Calendar.DAY_OF_MONTH, -1);
int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxPropertyContract.getEndDate()));
String endDateStr = DateUtils.date2String(instance.getTime(),"yyyy-MM")+ "-" +endDateInt;
wxBillProperty.setEndtime(DateUtils.stringToDate(endDateStr,"yyyy-MM-dd"));
wxBillProperty.setEndtime(instance.getTime());

double needPayDouble;
double needPayDouble = 0;
double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillProperty.getEndtime());
if(receivePeriod <= 1) {//周期为一个月
needPayDouble = oneDayProce * endDateInt;
}else{
needPayDouble = price * (extralease-1);
needPayDouble += oneDayProce * endDateInt;
if(receivePeriod > 1) {
needPayDouble += price * extralease;
}
needPayDouble += oneDayProce * endDateInt;
DecimalFormat format = new DecimalFormat("0");
needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入
}
@@ -657,7 +711,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
result = buildRentMonth(wxMerchant, userId, propertyContract, receivePeriod, lease, rentalStartDate, price,isPreview);
} else {
//按日计租
Map<String, Object> resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, propertyContract, userId, wxMerchant, 0, isPreview, null);
Map<String, Object> resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, propertyContract, userId, wxMerchant, 0, isPreview, null,false);
result = (List<WxBillProperty>)resultMap.get("billList");
}
}


+ 52
- 53
mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java Просмотреть файл

@@ -98,6 +98,11 @@ public class WxRentContractServiceImpl implements WxRentContractService {
@Autowired
WxMerchantShopMapper wxMerchantShopMapper;

public static void main(String[] args) {
System.out.println(3%3);
System.out.println(6%3);
}

@Override
public Map<String, Object> listAsPage(WxRentContract record, Integer pageIndex, Integer pageSize) {
Object rentContractStatusInfo = getRentContractStatusInfo(record);
@@ -812,18 +817,19 @@ public class WxRentContractServiceImpl implements WxRentContractService {
}
Map<String,Object> resultMap = new HashedMap();
List<WxBillRent> resultList = new ArrayList<>();
int extralease = lease % receivePeriod;
int extralease = lease % receivePeriod; //余
int extracount = extralease > 0 ? 1 : 0;
int paycount = lease / receivePeriod + extracount;
int index = paycount - 1;
final IdWorker idWorker = IdWorker.get();
//自然月,而且残月,而且整除,最后一个月单独一个周期
// if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())
// && !isFirstDay(wxRentContract.getRentalStartDate()) && isLastYesr
// && (wxRentContract.getLease()/wxRentContract.getReceivePeriod() == 0)
// ){
// paycount ++;
// }
//自然月,而且残月,周期整除,n+1,最后一个周期作为残月
if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())
&& !isFirstDay(wxRentContract.getRentalStartDate())
&& (wxRentContract.getLease() % wxRentContract.getReceivePeriod() == 0)
&& isLastYesr
){
paycount ++;
}
for(int i = 0; i < paycount; i++){
WxBillRent wxBillRent = new WxBillRent();
wxBillRent.setIsPreview(isPreview);
@@ -878,9 +884,12 @@ public class WxRentContractServiceImpl implements WxRentContractService {

//自然月,开始日期、缴款日,结束日期
if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){
int rentStartDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxRentContract.getRentalStartDate()));
int startDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxBillRent.getStarttime()));
int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxRentContract.getRentalEndDate()));

if(i == 0){//第一周期
double oneDayProce = (double) price / DateUtils.getMonthDayCount(wxBillRent.getStarttime());
int startDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxBillRent.getStarttime()));
double needPayDouble;

if(receivePeriod <= 1) {//周期为一个月
@@ -890,12 +899,28 @@ public class WxRentContractServiceImpl implements WxRentContractService {
Date firstDay = DateUtils.getFirstDayForCurrMonth(wxBillRent.getStarttime());
instance.clear();
instance.setTime(firstDay);
instance.add(dayType, extralease);
//最后一个期有余,加上残月,不整除时,最后一个月有余,否则为0
if(extralease > 0 && (i == paycount - 1)){
instance.add(dayType, extralease);
instance.add(Calendar.DAY_OF_MONTH, rentStartDateInt-1);
}else{
instance.add(dayType, receivePeriod);
}
instance.add(Calendar.DAY_OF_MONTH, -1);

wxBillRent.setEndtime(instance.getTime());
// [A/31 *(31-12+1)]+A+A
needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxBillRent.getStarttime())-startDateInt+1);
needPayDouble += price * (receivePeriod - 1);
if(isLastYesr && (i == paycount - 1)){ //最后一年 最后一期
needPayDouble = 0;
oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillRent.getEndtime());
if(receivePeriod > 1) {
needPayDouble += price * extralease;
}
needPayDouble += oneDayProce * endDateInt;
}else{
//[A/31 *(31-12+1)]+A+A
needPayDouble = oneDayProce * (DateUtils.getMonthDayCount(wxBillRent.getStarttime())-startDateInt+1);
needPayDouble += price * (receivePeriod - 1);
}
}
DecimalFormat format = new DecimalFormat("0");
needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入
@@ -911,58 +936,32 @@ public class WxRentContractServiceImpl implements WxRentContractService {
instance.add(Calendar.DAY_OF_MONTH, -1);
wxBillRent.setEndtime(instance.getTime());
}else if(i == paycount - 1) {//最后周期
Date receiveDate = DateUtils.getFirstDayOfNextMonth(wxRentContract.getRentalStartDate(),receivePeriod * i);
Date receiveDate = DateUtils.getFirstDayOfNextMonth(startdate,receivePeriod * i);
wxBillRent.setReceiveDate(receiveDate);
wxBillRent.setStarttime(receiveDate);
instance.clear();
instance.setTime(receiveDate);
instance.add(dayType, extracount>0?extralease:receivePeriod);//最后一期不足,一个完整周期
instance.add(Calendar.DAY_OF_MONTH, -1);
int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxRentContract.getRentalEndDate()));
String endDateStr = DateUtils.date2String(instance.getTime(),"yyyy-MM")+ "-" +endDateInt;
wxBillRent.setEndtime(DateUtils.stringToDate(endDateStr,"yyyy-MM-dd"));

double needPayDouble;
double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillRent.getEndtime());
needPayDouble = oneDayProce * endDateInt;
DecimalFormat format = new DecimalFormat("0");
needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入
}
}
//最后一个周期
if (isLastYesr) {
if(wxRentContract.getLease()/wxRentContract.getReceivePeriod() == 0){
wxBillRent.setStarttime(startdate);

int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxRentContract.getRentalEndDate()));
String endDateStr = DateUtils.date2String(startdate,"yyyy-MM")+ "-" +(endDateInt - 1);
wxBillRent.setEndtime(DateUtils.stringToDate(endDateStr,"yyyy-MM-dd"));

double needPayDouble;
double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillRent.getEndtime());
needPayDouble = oneDayProce * endDateInt;
DecimalFormat format = new DecimalFormat("0");
needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入
}else{
wxBillRent.setStarttime(startdate);
int endDateInt = Integer.parseInt(new SimpleDateFormat("d").format(wxRentContract.getRentalEndDate()));

Date firstDay = DateUtils.getFirstDayForCurrMonth(wxBillRent.getStarttime());
instance.clear();
instance.setTime(DateUtils.getLastDayOfNextMonth(startdate,lease));
instance.add(dayType, receivePeriod);
instance.add(Calendar.DAY_OF_MONTH, endDateInt-1);
instance.setTime(firstDay);
//最后一期有余,加上残月,(不整除时,最后一个月有余,否则为0)
if(receivePeriod > 1) {
instance.add(dayType, extralease);
}
instance.add(Calendar.DAY_OF_MONTH, rentStartDateInt-1);
instance.add(Calendar.DAY_OF_MONTH, -1);
wxBillRent.setEndtime(instance.getTime());

double needPayDouble;
double needPayDouble = 0;
double oneDayProce = (double) price/DateUtils.getMonthDayCount(wxBillRent.getEndtime());
needPayDouble = oneDayProce * endDateInt;
if(receivePeriod > 1) {
needPayDouble += price * extralease;
}
needPayDouble += oneDayProce * endDateInt;
DecimalFormat format = new DecimalFormat("0");
needpay = Integer.parseInt(format.format(needPayDouble)); //分做四舍五入
}

}


wxBillRent.setNeedPay(needpay);
wxBillRent.setOwe(needpay);
wxBillRent.setReceivePay(needpay);


+ 1
- 1
mallinkService/src/main/java/com/iformall/utils/Constant.java Просмотреть файл

@@ -14,5 +14,5 @@ public class Constant {

public static final String fileDirectory = "./uploads/";
public static final String importMemPrev = "importmem/";
public static final String adminPage = "http://admin.malls.iformall.com";
public static final String adminPage = "https://admin.malls.iformall.com";
}

Загрузка…
Отмена
Сохранить