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.

291 lines
16 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years 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.jtem.modules.Schedule.dao.ScheduleMapper">
  4. <select id="getShopOrderRoutingData" resultType="ShopOrderRoutingData">
  5. select a.site, a.OrderNo,a.PartNo,a.Status,a.PlanStartDate,a.NeedDate,a.LotSize,a.EnterDate,a.UserName,
  6. P.Spec+'/'+isnull(P.PartDescription,'') PartDescription,P.Spec,isnull(SL.scheduledQty,0) as scheduledQty,s.workCenterNo,S.qtyReported,S.qtyApprove,S.machSetupTime,
  7. S.machRunFactor,S.factorUnit,S.ItemNo,S.OperationDesc,s.Efficiency,isnull(SOP.TotalFinishedQty,0) lastApproveQty
  8. FROM ShopOrder a
  9. LEFT JOIN Part P ON P.PartNo=a.PartNo AND a.site=P.Site
  10. LEFT JOIN v_SORouting S on S.site=a.site and S.OrderNo=a.orderNo
  11. LEFT JOIN ScheduleList SL on S.site=SL.site and S.OrderNo=SL.orderNo and S.ItemNo=SL.ItemNo
  12. LEFT JOIN SORoutingOutput SOP ON a.site=SOP.site and a.OrderNo=SOP.OrderNo and SOP.itemNo=dbo.Get_SORouting_PreviousOperationItemNo(a.site,a.OrderNo,S.itemNo)
  13. <!-- left join user_work_center uwc on a.site=uwc.site and s.workCenterNo =uwc.WorkCenterNo and uwc.userId=#{userId}-->
  14. <!-- left join CODetail cod on a.site=cod.site and a.orderRef1=cod.OrderNo and a.orderRef2= CONVERT(VARCHAR(10),cod.ItemNo)-->
  15. <where>
  16. <!-- and uwc.WorkCenterNo is not null-->
  17. <!-- and a.E_Levels =0-->
  18. <if test="site != null and site != ''">
  19. AND a.site = #{site}
  20. </if>
  21. <if test="orderNo != null and orderNo != ''">
  22. AND a.OrderNo LIKE '%' + #{orderNo} + '%'
  23. </if>
  24. <!-- <if test="status !=null and status != ''">-->
  25. <!-- AND a.Status IN ${status}-->
  26. <!-- </if>-->
  27. and a.status in ('已下达','已发料','已入库','已开工','已排产')
  28. <if test="startDate1 != null ">
  29. AND a.EnterDate >= #{startDate1}
  30. </if>
  31. <if test="endDate1 != null ">
  32. AND #{endDate1} >= DATEADD(dd, -1, a.EnterDate)
  33. </if>
  34. <if test="startDate2 != null ">
  35. AND a.PlanStartDate >= #{startDate2}
  36. </if>
  37. <if test="endDate2 != null ">
  38. AND #{endDate2} >= a.PlanStartDate
  39. </if>
  40. <if test="startDate3 != null ">
  41. AND a.NeedDate >= #{startDate3}
  42. </if>
  43. <if test="endDate3 != null ">
  44. AND #{endDate3} >= a.NeedDate
  45. </if>
  46. <if test="startDate4 != null ">
  47. AND cod.PlanShipDate >= #{startDate4}
  48. </if>
  49. <if test="partNo != null and partNo != ''">
  50. AND a.PartNo LIKE '%' + #{partNo} + '%'
  51. </if>
  52. <if test="planStatus != null and planStatus != ''">
  53. and ${planStatus}
  54. </if>
  55. <if test="itemNo != null and itemNo != ''">
  56. and S.ItemNo = #{itemNo}
  57. </if>
  58. <!-- <if test="eLevels != null ">-->
  59. <!-- and a.E_Levels = #{eLevels}-->
  60. <!-- </if>-->
  61. </where>
  62. order by a.PlanStartDate desc,s.itemNo
  63. </select>
  64. <select id="getOperatorList" resultType="OperatorData">
  65. Select a.OperatorID,a.OperatorName from Operator a where a.site=#{site} and a.Active='Y'
  66. </select>
  67. <select id="checkScheduleQty" resultType="ScheduleCheckData">
  68. Select a.lotSize as Qty,isnull(b.scheduledQty,0) scheduledQty from ShopOrder a left join ScheduleList b on a.site=b.site and a.orderNo=b.orderNo and b.itemNo=#{itemNo} where a.Site=#{site} and a.OrderNo=#{orderNo}
  69. </select>
  70. <select id="checkScheduleList" resultType="ScheduleCheckData">
  71. Select Qty from ScheduleList where Site=#{site} and OrderNo=#{orderNo} and itemNo=#{itemNo}
  72. </select>
  73. <insert id="saveScheduleList">
  74. insert into ScheduleList(Site,OrderNo,ItemNo,Type,Type_db,Qty,scheduledQty) values (#{site},#{orderNo},#{itemNo},'生产订单派工单','S',#{qty},0)
  75. </insert>
  76. <select id="getDataSequence" resultType="integer">
  77. select seqNo from DataSequence where SeqType= 'A'
  78. </select>
  79. <update id="updateDataSequence">
  80. update DataSequence set seqNo=seqNo+1 where SeqType= 'A'
  81. </update>
  82. <insert id="saveSchedule">
  83. Insert into soscheduledrouting(Site,OrderNo,ItemNo,SeqNo,QtyRequired,QtyReported,QtyApprove,TimeRequired,TimeReported,PlanStartTime,PlanFinishTime
  84. ,BarcodeID,Remark,Crewsize,ClosedFlag,QtyScrapt,OutWorkFlag,S_ScheduledDate,S_ResourceID,S_ShiftNo,S_WorkCenterNo
  85. ,SelectedFlag,SourceFlag,ParkFlag,TimeRequired_Original,QtyRequired_Original
  86. ,StartProdFlag,CancelledProdFlag,Efficiency,EnteredDate,scheduleType,operatorId,partNo,OrderRef1,cancelReportFlag,CreateBy,WorkTime,stopTime)
  87. values(#{site},#{orderNo},#{itemNo},#{seqNo},#{scheduleQty},0,0,dbo.Get_SOScheduleRouting_TimeRequired(#{site},#{orderNo},#{itemNo},#{scheduleQty}),0,#{scheduleDate},#{scheduleDate}
  88. ,'*',#{remark},1,'N',0,'Y',#{scheduleDate},#{resourceId},#{shiftNo},#{workCenterNo}
  89. ,'N','N','N',dbo.Get_SOScheduleRouting_TimeRequired(#{site},#{orderNo},#{itemNo},#{scheduleQty}),#{scheduleQty}
  90. ,'N','N',#{efficiency},GETDATE(),'生产订单派工单',#{operatorId},#{partNo},#{orderNo},'N',#{createBy},0,0)
  91. </insert>
  92. <update id="updateScheduleListQty">
  93. update ScheduleList set scheduledQty=scheduledQty+#{sumQty} where Site=#{site} and OrderNo=#{orderNo} and itemNo=#{itemNo} and type=#{scheduleType}
  94. </update>
  95. <select id="searchLastApproveQty" resultType="SORoutingData">
  96. select top 1 isnull(TotalFinishedQty,0) lastApproveQty from v_SORouting where Site=#{site} and OrderNo=#{orderNo} and itemNo=dbo.Get_SORouting_PreviousOperationItemNo(#{site},#{orderNo},#{itemNo})
  97. </select>
  98. <select id="getSOScheduleRoutingData" resultType="SOScheduledRoutingOutData">
  99. select a.Site,OrderNo,ItemNo,SeqNo,QtyRequired,QtyReported,QtyApprove,TimeRequired,TimeReported,
  100. BarcodeID,Remark,Crewsize,ClosedFlag,S_ScheduledDate,S_ResourceID,S_ScheduledSeqNo,S_ShiftNo,
  101. S_WorkCenterNo, EnteredDate,scheduleType,operatorId,partNo,dbo.Get_Part_SpecDesc(a.Site,partNo) as partDesc,
  102. dbo.Get_OperatorDesc(a.Site,operatorId) as operatorName,dbo.Get_ItemDesc(a.Site,OrderNo,ItemNo) as itemDesc,orderRef1 ,
  103. dbo.Get_WorkCenterDesc(a.Site,S_WorkCenterNo) as workCenterDesc , dbo.Get_Part_SpecDesc(a.Site,partNo) as partSpec,circulation_seqNo,circulation_qty
  104. ,dbo.Get_Part_UMID(a.Site,PartNo) umid from SOScheduledRouting a
  105. <!-- left join user_work_center uwc on a.site=uwc.site and a.S_WorkCenterNo =uwc.WorkCenterNo and uwc.userId=#{userId}-->
  106. <where>
  107. <!-- and uwc.WorkCenterNo is not null-->
  108. <if test="site != null and site != ''">
  109. AND a.site = #{site}
  110. </if>
  111. <if test="orderNo != null and orderNo != ''">
  112. AND OrderNo LIKE '%' + #{orderNo} + '%'
  113. </if>
  114. <if test="seqNo != null ">
  115. AND seqNo = #{seqNo}
  116. </if>
  117. <if test="partNo != null and partNo != ''">
  118. AND PartNo LIKE '%' + #{partNo} + '%'
  119. </if>
  120. <if test="sWorkCenterNo != null and sWorkCenterNo != ''">
  121. AND S_WorkCenterNo LIKE '%'+#{sWorkCenterNo}+'%'
  122. </if>
  123. <if test="itemNo != null and itemNo != ''">
  124. and ItemNo = #{itemNo}
  125. </if>
  126. <if test="itemDesc != null and itemDesc != ''">
  127. and dbo.Get_ItemDesc(a.Site,OrderNo,ItemNo) = #{itemDesc}
  128. </if>
  129. <if test="closedFlag != null and closedFlag != ''">
  130. and ClosedFlag = #{closedFlag}
  131. </if>
  132. <if test="startDate != null ">
  133. and S_ScheduledDate >= #{startDate}
  134. </if>
  135. <if test="endDate != null ">
  136. and #{endDate} >= S_ScheduledDate
  137. </if>
  138. <if test="scheduleType != null and scheduleType != ''">
  139. and scheduleType = #{scheduleType}
  140. </if>
  141. <if test="reportFlag != null and reportFlag != ''">
  142. and ${reportFlag}
  143. </if>
  144. <if test="operatorName != null and operatorName != ''">
  145. and dbo.Get_OperatorDesc(a.Site,operatorId) like '%'+#{operatorName}+'%'
  146. </if>
  147. <if test="sResourceID != null and sResourceID != ''">
  148. and S_ResourceID like '%'+#{sResourceID}+'%'
  149. </if>
  150. <if test="sShiftNo != null and sShiftNo != ''">
  151. and S_ShiftNo = #{sShiftNo}
  152. </if>
  153. </where>
  154. order by S_ScheduledDate
  155. </select>
  156. <select id="getOldSOScheduledRoutingOutData" resultType="SOScheduledRoutingOutData">
  157. select Site,OrderNo,ItemNo,SeqNo,QtyRequired,QtyReported,QtyApprove,TimeRequired,TimeReported,PlanStartTime,PlanFinishTime,
  158. BarcodeID,Remark,Crewsize,ClosedFlag,QtyScrapt,OutWorkFlag,S_ScheduledDate,S_ResourceID,S_ScheduledSeqNo,S_ShiftNo,
  159. S_WorkCenterNo,ParkFlag,TimeRequired_Original,QtyRequired_Original,QtyReturntoSchedule,StartProdFlag,CancelledProdFlag,
  160. Efficiency,EnteredDate,SelectedFlag,SourceFlag,Closedby,ClosedDate,VirtualResourceFlag,mat_issueflag,plate_issueflag,
  161. tool_issueflag,scheduleType,operatorId,partNo,orderRef1,circulation_seqNo,circulation_qty from SOScheduledRouting where
  162. site=#{site} and seqNo=#{seqNo}
  163. </select>
  164. <update id="closeOldSchedule">
  165. update SOScheduledRouting set ClosedFlag='Y',circulation_seqNo=#{newSeqNo},circulation_qty=#{circulationQty} where site=#{site} and seqNo=#{oldSeqNo}
  166. </update>
  167. <insert id="saveCirculationSchedule" >
  168. INSERT into SOScheduledRouting (Site,OrderNo,ItemNo,SeqNo,QtyRequired,QtyReported,QtyApprove,TimeRequired,TimeReported,PlanStartTime,PlanFinishTime,
  169. BarcodeID,Remark,Crewsize,ClosedFlag,QtyScrapt,OutWorkFlag,S_ScheduledDate,S_ResourceID,S_ScheduledSeqNo,S_ShiftNo,
  170. S_WorkCenterNo,ParkFlag,TimeRequired_Original,QtyRequired_Original,QtyReturntoSchedule,StartProdFlag,CancelledProdFlag,
  171. Efficiency,EnteredDate,SelectedFlag,SourceFlag,Closedby,ClosedDate,VirtualResourceFlag,mat_issueflag,plate_issueflag,
  172. tool_issueflag,scheduleType,operatorId,partNo,orderRef1) values
  173. (#{site},#{orderNo},#{itemNo},#{seqNo},#{qtyRequired},0,0,0,0,#{planStartTime},#{planFinishTime},
  174. #{barcodeID},#{remark},#{crewsize},'N',0,'Y',#{sScheduledDate},#{sResourceID},#{sScheduledSeqNo},#{sShiftNo},
  175. #{sWorkCenterNo},#{parkFlag},#{timeRequiredOriginal},#{qtyRequiredOriginal},null,'N','N',
  176. 0,GetDate(),'N','N',NULL,NULL,NULL,#{matIssueflag},'N','N',#{scheduleType},#{operatorId},#{partNo},#{orderRef1}
  177. )
  178. </insert>
  179. <update id="closeSchedule">
  180. update SOScheduledRouting set ClosedFlag='Y' where site=#{site} and seqNo=#{seqNo}
  181. </update>
  182. <select id="searchReportedQty" resultType="SORoutingData">
  183. select top 1 isnull(a.QtyReported,0) QtyReported,isnull(SOP.TotalFinishedQty,0) lastApproveQty
  184. from v_SORouting a
  185. LEFT JOIN SORoutingOutput SOP ON a.site=SOP.site and a.OrderNo=SOP.OrderNo and SOP.itemNo=dbo.Get_SORouting_PreviousOperationItemNo(a.site,a.OrderNo,a.itemNo)
  186. where a.Site=#{site} and a.OrderNo=#{orderNo} and a.itemNo=#{itemNo}
  187. </select>
  188. <select id="getSeqNoSite" resultType="String">
  189. select site from SOScheduledRouting where SeqNo=#{seqNo}
  190. </select>
  191. <select id="searchSeqNo" resultType="SOScheduledRoutingOutData">
  192. select top 1 Site,OrderNo,ItemNo,SeqNo,QtyRequired,QtyReported,QtyApprove,TimeRequired,TimeReported,
  193. BarcodeID,Remark,Crewsize,ClosedFlag,S_ScheduledDate,S_ResourceID,S_ScheduledSeqNo,S_ShiftNo,
  194. S_WorkCenterNo, EnteredDate,scheduleType,operatorId,partNo,dbo.Get_PartDesc(Site,partNo) as partDesc,
  195. dbo.Get_OperatorDesc(Site,operatorId) as operatorName,dbo.Get_ItemDesc(site,orderNo,ItemNo) as itemDesc,orderRef1 ,
  196. dbo.Get_WorkCenterDesc(Site,S_WorkCenterNo) as workCenterDesc , dbo.Get_Part_SpecDesc(Site,partNo) as partSpec,closedFlag,outWorkFlag,ParkFlag,CancelReportFlag
  197. from SOScheduledRouting
  198. where SeqNo=#{seqNo}
  199. </select>
  200. <select id="checkFirstItem" resultType="SOScheduledRoutingOutData">
  201. select site from v_SORouting where orderNo=#{orderNo} and site=#{site} and #{itemNo} >itemNo
  202. </select>
  203. <update id="updateOutWorkFlag">
  204. update SOScheduledRouting set OutWorkFlag='N' where SeqNo =#{seqNo}
  205. </update>
  206. <select id="getSfdcList" resultType="com.jtem.modules.Schedule.entity.SfdcCancel">
  207. select a.site,a.OrderNo,a.ItemNo ,a.SeqNo,a.WorkCenterNo,a.ReportDate,a.OperatorID,a.ReportQty,a.ApproveQty,a.ReportedManfTime,a.StatisticDate,
  208. a.AssJobSeqNo,a.Scheduled_ResourceId ResourceID,b.S_ShiftNo ShiftNo,b.partNo,dbo.Get_ItemDesc(a.site,a.OrderNo,a.ItemNo) operation_desc,c.OperatorName,b.S_ShiftNo ShiftDesc,e.ResourceDesc,Reverseflag
  209. ,dbo.Get_Part_Spec(a.site,b.partNo) partSpec,dbo.Get_PartDesc(a.site,b.partNo) PartDesc
  210. from sfdc a LEFT JOIN SOScheduledRouting b on a.Site=b.Site and a.AssJobSeqNo=b.SeqNo
  211. left join Operator c on a.site=c.site and a.OperatorID=c.OperatorID
  212. left join WorkCenterResource e on a.Site=e.Site and a.Scheduled_ResourceId =e.ResourceID and a.WorkCenterNo=e.WorkCenterNo
  213. <where>
  214. and a.AssJobSeqNo is not null
  215. <if test="orderNo != null and orderNo != ''">
  216. and a.OrderNo like '%'+#{orderNo}+'%'
  217. </if>
  218. <if test="workCenterNo != null and workCenterNo != ''">
  219. and a.WorkCenterNo like '%'+#{workCenterNo}+'%'
  220. </if>
  221. <if test="partNo != null and partNo != ''">
  222. and b.partNo like '%'+#{partNo}+'%'
  223. </if>
  224. <if test="itemNo != null and itemNo != ''">
  225. and a.ItemNo = #{itemNo}
  226. </if>
  227. <if test="operatorName != null and operatorName != ''">
  228. and c.OperatorName like '%'+#{operatorName}+'%'
  229. </if>
  230. <if test="resourceId != null and resourceId != ''">
  231. and a.Scheduled_ResourceId = #{resourceId}
  232. </if>
  233. <if test="shiftNo != null and shiftNo != ''">
  234. and b.S_ShiftNo = #{shiftNo}
  235. </if>
  236. <if test="startDate != null ">
  237. and ReportDate >= #{startDate}
  238. </if>
  239. <if test="endDate != null ">
  240. and #{endDate} >= ReportDate
  241. </if>
  242. <if test="seqNo != null and seqNo != '' ">
  243. and a.AssJobSeqNo = #{seqNo}
  244. </if>
  245. </where>
  246. order by a.ReportDate desc
  247. </select>
  248. <select id="getStockPrint" resultType="com.jtem.modules.Schedule.entity.InventoryStockData">
  249. select Site,WarehouseID,PartNo,BatchNo,LocationID,FirstInDate,LatestOutDate,LatestInDate,ActiveDate,InQty,OutQty,Round(QtyOnHand,4) QtyOnHand,
  250. QtyReserved,InStandardValue,InActualValue,OutStandardValue,OutActualValue,PartnerID,PartnerType,LatestCountDate,
  251. Freezeflag,QtyTmp,ManufactureDate,ExpiredDate,QtytoIssue,DemandPartnerType,DemandPartnerID,DemandPartnerName
  252. ,dbo.Get_Part_DescSpec(Site,PartNo) partDesc
  253. from InventoryStock
  254. <where>
  255. <if test="partNo != null and partNo != '' ">
  256. and PartNo >= #{partNo}
  257. </if>
  258. <if test="batchNo != null and batchNo != '' ">
  259. and BatchNo >= #{batchNo}
  260. </if>
  261. ${zeroSql}
  262. </where>
  263. </select>
  264. </mapper>