WmsQaInspectionService.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. using DapperORMCore.Context.DataContext;
  2. using DapperORMCore.Model.CoreModel;
  3. using DapperORMCore.Repository.IRepositorys;
  4. using Microsoft.Extensions.Configuration;
  5. using NXWMS.IService.NXWMS.Inspection;
  6. using NXWMS.Model.AppModels.Condition.Inspection;
  7. using NXWMS.Model.AppModels.Result.Inspection;
  8. using NXWMS.Model.AppModels.Result.Instock;
  9. using NXWMS.Model.Common;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using WestDistance.DapperORM.Repository.Repositorys;
  16. namespace NXWMS.Service.NXWMS.Inspection
  17. {
  18. /// <summary>
  19. /// 质检单服务
  20. /// </summary>
  21. [AutoInject(typeof(IWmsQaInspectionService), InjectType.Scope)]
  22. public class WmsQaInspectionService : ServiceBase, IWmsQaInspectionService
  23. {
  24. #region 全局变量、构造注入
  25. /// <summary>
  26. /// 系统操作仓储中转
  27. /// </summary>
  28. private IDataRepositoryContext _dataContext;
  29. /// <summary>
  30. /// SQL节点仓储
  31. /// </summary>
  32. private ISQLNodeRepository _iSQLNodeRepository;
  33. /// <summary>
  34. /// 配置
  35. /// </summary>
  36. private IConfiguration _configuration;
  37. /// <summary>
  38. /// 构造注入
  39. /// </summary>
  40. /// <param name="dataRepositoryContext"></param>
  41. /// <param name="configuration"></param>
  42. /// <param name="iSQLNodeRepository"></param>
  43. public WmsQaInspectionService(IDataRepositoryContext dataRepositoryContext, IConfiguration configuration, ISQLNodeRepository iSQLNodeRepository)
  44. {
  45. this._dataContext = dataRepositoryContext;
  46. this._configuration = configuration;
  47. this._iSQLNodeRepository = iSQLNodeRepository;
  48. }
  49. #endregion
  50. /// <summary>
  51. /// 分页查询质检单主表数据
  52. /// </summary>
  53. /// <param name="inspectionSearchMd">质检单查询条件实体类对象</param>
  54. /// <returns></returns>
  55. public OperateResultInfo<List<WmsQaInspectionResult>> GetWmsQaInspectionListForPage(WmsQaInspectionSearchMd inspectionSearchMd)
  56. {
  57. try
  58. {
  59. #region SQL语句生成
  60. StringBuilder sqlCondition = new StringBuilder();
  61. if (!string.IsNullOrEmpty(inspectionSearchMd.InspectionNoMsg))
  62. {
  63. sqlCondition.Append($" AND INSPECTION_NO = '{inspectionSearchMd.InspectionNoMsg}'");
  64. }
  65. if (!string.IsNullOrEmpty(inspectionSearchMd.MaterielTypeMsg))
  66. {
  67. sqlCondition.Append($" AND INSPECTION_ID in (SELECT INSPECTION_ID FROM VW_WMS_QA_INSPECTION_DTL WHERE MATERIEL_TYPE_CODE = '{inspectionSearchMd.MaterielTypeMsg}')");
  68. }
  69. if (!string.IsNullOrEmpty(inspectionSearchMd.MaterielMsg))
  70. {
  71. sqlCondition.Append($" AND INSPECTION_ID IN (SELECT INSPECTION_ID FROM VW_WMS_QA_INSPECTION_DTL WHERE MATERIEL_CODE LIKE '%{inspectionSearchMd.MaterielMsg}%' OR MATERIEL_NAME LIKE '%{inspectionSearchMd.MaterielMsg}%' OR MATERIEL_BARCODE LIKE '%{inspectionSearchMd.MaterielMsg}%'");
  72. }
  73. if (!string.IsNullOrEmpty(inspectionSearchMd.InspectionStatusMsg))
  74. {
  75. sqlCondition.Append($" AND INSPECTION_STATUS = '{inspectionSearchMd.InspectionStatusMsg}'");
  76. }
  77. if (!string.IsNullOrEmpty(inspectionSearchMd.InspectionTypeMsg))
  78. {
  79. sqlCondition.Append($" AND INSPECTION_TYPE = '{inspectionSearchMd.InspectionTypeMsg}'");
  80. }
  81. if (!string.IsNullOrEmpty(inspectionSearchMd.InspectionResultMsg))
  82. {
  83. sqlCondition.Append($" AND INSPECTION_ID in (SELECT INSPECTION_ID FROM VW_WMS_QA_INSPECTION_DTL WHERE INSPECTION_RESULT = '{inspectionSearchMd.InspectionResultMsg}')");
  84. }
  85. if (!string.IsNullOrEmpty(inspectionSearchMd.BillNoMsg))
  86. {
  87. sqlCondition.Append($" AND INSPECTION_ID in (SELECT INSPECTION_ID FROM VW_WMS_QA_INSPECTION_DTL WHERE BILL_NO = '{inspectionSearchMd.BillNoMsg}')");
  88. }
  89. if (!string.IsNullOrEmpty(inspectionSearchMd.RegionNoMsg))
  90. {
  91. sqlCondition.Append($" AND INSPECTION_ID in (SELECT INSPECTION_ID FROM VW_WMS_QA_INSPECTION_DTL WHERE REGION_CODE = '{inspectionSearchMd.RegionNoMsg}')");
  92. }
  93. if (!string.IsNullOrEmpty(inspectionSearchMd.BinNoMsg))
  94. {
  95. sqlCondition.Append($" AND INSPECTION_ID in (SELECT INSPECTION_ID FROM VW_WMS_QA_INSPECTION_DTL WHERE BIN_CODE = '{inspectionSearchMd.BinNoMsg}')");
  96. }
  97. if (!string.IsNullOrEmpty(inspectionSearchMd.SupplierMsg))
  98. {
  99. sqlCondition.Append($" AND INSPECTION_ID IN (SELECT INSPECTION_ID FROM VW_WMS_QA_INSPECTION_DTL WHERE SUPPLIER_CODE LIKE '%{inspectionSearchMd.SupplierMsg}%' OR SUPPLIER_NAME LIKE '%{inspectionSearchMd.SupplierMsg}%')");
  100. }
  101. if (!string.IsNullOrEmpty(inspectionSearchMd.StartCreateMsg))
  102. {
  103. sqlCondition.Append($" AND CREATE_TIME >= '{inspectionSearchMd.StartCreateMsg}'");
  104. }
  105. if (!string.IsNullOrEmpty(inspectionSearchMd.EndCreateMsg))
  106. {
  107. sqlCondition.Append($" AND CREATE_TIME <= '{inspectionSearchMd.EndCreateMsg}'");
  108. }
  109. if (!string.IsNullOrEmpty(inspectionSearchMd.StartInspectionTimeMsg))
  110. {
  111. sqlCondition.Append($" AND INSPECTION_TIME >= '{inspectionSearchMd.StartInspectionTimeMsg}'");
  112. }
  113. if (!string.IsNullOrEmpty(inspectionSearchMd.EndInspectionTimeMsg))
  114. {
  115. sqlCondition.Append($" AND INSPECTION_TIME <= '{inspectionSearchMd.EndInspectionTimeMsg}'");
  116. }
  117. StringBuilder sqlCountInspectionData = new StringBuilder($@"SELECT COUNT(1) FROM VW_WMS_QA_INSPECTION WHERE 1=1");
  118. sqlCountInspectionData.Append(sqlCondition.ToString());
  119. int pageStartIndex = (inspectionSearchMd.PageNum - 1) * inspectionSearchMd.EveryPageQty;
  120. int pageEndIndex = inspectionSearchMd.PageNum * inspectionSearchMd.EveryPageQty;
  121. StringBuilder sqlQueryInspectionData = new StringBuilder($@"
  122. SELECT
  123. INSPECTION_ID,
  124. INSPECTION_NO,
  125. INSPECTION_TYPE,
  126. INSPECTION_TYPE_NAME,
  127. INSPECTION_WAY,
  128. INSPECTION_WAY_NAME,
  129. INSPECTION_USER,
  130. INSPECTION_TIME,
  131. INSPECTION_STATUS,
  132. INSPECTION_STATUS_NAME,
  133. DESCRIBE,
  134. CREATE_BY,
  135. CREATE_NAME,
  136. CREATE_TIME,
  137. UPDATE_BY,
  138. UPDATE_NAME,
  139. UPDATE_TIME
  140. FROM
  141. VW_WMS_QA_INSPECTION
  142. WHERE
  143. 1=1
  144. {sqlCondition}
  145. ORDER BY UPDATE_TIME DESC,CREATE_TIME DESC
  146. OFFSET {pageStartIndex} ROWS
  147. FETCH NEXT {inspectionSearchMd.EveryPageQty} ROWS ONLY
  148. ");
  149. #endregion
  150. int dataCount = Convert.ToInt32(new DataRepository<object>(_dataContext).ExecuteScalar(sqlCountInspectionData.ToString()));
  151. List<WmsQaInspectionResult> resultList = new DataRepository<WmsQaInspectionResult>(_dataContext).Query(sqlQueryInspectionData.ToString()).ToList();
  152. OperateResultInfo<List<WmsQaInspectionResult>> retDataMsg = SuccessStatus(resultList);
  153. retDataMsg.DataCount = dataCount;
  154. return retDataMsg;
  155. }
  156. catch (Exception ex)
  157. {
  158. return FailMessageStatus<List<WmsQaInspectionResult>>($"查询质检单数据发生异常,【{ex.Message}】", null);
  159. }
  160. }
  161. /// <summary>
  162. /// 根据质检单主键Id查询质检单明细数据
  163. /// </summary>
  164. /// <param name="wmsQaInspection">质检单实体类对象</param>
  165. /// <returns></returns>
  166. public OperateResultInfo<WmsQaInspectionResult> GetWmsQaInspectionDtlListForID(WmsQaInspectionResult wmsQaInspection)
  167. {
  168. try
  169. {
  170. #region SQL语句生成
  171. string sqlQueryWmsQaInspection = $@"
  172. SELECT
  173. INSPECTION_ID,
  174. INSPECTION_NO,
  175. INSPECTION_TYPE,
  176. INSPECTION_TYPE_NAME,
  177. INSPECTION_WAY,
  178. INSPECTION_WAY_NAME,
  179. INSPECTION_USER,
  180. INSPECTION_TIME,
  181. INSPECTION_STATUS,
  182. INSPECTION_STATUS_NAME,
  183. DESCRIBE,
  184. CREATE_BY,
  185. CREATE_NAME,
  186. CREATE_TIME,
  187. UPDATE_BY,
  188. UPDATE_NAME,
  189. UPDATE_TIME
  190. FROM
  191. VW_WMS_QA_INSPECTION
  192. WHERE
  193. INSPECTION_ID = '{wmsQaInspection.INSPECTION_ID}'
  194. ";
  195. string strWhere = string.Empty;
  196. if (wmsQaInspection.REMARKS1 == "查询已删除明细数据")
  197. {
  198. strWhere = "1=1";
  199. }
  200. else
  201. {
  202. strWhere = "INSPECTION_DTL_STATUS < 99";
  203. }
  204. string sqlQueryWmsInArivalDtl = $@"
  205. SELECT
  206. *
  207. FROM
  208. VW_WMS_QA_INSPECTION_DTL
  209. WHERE
  210. INSPECTION_ID = '{wmsQaInspection.INSPECTION_ID}'
  211. AND {strWhere}
  212. ORDER BY INSPECTION_DTL_STATUS,INSPECTION_DTL_ID
  213. ";
  214. #endregion
  215. List<WmsQaInspectionResult> resultList = new DataRepository<WmsQaInspectionResult>(_dataContext).Query(sqlQueryWmsQaInspection).ToList();
  216. List<WmsQaInspectionDtlResult> resultDtlList = new DataRepository<WmsQaInspectionDtlResult>(_dataContext).Query(sqlQueryWmsInArivalDtl).ToList();
  217. wmsQaInspection = resultList[0];
  218. wmsQaInspection.WmsQaInspectionDtlList = resultDtlList;
  219. OperateResultInfo<WmsQaInspectionResult> retDataMsg = SuccessStatus(wmsQaInspection);
  220. return retDataMsg;
  221. }
  222. catch (Exception ex)
  223. {
  224. return FailMessageStatus<WmsQaInspectionResult>($"查询质检单明细数据发生异常,【{ex.Message}】", null);
  225. }
  226. }
  227. /// <summary>
  228. /// 新增质检单数据
  229. /// </summary>
  230. /// <param name="wmsQaInspection">质检单主表对象</param>
  231. /// <returns></returns>
  232. public OperateResultInfo AddWmsQaInspectionData(WmsQaInspectionResult wmsQaInspection)
  233. {
  234. try
  235. {
  236. #region SQL语句生成
  237. List<string> sqlList = new List<string>();
  238. wmsQaInspection.INSPECTION_ID = Convert.ToInt32(new DataRepository<object>(_dataContext).GetSequenceMsg("Inspection_Id"));
  239. wmsQaInspection.INSPECTION_NO = new DataRepository<object>(_dataContext).GetSequenceMsg("Inspection_No");
  240. wmsQaInspection.INSPECTION_STATUS = 0;
  241. StringBuilder sqlAddWmsQaInspection = new StringBuilder();
  242. string inspectionTime = DateTime.Compare(wmsQaInspection.INSPECTION_TIME, new DateTime()) == 0 ? "NULL" : $"'{wmsQaInspection.INSPECTION_TIME}'";
  243. sqlAddWmsQaInspection.Append($@"
  244. INSERT INTO [WMS_QA_INSPECTION] (
  245. [INSPECTION_ID],
  246. [INSPECTION_NO],
  247. [INSPECTION_TYPE],
  248. [INSPECTION_WAY],
  249. [INSPECTION_USER],
  250. [INSPECTION_TIME],
  251. [INSPECTION_STATUS],
  252. [DESCRIBE],
  253. [CREATE_BY],
  254. [CREATE_TIME],
  255. [UPDATE_BY],
  256. [UPDATE_TIME],
  257. [DATA_VERSION],
  258. [REMARKS1],
  259. [REMARKS2],
  260. [REMARKS3],
  261. [REMARKS4],
  262. [REMARKS5]
  263. )
  264. VALUES
  265. (
  266. '{wmsQaInspection.INSPECTION_ID}',
  267. '{wmsQaInspection.INSPECTION_NO}',
  268. '{wmsQaInspection.INSPECTION_TYPE}',
  269. '{wmsQaInspection.INSPECTION_WAY}',
  270. '{wmsQaInspection.INSPECTION_USER}',
  271. {inspectionTime},
  272. '{wmsQaInspection.INSPECTION_STATUS}',
  273. '{wmsQaInspection.DESCRIBE}',
  274. '{wmsQaInspection.CREATE_BY}',
  275. getdate(),
  276. '{wmsQaInspection.UPDATE_BY}',
  277. getdate(),
  278. 0,
  279. NULL,
  280. NULL,
  281. NULL,
  282. NULL,
  283. NULL
  284. );
  285. ");
  286. sqlList.Add(sqlAddWmsQaInspection.ToString());
  287. foreach (WmsQaInspectionDtlResult item in wmsQaInspection.WmsQaInspectionDtlList)
  288. {
  289. StringBuilder sqlAddWmsQaInspectionDtl = new StringBuilder();
  290. item.INSPECTION_DTL_ID = Convert.ToInt32(new DataRepository<object>(_dataContext).GetSequenceMsg("Inspection_Dtl_Id"));
  291. item.INSPECTION_ID = wmsQaInspection.INSPECTION_ID;
  292. item.INSPECTION_DTL_STATUS = 0;
  293. sqlAddWmsQaInspectionDtl.Append($@"
  294. INSERT INTO [WMS_QA_INSPECTION_DTL] (
  295. [INSPECTION_DTL_ID],
  296. [INSPECTION_ID],
  297. [MATERIEL_CODE],
  298. [MATERIEL_NAME],
  299. [MATERIEL_BARCODE],
  300. [MATERIEL_SPEC],
  301. [PACKAGE_CODE],
  302. [UNIT_CODE],
  303. [BATCH_NO],
  304. [SUPPLIER_CODE],
  305. [SUPPLIER_NAME],
  306. [PRODUCT_DATE],
  307. [EXP_DATE],
  308. [REGION_CODE],
  309. [REGION_NAME],
  310. [BIN_CODE],
  311. [BIN_NAME],
  312. [BILL_NO],
  313. [BILL_DTL_ID],
  314. [TRAY_CODE],
  315. [PALLET_CODE],
  316. [TRAY_DTL_ID],
  317. [INSPECTION_RESULT],
  318. [INSPECTION_DTL_STATUS],
  319. [ITEM_STATUS],
  320. [DESCRIBE],
  321. [CREATE_BY],
  322. [CREATE_TIME],
  323. [UPDATE_BY],
  324. [UPDATE_TIME],
  325. [DATA_VERSION],
  326. [REMARKS1],
  327. [REMARKS2],
  328. [REMARKS3],
  329. [REMARKS4],
  330. [REMARKS5]
  331. )
  332. VALUES
  333. (
  334. '{item.INSPECTION_DTL_ID}',
  335. '{item.INSPECTION_ID}',
  336. '{item.MATERIEL_CODE}',
  337. '{item.MATERIEL_NAME}',
  338. '{item.MATERIEL_BARCODE}',
  339. '{item.MATERIEL_SPEC}',
  340. '{item.PACKAGE_CODE}',
  341. '{item.UNIT_CODE}',
  342. '{item.BATCH_NO}',
  343. '{item.SUPPLIER_CODE}',
  344. '{item.SUPPLIER_NAME}',
  345. '{item.PRODUCT_DATE}',
  346. '{item.EXP_DATE}',
  347. '{item.REGION_CODE}',
  348. '{item.REGION_NAME}',
  349. '{item.BIN_CODE}',
  350. '{item.BIN_NAME}',
  351. '{item.BILL_NO}',
  352. '{item.BILL_DTL_ID}',
  353. '{item.TRAY_CODE}',
  354. '{item.PALLET_CODE}',
  355. '{item.TRAY_DTL_ID}',
  356. '{item.INSPECTION_RESULT}',
  357. '{item.INSPECTION_DTL_STATUS}',
  358. '{item.ITEM_STATUS}',
  359. '{item.DESCRIBE}',
  360. '{item.CREATE_BY}',
  361. getdate(),
  362. '{item.UPDATE_BY}',
  363. getdate(),
  364. '{0}',
  365. NULL,
  366. NULL,
  367. NULL,
  368. NULL,
  369. NULL
  370. );
  371. ");
  372. sqlList.Add(sqlAddWmsQaInspectionDtl.ToString());
  373. }
  374. #endregion
  375. int row = new DataRepository<object>(_dataContext).ExecSqlListTran(sqlList);
  376. if (row > 0)
  377. {
  378. return SuccessMessageStatus("新增质检单数据成功!", row);
  379. }
  380. else
  381. {
  382. return FailMessageStatus("新增质检单数据失败!", row);
  383. }
  384. }
  385. catch (Exception ex)
  386. {
  387. return FailMessageStatus($"新增质检单数据发生异常,【{ex.Message}】");
  388. }
  389. }
  390. /// <summary>
  391. /// 修改质检单数据
  392. /// </summary>
  393. /// <param name="wmsQaInspection">质检单主表对象</param>
  394. /// <returns></returns>
  395. public OperateResultInfo EditWmsQaInspectionData(WmsQaInspectionResult wmsQaInspection)
  396. {
  397. try
  398. {
  399. #region SQL语句生成
  400. List<string> sqlList = new List<string>();
  401. string inspectionTime = DateTime.Compare(wmsQaInspection.INSPECTION_TIME, new DateTime()) == 0 ? "NULL" : $"'{wmsQaInspection.INSPECTION_TIME}'";
  402. string sqlUpdateWmsQaInspection = $@"
  403. UPDATE [WMS_QA_INSPECTION]
  404. SET
  405. [INSPECTION_NO] = '{wmsQaInspection.INSPECTION_NO}',
  406. [INSPECTION_TYPE] = '{wmsQaInspection.INSPECTION_TYPE}',
  407. [INSPECTION_WAY] = '{wmsQaInspection.INSPECTION_WAY}',
  408. [INSPECTION_USER] = '{wmsQaInspection.INSPECTION_USER}',
  409. [INSPECTION_TIME] = {inspectionTime},
  410. [INSPECTION_STATUS] = '{wmsQaInspection.INSPECTION_STATUS}',
  411. [DESCRIBE] = '{wmsQaInspection.DESCRIBE}',
  412. [UPDATE_BY] = '{wmsQaInspection.UPDATE_BY}',
  413. [UPDATE_TIME] = getdate(),
  414. [DATA_VERSION] = [DATA_VERSION] + 1
  415. WHERE
  416. ([INSPECTION_ID] = '{wmsQaInspection.INSPECTION_ID}');
  417. ";
  418. sqlList.Add(sqlUpdateWmsQaInspection);
  419. foreach (WmsQaInspectionDtlResult item in wmsQaInspection.WmsQaInspectionDtlList)
  420. {
  421. if (item.REMARKS1 == "更新" || item.REMARKS1 == "删除")
  422. {
  423. string sqlUpdateWmsQaInspectionDtl = $@"
  424. UPDATE [WMS_QA_INSPECTION_DTL]
  425. SET
  426. [MATERIEL_CODE] = '{item.MATERIEL_CODE}',
  427. [MATERIEL_NAME] = '{item.MATERIEL_NAME}',
  428. [MATERIEL_BARCODE] = '{item.MATERIEL_BARCODE}',
  429. [MATERIEL_SPEC] = '{item.MATERIEL_SPEC}',
  430. [PACKAGE_CODE] = '{item.PACKAGE_CODE}',
  431. [UNIT_CODE] = '{item.UNIT_CODE}',
  432. [BATCH_NO] = '{item.BATCH_NO}',
  433. [SUPPLIER_CODE] = '{item.SUPPLIER_CODE}',
  434. [SUPPLIER_NAME] = '{item.SUPPLIER_NAME}',
  435. [PRODUCT_DATE] = '{item.PRODUCT_DATE}',
  436. [EXP_DATE] = '{item.EXP_DATE}',
  437. [REGION_CODE] = '{item.REGION_CODE}',
  438. [REGION_NAME] = '{item.REGION_NAME}',
  439. [BIN_CODE] = '{item.BIN_CODE}',
  440. [BIN_NAME] = '{item.BIN_NAME}',
  441. [BILL_NO] = '{item.BILL_NO}',
  442. [BILL_DTL_ID] = '{item.BILL_DTL_ID}',
  443. [TRAY_CODE] = '{item.TRAY_CODE}',
  444. [PALLET_CODE] = '{item.PALLET_CODE}',
  445. [TRAY_DTL_ID] = '{item.TRAY_DTL_ID}',
  446. [INSPECTION_RESULT] = '{item.INSPECTION_RESULT}',
  447. [INSPECTION_DTL_STATUS] = '{item.INSPECTION_DTL_STATUS}',
  448. [ITEM_STATUS] = '{item.ITEM_STATUS}',
  449. [DESCRIBE] = '{item.DESCRIBE}',
  450. [UPDATE_BY] = '{item.UPDATE_BY}',
  451. [UPDATE_TIME] = GETDATE(),
  452. [DATA_VERSION] = [DATA_VERSION] + 1
  453. WHERE
  454. ([INSPECTION_DTL_ID] = '{item.INSPECTION_DTL_ID}');
  455. ";
  456. sqlList.Add(sqlUpdateWmsQaInspectionDtl);
  457. }
  458. if (item.REMARKS1 == "添加")
  459. {
  460. StringBuilder sqlAddWmsQaInspectionDtl = new StringBuilder();
  461. item.INSPECTION_DTL_ID = Convert.ToInt32(new DataRepository<object>(_dataContext).GetSequenceMsg("Inspection_Dtl_Id"));
  462. item.INSPECTION_ID = wmsQaInspection.INSPECTION_ID;
  463. item.INSPECTION_DTL_STATUS = 0;
  464. sqlAddWmsQaInspectionDtl.Append($@"
  465. INSERT INTO [WMS_QA_INSPECTION_DTL] (
  466. [INSPECTION_DTL_ID],
  467. [INSPECTION_ID],
  468. [MATERIEL_CODE],
  469. [MATERIEL_NAME],
  470. [MATERIEL_BARCODE],
  471. [MATERIEL_SPEC],
  472. [PACKAGE_CODE],
  473. [UNIT_CODE],
  474. [BATCH_NO],
  475. [SUPPLIER_CODE],
  476. [SUPPLIER_NAME],
  477. [PRODUCT_DATE],
  478. [EXP_DATE],
  479. [REGION_CODE],
  480. [REGION_NAME],
  481. [BIN_CODE],
  482. [BIN_NAME],
  483. [BILL_NO],
  484. [BILL_DTL_ID],
  485. [TRAY_CODE],
  486. [PALLET_CODE],
  487. [TRAY_DTL_ID],
  488. [INSPECTION_RESULT],
  489. [INSPECTION_DTL_STATUS],
  490. [ITEM_STATUS],
  491. [DESCRIBE],
  492. [CREATE_BY],
  493. [CREATE_TIME],
  494. [UPDATE_BY],
  495. [UPDATE_TIME],
  496. [DATA_VERSION],
  497. [REMARKS1],
  498. [REMARKS2],
  499. [REMARKS3],
  500. [REMARKS4],
  501. [REMARKS5]
  502. )
  503. VALUES
  504. (
  505. '{item.INSPECTION_DTL_ID}',
  506. '{item.INSPECTION_ID}',
  507. '{item.MATERIEL_CODE}',
  508. '{item.MATERIEL_NAME}',
  509. '{item.MATERIEL_BARCODE}',
  510. '{item.MATERIEL_SPEC}',
  511. '{item.PACKAGE_CODE}',
  512. '{item.UNIT_CODE}',
  513. '{item.BATCH_NO}',
  514. '{item.SUPPLIER_CODE}',
  515. '{item.SUPPLIER_NAME}',
  516. '{item.PRODUCT_DATE}',
  517. '{item.EXP_DATE}',
  518. '{item.REGION_CODE}',
  519. '{item.REGION_NAME}',
  520. '{item.BIN_CODE}',
  521. '{item.BIN_NAME}',
  522. '{item.BILL_NO}',
  523. '{item.BILL_DTL_ID}',
  524. '{item.TRAY_CODE}',
  525. '{item.PALLET_CODE}',
  526. '{item.TRAY_DTL_ID}',
  527. '{item.INSPECTION_RESULT}',
  528. '{item.INSPECTION_DTL_STATUS}',
  529. '{item.ITEM_STATUS}',
  530. '{item.DESCRIBE}',
  531. '{item.CREATE_BY}',
  532. getdate(),
  533. '{item.UPDATE_BY}',
  534. getdate(),
  535. '{0}',
  536. NULL,
  537. NULL,
  538. NULL,
  539. NULL,
  540. NULL
  541. );
  542. ");
  543. sqlList.Add(sqlAddWmsQaInspectionDtl.ToString());
  544. }
  545. }
  546. #endregion
  547. int row = new DataRepository<object>(_dataContext).ExecSqlListTran(sqlList);
  548. if (row > 0)
  549. {
  550. return SuccessMessageStatus("修改质检单数据成功!", row);
  551. }
  552. else
  553. {
  554. return FailMessageStatus("修改质检单数据失败!", row);
  555. }
  556. }
  557. catch (Exception ex)
  558. {
  559. return FailMessageStatus($"修改质检单数据发生异常,【{ex.Message}】");
  560. }
  561. }
  562. /// <summary>
  563. /// 删除质检单数据
  564. /// </summary>
  565. /// <param name="wmsQaInspection">质检单主表对象</param>
  566. /// <returns></returns>
  567. public OperateResultInfo DeleteWmsQaInspectionData(WmsQaInspectionResult wmsQaInspection)
  568. {
  569. try
  570. {
  571. #region SQL语句生成
  572. string[] inspectionIdList = wmsQaInspection.INSPECTION_NO.Split(',');
  573. List<string> sqlList = new List<string>();
  574. foreach (string item in inspectionIdList)
  575. {
  576. string sqlDeleteWmsQaInspection = $@"
  577. UPDATE WMS_QA_INSPECTION
  578. SET INSPECTION_STATUS = '111',
  579. UPDATE_BY = '{wmsQaInspection.UPDATE_BY}',
  580. UPDATE_TIME = GETDATE(),
  581. DATA_VERSION = DATA_VERSION + 1
  582. WHERE
  583. INSPECTION_ID = '{item}';
  584. ";
  585. string sqlDeleteWmsQaInspectionDtl = $@"
  586. UPDATE WMS_QA_INSPECTION_DTL
  587. SET INSPECTION_DTL_STATUS = '111',
  588. UPDATE_BY = '{wmsQaInspection.UPDATE_BY}',
  589. UPDATE_TIME = GETDATE(),
  590. DATA_VERSION = DATA_VERSION + 1
  591. WHERE
  592. INSPECTION_ID = '{item}';
  593. ";
  594. sqlList.Add(sqlDeleteWmsQaInspection);
  595. sqlList.Add(sqlDeleteWmsQaInspectionDtl);
  596. /*
  597. ToDo: 后续增加删除移至历史表中。
  598. */
  599. }
  600. #endregion
  601. int row = new DataRepository<object>(_dataContext).ExecSqlListTran(sqlList);
  602. if (row > 0)
  603. {
  604. return SuccessMessageStatus("删除质检单数据成功!", row);
  605. }
  606. else
  607. {
  608. return FailMessageStatus("删除质检单数据失败!", row);
  609. }
  610. }
  611. catch (Exception ex)
  612. {
  613. return FailMessageStatus($"删除质检单数据发生异常,【{ex.Message}】");
  614. }
  615. }
  616. /// <summary>
  617. /// 质检审核
  618. /// </summary>
  619. /// <param name="wmsQaInspection">质检单主表对象</param>
  620. /// <returns></returns>
  621. public OperateResultInfo QaInspectionExamine(WmsQaInspectionResult wmsQaInspection)
  622. {
  623. try
  624. {
  625. #region SQL语句生成
  626. List<string> sqlList = new List<string>();
  627. string sqlUpdateWmsQaInspection = $@"
  628. UPDATE [WMS_QA_INSPECTION]
  629. SET
  630. [INSPECTION_STATUS] = '{wmsQaInspection.INSPECTION_STATUS}',
  631. [UPDATE_BY] = '{wmsQaInspection.UPDATE_BY}',
  632. [UPDATE_TIME] = getdate(),
  633. [DATA_VERSION] = [DATA_VERSION] + 1
  634. WHERE
  635. ([INSPECTION_ID] = '{wmsQaInspection.INSPECTION_ID}');
  636. ";
  637. sqlList.Add(sqlUpdateWmsQaInspection);
  638. foreach (WmsQaInspectionDtlResult item in wmsQaInspection.WmsQaInspectionDtlList)
  639. {
  640. string sqlUpdateWmsQaInspectionDtl = $@"
  641. UPDATE [WMS_QA_INSPECTION_DTL]
  642. SET
  643. [INSPECTION_RESULT] = '{item.INSPECTION_RESULT}',
  644. [INSPECTION_DTL_STATUS] = '{item.INSPECTION_DTL_STATUS}',
  645. [UPDATE_BY] = '{item.UPDATE_BY}',
  646. [UPDATE_TIME] = GETDATE(),
  647. [DATA_VERSION] = [DATA_VERSION] + 1
  648. WHERE
  649. ([INSPECTION_DTL_ID] = '{item.INSPECTION_DTL_ID}');
  650. ";
  651. sqlList.Add(sqlUpdateWmsQaInspectionDtl);
  652. //string sqlUpdateWmsInReceiptDtl = $@"
  653. // UPDATE WMS_IN_RECEIPT_DTL
  654. // SET INSPECTION_RESULT = '{item.INSPECTION_RESULT}',
  655. // UPDATE_BY = '{item.UPDATE_BY}',
  656. // UPDATE_TIME = GETDATE()
  657. // WHERE
  658. // RECEIPT_DTL_ID = '{item.BILL_DTL_ID}'
  659. // ";
  660. //sqlList.Add(sqlUpdateWmsInReceiptDtl);
  661. string sqlUpdateWmsInReceiptDtl = $@"
  662. UPDATE WMS_IN_ARRIVAL_DTL
  663. SET INSPECTION_RESULT = '{item.INSPECTION_RESULT}',
  664. UPDATE_BY = '{item.UPDATE_BY}',
  665. UPDATE_TIME = GETDATE()
  666. WHERE
  667. ARRIVAL_DTL_ID = '{item.BILL_DTL_ID}'
  668. ";
  669. sqlList.Add(sqlUpdateWmsInReceiptDtl);
  670. }
  671. #endregion
  672. int row = new DataRepository<object>(_dataContext).ExecSqlListTran(sqlList);
  673. if (row > 0)
  674. {
  675. return SuccessMessageStatus("质检审核成功!", row);
  676. }
  677. else
  678. {
  679. return FailMessageStatus("质检审核失败!", row);
  680. }
  681. }
  682. catch (Exception ex)
  683. {
  684. return FailMessageStatus($"质检审核发生异常,【{ex.Message}】");
  685. }
  686. }
  687. }
  688. }