Skip to content

Commit

Permalink
Merge pull request #155 from Jzow/master
Browse files Browse the repository at this point in the history
Improve homepage data acquisition
  • Loading branch information
Jzow committed Nov 4, 2023
2 parents d9c096c + 50976ea commit ad50426
Show file tree
Hide file tree
Showing 20 changed files with 448 additions and 91 deletions.
18 changes: 9 additions & 9 deletions core/api/src/main/java/com/wansenai/api/RetailController.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wansenai.dto.receipt.QueryShipmentsDTO;
import com.wansenai.dto.receipt.RetailShipmentsDTO;
import com.wansenai.service.receipt.RetailService;
import com.wansenai.service.receipt.ReceiptService;
import com.wansenai.utils.response.Response;
import com.wansenai.vo.receipt.RetailShipmentsDetailVO;
import com.wansenai.vo.receipt.RetailShipmentsVO;
Expand All @@ -27,34 +27,34 @@
@RequestMapping("/retail")
public class RetailController {

private final RetailService retailService;
private final ReceiptService receiptService;

public RetailController(RetailService retailService) {
this.retailService = retailService;
public RetailController(ReceiptService receiptService) {
this.receiptService = receiptService;
}

@PostMapping("/shipments/pageList")
public Response<Page<RetailShipmentsVO>> pageList(@RequestBody QueryShipmentsDTO queryShipmentsDTO) {
return retailService.getRetailShipments(queryShipmentsDTO);
return receiptService.getRetailShipments(queryShipmentsDTO);
}

@PostMapping("/shipments/addOrUpdate")
public Response<String> addOrUpdate(@RequestBody RetailShipmentsDTO retailShipmentsDTO) {
return retailService.addOrUpdateRetailShipments(retailShipmentsDTO);
return receiptService.addOrUpdateRetailShipments(retailShipmentsDTO);
}

@PostMapping("/shipments/deleteByIds")
public Response<String> deleteByIds(@RequestParam("ids") List<Long> ids) {
return retailService.deleteRetailShipments(ids);
return receiptService.deleteRetailShipments(ids);
}

@PutMapping("/shipments/updateStatus")
public Response<String> updateStatus(@RequestParam("ids") List<Long> ids, @RequestParam("status") Integer status) {
return retailService.updateRetailShipmentsStatus(ids, status);
return receiptService.updateRetailShipmentsStatus(ids, status);
}

@GetMapping("/shipments/detail/{id}")
public Response<RetailShipmentsDetailVO> detail(@PathVariable("id") Long id) {
return retailService.getRetailShipmentsDetail(id);
return receiptService.getRetailShipmentsDetail(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.api.report;

import com.wansenai.service.receipt.ReceiptService;
import com.wansenai.utils.response.Response;
import com.wansenai.vo.receipt.RetailStatisticalDataVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/report")
public class ReportController {

private final ReceiptService receiptService;

public ReportController(ReceiptService receiptService) {
this.receiptService = receiptService;
}

@GetMapping("homePage/statistics")
public Response<RetailStatisticalDataVO> getStatisticalData() {
return receiptService.getRetailStatistics();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wansenai.mappers.warehouse.WarehouseMapper">
<mapper namespace="com.wansenai.mappers.receipt.ReceiptMainMapper">

</mapper>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.receipt;

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

import java.math.BigDecimal;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RetailStatisticalDataVO {

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

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

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

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

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

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

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

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

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

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

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

@JsonSerialize(using = BigDecimalSerializerBO.class)
private BigDecimal yearPurchase;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.math.RoundingMode
class BigDecimalSerializerBO : JsonSerializer<BigDecimal>() {
override fun serialize(value: BigDecimal?, gen: JsonGenerator, serializers: SerializerProvider) {
if (value != null) {
val scaledValue = value.setScale(3, RoundingMode.HALF_UP)
val scaledValue = value.setScale(2, RoundingMode.HALF_UP)
if (scaledValue.stripTrailingZeros().scale() <= 0) {
gen.writeNumber(scaledValue.toBigInteger())
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
import com.wansenai.utils.response.Response;
import com.wansenai.vo.receipt.RetailShipmentsVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wansenai.vo.receipt.RetailStatisticalDataVO;

import java.util.List;

public interface RetailService extends IService<ReceiptMain> {
public interface ReceiptService extends IService<ReceiptMain> {

/**
* Query retail shipment orders with pagination.
Expand Down Expand Up @@ -83,4 +84,14 @@ public interface RetailService extends IService<ReceiptMain> {
*/
Response<String> updateRetailShipmentsStatus(List<Long> ids, Integer status);


/**
* Query the data summary of the six columns on the tenant's homepage.
* <p>
* 根据id集合和状态批量修改零售出库单状态
*
* @return Return to homepage data summary
* 返回首页数据汇总
*/
Response<RetailStatisticalDataVO> getRetailStatistics();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
import com.wansenai.bo.ShipmentsDataBO;
import com.wansenai.dto.receipt.QueryShipmentsDTO;
import com.wansenai.dto.receipt.RetailShipmentsDTO;
import com.wansenai.entities.product.ProductStock;
import com.wansenai.entities.product.ProductStockKeepUnit;
import com.wansenai.entities.receipt.ReceiptMain;
import com.wansenai.entities.receipt.ReceiptSub;
import com.wansenai.entities.system.SysFile;
import com.wansenai.mappers.product.ProductStockKeepUnitMapper;
import com.wansenai.mappers.product.ProductStockMapper;
import com.wansenai.mappers.receipt.ReceiptMainMapper;
import com.wansenai.mappers.system.SysFileMapper;
import com.wansenai.service.basic.MemberService;
import com.wansenai.service.receipt.ReceiptSubService;
import com.wansenai.service.receipt.RetailService;
import com.wansenai.service.receipt.ReceiptService;
import com.wansenai.service.user.ISysUserService;
import com.wansenai.utils.SnowflakeIdUtil;
import com.wansenai.utils.constants.CommonConstants;
Expand All @@ -27,20 +24,27 @@
import com.wansenai.utils.response.Response;
import com.wansenai.vo.receipt.RetailShipmentsDetailVO;
import com.wansenai.vo.receipt.RetailShipmentsVO;
import com.wansenai.vo.receipt.RetailStatisticalDataVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class RetailServiceImpl extends ServiceImpl<ReceiptMainMapper, ReceiptMain> implements RetailService {
public class ReceiptServiceImpl extends ServiceImpl<ReceiptMainMapper, ReceiptMain> implements ReceiptService {

private final ReceiptMainMapper receiptMainMapper;

Expand All @@ -54,7 +58,7 @@ public class RetailServiceImpl extends ServiceImpl<ReceiptMainMapper, ReceiptMai

private final ProductStockKeepUnitMapper productStockKeepUnitMapper;

public RetailServiceImpl(ReceiptMainMapper receiptMainMapper, ReceiptSubService receiptSubService, MemberService memberService, ISysUserService userService, SysFileMapper fileMapper, ProductStockKeepUnitMapper productStockKeepUnitMapper) {
public ReceiptServiceImpl(ReceiptMainMapper receiptMainMapper, ReceiptSubService receiptSubService, MemberService memberService, ISysUserService userService, SysFileMapper fileMapper, ProductStockKeepUnitMapper productStockKeepUnitMapper) {
this.receiptMainMapper = receiptMainMapper;
this.receiptSubService = receiptSubService;
this.memberService = memberService;
Expand Down Expand Up @@ -368,4 +372,73 @@ public Response<String> updateRetailShipmentsStatus(List<Long> ids, Integer stat
return Response.responseMsg(RetailCodeEnum.UPDATE_RETAIL_SHIPMENTS_ERROR);
}
}

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

var retailData = lambdaQuery()
.eq(ReceiptMain::getType, "出库")
.in(ReceiptMain::getSubType, "零售出库")
.eq(ReceiptMain::getStatus, 1)
.eq(ReceiptMain::getDeleteFlag, 0)
.list();

var salesData = lambdaQuery()
.eq(ReceiptMain::getType, "出库")
.in(ReceiptMain::getSubType, "销售出库")
.eq(ReceiptMain::getStatus, 1)
.eq(ReceiptMain::getDeleteFlag, 0)
.list();

var purchaseData = lambdaQuery()
.eq(ReceiptMain::getType, "入库")
.eq(ReceiptMain::getSubType, "采购入库")
.eq(ReceiptMain::getStatus, 1)
.eq(ReceiptMain::getDeleteFlag, 0)
.list();

var todayRetailSales = calculateTotalPrice(retailData, now.with(LocalTime.MIN), now.with(LocalTime.MAX));
var yesterdayRetailSales = calculateTotalPrice(retailData, now.minusDays(1).with(LocalTime.MIN), now.minusDays(1).with(LocalTime.MAX));
var monthRetailSales = calculateTotalPrice(retailData, now.withDayOfMonth(1).with(LocalTime.MIN), now.with(LocalTime.MAX));
var yearRetailSales = calculateTotalPrice(retailData, now.withDayOfYear(1).with(LocalTime.MIN), now.with(LocalTime.MAX));

var todaySales = calculateTotalPrice(salesData, now.with(LocalTime.MIN), now.with(LocalTime.MAX));
var yesterdaySales = calculateTotalPrice(salesData, now.minusDays(1).with(LocalTime.MIN), now.minusDays(1).with(LocalTime.MAX));
var monthSales = calculateTotalPrice(salesData, now.withDayOfMonth(1).with(LocalTime.MIN), now.with(LocalTime.MAX));
var yearSales = calculateTotalPrice(salesData, now.withDayOfYear(1).with(LocalTime.MIN), now.with(LocalTime.MAX));

var todayPurchase = calculateTotalPrice(purchaseData, now.with(LocalTime.MIN), now.with(LocalTime.MAX));
var yesterdayPurchase = calculateTotalPrice(purchaseData, now.minusDays(1).with(LocalTime.MIN), now.minusDays(1).with(LocalTime.MAX));
var monthPurchase = calculateTotalPrice(purchaseData, now.withDayOfMonth(1).with(LocalTime.MIN), now.with(LocalTime.MAX));
var yearPurchase = calculateTotalPrice(purchaseData, now.withDayOfYear(1).with(LocalTime.MIN), now.with(LocalTime.MAX));

var retailStatisticalDataVO = RetailStatisticalDataVO.builder()
.todayRetailSales(todayRetailSales)
.yesterdayRetailSales(yesterdayRetailSales)
.monthRetailSales(monthRetailSales)
.yearRetailSales(yearRetailSales)

.todaySales(todaySales)
.yesterdaySales(yesterdaySales)
.monthSales(monthSales)
.yearSales(yearSales)

.todayPurchase(todayPurchase)
.yesterdayPurchase(yesterdayPurchase)
.monthPurchase(monthPurchase)
.yearPurchase(yearPurchase)
.build();

return Response.responseData(retailStatisticalDataVO);
}

private BigDecimal calculateTotalPrice(List<ReceiptMain> data, LocalDateTime start, LocalDateTime end) {
return data.stream()
.filter(item -> item.getCreateTime().isAfter(start) && item.getCreateTime().isBefore(end))
.map(ReceiptMain::getTotalPrice)
.reduce(BigDecimal.ZERO, BigDecimal::add)
.setScale(2, RoundingMode.HALF_UP);
}

}
16 changes: 16 additions & 0 deletions web/src/api/report/report.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {defHttp} from '/@/utils/http/axios';
import {BaseDataResp, BaseResp} from "@/api/model/baseModel";
import {reportModel} from "@/api/report/model/reportModel";

enum API {
getStatisticalData = '/report/homePage/statistics'
}


export function getStatistical() {
return defHttp.get<BaseDataResp<reportModel>>(
{
url: API.getStatisticalData,
},
);
}
14 changes: 14 additions & 0 deletions web/src/api/report/reportModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface RetailStatisticalResp {
todaySales: number;
yesterdaySales: number;
todayRetailSales: number;
yesterdayRetailSales: number;
todayPurchase: number;
yesterdayPurchase: number;
monthSales: number;
monthRetailSales: number;
monthPurchase: number;
yearSales: number;
yearRetailSales: number;
yearPurchase: number;
}
3 changes: 1 addition & 2 deletions web/src/components/VxeTable/src/css/component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
& > .ant-input-number,
& > .ant-cascader-picker .ant-cascader-input,
& > .ant-calendar-picker .ant-calendar-picker-input {
// border-color: $vxe-table-validate-error-color;
box-shadow: none;
}
}
Expand Down Expand Up @@ -121,4 +120,4 @@
}
}
}
}
}
3 changes: 1 addition & 2 deletions web/src/components/VxeTable/src/css/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@import './common';
@import './variable';
@import './scrollbar';
@import './toolbar';
@import './component';
@import 'vxe-table/styles/index';
@import 'vxe-table/styles/index';
2 changes: 1 addition & 1 deletion web/src/components/VxeTable/src/css/scrollbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
::-webkit-scrollbar-corner {
background-color: #fff;
}
}
}
Loading

0 comments on commit ad50426

Please sign in to comment.