2026-09-15 15:50:24 +08:00
|
|
|
<?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.warehouse.mapper.PurchaseRequestMapper">
|
|
|
|
|
<resultMap type="PurchaseRequest" id="PurchaseRequestResult">
|
|
|
|
|
<id property="id" column="id"/>
|
|
|
|
|
<result property="requestNo" column="request_no"/>
|
|
|
|
|
<result property="productId" column="product_id"/>
|
|
|
|
|
<result property="purchaseBatchId" column="purchase_batch_id"/>
|
2026-09-28 10:55:48 +08:00
|
|
|
<result property="projectId" column="project_id"/>
|
|
|
|
|
<result property="projectCode" column="project_code"/>
|
|
|
|
|
<result property="projectName" column="project_name"/>
|
|
|
|
|
<result property="expenseCategoryId" column="expense_category_id"/>
|
|
|
|
|
<result property="expenseCategoryCode" column="expense_category_code"/>
|
|
|
|
|
<result property="expenseCategoryName" column="expense_category_name"/>
|
2026-09-15 15:50:24 +08:00
|
|
|
<result property="materialName" column="material_name"/>
|
|
|
|
|
<result property="materialBrand" column="material_brand"/>
|
|
|
|
|
<result property="category" column="category"/>
|
|
|
|
|
<result property="materialParams" column="material_params"/>
|
|
|
|
|
<result property="purchaseLink" column="purchase_link"/>
|
|
|
|
|
<result property="quantity" column="quantity"/>
|
2026-09-28 10:55:48 +08:00
|
|
|
<result property="estimatedUnitPrice" column="estimated_unit_price"/>
|
|
|
|
|
<result property="estimatedAmount" column="estimated_amount"/>
|
2026-09-15 15:50:24 +08:00
|
|
|
<result property="unit" column="unit"/>
|
|
|
|
|
<result property="expectedDate" column="expected_date"/>
|
|
|
|
|
<result property="applicantId" column="applicant_id"/>
|
|
|
|
|
<result property="applicantName" column="applicant_name"/>
|
|
|
|
|
<result property="purchaseStatus" column="purchase_status"/>
|
|
|
|
|
<result property="purchaseBatchNo" column="purchase_batch_no"/>
|
|
|
|
|
<result property="progressRemark" column="progress_remark"/>
|
|
|
|
|
<result property="productRemark" column="product_remark"/>
|
|
|
|
|
<result property="requestRemark" column="remark"/>
|
|
|
|
|
<result property="remark" column="remark"/>
|
|
|
|
|
<result property="createBy" column="create_by"/>
|
|
|
|
|
<result property="createTime" column="create_time"/>
|
|
|
|
|
<result property="updateBy" column="update_by"/>
|
|
|
|
|
<result property="updateTime" column="update_time"/>
|
|
|
|
|
<result property="productCode" column="product_code"/>
|
|
|
|
|
<result property="productName" column="product_name"/>
|
|
|
|
|
<result property="productBrand" column="product_brand"/>
|
|
|
|
|
<result property="productCategory" column="product_category"/>
|
|
|
|
|
<result property="productSpec" column="product_spec"/>
|
|
|
|
|
<result property="acceptedQuantity" column="accepted_quantity"/>
|
|
|
|
|
<result property="pendingArrivalQuantity" column="pending_arrival_quantity"/>
|
|
|
|
|
<result property="remainingQuantity" column="remaining_quantity"/>
|
|
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
|
|
<sql id="selectPurchaseRequestVo">
|
2026-09-28 10:55:48 +08:00
|
|
|
select pr.id, pr.request_no, pr.product_id, pr.purchase_batch_id,
|
|
|
|
|
pr.project_id, project.project_code, project.project_name,
|
|
|
|
|
pr.expense_category_id, ec.category_code as expense_category_code,
|
|
|
|
|
ec.category_name as expense_category_name,
|
|
|
|
|
pr.material_name, pr.material_brand, pr.category, pr.material_params,
|
|
|
|
|
pr.purchase_link, pr.quantity, pr.estimated_unit_price, pr.estimated_amount,
|
|
|
|
|
pr.unit, pr.expected_date, pr.applicant_id,
|
2026-09-15 16:41:53 +08:00
|
|
|
coalesce(applicant_user.nick_name, pr.applicant_name) as applicant_name,
|
2026-09-15 15:50:24 +08:00
|
|
|
pr.purchase_status, pr.purchase_batch_no, pr.progress_remark, pr.remark,
|
|
|
|
|
pr.create_by, pr.create_time, pr.update_by, pr.update_time,
|
|
|
|
|
pi.product_code, pi.product_name, pi.brand as product_brand,
|
|
|
|
|
pi.category as product_category, pi.spec as product_spec, pi.remark as product_remark,
|
|
|
|
|
coalesce(pa.accepted_quantity, 0) as accepted_quantity,
|
|
|
|
|
coalesce(pa.pending_quantity, 0) as pending_arrival_quantity,
|
|
|
|
|
greatest(pr.quantity - coalesce(pa.accepted_quantity, 0) - coalesce(pa.pending_quantity, 0), 0) as remaining_quantity
|
|
|
|
|
from purchase_request pr
|
|
|
|
|
left join product_info pi on pi.id = pr.product_id
|
2026-09-28 10:55:48 +08:00
|
|
|
left join project_info project on project.id = pr.project_id
|
|
|
|
|
left join expense_category ec on ec.id = pr.expense_category_id
|
2026-09-15 16:41:53 +08:00
|
|
|
left join sys_user applicant_user on applicant_user.user_id = pr.applicant_id
|
2026-09-15 15:50:24 +08:00
|
|
|
left join (
|
|
|
|
|
select purchase_request_id,
|
|
|
|
|
sum(case when acceptance_status = 1 then arrival_quantity else 0 end) as accepted_quantity,
|
|
|
|
|
sum(case when acceptance_status = 0 then arrival_quantity else 0 end) as pending_quantity
|
|
|
|
|
from purchase_arrival
|
2026-09-28 10:55:48 +08:00
|
|
|
where acceptance_status in (0, 1)
|
2026-09-15 15:50:24 +08:00
|
|
|
group by purchase_request_id
|
|
|
|
|
) pa on pa.purchase_request_id = pr.id
|
|
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
<select id="selectPurchaseRequestList" parameterType="PurchaseRequest" resultMap="PurchaseRequestResult">
|
|
|
|
|
<include refid="selectPurchaseRequestVo"/>
|
|
|
|
|
<where>
|
|
|
|
|
<if test="requestNo != null and requestNo != ''">and pr.request_no like concat('%', #{requestNo}, '%')</if>
|
|
|
|
|
<if test="productId != null">and pr.product_id = #{productId}</if>
|
2026-09-28 10:55:48 +08:00
|
|
|
<if test="projectId != null">and pr.project_id = #{projectId}</if>
|
|
|
|
|
<if test="expenseCategoryId != null">and pr.expense_category_id = #{expenseCategoryId}</if>
|
2026-09-15 15:50:24 +08:00
|
|
|
<if test="materialName != null and materialName != ''">
|
2026-09-28 10:55:48 +08:00
|
|
|
and convert(lower(concat_ws(' ', pr.material_name, pr.material_brand, pr.category, pr.material_params, pi.product_name, pi.product_code)) using utf8mb4) collate utf8mb4_bin
|
|
|
|
|
like concat('%', convert(lower(#{materialName}) using utf8mb4) collate utf8mb4_bin, '%')
|
2026-09-15 15:50:24 +08:00
|
|
|
</if>
|
|
|
|
|
<if test="category != null and category != ''">and pr.category like concat('%', #{category}, '%')</if>
|
|
|
|
|
<if test="applicantId != null">and pr.applicant_id = #{applicantId}</if>
|
2026-09-15 16:41:53 +08:00
|
|
|
<if test="applicantName != null and applicantName != ''">
|
|
|
|
|
and (pr.applicant_name like concat('%', #{applicantName}, '%')
|
|
|
|
|
or applicant_user.nick_name like concat('%', #{applicantName}, '%'))
|
|
|
|
|
</if>
|
2026-09-15 15:50:24 +08:00
|
|
|
<if test="purchaseStatus != null">and pr.purchase_status = #{purchaseStatus}</if>
|
|
|
|
|
<if test="purchaseBatchNo != null and purchaseBatchNo != ''">and pr.purchase_batch_no like concat('%', #{purchaseBatchNo}, '%')</if>
|
|
|
|
|
</where>
|
|
|
|
|
order by pr.id desc
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="selectPurchaseRequestById" resultMap="PurchaseRequestResult">
|
|
|
|
|
<include refid="selectPurchaseRequestVo"/>
|
|
|
|
|
where pr.id = #{id}
|
|
|
|
|
<if test="applicantId != null">and pr.applicant_id = #{applicantId}</if>
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="selectPurchaseRequestByIdForUpdate" parameterType="Long" resultMap="PurchaseRequestResult">
|
2026-09-28 10:55:48 +08:00
|
|
|
select pr.id, pr.request_no, pr.product_id, pr.purchase_batch_id, pr.project_id,
|
|
|
|
|
pr.expense_category_id, pr.material_name,
|
2026-09-15 15:50:24 +08:00
|
|
|
pr.material_brand, pr.category, pr.material_params, pr.purchase_link, pr.quantity,
|
2026-09-28 10:55:48 +08:00
|
|
|
pr.estimated_unit_price, pr.estimated_amount, pr.unit, pr.expected_date,
|
|
|
|
|
pr.applicant_id, pr.applicant_name, pr.purchase_status,
|
2026-09-15 15:50:24 +08:00
|
|
|
pr.purchase_batch_no, pr.progress_remark, pr.remark, pr.create_by, pr.create_time,
|
|
|
|
|
pr.update_by, pr.update_time
|
|
|
|
|
from purchase_request pr where pr.id = #{id} for update
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="checkRequestNoUnique" parameterType="String" resultMap="PurchaseRequestResult">
|
|
|
|
|
<include refid="selectPurchaseRequestVo"/> where pr.request_no = #{requestNo} limit 1
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<insert id="insertPurchaseRequest" parameterType="PurchaseRequest" useGeneratedKeys="true" keyProperty="id">
|
|
|
|
|
insert into purchase_request(
|
2026-09-28 10:55:48 +08:00
|
|
|
request_no, product_id, project_id, expense_category_id,
|
|
|
|
|
material_name, material_brand, category, material_params, purchase_link,
|
|
|
|
|
quantity, estimated_unit_price, estimated_amount, unit, expected_date,
|
|
|
|
|
applicant_id, applicant_name, purchase_status, purchase_batch_no,
|
2026-09-15 15:50:24 +08:00
|
|
|
progress_remark, remark, create_by, create_time
|
|
|
|
|
) values (
|
2026-09-28 10:55:48 +08:00
|
|
|
#{requestNo}, #{productId}, #{projectId}, #{expenseCategoryId},
|
|
|
|
|
#{materialName}, #{materialBrand}, #{category}, #{materialParams}, #{purchaseLink},
|
|
|
|
|
#{quantity}, #{estimatedUnitPrice}, #{estimatedAmount}, #{unit}, #{expectedDate},
|
|
|
|
|
#{applicantId}, #{applicantName}, #{purchaseStatus}, #{purchaseBatchNo},
|
2026-09-15 15:50:24 +08:00
|
|
|
#{progressRemark}, #{remark}, #{createBy}, sysdate()
|
|
|
|
|
)
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
<update id="updatePurchaseRequest">
|
|
|
|
|
update purchase_request
|
|
|
|
|
<set>
|
|
|
|
|
<if test="purchaseRequest.requestNo != null and purchaseRequest.requestNo != ''">request_no = #{purchaseRequest.requestNo},</if>
|
|
|
|
|
product_id = #{purchaseRequest.productId},
|
2026-09-28 10:55:48 +08:00
|
|
|
project_id = #{purchaseRequest.projectId},
|
|
|
|
|
expense_category_id = #{purchaseRequest.expenseCategoryId},
|
2026-09-15 15:50:24 +08:00
|
|
|
<if test="purchaseRequest.materialName != null and purchaseRequest.materialName != ''">material_name = #{purchaseRequest.materialName},</if>
|
|
|
|
|
<if test="purchaseRequest.materialBrand != null">material_brand = #{purchaseRequest.materialBrand},</if>
|
|
|
|
|
<if test="purchaseRequest.category != null">category = #{purchaseRequest.category},</if>
|
|
|
|
|
<if test="purchaseRequest.materialParams != null">material_params = #{purchaseRequest.materialParams},</if>
|
|
|
|
|
<if test="purchaseRequest.purchaseLink != null">purchase_link = #{purchaseRequest.purchaseLink},</if>
|
|
|
|
|
<if test="purchaseRequest.quantity != null">quantity = #{purchaseRequest.quantity},</if>
|
2026-09-28 10:55:48 +08:00
|
|
|
estimated_unit_price = #{purchaseRequest.estimatedUnitPrice},
|
|
|
|
|
estimated_amount = #{purchaseRequest.estimatedAmount},
|
2026-09-15 15:50:24 +08:00
|
|
|
<if test="purchaseRequest.unit != null">unit = #{purchaseRequest.unit},</if>
|
|
|
|
|
<if test="purchaseRequest.expectedDate != null">expected_date = #{purchaseRequest.expectedDate},</if>
|
|
|
|
|
<if test="purchaseRequest.applicantId != null">applicant_id = #{purchaseRequest.applicantId},</if>
|
|
|
|
|
<if test="purchaseRequest.applicantName != null and purchaseRequest.applicantName != ''">applicant_name = #{purchaseRequest.applicantName},</if>
|
|
|
|
|
<if test="purchaseRequest.purchaseStatus != null">purchase_status = #{purchaseRequest.purchaseStatus},</if>
|
|
|
|
|
<if test="purchaseRequest.purchaseBatchNo != null">purchase_batch_no = #{purchaseRequest.purchaseBatchNo},</if>
|
|
|
|
|
<if test="purchaseRequest.progressRemark != null">progress_remark = #{purchaseRequest.progressRemark},</if>
|
|
|
|
|
<if test="purchaseRequest.remark != null">remark = #{purchaseRequest.remark},</if>
|
|
|
|
|
<if test="purchaseRequest.updateBy != null">update_by = #{purchaseRequest.updateBy},</if>
|
|
|
|
|
update_time = sysdate()
|
|
|
|
|
</set>
|
|
|
|
|
where id = #{purchaseRequest.id}
|
|
|
|
|
<if test="applicantId != null">and applicant_id = #{applicantId}</if>
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
<delete id="deletePurchaseRequestByIds">
|
|
|
|
|
delete from purchase_request where id in
|
|
|
|
|
<foreach collection="ids" item="id" open="(" separator="," close=")">#{id}</foreach>
|
|
|
|
|
<if test="applicantId != null">and applicant_id = #{applicantId}</if>
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<update id="updatePurchaseStatus">
|
|
|
|
|
update purchase_request
|
|
|
|
|
set purchase_status = #{purchaseStatus},
|
|
|
|
|
progress_remark = #{progressRemark},
|
|
|
|
|
update_by = #{updateBy}, update_time = sysdate()
|
|
|
|
|
where id = #{id}
|
|
|
|
|
</update>
|
|
|
|
|
</mapper>
|