Commit 86fc74b8dd3e53fd1e20ec7102cb12f3d5a863d2

Authored by yeqianyong
1 parent dbf33c85

楚江erp:台账报表相关接口开发

  1 +package com.lframework.xingyun.sc.bo.ledger.receipt;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import java.math.BigDecimal;
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * <p>
  11 + * 应收款台账明细 QueryBo
  12 + * </p>
  13 + *
  14 + */
  15 +@Data
  16 +public class ReceiptLedgerReportBo {
  17 +
  18 + /**
  19 + * 额度
  20 + */
  21 + @ApiModelProperty("额度")
  22 + private BigDecimal quota;
  23 +
  24 + /**
  25 + * 结算期限
  26 + */
  27 + @ApiModelProperty("结算期限")
  28 + private String settleTerm;
  29 +
  30 + /**
  31 + * 办事处ID
  32 + */
  33 + @ApiModelProperty("办事处ID")
  34 + private String deptId;
  35 +
  36 + /**
  37 + * 办事处名称
  38 + */
  39 + @ApiModelProperty("办事处名称")
  40 + private String deptName;
  41 +
  42 + /**
  43 + * 区域ID
  44 + */
  45 + @ApiModelProperty("区域ID")
  46 + private String region;
  47 +
  48 + /**
  49 + * 区域名称
  50 + */
  51 + @ApiModelProperty("区域名称")
  52 + private String regionName;
  53 +
  54 + /**
  55 + * 客户类型
  56 + */
  57 + @ApiModelProperty("客户类型")
  58 + private String customerType;
  59 +
  60 + /**
  61 + * 客户简称ID
  62 + */
  63 + @ApiModelProperty("客户简称ID")
  64 + private String customerShortId;
  65 +
  66 + /**
  67 + * 客户简称
  68 + */
  69 + @ApiModelProperty("客户简称")
  70 + private String customerShortName;
  71 +
  72 + /**
  73 + * 报表明细
  74 + */
  75 + @ApiModelProperty("报表明细")
  76 + private List<ReceiptLedgerReportDetail> detailList;
  77 +
  78 + /**
  79 + * 总欠款
  80 + */
  81 + @ApiModelProperty("总欠款")
  82 + private BigDecimal debtTotal;
  83 +
  84 + /**
  85 + * 约定内总欠款
  86 + */
  87 + @ApiModelProperty("约定内总欠款")
  88 + private BigDecimal agreementTotal;
  89 +
  90 + /**
  91 + * 一次协调总欠款
  92 + */
  93 + @ApiModelProperty("一次协调总欠款")
  94 + private BigDecimal firstCoordinateTotal;
  95 +
  96 + /**
  97 + * 二次协调总欠款
  98 + */
  99 + @ApiModelProperty("二次协调总欠款")
  100 + private BigDecimal secondCoordinateTotal;
  101 +
  102 + /**
  103 + * 清欠总欠款
  104 + */
  105 + @ApiModelProperty("清欠总欠款")
  106 + private BigDecimal clearDebtTotal;
  107 +
  108 + /**
  109 + * 授信状态
  110 + */
  111 + @ApiModelProperty("授信状态")
  112 + private String creditStatus;
  113 +
  114 + /**
  115 + * 授时状态
  116 + */
  117 + @ApiModelProperty("总欠款")
  118 + private String timingStatus;
  119 +
  120 + /**
  121 + * 待交付订单总数
  122 + */
  123 + @ApiModelProperty("待交付订单总数")
  124 + private Integer waitDeliveredOrderTotal;
  125 +}
