TdevDevOpeAccountRepository.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Google.Protobuf.WellKnownTypes;
  2. using Ropin.Inspection.Model;
  3. using Ropin.Inspection.Model.Entities;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace Ropin.Inspection.Repository
  10. {
  11. public class TdevDevOpeAccountRepository : RepositoryBase<TDEV_DevOpeAccount, Guid>, ITdevDevOpeAccountRepository
  12. {
  13. public TdevDevOpeAccountRepository(InspectionDbContext DbContext) : base(DbContext)
  14. {
  15. }
  16. public Task<int> DeleteByDevIdAsync(string devId)
  17. {
  18. MySqlConnector.MySqlParameter[] parameters = new[] { new MySqlConnector.MySqlParameter("devId", devId) };
  19. int result = EntityFrameworkCoreExtensions.ExecuteSqlNoQuery(DbContext.Database, "DELETE from TDEV_DevOpeAccount WHERE C_DevStoreCode = @devId", parameters);
  20. return Task.FromResult(result);
  21. }
  22. public Task<List<DevOpeAccountConfigSelect>> GetDevOpeAccountConfigSelectAsync(TdevDevOpeAccountSearchModel searchModel)
  23. {
  24. MySqlConnector.MySqlParameter[] parameters = new[] {
  25. new MySqlConnector.MySqlParameter("DevStoreCode", searchModel.C_DevStoreCode),
  26. new MySqlConnector.MySqlParameter("Start", searchModel.D_Start?.ToString("yyyy-MM-dd")),
  27. new MySqlConnector.MySqlParameter("End", searchModel.D_End==null?null:searchModel.D_End.Value.AddDays(1).ToString("yyyy-MM-dd")),
  28. };
  29. StringBuilder sql = new StringBuilder();
  30. sql.Append(@"SELECT
  31. t1.C_DevOpeAccountConfigCode AS code,
  32. CONCAT(date_format(MIN(t1.D_CreateOn), '%Y-%m-%d %H:%i'),' 至 ',date_format(MAX(t1.D_CreateOn), '%Y-%m-%d %H:%i')) as name
  33. FROM
  34. TDEV_DevOpeAccount t1
  35. INNER JOIN (
  36. SELECT DISTINCT C_DevOpeAccountConfigCode FROM TDEV_DevOpeAccount
  37. ) t2 ON t1.C_DevOpeAccountConfigCode = t2.C_DevOpeAccountConfigCode
  38. WHERE 1=1
  39. ");
  40. if (!string.IsNullOrEmpty(searchModel.C_DevStoreCode))
  41. {
  42. sql.Append(" and t1.C_DevStoreCode=@DevStoreCode ");
  43. }
  44. if (searchModel.D_Start != null && searchModel.D_End != null)
  45. {
  46. sql.Append(" and LEFT (t1.D_CreateOn,10)>=@Start and LEFT (t1.D_CreateOn,10)<=@End ");
  47. }
  48. sql.Append(@"
  49. GROUP BY t1.C_DevOpeAccountConfigCode
  50. order by t1.D_CreateOn desc ");
  51. var result = EntityFrameworkCoreExtensions.SqlQuery<DevOpeAccountConfigSelect>(DbContext.Database, sql.ToString(), parameters).ToList();
  52. return Task.FromResult(result);
  53. }
  54. }
  55. }