winter 1 год назад
Родитель
Сommit
fb5b8075a6
3 измененных файлов: 490 добавлений и 478 удалений
  1. +10
    -1
      mallinkAdmin/src/main/java/com/iformall/controller/rent/WxAllBillController.java
  2. +2
    -0
      mallinkService/src/main/java/com/iformall/domain/po/WxShop.java
  3. +478
    -477
      mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java

+ 10
- 1
mallinkAdmin/src/main/java/com/iformall/controller/rent/WxAllBillController.java Просмотреть файл

@@ -457,7 +457,16 @@ public class WxAllBillController extends BillBaseController {
wxShop.setOweBillBeforeDays(getOweBillBeforeDays());
}
wxShop.setNearBillBeforeDays(nearBillBeforeDays);
if (StringUtils.isNotBlank(wxShop.getEnergyFeesIds())){
String[] efs = wxShop.getEnergyFeesIds().split(",");
if (null != efs && efs.length > 0 ) {
List<Long> feesIds = new ArrayList<Long>();
for (int i = 0 ; i < efs.length; i++ ) {
feesIds.add(Long.parseLong(efs[i]));
}
wxShop.setEnergyFeesIdList(feesIds);
}
}
return billAllHelper.getBillList(wxShop,pageNum,pageSize);
}


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

@@ -246,4 +246,6 @@ public class WxShop extends TenantEntity {
private String queryShopIdStr;
@TableField(exist = false)
private Long templateId;
@TableField(exist = false)
private String energyFeesIds;
}

+ 478
- 477
mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java Просмотреть файл

