IcsFromERPJob
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.

218 lines
13 KiB

4 months ago
  1. using Quartz;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. namespace ICSSoft.FromERP
  8. {
  9. /// <summary>
  10. /// 委外采购订单
  11. /// </summary>
  12. public class ICSOutsourcingOrder : IJob
  13. {
  14. private static object key = new object();
  15. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  16. public void Execute(IJobExecutionContext context)
  17. {
  18. try
  19. {
  20. lock (key)
  21. {
  22. log.Info("开始……………………………………………………………………");
  23. Execute();
  24. log.Info("结束……………………………………………………………………");
  25. }
  26. }
  27. catch (Exception ex)
  28. {
  29. log.Error(ex.ToString());
  30. }
  31. }
  32. public void Execute()
  33. {
  34. try
  35. {
  36. string conStr = ICSHelper.GetConnectString();
  37. string Namespace = this.GetType().Namespace;
  38. //string Class = this.GetType().Name;
  39. DataTable dt = ICSHelper.GetERPDB(conStr);
  40. foreach (DataRow dr in dt.Rows)
  41. {
  42. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  43. string WorkPoint = dr["WorkPointCode"].ToString();
  44. string Class = this.GetType().Name + WorkPoint;
  45. erpName = string.Format(erpName, WorkPoint);
  46. #region SQL
  47. string sql = @"SELECT
  48. CAST (b.MODetailsID AS VARCHAR(50)) AS OODetailID,
  49. b.MOID AS OOID,
  50. c.cCode AS OOCode,
  51. CAST (b.iVouchRowNo AS VARCHAR(50)) AS PORow,
  52. c.dDate AS PODate,
  53. c.cVenCode AS VenCode,
  54. v.cVenName AS VenName,
  55. c.cPersonCode AS PersonCode,
  56. p.cPersonName AS PersonName,
  57. c.cDepCode AS GroupCode,
  58. q.cDepName AS GroupName,
  59. c.cexch_name AS CurrencyName,
  60. c.cPTCode AS SubjectCode,
  61. pt.cPTName AS ProjectType,
  62. b.cInvCode AS InvCode,
  63. b.iQuantity AS Quantity,
  64. c.cMaker AS CreatePerson,
  65. b.dArriveDate AS PreArriveDate,
  66. c.dCreateTime as CreateDateTime,
  67. '2' AS Status,
  68. isnull(b.iNum,0) AS Amount,
  69. '1' AS Type,
  70. 'CS' AS ServerModel,
  71. b.iTaxPrice AS Price,
  72. '' AS ORDERNO,
  73. ISNULL(b.dbCloseTime,ISNULL(c.dChangeVerifyTime,ISNULL(c.dVerifyTime, ISNULL(c.dModifyTime, c.dCreateTime)))) AS MTIME,
  74. '' AS MEMO,
  75. '' AS WHCode,
  76. c.cdefine13 AS ReMark,
  77. c.cMaker AS DateTime1User,
  78. c.dDate AS DateTime1,
  79. c.cVerifier AS DateTime2User,
  80. c.dVerifyDate AS DateTime2,
  81. CASE WHEN b.dbCloseTime IS NULL THEN '' ELSE '' END AS ISUrgent,
  82. isnull(b.cItemCode,'') ProjectCode,'' cBatch,'' version ,'' brand,
  83. (case WHEN d.bFree1=1 THEN isnull(b.cFree1,'') ELSE '' END) as cFree1,
  84. (case WHEN d.bFree2=1 THEN isnull(b.cFree2,'') ELSE '' END) as cFree2,
  85. (case WHEN d.bFree3=1 THEN isnull(b.cFree3,'') ELSE '' END) as cFree3,
  86. (case WHEN d.bFree4=1 THEN isnull(b.cFree4,'') ELSE '' END) as cFree4,
  87. (case WHEN d.bFree5=1 THEN isnull(b.cFree5,'') ELSE '' END) as cFree5,
  88. (case WHEN d.bFree6=1 THEN isnull(b.cFree6,'') ELSE '' END) as cFree6,
  89. (case WHEN d.bFree7=1 THEN isnull(b.cFree7,'') ELSE '' END) as cFree7,
  90. (case WHEN d.bFree8=1 THEN isnull(b.cFree8,'') ELSE '' END) as cFree8,
  91. (case WHEN d.bFree9=1 THEN isnull(b.cFree9,'') ELSE '' END) as cFree9,
  92. (case WHEN d.bFree10=1 THEN isnull(b.cFree10,'') ELSE '' END) as cFree10,CAST('' AS NVARCHAR(500)) as Colspan
  93. , '{0}' as WorkPoint
  94. INTO #TempPOWW
  95. FROM {1}.dbo.OM_MODetails b
  96. LEFT JOIN {1}.dbo.OM_MOMain c ON b.MOID = c.MOID
  97. LEFT JOIN {1}.dbo.Inventory d ON b.cInvCode = d.cInvCode
  98. LEFT JOIN {1}.dbo.PurchaseType pt ON c.cPTCode = pt.cPTCode
  99. LEFT JOIN {1}.dbo.ComputationUnit g ON d.cComUnitCode = g.cComunitCode
  100. LEFT JOIN {1}.dbo.Vendor v ON c.cVenCode = v.cVenCode
  101. LEFT JOIN {1}.dbo.Department q ON c.cDepCode = q.cDepCode
  102. LEFT JOIN {1}.dbo.Person p ON c.cPersonCode = p.cPersonCode
  103. WHERE c.cverifier IS NOT NULL AND ISNULL(b.dbCloseTime,ISNULL(c.dChangeVerifyTime,ISNULL(c.dVerifyTime, ISNULL(c.dModifyTime, c.dCreateTime))))>=@LastTime
  104. and c.cVerifier IS NOT NULL --AND ISNULL(b.cbCloser,'')=''
  105. update #TempPOWW set Colspan=isNULL(ProjectCode,'')+'~'+isNULL(cBatch,'')+'~'+isNULL(Version,'')+'~'+isNULL(Brand,'')+'~'+isNULL(cFree1,'')+'~'+isnull(cFree2,'')+'~'+isnull(cFree3,'')+'~'+isnull(cFree4,'')+'~'+isnull(cFree5,'')+'~'+isnull(cFree6,'')+'~'+isnull(cFree7,'')+'~'+isnull(cFree8,'')+'~'+isnull(cFree9,'')+'~'+isnull(cFree10,'')
  106. select distinct
  107. Colspan,ProjectCode,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint,cBatch,version ,brand
  108. INTO #TempExtension
  109. from #TempPOWW
  110. IF NOT EXISTS(SELECT * FROM #TempPOWW)
  111. RETURN";
  112. sql = ICSHelper.Time(Namespace, Class, WorkPoint, sql, "#TempPOWW");
  113. Dictionary<string, string> value = new Dictionary<string, string>();
  114. value.Add("ID", "NEWID()");
  115. value.Add("BatchCode", "a.cBatch");
  116. value.Add("version", "a.version");
  117. value.Add("brand", "a.brand");
  118. value.Add("ProjectCode", "a.ProjectCode");
  119. value.Add("cFree1", "a.cFree1");
  120. value.Add("cFree2", "a.cFree2");
  121. value.Add("cFree3", "a.cFree3");
  122. value.Add("cFree4", "a.cFree4");
  123. value.Add("cFree5", "a.cFree5");
  124. value.Add("cFree6", "a.cFree6");
  125. value.Add("cFree7", "a.cFree7");
  126. value.Add("cFree8", "a.cFree8");
  127. value.Add("cFree9", "a.cFree9");
  128. value.Add("cFree10", "a.cFree10");
  129. value.Add("Colspan", "a.Colspan");
  130. value.Add("MTIME", "GETDATE()");
  131. value.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");
  132. value.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");
  133. value.Add("WorkPoint", "'" + WorkPoint + "'");
  134. //插入新增数据->ICSExtension表
  135. sql += ICSHelper.InsertSQL("ICSExtension", value)
  136. + @"#TempExtension a
  137. LEFT JOIN ICSExtension b ON a.ProjectCode+'~'+a.cBatch+'~'+a.Version+'~'+a.Brand+'~'+a.cFree1+'~'+a.cFree2+'~'+a.cFree3+'~'+a.cFree4+'~'+a.cFree5+'~'+a.cFree6+'~'+a.cFree7+'~'+a.cFree8+'~'+a.cFree9+'~'+a.cFree10=b.Colspan and a.WorkPoint=b.WorkPoint
  138. WHERE b.Colspan IS NULL";
  139. sql += @"--删除数据
  140. -- DELETE ICSOutsourcingOrder WHERE OODetailID NOT IN ( SELECT CAST(MODetailsID AS VARCHAR) FROM {1}.dbo.[OM_MODetails])
  141. SELECT a.OODetailID INTO #tableICSOutsourcingOrder
  142. FROM ICSOutsourcingOrder a With(NoLock)
  143. LEFT JOIN {1}.dbo.[OM_MODetails] b With(NoLock) ON a.OODetailID= CAST(b.MODetailsID AS VARCHAR)
  144. WHERE a.WorkPoint='{0}' and b.MODetailsID IS NULL
  145. DELETE ICSOutsourcingOrder
  146. WHERE WorkPoint='{0}' and OODetailID IN ( SELECT OODetailID from #tableICSOutsourcingOrder)
  147. ";
  148. Dictionary<string, string> values = new Dictionary<string, string>();
  149. values.Add("OOCode", "a.OOCode");//采购订单号
  150. values.Add("Sequence", "a.PORow");//采购订单行号
  151. values.Add("VenCode", "a.VenCode");//供应商代码
  152. values.Add("Amount", "a.Amount");//辅计量
  153. values.Add("DepCode", "a.GroupCode");//部门代码
  154. values.Add("PersonCode", "a.PersonCode");//业务员代码
  155. values.Add("Type", "a.Type");//采购类型
  156. values.Add("InvCode", "a.InvCode");//物料代码
  157. values.Add("Quantity", "a.Quantity");//数量
  158. values.Add("UnitPrice", "a.Price");//价格
  159. values.Add("Currency", "a.CurrencyName");//币种
  160. values.Add("Status", "a.Status");
  161. values.Add("CreatePerson", "a.CreatePerson");//创建人
  162. values.Add("PlanArriveDate", "a.PreArriveDate");//预计到货日期
  163. values.Add("CreateDateTime", "a.CreateDateTime");//业务员名称
  164. values.Add("OODetailID", "a.OODetailID");
  165. values.Add("OOID", "a.OOID");
  166. values.Add("ExtensionID", "c.ID");
  167. //values.Add("POID", "a.POID");
  168. values.Add("MTIME", "a.MTIME");
  169. //更新存在数据
  170. sql += ICSHelper.UpdateSQL("b", values)
  171. + @" #TempPOWW a
  172. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID+a.Type=b.OODetailID+b.Type and a.WorkPoint=b.WorkPoint
  173. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  174. WHERE a.WorkPoint='" + WorkPoint + "' ";
  175. //values.Add("PODetailID", "a.Free2");
  176. //values.Add("POType", "a.POType");
  177. //values.Add("ServerModel", "a.ServerModel");
  178. values.Add("ID", "NEWID()");//ID
  179. values.Add("MUSER", "'" + ConstWorkPoint.Muser + "'");//操作人
  180. values.Add("MUSERName", "'" + ConstWorkPoint.Musername + "'");//操作人姓名
  181. values.Add("WorkPoint", "'" + WorkPoint + "'");//站点
  182. values.Add("EATTRIBUTE1", "''");//站点
  183. values.Add("ReleaseState", "'0'");//发布状态
  184. //插入新增数据
  185. sql += ICSHelper.InsertSQL("ICSOutsourcingOrder", values)
  186. + @" #TempPOWW a
  187. LEFT JOIN ICSOutsourcingOrder b ON a.OODetailID+a.Type=b.OODetailID+b.Type and a.WorkPoint=b.WorkPoint
  188. inner join ICSExtension c on a.Colspan=c.Colspan and a.WorkPoint=c.WorkPoint
  189. WHERE b.OODetailID IS NULL and a.WorkPoint='" + WorkPoint + @"' ";
  190. sql += " DROP TABLE #TempPOWW";
  191. sql += " DROP TABLE #TempExtension " +
  192. " DROP TABLE #tableICSOutsourcingOrder";
  193. sql = string.Format(sql, WorkPoint, erpName);
  194. ICSHelper.ExecuteDate(conStr, sql);
  195. #endregion
  196. }
  197. }
  198. catch (Exception ex)
  199. {
  200. log.Error(ex.ToString());
  201. }
  202. }
  203. }
  204. }