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

[铜锣湾][修改][预账单]

release_toaliyun_real
luozukai 7 лет назад
Родитель
Сommit
49e925cdc4
3 измененных файлов: 167 добавлений и 89 удалений
  1. +13
    -0
      mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java
  2. +151
    -87
      mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java
  3. +3
    -2
      mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml

+ 13
- 0
mallinkService/src/main/java/com/iformall/domain/po/WxPropertyContract.java Просмотреть файл

@@ -166,11 +166,24 @@ public class WxPropertyContract implements Serializable {
@io.swagger.annotations.ApiModelProperty(value = "审批流参数", name = "flowParams")
private Map<String, Object> flowParams;

@io.swagger.annotations.ApiModelProperty(value = "调整比例", name = "adjustRatio")
private String adjustRatio;


// 物业预账单列表
@Transient
@io.swagger.annotations.ApiModelProperty(value = "物业预账单列表", name = "previewBillRentList")
private List<WxBillProperty> previewBillRentList;


public String getAdjustRatio() {
return adjustRatio;
}

public void setAdjustRatio(String adjustRatio) {
this.adjustRatio = adjustRatio;
}

public List<WxBillProperty> getPreviewBillRentList() {
return previewBillRentList;
}


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

@@ -1,5 +1,6 @@
package com.iformall.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode;
@@ -14,16 +15,18 @@ import com.iformall.service.WxFlowRecordService;
import com.iformall.service.WxFlowService;
import com.iformall.service.WxPropertyContractService;
import com.iformall.utils.Constant;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;
@@ -226,7 +229,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
//生成预览账单
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);

message = "保存物业合同信息成功";
@@ -270,7 +273,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
wxPropertyContract.setDeposit(record.getDeposit());
wxPropertyContract.setReceivePeriod(record.getReceivePeriod());
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);
}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
@@ -402,7 +540,7 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
* @return
*/
@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<>();

WxPropertyContract wxPropertyContract;
@@ -419,92 +557,18 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
}

if (wxPropertyContract != null) {
int dayType = wxPropertyContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH;
int receivePeriod = wxPropertyContract.getReceivePeriod().intValue();
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++) {


+ 3
- 2
mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml Просмотреть файл

@@ -35,6 +35,7 @@
<result column="apply_status" property="applyStatus"/>
<result column="adjust_period" jdbcType="INTEGER" property="adjustPeriod"/>
<result column="business_type" property="businessType"/>
<result column="adjust_ratio" property="adjustRatio"/>

</resultMap>
@@ -44,7 +45,7 @@
`deposit`,`pay_date`,`is_del`,`merchant_name`,`brand`,`business_id`,
`shop_type`,`shop_id`,`updatetime`,`createtime`,`rent_area`,
`link_person`,`link_phone`,`pay_account`,`filename`,`lease`,`rent_contract_id`,
`start_date`,`end_date`,`apply_status`,`adjust_period`,`business_type`
`start_date`,`end_date`,`apply_status`,`adjust_period`,`business_type`,adjust_ratio
</sql>
<sql id="dynamicWhereConditions">
@@ -103,7 +104,7 @@
f.floor_name floorName,b.building_name buildingName,receive_period receivePeriod,
rc.lease,rc.filepath,rc.filename,rc.pay_account payAccount,rc.sign_date signDate,
start_date startDate,end_date endDate,rc.rent_contract_id rentContractId,br.`name` brandName,
s.addr,rc.apply_status applyStatus,rc.adjust_period adjustPeriod,rc.business_type businessType
s.addr,rc.apply_status applyStatus,rc.adjust_period adjustPeriod,rc.business_type businessType,rc.adjust_ratio adjustRatio
from wx_property_contract rc
left join wx_shop s on rc.shop_id=s.id
left join wx_mall_floor f on s.floor=f.id


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