Skip to content

Commit

Permalink
Merge pull request #204 from Jzow/master
Browse files Browse the repository at this point in the history
Add retail retailStatistics api and views
  • Loading branch information
Jzow authored Nov 19, 2023
2 parents 613ff1c + 56a7ab7 commit ee2eea3
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
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.QueryRetailReportDTO;
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.AccountFlowVO;
import com.wansenai.vo.report.AccountStatisticsVO;
import com.wansenai.vo.report.ProductStockVO;
import com.wansenai.vo.report.StockFlowVO;
import com.wansenai.vo.receipt.retail.StatisticalDataVO;
import com.wansenai.vo.report.*;
import org.springframework.web.bind.annotation.*;

@RestController
Expand All @@ -37,8 +35,8 @@ public ReportController(ReceiptService receiptService) {
}

@GetMapping("homePage/statistics")
public Response<RetailStatisticalDataVO> getStatisticalData() {
return receiptService.getRetailStatistics();
public Response<StatisticalDataVO> getStatisticalData() {
return receiptService.getStatisticalData();
}

@PostMapping("productStock")
Expand All @@ -64,4 +62,9 @@ public Response<Page<AccountFlowVO>> getAccountFlow(
) {
return receiptService.getAccountFlow(accountId, page, pageSize);
}

@PostMapping("retailStatistics")
public Response<Page<RetailReportVO>> getRetailStatistics(@RequestBody QueryRetailReportDTO queryRetailReportDTO) {
return receiptService.getRetailStatistics(queryRetailReportDTO);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 QueryRetailReportDTO {

private String productExtendInfo;

private Long memberId;

private Long warehouseId;

private String startDate;

private String endDate;

private Integer page;

private Integer pageSize;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RetailStatisticalDataVO {
public class StatisticalDataVO {

@JsonSerialize(using = BigDecimalSerializerBO.class)
private BigDecimal todaySales;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 RetailReportVO {

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

private String productName;

private String productModel;

private String productStandard;

private String productExtendInfo;

private String productUnit;

private Integer retailNumber;

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

private Integer retailRefundNumber;

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

@JsonSerialize(using = BigDecimalSerializerBO.class)
private BigDecimal retailLastAmount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public interface CommonService {

List<FileDataBO> getFileList(String fileId);

String getProductName(Long productId);

String getWarehouseName(Long warehouseId);

String getMemberName(Long memberId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,13 @@ public List<FileDataBO> getFileList(String fileId) {
return fileList;
}

@Override
public String getProductName(Long productId) {
return Optional.ofNullable(productService.getById(productId))
.map(Product::getProductName)
.orElse(NullString);
}

@Override
public String getWarehouseName(Long warehouseId) {
return Optional.ofNullable(warehouseService.getById(warehouseId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
import com.wansenai.dto.receipt.QueryReceiptDTO;
import com.wansenai.dto.report.QueryAccountStatisticsDTO;
import com.wansenai.dto.report.QueryProductStockDTO;
import com.wansenai.dto.report.QueryRetailReportDTO;
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.AccountFlowVO;
import com.wansenai.vo.report.AccountStatisticsVO;
import com.wansenai.vo.report.ProductStockVO;
import com.wansenai.vo.report.StockFlowVO;
import com.wansenai.vo.receipt.retail.StatisticalDataVO;
import com.wansenai.vo.report.*;

public interface ReceiptService {

Expand All @@ -37,7 +35,7 @@ public interface ReceiptService {
* @return Return to homepage data summary
* 返回首页数据汇总
*/
Response<RetailStatisticalDataVO> getRetailStatistics();
Response<StatisticalDataVO> getStatisticalData();

Response<Page<ReceiptVO>> otherReceipt(QueryReceiptDTO receiptDTO);

Expand All @@ -50,4 +48,6 @@ public interface ReceiptService {
Response<Page<AccountStatisticsVO>> getAccountStatistics(QueryAccountStatisticsDTO accountStatisticsDTO);

Response<Page<AccountFlowVO>> getAccountFlow(Long accountId, Long page, Long pageSize);

Response<Page<RetailReportVO>> getRetailStatistics(QueryRetailReportDTO queryRetailReportDTO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.wansenai.dto.receipt.QueryReceiptDTO;
import com.wansenai.dto.report.QueryAccountStatisticsDTO;
import com.wansenai.dto.report.QueryProductStockDTO;
import com.wansenai.dto.report.QueryRetailReportDTO;
import com.wansenai.dto.report.QueryStockFlowDTO;
import com.wansenai.entities.basic.Customer;
import com.wansenai.entities.basic.Member;
Expand All @@ -41,11 +42,8 @@
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.AccountFlowVO;
import com.wansenai.vo.report.AccountStatisticsVO;
import com.wansenai.vo.report.ProductStockVO;
import com.wansenai.vo.report.StockFlowVO;
import com.wansenai.vo.receipt.retail.StatisticalDataVO;
import com.wansenai.vo.report.*;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -128,7 +126,7 @@ private String getWarehouseName(Long id) {
}

@Override
public Response<RetailStatisticalDataVO> getRetailStatistics() {
public Response<StatisticalDataVO> getStatisticalData() {
var now = LocalDateTime.now();

var retailData = receiptRetailService.lambdaQuery()
Expand Down Expand Up @@ -179,7 +177,7 @@ public Response<RetailStatisticalDataVO> getRetailStatistics() {
var monthPurchase = calculatePurchaseTotalPrice(purchaseData, purchaseRefundData, now.withDayOfMonth(1).with(LocalTime.MIN), now.with(LocalTime.MAX));
var yearPurchase = calculatePurchaseTotalPrice(purchaseData, purchaseRefundData, now.withDayOfYear(1).with(LocalTime.MIN), now.with(LocalTime.MAX));

var retailStatisticalDataVO = RetailStatisticalDataVO.builder()
var retailStatisticalDataVO = StatisticalDataVO.builder()
.todayRetailSales(todayRetailSales)
.yesterdayRetailSales(yesterdayRetailSales)
.monthRetailSales(monthRetailSales)
Expand Down Expand Up @@ -883,4 +881,65 @@ public Response<Page<AccountFlowVO>> getAccountFlow(Long accountId, Long page, L

return Response.responseData(result);
}

@Override
public Response<Page<RetailReportVO>> getRetailStatistics(QueryRetailReportDTO queryRetailReportDTO) {
var result = new Page<RetailReportVO>();
var page = new Page<ReceiptRetailMain>(queryRetailReportDTO.getPage(), queryRetailReportDTO.getPageSize());
var retailPage = receiptRetailService.lambdaQuery()
.eq(ReceiptRetailMain::getDeleteFlag, CommonConstants.NOT_DELETED)
.eq(queryRetailReportDTO.getMemberId() != null, ReceiptRetailMain::getMemberId, queryRetailReportDTO.getMemberId())
.le(queryRetailReportDTO.getStartDate() != null, ReceiptRetailMain::getReceiptDate, queryRetailReportDTO.getStartDate())
.ge(queryRetailReportDTO.getEndDate() != null, ReceiptRetailMain::getReceiptDate, queryRetailReportDTO.getEndDate())
.page(page);

var retailVos = new ArrayList<RetailReportVO>();
retailPage.getRecords().forEach(item -> {
var retailSub = receiptRetailSubService.lambdaQuery()
.eq(ReceiptRetailSub::getReceiptMainId, item.getId())
.eq(ReceiptRetailSub::getDeleteFlag, CommonConstants.NOT_DELETED)
.one();

var retailVo = RetailReportVO.builder()
.productBarcode(retailSub.getProductBarcode())
.retailNumber(retailSub.getProductNumber())
.build();

var product = productService.getById(retailSub.getProductId());
if (product != null) {
String productExtendInfo = product.getProductManufacturer() +
"|" +
product.getOtherFieldOne() +
"|" +
product.getOtherFieldTwo() +
"|" +
product.getOtherFieldThree();
retailVo.setProductName(product.getProductName());
retailVo.setProductStandard(product.getProductStandard());
retailVo.setProductModel(product.getProductModel());
retailVo.setProductUnit(product.getProductUnit());
retailVo.setProductExtendInfo(productExtendInfo);
}

var retailLastAmount = BigDecimal.ZERO;
if (item.getSubType().equals("零售出库")) {
retailVo.setRetailAmount(retailSub.getTotalAmount());
retailVo.setRetailNumber(retailSub.getProductNumber());
retailLastAmount = retailLastAmount.add(retailSub.getTotalAmount());
} else {
retailVo.setRetailRefundAmount(retailSub.getTotalAmount());
retailVo.setRetailRefundNumber(retailSub.getProductNumber());
retailLastAmount = retailLastAmount.subtract(retailSub.getTotalAmount());
}
retailVo.setRetailLastAmount(retailLastAmount);

retailVos.add(retailVo);
});
result.setRecords(retailVos);
result.setPages(retailPage.getPages());
result.setSize(retailPage.getSize());
result.setTotal(retailPage.getTotal());

return Response.responseData(result);
}
}
14 changes: 12 additions & 2 deletions web/src/api/report/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import {
ProductStockFlowResp,
QueryProductStockFlowReq,
QueryAccountStatisticsReq,
AccountStatisticsResp, AccountFlowResp
AccountStatisticsResp, AccountFlowResp, QueryRetailStatisticsReq, RetailStatisticsResp
} from "@/api/report/reportModel";

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


Expand Down Expand Up @@ -61,4 +62,13 @@ export function getAccountFlow(accountId: number) {
params: accountId
}
);
}

export function getRetailStatistics(params: QueryRetailStatisticsReq) {
return defHttp.post<BaseDataResp<RetailStatisticsResp>>(
{
url: API.getRetailStatistics,
params
}
);
}
20 changes: 20 additions & 0 deletions web/src/api/report/reportModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,24 @@ export interface AccountFlowResp {
amount: number;
balance: number;
receiptDate: string;
}

export interface QueryRetailStatisticsReq {
productExtendInfo: string;
memberId: number;
warehouseId: number;
}

export interface RetailStatisticsResp {
productBarcode: string;
productName: string;
productStandard: string;
productModel: string;
productExtendInfo: string;
productUnit: string;
retailNumber: number;
retailAmount: number;
retailRefundNumber: number;
retailRefundAmount: number;
retailLastAmount: number;
}
Loading

0 comments on commit ee2eea3

Please sign in to comment.