Browse Source

[bug][修改][修改预览账单问题]

release_toaliyun_real
luozukai 7 years ago
parent
commit
00523d18d2
2 changed files with 84 additions and 33 deletions
  1. +20
    -17
      mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java
  2. +64
    -16
      mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java

+ 20
- 17
mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java View File

@@ -517,21 +517,20 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
}

List<BillTimeVo> billTimeVoList = WxRentContractServiceImpl.initBillTimeList(wxPropertyContract.getRentalStartDate(),wxPropertyContract.getRentalEndDate(),wxPropertyContract.getAdjustPeriod(),dayType,receivePeriod);

int index = 0;
for (BillTimeVo billTimeVo : billTimeVoList){
if(sd.format(billTimeVo.getStartDate()).equals("2020-05-29")){
System.out.println();
}
for (int i = 0; i < billTimeVoList.size(); i++) {
BillTimeVo billTimeVo = billTimeVoList.get(i);

if(yearList.size() > 1) {
if (endDate!=null && (sd.format(billTimeVo.getStartDate()).equals(sd.format(endDate)) || billTimeVo.getStartDate().after(endDate))) {
if (endDate!=null && (sd.format(billTimeVo.getStartDate()).equals(sd.format(endDate)) || billTimeVo.getStartDate().after(endDate) || billTimeVo.getEndDate().after(endDate) )) {
logger.info("=====billTimeVo.getStartDate():"+sd.format(billTimeVo.getStartDate())+" endDate:"+sd.format(endDate));

index++;
if(index >= yearList.size()-1){
//endDate = wxPropertyContract.getRentalEndDate();
//endDate = wxRentContract.getRentalEndDate();
endDate = null;
}else {
}else{
endDate = yearList.get(index+1);//price index 0开始,year.end 从第二年开始
logger.info("==========cross:"+sd.format(endDate));
}
@@ -551,7 +550,6 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
wxBillProperty.setReceiveDate(billTimeVo.getReceiveDate());

long needpay;

//按日
if (wxPropertyContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())){
Double priceD = new Double(price);
@@ -564,15 +562,19 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
priceD = new Double(price)/12;
}

//当天也算,加1天
Date newEndDate = DateUtils.getDaySet(wxBillProperty.getEndtime(),Calendar.DATE,1);
//按月
int[] diff = DateUtils.getDiff(wxBillProperty.getStarttime(),newEndDate);
needpay =new Double( diff[0]*priceD).longValue();

double oneDayProce = priceD/DateUtils.getMonthDayCount(wxPropertyContract.getRentalEndDate());
needpay += diff[1] * oneDayProce;
if(i == 0){//第一期
if(wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){
needpay = new Double(WxRentContractServiceImpl.getMonthNeedPay(priceD,billTimeVo.getStartDate(),billTimeVo.getEndDate())).longValue();
}else{
needpay = new Double(receivePeriod * priceD).longValue();
}
}else if(i == billTimeVoList.size()-1){//最后
needpay = new Double(WxRentContractServiceImpl.getMonthNeedPay(priceD,billTimeVo.getStartDate(),billTimeVo.getEndDate())).longValue();
}else{//中间
needpay = new Double(receivePeriod * priceD).longValue();
}
}

wxBillProperty.setNeedPay(needpay);
wxBillProperty.setOwe(needpay);
wxBillProperty.setReceivePay(needpay);
@@ -650,7 +652,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
//按月计租
// if (propertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode())
// ||propertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) {
result = buildRentMonth(wxMerchant, userId, propertyContract, receivePeriod, lease, rentalStartDate, price,isPreview);
result = buildRentMonth(wxMerchant, userId, propertyContract, receivePeriod, lease, rentalStartDate, price,isPreview);
// } else {
// //如果按日
// List<Date> yearList = new ArrayList<>();
@@ -916,3 +918,4 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
}




+ 64
- 16
mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java View File

@@ -33,7 +33,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import org.joda.time.DateTime;
import org.joda.time.Months;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
@@ -732,7 +735,7 @@ public class WxRentContractServiceImpl implements WxRentContractService {
//按月计租
// if (wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode())
// ||wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())) {
rentList = buildRentMonth(wxMerchant, userId, wxRentContract, receivePeriod, lease, rentalStartDate, price,isPreview);
rentList = buildRentMonth(wxMerchant, userId, wxRentContract, receivePeriod, lease, rentalStartDate, price,isPreview);
// } else {
// //如果按日
// List<Date> yearList = new ArrayList<>();
@@ -882,9 +885,11 @@ public class WxRentContractServiceImpl implements WxRentContractService {
// }

int index = 0;
for (BillTimeVo billTimeVo : billTimeVoList){
for (int i = 0; i < billTimeVoList.size(); i++) {
BillTimeVo billTimeVo = billTimeVoList.get(i);

if(yearList.size() > 1) {
if (endDate!=null && (sd.format(billTimeVo.getStartDate()).equals(sd.format(endDate)) || billTimeVo.getStartDate().after(endDate))) {
if (endDate!=null && (sd.format(billTimeVo.getStartDate()).equals(sd.format(endDate)) || billTimeVo.getStartDate().after(endDate) || billTimeVo.getEndDate().after(endDate) )) {
logger.info("=====billTimeVo.getStartDate():"+sd.format(billTimeVo.getStartDate())+" endDate:"+sd.format(endDate));

index++;
@@ -895,7 +900,6 @@ public class WxRentContractServiceImpl implements WxRentContractService {
endDate = yearList.get(index+1);//price index 0开始,year.end 从第二年开始
logger.info("==========cross:"+sd.format(endDate));
}

}
}

@@ -916,8 +920,8 @@ public class WxRentContractServiceImpl implements WxRentContractService {
JSONArray rentInfoArray = JSONArray.parseArray(rentInfo);
int rentSize = rentInfoArray.size();
Map<String, Object> shopInfoMap = new HashMap<>();
for (int i = 0; i < rentSize; i++) {
JSONObject rentInfoObject = rentInfoArray.getJSONObject(i);
for (int j = 0; j < rentSize; j++) {
JSONObject rentInfoObject = rentInfoArray.getJSONObject(j);
shopInfoMap.put(rentInfoObject.getString("shopNumber"), 0);
}
shopInfoStr = JSONObject.toJSONString(shopInfoMap);
@@ -934,7 +938,6 @@ public class WxRentContractServiceImpl implements WxRentContractService {
wxBillRent.setReceiveDate(billTimeVo.getReceiveDate());

long needpay;

//按日
if (wxRentContract.getPriceUnit().equals(EnumPriceUnit.D.getCode())){
Double priceD = new Double(price);
@@ -947,14 +950,17 @@ public class WxRentContractServiceImpl implements WxRentContractService {
priceD = new Double(price)/12;
}

//当天也算,加1天
Date newEndDate = DateUtils.getDaySet(wxBillRent.getEndtime(),Calendar.DATE,1);
//按月
int[] diff = DateUtils.getDiff(wxBillRent.getStarttime(),newEndDate);
needpay =new Double( diff[0]*priceD).longValue();

double oneDayProce = priceD/DateUtils.getMonthDayCount(wxRentContract.getRentalEndDate());
needpay += diff[1] * oneDayProce;
if(i == 0){//第一期
if(wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_NAR_MONTH.getCode())){
needpay = new Double(getMonthNeedPay(priceD,billTimeVo.getStartDate(),billTimeVo.getEndDate())).longValue();
}else{
needpay = new Double(receivePeriod * priceD).longValue();
}
}else if(i == billTimeVoList.size()-1){//最后
needpay = new Double(getMonthNeedPay(priceD,billTimeVo.getStartDate(),billTimeVo.getEndDate())).longValue();
}else{//中间
needpay = new Double(receivePeriod * priceD).longValue();
}
}

wxBillRent.setNeedPay(needpay);
@@ -1001,6 +1007,23 @@ public class WxRentContractServiceImpl implements WxRentContractService {
return resultMap;
}

public boolean isFirstDay(Date date){
int dateInt = Integer.parseInt(new SimpleDateFormat("d").format(date));
if(dateInt == 1){
return true;
}
return false;
}

public static int getMonths(String startStr,String endStr){
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTime start = formatter.parseDateTime(startStr);
DateTime end = formatter.parseDateTime(endStr);
int months = Months.monthsBetween(start, end).getMonths();
return months;
}


@Transactional(rollbackFor = {Exception.class})
@Override
public ResultData deleteById(String id) {
@@ -1769,6 +1792,30 @@ public class WxRentContractServiceImpl implements WxRentContractService {
return wxRentContractMapper.getShopType(wxRentContract);
}

public static double getMonthNeedPay(Double price,Date start,Date end){
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdM = new SimpleDateFormat("yyyy-MM");
Double total = new Double(0);
int[] diff;

//第一个月
Date lastMonthDay = DateUtils.getLastDayForMonth(start);
diff = DateUtils.getDiff(start,lastMonthDay);
int dayCount = DateUtils.getMonthDayCount(start);
total += (diff[1]+1) * (price/dayCount);

//中间月份
Date newStartDate = DateUtils.getDaySet(lastMonthDay,Calendar.DATE,1);
int months = getMonths(sdM.format(newStartDate)+"-01",sdM.format(end)+"-01");
total += months * price;

//最后一个月
diff = DateUtils.getDiff(DateUtils.getFirstDayForCurrMonth(end),end);
dayCount = DateUtils.getMonthDayCount(end);
total += (diff[1]+1) * (price/dayCount);
return total;
}

/**
* 按日计租 根据每月的日期总数计算needpay
* @param monthPrice
@@ -1908,3 +1955,4 @@ public class WxRentContractServiceImpl implements WxRentContractService {





Loading…
Cancel
Save