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.

422 lines
18 KiB

1 week ago
1 week ago
1 week ago
1 month ago
1 week ago
1 week ago
2 weeks ago
2 weeks ago
2 weeks ago
1 week ago
1 week ago
1 week ago
2 weeks ago
1 week ago
1 week ago
2 weeks ago
1 week ago
1 week ago
1 week ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
1 month 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.inspection.mapper.InspectionRequestHeaderMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.xujie.modules.inspection.entity.InspectionRequestHeader">
  6. <id column="site" property="site" />
  7. <id column="request_no" property="requestNo" />
  8. <result column="request_date" property="requestDate" />
  9. <result column="need_inspect_date" property="needInspectDate" />
  10. <result column="supplier_no" property="supplierNo" />
  11. <result column="planner" property="planner" />
  12. <result column="create_by" property="createBy" />
  13. <result column="create_date" property="createDate" />
  14. <result column="inspect_address" property="inspectAddress" />
  15. <result column="inspect_contract" property="inspectContract" />
  16. <result column="remark" property="remark" />
  17. <result column="status" property="status" />
  18. <result column="status_db" property="statusDb" />
  19. <result column="qc_operator" property="qcOperator" />
  20. <result column="inspect_date" property="inspectDate" />
  21. <result column="plan_start_date" property="planStartDate" />
  22. <result column="plan_end_date" property="planEndDate" />
  23. <result column="scheduled_date" property="scheduledDate" />
  24. <result column="scheduled_by" property="scheduledBy" />
  25. <result column="schedule_remark" property="scheduleRemark" />
  26. <result column="supplier_name" property="supplierName" />
  27. </resultMap>
  28. <!-- 通用查询结果列 -->
  29. <sql id="BaseColumnList">
  30. h.site, h.request_no, h.request_date, h.need_inspect_date, h.supplier_no, ISNULL(dbo.plm_get_user_display(h.site, h.planner), h.planner) AS planner, h.create_by, h.create_date, h.inspect_address, h.inspect_contract, h.remark, h.status, h.status_db, h.qc_operator, h.inspect_date, h.plan_start_date, h.plan_end_date, h.scheduled_date, h.scheduled_by, h.schedule_remark, s.supplier_name
  31. </sql>
  32. <select id="myPage" resultType="com.xujie.modules.inspection.entity.InspectionRequestHeader">
  33. select
  34. <include refid="BaseColumnList"/>
  35. from srm_inspection_request_header h
  36. left join srm_supplier s on h.supplier_no = s.supplier_no and h.site = s.site
  37. <where>
  38. <if test="query.site != null and query.site != '' "> and h.site = #{query.site}</if>
  39. <if test="query.requestNo != null and query.requestNo != '' "> and h.request_no like '%${query.requestNo}%'</if>
  40. <if test="query.supplierNo != null and query.supplierNo != '' "> and h.supplier_no like '%${query.supplierNo}%'</if>
  41. <if test="query.supplierName != null and query.supplierName != '' "> and s.supplier_name like '%${query.supplierName}%'</if>
  42. <if test="query.planner != null and query.planner != '' ">
  43. and (h.planner like '%${query.planner}%'
  44. or ISNULL(dbo.plm_get_user_display(h.site, h.planner), '') like '%${query.planner}%')
  45. </if>
  46. <if test="query.status == 'NON_DRAFT'"> and h.status_db != 'Draft'</if>
  47. <if test="query.status != null and query.status != '' and query.status != 'NON_DRAFT' "> and h.status_db = #{query.status}</if>
  48. <if test="query.qcOperator != null and query.qcOperator != '' "> and h.qc_operator like '%${query.qcOperator}%'</if>
  49. <if test="query.createBy != null and query.createBy != '' "> and h.create_by like '%${query.createBy}%'</if>
  50. <if test="query.requestDateStart != null and query.requestDateStart != '' "> and h.request_date &gt;= #{query.requestDateStart}</if>
  51. <if test="query.requestDateEnd != null and query.requestDateEnd != '' "> and h.request_date &lt;= #{query.requestDateEnd}</if>
  52. <if test="query.needInspectDateStart != null and query.needInspectDateStart != '' "> and h.need_inspect_date &gt;= #{query.needInspectDateStart}</if>
  53. <if test="query.needInspectDateEnd != null and query.needInspectDateEnd != '' "> and h.need_inspect_date &lt;= #{query.needInspectDateEnd}</if>
  54. <if test="query.planStartDateStr != null and query.planStartDateStr != '' "> and h.plan_start_date &gt;= #{query.planStartDateStr}</if>
  55. <if test="query.planEndDateStr != null and query.planEndDateStr != '' "> and h.plan_end_date &lt;= #{query.planEndDateStr}</if>
  56. </where>
  57. order by h.request_no desc
  58. </select>
  59. <select id="queryPoPage" resultType="com.xujie.modules.inspection.data.InspectionRequestItemVO">
  60. SELECT
  61. pod.site,
  62. pod.order_no,
  63. pod.item_no,
  64. pod.part_no,
  65. pod.order_ref1,
  66. pod.order_ref2,
  67. pod.qty,
  68. pod.to_inspect_qty,
  69. p.item AS item,
  70. p.sku AS sku,
  71. p.part_desc AS partDesc,
  72. ISNULL(pod.to_inspect_qty,0)
  73. AS toInspectQty,
  74. (
  75. pod.qty - ISNULL(pod.to_inspect_qty,0)
  76. )
  77. AS waitInspectQty,
  78. ISNULL(pod.c_crd,pod.want_receive_date)
  79. AS crd,
  80. poh.ship_via AS shipMethod,
  81. poh.supplier_no,
  82. ss.supplier_name,
  83. ISNULL(dbo.plm_get_user_display(poh.site, poh.c_planner), poh.c_planner) AS planner
  84. FROM PODetail pod
  85. INNER JOIN POHeader poh
  86. ON poh.order_no = pod.order_no
  87. AND poh.site = pod.site
  88. LEFT JOIN srm_supplier ss
  89. ON ss.site = pod.site
  90. AND ss.supplier_no = poh.supplier_no
  91. LEFT JOIN part p
  92. ON pod.part_no = p.part_no
  93. AND pod.site = p.site
  94. WHERE pod.site = #{query.site}
  95. AND ISNULL(poh.status, '') NOT IN ('Draft','Shipped','Closed','Cancelled','草稿','已发货','已关闭','已取消')
  96. AND (
  97. pod.qty - ISNULL(pod.to_inspect_qty,0)
  98. ) > 0
  99. <if test="query.supplierNo != null and query.supplierNo != ''">
  100. AND poh.supplier_no = #{query.supplierNo}
  101. </if>
  102. <if test="query.orderNo != null and query.orderNo != ''">
  103. AND (
  104. pod.order_ref1 like concat('%',#{query.orderNo},'%')
  105. OR pod.order_no like concat('%',#{query.orderNo},'%')
  106. )
  107. </if>
  108. <if test="query.partNo != null and query.partNo != ''">
  109. AND pod.part_no like concat('%',#{query.partNo},'%')
  110. </if>
  111. <if test="query.item != null and query.item != ''">
  112. AND p.item like concat('%',#{query.item},'%')
  113. </if>
  114. <if test="query.sku != null and query.sku != ''">
  115. AND p.sku like concat('%',#{query.sku},'%')
  116. </if>
  117. <if test="query.partDesc != null and query.partDesc != ''">
  118. AND p.part_desc like concat('%',#{query.partDesc},'%')
  119. </if>
  120. <if test="query.supplierName != null and query.supplierName != ''">
  121. AND ss.supplier_name like concat('%',#{query.supplierName},'%')
  122. </if>
  123. <if test="query.planner != null and query.planner != ''">
  124. AND (
  125. ISNULL(poh.c_planner, '') like concat('%',#{query.planner},'%')
  126. OR ISNULL(dbo.plm_get_user_display(poh.site, poh.c_planner), '') like concat('%',#{query.planner},'%')
  127. )
  128. </if>
  129. ORDER BY pod.id DESC
  130. </select>
  131. <select id="queryPoSupplierOrderPage" resultType="com.xujie.modules.inspection.data.InspectionRequestItemVO">
  132. SELECT
  133. pod.site,
  134. pod.order_no,
  135. pod.item_no,
  136. pod.part_no,
  137. pod.order_ref1,
  138. pod.order_ref2,
  139. pod.qty,
  140. pod.to_inspect_qty,
  141. p.item AS item,
  142. p.sku AS sku,
  143. p.part_desc AS partDesc,
  144. ISNULL(pod.to_inspect_qty,0)
  145. AS toInspectQty,
  146. (
  147. pod.qty - ISNULL(pod.to_inspect_qty,0)
  148. )
  149. AS waitInspectQty,
  150. ISNULL(pod.c_crd,pod.want_receive_date)
  151. AS crd,
  152. poh.ship_via AS shipMethod,
  153. poh.supplier_no AS supplierNo,
  154. ss.supplier_name AS supplierName,
  155. ISNULL(dbo.plm_get_user_display(poh.site, poh.c_planner), poh.c_planner) AS planner
  156. FROM PODetail pod
  157. INNER JOIN POHeader poh
  158. ON poh.order_no = pod.order_no
  159. AND poh.site = pod.site
  160. LEFT JOIN srm_supplier ss
  161. ON ss.site = pod.site
  162. AND ss.supplier_no = poh.supplier_no
  163. LEFT JOIN part p
  164. ON pod.part_no = p.part_no
  165. AND pod.site = p.site
  166. WHERE pod.site = #{query.site}
  167. AND ISNULL(poh.status, '') NOT IN ('Draft','Shipped','Closed','Cancelled','草稿','已发货','已关闭','已取消')
  168. AND (
  169. pod.qty - ISNULL(pod.to_inspect_qty,0)
  170. ) > 0
  171. <if test="query.supplierNo != null and query.supplierNo != ''">
  172. AND poh.supplier_no = #{query.supplierNo}
  173. </if>
  174. <if test="query.orderNo != null and query.orderNo != ''">
  175. AND (
  176. pod.order_ref1 like concat('%',#{query.orderNo},'%')
  177. OR pod.order_no like concat('%',#{query.orderNo},'%')
  178. )
  179. </if>
  180. <if test="query.partNo != null and query.partNo != ''">
  181. AND pod.part_no like concat('%',#{query.partNo},'%')
  182. </if>
  183. <if test="query.item != null and query.item != ''">
  184. AND p.item like concat('%',#{query.item},'%')
  185. </if>
  186. <if test="query.sku != null and query.sku != ''">
  187. AND p.sku like concat('%',#{query.sku},'%')
  188. </if>
  189. <if test="query.partDesc != null and query.partDesc != ''">
  190. AND p.part_desc like concat('%',#{query.partDesc},'%')
  191. </if>
  192. <if test="query.supplierName != null and query.supplierName != ''">
  193. AND ss.supplier_name like concat('%',#{query.supplierName},'%')
  194. </if>
  195. <if test="query.planner != null and query.planner != ''">
  196. AND (
  197. ISNULL(poh.c_planner, '') like concat('%',#{query.planner},'%')
  198. OR ISNULL(dbo.plm_get_user_display(poh.site, poh.c_planner), '') like concat('%',#{query.planner},'%')
  199. )
  200. </if>
  201. ORDER BY ISNULL(pod.c_crd,pod.want_receive_date) DESC, pod.id DESC
  202. </select>
  203. <select id="queryPoSupplierPage" resultType="com.xujie.modules.inspection.data.InspectionRequestItemVO">
  204. SELECT
  205. poh.supplier_no AS supplierNo,
  206. ss.supplier_name AS supplierName,
  207. COUNT(1) AS poDetailCount
  208. FROM PODetail pod
  209. INNER JOIN POHeader poh
  210. ON poh.order_no = pod.order_no
  211. AND poh.site = pod.site
  212. LEFT JOIN srm_supplier ss
  213. ON ss.site = pod.site
  214. AND ss.supplier_no = poh.supplier_no
  215. WHERE pod.site = #{query.site}
  216. AND ISNULL(poh.status, '') NOT IN ('Draft','Shipped','Closed','Cancelled','草稿','已发货','已关闭','已取消')
  217. AND (
  218. pod.qty - ISNULL(pod.to_inspect_qty,0)
  219. ) > 0
  220. <if test="query.supplierNo != null and query.supplierNo != ''">
  221. AND poh.supplier_no like concat('%',#{query.supplierNo},'%')
  222. </if>
  223. <if test="query.supplierName != null and query.supplierName != ''">
  224. AND ss.supplier_name like concat('%',#{query.supplierName},'%')
  225. </if>
  226. GROUP BY poh.supplier_no, ss.supplier_name
  227. ORDER BY COUNT(1) DESC, poh.supplier_no ASC
  228. </select>
  229. <update id="cancel">
  230. UPDATE srm_inspection_request_header
  231. SET status = '已取消',
  232. status_db = 'Cancelled'
  233. WHERE site = #{site}
  234. AND request_no = #{requestNo}
  235. </update>
  236. <select id="selectByRequestNo" resultType="com.xujie.modules.inspection.entity.InspectionRequestHeader">
  237. SELECT <include refid="BaseColumnList"/>
  238. FROM srm_inspection_request_header h
  239. LEFT JOIN srm_supplier s ON h.supplier_no = s.supplier_no AND h.site = s.site
  240. WHERE h.site = #{site}
  241. AND h.request_no = #{requestNo}
  242. </select>
  243. <select id="getQcPersonList" resultType="com.xujie.modules.inspection.entity.QcPersonList">
  244. SELECT DISTINCT
  245. a.username AS userName,
  246. a.user_display AS userDisplay
  247. FROM sys_user a
  248. INNER JOIN access_role ar
  249. ON ar.username = a.username
  250. AND ar.site = #{qc.site}
  251. AND ar.role_no = 'QC'
  252. INNER JOIN business_role br
  253. ON br.site = ar.site
  254. AND br.role_no = ar.role_no
  255. AND ISNULL(br.active, 'Y') = 'Y'
  256. <where>
  257. a.status = 1
  258. <if test="qc.userName != null and qc.userName != ''">
  259. AND a.username LIKE CONCAT('%', #{qc.userName}, '%')
  260. </if>
  261. <if test="qc.userDisplay != null and qc.userDisplay != ''">
  262. AND a.user_display LIKE CONCAT('%', #{qc.userDisplay}, '%')
  263. </if>
  264. </where>
  265. ORDER BY a.username
  266. </select>
  267. <delete id="deleteByRequestNo">
  268. DELETE FROM srm_inspection_request_header
  269. WHERE site = #{site}
  270. AND request_no = #{requestNo}
  271. </delete>
  272. <update id="confirm">
  273. UPDATE srm_inspection_request_header
  274. SET status = '待审核',
  275. status_db = 'Confirmed'
  276. WHERE site = #{site}
  277. AND request_no = #{requestNo}
  278. </update>
  279. <update id="audit">
  280. UPDATE srm_inspection_request_header
  281. SET status = '已下达',
  282. status_db = 'Audited'
  283. WHERE site = #{site}
  284. AND request_no = #{requestNo}
  285. </update>
  286. <update id="batchSchedule">
  287. UPDATE srm_inspection_request_header
  288. SET
  289. qc_operator = #{qcOperator},
  290. plan_start_date = #{planStartDate},
  291. plan_end_date = #{planEndDate},
  292. scheduled_date = #{scheduledDate},
  293. scheduled_by = #{scheduledBy},
  294. schedule_remark = #{remark},
  295. status = '已排程',
  296. status_db = 'Scheduled'
  297. WHERE site = #{site}
  298. AND request_no IN
  299. <foreach collection="requestNos"
  300. item="item"
  301. open="("
  302. separator=","
  303. close=")">
  304. #{item}
  305. </foreach>
  306. </update>
  307. <select id="queryScheduleView"
  308. resultType="com.xujie.modules.inspection.data.InspectionScheduleViewVO">
  309. SELECT
  310. h.request_no AS requestNo,
  311. s.supplier_name AS supplierName,
  312. d.poNo AS poNo,
  313. h.inspect_address AS inspectAddress,
  314. h.plan_start_date AS planStartDate,
  315. h.plan_end_date AS planEndDate
  316. FROM srm_inspection_request_header h
  317. LEFT JOIN srm_supplier s
  318. ON h.supplier_no = s.supplier_no
  319. AND h.site = s.site
  320. LEFT JOIN (
  321. SELECT
  322. site,
  323. request_no,
  324. MIN(order_ref1) AS poNo
  325. FROM srm_inspect_request_detail
  326. GROUP BY site, request_no
  327. ) d
  328. ON d.site = h.site
  329. AND d.request_no = h.request_no
  330. WHERE h.site = #{site}
  331. AND h.qc_operator = #{qcOperator}
  332. AND h.status_db = 'Scheduled'
  333. AND h.plan_start_date IS NOT NULL
  334. AND h.plan_end_date IS NOT NULL
  335. AND CAST(h.plan_end_date AS DATE) >= CAST(#{startDate} AS DATE)
  336. AND CAST(#{endDate} AS DATE) >= CAST(h.plan_start_date AS DATE)
  337. ORDER BY h.plan_start_date ASC
  338. </select>
  339. <!-- 开始验货 - 更新头表状态 -->
  340. <update id="startInspection">
  341. UPDATE srm_inspection_request_header
  342. SET status = '验货中',
  343. status_db = 'Inspecting'
  344. WHERE site = #{site}
  345. AND request_no = #{requestNo}
  346. </update>
  347. <select id="getInspectionDetail" resultType="com.xujie.modules.inspection.data.MyInspectionListVO">
  348. SELECT
  349. d.site,
  350. d.request_no AS requestNo,
  351. d.item_no AS itemNo,
  352. d.part_no AS partNo,
  353. d.qty,
  354. d.approve_qty AS approveQty,
  355. p.item AS item,
  356. p.sku AS sku,
  357. p.part_desc AS partDesc,
  358. h.supplier_no AS supplierNo
  359. FROM srm_inspect_request_detail d
  360. left join srm_inspection_request_header h
  361. ON d.request_no = h.request_no
  362. AND d.site = h.site
  363. left join part p
  364. on p.part_no = d.part_no
  365. and p.site = d.site
  366. WHERE d.site = #{site}
  367. AND d.request_no = #{requestNo}
  368. AND d.item_no = #{itemNo}
  369. </select>
  370. <update id="updateInspectNo">
  371. UPDATE srm_inspect_request_detail
  372. SET inspect_no = #{inspectNo}
  373. WHERE site = #{site}
  374. AND request_no = #{requestNo}
  375. AND item_no = #{itemNo}
  376. </update>
  377. <!-- 刷新验货结果 - 更新头表状态为验货完成 -->
  378. <update id="refreshHeaderToCompleted">
  379. UPDATE srm_inspection_request_header
  380. SET status = '验货完成',
  381. status_db = 'InspectionCompleted',
  382. inspect_date = GETDATE()
  383. WHERE site = #{site}
  384. AND request_no = #{requestNo}
  385. </update>
  386. <!-- 回滚验货结果 - 更新头表状态为验货中 -->
  387. <update id="rollbackHeaderToInspecting">
  388. UPDATE srm_inspection_request_header
  389. SET status = '验货中',
  390. status_db = 'Inspecting'
  391. WHERE site = #{site}
  392. AND request_no = #{requestNo}
  393. </update>
  394. <!-- 回滚头表状态为已排程(当所有明细都回滚为已排程时调用) -->
  395. <update id="rollbackHeaderToScheduled">
  396. UPDATE srm_inspection_request_header
  397. SET status = '已排程',
  398. status_db = 'Scheduled'
  399. WHERE site = #{site}
  400. AND request_no = #{requestNo}
  401. </update>
  402. </mapper>