Commit 6f19a0ed by zhangtw

入库、申领、归还

parent c5829391
......@@ -54,7 +54,7 @@
id,application_no,applicant_id,applicant_name,department_id,department_name,borrow_purpose,expected_return_date,
approval_status,issue_status,is_used,create_by,create_time,order_no
) VALUES (
#{id},#{application_no},#{applicant_id},#{applicant_name},#{department_id},#{department_name},#{borrow_purpose},#{expected_return_date},
#{id},CONCAT('borrow', REPLACE(UUID(),'-','')),#{applicant_id},#{applicant_name},#{department_id},#{department_name},#{borrow_purpose},#{expected_return_date},
#{approval_status},#{issue_status},1,#{_user.id},NOW(),#{order_no}
)
</insert>
......@@ -94,6 +94,16 @@
FROM jl_key_dm_borrow_application WHERE id = #{id}
</insert>
<!-- 生成出库记录与明细(批量由 mapper 内部实现) -->
<insert id="insertOutboundDetail" parameterType="map">
<!-- mapper implementation should insert outbound record and details based on application id -->
INSERT INTO jl_key_dm_outbound_detail(id,outbound_id,material_id,outbound_type,outbound_quantity,unit_price,total_amount,borrow_application_detail_id,is_used,create_by,create_time)
SELECT UUID(), CONCAT('OUT', REPLACE(UUID(),'-','')),bad.material_id,2,bad.apply_quantity,m.unit_price,(m.unit_price * bad.apply_quantity) as total_amount,bad.id,1,#{_user.id},NOW()
FROM jl_key_dm_borrow_application_detail as bad
left join jl_key_dm_material as m on m.id = bad.material_id
WHERE application_id = #{id}
</insert>
<select id="selectInventoryByMaterialId" parameterType="map" resultType="map">
select i.*,m.can_borrow
from jl_key_dm_inventory as i
......@@ -121,11 +131,7 @@
where material_id = #{material_id}
</update>
<!-- 插入日志 -->
<insert id="insertMaterialLogByApplication" parameterType="map">
<!-- 简化:实现者可在业务层调用单条插入,此处为占位 -->
insert into jl_key_dm_material_log()
</insert>
<select id="selectLogsByApplicationId" parameterType="map">
</select>
......
......@@ -19,10 +19,13 @@
WHERE i.inbound_id = #{id} AND i.is_used = 1 ORDER BY i.create_time ASC
</select>
<delete id="deleteDetailsByInboundId" parameterType="map">
DELETE FROM jl_key_dm_inbound_detail WHERE inbound_id = #{id}
</delete>
<!-- <delete id="deleteDetailsByInboundId" parameterType="map">-->
<!-- DELETE FROM jl_key_dm_inbound_detail WHERE inbound_id = #{id}-->
<!-- </delete>-->
<update id="deleteDetailsByInboundId" parameterType="map">
UPDATE jl_key_dm_inbound_detail SET is_used = 0, update_by = #{_user.id}, update_time = NOW() WHERE inbound_id = #{id}
</update>
</mapper>
......@@ -6,11 +6,23 @@
SELECT * FROM jl_key_dm_inbound_record
<where>
AND is_used = 1
<if test="params.inbound_no != null and params.inbound_no != ''">
AND (inbound_no LIKE CONCAT('%', #{params.inbound_no}, '%') OR batch_no LIKE CONCAT('%', #{params.inbound_no}, '%'))
<if test="params.params.inbound_no != null">
AND inbound_no LIKE CONCAT('%', #{params.params.inbound_no}, '%')
</if>
<if test="params.params.batch_no != null">
AND batch_no LIKE CONCAT('%', #{params.params.batch_no}, '%')
</if>
<if test="params.params.startDate != null and params.params.endDate != null">
AND inbound_date &gt;= #{params.params.startDate} and inbound_date &lt;= #{params.params.endDate}
</if>
<if test="params.params.inbound_type != null">
AND inbound_type = #{params.params.inbound_type}
</if>
<if test="params.params.inbound_status != null">
AND inbound_status = #{params.params.inbound_status}
</if>
</where>
ORDER BY inbound_date DESC
ORDER BY inbound_date DESC,create_time desc
</select>
<select id="getById" parameterType="map" resultType="map">
......@@ -44,19 +56,39 @@
SELECT * FROM jl_key_dm_inventory
<where>
AND is_used = 1
<if test="params.material_name != null and params.material_name != ''">
AND (material_name LIKE CONCAT('%', #{params.material_name}, '%') OR material_code LIKE CONCAT('%', #{params.material_name}, '%'))
<if test="params.params.material_name != null and params.params.material_name != ''">
AND (material_name LIKE CONCAT('%', #{params.params.material_name}, '%') OR material_code LIKE CONCAT('%', #{params.params.material_name}, '%'))
</if>
</where>
ORDER BY material_name ASC
</select>
<!-- insert inbound by return (simplified) -->
<!-- 入库主表添加归还入库单 -->
<insert id="insertInboundByReturn" parameterType="map">
INSERT INTO jl_key_dm_inbound_record(id,inbound_no,batch_no,inbound_date,inbound_type,storage_location,inbound_status,remark,is_used,create_by,create_time)
SELECT UUID(), CONCAT('INR', REPLACE(UUID(),'-','')), '', NOW(), 2, '', 1, '归还入库', 1, #{_user.id}, NOW()
SELECT #{inbound_id}, CONCAT('INR', REPLACE(UUID(),'-','')), '', NOW(), 2, '', 1, '归还入库', 1, #{_user.id}, NOW()
FROM jl_key_dm_borrow_application WHERE id = #{id}
</insert>
<!-- 入库明细添加 -->
<insert id="insertInboundDetailByReturn" parameterType="map">
insert into jl_key_dm_inbound_detail(id,inbound_id,material_id,inbound_type,inbound_quantity,unit_price,total_amount,production_date,expiry_date,is_used,create_by,create_time)
select UUID(), #{inbound_id}, material_id,2,apply_quantity,0,0,null,null,1,#{_user.id},now()
from jl_key_dm_borrow_application_detail where application_id = #{id}
</insert>
<!-- 修改申领明细表归还数量-->
<update id="updateBorrowDetailReturnedQuantity" parameterType="map">
update jl_key_dm_borrow_application_detail
set returned_quantity = returned_quantity + #{apply_quantity},damaged_quantity = damaged_quantity + #{damaged_quantity}
,update_by = #{_user.id},update_time = NOW()
where application_id = #{application_id} and material_id = #{material_id}
</update>
<update id="updateInventoryBorrowed" parameterType="map">
update jl_key_dm_inventory
set borrowed_quantity = borrowed_quantity - #{apply_quantity}
,damaged_quantity = damaged_quantity + #{damaged_quantity}
where material_id = #{material_id}
</update>
<!-- update inventory by inbound (placeholder) -->
<insert id="updateInventoryByInbound" parameterType="map">
......@@ -87,8 +119,8 @@
#{item.material_name},
#{item.inbound_quantity},
#{item.available_quantity},
#{item.borrowed_quantity},
#{item.damaged_quantity},
0,
0,
#{item.is_used},
#{_user.id},
NOW(),
......@@ -100,10 +132,10 @@
ON DUPLICATE KEY UPDATE
material_code = VALUES(material_code),
material_name = VALUES(material_name),
total_quantity = VALUES(total_quantity),
available_quantity = VALUES(available_quantity),
borrowed_quantity = VALUES(borrowed_quantity),
damaged_quantity = VALUES(damaged_quantity),
total_quantity = total_quantity + VALUES(total_quantity),
available_quantity = available_quantity + VALUES(available_quantity),
borrowed_quantity = borrowed_quantity + VALUES(borrowed_quantity),
damaged_quantity = damaged_quantity + VALUES(damaged_quantity),
is_used = VALUES(is_used),
update_by = VALUES(update_by),
update_time = NOW(),
......@@ -118,6 +150,34 @@
WHERE ml.relation_id = #{id} AND ml.is_used = 1 ORDER BY ml.create_time ASC
</select>
<select id="selectPendingReturnList" parameterType="map" resultType="map">
select ba.id,ba.applicant_id,ba.application_no,ba.applicant_name,ba.department_id,
ba.department_name,ba.issue_status,ba.expected_return_date,ba.issue_time
from jl_key_dm_borrow_application as ba
left join jl_key_dm_borrow_application_detail as bad on bad.application_id = ba.id
left join jl_key_dm_material as m on bad.material_id = m.id
<where>
m.can_borrow = 1 and ba.issue_status = 1
and bad.returned_quantity + bad.damaged_quantity != bad.apply_quantity
<if test="params.params.applicant_name != null and params.params.applicant_name != ''">
and applicant_name = concat('%',#{params.params.applicant_name},'%')
</if>
<if test="params.params.application_no != null and params.params.application_no != ''">
and application_no = concat('%',#{params.params.application_no},'%')
</if>
</where>
group by ba.id
</select>
<select id="selectPendingReturnDetailsByApplicationId" parameterType="map" resultType="map">
select ba.expected_return_date,ba.issue_time,
bad.material_id,bad.material_code,bad.material_name,bad.apply_quantity,bad.returned_quantity,
bad.damaged_quantity,bad.return_remark,bad.is_overdue,bad.overdue_days
from jl_key_dm_borrow_application_detail as bad
left join jl_key_dm_material as m on bad.material_id = m.id
left join jl_key_dm_borrow_application as ba on bad.application_id = ba.id
where ba.id = #{id}
</select>
</mapper>
......@@ -12,7 +12,26 @@
)
</foreach>
</insert>
<insert id="insertLogByInbound" parameterType="map">
INSERT INTO jl_key_dm_material_log(
id,category_id,material_id,op_type,relation_id,relation_item_id,quantity,unit_price,total_amount,is_used,create_by,create_time
) VALUES
<foreach collection="details" item="item" separator=",">
(
UUID(),#{item.category_id},#{item.material_id},#{inbound_type},#{id},#{item.material_id},#{item.inbound_quantity},#{item.unit_price},#{item.total_amount},1,#{create_by},NOW()
)
</foreach>
</insert>
<insert id="insertLogByReturn" parameterType="map">
INSERT INTO jl_key_dm_material_log(
id,category_id,material_id,op_type,relation_id,relation_item_id,quantity,unit_price,total_amount,is_used,create_by,create_time
) VALUES
<foreach collection="details" item="item" separator=",">
(
UUID(),#{item.category_id},#{item.material_id},#{inbound_type},#{inbound_id},#{item.material_id},#{item.apply_quantity},#{item.unit_price},#{item.total_amount},1,#{create_by},NOW()
)
</foreach>
</insert>
<select id="selectLogsByApplicationId" parameterType="map" resultType="map">
SELECT ml.*,m.material_name
FROM jl_key_dm_material_log as ml
......
......@@ -247,6 +247,13 @@
ORDER BY o.grade, o.sort
</select>
<!-- 将用户id和name做成字典-->
<select id="getUserMap" resultType="map">
select Id,name
from jl_key_dm_user
where is_used = 1
</select>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论