PowerMettersBaseProvider.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Winsoft.GOV.Framework.Model;
  7. using Dapper;
  8. using System.Data;
  9. namespace Winsoft.GOV.Framework.Provider
  10. {
  11. public class PowerMettersBaseProvider : BaseProvider<PowerMattersBase>
  12. {
  13. private static PowerMettersBaseProvider instance;
  14. private static string cols = " `QL_INNER_CODE`, "
  15. + "`QL_NAME` ";
  16. public void CreateTable()
  17. {
  18. string sql = "create table if not exists PowerMattersBase("
  19. + "QL_NAME varchar(200),"
  20. + "QL_INNER_CODE varchar(50),"
  21. + "QL_DEP varchar(50),"
  22. + "OUGUID varchar(50)"
  23. + "); "
  24. + "call add_index('PowerMattersBase', 'index1', 'index1(QL_INNER_CODE, OUGUID)'); "
  25. + "call add_index('PowerMattersBase', 'index2', 'index2(QL_INNER_CODE)'); "
  26. + "call add_index('PowerMattersBase', 'index3', 'index3(OUGUID)'); ";
  27. //+ "call add_index('PowerMattersBase', 'index4', 'index4(QL_NAME)'); ";
  28. using(var con = GetDbConnection())
  29. {
  30. con.Execute(sql);
  31. }
  32. }
  33. public PowerMettersBaseProvider() : base("gov")
  34. {
  35. }
  36. public static PowerMettersBaseProvider Instance
  37. {
  38. get
  39. {
  40. CreateInstance(ref instance);
  41. return instance;
  42. }
  43. }
  44. public void DeleteAll()
  45. {
  46. using (IDbConnection connection = GetDbConnection())
  47. {
  48. connection.Execute("delete from PowerMattersBase");
  49. }
  50. }
  51. public IEnumerable<PowerMattersBase> FindByBranchGUID(string guid)
  52. {
  53. string sql = "select " + cols + " from PowerMattersBase where ouguid=@guid";
  54. using (IDbConnection connection = GetDbConnection())
  55. {
  56. return connection.Query<PowerMattersBase>(sql, new { guid = guid });
  57. }
  58. }
  59. public IEnumerable<PowerMattersBase> Find(string guid, string ql_kind)
  60. {
  61. string sql = "select " + cols + " from powerMettersDetail where OUGUID=@guid and ql_kind = @ql_kind and QL_INNER_CODE in (SELECT QL_INNER_CODE FROM PowerMattersBase WHERE ouguid=@guid)";
  62. using (IDbConnection connection = GetDbConnection())
  63. {
  64. return connection.Query<PowerMattersBase>(sql, new { guid = guid, ql_kind = ql_kind });
  65. }
  66. }
  67. public IEnumerable<PowerMattersBase> Search(string ql_name, int itemIndex, int size)
  68. {
  69. string sql = "select " + cols + " from PowerMattersBase where ql_name like @ql_name";
  70. return GetItemList(sql, itemIndex, size, new { ql_name = "%" + ql_name + "%" });
  71. }
  72. public bool IsExistByQL_INNER_CODE(string ql_inner_code)
  73. {
  74. string sql = "select ouguid from PowerMattersBase where ql_inner_code=@ql_inner_code";
  75. using (IDbConnection connection = GetDbConnection())
  76. {
  77. IEnumerable<string> tmp = connection.Query<string>(sql, new { ql_inner_code = ql_inner_code });
  78. return tmp != null && tmp.Count() > 0;
  79. }
  80. }
  81. public void Insert(IList<PowerMattersBase> list)
  82. {
  83. string select = "select count(*) from PowerMattersBase where QL_INNER_CODE=@QL_INNER_CODE and OUGUID=@OUGUID;";
  84. string update = "update PowerMattersBase set QL_NAME=@QL_NAME, QL_DEP=@QL_DEP where QL_INNER_CODE=@QL_INNER_CODE and OUGUID=@OUGUID;";
  85. string insert = "insert PowerMattersBase(QL_NAME, QL_INNER_CODE, OUGUID, QL_DEP) values(@QL_NAME, @QL_INNER_CODE, @OUGUID, @QL_DEP);";
  86. using (var conn = GetDbConnection())
  87. {
  88. foreach(PowerMattersBase p in list)
  89. {
  90. try
  91. {
  92. //int count = conn.QueryFirstOrDefault<int>(select, p);
  93. //if (count <= 0)
  94. conn.Execute(insert, p);
  95. //else
  96. // conn.Execute(update, p);
  97. }
  98. catch (Exception e)
  99. {
  100. }
  101. }
  102. }
  103. }
  104. public void Update(PowerMattersBase p)
  105. {
  106. //const string sql = "UPDATE `powermettersbase` "
  107. // + "SET "
  108. // + "`QL_MAINITEM_ID` = @QL_MAINITEM_ID, "
  109. // + "`QL_SUBITEM_ID` = @QL_SUBITEM_ID, "
  110. // + "`QL_NAME` = @QL_NAME, "
  111. // + "`QL_KIND` = @QL_KIND, "
  112. // + "`QL_STATE` = @QL_STATE, "
  113. // + "`OUGUID` = @OUGUID, "
  114. // + "`QL_DEP` = @QL_DEP, "
  115. // + "`UPDATE_DATE` = @UPDATE_DATE, "
  116. // + "`APPLYERMIN_COUNT_DESC` = @APPLYERMIN_COUNT_DESC "
  117. // + " WHERE `ROWGUID` = @ROWGUID; ";
  118. //using (IDbConnection connection = GetDbConnection())
  119. //{
  120. // connection.Execute(sql, p);
  121. //}
  122. }
  123. public void Insert(PowerMattersBase p)
  124. {
  125. //string sql = "INSERT INTO `powermettersbase`"
  126. // + "(`ROWGUID`, "
  127. // + "`QL_MAINITEM_ID`, "
  128. // + "`QL_SUBITEM_ID`, "
  129. // + "`QL_NAME`, "
  130. // + "`QL_KIND`, "
  131. // + "`QL_STATE`, "
  132. // + "`OUGUID`, "
  133. // + "`ShortName`, "
  134. // + "`QL_DEP`, "
  135. // + "`UPDATE_DATE`, "
  136. // + "`IsOnceRun`, "
  137. // + "`APPLYERMIN_COUNT_DESC`) "
  138. // + "VALUES"
  139. // + "(@ROWGUID, "
  140. // + "@QL_MAINITEM_ID, "
  141. // + "@QL_SUBITEM_ID, "
  142. // + "@QL_NAME, "
  143. // + "@QL_KIND, "
  144. // + "@QL_STATE, "
  145. // + "@OUGUID, "
  146. // + "@ShortName, "
  147. // + "@QL_DEP, "
  148. // + "@UPDATE_DATE, "
  149. // + "@IsOnceRun, "
  150. // + "@APPLYERMIN_COUNT_DESC); ";
  151. //using (IDbConnection connection = GetDbConnection())
  152. //{
  153. // connection.Execute(sql, p);
  154. //}
  155. }
  156. public bool IsOnceRun(string ql_inner_code)
  157. {
  158. string sql = "select ql_inner_code from oncerunpowermatters where ql_inner_code=@ql_inner_code";
  159. using (IDbConnection connection = GetDbConnection())
  160. {
  161. IEnumerable<string> tmp = connection.Query<string>(sql, new { ql_inner_code = ql_inner_code });
  162. return tmp != null && tmp.Count() > 0;
  163. }
  164. }
  165. }
  166. }