盘点模块修改

This commit is contained in:
2025-09-15 15:17:16 +08:00
parent 8c6cc08cac
commit 496547211b
12 changed files with 273 additions and 194 deletions

View File

@@ -196,22 +196,20 @@
parameterType="InventoryMatchScan"
resultType="com.zg.project.Inventory.domain.vo.RkInfoMatchVO">
SELECT
r.pcode AS rkPcode,
r.real_qty AS realQty
r.pcode AS rkPcode,
COALESCE(SUM(r.real_qty), 0) AS realQty
FROM rk_info r
WHERE r.pcode_id IN (
SELECT DISTINCT i.pcode
FROM inventory_match_scan i
LEFT JOIN rk_info r ON i.pcode = r.pcode_id
<where>
<if test="taskId != null and taskId != ''">
AND i.task_id = #{taskId}
</if>
<if test="deviceId != null and deviceId != ''">
AND i.device_id = #{deviceId}
</if>
<if test="status != null and status != ''">
AND i.status = #{status}
</if>
<if test="taskId != null and taskId != ''">AND i.task_id = #{taskId}</if>
<if test="deviceId != null and deviceId != ''">AND i.device_id = #{deviceId}</if>
<if test="status != null and status != ''">AND i.status = #{status}</if>
</where>
ORDER BY i.tme DESC
)
GROUP BY r.pcode
ORDER BY MAX(r.create_time) DESC
</select>
</mapper>

View File

@@ -85,6 +85,14 @@
where id = #{taskId}
</select>
<select id="selectSceneIdById" parameterType="string" resultType="java.lang.String">
SELECT scene_id
FROM inventory_task
WHERE id = #{id}
AND is_delete = '0'
LIMIT 1
</select>
<insert id="insertInventoryTask" parameterType="InventoryTask" useGeneratedKeys="true" keyProperty="id">
insert into inventory_task
<trim prefix="(" suffix=")" suffixOverrides=",">

View File

