|
|
|
@@ -13,12 +13,15 @@ import com.iformall.domain.po.*; |
|
|
|
import com.iformall.domain.po.base.BaseEntity; |
|
|
|
import com.iformall.domain.po.base.TenantEntity; |
|
|
|
import com.iformall.domain.vo.BillTimeVo; |
|
|
|
import com.iformall.domain.vo.WxBillFeesStandardsListVo; |
|
|
|
import com.iformall.domain.vo.WxBillFeesStandardsVo; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.mapper.*; |
|
|
|
import com.iformall.service.*; |
|
|
|
import com.iformall.service.helper.WxBillAllHelper; |
|
|
|
import com.iformall.service.helper.WxRentContractHelper; |
|
|
|
import com.iformall.utils.Constant; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import org.apache.commons.collections.map.HashedMap; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
@@ -643,7 +646,6 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService |
|
|
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
Map<String,Object> resultMap = new HashedMap(); |
|
|
|
List<WxBillProperty> resultList = new ArrayList<>(); |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
|
|
|
|
Date endDate = null; |
|
|
|
if(yearList.size() > 1){ |
|
|
|
@@ -663,97 +665,99 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService |
|
|
|
billTimeVoList.add(billTimeVo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//结算其他金额 |
|
|
|
Date billStartDate = null; |
|
|
|
Date billEndDate = null; |
|
|
|
if (billTimeVoList.size() > 0 ) { |
|
|
|
billStartDate = billTimeVoList.get(0).getStartDate(); |
|
|
|
billEndDate = billTimeVoList.get(billTimeVoList.size()-1).getEndDate(); |
|
|
|
} |
|
|
|
WxBillFeesStandardsVo standardsVo = WxRentContractHelper.getStandardsBillList(wxPropertyContract.getFeesStardarsList(),billStartDate,billEndDate); |
|
|
|
List<WxBillFeesStandardsListVo> fixedList = null; |
|
|
|
List<WxBillFeesStandardsListVo> unFixedList = null; |
|
|
|
if (null != standardsVo) { |
|
|
|
fixedList = standardsVo.getFixedFeeStandards(); |
|
|
|
unFixedList = standardsVo.getUnFixedFeeStandards(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int index = 0; |
|
|
|
for (int i = 0; i < billTimeVoList.size(); i++) { |
|
|
|
BillTimeVo billTimeVo = billTimeVoList.get(i); |
|
|
|
//计算金额 |
|
|
|
String needpay = "0"; |
|
|
|
//结算其他金额 |
|
|
|
String standarsTotal = "0"; |
|
|
|
|
|
|
|
boolean flag = false; |
|
|
|
//超过1年 |
|
|
|
if(yearList.size() > 1) { |
|
|
|
//从第二年开始 |
|
|
|
if (endDate!=null && (sd.format(billTimeVo.getStartDate()).equals(sd.format(endDate)) || billTimeVo.getStartDate().after(endDate) || billTimeVo.getEndDate().after(endDate) )) { |
|
|
|
if(yearList.size() > 1) { |
|
|
|
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++; |
|
|
|
|
|
|
|
//如果是计算账单金额&cross 拆分日期进行计算 |
|
|
|
if(!saveDb && billTimeVo.getEndDate().after(endDate)) { |
|
|
|
String needpayFront = "0"; |
|
|
|
String needpayAfter = "0"; |
|
|
|
//同一天,算一天 |
|
|
|
if(sd.format(billTimeVo.getStartDate()).equals(sd.format(billTimeVo.getEndDate()))){ |
|
|
|
needpayFront = getNeedPayMoney(wxPropertyContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod); |
|
|
|
}else{ |
|
|
|
if(billTimeVo.getStartDate().before(endDate)){ |
|
|
|
needpayFront = getNeedPayMoney(wxPropertyContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate,Calendar.DATE,-1), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); |
|
|
|
needpayAfter = getNeedPayMoney(wxPropertyContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); |
|
|
|
}else{ |
|
|
|
needpayFront = getNeedPayMoney(wxPropertyContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); |
|
|
|
} |
|
|
|
} |
|
|
|
needpay = needpayFront+needpayAfter; |
|
|
|
flag = true; |
|
|
|
} |
|
|
|
if(index >= yearList.size()-1){ |
|
|
|
endDate = null; |
|
|
|
//logger.info("=====billTimeVo.getStartDate():"+sd.format(billTimeVo.getStartDate())+" endDate:"+sd.format(endDate)); |
|
|
|
|
|
|
|
index++; |
|
|
|
|
|
|
|
//如果是计算账单金额&cross 拆分日期进行计算 |
|
|
|
if(!saveDb && billTimeVo.getEndDate().after(endDate)) { |
|
|
|
String needpayFront = "0"; |
|
|
|
String needpayAfter = "0"; |
|
|
|
//同一天,算一天 |
|
|
|
if(sd.format(billTimeVo.getStartDate()).equals(sd.format(billTimeVo.getEndDate()))){ |
|
|
|
needpayFront = getNeedPayMoney(wxPropertyContract,priceArrs[index-1],billTimeVo.getStartDate(),endDate,i,billTimeVoList.size(),saveDb,dayType,receivePeriod); |
|
|
|
standarsTotal = calcuteStandardsFee(unFixedList, billTimeVo.getStartDate(), endDate, wxPropertyContract); |
|
|
|
}else{ |
|
|
|
if(billTimeVo.getStartDate().before(endDate)){ |
|
|
|
needpayFront = getNeedPayMoney(wxPropertyContract, priceArrs[index - 1], billTimeVo.getStartDate(), DateUtils.getDaySet(endDate,Calendar.DATE,-1), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); |
|
|
|
needpayAfter = getNeedPayMoney(wxPropertyContract, priceArrs[index], endDate, billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); |
|
|
|
}else{ |
|
|
|
endDate = yearList.get(index+1);//price index 0开始,year.end 从第二年开始 |
|
|
|
//logger.info("==========cross:"+sd.format(endDate)); |
|
|
|
needpayFront = getNeedPayMoney(wxPropertyContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(), saveDb,dayType,receivePeriod); |
|
|
|
} |
|
|
|
standarsTotal = calcuteStandardsFee(unFixedList, billTimeVo.getStartDate(), billTimeVo.getEndDate(), wxPropertyContract); |
|
|
|
} |
|
|
|
needpay = needpayFront+needpayAfter; |
|
|
|
flag = true; |
|
|
|
} |
|
|
|
if(index >= yearList.size()-1){ |
|
|
|
endDate = null; |
|
|
|
}else{ |
|
|
|
endDate = yearList.get(index+1);//price index 0开始,year.end 从第二年开始 |
|
|
|
//logger.info("==========cross:"+sd.format(endDate)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//计算金额 |
|
|
|
//第一年的,计算金额 |
|
|
|
if(!flag){ |
|
|
|
needpay = getNeedPayMoney(wxPropertyContract, priceArrs[index], billTimeVo.getStartDate(), billTimeVo.getEndDate(), i, billTimeVoList.size(),saveDb,dayType,receivePeriod); |
|
|
|
standarsTotal = calcuteStandardsFee(unFixedList, billTimeVo.getStartDate(), billTimeVo.getEndDate(), wxPropertyContract); |
|
|
|
} |
|
|
|
|
|
|
|
WxBillProperty wxBillProperty = new WxBillProperty(); |
|
|
|
wxBillProperty.setIsPreview(isPreview); |
|
|
|
wxBillProperty.setId(idWorker.nextId()); |
|
|
|
wxBillProperty.setPropertyContractId(wxPropertyContract.getId()); |
|
|
|
wxBillProperty.setPay("0"); |
|
|
|
wxBillProperty.setStarttime(billTimeVo.getStartDate()); |
|
|
|
wxBillProperty.setEndtime(billTimeVo.getEndDate()); |
|
|
|
wxBillProperty.setReceiveDate(billTimeVo.getReceiveDate()); |
|
|
|
|
|
|
|
wxBillProperty.setNeedPay(needpay); |
|
|
|
//wxBillProperty.setOwe(needpay); |
|
|
|
wxBillProperty.setReceivePay(needpay); |
|
|
|
|
|
|
|
//截止收租日在当前时间之前 |
|
|
|
Date date = new Date(); |
|
|
|
//setExpiredDay(wxBillProperty,dayType,receivePeriod); |
|
|
|
wxBillProperty.updateTenantInfo(wxPropertyContract); |
|
|
|
wxBillProperty.setIsDel(0); |
|
|
|
wxBillProperty.setMerchantId(wxPropertyContract.getMerchantId()); |
|
|
|
wxBillProperty.setUserId(userId); |
|
|
|
//wxBillProperty.setShopId(wxPropertyContract.getShopId()); |
|
|
|
wxBillProperty.setCreatetime(date); |
|
|
|
wxBillProperty.setUpdatetime(date); |
|
|
|
wxBillProperty.setIsDel(EnumDelStatus.NOT_DEL.getCode()); |
|
|
|
wxBillProperty.setRentShopType(wxPropertyContract.getRentShopType()); |
|
|
|
wxBillProperty.setPeriod(++billcount); |
|
|
|
if (shopInfo != null) { |
|
|
|
wxBillProperty.setShopInfo(JSONObject.toJSONString(shopInfo)); |
|
|
|
} |
|
|
|
wxBillProperty.setLatePayRatio(0); |
|
|
|
wxBillProperty.calcuteTotalFee(wxPropertyContract.getDecimalSize()); |
|
|
|
++billcount; |
|
|
|
WxBillProperty wxBillProperty = generateBillProperty(wxPayAccountBill,wxPropertyContract,isPreview,billTimeVo.getStartDate(),billTimeVo.getEndDate(),billTimeVo.getReceiveDate(),needpay,userId,billcount,shopInfo,standarsTotal); |
|
|
|
wxBillProperty.setUnFixedbillFeesStandardsList(unFixedList); |
|
|
|
|
|
|
|
|
|
|
|
//计算手续费 |
|
|
|
BigDecimal servicePay = new BigDecimal(wxBillProperty.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(100), wxPropertyContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); |
|
|
|
wxBillProperty.setServiceChargePay(servicePay.toPlainString()); |
|
|
|
//wxBillProperty.setOwe(new BigDecimal(wxBillProperty.getReceivePay()).add(new BigDecimal(wxBillProperty.getServiceChargePay())).toPlainString()); |
|
|
|
//wxBillProperty.setOwe(new BigDecimal(wxBillProperty.getReceivePay()).toPlainString()); |
|
|
|
resultList.add(wxBillProperty); |
|
|
|
} |
|
|
|
|
|
|
|
if (null != fixedList) { |
|
|
|
for (int i = 0 ; i < fixedList.size(); i ++ ) { |
|
|
|
WxBillFeesStandardsListVo svo = fixedList.get(i); |
|
|
|
++billcount; |
|
|
|
WxBillProperty property = generateBillPropertyByBillStandards(wxPayAccountBill,wxPropertyContract,isPreview,userId,svo,billcount,shopInfo); |
|
|
|
resultList.add(property); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (null != unFixedList) { |
|
|
|
for (int i = 0 ; i < unFixedList.size(); i ++ ) { |
|
|
|
WxBillFeesStandardsListVo svo = unFixedList.get(i); |
|
|
|
++billcount; |
|
|
|
WxBillProperty property = generateBillPropertyByBillStandards(wxPayAccountBill,wxPropertyContract,isPreview,userId,svo,billcount,shopInfo); |
|
|
|
resultList.add(property); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//批量生成预账单 |
|
|
|
if(saveDb && resultList.size() > 0 ) { |
|
|
|
wxBillPropertyMapper.insertBills(resultList); |
|
|
|
@@ -765,6 +769,81 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService |
|
|
|
resultMap.put("billList",resultList); |
|
|
|
return resultMap; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private WxBillProperty generateBillPropertyByBillStandards(WxPayAccountBill wxPayAccountBill,WxPropertyContract wxPropertyContract,Integer isPreview,Long userId,WxBillFeesStandardsListVo svo, |
|
|
|
Integer billcount,Map<String, Object> shopInfo) { |
|
|
|
return generateBillProperty(wxPayAccountBill,wxPropertyContract,isPreview,svo.getStart(),svo.getEnd(),svo.getReceiveDate(),svo.getTotal(),userId,billcount,shopInfo,"0"); |
|
|
|
} |
|
|
|
|
|
|
|
private WxBillProperty generateBillProperty(WxPayAccountBill wxPayAccountBill,WxPropertyContract wxPropertyContract,Integer isPreview,Date start,Date end,Date receiveDate,String needpay, |
|
|
|
Long userId,Integer billcount,Map<String, Object> shopInfo,String standarsTotal) { |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
WxBillProperty wxBillProperty = new WxBillProperty(); |
|
|
|
wxBillProperty.setIsPreview(isPreview); |
|
|
|
wxBillProperty.setId(idWorker.nextId()); |
|
|
|
wxBillProperty.setPropertyContractId(wxPropertyContract.getId()); |
|
|
|
wxBillProperty.setPay("0"); |
|
|
|
wxBillProperty.setStarttime(start); |
|
|
|
wxBillProperty.setEndtime(end); |
|
|
|
wxBillProperty.setReceiveDate(receiveDate); |
|
|
|
|
|
|
|
wxBillProperty.setNeedPay(needpay); |
|
|
|
//wxBillProperty.setOwe(needpay); |
|
|
|
wxBillProperty.setReceivePay(needpay); |
|
|
|
|
|
|
|
//截止收租日在当前时间之前 |
|
|
|
Date date = new Date(); |
|
|
|
//setExpiredDay(wxBillProperty,dayType,receivePeriod); |
|
|
|
wxBillProperty.updateTenantInfo(wxPropertyContract); |
|
|
|
wxBillProperty.setIsDel(0); |
|
|
|
wxBillProperty.setMerchantId(wxPropertyContract.getMerchantId()); |
|
|
|
wxBillProperty.setUserId(userId); |
|
|
|
//wxBillProperty.setShopId(wxPropertyContract.getShopId()); |
|
|
|
wxBillProperty.setCreatetime(date); |
|
|
|
wxBillProperty.setUpdatetime(date); |
|
|
|
wxBillProperty.setIsDel(EnumDelStatus.NOT_DEL.getCode()); |
|
|
|
wxBillProperty.setRentShopType(wxPropertyContract.getRentShopType()); |
|
|
|
wxBillProperty.setPeriod(billcount); |
|
|
|
if (shopInfo != null) { |
|
|
|
wxBillProperty.setShopInfo(JSONObject.toJSONString(shopInfo)); |
|
|
|
} |
|
|
|
wxBillProperty.setLatePayRatio(0); |
|
|
|
wxBillProperty.setTotalFee(new BigDecimal(needpay).add(new BigDecimal(standarsTotal)).toPlainString()); |
|
|
|
|
|
|
|
|
|
|
|
//计算手续费 |
|
|
|
BigDecimal servicePay = new BigDecimal(wxBillProperty.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(100), wxPropertyContract.getDecimalSize(), BigDecimal.ROUND_HALF_UP); |
|
|
|
wxBillProperty.setServiceChargePay(servicePay.toPlainString()); |
|
|
|
//wxBillProperty.setOwe(new BigDecimal(wxBillProperty.getReceivePay()).add(new BigDecimal(wxBillProperty.getServiceChargePay())).toPlainString()); |
|
|
|
//wxBillProperty.setOwe(new BigDecimal(wxBillProperty.getReceivePay()).toPlainString()); |
|
|
|
|
|
|
|
return wxBillProperty; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String calcuteStandardsFee(List<WxBillFeesStandardsListVo> unFixedList,Date start,Date end,WxPropertyContract wxPropertyContract) { |
|
|
|
if (null != unFixedList) { |
|
|
|
BigDecimal total = new BigDecimal(0); |
|
|
|
for (int j = 0 ; j < unFixedList.size(); j ++) { |
|
|
|
WxBillFeesStandardsListVo bfsvo = unFixedList.get(j); |
|
|
|
WxFeesStandards feeStandars = bfsvo.getFeeStandards(); |
|
|
|
if(EnumFeesStandardsCalcuteUnit.MM.getCode().intValue() == feeStandars.getCalcuteUnit().intValue()) { |
|
|
|
bfsvo.setTotal(feeStandars.calcuteTotalMoney(wxPropertyContract.getDecimalSize(), start, end,wxPropertyContract.getRentArea())); |
|
|
|
}else if (EnumFeesStandardsCalcuteUnit.HU.getCode().intValue() == feeStandars.getCalcuteUnit().intValue()) { |
|
|
|
bfsvo.setTotal(feeStandars.calcuteTotalMoney(wxPropertyContract.getDecimalSize(), start, end,"1")); |
|
|
|
}else { |
|
|
|
bfsvo.setTotal(feeStandars.calcuteTotalMoney(wxPropertyContract.getDecimalSize(), start, end,"1")); |
|
|
|
} |
|
|
|
bfsvo.setStart(start); |
|
|
|
bfsvo.setEnd(end); |
|
|
|
bfsvo.setReceiveDate(DateUtils.getDaySet(start,Calendar.DATE,-1)); |
|
|
|
total.add(new BigDecimal(bfsvo.getTotal()));; |
|
|
|
} |
|
|
|
return total.toPlainString(); |
|
|
|
} |
|
|
|
return "0"; |
|
|
|
} |
|
|
|
|
|
|
|
public String getNeedPayMoney(WxPropertyContract wxRentContract,String price,Date startDate,Date endDate,int i,int billTimeVoListSize,boolean saveDb,int dayType,int receivePeriod){ |
|
|
|
String needpay; |
|
|
|
@@ -773,11 +852,12 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService |
|
|
|
BigDecimal priceD = new BigDecimal(price); |
|
|
|
String needpayD = WxRentContractHelper.getNeedPay(wxRentContract.getDecimalSize(),new BigDecimal(0),priceD,startDate,endDate); |
|
|
|
needpay = needpayD; |
|
|
|
//按月计算 |
|
|
|
}else{ |
|
|
|
//年 需要除12 |
|
|
|
BigDecimal priceD = new BigDecimal(price); |
|
|
|
if(EnumPriceUnit.Y.getCode().equals(wxRentContract.getPriceUnit())){ |
|
|
|
priceD = new BigDecimal(price).divide(new BigDecimal(12),wxRentContract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); |
|
|
|
priceD = new BigDecimal(price).divide(new BigDecimal(12),Constant.default_long_decimal_size,BigDecimal.ROUND_HALF_UP); |
|
|
|
} |
|
|
|
|
|
|
|
//生成金额直接计算 |
|
|
|
|