... ...
  1 +package com.lframework.xingyun.sc.bo.ledger.receipt;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import java.math.BigDecimal;
  7 +
  8 +/**
  9 + * <p>
  10 + * 应收款台账明细 QueryBo
  11 + * </p>
  12 + *
  13 + */
  14 +@Data
  15 +public class ReceiptLedgerReportDetail {
  16 +
  17 + /**
  18 + * 客户ID
  19 + */
  20 + @ApiModelProperty("客户ID")
  21 + private String customerId;
  22 +
  23 + /**
  24 + * 客户名称
  25 + */
  26 + @ApiModelProperty("客户名称")
  27 + private String customerName;
  28 +
  29 + /**
  30 + * 总欠款
  31 + */
  32 + @ApiModelProperty("总欠款")
  33 + private BigDecimal debtTotal;
  34 +
  35 + /**
  36 + * 约定内欠款
  37 + */
  38 + @ApiModelProperty("约定内欠款")
  39 + private BigDecimal agreement;
  40 +
  41 + /**
  42 + * 一次协调欠款
  43 + */
  44 + @ApiModelProperty("一次协调欠款")
  45 + private BigDecimal firstCoordinate;
  46 +
  47 + /**
  48 + * 二次协调欠款
  49 + */
  50 + @ApiModelProperty("二次协调欠款")
  51 + private BigDecimal secondCoordinate;
  52 +
  53 + /**
  54 + * 清欠阶段欠款金额
  55 + */
  56 + @ApiModelProperty("清欠阶段欠款金额")
  57 + private BigDecimal clearDebt;
  58 +
  59 + /**
  60 + * 授信状态
  61 + */
  62 + @ApiModelProperty("授信状态")
  63 + private String creditStatus;
  64 +
  65 + /**
  66 + * 授时状态
  67 + */
  68 + @ApiModelProperty("授时状态")
  69 + private String timingStatus;
  70 +
  71 + /**
  72 + * 待交付订单数量
  73 + */
  74 + @ApiModelProperty("授时状态")
  75 + private Integer waitDeliveredOrder;
  76 +}
... ...
... ... @@ -2,6 +2,7 @@ package com.lframework.xingyun.sc.controller.ledger;
2 2
3 3 import com.lframework.xingyun.sc.bo.ledger.receipt.GetReceiptLedgerInfoBo;
4 4 import com.lframework.xingyun.sc.bo.ledger.receipt.QueryReceiptLedgerInfoBo;
  5 +import com.lframework.xingyun.sc.bo.ledger.receipt.ReceiptLedgerReportBo;
5 6 import com.lframework.xingyun.sc.utils.CommonUtil;
6 7 import com.lframework.xingyun.sc.vo.ledger.receipt.QueryReceiptLedgerInfoVo;
7 8 import com.lframework.xingyun.sc.service.ledger.ReceiptLedgerInfoService;
... ... @@ -129,4 +130,16 @@ public class ReceiptLedgerInfoController extends DefaultBaseController {
129 130 receiptLedgerInfoService.deleteById(id);
130 131 return InvokeResultBuilder.success();
131 132 }
  133 +
  134 +
  135 + /**
  136 + * 台账报表
  137 + */
  138 + @ApiOperation("台账报表")
  139 + @HasPermission({"account-manage:ledger-detail:query"})
  140 + @GetMapping("/report")
  141 + public InvokeResult<PageResult<ReceiptLedgerReportBo>> report(@Valid QueryReceiptLedgerInfoVo vo) {
  142 + PageResult<ReceiptLedgerReportBo> pageResult = receiptLedgerInfoService.report(getPageIndex(vo), getPageSize(vo), vo);
  143 + return InvokeResultBuilder.success(pageResult);
  144 + }
132 145 }
... ...
... ... @@ -13,6 +13,8 @@ import com.lframework.xingyun.basedata.entity.Customer;
13 13 import com.lframework.xingyun.basedata.entity.CustomerShort;
14 14 import com.lframework.xingyun.basedata.service.customer.CustomerService;
15 15 import com.lframework.xingyun.basedata.service.customer.CustomerShortService;
  16 +import com.lframework.xingyun.sc.bo.ledger.receipt.ReceiptLedgerReportBo;
  17 +import com.lframework.xingyun.sc.bo.ledger.receipt.ReceiptLedgerReportDetail;
