From 531e05acdaf9946c2b4b263f5a84a73a2cb1a6ff Mon Sep 17 00:00:00 2001 From: zhengfangyuan Date: Mon, 2 Jan 2023 19:59:04 +0800 Subject: [PATCH] fix bug --- .../rent/WxBillRentManageController.java | 139 ++++++++ .../com/iformall/domain/po/WxBillRent.java | 4 +- .../com/iformall/domain/vo/OweMerchantVo.java | 12 +- .../com/iformall/enums/EnumBillTypeParam.java | 5 +- .../enums/EnumRentContractManageFeeType.java | 2 +- .../service/WxBillRentManageService.java | 65 ++++ .../service/impl/WxBillAllServiceImpl.java | 70 +++- .../impl/WxBillRentManageServiceImpl.java | 302 ++++++++++++++++++ .../service/impl/WxBillRentServiceImpl.java | 2 + .../main/resources/mapper/WxBillAllMapper.xml | 48 ++- 10 files changed, 637 insertions(+), 12 deletions(-) create mode 100644 mallinkAdmin/src/main/java/com/iformall/controller/rent/WxBillRentManageController.java create mode 100644 mallinkService/src/main/java/com/iformall/service/WxBillRentManageService.java create mode 100644 mallinkService/src/main/java/com/iformall/service/impl/WxBillRentManageServiceImpl.java diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/rent/WxBillRentManageController.java b/mallinkAdmin/src/main/java/com/iformall/controller/rent/WxBillRentManageController.java new file mode 100644 index 000000000..dee35b698 --- /dev/null +++ b/mallinkAdmin/src/main/java/com/iformall/controller/rent/WxBillRentManageController.java @@ -0,0 +1,139 @@ +package com.iformall.controller.rent; + +import com.github.pagehelper.PageInfo; +import com.iformall.annotation.SystemControllerLog; +import com.iformall.common.Result; +import com.iformall.common.ResultData; +import com.iformall.controller.base.BaseController; +import com.iformall.domain.po.base.BaseEntity; +import com.iformall.enums.EnumRentContractManageFeeType; +import com.iformall.domain.po.WxBillRent; +import com.iformall.domain.po.WxBillRentManage; +import com.iformall.service.WxBillRentManageService; +import com.iformall.service.WxBillRentService; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @author gongbiao + */ +@RestController +@RequestMapping("wxBillRentManage") +public class WxBillRentManageController extends BaseController { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private WxBillRentManageService wxBillRentManageService; + + @GetMapping("list") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) + public ResultData list(@ModelAttribute WxBillRentManage wxBillRentManage, Integer pageNum, Integer pageSize) { + logger.debug("[" + getIpAddr() + "] WxBillRentController::list"); + if (null == wxBillRentManage) { + wxBillRentManage = new WxBillRentManage(); + } + wxBillRentManage.updateTenantInfo(getTenantInfo()); + if (null == wxBillRentManage.getManageFeeType()) { + return new ResultData(Result.ERROR, "参数错误", null); + } + if (null == EnumRentContractManageFeeType.getEnum(wxBillRentManage.getManageFeeType())) { + return new ResultData(Result.ERROR, "参数错误", null); + } + wxBillRentManage.setSortColumns(BaseEntity.SortField.Createtime_DESC,BaseEntity.SortField.Id_DESC); + final PageInfo page = wxBillRentManageService.listAsPage(wxBillRentManage, pageNum, pageSize); + return new ResultData(page); + } + + @GetMapping("/detail") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + public ResultData detail(Long id) { + logger.debug("[" + getIpAddr() + "] WxBillRentController::detail"); + return new ResultData(Result.SUCCESS, "查询成功", wxBillRentManageService.getById(id)); + } + + @PostMapping("add") + @SystemControllerLog(description = "租赁押金账单-新增") + public ResultData add(@RequestBody WxBillRentManage wxBillRentManage) { + logger.debug("[" + getIpAddr() + "] WxBillRentController::add"); + wxBillRentManage.updateTenantInfo(getTenantInfo()); + if (null == wxBillRentManage.getManageFeeType()) { + return new ResultData(Result.ERROR, "参数错误", null); + } + if (null == EnumRentContractManageFeeType.getEnum(wxBillRentManage.getManageFeeType())) { + return new ResultData(Result.ERROR, "参数错误", null); + } + return wxBillRentManageService.saveOrUpdate(wxBillRentManage, getUser()); + } + + @PostMapping("update") + @SystemControllerLog(description = "租赁押金账单-更新") + public ResultData update(@RequestBody WxBillRentManage wxBillRentManage) { + logger.debug("[" + getIpAddr() + "] WxBillRentController::update"); + return wxBillRentManageService.saveOrUpdate(wxBillRentManage, getUser()); + } + + @GetMapping("/findByRentContractId") + @ApiImplicitParams({ + @ApiImplicitParam(name = "rentContractId", value = "合同编号", dataType = "Long", paramType = "query", required = true), + @ApiImplicitParam(name = "manageFeeType", value = "管理费类型", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) + @SystemControllerLog(description = "租赁押金账单-根据商户获取") + public ResultData findByRentContractId(Long rentContractId, Integer manageFeeType,Integer pageNum, Integer pageSize) { + logger.debug("[" + getIpAddr() + "] WxBillRentController::findByRentContractId"); + WxBillRentManage record = new WxBillRentManage(); + record.setRentContractId(rentContractId); + record.updateTenantInfo(getTenantInfo()); + if (null == EnumRentContractManageFeeType.getEnum(manageFeeType)) { + return new ResultData(Result.ERROR, "参数错误", null); + } + record.setManageFeeType(manageFeeType); + final PageInfo page = wxBillRentManageService.findByRentContractId(record, pageNum, pageSize); + return new ResultData(page); + } + + @ApiOperation("修改滞纳金") + @PostMapping("updateLatePayMoney") + @SystemControllerLog(description = "修改滞纳金") + public ResultData updateLatePayMoney(@RequestBody WxBillRentManage wxBillRentManage) { + logger.debug("[" + getIpAddr() + "] WxBillRentController::updateLatePayMoney"); + return wxBillRentManageService.updateLatePayMoney(wxBillRentManage, getUser()); + } + + @GetMapping("/del") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + @SystemControllerLog(description = "租赁押金账单-删除") + public ResultData delete(Long id) { + logger.debug("[" + getIpAddr() + "] WxBillRentController::delete"); + wxBillRentManageService.deleteById(id); + return new ResultData(Result.SUCCESS, "删除成功", null); + } + + @GetMapping("/updatePaid") + @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) + @SystemControllerLog(description = "租赁押金账单-支付更新") + public ResultData updatePaid(Long id) { + logger.debug("[" + getIpAddr() + "] WxBillRentController::updatePaid"); + return wxBillRentManageService.updatePaid(id); + } + + + @PostMapping("updateLatePayStatus") + @SystemControllerLog(description = "租赁押金账单-滞纳金结单") + public ResultData updateLatePayStatus(@RequestBody WxBillRentManage wxBillRent) { + logger.debug("[" + getIpAddr() + "] WxBillRentController::updateLatePayStatus"); + return wxBillRentManageService.updateLatePayStatus(wxBillRent); + } + + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java index ce2ee0eec..3077d3590 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxBillRent.java @@ -121,8 +121,8 @@ public class WxBillRent extends TenantEntity { infoStr += "场地费:" + (StringUtils.isBlank(siteMoney1) ? "0":siteMoney1) + "\n"; String facilityMoney1 = jsonObject.getString("facilityMoney"); infoStr += "设备费:" + (StringUtils.isBlank(facilityMoney1) ? "0":facilityMoney1) + "\n"; - String administratorMoney1 = jsonObject.getString("administratorMoney"); - infoStr += "商业管理费:" + (StringUtils.isBlank(administratorMoney1) ? "0":administratorMoney1); + //String administratorMoney1 = jsonObject.getString("administratorMoney"); + //infoStr += "商业管理费:" + (StringUtils.isBlank(administratorMoney1) ? "0":administratorMoney1); } return infoStr; diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/OweMerchantVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/OweMerchantVo.java index 42194f382..a5d89ae39 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/OweMerchantVo.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/OweMerchantVo.java @@ -15,13 +15,17 @@ public class OweMerchantVo { private String linkPhone; @Excel(name="欠缴租金(元)",width = 20,orderNum = "6") private BigDecimal rentOwe; - @Excel(name="欠缴物业费(元)",width = 20,orderNum = "7") + @Excel(name="欠缴商业管理费(元)",width = 20,orderNum = "7") + private BigDecimal bussinessManageOwe; + @Excel(name="欠缴营业管理费(元)",width = 20,orderNum = "8") + private BigDecimal operatingManageOwe; + @Excel(name="欠缴物业费(元)",width = 20,orderNum = "9") private BigDecimal propertyOwe; - @Excel(name="欠缴押金(元)",width = 20,orderNum = "8") + @Excel(name="欠缴押金(元)",width = 20,orderNum = "10") private BigDecimal depositOwe; - @Excel(name="其他费用(元)",width = 20,orderNum = "9") + @Excel(name="其他费用(元)",width = 20,orderNum = "11") private BigDecimal otherOwe; - @Excel(name="欠缴总额(元)",width = 20,orderNum = "10") + @Excel(name="欠缴总额(元)",width = 20,orderNum = "12") private BigDecimal totalOwe; } diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumBillTypeParam.java b/mallinkService/src/main/java/com/iformall/enums/EnumBillTypeParam.java index a7cbb5806..2b7c8e956 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumBillTypeParam.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumBillTypeParam.java @@ -16,8 +16,9 @@ public enum EnumBillTypeParam { ROUTINE(7, "其他费用"), ATHER_DEPOSIT(8, "其他押金"), AIR_CONDITIONING(9, "空调费"), - - SETTLE(10, "结算单") + SETTLE(10, "结算单"), + RENT_BUSSINESS_MANAGE(11,"商业管理费"), + RENT_OPERATING_MANAGE(12,"营业管理费") ; public static EnumBillTypeParam getEnum(Integer code) { diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumRentContractManageFeeType.java b/mallinkService/src/main/java/com/iformall/enums/EnumRentContractManageFeeType.java index c293e0240..69e55a314 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumRentContractManageFeeType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumRentContractManageFeeType.java @@ -2,7 +2,7 @@ package com.iformall.enums; /** * Created by luozukai - * 预览账单0否1是 + * 管理费账单类型 */ public enum EnumRentContractManageFeeType { diff --git a/mallinkService/src/main/java/com/iformall/service/WxBillRentManageService.java b/mallinkService/src/main/java/com/iformall/service/WxBillRentManageService.java new file mode 100644 index 000000000..4987e6ab6 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/WxBillRentManageService.java @@ -0,0 +1,65 @@ +package com.iformall.service; + +import com.github.pagehelper.PageInfo; +import com.iformall.common.ResultData; +import com.iformall.domain.po.MallUserInfo; +import com.iformall.domain.po.WxBillDeposit; +import com.iformall.domain.po.WxBillRent; +import com.iformall.domain.po.WxBillRentManage; +import com.iformall.domain.po.WxPayAccountBill; + +public interface WxBillRentManageService { + + /** + * 根据实体查询分页列表 + * + * @param offset + * @param limit + * @param record + * @return + */ + PageInfo listAsPage(WxBillRentManage wxBillRentManage, Integer pageIndex, Integer pageSize); + + void updateBillStatus(WxBillRentManage record); + + /** + * 根据Id获得实体 + * + * @param id + * @return + */ + WxBillRentManage getById(Long id); + + PageInfo findByRentContractId(WxBillRentManage record, Integer pageIndex, Integer pageSize); + + /** + * 保存或更新实体 + * + * @param record + * @param user + */ + ResultData saveOrUpdate(WxBillRentManage record, MallUserInfo user); + + /** + * 修改滞纳金 + * @param record + * @param user + * @return + */ + ResultData updateLatePayMoney(WxBillRentManage record, MallUserInfo user); + + /** + * 根据Id删除实体 + * + * @param id + */ + void deleteById(Long id); + + ResultData updatePaid(Long id); + + + void computeTotalMoney(WxPayAccountBill wxPayAccountBill, WxBillRentManage deposit); + + ResultData updateLatePayStatus(WxBillRentManage wxBillRent); + +} 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 a9793c3fe..7b50d41ea 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java @@ -161,7 +161,14 @@ public class WxBillAllServiceImpl implements WxBillAllService { @Autowired WxMerchantMapper wxMerchantMapper; - + + @Autowired + WxBillRentManageMapper wxBillRentManageMapper; + + @Lazy + @Autowired + WxBillRentManageService wxBillRentManageService; + @Override public Map listAsPage(WxBillAll record, Integer pageIndex, Integer pageSize) { WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(record); @@ -873,6 +880,11 @@ public class WxBillAllServiceImpl implements WxBillAllService { WxBillRent wxBillRent = new WxBillRent(); wxBillRent.updateTenantInfo(record); wxBillRentService.updateBillStatus(wxBillRent); + //更新管理费账单状态 + WxBillRentManage wxBillRentManage = new WxBillRentManage(); + wxBillRentManage.updateTenantInfo(record); + wxBillRentManageService.updateBillStatus(wxBillRentManage); + logger.info("更新各账单状态结束"); } @@ -927,6 +939,21 @@ public class WxBillAllServiceImpl implements WxBillAllService { if(!rentList.isEmpty()){ rentSum = rentList.stream().collect(Collectors.summingLong(b -> status == null && filterHasPay == null ? b.getReceivePay() + b.getLatePayPrice() + b.getServiceChargePay() : b.getOwe())); } + //商业管理费 + wxBillAll.setBillTypeValue(EnumBillQueryType.RENT_BUSSINESS_MANAGE.getCode()); + List bmList = this.list(wxBillAll); + Long bussinessManageSum = 0L; + if(!bmList.isEmpty()){ + bussinessManageSum = bmList.stream().collect(Collectors.summingLong(b -> status == null && filterHasPay == null ? b.getReceivePay() + b.getLatePayPrice() + b.getServiceChargePay() : b.getOwe())); + } + //营业管理费 + wxBillAll.setBillTypeValue(EnumBillQueryType.RENT_OPERATING_MANAGE.getCode()); + List omList = this.list(wxBillAll); + Long operatingManageSum = 0L; + if(!omList.isEmpty()){ + operatingManageSum = omList.stream().collect(Collectors.summingLong(b -> status == null && filterHasPay == null ? b.getReceivePay() + b.getLatePayPrice() + b.getServiceChargePay() : b.getOwe())); + } + //物业 wxBillAll.setBillTypeValue(EnumBillQueryType.PROPERTY.getCode()); List propertyList = this.list(wxBillAll); @@ -983,8 +1010,11 @@ public class WxBillAllServiceImpl implements WxBillAllService { }); } //总计 - Long summarySum = rentSum + propertySum + depositSum + waterSum + powerSum + airConditioningSum + otherSum; + Long summarySum = rentSum + bussinessManageSum + operatingManageSum + propertySum + depositSum + waterSum + powerSum + airConditioningSum + otherSum; BigDecimal rent = new BigDecimal(rentSum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN); + BigDecimal bussinessManage = new BigDecimal(bussinessManageSum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN); + BigDecimal operatingManage = new BigDecimal(operatingManageSum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN); + BigDecimal property = new BigDecimal(propertySum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN); BigDecimal deposit = new BigDecimal(depositSum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN); BigDecimal water = new BigDecimal(waterSum).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN); @@ -995,6 +1025,8 @@ public class WxBillAllServiceImpl implements WxBillAllService { String summaryUpper = PriceUtil.number2CNMontrayUnit(summary); result.put("rent", rent.toPlainString()); + result.put("bussinessManage", bussinessManage.toPlainString()); + result.put("operatingManage", operatingManage.toPlainString()); result.put("property", property.toPlainString()); result.put("deposit", deposit.toPlainString()); result.put("water", water.toPlainString()); @@ -1309,6 +1341,36 @@ public class WxBillAllServiceImpl implements WxBillAllService { wxBillOtherDepositMapper.updateById(wxBillOtherDeposit); //账单日志 addBillAction(EnumBillAction.UPDATE_BILL, id, oldPrice, newPrice, user); + }if (billType.equals(EnumBillTypeParam.RENT_BUSSINESS_MANAGE.getCode()) || billType.equals(EnumBillTypeParam.RENT_OPERATING_MANAGE.getCode())) { + WxBillRentManage dbBill = wxBillRentManageMapper.selectById(id); + WxBillRentManage wxBillRent = new WxBillRentManage(); + wxBillRent.setId(id); + wxBillRent.setUpdatetime(updateDate); + if (forcePaid) { + wxBillRent.setReceivePay(dbBill.getPay()); + wxBillRent.setStatus(EnumBillRentStatus.PAID.getCode()); + wxBillRent.setOwe(0L); + wxBillRentManageMapper.updateById(wxBillRent); + addBillAction(EnumBillAction.UPDATE_BILL, id, dbBill.getPay(), dbBill.getPay(), user); + }else { + if (oldLatePrice != null) { + wxBillRent.setLatePayPrice(newLatePrice); + wxBillRent.setOwe(dbBill.getReceivePay() + dbBill.getServiceChargePay() + newLatePrice - dbBill.getPay()); + wxBillRentManageMapper.updateById(wxBillRent); + addBillAction(EnumBillAction.UPDATE_LATE_PAY_MONEY, id, oldLatePrice, newLatePrice, user); + } else { + //租赁账单更新 + wxBillRent.setReceivePay(newPrice); + long latePayPrice = dbBill.getLatePayPrice() == null ? 0 : dbBill.getLatePayPrice(); + wxBillRent.setOwe(newPrice + dbBill.getServiceChargePay() + latePayPrice - dbBill.getPay()); + if (newPrice.equals(dbBill.getPay())) { + wxBillRent.setStatus(EnumBillRentStatus.PAID.getCode()); + } + wxBillRentManageMapper.updateById(wxBillRent); + //账单日志 + addBillAction(EnumBillAction.UPDATE_BILL, id, oldPrice, newPrice, user); + } + } } else { logger.info("未找到账单类型"); } @@ -1970,6 +2032,8 @@ public class WxBillAllServiceImpl implements WxBillAllService { List> list = pageInfo.getList(); for (Map map : list) { map.put("rentOwe", subZeroAndDot(map.get("rentOwe").toString())); + map.put("bussinessManageOwe", subZeroAndDot(map.get("bussinessManageOwe").toString())); + map.put("operatingManageOwe", subZeroAndDot(map.get("operatingManageOwe").toString())); map.put("propertyOwe", subZeroAndDot(map.get("propertyOwe").toString())); map.put("depositOwe", subZeroAndDot(map.get("depositOwe").toString())); map.put("otherOwe", subZeroAndDot(map.get("otherOwe").toString())); @@ -2045,6 +2109,8 @@ public class WxBillAllServiceImpl implements WxBillAllService { oweMerchantVo.setOtherOwe(new BigDecimal(subZeroAndDot(map.get("otherOwe").toString()))); oweMerchantVo.setPropertyOwe(new BigDecimal(subZeroAndDot(map.get("propertyOwe").toString()))); oweMerchantVo.setRentOwe(new BigDecimal(subZeroAndDot(map.get("rentOwe").toString()))); + oweMerchantVo.setBussinessManageOwe(new BigDecimal(subZeroAndDot(map.get("bussinessManageOwe").toString()))); + oweMerchantVo.setOperatingManageOwe(new BigDecimal(subZeroAndDot(map.get("operatingManageOwe").toString()))); oweMerchantVo.setTotalOwe(new BigDecimal(subZeroAndDot(map.get("totalOwe").toString()))); list.add(oweMerchantVo); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentManageServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentManageServiceImpl.java new file mode 100644 index 000000000..f4b642286 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentManageServiceImpl.java @@ -0,0 +1,302 @@ +package com.iformall.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.iformall.common.ErrorCode; +import com.iformall.common.IdWorker; +import com.iformall.common.Result; +import com.iformall.common.ResultData; +import com.iformall.domain.po.MallUserInfo; +import com.iformall.domain.po.WxBillAction; +import com.iformall.domain.po.WxBillDeposit; +import com.iformall.domain.po.WxBillRent; +import com.iformall.domain.po.WxBillRentManage; +import com.iformall.domain.po.WxPayAccountBill; +import com.iformall.enums.EnumBillAction; +import com.iformall.enums.EnumBillDailyStatus; +import com.iformall.enums.EnumBillPayWay; +import com.iformall.enums.EnumBillRentStatus; +import com.iformall.enums.EnumDelStatus; +import com.iformall.exception.MallinkException; +import com.iformall.mapper.WxBillActionMapper; +import com.iformall.mapper.WxBillDepositMapper; +import com.iformall.mapper.WxBillRentManageMapper; +import com.iformall.service.WxBillActionService; +import com.iformall.service.WxBillDepositService; +import com.iformall.service.WxBillRentManageService; +import com.iformall.service.WxPayAccountBillService; +import com.iformall.utils.DateUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author gongbiao + */ +@Service +public class WxBillRentManageServiceImpl implements WxBillRentManageService { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxBillRentManageMapper wxBillRentManageMapper; + + @Autowired + WxPayAccountBillService wxPayAccountBillService; + + @Autowired + WxBillActionService wxBillActionService; + + @Autowired + WxBillActionMapper wxBillActionMapper; + + @Override + public PageInfo listAsPage(WxBillRentManage wxBillRentManage, Integer pageIndex, Integer pageSize) { + PageHelper.startPage(pageIndex, pageSize); + List billDepositList = wxBillRentManageMapper.queryBillManageList(wxBillRentManage); + PageInfo pageInfo = new PageInfo<>(billDepositList); + return pageInfo; + } + + @Override + public ResultData saveOrUpdate(WxBillRentManage record, MallUserInfo user) { + int receivepay = record.getRealReceivePay() == null ? 0 : record.getRealReceivePay().intValue(); + int pay = record.getPay()==null?0:record.getPay().intValue(); + if(pay>receivepay){ + return new ResultData(ErrorCode.BILL_PAY_ERROR.getCode(), "实收金额不能大于实际应收总金额"); + } + Date date = new Date(); + if (record.getId() == null) { + final IdWorker idWorker = IdWorker.get(); + record.setId(idWorker.nextId()); + record.setCreatetime(date); + record.setUpdatetime(date); + record.setOwe(record.getReceivePay()-record.getPay()); + record.setIsDel(EnumDelStatus.NOT_DEL.getCode()); + try { + wxBillRentManageMapper.insert(record); + } catch (Exception e) { + logger.error("保存租赁账单失败,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + return new ResultData(Result.SUCCESS, "保存租赁账单成功"); + } else { + logger.info("更新租赁账单"); + WxBillRentManage wxBillRent = wxBillRentManageMapper.selectById(record.getId()); + if(wxBillRent==null){ + return new ResultData(ErrorCode.BILL_RENT_IS_NOT_FOUND); + } + + String price = ""; + String message =""; + if(record.getServiceChargePayUpdate() != null){ + Double l = Double.valueOf(record.getServiceChargePayUpdate())*100; + wxBillRent.setServiceChargePay(l.intValue()); + long latePayPrice = wxBillRent.getLatePayPrice() == null ? 0 : wxBillRent.getLatePayPrice(); + wxBillRent.setOwe(wxBillRent.getReceivePay() + latePayPrice + wxBillRent.getServiceChargePay() - wxBillRent.getPay()); + }else{ + Long addpay = wxBillRent.getPay(); + wxBillRent.setLatePayRatio(record.getLatePayRatio()); + wxBillRent.setLatePayTime(record.getLatePayTime()); + wxBillRent.setLatePayStatus(record.getLatePayStatus()); + wxBillRent.setPay(record.getPay()); + wxBillRent.setReceivePay(record.getReceivePay()); + wxBillRent.setOwe(record.getRealReceivePay() - record.getPay()); + if (record.getPay().equals(record.getRealReceivePay())) { + wxBillRent.setStatus(EnumBillRentStatus.PAID.getCode()); + Date payDate = record.getPayDate(); + Date receiveDate = wxBillRent.getReceiveDate(); + wxBillRent.setExpiredDay(0L); + if (payDate.after(receiveDate)) { + int expiredDay = DateUtils.daysBetween(receiveDate, payDate); + wxBillRent.setExpiredDay((long) expiredDay); + } + } + wxBillRent.setPayDate(record.getPayDate()); + wxBillRent.setUpdatetime(date); + wxBillRent.setPayWay(record.getPayWay()); + price = new BigDecimal(record.getPay() - addpay).divide(new BigDecimal(100)).toPlainString(); + } + + try { + wxBillRentManageMapper.updateById(wxBillRent); + } catch (Exception e) { + logger.error("更新租赁账单失败,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + //日志 + WxBillAction wxBillAction = new WxBillAction(); + wxBillAction.setBillId(wxBillRent.getId()); + if(record.getServiceChargePayUpdate() != null){ + wxBillAction.setDetails(record.getServiceChargePayBefore()+"元变更为" +record.getServiceChargePayUpdate()+"元"); + wxBillAction.setAction(EnumBillAction.UPDATE_SERVICE_MONEY.getCode()); + }else{ + wxBillAction.setAction(EnumBillAction.OFFLINE_PAY.getCode()); + message = EnumBillPayWay.getEnum(record.getPayWay()).getMessage(); + wxBillAction.setDetails(message + price + "元"); + } + wxBillAction.setUserId(user.getId()); + wxBillAction.setUserName(user.getName()); + wxBillAction.setPhone(user.getPhone()); + wxBillAction.updateTenantInfo(wxBillRent); + wxBillAction.setPayDate(wxBillRent.getPayDate()); + try { + wxBillActionService.save(wxBillAction); + } catch (Exception e) { + logger.error("添加租赁账单行为日志,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + return new ResultData(Result.SUCCESS, "更新租赁账单成功", wxBillRent); + } + } + + @Override + public WxBillRentManage getById(Long id) { + WxBillRentManage record = new WxBillRentManage(); + record.setId(id); + return wxBillRentManageMapper.queryBillManageList(record).get(0); + } + + @Override + public PageInfo findByRentContractId(WxBillRentManage record, Integer pageIndex, Integer pageSize) { + WxPayAccountBill wxPayAccountBill = wxPayAccountBillService.getByTenantInfo(record); + PageHelper.startPage(pageIndex, pageSize); + List billRentList = wxBillRentManageMapper.queryBillManageList(record); + billRentList.stream().forEach(e->{ + //手续费 = 合同应收+手续费+滞纳金 + computeTotalMoney(wxPayAccountBill, e); + }); + PageInfo pageInfo = new PageInfo<>(billRentList); + return pageInfo; + } + + @Override + public void computeTotalMoney(WxPayAccountBill wxPayAccountBill, WxBillRentManage rent) { + if (rent.getReceivePay() != null) { + if (rent.getLatePayPrice() == null) { + rent.setLatePayPrice(0L); + } + BigDecimal servicePay; + if (rent.getServiceChargePay() != null) { + servicePay = new BigDecimal(rent.getServiceChargePay()); + } else { + servicePay = new BigDecimal(rent.getReceivePay()).multiply(new BigDecimal(wxPayAccountBill.getServiceChargeRate())).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_HALF_UP); + } + Long realReceivePay = servicePay.longValue() + rent.getLatePayPrice() + rent.getReceivePay(); + rent.setRealReceivePay(realReceivePay); + rent.setServiceChargePay(servicePay.intValue()); + if (!rent.getStatus().equals(EnumBillRentStatus.NOT_PAID.getCode())) { + rent.setOwe(0L); + } else { + rent.setOwe(realReceivePay - rent.getPay()); + } + } + } + + @Override + public ResultData updateLatePayMoney(WxBillRentManage record, MallUserInfo user) { + WxBillRentManage rent = wxBillRentManageMapper.selectById(record.getId()); + if(record.getLatePayMoneyUpdate() != null) { + rent.setLatePayPrice(Long.parseLong(record.getLatePayMoneyUpdate()) * 100); + rent.setOwe(rent.getReceivePay() + rent.getLatePayPrice() + rent.getServiceChargePay() - rent.getPay()); + final IdWorker idWorker = IdWorker.get(); + WxBillAction billAction = new WxBillAction(); + billAction.setId(idWorker.nextId()); + billAction.setCreatetime(new Date()); + billAction.setUserName("系统端"); + billAction.setAction(EnumBillAction.UPDATE_LATE_PAY_MONEY.getCode()); + billAction.setBillId(record.getId()); + billAction.setDetails(record.getLatePayMoneyBefore()+"元变更为" +record.getLatePayMoneyUpdate()+"元"); + billAction.setUpdatetime(new Date()); + wxBillActionMapper.insert(billAction); + } + wxBillRentManageMapper.updateById(rent); + return new ResultData(); + } + + @Override + public void updateBillStatus(WxBillRentManage record) { + logger.info("更新租赁押金账单状态开始..."); + //更新逾期天数及状态 + updateNotPaidStatus(record); + //更新待缴的状态 + updateWaidPayStatus(record); + logger.info("更新租赁押金账单状态结束..."); + } + + @Transactional(rollbackFor = {Exception.class}) + public void updateWaidPayStatus(WxBillRentManage record) { + Map params = new HashMap<>(); + params.put("tenantId", record.getTenantId()); + params.put("waitPay", EnumBillRentStatus.WAIT_PAY.getCode()); + params.put("paid", EnumBillRentStatus.PAID.getCode()); + + try { + wxBillRentManageMapper.updateWaitPayStatus(params); + } catch (Exception e) { + logger.error("更新物业待缴账单状态失败,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + } + + + @Transactional(rollbackFor = {Exception.class}) + public void updateNotPaidStatus(WxBillRentManage record) { + Map params = new HashMap<>(); + params.put("tenantId", record.getTenantId()); + params.put("notPaid", EnumBillRentStatus.NOT_PAID.getCode()); + params.put("paid", EnumBillRentStatus.PAID.getCode()); + try { + wxBillRentManageMapper.updateNotPaidStatus(params); + } catch (Exception e) { + logger.error("更新物业欠缴账单状态失败,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + } + + @Override + public void deleteById(Long id) { + wxBillRentManageMapper.deleteById(id); + } + + @Transactional(rollbackFor = {Exception.class}) + @Override + public ResultData updatePaid(Long id) { + WxBillRentManage wxBillDeposit = wxBillRentManageMapper.selectById(id); + if(wxBillDeposit==null){ + return new ResultData(ErrorCode.BILL_RENT_DEPOSIT_IS_NOT_FOUND); + } + wxBillDeposit.setStatus(EnumBillRentStatus.PAID.getCode()); + Date d =new Date(); + wxBillDeposit.setPayDate(d); + wxBillDeposit.setUpdatetime(d); + try { + wxBillRentManageMapper.updateById(wxBillDeposit); + } catch (Exception e) { + logger.error("租赁押金结单失败,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); + } + return new ResultData(Result.SUCCESS, "租赁押金结单成功"); + } + + @Override + public ResultData updateLatePayStatus(WxBillRentManage record) { + record.setLatePayStatus(EnumBillDailyStatus.PAID.getCode()); + record.setUpdatetime(new Date()); + try { + wxBillRentManageMapper.updateById(record); + } catch (Exception e) { + logger.error("修改营业额失败,e:" + e.getMessage()); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "滞纳金结单失败"); + } + return new ResultData(Result.SUCCESS, "滞纳金结单成功", record); + } + +} diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java index c693f82c9..c229fa02e 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxBillRentServiceImpl.java @@ -58,6 +58,8 @@ public class WxBillRentServiceImpl implements WxBillRentService { WxPayAccountBillService wxPayAccountBillService; @Autowired WxBillDepositService wxBillDepositService; + @Autowired + WxBillRentManageMapper wxBillRentManageMapper; @Override public PageInfo listAsPage(WxBillRent record, Integer pageIndex, Integer pageSize) { diff --git a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml index 19cc78135..7cfa3f0a9 100644 --- a/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBillAllMapper.xml @@ -690,15 +690,21 @@ bill.receive_date receiveDate,DATEDIFF(now(),bill.receive_date) expiredDay, round(bill.rentOwe/100,2) rentOwe, + round(bill.bmOwe/100,2) bussinessManageOwe, + round(bill.omOwe/100,2) operatingManageOwe, round(bill.propertyOwe/100,2) propertyOwe, round(bill.depositOwe/100,2) depositOwe, round(bill.otherOwe/100,2) otherOwe, - round((bill.rentOwe+bill.propertyOwe+bill.depositOwe+bill.otherOwe)/100,2) totalOwe, + round((bill.rentOwe+bill.bussinessManageOwe+bill.operatingManageOwe+bill.propertyOwe+bill.depositOwe+bill.otherOwe)/100,2) totalOwe, round((bill.rentReceivePay+bill.rentLatePay+bill.rentServiceChargePay-bill.rentPay)/100,2) rentReceivePay, + round((bill.bmReceivePay+bill.bmLatePay+bill.bmServiceChargePay-bill.bmPay)/100,2) + bussinessManageReceivePay, + round((bill.omReceivePay+bill.omLatePay+bill.omServiceChargePay-bill.omPay)/100,2) + operatingManageReceivePay, round((bill.propertyReceivePay+bill.propertyLatePay+bill.propertyServiceChargePay-bill.propertyPay)/100,2) propertyReceivePay, round((bill.depositReceivePay+bill.depositLatePay+bill.depositServiceChargePay-bill.depositPay)/100,2) @@ -712,6 +718,8 @@ round((bill.rentReceivePay+bill.rentLatePay+bill.rentServiceChargePay)/100,2) rentReceivePay, + round((bill.bmReceivePay+bill.bmLatePay+bill.bmServiceChargePay)/100,2) bussinessManageReceivePay, + round((bill.omReceivePay+bill.omLatePay+bill.omServiceChargePay)/100,2) operatingManageReceivePay, round((bill.propertyReceivePay+bill.propertyLatePay+bill.propertyServiceChargePay)/100,2) propertyReceivePay, round((bill.depositReceivePay+bill.depositLatePay+bill.depositServiceChargePay)/100,2) @@ -728,26 +736,36 @@ select oweList.*, max(case oweList.bill_type when '租金' then oweList.owe else 0 end) rentOwe, + max(case oweList.bill_type when '商业管理费' then oweList.owe else 0 end) bmOwe, + max(case oweList.bill_type when '营业管理费' then oweList.owe else 0 end) omOwe, max(case oweList.bill_type when '物业费' then oweList.owe else 0 end) propertyOwe, max(case oweList.bill_type when '欠缴押金' then oweList.owe else 0 end) depositOwe, max(case oweList.bill_type when '其他费用' then oweList.owe else 0 end) otherOwe, max(case oweList.bill_type when '租金' then oweList.receive_pay else 0 end) rentReceivePay, + max(case oweList.bill_type when '商业管理费' then oweList.receive_pay else 0 end) bmReceivePay, + max(case oweList.bill_type when '营业管理费' then oweList.receive_pay else 0 end) omReceivePay, max(case oweList.bill_type when '物业费' then oweList.receive_pay else 0 end) propertyReceivePay, max(case oweList.bill_type when '欠缴押金' then oweList.receive_pay else 0 end) depositReceivePay, max(case oweList.bill_type when '其他费用' then oweList.receive_pay else 0 end) otherReceivePay, max(case oweList.bill_type when '租金' then oweList.pay else 0 end) rentPay, + max(case oweList.bill_type when '商业管理费' then oweList.pay else 0 end) bmPay, + max(case oweList.bill_type when '营业管理费' then oweList.pay else 0 end) omPay, max(case oweList.bill_type when '物业费' then oweList.pay else 0 end) propertyPay, max(case oweList.bill_type when '欠缴押金' then oweList.pay else 0 end) depositPay, max(case oweList.bill_type when '其他费用' then oweList.pay else 0 end) otherPay, max(case oweList.bill_type when '租金' then oweList.latePayPrice else 0 end) rentLatePay, + max(case oweList.bill_type when '商业管理费' then oweList.latePayPrice else 0 end) bmLatePay, + max(case oweList.bill_type when '营业管理费' then oweList.latePayPrice else 0 end) omtLatePay, max(case oweList.bill_type when '物业费' then oweList.latePayPrice else 0 end) propertyLatePay, max(case oweList.bill_type when '欠缴押金' then oweList.latePayPrice else 0 end) depositLatePay, max(case oweList.bill_type when '其他费用' then oweList.latePayPrice else 0 end) otherLatePay, max(case oweList.bill_type when '租金' then oweList.serviceChargePay else 0 end) rentServiceChargePay, + max(case oweList.bill_type when '商业管理费' then oweList.serviceChargePay else 0 end) bmServiceChargePay, + max(case oweList.bill_type when '营业管理费' then oweList.serviceChargePay else 0 end) omServiceChargePay, max(case oweList.bill_type when '物业费' then oweList.serviceChargePay else 0 end) propertyServiceChargePay, max(case oweList.bill_type when '欠缴押金' then oweList.serviceChargePay else 0 end) depositServiceChargePay, max(case oweList.bill_type when '其他费用' then oweList.serviceChargePay else 0 end) otherServiceChargePay @@ -769,6 +787,34 @@ and `parent_tenant_id` = #{parentTenantId} + union all + select id,merchant_id,shop_id,tenant_id,parent_tenant_id,'商业管理费' name,11 bill_type_value,'商业管理费' + bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') + receive_date,pay_date,expired_day,status,'' starttime,'' + endtime,rent_shop_type,late_pay_price,service_charge_pay from wx_bill_rent_manage + where manage_fee_type = 1 + + and `tenant_id` = #{tenantId} + + + and `parent_tenant_id` = #{parentTenantId} + + + + union all + select id,merchant_id,shop_id,tenant_id,parent_tenant_id,'营业管理费' name,12 bill_type_value,'营业管理费' + bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') + receive_date,pay_date,expired_day,status,'' starttime,'' + endtime,rent_shop_type,late_pay_price,service_charge_pay from wx_bill_rent_manage + where manage_fee_type = 2 + + and `tenant_id` = #{tenantId} + + + and `parent_tenant_id` = #{parentTenantId} + + + union all select id,merchant_id,shop_id,tenant_id,parent_tenant_id,'物业费' name,3 bill_type_value,'物业费' bill_type,need_pay,receive_pay,pay,owe,DATE_FORMAT(receive_date,'%Y-%m-%d') receive_date,pay_date,expired_day,status,'' starttime,''