BasCommon_Dal.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  1. using NX_CommonClassLibrary;
  2. using NX_DbClassLibrary;
  3. using NX_LogClassLibrary;
  4. using NX_ModelClassLibrary.BaseModel;
  5. using NX_ModelClassLibrary.CustomEnum;
  6. using NX_ModelClassLibrary.OpcModel;
  7. using NX_ModelClassLibrary.SysModel;
  8. using NX_ModelClassLibrary.WmsBalance;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Data.SqlClient;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. namespace NX_WcsDal.CommonBusiness
  17. {
  18. public class BasCommon_Dal
  19. {
  20. #region 单例模式
  21. /// <summary>
  22. /// 单例模式对象
  23. /// </summary>
  24. private static BasCommon_Dal _instance = null;
  25. private static readonly object lockObj = new object();
  26. /// <summary>
  27. /// 单例模式方法
  28. /// </summary>
  29. public static BasCommon_Dal Instance
  30. {
  31. get
  32. {
  33. if (_instance == null)
  34. {
  35. lock (lockObj)
  36. {
  37. if (_instance == null)
  38. {
  39. _instance = new BasCommon_Dal();
  40. }
  41. }
  42. }
  43. return _instance;
  44. }
  45. }
  46. #endregion
  47. #region 获取基础配置信息 PLC、设备、设备类型
  48. /// <summary>
  49. /// 获取基础PLC配置信息数据
  50. /// </summary>
  51. /// <returns></returns>
  52. public List<BasWcsPlcMd> GetBasWcsPlcMsg(string regionCode)
  53. {
  54. try
  55. {
  56. string sqlQueryBasWcsPlc = $@"
  57. SELECT
  58. A.PLC_ID,
  59. A.NEWID,
  60. A.REGION_CODE,
  61. A.PLC_CODE,
  62. A.PLC_NAME,
  63. A.CONN_TYPE_CODE,
  64. A.PLC_TYPE_CODE,
  65. A.IP_ADDR,
  66. A.PORT_NO,
  67. A.READ_BLOCK_NO,
  68. A.READ_START_POS,
  69. A.READ_LEN,
  70. A.WRITE_BLOCK_NO,
  71. A.WRITE_START_POS,
  72. A.WRITE_LEN,
  73. A.USED_FLAG,
  74. A.DEL_FLAG,
  75. A.CREATE_BY,
  76. A.CREATE_TIME,
  77. A.UPDATE_BY,
  78. A.UPDATE_TIME,
  79. A.DATA_VERSION,
  80. A.REMARKS1,
  81. A.REMARKS2,
  82. A.REMARKS3,
  83. A.REMARKS4,
  84. A.REMARKS5,
  85. B.USER_CODE CreateCode,
  86. B.USER_NAME CreateName,
  87. C.USER_CODE UpdateCode,
  88. C.USER_NAME UpdateName
  89. FROM
  90. WCS_BAS_PLC A
  91. LEFT JOIN SYS_USER B ON A.CREATE_BY = B.USER_ID
  92. LEFT JOIN SYS_USER C ON A.UPDATE_BY = C.USER_ID
  93. WHERE
  94. A.USED_FLAG = 1
  95. AND A.DEL_FLAG = 0
  96. AND A.REGION_CODE = '{regionCode}'
  97. ";
  98. DataTable dt = LeadDbHelperSQLServer.Query(sqlQueryBasWcsPlc).Tables[0];
  99. if (dt != null && dt.Rows.Count > 0)
  100. {
  101. List<BasWcsPlcMd> retLst = new List<BasWcsPlcMd>();
  102. foreach (DataRow item in dt.Rows)
  103. {
  104. retLst.Add(ColumnToClassPropertyHelper.ColumnToClassProperty<BasWcsPlcMd>(dt.Columns, item));
  105. }
  106. return retLst;
  107. }
  108. else
  109. {
  110. return null;
  111. }
  112. }
  113. catch (Exception ex)
  114. {
  115. LogHelper.WriteLog($"获取基础PLC配置信息数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  116. return null;
  117. }
  118. }
  119. /// <summary>
  120. /// 获取基础设备配置信息数据
  121. /// </summary>
  122. /// <returns></returns>
  123. public List<BasWcsDevMd> GetBasWcsDevMsg(string regionCode)
  124. {
  125. try
  126. {
  127. string sqlQueryBasWcsDev = $@"
  128. SELECT
  129. A.DEV_ID,
  130. A.NEWID,
  131. A.REGION_CODE,
  132. A.DEV_TYPE_CODE,
  133. A.DEV_CODE,
  134. A.DEV_NAME,
  135. A.DEV_PLC_NO,
  136. A.USED_FLAG,
  137. A.DEL_FLAG,
  138. A.CREATE_BY,
  139. B.USER_CODE CreateCode,
  140. B.USER_NAME CreateName,
  141. A.CREATE_TIME,
  142. A.UPDATE_BY,
  143. C.USER_CODE UpdateCode,
  144. C.USER_NAME UpdateName,
  145. A.UPDATE_TIME,
  146. A.DATA_VERSION,
  147. A.REMARKS1,
  148. A.REMARKS2,
  149. A.REMARKS3,
  150. A.REMARKS4,
  151. A.REMARKS5
  152. FROM
  153. WCS_BAS_DEV A
  154. LEFT JOIN SYS_USER B ON A.CREATE_BY = B.USER_ID
  155. LEFT JOIN SYS_USER C ON A.UPDATE_BY = C.USER_ID
  156. WHERE
  157. A.USED_FLAG = 1
  158. AND A.DEL_FLAG = 0
  159. AND A.REGION_CODE = '{regionCode}'
  160. ";
  161. DataTable dt = LeadDbHelperSQLServer.Query(sqlQueryBasWcsDev).Tables[0];
  162. if (dt != null && dt.Rows.Count > 0)
  163. {
  164. List<BasWcsDevMd> retLst = new List<BasWcsDevMd>();
  165. foreach (DataRow item in dt.Rows)
  166. {
  167. retLst.Add(ColumnToClassPropertyHelper.ColumnToClassProperty<BasWcsDevMd>(dt.Columns, item));
  168. }
  169. return retLst;
  170. }
  171. else
  172. {
  173. return null;
  174. }
  175. }
  176. catch (Exception ex)
  177. {
  178. LogHelper.WriteLog($"获取基础设备配置信息数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  179. return null;
  180. }
  181. }
  182. /// <summary>
  183. /// 获取基础设备类型配置信息数据
  184. /// </summary>
  185. /// <returns></returns>
  186. public List<BasWcsDevTypeMd> GetBasWcsDevTypeMsg()
  187. {
  188. try
  189. {
  190. string sqlQueryBasWcsDevType = $@"
  191. SELECT
  192. A.DEV_TYPE_ID,
  193. A.NEWID,
  194. A.DEV_TYPE_CODE,
  195. A.DEV_TYPE_NAME,
  196. A.[DESCRIBE],
  197. A.USED_FLAG,
  198. A.DEL_FLAG,
  199. A.CREATE_BY,
  200. B.USER_CODE CreateCode,
  201. B.USER_NAME CreateName,
  202. A.CREATE_TIME,
  203. A.UPDATE_BY,
  204. C.USER_CODE UpdateCode,
  205. C.USER_NAME UpdateName,
  206. A.UPDATE_TIME,
  207. A.DATA_VERSION,
  208. A.REMARKS1,
  209. A.REMARKS2,
  210. A.REMARKS3,
  211. A.REMARKS4,
  212. A.REMARKS5
  213. FROM
  214. WCS_BAS_DEV_TYPE A
  215. LEFT JOIN SYS_USER B ON A.CREATE_BY = B.USER_ID
  216. LEFT JOIN SYS_USER C ON A.UPDATE_BY = C.USER_ID
  217. WHERE
  218. A.USED_FLAG = 1
  219. AND A.DEL_FLAG = 0
  220. ";
  221. DataTable dt = LeadDbHelperSQLServer.Query(sqlQueryBasWcsDevType).Tables[0];
  222. if (dt != null && dt.Rows.Count > 0)
  223. {
  224. List<BasWcsDevTypeMd> retLst = new List<BasWcsDevTypeMd>();
  225. foreach (DataRow item in dt.Rows)
  226. {
  227. retLst.Add(ColumnToClassPropertyHelper.ColumnToClassProperty<BasWcsDevTypeMd>(dt.Columns, item));
  228. }
  229. return retLst;
  230. }
  231. else
  232. {
  233. return null;
  234. }
  235. }
  236. catch (Exception ex)
  237. {
  238. LogHelper.WriteLog($"获取基础设备类型配置信息数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  239. return null;
  240. }
  241. }
  242. /// <summary>
  243. /// 获取所有OPCItem变量数据
  244. /// </summary>
  245. /// <returns></returns>
  246. public List<WcsOpcItemMd> GetAllWcsOpcItemMsg(string regionCode)
  247. {
  248. try
  249. {
  250. string sqlQueryOpcItem = $@"
  251. SELECT
  252. A.OPC_ITEM_ID,
  253. A.NEWID,
  254. A.OPC_GROUP_CODE,
  255. A.OPC_ITEM_CODE,
  256. A.OPC_ITEM_NAME,
  257. A.OPC_ITEM_DESC,
  258. A.PLC_CODE,
  259. D.PLC_NAME,
  260. A.DEV_CODE,
  261. E.DEV_NAME,
  262. A.OPC_ITEM_TYPE,
  263. F.PLC_ITEM_DATA_TYPE,
  264. A.OPC_ITEM_POS,
  265. A.USED_FLAG,
  266. A.DEL_FLAG,
  267. A.CREATE_BY,
  268. B.USER_CODE CreateCode,
  269. B.USER_NAME CreateName,
  270. A.CREATE_TIME,
  271. A.UPDATE_BY,
  272. C.USER_CODE UpdateCode,
  273. C.USER_NAME UpdateName,
  274. A.UPDATE_TIME,
  275. A.DATA_VERSION,
  276. A.REMARKS1,
  277. A.REMARKS2,
  278. A.REMARKS3,
  279. A.REMARKS4,
  280. A.REMARKS5
  281. FROM
  282. WCS_BAS_OPC_ITEM A
  283. LEFT JOIN SYS_USER B ON A.CREATE_BY = B.USER_ID
  284. LEFT JOIN SYS_USER C ON A.UPDATE_BY = C.USER_ID
  285. left JOIN WCS_BAS_PLC D ON A.PLC_CODE = D.PLC_CODE
  286. LEFT JOIN WCS_BAS_DEV E ON A.DEV_CODE = E.DEV_CODE
  287. LEFT JOIN WCS_MOT_PLC_ITEM F ON A.OPC_ITEM_CODE = F.PLC_ITEM_CODE
  288. AND A.DEV_CODE = F.DEV_CODE
  289. WHERE
  290. A.USED_FLAG = 1
  291. AND A.DEL_FLAG = 0
  292. AND D.REGION_CODE = '{regionCode}'
  293. AND E.REGION_CODE = '{regionCode}'
  294. ";
  295. DataTable dt = LeadDbHelperSQLServer.Query(sqlQueryOpcItem).Tables[0];
  296. if (dt != null && dt.Rows.Count > 0)
  297. {
  298. List<WcsOpcItemMd> retLst = new List<WcsOpcItemMd>();
  299. foreach (DataRow item in dt.Rows)
  300. {
  301. retLst.Add(ColumnToClassPropertyHelper.ColumnToClassProperty<WcsOpcItemMd>(dt.Columns, item));
  302. }
  303. return retLst;
  304. }
  305. else
  306. {
  307. return null;
  308. }
  309. }
  310. catch (Exception ex)
  311. {
  312. LogHelper.WriteLog($"获取所有OPCItem变量数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  313. return null;
  314. }
  315. }
  316. /// <summary>
  317. /// 获取所有配置好的站台信息数据
  318. /// </summary>
  319. /// <returns></returns>
  320. public List<BasWcsLocMd> GetAllWcsLocMsg(string regionCode)
  321. {
  322. try
  323. {
  324. string sqlQueryAllWcsLoc = $@"
  325. SELECT
  326. A.LOC_ID,
  327. A.NEWID,
  328. A.REGION_CODE,
  329. A.LOC_CODE,
  330. A.LOC_NAME,
  331. A.LOC_TYPE_CODE,
  332. A.LOC_EXT_MSG,
  333. A.LOC_BIN_EXT_MSG,
  334. A.VIRTUAL_FLAG,
  335. A.CACHE_FLAG,
  336. A.CACHE_SIZE,
  337. A.USED_FLAG,
  338. A.DEL_FLAG,
  339. A.CREATE_BY,
  340. B.USER_CODE CreateCode,
  341. B.USER_NAME CreateName,
  342. A.CREATE_TIME,
  343. A.UPDATE_BY,
  344. C.USER_CODE UpdateCode,
  345. C.USER_NAME UpdateName,
  346. A.UPDATE_TIME,
  347. A.DATA_VERSION,
  348. A.REMARKS1,
  349. A.REMARKS2,
  350. A.REMARKS3,
  351. A.REMARKS4,
  352. A.REMARKS5
  353. FROM
  354. WCS_BAS_LOC A
  355. LEFT JOIN SYS_USER B ON A.CREATE_BY = B.USER_ID
  356. LEFT JOIN SYS_USER C ON A.UPDATE_BY = C.USER_ID
  357. WHERE
  358. A.USED_FLAG = 1
  359. AND A.DEL_FLAG = 0
  360. AND A.REGION_CODE = '{regionCode}'
  361. ";
  362. DataTable dt = LeadDbHelperSQLServer.Query(sqlQueryAllWcsLoc).Tables[0];
  363. if (dt != null && dt.Rows.Count > 0)
  364. {
  365. List<BasWcsLocMd> retLst = new List<BasWcsLocMd>();
  366. foreach (DataRow item in dt.Rows)
  367. {
  368. BasWcsLocMd tmpMd = ColumnToClassPropertyHelper.ColumnToClassProperty<BasWcsLocMd>(dt.Columns, item);
  369. retLst.Add(tmpMd);
  370. }
  371. return retLst;
  372. }
  373. else
  374. {
  375. return null;
  376. }
  377. }
  378. catch (Exception ex)
  379. {
  380. LogHelper.WriteLog($"获取所有配置好的站台信息数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  381. return null;
  382. }
  383. }
  384. #endregion
  385. #region 获取序列号
  386. /// <summary>
  387. /// 调用存储过程获取序列号
  388. /// </summary>
  389. /// <param name="sqCode">序列号编码</param>
  390. /// <returns></returns>
  391. public string GetSysSequence(string sqCode)
  392. {
  393. try
  394. {
  395. SqlParameter[] pr = { new SqlParameter("@sq_code",SqlDbType.VarChar,100) ,
  396. new SqlParameter("@count",SqlDbType.Int),
  397. new SqlParameter("@out_id",SqlDbType.VarChar,100)
  398. };
  399. pr[0].Direction = ParameterDirection.Input;
  400. pr[0].Value = sqCode;
  401. pr[1].Direction = ParameterDirection.Input;
  402. pr[1].Value = 1;
  403. pr[2].Direction = ParameterDirection.Output;
  404. pr[2].Value = "";
  405. LeadDbHelperSQLServer.RunProcedure("Sys_Proc_Get_Sequences", pr);
  406. return pr[2].Value.ToString();
  407. }
  408. catch (Exception ex)
  409. {
  410. LogHelper.WriteLog($"获取序列号发生异常!【{ex.Message}】", LogTypeEnum.Err);
  411. return null;
  412. }
  413. }
  414. #endregion
  415. public List<BasBarcodeScannerMd> GetBarCodeScannerLst(string regionCode)
  416. {
  417. try
  418. {
  419. string sql = $@"select * from BAS_BARCODE_SCANNER where REGION_CODE = '{regionCode}' and USED_FLAG = 1";
  420. DataTable dt = LeadDbHelperSQLServer.Query(sql).Tables[0];
  421. if (dt != null && dt.Rows.Count > 0)
  422. {
  423. List<BasBarcodeScannerMd> retLst = new List<BasBarcodeScannerMd>();
  424. foreach (DataRow item in dt.Rows)
  425. {
  426. BasBarcodeScannerMd tmpMd = ColumnToClassPropertyHelper.ColumnToClassProperty<BasBarcodeScannerMd>(dt.Columns, item);
  427. retLst.Add(tmpMd);
  428. }
  429. return retLst;
  430. }
  431. else
  432. {
  433. return null;
  434. }
  435. }
  436. catch (Exception ex)
  437. {
  438. LogHelper.WriteLog($"获取库位监控数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  439. return null;
  440. }
  441. }
  442. public List<BasBinMonitorMd> GetBinMonitorData()
  443. {
  444. try
  445. {
  446. string sql = $@"select * from VW_WMS_BALANCE_MONITOR";
  447. DataTable dt = LeadDbHelperSQLServer.Query(sql).Tables[0];
  448. if (dt != null && dt.Rows.Count > 0)
  449. {
  450. List<BasBinMonitorMd> retLst = new List<BasBinMonitorMd>();
  451. foreach (DataRow item in dt.Rows)
  452. {
  453. BasBinMonitorMd tmpMd = ColumnToClassPropertyHelper.ColumnToClassProperty<BasBinMonitorMd>(dt.Columns, item);
  454. retLst.Add(tmpMd);
  455. }
  456. return retLst;
  457. }
  458. else
  459. {
  460. return null;
  461. }
  462. }
  463. catch (Exception ex)
  464. {
  465. LogHelper.WriteLog($"获取库位监控数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  466. return null;
  467. }
  468. }
  469. public WmsTrayMd GetWmsTrayMd(string trayCode)
  470. {
  471. try
  472. {
  473. string sqlWmsTray = $@"select * from VW_WMS_STK_TRAY where TRAY_CODE = '{trayCode}' and TRAY_STATUS < 99";
  474. DataTable dt = LeadDbHelperSQLServer.Query(sqlWmsTray).Tables[0];
  475. if (dt != null && dt.Rows.Count > 0)
  476. {
  477. DataRow item = dt.Rows[0];
  478. WmsTrayMd trayMd = ColumnToClassPropertyHelper.ColumnToClassProperty<WmsTrayMd>(dt.Columns, item);
  479. string sqlWmsTrayDtlExt = $@"select * from VW_WMS_STK_TRAY_DTL_EXT where TRAY_ID = '{trayMd.TrayId}'";
  480. DataTable dtTrayDtlExt = LeadDbHelperSQLServer.Query(sqlWmsTrayDtlExt).Tables[0];
  481. List<WmsTrayDtlExtMd> trayDtlExtLst = new List<WmsTrayDtlExtMd>();
  482. if (dtTrayDtlExt != null && dtTrayDtlExt.Rows.Count > 0)
  483. {
  484. foreach (DataRow drTrayDtlExtMd in dtTrayDtlExt.Rows)
  485. {
  486. WmsTrayDtlExtMd trayDtlExtMd = ColumnToClassPropertyHelper.ColumnToClassProperty<WmsTrayDtlExtMd>(dtTrayDtlExt.Columns, drTrayDtlExtMd);
  487. trayDtlExtLst.Add(trayDtlExtMd);
  488. }
  489. }
  490. string sqlWmsTrayDtl = $@"select * from VW_WMS_STK_TRAY_DTL where TRAY_ID = '{trayMd.TrayId}'";
  491. DataTable dtTrayDtl = LeadDbHelperSQLServer.Query(sqlWmsTrayDtl).Tables[0];
  492. List<WmsTrayDtlMd> trayDtlLst = new List<WmsTrayDtlMd>();
  493. if (dtTrayDtl != null && dtTrayDtl.Rows.Count > 0)
  494. {
  495. foreach (DataRow drTrayDtlMd in dtTrayDtl.Rows)
  496. {
  497. WmsTrayDtlMd trayDtlMd = ColumnToClassPropertyHelper.ColumnToClassProperty<WmsTrayDtlMd>(dtTrayDtl.Columns, drTrayDtlMd);
  498. trayDtlMd.trayDtlExtMd = trayDtlExtLst.Find(x => x.TrayDtlId == trayDtlMd.TrayDtlId);
  499. trayDtlLst.Add(trayDtlMd);
  500. }
  501. }
  502. trayMd.TrayDtls = trayDtlLst;
  503. return trayMd;
  504. }
  505. else
  506. {
  507. return null;
  508. }
  509. }
  510. catch (Exception ex)
  511. {
  512. LogHelper.WriteLog($"获取组盘数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  513. return null;
  514. }
  515. }
  516. public List<BasBinMd> GetEmptyOutSideExtentionBinLst(string regionCode, List<BasShelfMd> shelfLst)
  517. {
  518. try
  519. {
  520. string str = string.Join("','", shelfLst.Select(x => x.ShelfCode));
  521. str = str.Substring(0, str.Length - 2);
  522. string shelfCondition = "('" + str + ")";
  523. string sql = $@"
  524. SELECT
  525. A.*, B.USER_CODE CreateCode,
  526. B.USER_NAME CreateName,
  527. C.USER_CODE UpdateCode,
  528. C.USER_NAME UpdateName
  529. FROM
  530. BAS_BIN A
  531. LEFT JOIN SYS_USER B ON A.CREATE_BY = B.USER_ID
  532. LEFT JOIN SYS_USER C ON A.UPDATE_BY = C.USER_ID
  533. WHERE
  534. A.REGION_CODE = '{regionCode}'
  535. AND A.BIN_TYPE = '3'
  536. AND A.USED_FLAG = '1'
  537. AND A.EXTENSION_IDX = 2 -- 外伸
  538. AND A.BIN_CODE NOT IN (
  539. SELECT
  540. BIN_CODE
  541. FROM
  542. VW_BALANCE_TEMP
  543. )
  544. AND A.EXTENSION_GROUP NOT IN (
  545. SELECT
  546. B.EXTENSION_GROUP
  547. FROM
  548. VW_BALANCE_TEMP A
  549. LEFT JOIN BAS_BIN B ON A.BIN_CODE = B.BIN_CODE
  550. )
  551. AND A.SHELF_CODE IN {shelfCondition}
  552. ORDER BY
  553. A.BIN_LAYER,
  554. A.BIN_COLUMN,
  555. A.BIN_ROW
  556. ";
  557. DataTable dt = LeadDbHelperSQLServer.Query(sql).Tables[0];
  558. if (dt != null && dt.Rows.Count > 0)
  559. {
  560. List<BasBinMd> retLst = new List<BasBinMd>();
  561. foreach (DataRow item in dt.Rows)
  562. {
  563. BasBinMd retMd = ColumnToClassPropertyHelper.ColumnToClassProperty<BasBinMd>(dt.Columns, item);
  564. retLst.Add(retMd);
  565. }
  566. return retLst;
  567. }
  568. else
  569. {
  570. return null;
  571. }
  572. }
  573. catch (Exception ex)
  574. {
  575. LogHelper.WriteLog($"获取空闲的内伸无货的外伸库位数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  576. return null;
  577. }
  578. }
  579. public List<BasShelfMd> GetCrnRelationShelfLst(BasBinMd binMd)
  580. {
  581. try
  582. {
  583. string sql = $@"
  584. SELECT
  585. *
  586. FROM
  587. BAS_SHELF
  588. WHERE
  589. DEV_CODE = (
  590. SELECT
  591. DEV_CODE
  592. FROM
  593. BAS_SHELF
  594. WHERE
  595. SHELF_CODE = '{binMd.ShelfCode}'
  596. )
  597. ";
  598. DataTable dt = LeadDbHelperSQLServer.Query(sql).Tables[0];
  599. if (dt != null && dt.Rows.Count > 0)
  600. {
  601. List<BasShelfMd> retLst = new List<BasShelfMd>();
  602. foreach (DataRow item in dt.Rows)
  603. {
  604. BasShelfMd retMd = ColumnToClassPropertyHelper.ColumnToClassProperty<BasShelfMd>(dt.Columns, item);
  605. retLst.Add(retMd);
  606. }
  607. return retLst;
  608. }
  609. else
  610. {
  611. return null;
  612. }
  613. }
  614. catch (Exception ex)
  615. {
  616. LogHelper.WriteLog($"获取堆垛机关联的货架排数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  617. return null;
  618. }
  619. }
  620. public List<BasBinMd> GetIsGoodsOutSideExtentionBinLst(string regionCode, List<BasShelfMd> shelfLst, string materielCode)
  621. {
  622. try
  623. {
  624. string str = string.Join("','", shelfLst.Select(x => x.ShelfCode));
  625. str = str.Substring(0, str.Length - 2);
  626. string shelfCondition = "('" + str + ")";
  627. string sql = $@"
  628. SELECT
  629. B.*, C.USER_CODE CreateCode,
  630. C.USER_NAME CreateName,
  631. D.USER_CODE UpdateCode,
  632. D.USER_NAME UpdateName
  633. FROM
  634. WMS_STK_BALANCE A
  635. LEFT JOIN BAS_BIN B ON A.BIN_CODE = B.BIN_CODE
  636. LEFT JOIN SYS_USER C ON B.CREATE_BY = C.USER_ID
  637. LEFT JOIN SYS_USER D ON B.UPDATE_BY = D.USER_ID
  638. WHERE
  639. A.TRAY_ID IN (
  640. SELECT
  641. TRAY_ID
  642. FROM
  643. WMS_STK_TRAY_DTL
  644. WHERE
  645. MATERIEL_CODE = '{materielCode}'
  646. AND TRAY_DTL_STATUS < 99
  647. ) -- 如果后续管控批次,管理库存拓展表,在此添加批次条件即可
  648. AND A.BALANCE_STATUS < 99
  649. AND B.EXTENSION_IDX = 2
  650. AND B.REGION_CODE = '{regionCode}'
  651. AND A.REGION_CODE = '{regionCode}'
  652. AND B.SHELF_CODE IN {shelfCondition}
  653. ORDER BY
  654. B.BIN_COLUMN,
  655. B.BIN_LAYER,
  656. B.BIN_ROW
  657. ";
  658. DataTable dt = LeadDbHelperSQLServer.Query(sql).Tables[0];
  659. if (dt != null && dt.Rows.Count > 0)
  660. {
  661. List<BasBinMd> retLst = new List<BasBinMd>();
  662. foreach (DataRow item in dt.Rows)
  663. {
  664. BasBinMd retMd = ColumnToClassPropertyHelper.ColumnToClassProperty<BasBinMd>(dt.Columns, item);
  665. retLst.Add(retMd);
  666. }
  667. return retLst;
  668. }
  669. else
  670. {
  671. return null;
  672. }
  673. }
  674. catch (Exception ex)
  675. {
  676. LogHelper.WriteLog($"获取同一个商品已分配的外伸库位数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  677. return null;
  678. }
  679. }
  680. public List<BasBinMd> GetEmptyIntroversionBinLst(string regionCode, List<BasShelfMd> shelfLst)
  681. {
  682. try
  683. {
  684. string str = string.Join("','", shelfLst.Select(x => x.ShelfCode));
  685. str = str.Substring(0, str.Length - 2);
  686. string shelfCondition = "('" + str + ")";
  687. string sql = $@"
  688. SELECT
  689. A.*, B.USER_CODE CreateCode,
  690. B.USER_NAME CreateName,
  691. C.USER_CODE UpdateCode,
  692. C.USER_NAME UpdateName
  693. FROM
  694. BAS_BIN A
  695. LEFT JOIN SYS_USER B ON A.CREATE_BY = B.USER_ID
  696. LEFT JOIN SYS_USER C ON A.UPDATE_BY = C.USER_ID
  697. WHERE
  698. A.REGION_CODE = '{regionCode}'
  699. AND A.BIN_TYPE = '3'
  700. AND A.USED_FLAG = '1'
  701. AND A.EXTENSION_IDX = 1 -- 内伸
  702. AND A.BIN_CODE NOT IN (
  703. SELECT
  704. BIN_CODE
  705. FROM
  706. VW_BALANCE_TEMP
  707. WHERE
  708. REGION_CODE = '{regionCode}'
  709. )
  710. AND A.SHELF_CODE IN {shelfCondition}
  711. ORDER BY
  712. A.BIN_COLUMN,
  713. A.BIN_LAYER,
  714. A.BIN_ROW
  715. ";
  716. DataTable dt = LeadDbHelperSQLServer.Query(sql).Tables[0];
  717. if (dt != null && dt.Rows.Count > 0)
  718. {
  719. List<BasBinMd> retLst = new List<BasBinMd>();
  720. foreach (DataRow item in dt.Rows)
  721. {
  722. BasBinMd retMd = ColumnToClassPropertyHelper.ColumnToClassProperty<BasBinMd>(dt.Columns, item);
  723. retLst.Add(retMd);
  724. }
  725. return retLst;
  726. }
  727. else
  728. {
  729. return null;
  730. }
  731. }
  732. catch (Exception ex)
  733. {
  734. LogHelper.WriteLog($"获取空闲的内伸库位发生异常!【{ex.Message}】", LogTypeEnum.Err);
  735. return null;
  736. }
  737. }
  738. public BasBinMd GetEmptyBinMd(string regionCode, List<BasShelfMd> shelfLst)
  739. {
  740. try
  741. {
  742. string str = string.Join("','", shelfLst.Select(x => x.ShelfCode));
  743. str = str.Substring(0, str.Length - 2);
  744. string shelfCondition = "('" + str + ")";
  745. string sqlQueryEmptyBin = $@"
  746. SELECT
  747. TOP 1 A.*, B.USER_CODE CreateCode,
  748. B.USER_NAME CreateName,
  749. C.USER_CODE UpdateCode,
  750. C.USER_NAME UpdateName
  751. FROM
  752. BAS_BIN A
  753. LEFT JOIN SYS_USER B ON A.CREATE_BY = B.USER_ID
  754. LEFT JOIN SYS_USER C ON A.UPDATE_BY = C.USER_ID
  755. WHERE
  756. A.USED_FLAG = 1
  757. AND A.DEL_FLAG = 0
  758. AND A.BIN_CODE NOT IN (
  759. SELECT
  760. BIN_CODE
  761. FROM
  762. WMS_STK_BALANCE
  763. WHERE
  764. BALANCE_STATUS < 99
  765. AND REGION_CODE = '{regionCode}'
  766. )
  767. AND A.SHELF_CODE IN {shelfCondition}
  768. AND A.REGION_CODE = '{regionCode}'
  769. ORDER BY
  770. A.BIN_COLUMN,
  771. A.BIN_LAYER,
  772. A.BIN_ROW
  773. ";
  774. DataTable dt = LeadDbHelperSQLServer.Query(sqlQueryEmptyBin).Tables[0];
  775. if (dt != null && dt.Rows.Count > 0)
  776. {
  777. DataRow item = dt.Rows[0];
  778. BasBinMd retMd = ColumnToClassPropertyHelper.ColumnToClassProperty<BasBinMd>(dt.Columns, item);
  779. return retMd;
  780. }
  781. else
  782. {
  783. return null;
  784. }
  785. }
  786. catch (Exception ex)
  787. {
  788. LogHelper.WriteLog($"获取库区:【{regionCode}】的空闲库位发生异常!【{ex.Message}】", LogTypeEnum.Err);
  789. return null;
  790. }
  791. }
  792. public List<WcsOpcItemMonitorMd> GetOpcItemMonitorData(string devTypeCode)
  793. {
  794. try
  795. {
  796. string sql = $@"SELECT A.*,B.DEV_NAME FROM WCS_MOT_PLC_ITEM A LEFT JOIN WCS_BAS_DEV B ON A.DEV_CODE = B.DEV_CODE LEFT JOIN WCS_BAS_DEV_TYPE C ON B.DEV_TYPE_CODE = C.DEV_TYPE_CODE WHERE B.DEV_TYPE_CODE = '{devTypeCode}'";
  797. DataTable dt = LeadDbHelperSQLServer.Query(sql).Tables[0];
  798. if (dt != null && dt.Rows.Count > 0)
  799. {
  800. List<WcsOpcItemMonitorMd> retLst = new List<WcsOpcItemMonitorMd>();
  801. foreach (DataRow item in dt.Rows)
  802. {
  803. WcsOpcItemMonitorMd tmpMd = ColumnToClassPropertyHelper.ColumnToClassProperty<WcsOpcItemMonitorMd>(dt.Columns, item);
  804. retLst.Add(tmpMd);
  805. }
  806. return retLst;
  807. }
  808. else
  809. {
  810. return null;
  811. }
  812. }
  813. catch (Exception ex)
  814. {
  815. LogHelper.WriteLog($"获取OPC变量监控数据发生异常!【{ex.Message}】", LogTypeEnum.Err);
  816. return null;
  817. }
  818. }
  819. private readonly object thLock = new object();
  820. public void UpdateOpcItemMonitorToDataBase(WcsOpcItemMd wcsOpcItemMd)
  821. {
  822. lock (thLock)
  823. {
  824. try
  825. {
  826. string sql = $@"update WCS_MOT_PLC_ITEM set PLC_ITEM_VALUE = '{wcsOpcItemMd.OpcItemValue}' where DEV_CODE = '{wcsOpcItemMd.DevCode}' and PLC_ITEM_CODE = '{wcsOpcItemMd.OpcItemCode}'";
  827. LeadDbHelperSQLServer.ExecuteSql(sql);
  828. }
  829. catch (Exception ex)
  830. {
  831. LogHelper.WriteLog($"OPC变量监控实时数据更新到数据库发生异常!【{ex.Message}】", LogTypeEnum.Err);
  832. }
  833. }
  834. }
  835. public List<SysParameterMd> GetWcsParameterLst(SysParameterSearchMd searchMd)
  836. {
  837. try
  838. {
  839. string sqlQuery = string.Empty;
  840. if (!string.IsNullOrEmpty(searchMd.ParameterMsg))
  841. {
  842. sqlQuery += $" AND (A.PARAMETER_CODE like '%{searchMd.ParameterMsg}%' or A.PARAMETER_NAME like '%{searchMd.ParameterMsg}%')";
  843. }
  844. if (!string.IsNullOrEmpty(searchMd.ParameterValue))
  845. {
  846. sqlQuery += $" AND A.PARAMETER_VALUE = '{searchMd.ParameterValue}'";
  847. }
  848. if (!string.IsNullOrEmpty(searchMd.ParameterEditFlag))
  849. {
  850. sqlQuery += $" AND A.ALLOW_EDIT_FLAG = '{searchMd.ParameterEditFlag}'";
  851. }
  852. string sql = $@"
  853. SELECT
  854. A.*, B.USER_CODE CreateCode,
  855. B.USER_NAME CreateName,
  856. C.USER_CODE UpdateCode,
  857. C.USER_NAME UpdateName
  858. FROM
  859. SYS_PARAMETER A
  860. LEFT JOIN SYS_USER B ON A.CREATE_BY = B.USER_ID
  861. LEFT JOIN SYS_USER C ON A.UPDATE_BY = C.USER_ID
  862. WHERE
  863. 1 = 1 AND PARAMETER_TYPE = 'WCS'
  864. {sqlQuery}
  865. ";
  866. DataTable dt = LeadDbHelperSQLServer.Query(sql).Tables[0];
  867. if (dt != null && dt.Rows.Count > 0)
  868. {
  869. List<SysParameterMd> retLst = new List<SysParameterMd>();
  870. foreach (DataRow item in dt.Rows)
  871. {
  872. retLst.Add(ColumnToClassPropertyHelper.ColumnToClassProperty<SysParameterMd>(dt.Columns, item));
  873. }
  874. return retLst;
  875. }
  876. else
  877. {
  878. return null;
  879. }
  880. }
  881. catch (Exception ex)
  882. {
  883. LogHelper.WriteLog($"获取WCS参数信息发生异常!【{ex.Message}】", LogTypeEnum.Err);
  884. return null;
  885. }
  886. }
  887. public SysParameterMd GetWcsParameterMd(string paramId)
  888. {
  889. try
  890. {
  891. string sql = $@"
  892. SELECT
  893. A.*, B.USER_CODE CreateCode,
  894. B.USER_NAME CreateName,
  895. C.USER_CODE UpdateCode,
  896. C.USER_NAME UpdateName
  897. FROM
  898. SYS_PARAMETER A
  899. LEFT JOIN SYS_USER B ON A.CREATE_BY = B.USER_ID
  900. LEFT JOIN SYS_USER C ON A.UPDATE_BY = C.USER_ID
  901. WHERE
  902. PARAMETER_ID = '{paramId}'
  903. ";
  904. DataTable dt = LeadDbHelperSQLServer.Query(sql).Tables[0];
  905. if (dt != null && dt.Rows.Count > 0)
  906. {
  907. DataRow item = dt.Rows[0];
  908. return ColumnToClassPropertyHelper.ColumnToClassProperty<SysParameterMd>(dt.Columns, item);
  909. }
  910. else
  911. {
  912. return null;
  913. }
  914. }
  915. catch (Exception ex)
  916. {
  917. LogHelper.WriteLog($"获取WCS参数信息发生异常!【{ex.Message}】", LogTypeEnum.Err);
  918. return null;
  919. }
  920. }
  921. public int EditParamMsg(SysParameterMd paramMd)
  922. {
  923. try
  924. {
  925. string sql = $@"update SYS_PARAMETER set PARAMETER_NAME = '{paramMd.ParameterName}',PARAMETER_VALUE = '{paramMd.ParameterValue}',UPDATE_TIME = getdate(),DATA_VERSION = DATA_VERSION + 1 where PARAMETER_ID = '{paramMd.ParameterId}'";
  926. return LeadDbHelperSQLServer.ExecuteSql(sql);
  927. }
  928. catch (Exception ex)
  929. {
  930. LogHelper.WriteLog($"编辑WCS参数信息发生异常!【{ex.Message}】", LogTypeEnum.Err);
  931. return 0;
  932. }
  933. }
  934. public List<BasDevAlarmMd> GetDevAlarmMsg(BasDevAlarmSearchMd searchMd)
  935. {
  936. try
  937. {
  938. string sqlQuery = string.Empty;
  939. if (!string.IsNullOrEmpty(searchMd.DevTypeMsg))
  940. {
  941. sqlQuery += $" AND C.DEV_TYPE_CODE = '{searchMd.DevTypeMsg}'";
  942. }
  943. if (!string.IsNullOrEmpty(searchMd.DevMsg))
  944. {
  945. sqlQuery += $" AND B.DEV_CODE = '{searchMd.DevMsg}'";
  946. }
  947. if (!string.IsNullOrEmpty(searchMd.FaultMsg))
  948. {
  949. sqlQuery += $" AND (A.FAULT_NO like '%{searchMd.FaultMsg}%' OR A.FAULT_DESC like '%{searchMd.FaultMsg}%')";
  950. }
  951. if (!string.IsNullOrEmpty(searchMd.StartFaultTime))
  952. {
  953. sqlQuery += $" AND A.FAULT_TIME >= '{searchMd.StartFaultTime}'";
  954. }
  955. if (!string.IsNullOrEmpty(searchMd.EndFaultTime))
  956. {
  957. sqlQuery += $" AND A.FAULT_TIME <= '{searchMd.EndFaultTime}'";
  958. }
  959. int pageStartIndex = (searchMd.PageNum - 1) * searchMd.EveryPageQty;
  960. int pageEndIndex = searchMd.PageNum * searchMd.EveryPageQty;
  961. string sql = $@"
  962. SELECT
  963. A.LOG_FAULT_ID,
  964. C.DEV_TYPE_NAME,
  965. B.DEV_NAME,
  966. A.FAULT_NO,
  967. A.FAULT_DESC,
  968. A.FAULT_TIME,
  969. A.WARING_STATUS,
  970. A.END_TIME
  971. FROM
  972. WMS_LOG_FAULT_MSG A
  973. LEFT JOIN WCS_BAS_DEV B ON A.FAULT_DEV_CODE = B.DEV_CODE
  974. LEFT JOIN WCS_BAS_DEV_TYPE C ON B.DEV_TYPE_CODE = C.DEV_TYPE_CODE
  975. WHERE
  976. 1 = 1
  977. {sqlQuery}
  978. ORDER BY A.UPDATE_TIME DESC,A.CREATE_TIME DESC
  979. OFFSET {pageStartIndex} ROWS
  980. FETCH NEXT {searchMd.EveryPageQty} ROWS ONLY
  981. ";
  982. DataTable dt = LeadDbHelperSQLServer.Query(sql).Tables[0];
  983. if (dt != null && dt.Rows.Count > 0)
  984. {
  985. List<BasDevAlarmMd> retLst = new List<BasDevAlarmMd>();
  986. foreach (DataRow item in dt.Rows)
  987. {
  988. retLst.Add(ColumnToClassPropertyHelper.ColumnToClassProperty<BasDevAlarmMd>(dt.Columns, item));
  989. }
  990. return retLst;
  991. }
  992. else
  993. {
  994. return null;
  995. }
  996. }
  997. catch (Exception ex)
  998. {
  999. LogHelper.WriteLog($"获取设备报警信息发生异常!【{ex.Message}】", LogTypeEnum.Err);
  1000. return null;
  1001. }
  1002. }
  1003. public List<BasFaultMd> GetBasFaultMsg()
  1004. {
  1005. try
  1006. {
  1007. string sql = $@"
  1008. SELECT
  1009. A.FAULT_ID,
  1010. A.NEWID,
  1011. A.FAULT_CODE,
  1012. A.FAULT_NAME,
  1013. A.DEV_TYPE_CODE,
  1014. A.[DESCRIBE],
  1015. A.USED_FLAG,
  1016. A.DEL_FLAG,
  1017. A.CREATE_BY,
  1018. B.USER_CODE CreateCode,
  1019. B.USER_NAME CreateName,
  1020. A.CREATE_TIME,
  1021. A.UPDATE_BY,
  1022. C.USER_CODE UpdateCode,
  1023. C.USER_NAME UpdateName,
  1024. A.UPDATE_TIME,
  1025. A.DATA_VERSION,
  1026. A.REMARKS1,
  1027. A.REMARKS2,
  1028. A.REMARKS3,
  1029. A.REMARKS4,
  1030. A.REMARKS5
  1031. FROM
  1032. BAS_FAULT A
  1033. LEFT JOIN SYS_USER B ON A.CREATE_BY = B.USER_ID
  1034. LEFT JOIN SYS_USER C ON A.UPDATE_BY = C.USER_ID
  1035. WHERE
  1036. A.USED_FLAG = 1
  1037. AND A.DEL_FLAG = 0
  1038. ";
  1039. DataTable dt = LeadDbHelperSQLServer.Query(sql).Tables[0];
  1040. if (dt != null && dt.Rows.Count > 0)
  1041. {
  1042. List<BasFaultMd> retLst = new List<BasFaultMd>();
  1043. foreach (DataRow item in dt.Rows)
  1044. {
  1045. retLst.Add(ColumnToClassPropertyHelper.ColumnToClassProperty<BasFaultMd>(dt.Columns, item));
  1046. }
  1047. return retLst;
  1048. }
  1049. else
  1050. {
  1051. return null;
  1052. }
  1053. }
  1054. catch (Exception ex)
  1055. {
  1056. LogHelper.WriteLog($"获取基础报警代码信息发生异常!【{ex.Message}】", LogTypeEnum.Err);
  1057. return null;
  1058. }
  1059. }
  1060. }
  1061. }