StaffMachineDal.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using DllEapEntity;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. namespace DllEapDal
  9. {
  10. public class StaffMachineDal
  11. {
  12. private IDatabase CurrDb;
  13. public StaffMachineDal(IDatabase db)
  14. {
  15. CurrDb = db;
  16. }
  17. public string GetFilter(string staffCode, ref string errorinfo)
  18. {
  19. using(IDatabase db = DbFactory.Base("ufp"))
  20. {
  21. var sql = $"select * from staff where fcode='{staffCode}'";
  22. var staff = db.FindList<DllUfpEntity.Staff>(sql).FirstOrDefault();
  23. if (staff != null && staff.IsSA == 1)
  24. {
  25. return string.Empty;
  26. }
  27. else
  28. {
  29. sql = $"select b.* from staffrole a left join role b on a.roleid=b.id where a.staffcode='{staffCode}'";
  30. var roles = db.FindList<DllUfpEntity.Role>(sql);
  31. if (roles.Any(c => c.FCode.Contains("SuperAdmin")))
  32. {
  33. return string.Empty;
  34. }
  35. }
  36. }
  37. var ids = CurrDb.FindListForCondition<StaffMachine>($" and StaffCode='{staffCode}'", ref errorinfo)?.Select(c => c.MacId);
  38. string filter = string.Empty;
  39. if (ids != null && ids.Count() > 0)
  40. {
  41. filter = $" and a.id in ({string.Join(",", ids)})";
  42. }
  43. else
  44. {
  45. filter = " and a.id <0";
  46. }
  47. return filter;
  48. }
  49. }
  50. }