liding
2 天以前 f6f57ba70679a0b050031f3cdf81b5bf5d4cbd60
1.生产加工优化 2.销售,库存查询优化
已修改8个文件
126 ■■■■ 文件已修改
main-business/src/main/java/com/ruoyi/business/controller/HomePageController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
main-business/src/main/java/com/ruoyi/business/dto/HomePageDto.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
main-business/src/main/java/com/ruoyi/business/dto/PendingInventoryDto.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main-business/src/main/java/com/ruoyi/business/dto/SalesRecordDto.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main-business/src/main/java/com/ruoyi/business/service/impl/ProductionMasterServiceImpl.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java 41 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main-business/src/main/resources/db/migration/postgresql/V20250611160300__create_table_sales_record.sql 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main-business/src/main/java/com/ruoyi/business/controller/HomePageController.java
@@ -39,7 +39,7 @@
        Map<String, BigDecimal> maps = officialInventoryService.selectOfficialAllInfo();
        homePageDto.setInventory(maps);
        //月度统计
        homePageDto.setResultMouth((List<Map<String, BigDecimal>>) map.get("resultMouth"));
        homePageDto.setResultMouth((Map<String, BigDecimal>) map.get("resultMouth"));
        //销售数据
        homePageDto.setSalesResults((List<Map<String, Object>>) map.get("salesResults"));
main-business/src/main/java/com/ruoyi/business/dto/HomePageDto.java
@@ -28,6 +28,6 @@
    //销售数据
    private List<Map<String, Object>> salesResults;
    //月度销售
    private List<Map<String, BigDecimal>> resultMouth;
    private Map<String, BigDecimal> resultMouth;
}
main-business/src/main/java/com/ruoyi/business/dto/PendingInventoryDto.java
@@ -44,5 +44,10 @@
     */
    private String coal;
    /**
     * 登记人
     */
    private String registrant;
    private String searchAll;
}
main-business/src/main/java/com/ruoyi/business/dto/SalesRecordDto.java
@@ -6,5 +6,7 @@
@Data
public class SalesRecordDto extends SalesRecord {
    private String searchAll;
    private String coal;
}
main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
@@ -15,6 +15,7 @@
import com.ruoyi.business.dto.PendingInventoryDto;
import com.ruoyi.business.entity.OfficialInventory;
import com.ruoyi.business.entity.PendingInventory;
import com.ruoyi.business.entity.SalesRecord;
import com.ruoyi.business.mapper.OfficialInventoryMapper;
import com.ruoyi.business.mapper.PendingInventoryMapper;
import com.ruoyi.business.service.InputInventoryRecordService;
@@ -22,6 +23,7 @@
import com.ruoyi.business.service.PendingInventoryService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import lombok.RequiredArgsConstructor;
@@ -29,6 +31,8 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -65,6 +69,31 @@
    public IPage<PendingInventoryDto> selectPendingInventoryList(Page page, PendingInventoryDto pendingInventoryDto) {
        // 1. 构建主查询
        LambdaQueryWrapper<PendingInventory> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(pendingInventoryDto.getSearchAll())) {
            String searchValue = pendingInventoryDto.getSearchAll();
            // 1. 先尝试作为日期查询
            try {
                LocalDate RegistrationDate = LocalDate.parse(searchValue);
                queryWrapper.eq(PendingInventory::getRegistrationDate, RegistrationDate);
            } catch (DateTimeParseException e) {
                // 2. 如果不是日期,则作为煤种名称查询
                LambdaQueryWrapper<CoalInfo> coalQueryWrapper = new LambdaQueryWrapper<>();
                coalQueryWrapper.like(CoalInfo::getCoal, searchValue);
                List<CoalInfo> coalInfos = coalInfoMapper.selectList(coalQueryWrapper);
                if (!coalInfos.isEmpty()) {
                    // 提取所有匹配的煤种ID
                    List<Long> coalIds = coalInfos.stream()
                            .map(CoalInfo::getId)
                            .collect(Collectors.toList());
                    // 使用in查询匹配任意一个煤种ID
                    queryWrapper.in(PendingInventory::getCoalId, coalIds);
                } else {
                    // 3. 如果找不到煤种,可以返回空结果
                    queryWrapper.eq(PendingInventory::getCoalId, "-1"); // 使用不可能存在的ID
                }
            }
        }
        queryWrapper.orderByDesc(PendingInventory::getCreateTime);
        // 2. 执行主表分页查询
