颐和api

FeedbackController.cs 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Claims;
  5. using System.Threading.Tasks;
  6. using MadRunFabric.Common;
  7. using MadRunFabric.Model;
  8. using Microsoft.AspNetCore.Authorization;
  9. using Microsoft.AspNetCore.Mvc;
  10. using Microsoft.Extensions.Logging;
  11. using MongoDB.Driver;
  12. using SignTokenApi.IRepositories;
  13. using SignTokenApi.Model.Input;
  14. namespace SignTokenApi.Controllers
  15. {
  16. /// <summary>
  17. /// 意见反馈
  18. /// </summary>
  19. [Authorize]
  20. [ApiVersion("6.0")]
  21. [Produces("application/json")]
  22. [Route("api/[controller]")]
  23. public class FeedbackController : BaseController
  24. {
  25. private readonly ILogger<FeedbackController> _logger;
  26. private readonly ISys_User_FeedbackRepository _sys_user_feedbackRepository;
  27. private readonly ISys_User_AccountRepository _sys_user_accountRepository;
  28. public FeedbackController(ILogger<FeedbackController> logger, ISys_User_FeedbackRepository sys_user_feedbackRepository, ISys_User_AccountRepository sys_user_accountRepository)
  29. {
  30. _logger = logger;
  31. _sys_user_feedbackRepository = sys_user_feedbackRepository;
  32. _sys_user_accountRepository = sys_user_accountRepository;
  33. }
  34. /// <summary>
  35. /// 获取意见反馈分页
  36. /// </summary>
  37. /// <param name="keyword"></param>
  38. /// <param name="stime"></param>
  39. /// <param name="etime"></param>
  40. /// <param name="pageindex"></param>
  41. /// <param name="pagesize"></param>
  42. /// <returns></returns>
  43. [HttpGet("getlistbypage")]
  44. public async Task<IActionResult> GetListsByPageAsync(string keyword, int apptype, string phone, string stime, string etime, int pageindex = 1, int pagesize = 10)
  45. {
  46. #region 条件信息
  47. ////排序字段
  48. var sort = Builders<Sys_User_Feedback>.Sort.Ascending("sort");
  49. //根据条件查询集合
  50. var listApp = new List<FilterDefinition<Sys_User_Feedback>>();
  51. listApp.Add(Builders<Sys_User_Feedback>.Filter.Eq("isdelete", 0));
  52. if (apptype > 0)
  53. listApp.Add(Builders<Sys_User_Feedback>.Filter.Eq("apptype", apptype));
  54. if (!string.IsNullOrEmpty(phone))
  55. listApp.Add(Builders<Sys_User_Feedback>.Filter.Where(s => s.phone.Contains(phone)));
  56. //模糊查询
  57. if (!string.IsNullOrEmpty(keyword))
  58. listApp.Add(Builders<Sys_User_Feedback>.Filter.Where(s => s.title.Contains(keyword) || s.content.Contains(keyword)));
  59. if (!string.IsNullOrEmpty(stime))
  60. //listApp.Add(Builders<Sys_User_Feedback>.Filter.Where(s => DateTime.Compare(s.createtime, DateTime.Parse(stime + " 00:00:00")) >= 0));
  61. listApp.Add(Builders<Sys_User_Feedback>.Filter.Gte("createtime", DateTime.Parse(stime + " 00:00:00")));
  62. if (!string.IsNullOrEmpty(etime))
  63. //listApp.Add(Builders<Sys_User_Feedback>.Filter.Where(s => DateTime.Compare(s.createtime, DateTime.Parse(etime + " 23:59:59")) <= 0));
  64. listApp.Add(Builders<Sys_User_Feedback>.Filter.Lte("createtime", DateTime.Parse(etime + " 23:59:59")));
  65. #endregion
  66. int recordCount = 0;
  67. var filter = Builders<Sys_User_Feedback>.Filter.And(listApp);
  68. var list = await _sys_user_feedbackRepository.GetByPage(filter, pageindex, pagesize, sort);
  69. var redCount = await _sys_user_feedbackRepository.CountAsync(filter); //获取总数
  70. recordCount = int.Parse(redCount.ToString());
  71. var obj = new
  72. {
  73. rows = list,
  74. total = recordCount,
  75. };
  76. return Success("成功", obj);
  77. }
  78. /// <summary>
  79. /// 获取意见反馈
  80. /// </summary>
  81. /// <param name="id">意见反馈id</param>
  82. /// <returns></returns>
  83. [HttpGet("getdetailes")]
  84. public async Task<IActionResult> GetDetailsAsync(string id)
  85. {
  86. if (string.IsNullOrEmpty(id))
  87. return Error("参数错误");
  88. var model = await _sys_user_feedbackRepository.GetSingle(id);
  89. if (model == null)
  90. {
  91. return Error("获取失败");
  92. }
  93. return Success("获取成功!", model);
  94. }
  95. /// <summary>
  96. /// 添加意见反馈
  97. /// </summary>
  98. /// <param name="input"></param>
  99. /// <returns></returns>
  100. [HttpPost("add")]
  101. public async Task<IActionResult> AddAsync(FeedbackInput input)
  102. {
  103. #region 验证判断
  104. if (string.IsNullOrEmpty(input.content))
  105. return Error("请输入内容");
  106. #endregion
  107. var model = new Sys_User_Feedback();
  108. model.apptype = input.apptype;
  109. model.phone = input.phone;
  110. model.title = input.title;
  111. model.content = input.content;
  112. model.files = input.files;
  113. model.remark = input.remark;
  114. model.createby = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  115. //2018-8-4
  116. var modelu = await _sys_user_accountRepository.GetSingle(p => p.usercode == model.createby);
  117. if (modelu != null)
  118. {
  119. model.createbyname = modelu.username;
  120. }
  121. if (await _sys_user_feedbackRepository.Add(model))
  122. {
  123. return Success("添加成功");
  124. }
  125. else
  126. {
  127. return Error("添加失败");
  128. }
  129. }
  130. /// <summary>
  131. /// 修改意见反馈信息
  132. /// </summary>
  133. [HttpPost("update")]
  134. public async Task<IActionResult> UpdateAsync(FeedbackInput input)
  135. {
  136. #region 验证判断
  137. if (string.IsNullOrEmpty(input.content))
  138. return Error("请输入内容");
  139. #endregion
  140. var model = await _sys_user_feedbackRepository.GetSingle(input.id);
  141. if (model == null)
  142. return Error("操作失败");
  143. model.apptype = input.apptype;
  144. model.phone = input.phone;
  145. model.title = input.title;
  146. model.content = input.content;
  147. model.files = input.files;
  148. model.remark = input.remark;
  149. bool b = await _sys_user_feedbackRepository.Update(model);
  150. if (b)
  151. return Success("修改成功");
  152. return Error("修改失败");
  153. }
  154. /// <summary>
  155. /// 删除意见反馈信息 by ids
  156. /// </summary>
  157. /// <param name="ids"></param>
  158. /// <returns></returns>
  159. [HttpPost("delete")]
  160. public async Task<IActionResult> DeleteAsync(string[] ids)
  161. {
  162. var res = 0;
  163. if (ids != null && ids.Length > 0)
  164. {
  165. foreach (var item in ids)
  166. {
  167. var ml = await _sys_user_feedbackRepository.GetSingle(item);
  168. ml.isdelete = 1;
  169. ml.deletetime = DateTime.Now.ToLocalTime();
  170. ml.deleteby = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  171. if (_sys_user_feedbackRepository.Update(ml).Result)
  172. res += 1;
  173. }
  174. if (res == ids.Length)
  175. return Success("删除成功");
  176. else if (res > 0 && res < ids.Length)
  177. return Error("部分删除失败,请查看后重新操作");
  178. else
  179. return Error("删除失败,请查看后重新操作");
  180. }
  181. else
  182. return Error("请选择要删除的记录");
  183. }
  184. }
  185. }