|
|
@@ -0,0 +1,148 @@
|
|
|
+package com.sckw.report.service.impl;
|
|
|
+
|
|
|
+import com.sckw.contract.api.feign.SalesReportContractFeignService;
|
|
|
+import com.sckw.contract.api.model.dto.req.SalesReportGoodsQueryDto;
|
|
|
+import com.sckw.contract.api.model.dto.req.TradeEntListQueryFeignDto;
|
|
|
+import com.sckw.contract.api.model.dto.res.SalesReportGoodsResVo;
|
|
|
+import com.sckw.contract.api.model.dto.res.TradeEntInfoResVo;
|
|
|
+import com.sckw.core.web.context.LoginUserHolder;
|
|
|
+import com.sckw.core.web.response.BaseResult;
|
|
|
+import com.sckw.excel.utils.ExcelUtil;
|
|
|
+import com.sckw.order.api.feign.SalesReportOrderFeignService;
|
|
|
+import com.sckw.order.api.model.SalesReportDataVo;
|
|
|
+import com.sckw.order.api.model.SalesReportQueryDto;
|
|
|
+import com.sckw.report.model.dto.SalesReportDTO;
|
|
|
+import com.sckw.report.model.vo.CustomerVO;
|
|
|
+import com.sckw.report.model.vo.ProductVO;
|
|
|
+import com.sckw.report.model.vo.SalesReportVO;
|
|
|
+import com.sckw.report.model.vo.SalesReportSummaryVO;
|
|
|
+import com.sckw.report.service.KwSalesReportService;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class KwSalesReportServiceImpl implements KwSalesReportService {
|
|
|
+
|
|
|
+ private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SalesReportContractFeignService salesReportContractFeignService;
|
|
|
+ @Autowired
|
|
|
+ private SalesReportOrderFeignService salesReportOrderFeignService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SalesReportVO> getSalesReportData(SalesReportDTO salesReportDTO) {
|
|
|
+ // 调用订单服务获取销售报表数据
|
|
|
+ SalesReportQueryDto queryDto = new SalesReportQueryDto();
|
|
|
+ queryDto.setCurEntId(LoginUserHolder.getEntId());
|
|
|
+ queryDto.setCustomerId(salesReportDTO.getCustomerId());
|
|
|
+ queryDto.setGoodsId(salesReportDTO.getProductId());
|
|
|
+
|
|
|
+ // 转换时间格式:Date转String yyyy-MM-dd
|
|
|
+ if (salesReportDTO.getStartTime() != null) {
|
|
|
+ queryDto.setStartTime(sdf.format(salesReportDTO.getStartTime()));
|
|
|
+ }
|
|
|
+ if (salesReportDTO.getEndTime() != null) {
|
|
|
+ queryDto.setEndTime(sdf.format(salesReportDTO.getEndTime()));
|
|
|
+ }
|
|
|
+
|
|
|
+ BaseResult<List<SalesReportDataVo>> result = salesReportOrderFeignService.querySalesReportData(queryDto);
|
|
|
+ if (result != null && result.isSuccess() && result.getData() != null) {
|
|
|
+ List<SalesReportDataVo> salesReportData = result.getData();
|
|
|
+ // 转换为销售报表VO
|
|
|
+ AtomicInteger serialNumber = new AtomicInteger(1);
|
|
|
+ return salesReportData.stream().map(data -> {
|
|
|
+ SalesReportVO vo = new SalesReportVO();
|
|
|
+ vo.setSerialNumber(serialNumber.getAndIncrement());
|
|
|
+ vo.setCustomerName(data.getCustomerName());
|
|
|
+ vo.setProductName(data.getGoodsName());
|
|
|
+ vo.setSalesQuantity(data.getSalesQuantity());
|
|
|
+ vo.setAveragePrice(data.getAveragePrice());
|
|
|
+ vo.setSalesAmount(data.getSalesAmount());
|
|
|
+ vo.setTotalSalesQuantity(data.getCumulativeQuantity());
|
|
|
+ vo.setTotalAveragePrice(data.getCumulativeAveragePrice());
|
|
|
+ vo.setTotalSalesAmount(data.getCumulativeAmount());
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SalesReportSummaryVO getSalesReportSummary(SalesReportDTO salesReportDTO) {
|
|
|
+ List<SalesReportVO> reportData = getSalesReportData(salesReportDTO);
|
|
|
+ SalesReportSummaryVO summary = new SalesReportSummaryVO();
|
|
|
+
|
|
|
+ BigDecimal totalSalesQuantity = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalSalesAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalTotalSalesQuantity = BigDecimal.ZERO;
|
|
|
+ BigDecimal totalTotalSalesAmount = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ for (SalesReportVO vo : reportData) {
|
|
|
+ totalSalesQuantity = totalSalesQuantity.add(vo.getSalesQuantity());
|
|
|
+ totalSalesAmount = totalSalesAmount.add(vo.getSalesAmount());
|
|
|
+ totalTotalSalesQuantity = totalTotalSalesQuantity.add(vo.getTotalSalesQuantity());
|
|
|
+ totalTotalSalesAmount = totalTotalSalesAmount.add(vo.getTotalSalesAmount());
|
|
|
+ }
|
|
|
+
|
|
|
+ summary.setTotalSalesQuantity(totalSalesQuantity);
|
|
|
+ summary.setTotalSalesAmount(totalSalesAmount);
|
|
|
+ summary.setTotalTotalSalesQuantity(totalTotalSalesQuantity);
|
|
|
+ summary.setTotalTotalSalesAmount(totalTotalSalesAmount);
|
|
|
+
|
|
|
+ return summary;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void exportSalesReport(SalesReportDTO salesReportDTO, HttpServletResponse response) {
|
|
|
+ List<SalesReportVO> reportData = getSalesReportData(salesReportDTO);
|
|
|
+
|
|
|
+ // 导出Excel
|
|
|
+ ExcelUtil.download(response, SalesReportVO.class, reportData);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CustomerVO> getAllCustomers() {
|
|
|
+ TradeEntListQueryFeignDto queryDto = new TradeEntListQueryFeignDto();
|
|
|
+ queryDto.setCurEntId(LoginUserHolder.getEntId());
|
|
|
+ BaseResult<List<TradeEntInfoResVo>> result = salesReportContractFeignService.queryTradeEntList(queryDto);
|
|
|
+ if (result != null && result.isSuccess() && result.getData() != null) {
|
|
|
+ List<TradeEntInfoResVo> customerList = result.getData();
|
|
|
+ return customerList.stream().map(customer -> {
|
|
|
+ CustomerVO vo = new CustomerVO();
|
|
|
+ vo.setCustomerId(customer.getEntId());
|
|
|
+ vo.setCustomerName(customer.getEntName());
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ProductVO> getAllProducts() {
|
|
|
+ SalesReportGoodsQueryDto queryDto = new SalesReportGoodsQueryDto();
|
|
|
+ queryDto.setCurEntId(LoginUserHolder.getEntId());
|
|
|
+ BaseResult<List<SalesReportGoodsResVo>> result = salesReportContractFeignService.queryGoodsList(queryDto);
|
|
|
+ if (result != null && result.isSuccess() && result.getData() != null) {
|
|
|
+ List<SalesReportGoodsResVo> goodsList = result.getData();
|
|
|
+ return goodsList.stream().map(goods -> {
|
|
|
+ ProductVO vo = new ProductVO();
|
|
|
+ vo.setProductId(goods.getGoodsId());
|
|
|
+ vo.setProductName(goods.getGoodsName());
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+}
|