|
|
<?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.xujie.modules.part.dao.PartMapper">
<!-- 通用查询映射结果 --> <resultMap id="BaseResultMap" type="com.xujie.modules.part.entity.Part"> <id column="id" property="id" /> <result column="site" property="site" /> <result column="part_no" property="partNo" /> <result column="bast_part_no" property="basePartNo" /> <result column="part_desc" property="partDesc" /> <result column="remark" property="remark" /> <result column="create_by" property="createBy" /> <result column="create_date" property="createDate" /> <result column="update_by" property="updateBy" /> <result column="update_date" property="updateDate" /> <result column="npc" property="npc" /> <result column="part_spec" property="partSpec" /> <result column="buyer_name" property="buyerName" /> <result column="buyer_id" property="buyerId" /> <result column="sourcing_name" property="sourcingName" /> <result column="sourcing_id" property="sourcingId" /> <result column="category" property="category" /> <result column="category_level2" property="categoryLevel2" /> <result column="category_level3" property="categoryLevel3" /> <result column="unit" property="unit" /> <result column="status" property="status" /> <result column="code_no" property="codeNo" /> <result column="part_stage" property="partStage" /> <result column="sku" property="sku" /> <result column="item" property="item" /> <result column="default_supplier_no" property="defaultSupplierNo" /> <result column="defaultSupplierName" property="defaultSupplierName" /> </resultMap>
<!-- 通用查询结果列 --> <sql id="BaseColumnList"> site, part_no, bast_part_no, part_desc, remark, create_by, create_date, update_by, update_date, npc, part_spec, buyer_name, buyer_id, sourcing_name, sourcing_id, category, category_level2, category_level3, unit, status, code_no, part_stage, id, sku, item, default_supplier_no </sql>
<sql id="PartColumnListAlias"> p.site, p.part_no, p.part_desc, p.remark, p.create_by, p.create_date, p.update_by, p.update_date, p.npc, p.part_spec, p.buyer_name, p.buyer_id, p.sourcing_name, p.sourcing_id, p.category, p.category_level2, p.category_level3, p.unit, p.status, p.code_no, p.part_stage, p.id, p.sku, p.item, p.default_supplier_no, p.bast_part_no AS basePartNo, ss.supplier_name as defaultSupplierName </sql>
<sql id="PartCategoryNameColumns"> pf1.family_name as categoryName, pf2.family_name as categoryLevel2Name, pf3.family_name as categoryLevel3Name </sql>
<sql id="PartCategoryJoins"> left join part_family pf1 on p.site = pf1.site and p.category = pf1.family_id left join part_family pf2 on p.site = pf2.site and p.category_level2 = pf2.family_id left join part_family pf3 on p.site = pf3.site and p.category_level3 = pf3.family_id </sql>
<sql id="PartSupplierJoin"> left join srm_supplier ss on p.site = ss.site and p.default_supplier_no = ss.supplier_no </sql>
<select id="getListByModel" resultType="com.xujie.modules.part.entity.Part"> select <include refid="PartColumnListAlias"/>, <include refid="PartCategoryNameColumns"/> from part p <include refid="PartSupplierJoin"/> <include refid="PartCategoryJoins"/> where 1=1 <if test="site != null and site != '' "> and p.site = #{site}</if> <if test="partNo != null and partNo != '' "> and p.part_no = #{partNo}</if> <if test="basePartNo != null and basePartNo != '' "> and p.bast_part_no = #{basePartNo}</if> <if test="partDesc != null and partDesc != '' "> and p.part_desc = #{partDesc}</if> <if test="remark != null and remark != '' "> and p.remark = #{remark}</if> <if test="createBy != null and createBy != '' "> and p.create_by = #{createBy}</if> <if test="createDate != null and createDate != '' "> and p.create_date = #{createDate}</if> <if test="updateBy != null and updateBy != '' "> and p.update_by = #{updateBy}</if> <if test="updateDate != null and updateDate != '' "> and p.update_date = #{updateDate}</if> <if test="npc != null and npc != '' "> and p.npc = #{npc}</if> <if test="partSpec != null and partSpec != '' "> and p.part_spec = #{partSpec}</if> <if test="buyerName != null and buyerName != '' "> and p.buyer_name = #{buyerName}</if> <if test="buyerId != null "> and p.buyer_id = #{buyerId}</if> <if test="sourcingName != null and sourcingName != '' "> and p.sourcing_name = #{sourcingName}</if> <if test="sourcingId != null "> and p.sourcing_id = #{sourcingId}</if> <if test="category != null and category != '' "> and p.category = #{category}</if> <if test="categoryLevel2 != null and categoryLevel2 != '' "> and p.category_level2 = #{categoryLevel2}</if> <if test="categoryLevel3 != null and categoryLevel3 != '' "> and p.category_level3 = #{categoryLevel3}</if> <if test="unit != null and unit != '' "> and p.unit = #{unit}</if> <if test="status != null "> and p.status = #{status}</if> <if test="codeNo != null and codeNo != '' "> and p.code_no = #{codeNo}</if> <if test="id != null "> and p.id = #{id}</if> <if test="sku != null and sku != '' "> and p.sku = #{sku}</if> <if test="item != null and item != '' "> and p.item = #{item}</if> <if test="defaultSupplierNo != null and defaultSupplierNo != '' "> and p.default_supplier_no = #{defaultSupplierNo}</if> ORDER BY p.part_no </select>
<select id="myPage" resultType="com.xujie.modules.part.vo.PartVo"> select <include refid="PartColumnListAlias"/>, <include refid="PartCategoryNameColumns"/> from part p <include refid="PartSupplierJoin"/> <include refid="PartCategoryJoins"/> where p.site = '${query.site}' <if test="query.id != null "> and p.id = '${query.id}'</if> <if test="query.partNo != null and query.partNo != '' "> and p.part_no like '%${query.partNo}%'</if> <if test="query.basePartNo != null and query.basePartNo != '' "> and p.bast_part_no like '%${query.basePartNo}%'</if> <if test="query.partDesc != null and query.partDesc != '' "> and p.part_desc like '%${query.partDesc}%'</if> <if test="query.remark != null and query.remark != '' "> and p.remark like '%${query.remark}%'</if> <if test="query.createBy != null and query.createBy != '' "> and p.create_by like '%${query.createBy}%'</if> <if test="query.createDate != null "> and p.create_date like '%${query.createDate}%'</if> <if test="query.updateBy != null and query.updateBy != '' "> and p.update_by like '%${query.updateBy}%'</if> <if test="query.updateDate != null "> and p.update_date like '%${query.updateDate}%'</if> <if test="query.npc != null and query.npc != '' "> and p.npc like '%${query.npc}%'</if> <if test="query.partSpec != null and query.partSpec != '' "> and p.part_spec like '%${query.partSpec}%'</if> <if test="query.buyerName != null and query.buyerName != '' "> and p.buyer_name like '%${query.buyerName}%'</if> <if test="query.buyerId != null "> and p.buyer_id = '${query.buyerId}'</if> <if test="query.sourcingName != null and query.sourcingName != '' "> and p.sourcing_name like '%${query.sourcingName}%'</if> <if test="query.sourcingId != null "> and p.sourcing_id = '${query.sourcingId}'</if> <if test="query.category != null and query.category != '' "> and p.category = '${query.category}'</if> <if test="query.categoryLevel2 != null and query.categoryLevel2 != '' "> and p.category_level2 = '${query.categoryLevel2}'</if> <if test="query.categoryLevel3 != null and query.categoryLevel3 != '' "> and p.category_level3 = '${query.categoryLevel3}'</if> <if test="query.unit != null and query.unit != '' "> and p.unit like '%${query.unit}%'</if> <if test="query.status != null and query.status != ''"> and p.status = '${query.status}'</if> <if test="query.codeNo != null and query.codeNo != '' "> and p.code_no like '%${query.codeNo}%'</if> <if test="query.sku != null and query.sku != '' "> and p.sku like '%${query.sku}%'</if> <if test="query.item != null and query.item != '' "> and p.item like '%${query.item}%'</if> <if test="query.defaultSupplierNo != null and query.defaultSupplierNo != '' "> and p.default_supplier_no like '%${query.defaultSupplierNo}%'</if> ORDER BY p.part_no </select> <select id="getAvailableValueList" resultType="com.xujie.modules.base.data.PlmPropertiesItemAvailableData"> select ItemNo, ValueNo, AvailableValue from plm_properties_item_available where itemNo = #{propertiesItemNo} and site = #{site} and ItemType = #{recordType} </select> <select id="searchPartApproveList" resultType="com.xujie.modules.part.vo.PartVo"> select ni.apply_no, ni.node_code, ni.attempt_no, ni.site, ni.order_type, ni.assignee_user_id, ni.assignee_name, ni.special_release, ni.department_id, ni.department_name, i.status as flowStatus, p.part_stage, p.part_no, p.bast_part_no as basePartNo, p.part_desc, p.remark, p.create_by, p.create_date, p.update_by, p.update_date, p.npc, p.part_spec, p.buyer_name, p.buyer_id, p.sourcing_name, p.sourcing_id, p.category, p.category_level2, p.category_level3, pf1.family_name as categoryName, pf2.family_name as categoryLevel2Name, pf3.family_name as categoryLevel3Name, p.unit, p.status, p.code_no, p.sku, p.item, p.default_supplier_no, p.id from erf_flow_node_instance ni left join erf_flow_instance i on ni.apply_no = i.apply_no and ni.site = i.site and ni.order_type = i.order_type left join part p on i.order_ref1 = p.part_no and i.site = p.site left join part_family pf1 on p.site = pf1.site and p.category = pf1.family_id left join part_family pf2 on p.site = pf2.site and p.category_level2 = pf2.family_id left join part_family pf3 on p.site = pf3.site and p.category_level3 = pf3.family_id where ni.site = '${query.site}' and ni.status = 'PENDING' and ni.order_type = '${query.orderType}' and p.id is not null <if test="query.id != null "> and ni.id = '${query.id}'</if> <if test="query.partNo != null and query.partNo != '' "> and p.part_no like '%${query.partNo}%'</if> <if test="query.partDesc != null and query.partDesc != '' "> and p.part_desc like '%${query.partDesc}%'</if> <if test="query.remark != null and query.remark != '' "> and p.remark like '%${query.remark}%'</if> <if test="query.createBy != null and query.createBy != '' "> and p.create_by like '%${query.createBy}%'</if> <if test="query.createDate != null "> and p.create_date like '%${query.createDate}%'</if> <if test="query.updateBy != null and query.updateBy != '' "> and p.update_by like '%${query.updateBy}%'</if> <if test="query.updateDate != null "> and p.update_date like '%${query.updateDate}%'</if> <if test="query.npc != null and query.npc != '' "> and p.npc like '%${query.npc}%'</if> <if test="query.partSpec != null and query.partSpec != '' "> and p.part_spec like '%${query.partSpec}%'</if> <if test="query.buyerName != null and query.buyerName != '' "> and p.buyer_name like '%${query.buyerName}%'</if> <if test="query.buyerId != null "> and p.buyer_id = '${query.buyerId}'</if> <if test="query.sourcingName != null and query.sourcingName != '' "> and p.sourcing_name like '%${query.sourcingName}%'</if> <if test="query.sourcingId != null "> and p.sourcing_id = '${query.sourcingId}'</if> <if test="query.category != null and query.category != '' "> and p.category like '%${query.category}%'</if> <if test="query.unit != null and query.unit != '' "> and p.unit like '%${query.unit}%'</if> <if test="query.status != null and query.status != ''"> and p.status = '${query.status}'</if> <if test="query.codeNo != null and query.codeNo != '' "> and p.code_no like '%${query.codeNo}%'</if> <if test="query.partStage != null and query.partStage != ''"> and p.part_stage = '${query.partStage}'</if> <if test="query.flowStatus != null and query.flowStatus != ''"> and i.flow_status = '${query.flowStatus}'</if> <if test="query.applyNo != null and query.applyNo != ''"> and i.apply_no like '%${query.applyNo}%'</if> <if test="query.nodeCode != null and query.nodeCode != ''"> and ni.node_code = '${query.nodeCode}'</if> <if test="query.specialRelease != null and query.specialRelease != ''"> and ni.special_release = '${query.specialRelease}'</if> <!-- 112 样式码表示 yyyyMMdd 格式--> <if test="query.startDate != null "> AND CONVERT(varchar(8), ni.receive_time, 112) >= #{query.startDate} </if> <if test="query.endDate != null "> AND CONVERT(varchar(8), ni.receive_time, 112) <= #{query.endDate} </if> order by p.id desc </select>
<select id="findFirstByBasePartNo" resultMap="BaseResultMap"> select top 1 <include refid="BaseColumnList"/> from part where site = #{site} and ( bast_part_no = #{basePartNo} or part_no = #{basePartNo} or part_no like #{basePartNo} + '-%' ) order by case when bast_part_no = #{basePartNo} then 0 else 1 end, id asc </select>
<select id="countSupplierByNo" resultType="java.lang.Integer"> select count(1) from srm_supplier where site = #{site} and supplier_no = #{supplierNo} </select>
<select id="getSupplierCurrency" resultType="java.lang.String"> select top 1 Currency from srm_supplier where site = #{site} and supplier_no = #{supplierNo} </select>
<select id="countRunningFlowInstanceForPart" resultType="java.lang.Integer"> select count(1) from erf_flow_instance where site = #{site} and order_ref1 = #{partNo} and order_type = #{orderType} and status = 'RUNNING' </select>
<select id="countPoDetailBySiteAndPartNo" resultType="java.lang.Integer"> select count(1) from PODetail where site = #{site} and part_no = #{partNo} </select>
<select id="countPurQuotationDetailBySiteAndPartNo" resultType="java.lang.Integer"> select count(1) from PurQuotationDetail where site = #{site} and part_no = #{partNo} </select>
<!-- 删除物料关联数据(转正申请、供应商关系、属性值) - rqrq --> <delete id="deleteFlowNodeInstanceBySiteAndPartNoAndOrderType"> delete from erf_flow_node_instance where site = #{site} and order_type = #{orderType} and apply_no in ( select apply_no from erf_flow_instance where site = #{site} and order_type = #{orderType} and order_ref1 = #{partNo} ) </delete>
<delete id="deleteFlowInstanceBySiteAndPartNoAndOrderType"> delete from erf_flow_instance where site = #{site} and order_type = #{orderType} and order_ref1 = #{partNo} </delete>
<delete id="deleteSupplierForPartBySiteAndPartNo"> delete from SupplierforPart where site = #{site} and part_no = #{partNo} </delete>
<delete id="deletePartSubPropertiesValueBySiteAndPartNo"> delete from PartSubPropertiesValue where site = #{site} and PartNo = #{partNo} </delete>
<delete id="deletePartSubPropertiesValueHeaderBySiteAndPartNo"> delete from PartSubPropertiesValueHeader where site = #{site} and PartNo = #{partNo} </delete>
<delete id="deletePartBySiteAndPartNo"> delete from part where site = #{site} and part_no = #{partNo} </delete>
<!-- 查询物料分类是否跳过新品流程,无分类时返回空 --> <select id="getPartFamilySkipNew" resultType="java.lang.String"> SELECT TOP 1 pf.skip_new FROM part p INNER JOIN part_family pf ON pf.site = p.site AND pf.family_id = p.category WHERE p.site = #{site} AND p.part_no = #{partNo} </select>
<update id="mergeSupplierForPart"> MERGE INTO SupplierforPart AS target USING ( SELECT #{site} AS site, #{supplierNo} AS supplier_no, #{partNo} AS part_no ) AS src ON target.site = src.site AND target.supplier_no = src.supplier_no AND target.part_no = src.part_no WHEN MATCHED THEN UPDATE SET active = 'Y', currency = #{currency}, [minOrderQty] = ISNULL(target.[minOrderQty], 0), new_product_audited = ISNULL(#{newProductAudited,jdbcType=VARCHAR}, ISNULL(target.new_product_audited, 'N')) WHEN NOT MATCHED THEN INSERT (site, supplier_no, part_no, active, currency, [minOrderQty], new_product_audited) VALUES (#{site}, #{supplierNo}, #{partNo}, 'Y', #{currency}, 0, ISNULL(#{newProductAudited,jdbcType=VARCHAR}, 'N')); </update>
<update id="updateDefaultSupplierByPartNo"> UPDATE part SET default_supplier_no = #{targetSupplierNo}, update_date = GETDATE() WHERE site = #{site} AND part_no = #{partNo} AND ISNULL(default_supplier_no, '') <> #{targetSupplierNo} </update>
<update id="updateDefaultSupplierByBasePartNo"> UPDATE part SET default_supplier_no = #{targetSupplierNo}, update_date = GETDATE() WHERE site = #{site} AND ( bast_part_no = #{basePartNo} OR part_no = #{basePartNo} OR part_no LIKE CONCAT(#{basePartNo}, '-%') ) AND ISNULL(default_supplier_no, '') <> #{targetSupplierNo} </update>
<update id="mergeSupplierForPartByBasePart"> MERGE INTO SupplierforPart AS target USING ( SELECT p.site, #{supplierNo} AS supplier_no, p.part_no, #{currency} AS currency FROM part p WHERE p.site = #{site} AND ( p.bast_part_no = #{basePartNo} OR p.part_no = #{basePartNo} OR p.part_no LIKE CONCAT(#{basePartNo}, '-%') ) AND ISNULL(p.default_supplier_no, '') = #{supplierNo} ) AS src ON target.site = src.site AND target.supplier_no = src.supplier_no AND target.part_no = src.part_no WHEN MATCHED THEN UPDATE SET active = 'Y', currency = src.currency, [minOrderQty] = ISNULL(target.[minOrderQty], 0) WHEN NOT MATCHED THEN INSERT (site, supplier_no, part_no, active, currency, [minOrderQty]) VALUES (src.site, src.supplier_no, src.part_no, 'Y', src.currency, 0); </update>
<update id="updatePartStageBySiteAndPartNo"> UPDATE part SET part_stage = #{partStage}, update_date = GETDATE() WHERE site = #{site} AND part_no = #{partNo} </update>
</mapper>
|