SELECT
ri.id,
ri.bill_no,
ri.bill_no_ck,
ri.rk_type, st.type_name AS rk_type_name,
ri.wl_type, mt.type_name AS wl_type_name,
ri.cangku,
wh.warehouse_name AS cangku_name,
wh.parent_warehouse_code AS parent_warehouse_code,
wh.parent_warehouse_name AS parent_warehouse_name,
wh.warehouse_code AS warehouse_code,
wh.warehouse_name AS warehouse_name,
ri.rk_time,
ri.lihuo_y,
ri.is_chuku,
ri.is_borrowed,
ri.is_delivery,
ri.remark,
ri.ck_lihuo_y,
ri.ck_type,
sot.type_name AS ck_type_name,
ri.team_code,
ct.team_name,
ri.ck_remark,
ri.ly_time,
ri.borrow_time,
ri.return_time,
ri.xj,
ri.xm_no,
ri.xm_ms,
ri.xm_no_ck,
ri.xm_ms_ck,
ri.wl_no,
ri.wl_ms,
ri.gys_no,
ri.gys_mc,
ri.jh_amt,
ri.ht_dj,
ri.sap_no,
ri.xh,
ri.gys_jh_id,
ri.jh_qty,
ri.ht_qty,
ri.dw,
ri.real_qty,
ri.pcode,
ri.pcode_id,
ri.tray_code,
ri.entity_id,
ri.status,
ri.has_moved,
ri.create_by,
ri.create_time,
ri.update_by,
ri.update_time,
ri.is_delete,
u.user_name AS lihuo_y_name,
-- ✅ 库龄(天)
DATEDIFF(CURDATE(), ri.rk_time) AS stock_age,
-- 总金额 = 单价 × 实际数量
COALESCE(ri.ht_dj, 0) * COALESCE(ri.real_qty, 0) AS total_amount
FROM rk_info ri
LEFT JOIN stock_in_type st ON ri.rk_type = st.type_code
LEFT JOIN material_type mt ON ri.wl_type = mt.type_code
LEFT JOIN warehouse_info wh ON ri.cangku = wh.warehouse_code
LEFT JOIN stock_out_type sot ON ri.ck_type = sot.type_code
LEFT JOIN construction_team ct ON ri.team_code = ct.team_code
LEFT JOIN sys_user u ON ri.lihuo_y = u.user_id
SELECT
ri.id,
ri.bill_no,
ri.bill_no_ck,
ri.rk_type,
ri.wl_type,
ri.cangku,
ri.rk_time,
ri.lihuo_y,
ri.is_chuku,
ri.xj,
ri.xm_no,
ri.xm_ms,
ri.xm_no_ck,
ri.xm_ms_ck,
ri.gys_mc,
ri.wl_no,
ri.wl_ms,
ri.gys_no,
ri.sap_no,
ri.ck_type,
ri.ly_time,
ri.ck_lihuo_y,
ri.pcode,
ri.is_delete
FROM rk_info ri
INSERT INTO rk_info (
bill_no,
rk_type, wl_type, cangku, lihuo_y, rk_time,
wl_no, wl_ms, xm_no, xm_ms,
xm_no_ck, xm_ms_ck, xj, sap_no, gys_no, gys_mc,
jh_qty, ht_qty, jh_amt, ht_dj, dw,
borrow_time, return_time, status,
pcode, pcode_id, tray_code, real_qty, entity_id, fycde_1, fycde_2,
remark, is_chuku, is_borrowed, gys_jh_id,
is_delete, create_by, create_time
)
VALUES
(
#{item.billNo},
#{item.rkType}, #{item.wlType}, #{item.cangku}, #{item.lihuoY}, #{item.rkTime},
#{item.wlNo}, #{item.wlMs}, #{item.xmNo}, #{item.xmMs},
#{item.xmNoCk}, #{item.xmMsCk}, #{item.xj}, #{item.sapNo}, #{item.gysNo}, #{item.gysMc},
#{item.jhQty}, #{item.htQty}, #{item.jhAmt}, #{item.htDj}, #{item.dw},
#{item.borrowTime}, #{item.returnTime}, #{item.status},
#{item.pcode}, #{item.pcodeId}, #{item.trayCode}, #{item.realQty}, #{item.entityId},
#{item.fycde1}, #{item.fycde2},
#{item.remark}, #{item.isChuku}, #{item.isBorrowed}, #{item.gysJhId},
#{item.isDelete}, #{item.createBy}, #{item.createTime}
)
INSERT INTO rk_info (
rk_type, wl_type, cangku, rk_time, lihuo_y,
is_chuku, remark, bill_no, xj, xm_no, xm_ms, is_borrowed,
wl_no, wl_ms, gys_no, gys_mc, jh_amt, ht_dj,
sap_no, xh, jh_qty, ht_qty, dw, real_qty,
pcode, tray_code, entity_id,
ck_lihuo_y, ck_type, team_code, ck_remark,
ly_time, bill_no_ck, has_moved, borrow_time,
gys_jh_id,
status,
create_by, create_time, update_by, update_time, is_delete
) VALUES (
#{rkType}, #{wlType}, #{cangku}, #{rkTime}, #{lihuoY},
#{isChuku}, #{remark}, #{billNo}, #{xj}, #{xmNo}, #{xmMs}, #{isBorrowed},
#{wlNo}, #{wlMs}, #{gysNo}, #{gysMc}, #{jhAmt}, #{htDj},
#{sapNo}, #{xh}, #{jhQty}, #{htQty}, #{dw}, #{realQty},
#{pcode}, #{trayCode}, #{entityId},
#{ckLihuoY}, #{ckType}, #{teamCode}, #{ckRemark},
#{lyTime}, #{billNoCk}, #{hasMoved}, #{borrowTime},
#{gysJhId},
#{status},
#{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{isDelete}
)
UPDATE rk_info
SET
is_chuku = '0',
bill_no_ck = NULL,
ck_lihuo_y = NULL,
ck_type = NULL,
team_code = NULL,
ly_time = NULL,
ck_remark = NULL,
is_borrowed = NULL,
update_time = NOW()
WHERE bill_no_ck = #{billNoCk}
DELETE FROM rk_info
WHERE bill_no = #{billNo}
UPDATE rk_info
rk_type = #{rkType},
wl_type = #{wlType},
cangku = #{cangku},
rk_time = #{rkTime},
lihuo_y = #{lihuoY},
is_chuku = #{isChuku},
is_borrowed = #{isBorrowed},
bill_no = #{billNo},
bill_no_ck = #{billNoCk},
remark = #{remark},
xj = #{xj},
xm_no = #{xmNo},
xm_ms = #{xmMs},
xm_no_ck = #{xmNoCk},
xm_ms_ck = #{xmMsCk},
wl_no = #{wlNo},
wl_ms = #{wlMs},
gys_no = #{gysNo},
gys_mc = #{gysMc},
jh_amt = #{jhAmt},
ht_dj = #{htDj},
sap_no = #{sapNo},
xh = #{xh},
jh_qty = #{jhQty},
ht_qty = #{htQty},
dw = #{dw},
real_qty = #{realQty},
pcode = #{pcode},
pcode_id = #{pcodeId},
tray_code = #{trayCode},
entity_id = #{entityId},
ck_lihuo_y = #{ckLihuoY},
ck_type = #{ckType},
team_code = #{teamCode},
ly_time = #{lyTime},
borrow_time = #{borrowTime},
return_time = #{returnTime},
ck_remark = #{ckRemark},
is_delivery = #{isDelivery},
has_moved = #{hasMoved},
fycde_1 = #{fycde1},
fycde_2 = #{fycde2},
gys_jh_id = #{gysJhId},
update_by = #{updateBy},
update_time = #{updateTime},
is_delete = #{isDelete},
WHERE id = #{id}
UPDATE rk_info
rk_type = #{rkType},
wl_type = #{wlType},
cangku = #{cangku},
rk_time = #{rkTime},
lihuo_y = #{lihuoY},
is_chuku = #{isChuku},
is_borrowed = #{isBorrowed},
remark = #{remark},
xm_no_ck = #{xmNoCk},
xm_ms_ck = #{xmMsCk},
ck_lihuo_y = #{ckLihuoY},
ck_type = #{ckType},
team_code = #{teamCode},
ck_remark = #{ckRemark},
ly_time = #{lyTime},
borrow_time = #{borrowTime},
return_time = #{returnTime},
is_delivery = #{isDelivery},
has_moved = #{hasMoved},
update_by = #{updateBy},
update_time = #{updateTime},
WHERE bill_no_ck = #{billNoCk}
AND is_delete = '0'
update rk_info
is_delete = 1
where id = #{id}
update rk_info
set is_delete = 1
where id in
#{id}
UPDATE rk_info
is_chuku = #{isChuku},
is_borrowed = #{isBorrowed},
bill_no_ck = #{billNoCk},
ck_type = #{ckType},
is_delivery = #{isDelivery},
ck_lihuo_y = #{ckLihuoY},
team_code = #{teamCode},
ck_remark = #{ckRemark},
xm_no_ck = #{xmNoCk},
xm_ms_ck = #{xmMsCk},
update_by = #{updateBy},
update_time = #{updateTime},
ly_time = #{lyTime},
borrow_time = #{borrowTime},
return_time = #{returnTime},
pcode = #{pcode},
cangku = #{cangku},
status = #{status},
real_qty = #{realQty},
WHERE id = #{id}
UPDATE rk_info
status = #{status},
is_chuku = #{isChuku},
update_by = #{updateBy},
update_time = #{updateTime},
bill_no = #{billNo}
bill_no_ck = #{billNoCk}
UPDATE rk_info
SET is_delete = #{isDelete},
status = #{status},
update_by = #{updateBy},
update_time = #{updateTime}
WHERE bill_no = #{billNo}
AND status IN ('0', '2')
UPDATE rk_info
SET is_delete = #{isDelete},
status = #{status},
update_by = #{updateBy},
update_time = #{updateTime}
WHERE bill_no_ck = #{billNoCk}
AND status IN ('0', '2')
UPDATE rk_info
SET status = #{status},
is_chuku = #{isChuku},
update_by = #{updateBy},
update_time = #{updateTime}
WHERE bill_no_ck = #{billNoCk}
AND is_delete = '0'
AND bill_no IS NOT NULL
UPDATE rk_info
rk_type = #{rkType},
wl_type = #{wlType},
cangku = #{warehouseCode},
rk_time = #{rkTime},
WHERE bill_no = #{billNo}
UPDATE rk_info
SET is_delivery = #{isDelivery}
WHERE is_delete = '0'
AND id IN
#{id}