16 18 import com.lframework.xingyun.sc.entity.*;
17 19 import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
18 20 import com.lframework.starter.web.core.utils.PageResultUtil;
... ... @@ -149,7 +151,7 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
149 151 throw new DefaultClientException("应收款台账明细不存在!");
150 152 }
151 153 // 获取欠款状态
152   - String settlementStatus = getSettlementStatus(data.getEndAccountReceivable(), data.getProcessedDate());
  154 + String settlementStatus = getSettlementStatus(data.getEndAccountReceivable(), vo.getProcessedDate());
153 155 LambdaUpdateWrapper<ReceiptLedgerInfo> updateWrapper = Wrappers.lambdaUpdate(ReceiptLedgerInfo.class)
154 156 .set(ReceiptLedgerInfo::getDescription, StringUtil.isBlank(vo.getDescription()) ? null : vo.getDescription())
155 157 .set(ReceiptLedgerInfo::getProcessedDate, vo.getProcessedDate() == null ? null : vo.getProcessedDate())
... ... @@ -369,6 +371,107 @@ public class ReceiptLedgerInfoServiceImpl extends BaseMpServiceImpl<ReceiptLedge
369 371 getBaseMapper().batchAdd(dataList);
370 372 }
371 373
  374 + @Override
  375 + public PageResult<ReceiptLedgerReportBo> report(Integer pageIndex, Integer pageSize, QueryReceiptLedgerInfoVo vo) {
  376 + Assert.greaterThanZero(pageIndex);
  377 + Assert.greaterThanZero(pageSize);
  378 + // 开启分页
  379 + PageHelperUtil.startPage(pageIndex, pageSize);
  380 + List<ReceiptLedgerReportBo> dataList = getBaseMapper().report(vo);
  381 + PageResult<ReceiptLedgerReportBo> result = PageResultUtil.convert(new PageInfo<>(dataList));
  382 + if (CollectionUtils.isEmpty(dataList)) {
  383 + return result;
  384 + }
  385 + List<String> shortNames = dataList.stream().map(ReceiptLedgerReportBo::getCustomerShortName).distinct().collect(Collectors.toList());
  386 + // 只统计约定内、一次、二次协调、清欠阶段
  387 + List<String> debtStatusList = new ArrayList<>();
  388 + debtStatusList.add("AGREEMENT");
  389 + debtStatusList.add("FIRST_COORDINATE");
  390 + debtStatusList.add("SECOND_COORDINATE");
  391 + debtStatusList.add("CLEAR_DEBTS");
  392 + List<Map<String, Object>> debtAmountList = getBaseMapper().statisticsDeptByShortName(shortNames, debtStatusList);
  393 + if (CollectionUtils.isEmpty(debtAmountList)) {
  394 + return result;
  395 + }
  396 + // 根据简称分组
  397 + Map<String, List<Map<String, Object>>> debtMap = new HashMap<>();
  398 + for (Map<String, Object> map : debtAmountList) {
  399 + String shortName = (String) map.get("short_name");
  400 + List<Map<String, Object>> list = debtMap.computeIfAbsent(shortName, k -> new ArrayList<>());
  401 + list.add(map);
  402 + }
  403 + for (ReceiptLedgerReportBo report : dataList) {
  404 + String customerShortName = report.getCustomerShortName();
  405 + List<Map<String, Object>> list = debtMap.get(customerShortName);
  406 + if (CollectionUtils.isEmpty(list)) {
  407 + continue;
  408 + }
  409 + BigDecimal debtTotal = BigDecimal.ZERO;
  410 + BigDecimal agreementTotal = BigDecimal.ZERO;
  411 + BigDecimal firstCoordinateTotal = BigDecimal.ZERO;
  412 + BigDecimal secondCoordinateTotal = BigDecimal.ZERO;
  413 + BigDecimal clearDebtTotal = BigDecimal.ZERO;
  414 + Integer waitDeliveredOrderTotal = 0;
  415 + Map<String, ReceiptLedgerReportDetail> reportDetailMap = new HashMap<>();
  416 + for (Map<String, Object> map : list) {
  417 + String customerName = (String) map.get("name");
  418 + String debtStatus = (String) map.get("debt_status");
  419 + BigDecimal debtAmount = (BigDecimal) map.get("debt_amount");
  420 +
  421 + ReceiptLedgerReportDetail reportDetail = reportDetailMap.get(customerName);
  422 + if (reportDetail == null) {
  423 + reportDetail = new ReceiptLedgerReportDetail();
  424 + }
  425 + reportDetail.setCustomerName(customerName);
  426 + if ("AGREEMENT".equals(debtStatus)) {
  427 + reportDetail.setAgreement(debtAmount);
  428 + agreementTotal = agreementTotal.add(debtAmount);
  429 + } else if ("FIRST_COORDINATE".equals(debtStatus)) {
  430 + reportDetail.setFirstCoordinate(debtAmount);
  431 + firstCoordinateTotal = firstCoordinateTotal.add(debtAmount);
  432 + } else if ("SECOND_COORDINATE".equals(debtStatus)) {
  433 + reportDetail.setSecondCoordinate(debtAmount);
  434 + secondCoordinateTotal = secondCoordinateTotal.add(debtAmount);
  435 + } else if ("CLEAR_DEBTS".equals(debtStatus)) {
  436 + reportDetail.setClearDebt(debtAmount);
  437 + clearDebtTotal = clearDebtTotal.add(debtAmount);
  438 + }
  439 + debtTotal = debtTotal.add(debtAmount);
  440 +
  441 + reportDetailMap.put(reportDetail.getCustomerName(), reportDetail);
  442 + }
  443 + List<ReceiptLedgerReportDetail> details = new ArrayList<>(reportDetailMap.values());
  444 + for (ReceiptLedgerReportDetail detail : details) {
  445 + BigDecimal total = getDebtTotal(detail);
  446 + detail.setDebtTotal(total);
  447 + }
  448 + report.setDetailList(details);
  449 +
  450 + report.setDebtTotal(debtTotal);
  451 + report.setAgreementTotal(agreementTotal);
  452 + report.setFirstCoordinateTotal(firstCoordinateTotal);
  453 + report.setSecondCoordinateTotal(secondCoordinateTotal);
  454 + report.setClearDebtTotal(clearDebtTotal);
  455 + report.setWaitDeliveredOrderTotal(waitDeliveredOrderTotal);
  456 + }
  457 + return result;
  458 + }
  459 +
  460 +
  461 + /**
  462 + * 获取总欠款
  463 + *
  464 + * @param detail 报表明细数据
  465 + * @return BigDecimal
  466 + */
  467 + private static BigDecimal getDebtTotal(ReceiptLedgerReportDetail detail) {
  468 + BigDecimal agreement = detail.getAgreement() == null ? BigDecimal.ZERO : detail.getAgreement();
  469 + BigDecimal firstCoordinate = detail.getFirstCoordinate() == null ? BigDecimal.ZERO : detail.getFirstCoordinate();
  470 + BigDecimal secondCoordinate = detail.getSecondCoordinate()== null ? BigDecimal.ZERO : detail.getSecondCoordinate();
  471 + BigDecimal clearDebt = detail.getClearDebt() == null ? BigDecimal.ZERO : detail.getClearDebt();
  472 +
  473 + return agreement.add(firstCoordinate).add(secondCoordinate).add(clearDebt);
  474 + }
