dev_HandRepository.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Ropin.Inspection.Model;
  2. using Ropin.Inspection.Model.Entities;
  3. using Ropin.Inspection.Model.SearchModel;
  4. using Ropin.Inspection.Model.ViewModel;
  5. using Ropin.Inspection.Model.ViewModel.DEV;
  6. using Ropin.Inspection.Repository.DEV.Interface;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace Ropin.Inspection.Repository.DEV
  13. {
  14. public class dev_HandRepository : RepositoryBase<TDEV_Hand, Guid>, Idev_HandRepository
  15. {
  16. public dev_HandRepository(InspectionDbContext DbContext) : base(DbContext)
  17. {
  18. }
  19. public Task<IEnumerable<devHandViewModel>> GetConditionAsync(TdevHandSearchModel searchModel)
  20. {
  21. MySqlConnector.MySqlParameter[] parameters = new[] {
  22. new MySqlConnector.MySqlParameter("Status", searchModel.C_Status),
  23. new MySqlConnector.MySqlParameter("name", "%"+searchModel.C_Name+"%"),
  24. new MySqlConnector.MySqlParameter("OrgCode", searchModel.C_OrgCode),
  25. new MySqlConnector.MySqlParameter("StoreCode", searchModel.C_StoreCode),
  26. new MySqlConnector.MySqlParameter("Id ", searchModel.C_ID.ToString())
  27. };
  28. StringBuilder sql = new StringBuilder();
  29. sql.Append("select h.*,g.C_Name as C_OrgName,ifnull(rh.bindCut,0) as bindCut from TDEV_Hand h LEFT JOIN TSYS_Org g on (h.C_OrgCode=g.C_Code) LEFT JOIN TPNT_StoreOrg stororg on (g.C_Code=stororg.C_OrgCode) LEFT JOIN (select C_HandCode,count(C_RoleCode) as bindCut from TSYS_RoleHand group by C_HandCode) rh on (rh.C_HandCode=h.C_ID) where 1=1");
  30. if (!string.IsNullOrEmpty(searchModel.C_Status))
  31. {
  32. sql.Append(" and h.C_Status=@Status ");
  33. }
  34. else
  35. {
  36. sql.Append(" and h.C_Status!='0' ");
  37. }
  38. if (!string.IsNullOrEmpty(searchModel.C_Name))
  39. {
  40. sql.Append(" and h.C_Name like @name");
  41. }
  42. if (!string.IsNullOrEmpty(searchModel.C_OrgCode))
  43. {
  44. sql.Append(" and h.C_OrgCode=@OrgCode ");
  45. }
  46. if (!string.IsNullOrEmpty(searchModel.C_StoreCode))
  47. {
  48. sql.Append(" and stororg.C_StoreCode=@StoreCode ");
  49. }
  50. if (searchModel.C_ID!=Guid.Empty)
  51. {
  52. sql.Append(" and h.C_ID=@Id ");
  53. }
  54. sql.Append(" order by I_Sort ");
  55. IEnumerable<devHandViewModel> recordItemlist = EntityFrameworkCoreExtensions.GetList<devHandViewModel>(DbContext.Database, sql.ToString(), parameters);
  56. searchModel.TotalCount = recordItemlist.First() != null ? recordItemlist.ToList().Count : 0;
  57. return Task.FromResult(searchModel.IsPagination ? recordItemlist.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : recordItemlist);
  58. }
  59. }
  60. }