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.

2201 lines
95 KiB

11 months ago
11 months ago
7 months ago
7 months ago
8 months ago
8 months ago
9 months ago
6 months ago
8 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.schedule.mapper.ScheduleMapper">
  4. <update id="closeOrOpenProduceOrder">
  5. Update SOScheduledRouting
  6. Set ClosedFlag=#{closedFlag}
  7. , Closedby=#{username}
  8. , ClosedDate=#{closedDate}
  9. Where Site = #{site}
  10. and OrderNo = #{orderNo}
  11. and ItemNo = #{itemNo}
  12. and SeqNo = #{seqNo}
  13. </update>
  14. <update id="pauseOrReopenProduceOrder">
  15. Update SOScheduledRouting
  16. Set ParkFlag=#{parkFlag}
  17. Where Site = #{site}
  18. and OrderNo = #{orderNo}
  19. and ItemNo = #{itemNo}
  20. and SeqNo = #{seqNo}
  21. </update>
  22. <update id="costRollUpProduceOrder">
  23. Update ShopOrder
  24. Set CostRollUpFlag= #{costRollUpFlag}
  25. Where Site = #{site}
  26. and OrderNo = #{orderNo}
  27. </update>
  28. <update id="manualProduceOrder">
  29. Update ShopOrder
  30. Set ManualFlag=#{manualFlag}
  31. Where Site = #{site}
  32. and OrderNo = #{orderNo}
  33. </update>
  34. <update id="repairSOFlagProduceOrder">
  35. Update ShopOrder
  36. Set RepairSOFlag=#{repairSOFlag}
  37. Where Site = #{site}
  38. and OrderNo = #{orderNo}
  39. </update>
  40. <!--查询加工中心机台的信息-->
  41. <select id="getResourceLIst" parameterType="SearchScheduleData" resultType="ResourceOutData">
  42. SELECT wcr.Site site, wcr.WorkCenterNo workCenterNo, wcr.ResourceID resourceId, wcr.ResourceDesc resourceDEsc,
  43. wcr.Efficiency efficiency,
  44. wcr.Utilization utilization, wcr.Active active, wcr.Remark Remark, wcr.CreatedDate createdDate, wcr.CalendarID
  45. calendarId, wcr.VirturlFlag virturlFlag
  46. FROM WorkCenterResource wcr
  47. <where>
  48. wcr.Site = site
  49. <if test="workCenterNo != null and workCenterNo != ''">
  50. AND wcr.WorkCenterNo= #{workCenterNo}
  51. </if>
  52. <if test="resourceId != null and resourceId != ''">
  53. AND wcr.ResourceID = #{resourceId}
  54. </if>
  55. </where>
  56. </select>
  57. <!--查询机台+排产日期的休息信息-->
  58. <select id="getResourceRestList" parameterType="SearchScheduleData" resultType="ShiftInfoData">
  59. Select top 10 ScheduleDate shiftDate, CONVERT(Varchar(200), (Case when ExceptDuration1<![CDATA[ <> ]]>0 then
  60. CONVERT(Varchar(10),Convert(float,ExceptTime1)) + '/' + CONVERT(Varchar(10),Convert(float,ExceptDuration1)) else
  61. '' end)
  62. +' ; '+
  63. (Case when ExceptDuration2<![CDATA[ <> ]]>0 then CONVERT(Varchar(10),Convert(float,ExceptTime2)) + '/' +
  64. CONVERT(Varchar(10),Convert(float,ExceptDuration2)) else '' end)
  65. +' ; '+
  66. (Case when ExceptDuration3<![CDATA[ <> ]]>0 then CONVERT(Varchar(10),Convert(float,ExceptTime3)) + '/' +
  67. CONVERT(Varchar(10),Convert(float,ExceptDuration3)) else '' end)
  68. +' ; '+
  69. (Case when ExceptDuration4<![CDATA[ <> ]]>0 then CONVERT(Varchar(10),Convert(float,ExceptTime4)) + '/' +
  70. CONVERT(Varchar(10),Convert(float,ExceptDuration4)) else '' end)
  71. +' ; '+
  72. (Case when ExceptDuration5<![CDATA[ <> ]]>0 then CONVERT(Varchar(10),Convert(float,ExceptTime5)) + '/' +
  73. CONVERT(Varchar(10),Convert(float,ExceptDuration5)) else '' end)
  74. +' ; '+
  75. (Case when ExceptDuration6<![CDATA[ <> ]]>0 then CONVERT(Varchar(10),Convert(float,ExceptTime6)) + '/' +
  76. CONVERT(Varchar(10),Convert(float,ExceptDuration6)) else '' end)
  77. ) as shiftInfo from Calendar_Exception cde
  78. <where>
  79. AND cde.Site = #{site}
  80. AND cde.CalendarID = #{calendarId}
  81. AND cde.ScheduleDate <![CDATA[ >= ]]> #{scheduleDate}
  82. </where>
  83. </select>
  84. <!--按照条件查询工单的数据-->
  85. <select id="getShopOrderList" parameterType="SearchScheduleData" resultType="ShopOrderOutData">
  86. Select T.Site site, T.OrderNo orderNo, T.ItemNo itemNo, T.OperationDesc itemDesc, T.PartNo partNo,
  87. P.PartDescription partDesc, P.Spec spec,
  88. D.LotSize lotSize, T.QtyReported qtyReported, D.NeedDate needDate, T.PreItemNo PreItemNo, S1.OperationDesc
  89. PreItemDesc, S1.ScheduledFlag preScheduledFlag,
  90. T.NextItemNo nextItemNo, S2.OperationDesc nextItemDesc, S2.ScheduledFlag nextScheduledFlag, D.CustomerID
  91. customerId, P.ConfigurationTemplateID customerName,
  92. D.EnterDate enterDate, dbo.Get_SOOpsScheduleAvailResource(T.Site,T.OrderNo,T.WorkCenterNo,T.ItemNo)
  93. availResource, T.WorkCenterNo workCenterNo,
  94. T.MachRunFactor machRunFactor, T.MachSetupTime machSetupTime, T.FactorUnit factorUnit, T.ScheduledFlag
  95. scheduledFlag, D.RoutingRevNo routingRevNo,
  96. T.QtyScheduled qtyScheduled,(round(T.QtyRequired,3) - Round(T.QtyScheduled,3)) qtyToSchedule,
  97. Isnull(S1.QtyScheduled,0.0) qtyScheduledPreOps,
  98. dbo.getScheduleToPlanTime(D.LotSize, T.MachSetupTime, T.MachRunFactor, T.FactorUnit, t.Efficiency)
  99. scheduleToPlanTime,
  100. D.OriSOOrderNo oriSOOrderNo, P.Remark custPartNo, 1*t.Efficiency efficiency, D.CostRollUpFlag costRollUpFlag,
  101. isnull(S1.QtyApprove,0.0) qtyApprovedPreOps,
  102. d.ManualFlag manualFlag, d.RepairSOFlag repairSOFlag
  103. from SORouting as T
  104. Left Join ShopOrder as D On T.Site=D.Site and T.OrderNo=D.OrderNo
  105. Left Join Part as P On T.Site=P.Site and T.PartNo=P.PartNo
  106. Left Join SORouting as S1 On T.Site=S1.Site and T.OrderNo=S1.OrderNo and T.PreItemNo=S1.ItemNo
  107. Left Join SORouting as S2 On T.Site=S2.Site and T.OrderNo=S2.OrderNo and T.NextItemNo=S2.ItemNo
  108. <where>
  109. Round(T.QtyScheduled,3) <![CDATA[ < ]]> round(T.QtyRequired,3) and T.ClosedFlag = 'N'
  110. <if test="username != null and username != ''">
  111. and T.site in (Select Site from AccessSite where upper(UserID)=#{username})
  112. </if>
  113. and T.OrderNo<![CDATA[ <> ]]>'9999' and isnull(D.Status,'')<![CDATA[ <> ]]>'已取消' and isnull(D.Status,'')
  114. <![CDATA[ <> ]]>'已计划'
  115. and isnull(D.Status,'')<![CDATA[ <> ]]>'已关闭'
  116. <if test="enterTime1 != null">
  117. and D.EnterDate<![CDATA[ >= ]]> #{enterTime1}
  118. </if>
  119. <if test="enterTime2 != null">
  120. and D.EnterDate-1<![CDATA[<]]> #{enterTime2}
  121. </if>
  122. <if test="needTime1 != null">
  123. and D.NeedDate<![CDATA[ >= ]]>#{needTime1}
  124. </if>
  125. <if test="needTime2 != null">
  126. and D.NeedDate<![CDATA[ <= ]]>#{needTime2}
  127. </if>
  128. <if test="site != null and site != ''">
  129. AND T.Site like '%' + #{site} + '%'
  130. </if>
  131. <if test="partNo != null and partNo != ''">
  132. AND T.PartNo like '%' + #{partNo} + '%'
  133. </if>
  134. AND Rtrim(T.WorkCenterNo) like '%' + #{workCenterNo} + '%'
  135. <if test="scheduledFlag != null and scheduledFlag != ''">
  136. AND Isnull(S1.ScheduledFlag, 'Y') = #{scheduledFlag}
  137. </if>
  138. <if test='preScheduledFlag != null and preScheduledFlag == "Y"'>
  139. and Isnull(S1.ScheduledFlag,'Y') = 'Y'
  140. </if>
  141. AND dbo.Get_SOOpsScheduleAvailResource(T.Site,T.OrderNo,T.WorkCenterNo,T.ItemNo) like '%' + #{resourceId} +
  142. '(%'
  143. </where>
  144. /*设置排序规则*/
  145. <if test="sortField == null || sortField == ''">
  146. Order by D.NeedDate
  147. </if>
  148. <if test="sortField != null and sortField == 'needDate'">
  149. Order by D.NeedDate
  150. </if>
  151. <if test="sortField != null and sortField == 'orderNo'">
  152. Order by T.OrderNo
  153. </if>
  154. <if test="sortField != null and sortField == 'partNo'">
  155. Order by T.PartNo
  156. </if>
  157. </select>
  158. <!--按照条件查询工单的数据-->
  159. <select id="getOrderScheduleList" parameterType="SearchScheduleData" resultType="ScheduleData">
  160. select
  161. T.Site site,
  162. T.OrderNo orderNo,
  163. T.ItemNo itemNo,
  164. S.OperationDesc itemDesc,
  165. S.PartNo partNo,
  166. P.PartDescription partDesc,
  167. P.Spec spec,
  168. T.QtyRequired qtyRequired,
  169. T.QtyReported qtyReported,
  170. (T.QtyRequired - T.QtyReported) as qtyToReport,
  171. D.NeedDate needDate,
  172. S.PreItemNo preItemNo,
  173. S1.OperationDesc preItemDesc,
  174. S1.ScheduledFlag preScheduledFlag,
  175. S.NextItemNo nextItemNo,
  176. S2.OperationDesc nextItemDesc,
  177. S2.ScheduledFlag nextScheduledFlag,
  178. D.CustomerID customerId,
  179. dbo.Get_CustomerDesc (D.Site, D.CustomerID) customerName,
  180. D.EnterDate enterDate,
  181. dbo.Get_SOOpsScheduleAvailResource (
  182. T.Site,
  183. S.OrderNo,
  184. T.S_WorkCenterNo,
  185. T.ItemNo
  186. ) availResource,
  187. T.S_WorkCenterNo workCenterNo,
  188. S.MachRunFactor machRunFactor,
  189. S.MachSetupTime machSetupTime,
  190. S.FactorUnit factorUnit,
  191. T.ClosedFlag closedFlag,
  192. E.S_ScheduledSeqNo scheduledSeqNo,
  193. T.PlanStartTime planStartTime,
  194. T.PlanFinishTime planFinishTime,
  195. T.S_ResourceID resourceId,
  196. T.TimeRequired timeRequired,
  197. T.SeqNo seqNo,
  198. T.SelectedFlag selectedFlag,
  199. T.SourceFlag sourceFlag,
  200. S1.QtyScheduled qtyScheduledPreOps,
  201. T.ParkFlag parkFlag,
  202. T.TimeRequired_Original timeRequiredOriginal,
  203. T.QtyRequired_Original qtyRequiredOriginal,
  204. S1.PlanStartTime preOpsPlanStartTime,
  205. S1.PlanFinishTime preOpsPlanFinishTime,
  206. T.Remark remark,
  207. D.OriSOOrderNo oriSOOrderNo,
  208. P.Remark custPartNo,
  209. T.Efficiency eficiency,
  210. (Case when dbo.Get_SOOpsJobEstFinishDate(T.Site,T.OrderNo,T.ItemNo,T.SeqNo)<![CDATA[ <= ]]>T.PlanFinishTime then
  211. 0.0
  212. else round((convert(float,dbo.Get_SOOpsJobEstFinishDate(T.Site,T.OrderNo,T.ItemNo,T.SeqNo)) -
  213. convert(float,T.PlanFinishTime)) * 24,2) end) delayHours,
  214. dbo.Get_SOSchedule_RecordIdentity(T.Site,T.PlanStartTime,T.PlanFinishTime,D.NeedDate,S1.PlanStartTime,S1.PlanFinishTime) mergeStatusCon,
  215. T.mat_issueflag costRollUpFlag,
  216. dbo.getCurrentScheduleColorStyle(T.QtyReported, T.QtyRequired, T.PlanFinishTime, T.ClosedFlag) colorStyle
  217. from SOScheduledList as E,SOScheduledRouting as T
  218. Left Join ShopOrder as D On T.Site=D.Site and T.OrderNo=D.OrderNo
  219. ,SORouting as S
  220. Left Join Part as P On S.Site=P.Site and S.PartNo=P.PartNo
  221. Left Join SORouting as S1 On S.Site=S1.Site and S.OrderNo=S1.OrderNo and S.PreItemNo=S1.ItemNo
  222. Left Join SORouting as S2 On S.Site=S2.Site and S.OrderNo=S2.OrderNo and S.NextItemNo=S2.ItemNo
  223. <where>
  224. T.Site=S.Site and T.OrderNo=S.OrderNo and T.ItemNo=S.ItemNo and E.Site=T.Site and E.LinkedSeqNo=T.SeqNo
  225. <if test="site != null and site != ''">
  226. AND E.Site like '%' + #{site} + '%'
  227. </if>
  228. AND RTrim(T.S_WorkCenterNo) like #{workCenterNo} AND T.S_WorkCenterNo <![CDATA[<>]]> 'FQC'
  229. AND RTrim(E.ResourceID) like '%' + #{resourceId} + '%'
  230. </where>
  231. Order by E.S_ScheduledSeqNo
  232. </select>
  233. <!--查询-待生产工单-->
  234. <select id="getProduceScheduleData" parameterType="SearchScheduleData" resultType="ScheduleData">
  235. <choose>
  236. <when test='exportFlag != null and exportFlag == "Y"'>
  237. Select T.Site site, T.OrderNo orderNo, T.ItemNo itemNo, D.OperationDesc itemDesc, D.PartNo partNo,
  238. </when>
  239. <otherwise>
  240. Select T.Site site, T.OrderNo orderNo, T.ItemNo itemNo, D.OperationDesc itemDesc, D.PartNo partNo,
  241. </otherwise>
  242. </choose>
  243. P.PartDescription partDesc,
  244. P.Spec spec,
  245. T.SeqNo seqNo,
  246. T.QtyRequired qtyRequired,
  247. T.QtyReported qtyReported,
  248. (T.QtyRequired - T.QtyReported) as qtyToReport,
  249. T.QtyApprove qtyApprove,
  250. ROUND(T.TimeRequired, 3) timeRequired,
  251. T.TimeReported timeReported,
  252. T.PlanStartTime planStartTime,
  253. T.PlanFinishTime planFinishTime,
  254. T.BarcodeID barcodeId,
  255. T.Remark remark,
  256. T.Crewsize crewSize,
  257. T.ClosedFlag closedFlag,
  258. T.QtyScrapt qtyScrapt,
  259. T.OutWorkFlag outWorkFlag,
  260. T.S_ScheduledDate scheduledDate,
  261. T.S_ResourceID resourceId,
  262. dbo.getWorkCenterResourceDesc(T.Site, t.S_WorkCenterNo, T.S_ResourceID) resourceDesc,
  263. T.serial_number serialNumber,
  264. T.S_ShiftNo shiftNo,
  265. D.MachSetupTime machSetupTime,
  266. D.MachRunFactor machRunFactor,
  267. D.FactorUnit factorUnit,
  268. D.Efficiency efficiency,
  269. D.NextItemNo nextItemNo,
  270. dbo.Get_SOOpsDescription(T.Site,T.OrderNo,D.NextItemNo) nextItemDesc,
  271. D.PreItemNo preItemNo,
  272. dbo.Get_SOOpsDescription(T.Site,T.OrderNo,D.PreItemNo) preItemDesc,
  273. SO.NeedDate needDate,
  274. T.ParkFlag parkFlag,
  275. dbo.Get_SOOpsPreResourceInfo(T.Site, T.OrderNo, T.ItemNo) preResourceInfo,
  276. dbo.Get_SOOpsPreQtyFinished(T.Site, T.OrderNo, T.ItemNo) preQtyFinished,
  277. P.ConfigurationTemplateID customerName,
  278. P.Remark custPartNo,
  279. t.S_WorkCenterNo workCenterNo,
  280. dbo.Get_WorkCenterDesc(T.Site, T.S_WorkCenterNo) workCenterDesc,
  281. T.QtyRequired_Original qtyRequiredOriginal,
  282. SO.orderType,
  283. T.ClosedBy closedBy,
  284. T.ClosedDate closedDate,
  285. T.mat_issueflag matIssueFlag,
  286. T.plate_issueflag plateIssueFlag,
  287. T.tool_issueflag toolIssueFlag,
  288. so.bu_no buNo
  289. from SOScheduledRouting as T
  290. Left Join SOScheduledList as E on E.Site=T.Site and E.LinkedSeqNo=T.SeqNo and T.S_ResourceID = E.ResourceID,
  291. SORouting as D,Part as P,ShopOrder as SO
  292. <where>
  293. T.Site=D.Site and T.OrderNo=D.OrderNo and T.ItemNo=D.ItemNo and D.Site=P.Site and D.PartNo=P.PartNo
  294. and T.site in (Select Site from AccessSite where upper(UserID)=#{username})
  295. and T.Site=SO.Site and T.OrderNo=SO.OrderNo and T.OrderNo<![CDATA[ <> ]]>'9999'
  296. <if test="site != null and site != ''">
  297. AND T.Site like '%' + #{site} + '%'
  298. </if>
  299. <if test="planStartTime1 != null">
  300. and T.PlanStartTime<![CDATA[ >= ]]> #{planStartTime1}
  301. </if>
  302. <if test="planStartTime2 != null">
  303. and T.PlanStartTime<![CDATA[ <= ]]> #{planStartTime2}
  304. </if>
  305. <if test="resourceId != null and resourceId != ''">
  306. AND T.S_ResourceID = #{resourceId}
  307. </if>
  308. <if test="orderNo != null and orderNo != ''">
  309. AND T.OrderNo like '%' + #{orderNo} + '%'
  310. </if>
  311. <if test="seqNo != null and seqNo != ''">
  312. AND T.SeqNo like '%' + #{seqNo} + '%'
  313. </if>
  314. <if test='closedFlag != null and closedFlag == "N"'>
  315. and T.ClosedFlag = #{closedFlag}
  316. </if>
  317. </where>
  318. Order by SO.bu_no, T.S_ResourceID, ISNULL(T.serial_number, 999999) asc
  319. <if test='exportFlag == null or exportFlag == "N"'>
  320. OFFSET #{page} ROWS FETCH NEXT #{limit} ROWS ONLY
  321. </if>
  322. </select>
  323. <!--查询-待生产工单总数-->
  324. <select id="countProduceScheduleData" parameterType="SearchScheduleData" resultType="java.lang.Integer">
  325. Select COUNT(1)
  326. from SOScheduledRouting as T
  327. Left Join SOScheduledList as E on E.Site=T.Site and E.LinkedSeqNo=T.SeqNo and T.S_ResourceID = E.ResourceID,
  328. SORouting as D,Part as P,ShopOrder as SO
  329. <where>
  330. T.Site=D.Site and T.OrderNo=D.OrderNo and T.ItemNo=D.ItemNo and D.Site=P.Site and D.PartNo=P.PartNo
  331. and T.site in (Select Site from AccessSite where upper(UserID)=#{username})
  332. and T.Site=SO.Site and T.OrderNo=SO.OrderNo and T.OrderNo<![CDATA[ <> ]]>'9999'
  333. <if test="site != null and site != ''">
  334. AND T.Site like '%' + #{site} + '%'
  335. </if>
  336. <if test="planStartTime1 != null">
  337. and T.PlanStartTime<![CDATA[ >= ]]> #{planStartTime1}
  338. </if>
  339. <if test="planStartTime2 != null">
  340. and T.PlanStartTime<![CDATA[ <= ]]> #{planStartTime2}
  341. </if>
  342. <if test="resourceId != null and resourceId != ''">
  343. AND T.S_ResourceID = #{resourceId}
  344. </if>
  345. <if test="orderNo != null and orderNo != ''">
  346. AND T.OrderNo like '%' + #{orderNo} + '%'
  347. </if>
  348. <if test="seqNo != null and seqNo != ''">
  349. AND T.SeqNo like '%' + #{seqNo} + '%'
  350. </if>
  351. <if test='closedFlag != null and closedFlag == "N"'>
  352. and T.ClosedFlag = #{closedFlag}
  353. </if>
  354. </where>
  355. </select>
  356. <!--查询操作员信息列表-->
  357. <select id="getOperatorList" parameterType="OperatorOutData" resultType="com.gaotao.modules.shopOrder.entity.OperatorData">
  358. SELECT
  359. op.Site site,
  360. op.OperatorID operatorId,
  361. op.OperatorName operatorName,
  362. op.Active status
  363. FROM Operator op
  364. <where>
  365. op.Site IN (SELECT Site FROM AccessSite WHERE UPPER(UserID) = #{username})
  366. <if test="site != null and site != ''">
  367. AND op.Site = #{site}
  368. </if>
  369. <if test="operatorId != null and operatorId != ''">
  370. AND op.OperatorID like '%' + #{operatorId} + '%'
  371. </if>
  372. <if test="operatorName != null and operatorName != ''">
  373. AND op.OperatorName like '%' + #{operatorName} + '%'
  374. </if>
  375. <if test="status != null and status != ''">
  376. AND op.Active = #{status}
  377. </if>
  378. </where>
  379. </select>
  380. <!--查询操作员信息-->
  381. <select id="getOperatorData" parameterType="OperatorOutData" resultType="OperatorOutData">
  382. SELECT op.Site site, op.OperatorID operatorId, op.OperatorName operatorName, op.Active status
  383. FROM Operator op
  384. <where>
  385. op.Site IN (SELECT Site FROM AccessSite WHERE UPPER(UserID) = #{username})
  386. <if test="site != null and site != ''">
  387. AND op.Site = #{site}
  388. </if>
  389. <if test="operatorId != null and operatorId != ''">
  390. AND op.OperatorID = #{operatorId}
  391. </if>
  392. <if test="operatorName != null and operatorName != ''">
  393. AND op.OperatorName = #{operatorName}
  394. </if>
  395. </where>
  396. </select>
  397. <!--获取操作员列表-->
  398. <select id="getOperatorList2" parameterType="java.util.Map" resultType="java.util.Map">
  399. SELECT
  400. id,
  401. site,
  402. order_no AS orderNo,
  403. item_no AS itemNo,
  404. seq_no AS seqNo,
  405. roll_no AS rollNo,
  406. created_by AS createdBy,
  407. created_date AS createdDate,
  408. operator,
  409. (SELECT OperatorName FROM Operator WHERE OperatorID = sol.operator AND Site = sol.site) AS operatorName,
  410. is_on_duty AS isOnDuty,
  411. on_duty_time AS onDutyTime,
  412. off_duty_time AS offDutyTime,
  413. batch_no AS batchNo,
  414. remark
  415. FROM sfdc_operator_list sol
  416. <where>
  417. <if test="site != null and site != ''">
  418. AND site = #{site}
  419. </if>
  420. <if test="orderNo != null and orderNo != ''">
  421. AND order_no = #{orderNo}
  422. </if>
  423. <if test="itemNo != null">
  424. AND item_no = #{itemNo}
  425. </if>
  426. <if test="seqNo != null and seqNo != ''">
  427. AND seq_no = #{seqNo}
  428. </if>
  429. <if test="isOnDuty != null and isOnDuty != ''">
  430. AND is_on_duty = #{isOnDuty}
  431. </if>
  432. </where>
  433. ORDER BY on_duty_time DESC
  434. </select>
  435. <!--添加操作员上岗-->
  436. <insert id="addOperatorOnDuty" parameterType="java.util.Map">
  437. INSERT INTO sfdc_operator_list (
  438. site,
  439. order_no,
  440. item_no,
  441. seq_no,
  442. roll_no,
  443. created_by,
  444. created_date,
  445. operator,
  446. is_on_duty,
  447. on_duty_time,
  448. batch_no,
  449. remark
  450. ) VALUES (
  451. #{site},
  452. #{orderNo},
  453. #{itemNo},
  454. #{seqNo},
  455. #{rollNo},
  456. #{createdBy},
  457. #{createdDate},
  458. #{operator},
  459. #{isOnDuty},
  460. #{onDutyTime},
  461. #{batchNo},
  462. #{remark}
  463. )
  464. </insert>
  465. <!--操作员下岗-->
  466. <update id="removeOperatorOnDuty" parameterType="java.util.Map">
  467. UPDATE sfdc_operator_list
  468. SET is_on_duty = #{isOnDuty},
  469. off_duty_time = #{offDutyTime}
  470. <where>
  471. <if test="id != null">
  472. AND id = #{id}
  473. </if>
  474. <if test="site != null and site != ''">
  475. AND site = #{site}
  476. </if>
  477. <if test="orderNo != null and orderNo != ''">
  478. AND order_no = #{orderNo}
  479. </if>
  480. <if test="itemNo != null">
  481. AND item_no = #{itemNo}
  482. </if>
  483. <if test="seqNo != null and seqNo != ''">
  484. AND seq_no = #{seqNo}
  485. </if>
  486. <if test="operator != null and operator != ''">
  487. AND operator = #{operator}
  488. </if>
  489. </where>
  490. </update>
  491. <!--删除操作员数据-->
  492. <delete id="deleteOperatorData" parameterType="java.util.Map">
  493. DELETE FROM sfdc_operator_list
  494. <where>
  495. <if test="id != null">
  496. AND id = #{id}
  497. </if>
  498. <if test="site != null and site != ''">
  499. AND site = #{site}
  500. </if>
  501. <if test="orderNo != null and orderNo != ''">
  502. AND order_no = #{orderNo}
  503. </if>
  504. <if test="itemNo != null">
  505. AND item_no = #{itemNo}
  506. </if>
  507. <if test="seqNo != null and seqNo != ''">
  508. AND seq_no = #{seqNo}
  509. </if>
  510. <if test="operator != null and operator != ''">
  511. AND operator = #{operator}
  512. </if>
  513. </where>
  514. </delete>
  515. <!--更新操作员时间-->
  516. <update id="updateOperatorTime" parameterType="java.util.Map">
  517. UPDATE sfdc_operator_list
  518. SET
  519. on_duty_time = #{onDutyTime},
  520. off_duty_time = #{offDutyTime}
  521. <where>
  522. <if test="id != null">
  523. AND id = #{id}
  524. </if>
  525. <if test="site != null and site != ''">
  526. AND site = #{site}
  527. </if>
  528. <if test="orderNo != null and orderNo != ''">
  529. AND order_no = #{orderNo}
  530. </if>
  531. <if test="itemNo != null">
  532. AND item_no = #{itemNo}
  533. </if>
  534. <if test="seqNo != null and seqNo != ''">
  535. AND seq_no = #{seqNo}
  536. </if>
  537. <if test="operator != null and operator != ''">
  538. AND operator = #{operator}
  539. </if>
  540. </where>
  541. </update>
  542. <!--更新派工单MRB信息-->
  543. <update id="updateScheduleMrbInfo" parameterType="java.util.Map">
  544. UPDATE SOScheduledRouting
  545. SET
  546. mrb = #{mrb},
  547. mrb_inspection_report = #{mrbInspectionReport},
  548. mrb_remark = #{mrbRemark}
  549. WHERE
  550. Site = #{site}
  551. AND OrderNo = #{orderNo}
  552. AND ItemNo = #{itemNo}
  553. AND SeqNo = #{seqNo}
  554. </update>
  555. <!--查询派工单MRB信息-->
  556. <select id="getScheduleMrbInfo" parameterType="java.util.Map" resultType="java.util.Map">
  557. SELECT
  558. mrb,
  559. mrb_inspection_report AS mrbInspectionReport,
  560. mrb_remark AS mrbRemark
  561. FROM SOScheduledRouting
  562. WHERE
  563. Site = #{site}
  564. AND OrderNo = #{orderNo}
  565. AND ItemNo = #{itemNo}
  566. AND SeqNo = #{seqNo}
  567. </select>
  568. <!--只更新操作员上岗时间-->
  569. <update id="updateOnDutyTime" parameterType="java.util.Map">
  570. UPDATE sfdc_operator_list
  571. SET on_duty_time = #{onDutyTime}
  572. <where>
  573. <if test="id != null">
  574. AND id = #{id}
  575. </if>
  576. <if test="site != null and site != ''">
  577. AND site = #{site}
  578. </if>
  579. <if test="orderNo != null and orderNo != ''">
  580. AND order_no = #{orderNo}
  581. </if>
  582. <if test="itemNo != null">
  583. AND item_no = #{itemNo}
  584. </if>
  585. <if test="seqNo != null and seqNo != ''">
  586. AND seq_no = #{seqNo}
  587. </if>
  588. <if test="operator != null and operator != ''">
  589. AND operator = #{operator}
  590. </if>
  591. </where>
  592. </update>
  593. <!--按照派工单号查询派工单的数据-->
  594. <select id="getScheduleDataBySeqNo" parameterType="java.lang.String" resultType="ScheduleData">
  595. Select
  596. T.Site site,
  597. T.OrderNo orderNo,
  598. T.ItemNo itemNo,
  599. D.OperationDesc itemDesc,
  600. D.PartNo partNo,
  601. P.PartDescription partDesc,
  602. P.Spec spec,
  603. SO.bu_no buNo,
  604. T.SeqNo seqNo,
  605. T.QtyRequired qtyRequired,
  606. T.QtyReported qtyReported,
  607. (SELECT SUM(RollQty) FROM SFDC_Rolls S WHERE s.Site = T.SITE AND S.OrderNo = T.OrderNo AND s.VirtualNewRollFlag ='N' and s.RollType ='下道流转') qtyApprove,
  608. ROUND(T.TimeRequired, 3) timeRequired,
  609. T.TimeReported timeReported,
  610. T.PlanStartTime planStartTime,
  611. T.PlanFinishTime planFinishTime,
  612. T.BarcodeID as barcodeId,
  613. T.Remark remark,
  614. T.Crewsize crewSize,
  615. T.ClosedFlag closedFlag,
  616. T.QtyScrapt qtyScrapt,
  617. T.OutWorkFlag outWorkFlag,
  618. T.S_ScheduledDate scheduledDate,
  619. t.S_WorkCenterNo workCenterNo,
  620. T.S_ResourceID resourceId,
  621. dbo.getWorkCenterResourceDesc(T.Site, t.S_WorkCenterNo, T.S_ResourceID) resourceDesc,
  622. E.S_ScheduledSeqNo scheduledSeqNo,
  623. T.S_ShiftNo shiftNo,
  624. D.MachSetupTime machSetupTime,
  625. D.MachRunFactor machRunFactor,
  626. D.FactorUnit factorUnit,
  627. D.Efficiency efficiency,
  628. D.NextItemNo nextItemNo,
  629. dbo.Get_SOOpsDescription(T.Site,T.OrderNo,D.NextItemNo) nextItemDesc,
  630. D.PreItemNo preItemNo,
  631. dbo.Get_SOOpsDescription(T.Site,T.OrderNo,D.PreItemNo) preItemDesc,
  632. SO.NeedDate needDate,
  633. T.ParkFlag parkFlag,
  634. P.ConfigurationTemplateID customerName,
  635. P.Remark custPartNo,
  636. t.S_WorkCenterNo workCenterNo,
  637. dbo.Get_WorkCenterDesc(T.Site, T.S_WorkCenterNo) workCenterDesc,
  638. T.QtyRequired_Original qtyRequiredOriginal,
  639. T.ClosedBy closedBy,
  640. T.ClosedDate closedDate,
  641. SO.CostRollUpFlag costRollUpFlag,
  642. SO.RepairSOFlag repairSOFlag,
  643. SO.ManualFlag manualFlag,
  644. T.row_count,
  645. T.roll_count,
  646. T.carrier_no,
  647. (SELECT TOP 1 ISNULL(WC.packing_list_flag, 'N')
  648. FROM WorkCenter WC
  649. WHERE WC.Site = T.Site
  650. AND WC.WorkCenterNo = T.S_WorkCenterNo) as packingListFlag,
  651. d.production_qty,
  652. d.total_roll_qty,
  653. d.total_per_volume,
  654. d.Remark as soRemark,
  655. SO.batch_no as batchNo,
  656. (SELECT count(1) FROM SFDC_Rolls S WHERE s.Site = T.SITE AND S.OrderNo = T.OrderNo AND s.VirtualNewRollFlag ='N' and s.RollType ='下道流转') as productionRollQty
  657. from SOScheduledRouting as T
  658. Left Join SOScheduledList as E on E.Site = T.Site and E.LinkedSeqNo = T.SeqNo,
  659. SORouting as D, Part as P, ShopOrder as SO
  660. <where>
  661. T.Site=D.Site and T.OrderNo=D.OrderNo and T.ItemNo=D.ItemNo and D.Site=P.Site and D.PartNo=P.PartNo
  662. and T.Site=SO.Site and T.OrderNo=SO.OrderNo and T.OrderNo<![CDATA[ <> ]]>'9999'
  663. AND T.SeqNo = #{seqNo}
  664. </where>
  665. </select>
  666. <select id="countEnabledDownTimeReasonByWorkCenter" resultType="java.lang.Integer">
  667. SELECT COUNT(1)
  668. FROM DowntimeReason A
  669. WHERE A.Site = #{site}
  670. AND A.ReasonCode = #{downTimeCode}
  671. AND ISNULL(A.Active, 'Y') = 'Y'
  672. AND ISNULL(RTRIM(A.WorkCenter_No), '') = #{workCenterNo}
  673. </select>
  674. <select id="countEnabledDefectCodeByWorkCenter" resultType="java.lang.Integer">
  675. SELECT COUNT(1)
  676. FROM InspectionDefectCode A
  677. WHERE A.Site = #{site}
  678. AND A.DefectCode = #{defectCode}
  679. AND ISNULL(A.Active, 'Y') = 'Y'
  680. AND ISNULL(RTRIM(A.workCenter_no), '') = #{workCenterNo}
  681. </select>
  682. <!--获取当前的上机卷信息-->
  683. <select id="getCurrentRollOpsBySeqNo" parameterType="BaseRollData" resultType="SfdcRollOpsData">
  684. SELECT TOP 1 sro.Site site, sro.OrderNo orderNo, sro.RollNo rollNo, sro.ItemNo itemNo, sro.SeqNo seqNo,
  685. sro.ScanedBy scanedBy, sro.ScanedDate scanedDate,
  686. sro.StartProdFlag startProdFlag, sro.FirstSetupBy firstSetupBy, sro.FirstSetupDate firstSetupDate,
  687. sro.LatestSetupBy latestSetupBy,
  688. sro.LatestSetupDate latestSetupDate, sro.FirstEndSetupBy firstEndSetupBy, sro.FirstEndSetupDate
  689. firstEndSetupDate, sro.LatestEndSetupBy latestEndSetupBy,
  690. sro.LatestEndSetupDate latestEndSetupDate, sro.FirstProdBy firstProdBy, sro.FirstProdDate firstProdDate,
  691. sro.LatestProdBy latestProdBy,
  692. sro.LatestProdDate latestProdDate, sro.FirstEndProdBy firstEndProdBy, sro.FirstEndProdDate firstEndProdDate,
  693. sro.LatestEndProdBy latestEndProdBy,
  694. sro.LatestEndProdDate latestEndProdDate, sro.FinishedDate finishedDate, sro.FinishedBy finishedBy,
  695. sro.FinishedFlag finishedFlag, sro.PauseFlag pauseFlag,
  696. sro.Remark remark, sro.QtyReported qtyReported, sro.QtyDefected qtyDefected, sro.ReportedFlag reportedFlag
  697. FROM SFDC_RollOps sro
  698. <where>
  699. sro.Site = #{site} AND sro.SeqNo = #{seqNo}
  700. AND sro.FinishedFlag <![CDATA[<>]]> 'Y' AND sro.PauseFlag <![CDATA[<>]]> 'Y'
  701. </where>
  702. </select>
  703. <!--查询派工单的时间记录信息-->
  704. <select id="getSfdcTimeByCon" parameterType="SearchScheduleData" resultType="SfdcTimeData">
  705. SELECT sth.Site site, sth.OrderNo orderNo,sth.ItemNo itemNo, sth.SeqNo seqNo, sth.HistSeqNo histSeqNo,
  706. sth.RollNo rollNo,
  707. sth.EventTime eventTime, sth.Enteredby enteredby, sth.EventDesc eventDesc, sth.DowntimeCode downtimeCode,
  708. sth.TillTime tillTime,
  709. sth.TillEnteredTime tillEnteredTime, sth.TillEnteredBy tillEnteredBy, sth.CompletedFlag completedFlag,
  710. ROUND(sth.TotalTime, 3) totalTime,
  711. sth.DowntimePhaseIn downtimePhaseIn
  712. FROM SFDC_TimeHist sth
  713. <where>
  714. <if test="site != null and site != ''">
  715. AND sth.Site = #{site}
  716. </if>
  717. <if test="orderNo != null and orderNo != ''">
  718. AND sth.OrderNo = #{orderNo}
  719. </if>
  720. <if test="itemNo != null and itemNo != ''">
  721. AND sth.ItemNo = #{itemNo}
  722. </if>
  723. <if test="seqNo != null and seqNo != ''">
  724. AND sth.SeqNo = #{seqNo}
  725. </if>
  726. <if test="rollNo != null and rollNo != ''">
  727. AND sth.RollNo = #{rollNo}
  728. </if>
  729. </where>
  730. ORDER BY sth.HistSeqNo DESC
  731. </select>
  732. <!--查询工单工序的刀具信息-->
  733. <select id="getOrderToolByCon" parameterType="SearchScheduleData" resultType="ToolInstanceData">
  734. SELECT st.Site site, st.OrderNo orderNo, st.ItemNo itemNo, st.ToolID toolId, th.ToolDescription toolDesc,
  735. th.Spec spec,
  736. st.ToolQty toolQty, th.UMID umid, th.FamilyID familyId, dbo.Get_PartFamilyDesc (st.Site, th.FamilyID)
  737. familyName,
  738. th.Active active, st.Remark remark, st.CreateDate createdDate, st.CreatedBy createdBy
  739. FROM SOTool st
  740. LEFT JOIN ToolHeader th ON st.Site = th.Site AND st.ToolID = th.ToolID
  741. <where>
  742. st.Site = th.Site AND st.ToolID = th.ToolID
  743. <if test="site != null and site != ''">
  744. AND st.Site = #{site}
  745. </if>
  746. <if test="orderNo != null and orderNo != ''">
  747. AND st.OrderNo = #{orderNo}
  748. </if>
  749. <if test="itemNo != null and itemNo != ''">
  750. AND st.ItemNo = #{itemNo}
  751. </if>
  752. </where>
  753. ORDER BY st.ItemNo
  754. </select>
  755. <!--查询派工单的工具记录信息-->
  756. <select id="getSfdcToolByCon" parameterType="SearchScheduleData" resultType="SfdcToolData">
  757. SELECT sth.Site site, sth.OrderNo orderNo, sth.ItemNo itemNo, sth.SeqNo seqNo, sth.HistSeqNo histSeqNo,
  758. sth.RollNo rollNo,
  759. sth.ReportDate reportedDate, sth.Reportedby reportedby, sth.ToolInstanceID toolInstanceID, sth.StartDate
  760. startDate,
  761. sth.FinishDate finishedDate, sth.FinishFlag finishedFlag, sth.Remark remark, sth.StartFromRollNo
  762. startFromRollNo, sth.FinishQty finishQty
  763. FROM SFDC_ToolingHist sth
  764. <where>
  765. <if test="site != null and site != ''">
  766. AND sth.Site = #{site}
  767. </if>
  768. <if test="orderNo != null and orderNo != ''">
  769. AND sth.OrderNo = #{orderNo}
  770. </if>
  771. <if test="itemNo != null and itemNo != ''">
  772. AND sth.ItemNo = #{itemNo}
  773. </if>
  774. <if test="seqNo != null and seqNo != ''">
  775. AND sth.SeqNo = #{seqNo}
  776. </if>
  777. <if test="rollNo != null and rollNo != ''">
  778. AND sth.RollNo = #{rollNo}
  779. </if>
  780. </where>
  781. ORDER BY sth.HistSeqNo DESC
  782. </select>
  783. <!--获取关联的客户ID-->
  784. <select id="getReferenceCustomerId" parameterType="java.lang.String" resultType="java.lang.String">
  785. SELECT ISNULL(ReferenceCustomerID, '') referenceCustomerID
  786. FROM Site
  787. WHERE SiteID = #{site}
  788. </select>
  789. <!--查询工单的bom信息-->
  790. <select id="getOrderBomByCon" parameterType="SearchScheduleData" resultType="OrderBomData">
  791. SELECT
  792. vss.Site site,
  793. vss.OrderNo orderNo,
  794. vss.ItemNo itemNo,
  795. vss.ComponentPartNo componentPartNo,
  796. P.PartDescription partDesc,
  797. P.Spec partSpec,
  798. U.UMName partUm,
  799. vss.QtyAssembly qtyAssembly,
  800. vss.QtyFixedScrapt qtyFixedScrapt,
  801. vss.ScraptFactor scraptFactor,
  802. vss.Remark remark,
  803. vss.QtyRequired qtyRequired,
  804. vss.QtyIssue qtyIssue,
  805. vss.IssueDate issueDate,
  806. vss.QtyReserved qtyReserved,
  807. vss.MatGroup matGroup,
  808. vss.RMType_DB rmTypeDb,
  809. ISNULL(vss.qtyReturn, 0) as qtyReturn,
  810. CAST (
  811. ROUND(CASE WHEN ISNULL(vss.QtyIssue, 0) > ISNULL(vss.qtyRequired, 0) THEN
  812. ISNULL(vss.QtyIssue, 0) - ISNULL(vss.qtyRequired, 0) ELSE 0 END, 6) AS DECIMAL (18, 6)
  813. ) AS theoryQtyReturn
  814. FROM dbo.view_SAP_SOBOM vss
  815. LEFT JOIN Part P ON vss.Site = P.Site AND vss.ComponentPartNo = P.PartNo
  816. LEFT JOIN UM U ON P.Site = U.Site AND P.UMID = U.UMID
  817. <where>
  818. vss.Site = P.Site AND vss.ComponentPartNo = P.PartNo
  819. <if test="site != null and site != ''">
  820. AND vss.Site = #{site}
  821. </if>
  822. <if test="orderNo != null and orderNo != ''">
  823. AND vss.OrderNo = #{orderNo}
  824. </if>
  825. </where>
  826. ORDER BY vss.ItemNo ASC
  827. </select>
  828. <!-- 更新工单BOM备注 -->
  829. <update id="updateOrderBomRemark">
  830. UPDATE SOBOM
  831. SET Remark = #{remark}
  832. WHERE Site = #{site}
  833. AND OrderNo = #{orderNo}
  834. AND ItemNo = #{itemNo}
  835. </update>
  836. <!--查询派工单时的材料记录信息-->
  837. <select id="getSfdcMaterialByCon" parameterType="SearchScheduleData" resultType="SfdcMaterialData">
  838. SELECT
  839. smh.Site site,
  840. smh.OrderNo orderNo,
  841. smh.ItemNo itemNo,
  842. smh.SeqNo seqNo,
  843. smh.HistSeqNo histSeqNo,
  844. smh.RollNo rollNo,
  845. smh.ReportDate reportDate,
  846. smh.Reportedby reportedby,
  847. smh.RMRollNo rmRollNo,
  848. smh.PartNo partNo,
  849. smh.Remark remark,
  850. smh.StartDate startDate,
  851. smh.FinishDate finishedDate,
  852. smh.FinishFlag finishedFlag,
  853. case when smh.FinishFlag = 'Y' then '是' else '否' end as finishedFlagDesc,
  854. smh.HistType histType,
  855. smh.TransGeneratedFlag transGeneratedFlag,
  856. smh.OriginalRMRollNo originalRMRollNo,
  857. smh.UnissueFlag unissueFlag,
  858. case when smh.UnissueFlag = 'Y' then '是' else '否' end as unissueFlagDesc,
  859. ROUND(smh.TransQty, 3) transQty,
  860. ROUND(smh.NetIssueQty, 3) netIssueQty,
  861. smh.OriginalHistSeqNo originalHistSeqNo,
  862. smh.StartFromRollNo startFromRollNo,
  863. smh.KeyRMFlag keyRMFlag,
  864. case when smh.KeyRMFlag = 'Y' then '是' else '否' end as keyRMFlagDesc,
  865. smh.SAPBOMItemNo sAPBOMItemNo,
  866. smh.Setupflag setupflag,
  867. case when smh.Setupflag = 'Y' then '是' else '否' end as setupFlagDesc,
  868. B.PartDescription AS partDesc, --新增字段:物料名称,放到物料编码下面
  869. B.Spec AS Spec ,--新增字段,放到物料名称下面
  870. I.wdr as batchNo,
  871. smh.OriginalHistQty as originalHistQty
  872. FROM SFDC_MaterialHist smh WITH(NOLOCK)
  873. LEFT JOIN Part B WITH(NOLOCK) ON smh.Site = B.Site AND smh.PartNo = B.PartNo
  874. LEFT JOIN inventory_stock I ON SMH.Site = I.Site AND SMH.RMRollNo = I.roll_no
  875. <where>
  876. <if test="site != null and site != ''">
  877. AND smh.Site = #{site}
  878. </if>
  879. <if test="orderNo != null and orderNo != ''">
  880. AND smh.OrderNo = #{orderNo}
  881. </if>
  882. <if test="itemNo != null and itemNo != ''">
  883. AND smh.ItemNo = #{itemNo}
  884. </if>
  885. <if test="seqNo != null and seqNo != ''">
  886. AND smh.SeqNo = #{seqNo}
  887. </if>
  888. <if test="rollNo != null and rollNo != ''">
  889. AND smh.RollNo = #{rollNo}
  890. </if>
  891. <if test="finishedFlag != null and finishedFlag != ''">
  892. AND smh.FinishFlag = #{finishedFlag}
  893. </if>
  894. <if test="keyRMFlag != null and keyRMFlag != ''">
  895. AND smh.KeyRMFlag = #{keyRMFlag}
  896. </if>
  897. <if test="histType != null and histType != ''">
  898. AND smh.HistType = #{histType}
  899. </if>
  900. <if test="bomItemNo != null and bomItemNo > -1">
  901. AND smh.SAPBOMItemNo = #{bomItemNo}
  902. </if>
  903. <if test="histSeqNo != null and histSeqNo > 0">
  904. AND smh.HistSeqNo = #{histSeqNo}
  905. </if>
  906. </where>
  907. ORDER BY (CASE WHEN smh.FinishFlag = 'N' THEN 1 ELSE 999 END ) ASC, smh.HistSeqNo DESC
  908. </select>
  909. <!--按照条件查询上机卷记录-->
  910. <select id="getSfdcRollOpsByCon" parameterType="SearchScheduleData" resultType="SfdcRollOpsData">
  911. SELECT sro.Site site, sro.OrderNo orderNo, sro.RollNo rollNo, sro.ItemNo itemNo, sro.SeqNo seqNo, sro.ScanedBy
  912. scanedBy, sro.ScanedDate scanedDate,
  913. sro.StartProdFlag startProdFlag, sro.FirstSetupBy firstSetupBy, sro.FirstSetupDate firstSetupDate,
  914. sro.LatestSetupBy latestSetupBy,
  915. sro.LatestSetupDate latestSetupDate, sro.FirstEndSetupBy firstEndSetupBy, sro.FirstEndSetupDate
  916. firstEndSetupDate, sro.LatestEndSetupBy latestEndSetupBy,
  917. sro.LatestEndSetupDate latestEndSetupDate, sro.FirstProdBy firstProdBy, sro.FirstProdDate firstProdDate,
  918. sro.LatestProdBy latestProdBy,
  919. sro.LatestProdDate latestProdDate, sro.FirstEndProdBy firstEndProdBy, sro.FirstEndProdDate firstEndProdDate,
  920. sro.LatestEndProdBy latestEndProdBy,
  921. sro.LatestEndProdDate latestEndProdDate, sro.FinishedDate finishedDate, sro.FinishedBy finishedBy,
  922. sro.FinishedFlag finishedFlag, sro.PauseFlag pauseFlag,
  923. sro.Remark remark, sro.QtyReported qtyReported, sro.QtyDefected qtyDefected, sro.ReportedFlag reportedFlag
  924. FROM SFDC_RollOps sro
  925. <where>
  926. <if test="site != null and site != ''">
  927. AND sro.Site = #{site}
  928. </if>
  929. <if test="orderNo != null and orderNo != ''">
  930. AND sro.OrderNo = #{orderNo}
  931. </if>
  932. <if test="itemNo != null and itemNo != ''">
  933. AND sro.ItemNo = #{itemNo}
  934. </if>
  935. <if test="seqNo != null and seqNo != ''">
  936. AND sro.SeqNo = #{seqNo}
  937. </if>
  938. <if test="rollNo != null and rollNo != ''">
  939. AND sro.RollNo = #{rollNo}
  940. </if>
  941. </where>
  942. ORDER BY sro.RollNo DESC
  943. </select>
  944. <!--查询派工单的不良信息记录-->
  945. <select id="getSfdcDefectByCon" parameterType="SearchScheduleData" resultType="SfdcDefectData">
  946. SELECT sdh.Site site, sdh.OrderNo orderNo, sdh.ItemNo itemNo, sdh.SeqNo seqNo, sdh.HistSeqNo histSeqNo,
  947. sdh.RollNo rollNo,
  948. sdh.ReportDate reportedDate, sdh.Reportedby reportedBy, sdh.DefectCode defectCode, sdh.DefectQty defectQty,
  949. sdh.Remark remark,
  950. (SELECT idc.DefectDesc FROM InspectionDefectCode idc WHERE idc.Site = sdh.Site AND idc.DefectCode =
  951. sdh.DefectCode) defectDesc
  952. FROM SFDC_DefectHist sdh
  953. <where>
  954. <if test="site != null and site != ''">
  955. AND sdh.Site = #{site}
  956. </if>
  957. <if test="orderNo != null and orderNo != ''">
  958. AND sdh.OrderNo = #{orderNo}
  959. </if>
  960. <if test="itemNo != null and itemNo != ''">
  961. AND sdh.ItemNo = #{itemNo}
  962. </if>
  963. <if test="seqNo != null and seqNo != ''">
  964. AND sdh.SeqNo = #{seqNo}
  965. </if>
  966. <if test="rollNo != null and rollNo != ''">
  967. AND sdh.RollNo = #{rollNo}
  968. </if>
  969. </where>
  970. ORDER BY sdh.HistSeqNo DESC
  971. </select>
  972. <!--查询派工单的下机卷信息-->
  973. <select id="getSfdcRollByCon" parameterType="SearchScheduleData" resultType="SfdcRollData">
  974. SELECT
  975. sfr.Site site,
  976. sfr.OrderNo orderNo,
  977. sfr.RollNo rollNo,
  978. sfr.CreatedDate createdDate,
  979. sfr.Createdby createdby,
  980. sfr.CurrentOpsItemNo currentOpsItemNo,
  981. sfr.LastFinishedOpsItemNo lastFinishedOpsItemNo,
  982. sfr.FinishedDate finishedDate,
  983. sfr.FinishedFlag finishedFlag,
  984. sfr.OnLineFlag onLineFlag,
  985. sfr.PauseFlag pauseFlag,
  986. sfr.OriRollNo oriRollNo,
  987. sfr.StartOpsItemNo startOpsItemNo,
  988. sfr.RollType rollType,
  989. sfr.CreatedOpsItemNo createdOpsItemNo,
  990. sfr.CreatedOpsSeqNo createdOpsSeqNo,
  991. sfr.RollQty rollQty,
  992. sfr.FirstLevelRollNo firstLevelRollNo,
  993. sfr.VirtualRollFlag virtualRollFlag,
  994. SUM(B.good_qty) AS goodQty,
  995. SUM(B.defect_qty) AS defectQty,
  996. SUM(B.total_qty) AS totalQty,
  997. CASE WHEN SUM(B.total_qty) = 0 THEN CAST(0 AS DECIMAL(18, 2)) ELSE CAST( ROUND( CAST(SUM(B.good_qty) AS DECIMAL(20, 6)) / SUM(B.total_qty) * 100, 2) AS DECIMAL(18, 2) ) END AS yieldRate
  998. FROM
  999. SFDC_Rolls sfr
  1000. LEFT JOIN ProductionReport B ON sfr.Site = B.site
  1001. AND sfr.OrderNo = B.order_no
  1002. AND sfr.CreatedOpsSeqNo = B.seq_no
  1003. AND sfr.RollNo = B.roll_no
  1004. <where>
  1005. ISNULL(virtualNewRollFlag, 'Y') = 'N' and sfr.RollType = '下道流转'
  1006. <if test="site != null and site != ''">
  1007. AND sfr.Site = #{site}
  1008. </if>
  1009. <if test="orderNo != null and orderNo != ''">
  1010. AND sfr.OrderNo = #{orderNo}
  1011. </if>
  1012. <if test="itemNo != null and itemNo != ''">
  1013. AND sfr.CreatedOpsItemNo = #{itemNo}
  1014. </if>
  1015. <if test="seqNo != null and seqNo != ''">
  1016. AND sfr.CreatedOpsSeqNo = #{seqNo}
  1017. </if>
  1018. <if test="rollNo != null and rollNo != ''">
  1019. AND sfr.RollNo = #{rollNo}
  1020. </if>
  1021. </where>
  1022. GROUP BY sfr.Site,sfr.OrderNo,sfr.RollID,sfr.RollNo,sfr.CreatedDate,sfr.Createdby,sfr.CurrentOpsItemNo,sfr.LastFinishedOpsItemNo,sfr.FinishedDate,sfr.FinishedFlag,sfr.OnLineFlag,sfr.PauseFlag,sfr.OriRollNo,sfr.StartOpsItemNo,sfr.RollType,sfr.CreatedOpsItemNo,sfr.CreatedOpsSeqNo,sfr.RollQty,sfr.FirstLevelRollNo,sfr.VirtualRollFlag
  1023. ORDER BY sfr.RollID desc
  1024. </select>
  1025. <!--查询报工数据-->
  1026. <select id="getSfdcDataByCon" parameterType="SearchScheduleData" resultType="SfdcData">
  1027. SELECT SUM (ApproveQty) approveQty, SUM (ReportQty - ApproveQty) defectQty, SUM (ReportedManfTime)
  1028. reportedManfTime,
  1029. SUM (Downtime) downtime
  1030. FROM SFDC
  1031. <where>
  1032. <if test="site != null and site != ''">
  1033. AND Site = #{site}
  1034. </if>
  1035. <if test="orderNo != null and orderNo != ''">
  1036. AND OrderNo = #{orderNo}
  1037. </if>
  1038. <if test="itemNo != null and itemNo != ''">
  1039. AND ItemNo = #{itemNo}
  1040. </if>
  1041. <if test="seqNo != null and seqNo != ''">
  1042. AND AssJobSeqNo = #{seqNo}
  1043. </if>
  1044. <if test="rollNo != null and rollNo != ''">
  1045. AND RollNo = #{rollNo}
  1046. </if>
  1047. </where>
  1048. </select>
  1049. <!--查询sfdc_roll表的数据-->
  1050. <select id="getSfdcRollReportedQty" parameterType="SearchScheduleData" resultType="java.lang.Float">
  1051. SELECT SUM(RollQty) reportedQty FROM SFDC_Rolls sfr
  1052. <where>
  1053. <if test="site != null and site != ''">
  1054. AND sfr.Site = #{site}
  1055. </if>
  1056. <if test="orderNo != null and orderNo != ''">
  1057. AND sfr.OrderNo = #{orderNo}
  1058. </if>
  1059. <if test="itemNo != null and itemNo != ''">
  1060. AND sfr.CreatedOpsItemNo = #{itemNo}
  1061. </if>
  1062. <if test="seqNo != null and seqNo != ''">
  1063. AND sfr.CreatedOpsSeqNo = #{seqNo}
  1064. </if>
  1065. <if test="rollNo != null and rollNo != ''">
  1066. AND sfr.OriRollNo = #{rollNo}
  1067. </if>
  1068. <choose>
  1069. <when test='switchKey != null and switchKey == "V"'>
  1070. AND sfr.VirtualRollFlag<![CDATA[<>]]>'Y'
  1071. </when>
  1072. <when test='switchKey != null and switchKey == "VC"'>
  1073. AND NOT(sfr.VirtualRollFlag='N' AND sfr.CombineFlag='Y')
  1074. </when>
  1075. </choose>
  1076. AND sfr.RollType_DB<![CDATA[<>]]>'C'
  1077. </where>
  1078. </select>
  1079. <!--统计是否报工过-->
  1080. <select id="countSfdcRollByRollNo" parameterType="SearchScheduleData" resultType="java.lang.Integer">
  1081. SELECT COUNT(1) FROM SFDC_Rolls sfr
  1082. <where>
  1083. <if test="site != null and site != ''">
  1084. AND sfr.Site = #{site}
  1085. </if>
  1086. <if test="orderNo != null and orderNo != ''">
  1087. AND sfr.OrderNo = #{orderNo}
  1088. </if>
  1089. <if test="itemNo != null and itemNo != ''">
  1090. AND sfr.CreatedOpsItemNo = #{itemNo}
  1091. </if>
  1092. <if test="seqNo != null and seqNo != ''">
  1093. AND sfr.CreatedOpsSeqNo = #{seqNo}
  1094. </if>
  1095. <if test="rollNo != null and rollNo != ''">
  1096. AND sfr.OriRollNo = #{rollNo}
  1097. </if>
  1098. AND sfr.RollType_DB<![CDATA[<>]]>'C'
  1099. </where>
  1100. </select>
  1101. <!--查询sfdcdefect的数据-->
  1102. <select id="getSfdcDefectDefectedQty" parameterType="SearchScheduleData" resultType="java.lang.Float">
  1103. SELECT SUM(sfd.DefectQty) defectQty FROM SFDC_DefectHist sfd
  1104. <where>
  1105. <if test="site != null and site != ''">
  1106. AND sfd.Site = #{site}
  1107. </if>
  1108. <if test="orderNo != null and orderNo != ''">
  1109. AND sfd.OrderNo = #{orderNo}
  1110. </if>
  1111. <if test="itemNo != null and itemNo != ''">
  1112. AND sfd.ItemNo = #{itemNo}
  1113. </if>
  1114. <if test="seqNo != null and seqNo != ''">
  1115. AND sfd.SeqNo = #{seqNo}
  1116. </if>
  1117. <if test="rollNo != null and rollNo != ''">
  1118. AND sfd.RollNo = #{rollNo}
  1119. </if>
  1120. </where>
  1121. </select>
  1122. <!--查询sfdc_time_hist的数据-->
  1123. <select id="countSfdcTimeQty" parameterType="SearchScheduleData" resultType="java.util.HashMap">
  1124. SELECT Round(SUM(CASE WHEN EventType='P' AND sfd.EventDesc='开始调机'
  1125. THEN ISNULL(((CONVERT(FLOAT,CONVERT(datetime,(CASE WHEN sfd.CompletedFlag='Y' THEN sfd.TillTime ELSE getdate()
  1126. END))) - CONVERT(FLOAT,EventTime)) * 24),0.0)
  1127. ELSE 0.0 END), 2) totalSetupTime
  1128. , Round(SUM(CASE WHEN EventType='D' AND sfd.DowntimePhaseIn='调机'
  1129. THEN ISNULL(((CONVERT(FLOAT,CONVERT(datetime,(CASE WHEN sfd.CompletedFlag='Y' THEN sfd.TillTime ELSE getdate()
  1130. END))) - CONVERT(FLOAT,EventTime)) * 24),0.0)
  1131. ELSE 0.0 END), 2) totalDowntimeTimeSetup
  1132. , Round(SUM(CASE WHEN EventType='P' AND sfd.EventDesc='开始生产'
  1133. THEN ISNULL(((CONVERT(FLOAT,CONVERT(datetime,(CASE WHEN sfd.CompletedFlag='Y' THEN sfd.TillTime ELSE getdate()
  1134. END))) - CONVERT(FLOAT,EventTime)) * 24),0.0)
  1135. ELSE 0.0 END), 2) totalProdTime
  1136. , Round(SUM(CASE WHEN EventType='D' AND sfd.DowntimePhaseIn='生产'
  1137. THEN ISNULL(((CONVERT(FLOAT,CONVERT(datetime,(CASE WHEN sfd.CompletedFlag='Y' THEN sfd.TillTime ELSE getdate()
  1138. END))) - CONVERT(FLOAT,EventTime)) * 24),0.0)
  1139. ELSE 0.0 END), 2) totalDowntimeTimeProd
  1140. ,SUM(CASE WHEN CompletedFlag='N' THEN 1.0 ELSE 0.0 END) unCloseLeft
  1141. FROM SFDC_TimeHist sfd
  1142. <where>
  1143. <if test="site != null and site != ''">
  1144. AND sfd.Site = #{site}
  1145. </if>
  1146. <if test="orderNo != null and orderNo != ''">
  1147. AND sfd.OrderNo = #{orderNo}
  1148. </if>
  1149. <if test="itemNo != null and itemNo != ''">
  1150. AND sfd.ItemNo = #{itemNo}
  1151. </if>
  1152. <if test="seqNo != null and seqNo != ''">
  1153. AND sfd.SeqNo = #{seqNo}
  1154. </if>
  1155. <if test="rollNo != null and rollNo != ''">
  1156. AND sfd.RollNo = #{rollNo}
  1157. </if>
  1158. </where>
  1159. </select>
  1160. <!--查询sfdc_time_hist的数据-->
  1161. <select id="getSfdcTimeMaxAndMinTime" parameterType="SearchScheduleData" resultType="java.util.HashMap">
  1162. SELECT MIN(sfd.EventTime) eventTime, COUNT(1) sl, ROUND(SUM(TotalTime), 2) totalTime,
  1163. MAX((CASE WHEN sfd.CompletedFlag='Y' THEN sfd.TillTime ELSE getdate()END)) tillTime
  1164. FROM SFDC_TimeHist sfd
  1165. <where>
  1166. <if test="site != null and site != ''">
  1167. AND sfd.Site = #{site}
  1168. </if>
  1169. <if test="orderNo != null and orderNo != ''">
  1170. AND sfd.OrderNo = #{orderNo}
  1171. </if>
  1172. <if test="itemNo != null and itemNo != ''">
  1173. AND sfd.ItemNo = #{itemNo}
  1174. </if>
  1175. <if test="seqNo != null and seqNo != ''">
  1176. AND sfd.SeqNo = #{seqNo}
  1177. </if>
  1178. <if test="rollNo != null and rollNo != ''">
  1179. AND sfd.RollNo = #{rollNo}
  1180. </if>
  1181. AND sfd.EventType='P'
  1182. </where>
  1183. </select>
  1184. <!--查询sfdc_rollops表的数据-->
  1185. <select id="getSfdcRollOpsReportedQty" parameterType="SearchScheduleData" resultType="java.util.HashMap">
  1186. SELECT sfo.QtyReported approvedQty, ISNULL((SELECT SUM(DefectQty) FROM SFDC_DefectHist sfd
  1187. WHERE sfo.Site = sfd.Site AND sfo.OrderNo = sfd.OrderNo AND sfo.ItemNo = sfd.ItemNo AND sfo.SeqNo = sfd.SeqNo
  1188. AND sfo.RollNo = sfd.RollNo), 0) defectedQty
  1189. FROM SFDC_RollOps sfo
  1190. <where>
  1191. <if test="site != null and site != ''">
  1192. AND sfo.Site = #{site}
  1193. </if>
  1194. <if test="orderNo != null and orderNo != ''">
  1195. AND sfo.OrderNo = #{orderNo}
  1196. </if>
  1197. <if test="itemNo != null and itemNo != ''">
  1198. AND sfo.ItemNo = #{itemNo}
  1199. </if>
  1200. <if test="seqNo != null and seqNo != ''">
  1201. AND sfo.SeqNo = #{seqNo}
  1202. </if>
  1203. <if test="rollNo != null and rollNo != ''">
  1204. AND sfo.RollNo = #{rollNo}
  1205. </if>
  1206. </where>
  1207. </select>
  1208. <!--查询派工单的班次信息数据-->
  1209. <select id="getScheduleShiftData" parameterType="SearchScheduleData" resultType="java.util.HashMap">
  1210. Select WR.ResourceID resourceId,
  1211. CE.ScheduleDate scheduledDate,
  1212. CES.ShiftNo shiftNo,
  1213. CES.ShiftDesc shiftDesc,
  1214. (CONVERT(Decimal(20, 6), CE.ScheduleDate) + CONVERT(Decimal(20, 6), CES.StartTime / 24.0)) startTime,
  1215. (CONVERT(Decimal(20, 6), CE.ScheduleDate) + CONVERT(Decimal(20, 6), CES.EndTime / 24.0) +
  1216. (case when CES.EndTime <![CDATA[<]]> CES.StartTime then 1.0 else 0.0 end)) endTime,
  1217. (CONVERT(Decimal(20, 6), Convert(datetime, #{currentTime}))) curTime
  1218. from WorkCenterResource as WR
  1219. , Calendar_Exception as CE
  1220. , Calendar_Exception_Shift CES
  1221. where WR.Site = CE.Site
  1222. and WR.CalendarID = CE.CalendarID
  1223. and CE.Site = CES.Site
  1224. and CE.CalendarID = CES.CalendarID
  1225. and CE.ScheduleDate = CES.ScheduleDate
  1226. and WR.Site = '1'
  1227. and WR.ResourceID = #{resourceId}
  1228. and CONVERT(Decimal(20, 6), CE.ScheduleDate)<![CDATA[ >=]]>
  1229. Convert(Decimal(20, 6), Convert(datetime, #{currentDate})) - 1
  1230. and CONVERT(Decimal(20, 6), CE.ScheduleDate)<![CDATA[ <=]]>
  1231. Convert(Decimal(20, 6), Convert(datetime, #{currentDate})) + 1
  1232. Order by CE.ScheduleDate, CES.StartTime
  1233. </select>
  1234. <!--查询sfdc的时间数据-->
  1235. <select id="getSfdcTimeData" parameterType="SearchScheduleData" resultType="java.util.Map">
  1236. SELECT MAX(finishtime) finishTime, SUM(ReportedSetupTime) reportedSetupTime, SUM(ReportedManfTime)
  1237. reportedManfTime,
  1238. SUM(Downtime) downTime, SUM(ReportedSetupDowntime) reportedSetupDowntime, SUM(ReportedManfDowntime)
  1239. reportedManfDowntime
  1240. FROM SFDC
  1241. <where>
  1242. <if test="site != null and site != ''">
  1243. AND Site = #{site}
  1244. </if>
  1245. <if test="orderNo != null and orderNo != ''">
  1246. AND OrderNo = #{orderNo}
  1247. </if>
  1248. <if test="itemNo != null and itemNo != ''">
  1249. AND ItemNo = #{itemNo}
  1250. </if>
  1251. AND AssJobSeqNo = #{seqNo} AND RollNo = #{rollNo} AND InAdvanceflag='Y'
  1252. </where>
  1253. </select>
  1254. <select id="getSfdcMaterialByRollNo" parameterType="SearchScheduleData" resultType="SfdcMaterialData">
  1255. SELECT
  1256. smh.Site site,
  1257. smh.OrderNo orderNo,
  1258. smh.ItemNo itemNo,
  1259. smh.SeqNo seqNo,
  1260. smh.HistSeqNo histSeqNo,
  1261. smh.RollNo rollNo,
  1262. smh.ReportDate reportDate,
  1263. smh.Reportedby reportedby,
  1264. smh.RMRollNo rmRollNo,
  1265. smh.PartNo partNo,
  1266. smh.Remark remark,
  1267. smh.StartDate startDate,
  1268. smh.FinishDate finishedDate,
  1269. smh.FinishFlag finishedFlag,
  1270. smh.HistType histType,
  1271. smh.TransGeneratedFlag transGeneratedFlag,
  1272. smh.OriginalRMRollNo originalRMRollNo,
  1273. smh.UnissueFlag unissueFlag,
  1274. ROUND(smh.TransQty, 3) transQty,
  1275. NetIssueQty netIssueQty,
  1276. smh.OriginalHistSeqNo originalHistSeqNo,
  1277. smh.StartFromRollNo startFromRollNo,
  1278. smh.KeyRMFlag keyRMFlag,
  1279. smh.SAPBOMItemNo sAPBOMItemNo,
  1280. smh.Setupflag setupflag
  1281. FROM SFDC_MaterialHist smh
  1282. <where>
  1283. <if test="site != null and site != ''">
  1284. AND smh.Site = #{site}
  1285. </if>
  1286. <if test="orderNo != null and orderNo != ''">
  1287. AND smh.OrderNo = #{orderNo}
  1288. </if>
  1289. <if test="itemNo != null and itemNo != ''">
  1290. AND smh.ItemNo = #{itemNo}
  1291. </if>
  1292. <if test="seqNo != null and seqNo != ''">
  1293. AND smh.SeqNo = #{seqNo}
  1294. </if>
  1295. <if test="rollNo != null and rollNo != ''">
  1296. AND smh.RollNo = #{rollNo}
  1297. </if>
  1298. <if test="finishedFlag != null and finishedFlag != ''">
  1299. AND smh.FinishFlag = #{finishedFlag}
  1300. </if>
  1301. <if test="keyRMFlag != null and keyRMFlag != ''">
  1302. AND smh.KeyRMFlag = #{keyRMFlag}
  1303. </if>
  1304. <if test="histType != null and histType != ''">
  1305. AND smh.HistType = #{histType}
  1306. </if>
  1307. </where>
  1308. ORDER BY smh.HistSeqNo DESC
  1309. </select>
  1310. <!--检查派工单是否关闭-->
  1311. <select id="checkScheduleStatus" parameterType="SearchScheduleData" resultType="java.lang.Integer">
  1312. SELECT COUNT(1) FROM SOScheduledRouting ssr
  1313. <where>
  1314. <if test="site != null and site != ''">
  1315. AND ssr.Site = #{site}
  1316. </if>
  1317. <if test="orderNo != null and orderNo != ''">
  1318. AND ssr.OrderNo = #{orderNo}
  1319. </if>
  1320. <if test="itemNo != null and itemNo != ''">
  1321. AND ssr.ItemNo = #{itemNo}
  1322. </if>
  1323. <if test="seqNo != null and seqNo != ''">
  1324. AND ssr.SeqNo = #{seqNo}
  1325. </if>
  1326. <if test="closedFlag != null and closedFlag != ''">
  1327. AND ssr.ClosedFlag = #{closedFlag}
  1328. </if>
  1329. </where>
  1330. </select>
  1331. <!--获取rollId和normalRollId-->
  1332. <select id="getRollIdAndNormalRollIdByCon" parameterType="SearchScheduleData" resultType="java.util.HashMap">
  1333. SELECT MAX(RollID) rollId, MAX(NormalRollID) normalRollId FROM SFDC_Rolls ssr
  1334. <where>
  1335. <if test="site != null and site != ''">
  1336. AND ssr.Site = #{site}
  1337. </if>
  1338. <if test="orderNo != null and orderNo != ''">
  1339. AND ssr.OrderNo = #{orderNo}
  1340. </if>
  1341. </where>
  1342. </select>
  1343. <!--插入sfdcRolls的数据-->
  1344. <insert id="insertSfdcRolls" parameterType="SfdcRollData">
  1345. INSERT INTO SFDC_Rolls(Site, OrderNo, RollID, RollNo, CreatedDate, Createdby, CreatedOpsItemNo, CreatedOpsSeqNo,
  1346. CurrentOpsItemNo, LastFinishedOpsItemNo, FinishedDate,
  1347. FinishedFlag, OnLineFlag, PauseFlag, OriRollNo, Remark, StartOpsItemNo, RollType,
  1348. RollType_DB, RollQty, FirstLevelRollNo, FGRollFlag, FGRollID,
  1349. NormalRollID, CombineFlag, VirtualRollFlag, VirtualLinkRollNo, CQCPassFlag,
  1350. CQCInspectedFlag, CQCNeedInspectFlag)
  1351. VALUES (#{site}, #{orderNo}, #{rollId}, #{rollNo}, #{createdDate}, #{createdBy}, #{createdOpsItemNo},
  1352. #{createdOpsSeqNo}, #{currentOpsItemNo}, #{lastFinishedOpsItemNo}, #{finishedDate},
  1353. #{finishedFlag}, #{onLineFlag}, #{pauseFlag}, #{oriRollNo}, #{remark}, #{startOpsItemNo}, #{rollType},
  1354. #{rollTypeDb}, #{rollQty}, #{firstLevelRollNo}, #{fgRollFlag}, #{fgRollId},
  1355. #{normalRollId}, #{combineFlag}, #{virtualRollFlag}, #{virtualLinkRollNo}, #{cqcPassFlag},
  1356. #{cqcInspectedFlag}, #{cqcNeedInspectFlag})
  1357. </insert>
  1358. <!--插入sfdcRollOps的数据-->
  1359. <insert id="insertSfdcRollOps" parameterType="SfdcRollData">
  1360. INSERT INTO SFDC_RollOps(Site, OrderNo, RollNo, ItemNo, SeqNo, StartProdFlag, FinishedFlag, PauseFlag,
  1361. ScanedBy, ScanedDate, Remark, QtyReported, QtyDefected, ReportedFlag)
  1362. VALUES (#{site}, #{orderNo}, #{rollNo}, #{itemNo}, #{seqNo}, #{startProdFlag}, #{finishedFlag}, #{pauseFlag},
  1363. #{scanedBy}, #{scanedDate}, #{remark}, #{qtyReported}, #{qtyDefected}, #{reportedFlag})
  1364. </insert>
  1365. <!--根据条件或者材料卷数据-->
  1366. <select id="getCRollInfoByRollNo" parameterType="SearchScheduleData" resultType="CRollInfoOutData">
  1367. SELECT cri.rollno rollNo,
  1368. cri.partno partNo,
  1369. part.PartDescription partDesc,
  1370. cri.rolltype rollType,
  1371. cri.rolltype_db rollTypeDb,
  1372. status status,
  1373. cri.status_db statusDb,
  1374. cri.rollqty rollQty,
  1375. cri.site,
  1376. cri.SourceType orderRefType,
  1377. cri.orderref1 orderRef1,
  1378. cri.orderref2 orderRef2,
  1379. cri.orderref3 orderRef3,
  1380. cri.frozenflag frozenFlag
  1381. FROM C_RollInfo cri
  1382. LEFT JOIN Part part ON part.Site = cri.site AND part.PartNo = cri.partno
  1383. WHERE cri.site = #{site}
  1384. AND cri.rollno = #{rmRollNo}
  1385. </select>
  1386. <!--根据条件或者材料卷数据-->
  1387. <select id="getInventoryStockByRollNo" parameterType="SearchScheduleData" resultType="CRollInfoOutData">
  1388. SELECT cri.roll_no rollNo,
  1389. cri.part_no partNo,
  1390. part.PartDescription partDesc,
  1391. '合格卷' rollType,
  1392. '0' rollTypeDb,
  1393. status status,
  1394. cri.status_tb statusDb,
  1395. cri.qty_on_hand rollQty,
  1396. cri.site,
  1397. cri.orderref0 orderRefType,
  1398. cri.orderref1 orderRef1,
  1399. cri.orderref2 orderRef2,
  1400. cri.orderref3 orderRef3,
  1401. case when cri.status='冻结' then 'Y' else 'N' end frozenFlag
  1402. FROM inventory_stock cri
  1403. inner JOIN Part part ON part.Site = cri.site AND part.PartNo = cri.part_no
  1404. WHERE cri.site = #{site}
  1405. AND cri.roll_no = #{rmRollNo}
  1406. </select>
  1407. <!--根据工单和物料自动获取bom行数据-->
  1408. <select id="getBomItemNosByPartNo" parameterType="SearchScheduleData" resultType="java.util.HashMap">
  1409. SELECT Site site,
  1410. OrderNo orderNo,
  1411. CONVERT(INT, ItemNo) itemNo,
  1412. ComponentPartNo partNo,
  1413. dbo.Get_PartDesc(Site, ComponentPartNo) partDesc,
  1414. QtyAssembly qtyAssembly,
  1415. QtyFixedScrapt qtyFixedScrapt,
  1416. ScraptFactor scraptFactor,
  1417. Remark remark,
  1418. QtyRequired qtyRequired,
  1419. QtyIssue qtyIssue,
  1420. CONVERT(VARCHAR(20), IssueDate, 120) issueDate,
  1421. QtyReserved qtyReserved,
  1422. MatGroup matGroup,
  1423. QtyNotified qtyNotified,
  1424. RMType_DB rmTypeDb,
  1425. IssueType issueType
  1426. FROM dbo.view_SAP_SOBOM vss
  1427. WHERE vss.Site = #{site}
  1428. AND vss.OrderNo = #{orderNo}
  1429. AND vss.ComponentPartNo = #{rmPartNo}
  1430. </select>
  1431. <!--查询材料的上机卷记录数据-->
  1432. <select id="getBomItemNosByPartNo" parameterType="SearchScheduleData" resultType="java.util.HashMap">
  1433. SELECT OrderNo + '/' + CONVERT(VARCHAR(20), ItemNo) + '/' + CONVERT(VARCHAR(20), SeqNo) orderInfo
  1434. FROM SFDC_MaterialHist
  1435. WHERE Site = #{site}
  1436. AND RMRollNo = #{rmPartNo}
  1437. </select>
  1438. <!--查询派工单时的材料记录信息-->
  1439. <select id="getSfdcMaterialByBomItemNo" parameterType="SearchScheduleData" resultType="SfdcMaterialData">
  1440. SELECT smh.Site site, smh.OrderNo orderNo, smh.ItemNo itemNo, smh.SeqNo seqNo, smh.HistSeqNo histSeqNo,
  1441. smh.RollNo rollNo, smh.ReportDate reportDate,
  1442. smh.Reportedby reportedby, smh.RMRollNo rmRollNo, smh.PartNo partNo, smh.Remark remark, smh.StartDate startDate,
  1443. smh.FinishDate finishedDate,
  1444. smh.FinishFlag finishedFlag, smh.HistType histType, smh.TransGeneratedFlag transGeneratedFlag,
  1445. smh.OriginalRMRollNo originalRMRollNo,
  1446. smh.UnissueFlag unissueFlag, ROUND(smh.TransQty, 3) transQty, ROUND(smh.NetIssueQty, 3) netIssueQty,
  1447. smh.OriginalHistSeqNo originalHistSeqNo,
  1448. smh.StartFromRollNo startFromRollNo, smh.KeyRMFlag keyRMFlag, smh.SAPBOMItemNo sAPBOMItemNo, smh.Setupflag
  1449. setupflag
  1450. FROM SFDC_MaterialHist smh
  1451. <where>
  1452. <if test="site != null and site != ''">
  1453. AND smh.Site = #{site}
  1454. </if>
  1455. <if test="orderNo != null and orderNo != ''">
  1456. AND smh.OrderNo = #{orderNo}
  1457. </if>
  1458. <if test="itemNo != null and itemNo > 0">
  1459. AND smh.ItemNo = #{itemNo}
  1460. </if>
  1461. <if test="seqNo != null and seqNo != ''">
  1462. AND smh.SeqNo = #{seqNo}
  1463. </if>
  1464. <if test="bomItemNo != null and bomItemNo > -1">
  1465. AND smh.SAPBOMItemNo = #{bomItemNo}
  1466. </if>
  1467. </where>
  1468. ORDER BY smh.HistSeqNo DESC
  1469. </select>
  1470. <!--查询派工单时的材料记录信息-->
  1471. <select id="getSfdcMaterialByBomItemNo" parameterType="SearchScheduleData" resultType="SfdcMaterialData">
  1472. SELECT COUNT(1) FROM SFDC_MaterialHist smh
  1473. <where>
  1474. <if test="site != null and site != ''">
  1475. AND smh.Site = #{site}
  1476. </if>
  1477. <if test="orderNo != null and orderNo != ''">
  1478. AND smh.OrderNo = #{orderNo}
  1479. </if>
  1480. <if test="itemNo != null and itemNo > 0">
  1481. AND smh.ItemNo = #{itemNo}
  1482. </if>
  1483. <if test="seqNo != null and seqNo != ''">
  1484. AND smh.SeqNo = #{seqNo}
  1485. </if>
  1486. <if test="rollNo != null and rollNo != ''">
  1487. AND smh.RollNo = #{rollNo}
  1488. </if>
  1489. <if test="rmPartNo != null and rmPartNo != ''">
  1490. AND smh.PartNo = #{rmPartNo}
  1491. </if>
  1492. <if test="finishedFlag != null and finishedFlag != ''">
  1493. AND smh.FinishFlag = #{finishedFlag}
  1494. </if>
  1495. <if test="histType != null and histType != ''">
  1496. AND smh.HistType = #{histType}
  1497. </if>
  1498. </where>
  1499. ORDER BY smh.HistSeqNo DESC
  1500. </select>
  1501. <!--查询派工单的不良记录-->
  1502. <select id="getScheduleDefectHist" parameterType="SearchScheduleData" resultType="SfdcDefectData">
  1503. SELECT sdh.Site site, sdh.OrderNo orderNo, sdh.ItemNo itemNo, sdh.SeqNo seqNo, sdh.HistSeqNo histSeqNo,
  1504. sdh.RollNo rollNo,
  1505. sdh.ReportDate reportedDate, sdh.Reportedby reportedBy, sdh.DefectCode defectCode, sdh.DefectQty defectQty,
  1506. sdh.Remark remark,
  1507. (SELECT idc.DefectDesc FROM InspectionDefectCode idc WHERE idc.Site = sdh.Site AND idc.DefectCode =
  1508. sdh.DefectCode) defectDesc
  1509. FROM SFDC_DefectHist sdh
  1510. <where>
  1511. <if test="site != null and site != ''">
  1512. AND sdh.Site = #{site}
  1513. </if>
  1514. <if test="orderNo != null and orderNo != ''">
  1515. AND sdh.OrderNo = #{orderNo}
  1516. </if>
  1517. <if test="itemNo != null and itemNo != ''">
  1518. AND sdh.ItemNo = #{itemNo}
  1519. </if>
  1520. <if test="seqNo != null and seqNo != ''">
  1521. AND sdh.SeqNo = #{seqNo}
  1522. </if>
  1523. </where>
  1524. ORDER BY sdh.HistSeqNo DESC
  1525. </select>
  1526. <!--查询派工单的不良记录-->
  1527. <select id="countToolUsedQty" parameterType="SearchScheduleData" resultType="java.lang.Float">
  1528. SELECT SUM(FinishQty)
  1529. FROM SFDC_ToolingHist sth
  1530. WHERE sth.Site = #{site}
  1531. AND sth.OrderNo = #{orderNo}
  1532. AND sth.ItemNo = #{itemNo}
  1533. AND sth.SeqNo = #{seqNo}
  1534. AND sth.RollNo <![CDATA[<>]]> #{rollNo}
  1535. AND sth.ToolInstanceID = #{oriToolInstanceId}
  1536. </select>
  1537. <!--查询派工单的时间记录信息-->
  1538. <select id="getSfdcTimeHistBySeqNo" parameterType="SearchScheduleData" resultType="SfdcTimeData">
  1539. SELECT sth.Site site, sth.OrderNo orderNo,sth.ItemNo itemNo, sth.SeqNo seqNo, sth.HistSeqNo histSeqNo,
  1540. sth.RollNo rollNo,
  1541. sth.EventTime eventTime, sth.Enteredby enteredby, sth.EventDesc eventDesc, sth.DowntimeCode downtimeCode,
  1542. sth.TillTime tillTime,
  1543. sth.TillEnteredTime tillEnteredTime, sth.TillEnteredBy tillEnteredBy, sth.CompletedFlag completedFlag,
  1544. ROUND(sth.TotalTime, 3) totalTime,
  1545. sth.DowntimePhaseIn downtimePhaseIn
  1546. FROM SFDC_TimeHist sth
  1547. <where>
  1548. <if test="site != null and site != ''">
  1549. AND sth.Site = #{site}
  1550. </if>
  1551. <if test="orderNo != null and orderNo != ''">
  1552. AND sth.OrderNo = #{orderNo}
  1553. </if>
  1554. <if test="itemNo != null and itemNo != ''">
  1555. AND sth.ItemNo = #{itemNo}
  1556. </if>
  1557. <if test="seqNo != null and seqNo != ''">
  1558. AND sth.SeqNo = #{seqNo}
  1559. </if>
  1560. <if test='showNoFinishedTimeFlag != null and showNoFinishedTimeFlag != "" and showNoFinishedTimeFlag == "Y"'>
  1561. AND sth.CompletedFlag = 'N'
  1562. </if>
  1563. </where>
  1564. ORDER BY sth.HistSeqNo DESC
  1565. </select>
  1566. <!--查询派工单的工具记录信息-->
  1567. <select id="getSfdcToolHistBySeqNo" parameterType="SearchScheduleData" resultType="SfdcToolData">
  1568. SELECT sth.Site site, sth.OrderNo orderNo, sth.ItemNo itemNo, sth.SeqNo seqNo, sth.HistSeqNo histSeqNo,
  1569. sth.RollNo rollNo,
  1570. sth.ReportDate reportedDate, sth.Reportedby reportedby, sth.ToolInstanceID toolInstanceID, sth.StartDate
  1571. startDate,
  1572. sth.FinishDate finishedDate, sth.FinishFlag finishedFlag, sth.Remark remark, sth.StartFromRollNo
  1573. startFromRollNo, sth.FinishQty finishQty
  1574. FROM SFDC_ToolingHist sth
  1575. <where>
  1576. <if test="site != null and site != ''">
  1577. AND sth.Site = #{site}
  1578. </if>
  1579. <if test="orderNo != null and orderNo != ''">
  1580. AND sth.OrderNo = #{orderNo}
  1581. </if>
  1582. <if test="itemNo != null and itemNo != ''">
  1583. AND sth.ItemNo = #{itemNo}
  1584. </if>
  1585. <if test="seqNo != null and seqNo != ''">
  1586. AND sth.SeqNo = #{seqNo}
  1587. </if>
  1588. <if test='showNoFinishedToolFlag != null and showNoFinishedToolFlag != "" and showNoFinishedToolFlag == "Y"'>
  1589. AND sth.FinishFlag = 'N'
  1590. </if>
  1591. </where>
  1592. ORDER BY sth.HistSeqNo DESC
  1593. </select>
  1594. <!--查询派工单时的材料记录信息-->
  1595. <select id="getSfdcMaterialHistBySeqNo" parameterType="SearchScheduleData" resultType="SfdcMaterialData">
  1596. SELECT smh.Site site, smh.OrderNo orderNo, smh.ItemNo itemNo, smh.SeqNo seqNo, smh.HistSeqNo histSeqNo,
  1597. smh.RollNo rollNo, smh.ReportDate reportDate,
  1598. smh.Reportedby reportedby, smh.RMRollNo rmRollNo, smh.PartNo partNo, smh.Remark remark, smh.StartDate startDate,
  1599. smh.FinishDate finishedDate,
  1600. smh.FinishFlag finishedFlag, smh.HistType histType, smh.TransGeneratedFlag transGeneratedFlag,
  1601. smh.OriginalRMRollNo originalRMRollNo,
  1602. smh.UnissueFlag unissueFlag, ROUND(smh.TransQty, 3) transQty, ROUND(smh.NetIssueQty, 3) netIssueQty,
  1603. smh.OriginalHistSeqNo originalHistSeqNo,
  1604. smh.StartFromRollNo startFromRollNo, smh.KeyRMFlag keyRMFlag, smh.SAPBOMItemNo sAPBOMItemNo, smh.Setupflag
  1605. setupflag
  1606. FROM SFDC_MaterialHist smh
  1607. <where>
  1608. <if test="site != null and site != ''">
  1609. AND smh.Site = #{site}
  1610. </if>
  1611. <if test="orderNo != null and orderNo != ''">
  1612. AND smh.OrderNo = #{orderNo}
  1613. </if>
  1614. <if test="itemNo != null and itemNo != ''">
  1615. AND smh.ItemNo = #{itemNo}
  1616. </if>
  1617. <if test="seqNo != null and seqNo != ''">
  1618. AND smh.SeqNo = #{seqNo}
  1619. </if>
  1620. <if test='showNoFinishedMaterialFlag != null and showNoFinishedMaterialFlag != "" and showNoFinishedMaterialFlag == "Y"'>
  1621. AND smh.FinishFlag = 'N'
  1622. </if>
  1623. </where>
  1624. ORDER BY smh.HistSeqNo DESC
  1625. </select>
  1626. <!--获取当前加工中心机台对应的calendarId-->
  1627. <select id="getCalendarId" parameterType="SearchScheduleData" resultType="java.util.HashMap">
  1628. SELECT wcr.CalendarID calendarId,
  1629. (SELECT cd.CalendarDesc
  1630. FROM Calendar cd
  1631. WHERE wcr.Site = cd.Site
  1632. AND wcr.CalendarID = cd.CalendarID) calendarDesc,
  1633. Efficiency efficiency
  1634. FROM WorkCenterResource wcr
  1635. WHERE wcr.Site = #{site}
  1636. AND wcr.WorkCenterNo = #{workCenterNo}
  1637. AND wcr.ResourceID = #{resourceId}
  1638. </select>
  1639. <!--获取班次选择的数据-->
  1640. <select id="getScheduleShiftWithSelect" parameterType="SearchScheduleData" resultType="java.util.HashMap">
  1641. SELECT WR.ResourceID resourceId,
  1642. CONVERT(VARCHAR(10), CE.ScheduleDate, 120) scheduleDate,
  1643. CES.ShiftNo shiftNo,
  1644. CES.ShiftDesc shiftDesc,
  1645. CONVERT(VARCHAR(5), CES.StartExactTime, 108) startTime,
  1646. CONVERT(VARCHAR(5), CES.EndExactTime, 108) endTime,
  1647. (CASE WHEN CES.EndTime <![CDATA[<]]> CES.StartTime THEN 'Y' ELSE 'N' END) nextDayFlag
  1648. FROM WorkCenterResource WR,
  1649. Calendar_Exception CE,
  1650. Calendar_Exception_Shift CES
  1651. WHERE WR.Site = CE.Site
  1652. and WR.CalendarID = CE.CalendarID
  1653. AND CE.Site = CES.Site
  1654. and CE.CalendarID = CES.CalendarID
  1655. and CE.ScheduleDate = CES.ScheduleDate
  1656. AND WR.Site = #{site}
  1657. AND WR.ResourceID = #{resourceId}
  1658. AND CONVERT(DECIMAL(20, 6), CE.ScheduleDate)<![CDATA[ >=]]>
  1659. CONVERT(DECIMAL(20, 6), CONVERT(datetime, #{scheduledDate})) - 1
  1660. AND CONVERT(DECIMAL(20, 6), CE.ScheduleDate)<![CDATA[ <=]]>
  1661. CONVERT(DECIMAL(20, 6), CONVERT(datetime, #{scheduledDate})) + 1
  1662. AND (CONVERT(DECIMAL(20, 6), CE.ScheduleDate) + CONVERT(DECIMAL(20, 6), CES.StartTime / 24.0)) <![CDATA[<=]]>
  1663. (CONVERT(DECIMAL(20, 6), CONVERT(datetime, #{scheduledDate})) +
  1664. (CONVERT(DECIMAL(20, 6), CONVERT(datetime, #{reportedTime})) -
  1665. floor(CONVERT(DECIMAL(20, 6), CONVERT(datetime, #{reportedTime})))))
  1666. ORDER BY CE.ScheduleDate, CES.Starttime
  1667. </select>
  1668. <select id="searchFqcSfdcRolls" resultType="com.gaotao.modules.schedule.data.SfdcRollData">
  1669. SELECT sfr.Site site, sfr.OrderNo orderNo, sfr.RollNo rollNo, sfr.CreatedDate createdDate, sfr.Createdby
  1670. createdby, sfr.CurrentOpsItemNo currentOpsItemNo,
  1671. sfr.LastFinishedOpsItemNo lastFinishedOpsItemNo, sfr.FinishedDate finishedDate, sfr.FinishedFlag finishedFlag,
  1672. sfr.OnLineFlag onLineFlag,
  1673. sfr.PauseFlag pauseFlag, sfr.OriRollNo oriRollNo, sfr.StartOpsItemNo startOpsItemNo, sfr.RollType rollType,
  1674. sfr.CreatedOpsItemNo createdOpsItemNo,
  1675. sfr.CreatedOpsSeqNo createdOpsSeqNo, sfr.RollQty rollQty, sfr.FirstLevelRollNo firstLevelRollNo,
  1676. sfr.VirtualRollFlag virtualRollFlag
  1677. FROM SFDC_Rolls sfr
  1678. <where>
  1679. sfr.Site= #{site}
  1680. and sfr.OrderNo=#{orderNo}
  1681. and sfr.StartOpsItemNo <![CDATA[ <= ]]> #{itemNo}
  1682. and sfr.CQCPassFlag='N'
  1683. and sfr.FinishedFlag='N'
  1684. and sfr.CQCInspectedFlag='Y'
  1685. <if test=" rollNo != null and rollNo != ''">
  1686. and sfr.RollNo like '%' + #{rollNo} + '%'
  1687. </if>
  1688. </where>
  1689. </select>
  1690. <select id="getReworkSfdcRollByCon" resultType="com.gaotao.modules.schedule.data.SfdcRollData">
  1691. SELECT sfr.Site site, sfr.OrderNo orderNo, sfr.RollNo rollNo, sfr.CreatedDate createdDate, sfr.Createdby
  1692. createdby, sfr.CurrentOpsItemNo currentOpsItemNo,
  1693. sfr.LastFinishedOpsItemNo lastFinishedOpsItemNo, sfr.FinishedDate finishedDate, sfr.FinishedFlag finishedFlag,
  1694. sfr.OnLineFlag onLineFlag,
  1695. sfr.PauseFlag pauseFlag, sfr.OriRollNo oriRollNo, sfr.StartOpsItemNo startOpsItemNo, sfr.RollType rollType,
  1696. sfr.CreatedOpsItemNo createdOpsItemNo,
  1697. sfr.CreatedOpsSeqNo createdOpsSeqNo, sfr.RollQty rollQty, sfr.FirstLevelRollNo firstLevelRollNo,
  1698. sfr.VirtualRollFlag virtualRollFlag,
  1699. sfr.CombineFlag combineFlag
  1700. FROM SFDC_Rolls sfr
  1701. <where>
  1702. <if test="site != null and site != ''">
  1703. AND sfr.Site = #{site}
  1704. </if>
  1705. <if test="orderNo != null and orderNo != ''">
  1706. AND sfr.OrderNo = #{orderNo}
  1707. </if>
  1708. <if test="itemNo != null and itemNo != ''">
  1709. AND sfr.CreatedOpsItemNo = #{itemNo}
  1710. </if>
  1711. <if test="seqNo != null and seqNo != ''">
  1712. AND sfr.CreatedOpsSeqNo = #{seqNo}
  1713. </if>
  1714. <if test="rollNo != null and rollNo != ''">
  1715. AND sfr.RollNo = #{rollNo}
  1716. </if>
  1717. </where>
  1718. Union all
  1719. Select
  1720. T.Site,T.OrderNo,D.RollNo,D.CreatedDate,D.Createdby,D.CurrentOpsItemNo,D.LastFinishedOpsItemNo,D.FinishedDate,D.FinishedFlag
  1721. ,D.OnLineFlag,D.PauseFlag,D.OriRollNo,D.StartOpsItemNo,D.RollType,D.CreatedOpsItemNo,D.CreatedOpsSeqNo,D.RollQty,D.FirstLevelRollNo
  1722. ,D.FGRollFlag,D.CombineFlag
  1723. from SFDC_RollOps as T,SFDC_Rolls as D
  1724. Where T.Site=D.Site and T.OrderNo=D.OrderNo and T.RollNo=D.RollNo
  1725. and T.Site=#{site}
  1726. and T.OrderNo=#{orderNo}
  1727. and T.ItemNo=#{itemNo}
  1728. and T.SeqNo=#{seqNo}
  1729. and T.Remark='直接送检'
  1730. ORDER BY sfr.RollNo
  1731. </select>
  1732. <select id="reportCheck" resultType="java.lang.Integer">
  1733. Select count(1)
  1734. from SOScheduledRouting as T
  1735. Where Site = #{site}
  1736. and S_ResourceID = #{resourceId}
  1737. and S_WorkCenterNo = #{workCenterNo}
  1738. and SeqNo != #{seqNo}
  1739. and ClosedFlag = 'N'
  1740. and StartProdFlag = 'Y'
  1741. and (
  1742. (case
  1743. when exists(select 1
  1744. from SFDC_MaterialHist as T1
  1745. where T1.Site = T.Site
  1746. and T1.OrderNo = T.OrderNo
  1747. and T1.ItemNo = T.ItemNo
  1748. and T1.SeqNo = T.SeqNo
  1749. and T1.FinishFlag = 'N'
  1750. )
  1751. then 1
  1752. else 0 end
  1753. )
  1754. +
  1755. (case
  1756. when exists(select 1
  1757. from SFDC_ToolingHist as T2
  1758. where T2.Site = T.Site
  1759. and T2.OrderNo = T.OrderNo
  1760. and T2.ItemNo = T.ItemNo
  1761. and T2.SeqNo = T.SeqNo
  1762. and T2.FinishFlag = 'N'
  1763. )
  1764. then 1
  1765. else 0 end
  1766. )
  1767. +
  1768. (case
  1769. when exists(select 1
  1770. from SFDC_TimeHist as T3
  1771. where T3.Site = T.Site
  1772. and T3.OrderNo = T.OrderNo
  1773. and T3.ItemNo = T.ItemNo
  1774. and T3.SeqNo = T.SeqNo
  1775. and T3.CompletedFlag = 'N'
  1776. )
  1777. then 1
  1778. else 0 end
  1779. )
  1780. +
  1781. (case
  1782. when exists(select 1
  1783. from SFDC_RollOps as T4
  1784. where T4.Site = T.Site
  1785. and T4.OrderNo = T.OrderNo
  1786. and T4.ItemNo = T.ItemNo
  1787. and T4.SeqNo = T.SeqNo
  1788. and T4.FinishedFlag = 'N'
  1789. )
  1790. then 1
  1791. else 0 end
  1792. )
  1793. ) > 0
  1794. </select>
  1795. <select id="getUserSpecialSecurity" resultType="java.lang.String">
  1796. select dbo.Get_User_Special_Security(#{username}, #{sNo})
  1797. </select>
  1798. <insert id="saveSfdcDefect" parameterType="SfdcDefectData">
  1799. INSERT INTO SFDC_DefectHist(Site, OrderNo, ItemNo, SeqNo, HistSeqNo, ReportDate, Reportedby, DefectCode,
  1800. DefectQty, RollNo)
  1801. VALUES (#{site}, #{orderNo}, #{itemNo}, #{seqNo}, #{histSeqNo}, #{reportedDate}, #{reportedBy}, #{defectCode},
  1802. #{defectQty}, #{rollNo})
  1803. </insert>
  1804. <insert id="saveSfdcDefectList">
  1805. INSERT INTO
  1806. SFDC_DefectHist(Site,OrderNo,ItemNo,SeqNo,HistSeqNo,ReportDate,Reportedby,DefectCode,DefectQty,RollNo)
  1807. VALUES
  1808. <foreach collection="list" separator="," item="item">
  1809. ( #{item.site},#{item.orderNo},#{item.itemNo},#{item.seqNo},#{item.histSeqNo}
  1810. ,#{item.reportedDate},#{item.reportedBy},#{item.defectCode},#{item.defectQty},#{item.rollNo} )
  1811. </foreach>
  1812. </insert>
  1813. <insert id="insertShopOrderChangeHist">
  1814. Insert into ShopOrderChangeHist(Site, OrderNo, CreateDate, Fieldname, FieldCaption, OldValue, NewValue, UserID,
  1815. RecordType, Remark)
  1816. Values (#{site}, #{orderNo}, getdate(), '*', '*', '*', '*', #{username}, '更改', #{orderChangeStatus})
  1817. </insert>
  1818. <select id="getSORoutingPreviousOperationItemNo" resultType="java.lang.Integer">
  1819. select dbo.Get_SORouting_PreviousOperationItemNo(#{site}, #{orderNo}, #{itemNo})
  1820. </select>
  1821. <select id="getShopOrderType" resultType="java.lang.String">
  1822. Select OrderType as order_type
  1823. from ShopOrder
  1824. where Site = #{site}
  1825. and OrderNo = #{orderNo}
  1826. </select>
  1827. <!--查询分切工单的物料信息-->
  1828. <select id="getSplitOrderParts" parameterType="SearchScheduleData" resultType="java.util.HashMap">
  1829. SELECT vss.Site site,
  1830. vss.SAPOrderNo sapOrderNo,
  1831. vss.OrderNo orderNo,
  1832. vss.OrderItemNo bomItemNo,
  1833. vss.PartNo partNo,
  1834. vss.PartDescription partDesc,
  1835. vss.Quantity orderQty
  1836. FROM view_sap_slitting_partlist vss
  1837. WHERE vss.Site = #{site}
  1838. AND vss.OrderNo = #{orderNo}
  1839. </select>
  1840. <!--统计C_RollInfo是否报工过-->
  1841. <select id="countCRollByRollNo" parameterType="SearchScheduleData" resultType="java.lang.Integer">
  1842. SELECT COUNT(1) FROM C_RollInfo cri
  1843. <where>
  1844. cri.Site = #{site} AND cri.OrderRef1 = #{orderNo} AND cri.OriginalRollNo = #{rollNo}
  1845. </where>
  1846. </select>
  1847. <!--统计C_RollInfo表的报工数据-->
  1848. <select id="getCRollReportedQty" parameterType="SearchScheduleData" resultType="java.lang.Float">
  1849. SELECT SUM(ISNULL(cri.RollQty, 0)) FROM C_RollInfo cri
  1850. <where>
  1851. cri.Site = #{site} AND cri.OrderRef1 = #{orderNo} AND cri.OriginalRollNo = #{rollNo}
  1852. </where>
  1853. </select>
  1854. <!--修改派工单的排料标记-->
  1855. <update id="updateSoScheduledRoutingMatIssueFlag" parameterType="SearchScheduleData">
  1856. UPDATE SOScheduledRouting
  1857. SET mat_issueflag = #{matIssueFlag}
  1858. WHERE Site = #{site}
  1859. AND OrderNo = #{orderNo}
  1860. AND SeqNo = #{seqNo}
  1861. </update>
  1862. <!--修改派工单的网版标记-->
  1863. <update id="updateSoScheduledRoutingPlateIssueFlag" parameterType="SearchScheduleData">
  1864. UPDATE SOScheduledRouting
  1865. SET plate_issueflag = #{plateIssueFlag}
  1866. WHERE Site = #{site}
  1867. AND OrderNo = #{orderNo}
  1868. AND SeqNo = #{seqNo}
  1869. </update>
  1870. <!--修改派工单的刀模标记-->
  1871. <update id="updateSoScheduledRoutingToolIssueFlag" parameterType="SearchScheduleData">
  1872. UPDATE SOScheduledRouting
  1873. SET tool_issueflag = #{toolIssueFlag}
  1874. WHERE Site = #{site}
  1875. AND OrderNo = #{orderNo}
  1876. AND SeqNo = #{seqNo}
  1877. </update>
  1878. <update id="updateSOScheduledRouting">
  1879. Update SOScheduledRouting
  1880. Set ClosedFlag='Y'
  1881. , Closedby=#{userId}
  1882. , ClosedDate=getdate()
  1883. Where Site = #{site}
  1884. and OrderNo = #{orderNo}
  1885. and ItemNo = #{itemNo}
  1886. and SeqNo = #{seqNo}
  1887. </update>
  1888. <!-- 更新派工单的备注 -->
  1889. <update id="updateSOScheduledRoutingRemark">
  1890. UPDATE SOScheduledRouting
  1891. SET Remark = #{remark}
  1892. WHERE Site = #{site}
  1893. AND OrderNo = #{orderNo}
  1894. AND ItemNo = #{itemNo}
  1895. AND SeqNo = #{seqNo}
  1896. </update>
  1897. <select id="checkKeyMart" resultType="java.lang.String">
  1898. Select Isnull(RMType_DB, '') as RMType_DB
  1899. From dbo.view_SAP_SOBOM as B
  1900. Where B.Site = #{site}
  1901. and B.OrderNo = #{orderNo}
  1902. and B.ItemNo = #{bomItemNo}
  1903. </select>
  1904. <select id="sumProductionCapacity" resultType="java.lang.Double">
  1905. SELECT
  1906. sum (dbo.getScheduleToPlanTime ( D.LotSize, T.MachSetupTime, T.MachRunFactor, T.FactorUnit, t.Efficiency ))
  1907. scheduleToPlanTime
  1908. FROM
  1909. SORouting AS T
  1910. LEFT JOIN ShopOrder AS D ON T.Site= D.Site
  1911. AND T.OrderNo= D.OrderNo
  1912. <where>
  1913. Round(T.QtyScheduled,3) <![CDATA[ < ]]> round(T.QtyRequired,3) and T.ClosedFlag = 'N' AND T.WorkCenterNo
  1914. <![CDATA[<>]]> 'FQC'
  1915. <if test="username != null and username != ''">
  1916. and T.site in (Select Site from AccessSite where upper(UserID)=#{username})
  1917. </if>
  1918. and T.OrderNo<![CDATA[ <> ]]>'9999' and isnull(D.Status,'')<![CDATA[ <> ]]>'已取消' and isnull(D.Status,'')
  1919. <![CDATA[ <> ]]>'已计划'
  1920. and isnull(D.Status,'')<![CDATA[ <> ]]>'已关闭'
  1921. <if test="enterTime1 != null">
  1922. and D.EnterDate<![CDATA[ >= ]]> #{enterTime1}
  1923. </if>
  1924. <if test="enterTime2 != null">
  1925. and D.EnterDate-1 <![CDATA[<]]> #{enterTime2}
  1926. </if>
  1927. <if test="needTime1 != null">
  1928. and D.NeedDate<![CDATA[ >= ]]>#{needTime1}
  1929. </if>
  1930. <if test="needTime2 != null">
  1931. and D.NeedDate<![CDATA[ <= ]]>#{needTime2}
  1932. </if>
  1933. <if test="site != null and site != ''">
  1934. AND T.Site like '%' + #{site} + '%'
  1935. </if>
  1936. <if test="partNo != null and partNo != ''">
  1937. AND T.PartNo like '%' + #{partNo} + '%'
  1938. </if>
  1939. AND T.WorkCenterNo = #{workCenterNo}
  1940. <if test="scheduledFlag != null and scheduledFlag != ''">
  1941. AND Isnull(S1.ScheduledFlag, 'Y') = #{scheduledFlag}
  1942. </if>
  1943. </where>
  1944. </select>
  1945. <select id="getBomItemNosByKeyPartNo" resultType="java.util.Map">
  1946. SELECT Site site,
  1947. OrderNo orderNo,
  1948. CONVERT(INT, ItemNo) itemNo,
  1949. ComponentPartNo partNo,
  1950. QtyAssembly qtyAssembly,
  1951. QtyFixedScrapt qtyFixedScrapt,
  1952. ScraptFactor scraptFactor,
  1953. Remark remark,
  1954. QtyRequired qtyRequired,
  1955. QtyIssue qtyIssue,
  1956. CONVERT(VARCHAR(20), IssueDate, 120) issueDate,
  1957. QtyReserved qtyReserved,
  1958. MatGroup matGroup,
  1959. QtyNotified qtyNotified,
  1960. RMType_DB rmTypeDb,
  1961. IssueType issueType
  1962. FROM dbo.view_SAP_SOBOM vss
  1963. WHERE vss.Site = #{site}
  1964. AND vss.RMType_DB = 'key Mart'
  1965. AND vss.OrderNo = #{orderNo}
  1966. AND vss.ComponentPartNo = #{rmPartNo}
  1967. </select>
  1968. <select id="deleteSfdcDefect" resultType="java.util.Map">
  1969. exec dbo.RemoveSfdcDefect #{site},#{orderNo},#{itemNo},#{seqNo},#{rollNo},#{histSeqNo}
  1970. </select>
  1971. <select id="deleteSfdcTimeHist" resultType="java.util.Map">
  1972. exec dbo.RemoveSfdcTimeHist #{site},#{orderNo},#{itemNo},#{seqNo},#{rollNo},#{histSeqNo}
  1973. </select>
  1974. <select id="deleteSfdcMaterialHist" resultType="java.util.Map">
  1975. exec dbo.RemoveSfdcMaterialHist #{site},#{orderNo},#{itemNo},#{seqNo},#{rollNo},#{histSeqNo},#{histType}
  1976. </select>
  1977. <!-- 获取固定载具列表 -->
  1978. <select id="getFixedCarrierList" resultType="map">
  1979. SELECT
  1980. site,
  1981. bu_no AS buNo,
  1982. carrier_no AS carrierNo,
  1983. carrier_type_code AS carrierTypeCode,
  1984. carrier_type_name AS carrierTypeName,
  1985. specification,
  1986. asset_no AS assetNo,
  1987. dimensions,
  1988. max_weight AS maxWeight,
  1989. expected_life_cycles AS expectedLifeCycles,
  1990. expected_life_days AS expectedLifeDays,
  1991. status,
  1992. current_location AS currentLocation,
  1993. last_used_time AS lastUsedTime,
  1994. total_usage_count AS totalUsageCount,
  1995. purchase_date AS purchaseDate,
  1996. create_by AS createBy,
  1997. create_date AS createDate,
  1998. remark,
  1999. available_qty AS availableQty
  2000. FROM fixed_carrier
  2001. WHERE site = #{site} and status = 1
  2002. <if test="carrierNo != null and carrierNo != ''">
  2003. AND carrier_no LIKE '%' + #{carrierNo} + '%'
  2004. </if>
  2005. <if test="carrierTypeName != null and carrierTypeName != ''">
  2006. AND carrier_type_name LIKE '%' + #{carrierTypeName} + '%'
  2007. </if>
  2008. <if test="specification != null and specification != ''">
  2009. AND specification LIKE '%' + #{specification} + '%'
  2010. </if>
  2011. ORDER BY carrier_no
  2012. </select>
  2013. <!-- 批量更新固定载具可用数量 -->
  2014. <update id="updateFixedCarrierBatch">
  2015. <foreach collection="list" item="item" separator=";">
  2016. UPDATE fixed_carrier
  2017. SET available_qty = #{item.availableQty}
  2018. WHERE site = #{item.site}
  2019. AND carrier_no = #{item.carrierNo}
  2020. </foreach>
  2021. </update>
  2022. <!-- 查询工单的订单备注信息 -->
  2023. <select id="getOrderNotesByOrderNo" parameterType="SearchScheduleData" resultType="java.util.Map">
  2024. SELECT TOP 1
  2025. B.orderref01 AS orderNotes -- 订单备注信息
  2026. FROM ShopOrder A
  2027. LEFT JOIN outbound_notification_detail B
  2028. ON A.Site = B.site
  2029. AND A.bu_no = B.bu_no
  2030. AND A.batch_no = B.related_order_no
  2031. WHERE A.Site = #{site}
  2032. AND A.OrderNo like '%' + #{batchNo} +'%'
  2033. </select>
  2034. <!-- 扫描获取新卷数量 -->
  2035. <select id="getNewRollQtyByScan" resultType="java.lang.Float">
  2036. SELECT RollQty as rollQty
  2037. FROM SFDC_Rolls
  2038. WHERE site = #{site}
  2039. AND RollNo = #{rollNo}
  2040. </select>
  2041. <!-- 获取领料记录 -->
  2042. <select id="getMaterialRecordList" resultType="java.util.Map">
  2043. select * from (
  2044. select
  2045. A.site,
  2046. A.bu_no as buNo,
  2047. A.transaction_id as transactionId,
  2048. A.document_type as documentType,
  2049. A.document_no as documentNo,
  2050. A.roll_no as rollNo,
  2051. B.status, --标签状态
  2052. (CASE WHEN B.consumed_flag = 'Y' THEN '已消耗' ELSE '未使用' END) consumedFlag , --是否耗用
  2053. A.roll_qty as rollQty,
  2054. A.batch_no as batchNo,
  2055. A.transaction_by as transactionBy,
  2056. A.transaction_date as transactionDate
  2057. from StockTransactionLog A WITH(NOLOCK)
  2058. INNER JOIN inventory_stock B WITH(NOLOCK) ON A.site = B.site AND A.roll_no = B.roll_no
  2059. where A.site =#{site} and A.order_no = #{orderNo} AND a.part_no = #{partNo} and a.document_type in ('生产领料','生产退仓')
  2060. UNION ALL
  2061. SELECT
  2062. A.site,
  2063. A.bu_no buNo,
  2064. A.orderref1 as transactionId,
  2065. A.orderref0 as documentType,
  2066. A.orderref1 as documentNo,
  2067. A.roll_no rollNo,
  2068. A.status, --标签状态
  2069. (CASE WHEN a.consumed_flag = 'Y' THEN '已消耗' ELSE '未使用' END) consumedFlag , --是否使用
  2070. a.qty_on_hand as rollQty,
  2071. a.batch_no batchNo,
  2072. create_by as transactionBy ,
  2073. latest_in_date as transactionDate
  2074. FROM inventory_stock A WITH(NOLOCK)
  2075. WHERE A.site =#{site} and A.orderref1 = #{orderNo} AND A.part_no = #{partNo} and a.orderref0 ='生产退仓' AND a.status = '待入'
  2076. ) T
  2077. <where>
  2078. <if test="transactionId != null and transactionId != ''">
  2079. and T.transactionId like concat('%', #{transactionId}, '%')
  2080. </if>
  2081. <if test="documentType != null and documentType != ''">
  2082. and T.documentType = #{documentType}
  2083. </if>
  2084. <if test="rollNo != null and rollNo != ''">
  2085. and T.rollNo like concat('%', #{rollNo}, '%')
  2086. </if>
  2087. <if test="status != null and status != ''">
  2088. and T.status = #{status}
  2089. </if>
  2090. <if test="consumedFlag != null and consumedFlag != ''">
  2091. and T.consumedFlag = #{consumedFlag}
  2092. </if>
  2093. </where>
  2094. </select>
  2095. <!-- 调用存储过程 sfdcRollsOpsReportExecute 用于打开材料卷 -->
  2096. <select id="callSfdcRollsOpsReportExecute" resultType="java.util.Map" statementType="CALLABLE">
  2097. exec sfdcRollsOpsReportExecute
  2098. #{site},
  2099. #{seqNo},
  2100. #{rollNo},
  2101. #{histSeqNo},
  2102. #{type},
  2103. #{userId}
  2104. </select>
  2105. <!-- 调用存储过程 UspUpdateProductionStatus:暂停生产/继续生产(写入 SFDC_TimeHist 并更新 ParkFlag) -->
  2106. <select id="updateProductionStatus" resultType="java.util.Map">
  2107. exec dbo.UspUpdateProductionStatus
  2108. #{site},
  2109. #{orderNo},
  2110. #{seqNo},
  2111. #{itemNo},
  2112. #{rollNo},
  2113. #{currentTime},
  2114. #{operatorId},
  2115. #{parkFlag}
  2116. </select>
  2117. </mapper>