SetDataRepository.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. 
  2. using AutoMapper;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Dtos.System;
  5. using OASystem.Domain.Dtos.UserDto;
  6. using OASystem.Domain.Entities.Financial;
  7. using OASystem.Domain.Entities.Resource;
  8. using OASystem.Domain.Entities.System;
  9. using OASystem.Domain.ViewModels.Groups;
  10. using OASystem.Domain.ViewModels.System;
  11. using OASystem.Infrastructure.Tools;
  12. namespace OASystem.Infrastructure.Repositories.System
  13. {
  14. public class SetDataRepository : BaseRepository<Sys_SetData, SetDataView>
  15. {
  16. private readonly IMapper _mapper;
  17. public SetDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  18. {
  19. _mapper = mapper;
  20. }
  21. /// <summary>
  22. /// 获取所有系统模块
  23. /// </summary>
  24. /// <param name="_SetData"></param>
  25. /// <returns></returns>
  26. public async Task<Result> GetSySDefultModule()
  27. {
  28. Result result = new Result();
  29. string sql = "select * from Sys_SetData where STid = 5 and isdel = 0";
  30. var DBdata = await GetListBySqlWithNolockAsync(sql);
  31. if (DBdata == null || DBdata.Count == 0)
  32. {
  33. return result;
  34. }
  35. result.Data = DBdata.Select(x=> new SetDataView
  36. {
  37. Name = x.Name,
  38. STid = x.STid,
  39. Id = x.Id,
  40. });
  41. result.Code = 0;
  42. result.Msg = "成功!";
  43. return result;
  44. }
  45. /// <summary>
  46. /// 获取类型Data By STId
  47. /// </summary>
  48. /// <param name="_SetData"></param>
  49. /// <returns></returns>
  50. public async Task<Result> GetSetDataBySTId(SetDataRepository _SetData,int stId)
  51. {
  52. Result result = new Result();
  53. string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0",stId);
  54. var DBdata = await _SetData.GetListBySqlWithNolockAsync(sql);
  55. if (DBdata == null || DBdata.Count == 0)
  56. {
  57. return result;
  58. }
  59. result.Data = DBdata.Select(x => new SetDataInfoView
  60. {
  61. Name = x.Name,
  62. Id = x.Id,
  63. Remark = x.Remark,
  64. });
  65. result.Code = 0;
  66. result.Msg = "成功!";
  67. return result;
  68. }
  69. public async Task<Result> GetSetDataAndPageInfoBySTId(int stId = 5)
  70. {
  71. Result result = new Result();
  72. List<SetDataAndPageInfoView> ViewList = _sqlSugar.SqlQueryable<SetDataAndPageInfoView>($@"
  73. select a.id as modulid,a.Name as modulName,a.STid,a.Remark as modulRemark,
  74. b.Id as pageid, b.Name as pageName, b.IsEnable as PageIsEnable ,b.phoneIsEnable as PagePhoneIsEnable,b.SystemMenuCode,b.webUrl,b.androidUrl,
  75. b.iosUrl,b.icon ,b.Remark as PageRemark
  76. from Sys_SetData a , Sys_SystemMenuPermission b where STid = {stId}
  77. and a.isdel = 0 and b.Mid = a.Id and b.IsDel = 0
  78. ").ToList();
  79. result.Data = ViewList;
  80. result.Code = 0;
  81. result.Msg = "成功!";
  82. if (ViewList == null || ViewList.Count == 0)
  83. {
  84. result.Msg = "无数据!";
  85. result.Code = -1;
  86. }
  87. return result;
  88. }
  89. public async Task<Result> QuerySetData(SetDataIDto dto)
  90. {
  91. Result result = new Result() { Code = -2, Msg = "未知错误" };
  92. try
  93. {
  94. string sqlWhere = string.Empty;
  95. if (dto.STid!=0)
  96. {
  97. sqlWhere += string.Format(@" And s2.STid ={0}=", dto.STid);
  98. }
  99. sqlWhere += string.Format(@" And s1.IsDel={0} And s2.IsDel={0}", 0);
  100. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  101. {
  102. Regex r = new Regex("And");
  103. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  104. }
  105. if (dto.PortType == 1)
  106. {
  107. string sql = string.Format(@"select s2.*,s1.Name as 'StName',u.CnName from Sys_setDataType s1 left join Sys_SetData s2 on s1.Id=s2.STid left join Sys_Users u on s2.CreateUserId=u.Id {0}", sqlWhere);
  108. List<SetDataIView> SetData = await _sqlSugar.SqlQueryable<SetDataIView>(sql).ToListAsync();
  109. if (SetData.Count == 0)
  110. {
  111. return result = new Result() { Code = -1, Msg = "暂无数据" };
  112. }
  113. SetData = SetData.OrderByDescending(x => x.CreateTime).ToList();
  114. if (dto.PageSize == 0 && dto.PageIndex == 0)
  115. {
  116. return result = new Result()
  117. {
  118. Code = 0,
  119. Msg = "查询成功",
  120. Data = SetData,
  121. };
  122. }
  123. else
  124. {
  125. int count = SetData.Count;
  126. float totalPage = (float)count / dto.PageSize;//总页数
  127. if (totalPage == 0) totalPage = 1;
  128. else totalPage = (int)Math.Ceiling((double)totalPage);
  129. List<SetDataIView> _SetData = new List<SetDataIView>();
  130. for (int i = 0; i < dto.PageSize; i++)
  131. {
  132. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  133. if (RowIndex < SetData.Count)
  134. {
  135. _SetData.Add(SetData[RowIndex]);
  136. }
  137. else
  138. {
  139. break;
  140. }
  141. }
  142. return result = new Result()
  143. {
  144. Code = 0,
  145. Msg = "查询成功",
  146. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = _SetData },
  147. };
  148. }
  149. }
  150. else if (dto.PortType == 2)
  151. {
  152. string sql = string.Format(@"select s2.*,s1.Name as 'StName' from Sys_setDataType s1 left join Sys_SetData s2 on s1.Id=s2.STid {0}", sqlWhere);
  153. List<SetDataIView> SetData = await _sqlSugar.SqlQueryable<SetDataIView>(sql).ToListAsync();
  154. if (SetData.Count == 0)
  155. {
  156. return result = new Result() { Code = -1, Msg = "暂无数据" };
  157. }
  158. SetData = SetData.OrderByDescending(x => x.CreateTime).ToList();
  159. if (dto.PageSize == 0 && dto.PageIndex == 0)
  160. {
  161. return result = new Result()
  162. {
  163. Code = 0,
  164. Msg = "查询成功",
  165. Data = SetData,
  166. };
  167. }
  168. else
  169. {
  170. int count = SetData.Count;
  171. float totalPage = (float)count / dto.PageSize;//总页数
  172. if (totalPage == 0) totalPage = 1;
  173. else totalPage = (int)Math.Ceiling((double)totalPage);
  174. List<SetDataIView> _SetData = new List<SetDataIView>();
  175. for (int i = 0; i < dto.PageSize; i++)
  176. {
  177. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  178. if (RowIndex < SetData.Count)
  179. {
  180. _SetData.Add(SetData[RowIndex]);
  181. }
  182. else
  183. {
  184. break;
  185. }
  186. }
  187. return result = new Result()
  188. {
  189. Code = 0,
  190. Msg = "查询成功",
  191. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = _SetData },
  192. };
  193. }
  194. }
  195. else
  196. {
  197. return result = new Result() { Code = -2, Msg = "请传入PortType参数!1:Web,2:Android,3:IOS" };
  198. }
  199. }
  200. catch (Exception)
  201. {
  202. return result;
  203. throw;
  204. }
  205. }
  206. public async Task<Result> OperationSetData(OperationSetDataDto dto)
  207. {
  208. Result result = new Result() { Code = -2, Msg = "未知错误" };
  209. try
  210. {
  211. if (dto.Status == 1)//添加
  212. {
  213. string selectSql = string.Format(@"select * from Sys_SetData where Name='{0}' and IsDel='{1}'"
  214. , dto.Name, 0);
  215. var SetData = await _sqlSugar.SqlQueryable<Sys_SetData>(selectSql).FirstAsync();//查询是否存在
  216. if (SetData != null)
  217. {
  218. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  219. }
  220. else//不存在,可添加
  221. {
  222. Sys_SetData _SetData = _mapper.Map<Sys_SetData>(dto);
  223. int id = await AddAsyncReturnId(_SetData);
  224. if (id == 0)
  225. {
  226. return result = new Result() { Code = -1, Msg = "添加失败!" };
  227. }
  228. result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  229. }
  230. }
  231. else if (dto.Status == 2)//修改
  232. {
  233. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Sys_SetData
  234. {
  235. Name = dto.Name,
  236. STid = dto.STid,
  237. Remark = dto.Remark,
  238. });
  239. if (!res)
  240. {
  241. return result = new Result() { Code = -1, Msg = "修改失败!" };
  242. }
  243. result = new Result() { Code = 0, Msg = "修改成功!" };
  244. }
  245. else
  246. {
  247. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  248. }
  249. }
  250. catch (Exception ex)
  251. {
  252. return result = new Result() { Code = -2, Msg = "程序错误!" };
  253. }
  254. return result;
  255. }
  256. public async Task<Result> PostCurrencyByDiid(int diId,int CId, int currencyId)
  257. {
  258. if (diId==0)
  259. {
  260. return new Result() { Code = -1, Msg = "请传入团组Id!" };
  261. }
  262. if (CId == 0)
  263. {
  264. return new Result() { Code = -1, Msg = "请传入类型Id!" };
  265. }
  266. if (currencyId == 0)
  267. {
  268. return new Result() { Code = -1, Msg = "请传入币种Id!" };
  269. }
  270. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == diId && a.IsDel == 0 && a.CTable == CId);
  271. List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
  272. CurrencyInfo CurrencyRate = new CurrencyInfo();
  273. try
  274. {
  275. if (_TeamRate != null)
  276. {
  277. Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == currencyId);
  278. if (_SetData != null)
  279. {
  280. currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
  281. CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
  282. if (CurrencyRate!=null)
  283. {
  284. return new Result() { Code = 0, Msg = "查询成功!", Data = CurrencyRate };
  285. }
  286. else
  287. {
  288. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  289. }
  290. }
  291. else
  292. {
  293. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  294. }
  295. }
  296. else
  297. {
  298. return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
  299. }
  300. }
  301. catch (Exception)
  302. {
  303. return new Result() { Code = -1, Msg = "查询异常!", Data = CurrencyRate };
  304. }
  305. }
  306. }
  307. }