feat:1.出入库单位转换
2.仓储/耗材导出字段值优化
3.仓储/耗材库存为0不展示
已修改12个文件
131 ■■■■ 文件已修改
src/main/java/com/ruoyi/approve/utils/DailyRedisCounter.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/consumables/execl/ConsumablesOutRecordExportData.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/production/dto/ProductOrderDto.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/stock/dto/StockInventoryDto.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/stock/execl/StockOutRecordExportData.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java 45 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/consumables/ConsumablesInRecordMapper.xml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/consumables/ConsumablesInventoryMapper.xml 58 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/consumables/ConsumablesOutRecordMapper.xml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/stock/StockInRecordMapper.xml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/stock/StockInventoryMapper.xml 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/stock/StockOutRecordMapper.xml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ruoyi/approve/utils/DailyRedisCounter.java
@@ -8,7 +8,6 @@
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
src/main/java/com/ruoyi/consumables/execl/ConsumablesOutRecordExportData.java
@@ -20,7 +20,7 @@
    @Excel(name = "出库来源")
    private String recordType;
    @Excel(name = "出库数量")
    private String ConsumablesInNum;
    private String stockOutNum;
    @Excel(name = "出库时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
src/main/java/com/ruoyi/production/dto/ProductOrderDto.java
@@ -57,4 +57,7 @@
    //是否发货(台账页面颜色控制)
    private Boolean isFh;
    //单位
    private String unit;
}
src/main/java/com/ruoyi/stock/dto/StockInventoryDto.java
@@ -4,12 +4,14 @@
import com.ruoyi.stock.pojo.StockInventory;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
@EqualsAndHashCode(callSuper = true)
@Data
public class StockInventoryDto extends StockInventory {
src/main/java/com/ruoyi/stock/execl/StockOutRecordExportData.java
@@ -20,7 +20,7 @@
    @Excel(name = "出库来源")
    private String recordType;
    @Excel(name = "出库数量")
    private String stockInNum;
    private String stockOutNum;
    @Excel(name = "出库时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -12,6 +12,7 @@
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.equipmentenergyconsumption.mapper.ElectricityConsumptionAreaMapper;
import com.ruoyi.framework.web.domain.R;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.stock.dto.StockInRecordDto;
@@ -34,6 +35,7 @@
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
/**
@@ -55,6 +57,7 @@
    private final WeighbridgeDocGenerator weighbridgeDocGenerator;
    private final ProductMapper productMapper;
    private final ProductModelMapper productModelMapper;
    private final ElectricityConsumptionAreaMapper electricityConsumptionAreaMapper;
    @Override
    public IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto) {
@@ -70,9 +73,11 @@
        stockInRecordDto.setRecordId(stockInventoryDto.getRecordId());
        stockInRecordDto.setRecordType(stockInventoryDto.getRecordType());
        stockInRecordDto.setWeighingOperator(stockInventoryDto.getWeighingOperator());
        Long modelId;
        if (stockInventoryDto.getProductId() != null) {
            stockInRecordDto.setProductId(stockInventoryDto.getProductId());
            stockInRecordDto.setProductModelId(stockInventoryDto.getProductModelId());
            modelId = stockInventoryDto.getProductModelId();
        }else {
            Product parent = productMapper.selectOne(new LambdaQueryWrapper<Product>().eq(Product::getProductName, "原材料").last("limit 1"));
            if (parent == null) {
@@ -120,6 +125,8 @@
            stockInRecordDto.setProductId(product.getId());
            stockInRecordDto.setProductModelId(productModelId);
            stockInventoryDto.setProductModelId(productModelId);
            modelId = productModelId;
        }
        stockInRecordDto.setRemark(stockInventoryDto.getRemark());
        stockInRecordDto.setType("0");
@@ -148,12 +155,13 @@
                new QueryWrapper<StockInventory>().lambda()
                        .eq(StockInventory::getProductModelId, stockInventoryDto.getProductModelId())
        );
        ProductModel productModel = productModelMapper.selectById(modelId);
        BigDecimal weight = compareUnit(stockInventoryDto, productModel);
        if (ObjectUtils.isEmpty(oldStockInventory)) {
            // 新增库存
            StockInventory newStockInventory = new StockInventory();
            newStockInventory.setProductModelId(stockInventoryDto.getProductModelId());
            newStockInventory.setQualitity(stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ?
                    stockInventoryDto.getNetWeight() : stockInventoryDto.getQualitity());
            newStockInventory.setQualitity(weight);
            newStockInventory.setVersion(1);
            newStockInventory.setRemark(stockInventoryDto.getRemark());
            newStockInventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
@@ -162,8 +170,7 @@
            stockInventoryMapper.insert(newStockInventory);
        } else {
            // 更新库存
            stockInventoryDto.setQualitity(stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ?
                    stockInventoryDto.getNetWeight() : stockInventoryDto.getQualitity());
            stockInventoryDto.setQualitity(weight);
            stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
        }
        return true;
@@ -173,6 +180,9 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean subtractStockInventory(StockInventoryDto stockInventoryDto) {
        ProductModel productModel = productModelMapper.selectById(stockInventoryDto.getProductModelId());
        BigDecimal weight = compareUnit(stockInventoryDto, productModel);
        //  新增出库记录
        StockOutRecordDto stockOutRecordDto = new StockOutRecordDto();
        stockOutRecordDto.setRecordId(stockInventoryDto.getRecordId());
@@ -202,12 +212,37 @@
        if (lockedQty == null) {
            lockedQty = BigDecimal.ZERO;
        }
        stockInventoryDto.setQualitity(weight);
        if (stockInventoryDto.getQualitity().compareTo(oldStockInventory.getQualitity().subtract(lockedQty)) > 0) {
            throw new RuntimeException("库存不足无法出库");
        }
        stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto);
        return true;
    }
    private BigDecimal compareUnit(StockInventoryDto stockInventoryDto, ProductModel productModel) {
        String unit = "";
        if (productModel != null) {
            unit = productModel.getUnit();
        }
        BigDecimal weight;
        if (stockInventoryDto.getUnit().equals(unit)) {
            weight = stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ?
                    stockInventoryDto.getNetWeight() : stockInventoryDto.getQualitity();
        } else {
            if ("吨".equals(unit)) {
                weight =stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ?
                        stockInventoryDto.getNetWeight().divide(BigDecimal.valueOf(1000),2, RoundingMode.HALF_UP) : stockInventoryDto.getQualitity().divide(BigDecimal.valueOf(1000),2,RoundingMode.HALF_UP);
            } else if ("公斤".equals(unit)) {
                weight = stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ?
                        stockInventoryDto.getNetWeight().multiply(BigDecimal.valueOf(1000)) : stockInventoryDto.getQualitity().multiply(BigDecimal.valueOf(1000));
            }else {
                weight =stockInventoryDto.getProductType() != null && stockInventoryDto.getProductType() == 0 ?
                        stockInventoryDto.getNetWeight() : stockInventoryDto.getQualitity();
            }
        }
        return weight;
    }
    @Override
@@ -235,7 +270,7 @@
                stockInventoryDto.setModel(dto.getModel());
                stockInventoryDto.setUnit(dto.getUnit());
                // 解决方案1:通过代理对象调用
                //通过代理对象调用
                ((StockInventoryService) AopContext.currentProxy()).addstockInventory(stockInventoryDto);
            }
            return R.ok("导入成功");
src/main/resources/mapper/consumables/ConsumablesInRecordMapper.xml
@@ -16,6 +16,7 @@
        LEFT JOIN product as p on pm.product_id = p.id
        LEFT JOIN sys_user as u on sir.create_user = u.user_id
        <where>
            1=1
            <if test="params.timeStr != null and params.timeStr != ''">
                and sir.create_time like concat('%',#{params.timeStr},'%')
            </if>
@@ -43,6 +44,7 @@
        LEFT JOIN product as p on pm.product_id = p.id
        LEFT JOIN sys_user as u on sir.create_user = u.user_id
        <where>
            1=1
            <if test="params.timeStr != null and params.timeStr != ''">
                and sir.create_time like concat('%',#{params.timeStr},'%')
            </if>
src/main/resources/mapper/consumables/ConsumablesInventoryMapper.xml
@@ -57,55 +57,57 @@
    </update>
    <select id="pageConsumablesInventory" resultType="com.ruoyi.consumables.dto.ConsumablesInventoryDto">
        select
        SELECT * FROM (
        SELECT
        si.id,
        -- 当前净重 = 入库净重 - 出库净重
        (COALESCE(sir.total_net_weight,0) - COALESCE(sor.total_net_weight,0)) as qualitity,
        (COALESCE(sir.total_net_weight, 0) - COALESCE(sor.total_net_weight, 0)) AS qualitity,
        si.purchaser,
        COALESCE(si.locked_quantity, 0) as locked_quantity,
        COALESCE(si.locked_quantity, 0) AS locked_quantity,
        si.product_model_id,
        si.create_time,
        si.update_time,
        COALESCE(si.warn_num, 0) as warn_num,
        COALESCE(si.warn_num, 0) AS warn_num,
        si.version,
        (si.qualitity - COALESCE(si.locked_quantity, 0)) as un_locked_quantity,
        (si.qualitity - COALESCE(si.locked_quantity, 0)) AS un_locked_quantity,
        pm.model,
        si.remark,
        pm.unit,
        p.product_name,
        p1.product_name as parent_name,
        p1.id as parent_id,
        si.product_id as productId
        from consumables_inventory si
        left join product_model pm on si.product_model_id = pm.id
        left join product p on pm.product_id = p.id
        left join product p1 on p.parent_id = p1.id
        p1.product_name AS parent_name,
        p1.id AS parent_id,
        si.product_id AS productId
        FROM consumables_inventory si
        LEFT JOIN product_model pm ON si.product_model_id = pm.id
        LEFT JOIN product p ON pm.product_id = p.id
        LEFT JOIN product p1 ON p.parent_id = p1.id
        -- 入库净重
        left join (
        select
        LEFT JOIN (
        SELECT
        product_model_id,
        sum(stock_in_num) as total_net_weight
        from consumables_in_record
        group by product_model_id
        ) sir on si.product_model_id = sir.product_model_id
        SUM(stock_in_num) AS total_net_weight
        FROM consumables_in_record
        GROUP BY product_model_id
        ) sir ON si.product_model_id = sir.product_model_id
        -- 出库净重
        left join (
        select
        LEFT JOIN (
        SELECT
        product_model_id,
        sum(stock_out_num) as total_net_weight
        from consumables_out_record
        group by product_model_id
        ) sor on si.product_model_id = sor.product_model_id
        SUM(stock_out_num) AS total_net_weight
        FROM consumables_out_record
        GROUP BY product_model_id
        ) sor ON si.product_model_id = sor.product_model_id
        <where>
            1=1
            <if test="ew.parentId != null and ew.parentId !=''">
                and p.parent_id = #{ew.parentId}
                AND p.parent_id = #{ew.parentId}
            </if>
            <if test="ew.productName != null and ew.productName !=''">
                and p.product_name like concat('%',#{ew.productName},'%')
                AND p.product_name LIKE CONCAT('%', #{ew.productName}, '%')
            </if>
        </where>
        ) temp
        WHERE qualitity != 0
    </select>
    <select id="listConsumablesInventoryExportData" resultType="com.ruoyi.consumables.execl.ConsumablesInventoryExportData">
@@ -190,6 +192,7 @@
        on sir.product_model_id = outWeight.product_model_id
        <where>
            1=1
            <if test="ew.reportDate != null">
                and sir.create_time >= #{ew.reportDate}
                and sir.create_time &lt; DATE_ADD(#{ew.reportDate}, INTERVAL 1 DAY)
@@ -296,6 +299,7 @@
        LEFT JOIN product_model pm ON pm.id = combined_data.product_model_id
        LEFT JOIN product p ON p.id = pm.product_id
        <where>
            1=1
            <if test="ew.productName != null and ew.productName !=''">
                and p.product_name like concat('%',#{ew.productName},'%')
            </if>
src/main/resources/mapper/consumables/ConsumablesOutRecordMapper.xml
@@ -32,6 +32,7 @@
        LEFT JOIN product as p on pm.product_id = p.id
        LEFT JOIN sys_user as u on sor.create_user = u.user_id
        <where>
            1=1
            <if test="params.timeStr != null and params.timeStr != ''">
                and sor.create_time like concat('%',#{params.timeStr},'%')
            </if>
@@ -59,6 +60,7 @@
        LEFT JOIN product as p on pm.product_id = p.id
        LEFT JOIN sys_user as u on sor.create_user = u.user_id
        <where>
            1=1
            <if test="params.timeStr != null and params.timeStr != ''">
                and sor.create_time like concat('%',#{params.timeStr},'%')
            </if>
src/main/resources/mapper/stock/StockInRecordMapper.xml
@@ -17,6 +17,7 @@
        INNER JOIN product p1 ON p1.id = p.parent_id AND p1.product_name != '半成品'
        LEFT JOIN sys_user AS u ON sir.create_user = u.user_id
        <where>
            1=1
            <if test="params.timeStr != null and params.timeStr != ''">
                AND sir.create_time LIKE CONCAT('%', #{params.timeStr}, '%')
            </if>
@@ -44,6 +45,7 @@
        LEFT JOIN product as p on pm.product_id = p.id
        LEFT JOIN sys_user as u on sir.create_user = u.user_id
        <where>
            1=1
            <if test="params.timeStr != null and params.timeStr != ''">
                and sir.create_time like concat('%',#{params.timeStr},'%')
            </if>
src/main/resources/mapper/stock/StockInventoryMapper.xml
@@ -42,8 +42,8 @@
    <update id="updateSubtractStockInventory">
        update stock_inventory
        <set>
            <if test="ew.netWeight != null">
                qualitity = qualitity - #{ew.netWeight},
            <if test="ew.qualitity != null">
                qualitity = qualitity - #{ew.qualitity},
            </if>
            <if test="ew.version != null">
                version = version + 1,
@@ -57,9 +57,9 @@
    </update>
    <select id="pagestockInventory" resultType="com.ruoyi.stock.dto.StockInventoryDto">
        SELECT * FROM (
        SELECT
        si.id,
        -- 当前净重 = 入库净重 - 出库净重
        (COALESCE(sir.total_net_weight, 0) - COALESCE(sor.total_net_weight, 0)) AS qualitity,
        COALESCE(si.locked_quantity, 0) AS locked_quantity,
        si.product_model_id,
@@ -90,6 +90,7 @@
        GROUP BY product_model_id
        ) sor ON si.product_model_id = sor.product_model_id
        <where>
            1=1
            <if test="ew.parentId != null and ew.parentId != ''">
                AND p.parent_id = #{ew.parentId}
            </if>
@@ -97,6 +98,8 @@
                AND p.product_name LIKE CONCAT('%', #{ew.productName}, '%')
            </if>
        </where>
        ) temp
        WHERE qualitity != 0
    </select>
    <select id="listStockInventoryExportData" resultType="com.ruoyi.stock.execl.StockInventoryExportData">
@@ -176,6 +179,7 @@
        on sir.product_model_id = outWeight.product_model_id
        <where>
            1=1
            <if test="ew.reportDate != null">
                and sir.create_time >= #{ew.reportDate}
                and sir.create_time &lt; DATE_ADD(#{ew.reportDate}, INTERVAL 1 DAY)
src/main/resources/mapper/stock/StockOutRecordMapper.xml
@@ -31,6 +31,7 @@
        LEFT JOIN product as p on pm.product_id = p.id
        LEFT JOIN sys_user as u on sor.create_user = u.user_id
        <where>
            1=1
            <if test="params.timeStr != null and params.timeStr != ''">
                and sor.create_time like concat('%',#{params.timeStr},'%')
            </if>
@@ -58,6 +59,7 @@
        LEFT JOIN product as p on pm.product_id = p.id
        LEFT JOIN sys_user as u on sor.create_user = u.user_id
        <where>
            1=1
            <if test="params.timeStr != null and params.timeStr != ''">
                and sor.create_time like concat('%',#{params.timeStr},'%')
            </if>