From 1d915922d8197aa5d5dc3e40e3088d983dd6e141 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 13 三月 2026 17:57:59 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New_kthg' into dev_New_kthg
---
src/main/resources/mapper/consumables/ConsumablesInventoryMapper.xml | 307 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 307 insertions(+), 0 deletions(-)
diff --git a/src/main/resources/mapper/consumables/ConsumablesInventoryMapper.xml b/src/main/resources/mapper/consumables/ConsumablesInventoryMapper.xml
new file mode 100644
index 0000000..2940d56
--- /dev/null
+++ b/src/main/resources/mapper/consumables/ConsumablesInventoryMapper.xml
@@ -0,0 +1,307 @@
+<?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.ruoyi.consumables.mapper.ConsumablesInventoryMapper">
+
+ <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 -->
+ <resultMap id="BaseResultMap" type="com.ruoyi.consumables.pojo.ConsumablesInventory">
+ <result column="id" property="id"/>
+ <result column="product_model_id" property="productModelId"/>
+ <result column="qualitity" property="qualitity"/>
+ <result column="create_time" property="createTime"/>
+ <result column="update_time" property="updateTime"/>
+ <result column="version" property="version"/>
+ <result column="locked_quantity" property="lockedQuantity"/>
+ <result column="warn_num" property="warnNum"/>
+ </resultMap>
+ <update id="updateAddConsumablesInventory">
+ update Consumables_inventory
+ <set>
+ <if test="ew.qualitity != null">
+ qualitity = qualitity + #{ew.qualitity},
+ </if>
+ <if test="ew.version != null">
+ version = version + 1,
+ </if>
+
+ <if test="ew.remark != null and ew.remark !=''">
+ remark = #{ew.remark},
+ </if>
+ <if test="ew.warnNum != null and ew.warnNum !=''">
+ warn_num = #{ew.warnNum},
+ </if>
+ <if test="ew.lockedQuantity != null and ew.lockedQuantity !=''">
+ locked_quantity = locked_quantity + #{ew.lockedQuantity},
+ </if>
+ update_time = now()
+ </set>
+ where product_model_id = #{ew.productModelId}
+ </update>
+ <update id="updateSubtractConsumablesInventory">
+ update Consumables_inventory
+ <set>
+ <if test="ew.netWeight != null">
+ qualitity = qualitity - #{ew.netWeight},
+ </if>
+ <if test="ew.version != null">
+ version = version + 1,
+ </if>
+ <if test="ew.remark != null and ew.remark !=''">
+ remark = #{ew.remark},
+ </if>
+ update_time = now()
+ </set>
+ where product_model_id = #{ew.productModelId} and qualitity >= #{ew.qualitity}
+ </update>
+
+ <select id="pageConsumablesInventory" resultType="com.ruoyi.consumables.dto.ConsumablesInventoryDto">
+ select
+ si.id,
+ -- 褰撳墠鍑�閲� = 鍏ュ簱鍑�閲� - 鍑哄簱鍑�閲�
+ (COALESCE(sir.total_net_weight,0) - COALESCE(sor.total_net_weight,0)) as net_weight,
+ si.qualitity,
+ 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,
+ si.version,
+ (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
+
+ 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
+ product_model_id,
+ sum(net_weight) 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
+ product_model_id,
+ sum(net_weight) 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}
+ </if>
+ <if test="ew.productName != null and ew.productName !=''">
+ and p.product_name like concat('%',#{ew.productName},'%')
+ </if>
+ </where>
+ </select>
+
+ <select id="listConsumablesInventoryExportData" resultType="com.ruoyi.consumables.execl.ConsumablesInventoryExportData">
+ select si.qualitity,
+ pm.model,
+ pm.unit,
+ p.product_name,
+ coalesce(si.warn_num, 0) as warn_num,
+ coalesce(si.locked_quantity, 0) as locked_quantity,
+ si.remark,
+ si.update_time
+ 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
+ where 1 = 1
+ <if test="ew.productName != null and ew.productName !=''">
+ and p.product_name like concat('%',#{ew.productName},'%')
+ </if>
+ </select>
+
+ <select id="ConsumablesInventoryPage" resultType="com.ruoyi.consumables.dto.ConsumablesInRecordDto">
+ select
+ sir.*,
+ si.qualitity as current_Consumables,
+ pm.model,
+ pm.unit,
+ p.product_name,
+ su.nick_name as create_by,
+
+ -- 褰撳墠鍑�閲� = 鍏ュ簱鍑�閲� - 鍑哄簱鍑�閲�
+ IFNULL(inWeight.total_in_weight,0) - IFNULL(outWeight.total_out_weight,0) as current_weight
+
+ from Consumables_in_record sir
+
+ left join Consumables_inventory si
+ on sir.product_model_id = si.product_model_id
+
+ left join product_model pm
+ on sir.product_model_id = pm.id
+
+ left join product p
+ on pm.product_id = p.id
+
+ left join sys_user su
+ on sir.create_user = su.user_id
+
+ -- 鍏ュ簱鍑�閲嶇粺璁�
+ left join (
+ select
+ product_model_id,
+ sum(net_weight) as total_in_weight
+ from Consumables_in_record
+ group by product_model_id
+ ) inWeight
+ on sir.product_model_id = inWeight.product_model_id
+
+ -- 鍑哄簱鍑�閲嶇粺璁�
+ left join (
+ select
+ product_model_id,
+ sum(net_weight) as total_out_weight
+ from Consumables_out_record
+ group by product_model_id
+ ) outWeight
+ on sir.product_model_id = outWeight.product_model_id
+
+ <where>
+ <if test="ew.reportDate != null">
+ and sir.create_time >= #{ew.reportDate}
+ and sir.create_time < DATE_ADD(#{ew.reportDate}, INTERVAL 1 DAY)
+ </if>
+ <if test="ew.startMonth != null">
+ and sir.create_time >= #{ew.startMonth}
+ </if>
+ <if test="ew.endMonth != null">
+ and sir.create_time <= #{ew.endMonth}
+ </if>
+ </where>
+ </select>
+
+ <select id="ConsumablesInAndOutRecord" resultType="com.ruoyi.consumables.dto.ConsumablesInventoryDto">
+ SELECT
+ pm.model,
+ pm.unit,
+ p.product_name,
+ MAX(current_inventory) as current_Consumables,
+ SUM(CASE WHEN record_type = 'in' THEN amount ELSE 0 END) as total_Consumables_in,
+ SUM(CASE WHEN record_type = 'out' THEN amount ELSE 0 END) as total_Consumables_out
+ FROM (
+ SELECT
+ product_model_id,
+ SUM(qualitity) as current_inventory,
+ 0 as amount,
+ '' as record_type
+ FROM Consumables_inventory
+ GROUP BY product_model_id
+
+ UNION ALL
+
+ SELECT
+ product_model_id,
+ 0 as current_inventory,
+ SUM(Consumables_in_num) as amount,
+ 'in' as record_type
+ FROM Consumables_in_record
+ <where>
+ type = 0
+ <if test="ew.startMonth != null">
+ and Consumables_in_record.create_time >= #{ew.startMonth}
+ </if>
+ <if test="ew.endMonth != null">
+ and Consumables_in_record.create_time <= #{ew.endMonth}
+ </if>
+ </where>
+ GROUP BY product_model_id
+
+ UNION ALL
+
+ SELECT
+ product_model_id,
+ 0 as current_inventory,
+ SUM(Consumables_out_num) as amount,
+ 'out' as record_type
+ FROM Consumables_out_record
+ <where>
+ type = 0
+ <if test="ew.startMonth != null">
+ and Consumables_out_record.create_time >= #{ew.startMonth}
+ </if>
+ <if test="ew.endMonth != null">
+ and Consumables_out_record.create_time <= #{ew.endMonth}
+ </if>
+ </where>
+ GROUP BY product_model_id
+ ) combined_data
+ LEFT JOIN product_model pm ON pm.id = combined_data.product_model_id
+ LEFT JOIN product p ON p.id = pm.product_id
+ <where>
+ <if test="ew.productName != null and ew.productName !=''">
+ and p.product_name like concat('%',#{ew.productName},'%')
+ </if>
+ <if test="ew.model != null and ew.model !=''">
+ and pm.model like concat('%',#{ew.model},'%')
+ </if>
+ </where>
+ GROUP BY
+ pm.model,
+ pm.unit,
+ p.product_name
+ </select>
+ <select id="selectTotal" resultType="java.math.BigDecimal">
+ select ifnull(sum(qualitity), 0)
+ from consumables_inventory
+ </select>
+
+ <select id="selectTotalByDate" resultType="java.math.BigDecimal">
+ select IFNULL(sum(qualitity), 0)
+ from consumables_inventory
+ where create_time >= #{now}
+ and create_time < DATE_ADD(#{now}, INTERVAL 1 DAY)
+ </select>
+
+ <select id="selectStorageProductCountByDate" resultType="int">
+ SELECT SUM(total_count)
+ FROM (SELECT COUNT(*) as total_count
+ FROM consumables_inventory
+ WHERE create_time >= #{startDate}
+ AND create_time <= #{endDate}
+ UNION ALL
+ SELECT COUNT(*) as total_count
+ FROM consumables_uninventory
+ WHERE create_time >= #{startDate}
+ AND create_time <= #{endDate}) AS combined_counts
+ </select>
+
+ <select id="selectDailyConsumablesInCounts" resultType="java.util.Map">
+ SELECT DATE(sir.create_time) AS date,
+ SUM(sir.Consumables_in_num) AS count
+ FROM consumables_in_record sir
+ JOIN product_model pm ON sir.product_model_id = pm.id
+ JOIN product p ON pm.product_id = p.id
+ WHERE (p.parent_id = #{rootCategoryId} OR p.id = #{rootCategoryId})
+ AND sir.create_time >= #{startDate}
+ AND sir.create_time <= #{endDate}
+ GROUP BY DATE(sir.create_time)
+ ORDER BY DATE(sir.create_time) ASC
+ </select>
+
+ <select id="selectDailyConsumablesOutCounts" resultType="java.util.Map">
+ SELECT DATE(sor.create_time) AS date,
+ SUM(sor.Consumables_out_num) AS count
+ FROM consumables_out_record sor
+ JOIN product_model pm ON sor.product_model_id = pm.id
+ JOIN product p ON pm.product_id = p.id
+ WHERE (p.parent_id = #{rootCategoryId} OR p.id = #{rootCategoryId})
+ AND sor.create_time >= #{startDate}
+ AND sor.create_time <= #{endDate}
+ GROUP BY DATE(sor.create_time)
+ ORDER BY DATE(sor.create_time) ASC
+ </select>
+
+</mapper>
--
Gitblit v1.9.3