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.

1700 lines
79 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 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.gaotao.modules.pms.mapper.QcBaseInfoMapper">
  4. <!-- ================================================= 检验方法 ================================================= -->
  5. <!-- 条件查询检验方法 -->
  6. <select id="qcMethodSearch" parameterType="com.gaotao.modules.pms.data.QcMethodData" resultType="com.gaotao.modules.pms.data.QcMethodData">
  7. SELECT
  8. qm.site,
  9. qm.bu_no,
  10. dbo.get_bu_desc(qm.site, qm.bu_no) as buDesc,
  11. qm.method_no,
  12. qm.method_name,
  13. qm.create_date,
  14. qm.create_by,
  15. dbo.getOperatorDesc(qm.site, qm.create_by) as createByDesc,
  16. qm.method_remark,
  17. qm.update_date,
  18. qm.update_by,
  19. dbo.getOperatorDesc(qm.site, qm.update_by) as updateByDesc,
  20. qm.inspection_type_no,
  21. qit.inspection_type_name
  22. FROM qc_method as qm
  23. LEFT JOIN qc_inspection_type as qit on qm.site = qit.site and qm.inspection_type_no = qit.inspection_type_no
  24. <where>
  25. qm.site in (select site from AccessSite where userID = #{query.userName})
  26. and qm.bu_no in (select bu_no from AccessBu where username = #{query.userName})
  27. <if test="query.buDesc != null and query.buDesc != ''">
  28. AND dbo.get_bu_desc ( qm.site, qm.bu_no ) = #{query.buDesc}
  29. </if>
  30. <if test="query.methodNo != null and query.methodNo != ''">
  31. AND qm.method_no LIKE '%' + #{query.methodNo} +'%'
  32. </if>
  33. <if test="query.methodName != null and query.methodName != ''">
  34. AND qm.method_name LIKE '%' + #{query.methodName} +'%'
  35. </if>
  36. <if test="query.inspectionTypeNo != null and query.inspectionTypeNo != ''">
  37. AND qm.inspection_type_no = #{query.inspectionTypeNo}
  38. </if>
  39. </where>
  40. </select>
  41. <!-- 获得检验方法单号 -->
  42. <select id="getMethodNo" resultType="string" parameterType="com.gaotao.modules.pms.data.QcMethodData">
  43. SELECT
  44. Right('0000' + convert(varchar(10),isnull(max(convert(INT,Right(method_no,4))),0)+1),4)
  45. FROM qc_method
  46. WHERE site = #{site} AND inspection_type_no = #{inspectionTypeNo} and bu_no = #{buNo}
  47. </select>
  48. <!-- 新增检验方法 -->
  49. <insert id="qcMethodSave" parameterType="com.gaotao.modules.pms.data.QcMethodData">
  50. INSERT INTO qc_method (site, bu_no, method_no, method_name, create_date, create_by, method_remark, update_date, update_by, inspection_type_no)
  51. VALUES (#{site}, #{buNo}, #{methodNo}, #{methodName}, GetDate(), #{createBy}, #{methodRemark}, getDate(), #{updateBy}, #{inspectionTypeNo})
  52. </insert>
  53. <!-- 修改检验方法 -->
  54. <update id="qcMethodUpdate" parameterType="com.gaotao.modules.pms.data.QcMethodData">
  55. UPDATE qc_method
  56. SET method_name = #{methodName},
  57. method_remark = #{methodRemark},
  58. update_date = getDate(),
  59. update_by = #{updateBy},
  60. inspection_type_no = #{inspectionTypeNo}
  61. WHERE site = #{site} and method_no = #{methodNo} and bu_no = #{buNo}
  62. </update>
  63. <!-- 检查方法是否在被项目使用 -->
  64. <select id="checkMethodIsUsed" parameterType="com.gaotao.modules.pms.data.QcMethodData" resultType="com.gaotao.modules.pms.data.EamPropertiesItemData">
  65. SELECT
  66. ItemNo
  67. FROM qc_method_item
  68. WHERE site = #{site} and method_no = #{methodNo} and bu_no = #{buNo}
  69. </select>
  70. <!-- 删除检验方法 -->
  71. <delete id="qcMethodDelete" parameterType="com.gaotao.modules.pms.data.QcMethodData">
  72. DELETE FROM qc_method
  73. WHERE site = #{site} and method_no = #{methodNo} and bu_no = #{buNo}
  74. </delete>
  75. <!-- 查询检验方法唯一 -->
  76. <select id="checkMethodOnlyOne" resultType="com.gaotao.modules.pms.data.QcMethodData" parameterType="com.gaotao.modules.pms.data.QcMethodData">
  77. SELECT
  78. site,
  79. bu_no,
  80. method_no
  81. FROM qc_method
  82. <where>
  83. site = #{site} and bu_no = #{buNo} and method_no = #{methodNo}
  84. </where>
  85. </select>
  86. <!-- ================================================= 检验项目 ================================================= -->
  87. <!-- 根据条件查询检验项目 -->
  88. <select id="qcItemSearch" parameterType="com.gaotao.modules.pms.data.QcItemData" resultType="com.gaotao.modules.pms.data.QcItemData">
  89. SELECT
  90. epi.site,
  91. epi.bu_no,
  92. dbo.get_bu_desc(epi.site, epi.bu_no) as buDesc,
  93. epi.ItemNo,
  94. epi.ItemDesc,
  95. epi.DefaultValue,
  96. epi.ValueType,
  97. epi.ValueType_DB as valueTypeDb,
  98. epi.ValueChooseFlag,
  99. epi.CreatedDate,
  100. epi.CreatedBy,
  101. dbo.getOperatorDesc(epi.site, epi.CreatedBy) as createdByDesc,
  102. epi.MaxValue,
  103. epi.MinValue,
  104. epi.ItemRemark,
  105. epi.ItemType,
  106. epi.update_date,
  107. epi.update_by,
  108. dbo.getOperatorDesc(epi.site, epi.update_by) as updateByDesc,
  109. qm.method_no,
  110. qm.method_name,
  111. qm.method_remark,
  112. epi.inspection_type_no,
  113. qit.inspection_type_name,
  114. epi.item_sampling_quantity,
  115. epi.sampling_programme_no,
  116. qsip.sampling_programme_desc,
  117. epi.sampling_level_no,
  118. qsil.sampling_level_desc,
  119. epi.default_sampling_proportion,
  120. epi.collection_flag,
  121. epi.collection_source,
  122. epi.collection_method,
  123. CASE WHEN epi.collection_method = 'plc' THEN 'PLC'
  124. WHEN epi.collection_method = 'file' THEN '文件'
  125. WHEN epi.collection_method = 'image' THEN '图片'
  126. else '' end as collectionMethodDesc,
  127. epi.collection_condition,
  128. epi.collection_data_content
  129. FROM eam_properties_item as epi
  130. LEFT JOIN qc_method_item as qmi on epi.ItemNo = qmi.ItemNo and epi.site = qmi.site and epi.bu_no = qmi.bu_no
  131. LEFT JOIN qc_method as qm on qmi.method_no = qm.method_no and qmi.site = qm.site and qmi.bu_no = qm.bu_no
  132. LEFT JOIN qc_inspection_type as qit on qit.inspection_type_no = epi.inspection_type_no and qit.site = epi.site
  133. left join qc_sampling_inspection_programme as qsip on qsip.site = epi.site and qsip.sampling_programme_no = epi.sampling_programme_no and qsip.bu_no = epi.bu_no
  134. left join qc_sampling_inspection_level as qsil on qsil.site = epi.site and qsil.sampling_level_no = epi.sampling_level_no and qsil.bu_no = epi.bu_no
  135. <where>
  136. epi.site in (select site from AccessSite where userID = #{query.userName})
  137. and epi.bu_no in (select bu_no from AccessBu where username = #{query.userName})
  138. and epi.ItemType = #{query.itemType}
  139. <if test="query.buDesc != null and query.buDesc != ''">
  140. AND dbo.get_bu_desc ( epi.site, epi.bu_no ) = #{query.buDesc}
  141. </if>
  142. <if test="query.itemDesc != null and query.itemDesc != ''">
  143. AND epi.ItemDesc LIKE '%' + #{query.itemDesc} +'%'
  144. </if>
  145. <if test="query.itemNo != null and query.itemNo != ''">
  146. AND epi.ItemNo LIKE '%' + #{query.itemNo} +'%'
  147. </if>
  148. <if test="query.inspectionTypeNo != null and query.inspectionTypeNo != ''">
  149. AND epi.inspection_type_no = #{query.inspectionTypeNo}
  150. </if>
  151. </where>
  152. </select>
  153. <!-- 检测是否存在该项目 -->
  154. <select id="checkQcItem" parameterType="com.gaotao.modules.pms.data.QcItemData" resultType="com.gaotao.modules.pms.data.QcItemData">
  155. SELECT ItemNo,
  156. ItemDesc
  157. FROM eam_properties_item
  158. WHERE site = #{site} and ItemNo = #{itemNo} and ItemType = #{itemType}
  159. </select>
  160. <!-- 获得检验项目单号 -->
  161. <select id="getItemNo" resultType="string" parameterType="com.gaotao.modules.pms.data.QcItemData">
  162. SELECT
  163. Right('0000' + convert(varchar(10),isnull(max(convert(INT,Right(ItemNo,4))),0)+1),4)
  164. FROM eam_properties_item
  165. WHERE site = #{site} and ItemType = 'D' and inspection_type_no = #{inspectionTypeNo} and bu_no = #{buNo}
  166. </select>
  167. <!-- 新增检验项目 -->
  168. <insert id="qcItemSave" parameterType="com.gaotao.modules.pms.data.QcItemData">
  169. INSERT INTO eam_properties_item (site, bu_no, ItemNo, ItemDesc, DefaultValue, ValueType, ValueType_DB, ValueChooseFlag, CreatedDate, CreatedBy, MaxValue, MinValue, ItemRemark, ItemType, update_date, update_by, inspection_type_no, item_sampling_quantity, sampling_programme_no, sampling_level_no, default_sampling_proportion, collection_flag, collection_source, collection_method, collection_condition, collection_data_content)
  170. VALUES (#{site}, #{buNo}, #{itemNo}, #{itemDesc}, #{defaultValue}, #{valueType}, #{valueTypeDb}, #{valueChooseFlag}, GetDate(), #{createdBy}, #{maxValue,jdbcType=DECIMAL}, #{minValue,jdbcType=DECIMAL}, #{itemRemark}, #{itemType}, getDate(), #{updateBy}, #{inspectionTypeNo}, #{itemSamplingQuantity}, #{samplingProgrammeNo}, #{samplingLevelNo}, #{defaultSamplingProportion}, #{collectionFlag}, #{collectionSource}, #{collectionMethod}, #{collectionCondition}, #{collectionDataContent})
  171. </insert>
  172. <!-- 新增项目里的方法 -->
  173. <insert id="qcItemMethodSave" parameterType="com.gaotao.modules.pms.data.QcItemData">
  174. INSERT INTO qc_method_item (ItemNo, method_no, site, bu_no)
  175. VALUES (#{itemNo}, #{methodNo}, #{site}, #{buNo})
  176. </insert>
  177. <!-- 修改检验项目 -->
  178. <update id="qcItemUpdate" parameterType="com.gaotao.modules.pms.data.QcItemData">
  179. UPDATE eam_properties_item
  180. SET ItemDesc = #{itemDesc},
  181. DefaultValue = #{defaultValue},
  182. ValueType = #{valueType},
  183. ValueType_DB = #{valueTypeDb},
  184. ValueChooseFlag = #{valueChooseFlag},
  185. MaxValue = #{maxValue,jdbcType=DECIMAL},
  186. MinValue = #{minValue,jdbcType=DECIMAL},
  187. ItemRemark = #{itemRemark},
  188. update_date = getDate(),
  189. update_by = #{updateBy},
  190. inspection_type_no = #{inspectionTypeNo},
  191. item_sampling_quantity = #{itemSamplingQuantity},
  192. sampling_programme_no = #{samplingProgrammeNo},
  193. sampling_level_no = #{samplingLevelNo},
  194. default_sampling_proportion = #{defaultSamplingProportion},
  195. collection_flag = #{collectionFlag},
  196. collection_source = #{collectionSource},
  197. collection_method = #{collectionMethod},
  198. collection_condition = #{collectionCondition},
  199. collection_data_content = #{collectionDataContent}
  200. WHERE site = #{site} and ItemNo = #{itemNo} and ItemType = #{itemType} and bu_no = #{buNo}
  201. </update>
  202. <!-- 修改项目中的方法 -->
  203. <update id="qcItemMethodUpdate" parameterType="com.gaotao.modules.pms.data.QcItemData">
  204. UPDATE qc_method_item
  205. SET method_no = #{methodNo}
  206. WHERE site = #{site} and ItemNo = #{itemNo} and bu_no = #{buNo}
  207. </update>
  208. <!-- 检查项目是否在被模板使用 -->
  209. <select id="checkItemIsUsed" parameterType="com.gaotao.modules.pms.data.QcItemData" resultType="EamPropertiesModelDetailData">
  210. SELECT template_id
  211. FROM qc_template_detailed
  212. WHERE site = #{site} and ItemNo = #{itemNo} and bu_no = #{buNo}
  213. </select>
  214. <!-- 删除检验项目 -->
  215. <delete id="qcItemDelete" parameterType="com.gaotao.modules.pms.data.QcItemData">
  216. DELETE
  217. FROM eam_properties_item
  218. WHERE site = #{site} and ItemNo = #{itemNo} and ItemType = #{itemType} and bu_no = #{buNo}
  219. </delete>
  220. <!-- 删除项目-方法中间表数据 -->
  221. <delete id="qcItemMethodDelete" parameterType="com.gaotao.modules.pms.data.QcItemData">
  222. DELETE
  223. FROM qc_method_item
  224. WHERE site = #{site} and ItemNo = #{itemNo} and bu_no = #{buNo}
  225. </delete>
  226. <!-- 查询检验项目唯一 -->
  227. <select id="checkItemOnlyOne" resultType="com.gaotao.modules.pms.data.QcItemData" parameterType="com.gaotao.modules.pms.data.QcItemData">
  228. SELECT
  229. site,
  230. bu_no,
  231. ItemNo,
  232. ItemDesc
  233. FROM eam_properties_item
  234. <where>
  235. site = #{site} and bu_no = #{buNo} and ItemNo = #{itemNo} and ItemType = #{itemType} and inspection_type_no = #{inspectionTypeNo}
  236. </where>
  237. </select>
  238. <!-- 可选模板 -->
  239. <select id="getTemplateList" resultType="com.gaotao.modules.pms.data.QcTemplateData" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  240. SELECT
  241. qt.template_id,
  242. qt.template_name,
  243. qit.inspection_type_name
  244. FROM qc_template as qt
  245. LEFT JOIN qc_attribute_template as qat ON qat.template_id = qt.template_id and qat.attribute_no = #{attributeNo}
  246. LEFT JOIN qc_inspection_type AS qit ON qt.inspection_type_no = qit.inspection_type_no
  247. <where>
  248. qt.site = #{site}
  249. AND qat.attribute_no is null
  250. <if test = "inspectionTypeNo != null and inspectionTypeNo != ''">
  251. AND qt.inspection_type_no = #{inspectionTypeNo}
  252. </if>
  253. <if test = "templateId != null and templateId != ''">
  254. AND qt.template_id LIKE '%' + #{templateId}+'%'
  255. </if>
  256. <if test = "templateName != null and templateName != ''">
  257. AND qt.template_name LIKE '%' + #{templateName}+'%'
  258. </if>
  259. </where>
  260. </select>
  261. <!-- 已有模板 -->
  262. <select id="getPartTemplateList" resultType="com.gaotao.modules.pms.data.QcTemplateData" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  263. SELECT
  264. qt.template_id,
  265. qt.template_name,
  266. qit.inspection_type_name,
  267. qat.operation,
  268. qat.manufacturer_id,
  269. dbo.qc_get_supplier_name(qt.site, qat.manufacturer_id) as manufacturerName,
  270. qat.resource_id,
  271. qat.customer_id as customerID,
  272. dbo.qc_get_customer_name(qt.site, qat.customer_id) as customerName
  273. FROM qc_attribute_template as qat
  274. LEFT JOIN qc_template as qt ON qat.template_id = qt.template_id and qat.site = qt.site and qat.bu_no = qt.bu_no
  275. LEFT JOIN qc_inspection_type AS qit ON qt.inspection_type_no = qit.inspection_type_no and qt.site = qit.site
  276. WHERE qt.site = #{site} AND qat.attribute_no = #{attributeNo} and qt.bu_no = #{buNo}
  277. </select>
  278. <!-- 物料可选模板 -->
  279. <select id="getTemplateListAll" resultType="com.gaotao.modules.pms.data.QcTemplateData" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  280. SELECT
  281. qt.template_id,
  282. qt.template_name,
  283. qit.inspection_type_name
  284. FROM qc_template as qt
  285. LEFT JOIN qc_inspection_type AS qit ON qt.inspection_type_no = qit.inspection_type_no and qt.site = qit.site
  286. <where>
  287. qt.site = #{site} and qt.bu_no = #{buNo}
  288. <if test = "inspectionTypeNo != null and inspectionTypeNo != ''">
  289. AND qt.inspection_type_no = #{inspectionTypeNo}
  290. </if>
  291. <if test = "templateId != null and templateId != ''">
  292. AND qt.template_id LIKE '%' + #{templateId}+'%'
  293. </if>
  294. <if test = "templateName != null and templateName != ''">
  295. AND qt.template_name LIKE '%' + #{templateName}+'%'
  296. </if>
  297. </where>
  298. </select>
  299. <!-- ================================================= 抽样矩阵维护 ================================================= -->
  300. <!-- 查询抽样矩阵 -->
  301. <select id="samplingInspectionPlanSearch" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData">
  302. SELECT
  303. qsip.site,
  304. qsip.bu_no,
  305. dbo.get_bu_desc(qsip.site, qsip.bu_no) as buDesc,
  306. qsip.sampling_plan_no,
  307. qsip.sampling_plan_desc,
  308. qsip.sampling_qty_no,
  309. qsiq.sampling_qty,
  310. qsiq.sampling_qty_desc,
  311. qsip.sampling_qty_rank_no,
  312. qsiqr.sampling_qty_rank_desc,
  313. qsiqr.min_qty,
  314. qsiqr.max_qty,
  315. qsip.sampling_level_no,
  316. qsil.sampling_level_desc,
  317. qsip.sampling_plan_active,
  318. case when qsip.sampling_plan_active = 'Y' then '是' when qsip.sampling_plan_active = 'N' then '否' else '' end as samplingPlanActiveDesc,
  319. qsip.create_date,
  320. qsip.create_by,
  321. dbo.getOperatorDesc(qsip.site, qsip.create_by) as createByDesc,
  322. qsip.update_date,
  323. qsip.update_by,
  324. dbo.getOperatorDesc(qsip.site, qsip.update_by) as updateByDesc
  325. FROM qc_sampling_inspection_plan as qsip
  326. LEFT JOIN qc_sampling_inspection_qty as qsiq ON qsip.sampling_qty_no = qsiq.sampling_qty_no and qsip.site = qsiq.site and qsip.bu_no = qsiq.bu_no
  327. LEFT JOIN qc_sampling_inspection_qty_rank as qsiqr ON qsip.sampling_qty_rank_no = qsiqr.sampling_qty_rank_no and qsip.site = qsiqr.site and qsip.bu_no = qsiqr.bu_no
  328. LEFT JOIN qc_sampling_inspection_level as qsil ON qsip.sampling_level_no = qsil.sampling_level_no and qsip.site = qsil.site and qsip.bu_no = qsil.bu_no
  329. <where>
  330. qsip.site in (select site from AccessSite where userID = #{query.userName})
  331. and qsip.bu_no in (select bu_no from AccessBu where username = #{query.userName})
  332. <if test="query.buDesc != null and query.buDesc != ''">
  333. AND dbo.get_bu_desc ( qsip.site, qsip.bu_no ) = #{query.buDesc}
  334. </if>
  335. <if test="query.samplingQtyDesc != null and query.samplingQtyDesc != ''">
  336. AND qsiq.sampling_qty_desc LIKE '%' + #{query.samplingQtyDesc}+'%'
  337. </if>
  338. <if test="query.samplingLevelDesc != null and query.samplingLevelDesc != ''">
  339. AND qsil.sampling_level_desc LIKE '%' + #{query.samplingLevelDesc}+'%'
  340. </if>
  341. <if test="query.samplingPlanActive != null and query.samplingPlanActive != ''">
  342. AND qsip.sampling_plan_active = #{query.samplingPlanActive}
  343. </if>
  344. </where>
  345. </select>
  346. <!-- 根据三个编码查矩阵 -->
  347. <select id="selectSamplingPlanByNo" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData">
  348. SELECT
  349. site,
  350. bu_no,
  351. sampling_plan_no,
  352. sampling_qty_no,
  353. sampling_qty_rank_no,
  354. sampling_level_no,
  355. sampling_plan_active
  356. FROM qc_sampling_inspection_plan
  357. WHERE sampling_qty_no = #{samplingQtyNo} AND sampling_qty_rank_no = #{samplingQtyRankNo} AND sampling_level_no = #{samplingLevelNo} AND site = #{site} and bu_no = #{buNo}
  358. </select>
  359. <!-- 根据名称查矩阵 -->
  360. <select id="selectSamplingPlanByDesc" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData">
  361. SELECT
  362. site,
  363. bu_no,
  364. sampling_plan_no,
  365. sampling_qty_no,
  366. sampling_qty_rank_no,
  367. sampling_level_no,
  368. sampling_plan_active
  369. FROM qc_sampling_inspection_plan
  370. WHERE sampling_plan_desc = #{samplingPlanDesc} AND site = #{site} and bu_no = #{buNo}
  371. </select>
  372. <!-- 获取最大方矩阵编码 -->
  373. <select id="queryLastSamplingPlanNo" resultType="string" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData">
  374. SELECT top 1 sampling_plan_no
  375. FROM qc_sampling_inspection_plan
  376. where site = #{site} and bu_no = #{buNo}
  377. ORDER BY sampling_plan_no Desc
  378. </select>
  379. <!-- 新增抽样矩阵 -->
  380. <insert id="samplingInspectionPlanSave" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData">
  381. INSERT INTO qc_sampling_inspection_plan (site, bu_no, sampling_plan_no, sampling_plan_desc, sampling_qty_rank_no, sampling_level_no, sampling_qty_no, sampling_plan_active, create_date, create_by, update_date, update_by)
  382. VALUES (#{site}, #{buNo}, #{samplingPlanNo}, #{samplingPlanDesc}, #{samplingQtyRankNo}, #{samplingLevelNo}, #{samplingQtyNo}, #{samplingPlanActive}, getDate(), #{createBy}, getDate(), #{updateBy})
  383. </insert>
  384. <!-- 修改抽样矩阵 -->
  385. <update id="samplingInspectionPlanUpdate" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData">
  386. UPDATE qc_sampling_inspection_plan
  387. SET sampling_qty_rank_no = #{samplingQtyRankNo},
  388. sampling_level_no = #{samplingLevelNo},
  389. sampling_qty_no = #{samplingQtyNo},
  390. sampling_plan_active = #{samplingPlanActive},
  391. update_date = getDate(),
  392. update_by = #{updateBy}
  393. WHERE sampling_plan_no = #{samplingPlanNo} AND site = #{site} and bu_no = #{buNo}
  394. </update>
  395. <!-- 删除抽样矩阵 -->
  396. <delete id="samplingInspectionPlanDelete" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData">
  397. DELETE FROM qc_sampling_inspection_plan
  398. WHERE sampling_plan_no = #{samplingPlanNo} AND site = #{site} and bu_no = #{buNo}
  399. </delete>
  400. <!-- ================================================= 检验模板维护 ================================================= -->
  401. <!-- 查询模板 -->
  402. <select id="templateSearch" parameterType="com.gaotao.modules.pms.data.QcTemplateData" resultType="com.gaotao.modules.pms.data.QcTemplateData">
  403. SELECT
  404. qt.site,
  405. qt.bu_no,
  406. dbo.get_bu_desc(qt.site, qt.bu_no) as buDesc,
  407. qt.template_id,
  408. qt.template_name,
  409. qt.template_remark,
  410. qt.template_type,
  411. qt.template_version,
  412. qt.sampling_programme_no,
  413. qsip.sampling_programme_Desc,
  414. qt.inspection_type_no,
  415. qit.inspection_type_name,
  416. qt.sampling_level_no,
  417. qsil.sampling_level_desc,
  418. qt.inspection_cycle,
  419. qt.create_time,
  420. qt.create_by,
  421. dbo.getOperatorDesc(qt.site, qt.create_by) as createByDesc,
  422. qt.update_date,
  423. qt.update_by,
  424. dbo.getOperatorDesc(qt.site, qt.update_by) as updateByDesc,
  425. qt.AQL,
  426. qt.AC,
  427. qt.RE,
  428. qt.default_sampling_quantity,
  429. qt.default_sampling_proportion
  430. FROM qc_template as qt
  431. LEFT JOIN qc_inspection_type as qit on qt.inspection_type_no = qit.inspection_type_no and qt.site = qit.site
  432. LEFT JOIN qc_sampling_inspection_level as qsil on qt.sampling_level_no = qsil.sampling_level_no and qt.site = qsil.site and qt.bu_no = qsil.bu_no
  433. LEFT JOIN qc_sampling_inspection_programme as qsip on qt.sampling_programme_no = qsip.sampling_programme_no and qt.site = qsip.site and qt.bu_no = qsip.bu_no
  434. <where>
  435. qt.site in (select site from AccessSite where userID = #{query.userName})
  436. and qt.bu_no in (select bu_no from AccessBu where username = #{query.userName})
  437. <if test="query.buDesc != null and query.buDesc != ''">
  438. AND dbo.get_bu_desc ( qt.site, qt.bu_no ) = #{query.buDesc}
  439. </if>
  440. <if test = "query.templateId != null and query.templateId != ''">
  441. AND qt.template_id LIKE '%' + #{query.templateId}+'%'
  442. </if>
  443. <if test = "query.templateName != null and query.templateName != ''">
  444. AND qt.template_name LIKE '%' + #{query.templateName}+'%'
  445. </if>
  446. <if test = "query.inspectionTypeNo != null and query.inspectionTypeNo != ''">
  447. AND qt.inspection_type_no = #{query.inspectionTypeNo}
  448. </if>
  449. </where>
  450. order by qt.create_time desc
  451. </select>
  452. <!-- 获得检验模板单号 -->
  453. <select id="getTemplateNo" resultType="string" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  454. SELECT
  455. Right('0000' + convert(varchar(10),isnull(max(convert(INT,Right(template_id,3))),0)+1),3)
  456. FROM qc_template
  457. WHERE site = #{site} and inspection_type_no = #{inspectionTypeNo} and bu_no = #{buNo}
  458. </select>
  459. <!-- 新增模板 -->
  460. <insert id="templateSave" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  461. INSERT INTO qc_template (site, bu_no, template_id, template_name, template_version, template_remark, template_type, sampling_programme_no, inspection_type_no, create_time, create_by, sampling_level_no, inspection_cycle, AQL, AC, RE, default_sampling_quantity, default_sampling_proportion, update_date, update_by)
  462. VALUES (#{site}, #{buNo}, #{templateId}, #{templateName},#{templateVersion}, #{templateRemark}, #{templateType}, #{samplingProgrammeNo}, #{inspectionTypeNo}, getDate(), #{createBy}, #{samplingLevelNo}, #{inspectionCycle,jdbcType=DECIMAL}, #{aql}, #{ac}, #{re}, #{defaultSamplingQuantity}, #{defaultSamplingProportion}, getDate(), #{updateBy})
  463. </insert>
  464. <!-- 修改模板 -->
  465. <update id="templateUpdate" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  466. UPDATE qc_template
  467. SET template_name = #{templateName},
  468. template_version = #{templateVersion},
  469. template_remark = #{templateRemark},
  470. template_type = #{templateType},
  471. sampling_programme_no = #{samplingProgrammeNo},
  472. inspection_cycle = #{inspectionCycle},
  473. inspection_type_no = #{inspectionTypeNo},
  474. sampling_level_no = #{samplingLevelNo},
  475. AQL = #{aql},
  476. AC = #{ac},
  477. RE = #{re},
  478. default_sampling_quantity = #{defaultSamplingQuantity},
  479. default_sampling_proportion = #{defaultSamplingProportion},
  480. update_date = getDate(),
  481. update_by = #{updateBy}
  482. WHERE template_id = #{templateId} AND site = #{site} and bu_no = #{buNo}
  483. </update>
  484. <!-- 查询模板里的项目详情 -->
  485. <select id="templateDetailsSearch" resultType="com.gaotao.modules.pms.data.QcTemplateData">
  486. SELECT
  487. a.site,
  488. a.bu_no,
  489. a.template_id,
  490. a.ItemNo,
  491. b.ItemDesc,
  492. a.default_value,
  493. b.ValueType,
  494. b.ValueType_DB,
  495. a.max_value,
  496. a.min_value,
  497. b.ItemRemark,
  498. b.ItemType,
  499. b.item_sampling_quantity,
  500. b.sampling_programme_no,
  501. c.sampling_programme_desc,
  502. b.sampling_level_no,
  503. d.sampling_level_desc,
  504. b.default_sampling_proportion,a.order_id
  505. FROM qc_template_detailed a
  506. LEFT JOIN eam_properties_item b ON a.ItemNo = b.ItemNo and a.site = b.site and a.bu_no = b.bu_no
  507. left join qc_sampling_inspection_programme as c on b.site = c.site and b.sampling_programme_no = c.sampling_programme_no and b.bu_no = c.bu_no
  508. left join qc_sampling_inspection_level as d on b.site = d.site and b.sampling_level_no = d.sampling_level_no and b.bu_no = d.bu_no
  509. WHERE a.template_id = #{templateId} AND b.ItemType = #{itemType} and a.site = #{site} and a.bu_no = #{buNo}
  510. order by order_id, ItemNo
  511. </select>
  512. <!-- 查询模板里是否已存在该项目 -->
  513. <select id="selectItemDetails" resultType="com.gaotao.modules.pms.data.QcTemplateData">
  514. SELECT template_id,
  515. ItemNo,
  516. default_value,
  517. max_value,
  518. min_value
  519. FROM qc_template_detailed
  520. WHERE template_id = #{templateId} and ItemNo = #{itemNo} and site = #{site} and bu_no = #{buNo}
  521. </select>
  522. <!-- 查询项目的最大最小值 -->
  523. <select id="selectDetail" resultType="com.gaotao.modules.pms.data.QcTemplateData">
  524. SELECT ItemNo,
  525. DefaultValue,
  526. MaxValue,
  527. MinValue
  528. FROM eam_properties_item
  529. WHERE ItemNo = #{itemNo} and ItemType = #{itemType} and site = #{site} and bu_no = #{buNo}
  530. </select>
  531. <!-- 新增模板的检验项目 -->
  532. <insert id="addItemDetails" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  533. INSERT INTO qc_template_detailed (template_id, ItemNo, default_value, max_value, min_value, site, bu_no,order_id)
  534. VALUES (#{templateId}, #{itemNo}, #{defaultValue}, #{maxValue,jdbcType=DECIMAL}, #{minValue,jdbcType=DECIMAL}, #{site}, #{buNo},#{orderId})
  535. </insert>
  536. <!-- 删除模板的检验项目 -->
  537. <delete id="delItemDetails" >
  538. DELETE FROM qc_template_detailed
  539. WHERE template_id = #{templateId} and ItemNo = #{itemNo} and site = #{site} and bu_no = #{buNo}
  540. </delete>
  541. <!-- 获取当前模板不包含的项目 -->
  542. <select id="getItemList" resultType="com.gaotao.modules.pms.data.QcTemplateData">
  543. SELECT
  544. a.site,
  545. a.bu_no,
  546. a.itemNo,
  547. a.ItemDesc,
  548. a.DefaultValue,
  549. a.MaxValue,
  550. a.MinValue
  551. FROM eam_properties_item a
  552. LEFT JOIN qc_template_detailed b ON b.template_id = #{templateId} and b.ItemNo = a.ItemNo and a.site = b.site and a.bu_no = b.bu_no
  553. WHERE a.ItemType = #{itemType} and a.site = #{site} and b.template_id is null and a.bu_no = #{buNo} and dbo.qc_get_inspection_type_name(a.site, a.inspection_type_no) = #{inspectionTypeName}
  554. </select>
  555. <!-- 查询项目 -->
  556. <select id="getItem" resultType="com.gaotao.modules.pms.data.QcTemplateData">
  557. SELECT
  558. a.site,
  559. a.bu_no,
  560. a.itemNo,
  561. a.ItemDesc,
  562. a.DefaultValue,
  563. a.MaxValue,
  564. a.MinValue
  565. FROM eam_properties_item a
  566. LEFT JOIN qc_template_detailed b ON b.template_id = #{templateId} and b.ItemNo = a.ItemNo and a.site = b.site and a.bu_no = b.bu_no
  567. <where>
  568. a.ItemType = #{itemType} and a.site = #{site} and b.template_id is null and a.bu_no = #{buNo} and dbo.qc_get_inspection_type_name(a.site, a.inspection_type_no) = #{inspectionTypeName}
  569. <if test = "itemNo != null and itemNo != ''">
  570. AND a.ItemNo LIKE '%' + #{itemNo} + '%'
  571. </if>
  572. <if test = "itemDesc != null and itemDesc != ''">
  573. AND a.ItemDesc LIKE '%' + #{itemDesc} + '%'
  574. </if>
  575. <if test = "inspectionTypeNo != null and inspectionTypeNo != ''">
  576. AND a.inspection_type_no = #{inspectionTypeNo}
  577. </if>
  578. </where>
  579. </select>
  580. <!-- 删除模板 -->
  581. <delete id="templateDelete" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  582. DELETE FROM qc_template
  583. WHERE template_id = #{templateId} AND site = #{site} and bu_no = #{buNo}
  584. </delete>
  585. <!-- 删除模板-项目中间表 -->
  586. <delete id="itemItemDelete" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  587. DELETE FROM qc_template_detailed
  588. WHERE template_id = #{templateId} and site = #{site} and bu_no = #{buNo}
  589. </delete>
  590. <!-- 搜索所有检验类型 -->
  591. <select id="inspectionTypeSearch" resultType="com.gaotao.modules.pms.data.QcInspectionTypeData" parameterType="com.gaotao.modules.pms.data.QcInspectionTypeData">
  592. SELECT inspection_type_no,
  593. inspection_type_name
  594. FROM qc_inspection_type
  595. WHERE site = #{site}
  596. </select>
  597. <!-- 搜索所有设备 -->
  598. <select id="objectSearch" resultType="EamObjectData">
  599. SELECT
  600. ObjectID,
  601. ObjectDesc
  602. FROM eam_object
  603. WHERE Active = 'Y' and site = #{site} and bu_no = #{buNo}
  604. </select>
  605. <!-- 导入文件检验 -->
  606. <select id="getItemByItemNo" resultType="com.gaotao.modules.pms.data.EamPropertiesItemData" parameterType="com.gaotao.modules.pms.data.QcItemData">
  607. SELECT ItemDesc,
  608. ItemType
  609. FROM eam_properties_item
  610. WHERE ItemDesc = #{itemDesc}
  611. AND DefaultValue = #{defaultValue}
  612. AND MaxValue = #{maxValue}
  613. AND MinValue = #{minValue}
  614. AND ItemType = #{itemType}
  615. </select>
  616. <!-- 新增检验项目 -->
  617. <insert id="insertItem" parameterType="com.gaotao.modules.pms.data.EamPropertiesItemData">
  618. INSERT INTO eam_properties_item (ItemNo, ItemDesc,DefaultValue,ValueType,ValueType_DB, CreatedDate,CreatedBy,MaxValue, MinValue, ItemRemark,ItemType)
  619. VALUES(#{itemNo},#{itemDesc}, #{defaultValue}, #{valueType}, #{valueTypeDb}, GetDate(), #{createdBy}, #{maxValue,jdbcType=DECIMAL}, #{minValue,jdbcType=DECIMAL}, #{itemRemark}, #{itemType})
  620. </insert>
  621. <!-- 根据模板名称查询模板 -->
  622. <select id="selectTemplateByDesc" parameterType="com.gaotao.modules.pms.data.QcTemplateData" resultType="com.gaotao.modules.pms.data.QcTemplateData">
  623. SELECT template_id,
  624. template_name,
  625. template_version
  626. FROM qc_template
  627. WHERE template_name = #{templateName}
  628. AND site = #{site}
  629. AND template_version = #{templateVersion}
  630. </select>
  631. <delete id="delTemplateItem" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  632. delete qc_template_detailed
  633. WHERE template_id = #{templateId} and site = #{site} and bu_no = #{buNo}
  634. </delete>
  635. <!-- 修改项目明细的最大最小值 -->
  636. <insert id="saveItemDetailed">
  637. INSERT INTO qc_template_detailed
  638. (site, bu_no, template_id, ItemNo, default_value, max_value, min_value, order_id)
  639. VALUES
  640. (#{site}, #{buNo}, #{templateId}, #{itemNo}, #{defaultValue}, #{maxValue,jdbcType=DECIMAL}, #{minValue,jdbcType=DECIMAL},#{orderId})
  641. </insert>
  642. <!-- 查询项目明细 -->
  643. <select id="selectItem" resultType="com.gaotao.modules.pms.data.QcTemplateData">
  644. SELECT ItemNo,
  645. ItemDesc,
  646. DefaultValue,
  647. ValueType,
  648. ValueType_DB,
  649. MaxValue,
  650. MinValue,
  651. ItemRemark,
  652. ItemType,
  653. site,
  654. bu_no
  655. FROM eam_properties_item
  656. WHERE ItemNo = #{itemNo} AND ItemType = #{itemType} AND bu_no = #{buNo}
  657. </select>
  658. <!-- 查询检验项目唯一 -->
  659. <select id="checkTemplateOnlyOne" resultType="com.gaotao.modules.pms.data.QcTemplateData" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  660. SELECT
  661. site,
  662. bu_no,
  663. template_id,
  664. template_name
  665. FROM qc_template
  666. <where>
  667. site = #{site} and bu_no = #{buNo} and template_id = #{templateId}
  668. </where>
  669. </select>
  670. <select id="getQCDetailOrderId" resultType="Integer">
  671. SELECT isnull(max(order_id), 0) + 1
  672. from qc_template_detailed
  673. where site = #{site}
  674. and bu_no= #{buNo}
  675. and template_id = #{templateId}
  676. </select>
  677. <delete id="deleteInspectionStandard2" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  678. delete from qc_inspection_standards
  679. where site = #{site} and bu_no = #{buNo} and template_id = #{templateId} and item_no = #{itemNo}
  680. </delete>
  681. <!-- 查询检验方法列表 -->
  682. <select id="queryMethodList" resultType="com.gaotao.modules.pms.data.QcMethodData" parameterType="com.gaotao.modules.pms.data.QcMethodData">
  683. SELECT
  684. site,
  685. bu_no,
  686. method_no,
  687. method_name,
  688. inspection_type_no,
  689. dbo.qc_get_inspection_type_name(site, inspection_type_no) as inspectionTypeName
  690. FROM qc_method
  691. <where>
  692. site = #{site} and bu_no = #{buNo}
  693. <if test = "methodNo != null and methodNo != ''">
  694. AND method_no LIKE '%' + #{methodNo} + '%'
  695. </if>
  696. <if test = "methodName != null and methodName != ''">
  697. AND method_name LIKE '%' + #{methodName} + '%'
  698. </if>
  699. <if test = "inspectionTypeNo != null and inspectionTypeNo != ''">
  700. AND inspection_type_no = #{inspectionTypeNo}
  701. </if>
  702. <if test="inspectionTypeName != null and inspectionTypeName != ''">
  703. AND dbo.qc_get_inspection_type_name(site, inspection_type_no) = #{inspectionTypeName}
  704. </if>
  705. </where>
  706. </select>
  707. <select id="updateQCDetailOrderIdNull">
  708. UPDATE qc_template_detailed
  709. SET qc_template_detailed.order_id = oi.rn
  710. FROM (SELECT
  711. site,
  712. bu_no,
  713. template_id,
  714. ItemNo,
  715. ROW_NUMBER() OVER (PARTITION BY site,bu_no,template_id ORDER BY ItemNo) AS rn
  716. FROM qc_template_detailed
  717. ) as oi
  718. where qc_template_detailed.template_id = oi.template_id
  719. AND qc_template_detailed.ItemNo = oi.ItemNo
  720. and qc_template_detailed.order_id is null
  721. </select>
  722. <!-- ================================================= 样本量维护 ================================================= -->
  723. <!-- 查询样本量 -->
  724. <select id="samplingQtySearch" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyData" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyData">
  725. SELECT
  726. site,
  727. bu_no,
  728. dbo.get_bu_desc(site, bu_no) as buDesc,
  729. sampling_qty_no,
  730. sampling_qty_desc,
  731. sampling_qty,
  732. sampling_qty_remark,
  733. sampling_qty_active,
  734. case when sampling_qty_active = 'Y' then '是' when sampling_qty_active = 'N' then '否' else '' end as samplingQtyActiveDesc,
  735. create_date,
  736. create_by,
  737. dbo.getOperatorDesc(site, create_by) as createByDesc,
  738. update_date,
  739. update_by,
  740. dbo.getOperatorDesc(site, update_by) as updateByDesc
  741. FROM qc_sampling_inspection_qty
  742. <where>
  743. site in (select site from AccessSite where userID = #{query.userName})
  744. and bu_no in (select bu_no from AccessBu where username = #{query.userName})
  745. <if test="query.buDesc != null and query.buDesc != ''">
  746. AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
  747. </if>
  748. <if test="query.samplingQtyNo != null and query.samplingQtyNo != ''">
  749. AND sampling_qty_no LIKE '%' + #{query.samplingQtyNo} + '%'
  750. </if>
  751. <if test="query.samplingQtyDesc != null and query.samplingQtyDesc != ''">
  752. AND sampling_qty_desc LIKE '%' + #{query.samplingQtyDesc} + '%'
  753. </if>
  754. <if test="query.samplingQty != null">
  755. AND sampling_qty = #{query.samplingQty,jdbcType=DECIMAL}
  756. </if>
  757. <if test="query.samplingQtyActive != null and query.samplingQtyActive != ''">
  758. AND sampling_qty_active = #{query.samplingQtyActive}
  759. </if>
  760. </where>
  761. </select>
  762. <!-- 新增样本量 -->
  763. <insert id="samplingQtySave" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyData">
  764. INSERT INTO qc_sampling_inspection_qty (site, bu_no, sampling_qty_no, sampling_qty, sampling_qty_remark, sampling_qty_active, sampling_qty_desc, create_date, create_by, update_date, update_by)
  765. VALUES(#{site}, #{buNo}, #{samplingQtyNo}, #{samplingQty,jdbcType=DECIMAL}, #{samplingQtyRemark}, #{samplingQtyActive}, #{samplingQtyDesc}, getDate(), #{createBy}, getDate(), #{updateBy})
  766. </insert>
  767. <!-- 根据样本量字码查询样本量 -->
  768. <select id="selectSamplingQtyByDesc" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyData" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyData">
  769. SELECT
  770. site,
  771. bu_no,
  772. sampling_qty_no,
  773. sampling_qty_desc,
  774. sampling_qty,
  775. sampling_qty_remark,
  776. sampling_qty_active
  777. FROM qc_sampling_inspection_qty
  778. WHERE sampling_qty_desc = #{samplingQtyDesc} AND site = #{site} and bu_no = #{buNo}
  779. </select>
  780. <!-- 获取最大样本量编码 -->
  781. <select id="queryLastSamplingQtyNo" resultType="string" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyData">
  782. SELECT top 1 sampling_qty_no
  783. FROM qc_sampling_inspection_qty
  784. where site = #{site} and bu_no = #{buNo}
  785. ORDER BY sampling_qty_no Desc
  786. </select>
  787. <!-- 修改样本量 -->
  788. <update id="samplingQtyUpdate" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyData">
  789. UPDATE qc_sampling_inspection_qty
  790. SET sampling_qty = #{samplingQty,jdbcType=DECIMAL},
  791. sampling_qty_desc = #{samplingQtyDesc},
  792. sampling_qty_remark = #{samplingQtyRemark},
  793. sampling_qty_active = #{samplingQtyActive},
  794. update_date = getDate(),
  795. update_by = #{updateBy}
  796. WHERE sampling_qty_no = #{samplingQtyNo} AND site = #{site} and bu_no = #{buNo}
  797. </update>
  798. <!-- 根据样本量编码查询矩阵 -->
  799. <select id="selectSamplingPlanBySamplingQtyNo" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyData">
  800. SELECT
  801. site,
  802. sampling_plan_no,
  803. sampling_qty_no,
  804. sampling_qty_rank_no,
  805. sampling_level_no,
  806. sampling_plan_active
  807. FROM qc_sampling_inspection_plan
  808. WHERE site = #{site} AND sampling_qty_no = #{samplingQtyNo} and bu_no = #{buNo}
  809. </select>
  810. <!-- 删除样本量 -->
  811. <delete id="samplingQtyDelete" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyData">
  812. DELETE FROM qc_sampling_inspection_qty
  813. WHERE site = #{site} AND sampling_qty_no = #{samplingQtyNo} AND sampling_qty_desc = #{samplingQtyDesc} and bu_no = #{buNo}
  814. </delete>
  815. <!-- ================================================= 批量级次维护 ================================================= -->
  816. <!-- 查询批量级次 -->
  817. <select id="samplingQtyRankSearch" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyRankData" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyRankData">
  818. SELECT
  819. site,
  820. bu_no,
  821. dbo.get_bu_desc(site, bu_no) as buDesc,
  822. sampling_qty_rank_no,
  823. sampling_qty_rank_desc,
  824. min_qty,
  825. max_qty,
  826. sampling_qty_rank_active,
  827. case when sampling_qty_rank_active = 'Y' then '是' when sampling_qty_rank_active = 'N' then '否' else '' end as samplingQtyRankActiveDesc,
  828. sampling_qty_rank_Remark,
  829. create_date,
  830. create_by,
  831. dbo.getOperatorDesc(site, create_by) as createByDesc,
  832. update_date,
  833. update_by,
  834. dbo.getOperatorDesc(site, update_by) as updateByDesc
  835. FROM qc_sampling_inspection_qty_rank
  836. <where>
  837. site in (select site from AccessSite where userID = #{query.userName})
  838. and bu_no in (select bu_no from AccessBu where username = #{query.userName})
  839. <if test="query.buDesc != null and query.buDesc != ''">
  840. AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
  841. </if>
  842. <if test="query.samplingQtyRankNo != null and query.samplingQtyRankNo != ''">
  843. AND sampling_qty_rank_no LIKE '%' + #{query.samplingQtyRankNo}+'%'
  844. </if>
  845. <if test="query.samplingQtyRankDesc != null and query.samplingQtyRankDesc != ''">
  846. AND sampling_qty_rank_desc LIKE '%' + #{query.samplingQtyRankDesc}+'%'
  847. </if>
  848. <if test="query.samplingQtyRankActive != null and query.samplingQtyRankActive != ''">
  849. AND sampling_qty_rank_active = #{query.samplingQtyRankActive}
  850. </if>
  851. </where>
  852. </select>
  853. <!-- 根据名称查询批量级次 -->
  854. <select id="selectSamplingQtyRankByDesc" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyRankData" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyRankData">
  855. SELECT
  856. site,
  857. bu_no,
  858. sampling_qty_rank_no,
  859. sampling_qty_rank_desc,
  860. min_qty,
  861. max_qty,
  862. sampling_qty_rank_active,
  863. sampling_qty_rank_Remark
  864. FROM qc_sampling_inspection_qty_rank
  865. WHERE sampling_qty_rank_desc = #{samplingQtyRankDesc} AND site = #{site} and bu_no = #{buNo}
  866. </select>
  867. <!-- 获取最大批量级次编码 -->
  868. <select id="queryLastSamplingQtyRankNo" resultType="string" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyRankData">
  869. SELECT top 1 sampling_qty_rank_no
  870. FROM qc_sampling_inspection_qty_rank
  871. where site = #{site} and bu_no = #{buNo}
  872. ORDER BY sampling_qty_rank_no Desc
  873. </select>
  874. <!-- 新增批量级次 -->
  875. <insert id="samplingQtyRankSave" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyRankData">
  876. INSERT INTO qc_sampling_inspection_qty_rank (site, bu_no, sampling_qty_rank_no, sampling_qty_rank_desc, min_qty, max_qty, sampling_qty_rank_Remark, sampling_qty_rank_active, create_date, create_by, update_date, update_by)
  877. VALUES(#{site}, #{buNo}, #{samplingQtyRankNo}, #{samplingQtyRankDesc}, #{minQty,jdbcType=DECIMAL}, #{maxQty,jdbcType=DECIMAL}, #{samplingQtyRankRemark}, #{samplingQtyRankActive}, getDate(), #{createBy}, getDate(), #{updateBy})
  878. </insert>
  879. <!-- 根据批量级次编码查询矩阵 -->
  880. <select id="selectSamplingPlanBySamplingQtyRankNo" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyRankData">
  881. SELECT
  882. site,
  883. bu_no,
  884. sampling_plan_no,
  885. sampling_qty_no,
  886. sampling_qty_rank_no,
  887. sampling_level_no,
  888. sampling_plan_active
  889. FROM qc_sampling_inspection_plan
  890. WHERE site = #{site} AND sampling_qty_rank_no = #{samplingQtyRankNo} and bu_no = #{buNo}
  891. </select>
  892. <!-- 修改批量级次 -->
  893. <update id="samplingQtyRankUpdate" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyRankData">
  894. UPDATE qc_sampling_inspection_qty_rank
  895. SET sampling_qty_rank_desc = #{samplingQtyRankDesc},
  896. min_qty = #{minQty,jdbcType=DECIMAL},
  897. max_qty = #{maxQty,jdbcType=DECIMAL},
  898. sampling_qty_rank_Remark = #{samplingQtyRankRemark},
  899. sampling_qty_rank_active = #{samplingQtyRankActive},
  900. update_date = getDate(),
  901. update_by = #{updateBy}
  902. WHERE sampling_qty_rank_no = #{samplingQtyRankNo} AND site = #{site} and bu_no = #{buNo}
  903. </update>
  904. <!-- 删除批量级次 -->
  905. <delete id="samplingQtyRankDelete" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionQtyRankData">
  906. DELETE FROM qc_sampling_inspection_qty_rank
  907. WHERE site = #{site} and bu_no = #{buNo}
  908. AND sampling_qty_rank_no = #{samplingQtyRankNo}
  909. AND sampling_qty_rank_desc = #{samplingQtyRankDesc}
  910. </delete>
  911. <!-- ================================================= 检验等级维护 ================================================= -->
  912. <!-- 查询检验等级 -->
  913. <select id="samplingLevelSearch" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionLevelData" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionLevelData">
  914. SELECT
  915. site,
  916. bu_no,
  917. dbo.get_bu_desc(site, bu_no) as buDesc,
  918. sampling_level_no,
  919. sampling_level_desc,
  920. sampling_level_remark,
  921. sampling_level_active,
  922. case when sampling_level_active = 'Y' then '是' when sampling_level_active = 'N' then '否' else '' end as samplingLevelActiveDesc,
  923. create_date,
  924. create_by,
  925. dbo.getOperatorDesc(site, create_by) as createByDesc,
  926. update_date,
  927. update_by,
  928. dbo.getOperatorDesc(site, update_by) as updateByDesc
  929. FROM qc_sampling_inspection_level
  930. <where>
  931. site in (select site from AccessSite where userID = #{query.userName})
  932. and bu_no in (select bu_no from AccessBu where username = #{query.userName})
  933. <if test="query.buDesc != null and query.buDesc != ''">
  934. AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
  935. </if>
  936. <if test="query.samplingLevelNo != null and query.samplingLevelNo != ''">
  937. AND sampling_level_no LIKE '%' + #{query.samplingLevelNo}+'%'
  938. </if>
  939. <if test="query.samplingLevelDesc != null and query.samplingLevelDesc != ''">
  940. AND sampling_level_desc LIKE '%' + #{query.samplingLevelDesc}+'%'
  941. </if>
  942. <if test="query.samplingLevelActive != null and query.samplingLevelActive != ''">
  943. AND sampling_level_active = #{query.samplingLevelActive}
  944. </if>
  945. </where>
  946. </select>
  947. <!-- 根据名称查询检验等级 -->
  948. <select id="selectSamplingLevelByDesc" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionLevelData" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionLevelData">
  949. SELECT
  950. site,
  951. bu_no,
  952. sampling_level_no,
  953. sampling_level_desc,
  954. sampling_level_remark,
  955. sampling_level_active
  956. FROM qc_sampling_inspection_level
  957. WHERE sampling_level_desc = #{samplingLevelDesc} AND site = #{site} and bu_no = #{buNo}
  958. </select>
  959. <!-- 获取最大检验等级编码 -->
  960. <select id="queryLastSamplingLevelNo" resultType="string" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionLevelData">
  961. SELECT top 1 sampling_level_no
  962. FROM qc_sampling_inspection_level
  963. where site = #{site} and bu_no = #{buNo}
  964. ORDER BY sampling_level_no Desc
  965. </select>
  966. <!-- 新增检验等级 -->
  967. <insert id="samplingLevelSave" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionLevelData">
  968. INSERT INTO qc_sampling_inspection_level (site, bu_no, sampling_level_no, sampling_level_desc, sampling_level_remark, sampling_level_active, create_date, create_by, update_date, update_by)
  969. VALUES (#{site}, #{buNo}, #{samplingLevelNo}, #{samplingLevelDesc}, #{samplingLevelRemark}, #{samplingLevelActive}, getDate(), #{createBy}, getDate(), #{updateBy})
  970. </insert>
  971. <!-- 根据检验等级编码查询矩阵 -->
  972. <select id="selectSamplingPlanBySamplingLevelNo" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionPlanData" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionLevelData">
  973. SELECT
  974. site,
  975. bu_no,
  976. sampling_plan_no,
  977. sampling_qty_no,
  978. sampling_qty_rank_no,
  979. sampling_level_no,
  980. sampling_plan_active
  981. FROM qc_sampling_inspection_plan
  982. WHERE site = #{site} and bu_no = #{buNo}
  983. AND sampling_level_no = #{samplingLevelNo}
  984. </select>
  985. <!-- 修改检验等级 -->
  986. <update id="samplingLevelUpdate" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionLevelData">
  987. UPDATE qc_sampling_inspection_level
  988. SET sampling_level_desc = #{samplingLevelDesc},
  989. sampling_level_remark = #{samplingLevelRemark},
  990. sampling_level_active = #{samplingLevelActive},
  991. update_date = getDate(),
  992. update_by = #{updateBy}
  993. WHERE sampling_level_no = #{samplingLevelNo}
  994. AND site = #{site} and bu_no = #{buNo}
  995. </update>
  996. <!-- 删除检验等级 -->
  997. <delete id="samplingLevelDelete" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionLevelData">
  998. DELETE FROM qc_sampling_inspection_level
  999. WHERE site = #{site} and bu_no = #{buNo}
  1000. AND sampling_level_no = #{samplingLevelNo}
  1001. AND sampling_level_desc = #{samplingLevelDesc}
  1002. </delete>
  1003. <!-- ================================================= 物料属性设置维护 ================================================= -->
  1004. <!-- 查询物料属性 -->
  1005. <select id="qcPartAttributeSearch" parameterType="com.gaotao.modules.pms.data.QcPartAttributeData" resultType="com.gaotao.modules.pms.entity.vo.PartInformationVo">
  1006. SELECT
  1007. a.site,
  1008. a.bu_no,
  1009. dbo.get_bu_desc(a.site, a.bu_no) as buDesc,
  1010. partNo,
  1011. PartDescription as partDesc,
  1012. part_desc_en,
  1013. spec,
  1014. PartType_DB,
  1015. PartType,
  1016. FamilyID,
  1017. GroupID,
  1018. a.UMID,
  1019. e.UMName as UMName,
  1020. a.Active,
  1021. Remark,
  1022. Stock,
  1023. StockInArrive,
  1024. StockInQuality,
  1025. StockInConsignment,
  1026. StockInPicking,
  1027. StockinActive,
  1028. QtyonPO,
  1029. MinStock,
  1030. MaxStock,
  1031. SafetyStockManage,
  1032. SafetyStock,
  1033. StandardOrderQty,
  1034. SupplierID,
  1035. AccountFamilyID,
  1036. LatestPrice,
  1037. AveragePrice,
  1038. ActualCost,
  1039. StandardCost,
  1040. StandardCost_BasePrice,
  1041. LatestSalesPrice,
  1042. AverageSalesPrice,
  1043. FinanceCheck,
  1044. MRPCode,
  1045. ManuLeadtime,
  1046. DefaultWarehouseID,
  1047. CodeNo,
  1048. SubCodeNo,
  1049. StandardLotSize,
  1050. ExpireDateControlFlag,
  1051. ToExpireDays,
  1052. CreateDate,
  1053. LastUpdateBy,
  1054. NeedApproveFlag,
  1055. ApprovedFlag,
  1056. NetWeight,
  1057. OtherGroup1,
  1058. OtherGroup2,
  1059. OtherGroup3,
  1060. OtherGroup4,
  1061. DefaultDepartmentID,
  1062. DefaultLocationID,
  1063. ConfigurationFlag,
  1064. ConfigurationTemplateID,
  1065. BOMLatestRevNo,
  1066. UMID_New,
  1067. PartNo_Base,
  1068. UMID_ConvertFactor,
  1069. expiration_flag,
  1070. expiration_day,
  1071. expiration_warning_day,
  1072. inbound_warehouse_id,
  1073. b.WareHouseName as inboundWarehouseName,
  1074. outbound_warehouse_id,
  1075. c.WareHouseName as outboundWarehouseName,
  1076. inbound_location_id,
  1077. d.LocationName as inboundLocationName,
  1078. exceed_in_ratio,
  1079. exceed_out_ratio,
  1080. iqc_exempt,
  1081. fai_exempt,
  1082. ipqc_exempt,
  1083. pqc_exempt,
  1084. fqc_exempt,
  1085. oqc_exempt,
  1086. first_inspection_duration,
  1087. next_inspection_duration,
  1088. total_inspection_duration,
  1089. sku,
  1090. cinv_source_code,
  1091. invtype,
  1092. standard_value,
  1093. default_value,
  1094. max_value,
  1095. min_value,
  1096. adhesive_active_period_flag,
  1097. thawing_duration,
  1098. accumulated_exposure_duration
  1099. from part as a
  1100. left join wareHouse as b on a.site = b.site and a.bu_no = b.bu_no and a.inbound_warehouse_id = b.WarehouseID
  1101. left join wareHouse as c on a.site = c.site and a.bu_no = c.bu_no and a.outbound_warehouse_id = c.WarehouseID
  1102. left join location as d on a.site = d.site and a.bu_no = d.bu_no and a.inbound_location_id = d.LocationID
  1103. left join um as e on a.site = e.site and a.UMID = e.UMID
  1104. <where>
  1105. a.site in (select site from AccessSite where userID = #{query.userName})
  1106. and a.bu_no in (select bu_no from AccessBu where username = #{query.userName})
  1107. <if test="query.buDesc != null and query.buDesc != ''">
  1108. AND dbo.get_bu_desc (site, bu_no) = #{query.buDesc}
  1109. </if>
  1110. <if test = "query.partNo != null and query.partNo != ''">
  1111. AND partNo LIKE '%' + #{query.partNo} + '%'
  1112. </if>
  1113. <if test = "query.partDesc != null and query.partDesc != ''">
  1114. AND PartDescription LIKE '%' + #{query.partDesc} + '%'
  1115. </if>
  1116. <if test = "query.cinvSourceCode != null and query.cinvSourceCode != ''">
  1117. AND cinv_source_code LIKE '%' + #{query.cinvSourceCode} + '%'
  1118. </if>
  1119. <if test = "query.sku != null and query.sku != ''">
  1120. AND sku LIKE '%' + #{query.sku} + '%'
  1121. </if>
  1122. <if test = "query.familyName != null and query.familyName != ''">
  1123. AND invtype LIKE '%' + #{query.familyName} + '%'
  1124. </if>
  1125. </where>
  1126. </select>
  1127. <!-- 查询是否已有该物料属性 -->
  1128. <select id="selectPartAttributeByNo" resultType="com.gaotao.modules.pms.entity.vo.PartInformationVo" parameterType="com.gaotao.modules.pms.entity.vo.PartInformationVo">
  1129. SELECT
  1130. site,
  1131. partNo,
  1132. bu_no
  1133. FROM part
  1134. WHERE site = #{site} and partNo = #{partNo} and bu_no = #{buNo}
  1135. </select>
  1136. <!-- 物料属性修改 -->
  1137. <update id="qcPartAttributeEdit" parameterType="com.gaotao.modules.pms.entity.vo.PartInformationVo">
  1138. UPDATE part
  1139. SET expiration_flag = #{expirationFlag},
  1140. expiration_day = #{expirationDay},
  1141. expiration_warning_day = #{expirationWarningDay},
  1142. exceed_in_ratio = #{exceedInRatio, jdbcType=FLOAT},
  1143. exceed_out_ratio = #{exceedOutRatio, jdbcType=FLOAT},
  1144. inbound_warehouse_id = #{inboundWarehouseId},
  1145. outbound_warehouse_id = #{outboundWarehouseId},
  1146. inbound_location_id = #{inboundLocationId},
  1147. iqc_exempt = #{iqcExempt},
  1148. fai_exempt = #{faiExempt},
  1149. ipqc_exempt = #{ipqcExempt},
  1150. pqc_exempt = #{pqcExempt},
  1151. fqc_exempt = #{fqcExempt},
  1152. oqc_exempt = #{oqcExempt},
  1153. first_inspection_duration = #{firstInspectionDuration, jdbcType=FLOAT},
  1154. next_inspection_duration = #{nextInspectionDuration, jdbcType=FLOAT},
  1155. total_inspection_duration = #{totalInspectionDuration, jdbcType=FLOAT},
  1156. LastUpdateBy = #{lastUpdateBy},
  1157. standard_value = #{standardValue, jdbcType=DECIMAL},
  1158. default_value = #{defaultValue, jdbcType=DECIMAL},
  1159. max_value = #{maxValue, jdbcType=DECIMAL},
  1160. min_value = #{minValue, jdbcType=DECIMAL},
  1161. adhesive_active_period_flag = #{adhesiveActivePeriodFlag},
  1162. thawing_duration = #{thawingDuration},
  1163. accumulated_exposure_duration = #{accumulatedExposureDuration}
  1164. WHERE site = #{site} and partNo = #{partNo} and bu_no = #{buNo}
  1165. </update>
  1166. <!-- 删除物料属性模板 -->
  1167. <delete id="deletePartAttributeTemplate" parameterType="com.gaotao.modules.pms.data.QcPartAttributeData">
  1168. DELETE FROM qc_attribute_template
  1169. WHERE site = #{site} and bu_no = #{buNo} and attribute_no = #{partNo} and attribute_type = #{attributeType}
  1170. </delete>
  1171. <!-- 查询类别模板 -->
  1172. <select id="searchPartAttributeDetails" resultType="com.gaotao.modules.pms.data.QcTemplateData" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  1173. SELECT
  1174. qat.site,
  1175. qat.bu_no,
  1176. qpa.attribute_no,
  1177. qpa.attribute_type,
  1178. qt.template_id,
  1179. qt.template_name,
  1180. qt.template_remark,
  1181. qt.template_version,
  1182. qat.sampling_programme_no,
  1183. qsip.sampling_programme_desc,
  1184. qat.AQL,
  1185. qat.AC,
  1186. qat.RE,
  1187. qt.inspection_type_no,
  1188. qit.inspection_type_name,
  1189. qt.default_sampling_quantity,
  1190. qt.default_sampling_proportion,
  1191. qat.sampling_level_no,
  1192. qsil.sampling_level_desc,
  1193. qat.inspection_cycle,
  1194. qat.operation,
  1195. qat.manufacturer_id,
  1196. dbo.qc_get_supplier_name(qat.site, qat.manufacturer_id) as manufacturerName,
  1197. qat.resource_id
  1198. FROM qc_attribute_template as qat
  1199. LEFT JOIN qc_part_attribute as qpa ON qpa.attribute_no = qat.attribute_no and qat.site = qpa.site and qat.bu_no = qpa.bu_no
  1200. LEFT JOIN qc_template as qt ON qat.template_id = qt.template_id and qat.site = qt.site and qat.bu_no = qt.bu_no
  1201. LEFT JOIN qc_sampling_inspection_level as qsil ON qat.sampling_level_no = qsil.sampling_level_no and qat.site = qsil.site and qat.bu_no = qsil.bu_no
  1202. LEFT JOIN qc_inspection_type as qit ON qt.inspection_type_no = qit.inspection_type_no and qt.site = qit.site
  1203. LEFT JOIN qc_sampling_inspection_programme as qsip ON qat.sampling_programme_no = qsip.sampling_programme_no and qat.site = qsip.site and qat.bu_no = qsip.bu_no
  1204. WHERE qat.site = #{site} and qpa.attribute_type = #{attributeType} and qpa.attribute_no = #{attributeNo} and qat.bu_no = #{buNo}
  1205. </select>
  1206. <!-- 物料属性模板查重 -->
  1207. <select id="searchPartRepeat" resultType="com.gaotao.modules.pms.data.QcTemplateData" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  1208. SELECT
  1209. attribute_no,
  1210. template_id
  1211. FROM qc_attribute_template
  1212. WHERE attribute_no = #{attributeNo}
  1213. AND template_id = #{templateId}
  1214. AND attribute_type = #{attributeType}
  1215. AND special_field = #{specialField}
  1216. </select>
  1217. <!-- 新增物料属性模板 -->
  1218. <insert id="savePartAttributeDetails" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  1219. INSERT INTO qc_attribute_template (attribute_no, template_id, sampling_level_no, inspection_cycle, sampling_programme_no, AQL, AC, RE, attribute_type, operation, manufacturer_id, resource_id, site, bu_no, customer_id)
  1220. VALUES (#{attributeNo}, #{templateId}, #{samplingLevelNo}, #{inspectionCycle,jdbcType=DECIMAL}, #{samplingProgrammeNo}, #{aql,jdbcType=DECIMAL}, #{ac,jdbcType=DECIMAL}, #{re,jdbcType=DECIMAL}, #{attributeType}, #{operation}, #{manufacturerID}, #{resourceID}, #{site}, #{buNo}, #{customerID})
  1221. </insert>
  1222. <!-- 删除物料属性模板 -->
  1223. <delete id="deletePartAttributeDetails" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  1224. DELETE FROM qc_attribute_template
  1225. <where>
  1226. site = #{site} and bu_no = #{buNo} and attribute_no = #{attributeNo} and template_id = #{templateId} and attribute_type = #{attributeType}
  1227. <if test = "operation != null and operation != ''">
  1228. and operation = #{operation}
  1229. </if>
  1230. <if test = "resourceID != null and resourceID != ''">
  1231. and resource_id = #{resourceID}
  1232. </if>
  1233. <if test = "manufacturerID != null and manufacturerID != ''">
  1234. and manufacturer_id = #{manufacturerID}
  1235. </if>
  1236. </where>
  1237. </delete>
  1238. <!-- 查询模板的基础数据 -->
  1239. <select id="selectTemplateData" resultType="com.gaotao.modules.pms.data.QcTemplateData" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  1240. SELECT
  1241. template_id,
  1242. template_name,
  1243. sampling_programme_no,
  1244. sampling_level_no,
  1245. inspection_cycle,
  1246. AQL,
  1247. AC,
  1248. RE,
  1249. inspection_type_no
  1250. FROM qc_template
  1251. WHERE site = #{site} AND template_id = #{templateId} and bu_no = #{buNo}
  1252. </select>
  1253. <!-- 新增物料属性模板详情 -->
  1254. <update id="saveAttributeDetailed" parameterType="com.gaotao.modules.pms.data.QcTemplateData">
  1255. UPDATE qc_attribute_template
  1256. SET sampling_level_no = #{samplingLevelNo},
  1257. inspection_cycle = #{inspectionCycle,jdbcType=DECIMAL},
  1258. sampling_programme_no = #{samplingProgrammeNo},
  1259. AQL = #{aql,jdbcType=DECIMAL},
  1260. AC = #{ac,jdbcType=DECIMAL},
  1261. RE = #{re,jdbcType=DECIMAL}
  1262. <where>
  1263. site = #{site} and attribute_no = #{attributeNo} AND template_id = #{templateId} AND attribute_type = #{attributeType} and bu_no = #{buNo}
  1264. <if test = "operation != null and operation != ''">
  1265. AND operation = #{operation}
  1266. </if>
  1267. <if test = "resourceID != null and resourceID != ''">
  1268. AND resource_id = #{resourceID}
  1269. </if>
  1270. <if test = "manufacturerID != null and manufacturerID != ''">
  1271. AND manufacturer_id = #{manufacturerID}
  1272. </if>
  1273. </where>
  1274. </update>
  1275. <!-- ================================================= 抽样方案维护 ================================================= -->
  1276. <!-- 查询类别属性 -->
  1277. <select id="samplingProgrammeSearch" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1278. SELECT
  1279. site,
  1280. bu_no,
  1281. dbo.get_bu_desc(site, bu_no) as buDesc,
  1282. sampling_programme_no,
  1283. sampling_programme_desc,
  1284. sampling_programme_code,
  1285. create_time,
  1286. create_by,
  1287. dbo.getOperatorDesc(site, create_by) as createByDesc,
  1288. update_date,
  1289. update_by,
  1290. dbo.getOperatorDesc(site, update_by) as updateByDesc
  1291. FROM qc_sampling_inspection_programme
  1292. <where>
  1293. site in (select site from AccessSite where userID = #{query.userName})
  1294. and bu_no in (select bu_no from AccessBu where username = #{query.userName})
  1295. <if test="query.buDesc != null and query.buDesc != ''">
  1296. AND dbo.get_bu_desc ( site, bu_no ) = #{query.buDesc}
  1297. </if>
  1298. <if test = "query.samplingProgrammeNo != null and query.samplingProgrammeNo != ''">
  1299. AND sampling_programme_no LIKE '%' + #{query.samplingProgrammeNo}+'%'
  1300. </if>
  1301. <if test = "query.samplingProgrammeCode != null and query.samplingProgrammeCode != ''">
  1302. AND sampling_programme_code LIKE '%' + #{query.samplingProgrammeCode}+'%'
  1303. </if>
  1304. <if test = "query.samplingProgrammeDesc != null and query.samplingProgrammeDesc != ''">
  1305. AND sampling_programme_desc LIKE '%' + #{query.samplingProgrammeDesc}+'%'
  1306. </if>
  1307. </where>
  1308. </select>
  1309. <!-- 新增抽样方案 -->
  1310. <insert id="samplingProgrammeSave" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1311. INSERT INTO qc_sampling_inspection_programme (site, bu_no, sampling_programme_no, sampling_programme_desc, sampling_programme_code, create_time, create_by, update_date, update_by)
  1312. VALUES(#{site}, #{buNo}, #{samplingProgrammeNo}, #{samplingProgrammeDesc}, #{samplingProgrammeCode}, getDate(), #{createBy}, getDate(), #{updateBy})
  1313. </insert>
  1314. <!-- 删除抽样方案 -->
  1315. <delete id="samplingProgrammeDelete" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1316. DELETE FROM qc_sampling_inspection_programme
  1317. WHERE site = #{site} and bu_no = #{buNo}
  1318. AND sampling_programme_no = #{samplingProgrammeNo}
  1319. </delete>
  1320. <!-- 删除抽样方案中的矩阵 -->
  1321. <delete id="deletePlanByProgrammeNo" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1322. DELETE FROM qc_programme_plan
  1323. WHERE sampling_programme_no = #{samplingProgrammeNo} and site = #{site} and bu_no = #{buNo}
  1324. </delete>
  1325. <!-- 根据名称查询抽样方案 -->
  1326. <select id="selectSamplingProgrammeByDesc" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1327. SELECT
  1328. site,
  1329. bu_no,
  1330. sampling_programme_no,
  1331. sampling_programme_desc
  1332. FROM qc_sampling_inspection_programme
  1333. WHERE sampling_programme_desc = #{samplingProgrammeDesc} AND site = #{site} and bu_no = #{buNo}
  1334. </select>
  1335. <!-- 获取最大抽样方案编码 -->
  1336. <select id="queryLastSamplingProgrammeNo" resultType="string" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1337. SELECT top 1 sampling_programme_no
  1338. FROM qc_sampling_inspection_programme
  1339. where site = #{site} and bu_no = #{buNo}
  1340. ORDER BY sampling_programme_no Desc
  1341. </select>
  1342. <!-- 搜索抽样方案中的矩阵 -->
  1343. <select id="searchSamplingProgrammeDetails" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1344. SELECT
  1345. qpp.site,
  1346. qpp.bu_no,
  1347. qpp.sampling_programme_no,
  1348. qsip.sampling_plan_no,
  1349. qsip.sampling_plan_Desc,
  1350. qsip.sampling_qty_no,
  1351. qsiq.sampling_qty_desc,
  1352. qsiq.sampling_qty,
  1353. qsip.sampling_qty_rank_no,
  1354. qsiqr.sampling_qty_rank_desc,
  1355. qsiqr.min_qty,
  1356. qsiqr.max_qty,
  1357. qsip.sampling_level_no,
  1358. qsil.sampling_level_desc,
  1359. qsip.sampling_plan_active
  1360. FROM qc_programme_plan as qpp
  1361. LEFT JOIN qc_sampling_inspection_plan as qsip on qpp.sampling_plan_no = qsip.sampling_plan_no and qpp.site = qsip.site and qpp.bu_no = qsip.bu_no
  1362. LEFT JOIN qc_sampling_inspection_qty as qsiq on qsip.sampling_qty_no = qsiq.sampling_qty_no and qsip.site = qsiq.site and qsip.bu_no = qsiq.bu_no
  1363. LEFT JOIN qc_sampling_inspection_qty_rank as qsiqr on qsip.sampling_qty_rank_no = qsiqr.sampling_qty_rank_no and qsip.site = qsiqr.site and qsip.bu_no = qsiqr.bu_no
  1364. LEFT JOIN qc_sampling_inspection_level as qsil on qsip.sampling_level_no = qsil.sampling_level_no and qsip.site = qsil.site and qsip.bu_no = qsil.bu_no
  1365. WHERE qpp.sampling_programme_no = #{samplingProgrammeNo} and qpp.site = #{site} and qpp.bu_no = #{buNo}
  1366. </select>
  1367. <!-- 获取该方案不包含的矩阵 -->
  1368. <select id="getPlanList" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1369. SELECT
  1370. qip.sampling_plan_no,
  1371. qip.sampling_plan_desc
  1372. FROM qc_sampling_inspection_plan as qip
  1373. LEFT JOIN qc_programme_plan as qpp ON qpp.sampling_plan_no = qip.sampling_plan_no and qpp.sampling_programme_no = #{samplingProgrammeNo} and qpp.site = qip.site and qpp.bu_no = qip.bu_no
  1374. WHERE qip.site = #{site} and qip.bu_no = #{buNo} AND qpp.sampling_programme_no is null
  1375. </select>
  1376. <!-- 获取当前方案所包含的矩阵 -->
  1377. <select id="getProgrammePlanList" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1378. SELECT
  1379. qip.sampling_plan_no,
  1380. qip.sampling_plan_desc
  1381. FROM qc_programme_plan as qpp
  1382. LEFT JOIN qc_sampling_inspection_plan as qip ON qpp.sampling_plan_no = qip.sampling_plan_no and qpp.site = qip.site and qpp.bu_no = qip.bu_no
  1383. WHERE qip.site = #{site} and qip.bu_no = #{buNo} AND qpp.sampling_programme_no = #{samplingProgrammeNo}
  1384. </select>
  1385. <!-- 查重 -->
  1386. <select id="searchPlanRepeat" resultType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1387. SELECT
  1388. sampling_plan_no,
  1389. sampling_programme_no
  1390. FROM qc_programme_plan
  1391. WHERE sampling_programme_no = #{samplingProgrammeNo} AND sampling_plan_no = #{samplingPlanNo} and site = #{site} and bu_no = #{buNo}
  1392. </select>
  1393. <!-- 新增抽样方案中的矩阵 -->
  1394. <insert id="saveSamplingProgrammeDetails" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1395. INSERT INTO qc_programme_plan (site, bu_no, sampling_programme_no, sampling_plan_no)
  1396. VALUES (#{site}, #{buNo}, #{samplingProgrammeNo}, #{samplingPlanNo})
  1397. </insert>
  1398. <!-- 更新抽样方案修改时间 -->
  1399. <update id="updateSamplingInspectionProgrammeDate" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1400. UPDATE qc_sampling_inspection_programme
  1401. SET update_date = getDate(),
  1402. update_by = #{updateBy}
  1403. WHERE site = #{site} AND sampling_programme_no = #{samplingProgrammeNo} and bu_no = #{buNo}
  1404. </update>
  1405. <!-- 删除抽样方案中的矩阵 -->
  1406. <delete id="deleteSamplingProgrammeDetails" parameterType="com.gaotao.modules.pms.data.QcSamplingInspectionProgrammeData">
  1407. DELETE FROM qc_programme_plan
  1408. WHERE sampling_programme_no = #{samplingProgrammeNo} and sampling_plan_no = #{samplingPlanNo} and site = #{site} and bu_no = #{buNo}
  1409. </delete>
  1410. <select id="getSiteAndBuByUserName" parameterType="com.gaotao.modules.base.data.BuData" resultType="com.gaotao.modules.base.data.BuData">
  1411. SELECT
  1412. b.id,
  1413. a.site,
  1414. c.sitename,
  1415. (a.site + '_' + a.bu_no) as buNo,
  1416. b.bu_desc
  1417. FROM AccessBu as a
  1418. left join bu as b on a.bu_no = b.bu_no and a.site = b.site
  1419. left join site as c on a.site = c.siteid
  1420. WHERE a.username = #{username}
  1421. </select>
  1422. <select id="getSiteAndBuByUserName2" parameterType="com.gaotao.modules.base.data.BuData" resultType="com.gaotao.modules.base.data.BuData">
  1423. SELECT
  1424. a.site,
  1425. c.sitename,
  1426. a.bu_no,
  1427. b.bu_desc
  1428. FROM AccessBu as a
  1429. left join bu as b on a.bu_no = b.bu_no and a.site = b.site
  1430. left join site as c on a.site = c.siteid
  1431. WHERE a.username = #{username}
  1432. </select>
  1433. <!-- 查询类别模板 -->
  1434. <select id="getPartDefectTracking" resultType="com.gaotao.modules.pms.entity.vo.PartDefectTrackingVo" parameterType="com.gaotao.modules.pms.entity.vo.PartDefectTrackingVo">
  1435. SELECT
  1436. a.site,
  1437. a.bu_no,
  1438. a.part_no,
  1439. a.supplier_id,
  1440. b.SupplierName,
  1441. a.defect_threshold,
  1442. a.recovery_batch_count,
  1443. a.current_defect_count,
  1444. a.last_defect_count
  1445. FROM part_defect_tracking as a
  1446. left join Supplier as b on a.site = b.site and a.supplier_id = b.SupplierID
  1447. <where>
  1448. a.site = #{site} and a.bu_no = #{buNo} and a.part_no = #{partNo}
  1449. <if test = "supplierId != null and supplierId != ''">
  1450. AND a.supplier_id = #{supplierId}
  1451. </if>
  1452. </where>
  1453. </select>
  1454. <!-- 新增跟踪缺陷 -->
  1455. <insert id="saveDefectTracking" parameterType="com.gaotao.modules.pms.entity.vo.PartDefectTrackingVo">
  1456. INSERT INTO part_defect_tracking (site, bu_no, part_no, supplier_id, defect_threshold, recovery_batch_count, current_defect_count, last_defect_count)
  1457. VALUES (#{site}, #{buNo}, #{partNo}, #{supplierId}, #{defectThreshold,jdbcType=INTEGER}, #{recoveryBatchCount,jdbcType=INTEGER}, #{currentDefectCount,jdbcType=INTEGER}, #{lastDefectCount,jdbcType=INTEGER})
  1458. </insert>
  1459. <!-- 删除跟踪缺陷 -->
  1460. <delete id="deleteDefectTracking" parameterType="com.gaotao.modules.pms.entity.vo.PartDefectTrackingVo">
  1461. DELETE FROM part_defect_tracking
  1462. WHERE site = #{site} and bu_no = #{buNo} and part_no = #{partNo} and supplier_id = #{supplierId}
  1463. </delete>
  1464. <!-- 编辑跟踪缺陷 -->
  1465. <update id="updateDefectTracking" parameterType="com.gaotao.modules.pms.entity.vo.PartDefectTrackingVo">
  1466. UPDATE part_defect_tracking
  1467. SET defect_threshold = #{defectThreshold,jdbcType=INTEGER},
  1468. recovery_batch_count = #{recoveryBatchCount,jdbcType=INTEGER},
  1469. current_defect_count = #{currentDefectCount,jdbcType=INTEGER},
  1470. last_defect_count = #{lastDefectCount,jdbcType=INTEGER}
  1471. where site = #{site} and bu_no = #{buNo} and part_no = #{partNo} AND supplier_id = #{supplierId}
  1472. </update>
  1473. <!-- 查询类别模板 -->
  1474. <select id="getPartLabelTemplate" resultType="com.gaotao.modules.pms.entity.vo.PartLabelTemplateVo" parameterType="com.gaotao.modules.pms.entity.vo.PartLabelTemplateVo">
  1475. SELECT
  1476. a.site,
  1477. a.bu_no,
  1478. a.part_no,
  1479. a.label_type_tb,
  1480. a.label_type,
  1481. a.default_flag,
  1482. case when a.default_flag = '1' then '默认' when a.default_flag = '0' then '非默认' else '' end as defaultFlagDesc,
  1483. a.created_by,
  1484. a.created_date
  1485. FROM part_label_template as a
  1486. <where>
  1487. a.site = #{site} and a.bu_no = #{buNo} and a.part_no = #{partNo}
  1488. <if test = "labelTypeTb != null and labelTypeTb != ''">
  1489. AND a.label_type_tb = #{labelTypeTb}
  1490. </if>
  1491. </where>
  1492. </select>
  1493. <!-- 新增标签模版设置 -->
  1494. <insert id="saveLabelTemplate" parameterType="com.gaotao.modules.pms.entity.vo.PartLabelTemplateVo">
  1495. INSERT INTO part_label_template (site, bu_no, part_no, label_type_tb, label_type, default_flag, created_by, created_date)
  1496. VALUES (#{site}, #{buNo}, #{partNo}, #{labelTypeTb}, #{labelType}, #{defaultFlag}, #{createdBy}, getDate())
  1497. </insert>
  1498. <!-- 删除标签模版设置 -->
  1499. <delete id="deleteLabelTemplate" parameterType="com.gaotao.modules.pms.entity.vo.PartLabelTemplateVo">
  1500. DELETE FROM part_label_template
  1501. WHERE site = #{site} and bu_no = #{buNo} and part_no = #{partNo} and label_type_tb = #{labelTypeTb}
  1502. </delete>
  1503. <!-- 编辑标签模版设置 -->
  1504. <update id="updateLabelTemplate" parameterType="com.gaotao.modules.pms.entity.vo.PartLabelTemplateVo">
  1505. UPDATE part_label_template
  1506. SET default_flag = #{defaultFlag}
  1507. where site = #{site} and bu_no = #{buNo} and part_no = #{partNo} AND label_type_tb = #{labelTypeTb}
  1508. </update>
  1509. <!-- 获取客户列表 -->
  1510. <select id="getCustomerList" parameterType="com.gaotao.modules.pms.data.QcPartAttributeData" resultType="com.gaotao.modules.pms.data.QcPartAttributeData">
  1511. SELECT
  1512. CustomerID as customerID,
  1513. CustomerName as customerName
  1514. FROM Customer
  1515. <where>
  1516. site = #{site}
  1517. <if test = "customerID != null and customerID != ''">
  1518. AND CustomerID LIKE '%' + #{customerID} + '%'
  1519. </if>
  1520. <if test = "customerName != null and customerName != ''">
  1521. AND CustomerName LIKE '%' + #{customerName} + '%'
  1522. </if>
  1523. </where>
  1524. </select>
  1525. <!-- 校验物料属性设置中的模板是否已存在 -->
  1526. <select id="getPA" parameterType="com.gaotao.modules.pms.data.QcTemplateData" resultType="com.gaotao.modules.pms.data.QcTemplateData">
  1527. SELECT
  1528. site,
  1529. bu_no,
  1530. attribute_no,
  1531. template_id,
  1532. sampling_level_no,
  1533. sampling_programme_no,
  1534. attribute_type,
  1535. resource_id,
  1536. operation
  1537. FROM qc_attribute_template
  1538. WHERE site = #{site} and bu_no = #{buNo} and attribute_no = #{attributeNo} and attribute_type = #{attributeType} and template_id = #{templateId} and resource_id = #{resourceID} and operation = #{operation}
  1539. </select>
  1540. <!-- 校验物料属性设置中的模板是否已存在 -->
  1541. <select id="getPA2" parameterType="com.gaotao.modules.pms.data.QcTemplateData" resultType="com.gaotao.modules.pms.data.QcTemplateData">
  1542. SELECT
  1543. site,
  1544. bu_no,
  1545. attribute_no,
  1546. template_id,
  1547. sampling_level_no,
  1548. sampling_programme_no,
  1549. attribute_type,
  1550. manufacturer_id
  1551. FROM qc_attribute_template
  1552. WHERE site = #{site} and bu_no = #{buNo} and attribute_no = #{attributeNo} and attribute_type = #{attributeType} and template_id = #{templateId} and manufacturer_id = #{manufacturerID}
  1553. </select>
  1554. <!-- 校验物料属性设置中的模板是否已存在 -->
  1555. <select id="getPA3" parameterType="com.gaotao.modules.pms.data.QcTemplateData" resultType="com.gaotao.modules.pms.data.QcTemplateData">
  1556. SELECT
  1557. site,
  1558. bu_no,
  1559. attribute_no,
  1560. template_id,
  1561. sampling_level_no,
  1562. sampling_programme_no,
  1563. attribute_type,
  1564. customer_id
  1565. FROM qc_attribute_template
  1566. WHERE site = #{site} and bu_no = #{buNo} and attribute_no = #{attributeNo} and attribute_type = #{attributeType} and template_id = #{templateId} and customer_id = #{customerID}
  1567. </select>
  1568. <select id="getStandardOperation" resultType="com.gaotao.modules.pms.entity.StandardOperationEntity">
  1569. select
  1570. id,
  1571. site,
  1572. operation_desc
  1573. from standard_operation
  1574. where site = #{site}
  1575. </select>
  1576. </mapper>