You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

416 lines
20 KiB

​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
5 months ago
4 months ago
​
​
​
​
4 months ago
5 months ago
​
​
​
​
4 months ago
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
5 months ago
5 months ago
​
4 months ago
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
5 months ago
​
5 months ago
​
​
5 months ago
​
​
​
4 months ago
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
4 months ago
​
​
​
​
​
5 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
4 months ago
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
4 months ago
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 months ago
​
​
​
​
​
​
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.xujie.modules.part.dao.PartMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.xujie.modules.part.entity.Part">
  6. <id column="id" property="id" />
  7. <result column="site" property="site" />
  8. <result column="part_no" property="partNo" />
  9. <result column="bast_part_no" property="basePartNo" />
  10. <result column="part_desc" property="partDesc" />
  11. <result column="remark" property="remark" />
  12. <result column="create_by" property="createBy" />
  13. <result column="create_date" property="createDate" />
  14. <result column="update_by" property="updateBy" />
  15. <result column="update_date" property="updateDate" />
  16. <result column="npc" property="npc" />
  17. <result column="part_spec" property="partSpec" />
  18. <result column="buyer_name" property="buyerName" />
  19. <result column="buyer_id" property="buyerId" />
  20. <result column="sourcing_name" property="sourcingName" />
  21. <result column="sourcing_id" property="sourcingId" />
  22. <result column="category" property="category" />
  23. <result column="category_level2" property="categoryLevel2" />
  24. <result column="category_level3" property="categoryLevel3" />
  25. <result column="unit" property="unit" />
  26. <result column="status" property="status" />
  27. <result column="code_no" property="codeNo" />
  28. <result column="part_stage" property="partStage" />
  29. <result column="sku" property="sku" />
  30. <result column="item" property="item" />
  31. <result column="default_supplier_no" property="defaultSupplierNo" />
  32. <result column="defaultSupplierName" property="defaultSupplierName" />
  33. </resultMap>
  34. <!-- 通用查询结果列 -->
  35. <sql id="BaseColumnList">
  36. 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
  37. </sql>
  38. <sql id="PartColumnListAlias">
  39. p.site, p.part_no, p.part_desc, p.remark, p.create_by, p.create_date, p.update_by, p.update_date,
  40. p.npc, p.part_spec, p.buyer_name, p.buyer_id, p.sourcing_name, p.sourcing_id,
  41. p.category, p.category_level2, p.category_level3, p.unit, p.status, p.code_no, p.part_stage, p.id, p.sku,
  42. p.item, p.default_supplier_no, p.bast_part_no AS basePartNo, ss.supplier_name as defaultSupplierName
  43. </sql>
  44. <sql id="PartCategoryNameColumns">
  45. pf1.family_name as categoryName,
  46. pf2.family_name as categoryLevel2Name,
  47. pf3.family_name as categoryLevel3Name
  48. </sql>
  49. <sql id="PartCategoryJoins">
  50. left join part_family pf1 on p.site = pf1.site and p.category = pf1.family_id
  51. left join part_family pf2 on p.site = pf2.site and p.category_level2 = pf2.family_id
  52. left join part_family pf3 on p.site = pf3.site and p.category_level3 = pf3.family_id
  53. </sql>
  54. <sql id="PartSupplierJoin">
  55. left join srm_supplier ss on p.site = ss.site and p.default_supplier_no = ss.supplier_no
  56. </sql>
  57. <select id="getListByModel" resultType="com.xujie.modules.part.entity.Part">
  58. select
  59. <include refid="PartColumnListAlias"/>,
  60. <include refid="PartCategoryNameColumns"/>
  61. from part p
  62. <include refid="PartSupplierJoin"/>
  63. <include refid="PartCategoryJoins"/>
  64. where 1=1
  65. <if test="site != null and site != '' "> and p.site = #{site}</if>
  66. <if test="partNo != null and partNo != '' "> and p.part_no = #{partNo}</if>
  67. <if test="basePartNo != null and basePartNo != '' "> and p.bast_part_no = #{basePartNo}</if>
  68. <if test="partDesc != null and partDesc != '' "> and p.part_desc = #{partDesc}</if>
  69. <if test="remark != null and remark != '' "> and p.remark = #{remark}</if>
  70. <if test="createBy != null and createBy != '' "> and p.create_by = #{createBy}</if>
  71. <if test="createDate != null and createDate != '' "> and p.create_date = #{createDate}</if>
  72. <if test="updateBy != null and updateBy != '' "> and p.update_by = #{updateBy}</if>
  73. <if test="updateDate != null and updateDate != '' "> and p.update_date = #{updateDate}</if>
  74. <if test="npc != null and npc != '' "> and p.npc = #{npc}</if>
  75. <if test="partSpec != null and partSpec != '' "> and p.part_spec = #{partSpec}</if>
  76. <if test="buyerName != null and buyerName != '' "> and p.buyer_name = #{buyerName}</if>
  77. <if test="buyerId != null "> and p.buyer_id = #{buyerId}</if>
  78. <if test="sourcingName != null and sourcingName != '' "> and p.sourcing_name = #{sourcingName}</if>
  79. <if test="sourcingId != null "> and p.sourcing_id = #{sourcingId}</if>
  80. <if test="category != null and category != '' "> and p.category = #{category}</if>
  81. <if test="categoryLevel2 != null and categoryLevel2 != '' "> and p.category_level2 = #{categoryLevel2}</if>
  82. <if test="categoryLevel3 != null and categoryLevel3 != '' "> and p.category_level3 = #{categoryLevel3}</if>
  83. <if test="unit != null and unit != '' "> and p.unit = #{unit}</if>
  84. <if test="status != null "> and p.status = #{status}</if>
  85. <if test="codeNo != null and codeNo != '' "> and p.code_no = #{codeNo}</if>
  86. <if test="id != null "> and p.id = #{id}</if>
  87. <if test="sku != null and sku != '' "> and p.sku = #{sku}</if>
  88. <if test="item != null and item != '' "> and p.item = #{item}</if>
  89. <if test="defaultSupplierNo != null and defaultSupplierNo != '' "> and p.default_supplier_no = #{defaultSupplierNo}</if>
  90. ORDER BY p.part_no
  91. </select>
  92. <select id="myPage" resultType="com.xujie.modules.part.vo.PartVo">
  93. select
  94. <include refid="PartColumnListAlias"/>,
  95. <include refid="PartCategoryNameColumns"/>
  96. from part p
  97. <include refid="PartSupplierJoin"/>
  98. <include refid="PartCategoryJoins"/>
  99. where p.site = '${query.site}'
  100. <if test="query.id != null "> and p.id = '${query.id}'</if>
  101. <if test="query.partNo != null and query.partNo != '' "> and p.part_no like '%${query.partNo}%'</if>
  102. <if test="query.basePartNo != null and query.basePartNo != '' "> and p.bast_part_no like '%${query.basePartNo}%'</if>
  103. <if test="query.partDesc != null and query.partDesc != '' "> and p.part_desc like '%${query.partDesc}%'</if>
  104. <if test="query.remark != null and query.remark != '' "> and p.remark like '%${query.remark}%'</if>
  105. <if test="query.createBy != null and query.createBy != '' "> and p.create_by like '%${query.createBy}%'</if>
  106. <if test="query.createDate != null "> and p.create_date like '%${query.createDate}%'</if>
  107. <if test="query.updateBy != null and query.updateBy != '' "> and p.update_by like '%${query.updateBy}%'</if>
  108. <if test="query.updateDate != null "> and p.update_date like '%${query.updateDate}%'</if>
  109. <if test="query.npc != null and query.npc != '' "> and p.npc like '%${query.npc}%'</if>
  110. <if test="query.partSpec != null and query.partSpec != '' "> and p.part_spec like '%${query.partSpec}%'</if>
  111. <if test="query.buyerName != null and query.buyerName != '' "> and p.buyer_name like '%${query.buyerName}%'</if>
  112. <if test="query.buyerId != null "> and p.buyer_id = '${query.buyerId}'</if>
  113. <if test="query.sourcingName != null and query.sourcingName != '' "> and p.sourcing_name like '%${query.sourcingName}%'</if>
  114. <if test="query.sourcingId != null "> and p.sourcing_id = '${query.sourcingId}'</if>
  115. <if test="query.category != null and query.category != '' "> and p.category = '${query.category}'</if>
  116. <if test="query.categoryLevel2 != null and query.categoryLevel2 != '' "> and p.category_level2 = '${query.categoryLevel2}'</if>
  117. <if test="query.categoryLevel3 != null and query.categoryLevel3 != '' "> and p.category_level3 = '${query.categoryLevel3}'</if>
  118. <if test="query.unit != null and query.unit != '' "> and p.unit like '%${query.unit}%'</if>
  119. <if test="query.status != null and query.status != ''"> and p.status = '${query.status}'</if>
  120. <if test="query.codeNo != null and query.codeNo != '' "> and p.code_no like '%${query.codeNo}%'</if>
  121. <if test="query.sku != null and query.sku != '' "> and p.sku like '%${query.sku}%'</if>
  122. <if test="query.item != null and query.item != '' "> and p.item like '%${query.item}%'</if>
  123. <if test="query.defaultSupplierNo != null and query.defaultSupplierNo != '' "> and p.default_supplier_no like '%${query.defaultSupplierNo}%'</if>
  124. ORDER BY p.part_no
  125. </select>
  126. <select id="getAvailableValueList" resultType="com.xujie.modules.base.data.PlmPropertiesItemAvailableData">
  127. select
  128. ItemNo,
  129. ValueNo,
  130. AvailableValue
  131. from plm_properties_item_available
  132. where itemNo = #{propertiesItemNo} and site = #{site} and ItemType = #{recordType}
  133. </select>
  134. <select id="searchPartApproveList" resultType="com.xujie.modules.part.vo.PartVo">
  135. select
  136. ni.apply_no,
  137. ni.node_code,
  138. ni.attempt_no,
  139. ni.site,
  140. ni.order_type,
  141. ni.assignee_user_id,
  142. ni.assignee_name,
  143. ni.special_release,
  144. ni.department_id,
  145. ni.department_name,
  146. i.status as flowStatus,
  147. p.part_stage,
  148. p.part_no,
  149. p.bast_part_no as basePartNo,
  150. p.part_desc,
  151. p.remark,
  152. p.create_by,
  153. p.create_date,
  154. p.update_by,
  155. p.update_date,
  156. p.npc,
  157. p.part_spec,
  158. p.buyer_name,
  159. p.buyer_id,
  160. p.sourcing_name,
  161. p.sourcing_id,
  162. p.category,
  163. p.category_level2,
  164. p.category_level3,
  165. pf1.family_name as categoryName,
  166. pf2.family_name as categoryLevel2Name,
  167. pf3.family_name as categoryLevel3Name,
  168. p.unit,
  169. p.status,
  170. p.code_no,
  171. p.sku,
  172. p.item,
  173. p.default_supplier_no,
  174. p.id
  175. from erf_flow_node_instance ni
  176. 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
  177. left join part p on i.order_ref1 = p.part_no and i.site = p.site
  178. left join part_family pf1 on p.site = pf1.site and p.category = pf1.family_id
  179. left join part_family pf2 on p.site = pf2.site and p.category_level2 = pf2.family_id
  180. left join part_family pf3 on p.site = pf3.site and p.category_level3 = pf3.family_id
  181. where ni.site = '${query.site}'
  182. and ni.status = 'PENDING'
  183. and ni.order_type = '${query.orderType}'
  184. and p.id is not null
  185. <if test="query.id != null "> and ni.id = '${query.id}'</if>
  186. <if test="query.partNo != null and query.partNo != '' "> and p.part_no like '%${query.partNo}%'</if>
  187. <if test="query.partDesc != null and query.partDesc != '' "> and p.part_desc like '%${query.partDesc}%'</if>
  188. <if test="query.remark != null and query.remark != '' "> and p.remark like '%${query.remark}%'</if>
  189. <if test="query.createBy != null and query.createBy != '' "> and p.create_by like '%${query.createBy}%'</if>
  190. <if test="query.createDate != null "> and p.create_date like '%${query.createDate}%'</if>
  191. <if test="query.updateBy != null and query.updateBy != '' "> and p.update_by like '%${query.updateBy}%'</if>
  192. <if test="query.updateDate != null "> and p.update_date like '%${query.updateDate}%'</if>
  193. <if test="query.npc != null and query.npc != '' "> and p.npc like '%${query.npc}%'</if>
  194. <if test="query.partSpec != null and query.partSpec != '' "> and p.part_spec like '%${query.partSpec}%'</if>
  195. <if test="query.buyerName != null and query.buyerName != '' "> and p.buyer_name like '%${query.buyerName}%'</if>
  196. <if test="query.buyerId != null "> and p.buyer_id = '${query.buyerId}'</if>
  197. <if test="query.sourcingName != null and query.sourcingName != '' "> and p.sourcing_name like '%${query.sourcingName}%'</if>
  198. <if test="query.sourcingId != null "> and p.sourcing_id = '${query.sourcingId}'</if>
  199. <if test="query.category != null and query.category != '' "> and p.category like '%${query.category}%'</if>
  200. <if test="query.unit != null and query.unit != '' "> and p.unit like '%${query.unit}%'</if>
  201. <if test="query.status != null and query.status != ''"> and p.status = '${query.status}'</if>
  202. <if test="query.codeNo != null and query.codeNo != '' "> and p.code_no like '%${query.codeNo}%'</if>
  203. <if test="query.partStage != null and query.partStage != ''"> and p.part_stage = '${query.partStage}'</if>
  204. <if test="query.flowStatus != null and query.flowStatus != ''"> and i.flow_status = '${query.flowStatus}'</if>
  205. <if test="query.applyNo != null and query.applyNo != ''"> and i.apply_no like '%${query.applyNo}%'</if>
  206. <if test="query.nodeCode != null and query.nodeCode != ''"> and ni.node_code = '${query.nodeCode}'</if>
  207. <if test="query.specialRelease != null and query.specialRelease != ''"> and ni.special_release = '${query.specialRelease}'</if>
  208. <!-- 112 样式码表示 yyyyMMdd 格式-->
  209. <if test="query.startDate != null ">
  210. AND CONVERT(varchar(8), ni.receive_time, 112) &gt;= #{query.startDate}
  211. </if>
  212. <if test="query.endDate != null ">
  213. AND CONVERT(varchar(8), ni.receive_time, 112) &lt;= #{query.endDate}
  214. </if>
  215. order by p.id desc
  216. </select>
  217. <select id="findFirstByBasePartNo" resultMap="BaseResultMap">
  218. select top 1
  219. <include refid="BaseColumnList"/>
  220. from part
  221. where site = #{site}
  222. and (
  223. bast_part_no = #{basePartNo}
  224. or part_no = #{basePartNo}
  225. or part_no like #{basePartNo} + '-%'
  226. )
  227. order by case when bast_part_no = #{basePartNo} then 0 else 1 end, id asc
  228. </select>
  229. <select id="countSupplierByNo" resultType="java.lang.Integer">
  230. select count(1)
  231. from srm_supplier
  232. where site = #{site}
  233. and supplier_no = #{supplierNo}
  234. </select>
  235. <select id="getSupplierCurrency" resultType="java.lang.String">
  236. select top 1 Currency
  237. from srm_supplier
  238. where site = #{site}
  239. and supplier_no = #{supplierNo}
  240. </select>
  241. <select id="countRunningFlowInstanceForPart" resultType="java.lang.Integer">
  242. select count(1)
  243. from erf_flow_instance
  244. where site = #{site}
  245. and order_ref1 = #{partNo}
  246. and order_type = #{orderType}
  247. and status = 'RUNNING'
  248. </select>
  249. <select id="countPoDetailBySiteAndPartNo" resultType="java.lang.Integer">
  250. select count(1)
  251. from PODetail
  252. where site = #{site}
  253. and part_no = #{partNo}
  254. </select>
  255. <select id="countPurQuotationDetailBySiteAndPartNo" resultType="java.lang.Integer">
  256. select count(1)
  257. from PurQuotationDetail
  258. where site = #{site}
  259. and part_no = #{partNo}
  260. </select>
  261. <!-- 删除物料关联数据(转正申请、供应商关系、属性值) - rqrq -->
  262. <delete id="deleteFlowNodeInstanceBySiteAndPartNoAndOrderType">
  263. delete
  264. from erf_flow_node_instance
  265. where site = #{site}
  266. and order_type = #{orderType}
  267. and apply_no in (
  268. select apply_no
  269. from erf_flow_instance
  270. where site = #{site}
  271. and order_type = #{orderType}
  272. and order_ref1 = #{partNo}
  273. )
  274. </delete>
  275. <delete id="deleteFlowInstanceBySiteAndPartNoAndOrderType">
  276. delete
  277. from erf_flow_instance
  278. where site = #{site}
  279. and order_type = #{orderType}
  280. and order_ref1 = #{partNo}
  281. </delete>
  282. <delete id="deleteSupplierForPartBySiteAndPartNo">
  283. delete
  284. from SupplierforPart
  285. where site = #{site}
  286. and part_no = #{partNo}
  287. </delete>
  288. <delete id="deletePartSubPropertiesValueBySiteAndPartNo">
  289. delete
  290. from PartSubPropertiesValue
  291. where site = #{site}
  292. and PartNo = #{partNo}
  293. </delete>
  294. <delete id="deletePartSubPropertiesValueHeaderBySiteAndPartNo">
  295. delete
  296. from PartSubPropertiesValueHeader
  297. where site = #{site}
  298. and PartNo = #{partNo}
  299. </delete>
  300. <delete id="deletePartBySiteAndPartNo">
  301. delete
  302. from part
  303. where site = #{site}
  304. and part_no = #{partNo}
  305. </delete>
  306. <!-- 查询物料分类是否跳过新品流程,无分类时返回空 -->
  307. <select id="getPartFamilySkipNew" resultType="java.lang.String">
  308. SELECT TOP 1 pf.skip_new
  309. FROM part p
  310. INNER JOIN part_family pf
  311. ON pf.site = p.site
  312. AND pf.family_id = p.category
  313. WHERE p.site = #{site}
  314. AND p.part_no = #{partNo}
  315. </select>
  316. <update id="mergeSupplierForPart">
  317. MERGE INTO SupplierforPart AS target
  318. USING (
  319. SELECT #{site} AS site, #{supplierNo} AS supplier_no, #{partNo} AS part_no
  320. ) AS src
  321. ON target.site = src.site
  322. AND target.supplier_no = src.supplier_no
  323. AND target.part_no = src.part_no
  324. WHEN MATCHED THEN
  325. UPDATE SET
  326. active = 'Y',
  327. currency = #{currency},
  328. [minOrderQty] = ISNULL(target.[minOrderQty], 0),
  329. new_product_audited = ISNULL(#{newProductAudited,jdbcType=VARCHAR}, ISNULL(target.new_product_audited, 'N'))
  330. WHEN NOT MATCHED THEN
  331. INSERT (site, supplier_no, part_no, active, currency, [minOrderQty], new_product_audited)
  332. VALUES (#{site}, #{supplierNo}, #{partNo}, 'Y', #{currency}, 0, ISNULL(#{newProductAudited,jdbcType=VARCHAR}, 'N'));
  333. </update>
  334. <update id="updateDefaultSupplierByPartNo">
  335. UPDATE part
  336. SET default_supplier_no = #{targetSupplierNo},
  337. update_date = GETDATE()
  338. WHERE site = #{site}
  339. AND part_no = #{partNo}
  340. AND ISNULL(default_supplier_no, '') &lt;&gt; #{targetSupplierNo}
  341. </update>
  342. <update id="updateDefaultSupplierByBasePartNo">
  343. UPDATE part
  344. SET default_supplier_no = #{targetSupplierNo},
  345. update_date = GETDATE()
  346. WHERE site = #{site}
  347. AND (
  348. bast_part_no = #{basePartNo}
  349. OR part_no = #{basePartNo}
  350. OR part_no LIKE CONCAT(#{basePartNo}, '-%')
  351. )
  352. AND ISNULL(default_supplier_no, '') &lt;&gt; #{targetSupplierNo}
  353. </update>
  354. <update id="mergeSupplierForPartByBasePart">
  355. MERGE INTO SupplierforPart AS target
  356. USING (
  357. SELECT p.site,
  358. #{supplierNo} AS supplier_no,
  359. p.part_no,
  360. #{currency} AS currency
  361. FROM part p
  362. WHERE p.site = #{site}
  363. AND (
  364. p.bast_part_no = #{basePartNo}
  365. OR p.part_no = #{basePartNo}
  366. OR p.part_no LIKE CONCAT(#{basePartNo}, '-%')
  367. )
  368. AND ISNULL(p.default_supplier_no, '') = #{supplierNo}
  369. ) AS src
  370. ON target.site = src.site
  371. AND target.supplier_no = src.supplier_no
  372. AND target.part_no = src.part_no
  373. WHEN MATCHED THEN
  374. UPDATE SET
  375. active = 'Y',
  376. currency = src.currency,
  377. [minOrderQty] = ISNULL(target.[minOrderQty], 0)
  378. WHEN NOT MATCHED THEN
  379. INSERT (site, supplier_no, part_no, active, currency, [minOrderQty])
  380. VALUES (src.site, src.supplier_no, src.part_no, 'Y', src.currency, 0);
  381. </update>
  382. <update id="updatePartStageBySiteAndPartNo">
  383. UPDATE part
  384. SET part_stage = #{partStage},
  385. update_date = GETDATE()
  386. WHERE site = #{site}
  387. AND part_no = #{partNo}
  388. </update>
  389. </mapper>