diff --git a/mallinkService/src/main/java/com/iformall/domain/dto/ContractJoinRenevueUpFeesDTO.java b/mallinkService/src/main/java/com/iformall/domain/dto/ContractJoinRenevueUpFeesDTO.java new file mode 100644 index 000000000..0b2e23abd --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/dto/ContractJoinRenevueUpFeesDTO.java @@ -0,0 +1,17 @@ +package com.iformall.domain.dto; + +import java.math.BigDecimal; +import java.util.List; + +import com.iformall.domain.po.base.TenantEntity; + +import lombok.Data; + +/** + */ +@Data +public class ContractJoinRenevueUpFeesDTO extends TenantEntity{ + private static final long serialVersionUID = 7369596648187876295L; + private BigDecimal needPay; + private List billIds; +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxAllBill.java b/mallinkService/src/main/java/com/iformall/domain/po/WxAllBill.java index 60252275c..d6ded7953 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxAllBill.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxAllBill.java @@ -214,11 +214,9 @@ public class WxAllBill extends TenantEntity { } - @Excel(name = "状态", replace = {"欠缴_1", "待缴_2", "已结清_3", "未到期_4", "已退还_5", "失效_6", "坏账_7", "退租待结算_8","预收待抵扣_9"}, width = 20, orderNum = "10") - @io.swagger.annotations.ApiModelProperty(value = "账单状态EnumBillStatus", name = "status") - public Integer status; - @TableField(exist = false) - public List statusList; + @Excel(name = "是否已删除", width = 20, orderNum = "10") + @io.swagger.annotations.ApiModelProperty(value = "是否已删除EnumYesOrNo", name = "isDel") + public Integer isDel; @io.swagger.annotations.ApiModelProperty(value = "费用科目", name = "energyFeesId") public Long energyFeesId; @@ -283,6 +281,9 @@ public class WxAllBill extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value = "账单额外生成来源EnumBillExtraCreateFrom", name = "extraCreateFrom") private Integer extraCreateFrom; + @io.swagger.annotations.ApiModelProperty(value = "是否参与扣点计算EnumYesOrNo", name = "isJoinRenevue") + private Integer isJoinRenevue; + @io.swagger.annotations.ApiModelProperty(value = "计费面积", name = "rentArea") private String rentArea; @@ -399,4 +400,6 @@ public class WxAllBill extends TenantEntity { private String queryShopIdStr; @TableField(exist = false) private Long orginContractId; + @TableField(exist = false) + private Integer queryNeedHuiSuanBills; } diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxAllBillMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxAllBillMapper.java index 5abb40a9d..197702e7b 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxAllBillMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxAllBillMapper.java @@ -16,6 +16,7 @@ import java.util.List; public interface WxAllBillMapper extends CommonMapper { List findList(WxAllBill wxBillRent); + List findIdList(WxAllBill wxBillRent); List queryBillRentContractIdList(WxAllBill record); List findContractSamePeriodSum(WxAllBill wxBillRent); @@ -36,6 +37,9 @@ public interface WxAllBillMapper extends CommonMapper { Integer countValidBillCountByRentHuiSuan(WxAllBill wxBillRent); void deleteByRentReveneuSales(WxAllBill wxBillRent); + void setIsDel(@Param("tenantId")String tenantId, @Param("list")List ids, @Param("isDel")Integer isDel,@Param("oldIsDel")Integer oldIsDel); + void setIsJoinRenevue(@Param("tenantId")String tenantId, @Param("isJoinRenevue")Integer isJoinRenevue, @Param("feesId")Long feesId,@Param("rentContractId")Long rentContractId); + void updatePreviewStatus(WxAllBill record); void insertBills(@Param("tenantId")String tenantId, @Param("list")List resultList); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxAgileContractServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxAgileContractServiceImpl.java index 3269b5e12..68d2c6eb7 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxAgileContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxAgileContractServiceImpl.java @@ -975,9 +975,13 @@ public class WxAgileContractServiceImpl implements WxAgileContractService { return wxRentContractRevenueJumpMapper.findList(jump); } + @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) @Override public void setJoinRenevueUp(WxRentContractAgileUnDeposit unDeposit) { wxRentContractAgileUnDepositMapper.updateJoinRenevueUp(unDeposit); + //设置款项账单是否参与提成计算。 + WxRentContractAgileUnDeposit aud = wxRentContractAgileUnDepositMapper.selectById(unDeposit.getId(),unDeposit.getTenantId()); + wxAllBillMapper.setIsJoinRenevue(aud.getTenantId(),unDeposit.getJoinRenevueUp(),aud.getFeesId(),aud.getRentContractId()); } @Override 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 194405ae8..2e3688361 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java @@ -10,6 +10,7 @@ import com.iformall.common.IdWorker; import com.iformall.common.Result; import com.iformall.common.ResultData; import com.iformall.common.SysConfigConstant; +import com.iformall.domain.dto.ContractJoinRenevueUpFeesDTO; import com.iformall.domain.po.MallUserInfo; import com.iformall.domain.po.SysConfig; import com.iformall.domain.po.WxAllBill; @@ -1027,23 +1028,42 @@ public class WxRentContractServiceImpl implements WxRentContractService { }else { sb.append("跳点规则计算金额:"+jumppay.toPlainString()+",扣点规则计算金额:"+needpay+"."); } - BigDecimal uneedPay = getJoinRenevueUpFeesReceivePayTotal(rentcontract,startime,endtime,true); - if (null != uneedPay && uneedPay.compareTo(new BigDecimal(0)) > 0 ){ - sb.append("参与取高款项计算金额:"+uneedPay.toPlainString()); - if (uneedPay.compareTo(new BigDecimal(needpay)) > 0 ) { - needpay = uneedPay.toPlainString(); + boolean createNewBill = true; + ContractJoinRenevueUpFeesDTO dto = getJoinRenevueUpFeesReceivePayTotal(rentcontract,startime,endtime); + if (null != dto) { + BigDecimal uneedPay = dto.getNeedPay(); + if (null != uneedPay && uneedPay.compareTo(new BigDecimal(0)) > 0 ){ + sb.append("参与取高款项计算金额:"+uneedPay.toPlainString()); + if (uneedPay.compareTo(new BigDecimal(needpay)) >= 0 ) { + //取高比扣点高 + createNewBill = false; + needpay = uneedPay.toPlainString(); + //此处取高的比提成高,如果之前有将参与取高的账单设置为已删除,则需要恢复 + wxAllBillMapper.setIsDel(rentcontract.getTenantId(),dto.getBillIds(),EnumYesOrNo.NO.getCode(),EnumYesOrNo.YES.getCode()); + }else { + //取高比扣点低 + if (null != dto.getBillIds() && dto.getBillIds().size() > 0 ) { + //如果提成的比参与取高的款项高,将这些参与取高的账单设置为已删除 + wxAllBillMapper.setIsDel(rentcontract.getTenantId(),dto.getBillIds(),EnumYesOrNo.YES.getCode(),null); + } + } + }else { + //无取高费用 + if (null != dto.getBillIds() && dto.getBillIds().size() > 0 ) { + //如果提成的比参与取高的款项高,将这些参与取高的账单设置为已删除 + wxAllBillMapper.setIsDel(rentcontract.getTenantId(),dto.getBillIds(),EnumYesOrNo.YES.getCode(),null); + } } + sb.append("取高后总金额为:["+needpay+"]."); } - - sb.append("取高后总金额为:["+needpay+"]."); //保存销售额 addRevenueSales(rentcontract,startime,endtime,needpay,sales,saleDecimalValid); - return handleBills(user,sb,rentcontract,needpay,startime,endtime,EnumBillExtraCreateFrom.RNET_REVENUE_SALES); + return handleBills(createNewBill,user,sb,rentcontract,needpay,startime,endtime,EnumBillExtraCreateFrom.RNET_REVENUE_SALES); } } - private BigDecimal getJoinRenevueUpFeesReceivePayTotal(WxRentContract rentcontract,Date begin,Date end,boolean isEqualTime) { + private ContractJoinRenevueUpFeesDTO getJoinRenevueUpFeesReceivePayTotal(WxRentContract rentcontract,Date begin,Date end) { //如果是取高的,则取高计算 if (rentcontract.getType().intValue() == EnumAgileContractType.RENEVUE_UP.getCode().intValue()) { //查询所有参与取高的款项的账单 @@ -1057,21 +1077,35 @@ public class WxRentContractServiceImpl implements WxRentContractService { udbill.updateTenantInfo(rentcontract); udbill.setRentContractId(rentcontract.getId()); udbill.setIsPreview(EnumYesOrNo.NO.getCode()); + //此处应该查询所有的,因为有可能是是重新录入销售额,之前的账单已经被设位置已删除 + //udbill.setIsDel(EnumYesOrNo.NO.getCode()); udbill.setEnergyFeesIds(udlist); - if (isEqualTime) { - udbill.setStarttimeEqual(begin); - udbill.setEndtimeEqual(end); - }else { - udbill.setStarttime(rentcontract.getYearsBegin()); - udbill.setEndtime(rentcontract.getYearsEnd()); - }; + udbill.setIsJoinRenevue(EnumYesOrNo.YES.getCode()); + udbill.setStarttimeEqual(begin); + udbill.setEndtimeEqual(end); BigDecimal uneedPay = wxAllBillMapper.getReceivePaySum(udbill); - return uneedPay; + ContractJoinRenevueUpFeesDTO dto = new ContractJoinRenevueUpFeesDTO(); + dto.setNeedPay(uneedPay); + dto.setBillIds(wxAllBillMapper.findIdList(udbill)); + return dto; } } return null; } + private BigDecimal getAllRenevueBillsReceivePayTotal(WxRentContract rentcontract,Date begin,Date end) { + WxAllBill udbill = new WxAllBill(); + udbill.updateTenantInfo(rentcontract); + udbill.setRentContractId(rentcontract.getId()); + udbill.setIsPreview(EnumYesOrNo.NO.getCode()); + udbill.setIsDel(EnumYesOrNo.NO.getCode()); + udbill.setQueryNeedHuiSuanBills(EnumYesOrNo.YES.getCode()); + udbill.setStarttime(begin); + udbill.setEndtime(end); + BigDecimal uneedPay = wxAllBillMapper.getReceivePaySum(udbill); + return uneedPay; + } + private void addRevenueSales(WxRentContract rentcontract,Date starttime,Date endtime,String needpay,String sales,BigDecimal saleDecimalValid) { WxRentContractRevenueSales rs = new WxRentContractRevenueSales(); rs.updateTenantInfo(rentcontract); @@ -1103,37 +1137,39 @@ public class WxRentContractServiceImpl implements WxRentContractService { } } - private WxRentContractRevenueSetSalesVo handleBills(MallUserInfo user,StringBuffer sb,WxRentContract rentcontract, String needpay,Date startDate,Date endDate, + private WxRentContractRevenueSetSalesVo handleBills(boolean createNewBill,MallUserInfo user,StringBuffer sb,WxRentContract rentcontract, String needpay,Date startDate,Date endDate, EnumBillExtraCreateFrom createFrom) { - //根据设置的比例海生成对应的账单. - List fees = wxAgileContractService.findRenevueFeesListByContract(rentcontract.getId(), rentcontract); - if (null == fees) { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"没有设置扣点款项"); - } - List shopIdList = rentcontract.shopIdsByRentInfo(); - Map shopAreaRateMap = rentcontract.getRentShopArea(); - WxShopUsers suq = new WxShopUsers(); - suq.updateTenantInfo(rentcontract); - suq.setShopIds(shopIdList); - suq.setStatus(EnumShopUsersStatus.LIVE.getCode()); - Map shopUserMap = wxShopService.getShopUserMap(suq); - WxShop sq = new WxShop(); - sq.updateTenantInfo(sq); - sq.setIds(shopIdList); - Map shopMap = wxShopService.findShopMap(sq); - - List allbill = new ArrayList(); - for (int i = 0 ; i < fees.size(); i++ ) { - WxRentContractAgileRenevueFees fee = fees.get(i); - //更新账单费用 - BigDecimal fneedpay = new BigDecimal(needpay).multiply(new BigDecimal(fee.getRate()).divide(new BigDecimal(100))).setScale(rentcontract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); - List renBill = generateRenevueBill(fee.getFeesId(),user,shopIdList,shopMap,shopUserMap,shopAreaRateMap,rentcontract,fneedpay,fee.getRate(),startDate,endDate,createFrom); - allbill.addAll(renBill); - } - WxRentContractRevenueSetSalesVo vo = new WxRentContractRevenueSetSalesVo(); vo.setTotal(needpay); - vo.setBillList(allbill);; + + if (createNewBill) { + //根据设置的比例海生成对应的账单. + List fees = wxAgileContractService.findRenevueFeesListByContract(rentcontract.getId(), rentcontract); + if (null == fees) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"没有设置扣点款项"); + } + List shopIdList = rentcontract.shopIdsByRentInfo(); + Map shopAreaRateMap = rentcontract.getRentShopArea(); + WxShopUsers suq = new WxShopUsers(); + suq.updateTenantInfo(rentcontract); + suq.setShopIds(shopIdList); + suq.setStatus(EnumShopUsersStatus.LIVE.getCode()); + Map shopUserMap = wxShopService.getShopUserMap(suq); + WxShop sq = new WxShop(); + sq.updateTenantInfo(sq); + sq.setIds(shopIdList); + Map shopMap = wxShopService.findShopMap(sq); + + List allbill = new ArrayList(); + for (int i = 0 ; i < fees.size(); i++ ) { + WxRentContractAgileRenevueFees fee = fees.get(i); + //更新账单费用 + BigDecimal fneedpay = new BigDecimal(needpay).multiply(new BigDecimal(fee.getRate()).divide(new BigDecimal(100))).setScale(rentcontract.getDecimalSize(),BigDecimal.ROUND_HALF_UP); + List renBill = generateRenevueBill(fee.getFeesId(),user,shopIdList,shopMap,shopUserMap,shopAreaRateMap,rentcontract,fneedpay,fee.getRate(),startDate,endDate,createFrom); + allbill.addAll(renBill); + } + vo.setBillList(allbill);; + } return vo; } @@ -1256,12 +1292,12 @@ public class WxRentContractServiceImpl implements WxRentContractService { } } - //查询所有参与取高的账单金额 - BigDecimal receivepay = getJoinRenevueUpFeesReceivePayTotal(rentcontract,rentcontract.getYearsBegin(),rentcontract.getYearsEnd(),false); + //查询未删除的参与扣点计算的非押金账单或者录入销售额生成的账单之和 + BigDecimal receivepay = getAllRenevueBillsReceivePayTotal(rentcontract,rentcontract.getYearsBegin(),rentcontract.getYearsEnd()); if (null == receivepay ){ receivepay = new BigDecimal(0); } - + WxRentContractYearsSumVo vo = new WxRentContractYearsSumVo(); vo.setTotalSales(sum.toPlainString()); vo.setTotalRevenue(jumpRevenuePay.toPlainString()); @@ -1277,7 +1313,7 @@ public class WxRentContractServiceImpl implements WxRentContractService { private WxRentContractRevenueSetSalesVo handelHuiSuanBills(MallUserInfo user,WxRentContract rentcontract,String owe) { StringBuffer sb = new StringBuffer(""); - return handleBills(user,sb,rentcontract,owe,rentcontract.getYearsBegin(),rentcontract.getYearsEnd(),EnumBillExtraCreateFrom.RNET_TIAODIAN_HUISUAN); + return handleBills(true,user,sb,rentcontract,owe,rentcontract.getYearsBegin(),rentcontract.getYearsEnd(),EnumBillExtraCreateFrom.RNET_TIAODIAN_HUISUAN); } diff --git a/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml b/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml index 1bcca2f9d..e9083fbd8 100644 --- a/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml @@ -25,7 +25,6 @@ - @@ -46,14 +45,16 @@ + + `id`,`tenant_id`,`parent_tenant_id`,`shop_id`,`createtime`,`create_by`,`create_by_name`,`updatetime`,`update_by`,`update_by_name`, - `price_detail`,`need_pay`,`receive_pay`,`history_receive_pay`,`pay`,`pay_way`,`pay_date`,`set_off`,`use_money`,`starttime`,`endtime`,`status`,`energy_fees_id`, + `price_detail`,`need_pay`,`receive_pay`,`history_receive_pay`,`pay`,`pay_way`,`pay_date`,`set_off`,`use_money`,`starttime`,`endtime`,`energy_fees_id`, `return_pay`,`bill_remark`,`last_owe_call_time`,`last_owe_call_user`,`receive_date`,`period`, `is_preview`,`shop_info`,`rent_contract_id`,`rent_contract_agile_fees_type`,`parent_bill_id`,`virtual_compose_id`,`parent_virtual_compose_id`, - `energy_reading_calcuteId`,`energy_reading_id`,`extra_create_from`,`rent_area`,`can_edit`,`cus_name`,`fees_type` + `energy_reading_calcuteId`,`energy_reading_id`,`extra_create_from`,`rent_area`,`can_edit`,`cus_name`,`fees_type`,`is_del`,`is_join_renevue` @@ -64,7 +65,8 @@ and `create_by` = #{createBy} and `create_by_name` like concat('%',#{createByName},'%') and `pay_way` = #{payWay} - and `status` = #{status} + and `is_del` = #{isDel} + and `is_join_renevue` = #{isJoinRenevue} and `fees_type` = #{feesType} and `energy_fees_id` = #{energyFeesId} and `rent_contract_id` = #{rentContractId} @@ -108,6 +110,9 @@ and (`last_owe_call_time` is not null and `receive_pay` - `pay`- IFNULL(`set_off`,'0') > 0 ) + + and ( (`is_join_renevue` = 1 and extra_create_from is null ) or extra_create_from = 2 ) + and `parent_bill_id` is not null and `parent_bill_id` is null and `energy_reading_calcuteId` = #{energyReadingCalcuteId} @@ -171,6 +176,11 @@ from wx_all_bill +