BranchProvider.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Winsoft.GOV.Framework.Model;
  8. using Dapper;
  9. namespace Winsoft.GOV.Framework.Provider
  10. {
  11. public class BranchProvider : BaseProvider<Branch>
  12. {
  13. private static BranchProvider instance;
  14. public BranchProvider() : base("gov")
  15. {
  16. }
  17. public static BranchProvider Instance
  18. {
  19. get
  20. {
  21. CreateInstance(ref instance);
  22. return instance;
  23. }
  24. }
  25. public Branch Find(string guid)
  26. {
  27. const string sql = "select * from branch where guid=@guid";
  28. using (IDbConnection connection = GetDbConnection())
  29. {
  30. return connection.QueryFirstOrDefault<Branch>(sql, new { guid = guid});
  31. }
  32. }
  33. public void Insert(Branch b)
  34. {
  35. const string sql = "insert branch(guid, shortname, position) values(@guid, @shortname, @position);";
  36. using (IDbConnection connection = GetDbConnection())
  37. {
  38. connection.Execute(sql, b);
  39. }
  40. }
  41. //public PagedResult<Branch> Select(int pageIndex, int pageSize)
  42. //{
  43. // return null;
  44. //}
  45. public IEnumerable<Branch> FindAll()
  46. {
  47. const string sql = "select * from branch order by position";
  48. using (IDbConnection connection = GetDbConnection())
  49. {
  50. return connection.Query<Branch>(sql);
  51. }
  52. }
  53. public IEnumerable<Branch> FindOnceRunBranch()
  54. {
  55. const string sql = "select ouguid as guid, ql_dep as ShortName from oncerunpowermatters group by ouguid, ql_dep order by ouguid";
  56. using (IDbConnection connection = GetDbConnection())
  57. {
  58. return connection.Query<Branch>(sql);
  59. }
  60. }
  61. public IEnumerable<Branch> FindByApplyType(int type)
  62. {
  63. string sql = "(select QL_DEP as ShortName, OUGUID as guid from PowerMatterType where ApplyCode = @applyCode group by OUGUID, QL_DEP order by ouguid)";
  64. using (IDbConnection connection = GetDbConnection())
  65. {
  66. return connection.Query<Branch>(sql, new { applyCode = type });
  67. }
  68. //if (type > -1 && type < ApplyType.Names.Length)
  69. //{
  70. // string sql = "(select QL_DEP as ShortName, OUGUID as guid from PowerMatterType where ApplyCode = @applyCode group by OUGUID, QL_DEP)";
  71. // using (IDbConnection connection = GetDbConnection())
  72. // {
  73. // return connection.Query<Branch>(sql, new { applyCode = type });
  74. // }
  75. //}
  76. //else
  77. //{
  78. // string sql = "select QL_DEP as ShortName, OUGUID as guid from OnceRunPowerMatters where ql_inner_code not in (select ql_inner_code from PowerMatterType) group by OUGUID, ql_dep";
  79. // using (IDbConnection connection = GetDbConnection())
  80. // {
  81. // return connection.Query<Branch>(sql);
  82. // }
  83. //}
  84. }
  85. }
  86. }