372 475
373 476
374 477 /**
... ...
1 1 package com.lframework.xingyun.sc.mappers;
2 2
  3 +import com.lframework.xingyun.sc.bo.ledger.receipt.ReceiptLedgerReportBo;
3 4 import com.lframework.xingyun.sc.entity.ReceiptLedgerInfo;
4 5 import com.lframework.starter.web.core.mapper.BaseMapper;
5 6 import com.lframework.xingyun.sc.vo.ledger.receipt.QueryReceiptLedgerInfoVo;
6 7 import org.apache.ibatis.annotations.Param;
7 8
8 9 import java.util.List;
  10 +import java.util.Map;
9 11
10 12 /**
11 13 * <p>
... ... @@ -30,4 +32,20 @@ public interface ReceiptLedgerInfoMapper extends BaseMapper<ReceiptLedgerInfo> {
30 32 * @param dataList 数据实体
31 33 */
32 34 void batchAdd(List<ReceiptLedgerInfo> dataList);
  35 +
  36 + /**
  37 + * 报表统计
  38 + *
  39 + * @param vo 查询条件
  40 + * @return List<ReceiptLedgerReportBo>
  41 + */
  42 + List<ReceiptLedgerReportBo> report(@Param("vo") QueryReceiptLedgerInfoVo vo);
  43 +
  44 + /**
  45 + * 根据客户简称统计欠款金额
  46 + *
  47 + * @param shortNames 客户简称
  48 + * @return List<Map<String, BigDecimal>>
  49 + */
  50 + List<Map<String, Object>> statisticsDeptByShortName(@Param("shortNames") List<String> shortNames, @Param("debtStatusList") List<String> debtStatusList);
