diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/rent/WxAllBillController.java b/mallinkAdmin/src/main/java/com/iformall/controller/rent/WxAllBillController.java index 3791546a2..8143709cf 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/rent/WxAllBillController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/rent/WxAllBillController.java @@ -56,6 +56,8 @@ import com.iformall.utils.DateUtils; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; + +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -153,6 +155,23 @@ public class WxAllBillController extends BillBaseController { wxShop.setId(-1L); } } + + if (StringUtils.isNotBlank(wxShop.getQueryShopIdStr())) { + String[] qsids = wxShop.getQueryShopIdStr().split(","); + if (null != qsids && qsids.length > 0 ) { + List shopIdList = new ArrayList(); + for (int i = 0 ; i < qsids.length ; i ++) { + String qsid = qsids[i]; + if (StringUtils.isNotBlank(qsid)) { + shopIdList.add(Long.parseLong(qsid)); + } + } + if (null != shopIdList && shopIdList.size() > 0 ) { + wxShop.setIds(shopIdList); + } + } + } + wxShop.setIsPreview(EnumYesOrNo.NO.getCode()); PageInfo shopPage = wxShopSerivce.listAsPage(wxShop, pageNum, pageSize); PageInfo page = new PageInfo(); diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxFinanceReceiveBill.java b/mallinkService/src/main/java/com/iformall/domain/po/WxFinanceReceiveBill.java index 528346001..6658e1620 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxFinanceReceiveBill.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxFinanceReceiveBill.java @@ -149,5 +149,7 @@ public class WxFinanceReceiveBill extends TenantEntity { private Integer noReduce; @TableField(exist = false) private List shopIdList; + @TableField(exist = false) + private String queryShopIdStr; } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java b/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java index cea2fc78c..2e0d6fbc9 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxShop.java @@ -240,4 +240,8 @@ public class WxShop extends TenantEntity { private String shopUserName; @TableField(exist = false) private Integer sortWay; + @TableField(exist = false) + private String cusName; + @TableField(exist = false) + private String queryShopIdStr; } diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxBillHotNotify.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillHotNotify.java index a80608282..0b56cd68b 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/WxBillHotNotify.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillHotNotify.java @@ -15,8 +15,10 @@ public class WxBillHotNotify implements Serializable { private static final long serialVersionUID = 1L; //EnumBillAllType - private Integer billType; - private String billTypeName; + //private Integer billType; + //private String billTypeName; + private Long energyFeesId; + private String feesName; private Integer totalCount = 0; private String totalMoney = "0"; private BigDecimal totalMoneyNumber; @@ -31,12 +33,12 @@ public class WxBillHotNotify implements Serializable { return totalMoneyNumber; } - public String getBillTypeName() { - if (null != billType) { - return EnumBillAllType.getEnum(billType).getMessage(); - } - return null; - } +// public String getBillTypeName() { +// if (null != billType) { +// return EnumBillAllType.getEnum(billType).getMessage(); +// } +// return null; +// } } diff --git a/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java b/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java index 18ebacf12..4de77f279 100644 --- a/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java +++ b/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java @@ -1,480 +1,480 @@ -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()); - } - - 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 getFeesBillSum(WxShop wxShop,Date starttime, Date enttime) { - WxAllBill br = new WxAllBill(); - updateQueryParm(wxShop, br,starttime,enttime); - return wxAllBillService.getFeesBillSum(br); - } - - public List getBillHotNotify(WxShop wxShop,Date starttime, Date enttime) { - WxAllBill br = new WxAllBill(); - updateQueryParm(wxShop, br,starttime,enttime); - 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 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 getUnionIds(List...lists ) { - if (null != lists && lists.length > 0 ) { - List retList = new ArrayList(); - for (int i = 0 ; i < lists.length; i++) { - List list = lists[i]; - if (null != list) { - retList.removeAll(list); - retList.addAll(list); - } - } - return retList; - } - return null; - } - - public PageInfo 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 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 getBillNotifyList(WxShop wxShop,Integer notifyed) { - - WxAllBill wxBillRent = new WxAllBill(); - updateQueryParm(wxShop, wxBillRent,wxShop.getStarttime(),wxShop.getEndtime()); - wxBillRent.setNotifyed(notifyed); - wxBillRent.setSortColumns("starttime asc"); - List retList = wxAllBillService.notifyList(wxBillRent); - if (null != retList && retList.size() > 0 ) { - List shopIdList = new ArrayList(); - 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 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 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 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); - } - - public List getMerchantAdvanceGroupSumList(WxAllBill bill) { - return wxAllBillService.getMerchantAdvanceGroupSumList(bill); - } - - /** - * 退租: - * 账单开始时间>= 今天,并且账单是 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 getFeesBillSum(WxShop wxShop,Date starttime, Date enttime) { + WxAllBill br = new WxAllBill(); + updateQueryParm(wxShop, br,starttime,enttime); + return wxAllBillService.getFeesBillSum(br); + } + + public List getBillHotNotify(WxShop wxShop,Date starttime, Date enttime) { + WxAllBill br = new WxAllBill(); + updateQueryParm(wxShop, br,starttime,enttime); + 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 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 getUnionIds(List...lists ) { + if (null != lists && lists.length > 0 ) { + List retList = new ArrayList(); + for (int i = 0 ; i < lists.length; i++) { + List list = lists[i]; + if (null != list) { + retList.removeAll(list); + retList.addAll(list); + } + } + return retList; + } + return null; + } + + public PageInfo 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 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 getBillNotifyList(WxShop wxShop,Integer notifyed) { + + WxAllBill wxBillRent = new WxAllBill(); + updateQueryParm(wxShop, wxBillRent,wxShop.getStarttime(),wxShop.getEndtime()); + wxBillRent.setNotifyed(notifyed); + wxBillRent.setSortColumns("starttime asc"); + List retList = wxAllBillService.notifyList(wxBillRent); + if (null != retList && retList.size() > 0 ) { + List shopIdList = new ArrayList(); + 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 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 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 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); + } + + public List getMerchantAdvanceGroupSumList(WxAllBill bill) { + return wxAllBillService.getMerchantAdvanceGroupSumList(bill); + } + + /** + * 退租: + * 账单开始时间>= 今天,并且账单是 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); + } + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxAllBillServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxAllBillServiceImpl.java index d6966ac4e..68c77e0e3 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxAllBillServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxAllBillServiceImpl.java @@ -243,7 +243,23 @@ public class WxAllBillServiceImpl extends WxBillBaseService implements WxAllBill @Override public List getBillHotNotify(WxAllBill wxBillRent) { updateQueryParam(wxBillRent); - return wxAllBillMapper.getBillHotNotify(wxBillRent); + List list = wxAllBillMapper.getBillHotNotify(wxBillRent); + if (null != list && list.size() > 0 ){ + WxEnergyFees fq = new WxEnergyFees(); + fq.updateTenantInfo(wxBillRent); + Map feesMap = wxEnergyService.getFeesMap(fq); + for (int i = 0 ; i < list.size() ; i ++) { + WxBillHotNotify hn = list.get(i); + if (null != feesMap) { + WxEnergyFees fees = feesMap.get(hn.getEnergyFeesId()); + if (null != fees) { + hn.setFeesName(fees.getName()); + } + } + + } + } + return list; } @Override diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxFinanceServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxFinanceServiceImpl.java index 5bfe9c581..1ce9353d5 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxFinanceServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxFinanceServiceImpl.java @@ -74,6 +74,7 @@ import com.iformall.utils.Constant; import com.iformall.utils.DateUtils; import com.iformall.utils.StringContentUtils; +import org.apache.commons.collections.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -548,9 +549,8 @@ public class WxFinanceServiceImpl implements WxFinanceService { } private void initReceiveBillQueryParam(WxFinanceReceiveBill record) { - if (StringUtils.isNotBlank(record.getBillCusName()) || StringUtils.isNotBlank(record.getShopNumber())) { + if (StringUtils.isNotBlank(record.getBillCusName())) { record.setBillCusName(StringContentUtils.unescapeHtml(record.getBillCusName())); - record.setShopNumber(StringContentUtils.unescapeHtml(record.getShopNumber())); } if (StringUtils.isNotBlank(record.getPayWayStr())) { @@ -573,14 +573,30 @@ public class WxFinanceServiceImpl implements WxFinanceService { record.setFeesIdList(feesIdList); } } - if (StringUtils.isNotBlank(record.getShopNumber()) - || null != record.getBuilding() || null != record.getFloor()) { + if (StringUtils.isNotBlank(record.getShopNumber()) || StringUtils.isNotBlank(record.getQueryShopIdStr()) || null != record.getBuilding() || null != record.getFloor()) { + //根据店铺去找到商户 WxShop sq = new WxShop(); sq.updateTenantInfo(record); sq.setShopNumber(record.getShopNumber()); sq.setBuilding(record.getBuilding()); sq.setFloor(record.getFloor()); + if (StringUtils.isNotBlank(record.getQueryShopIdStr())) { + String[] qsids = record.getQueryShopIdStr().split(","); + if (null != qsids && qsids.length > 0 ) { + List shopIdList = new ArrayList(); + for (int i = 0 ; i < qsids.length ; i ++) { + String qsid = qsids[i]; + if (StringUtils.isNotBlank(qsid)) { + shopIdList.add(Long.parseLong(qsid)); + } + } + if (null != shopIdList && shopIdList.size() > 0 ) { + sq.setIds(shopIdList);; + } + } + } + List shopIds = wxShopService.getShopIds(sq); if (null == shopIds || shopIds.size() <= 0 ) { record.setId(-1L); diff --git a/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml b/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml index 27ad222c2..36250ae2a 100644 --- a/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml @@ -287,18 +287,18 @@ - +