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

621 lines
23 KiB

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. 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 UFSoft.UBF.Business.BusinessEntity;
  11. using UFSoft.UBF.Service;
  12. using UFSoft.UBF.Util.Context;
  13. using www.ufida.org.EntityData;
  14. namespace UFIDA.ISV.CreateBFRTN
  15. {
  16. public class CustCreateBFRTNSrvSub
  17. {
  18. public List<rtnRcvInfo> CustCreateBFRTN(List<rCVhead> rCVInfoList)
  19. {
  20. #region 服务调用框架结构
  21. UFIDAU9ISVRCVICeateReceivementFromPOSRVClient client = new UFIDAU9ISVRCVICeateReceivementFromPOSRVClient();
  22. //服务返回结果
  23. EntityKey[] returnItems;
  24. //返回异常信息,目前还没有使用此属性
  25. UFSoft.UBF.Exceptions.MessageBase[] returnMsg;
  26. //上下文信息
  27. object context;
  28. //传入 参数
  29. UFIDAU9ISVRCVDTOPOToRcvTransDTOData[] pOList;
  30. //空
  31. string[] splitBy = new string[] { };
  32. try
  33. {
  34. List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
  35. if (rCVInfoList == null || rCVInfoList.Count == 0)
  36. {
  37. rtnRcvInfo rtnpo = new rtnRcvInfo();
  38. rtnpo.IsSuccess = false;
  39. rtnpo.Message = "传入参数不能为空";
  40. rtnpos.Add(rtnpo);
  41. return rtnpos;
  42. }
  43. foreach (var item in rCVInfoList)
  44. {
  45. if (item.lines == null || item.lines.Count() == 0)
  46. {
  47. rtnRcvInfo rtnpo = new rtnRcvInfo();
  48. rtnpo.IsSuccess = false;
  49. rtnpo.Message = "传入行信息不能为空";
  50. rtnpos.Add(rtnpo);
  51. return rtnpos;
  52. }
  53. foreach (var _item in item.lines)
  54. {
  55. //if (string.IsNullOrWhiteSpace(_item.ItemCode))
  56. //{
  57. // rtnRcvInfo rtnpo = new rtnRcvInfo();
  58. // rtnpo.IsSuccess = false;
  59. // rtnpo.Message = "传入料号不能为空";
  60. // rtnpos.Add(rtnpo);
  61. // return rtnpos;
  62. //}
  63. if (_item.srcDocPOLineNo == 0)
  64. {
  65. rtnRcvInfo rtnpo = new rtnRcvInfo();
  66. rtnpo.IsSuccess = false;
  67. rtnpo.Message = "请传入来源单据行号";
  68. rtnpos.Add(rtnpo);
  69. return rtnpos;
  70. }
  71. if (_item.ReqQty == 0)
  72. {
  73. rtnRcvInfo rtnpo = new rtnRcvInfo();
  74. rtnpo.IsSuccess = false;
  75. rtnpo.Message = "传入数量不能为空";
  76. rtnpos.Add(rtnpo);
  77. return rtnpos;
  78. }
  79. //if (string.IsNullOrWhiteSpace(_item.WhCode))
  80. //{
  81. // rtnRcvInfo rtnpo = new rtnRcvInfo();
  82. // rtnpo.IsSuccess = false;
  83. // rtnpo.Message = "传入仓库不能为空";
  84. // rtnpos.Add(rtnpo);
  85. // return rtnpos;
  86. //}
  87. }
  88. }
  89. //给上下文信息赋值
  90. context = CreateContextObj();
  91. //给传入参数赋值
  92. //pOList = SetrCVDtos(rCVInfoList);
  93. StringBuilder strlog = new StringBuilder();
  94. strlog.AppendLine("创建委外收货单");
  95. strlog.AppendLine("*****************************************************");
  96. List<UFIDAU9ISVRCVDTOPOToRcvTransDTOData> rCVList = new List<UFIDAU9ISVRCVDTOPOToRcvTransDTOData>();
  97. foreach (var rCVhead in rCVInfoList)
  98. {
  99. strlog.AppendLine("来源采购订单号:" + rCVhead.srcDocPONo);
  100. foreach (rCVLine line in rCVhead.lines)
  101. {
  102. UFIDAU9ISVRCVDTOPOToRcvTransDTOData rCV = new UFIDAU9ISVRCVDTOPOToRcvTransDTOData();
  103. rCV.m_pONo = rCVhead.srcDocPONo;
  104. rCV.m_pOLineNo = line.srcDocPOLineNo;
  105. rCV.m_businessDate = System.DateTime.Now;
  106. //数量
  107. rCV.m_transQty = new UFIDAU9CBODTOsDoubleQuantityData();
  108. rCV.m_transQty.m_amount1 = line.ReqQty;
  109. rCV.m_transQty.m_amount2 = decimal.Zero;
  110. string sqlWH = @"select Code from CBO_Wh
  111. WHERE Code='" + line.WhCode + "' ";
  112. sqlWH = string.Format(sqlWH);
  113. DataTable _dtWH = DBhlper.Query(sqlWH, Appconfig.GetU9ConnStr());
  114. string WHCode = string.Empty;
  115. if (_dtWH != null && _dtWH.Rows.Count > 0)
  116. {
  117. WHCode = _dtWH.Rows[0][0].ToString();
  118. }
  119. if (string.IsNullOrWhiteSpace(WHCode))
  120. {
  121. rtnRcvInfo rtnpo = new rtnRcvInfo();
  122. rtnpo.IsSuccess = false;
  123. rtnpo.Message = "未获取到仓库";
  124. rtnpos.Add(rtnpo);
  125. return rtnpos;
  126. }
  127. //仓库
  128. rCV.m_rcvLineInfoDTO = new UFIDAU9ISVRCVDTORcvLineInfoDTOData();
  129. rCV.m_rcvLineInfoDTO.m_whCode = WHCode;
  130. string sqlOper = @"select id,a.dept from CBO_Operators a where code='adminck' ";
  131. sqlOper = string.Format(sqlOper);
  132. DataTable _dtOper = DBhlper.Query(sqlOper, Appconfig.GetU9ConnStr());
  133. string operID = string.Empty;
  134. string operDept = string.Empty;
  135. if (_dtOper != null && _dtOper.Rows.Count > 0)
  136. {
  137. operID = _dtOper.Rows[0][0].ToString();
  138. operDept = _dtOper.Rows[0][1].ToString();
  139. rCV.m_rcvLineInfoDTO.WhMan =long.Parse( operID);
  140. rCV.m_rcvLineInfoDTO.m_whManCode = "adminck";
  141. }
  142. //库位
  143. rCV.m_rcvLineInfoDTO.m_lineLocations = new UFIDAU9ISVRCVDTOOBARcvLineLocationDTOData[] { };
  144. List<UFIDAU9ISVRCVDTOOBARcvLineLocationDTOData> locationList = new List<UFIDAU9ISVRCVDTOOBARcvLineLocationDTOData>();
  145. UFIDAU9ISVRCVDTOOBARcvLineLocationDTOData location = new UFIDAU9ISVRCVDTOOBARcvLineLocationDTOData();
  146. location.m_location = new UFIDAU9PMDTOsBESimp4UIDTOData();
  147. location.m_location.m_code = line.BinCode;
  148. //location.m_location.m_iD = long.Parse("");
  149. location.m_locationQtySU = line.ReqQty;
  150. location.m_locationQtyTU = line.ReqQty;
  151. if (!string.IsNullOrWhiteSpace(line.RcvLot))
  152. {
  153. strlog.AppendLine("开始调用创建批号接口------------");
  154. string OrgID = string.Empty;
  155. string OrgIDSQL = "SELECT a.Org FROM PM_PurchaseOrder a where DocNo='" + rCVhead.srcDocPONo + "'";
  156. DataTable dtOrgID = DBhlper.Query(OrgIDSQL, Appconfig.GetU9ConnStr());
  157. if (dtOrgID.Rows.Count > 0)
  158. {
  159. OrgID = dtOrgID.Rows[0][0].ToString();
  160. }
  161. string LotID = "";
  162. //创建批号
  163. //UFIDA.ISV.CreateLotMaster.CustCreateLotMaster createLot = new CreateLotMaster.CustCreateLotMaster();
  164. //UFIDA.ISV.CreateLotMaster.CustCreateLotMaster.LotMaster lot = new CreateLotMaster.CustCreateLotMaster.LotMaster();
  165. //lot.ItemCode = line.ItemCode;
  166. //lot.LotCode = line.RcvLot;
  167. //UFIDA.ISV.CreateLotMaster.CustCreateLotMaster.OperationResule result = createLot.CustCreateRCVLotMaster(lot);
  168. UFIDA.ISV.CreateLotMaster.CustCreateLotMaster LotMasterCreate = new UFIDA.ISV.CreateLotMaster.CustCreateLotMaster();
  169. string lotWHCode = line.WhCode;
  170. string lotItemCode = line.ItemCode;
  171. string LotCode = line.RcvLot;
  172. LotMasterCreate.CustCreateRCVLotMaster(lotWHCode, lotItemCode, LotCode, DateTime.Now, OrgID, ref LotID);
  173. if (LotID == "")
  174. {
  175. rtnRcvInfo rtnpo = new rtnRcvInfo();
  176. rtnpo.IsSuccess = false;
  177. rtnpo.Message = "批号创建失败";
  178. rtnpos.Add(rtnpo);
  179. return rtnpos;
  180. }
  181. if (!string.IsNullOrWhiteSpace(LotID))
  182. {
  183. //rCV.m_rcvLineInfoDTO.m_invLotCode = result.DocNo;
  184. rCV.m_rcvLineInfoDTO.m_invLotCode = LotCode;
  185. strlog.AppendLine("创建批号接口成功------------");
  186. }
  187. else
  188. {
  189. strlog.AppendLine("创建批号接口失败------------");
  190. }
  191. }
  192. //rCV.m_rcvLineInfoDTO.m_invLotCode = line.RcvLot;
  193. locationList.Add(location);
  194. rCV.m_rcvLineInfoDTO.m_lineLocations = locationList.ToArray();
  195. rCVList.Add(rCV);
  196. strlog.AppendLine("来源采购订单行号:" + line.srcDocPOLineNo);
  197. strlog.AppendLine("料品编码:" + line.ItemCode);
  198. strlog.AppendLine("料品数量:" + line.ReqQty);
  199. strlog.AppendLine("仓库:" + WHCode);
  200. strlog.AppendLine("库存批号:" + line.RcvLot);
  201. }
  202. }
  203. pOList = rCVList.ToArray();
  204. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  205. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  206. returnItems = client.Do(out returnMsg, context, pOList, splitBy, true);
  207. if (returnItems != null && returnItems.Length > 0)
  208. {
  209. //获取返回信息得到创建的收货单信息
  210. foreach (EntityKey returnInfo in returnItems)
  211. {
  212. //表头信息
  213. rtnRcvInfo rtnpo = new rtnRcvInfo();
  214. //行信息 服务不返回 sql查询
  215. string sql = @"select A.DocNo as docNo,A1.DocLineNo as docLineNo,A1.ItemInfo_ItemCode,A1.ID as lineID from PM_Receivement A
  216. left join PM_RcvLine A1 on A.ID=A1.Receivement where A.ID='{0}'";
  217. sql = string.Format(sql, returnInfo.ID);
  218. DataTable dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  219. if (dt.Rows.Count > 0)
  220. {
  221. List<rtnRcvLine> pOLines = new List<rtnRcvLine>();
  222. foreach (DataRow dr in dt.Rows)
  223. {
  224. rtnpo.DocNo = dr["docNo"].ToString();
  225. rtnpo.IsSuccess = true;
  226. rtnRcvLine line = new rtnRcvLine();
  227. line.LineNo = int.Parse(dr["docLineNo"].ToString());
  228. pOLines.Add(line);
  229. }
  230. rtnpo.rtnLines = pOLines.ToArray();
  231. }
  232. rtnpos.Add(rtnpo);
  233. }
  234. }
  235. strlog.AppendLine("返回数据:");
  236. foreach (var info in rtnpos)
  237. {
  238. strlog.AppendLine("单号:" + info.DocNo);
  239. strlog.AppendLine("结果:" + info.IsSuccess);
  240. strlog.AppendLine("返回消息:" + info.Message);
  241. foreach (var _line in info.rtnLines)
  242. {
  243. strlog.AppendLine("行号:" + _line.LineNo);
  244. }
  245. }
  246. strlog.AppendLine("*****************************************************");
  247. Appconfig.WriteLogFile(strlog.ToString(), "创建委外收货单");
  248. return rtnpos;
  249. }
  250. catch (Exception ex)
  251. {
  252. //异常信息捕获
  253. List<rtnRcvInfo> rtnpos = new List<rtnRcvInfo>();
  254. rtnRcvInfo rtnpo = new rtnRcvInfo();
  255. rtnpo.IsSuccess = false;
  256. rtnpo.Message = GetExceptionMessage(ex);
  257. rtnpos.Add(rtnpo);
  258. StringBuilder strlog = new StringBuilder();
  259. strlog.AppendLine("创建委外收货单");
  260. strlog.AppendLine("*****************************************************");
  261. foreach (var item in rCVInfoList)
  262. {
  263. strlog.AppendLine("来源采购订单号:" + item.srcDocPONo);
  264. foreach (var line in item.lines)
  265. {
  266. strlog.AppendLine("来源采购订单行号:" + line.srcDocPOLineNo);
  267. strlog.AppendLine("料品编码:" + line.ItemCode);
  268. strlog.AppendLine("料品数量:" + line.ReqQty);
  269. strlog.AppendLine("仓库:" + line.WhCode);
  270. strlog.AppendLine("库存批号:" + line.RcvLot);
  271. }
  272. }
  273. strlog.AppendLine("返回消息:" + rtnpo.Message);
  274. strlog.AppendLine("*****************************************************");
  275. Appconfig.WriteLogFile(strlog.ToString(), "创建委外收货单");
  276. return rtnpos;
  277. }
  278. #endregion
  279. }
  280. #region 表头类
  281. public class rCVhead
  282. {
  283. private rCVLine[] _lines;
  284. private string _srcDocPONo;
  285. private string _DocType;
  286. public rCVLine[] lines
  287. {
  288. get { return _lines; }
  289. set { _lines = value; }
  290. }
  291. /// <summary>
  292. /// 来源采购订单
  293. /// </summary>
  294. public string srcDocPONo
  295. {
  296. get { return _srcDocPONo; }
  297. set { _srcDocPONo = value; }
  298. }
  299. public string DocType
  300. {
  301. get { return _DocType; }
  302. set { _DocType = value; }
  303. }
  304. }
  305. #endregion
  306. #region 表体类
  307. public class rCVLine
  308. {
  309. /// <summary>
  310. /// 数量
  311. /// </summary>
  312. public decimal ReqQty { get; set; }
  313. public string WhCode { get; set; }
  314. public string BinCode { get; set; }
  315. /// <summary>
  316. /// 炉号
  317. /// </summary>
  318. public string FurnaceNo { get; set; }
  319. /// <summary>
  320. /// 来源采购订单料号
  321. /// </summary>
  322. public string ItemCode { get; set; }
  323. /// <summary>
  324. /// 来源采购订单行
  325. /// </summary>
  326. public int srcDocPOLineNo { get; set; }
  327. /// <summary>
  328. /// 库存批号
  329. /// </summary>
  330. public string RcvLot { get; set; }
  331. }
  332. #endregion
  333. #region 提取异常信息
  334. /// <summary>
  335. /// 提取异常信息
  336. /// </summary>
  337. /// <param name="ex"></param>
  338. private string GetExceptionMessage(Exception ex)
  339. {
  340. string faultMessage = "未知错误,请查看ERP日志!";
  341. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  342. if (timeoutEx != null)
  343. {
  344. faultMessage = "访问服务超时,请修改配置信息!";
  345. }
  346. else
  347. {
  348. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  349. if (faultEx == null)
  350. {
  351. faultMessage = ex.Message;
  352. }
  353. else
  354. {
  355. ServiceException serviceEx = faultEx.Detail;
  356. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  357. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  358. {
  359. // 错误信息在faultEx.Message中,请提取,
  360. // 格式为"Fault:料品不能为空,请录入\n 在....."
  361. int startIndex = serviceEx.Message.IndexOf(":");
  362. int endIndex = serviceEx.Message.IndexOf("\n");
  363. if (endIndex == -1)
  364. endIndex = serviceEx.Message.Length;
  365. if (endIndex > 0 && endIndex > startIndex + 1)
  366. {
  367. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  368. }
  369. else
  370. {
  371. faultMessage = serviceEx.Message;
  372. }
  373. }
  374. }
  375. }
  376. return faultMessage;
  377. }
  378. #endregion
  379. #region 给上下文信息赋值
  380. /// <summary>
  381. /// 给上下文信息赋值
  382. /// </summary>
  383. /// <returns></returns>
  384. private ThreadContext CreateContextObj()
  385. {
  386. // 实例化应用上下文对象
  387. ThreadContext thContext = new ThreadContext();
  388. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  389. ns.Add("OrgID", ConfigurationManager.AppSettings["orgID"].ToString());
  390. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  391. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  392. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  393. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  394. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  395. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  396. thContext.nameValueHas = ns;
  397. return thContext;
  398. }
  399. #endregion
  400. #region 时间戳方法
  401. private DateTime TimestampToDateTime(long timestamp)
  402. {
  403. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  404. long lTime = timestamp * 10000000;
  405. TimeSpan nowTimeSpan = new TimeSpan(lTime);
  406. DateTime resultDateTime = dateTimeStart.Add(nowTimeSpan);
  407. return resultDateTime;
  408. }
  409. #endregion
  410. }
  411. #region 上下文类信息
  412. public class contextInfo
  413. {
  414. private long _OrgID;
  415. private string _OrgCode;
  416. private long _UserID;
  417. private string _UserCode;
  418. private DateTime _Datetime;
  419. private string _CultureName;
  420. private string _EnterpriseID;
  421. /// <summary>
  422. /// 组织ID
  423. /// </summary>
  424. public long OrgID
  425. {
  426. get { return _OrgID; }
  427. set { _OrgID = value; }
  428. }
  429. /// <summary>
  430. /// 组织编码
  431. /// </summary>
  432. public string OrgCode
  433. {
  434. get { return _OrgCode; }
  435. set { _OrgCode = value; }
  436. }
  437. /// <summary>
  438. /// 操作员ID
  439. /// </summary>
  440. public long UserID
  441. {
  442. get { return _UserID; }
  443. set { _UserID = value; }
  444. }
  445. /// <summary>
  446. /// 操作员编码
  447. /// </summary>
  448. public string UserCode
  449. {
  450. get { return _UserCode; }
  451. set { _UserCode = value; }
  452. }
  453. /// <summary>
  454. /// 时间
  455. /// </summary>
  456. public DateTime Datetime
  457. {
  458. get { return _Datetime; }
  459. set { _Datetime = value; }
  460. }
  461. /// <summary>
  462. /// 语言
  463. /// </summary>
  464. public string CultureName
  465. {
  466. get { return _CultureName; }
  467. set { _CultureName = value; }
  468. }
  469. /// <summary>
  470. /// 企业ID号
  471. /// </summary>
  472. public string EnterpriseID
  473. {
  474. get { return _EnterpriseID; }
  475. set { _EnterpriseID = value; }
  476. }
  477. public contextInfo()
  478. {
  479. CultureName = "zh-CN";
  480. Datetime = DateTime.Now;
  481. }
  482. }
  483. #endregion
  484. #region 返回信息类
  485. public class rtnRcvInfo
  486. {
  487. public string DocNo { get; set; }
  488. public bool IsSuccess { get; set; }
  489. public string Message { get; set; }
  490. public rtnRcvLine[] rtnLines { get; set; }
  491. }
  492. public class rtnRcvLine
  493. {
  494. public int LineNo { get; set; }
  495. //public string srcDocNo { get; set; }
  496. //public int srcLineNo { get; set; }
  497. //public decimal reqQty { get; set; }
  498. //public string proCode { get; set; }
  499. }
  500. #endregion
  501. #region 表体类
  502. //public class rCVLine
  503. //{
  504. // /// <summary>
  505. // /// 来源采购订单
  506. // /// </summary>
  507. // public string srcDocPONo { get; set; }
  508. // private int _srcDocPOLineNo;
  509. // private decimal _reqQty;
  510. // public string WhCode { get; set; }
  511. // /// <summary>
  512. // /// 炉号
  513. // /// </summary>
  514. // public string FurnaceNo { get; set; }
  515. // /// <summary>
  516. // /// 数量
  517. // /// </summary>
  518. // public decimal ReqQty
  519. // {
  520. // get { return _reqQty; }
  521. // set { _reqQty = value; }
  522. // }
  523. // /// <summary>
  524. // /// 来源采购订单行
  525. // /// </summary>
  526. // public int srcDocPOLineNo
  527. // {
  528. // get { return _srcDocPOLineNo; }
  529. // set { _srcDocPOLineNo = value; }
  530. // }
  531. //}
  532. #endregion
  533. }