圣珀
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.

515 lines
21 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using ICS.WCF.Base;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.Linq;
  7. using System.ServiceModel;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. //using UFIDA.ISV.ApproveCompRpt;
  11. //using UFIDA.ISV.CloseCompRptSV;
  12. //using UFIDA.ISV.DeleteCompRptSV;
  13. using UFSoft.UBF.Service;
  14. using UFSoft.UBF.Util.Context;
  15. using www.ufida.org.EntityData;
  16. namespace UFIDA.ISV.CreateCompRpt
  17. {
  18. public class CustCreateCompRptSrvSub
  19. {
  20. /// <summary>
  21. /// 创建完工报告
  22. /// </summary>
  23. /// <param name="qty"></param>
  24. /// <param name="docTypeCode"></param>
  25. /// <param name="moCode"></param>
  26. /// <param name="Recer"></param>
  27. /// <param name="RecDept"></param>
  28. /// <returns></returns>
  29. public OperationResult CustCreateCompRpt(List<CompRpt> CompRptList)//List<rtnPoinfo>
  30. {
  31. #region 入口日志
  32. StringBuilder begionstr = new StringBuilder();
  33. begionstr.AppendLine("日志记录开始");
  34. foreach (var item in CompRptList)
  35. {
  36. bool isLotCheck = Appconfig.WHLotCheckState(item.WHCode, item.OrgCode);
  37. if (isLotCheck == false)
  38. {
  39. item.Batch = "";
  40. }
  41. begionstr.AppendLine("工单:" + item.moCode);
  42. begionstr.AppendLine("数量:" + item.qty);
  43. begionstr.AppendLine("单据类型:" + item.docTypeCode);
  44. begionstr.AppendLine("操作员:" + item.Recer);
  45. begionstr.AppendLine("仓库:" + item.WHCode);
  46. begionstr.AppendLine("部门:" + item.RecDept);
  47. begionstr.AppendLine("供应商编码:" + item.VenderCode);
  48. begionstr.AppendLine("供应商名称:" + item.VenderName);
  49. begionstr.AppendLine("组织编码:" + item.OrgCode);
  50. begionstr.AppendLine("物料编码:" + item.ItemCode);
  51. begionstr.AppendLine("传入批次:" + item.Batch);
  52. begionstr.AppendLine("备注:" + item.Memo);
  53. }
  54. Appconfig.WriteLogFile(begionstr.ToString(), "创建完工报告");
  55. #endregion
  56. #region 服务调用框架结构
  57. //实例化代理类 UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient
  58. UFIDAU9ISVMOICreateCompRptSrvClient client = new UFIDAU9ISVMOICreateCompRptSrvClient();
  59. //服务返回结果
  60. UFIDAU9ISVMOCompRptKeyDTOData[] returnItem;
  61. //返回异常信息,目前还没有使用此属性
  62. UFSoft.UBF.Exceptions.MessageBase[] returnMsg;
  63. //上下文信息
  64. object context;
  65. //传入 参数
  66. UFIDAU9ISVMOCompRptDTOData[] compRptDTOs;
  67. try
  68. {
  69. OperationResult result = new OperationResult();
  70. if (CompRptList == null || CompRptList.Count == 0)
  71. {
  72. result.MESSAGE = "请传入数据";
  73. result.IsSuccess = false;
  74. return result;
  75. }
  76. string OrgID = "";
  77. string orgsql = @"select ID from Base_Organization
  78. where Code='{0}'";
  79. orgsql = string.Format(orgsql, CompRptList[0].OrgCode);
  80. DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
  81. if (orgdt.Rows.Count != 0)
  82. {
  83. OrgID = orgdt.Rows[0]["ID"].ToString();
  84. }
  85. else
  86. {
  87. result.MESSAGE = "传入的组织编码有误!";
  88. result.IsSuccess = false;
  89. return result;
  90. }
  91. //给上下文信息赋值
  92. context = CreateContextObj(OrgID);
  93. //给传入参数赋值
  94. compRptDTOs = GetDataNew(CompRptList, OrgID);
  95. //服务调用
  96. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  97. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  98. returnItem = client.Do(out returnMsg, context, compRptDTOs);
  99. result.poheadList = returnItem;
  100. StringBuilder str = new StringBuilder();
  101. str.AppendLine("创建完工报告");
  102. foreach (var item in CompRptList)
  103. {
  104. str.AppendLine("工单:" + item.moCode);
  105. str.AppendLine("数量:" + item.qty);
  106. str.AppendLine("单据类型:" + item.docTypeCode);
  107. str.AppendLine("操作员:" + item.Recer);
  108. str.AppendLine("仓库:" + item.WHCode);
  109. str.AppendLine("部门:" + item.RecDept);
  110. str.AppendLine("组织编码" + item.OrgCode);
  111. str.AppendLine("物料编码:" + item.ItemCode);
  112. str.AppendLine("传入批次:" + item.Batch);
  113. str.AppendLine("备注:" + item.Memo);
  114. }
  115. str.AppendLine("结果:" + "True");
  116. Appconfig.WriteLogFile(str.ToString(), "创建完工报告");
  117. result.OrgID = OrgID;
  118. result.DocNo = returnItem[0].m_docNo;
  119. result.IsSuccess = true;
  120. result.MESSAGE = "完工报告创建成功";
  121. return result;
  122. }
  123. catch (Exception ex)
  124. {
  125. OperationResult result = new OperationResult();
  126. StringBuilder str = new StringBuilder();
  127. str.AppendLine("创建完工报告异常");
  128. //异常信息捕获
  129. //ReturnValue2 value = new ReturnValue2();
  130. result.IsSuccess = false;
  131. result.MESSAGE = GetExceptionMessage(ex);
  132. foreach (var item in CompRptList)
  133. {
  134. str.AppendLine("工单:" + item.moCode);
  135. str.AppendLine("数量:" + item.qty);
  136. str.AppendLine("单据类型:" + item.docTypeCode);
  137. str.AppendLine("操作员:" + item.Recer);
  138. str.AppendLine("部门:" + item.RecDept);
  139. str.AppendLine("仓库:" + item.WHCode);
  140. str.AppendLine("物料编码:" + item.ItemCode);
  141. str.AppendLine("传入批次:" + item.Batch);
  142. str.AppendLine("备注:" + item.Memo);
  143. str.AppendLine("错误消息:" + result.MESSAGE);
  144. }
  145. str.AppendLine("结果:" + "false");
  146. Appconfig.WriteLogFile(str.ToString(), "创建完工报告异常");
  147. //return value;
  148. return result;
  149. }
  150. #endregion
  151. }
  152. private static UFIDAU9ISVMOCompRptDTOData[] GetDataNew(List<CompRpt> CompRptList, string OrgID)
  153. {
  154. List<UFIDAU9ISVMOCompRptDTOData> datas = new List<UFIDAU9ISVMOCompRptDTOData>();
  155. List<UFIDAU9ISVMOCompRptRcvLineDTOData> rptrcvlinelist = new List<UFIDAU9ISVMOCompRptRcvLineDTOData>();
  156. foreach (var item in CompRptList)
  157. {
  158. UFIDAU9ISVMOCompRptDTOData data = new UFIDAU9ISVMOCompRptDTOData();
  159. if (item.qty != 0)
  160. {
  161. data.m_completeQty = item.qty;
  162. data.m_completeQtyCoUOM = item.qty;
  163. data.m_completeQtyWhUOM = item.qty;
  164. data.m_eligibleQtyCoUOM = item.qty;
  165. data.m_reworkingQtyCoUOM = item.qty;
  166. }
  167. data.m_org = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  168. data.m_org.m_iD = long.Parse(OrgID);
  169. long LotMaster = 0;
  170. if (!string.IsNullOrWhiteSpace(item.Batch))
  171. {
  172. //创建批号
  173. string lotID = "";
  174. UFIDA.ISV.CreateLotMaster.CustCreateLotMaster createLot = new CreateLotMaster.CustCreateLotMaster();
  175. UFIDA.ISV.CreateLotMaster.CustCreateLotMaster.OperationResule result = createLot.CustCreateRCVLotMaster(item.WHCode, item.ItemCode, item.Batch, OrgID, ref lotID);
  176. if (result.IsSuccess)
  177. {
  178. LotMaster = long.Parse(lotID);
  179. }
  180. else
  181. {
  182. throw new Exception("批号生成失败,完工报告生成失败!");
  183. }
  184. }
  185. data.m_docNo = item.DocNO;
  186. data.m_completeDocType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  187. data.m_completeDocType.m_code = item.docTypeCode;
  188. data.m_completeDocType.m_iD = GetTypeID(item.docTypeCode, OrgID);
  189. data.m_mO = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  190. data.m_mO.m_code = item.moCode;
  191. data.m_handlePerson = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  192. data.m_handlePerson.m_code = item.Recer;
  193. data.m_handleDept = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  194. data.m_handleDept.m_code = item.RecDept;
  195. data.m_rcvWh = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  196. data.m_rcvWh.m_iD = GetWHID(item.WHCode, OrgID);
  197. data.m_completeDate = DateTime.Now;
  198. data.m_actualRcvTime = DateTime.Now;
  199. List<UFIDAU9ISVMOCompRptRcvLineDTOData> rcvLineList = new List<UFIDAU9ISVMOCompRptRcvLineDTOData>();
  200. UFIDAU9ISVMOCompRptRcvLineDTOData rcvLine = new UFIDAU9ISVMOCompRptRcvLineDTOData();
  201. if (LotMaster != 0)
  202. {
  203. rcvLine.m_rcvLotNo = item.Batch;
  204. rcvLine.m_rcvLotMaster = long.Parse(LotMaster.ToString());
  205. }
  206. rcvLine.m_storageType = 4;
  207. rcvLine.m_grade = -1;
  208. rcvLine.m_element = -1;
  209. rcvLine.m_descFlexField = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
  210. rcvLine.m_descFlexField.m_privateDescSeg1 = item.Memo;
  211. rcvLine.m_descFlexField.m_privateDescSeg2 = item.VenderCode;
  212. rcvLine.m_descFlexField.m_privateDescSeg3 = item.VenderName;
  213. rcvLineList.Add(rcvLine);
  214. data.m_completeRptRcvLines = rcvLineList.ToArray();
  215. datas.Add(data);
  216. }
  217. return datas.ToArray();
  218. }
  219. /// <summary>
  220. /// 创建完工报告
  221. /// </summary>
  222. /// <param name="qty"></param>
  223. /// <param name="docTypeCode"></param>
  224. /// <param name="moCode"></param>
  225. /// <param name="Recer"></param>
  226. /// <param name="RecDept"></param>
  227. /// <returns></returns>
  228. public static ReturnValue2 CustCreateCompRpt_bak20200306(decimal qty, string docTypeCode, string moCode, string Recer, string RecDept)//List<rtnPoinfo>
  229. {
  230. #region 服务调用框架结构
  231. //实例化代理类 UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient
  232. UFIDAU9ISVMOICreateCompRptSrvClient client = new UFIDAU9ISVMOICreateCompRptSrvClient();
  233. //服务返回结果
  234. UFIDAU9ISVMOCompRptKeyDTOData[] returnItem;
  235. //返回异常信息,目前还没有使用此属性
  236. UFSoft.UBF.Exceptions.MessageBase[] returnMsg;
  237. //上下文信息
  238. object context;
  239. //传入 参数
  240. UFIDAU9ISVMOCompRptDTOData[] compRptDTOs;
  241. try
  242. {
  243. //给上下文信息赋值
  244. context = CreateContextObj("");
  245. //给传入参数赋值
  246. compRptDTOs = GetData(qty, docTypeCode, moCode, Recer, RecDept);
  247. //服务调用
  248. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  249. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  250. returnItem = client.Do(out returnMsg, context, compRptDTOs);
  251. ReturnValue2 value = new ReturnValue2();
  252. value.poheadList = returnItem;
  253. StringBuilder str = new StringBuilder();
  254. str.AppendLine("创建完工报告");
  255. str.AppendLine("单号:" + returnItem[0].m_docNo);
  256. str.AppendLine("工单:" + moCode);
  257. str.AppendLine("数量:" + qty);
  258. str.AppendLine("单据类型:" + docTypeCode);
  259. str.AppendLine("操作员:" + Recer);
  260. str.AppendLine("部门:" + RecDept);
  261. str.AppendLine("结果:" + "True");
  262. Appconfig.WriteLogFile(str.ToString(), "创建完工报告");
  263. //使实际入库时间为null
  264. foreach (UFIDAU9ISVMOCompRptKeyDTOData data in returnItem)
  265. {
  266. string sql = @"update MO_CompleteRpt set ActualRcvTime=NULL from MO_CompleteRpt where DocNo='" + data.m_docNo + "'";
  267. DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  268. }
  269. return value;
  270. }
  271. catch (Exception ex)
  272. {
  273. StringBuilder str = new StringBuilder();
  274. str.AppendLine("创建完工报告");
  275. str.AppendLine("工单:" + moCode);
  276. str.AppendLine("数量:" + qty);
  277. str.AppendLine("单据类型:" + docTypeCode);
  278. str.AppendLine("操作员:" + Recer);
  279. str.AppendLine("部门:" + RecDept);
  280. str.AppendLine("错误:" + GetExceptionMessage(ex));
  281. str.AppendLine("错误:" + "False");
  282. Appconfig.WriteLogFile(str.ToString(), "创建完工报告");
  283. //异常信息捕获
  284. ReturnValue2 value = new ReturnValue2();
  285. value.Mes = GetExceptionMessage(ex);
  286. return value;
  287. }
  288. #endregion
  289. }
  290. #region 提取异常信息
  291. /// <summary>
  292. /// 提取异常信息
  293. /// </summary>
  294. /// <param name="ex"></param>
  295. private static string GetExceptionMessage(Exception ex)
  296. {
  297. string faultMessage = "未知错误,请查看ERP日志!";
  298. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  299. if (timeoutEx != null)
  300. {
  301. faultMessage = "访问服务超时,请修改配置信息!";
  302. }
  303. else
  304. {
  305. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  306. if (faultEx == null)
  307. {
  308. faultMessage = ex.Message;
  309. }
  310. else
  311. {
  312. ServiceException serviceEx = faultEx.Detail;
  313. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  314. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  315. {
  316. // 错误信息在faultEx.Message中,请提取,
  317. // 格式为"Fault:料品不能为空,请录入\n 在....."
  318. int startIndex = serviceEx.Message.IndexOf(":");
  319. int endIndex = serviceEx.Message.IndexOf("\n");
  320. if (endIndex == -1)
  321. endIndex = serviceEx.Message.Length;
  322. if (endIndex > 0 && endIndex > startIndex + 1)
  323. {
  324. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  325. }
  326. else
  327. {
  328. faultMessage = serviceEx.Message;
  329. }
  330. }
  331. }
  332. }
  333. return faultMessage;
  334. }
  335. #endregion
  336. #region 给上下文信息赋值
  337. /// <summary>
  338. /// 给上下文信息赋值
  339. /// </summary>
  340. /// <returns></returns>
  341. private static ThreadContext CreateContextObj(string OrgID)
  342. {
  343. // 实例化应用上下文对象
  344. ThreadContext thContext = new ThreadContext();
  345. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  346. ns.Add("OrgID", OrgID);
  347. ns.Add("OrgCode", ConfigurationManager.AppSettings["orgCode"].ToString());
  348. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  349. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  350. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  351. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  352. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  353. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  354. thContext.nameValueHas = ns;
  355. return thContext;
  356. }
  357. #endregion
  358. private static UFIDAU9ISVMOCompRptDTOData[] GetData(decimal qty, string docTypeCode, string moCode, string Recer, string RecDept)
  359. {
  360. List<UFIDAU9ISVMOCompRptDTOData> datas = new List<UFIDAU9ISVMOCompRptDTOData>();
  361. UFIDAU9ISVMOCompRptDTOData data = new UFIDAU9ISVMOCompRptDTOData();
  362. if (qty != 0)
  363. {
  364. data.m_completeQty = qty;
  365. }
  366. data.m_completeDocType = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  367. data.m_completeDocType.m_code = docTypeCode;
  368. //data.m_completeDocType.m_iD = GetTypeID(docTypeCode);
  369. data.m_mO = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  370. data.m_mO.m_code = moCode;
  371. data.m_handlePerson = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  372. data.m_handlePerson.m_code = Recer;
  373. data.m_handleDept = new UFIDAU9CBOPubControllerCommonArchiveDataDTOData();
  374. data.m_handleDept.m_code = RecDept;
  375. //data.m_completeDate =DateTime. ;
  376. datas.Add(data);
  377. //data.m_actualRcvTime=;
  378. return datas.ToArray();
  379. }
  380. private static long GetTypeID(string docTypeCode, string OrgID)
  381. {
  382. string sql = @"SELECT A.[ID] as [ID], A.[Code] as [Code]
  383. FROM MO_CompleteRptDocType as A
  384. left join [MO_CompleteRptDocType_Trl] as A1 on (A1.SysMlFlag = 'zh-CN') and (A.[ID] = A1.[ID])
  385. left join [Base_Organization] as A4 on (A.[Org] = A4.[ID])
  386. WHERE ((A.[Code] = '"+ docTypeCode + "' and (1 = 1)) and (A4.[ID] = '" + OrgID + "')) ";
  387. DataTable dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  388. if (dt.Rows.Count > 0)
  389. {
  390. return long.Parse(dt.Rows[0][0].ToString());
  391. }
  392. else
  393. {
  394. return 0;
  395. }
  396. }
  397. public static long GetWHID(string WHCode, string OrgID)
  398. {
  399. long WHID = 0;
  400. string sql = @" SELECT ID FROM CBO_Wh WHERE Code='" + WHCode + "' AND Org='" + OrgID + "' ";
  401. sql = string.Format(sql);
  402. DataTable _dtWH = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  403. string _WHCode = string.Empty;
  404. if (_dtWH != null && _dtWH.Rows.Count > 0)
  405. {
  406. _WHCode = _dtWH.Rows[0][0].ToString();
  407. WHID = long.Parse(_WHCode);
  408. }
  409. return WHID;
  410. }
  411. }
  412. public class ReturnValue2//List<rtnPoinfo>
  413. {
  414. public string Mes;
  415. public UFIDAU9ISVMOCompRptKeyDTOData[] poheadList;
  416. }
  417. public class CompRpt
  418. {
  419. public string DocNO { get; set; }
  420. public decimal qty { get; set; }
  421. public string docTypeCode { get; set; }
  422. public string moCode { get; set; }
  423. public string Recer { get; set; }
  424. public string RecDept { get; set; }
  425. public string ItemCode { get; set; }
  426. public string WHCode { get; set; }
  427. public bool NeedTransferIN { get; set; }
  428. public string OrgCode { get; set; }
  429. public string Batch { get; set; }
  430. public string Memo { get; set; }
  431. public string VenderCode { get; set; }
  432. public string VenderName { get; set; }
  433. }
  434. public class OperationResult//List<rtnPoinfo>
  435. {
  436. /// <summary>
  437. /// 结果状态,默认值false
  438. /// </summary>
  439. public bool IsSuccess { get; set; }
  440. /// <summary>
  441. ///处理消息
  442. /// </summary>
  443. public string MESSAGE { get; set; }
  444. /// <summary>
  445. /// 完工报告编码
  446. /// </summary>
  447. public string DocNo { get; set; }
  448. /// <summary>
  449. /// 组织ID
  450. /// </summary>
  451. public string OrgID { get; set; }
  452. public UFIDAU9ISVMOCompRptKeyDTOData[] poheadList;
  453. }
  454. }