@@ -1,5 +1,6 @@
package com.iformall.service.impl;
package com.iformall.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode;
import com.iformall.common.ErrorCode;
@@ -14,16 +15,18 @@ import com.iformall.service.WxFlowRecordService;
import com.iformall.service.WxFlowService;
import com.iformall.service.WxFlowService;
import com.iformall.service.WxPropertyContractService;
import com.iformall.service.WxPropertyContractService;
import com.iformall.utils.Constant;
import com.iformall.utils.Constant;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.HttpURLConnection;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URL;
import java.util.*;
import java.util.*;
@@ -226,7 +229,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
//生成预览账单
//生成预览账单
wxBillPropertyMapper.deletePreviewBill(record);
wxBillPropertyMapper.deletePreviewBill(record);
//重新生成
//重新生成
List<WxBillProperty> billList = buildProperty(new WxMerchant(),record,EnumIsPreview.YES.getCode());
List<WxBillProperty> billList = buildProperty(new WxMerchant(),userId, record,EnumIsPreview.YES.getCode());
propertyContract.setPreviewBillRentList(billList);
propertyContract.setPreviewBillRentList(billList);
message = "保存物业合同信息成功";
message = "保存物业合同信息成功";
@@ -270,7 +273,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
wxPropertyContract.setDeposit(record.getDeposit());
wxPropertyContract.setDeposit(record.getDeposit());
wxPropertyContract.setReceivePeriod(record.getReceivePeriod());
wxPropertyContract.setReceivePeriod(record.getReceivePeriod());
wxPropertyContract.setPayAccount(record.getPayAccount());
wxPropertyContract.setPayAccount(record.getPayAccount());
List<WxBillProperty> billList = buildProperty(new WxMerchant(),wxPropertyContract,EnumIsPreview.YES.getCode());
List<WxBillProperty> billList = buildProperty(new WxMerchant(),userId, wxPropertyContract,EnumIsPreview.YES.getCode());
record.setPreviewBillRentList(billList);
record.setPreviewBillRentList(billList);
}else{
}else{
//查询预账单用于展示
//查询预账单用于展示
@@ -395,6 +398,141 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
}
}
}
}
public List<WxBillProperty> buildRentMonth(WxMerchant wxMerchant, Long userId, WxPropertyContract wxPropertyContract, int receivePeriod, Integer lease, Date rentalStartDate, Integer price,Integer isPreview) {
String adjustRatio = wxPropertyContract.getAdjustRatio();
List<Integer> integers = JSONArray.parseArray(adjustRatio, Integer.class);
integers.add(0, 0);
int size = integers.size();
int[] priceArr = new int[size];
priceArr[0] = price;
double priceD = price;
for (int i = 1; i < size; i++) {
priceD = priceD + priceD * integers.get(i) / 10000.0;
priceArr[i] = new BigDecimal(priceD).setScale(0, RoundingMode.HALF_EVEN).intValue();
}
int month = 12;
int divide = lease / month;
int mod = lease % month;
int[] leaseArr = new int[size];
for (int i = 0; i < divide; i++) {
leaseArr[i] = month;
}
if (mod > 0) {
leaseArr[divide] = mod;
}
int billcount = 0;
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);
List<WxBillProperty> billRentList = (List<WxBillProperty>)resultMap.get("billList");
billcount = (Integer)resultMap.get("billcount");
resultList.addAll(billRentList);
}
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> resultMap = new HashedMap();
List<WxBillProperty> resultList = new ArrayList<>();
int extralease = lease % receivePeriod;
int extracount = extralease > 0 ? 1 : 0;
int paycount = lease / receivePeriod + extracount;
int index = paycount - 1;
final IdWorker idWorker = IdWorker.get();
for (int i = 0; i < paycount; i++) {
WxBillProperty wxBillRent = new WxBillProperty();
wxBillRent.setIsPreview(isPreview);
wxBillRent.setId(idWorker.nextId());
wxBillRent.setPropertyContractId(wxPropertyContract.getId());
wxBillRent.setPay(0);
int needpay = price * receivePeriod;
Date date = new Date();
Calendar instance = Calendar.getInstance();
instance.setTime(startdate);
instance.add(dayType, receivePeriod * i);
instance.add(Calendar.DAY_OF_MONTH, -1);
Date time = instance.getTime();
wxBillRent.setReceiveDate(time);
//账单开始时间
instance.clear();
instance.setTime(wxBillRent.getReceiveDate());
instance.add(Calendar.DAY_OF_MONTH, 1);
wxBillRent.setStarttime(instance.getTime());
//账单结束时间
instance.clear();
instance.setTime(wxBillRent.getStarttime());
instance.add(dayType, receivePeriod);
instance.add(Calendar.DAY_OF_MONTH, -1);
wxBillRent.setEndtime(instance.getTime());
if (extracount > 0 && i == index) {
//账单开始时间
instance.clear();
instance.setTime(wxBillRent.getReceiveDate());
instance.add(Calendar.DAY_OF_MONTH, 1);
wxBillRent.setStarttime(instance.getTime());
//账单结束时间
instance.clear();
instance.setTime(wxBillRent.getStarttime());
instance.add(dayType, extralease);
instance.add(Calendar.DAY_OF_MONTH, -1);
wxBillRent.setEndtime(instance.getTime());
needpay = price * extralease;
}
wxBillRent.setNeedPay(needpay);
wxBillRent.setOwe(needpay);
wxBillRent.setReceivePay(needpay);
//截止收租日在当前时间之前
if (wxBillRent.getReceiveDate().before(date)) {
long day = (time.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
wxBillRent.setStatus(EnumBillRentStatus.NOT_PAID.getCode());
wxBillRent.setExpiredDay(day);
} else {//截止收租日在当前时间之后
Calendar now = Calendar.getInstance();
now.add(dayType, receivePeriod);
Date currenttime = now.getTime();
//当前日期加上周期后小于截止收租日就是没有到期,否则当前待缴
if (currenttime.before(wxBillRent.getReceiveDate())) {
wxBillRent.setStatus(EnumBillRentStatus.NOT_EXPIRED.getCode());
wxBillRent.setExpiredDay(0L);
} else {
wxBillRent.setStatus(EnumBillRentStatus.WAIT_PAY.getCode());
wxBillRent.setExpiredDay(0L);
}
}
wxBillRent.setTenantId(wxMerchant.getTenantId());
wxBillRent.setIsDel(0);
wxBillRent.setMerchantId(wxMerchant.getId());
wxBillRent.setUserId(userId);
wxBillRent.setShopId(wxPropertyContract.getShopId());
wxBillRent.setCreatetime(date);
wxBillRent.setUpdatetime(date);
wxBillRent.setIsDel(EnumDelStatus.NOT_DEL.getCode());
wxBillRent.setRentShopType(wxPropertyContract.getRentShopType());
wxBillRent.setPeriod(++billcount);
try {
wxBillPropertyMapper.insertSelective(wxBillRent);
resultList.add(wxBillRent);
} catch (Exception e) {
logger.error("添加租赁账单失败,e:" + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());
}
}
resultMap.put("billcount",billcount);
resultMap.put("billList",resultList);
return resultMap;
}
/**
/**
* 根据商户/指定物业合同生成物业账单
* 根据商户/指定物业合同生成物业账单
* @param wxMerchant
* @param wxMerchant
@@ -402,7 +540,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
* @return
* @return
*/
*/
@Transactional(rollbackFor = {Exception.class})
@Transactional(rollbackFor = {Exception.class})
public List<WxBillProperty> buildProperty(WxMerchant wxMerchant,WxPropertyContract propertyContract,Integer isPreview) {
public List<WxBillProperty> buildProperty(WxMerchant wxMerchant,Long userId, WxPropertyContract propertyContract,Integer isPreview) {
List<WxBillProperty> result = new ArrayList<>();
List<WxBillProperty> result = new ArrayList<>();
WxPropertyContract wxPropertyContract;
WxPropertyContract wxPropertyContract;
@@ -419,92 +557,18 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
}
}
if (wxPropertyContract != null) {
if (wxPropertyContract != null) {
int dayType = wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH;
int receivePeriod = wxPropertyContract.getReceivePeriod().intValue();
int receivePeriod = wxPropertyContract.getReceivePeriod().intValue();
Integer lease = wxPropertyContract.getLease();
Integer lease = wxPropertyContract.getLease();
int extralease = lease % receivePeriod;
int extracount = extralease > 0 ? 1 : 0;
int paycount = lease / receivePeriod + extracount;
int index = paycount - 1;
final IdWorker idWorker = IdWorker.get();
for (int i = 0; i < paycount; i++) {
WxBillProperty wxBillProperty = new WxBillProperty();
wxBillProperty.setIsPreview(isPreview);
wxBillProperty.setId(idWorker.nextId());
wxBillProperty.setPropertyContractId(wxPropertyContract.getId());
wxBillProperty.setPay(0);
Date date = new Date();
Calendar instance = Calendar.getInstance();
instance.setTime(wxPropertyContract.getRentalStartDate());
instance.add(dayType, receivePeriod * i);
instance.add(Calendar.DAY_OF_MONTH, -1);
Date time = instance.getTime();
wxBillProperty.setReceiveDate(time);
Date rentalStartDate = propertyContract.getRentalStartDate();
Integer price = propertyContract.getPrice();
//账单开始时间
instance.clear();
instance.setTime(wxBillProperty.getReceiveDate());
instance.add(Calendar.DAY_OF_MONTH, 1);
wxBillProperty.setStarttime(instance.getTime());
//账单结束时间
instance.clear();
instance.setTime(wxBillProperty.getStarttime());
instance.add(dayType, receivePeriod);
instance.add(Calendar.DAY_OF_MONTH, -1);
wxBillProperty.setEndtime(instance.getTime());
int needpay = wxPropertyContract.getPrice() * receivePeriod;
if (extracount > 0 && i == index) {
//账单开始时间
instance.clear();
instance.setTime(wxBillProperty.getReceiveDate());
instance.add(Calendar.DAY_OF_MONTH, 1);
wxBillProperty.setStarttime(instance.getTime());
//账单结束时间
instance.clear();
instance.setTime(wxBillProperty.getStarttime());
instance.add(dayType, extralease);
instance.add(Calendar.DAY_OF_MONTH, -1);
wxBillProperty.setEndtime(instance.getTime());
needpay = wxPropertyContract.getPrice() * extralease;
}
wxBillProperty.setNeedPay(needpay);
wxBillProperty.setOwe(needpay);
wxBillProperty.setReceivePay(needpay);
//截止收租日在当前时间之前
if (wxBillProperty.getReceiveDate().before(date)) {
long day = (time.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
wxBillProperty.setStatus(EnumBillRentStatus.NOT_PAID.getCode());
wxBillProperty.setExpiredDay(day);
} else {//截止收租日在当前时间之后
Calendar now = Calendar.getInstance();
now.add(dayType, receivePeriod);
Date currenttime = now.getTime();
//当前日期加上周期后小于截止收租日就是没有到期,否则当前待缴
if (currenttime.before(wxBillProperty.getReceiveDate())) {
wxBillProperty.setStatus(EnumBillRentStatus.NOT_EXPIRED.getCode());
wxBillProperty.setExpiredDay(0L);
} else {
wxBillProperty.setStatus(EnumBillRentStatus.WAIT_PAY.getCode());
wxBillProperty.setExpiredDay(0L);
}
}
wxBillProperty.setTenantId(wxMerchant.getTenantId());
wxBillProperty.setIsDel(0);
wxBillProperty.setMerchantId(wxMerchant.getId());
wxBillProperty.setShopId(wxPropertyContract.getShopId());
wxBillProperty.setCreatetime(date);
wxBillProperty.setUpdatetime(date);
wxBillProperty.setIsDel(EnumDelStatus.NOT_DEL.getCode());
wxBillProperty.setPeriod(i + 1);
try {
wxBillPropertyMapper.insertSelective(wxBillProperty);
result.add(wxBillProperty);
} catch (Exception e) {
logger.error("添加物业账单失败,e:" + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());
}
//按月计租
if (propertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_MONTH.getCode())) {
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);
result = (List<WxBillProperty>)resultMap.get("billList");
}
}
}
}
for (int i = 0; i < result.size(); i++) {
for (int i = 0; i < result.size(); i++) {