main-business/src/main/java/com/ruoyi/business/service/impl/ProductionMasterServiceImpl.java
@@ -19,7 +19,9 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@@ -282,13 +284,44 @@
     * 将加工产生的产品记录到待入库表
     */
    private void insertPendingInventory(List<Production> list) {
        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDate = currentDate.format(formatter);
        // 常量定义:保留2位小数,四舍五入模式
        final int SCALE = 2;
        final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP;
        // 税率13%,用字符串构造BigDecimal避免精度误差
        final BigDecimal TAX_RATE = new BigDecimal("1.13");
        for (Production p : list) {
            PendingInventory pending = new PendingInventory();
            pending.setCoalId(p.getCoalId());
            pending.setInventoryQuantity(p.getProductionQuantity());
            pending.setSupplierName("生产加工入库");
            pending.setTotalPriceIncludingTax(p.getTotalCost());
            pending.setPriceIncludingTax(p.getPurchasePrice());
            pending.setUnit("t");
            pending.setSupplierName(formattedDate + " - " + "生产加工入库");
            // 1. 非空处理:避免null导致的运算异常
            BigDecimal totalCost = p.getTotalCost() == null ? BigDecimal.ZERO : p.getTotalCost();
            BigDecimal productionQuantity = p.getProductionQuantity() == null ? BigDecimal.ZERO : p.getProductionQuantity();
            // 2. 含税总价 = 含税单价 * 产量 → 保留2位小数
            BigDecimal totalPriceIncludingTax = totalCost.multiply(productionQuantity)
                    .setScale(SCALE, ROUNDING_MODE);
            pending.setTotalPriceIncludingTax(totalPriceIncludingTax);
            // 3. 含税单价 → 直接保留2位小数
            pending.setPriceIncludingTax(totalCost.setScale(SCALE, ROUNDING_MODE));
            // 4. 不含税单价 = 含税单价 / 1.13 → 先高精度计算,再保留2位
            BigDecimal priceExcludingTax = totalCost.divide(TAX_RATE, 10, ROUNDING_MODE) // 中间保留10位防误差
                    .setScale(SCALE, ROUNDING_MODE);   // 最终保留2位
            pending.setPriceExcludingTax(priceExcludingTax);
            // 5. 不含税总价 = 不含税单价 * 产量 → 保留2位小数
            BigDecimal totalPriceExcludingTax = priceExcludingTax.multiply(productionQuantity)
                    .setScale(SCALE, ROUNDING_MODE);
            pending.setTotalPriceExcludingTax(totalPriceExcludingTax);
            pending.setRegistrantId(p.getProducerId());
            pending.setRegistrationDate(LocalDate.now());
            pendingInventoryMapper.insert(pending);
main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java
@@ -19,6 +19,7 @@
import com.ruoyi.business.service.SalesRecordService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import lombok.RequiredArgsConstructor;
@@ -67,6 +68,32 @@
    public IPage<SalesRecordDto> selectSalesRecordList(Page<SalesRecord> page, SalesRecordDto salesRecordDto) {
        // 1. 创建查询条件,按创建时间倒序排序
        LambdaQueryWrapper<SalesRecord> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(salesRecordDto.getSearchAll())) {
            String searchValue = salesRecordDto.getSearchAll();
            // 1. 先尝试作为日期查询
            try {
                LocalDate saleDate = LocalDate.parse(searchValue);
                queryWrapper.eq(SalesRecord::getSaleDate, saleDate);
            } catch (DateTimeParseException e) {
                // 2. 如果不是日期,则作为煤种名称查询
                LambdaQueryWrapper<CoalInfo> coalQueryWrapper = new LambdaQueryWrapper<>();
                coalQueryWrapper.like(CoalInfo::getCoal, searchValue);
                List<CoalInfo> coalInfos = coalInfoMapper.selectList(coalQueryWrapper);
                if (!coalInfos.isEmpty()) {
                    // 提取所有匹配的煤种ID
                    List<Long> coalIds = coalInfos.stream()
                            .map(CoalInfo::getId)
                            .collect(Collectors.toList());
                    // 使用in查询匹配任意一个煤种ID
                    queryWrapper.in(SalesRecord::getCoalId, coalIds);
                } else {
                    // 3. 如果找不到煤种,可以返回空结果
                    queryWrapper.eq(SalesRecord::getCoalId, "-1"); // 使用不可能存在的ID
                }
            }
        }
        queryWrapper.orderByDesc(SalesRecord::getCreateTime);
        // 2. 获取分页的销售记录
@@ -509,13 +536,13 @@
                        )
                ));
        //构建结果(保持煤种顺序,销量默认为0)
        List<Map<String, Object>> resultMouth = new ArrayList<>();
        // 2. 创建 resultMouth,存储煤种及其销量(Map 结构)
        Map<String, BigDecimal> resultMouthMap = new LinkedHashMap<>();
        for (CoalInfo coal : allCoalTypes) {
            Map<String, Object> item = new LinkedHashMap<>();
            item.put("coal", coal.getCoal()); // 煤种名称
            item.put("saleQuantity", salesByCoalId.getOrDefault(coal.getId(), BigDecimal.valueOf(0))); // 销量
            resultMouth.add(item);
            resultMouthMap.put(
                    coal.getCoal(),  // 煤种名称(如 "无烟煤")
                    salesByCoalId.getOrDefault(coal.getId(), BigDecimal.valueOf(0)) // 销量
            );
        }
        result.put("revenueAmount", revenueAmount.setScale(2, RoundingMode.HALF_UP));
