StoreHouseAmountPromissService.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * 分仓额度担保记录
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Main;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Main
  12. {
  13. public class StoreHouseAmountPromissService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. // public StoreHouseAmountPromissService()
  17. // {
  18. // _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  19. // }
  20. /// <summary>
  21. /// 查询列表
  22. /// </summary>
  23. /// <param name="relationData">关联表</param>
  24. /// <param name="condition">查询条件(sql语句)</param>
  25. /// <param name="count">总数(输出)</param>
  26. /// <param name="page">页码</param>
  27. /// <param name="limit">每页条数</param>
  28. /// <returns></returns>
  29. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, out int count, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  30. {
  31. List<string> fields = new List<string>(); //要显示的列
  32. fields.Add("Id");
  33. fields.Add("CreateDate"); //添加时间
  34. fields.Add("Status"); //状态
  35. fields.Add("FromUserId"); //担保人
  36. fields.Add("ToUserId"); //担保对象
  37. fields.Add("PromissAmount"); //担保金额
  38. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("StoreHouseAmountPromiss", relationData, orderBy, page, limit, condition, fields);
  39. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  40. count = int.Parse(obj["count"].ToString());
  41. return diclist;
  42. }
  43. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  44. {
  45. List<string> fields = new List<string>(); //要显示的列
  46. fields.Add("Id");
  47. fields.Add("CreateDate"); //添加时间
  48. fields.Add("Status"); //状态
  49. fields.Add("FromUserId"); //担保人
  50. fields.Add("ToUserId"); //担保对象
  51. fields.Add("PromissAmount"); //担保金额
  52. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("StoreHouseAmountPromiss", relationData, orderBy, page, limit, condition, fields);
  53. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  54. return diclist;
  55. }
  56. /// <summary>
  57. /// 查询一条记录
  58. /// </summary>
  59. /// <param name="Id">主键Id</param>
  60. /// <returns></returns>
  61. public static StoreHouseAmountPromiss Query(int Id)
  62. {
  63. WebCMSEntities db = new WebCMSEntities();
  64. StoreHouseAmountPromiss editData = db.StoreHouseAmountPromiss.FirstOrDefault(m => m.Id == Id) ?? new StoreHouseAmountPromiss();
  65. db.Dispose();
  66. return editData;
  67. }
  68. /// <summary>
  69. /// 通过创客Id查询名下所有有效保证金
  70. /// </summary>
  71. /// <param name="UserId">创客Id</param>
  72. /// <returns></returns>
  73. public static List<int> QueryAmountPromissByUserId(int UserId)
  74. {
  75. WebCMSEntities db = new WebCMSEntities();
  76. List<int> Ids = new List<int>();
  77. var idList = db.StoreHouseAmountPromiss.Where(m => m.Status == 1 && m.ToUserId == UserId).ToList();
  78. foreach (var item in idList)
  79. {
  80. Ids.Add(item.Id);
  81. }
  82. db.Dispose();
  83. return Ids;
  84. }
  85. /// <summary>
  86. /// 通过创客Id查询是否存在
  87. /// </summary>
  88. /// <param name="UserId">创客Id</param>
  89. /// <returns></returns>
  90. public static bool ExistByUserId(int UserId)
  91. {
  92. WebCMSEntities db = new WebCMSEntities();
  93. bool check = db.StoreHouseAmountPromiss.Any(m => m.Status == 1 && m.ToUserId == UserId);
  94. db.Dispose();
  95. return check;
  96. }
  97. /// <summary>
  98. /// 通过创客Id查询担保额度
  99. /// </summary>
  100. /// <param name="UserId">创客Id</param>
  101. /// <returns></returns>
  102. public static decimal SumPromissAmountByUserId(int UserId)
  103. {
  104. WebCMSEntities db = new WebCMSEntities();
  105. decimal PromissAmount = 0;
  106. bool check = db.StoreHouseAmountPromiss.Any(m => m.Status == 1 && m.ToUserId == UserId);
  107. if (check)
  108. {
  109. PromissAmount = db.StoreHouseAmountPromiss.Where(m => m.Status == 1 && m.ToUserId == UserId).Sum(m => m.PromissAmount);
  110. db.Dispose();
  111. }
  112. return PromissAmount;
  113. }
  114. /// <summary>
  115. /// 查询记录数
  116. /// </summary>
  117. /// <param name="Id">主键Id</param>
  118. /// <returns></returns>
  119. public static int Count(string condition = "")
  120. {
  121. int result = 0;
  122. DataTable dt = CustomerSqlConn.dtable("select count(Id) from StoreHouseAmountPromiss where 1=1" + condition, _conn);
  123. if (dt.Rows.Count > 0)
  124. {
  125. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  126. }
  127. return result;
  128. }
  129. /// <summary>
  130. /// 查询是否存在
  131. /// </summary>
  132. /// <param name="Id">主键Id</param>
  133. /// <returns></returns>
  134. public static bool Exist(int Id)
  135. {
  136. WebCMSEntities db = new WebCMSEntities();
  137. bool check = db.StoreHouseAmountPromiss.Any(m => m.Id == Id);
  138. db.Dispose();
  139. return check;
  140. }
  141. /// <summary>
  142. /// 添加数据
  143. /// </summary>
  144. /// <param name="Fields">要设置的字段</param>
  145. /// <returns></returns>
  146. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  147. {
  148. if (check)
  149. {
  150. }
  151. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("StoreHouseAmountPromiss", fields, 0);
  152. return new AppResultJson() { Status = "1", Data = Id };
  153. }
  154. /// <summary>
  155. /// 修改数据
  156. /// </summary>
  157. /// <param name="Fields">要设置的字段</param>
  158. /// <param name="Id">主键Id</param>
  159. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  160. {
  161. if (check)
  162. {
  163. }
  164. new DbService(AppConfig.Base.mainTables, _conn).Edit("StoreHouseAmountPromiss", fields, Id);
  165. return new AppResultJson() { Status = "1", Data = Id };
  166. }
  167. /// <summary>
  168. /// 逻辑删除
  169. /// </summary>
  170. /// <param name="Id">主键Id</param>
  171. public static void Remove(int Id)
  172. {
  173. Dictionary<string, object> fields = new Dictionary<string, object>();
  174. fields.Add("Status", -1);
  175. new DbService(AppConfig.Base.mainTables, _conn).Edit("StoreHouseAmountPromiss", fields, Id);
  176. }
  177. /// <summary>
  178. /// 删除数据
  179. /// </summary>
  180. /// <param name="Id">主键Id</param>
  181. public static void Delete(int Id)
  182. {
  183. new DbService(AppConfig.Base.mainTables, _conn).Delete("StoreHouseAmountPromiss", Id);
  184. }
  185. /// <summary>
  186. /// 排序
  187. /// </summary>
  188. /// <param name="Id">主键Id</param>
  189. /// <param name="Sort">排序序号</param>
  190. public static void Sort(int Id, int Sort)
  191. {
  192. new DbService(AppConfig.Base.mainTables, _conn).Sort("StoreHouseAmountPromiss", Sort, Id);
  193. }
  194. /// <summary>
  195. /// 导入数据
  196. /// </summary>
  197. /// <param name="ExcelData">json数据</param>
  198. public static void Import(string ExcelData)
  199. {
  200. WebCMSEntities db = new WebCMSEntities();
  201. JsonData list = JsonMapper.ToObject(ExcelData);
  202. for (int i = 1; i < list.Count; i++)
  203. {
  204. JsonData dr = list[i];
  205. db.StoreHouseAmountPromiss.Add(new StoreHouseAmountPromiss()
  206. {
  207. CreateDate = DateTime.Now,
  208. UpdateDate = DateTime.Now,
  209. });
  210. db.SaveChanges();
  211. }
  212. db.Dispose();
  213. }
  214. /// <summary>
  215. /// 导出excel表格
  216. /// </summary>
  217. /// <param name="fields">查询条件(单个字段)</param>
  218. /// <param name="condition">查询条件(sql语句)</param>
  219. /// <returns></returns>
  220. // public void ExportExcel(List<RelationData> relationData, string condition)
  221. // {
  222. // }
  223. }
  224. }