227 lines
10 KiB
XML
227 lines
10 KiB
XML
<?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.nflg.wms.repository.mapper.QmsQualityInspectorMapper">
|
||
|
||
<!--
|
||
分页查询:以质检人为主体,每个 user_id 只返回一条记录(主表一人一条)
|
||
JOIN user_interior/department 获取部门信息
|
||
JOIN user AS cu 获取转办人姓名
|
||
支持动态过滤:员工工号(userCode)、人员名称模糊(userName)、物料编号(materialNo)
|
||
-->
|
||
<select id="searchPage" resultType="com.nflg.wms.common.pojo.vo.QmsQualityInspectorVO">
|
||
SELECT
|
||
qi.id,
|
||
qi.user_id,
|
||
u.user_code,
|
||
u.user_name,
|
||
d.id AS dept_id,
|
||
d.name AS dept_name,
|
||
NULL::bigint AS dept_leader_id,
|
||
NULL::varchar AS dept_leader_name,
|
||
qi.enable,
|
||
qi.inspection_type,
|
||
qi.change_user_id,
|
||
cu.user_name AS change_user_name,
|
||
qi.create_by,
|
||
qi.create_time,
|
||
qi.update_by,
|
||
qi.update_time
|
||
FROM qms_quality_inspector qi
|
||
LEFT JOIN "user" u ON u.id = qi.user_id
|
||
LEFT JOIN user_interior ui ON ui.user_id = qi.user_id
|
||
LEFT JOIN department d ON d.id = ui.dept_id
|
||
LEFT JOIN qms_quality_inspector cqi ON cqi.id = qi.change_user_id
|
||
LEFT JOIN "user" cu ON cu.id = cqi.user_id
|
||
<where>
|
||
<if test="request.userCode != null and request.userCode != ''">
|
||
AND u.user_code = #{request.userCode}
|
||
</if>
|
||
<if test="request.userName != null and request.userName != ''">
|
||
AND u.user_name ilike concat('%', #{request.userName}, '%')
|
||
</if>
|
||
<if test="request.materialNo != null and request.materialNo != ''">
|
||
AND EXISTS (
|
||
SELECT 1
|
||
FROM qms_inspector_material_item imi
|
||
LEFT JOIN qms_qc_material m ON m.id = imi.material_id
|
||
WHERE imi.inspector_id = qi.id
|
||
AND m.material_no ilike concat('%', #{request.materialNo}, '%')
|
||
)
|
||
</if>
|
||
<if test="request.inspectionType != null">
|
||
AND qi.inspection_type = #{request.inspectionType}
|
||
</if>
|
||
</where>
|
||
ORDER BY qi.id DESC
|
||
</select>
|
||
|
||
<!-- 按 userId 查询关联物料列表(JOIN qms_qc_material 获取物料详情) -->
|
||
<select id="getMaterialsByUserId" resultType="com.nflg.wms.common.pojo.vo.QmsQualityInspectorMaterialVO">
|
||
SELECT
|
||
imi.id,
|
||
imi.material_id,
|
||
m.material_no,
|
||
m.material_category_code,
|
||
m.material_category_code_path_name AS material_category_name,
|
||
m.material_desc AS material_name,
|
||
m.material_specifications,
|
||
m.material_texture,
|
||
m.is_standard_maintained AS material_status
|
||
FROM qms_inspector_material_item imi
|
||
LEFT JOIN qms_qc_material m ON m.id = imi.material_id
|
||
WHERE imi.inspector_id = (
|
||
SELECT id FROM qms_quality_inspector WHERE user_id = #{userId} LIMIT 1
|
||
)
|
||
ORDER BY imi.id ASC
|
||
</select>
|
||
|
||
<!-- 按 userId 查询关联物料列表(支持供应商过滤) -->
|
||
<select id="getMaterialsByUserIdWithSupplier" resultType="com.nflg.wms.common.pojo.vo.QmsQualityInspectorMaterialVO">
|
||
SELECT
|
||
imi.id,
|
||
imi.material_id,
|
||
m.material_no,
|
||
m.material_category_code,
|
||
m.material_category_code_path_name AS material_category_name,
|
||
m.material_desc AS material_name,
|
||
m.material_specifications,
|
||
m.material_texture,
|
||
m.is_standard_maintained AS material_status
|
||
FROM qms_inspector_material_item imi
|
||
LEFT JOIN qms_qc_material m ON m.id = imi.material_id
|
||
LEFT JOIN qms_coa_review cr ON cr.material_id = m.id
|
||
LEFT JOIN user_supplier us ON us.id = cr.supplier_id
|
||
WHERE imi.inspector_id = (
|
||
SELECT id FROM qms_quality_inspector WHERE user_id = #{userId} LIMIT 1
|
||
)
|
||
<if test="supplierCode != null and supplierCode != ''">
|
||
AND us.supplier_code = #{supplierCode}
|
||
</if>
|
||
<if test="supplierName != null and supplierName != ''">
|
||
AND us.supplier_name LIKE CONCAT('%', #{supplierName}, '%')
|
||
</if>
|
||
GROUP BY imi.id, imi.material_id, m.material_no, m.material_category_code,
|
||
m.material_category_code_path_name, m.material_desc,
|
||
m.material_specifications, m.material_texture, m.is_standard_maintained
|
||
ORDER BY imi.id ASC
|
||
</select>
|
||
|
||
<!--
|
||
按 userId 查询绑定物料列表(支持物料编号/类别/描述过滤),合并两个来源:
|
||
1) qms_inspector_material_item:直接绑定的物料
|
||
2) qms_inspector_material_category_item:绑定的物料类别及其所有子孙类别下展开的物料
|
||
(类别项存 material_category_id;经 ltree 的后代匹配 descendant.parent_tree <@ mc.parent_tree
|
||
取出该类别自身及全部子孙类别,再用 category_code 匹配
|
||
qms_qc_material.material_category_code 展开为物料)
|
||
-->
|
||
<select id="getMaterialsByUserIdWithFilter" resultType="com.nflg.wms.common.pojo.vo.QmsQualityInspectorMaterialVO">
|
||
SELECT
|
||
m.id,
|
||
imi.material_id,
|
||
m.material_no,
|
||
m.drawing_no,
|
||
m.drawing_no_ver,
|
||
m.material_category_code,
|
||
m.material_category_code_path_name AS material_category_name,
|
||
m.material_desc AS material_name,
|
||
m.material_specifications,
|
||
m.material_texture,
|
||
m.is_standard_maintained AS material_status
|
||
FROM qms_inspector_material_item imi
|
||
INNER JOIN qms_quality_inspector qi ON qi.id = imi.inspector_id
|
||
LEFT JOIN qms_qc_material m ON m.id = imi.material_id
|
||
WHERE qi.inspection_type=#{request.inspectionType} AND imi.inspector_id = (
|
||
SELECT id FROM qms_quality_inspector WHERE user_id = #{userId} LIMIT 1
|
||
)
|
||
<if test="request.materialNo != null and request.materialNo != ''">
|
||
AND m.material_no = #{request.materialNo}
|
||
</if>
|
||
<if test="request.materialCategoryCode != null and request.materialCategoryCode != ''">
|
||
AND m.material_category_code LIKE CONCAT(#{request.materialCategoryCode}, '%')
|
||
</if>
|
||
<if test="request.materialDesc != null and request.materialDesc != ''">
|
||
AND m.material_desc LIKE CONCAT('%', #{request.materialDesc}, '%')
|
||
</if>
|
||
UNION ALL
|
||
SELECT
|
||
m.id,
|
||
m.id AS material_id,
|
||
m.material_no,
|
||
m.drawing_no,
|
||
m.drawing_no_ver,
|
||
m.material_category_code,
|
||
m.material_category_code_path_name AS material_category_name,
|
||
m.material_desc AS material_name,
|
||
m.material_specifications,
|
||
m.material_texture,
|
||
m.is_standard_maintained AS material_status
|
||
FROM qms_inspector_material_category_item imci
|
||
INNER JOIN qms_quality_inspector qi ON qi.id = imi.inspector_id
|
||
JOIN qms_qc_material_category mc ON mc.id = imci.material_category_id
|
||
JOIN qms_qc_material_category descendant ON descendant.parent_tree <@ mc.parent_tree
|
||
JOIN qms_qc_material m ON m.material_category_code = descendant.category_code
|
||
WHERE qi.inspection_type=#{request.inspectionType} AND imci.inspector_id = (
|
||
SELECT id FROM qms_quality_inspector WHERE user_id = #{userId} LIMIT 1
|
||
)
|
||
<if test="request.materialNo != null and request.materialNo != ''">
|
||
AND m.material_no = #{request.materialNo}
|
||
</if>
|
||
<if test="request.materialCategoryCode != null and request.materialCategoryCode != ''">
|
||
AND m.material_category_code LIKE CONCAT(#{request.materialCategoryCode}, '%')
|
||
</if>
|
||
<if test="request.materialDesc != null and request.materialDesc != ''">
|
||
AND m.material_desc LIKE CONCAT('%', #{request.materialDesc}, '%')
|
||
</if>
|
||
ORDER BY material_id ASC
|
||
</select>
|
||
|
||
<!-- 按 userId 查询关联物料类别列表(JOIN qms_qc_material_category 取类别信息) -->
|
||
<select id="getCategoriesByUserId" resultType="com.nflg.wms.common.pojo.vo.QmsQualityInspectorCategoryVO">
|
||
SELECT
|
||
imci.id,
|
||
imci.material_category_id,
|
||
mc.category_code AS material_category_code,
|
||
mc.category_name AS material_category_name
|
||
FROM qms_inspector_material_category_item imci
|
||
LEFT JOIN qms_qc_material_category mc ON mc.id = imci.material_category_id
|
||
WHERE imci.inspector_id = (
|
||
SELECT id FROM qms_quality_inspector WHERE user_id = #{userId} LIMIT 1
|
||
)
|
||
ORDER BY imci.id ASC
|
||
</select>
|
||
|
||
<!-- 按 inspectorId 直接查询关联物料列表 -->
|
||
<select id="getMaterialsByInspectorId" resultType="com.nflg.wms.common.pojo.vo.QmsQualityInspectorMaterialVO">
|
||
SELECT
|
||
imi.id,
|
||
imi.material_id,
|
||
m.material_no,
|
||
m.drawing_no,
|
||
m.drawing_no_ver,
|
||
m.material_category_code,
|
||
m.material_category_code_path_name AS material_category_name,
|
||
m.material_name,
|
||
m.material_specifications,
|
||
m.material_texture,
|
||
m.is_standard_maintained AS material_status
|
||
FROM qms_inspector_material_item imi
|
||
LEFT JOIN qms_qc_material m ON m.id = imi.material_id
|
||
WHERE imi.inspector_id = #{inspectorId}
|
||
ORDER BY imi.id ASC
|
||
</select>
|
||
|
||
<!-- 按 inspectorId 直接查询关联物料类别列表(通过 material_category_id JOIN qms_qc_material_category) -->
|
||
<select id="getCategoriesByInspectorId" resultType="com.nflg.wms.common.pojo.vo.QmsQualityInspectorCategoryVO">
|
||
SELECT
|
||
imci.id,
|
||
imci.material_category_id,
|
||
mc.category_code AS material_category_code,
|
||
mc.category_name AS material_category_name
|
||
FROM qms_inspector_material_category_item imci
|
||
LEFT JOIN qms_qc_material_category mc ON mc.id = imci.material_category_id
|
||
WHERE imci.inspector_id = #{inspectorId}
|
||
ORDER BY imci.id ASC
|
||
</select>
|
||
|
||
</mapper>
|