@@ -1,6 +1,7 @@
package com.iformall.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode;
@@ -390,6 +391,16 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
wxBillDeposit.setUpdatetime(date);
wxBillDeposit.setIsDel(EnumDelStatus.NOT_DEL.getCode());
wxBillDeposit.setRentShopType(wxPropertyContract.getRentShopType());
String rentInfo = wxPropertyContract.getRentInfo();
Map<String, Object> shopInfo = new HashMap<>();
if (rentInfo != null) {
JSONArray rentInfoArray = JSONArray.parseArray(rentInfo);
for (int i = 0, size = rentInfoArray.size(); i < size; i++) {
JSONObject rentInfoObject = rentInfoArray.getJSONObject(i);
shopInfo.put(rentInfoObject.getString("shopNumber"), rentInfoObject.get("buildArea"));
}
}
wxBillDeposit.setShopInfo(JSONObject.toJSONString(shopInfo));
try {
wxBillPropertyDepositMapper.insertSelective(wxBillDeposit);
} catch (Exception e) {
@@ -401,6 +412,15 @@ 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();
String rentInfo = wxPropertyContract.getRentInfo();
Map<String, Object> shopInfo = new HashMap<>();
if (rentInfo != null) {
JSONArray rentInfoArray = JSONArray.parseArray(rentInfo);
for (int i = 0, size = rentInfoArray.size(); i < size; i++) {
JSONObject rentInfoObject = rentInfoArray.getJSONObject(i);
shopInfo.put(rentInfoObject.getString("shopNumber"), rentInfoObject.get("buildArea"));
}
}
List<Integer> integers = JSONArray.parseArray(adjustRatio, Integer.class);
integers.add(0, 0);
int size = integers.size();
@@ -429,7 +449,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
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);
Map<String, Object> resultMap = buildRent(leaseArr[i], receivePeriod, priceArr[i], instance.getTime(), Calendar.MONTH, wxPropertyContract, userId, wxMerchant, billcount, isPreview, shopInfo );
List<WxBillProperty> billRentList = (List<WxBillProperty>)resultMap.get("billList");
billcount = (Integer)resultMap.get("billcount");
resultList.addAll(billRentList);
@@ -437,7 +457,7 @@ 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) {
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 ) {
Map<String,Object> resultMap = new HashedMap();
List<WxBillProperty> resultList = new ArrayList<>();
int extralease = lease % receivePeriod;
@@ -446,12 +466,12 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
int index = paycount - 1;
final IdWorker idWorker = IdWorker.get();
for (int i = 0; i < paycount; i++) {
WxBillProperty wxBillRent = new WxBillProperty();
wxBillRent .setIsPreview(isPreview);
WxBillProperty wxBillProperty = new WxBillProperty();
wxBillProperty .setIsPreview(isPreview);
wxBillRent .setId(idWorker.nextId());
wxBillRent .setPropertyContractId(wxPropertyContract.getId());
wxBillRent .setPay(0);
wxBillProperty .setId(idWorker.nextId());
wxBillProperty .setPropertyContractId(wxPropertyContract.getId());
wxBillProperty .setPay(0);
int needpay = price * receivePeriod;
Date date = new Date();
@@ -460,70 +480,73 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
instance.add(dayType, receivePeriod * i);
instance.add(Calendar.DAY_OF_MONTH, -1);
Date time = instance.getTime();
wxBillRent .setReceiveDate(time);
wxBillProperty .setReceiveDate(time);
//账单开始时间
instance.clear();
instance.setTime(wxBillRent .getReceiveDate());
instance.setTime(wxBillProperty .getReceiveDate());
instance.add(Calendar.DAY_OF_MONTH, 1);
wxBillRent .setStarttime(instance.getTime());
wxBillProperty .setStarttime(instance.getTime());
//账单结束时间
instance.clear();
instance.setTime(wxBillRent .getStarttime());
instance.setTime(wxBillProperty .getStarttime());
instance.add(dayType, receivePeriod);
instance.add(Calendar.DAY_OF_MONTH, -1);
wxBillRent .setEndtime(instance.getTime());
wxBillProperty .setEndtime(instance.getTime());
if (extracount > 0 && i == index) {
//账单开始时间
instance.clear();
instance.setTime(wxBillRent .getReceiveDate());
instance.setTime(wxBillProperty .getReceiveDate());
instance.add(Calendar.DAY_OF_MONTH, 1);
wxBillRent .setStarttime(instance.getTime());
wxBillProperty .setStarttime(instance.getTime());
//账单结束时间
instance.clear();
instance.setTime(wxBillRent .getStarttime());
instance.setTime(wxBillProperty .getStarttime());
instance.add(dayType, extralease);
instance.add(Calendar.DAY_OF_MONTH, -1);
wxBillRent .setEndtime(instance.getTime());
wxBillProperty .setEndtime(instance.getTime());
needpay = price * extralease;
}
wxBillRent .setNeedPay(needpay);
wxBillRent .setOwe(needpay);
wxBillRent .setReceivePay(needpay);
wxBillProperty .setNeedPay(needpay);
wxBillProperty .setOwe(needpay);
wxBillProperty .setReceivePay(needpay);
//截止收租日在当前时间之前
if (wxBillRent .getReceiveDate().before(date)) {
if (wxBillProperty .getReceiveDate().before(date)) {
long day = (time.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
wxBillRent .setStatus(EnumBillRentStatus.NOT_PAID.getCode());
wxBillRent .setExpiredDay(day);
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(wxBillRent .getReceiveDate())) {
wxBillRent .setStatus(EnumBillRentStatus.NOT_EXPIRED.getCode());
wxBillRent .setExpiredDay(0L);
if (currenttime.before(wxBillProperty .getReceiveDate())) {
wxBillProperty .setStatus(EnumBillRentStatus.NOT_EXPIRED.getCode());
wxBillProperty .setExpiredDay(0L);
} else {
wxBillRent .setStatus(EnumBillRentStatus.WAIT_PAY.getCode());
wxBillRent .setExpiredDay(0L);
wxBillProperty .setStatus(EnumBillRentStatus.WAIT_PAY.getCode());
wxBillProperty .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);
wxBillProperty.setTenantId(wxMerchant.getTenantId());
wxBillProperty.setIsDel(0);
wxBillProperty.setMerchantId(wxMerchant.getId());
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));
}
try {
wxBillPropertyMapper.insertSelective(wxBillRent);
resultList.add(wxBillRent);
wxBillPropertyMapper.insertSelective(wxBillProperty );
resultList.add(wxBillProperty );
} catch (Exception e) {
logger.error("添加租赁账单失败,e:" + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());
@@ -568,7 +591,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);
Map<String, Object> resultMap = buildRent(lease, receivePeriod, price, rentalStartDate, Calendar.DAY_OF_MONTH, propertyContract, userId, wxMerchant, 0, isPreview, null );
result = (List<WxBillProperty>)resultMap.get("billList");
}
}