Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add account statistics report #198

Merged
merged 5 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wansenai.dto.report.QueryAccountStatisticsDTO;
import com.wansenai.dto.report.QueryProductStockDTO;
import com.wansenai.dto.report.QueryStockFlowDTO;
import com.wansenai.service.receipt.ReceiptService;
import com.wansenai.utils.response.Response;
import com.wansenai.vo.receipt.retail.RetailStatisticalDataVO;
import com.wansenai.vo.report.AccountStatisticsVO;
import com.wansenai.vo.report.ProductStockVO;
import com.wansenai.vo.report.StockFlowVO;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -48,4 +50,8 @@ public Response<Page<StockFlowVO>> getStockFlow(@RequestBody QueryStockFlowDTO s
return receiptService.getStockFlow(stockFlowDTO);
}

@PostMapping("accountStatistics")
public Response<Page<AccountStatisticsVO>> getAccountStatistics(@RequestBody QueryAccountStatisticsDTO accountStatisticsDTO) {
return receiptService.getAccountStatistics(accountStatisticsDTO);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2023-2033 WanSen AI Team, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://opensource.wansenai.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansenai.dto.report;

import lombok.Data;

@Data
public class QueryAccountStatisticsDTO {

private String accountName;

private String accountNumber;

private Long page;

private Long pageSize;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2023-2033 WanSen AI Team, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://opensource.wansenai.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansenai.vo.report;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.wansenai.bo.BigDecimalSerializerBO;
import lombok.Builder;
import lombok.Data;

import java.math.BigDecimal;

@Data
@Builder
public class AccountStatisticsVO {

@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long accountId;

private String accountName;

private String accountNumber;

@JsonSerialize(using = BigDecimalSerializerBO.class)
private BigDecimal initialAmount;

@JsonSerialize(using = BigDecimalSerializerBO.class)
private BigDecimal thisMonthChangeAmount;

@JsonSerialize(using = BigDecimalSerializerBO.class)
private BigDecimal currentAmount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wansenai.dto.receipt.QueryReceiptDTO;
import com.wansenai.dto.report.QueryAccountStatisticsDTO;
import com.wansenai.dto.report.QueryProductStockDTO;
import com.wansenai.dto.report.QueryStockFlowDTO;
import com.wansenai.utils.response.Response;
import com.wansenai.vo.receipt.ReceiptDetailVO;
import com.wansenai.vo.receipt.ReceiptVO;
import com.wansenai.vo.receipt.retail.RetailStatisticalDataVO;
import com.wansenai.vo.report.AccountStatisticsVO;
import com.wansenai.vo.report.ProductStockVO;
import com.wansenai.vo.report.StockFlowVO;

Expand All @@ -43,4 +45,6 @@ public interface ReceiptService {
Response<IPage<ProductStockVO>> getProductStock(QueryProductStockDTO queryProductStockDTO);

Response<Page<StockFlowVO>> getStockFlow(QueryStockFlowDTO queryStockFlowDTO);

Response<Page<AccountStatisticsVO>> getAccountStatistics(QueryAccountStatisticsDTO accountStatisticsDTO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wansenai.dto.receipt.QueryReceiptDTO;
import com.wansenai.dto.report.QueryAccountStatisticsDTO;
import com.wansenai.dto.report.QueryProductStockDTO;
import com.wansenai.dto.report.QueryStockFlowDTO;
import com.wansenai.entities.basic.Customer;
import com.wansenai.entities.basic.Member;
import com.wansenai.entities.basic.Supplier;
import com.wansenai.entities.financial.FinancialAccount;
import com.wansenai.entities.product.Product;
import com.wansenai.entities.receipt.*;
import com.wansenai.entities.warehouse.Warehouse;
import com.wansenai.mappers.product.ProductStockMapper;
import com.wansenai.service.basic.CustomerService;
import com.wansenai.service.basic.MemberService;
import com.wansenai.service.basic.SupplierService;
import com.wansenai.service.financial.IFinancialAccountService;
import com.wansenai.service.product.ProductService;
import com.wansenai.service.receipt.*;
import com.wansenai.service.user.ISysUserService;
Expand All @@ -38,6 +41,7 @@
import com.wansenai.vo.receipt.ReceiptDetailVO;
import com.wansenai.vo.receipt.ReceiptVO;
import com.wansenai.vo.receipt.retail.RetailStatisticalDataVO;
import com.wansenai.vo.report.AccountStatisticsVO;
import com.wansenai.vo.report.ProductStockVO;
import com.wansenai.vo.report.StockFlowVO;
import org.springframework.stereotype.Service;
Expand All @@ -47,11 +51,7 @@
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.*;

@Service
public class ReceiptServiceImpl implements ReceiptService {
Expand Down Expand Up @@ -82,7 +82,9 @@ public class ReceiptServiceImpl implements ReceiptService {

private final WarehouseService warehouseService;

public ReceiptServiceImpl(ReceiptRetailService receiptRetailService, ReceiptRetailSubService receiptRetailSubService, ReceiptSaleService receiptSaleService, ReceiptSaleSubService receiptSaleSubService, ReceiptPurchaseService receiptPurchaseService, ReceiptPurchaseSubService receiptPurchaseSubService, MemberService memberService, CustomerService customerService, SupplierService supplierService, ISysUserService userService, ProductService productService, ProductStockMapper productStockMapper, WarehouseService warehouseService) {
private final IFinancialAccountService accountService;

public ReceiptServiceImpl(ReceiptRetailService receiptRetailService, ReceiptRetailSubService receiptRetailSubService, ReceiptSaleService receiptSaleService, ReceiptSaleSubService receiptSaleSubService, ReceiptPurchaseService receiptPurchaseService, ReceiptPurchaseSubService receiptPurchaseSubService, MemberService memberService, CustomerService customerService, SupplierService supplierService, ISysUserService userService, ProductService productService, ProductStockMapper productStockMapper, WarehouseService warehouseService, IFinancialAccountService accountService) {
this.receiptRetailService = receiptRetailService;
this.receiptRetailSubService = receiptRetailSubService;
this.receiptSaleService = receiptSaleService;
Expand All @@ -96,6 +98,7 @@ public ReceiptServiceImpl(ReceiptRetailService receiptRetailService, ReceiptReta
this.productService = productService;
this.productStockMapper = productStockMapper;
this.warehouseService = warehouseService;
this.accountService = accountService;
}

private String getProductName(Long id) {
Expand Down Expand Up @@ -676,4 +679,99 @@ public Response<Page<StockFlowVO>> getStockFlow(QueryStockFlowDTO queryStockFlow
return Response.responseData(page);

}

@Override
public Response<Page<AccountStatisticsVO>> getAccountStatistics(QueryAccountStatisticsDTO accountStatisticsDTO) {
var result = new Page<AccountStatisticsVO>();

var page = new Page<FinancialAccount>(accountStatisticsDTO.getPage(), accountStatisticsDTO.getPageSize());
var accountPage = accountService.lambdaQuery()
.eq(FinancialAccount::getDeleteFlag, CommonConstants.NOT_DELETED)
.eq(StringUtils.hasLength(accountStatisticsDTO.getAccountName()), FinancialAccount::getAccountName, accountStatisticsDTO.getAccountName())
.eq(StringUtils.hasLength(accountStatisticsDTO.getAccountNumber()), FinancialAccount::getAccountNumber, accountStatisticsDTO.getAccountNumber())
.page(page);

if(accountPage.getRecords().isEmpty()) {
return Response.responseMsg(BaseCodeEnum.QUERY_DATA_EMPTY);
}

var accountVos = new ArrayList<AccountStatisticsVO>();
accountPage.getRecords().forEach(item -> {
var retailData = receiptRetailService.lambdaQuery()
.eq(ReceiptRetailMain::getAccountId, item.getId())
.eq(ReceiptRetailMain::getDeleteFlag, CommonConstants.NOT_DELETED)
.list();

var retailChangeAmount = BigDecimal.ZERO;
var saleChangeAmount = BigDecimal.ZERO;
var purchaseChangeAmount = BigDecimal.ZERO;

if (!retailData.isEmpty()) {
retailChangeAmount = retailData.stream()
.filter(receiptRetailMain -> receiptRetailMain.getReceiptDate().isAfter(LocalDateTime.now().withDayOfMonth(1).with(LocalTime.MIN)))
.filter(receiptRetailMain -> receiptRetailMain.getReceiptDate().isBefore(LocalDateTime.now().with(LocalTime.MAX)))
.toList()
.stream()
.map(receipt -> Optional.ofNullable(receipt.getChangeAmount()).orElse(BigDecimal.ZERO))
.reduce(BigDecimal.ZERO, BigDecimal::add)
.setScale(2, RoundingMode.HALF_UP);
}

var salesData = receiptSaleService.lambdaQuery()
.eq(ReceiptSaleMain::getAccountId, item.getId())
.eq(ReceiptSaleMain::getDeleteFlag, CommonConstants.NOT_DELETED)
.list();
if (!salesData.isEmpty()) {
saleChangeAmount = salesData.stream()
.filter(receiptSaleMain -> receiptSaleMain.getReceiptDate().isAfter(LocalDateTime.now().withDayOfMonth(1).with(LocalTime.MIN)))
.filter(receiptSaleMain -> receiptSaleMain.getReceiptDate().isBefore(LocalDateTime.now().with(LocalTime.MAX)))
.toList()
.stream()
.map(receipt -> Optional.ofNullable(receipt.getChangeAmount()).orElse(BigDecimal.ZERO))
.reduce(BigDecimal.ZERO, BigDecimal::add)
.setScale(2, RoundingMode.HALF_UP);
}

var purchaseData = receiptPurchaseService.lambdaQuery()
.eq(ReceiptPurchaseMain::getAccountId, item.getId())
.eq(ReceiptPurchaseMain::getDeleteFlag, CommonConstants.NOT_DELETED)
.list();
if(!purchaseData.isEmpty()) {
purchaseChangeAmount = purchaseData.stream()
.filter(receiptPurchaseMain -> receiptPurchaseMain.getReceiptDate().isAfter(LocalDateTime.now().withDayOfMonth(1).with(LocalTime.MIN)))
.filter(receiptPurchaseMain -> receiptPurchaseMain.getReceiptDate().isBefore(LocalDateTime.now().with(LocalTime.MAX)))
.toList()
.stream()
.map(receipt -> Optional.ofNullable(receipt.getChangeAmount()).orElse(BigDecimal.ZERO))
.reduce(BigDecimal.ZERO, BigDecimal::add)
.setScale(2, RoundingMode.HALF_UP);
}

var saleAccountMultipleData = receiptSaleService.lambdaQuery()
.in(ReceiptSaleMain::getMultipleAccount, item.getId())
.eq(ReceiptSaleMain::getDeleteFlag, CommonConstants.NOT_DELETED)
.list();

System.err.println(saleAccountMultipleData);

var thisMonthChangeAmount = retailChangeAmount.add(saleChangeAmount).add(purchaseChangeAmount);

var accountVo = AccountStatisticsVO.builder()
.accountId(item.getId())
.accountName(item.getAccountName())
.accountNumber(item.getAccountNumber())
.initialAmount(item.getInitialAmount())
.thisMonthChangeAmount(thisMonthChangeAmount)
.currentAmount(item.getCurrentAmount())
.build();

accountVos.add(accountVo);
});
result.setRecords(accountVos);
result.setPages(accountPage.getPages());
result.setSize(accountPage.getSize());
result.setTotal(accountPage.getTotal());

return Response.responseData(result);
}
}
18 changes: 14 additions & 4 deletions web/src/api/report/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import {
QueryProductStockReq,
RetailStatisticalResp,
ProductStockFlowResp,
QueryProductStockFlowReq
QueryProductStockFlowReq,
QueryAccountStatisticsReq,
AccountStatisticsResp
} from "@/api/report/reportModel";

enum API {
getStatisticalData = '/report/homePage/statistics',
getProductStockData = '/report/productStock',
getProductStockFlowData = '/report/productStockFlow'
getProductStockFlowData = '/report/productStockFlow',
getAccountStatistics = '/report/accountStatistics'
}


Expand All @@ -33,12 +36,19 @@ export function getProductStock(params: QueryProductStockReq) {
}

export function getProductStockFlow(params: QueryProductStockFlowReq, productId: number) {
console.info("productId", productId);
console.info("params", params);
return defHttp.post<BaseDataResp<ProductStockFlowResp>>(
{
url: API.getProductStockFlowData,
params
}
);
}

export function getAccountStatistics(params: QueryAccountStatisticsReq) {
return defHttp.post<BaseDataResp<AccountStatisticsResp>>(
{
url: API.getAccountStatistics,
params
}
);
}
14 changes: 14 additions & 0 deletions web/src/api/report/reportModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,18 @@ export interface ProductStockFlowResp {
warehouseName: string;
productNumber: number;
receiptDate: string;
}

export interface QueryAccountStatisticsReq {
accountName: string;
accountNumber: string;
}

export interface AccountStatisticsResp {
accountId: string;
accountName: string;
accountNumber: string;
initialAmount: number;
thisMonthChangeAmount: number;
currentAmount: number;
}
Loading