@@ -1,477 +1,478 @@
package com.iformall.service.helper;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageInfo;
import com.iformall.common.SysConfigConstant;
import com.iformall.domain.dto.WxBillPayDTO;
import com.iformall.domain.dto.WxBillReceiveUpdateDTO;
import com.iformall.domain.po.MallUserInfo;
import com.iformall.domain.po.SysConfig;
import com.iformall.domain.po.WxBillAction;
import com.iformall.domain.po.WxAllBill;
import com.iformall.domain.po.WxMerchant;
import com.iformall.domain.po.WxMerchantBUser;
import com.iformall.domain.po.WxPropertyContract;
import com.iformall.domain.po.WxRentContract;
import com.iformall.domain.po.WxShop;
import com.iformall.domain.po.WxShopUsers;
import com.iformall.domain.po.WxShopUsersInfo;
import com.iformall.domain.po.base.TenantEntity;
import com.iformall.domain.vo.WxBillHotNotify;
import com.iformall.domain.vo.WxBillNotify;
import com.iformall.domain.vo.WxBillSum;
import com.iformall.domain.vo.WxShopVo;
import com.iformall.enums.EnumBillAction;
import com.iformall.enums.EnumBillAllType;
import com.iformall.enums.EnumBillDailyType;
import com.iformall.enums.EnumBillOweOrNearType;
import com.iformall.enums.EnumBillStatus;
import com.iformall.enums.EnumBillType;
import com.iformall.enums.EnumRentContractManageFeeType;
import com.iformall.enums.EnumShopUsersStatus;
import com.iformall.enums.EnumSystemUserType;
import com.iformall.enums.EnumYesOrNo;
import com.iformall.service.WxAllBillService;
import com.iformall.service.WxBillActionService;
import com.iformall.service.WxMallService;
import com.iformall.service.WxMerchantService;
import com.iformall.service.WxShopService;
import com.iformall.utils.Constant;
import com.iformall.utils.DateUtils;
import com.iformall.utils.PriceUtil;
import com.iformall.utils.WordUtil;
@Service
public class WxBillAllHelper {
@Autowired
private String fmUploadDir;
@Autowired
private WxAllBillService wxAllBillService;
@Autowired
private WxShopService wxShopService;
@Autowired
private WxMerchantService wxMerchantService;
@Autowired
private WxMallService wxMallService;
public Date getDateBefore(Integer afterDays) {
Date nowBegin = DateUtils.getDayBegin(new Date());
//return DateUtils.getDateTimeBefore(afterDays*3600*24, nowBegin);
return DateUtils.getSecondsTimeAfter(afterDays*3600*24, nowBegin);
}
private void updateQueryParm(WxShop wxShop,WxAllBill bill,Date starttime,Date enttime) {
bill.updateTenantInfo(wxShop);
bill.setShopId(wxShop.getId());
bill.setShopIdList(wxShop.getIds());
bill.setFloorForRule(wxShop.getFloorForRule());
bill.setBusinessForRule(wxShop.getBusinessForRule());
bill.setShopTypeForRule(wxShop.getShopTypeForRule());
bill.setBuilding(wxShop.getBuilding());
bill.setFloor(wxShop.getFloor());
bill.setStarttime(starttime);
bill.setEndtime(enttime);
//bill.setRentShopType(wxMerchant.getType());
if (null != wxShop.getOweBillBeforeDays()) {
bill.setOweBillLastTime(getDateBefore(wxShop.getOweBillBeforeDays()));
}
if (null != wxShop.getNearBillBeforeDays()) {
bill.setNearBillLastTime(getDateBefore(wxShop.getNearBillBeforeDays()));
}
if (null != wxShop.getNeedPayPreDays()) {
bill.setNeedPayStartDay(getDateBefore(wxShop.getNeedPayPreDays()));
}
bill.setToPayMerchant(wxShop.getToPayMerchant());
bill.setIsPreview(wxShop.getIsPreview());
bill.setNeedPayNoDays(wxShop.getNeedPayNoDays());
bill.setEnergyFeesIds(wxShop.getEnergyFeesIdList());
bill.setAdvanceHasMoney(wxShop.getAdvanceHasMoney());
bill.setReceiveDate(wxShop.getReceiveDate());
bill.setCusName(wxShop.getCusName()); }
public WxBillSum getBillSum(WxShop wxShop,Date starttime, Date enttime) {
WxAllBill br = new WxAllBill();
updateQueryParm(wxShop, br,starttime,enttime);
WxBillSum rentSum = wxAllBillService.getBillMonthSum(br);
if (null == rentSum) {
rentSum = new WxBillSum();
}
return rentSum;
}
public List<WxBillSum> getFeesBillSum(WxShop wxShop,Date starttime, Date enttime) {
WxAllBill br = new WxAllBill();
updateQueryParm(wxShop, br,starttime,enttime);
return wxAllBillService.getFeesBillSum(br);
}
public List<WxBillHotNotify> getBillHotNotify(WxShop wxShop,Date starttime, Date enttime) {
WxAllBill br = new WxAllBill();
updateQueryParm(wxShop, br,starttime,enttime);
br.setIsPreview(EnumYesOrNo.NO.getCode());
return wxAllBillService.getBillHotNotify(br);
}
public String calcuteSum(String... money) {
if (null != money) {
BigDecimal total = new BigDecimal(0);
for (int i = 0 ; i < money.length ; i++) {
String _m = money[i];
if (StringUtils.isBlank(_m)) {
_m = "0";
}
total = total.add(new BigDecimal(_m));
}
//return total.setScale(2,RoundingMode.HALF_UP).toPlainString();
return total.toPlainString();
}
return "0";
}
private Date getMinDate(Date... date) {
if (null != date && date.length > 0 ) {
Date minDate = null;
for (int i =0 ; i < date.length; i ++) {
Date ndate = date[i];
if (null != ndate) {
if (null == minDate) {
minDate = ndate;
}else {
if (minDate.after(ndate)) {
minDate = ndate;
}
}
}
}
return minDate;
}
return null;
}
private Date getMaxDate(Date... date) {
if (null != date && date.length > 0 ) {
Date maxDate = null;
for (int i =0 ; i < date.length; i ++) {
Date ndate = date[i];
if (null != ndate) {
if (null == maxDate) {
maxDate = ndate;
}else {
if (maxDate.before(ndate)) {
maxDate = ndate;
}
}
}
}
return maxDate;
}
return null;
}
public List<Long> getOwdShopIds(WxShop wxShop,Date starttime, Date enttime) {
WxAllBill br = new WxAllBill();
updateQueryParm(wxShop, br,starttime,enttime);
return wxAllBillService.getShopIds(br);
}
public WxAllBill generateRentContractQueryBill(TenantEntity tenantEntity,Long rentContractId,Date starttime, Date endtime) {
WxAllBill bq = new WxAllBill();
bq.updateTenantInfo(tenantEntity);
bq.setRentContractId(rentContractId);
bq.setIsPreview(EnumYesOrNo.NO.getCode());
bq.setBillType(EnumBillAllType.RENT.getCode());
bq.setEnergyFeesId(EnumBillAllType.RENT.getEnergyFeesId());
bq.setNoExtraCreateFrom(EnumYesOrNo.YES.getCode());
bq.setStarttimeEqual(starttime);
bq.setEndtimeEqual(endtime);
return bq;
}
private List<Long> getUnionIds(List<Long>...lists ) {
if (null != lists && lists.length > 0 ) {
List<Long> retList = new ArrayList<Long>();
for (int i = 0 ; i < lists.length; i++) {
List<Long> list = lists[i];
if (null != list) {
retList.removeAll(list);
retList.addAll(list);
}
}
return retList;
}
return null;
}
public PageInfo<WxAllBill> getBillList(WxShop wxShop,Integer pageNum, Integer pageSize) {
WxAllBill wxAllBill = new WxAllBill();
updateQueryParm(wxShop, wxAllBill,wxShop.getStarttime(),wxShop.getEndtime());
wxAllBill.setIsPreview(EnumYesOrNo.NO.getCode());
wxAllBill.setSortColumns("starttime asc");
return wxAllBillService.listAsPage(wxAllBill, pageNum, pageSize);
}
public List<WxAllBill> getMerchantBillList(WxShop wxShop) {
WxAllBill wxBillRent = new WxAllBill();
updateQueryParm(wxShop, wxBillRent,wxShop.getStarttime(),wxShop.getEndtime());
wxBillRent.setSortColumns("starttime asc");
return wxAllBillService.list(wxBillRent);
}
public WxAllBill getOneBill(TenantEntity tenantEntity,Long id) {
return wxAllBillService.getById(tenantEntity, id);
}
public List<WxBillNotify> getBillNotifyList(WxShop wxShop,Integer notifyed) {
WxAllBill wxBillRent = new WxAllBill();
updateQueryParm(wxShop, wxBillRent,wxShop.getStarttime(),wxShop.getEndtime());
wxBillRent.setNotifyed(notifyed);
wxBillRent.setSortColumns("starttime asc");
List<WxBillNotify> retList = wxAllBillService.notifyList(wxBillRent);
if (null != retList && retList.size() > 0 ) {
List<Long> shopIdList = new ArrayList<Long>();
for (int i = 0 ; i < retList.size(); i ++) {
WxBillNotify wbn = retList.get(i);
if (null != wbn.getShopId()) {
if (!shopIdList.contains(wbn.getShopId())) {
shopIdList.add(wbn.getShopId());
}
}
}
if (shopIdList.size() > 0) {
WxShopUsers suq = new WxShopUsers();
suq.updateTenantInfo(wxShop);
suq.setStatus(EnumShopUsersStatus.LIVE.getCode());
suq.setShopIds(shopIdList);
Map<Long, WxShopUsers> shopUserMap = wxShopService.getShopUserMap(suq);
if (null != shopUserMap) {
for (int i = 0 ; i < retList.size() ; i++) {
WxBillNotify bn = retList.get(i);
if (null != bn.getShopId()) {
WxShopUsers s = shopUserMap.get(bn.getShopId());
if (null != s) {
bn.setShopUserName(s.getName());
bn.setShopUserPerson(s.getLinkPerson());
bn.setShopUserPhone(s.getPhone());
}
}
}
}
}
}
return retList;
}
public void exportOneBillOweWord(boolean isOwe,WxAllBill bill,HttpServletRequest request, HttpServletResponse response) {
String templatePath = "contract-word-template/bill_owe_one.docx";
if (!isOwe) {
templatePath = "contract-word-template/bill_near_one.docx";
}
String filepath = fmUploadDir;
String filename = UUID.randomUUID() + ".docx";
String exportFileName = "催缴单";
Map<String, Object> result = new HashMap<>();
result.put("starttime", DateUtils.date2String(bill.getStarttime(),DateUtils.DATE_PATTERN));
result.put("endtime", DateUtils.date2String(bill.getEndtime(),DateUtils.DATE_PATTERN));
if (null != bill.getShopId()) {
WxShop shop = wxShopService.getById(bill.getShopId());
if (null != shop) {
result.put("shopNumber", shop.getShopNumber());
}
WxShopUsers su = wxShopService.getCurrentShopUser(bill, bill.getShopId());
if (null != su) {
result.put("merchantName", su.getName());
result.put("linkPerson", su.getLinkPerson());
result.put("linkPhone", su.getPhone());
exportFileName = exportFileName+"_"+su.getName();
}
}
result.put("billTypeName", bill.getBillTypeName());
exportFileName = exportFileName +"_"+ bill.getBillTypeName();
result.put("billRemark", bill.getBillRemark());
result.put("receivePay", bill.getReceivePay());
result.put("pay", bill.getPay());
result.put("owe", bill.getOwe());
result.put("number", "JF" + DateUtils.getSystemTime("yyyyMMddHHmmss"));
result.put("summaryUpper", PriceUtil.number2CNMontrayUnit(new BigDecimal(bill.getOwe()).setScale(2,RoundingMode.HALF_UP)));
result.put("mall", wxMallService.getByTenantInfo(bill).getName());
result.put("createtime", DateUtils.date2String(new Date()));
exportFileName = exportFileName +".docx";
WordUtil.exportWord(templatePath, filepath, filename, exportFileName, result, request, response, null);
}
public List<WxBillHotNotify> getHotNotify(WxShop wxShop) {
return this.getBillHotNotify( wxShop, wxShop.getStarttime(), wxShop.getEndtime());
}
public void updateReceivePay(WxBillReceiveUpdateDTO dto,MallUserInfo user,boolean forcePaid) {
wxAllBillService.updateReceivePay(dto, user, forcePaid);
}
public void notify(WxBillPayDTO dto,MallUserInfo user) {
//TODO 发短信通知
wxAllBillService.notify(dto, user);
}
public void backPay(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.backPay(dto, user);
}
public void backSetOff(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.backSetOff(dto, user);
}
public void backCut(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.backCut(dto, user);
}
public void toMechantBackPay(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.toMechantBackPay(dto, user);
}
public void updatePay(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.updatePay(dto, user);
}
public void updateCut(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.updateCut(dto, user);
}
public void updatePayByMerchant(WxBillPayDTO dto,WxMerchantBUser user,boolean isOnline) {
wxAllBillService.updatePayByMerchant(dto, user,isOnline);
}
public WxAllBill getBillDetail(TenantEntity tenantEntity,Long billId) {
return wxAllBillService.getById(tenantEntity,billId);
}
public void updatePayToMerchant(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.updatePayToMerchant(dto, user);
}
public void bad(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.bad(dto, user);
}
public void completeBill(EnumBillStatus status,WxShop wxShop,MallUserInfo user) {
wxAllBillService.completeBill(status,wxShop, user);
}
/**
* 退租:
* 账单开始时间>= 今天,并且账单是 WAIT_PAY,NOT_PAID,NOT_EXPIRED,BAD 变为INVALID,如果已付了款,需要退回
* 账单开始时间<今天 & 账单结束时间 > 今天:
* 账单 WAIT_PAY,NOT_PAID,NOT_EXPIRED,BAD 的,需要计算截止到今天账单总金额是多少钱,更新实际应收金额,并记录日志
* 账单 PAID, 需要计算截止到今天账单总金额是多少钱,更新实际应收金额,并记录日志
* 账单开始时间<今天 & 账单结束时间 <= 今天:
* 那是之前的账单,不处理。
* @param merchant
*/
public boolean billEndCalcute(Integer decimalSize,Date endTime,WxAllBill bill,WxBillAction action) {
String endTimeStr = DateUtils.date2String(endTime,DateUtils.DATE_TIME_PATTERN);
boolean isUpdate = false;
action.setBillId(bill.getId());
action.setBillType(bill.getBillType());
String oldReceivePay = bill.getReceivePay();
boolean isAllReturn = false;
if (EnumBillAllType.getEnum(bill.getBillType()).isDeposit()) {
isAllReturn = true;
}
//如果账单的开始时间在结束时间之后,已经支付了的要退回。
if (!bill.getStarttime().before(endTime)) {
bill.setReceivePay("0");
bill.setBillRemark(StringUtils.trimToEmpty(bill.getBillRemark())+";终止计费,终止日期["+endTimeStr+"],");
action.setOldMoney(oldReceivePay);
action.setNewMoney("0");
action.setAction(EnumBillAction.UPDATE_BILL.getCode());
action.setDetails(EnumBillAction.UPDATE_BILL.getDescription(bill.getReceivePay(), "0",null, null,null,null));
action.setRemark("终止计费,终止日期["+endTimeStr+"],");
isUpdate = true;
//如果结束时间在中间,则按天计算差额退回
}else if (bill.getStarttime().before(endTime) && bill.getEndtime().after(endTime)){
int realDays = DateUtils.daysBetween(bill.getStarttime(),endTime);
int billDays = DateUtils.daysBetween(bill.getStarttime(),bill.getEndtime());
String newReceivePay = new BigDecimal(bill.getReceivePay()).multiply(new BigDecimal(realDays)).divide(new BigDecimal(billDays),decimalSize,RoundingMode.HALF_UP).toPlainString();
if (isAllReturn) {
newReceivePay = "0";
}
action.setOldMoney(oldReceivePay);
action.setNewMoney(newReceivePay);
bill.setReceivePay(newReceivePay);
bill.setBillRemark(StringUtils.trimToEmpty(bill.getBillRemark())+";终止计费,终止日期["+endTimeStr+"],");
action.setAction(EnumBillAction.UPDATE_BILL.getCode());
action.setDetails(EnumBillAction.UPDATE_BILL.getDescription(oldReceivePay, newReceivePay, null,null,null,null));
action.setRemark("终止计费,终止日期["+endTimeStr+"],");
isUpdate = true;
}else {
//如果账单属于结束时间之前的,欠缴费的也需要结算
if (isAllReturn) {
bill.setReceivePay("0");
action.setOldMoney(oldReceivePay);
action.setNewMoney("0");
action.setAction(EnumBillAction.UPDATE_BILL.getCode());
action.setDetails(EnumBillAction.UPDATE_BILL.getDescription(oldReceivePay, "0", null,null,null,null));
action.setRemark("终止计费,终止日期["+endTimeStr+"],");
isUpdate = true;
}
}
return isUpdate;
}
private MallUserInfo getSystemUser(TenantEntity tenantEntity) {
MallUserInfo user = new MallUserInfo();
user.updateTenantInfo(tenantEntity);
user.setId(Constant.SYS_SERVER);
user.setName("SYSTEM");
user.setPhone("00000000000");
return user;
}
//租赁合同终止, 租赁押金需全部退回,租金账单,营业管理费,商业管理费账单需重新计算。
public void rentContractStop(WxRentContract rentContract,MallUserInfo user) {
if (null == user) {
user = getSystemUser(rentContract);
}
//根据合同查询租金账单,重新计算账单
wxAllBillService.rentContractStop(rentContract, user);
}
//物业合同终止,物业押金需全额退回,物业账单需重新计算
public void propertyContractStop(WxPropertyContract propertyContract,MallUserInfo user) {
if (null == user) {
user = getSystemUser(propertyContract);
}
//物业账单
wxAllBillService.propertyContractStop(propertyContract, user);
}
public void saveOrUpdateBill(WxAllBill bill,MallUserInfo user) {
wxAllBillService.saveOrUpdate(bill, user);
}
}
package com.iformall.service.helper;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageInfo;
import com.iformall.common.SysConfigConstant;
import com.iformall.domain.dto.WxBillPayDTO;
import com.iformall.domain.dto.WxBillReceiveUpdateDTO;
import com.iformall.domain.po.MallUserInfo;
import com.iformall.domain.po.SysConfig;
import com.iformall.domain.po.WxBillAction;
import com.iformall.domain.po.WxAllBill;
import com.iformall.domain.po.WxMerchant;
import com.iformall.domain.po.WxMerchantBUser;
import com.iformall.domain.po.WxPropertyContract;
import com.iformall.domain.po.WxRentContract;
import com.iformall.domain.po.WxShop;
import com.iformall.domain.po.WxShopUsers;
import com.iformall.domain.po.WxShopUsersInfo;
import com.iformall.domain.po.base.TenantEntity;
import com.iformall.domain.vo.WxBillHotNotify;
import com.iformall.domain.vo.WxBillNotify;
import com.iformall.domain.vo.WxBillSum;
import com.iformall.domain.vo.WxShopVo;
import com.iformall.enums.EnumBillAction;
import com.iformall.enums.EnumBillAllType;
import com.iformall.enums.EnumBillDailyType;
import com.iformall.enums.EnumBillOweOrNearType;
import com.iformall.enums.EnumBillStatus;
import com.iformall.enums.EnumBillType;
import com.iformall.enums.EnumRentContractManageFeeType;
import com.iformall.enums.EnumShopUsersStatus;
import com.iformall.enums.EnumSystemUserType;
import com.iformall.enums.EnumYesOrNo;
import com.iformall.service.WxAllBillService;
import com.iformall.service.WxBillActionService;
import com.iformall.service.WxMallService;
import com.iformall.service.WxMerchantService;
import com.iformall.service.WxShopService;
import com.iformall.utils.Constant;
import com.iformall.utils.DateUtils;
import com.iformall.utils.PriceUtil;
import com.iformall.utils.WordUtil;

