TaicAIBoxRepository.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Ropin.Inspection.Model;
  2. using Ropin.Inspection.Model.Entities;
  3. using Ropin.Inspection.Model.SearchModel.MTN;
  4. using Ropin.Inspection.Model.ViewModel.MTN;
  5. using Ropin.Inspection.Repository.TAIC.Interface;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace Ropin.Inspection.Repository.TAIC
  12. {
  13. public class TaicAIBoxRepository : RepositoryBase<TaicAibox, string>, ITaicAIBoxRepository
  14. {
  15. public TaicAIBoxRepository(InspectionDbContext dbContext) : base(dbContext)
  16. {
  17. }
  18. public Task<IEnumerable<AiBoxModel>> GetList(AiBoxSearchModel searchModel)
  19. {
  20. MySqlConnector.MySqlParameter[] parameters = new[] {
  21. new MySqlConnector.MySqlParameter("Status", searchModel.CStatus),
  22. new MySqlConnector.MySqlParameter("storeCode", searchModel.CStoreCode),
  23. new MySqlConnector.MySqlParameter("name", "%"+searchModel.Name+"%")
  24. };
  25. StringBuilder sql = new StringBuilder();
  26. sql.Append(@" select * from (
  27. select a.C_ID as CId,
  28. a.C_Name as CName,
  29. a.C_AIBoxNo as CAiboxNo,
  30. a.C_QRCode as CQrcode,
  31. a.C_MachineCode as CMachineCode,
  32. a.D_ProdDate as DProdDate,
  33. a.C_AIBoxTemplateCode as CAIBoxTemplateCode,
  34. t.C_Name as CAIBoxTemplateName,
  35. a.C_StoreCode as CStoreCode,
  36. s.C_Name as CStoreName,
  37. a.C_CfgUrl as CCfgUrl,
  38. a.I_Sort as I_Sort,
  39. a.C_Remark as CRemark,
  40. a.C_CreateBy as CCreateBy,
  41. a.D_CreateOn as DCreateOn,
  42. a.C_LastUpdatedBy as CLastUpdatedBy,
  43. a.D_LastUpdatedOn as DLastUpdatedOn,
  44. a.C_RunStatus as CRunStatus,
  45. a.C_Status as CStatus
  46. from TAIC_AIBox a
  47. LEFT JOIN TPNT_Store s on (a.C_StoreCode=s.C_Code)
  48. LEFT JOIN TAIC_AIBoxTemplate t on (a.C_AIBoxTemplateCode=t.C_ID)
  49. ) tab Where 1=1
  50. ");
  51. if (searchModel.CStatus.HasValue)
  52. {
  53. sql.Append(" AND CStatus=@Status ");
  54. }
  55. if (!string.IsNullOrEmpty(searchModel.CStoreCode))
  56. {
  57. sql.Append(" and CStoreCode=@storeCode ");
  58. }
  59. if (!string.IsNullOrEmpty(searchModel.Name))
  60. {
  61. sql.Append(" and CName like @name ");
  62. }
  63. sql.Append(" order by DCreateOn desc ");
  64. IEnumerable<AiBoxModel> recordItemlist = EntityFrameworkCoreExtensions.GetList<AiBoxModel>(DbContext.Database, sql.ToString(), parameters);
  65. searchModel.TotalCount = recordItemlist.First() != null ? recordItemlist.ToList().Count : 0;
  66. if (searchModel.TotalCount == 0)
  67. {
  68. recordItemlist = new List<AiBoxModel>();
  69. }
  70. return Task.FromResult(searchModel.IsPagination ? recordItemlist.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : recordItemlist);
  71. }
  72. }
  73. }