@@ -526,7 +553,7 @@
        result.put("trendQuantity", trendQuantity);
        result.put("revenueDistribution", revenueDistribution);
        result.put("salesResults", results);
        result.put("resultMouth", resultMouth);
        result.put("resultMouth", resultMouthMap);
        return result;
    }
main-business/src/main/resources/db/migration/postgresql/V20250611160300__create_table_sales_record.sql
@@ -5,7 +5,7 @@
    sale_date           DATE           NOT NULL,          -- 销售日期
    customer_id         BIGINT,                           -- 客户id
    customer            VARCHAR(255)   NOT NULL,          -- 客户
    coal_id             VARCHAR(255)   NOT NULL,          -- 煤种 id
    coal_id             BIGINT   NOT NULL,          -- 煤种 id
    price_including_tax DECIMAL(10, 2) NOT NULL,          -- 单价(含税)
    inventory_quantity  DECIMAL(10, 0) NOT NULL,          -- 库存数量
    unit                VARCHAR(100)   NOT NULL,          -- 单位
@@ -18,8 +18,8 @@
    gross_profit        DECIMAL(10, 2),                   -- 毛利润
    net_profit          DECIMAL(10, 2),                   -- 净利润
    registrant_id       BIGINT,                           -- 登记人id
    registrant          VARCHAR(255)   NOT NULL,          -- 登记人
    registration_date   DATE           NOT NULL,          -- 登记日期
    registrant          VARCHAR(255)   ,          -- 登记人
    registration_date   DATE           ,          -- 登记日期
    create_time         TIMESTAMP WITHOUT TIME ZONE,          -- 上传时间,默认当前时间
    update_time         TIMESTAMP WITHOUT TIME ZONE,          -- 最后更新时间,默认当前时间