@@ -325,62 +325,59 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-->
<select id="selectGroupedByBill" resultMap="RkInfoResult" parameterType="map">
SELECT
/* ============= 主键:取单据内任一(用最小 ID 代表) ============= */
MIN(t.id) AS id,
/* ============= 单据号 ============= */
t.bill_no AS bill_no, -- 入库单据号(分组键)
ANY_VALUE(t.bill_no_ck) AS bill_no_ck, -- 出库单据号(若单据发生过出库则可能有值)
/* ============= 通用字段(代表值/聚合) ============= */
ANY_VALUE(t.rk_type) AS rk_type, -- 入库类型编码type_code
-- 入库类型名称(由 stock_in_type 反查)
(SELECT si.type_name
FROM stock_in_type si
WHERE si.type_code = ANY_VALUE(t.rk_type)
LIMIT 1) AS rk_type_name,
ANY_VALUE(t.wl_type) AS wl_type, -- 物资类型
ANY_VALUE(t.cangku) AS cangku, -- 仓库(编码)
MIN(t.rk_time) AS rk_time, -- 入库时间(单据内最早)
ANY_VALUE(t.lihuo_y) AS lihuo_y, -- 理货员ID
MAX(t.is_chuku) AS is_chuku, -- 是否出库(单据内只要有出库,用最大值反映)
ANY_VALUE(t.xj) AS xj, -- 县局
ANY_VALUE(t.xm_no) AS xm_no, -- 入库项目号
ANY_VALUE(t.xm_ms) AS xm_ms, -- 入库项目描述
ANY_VALUE(t.xm_no_ck) AS xm_no_ck, -- 出库项目号
ANY_VALUE(t.xm_ms_ck) AS xm_ms_ck, -- 出库项目描述
ANY_VALUE(t.wl_no) AS wl_no, -- 物料号
ANY_VALUE(t.wl_ms) AS wl_ms, -- 物料描述
ANY_VALUE(t.gys_no) AS gys_no, -- 供应商编码
ANY_VALUE(t.sap_no) AS sap_no, -- SAP 订单号
/* ============= 出库附加信息 ============= */
ANY_VALUE(t.ck_type) AS ck_type, -- 出库类型编码
(SELECT s.type_name
FROM stock_out_type s
WHERE s.type_code = ANY_VALUE(t.ck_type)
LIMIT 1) AS ck_type_name, -- 出库类型名称
MAX(t.ly_time) AS ly_time, -- 领用时间(单据内最新)
ANY_VALUE(t.ck_lihuo_y) AS ck_lihuo_y, -- 出库理货员ID
(SELECT u.user_name
FROM sys_user u
WHERE u.user_id = ANY_VALUE(t.ck_lihuo_y)
LIMIT 1) AS ck_lihuo_y_name -- 出库理货员姓名
a.id,
a.bill_no,
a.bill_no_ck,
a.rk_type,
si.type_name AS rk_type_name,
a.wl_type,
a.cangku,
a.rk_time,
a.lihuo_y,
a.is_chuku,
a.xj,
a.xm_no,
a.xm_ms,
a.xm_no_ck,
a.xm_ms_ck,
a.wl_no,
a.wl_ms,
a.gys_no,
a.sap_no,
a.ck_type,
so.type_name AS ck_type_name,
a.ly_time,
a.ck_lihuo_y,
u.user_name AS ck_lihuo_y_name
FROM (
<!-- 这里完全复用你已有的 SELECT + JOIN 片段,列别名与 RkInfoResult 一致 -->
SELECT
MIN(t.id) AS id, -- 代表ID
t.bill_no AS bill_no, -- 分组键
MIN(t.bill_no_ck) AS bill_no_ck, -- 代表值
MIN(t.rk_type) AS rk_type,
MIN(t.wl_type) AS wl_type,
MIN(t.cangku) AS cangku,
MIN(t.rk_time) AS rk_time, -- 单据内最早入库时间
MIN(t.lihuo_y) AS lihuo_y,
MAX(t.is_chuku) AS is_chuku, -- 单据内只要有出库则为1
MIN(t.xj) AS xj,
MIN(t.xm_no) AS xm_no,
MIN(t.xm_ms) AS xm_ms,
MIN(t.xm_no_ck) AS xm_no_ck,
MIN(t.xm_ms_ck) AS xm_ms_ck,
MIN(t.wl_no) AS wl_no,
MIN(t.wl_ms) AS wl_ms,
MIN(t.gys_no) AS gys_no,
MIN(t.sap_no) AS sap_no,
MIN(t.ck_type) AS ck_type,
MAX(t.ly_time) AS ly_time,
MIN(t.ck_lihuo_y) AS ck_lihuo_y
FROM (
<!-- 复用已有的明细查询(列别名与 RkInfoResult 一致) -->
<include refid="selectRkInfoVo"/>
) t
<where>
<!-- ================= 与 /list 相同的筛选条件(把 ri.* 改为 t.* ================= -->
<!-- is_chuku优先列表其次单值 -->
<!-- is_chuku 优先列表,其次单值 -->
<choose>
<when test="q.isChukuList != null and q.isChukuList.size > 0">
AND t.is_chuku IN
@@ -396,29 +393,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- 关键词模糊 -->
<if test="q.keyword != null and q.keyword != ''">
AND (
t.xm_no like concat('%', #{q.keyword}, '%')
or t.xm_ms like concat('%', #{q.keyword}, '%')
or t.wl_no like concat('%', #{q.keyword}, '%')
or t.wl_ms like concat('%', #{q.keyword}, '%')
or t.gys_no like concat('%', #{q.keyword}, '%')
or t.gys_mc like concat('%', #{q.keyword}, '%')
or t.sap_no like concat('%', #{q.keyword}, '%')
or t.bill_no like concat('%', #{q.keyword}, '%')
or t.bill_no_ck like concat('%', #{q.keyword}, '%')
or t.ck_type like concat('%', #{q.keyword}, '%')
or t.pcode like concat('%', #{q.keyword}, '%')
t.xm_no LIKE concat('%', #{q.keyword}, '%')
OR t.xm_ms LIKE concat('%', #{q.keyword}, '%')
OR t.wl_no LIKE concat('%', #{q.keyword}, '%')
OR t.wl_ms LIKE concat('%', #{q.keyword}, '%')
OR t.gys_no LIKE concat('%', #{q.keyword}, '%')
OR t.gys_mc LIKE concat('%', #{q.keyword}, '%')
OR t.sap_no LIKE concat('%', #{q.keyword}, '%')
OR t.bill_no LIKE concat('%', #{q.keyword}, '%')
OR t.bill_no_ck LIKE concat('%', #{q.keyword}, '%')
OR t.ck_type LIKE concat('%', #{q.keyword}, '%')
OR t.pcode LIKE concat('%', #{q.keyword}, '%')
)
</if>
<!-- 维度筛选 -->
<if test="q.rkType != null and q.rkType != ''">
AND t.rk_type like concat('%', #{q.rkType}, '%')
AND t.rk_type LIKE concat('%', #{q.rkType}, '%')
</if>
<if test="q.wlType != null and q.wlType != ''">
AND t.wl_type like concat('%', #{q.wlType}, '%')
AND t.wl_type LIKE concat('%', #{q.wlType}, '%')
</if>
<if test="q.cangku != null and q.cangku != ''">
AND t.cangku like concat('%', #{q.cangku}, '%')
AND t.cangku LIKE concat('%', #{q.cangku}, '%')
</if>
<!-- ID 列表 -->
@@ -431,104 +428,90 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- 入库时间范围(闭区间) -->
<if test="q.startTime != null"><![CDATA[
AND t.rk_time >= #{q.startTime}
]]></if>
AND t.rk_time >= #{q.startTime}
]]></if>
<if test="q.endTime != null"><![CDATA[
AND t.rk_time <= #{q.endTime}
]]></if>
AND t.rk_time <= #{q.endTime}
]]></if>
<!-- 领用时间范围(闭区间) -->
<if test="q.lyStartTime != null"><![CDATA[
AND t.ly_time >= #{q.lyStartTime}
]]></if>
AND t.ly_time >= #{q.lyStartTime}
]]></if>
<if test="q.lyEndTime != null"><![CDATA[
AND t.ly_time <= #{q.lyEndTime}
]]></if>
AND t.ly_time <= #{q.lyEndTime}
]]></if>
<!-- 其它模糊/等值 -->
<if test="q.lihuoY != null and q.lihuoY != ''">
AND t.lihuo_y like concat('%', #{q.lihuoY}, '%')
AND t.lihuo_y LIKE concat('%', #{q.lihuoY}, '%')
</if>
<if test="q.xj != null and q.xj != ''">
AND t.xj like concat('%', #{q.xj}, '%')
AND t.xj LIKE concat('%', #{q.xj}, '%')
</if>
<if test="q.billNo != null and q.billNo != ''">
AND t.bill_no like concat('%', #{q.billNo}, '%')
AND t.bill_no LIKE concat('%', #{q.billNo}, '%')
</if>
<if test="q.billNoCk != null and q.billNoCk != ''">
AND t.bill_no_ck like concat('%', #{q.billNoCk}, '%')
AND t.bill_no_ck LIKE concat('%', #{q.billNoCk}, '%')
</if>
<if test="q.xmNo != null and q.xmNo != ''">
AND t.xm_no like concat('%', #{q.xmNo}, '%')
AND t.xm_no LIKE concat('%', #{q.xmNo}, '%')
</if>
<if test="q.xmMs != null and q.xmMs != ''">
AND t.xm_ms like concat('%', #{q.xmMs}, '%')
AND t.xm_ms LIKE concat('%', #{q.xmMs}, '%')
</if>
<if test="q.wlNo != null and q.wlNo != ''">
AND t.wl_no like concat('%', #{q.wlNo}, '%')
AND t.wl_no LIKE concat('%', #{q.wlNo}, '%')
</if>
<if test="q.wlMs != null and q.wlMs != ''">
AND t.wl_ms like concat('%', #{q.wlMs}, '%')
AND t.wl_ms LIKE concat('%', #{q.wlMs}, '%')
</if>
<if test="q.gysNo != null and q.gysNo != ''">
AND t.gys_no like concat('%', #{q.gysNo}, '%')
AND t.gys_no LIKE concat('%', #{q.gysNo}, '%')
</if>
<if test="q.gysMc != null and q.gysMc != ''">
AND t.gys_mc like concat('%', #{q.gysMc}, '%')
AND t.gys_mc LIKE concat('%', #{q.gysMc}, '%')
</if>
<if test="q.jhAmt != null">
AND t.jh_amt = #{q.jhAmt}
</if>
<if test="q.htDj != null">
AND t.ht_dj = #{q.htDj}
</if>
<if test="q.jhAmt != null"> AND t.jh_amt = #{q.jhAmt} </if>
<if test="q.htDj != null"> AND t.ht_dj = #{q.htDj} </if>
<if test="q.sapNo != null and q.sapNo != ''">
AND t.sap_no like concat('%', #{q.sapNo}, '%')
AND t.sap_no LIKE concat('%', #{q.sapNo}, '%')
</if>
<if test="q.xh != null and q.xh != ''">
AND t.xh like concat('%', #{q.xh}, '%')
</if>
<if test="q.jhQty != null">
AND t.jh_qty = #{q.jhQty}
</if>
<if test="q.htQty != null">
AND t.ht_qty = #{q.htQty}
AND t.xh LIKE concat('%', #{q.xh}, '%')
</if>
<if test="q.jhQty != null"> AND t.jh_qty = #{q.jhQty} </if>
<if test="q.htQty != null"> AND t.ht_qty = #{q.htQty} </if>
<if test="q.dw != null and q.dw != ''">
AND t.dw like concat('%', #{q.dw}, '%')
</if>
<if test="q.realQty != null">
AND t.real_qty = #{q.realQty}
AND t.dw LIKE concat('%', #{q.dw}, '%')
</if>
<if test="q.realQty != null"> AND t.real_qty = #{q.realQty} </if>
<if test="q.pcode != null and q.pcode != ''">
AND t.pcode like concat('%', #{q.pcode}, '%')
</if>
<if test="q.lyTime != null">
AND t.ly_time = #{q.lyTime}
</if>
<if test="q.returnTime != null">
AND t.return_time = #{q.returnTime}
AND t.pcode LIKE concat('%', #{q.pcode}, '%')
</if>
<if test="q.lyTime != null"> AND t.ly_time = #{q.lyTime} </if>
<if test="q.returnTime != null"> AND t.return_time = #{q.returnTime} </if>
<if test="q.trayCode != null and q.trayCode != ''">
AND t.tray_code like concat('%', #{q.trayCode}, '%')
AND t.tray_code LIKE concat('%', #{q.trayCode}, '%')
</if>
<if test="q.entityId != null and q.entityId != ''">
AND t.entity_id like concat('%', #{q.entityId}, '%')
AND t.entity_id LIKE concat('%', #{q.entityId}, '%')
</if>
<if test="q.ckType != null and q.ckType != ''">
AND t.ck_type like concat('%', #{q.ckType}, '%')
AND t.ck_type LIKE concat('%', #{q.ckType}, '%')
</if>
<!-- 若查询出库单据:单值 is_chuku=1 或 列表包含 1要求已生成出库单号 -->
<!-- 若查询出库单据,则要求已生成出库单号 -->
<if test="(q.isChuku != null and q.isChuku == 1)
or (q.isChukuList != null and q.isChukuList.size > 0 and q.isChukuList.contains(1))">
or (q.isChukuList != null and q.isChukuList.size > 0 and q.isChukuList.contains(1))">
AND t.bill_no_ck IS NOT NULL
</if>
<!-- 删除标记(默认 0 -->
<!-- 删除标记默认0 -->
<choose>
<when test="q.isDelete != null and q.isDelete != ''">
AND t.is_delete = #{q.isDelete}
@@ -538,7 +521,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</otherwise>
</choose>
<!-- 审核开启:剔除审核失败”的明细(未审核/通过保留 -->
<!-- 审核开启:剔除审核失败(不使用 &lt;&gt;,而用 != 或 CDATA -->
<if test="needAudit != null and needAudit == 1">
AND NOT EXISTS (
SELECT 1
@@ -549,13 +532,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
)
</if>
</where>
GROUP BY t.bill_no
ORDER BY MIN(t.rk_time) DESC
) a
LEFT JOIN stock_in_type si ON a.rk_type = si.type_code
LEFT JOIN stock_out_type so ON a.ck_type = so.type_code
LEFT JOIN sys_user u ON a.ck_lihuo_y = u.user_id
ORDER BY a.rk_time DESC
</select>
<select id="selectRkInfoById" parameterType="Long" resultMap="RkInfoResult">
<include refid="selectRkInfoVo"/>
where ri.id = #{id} and ri.is_delete = 0
@@ -600,7 +585,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE bill_no = #{billNo} AND sap_no IS NOT NULL
</select>
<select id="getByPcodeIdList" parameterType="list" resultMap="RkInfoResult">
<!-- 正常数据:扫描到的库位(限定场景) -->
<select id="getByPcodeIdList" parameterType="map" resultMap="RkInfoResult">
SELECT
ri.id, ri.rk_type, ri.wl_type, ri.cangku, ri.rk_time, ri.lihuo_y,
ri.is_chuku, ri.bill_no, ri.bill_no_ck,
@@ -611,40 +597,55 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ri.ck_lihuo_y, ri.ck_type, ri.team_code, ri.ly_time, ri.ck_remark,
ri.create_by, ri.create_time, ri.update_by, ri.update_time, ri.is_delete
FROM rk_info ri
JOIN pcde_detail pd ON ri.pcode_id = pd.encoded_id
WHERE ri.is_delete = '0'
AND pd.is_delete = '0'
AND ri.is_chuku = '0'
AND pd.scene = #{sceneId}
AND ri.pcode_id IN
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<select id="getMissedPcodeIds" parameterType="list" resultMap="RkInfoResult">
<!-- 未扫描到的数据(限定场景) -->
<select id="getMissedPcodeIds" parameterType="map" resultMap="RkInfoResult">
SELECT
id, rk_type, wl_type, cangku, rk_time, lihuo_y,
is_chuku, bill_no, bill_no_ck,
remark, xj, xm_no, xm_ms, wl_no, wl_ms, is_borrowed,
gys_no, gys_mc, jh_amt, ht_dj, sap_no, xh,
jh_qty, ht_qty, dw, real_qty,
pcode, pcode_id, tray_code, entity_id,
ck_lihuo_y, ck_type, team_code, ly_time, ck_remark,
create_by, create_time, update_by, update_time, is_delete
FROM rk_info
WHERE is_delete = '0'
ri.id, ri.rk_type, ri.wl_type, ri.cangku, ri.rk_time, ri.lihuo_y,
ri.is_chuku, ri.bill_no, ri.bill_no_ck,
ri.remark, ri.xj, ri.xm_no, ri.xm_ms, ri.wl_no, ri.wl_ms, ri.is_borrowed,
ri.gys_no, ri.gys_mc, ri.jh_amt, ri.ht_dj, ri.sap_no, ri.xh,
ri.jh_qty, ri.ht_qty, ri.dw, ri.real_qty,
ri.pcode, ri.pcode_id, ri.tray_code, ri.entity_id,
ri.ck_lihuo_y, ri.ck_type, ri.team_code, ri.ly_time, ri.ck_remark,
ri.create_by, ri.create_time, ri.update_by, ri.update_time, ri.is_delete
FROM rk_info ri
JOIN pcde_detail pd ON ri.pcode_id = pd.encoded_id
WHERE ri.is_delete = '0'
AND ri.is_chuku = '0'
AND pd.is_delete = '0'
AND pd.scene = #{sceneId}
<if test="list != null and list.size() > 0">
AND pcode_id NOT IN
AND ri.pcode_id NOT IN
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</select>
<select id="existsByPcodeId" parameterType="string" resultType="java.lang.Integer">
<!-- 判断某个库位在场景内是否存在 -->
<select id="existsByPcodeId" parameterType="map" resultType="java.lang.Integer">
SELECT COUNT(1)
FROM rk_info
WHERE is_delete = '0'
AND pcode_id = #{pcodeId}
FROM rk_info ri
JOIN pcde_detail pd ON ri.pcode_id = pd.encoded_id
WHERE ri.is_delete = '0'
AND pd.is_delete = '0'
AND ri.is_chuku = '0'
AND ri.pcode_id = #{pcodeId}
AND pd.scene = #{sceneId}
</select>
<select id="countGetByWh" resultType="java.lang.Integer" parameterType="java.lang.String">
SELECT COUNT(1) FROM rk_info
WHERE is_delete = '0'
@@ -871,5 +872,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND bill_no IS NOT NULL
</update>
<select id="listRkInfoByPcode"
parameterType="string"
resultMap="RkInfoResult">
SELECT
t.*,
wh.warehouse_name AS cangku_name
FROM rk_info t
LEFT JOIN warehouse_info wh
ON wh.warehouse_code = t.cangku
WHERE t.is_delete = 0
AND t.is_chuku = 0
AND t.pcode = #{pcode}
ORDER BY t.rk_time DESC, t.id DESC
</select>
</mapper>