33 51 }
... ...
1 1 package com.lframework.xingyun.sc.service.ledger;
2 2
  3 +import com.lframework.xingyun.sc.bo.ledger.receipt.ReceiptLedgerReportBo;
3 4 import com.lframework.xingyun.sc.entity.ShipmentsOrderInfo;
4 5 import com.lframework.xingyun.sc.vo.ledger.receipt.CreateReceiptLedgerInfoVo;
5 6 import com.lframework.xingyun.sc.vo.ledger.receipt.QueryReceiptLedgerInfoVo;
... ... @@ -80,4 +81,12 @@ public interface ReceiptLedgerInfoService extends BaseMpService<ReceiptLedgerInf
80 81 * @param orderInfoList 发货单数据
81 82 */
82 83 void generateLedgerInfo(List<ShipmentsOrderInfo> orderInfoList);
  84 +
  85 + /**
  86 + * 报表统计
  87 + *
  88 + * @param vo 查询条件
  89 + * @return PageResult<ReceiptLedgerReportBo>
  90 + */
  91 + PageResult<ReceiptLedgerReportBo> report(Integer pageIndex, Integer pageSize, QueryReceiptLedgerInfoVo vo);
83 92 }
... ...
... ... @@ -192,4 +192,39 @@
192 192 )
193 193 </foreach>
194 194 </insert>
  195 +
  196 + <select id="report" resultType="com.lframework.xingyun.sc.bo.ledger.receipt.ReceiptLedgerReportBo">
  197 + select tb.short_name as customer_short_name,
  198 + tb.type,
  199 + tb.dept_id,
  200 + d.name as dept_name,
  201 + tb.region,
  202 + r.name as region_name,
  203 + max(cc.company_credit_limit) as quota
  204 + from base_data_customer_short tb
  205 + left join sys_dept d on tb.dept_id = d.id
  206 + left join sys_dept r on tb.region = r.id
  207 + left join customer_credit cc on tb.customer_id = cc.company_id
  208 + group by tb.short_name,tb.type,tb.dept_id,tb.region
  209 + </select>
  210 +
  211 + <select id="statisticsDeptByShortName" resultType="java.util.Map">
  212 + select c.name,
  213 + cs.short_name,
  214 + tb.debt_status,
  215 + sum(tb.end_account_receivable) as debt_amount
  216 + from receipt_ledger_info tb
  217 + inner join base_data_customer_short cs on tb.customer_id = cs.customer_id
  218 + inner join base_data_customer c on tb.customer_id = c.id
  219 + where cs.short_name in
  220 + <foreach collection="shortNames" open="(" separator="," close=")" item="item">
  221 + #{item}
  222 + </foreach>
  223 + and tb.debt_status in
  224 + <foreach collection="debtStatusList" open="(" separator="," close=")" item="item">
  225 + #{item}
  226 + </foreach>
  227 + and tb.debt_status is not null
  228 + group by c.name,cs.short_name,tb.debt_status
  229 + </select>
195 230 </mapper>
... ...