xiaoyi
2 天以前 b5e1bceabb36fe1d1e5e88397280d12e7044c6dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cn.iocoder.yudao.module.erp.service.statistics;
 
import cn.iocoder.yudao.module.erp.dal.mysql.statistics.ErpPurchaseStatisticsMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
 
import java.math.BigDecimal;
import java.time.LocalDateTime;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.statistics.vo.purchase.ErpPurchasePriceRespVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
/**
 * ERP 采购统计 Service 实现类
 *
 * @author 超级管理员
 */
@Service
public class ErpPurchaseStatisticsServiceImpl implements ErpPurchaseStatisticsService {
 
    @Resource
    private ErpPurchaseStatisticsMapper purchaseStatisticsMapper;
 
    @Override
    public BigDecimal getPurchasePrice(LocalDateTime beginTime, LocalDateTime endTime) {
        return purchaseStatisticsMapper.getPurchasePrice(beginTime, endTime);
    }
 
    @Override
    public PageResult<ErpPurchasePriceRespVO> getPriceAnalysis(PageParam page, Long productId, LocalDateTime[] orderTime) {
        LocalDateTime begin = orderTime != null && orderTime.length > 0 ? orderTime[0] : null;
        LocalDateTime end = orderTime != null && orderTime.length > 1 ? orderTime[1] : null;
        var result = purchaseStatisticsMapper.selectPriceAnalysis(new Page<>(page.getPageNo(), page.getPageSize()), productId, begin, end);
        result.getRecords().forEach(row -> row.setPriceChangeRate(PurchasePriceMetrics.changeRate(row.getLatestPrice(), row.getPreviousPrice())));
        return new PageResult<>(result.getRecords(), result.getTotal());
    }
 
}