@Service
public class WxBillAllHelper {
@Autowired
private String fmUploadDir;

@Autowired
private WxAllBillService wxAllBillService;
@Autowired
private WxShopService wxShopService;
@Autowired
private WxMerchantService wxMerchantService;
@Autowired
private WxMallService wxMallService;
public Date getDateBefore(Integer afterDays) {
Date nowBegin = DateUtils.getDayBegin(new Date());
//return DateUtils.getDateTimeBefore(afterDays*3600*24, nowBegin);
return DateUtils.getSecondsTimeAfter(afterDays*3600*24, nowBegin);
}
private void updateQueryParm(WxShop wxShop,WxAllBill bill,Date starttime,Date enttime) {
bill.updateTenantInfo(wxShop);
bill.setShopId(wxShop.getId());
bill.setShopIdList(wxShop.getIds());
bill.setFloorForRule(wxShop.getFloorForRule());
bill.setBusinessForRule(wxShop.getBusinessForRule());
bill.setShopTypeForRule(wxShop.getShopTypeForRule());
bill.setBuilding(wxShop.getBuilding());
bill.setFloor(wxShop.getFloor());
bill.setStarttime(starttime);
bill.setEndtime(enttime);
//bill.setRentShopType(wxMerchant.getType());
if (null != wxShop.getOweBillBeforeDays()) {
bill.setOweBillLastTime(getDateBefore(wxShop.getOweBillBeforeDays()));
}
if (null != wxShop.getNearBillBeforeDays()) {
bill.setNearBillLastTime(getDateBefore(wxShop.getNearBillBeforeDays()));
}
if (null != wxShop.getNeedPayPreDays()) {
bill.setNeedPayStartDay(getDateBefore(wxShop.getNeedPayPreDays()));
}
bill.setToPayMerchant(wxShop.getToPayMerchant());
bill.setIsPreview(wxShop.getIsPreview());
bill.setNeedPayNoDays(wxShop.getNeedPayNoDays());
bill.setEnergyFeesIds(wxShop.getEnergyFeesIdList());
bill.setAdvanceHasMoney(wxShop.getAdvanceHasMoney());
bill.setReceiveDate(wxShop.getReceiveDate());
bill.setCusName(wxShop.getCusName());
}
public WxBillSum getBillSum(WxShop wxShop,Date starttime, Date enttime) {
WxAllBill br = new WxAllBill();
updateQueryParm(wxShop, br,starttime,enttime);
WxBillSum rentSum = wxAllBillService.getBillMonthSum(br);
if (null == rentSum) {
rentSum = new WxBillSum();
}
return rentSum;
}
public List<WxBillSum> getFeesBillSum(WxShop wxShop,Date starttime, Date enttime) {
WxAllBill br = new WxAllBill();
updateQueryParm(wxShop, br,starttime,enttime);
return wxAllBillService.getFeesBillSum(br);
}
public List<WxBillHotNotify> getBillHotNotify(WxShop wxShop,Date starttime, Date enttime) {
WxAllBill br = new WxAllBill();
updateQueryParm(wxShop, br,starttime,enttime);
br.setIsPreview(EnumYesOrNo.NO.getCode());
return wxAllBillService.getBillHotNotify(br);
}
public String calcuteSum(String... money) {
if (null != money) {
BigDecimal total = new BigDecimal(0);
for (int i = 0 ; i < money.length ; i++) {
String _m = money[i];
if (StringUtils.isBlank(_m)) {
_m = "0";
}
total = total.add(new BigDecimal(_m));
}
//return total.setScale(2,RoundingMode.HALF_UP).toPlainString();
return total.toPlainString();
}
return "0";
}
private Date getMinDate(Date... date) {
if (null != date && date.length > 0 ) {
Date minDate = null;
for (int i =0 ; i < date.length; i ++) {
Date ndate = date[i];
if (null != ndate) {
if (null == minDate) {
minDate = ndate;
}else {
if (minDate.after(ndate)) {
minDate = ndate;
}
}
}
}
return minDate;
}
return null;
}
private Date getMaxDate(Date... date) {
if (null != date && date.length > 0 ) {
Date maxDate = null;
for (int i =0 ; i < date.length; i ++) {
Date ndate = date[i];
if (null != ndate) {
if (null == maxDate) {
maxDate = ndate;
}else {
if (maxDate.before(ndate)) {
maxDate = ndate;
}
}
}
}
return maxDate;
}
return null;
}
public List<Long> getOwdShopIds(WxShop wxShop,Date starttime, Date enttime) {
WxAllBill br = new WxAllBill();
updateQueryParm(wxShop, br,starttime,enttime);
return wxAllBillService.getShopIds(br);
}
public WxAllBill generateRentContractQueryBill(TenantEntity tenantEntity,Long rentContractId,Date starttime, Date endtime) {
WxAllBill bq = new WxAllBill();
bq.updateTenantInfo(tenantEntity);
bq.setRentContractId(rentContractId);
bq.setIsPreview(EnumYesOrNo.NO.getCode());
bq.setBillType(EnumBillAllType.RENT.getCode());
bq.setEnergyFeesId(EnumBillAllType.RENT.getEnergyFeesId());
bq.setNoExtraCreateFrom(EnumYesOrNo.YES.getCode());
bq.setStarttimeEqual(starttime);
bq.setEndtimeEqual(endtime);
return bq;
}
private List<Long> getUnionIds(List<Long>...lists ) {
if (null != lists && lists.length > 0 ) {
List<Long> retList = new ArrayList<Long>();
for (int i = 0 ; i < lists.length; i++) {
List<Long> list = lists[i];
if (null != list) {
retList.removeAll(list);
retList.addAll(list);
}
}
return retList;
}
return null;
}
public PageInfo<WxAllBill> getBillList(WxShop wxShop,Integer pageNum, Integer pageSize) {
WxAllBill wxAllBill = new WxAllBill();
updateQueryParm(wxShop, wxAllBill,wxShop.getStarttime(),wxShop.getEndtime());
wxAllBill.setIsPreview(EnumYesOrNo.NO.getCode());
wxAllBill.setSortColumns("starttime asc");
return wxAllBillService.listAsPage(wxAllBill, pageNum, pageSize);
}
public List<WxAllBill> getMerchantBillList(WxShop wxShop) {
WxAllBill wxBillRent = new WxAllBill();
updateQueryParm(wxShop, wxBillRent,wxShop.getStarttime(),wxShop.getEndtime());
wxBillRent.setSortColumns("starttime asc");
return wxAllBillService.list(wxBillRent);
}
public WxAllBill getOneBill(TenantEntity tenantEntity,Long id) {
return wxAllBillService.getById(tenantEntity, id);
}
public List<WxBillNotify> getBillNotifyList(WxShop wxShop,Integer notifyed) {
WxAllBill wxBillRent = new WxAllBill();
updateQueryParm(wxShop, wxBillRent,wxShop.getStarttime(),wxShop.getEndtime());
wxBillRent.setNotifyed(notifyed);
wxBillRent.setSortColumns("starttime asc");
List<WxBillNotify> retList = wxAllBillService.notifyList(wxBillRent);
if (null != retList && retList.size() > 0 ) {
List<Long> shopIdList = new ArrayList<Long>();
for (int i = 0 ; i < retList.size(); i ++) {
WxBillNotify wbn = retList.get(i);
if (null != wbn.getShopId()) {
if (!shopIdList.contains(wbn.getShopId())) {
shopIdList.add(wbn.getShopId());
}
}
}
if (shopIdList.size() > 0) {
WxShopUsers suq = new WxShopUsers();
suq.updateTenantInfo(wxShop);
suq.setStatus(EnumShopUsersStatus.LIVE.getCode());
suq.setShopIds(shopIdList);
Map<Long, WxShopUsers> shopUserMap = wxShopService.getShopUserMap(suq);
if (null != shopUserMap) {
for (int i = 0 ; i < retList.size() ; i++) {
WxBillNotify bn = retList.get(i);
if (null != bn.getShopId()) {
WxShopUsers s = shopUserMap.get(bn.getShopId());
if (null != s) {
bn.setShopUserName(s.getName());
bn.setShopUserPerson(s.getLinkPerson());
bn.setShopUserPhone(s.getPhone());
}
}
}
}
}
}
return retList;
}
public void exportOneBillOweWord(boolean isOwe,WxAllBill bill,HttpServletRequest request, HttpServletResponse response) {
String templatePath = "contract-word-template/bill_owe_one.docx";
if (!isOwe) {
templatePath = "contract-word-template/bill_near_one.docx";
}
String filepath = fmUploadDir;
String filename = UUID.randomUUID() + ".docx";
String exportFileName = "催缴单";
Map<String, Object> result = new HashMap<>();
result.put("starttime", DateUtils.date2String(bill.getStarttime(),DateUtils.DATE_PATTERN));
result.put("endtime", DateUtils.date2String(bill.getEndtime(),DateUtils.DATE_PATTERN));
if (null != bill.getShopId()) {
WxShop shop = wxShopService.getById(bill.getShopId());
if (null != shop) {
result.put("shopNumber", shop.getShopNumber());
}
WxShopUsers su = wxShopService.getCurrentShopUser(bill, bill.getShopId());
if (null != su) {
result.put("merchantName", su.getName());
result.put("linkPerson", su.getLinkPerson());
result.put("linkPhone", su.getPhone());
exportFileName = exportFileName+"_"+su.getName();
}
}
result.put("billTypeName", bill.getBillTypeName());
exportFileName = exportFileName +"_"+ bill.getBillTypeName();
result.put("billRemark", bill.getBillRemark());
result.put("receivePay", bill.getReceivePay());
result.put("pay", bill.getPay());
result.put("owe", bill.getOwe());
result.put("number", "JF" + DateUtils.getSystemTime("yyyyMMddHHmmss"));
result.put("summaryUpper", PriceUtil.number2CNMontrayUnit(new BigDecimal(bill.getOwe()).setScale(2,RoundingMode.HALF_UP)));
result.put("mall", wxMallService.getByTenantInfo(bill).getName());
result.put("createtime", DateUtils.date2String(new Date()));
exportFileName = exportFileName +".docx";
WordUtil.exportWord(templatePath, filepath, filename, exportFileName, result, request, response, null);
}
public List<WxBillHotNotify> getHotNotify(WxShop wxShop) {
return this.getBillHotNotify( wxShop, wxShop.getStarttime(), wxShop.getEndtime());
}
public void updateReceivePay(WxBillReceiveUpdateDTO dto,MallUserInfo user,boolean forcePaid) {
wxAllBillService.updateReceivePay(dto, user, forcePaid);
}
public void notify(WxBillPayDTO dto,MallUserInfo user) {
//TODO 发短信通知
wxAllBillService.notify(dto, user);
}
public void backPay(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.backPay(dto, user);
}
public void backSetOff(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.backSetOff(dto, user);
}
public void backCut(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.backCut(dto, user);
}
public void toMechantBackPay(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.toMechantBackPay(dto, user);
}
public void updatePay(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.updatePay(dto, user);
}
public void updateCut(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.updateCut(dto, user);
}
public void updatePayByMerchant(WxBillPayDTO dto,WxMerchantBUser user,boolean isOnline) {
wxAllBillService.updatePayByMerchant(dto, user,isOnline);
}
public WxAllBill getBillDetail(TenantEntity tenantEntity,Long billId) {
return wxAllBillService.getById(tenantEntity,billId);
}
public void updatePayToMerchant(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.updatePayToMerchant(dto, user);
}
public void bad(WxBillPayDTO dto,MallUserInfo user) {
wxAllBillService.bad(dto, user);
}
public void completeBill(EnumBillStatus status,WxShop wxShop,MallUserInfo user) {
wxAllBillService.completeBill(status,wxShop, user);
}
/**
* 退租:
* 账单开始时间>= 今天,并且账单是 WAIT_PAY,NOT_PAID,NOT_EXPIRED,BAD 变为INVALID,如果已付了款,需要退回
* 账单开始时间<今天 & 账单结束时间 > 今天:
* 账单 WAIT_PAY,NOT_PAID,NOT_EXPIRED,BAD 的,需要计算截止到今天账单总金额是多少钱,更新实际应收金额,并记录日志
* 账单 PAID, 需要计算截止到今天账单总金额是多少钱,更新实际应收金额,并记录日志
* 账单开始时间<今天 & 账单结束时间 <= 今天:
* 那是之前的账单,不处理。
* @param merchant
*/
public boolean billEndCalcute(Integer decimalSize,Date endTime,WxAllBill bill,WxBillAction action) {
String endTimeStr = DateUtils.date2String(endTime,DateUtils.DATE_TIME_PATTERN);
boolean isUpdate = false;
action.setBillId(bill.getId());
action.setBillType(bill.getBillType());
String oldReceivePay = bill.getReceivePay();
boolean isAllReturn = false;
if (EnumBillAllType.getEnum(bill.getBillType()).isDeposit()) {
isAllReturn = true;
}
//如果账单的开始时间在结束时间之后,已经支付了的要退回。
if (!bill.getStarttime().before(endTime)) {
bill.setReceivePay("0");
bill.setBillRemark(StringUtils.trimToEmpty(bill.getBillRemark())+";终止计费,终止日期["+endTimeStr+"],");
action.setOldMoney(oldReceivePay);
action.setNewMoney("0");
action.setAction(EnumBillAction.UPDATE_BILL.getCode());
action.setDetails(EnumBillAction.UPDATE_BILL.getDescription(bill.getReceivePay(), "0",null, null,null,null));
action.setRemark("终止计费,终止日期["+endTimeStr+"],");
isUpdate = true;
//如果结束时间在中间,则按天计算差额退回
}else if (bill.getStarttime().before(endTime) && bill.getEndtime().after(endTime)){
int realDays = DateUtils.daysBetween(bill.getStarttime(),endTime);
int billDays = DateUtils.daysBetween(bill.getStarttime(),bill.getEndtime());
String newReceivePay = new BigDecimal(bill.getReceivePay()).multiply(new BigDecimal(realDays)).divide(new BigDecimal(billDays),decimalSize,RoundingMode.HALF_UP).toPlainString();
if (isAllReturn) {
newReceivePay = "0";
}
action.setOldMoney(oldReceivePay);
action.setNewMoney(newReceivePay);
bill.setReceivePay(newReceivePay);
bill.setBillRemark(StringUtils.trimToEmpty(bill.getBillRemark())+";终止计费,终止日期["+endTimeStr+"],");
action.setAction(EnumBillAction.UPDATE_BILL.getCode());
action.setDetails(EnumBillAction.UPDATE_BILL.getDescription(oldReceivePay, newReceivePay, null,null,null,null));
action.setRemark("终止计费,终止日期["+endTimeStr+"],");
isUpdate = true;
}else {
//如果账单属于结束时间之前的,欠缴费的也需要结算
if (isAllReturn) {
bill.setReceivePay("0");
action.setOldMoney(oldReceivePay);
action.setNewMoney("0");
action.setAction(EnumBillAction.UPDATE_BILL.getCode());
action.setDetails(EnumBillAction.UPDATE_BILL.getDescription(oldReceivePay, "0", null,null,null,null));
action.setRemark("终止计费,终止日期["+endTimeStr+"],");
isUpdate = true;
}
}
return isUpdate;
}
private MallUserInfo getSystemUser(TenantEntity tenantEntity) {
MallUserInfo user = new MallUserInfo();
user.updateTenantInfo(tenantEntity);
user.setId(Constant.SYS_SERVER);
user.setName("SYSTEM");
user.setPhone("00000000000");
return user;
}
//租赁合同终止, 租赁押金需全部退回,租金账单,营业管理费,商业管理费账单需重新计算。
public void rentContractStop(WxRentContract rentContract,MallUserInfo user) {
if (null == user) {
user = getSystemUser(rentContract);
}
//根据合同查询租金账单,重新计算账单
wxAllBillService.rentContractStop(rentContract, user);
}
//物业合同终止,物业押金需全额退回,物业账单需重新计算
public void propertyContractStop(WxPropertyContract propertyContract,MallUserInfo user) {
if (null == user) {
user = getSystemUser(propertyContract);
}
//物业账单
wxAllBillService.propertyContractStop(propertyContract, user);
}
public void saveOrUpdateBill(WxAllBill bill,MallUserInfo user) {
wxAllBillService.saveOrUpdate(bill, user);
}
}

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