赫艾后端
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.

1287 lines
70 KiB

4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
2 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
2 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
2 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
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
2 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
2 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
2 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 years ago
3 years ago
4 years ago
2 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 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
4 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
4 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
4 years ago
2 years ago
4 years ago
3 years ago
2 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
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
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 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
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 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
2 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
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 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.heai.modules.production.dao.DailyPlanMapper">
  4. <select id="getShopOrderData" resultType="com.heai.modules.production.entity.ShopOrderData" parameterType="com.heai.modules.production.entity.DailyPlanInData">
  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,ROUND(ISNULL(so.scheduling_size,0),3) as scheduling_size,dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderNo) as weightFactor,
  7. Round(dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderNo)*a.LotSize,2) as weight
  8. FROM ShopOrder a
  9. LEFT JOIN Part P ON P.PartNo=a.PartNo AND a.site=P.Site
  10. LEFT JOIN so_scheduled_list so ON a.site=so.Site AND a.OrderNo= so.order_no
  11. <where>
  12. <if test="site != null and site != ''">
  13. AND a.site = #{site}
  14. </if>
  15. <if test="partDescription != null and partDescription != ''">
  16. AND P.Spec+'/'+isnull(P.PartDescription,'') like #{partDescription}
  17. </if>
  18. <if test="orderNo != null and orderNo != ''">
  19. AND a.OrderNo LIKE #{orderNo}
  20. </if>
  21. <if test="status !=null and status != ''">
  22. AND a.Status IN ${status}
  23. </if>
  24. <if test="startDate1 != null ">
  25. AND a.EnterDate >= #{startDate1}
  26. </if>
  27. <if test="endDate1 != null ">
  28. AND #{endDate1} >= DATEADD(dd, -1, a.EnterDate)
  29. </if>
  30. <if test="startDate2 != null ">
  31. AND a.PlanStartDate >= #{startDate2}
  32. </if>
  33. <if test="endDate2 != null ">
  34. AND #{endDate2} >= a.PlanStartDate
  35. </if>
  36. <if test="startDate3 != null ">
  37. AND a.NeedDate >= #{startDate3}
  38. </if>
  39. <if test="endDate3 != null ">
  40. AND #{endDate3} >= a.NeedDate
  41. </if>
  42. <if test="partNo != null and partNo != ''">
  43. AND a.PartNo LIKE #{partNo}
  44. </if>
  45. <if test="planStatus != null and planStatus != ''">
  46. and ${planStatus}
  47. </if>
  48. AND a.PartNo like 'SP%'
  49. </where>
  50. order by a.PlanStartDate
  51. </select>
  52. <select id="getGenerateReportList" resultType="com.heai.modules.production.entity.GenerateReportData">
  53. Select T.Site,T.OrderNo,T.ItemNo,T.OperationDesc,T.WorkCenterNo,W.WorkCenterDesc,T.QtyRequired,T.QtyReported
  54. ,T.QtyApprove ,T.TimeRequired,T.TimeReported,T.PlanStartTime,T.PlanFinishTime
  55. ,T.ClosedFlag,T.PartNo,P.PartDescription,P.Spec,D.NeedDate,D.PlanStartDate,D.Status
  56. ,D.LotSize,D.FinishedQty
  57. from SORouting as T,ShopOrder as D,WorkCenter as W,Part as P
  58. <where>
  59. T.Site=D.Site and T.OrderNo=D.OrderNo and T.Site=W.Site and T.WorkCenterNo=W.WorkCenterNo
  60. and D.Site=P.Site and D.PartNo=P.PartNo
  61. <if test="site != null and site != ''">
  62. and T.site = #{site,jdbcType=VARCHAR}
  63. </if>
  64. <if test="workCenterNo != null and workCenterNo != ''">
  65. and T.WorkCenterNo like '%' + #{workCenterNo,jdbcType=VARCHAR} + '%'
  66. </if>
  67. <if test="partNo != null and partNo != ''">
  68. and T.PartNo like '%' + #{partNo,jdbcType=VARCHAR} + '%'
  69. </if>
  70. <if test="orderNo != null and orderNo != ''">
  71. and T.OrderNo like '%' + #{orderNo,jdbcType=VARCHAR} + '%'
  72. </if>
  73. </where>
  74. </select>
  75. <select id="getShopOrderForHunlian" resultType="com.heai.modules.production.entity.ShopOrderData">
  76. select A.OrderNo ,A.Site ,A.EnterDate ,A.UserName ,A.NeedDate ,A.OriginalNeedDate ,A.PlanStartDate ,A.ReleaseDate
  77. ,A.ReleaseGuys ,A.ScheduleDate ,A.Scheduler ,A.IssueDate ,A.ReportDate ,A.ReceiveDate ,A.CloseDate
  78. ,A.Planner ,A.Status ,A.Status_Tmp ,A.Printed ,A.OrderType ,A.PartNo ,A.LotSize ,A.FinishedQty
  79. ,A.ProjectID ,A.BOMRevNo ,A.RoutingRevNo ,A.Leadtime ,A.Remark ,A.OrderRef1 ,A.OrderRef2 ,A.CostRollUpFlag
  80. ,A.ManualFlag ,A.OriSOOrderNo ,A.CustomerID ,A.TechInfo ,A.ReceiveStatus ,A.E_OriginalOrderNo
  81. ,A.E_Levels ,A.E_OriginalOrderType ,A.E_SeqNo ,A.E_LevelCode ,A.SFDCReportedFlag ,A.RepairSOFlag
  82. ,A.ConfigurationFlag ,A.MaterialSplitFlag ,A.ObjectVersion ,A.ExpandFlag ,A.CodeNo ,A.LE_SeqNo
  83. ,A.LE_ItemNo ,A.LE_Levels
  84. ,B.PartDescription,dbo.Get_PartWeightFactorForReport(A.Site ,A.PartNo,A.OrderNo) as weightFactor,
  85. Round(dbo.Get_PartWeightFactorForReport(A.Site ,A.PartNo,A.OrderNo)*A.LotSize,2) weight
  86. from ShopOrder A
  87. left join Part B on A.site = B.site and A.PartNo = B.PartNo
  88. <where>
  89. and (a.PartNo like 'RC%' or a.PartNo like 'SC%')
  90. <if test="site != null and site != ''">
  91. and A.Site = #{site,jdbcType=VARCHAR}
  92. </if>
  93. <if test="orderNo != null and orderNo != ''">
  94. and A.OrderNo = #{orderNo,jdbcType=VARCHAR}
  95. </if>
  96. </where>
  97. </select>
  98. <select id="getHunlianTaskHeader" resultType="com.heai.modules.production.entity.HunlianData">
  99. select Site,TaskNo,orderRef1 from Hunlian_TaskHeader where DeleteFlag='N' and TaskNo=#{taskNo}
  100. </select>
  101. <select id="getShopOrderList" resultType="com.heai.modules.production.entity.ShopOrderData">
  102. select A.OrderNo ,A.Site ,A.EnterDate ,A.UserName ,A.NeedDate ,A.OriginalNeedDate ,A.PlanStartDate ,A.ReleaseDate
  103. ,A.ReleaseGuys ,A.ScheduleDate ,A.Scheduler ,A.IssueDate ,A.ReportDate ,A.ReceiveDate ,A.CloseDate
  104. ,A.Planner ,A.Status ,A.Status_Tmp ,A.Printed ,A.OrderType ,A.PartNo ,A.LotSize ,A.FinishedQty
  105. ,A.ProjectID ,A.BOMRevNo ,A.RoutingRevNo ,A.Leadtime ,A.Remark ,A.OrderRef1 ,A.OrderRef2 ,A.CostRollUpFlag
  106. ,A.ManualFlag ,A.OriSOOrderNo ,A.CustomerID ,A.TechInfo ,A.ReceiveStatus ,A.E_OriginalOrderNo
  107. ,A.E_Levels ,A.E_OriginalOrderType ,A.E_SeqNo ,A.E_LevelCode ,A.SFDCReportedFlag ,A.RepairSOFlag
  108. ,A.ConfigurationFlag ,A.MaterialSplitFlag ,A.ObjectVersion ,A.ExpandFlag ,A.CodeNo ,A.LE_SeqNo
  109. ,A.LE_ItemNo ,A.LE_Levels
  110. ,B.PartDescription
  111. from ShopOrder A
  112. left join Part B on A.site = B.site and A.PartNo = B.PartNo
  113. <where>
  114. <if test="site != null and site != ''">
  115. and A.Site = #{site,jdbcType=VARCHAR}
  116. </if>
  117. <if test="orderNo != null and orderNo != ''">
  118. and A.OrderNo = #{orderNo,jdbcType=VARCHAR}
  119. </if>
  120. </where>
  121. </select>
  122. <select id="getTransfer" resultType="com.heai.modules.production.entity.ShopOrderData">
  123. select a.TransNo as transFerNo ,b.PartNo,c.PartDescription,a.Status,b.TransQty as lotSize,b.ConfirmQty as FinishedQty,a.Site, b.OrderNo,dbo.Get_PartWeightFactorForReport(A.Site ,b.PartNo,b.OrderNo) as weightFactor,
  124. dbo.Get_Part_DefaultWarehouseID(a.Site,b.PartNo) DefaultWarehouseID,b.seqNo,a.needReceiveFlag,Round(isnull(b.boxWeight,0),2) boxWeight
  125. from SOOpsTransferHeader a left join SOOpsTransferDetail b on a.TransNo=b.TransNo and a.Site=b.Site
  126. LEFT JOIN Part c on b.partNo=c.partNo and c.site=a.site
  127. <where>
  128. <if test="transFerNo != null and transFerNo != ''">
  129. and a.TransNo = #{transFerNo}
  130. </if>
  131. </where>
  132. </select>
  133. <select id="checkShopOrderStatus" resultType="com.heai.modules.production.entity.ShopOrderData">
  134. select orderNo,status from shopOrder where Site=#{site} and OrderNo=#{orderNo}
  135. </select>
  136. <select id="getOperatorData" resultType="com.heai.modules.production.entity.OperatorData" >
  137. select Site,OperatorID,OperatorName,Active,Department,CreatedDate,Passwords,LineLeader,tv_id
  138. from Operator
  139. <where>
  140. <if test="site != null and site != ''">
  141. and Site = #{site}
  142. </if>
  143. <if test="operatorID != null and operatorID != ''">
  144. and OperatorID like #{operatorID,jdbcType=VARCHAR}
  145. </if>
  146. <if test="operatorName != null and operatorName != ''">
  147. and OperatorName like #{operatorName}
  148. </if>
  149. <if test="active != null and active != ''">
  150. and Active = #{active}
  151. </if>
  152. <if test="department != null and department != '' and department != 'all'">
  153. and department = #{department}
  154. </if>
  155. </where>
  156. order by CreatedDate
  157. </select>
  158. <select id="getWorkCenterData" resultType="WorkCenterData">
  159. select a.Site,a.WorkCenterNo,a.WorkCenterDesc,a.Active FROM WorkCenter a left join
  160. operator_work_center b on a.Site=b.Site and a.WorkCenterNo=b.WorkCenterNo and b.OperatorID=#{operatorID}
  161. where a.site=#{site} and b.WorkCenterNo is null
  162. order by a.WorkCenterNo
  163. </select>
  164. <select id="getWorkCenterOperatorData" resultType="WorkCenterData">
  165. select a.Site,a.WorkCenterNo,b.WorkCenterDesc,b.Active FROM operator_work_center a left join
  166. WorkCenter b on a.Site=b.Site and a.WorkCenterNo=b.WorkCenterNo
  167. where a.site=#{site} and a.OperatorID=#{operatorID}
  168. order by a.WorkCenterNo
  169. </select>
  170. <insert id="addSkill">
  171. insert into operator_work_center(OperatorID,WorkCenterNo,created_by,created_date,Site)
  172. values(#{operatorID},#{workCenterNo},#{user},GetDate(),#{site})
  173. </insert>
  174. <delete id="deleteSkill">
  175. delete from operator_work_center where OperatorID=#{operatorID} and Site=#{site} and WorkCenterNo=#{workCenterNo}
  176. </delete>
  177. <insert id="addUserSkill">
  178. insert into user_work_center(UserId,WorkCenterNo,created_by,created_date,Site)
  179. values(#{userId},#{workCenterNo},#{user},GetDate(),#{site})
  180. </insert>
  181. <insert id="addUserSkillAll">
  182. insert into user_work_center(UserId,WorkCenterNo,created_by,created_date,Site)
  183. SELECT #{userId} ,a.WorkCenterNo ,#{user},GETDATE(), a.site FROM WorkCenter a
  184. left join user_work_center b on a.site=b.site and a.WorkCenterNo=b.WorkCenterNo and b.UserId= #{userId}
  185. where b.Site is null
  186. </insert>
  187. <delete id="deleteUserSkill">
  188. delete from user_work_center where UserId=#{userId} and Site=#{site} and WorkCenterNo=#{workCenterNo}
  189. </delete>
  190. <delete id="deleteUserSkillAll">
  191. delete from user_work_center where UserId=#{userId}
  192. </delete>
  193. <select id="checkWorkCenterOperatorData" resultType="WorkCenterData">
  194. select site FROM operator_work_center where OperatorID=#{operatorID} and Site=#{site} and WorkCenterNo=#{workCenterNo}
  195. </select>
  196. <select id="checkUserOperatorData" resultType="WorkCenterData">
  197. select site FROM user_work_center where userId=#{userId} and Site=#{site} and WorkCenterNo=#{workCenterNo}
  198. </select>
  199. <select id="getAllWorkCenterDataForUser" resultType="WorkCenterData">
  200. select a.Site,a.WorkCenterNo,a.WorkCenterDesc,a.Active FROM WorkCenter a left join
  201. user_work_center b on a.Site=b.Site and a.WorkCenterNo=b.WorkCenterNo and b.userId=#{user}
  202. where b.WorkCenterNo is null and a.Active='Y'
  203. order by a.WorkCenterNo ,a.site
  204. </select>
  205. <select id="getWorkCenterUserData" resultType="WorkCenterData">
  206. select a.Site,a.WorkCenterNo,b.WorkCenterDesc,b.Active FROM user_work_center a left join
  207. WorkCenter b on a.Site=b.Site and a.WorkCenterNo=b.WorkCenterNo
  208. where a.userId=#{user} and b.Active='Y'
  209. order by a.WorkCenterNo,a.site
  210. </select>
  211. <select id="getShopOrderRoutingData" resultType="ShopOrderRoutingData">
  212. select a.site, a.OrderNo,a.PartNo,a.Status,a.PlanStartDate,a.NeedDate,a.LotSize,a.EnterDate,a.UserName,a.MaterialSplitFlag,a.RepairSOFlag,
  213. P.Spec+'/'+isnull(P.PartDescription,'') PartDescription,P.Spec,isnull(SL.scheduledQty,0) as scheduledQty,s.workCenterNo,S.qtyReported,S.qtyApprove,S.machSetupTime,
  214. S.machRunFactor,S.factorUnit,S.ItemNo,S.OperationDesc,s.Efficiency,isnull(SOP.TotalFinishedQty,0) lastApproveQty,dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderNo) weightFactor,
  215. Round(dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderNo)*a.LotSize,2) weight,dbo.Get_PartPlanQty(a.site,a.PartNo,a.OrderNo) partPlanQty,cod.PlanShipDate,
  216. dbo.Get_LastStartTime( a.site, a.OrderNo,S.ItemNo) LastStartDate,Round(S.DefectiveQty,3) DefectiveQty
  217. FROM ShopOrder a
  218. LEFT JOIN Part P ON P.PartNo=a.PartNo AND a.site=P.Site
  219. LEFT JOIN SORouting S on S.site=a.site and S.OrderNo=a.orderNo
  220. LEFT JOIN ScheduleList SL on S.site=SL.site and S.OrderNo=SL.orderNo and S.ItemNo=SL.ItemNo
  221. 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)
  222. left join user_work_center uwc on a.site=uwc.site and s.workCenterNo =uwc.WorkCenterNo and uwc.userId=#{userId}
  223. left join CODetail cod on a.site=cod.site and a.orderRef1=cod.OrderNo and a.orderRef2= CONVERT(VARCHAR(10),cod.ItemNo)
  224. <where>
  225. and uwc.WorkCenterNo is not null
  226. and a.PartNo NOT like 'SP%' and a.PartNo NOT like 'RC%' and a.PartNo NOT like 'SC%' AND a.OrderNo not LIKE 'HL%'
  227. <if test="site != null and site != ''">
  228. AND a.site = #{site}
  229. </if>
  230. <if test="orderNo != null and orderNo != ''">
  231. AND a.OrderNo LIKE #{orderNo}
  232. </if>
  233. and a.status in ('已下达','已发料','已入库','已开工','已排产')
  234. <if test="startDate1 != null ">
  235. AND a.EnterDate >= #{startDate1}
  236. </if>
  237. <if test="endDate1 != null ">
  238. AND #{endDate1} >= DATEADD(dd, -1, a.EnterDate)
  239. </if>
  240. <if test="startDate2 != null ">
  241. AND a.PlanStartDate >= #{startDate2}
  242. </if>
  243. <if test="endDate2 != null ">
  244. AND #{endDate2} >= a.PlanStartDate
  245. </if>
  246. <if test="startDate3 != null ">
  247. AND a.NeedDate >= #{startDate3}
  248. </if>
  249. <if test="endDate3 != null ">
  250. AND #{endDate3} >= a.NeedDate
  251. </if>
  252. <if test="startDate4 != null ">
  253. AND cod.PlanShipDate >= #{startDate4}
  254. </if>
  255. <if test="endDate4 != null ">
  256. AND #{endDate4} >= cod.PlanShipDate
  257. </if>
  258. <if test="partNo != null and partNo != ''">
  259. AND a.PartNo LIKE #{partNo}
  260. </if>
  261. <if test="planStatus != null and planStatus != ''">
  262. and ${planStatus}
  263. </if>
  264. <if test="itemNo != null and itemNo != ''">
  265. and S.ItemNo = #{itemNo}
  266. </if>
  267. <if test="partDescription != null and partDescription != ''">
  268. and P.Spec+'/'+isnull(P.PartDescription,'') like #{partDescription}
  269. </if>
  270. <if test="eLevels != null ">
  271. and a.E_Levels = #{eLevels}
  272. </if>
  273. </where>
  274. order by a.PlanStartDate desc,s.itemNo
  275. </select>
  276. <update id="updateSOTaskCombineTime">
  277. update SOTaskOrderHeader set CombineTime = GetDate() where site=#{site} and orderNo=#{orderNo}
  278. </update>
  279. <select id="getSOTastRoutingData" resultType="ShopOrderRoutingData">
  280. select a.site, a.OrderNo,a.PartNo,a.Status,a.OrderRef1,a.OrderDate,a.OrderQty as LotSize,dbo.Get_PartValue(a.site,a.PartNo,'equipment') as equipment,so.RepairSOFlag,
  281. P.Spec+'/'+isnull(P.PartDescription,'') PartDescription,P.Spec,isnull(SL.scheduledQty,0) as scheduledQty,s.workCenterNo,S.machSetupTime,
  282. S.machRunFactor,S.factorUnit,S.ItemNo,S.OperationDesc,s.Efficiency,a.qtyfinished,a.finishFlag,ROUND(dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderRef1)*a.OrderQty,2) as weight,
  283. dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderRef1) as weightFactor,dbo.Get_PartPlanQty(a.site,a.PartNo,a.OrderRef1) partPlanQty,so.needDate,cod.PlanShipDate
  284. ,a.comBineTime lastStartDate
  285. FROM SOTaskOrderHeader a
  286. LEFT JOIN Part P ON P.PartNo=a.PartNo AND a.site=P.Site
  287. LEFT JOIN SORouting S on S.site=a.site and S.OrderNo=a.OrderRef1
  288. LEFT JOIN ScheduleList SL on S.site=SL.site and a.OrderNo=SL.orderNo and S.ItemNo=SL.ItemNo
  289. left join user_work_center uwc on a.site=uwc.site and s.workCenterNo =uwc.WorkCenterNo and uwc.userId=#{userId}
  290. LEFT JOIN ShopOrder so on a.OrderRef1=so.OrderNo and a.site=so.site
  291. left join CODetail cod on so.site=cod.site and so.orderRef1=cod.OrderNo and so.orderRef2= CONVERT(VARCHAR(10),cod.ItemNo)
  292. <where>
  293. and uwc.WorkCenterNo is not null
  294. and so.status not in ('已关闭','已计划','已取消')
  295. <if test="site != null and site != ''">
  296. AND a.site = #{site}
  297. </if>
  298. <if test="orderNo != null and orderNo != ''">
  299. AND a.OrderNo LIKE #{orderNo}
  300. </if>
  301. <if test="status !=null and status != ''">
  302. AND a.Status IN ${status}
  303. </if>
  304. <if test="startDate1 != null ">
  305. AND a.orderDate >= #{startDate1}
  306. </if>
  307. <if test="endDate1 != null ">
  308. AND #{endDate1} >= a.orderDate
  309. </if>
  310. <if test="partDescription != null and partDescription != ''">
  311. and P.Spec+'/'+isnull(P.PartDescription,'') like #{partDescription}
  312. </if>
  313. <if test="orderRef1 != null and orderRef1 != ''">
  314. AND a.OrderRef1 LIKE #{orderRef1}
  315. </if>
  316. <if test="partNo != null and partNo != ''">
  317. AND a.PartNo LIKE #{partNo}
  318. </if>
  319. <if test="planStatus != null and planStatus != ''">
  320. and ${planStatus}
  321. </if>
  322. <if test="itemNo != null and itemNo != ''">
  323. and S.ItemNo = #{itemNo}
  324. </if>
  325. <if test="finishFlag != null and finishFlag != ''">
  326. AND a.FinishFlag=#{finishFlag}
  327. </if>
  328. <if test="startDate3 != null ">
  329. AND so.NeedDate >= #{startDate3}
  330. </if>
  331. <if test="endDate3 != null ">
  332. AND #{endDate3} >= so.NeedDate
  333. </if>
  334. <if test="startDate4 != null ">
  335. AND cod.PlanShipDate >= #{startDate4}
  336. </if>
  337. <if test="endDate4 != null ">
  338. AND #{endDate4} >= cod.PlanShipDate
  339. </if>
  340. </where>
  341. order by a.OrderDate desc,s.itemNo
  342. </select>
  343. <select id="getWorkCenterOperatorList" resultType="OperatorData">
  344. Select a.OperatorID,a.OperatorName from Operator a left join operator_work_center b on a.site=b.site and a.OperatorID=b.OperatorID
  345. where a.site=#{site} and b.WorkCenterNo=#{workCenterNo} and a.Active='Y'
  346. </select>
  347. <select id="checkScheduleQty" resultType="ScheduleCheckData">
  348. 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}
  349. </select>
  350. <select id="checkScheduleQtyForSoTask" resultType="ScheduleCheckData">
  351. Select a.OrderQty as Qty,isnull(b.scheduledQty,0) scheduledQty from SOTaskOrderHeader 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}
  352. </select>
  353. <select id="checkScheduleList" resultType="ScheduleCheckData">
  354. Select Qty from ScheduleList where Site=#{site} and OrderNo=#{orderNo} and itemNo=#{itemNo}
  355. </select>
  356. <insert id="saveScheduleList">
  357. insert into ScheduleList(Site,OrderNo,ItemNo,Type,Type_db,Qty,scheduledQty) values (#{site},#{orderNo},#{itemNo},'生产订单派工单','S',#{qty},0)
  358. </insert>
  359. <insert id="saveScheduleListForSOTask">
  360. insert into ScheduleList(Site,OrderNo,ItemNo,Type,Type_db,Qty,scheduledQty) values (#{site},#{orderNo},#{itemNo},'日计划派工单','D',#{qty},0)
  361. </insert>
  362. <select id="getDataSequence" resultType="integer">
  363. select seqNo from DataSequence where SeqType= 'A'
  364. </select>
  365. <update id="updateDataSequence">
  366. update DataSequence set seqNo=seqNo+1 where SeqType= 'A'
  367. </update>
  368. <insert id="saveSchedule">
  369. Insert into soscheduledrouting(Site,OrderNo,ItemNo,SeqNo,QtyRequired,QtyReported,QtyApprove,TimeRequired,TimeReported,PlanStartTime,PlanFinishTime
  370. ,BarcodeID,Remark,Crewsize,ClosedFlag,QtyScrapt,OutWorkFlag,S_ScheduledDate,S_ResourceID,S_ShiftNo,S_WorkCenterNo
  371. ,SelectedFlag,SourceFlag,ParkFlag,TimeRequired_Original,QtyRequired_Original
  372. ,StartProdFlag,CancelledProdFlag,Efficiency,EnteredDate,scheduleType,operatorId,partNo,OrderRef1,cancelReportFlag,CreateBy,WorkTime,stopTime,jobType,RepairSOFlag)
  373. values(#{site},#{orderNo},#{itemNo},#{seqNo},#{scheduleQty},0,0,dbo.Get_SOScheduleRouting_TimeRequired(#{site},#{orderNo},#{itemNo},#{scheduleQty}),0,#{scheduleDate},#{scheduleDate}
  374. ,'*',#{remark},1,'N',0,'Y',#{scheduleDate},#{resourceId},#{shiftNo},#{workCenterNo}
  375. ,'N','N','N',dbo.Get_SOScheduleRouting_TimeRequired(#{site},#{orderNo},#{itemNo},#{scheduleQty}),#{scheduleQty}
  376. ,'N','N',#{efficiency},GETDATE(),'生产订单派工单',#{operatorId},#{partNo},#{orderNo},'N',#{createBy},0,0,#{jobType},#{repairSOFlag})
  377. </insert>
  378. <insert id="saveScheduleForSOTask">
  379. Insert into soscheduledrouting(Site,OrderNo,ItemNo,SeqNo,QtyRequired,QtyReported,QtyApprove,TimeRequired,TimeReported,PlanStartTime,PlanFinishTime
  380. ,BarcodeID,Remark,Crewsize,ClosedFlag,QtyScrapt,OutWorkFlag,S_ScheduledDate,S_ResourceID,S_ShiftNo,S_WorkCenterNo
  381. ,SelectedFlag,SourceFlag,ParkFlag,TimeRequired_Original,QtyRequired_Original
  382. ,StartProdFlag,CancelledProdFlag,Efficiency,EnteredDate,scheduleType,operatorId,partNo,OrderRef1,cancelReportFlag,CreateBy,WorkTime,stopTime,jobType,RepairSOFlag)
  383. values(#{site},#{orderRef1},#{itemNo},#{seqNo},#{scheduleQty},0,0,dbo.Get_SOScheduleRouting_TimeRequired(#{site},#{orderRef1},#{itemNo},#{scheduleQty}),0,#{scheduleDate},#{scheduleDate}
  384. ,'*',#{remark},1,'N',0,'Y',#{scheduleDate},#{resourceId},#{shiftNo},#{workCenterNo}
  385. ,'N','N','N',dbo.Get_SOScheduleRouting_TimeRequired(#{site},#{orderRef1},#{itemNo},#{scheduleQty}),#{scheduleQty}
  386. ,'N','N',#{efficiency},GETDATE(),'日计划派工单',#{operatorId},#{partNo},#{orderNo},'N',#{createBy},0,0,#{jobType},#{repairSOFlag})
  387. </insert>
  388. <update id="updateScheduleListQty">
  389. update ScheduleList set scheduledQty=scheduledQty+#{sumQty} where Site=#{site} and OrderNo=#{orderNo} and itemNo=#{itemNo} and type=#{scheduleType}
  390. </update>
  391. <select id="searchReportedQty" resultType="SORoutingData">
  392. select top 1 isnull(a.QtyReported,0) QtyReported,isnull(SOP.TotalFinishedQty,0) lastApproveQty ,dbo.Get_PartWeightFactorForReport(#{site},#{partNo},#{orderNo}) as weightFactor,dbo.Get_sfdcReportedSetupTime(#{site},#{seqNo}) as timeReported,
  393. [dbo].[Get_Part_Cavity](#{site},#{partNo},#{orderNo}) as cavity
  394. from SORouting a
  395. 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)
  396. where a.Site=#{site} and a.OrderNo=#{orderNo} and a.itemNo=#{itemNo}
  397. </select>
  398. <select id="getSPBomQtyAssembly" resultType="com.heai.modules.app.entity.SoBomData">
  399. select QtyAssembly from SOBOM where site=#{site} and OrderNo=#{orderNo} and ComponentPartNo like 'SP%'
  400. </select>
  401. <select id="searchLastApproveQty" resultType="SORoutingData">
  402. select top 1 isnull(TotalFinishedQty,0) lastApproveQty from SORoutingOutput where Site=#{site} and OrderNo=#{orderNo} and itemNo=dbo.Get_SORouting_PreviousOperationItemNo(#{site},#{orderNo},#{itemNo})
  403. </select>
  404. <select id="getSOScheduleRoutingDataForShiyanshi" resultType="SOScheduledRoutingOutData">
  405. select a.Site,OrderNo,ItemNo,SeqNo,QtyRequired,QtyReported,QtyApprove,TimeRequired,TimeReported,
  406. BarcodeID,Remark,Crewsize,ClosedFlag,S_ScheduledDate,S_ResourceID,S_ScheduledSeqNo,S_ShiftNo,
  407. S_WorkCenterNo, EnteredDate,scheduleType,operatorId,partNo,dbo.Get_Part_SpecDesc(a.Site,partNo) as partDesc,
  408. dbo.Get_OperatorDesc(a.Site,operatorId) as operatorName,dbo.Get_ItemDesc(a.Site,OrderNo,ItemNo) as itemDesc,orderRef1 ,
  409. dbo.Get_WorkCenterDesc(a.Site,S_WorkCenterNo) as workCenterDesc , dbo.Get_Part_SpecDesc(a.Site,partNo) as partSpec,circulation_seqNo,circulation_qty
  410. ,dbo.Get_PartWeightFactorForReport(a.site,PartNo,OrderNo) as weightFactor,dbo.Get_Part_UMID(a.Site,PartNo) umid,
  411. Round(dbo.Get_PartWeightFactorForReport(a.site,PartNo,OrderNo)*QtyRequired,2) as weight from SOScheduledRouting a
  412. <where>
  413. <if test="seqNo != null and seqNo != ''">
  414. AND a.seqNo = #{seqNo}
  415. </if>
  416. <if test="site != null and site != ''">
  417. AND a.site = #{site}
  418. </if>
  419. </where>
  420. order by S_ScheduledDate
  421. </select>
  422. <select id="getSOScheduleRoutingData" resultType="SOScheduledRoutingOutData">
  423. select a.Site,a.OrderNo,a.ItemNo,a.SeqNo,a.QtyRequired,a.QtyReported,a.QtyApprove,a.TimeRequired,a.TimeReported,a.previousSeqNo,a.previousBatchNo,a.materSeqNo,
  424. a.BarcodeID,a.Remark,a.Crewsize,a.ClosedFlag,a.S_ScheduledDate,a.S_ResourceID,a.S_ScheduledSeqNo,a.S_ShiftNo,a.repairSOFlag,
  425. a.S_WorkCenterNo, a.EnteredDate,a.scheduleType,a.operatorId,a.partNo,dbo.Get_Part_SpecDesc(a.Site,a.partNo) as partDesc,
  426. dbo.Get_OperatorDesc(a.Site,a.operatorId) as operatorName,dbo.Get_ItemDesc(a.Site,a.OrderNo,a.ItemNo) as itemDesc,a.orderRef1 ,
  427. dbo.Get_WorkCenterDesc(a.Site,a.S_WorkCenterNo) as workCenterDesc , dbo.Get_Part_SpecDesc(a.Site,a.partNo) as partSpec,a.circulation_seqNo,a.circulation_qty
  428. ,dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderNo) as weightFactor,dbo.Get_Part_UMID(a.Site,a.PartNo) umid,a.jobType,
  429. case when a.worktime is not null and a.worktime>0 then Round(a.QtyReported/a.worktime,2) else Round(a.QtyReported/0.1,2) end as efficiency,Round(isnull(a.workTime,0),2) workTime,
  430. Round(dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderNo)*a.QtyRequired,2) as weight ,c.MachRunFactor
  431. ,case when 0>=c.MachRunFactor then 0 else Round(a.QtyReported*100/case when isnull(a.worktime,0.1)=0 then 0.1 else isnull(a.worktime,0.1) end/c.MachRunFactor,2) end as xiaolv
  432. from SOScheduledRouting a
  433. left join user_work_center uwc on a.site=uwc.site and a.S_WorkCenterNo =uwc.WorkCenterNo and uwc.userId=#{userId}
  434. left join SORouting c on a.Site=c.Site and a.orderNo=c.orderNo and a.itemNo=c.itemNo
  435. <where>
  436. and uwc.WorkCenterNo is not null
  437. <if test="site != null and site != ''">
  438. AND a.site = #{site}
  439. </if>
  440. <if test="orderNo != null and orderNo != ''">
  441. AND a.OrderNo LIKE #{orderNo}
  442. </if>
  443. <if test="partDesc != null and partDesc != ''">
  444. AND dbo.Get_Part_SpecDesc(a.Site,a.partNo) LIKE #{partDesc}
  445. </if>
  446. <if test="seqNo != null ">
  447. AND a.seqNo = #{seqNo}
  448. </if>
  449. <if test="partNo != null and partNo != ''">
  450. AND a.PartNo LIKE #{partNo}
  451. </if>
  452. <if test="sWorkCenterNo != null and sWorkCenterNo != ''">
  453. AND a.S_WorkCenterNo LIKE #{sWorkCenterNo}
  454. </if>
  455. <if test="itemNo != null and itemNo != ''">
  456. and a.ItemNo = #{itemNo}
  457. </if>
  458. <if test="itemDesc != null and itemDesc != ''">
  459. and dbo.Get_ItemDesc(a.Site,a.OrderNo,a.ItemNo) = #{itemDesc}
  460. </if>
  461. <if test="closedFlag != null and closedFlag != ''">
  462. and a.ClosedFlag = #{closedFlag}
  463. </if>
  464. <if test="startDate != null ">
  465. and a.S_ScheduledDate >= #{startDate}
  466. </if>
  467. <if test="endDate != null ">
  468. and #{endDate} >= a.S_ScheduledDate
  469. </if>
  470. <if test="scheduleType != null and scheduleType != ''">
  471. and a.scheduleType = #{scheduleType}
  472. </if>
  473. <if test="reportFlag != null and reportFlag != ''">
  474. and ${reportFlag}
  475. </if>
  476. <if test="operatorName != null and operatorName != ''">
  477. and dbo.Get_OperatorDesc(a.Site,a.operatorId) like #{operatorName}
  478. </if>
  479. <if test="sResourceID != null and sResourceID != ''">
  480. and a.S_ResourceID like #{sResourceID}
  481. </if>
  482. <if test="sShiftNo != null and sShiftNo != ''">
  483. and a.S_ShiftNo = #{sShiftNo}
  484. </if>
  485. <if test="previousSeqNo != null ">
  486. and a.previousSeqNo = #{previousSeqNo}
  487. </if>
  488. <if test="materSeqNo != null ">
  489. and a.materSeqNo = #{materSeqNo}
  490. </if>
  491. <if test="repairSOFlag != null and repairSOFlag != ''">
  492. and a.repairSOFlag = #{repairSOFlag}
  493. </if>
  494. </where>
  495. order by a.S_ScheduledDate
  496. </select>
  497. <select id="getSOScheduleRoutingDataPrint" resultType="SOScheduledRoutingOutData">
  498. select a.Site,a.OrderNo,a.ItemNo,a.SeqNo,a.QtyRequired,a.QtyReported,a.QtyApprove,a.TimeRequired,a.TimeReported,a.previousSeqNo,a.previousBatchNo,a.materSeqNo,
  499. a.BarcodeID,a.Remark,a.Crewsize,a.ClosedFlag,a.S_ScheduledDate,a.S_ResourceID,a.S_ScheduledSeqNo,a.S_ShiftNo,a.repairSOFlag,
  500. a.S_WorkCenterNo, a.EnteredDate,a.scheduleType,a.operatorId,a.partNo,dbo.Get_Part_SpecDesc(a.Site,a.partNo) as partDesc,
  501. dbo.Get_OperatorDesc(a.Site,a.operatorId) as operatorName,dbo.Get_ItemDesc(a.Site,a.OrderNo,a.ItemNo) as itemDesc,a.orderRef1 ,
  502. dbo.Get_WorkCenterDesc(a.Site,a.S_WorkCenterNo) as workCenterDesc , dbo.Get_Part_SpecDesc(a.Site,a.partNo) as partSpec,a.circulation_seqNo,a.circulation_qty
  503. ,dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderNo) as weightFactor,dbo.Get_Part_UMID(a.Site,a.PartNo) umid,a.jobType,
  504. case when a.worktime is not null and a.worktime>0 then Round(a.QtyReported/a.worktime,2) else Round(a.QtyReported/0.1,2) end as efficiency,Round(isnull(a.workTime,0),2) workTime,
  505. Round(dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderNo)*a.QtyRequired,2) as weight ,c.MachRunFactor
  506. ,case when 0>=c.MachRunFactor then 0 else Round(a.QtyReported*100/case when isnull(a.worktime,0.1)=0 then 0.1 else isnull(a.worktime,0.1) end/c.MachRunFactor,2) end as xiaolv
  507. from SOScheduledRouting a
  508. left join user_work_center uwc on a.site=uwc.site and a.S_WorkCenterNo =uwc.WorkCenterNo and uwc.userId=#{userId}
  509. left join SORouting c on a.Site=c.Site and a.orderNo=c.orderNo and a.itemNo=c.itemNo
  510. <where>
  511. <if test="site != null and site != ''">
  512. AND a.site = #{site}
  513. </if>
  514. <if test="orderNo != null and orderNo != ''">
  515. AND a.OrderNo LIKE #{orderNo}
  516. </if>
  517. <if test="partDesc != null and partDesc != ''">
  518. AND dbo.Get_Part_SpecDesc(a.Site,a.partNo) LIKE #{partDesc}
  519. </if>
  520. <if test="seqNo != null ">
  521. AND a.seqNo = #{seqNo}
  522. </if>
  523. <if test="partNo != null and partNo != ''">
  524. AND a.PartNo LIKE #{partNo}
  525. </if>
  526. <if test="sWorkCenterNo != null and sWorkCenterNo != ''">
  527. AND a.S_WorkCenterNo LIKE #{sWorkCenterNo}
  528. </if>
  529. <if test="itemNo != null and itemNo != ''">
  530. and a.ItemNo = #{itemNo}
  531. </if>
  532. <if test="itemDesc != null and itemDesc != ''">
  533. and dbo.Get_ItemDesc(a.Site,a.OrderNo,a.ItemNo) = #{itemDesc}
  534. </if>
  535. <if test="closedFlag != null and closedFlag != ''">
  536. and a.ClosedFlag = #{closedFlag}
  537. </if>
  538. <if test="startDate != null ">
  539. and a.S_ScheduledDate >= #{startDate}
  540. </if>
  541. <if test="endDate != null ">
  542. and #{endDate} >= a.S_ScheduledDate
  543. </if>
  544. <if test="scheduleType != null and scheduleType != ''">
  545. and a.scheduleType = #{scheduleType}
  546. </if>
  547. <if test="reportFlag != null and reportFlag != ''">
  548. and ${reportFlag}
  549. </if>
  550. <if test="operatorName != null and operatorName != ''">
  551. and dbo.Get_OperatorDesc(a.Site,a.operatorId) like #{operatorName}
  552. </if>
  553. <if test="sResourceID != null and sResourceID != ''">
  554. and a.S_ResourceID like #{sResourceID}
  555. </if>
  556. <if test="sShiftNo != null and sShiftNo != ''">
  557. and a.S_ShiftNo = #{sShiftNo}
  558. </if>
  559. <if test="previousSeqNo != null ">
  560. and a.previousSeqNo = #{previousSeqNo}
  561. </if>
  562. <if test="materSeqNo != null ">
  563. and a.materSeqNo = #{materSeqNo}
  564. </if>
  565. <if test="repairSOFlag != null and repairSOFlag != ''">
  566. and a.repairSOFlag = #{repairSOFlag}
  567. </if>
  568. </where>
  569. order by a.S_ScheduledDate
  570. </select>
  571. <select id="checkUserSeqNo" resultType="SOScheduledRoutingOutData">
  572. select seqNo ,CancelReportFlag,a.mat_issueflag,a.site,a.OrderNo,a.ItemNo,a.QtyRequired,a.S_WorkCenterNo,a.operatorId,a.partNo,dbo.Get_Part_Spec(a.site,a.partNo) PartSpec
  573. ,PreviousSeqNo,PreviousBatchNo,materSeqNo from SOScheduledRouting a
  574. left join user_work_center uwc on a.site=uwc.site and a.S_WorkCenterNo =uwc.WorkCenterNo and uwc.userId=#{userId}
  575. where seqNo=#{seqNo} and uwc.WorkCenterNo is not null
  576. </select>
  577. <select id="checkLastItemReport" resultType="SORoutingData">
  578. SELECT max(ItemNo) itemNo,QtyReported FROM [dbo].[SORouting]
  579. <where>
  580. <if test="site != null and site != ''">
  581. AND site = #{site}
  582. </if>
  583. and orderNo=#{orderNo} and #{itemNo}>ItemNo
  584. </where>
  585. Group by QtyReported
  586. </select>
  587. <select id="getStockPrint" resultType="com.heai.modules.production.entity.StockPrintData">
  588. select a.TransNo,a.Site,a.WareHouseId,a.BatchNo,a.LocationId,a.PartNo,a.OrderNo,a.TransDate,a.Qty,a.PrintFlag,dbo.Get_PartDesc(a.Site,a.PartNo) as partDesc,Round(dbo.Get_Part_NetWeight(a.Site,a.PartNo)*a.Qty/1000,2) weight
  589. ,dbo.Get_WareHouseDesc(a.Site,a.WareHouseId) as wareHouseDesc,dbo.Get_Part_UMID(a.Site,a.PartNo) umid,dbo.get_expiredDate_print(a.Site,a.PartNo,a.BatchNo) expiredDate
  590. ,dbo.Get_StorePrintPartStatus(a.Site,a.PartNo,a.BatchNo) status,isnull(Round(b.QtyOnHand,3),0) QtyOnHand
  591. from StockPrint a
  592. left join InventoryStock b on a.Site=b.site and a.WareHouseId=b.WarehouseID and a.PartNo=b.PartNo and a.BatchNo=b.BatchNo and
  593. a.LocationId=b.LocationId
  594. <where>
  595. <if test="startDate != null ">
  596. and a.TransDate >= #{startDate}
  597. </if>
  598. <if test="endDate != null ">
  599. and #{endDate} >= a.TransDate -1
  600. </if>
  601. <if test="site != null and site != ''">
  602. AND a.site = #{site}
  603. </if>
  604. <if test="orderNo != null and orderNo != ''">
  605. AND a.orderNo LIKE #{orderNo}
  606. </if>
  607. <if test="seqNo != null and seqNo != ''">
  608. AND a.seqNo = #{seqNo}
  609. </if>
  610. <if test="printFlag != null and printFlag != ''">
  611. AND a.printFlag = #{printFlag}
  612. </if>
  613. <if test="batchNo != null and batchNo != ''">
  614. AND a.BatchNo LIKE #{batchNo}
  615. </if>
  616. <if test="partNo != null and partNo != ''">
  617. AND a.PartNo LIKE #{partNo}
  618. </if>
  619. </where>
  620. order by a.TransDate desc
  621. </select>
  622. <update id="updatePrintStock">
  623. update StockPrint set PrintFlag='Y' where Site=#{site} and TransNo=#{transNo}
  624. </update>
  625. <update id="updatePrintInfo">
  626. update print_info set status='Y' where Site=#{site} and orderref1=#{transNo}
  627. </update>
  628. <select id="checkFirstItem" resultType="SOScheduledRoutingOutData">
  629. select site,OrderNo,ItemNo from SORouting where orderNo=#{orderNo} and site=#{site} and #{itemNo} >itemNo order by itemNo desc
  630. </select>
  631. <select id="searchSeqNo" resultType="SOScheduledRoutingOutData">
  632. select top 1 Site,OrderNo,ItemNo,SeqNo,QtyRequired,QtyReported,QtyApprove,TimeRequired,TimeReported,
  633. BarcodeID,Remark,Crewsize,ClosedFlag,S_ScheduledDate,S_ResourceID,S_ScheduledSeqNo,S_ShiftNo,
  634. S_WorkCenterNo, EnteredDate,scheduleType,operatorId,partNo,dbo.Get_PartDesc(Site,partNo) as partDesc,
  635. dbo.Get_OperatorDesc(Site,operatorId) as operatorName,dbo.Get_ItemDesc(site,orderNo,ItemNo) as itemDesc,orderRef1 ,
  636. dbo.Get_WorkCenterDesc(Site,S_WorkCenterNo) as workCenterDesc , dbo.Get_Part_SpecDesc(Site,partNo) as partSpec,closedFlag,outWorkFlag,ParkFlag,CancelReportFlag
  637. from SOScheduledRouting
  638. where SeqNo=#{seqNo}
  639. </select>
  640. <select id="checkELevels" resultType="Integer">
  641. select isnull(E_Levels,-1) E_Levels from shoporder where site=#{site} and orderNo=#{orderNo}
  642. </select>
  643. <select id="checkShopOrderForTransfer" resultType="com.heai.modules.production.entity.ShopOrderData">
  644. select orderNo,PartNo from shoporder where site=#{site} and orderNo=#{orderNo}
  645. </select>
  646. <select id="checkReceiveFlag" resultType="com.heai.modules.production.entity.SOOpsTransferData">
  647. select a.TransNo from SOOpsTransferHeader a left join SOOpsTransferDetail b on a.site=b.site and a.TransNo=b.TransNo
  648. where a.site=#{site} and b.seqNo=#{seqNo} and a.Status='已录入' and a.NeedReceiveFlag='Y' and a.ToTypeFlag_DB='W'
  649. </select>
  650. <select id="checkNotInspectTransFer" resultType="com.heai.modules.production.entity.SOOpsTransferData">
  651. select a.TransNo from SOOpsTransferHeader a left join SOOpsTransferDetail b on a.site=b.site and a.TransNo=b.TransNo
  652. where a.site=#{site} and b.seqNo=#{seqNo} and a.Status='已录入' and a.NeedReceiveFlag='Y' and a.ToTypeFlag_DB='I'
  653. </select>
  654. <select id="getSOScheduledRoutingOutData" resultType="SOScheduledRoutingOutData">
  655. select Site,OrderNo,seqNo,itemNo,S_ShiftNo,scheduleType,operatorId,circulation_seqNo from SOScheduledRouting where seqNo=#{seqNo}
  656. </select>
  657. <select id="checkItemNoForIssue" resultType="SORoutingData">
  658. select Site,OrderNo,itemNo from SORouting where Site=#{site} and orderNo=#{orderNo} and #{itemNo}>itemNo
  659. </select>
  660. <select id="getsfdcTimeHistData" resultType="com.heai.modules.production.entity.SfdcTimeHistData">
  661. select top 1 site,OrderNo,ItemNo,SeqNo,#{username} as Enteredby ,ClosedFlag,OutWorkFlag from SOScheduledRouting where site=#{site} and SeqNo=#{seqNo} and ClosedFlag='N'
  662. </select>
  663. <select id="getsfdcTimeHistAbnormal" resultType="com.heai.modules.production.entity.SfdcTimeHistData">
  664. select top 1 site,SeqNo,AbnormalCode,AbnormalRemark from SFDC_TimeHist where site=#{site} and SeqNo=#{seqNo} and EventType='D' order by HistSeqNo desc
  665. </select>
  666. <select id="getSeqNoSite" resultType="String">
  667. select site from SOScheduledRouting where SeqNo=#{seqNo}
  668. </select>
  669. <select id="checkSfdcTimeHistData" resultType="com.heai.modules.production.entity.SfdcTimeHistData">
  670. select site,OrderNo,ItemNo,SeqNo from SFDC_TimeHist where site=#{site} and seqNo=#{seqNo} and EventDesc='开始生产' and CompletedFlag='N'
  671. </select>
  672. <select id="getHistSeqNo" resultType="Integer">
  673. select isnull(max(HistSeqNo),0)+1 from SFDC_TimeHist where site=#{site} and seqNo=#{seqNo}
  674. </select>
  675. <update id="updateSfdcTimeHistDataContinue" >
  676. Update SFDC_TimeHist set CompletedFlag='Y' ,TillTime=GETDATE(),TillEnteredTime=GETDATE(),TillEnteredBy=#{enteredby},TotalTime=Round(datediff(mi,EventTime,GETDATE())/60.0,2) where SeqNo=#{seqNo,jdbcType=INTEGER} and Site=#{site} and CompletedFlag='N' and EventDesc='暂停生产'
  677. </update>
  678. <update id="updateStopWork" >
  679. update SOScheduledRouting set OutWorkFlag=#{flag} where Site=#{site} and seqNo=#{seqNo}
  680. </update>
  681. <insert id="saveSfdcTimeHistDataStart">
  682. insert into SFDC_TimeHist (Site,OrderNo,ItemNo,SeqNo,HistSeqNo,EventTime,Enteredby,EventDesc,DowntimeCode,EventType,LinkHistSeqNo,TillTime,TillEnteredTime,
  683. TillEnteredBy,CompletedFlag,TotalTime,DowntimePhaseIn,RollNo,LastStartTime) values
  684. (#{site},#{orderNo},#{itemNo},#{seqNo},#{histSeqNo},GetDate(),#{enteredby},'开始生产','','P',null,null,null,null,'N',0,'','*',#{lastStartTime})
  685. </insert>
  686. <insert id="saveSfdcTimeHistDataStop">
  687. insert into SFDC_TimeHist (Site,OrderNo,ItemNo,SeqNo,HistSeqNo,EventTime,Enteredby,EventDesc,DowntimeCode,EventType,LinkHistSeqNo,TillTime,TillEnteredTime,
  688. TillEnteredBy,CompletedFlag,TotalTime,DowntimePhaseIn,RollNo,AbnormalCode,AbnormalRemark) values
  689. (#{site},#{orderNo},#{itemNo},#{seqNo},#{histSeqNo},GetDate(),#{enteredby},'暂停生产','','D',null,null,null,null,'N',0,'','*',#{abnormalCode},#{abnormalRemark})
  690. </insert>
  691. <select id="getOldSOScheduledRoutingOutData" resultType="SOScheduledRoutingOutData">
  692. select Site,OrderNo,ItemNo,SeqNo,QtyRequired,QtyReported,QtyApprove,TimeRequired,TimeReported,PlanStartTime,PlanFinishTime,
  693. BarcodeID,Remark,Crewsize,ClosedFlag,QtyScrapt,OutWorkFlag,S_ScheduledDate,S_ResourceID,S_ScheduledSeqNo,S_ShiftNo,
  694. S_WorkCenterNo,ParkFlag,TimeRequired_Original,QtyRequired_Original,QtyReturntoSchedule,StartProdFlag,CancelledProdFlag,
  695. Efficiency,EnteredDate,SelectedFlag,SourceFlag,Closedby,ClosedDate,VirtualResourceFlag,mat_issueflag,plate_issueflag,
  696. tool_issueflag,scheduleType,operatorId,partNo,orderRef1,circulation_seqNo,circulation_qty,PreviousSeqNo,PreviousBatchNo,materSeqNo,jobType from SOScheduledRouting where
  697. site=#{site} and seqNo=#{seqNo}
  698. </select>
  699. <update id="closeOldSchedule">
  700. update SOScheduledRouting set ClosedFlag='Y',circulation_seqNo=#{newSeqNo},circulation_qty=#{circulationQty} where site=#{site} and seqNo=#{oldSeqNo}
  701. </update>
  702. <insert id="saveCirculationSchedule" >
  703. INSERT into SOScheduledRouting (Site,OrderNo,ItemNo,SeqNo,QtyRequired,QtyReported,QtyApprove,TimeRequired,TimeReported,PlanStartTime,PlanFinishTime,
  704. BarcodeID,Remark,Crewsize,ClosedFlag,QtyScrapt,OutWorkFlag,S_ScheduledDate,S_ResourceID,S_ScheduledSeqNo,S_ShiftNo,
  705. S_WorkCenterNo,ParkFlag,TimeRequired_Original,QtyRequired_Original,QtyReturntoSchedule,StartProdFlag,CancelledProdFlag,
  706. Efficiency,EnteredDate,SelectedFlag,SourceFlag,Closedby,ClosedDate,VirtualResourceFlag,mat_issueflag,plate_issueflag,
  707. tool_issueflag,scheduleType,operatorId,partNo,orderRef1,jobType,PreviousSeqNo,PreviousBatchNo,materSeqNo) values
  708. (#{site},#{orderNo},#{itemNo},#{seqNo},#{qtyRequired},0,0,0,0,#{planStartTime},#{planFinishTime},
  709. #{barcodeID},#{remark},#{crewsize},'N',0,'Y',#{sScheduledDate},#{sResourceID},#{sScheduledSeqNo},#{sShiftNo},
  710. #{sWorkCenterNo},#{parkFlag},#{timeRequiredOriginal},#{qtyRequiredOriginal},null,'N','N',
  711. 0,GetDate(),'N','N',NULL,NULL,NULL,#{matIssueflag},'N','N',#{scheduleType},#{operatorId},#{partNo},#{orderRef1},#{jobType}
  712. ,#{previousSeqNo},#{previousBatchNo},#{materSeqNo})
  713. </insert>
  714. <update id="closeSchedule">
  715. update SOScheduledRouting set ClosedFlag='Y' where site=#{site} and seqNo=#{seqNo}
  716. </update>
  717. <select id="getTransData" resultType="com.heai.modules.production.entity.SOOpsTransferData">
  718. select top 1 a.TransNo,a.Site,b.FromWorkCenterNo WorkCenterNo ,b.OrderNo,b.TransQty,a.TransDate,b.PartNo,b.seqNo,dbo.Get_Part_SpecDesc(a.Site,b.PartNo) partDesc
  719. ,dbo.Get_Part_UMID(a.Site,b.PartNo) umid,'trans' as type ,b.OrderRef5
  720. FROM SOOpsTransferHeader a left join SOOpsTransferDetail b on a.site=b.site and a.TransNo=b.TransNo
  721. where a.TransNo=#{transNo} and a.Site=#{site} and ToTypeFlag_DB!='I'
  722. </select>
  723. <select id="getBadPrintData" resultType="com.heai.modules.production.entity.SOOpsTransferData">
  724. SELECT top 1 b.partNo ,dbo.Get_Part_SpecDesc(b.Site,b.partNo) as partDesc,b.SeqNo,b.S_WorkCenterNo workCenterNo ,b.OrderNo,a.DefectQty transQty,
  725. dbo.Get_Part_UMID(b.Site,b.partNo) as umid,a.ReportDate as transDate ,b.site ,Round(a.DefectQty*dbo.Get_PartWeightFactorForReport(b.Site,b.partNo,''),3) as orderRef5,a.Remark,
  726. c.createdBy userName,'bad' as type
  727. FROM SFDC_DefectHist a
  728. left join sfdc c on a.Site=c.Site and a.SeqNo=c.SeqNo and a.OrderNo=c.OrderNo and a.ItemNo=c.ItemNo
  729. left join SOScheduledRouting b on c.AssJobSeqNo=b.SeqNo and a.Site=b.Site
  730. where a.site=#{site} and b.seqNo=#{seqNo} and a.DefectCode='PQ003'
  731. order by a.seqNo desc
  732. </select>
  733. <select id="printDefectCard" resultType="com.heai.modules.production.entity.SOOpsTransferData">
  734. SELECT b.partNo ,dbo.Get_Part_SpecDesc(b.Site,b.partNo) as partDesc,b.SeqNo,b.S_WorkCenterNo workCenterNo ,b.OrderNo,a.DefectQty transQty,
  735. dbo.Get_Part_UMID(b.Site,b.partNo) as umid,a.ReportDate as transDate ,b.site ,convert(varchar(20),Round(a.DefectQty*dbo.Get_PartWeightFactorForReport(b.Site,b.partNo,''),3) )as orderRef5,a.Remark,
  736. c.createdBy userName,'bad' as type
  737. FROM SFDC_DefectHist a
  738. left join sfdc c on a.Site=c.Site and a.SeqNo=c.SeqNo and a.OrderNo=c.OrderNo and a.ItemNo=c.ItemNo
  739. left join SOScheduledRouting b on c.AssJobSeqNo=b.SeqNo and a.Site=b.Site
  740. where a.site=#{site} and a.orderNo=#{orderNo} and a.SeqNo=#{seqNo} and a.ItemNo=#{itemNo} and a.DefectCode='PQ003'
  741. </select>
  742. <select id="searchTaskTransNo" resultType="String">
  743. select top 1 TransNo from SOOpsTransferDetail where OrderNo=#{taskNo} and site=#{site}
  744. </select>
  745. <select id="transFerSearch" resultType="com.heai.modules.production.entity.SOOpsTransferData">
  746. SELECT a.transNo ,a.site,b.seqNo,a.TransDate,b.TransQty ,b.OrderNo ,b.PartNo,c.PartDescription as partDesc,
  747. case when a.status ='已入库' then '已入库' else '未入库' end as status
  748. FROM SOOpsTransferHeader a LEFT JOIN SOOpsTransferDetail b on a.TransNo=b.TransNo and a.site=b.Site
  749. LEFT JOIN Part c on b.PartNo=c.PartNo and b.site=c.site
  750. <where>
  751. and a.Status!='已取消' and a.ToTypeFlag_DB not in ('I','Q')
  752. <if test="startDate != null ">
  753. and TransDate >= #{startDate}
  754. </if>
  755. <if test="endDate != null ">
  756. and #{endDate} >= TransDate -1
  757. </if>
  758. <if test="site != null and site != ''">
  759. AND a.site = #{site}
  760. </if>
  761. <if test="orderNo != null and orderNo != ''">
  762. AND orderNo LIKE #{orderNo}
  763. </if>
  764. <if test="seqNo != null and seqNo != ''">
  765. AND seqNo = #{seqNo}
  766. </if>
  767. <if test="partNo != null and partNo != ''">
  768. AND b.PartNo LIKE #{partNo}
  769. </if>
  770. </where>
  771. ORDER BY a.TransDate
  772. </select>
  773. <select id="getPartCardPrintData" resultType="com.heai.modules.production.entity.PartCardPrintData">
  774. select top 1 a.orderNo,a.partNo,c.partDescription+'/'+C.Spec as partDesc,a.QtyRequired,a.S_ScheduledDate,
  775. dbo.Get_OperatorDesc(a.site,a.operatorId) OperatorName ,c.ToExpireDays,b.TechInfo,c.remark,Round(dbo.Get_PartWeightFactorForReport(a.site,a.PartNo,a.OrderNo)*a.QtyRequired,2) as weight
  776. from SOScheduledRouting a left join ShopOrder b on a.site=b.site and a.OrderNo=b.OrderNo
  777. left join part c on a.partNo=c.PartNo and a.site=c.site
  778. where a.site=#{site} and a.seqNo=#{seqNo}
  779. </select>
  780. <select id="checkTool" resultType="com.heai.modules.production.entity.SOToolData">
  781. select ToolID from SOTool where site=#{site} and OrderNo=#{orderNo} and itemNo=#{itemNo}
  782. </select>
  783. <select id="getHunlianTaskNo" resultType="String">
  784. select 'HL'+CONVERT(varchar(100), GETDATE(), 112)+ Right( '00000'+ convert(VARCHAR(10), isnull(max(convert(INT,SUBSTRING(TaskNo, 11,4))),0)+1) ,4) from Hunlian_TaskHeader where TaskNo like 'HL'+CONVERT(varchar(100), GETDATE(), 112)+'%'
  785. </select>
  786. <insert id="saveHunlianTaskDetailData" >
  787. insert into Hunlian_TaskDetail (Site,TaskNo,OrderNo,OrderRef1,OrderRef2,OrderQty,HunlianQty,OrderDate,PartNo,HunlianPartNo)
  788. select top 1 #{site},#{taskNo},#{orderNo},#{orderRef1},SO.OrderNo, SOT.OrderQty,#{hunlianQty},#{orderDate},SOT.partNo,#{hunlianPartNo}
  789. from SOTaskOrderHeader SOT
  790. left join ShopOrder t on t.site=#{site} and t.orderNo=#{orderRef1}
  791. left join ShopOrder SO on SOT.site=SO.Site and t.orderNo=SO.Prelev_order_no and t.E_OriginalOrderType=SO.E_OriginalOrderType and (SO.PartNo like 'RC%' or SO.PartNo like 'SC%' )
  792. where SOT.site=#{site} and SOT.orderNo=#{orderNo}
  793. </insert>
  794. <select id="getShopOrderScheduledQty" resultType="Double">
  795. select SUM(QtyRequired-isnull(circulation_qty,0)) from SOScheduledRouting where site=#{site} and OrderNo=#{orderNo} and itemNo=#{itemNo}
  796. </select>
  797. <select id="getOrderNoLotSizeSchedulingSize" resultType="com.heai.modules.production.entity.ShopOrderData">
  798. select lotSize, dbo.Get_PartPlanQty(site,PartNo,OrderNo) schedulingSize from ShopOrder where site=#{site} and OrderNo=#{orderNo}
  799. </select>
  800. <select id="checkTask" resultType="com.heai.modules.production.entity.HunlianTaskDetailData">
  801. select OrderNo as orderRef1 ,orderNo_hunlian as orderNo FROM view_KANBAN_SO_Hunlian_Plan
  802. where site=#{site} and (erpStatus='已取消' or FinishedFlag in ('2','3') or dispatched_hunlian='Y' ) and orderNo_hunlian in
  803. (select orderNo from Hunlian_TaskDetail where site=#{site} and TaskNo=#{taskNo} )
  804. </select>
  805. <update id="updateSOTaskDispatchedFlag" >
  806. update SOTaskOrderHeader set dispatched_hunlian =#{flag} where site=#{site} and orderNo in
  807. (select orderNo from Hunlian_TaskDetail where site=#{site} and TaskNo=#{taskNo} )
  808. </update>
  809. <update id="updateTaskReportFlag" >
  810. update Hunlian_TaskHeader set ReportFlag=#{flag} ,ReportQty=#{reportQty},reportReal=#{qtyReal},reportDate=#{reportDate} where site=#{site} and TaskNo=#{taskNo}
  811. </update>
  812. <insert id="saveHunlianTaskHeaderData" >
  813. insert into Hunlian_TaskHeader (Site,TaskNo,TaskQty,PartNo,CreateDate,CreateBy,ReportFlag,ReportQty,DeleteFlag,WareHouseFlag,WareHouseQty,Remark,OrderRef1)
  814. values(#{site},#{taskNo},#{taskQty},#{partNo},GetDate(),#{createBy},'N',0,'N','N',0,#{remark},#{orderRef1})
  815. </insert>
  816. <select id="getPartNoOnHand" resultType="com.heai.modules.production.entity.InventoryStockSearchData">
  817. select site,partNo, Round(sum(QtyOnHand),2) QtyOnHand from InventoryStock where site=#{site} and partNo=#{partNo} group by site,partNo
  818. </select>
  819. <select id="getHunlianTaskData" resultType="com.heai.modules.production.entity.HunlianData">
  820. select a.Site,a.TaskNo,a.TaskQty,a.PartNo,a.CreateDate,a.CreateBy,a.ReportFlag,a.ReportQty,dbo.Get_Part_SpecDesc(a.Site,a.PartNo) as partDesc
  821. ,b.toExpireDays,a.WareHouseFlag,a.remark,a.orderRef1
  822. from Hunlian_TaskHeader a
  823. left join part b on a.site=b.site and a.PartNo=b.partNo
  824. <where>
  825. and a.deleteFlag='N'
  826. <if test="startDate != null ">
  827. and a.CreateDate >= #{startDate}
  828. </if>
  829. <if test="endDate != null ">
  830. and #{endDate} >= a.CreateDate -1
  831. </if>
  832. <if test="reportFlag != null and reportFlag != ''">
  833. AND a.reportFlag = #{reportFlag}
  834. </if>
  835. <if test="partNo != null and partNo != ''">
  836. AND a.partNo like #{partNo}
  837. </if>
  838. <if test="taskNo != null and taskNo != ''">
  839. AND a.taskNo LIKE #{taskNo}
  840. </if>
  841. </where>
  842. ORDER BY a.CreateDate
  843. </select>
  844. <select id="getHunlianTaskList" resultType="com.heai.modules.production.entity.HunlianData">
  845. select a.Site,a.TaskNo,a.TaskQty,a.PartNo,a.CreateDate,a.CreateBy,a.ReportFlag,a.ReportQty,dbo.Get_Part_SpecDesc(a.Site,a.PartNo) as partDesc
  846. ,b.toExpireDays,a.WareHouseFlag,a.remark,a.orderRef1,dbo.Get_orderNoOnHand(a.Site,a.orderRef1) qtyOnHand,dbo.Get_Part_UMID(a.Site,a.PartNo) as umid
  847. from Hunlian_TaskHeader a
  848. left join part b on a.site=b.site and a.PartNo=b.partNo
  849. <where>
  850. and a.deleteFlag='N'
  851. <if test="query.startDate != null ">
  852. and a.CreateDate >= #{query.startDate}
  853. </if>
  854. <if test="query.endDate != null ">
  855. and #{query.endDate} >= a.CreateDate -1
  856. </if>
  857. <if test="query.reportFlag != null and query.reportFlag != ''">
  858. AND a.reportFlag = #{query.reportFlag}
  859. </if>
  860. <if test="query.partNo != null and query.partNo != ''">
  861. AND a.partNo like #{query.partNo}
  862. </if>
  863. <if test="query.taskNo != null and query.taskNo != ''">
  864. AND a.taskNo LIKE #{query.taskNo}
  865. </if>
  866. </where>
  867. ORDER BY a.CreateDate desc
  868. </select>
  869. <select id="getHunlianTaskDetailData" resultType="com.heai.modules.production.entity.HunlianTaskDetailData">
  870. select a.Site,a.TaskNo,a.OrderNo,a.OrderRef1,a.OrderRef2,a.OrderQty,a.HunlianQty,a.OrderDate,a.PartNo,a.HunlianPartNo,
  871. dbo.Get_Part_SpecDesc(a.Site,a.HunlianPartNo) as partDesc
  872. from Hunlian_TaskDetail a
  873. where site=#{site} and TaskNo=#{taskNo}
  874. </select>
  875. <select id="getHunlianTaskDetailDataSum" resultType="com.heai.modules.production.entity.HunlianTaskDetailData">
  876. select a.Site,a.TaskNo,a.OrderRef2,SUM(a.HunlianQty) HunlianQty,a.HunlianPartNo
  877. from Hunlian_TaskDetail a
  878. where site=#{site} and TaskNo=#{taskNo}
  879. GROUP BY a.Site,a.TaskNo,a.OrderRef2,a.HunlianPartNo
  880. </select>
  881. <select id="checkTaskHeader" resultType="com.heai.modules.production.entity.HunlianData">
  882. select Site,TaskNo,TaskQty,PartNo,CreateDate,CreateBy,ReportFlag,ReportQty,DeleteFlag,DeleteBy,DeleteDate,WareHouseFlag,orderRef1 from Hunlian_TaskHeader
  883. where site=#{site} and DeleteFlag='N' and TaskNo=#{taskNo}
  884. </select>
  885. <select id="checkTaskOrder" resultType="com.heai.modules.production.entity.HunlianData">
  886. select orderNo from shopOrder where status in ('已取消','已关闭') and site=#{site} and orderNo in (select orderRef1 from Hunlian_TaskDetail where site=#{site}
  887. and taskNo=#{taskNo} )
  888. </select>
  889. <update id="deleteTask">
  890. update Hunlian_TaskHeader set DeleteFlag='Y',DeleteBy=#{userId},DeleteDate=GetDate() where site=#{site} and TaskNo=#{taskNo}
  891. </update>
  892. <update id="updateSOTaskReport" parameterType="com.heai.modules.production.entity.DailyReportInData">
  893. update SOTaskOrderHeader SET Qtyfinished=Round(#{reportQty}*#{orderQty}/#{taskQty},1),ReportTime=GetDate(),FinishFlag='Y',ReportBy=#{userId} ,InputQty=Round(#{reportQty}*#{hunlianQty}/#{taskQty},1) where OrderNo=#{orderNo} and site =#{site}
  894. </update>
  895. <update id="cancelReportSOTask" parameterType="com.heai.modules.production.entity.HunlianData">
  896. update SOTaskOrderHeader SET Qtyfinished=0,ReportTime=null,FinishFlag='N',ReportBy=null ,InputQty=0 where site =#{site} and orderNo in (select orderNo from Hunlian_TaskDetail where site =#{site} and taskNo=#{taskNo})
  897. </update>
  898. <insert id="saveSOOpsTransferHeader">
  899. INSERT INTO SOOpsTransferHeader (TransNo,Site,FromProLineNo,ToProLineNo,ToWarehouseID,FromEnteredby,FromEnteredDate,TransDate,ToReceiver,FromReceiver,
  900. FromRemark,ToRemark,ConfirmedFlag,ToConfirmedBy,ToEnteredby,RecordVersion,
  901. Status,ToTypeFlag_DB,ToTypeFlag,ConfirmedTransNo,need_inspect_flag,NeedReceiveFlag) VALUES
  902. (#{transNo},#{site},'*','*','*',#{userId},GETDATE(),GETDATE(),'',#{userId},
  903. '','','N','N','','0',
  904. '已录入','W','混炼胶入库','','Y','N')
  905. </insert>
  906. <insert id="saveSOOpsTransferDetail">
  907. INSERT INTO SOOpsTransferDetail (TransNo,Site,ItemNo,FromOpsID,FromWorkCenterNo,ToWorkCenterNo,ToOpsID,OrderNo,PartNo,TransQty,ConfirmQty,TaskNo,InsStatus,
  908. ToConfirmQty) VALUES
  909. ( #{transNo},#{site},1,1,'*','',0,#{taskNo},#{partNo},#{reportQty},0,#{taskNo},'合格',0)
  910. </insert>
  911. <insert id="saveSOOpsTransferHeaderForShiYanShi">
  912. INSERT INTO SOOpsTransferHeader (TransNo,Site,FromProLineNo,ToProLineNo,ToWarehouseID,FromEnteredby,FromEnteredDate,TransDate,ToReceiver,FromReceiver,
  913. FromRemark,ToRemark,ConfirmedFlag,ToConfirmedBy,ToEnteredby,RecordVersion,
  914. Status,ToTypeFlag_DB,ToTypeFlag,ConfirmedTransNo,need_inspect_flag,NeedReceiveFlag,inspect_remark) VALUES
  915. (#{transNo},#{site},'*','*','*',#{operatorId},GETDATE(),GETDATE(),'',#{operatorId},
  916. '','','N','N','','0',
  917. '已录入','I',#{toTypeFlag},'','Y','N',#{inspectRemark})
  918. </insert>
  919. <insert id="saveSOOpsTransferDetailForShiYanShi">
  920. INSERT INTO SOOpsTransferDetail (TransNo,Site,ItemNo,FromOpsID,FromWorkCenterNo,ToWorkCenterNo,ToOpsID,OrderNo,PartNo,TransQty,ConfirmQty,TaskNo,InsStatus,
  921. ToConfirmQty,seqNo) VALUES
  922. ( #{transNo},#{site},1,1,#{sWorkCenterNo},'',0,#{orderNo},#{partNo},#{qtyRequired},0,#{orderNo},'待检验',0,#{seqNo})
  923. </insert>
  924. <select id="getTransNo" resultType="String">
  925. select 'OT'+CONVERT(varchar(100), GETDATE(), 112)+ Right( '00000'+ convert(VARCHAR(10), isnull(max(convert(INT,SUBSTRING(TransNo, 11,4))),0)+1) ,4)
  926. from SOOpsTransferHeader where TransNo like 'OT'+CONVERT(varchar(100), GETDATE(), 112)+'%'
  927. </select>
  928. <select id="checkLocationId" resultType="com.heai.modules.production.entity.LocationData">
  929. select LocationID,Site,LocationName,WareHouseID,Keeper,Active
  930. from Location where site=#{site} and LocationID=#{locationId}
  931. </select>
  932. <delete id="deleteSOOpsTransferHeader">
  933. update SOOpsTransferHeader set Status='已取消' where site=#{site} and transNo=#{transNo}
  934. </delete>
  935. <delete id="deleteSOOpsTransferDetail">
  936. delete from SOOpsTransferDetail where site=#{site} and transNo=#{transNo}
  937. </delete>
  938. <select id="getSfdcList" resultType="com.heai.modules.production.entity.SfdcCancel">
  939. select a.site,a.OrderNo,a.ItemNo ,a.SeqNo,a.WorkCenterNo,a.ReportDate,a.OperatorID,a.ReportQty,a.ApproveQty,a.ReportedManfTime,a.StatisticDate,
  940. 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
  941. ,a.reportWeight,a.approveWeight,a.moldQty,a.stopTime,dbo.Get_Part_SpecDesc(a.site,b.partNo) partSpec,dbo.Get_Part_SpecDesc(a.site,b.partNo) PartDesc,wasteWeight,b.jobType,
  942. f.Remark as scrapRemark,f.DefectQty as scrapQty,g.Remark as acceptRemark,g.DefectQty as acceptQty,b.RepairSOFlag
  943. from sfdc a LEFT JOIN SOScheduledRouting b on a.Site=b.Site and a.AssJobSeqNo=b.SeqNo
  944. left join Operator c on a.site=c.site and a.OperatorID=c.OperatorID
  945. left join WorkCenterResource e on a.Site=e.Site and a.Scheduled_ResourceId =e.ResourceID and a.WorkCenterNo=e.WorkCenterNo
  946. left join SFDC_DefectHist f on a.site=f.site and a.OrderNo=f.OrderNo and a.seqNo=f.SeqNo and f.DefectCode='PQ001'
  947. left join SFDC_DefectHist g on a.site=g.site and a.OrderNo=g.OrderNo and a.seqNo=g.SeqNo and g.DefectCode='PQ003'
  948. <where>
  949. and a.AssJobSeqNo is not null
  950. <if test="orderNo != null and orderNo != ''">
  951. and a.OrderNo like #{orderNo}
  952. </if>
  953. <if test="workCenterNo != null and workCenterNo != ''">
  954. and a.WorkCenterNo like #{workCenterNo}
  955. </if>
  956. <if test="partNo != null and partNo != ''">
  957. and b.partNo like #{partNo}
  958. </if>
  959. <if test="itemNo != null and itemNo != ''">
  960. and a.ItemNo = #{itemNo}
  961. </if>
  962. <if test="partDesc != null and partDesc != ''">
  963. and dbo.Get_Part_SpecDesc(a.site,b.partNo) like #{partDesc}
  964. </if>
  965. <if test="operatorName != null and operatorName != ''">
  966. and c.OperatorName like #{operatorName}
  967. </if>
  968. <if test="resourceId != null and resourceId != ''">
  969. and a.Scheduled_ResourceId = #{resourceId}
  970. </if>
  971. <if test="shiftNo != null and shiftNo != ''">
  972. and b.S_ShiftNo = #{shiftNo}
  973. </if>
  974. <if test="startDate != null ">
  975. and a.ReportDate >= #{startDate}
  976. </if>
  977. <if test="endDate != null ">
  978. and #{endDate} >= a.ReportDate
  979. </if>
  980. <if test="seqNo != null and seqNo != '' ">
  981. and a.AssJobSeqNo = #{seqNo}
  982. </if>
  983. <if test="operationDesc != null and operationDesc != ''">
  984. and dbo.Get_ItemDesc(a.site,a.OrderNo,a.ItemNo) like #{operationDesc}
  985. </if>
  986. <if test="repairSOFlag != null and repairSOFlag != ''">
  987. and b.RepairSOFlag like #{repairSOFlag}
  988. </if>
  989. </where>
  990. order by a.ReportDate desc
  991. </select>
  992. <update id="changeReceiveFlag">
  993. update SOOpsTransferHeader set NeedReceiveFlag=#{flag} from SOOpsTransferDetail b where SOOpsTransferHeader.site=b.site
  994. and SOOpsTransferHeader.transNo=b.transNo and SOOpsTransferHeader.status='已录入' and SOOpsTransferHeader.ToTypeFlag_DB='W' and
  995. b.seqNo=#{seqNo} and SOOpsTransferHeader.site=#{site}
  996. </update>
  997. <select id="getAllDepartment" resultType="OperatorData">
  998. select distinct isnull(Department,'') Department from Operator
  999. </select>
  1000. <update id="updateLastStartTime" >
  1001. update SORoutingOutput set LastStartTime=GetDate() where Site=#{site} and orderNo=#{orderNo} and itemNo=#{itemNo}
  1002. </update>
  1003. <select id="checkSORoutingOutput" resultType="SOScheduledRoutingOutData">
  1004. select site,orderNo from SORoutingOutput where Site=#{site} and orderNo=#{orderNo} and itemNo=#{itemNo}
  1005. </select>
  1006. <insert id="createSORoutingOutput" >
  1007. insert into SORoutingOutput (Site,OrderNo,ItemNo,TotalFinishedQty) values
  1008. (#{site},#{orderNo},#{itemNo},0)
  1009. </insert>
  1010. <select id="getLevelOneOrderNo" resultType="SOScheduledRoutingOutData">
  1011. select site,E_OriginalOrderNo OrderNo from shopOrder where orderNo=#{orderNo}
  1012. </select>
  1013. <update id="updateStockNewDate">
  1014. update InventoryStock set ExpiredDate_new=#{newDate} where Site=#{site} and WarehouseID=#{warehouseID} and PartNo=#{partNo} and BatchNo=#{barchNo} and LocationID=#{locationID}
  1015. </update>
  1016. <select id="checkTV" resultType="com.heai.modules.production.entity.TvSopBaseData">
  1017. select tv_id,work_station,now_seqNo,now_operator,sopAddress,badAddress from tv_sop_base
  1018. where tv_id=#{tvId}
  1019. </select>
  1020. <update id="updateTV" >
  1021. update Operator set tv_id=#{tvId} where site=#{site} and OperatorID=#{operatorID}
  1022. </update>
  1023. <select id="getTvList" resultType="com.heai.modules.production.entity.TvSopBaseData">
  1024. select tv_id,work_station,now_seqNo,now_operator,sopAddress,badAddress from tv_sop_base
  1025. <where>
  1026. <if test="tvId != null and tvId != ''">
  1027. and tv_id like #{tvId}
  1028. </if>
  1029. <if test="workStation != null and workStation != ''">
  1030. AND work_station = #{workStation}
  1031. </if>
  1032. </where>
  1033. </select>
  1034. <update id="updateWorkStation">
  1035. update tv_sop_base set work_station=#{workStation} where tv_id=#{tvId}
  1036. </update>
  1037. <select id="getPreviousSOSData" resultType="SOScheduledRoutingOutData">
  1038. select seqNo,PreviousSeqNo,PreviousBatchNo,materSeqNo from SOScheduledRouting where seqNo=#{previousSeqNo,jdbcType=INTEGER}
  1039. </select>
  1040. <update id="updatePreviousSOSData">
  1041. update SOScheduledRouting set PreviousSeqNo=#{previousSeqNo,jdbcType=INTEGER},PreviousBatchNo=#{previousBatchNo},materSeqNo=#{materSeqNo,jdbcType=INTEGER}
  1042. where seqNo=#{seqNo}
  1043. </update>
  1044. <select id="sfdcCheck" resultType="com.heai.modules.production.entity.SfdcCancel">
  1045. select Site,OrderNo,ItemNo,SeqNo from SFDC where AssJobSeqNo=#{seqNo}
  1046. </select>
  1047. <select id="selectSoScheduledRouting" resultType="SOScheduledRoutingOutData">
  1048. select Site,OrderNo,seqNo,itemNo,S_ShiftNo,scheduleType,ClosedFlag from SOScheduledRouting
  1049. <where>
  1050. <if test="seqNo != null">
  1051. and seqNo=#{seqNo}
  1052. </if>
  1053. </where>
  1054. </select>
  1055. <select id="selectSoTool" resultType="com.heai.modules.production.entity.SOToolData">
  1056. select Site,OrderNo,ToolID,ToolQty,Remark,CreateDate,CreatedBy,ItemNo from SOTool
  1057. <where>
  1058. <if test="orderNo != null and orderNo != ''">
  1059. and OrderNo = #{orderNo}
  1060. </if>
  1061. <if test="site != null and site != ''">
  1062. and Site = #{site}
  1063. </if>
  1064. <if test="toolID != null and toolID != ''">
  1065. and ToolID = #{toolID}
  1066. </if>
  1067. <if test="itemNo != null">
  1068. and ItemNo = #{itemNo}
  1069. </if>
  1070. </where>
  1071. </select>
  1072. <select id="getToolHeaderDescription" resultType="java.lang.String">
  1073. select top 1 ToolDescription from ToolHeader
  1074. <where>
  1075. <if test="toolID != null and toolID != ''">
  1076. and ToolID = #{toolID}
  1077. </if>
  1078. <if test="site != null and site != ''">
  1079. and Site = #{site}
  1080. </if>
  1081. </where>
  1082. </select>
  1083. <insert id="batchSaveToolingHist">
  1084. <foreach collection="toolingHistDataList" separator=";" item="item">
  1085. insert into SFDC_ToolingHist
  1086. (Site, OrderNo, ItemNo, SeqNo, HistSeqNo, ReportDate, Reportedby,
  1087. ToolInstanceID, StartDate, FinishDate, FinishFlag, Remark,
  1088. StartFromRollNo, FinishQty, RollNo, moQty, useQty)
  1089. values (#{item.site},#{item.orderNo},#{item.itemNo},#{item.seqNo},
  1090. (select ISNULL(max(HistSeqNo),0)+1 from SFDC_ToolingHist where Site = #{item.site} and SeqNo = #{item.seqNo}),
  1091. null,'',#{item.toolInstanceID},current_timestamp,null,'N','','',0,'',0,0)
  1092. </foreach>
  1093. </insert>
  1094. <select id="getLastStartHist" resultType="com.heai.modules.production.entity.SfdcTimeHistData">
  1095. select top 1 a.EventTime,a.site
  1096. from SFDC_TimeHist a left join SOScheduledRouting b on a.Site=b.Site and a.SeqNo=b.SeqNo
  1097. <where>
  1098. and a.EventType='P'
  1099. and b.operatorId=#{operatorId}
  1100. </where>
  1101. order by a.EventTime desc
  1102. </select>
  1103. <select id="packagingParameters" resultType="java.util.HashMap">
  1104. select dbo.Get_PartValue(#{site},#{partNo},#{qtyBag}) as qtyBag
  1105. , dbo.Get_PartValue(#{site},#{partNo},#{bag}) as bag
  1106. , dbo.Get_PartValue(#{site},#{partNo},#{qty}) as qty
  1107. , dbo.Get_PartValue(#{site},#{partNo},#{carton}) as carton
  1108. </select>
  1109. <select id="getHunlianTaskIssure" resultType="com.heai.modules.production.entity.HunlianData">
  1110. select b.SeqNo,b.S_ScheduledDate,b.operatorId,round( sum( case when c.Direction='-' then c.TransQty else 0 end ),2) as issureQty,
  1111. dbo.Get_OperatorDesc(a.site,b.operatorId) operatorName ,b.partNo,dbo.Get_Part_SpecDesc(a.site,b.partNo) partDesc,
  1112. round( sum( case when c.Direction='+' then c.TransQty else 0 end ),2) as returnQty,
  1113. round(sum( case when c.Direction='+' then c.TransQty else 0 end )*100/sum( case when c.Direction='-' then c.TransQty else 0 end ),2) as returnPercent
  1114. , round( sum( case when c.Direction='-' then c.TransQty else 0 end )-sum( case when c.Direction='+' then c.TransQty else 0 end ),2) as realQty
  1115. from TransDetail a
  1116. left join TransDetail c on a.Site=c.Site and a.PartNo=c.PartNo and a.BatchNo=c.BatchNo and c.TransNo like 'SI%' and c.OrderRef3 is not null
  1117. left join SOScheduledRouting b on a.Site=b.Site and CONVERT(VARCHAR(20),b.SeqNo)=c.OrderRef3
  1118. where b.SeqNo is not null and a.TransNo like 'SR%' and a.Direction='+' and c.TransNo is not null and a.orderRef1=#{orderRef1} and a.site=#{site}
  1119. group by a.site,b.SeqNo,b.S_ScheduledDate,b.operatorId,b.partNo
  1120. </select>
  1121. <select id="liuhuaIssureAndReport" resultType="com.heai.modules.production.entity.HunlianData">
  1122. select a.SeqNo,a.operatorId , a.S_ScheduledDate,a.partNo,dbo.Get_Part_SpecDesc(a.Site,a.partNo) partDesc,
  1123. dbo.Get_OperatorDesc(a.Site,a.operatorId) operatorName,
  1124. Round( dbo.Get_scheduleIssure(a.Site,a.SeqNo),2) as qtyIssure,Round(QtyReported*dbo.Get_PartWeightFactorForReport(a.Site,a.partNo,null),2) as reportWeight,
  1125. Round(dbo.Get_scheduleIssure(a.Site,a.SeqNo) -QtyReported*dbo.Get_PartWeightFactorForReport(a.Site,a.partNo,null),2) as qty,
  1126. dbo.Get_ScheduleissurePartNo(a.Site,a.SeqNo) issurePartNo ,dbo.Get_Part_SpecDesc(a.Site,dbo.Get_ScheduleissurePartNo(a.Site,a.SeqNo)) issurePartDesc
  1127. from SOScheduledRouting a
  1128. <where>
  1129. and scheduleType='日计划派工单'
  1130. <if test="query.startDate != null ">
  1131. and a.S_ScheduledDate >= #{query.startDate}
  1132. </if>
  1133. <if test="query.endDate != null ">
  1134. and #{query.endDate} >= a.S_ScheduledDate
  1135. </if>
  1136. <if test="query.partNo != null and query.partNo != ''">
  1137. AND a.partNo like #{query.partNo}
  1138. </if>
  1139. <if test="query.sql != null and query.sql != ''">
  1140. AND ${query.sql}
  1141. </if>
  1142. <if test="query.seqNo != null ">
  1143. AND a.seqNo = #{query.seqNo}
  1144. </if>
  1145. </where>
  1146. ORDER BY a.S_ScheduledDate desc
  1147. </select>
  1148. </mapper>