郑州市第一人民医院

DistriWorkOrderEvaluateController.cs 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6. using MadRunFabric.Common;
  7. using Microsoft.AspNetCore.Authorization;
  8. using Microsoft.Extensions.Logging;
  9. using DistributionApi.IRepositories;
  10. using Api.SignToken;
  11. using System.Security.Claims;
  12. using MadRunFabric.Model;
  13. using Microsoft.Extensions.Configuration;
  14. namespace DistributionApi.Controllers
  15. {
  16. /// <summary>
  17. /// 工单评价 - 省三院
  18. /// </summary>
  19. [Authorize]
  20. [ApiVersion("6.0")]
  21. [Route("api/[controller]")]
  22. [Produces("application/json")]
  23. public class DistriWorkOrderEvaluateController : BaseController
  24. {
  25. private readonly ILogger<DistriWorkOrderEvaluateController> _logger;
  26. private readonly IConfiguration _configuration;
  27. private readonly ISys_User_AccountRepository _sys_user_accountRepository;
  28. private readonly ISignTokenService _signTokenService;
  29. private readonly IDistri_Workorder_EvaluateRepository _distri_workorder_evaluaterepository;
  30. private readonly IDistri_GoodsRepository _distri_goodsrepository;
  31. public DistriWorkOrderEvaluateController(
  32. ILogger<DistriWorkOrderEvaluateController> logger,
  33. IConfiguration configuration,
  34. ISys_User_AccountRepository sys_user_accountRepository,
  35. ISignTokenService signTokenService,
  36. IDistri_Workorder_EvaluateRepository distri_workorder_evaluaterepository,
  37. IDistri_GoodsRepository distri_goodsrepository
  38. )
  39. {
  40. _logger = logger;
  41. _configuration = configuration;
  42. _sys_user_accountRepository = sys_user_accountRepository;
  43. _signTokenService = signTokenService;
  44. _distri_workorder_evaluaterepository = distri_workorder_evaluaterepository;
  45. _distri_goodsrepository = distri_goodsrepository;
  46. }
  47. /// <summary>
  48. /// 获取工单评价列表分页 by page
  49. /// </summary>
  50. /// <param name="keyword"></param>
  51. /// <param name="stime"></param>
  52. /// <param name="etime"></param>
  53. /// <param name="pageindex"></param>
  54. /// <param name="pagesize"></param>
  55. /// <returns></returns>
  56. [HttpGet("getlistbypage")]
  57. public IActionResult GetListByPageAsync(string keyword, string projectid, string stime, string etime, int datetype = -1, int pageindex = 1, int pagesize = 10)
  58. {
  59. string usercode = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  60. //var userstr = _signTokenService.GetUserInfoAsync(usercode).Result;
  61. //var userinfo = userstr.ToJObject()["data"].ToString().ToObject<UserInfoModel>();
  62. string allprojectrole = _configuration["allprojectrole"];
  63. var userinfos = _sys_user_accountRepository.GetUserInfo(usercode, allprojectrole);
  64. var userinfo = JsonHelper.JsonToEntity<UserAccountInfoModel>(userinfos.ToJson());
  65. //获取当天、本周、本月、本年、累计时间
  66. if (datetype != -1)
  67. {
  68. GetStartEndTime(datetype, out stime, out etime);
  69. }
  70. //获取数据
  71. int recordCount = 0;
  72. var result = _distri_workorder_evaluaterepository.GetListsByPage(keyword, projectid, userinfo, usercode, stime, etime, pageindex, pagesize, out recordCount);
  73. var obj = new
  74. {
  75. rows = result.ToList(),
  76. total = recordCount
  77. };
  78. return Success("获取成功", obj);
  79. }
  80. /// <summary>
  81. /// 获取当天、本周、本月、本年、累计时间
  82. /// </summary>
  83. /// <param name="datetype"></param>
  84. /// <param name="start"></param>
  85. /// <param name="end"></param>
  86. public void GetStartEndTime(int datetype, out string start, out string end)
  87. {
  88. start = string.Empty;
  89. end = string.Empty;
  90. var datenow = DateTime.Now;
  91. var datestart = datenow;
  92. var dateend = datenow;
  93. switch (datetype)
  94. {
  95. case 0://当天
  96. break;
  97. case 1://本周
  98. int n = (int)datenow.DayOfWeek == 0 ? 7 : (int)datenow.DayOfWeek;
  99. datestart = datenow.AddDays(1 - n);//本周周一
  100. dateend = datestart.AddDays(6);//本周周日
  101. break;
  102. case 2://本月
  103. datestart = datenow.AddDays(1 - datenow.Day); //本月月初
  104. dateend = datestart.AddMonths(1).AddDays(-1); //本月月末
  105. break;
  106. case 3://本年
  107. datestart = new DateTime(datenow.Year, 1, 1); //本年年初
  108. dateend = new DateTime(datenow.Year, 12, 31); //本年年末
  109. break;
  110. case 4://全部
  111. break;
  112. default:
  113. break;
  114. }
  115. if (datetype != 4)
  116. {
  117. start = datestart.ToString("yyyy-MM-dd");
  118. end = dateend.ToString("yyyy-MM-dd");
  119. }
  120. }
  121. /// <summary>
  122. /// 获取工单评价详情
  123. /// </summary>
  124. [HttpGet("getsingle")]
  125. public IActionResult GetSingleAsync(string id)
  126. {
  127. var model = _distri_workorder_evaluaterepository.GetDetails(id);
  128. return Success("获取成功", model);
  129. }
  130. /// <summary>
  131. /// 删除工单评价
  132. /// </summary>
  133. /// <param name="ids"></param>
  134. /// <returns></returns>
  135. [HttpPost("delete")]
  136. public async Task<IActionResult> DeleteAsync(string[] ids)
  137. {
  138. string usercode = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  139. string username = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name).Value;
  140. //使用逻辑删除
  141. var res = 0;
  142. if (ids != null && ids.Length > 0)
  143. {
  144. foreach (var id in ids)
  145. {
  146. var model = await _distri_workorder_evaluaterepository.GetSingle(id);
  147. model.isdelete = 1;
  148. model.deleteby = usercode;
  149. model.deletetime = DateTime.Now;
  150. if (await _distri_workorder_evaluaterepository.UpdateOne(model))
  151. {
  152. res += 1;
  153. }
  154. }
  155. if (res == ids.Length)
  156. return Success("删除成功");
  157. else if (res > 0 && res < ids.Length)
  158. return Error("部分删除失败");
  159. else
  160. return Error("删除失败");
  161. }
  162. else
  163. return Error("请选择要删除的记录");
  164. }
  165. #region 我的工单评价
  166. /// <summary>
  167. /// 获取我的工单评价分页 by page
  168. /// </summary>
  169. /// <param name="keyword"></param>
  170. /// <param name="stime"></param>
  171. /// <param name="etime"></param>
  172. /// <param name="pageindex"></param>
  173. /// <param name="pagesize"></param>
  174. /// <returns></returns>
  175. [HttpGet("getmylistbypage")]
  176. public IActionResult GetMyListByPageAsync(string keyword, string projectid, string stime, string etime, int datetype = -1, int pageindex = 1, int pagesize = 10)
  177. {
  178. string usercode = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  179. //var userstr = _signTokenService.GetUserInfoAsync(usercode).Result;
  180. //var userinfo = userstr.ToJObject()["data"].ToString().ToObject<UserInfoModel>();
  181. string allprojectrole = _configuration["allprojectrole"];
  182. var userinfos = _sys_user_accountRepository.GetUserInfo(usercode, allprojectrole);
  183. var userinfo = JsonHelper.JsonToEntity<UserAccountInfoModel>(userinfos.ToJson());
  184. //获取当天、本周、本月、本年、累计时间
  185. if (datetype != -1)
  186. {
  187. GetStartEndTime(datetype, out stime, out etime);
  188. }
  189. //获取数据
  190. int recordCount = 0;
  191. var result = _distri_workorder_evaluaterepository.GetMyListsByPage(keyword, projectid, userinfo, usercode, stime, etime, pageindex, pagesize, out recordCount);
  192. var obj = new
  193. {
  194. rows = result.ToList(),
  195. total = recordCount
  196. };
  197. return Success("获取成功11", obj);
  198. }
  199. #endregion
  200. }
  201. }