From 6415902cf3cf3ea418e80ac05519c61de87ccc7f Mon Sep 17 00:00:00 2001 From: zhengfangyuan Date: Mon, 2 Jan 2023 14:19:33 +0800 Subject: [PATCH] fix bug --- .../db/migration/V202301200001__contract.sql | 44 ++++ .../iformall/domain/po/WxBillRentManage.java | 194 +++++++++++++++++ .../com/iformall/domain/vo/WxBillAll.java | 5 + .../com/iformall/enums/EnumBillQueryType.java | 4 +- .../enums/EnumRentContractManageFeeType.java | 37 ++++ .../com/iformall/mapper/WxBillAllMapper.java | 1 + .../mapper/WxBillRentManageMapper.java | 32 +++ .../service/impl/WxBillAllServiceImpl.java | 10 + .../impl/WxRentContractServiceImpl.java | 170 ++++++++++++++- .../main/resources/mapper/WxBillAllMapper.xml | 32 +++ .../resources/mapper/WxBillDepositMapper.xml | 1 + .../mapper/WxBillRentManageMapper.xml | 204 ++++++++++++++++++ 12 files changed, 731 insertions(+), 3 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/domain/po/WxBillRentManage.java create mode 100644 mallinkService/src/main/java/com/iformall/enums/EnumRentContractManageFeeType.java create mode 100644 mallinkService/src/main/java/com/iformall/mapper/WxBillRentManageMapper.java create mode 100644 mallinkService/src/main/resources/mapper/WxBillRentManageMapper.xml diff --git a/mallinkAdmin/src/main/resources/db/migration/V202301200001__contract.sql b/mallinkAdmin/src/main/resources/db/migration/V202301200001__contract.sql index f216a4b74..0d42fb792 100644 --- a/mallinkAdmin/src/main/resources/db/migration/V202301200001__contract.sql +++ b/mallinkAdmin/src/main/resources/db/migration/V202301200001__contract.sql @@ -76,3 +76,47 @@ ADD COLUMN `out_date_notify_days` INT(3) NOT NULL DEFAULT 0 COMMENT '到期提 ALTER TABLE `mallink`.`wx_property_contract` ADD COLUMN `out_date_notify_phone` varchar(30) COMMENT '到期提醒手机号' ; + +CREATE TABLE `wx_bill_rent_manage` ( + `id` bigint(20) NOT NULL COMMENT '主键ID', + `rent_contract_id` bigint(20) DEFAULT NULL COMMENT '租金合同ID', + `receive_pay` bigint(12) NOT NULL DEFAULT '0' COMMENT '实际应收', + `pay` bigint(12) NOT NULL DEFAULT '0' COMMENT '已付', + `receive_date` datetime DEFAULT NULL COMMENT '收款日期', + `pay_date` datetime DEFAULT NULL COMMENT '到账日期', + `createtime` datetime DEFAULT NULL COMMENT '创建时间', + `expired_day` int(5) DEFAULT NULL COMMENT '逾期天数', + `tenant_id` varchar(5) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '租户ID', + `parent_tenant_id` varchar(5) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '父租户ID', + `owe` bigint(12) NOT NULL DEFAULT '0' COMMENT '欠缴', + `status` smallint(2) DEFAULT '4' COMMENT '账单状态1欠缴2待缴3已结清4未到期5已退还6失效', + `is_del` smallint(2) DEFAULT NULL COMMENT '是否删除 是1否0 未到期不显示', + `need_pay` bigint(12) NOT NULL DEFAULT '0' COMMENT '应收', + `merchant_id` bigint(20) DEFAULT NULL COMMENT '商户ID', + `user_id` bigint(20) DEFAULT NULL COMMENT '账号ID', + `shop_id` bigint(20) DEFAULT NULL COMMENT '商铺ID', + `updatetime` datetime DEFAULT NULL COMMENT '更新时间', + `starttime` datetime DEFAULT NULL COMMENT '账单开始日期', + `endtime` datetime DEFAULT NULL COMMENT '账单结束日期', + `rent_shop_type` smallint(2) DEFAULT '1' COMMENT '租赁店铺类型1店铺2点位', + `late_pay_ratio` int(10) DEFAULT '0' COMMENT '滞纳金费率', + `late_pay_time` datetime DEFAULT NULL COMMENT '滞纳金时间', + `late_pay_price` bigint(12) DEFAULT NULL, + `period` int(10) DEFAULT '0' COMMENT '账期', + `apply_status` smallint(1) DEFAULT '0' COMMENT '审核状态0未审核1审核中2审核完成3驳回4合同作废5撤回', + `pay_way` smallint(2) DEFAULT '-1', + `late_pay_status` smallint(2) DEFAULT '2' COMMENT '滞纳金状态(使用账单的状态)', + `freeze` smallint(1) DEFAULT '0' COMMENT '0正常1冻结', + `service_charge_pay` bigint(12) DEFAULT '0' COMMENT '手续费费', + `apply_pay_img` varchar(1000) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '付款截图', + `apply_update_time` datetime DEFAULT NULL COMMENT '审核更新时间', + `shop_info` json DEFAULT NULL COMMENT '商铺信息', + `manage_fee_type` int(1) NOT NULL COMMENT '管理费类型,EnumRentManageFeeType', + PRIMARY KEY (`id`), + KEY `st` (`rent_shop_type`), + KEY `sta` (`status`), + KEY `m` (`merchant_id`), + KEY `s_e` (`starttime`,`endtime`), + KEY `t_p_r_s_c` (`tenant_id`,`rent_shop_type`,`status`,`createtime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='租金账单'; + diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRentManage.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRentManage.java new file mode 100644 index 000000000..fc6609e4f --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRentManage.java @@ -0,0 +1,194 @@ +package com.iformall.domain.po; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.iformall.common.SortColumn; +import com.iformall.domain.po.base.TenantEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.apache.commons.lang3.StringUtils; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author gongbiao + */ +@TableName(value = "wx_bill_rent_manage") +@Data +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +public class WxBillRentManage extends TenantEntity { + + protected Long id; + + + @Excel(name = "商户名称", width = 20, orderNum = "2") + @TableField(exist = false) + private String merchantName; + + @io.swagger.annotations.ApiModelProperty(value="租金合同ID",name="rentContractId") + private Long rentContractId; + + @io.swagger.annotations.ApiModelProperty(value="应收金额",name="receivePay") + private Long receivePay; + + public String getReceivePayStr() { + return new BigDecimal(receivePay == null ? 0 : receivePay).divide(new BigDecimal(100)).toPlainString(); + } + + @TableField(exist = false) + private String receivePayStr; + + public String getPayStr() { + return new BigDecimal(pay == null ? 0 : pay).divide(new BigDecimal(100)).toPlainString(); + } + + @Excel(name = "实收账款(元)", width = 20, orderNum = "9") + @TableField(exist = false) + private String payStr; + + @io.swagger.annotations.ApiModelProperty(value="实收金额",name="pay") + private Long pay; + + @Excel(name = "缴款截止日期", format = "yyyy-MM-dd", width = 20, orderNum = "13") + @io.swagger.annotations.ApiModelProperty(value="收款日期",name="receiveDate") + private Date receiveDate; + + @Excel(name = "收款日期", format = "yyyy-MM-dd", width = 20, orderNum = "12") + @io.swagger.annotations.ApiModelProperty(value="到账日期",name="payDate") + private Date payDate; + + @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createtime") + private Date createtime; + + @Excel(name = "逾期(天) ", width = 20, orderNum = "14") + @io.swagger.annotations.ApiModelProperty(value="逾期天数",name="expiredDay") + private Long expiredDay; + + @io.swagger.annotations.ApiModelProperty(value="欠缴",name="owe") + private Long owe; + + public String getOweStr() { + return new BigDecimal(owe == null ? 0 : owe).divide(new BigDecimal(100)).toPlainString(); + } + + @Excel(name = "欠缴金额(元)", width = 20, orderNum = "11") + @TableField(exist = false) + private String oweStr; + + @Excel(name = "状态", replace = {"欠缴_1", "待缴_2", "已结清_3", "未到期_4", "已退还_5", "失效_6"}, width = 20, orderNum = "10") + @io.swagger.annotations.ApiModelProperty(value = "账单状态1欠缴2待缴3已结清4未到期", name = "status") + private Integer status; + + @io.swagger.annotations.ApiModelProperty(value = "账单审核状态EnumBillRentApplyStatus", name = "applyStatus") + private Integer applyStatus; + @io.swagger.annotations.ApiModelProperty(value = "付款截图", name = "applyPayImg") + private String applyPayImg; + @io.swagger.annotations.ApiModelProperty(value = "付款截图", name = "applyUpdateTime") + private Date applyUpdateTime; + + @io.swagger.annotations.ApiModelProperty(value="是否删除 是1否0 未到期不显示",name="isDel") + private Integer isDel; + + @io.swagger.annotations.ApiModelProperty(value="应收金额",name="needPay") + private Long needPay; + + @io.swagger.annotations.ApiModelProperty(value="商户ID",name="merchantId") + private Long merchantId; + + @io.swagger.annotations.ApiModelProperty(value="账号ID",name="userId") + private Long userId; + + @io.swagger.annotations.ApiModelProperty(value="商铺ID",name="shopId") + private Long shopId; + + @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updatetime") + private Date updatetime; + + @Excel(name = "周期开始时间", format = "yyyy-MM-dd", width = 20, orderNum = "4") + @io.swagger.annotations.ApiModelProperty(value="开始时间",name="starttime") + private Date starttime; + + @Excel(name = "周期结束时间", format = "yyyy-MM-dd", width = 20, orderNum = "5") + @io.swagger.annotations.ApiModelProperty(value="结束时间",name="endtime") + private Date endtime; + + @io.swagger.annotations.ApiModelProperty(value = "租赁商铺类型", name = "rentShopType") + private Integer rentShopType; + + @io.swagger.annotations.ApiModelProperty(value = "滞纳金费率", name = "latePayRatio") + private Integer latePayRatio; + + @io.swagger.annotations.ApiModelProperty(value = "滞纳金时间", name = "latePayTime") + private Date latePayTime; + + @io.swagger.annotations.ApiModelProperty(value = "滞纳金总额", name = "latePayPrice") + private Long latePayPrice; + + public String getLatePayPriceStr() { + return new BigDecimal(latePayPrice == null ? 0 : latePayPrice).divide(new BigDecimal(100)).toPlainString(); + } + + @Excel(name = "滞纳金(元)", width = 20, orderNum = "12") + @TableField(exist = false) + private String latePayPriceStr; + + @SortColumn(column = "period") + @io.swagger.annotations.ApiModelProperty(value = "账期", name = "period") + private Integer period; + + @io.swagger.annotations.ApiModelProperty(value = "商铺信息", name = "shopInfo") + private String shopInfo; + + @io.swagger.annotations.ApiModelProperty(value = "支付方式:见枚举EnumBillPayWay", name = "payWay") + private Integer payWay; + + + @io.swagger.annotations.ApiModelProperty(value = "滞纳金状态", name = "latePayStatus") + private Integer latePayStatus; + + @TableField(exist = false) + private Integer limitStart; + @TableField(exist = false) + private Integer limitEnd; + + @TableField(exist = false) + private String latePayMoneyBefore; + @TableField(exist = false) + private String latePayMoneyUpdate; + + @io.swagger.annotations.ApiModelProperty(value = "冻结状态,0正常1冻结", name = "freeze") + private Integer freeze; + + @TableField(exist = false) + private String serviceChargePayBefore; + @TableField(exist = false) + private String serviceChargePayUpdate; + + @io.swagger.annotations.ApiModelProperty(value = "手续费", name = "serviceChargePay") + private Integer serviceChargePay; + + @io.swagger.annotations.ApiModelProperty(value="实际应收金额",name="realReceivePay") + @TableField(exist = false) + private Long realReceivePay; + + @Excel(name = "实际应收总金额(元)", width = 20, orderNum = "8") + @TableField(exist = false) + private String realReceivePayStr; + + public String getRealReceivePayStr() { + return new BigDecimal(realReceivePay == null ? 0 : realReceivePay).divide(new BigDecimal(100)).toPlainString(); + } + + @io.swagger.annotations.ApiModelProperty(value="管理费类型,EnumRentContractManageFeeType",name="manageFeeType") + private Integer manageFeeType; + + private void initByBillRent(WxBillRent billRent) { + + } + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxBillAll.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillAll.java index 3cee6a003..23634c6c1 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/WxBillAll.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxBillAll.java @@ -160,5 +160,10 @@ public class WxBillAll extends TenantEntity { private Integer limitStart; @TableField(exist = false) private Integer limitEnd; + + @TableField(exist = false) + private Integer manageFeeType; + @TableField(exist = false) + private String billTypeName; } diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumBillQueryType.java b/mallinkService/src/main/java/com/iformall/enums/EnumBillQueryType.java index c78cf2a03..d38d036e5 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumBillQueryType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumBillQueryType.java @@ -14,7 +14,9 @@ public enum EnumBillQueryType { WATER_POWER_AIR(5, "水电空调费"), OTHER(7, "其他"), OTHER_DEPOSIT(8, "其他押金"), - SETTLE(10, "结算单") + SETTLE(10, "结算单"), + RENT_BUSSINESS_MANAGE(11,"商业管理费"), + RENT_OPERATING_MANAGE(12,"营业管理费"), ; public static Integer getRealType(Integer type) { diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumRentContractManageFeeType.java b/mallinkService/src/main/java/com/iformall/enums/EnumRentContractManageFeeType.java new file mode 100644 index 000000000..c293e0240 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/enums/EnumRentContractManageFeeType.java @@ -0,0 +1,37 @@ +package com.iformall.enums; + +/** + * Created by luozukai + * 预览账单0否1是 + */ +public enum EnumRentContractManageFeeType { + + RENT_BUSSINESS_MANAGE_FEE(1, "商业管理费"), + RENT_OPERATING_MANAGE_FEE(2, "营业管理费") + ; + + public static EnumRentContractManageFeeType getEnum(Integer code) { + for (EnumRentContractManageFeeType value : values()) { + if (value.getCode().equals(code)) { + return value; + } + } + return null; + } + + private Integer code; + private String message; + + EnumRentContractManageFeeType(Integer code, String message) { + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String getMessage() { + return message; + } +} diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxBillAllMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxBillAllMapper.java index 8375d98f0..bda5ca989 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxBillAllMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxBillAllMapper.java @@ -26,6 +26,7 @@ public interface WxBillAllMapper { List listDailyBill(WxBillAll record); List listOtherBill(WxBillAll record); List listOtherDepositBill(WxBillAll record); + List listRentManageBill(WxBillAll record); Map queryOweInfo(WxBillAll record); diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxBillRentManageMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxBillRentManageMapper.java new file mode 100644 index 000000000..bede06dba --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/mapper/WxBillRentManageMapper.java @@ -0,0 +1,32 @@ +package com.iformall.mapper; + +import com.iformall.common.CommonMapper; +import com.iformall.domain.po.WxBillRentManage; + +import java.util.List; +import java.util.Map; + +import org.apache.ibatis.annotations.Param; + +/** + * @author gongbiao + */ +public interface WxBillRentManageMapper extends CommonMapper { + + List findList(WxBillRentManage wxBillRentManage); + + List queryBillManageList(WxBillRentManage wxBillRentManage); + + Map queryPayInfoTotal(Map params); + + void updateNotPaidStatus(Map params); + + void updateWaitPayStatus(Map params); + + void deletePreviewBill(WxBillRentManage wxBillRentManage); + + long oweBillCount(@Param("contractId") Long contractId); + + void insertBills(List resultList); + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java index 220df7b17..a9793c3fe 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java @@ -216,6 +216,16 @@ public class WxBillAllServiceImpl implements WxBillAllService { } else if (wxBillAll.getBillTypeValue().equals(EnumBillQueryType.OTHER_DEPOSIT.getCode())) { wxBillAll.setBillTypeValue(EnumBillQueryType.OTHER_DEPOSIT.getCode()); retList = wxBillAllMapper.listOtherDepositBill(wxBillAll); + }else if (wxBillAll.getBillTypeValue().equals(EnumBillQueryType.RENT_BUSSINESS_MANAGE.getCode())) { + wxBillAll.setBillTypeValue(EnumBillQueryType.RENT_BUSSINESS_MANAGE.getCode()); + wxBillAll.setManageFeeType(EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE.getCode()); + wxBillAll.setBillTypeName(EnumBillQueryType.RENT_BUSSINESS_MANAGE.getMessage()); + retList = wxBillAllMapper.listRentManageBill(wxBillAll); + }else if (wxBillAll.getBillTypeValue().equals(EnumBillQueryType.RENT_OPERATING_MANAGE.getCode())) { + wxBillAll.setBillTypeValue(EnumBillQueryType.RENT_OPERATING_MANAGE.getCode()); + wxBillAll.setManageFeeType(EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE.getCode()); + wxBillAll.setBillTypeName(EnumBillQueryType.RENT_OPERATING_MANAGE.getMessage()); + retList = wxBillAllMapper.listRentManageBill(wxBillAll); } else { logger.info("账单不存在"); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java index 04099dabd..faf3d7773 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -127,6 +127,9 @@ public class WxRentContractServiceImpl implements WxRentContractService { @Autowired WxShopService wxShopService; + @Autowired + WxBillRentManageMapper wxBillRentManageMapper; + // @Override // public Map listAsPage(WxRentContract record, Integer pageIndex, Integer pageSize) { // //Object rentContractStatusInfo = getRentContractStatusInfo(record); @@ -578,6 +581,16 @@ public class WxRentContractServiceImpl implements WxRentContractService { && !record.getReceivePeriod().equals(0) && !record.getLease().equals(0)) { //删除预账单,重新生成 wxBillRentMapper.deletePreviewBill(record); + //删除商业管理费账单 + WxBillRentManage wxBillRentManage = new WxBillRentManage(); + wxBillRentManage.setRentContractId(record.getId()); + wxBillRentManage.setManageFeeType(EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE.getCode()); + wxBillRentManageMapper.deletePreviewBill(wxBillRentManage); + //删除营业管理费账单 + wxBillRentManage.setManageFeeType(EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE.getCode()); + wxBillRentManageMapper.deletePreviewBill(wxBillRentManage); + + //联营扣点,不设置保底营业额,不生成账单 //if (EnumRentContractType.RENT_BY_JOINT.getCode().equals(record.getType()) && record.getRevenueRatio().equals(0)) { @@ -592,6 +605,10 @@ public class WxRentContractServiceImpl implements WxRentContractService { //保存调整金额(预账单调整) //if (saveBill) { savePreviewBill(record); + //保存商业管理费账单 + savePreviewManageFeeBill(record,EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE); + //保存营业管理费账单 + savePreviewManageFeeBill(record,EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE); //} WxRentContract wxRentContract = (WxRentContract)resultData.data; @@ -646,6 +663,62 @@ public class WxRentContractServiceImpl implements WxRentContractService { } wxBillRentMapper.insertBills(record.getPreviewBillRentList()); } + + /** + * 重新生成其他管理费用账单(预账单调整) + */ + private void savePreviewManageFeeBill(WxRentContract record,EnumRentContractManageFeeType feeType){ + if(CollectionUtils.isEmpty(record.getPreviewBillRentList())){ + return; + } + WxBillRentManage wxBillRentManage = new WxBillRentManage(); + wxBillRentManage.setRentContractId(record.getId()); + wxBillRentManage.setManageFeeType(feeType.getCode()); + wxBillRentManageMapper.deletePreviewBill(wxBillRentManage); + WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(record); + final IdWorker idWorker = IdWorker.get(); + int count = 1; + List shopIds = record.shopIdsByRentInfo(); + List billList = new ArrayList(); + for (WxBillRent _bi:record.getPreviewBillRentList()) { + WxBillRentManage bill = new WxBillRentManage(); + bill.setId(idWorker.nextId()); + Date date = new Date(); + bill.setRentContractId(record.getId()); + bill.setCreatetime(date); + bill.updateTenantInfo(record); + bill.setManageFeeType(feeType.getCode()); + if (feeType.getCode() == EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE.getCode()) { + bill.setNeedPay(_bi.getBussinessManageFeeNeedPay()); + }else if (feeType.getCode() == EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE.getCode()) { + bill.setNeedPay(_bi.getOperatingManageFeeNeedPay()); + } + bill.setUpdatetime(date); + bill.setRentShopType(record.getRentShopType()); + bill.setPeriod(count); + bill.setShopInfo(getShopInfoStr(record)); + bill.setLatePayRatio(0); + bill.setPay(0L); + bill.setIsDel(EnumDelStatus.NOT_DEL.getCode()); + if (null != shopIds && shopIds.size() == 1) { + bill.setShopId(shopIds.get(0)); + } + setManageExpiredDay(bill,Calendar.MONTH,record.getReceivePeriod()); + if (bill.getReceivePay().equals(0L)) { + bill.setStatus(EnumBillRentStatus.PAID.getCode()); + bill.setPayDate(date); + } + //计算手续费 + BigDecimal servicePay = new BigDecimal(bill.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP); + bill.setServiceChargePay(servicePay.intValue()); + bill.setOwe(bill.getReceivePay() + bill.getServiceChargePay()); + count++; + billList.add(bill); + } + if (billList.size() > 0 ) { + wxBillRentManageMapper.insertBills(billList); + } + } public ResultData getResultDataForUpdate(WxRentContract record, Long userId,int from,Date oldRentStartDate,boolean writeFinal) { //更新租赁合同信息 @@ -841,6 +914,72 @@ public class WxRentContractServiceImpl implements WxRentContractService { } } } + + private void buildBussinessManagementFee( Long userId,WxRentContract wxRentContract) { + if (wxRentContract != null && wxRentContract.getBussinessManagementFee() > 0) { + final IdWorker idWorker = IdWorker.get(); + WxBillDeposit wxBillDeposit = new WxBillDeposit(); + wxBillDeposit.setId(idWorker.nextId()); + wxBillDeposit.setRentContractId(wxRentContract.getId()); + wxBillDeposit.setPay(0L); + long needpay = wxRentContract.getDeposit(); + wxBillDeposit.setReceivePay(needpay); + wxBillDeposit.setNeedPay(needpay); + wxBillDeposit.setOwe(needpay); + //找到计租方式 + int dayType = wxRentContract.getAdjustPeriod().equals(EnumRentContractAdjustPeriod.ADJUST_PERIOD_DAY.getCode()) ? Calendar.DAY_OF_MONTH : Calendar.MONTH; + + Date date = new Date(); + Calendar instance = Calendar.getInstance(); + instance.setTime(wxRentContract.getRentalStartDate()); + instance.add(Calendar.DAY_OF_MONTH, -1); + Date time = instance.getTime(); + wxBillDeposit.setReceiveDate(time); + + //账单开始时间 + instance.clear(); + instance.setTime(wxBillDeposit.getReceiveDate()); + instance.add(Calendar.DAY_OF_MONTH, 1); + wxBillDeposit.setStarttime(instance.getTime()); + //账单结束时间 + instance.clear(); + instance.setTime(wxBillDeposit.getReceiveDate()); + instance.add(dayType, wxRentContract.getLease()); + wxBillDeposit.setEndtime(instance.getTime()); + wxBillDeposit.setStatus(EnumBillRentStatus.WAIT_PAY.getCode()); + wxBillDeposit.setExpiredDay(0L); + wxBillDeposit.setReceiveDate(time); + wxBillDeposit.updateTenantInfo(wxRentContract); + wxBillDeposit.setIsDel(0); + wxBillDeposit.setMerchantId(wxRentContract.getMerchantId()); + wxBillDeposit.setUserId(userId); + if (wxRentContract.shopIdsByRentInfo().size()==1) { + wxBillDeposit.setShopId(wxRentContract.shopIdsByRentInfo().get(0)); + } + wxBillDeposit.setCreatetime(date); + wxBillDeposit.setUpdatetime(date); + wxBillDeposit.setIsDel(EnumDelStatus.NOT_DEL.getCode()); + wxBillDeposit.setRentShopType(wxRentContract.getRentShopType()); + if (wxRentContract.getRentShopType().equals(EnumRentShopType.SHOP.getCode())) { + String rentInfo = wxRentContract.getRentInfo(); + if (rentInfo != null) { + JSONArray rentInfoArray = JSONArray.parseArray(rentInfo); + Map shopInfo = new HashMap<>(); + for (int i = 0, size = rentInfoArray.size(); i < size; i++) { + JSONObject rentInfoObject = rentInfoArray.getJSONObject(i); + shopInfo.put(rentInfoObject.getString("shopNumber"), rentInfoObject.get("deposit")); + } + wxBillDeposit.setShopInfo(JSONObject.toJSONString(shopInfo)); + } + } + try { + wxBillDepositMapper.insert(wxBillDeposit); + } catch (Exception e) { + logger.error("添加押金账单失败,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + } + } @Override public Object getMerchants(WxRentContract wxRentContract) { @@ -1449,7 +1588,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { wxBillRent.setRentPriceInfo(getRentPriceInfo(wxRentContract,needpay)); wxBillRent.setNeedPay(needpay); wxBillRent.setOwe(needpay); - wxBillRent.setReceivePay(bussinessManageFeeNeedpay+operatingManageFeeNeedpay+needpay); + wxBillRent.setReceivePay(needpay); //商业管理费 wxBillRent.setBussinessManageFeeNeedPay(bussinessManageFeeNeedpay); //运营管理费 @@ -1511,6 +1650,29 @@ public class WxRentContractServiceImpl implements WxRentContractService { } } } + + public void setManageExpiredDay(WxBillRentManage wxBillRentManage,int dayType, int receivePeriod){ + //截止收租日在当前时间之前 + Date date = new Date(); + wxBillRentManage.setExpiredDay(0L); + if (wxBillRentManage.getReceiveDate().before(date)) { + long day = (date.getTime() - wxBillRentManage.getReceiveDate().getTime()) / (24 * 60 * 60 * 1000); + wxBillRentManage.setStatus(EnumBillRentStatus.NOT_PAID.getCode()); + if (day > 0) { + wxBillRentManage.setExpiredDay(day); + } + } else {//截止收租日在当前时间之后 + Calendar now = Calendar.getInstance(); + now.add(dayType, receivePeriod); + Date currenttime = now.getTime(); + //当前日期加上周期后小于截止收租日就是没有到期,否则当前待缴 + if (currenttime.before(wxBillRentManage.getReceiveDate())) { + wxBillRentManage.setStatus(EnumBillRentStatus.NOT_EXPIRED.getCode()); + } else { + wxBillRentManage.setStatus(EnumBillRentStatus.WAIT_PAY.getCode()); + } + } + } @Transactional(rollbackFor = {Exception.class}) @Override @@ -1722,6 +1884,10 @@ public class WxRentContractServiceImpl implements WxRentContractService { // 保存调整金额(预账单调整) if(!CollectionUtils.isEmpty(record.getPreviewBillRentList())){ savePreviewBill(record); + //保存商业管理费账单 + savePreviewManageFeeBill(record,EnumRentContractManageFeeType.RENT_BUSSINESS_MANAGE_FEE); + //保存营业管理费账单 + savePreviewManageFeeBill(record,EnumRentContractManageFeeType.RENT_OPERATING_MANAGE_FEE); } ResultData resultData = getResultDataForUpdate(record, userId,0,oldRentStartDate,writeComplate); // if (resultData.code != Result.SUCCESS) { @@ -1782,6 +1948,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { if (buildProperyBill) { updatePropertyPreviewBill(record); } + //作废合同 //updateInvalidContract(id); } @@ -2334,7 +2501,6 @@ public class WxRentContractServiceImpl implements WxRentContractService { } }else{ - // TODO //double adjustRatio = wxRentContract.getAdjustRatio() != null ? wxRentContract.getAdjustRatio() / 100.0 : 0; result.put("adjustRatio", 0); double priceRent = new BigDecimal(wxRentContract.getPrice()) diff --git a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml index 6b7741802..19cc78135 100644 --- a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml @@ -74,6 +74,7 @@ and bill.freeze = #{freeze} and bill.id = #{id} + and bill.manage_fee_type = #{manageFeeType} and bill.`merchant_id` in @@ -97,6 +98,17 @@ + + + + + select + + from wx_bill_rent_manage + + + + + + + + + update wx_bill_rent_manage b set b.status=#{notPaid},b.expired_day= + DATEDIFF(now(), b.receive_date) + where b.status!=#{paid} and b.status!=6 and + DATEDIFF(now(), b.receive_date) >0 + + and b.`tenant_id` = #{tenantId} + + + and b.`parent_tenant_id` = #{parentTenantId} + + + + + update wx_bill_rent_manage set status=#{waitPay} where id in( + select a.id from (select br.id,rc.receive_period,br.rent_contract_id,br.receive_date from wx_bill_rent_manage br + left join wx_rent_contract rc on br.rent_contract_id=rc.id + where br.status!=#{paid} + + and br.`tenant_id` = #{tenantId} + + + and br.`parent_tenant_id` = #{parentTenantId} + + and br.status!=6 and now() < br.receive_date + and DATE_ADD(now(),INTERVAL 1 MONTH)>br.receive_date) a) + + + + delete from wx_bill_rent_manage where rent_contract_id = #{rentContractId} and manage_fee_type = #{manageFeeType} + + + + + + INSERT INTO wx_bill_rent_manage (id,tenant_id,parent_tenant_id, + rent_contract_id, receive_pay, pay, receive_date, pay_date, createtime, expired_day, + owe, status, is_del, need_pay, merchant_id, user_id, shop_id, updatetime, starttime, endtime, + rent_shop_type, late_pay_ratio, late_pay_time, late_pay_price, period, shop_info, + pay_way, late_pay_status, service_charge_pay,manage_fee_type) + VALUES + + ( + #{item.id},#{item.tenantId},#{item.parentTenantId}, + #{item.rentContractId},#{item.receivePay},#{item.pay},#{item.receiveDate},#{item.payDate},#{item.createtime}, + #{item.expiredDay},#{item.owe},#{item.status},#{item.isDel},#{item.needPay},#{item.merchantId}, + #{item.userId},#{item.shopId},#{item.updatetime},#{item.starttime},#{item.endtime},#{item.rentShopType}, + #{item.latePayRatio},#{item.latePayTime},#{item.latePayPrice},#{item.period},#{item.shopInfo}, + #{item.payWay},#{item.latePayStatus},#{item.serviceChargePay},#{manageFeeType} + ) + + + + +