足力健后端,使用.netcore版本,合并1个项目使用

TodoManagementController.cs 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Common;
  4. using System.Common.Helpers;
  5. using System.Data;
  6. using System.IRepositories;
  7. using System.Linq;
  8. using System.Model;
  9. using System.Security.Claims;
  10. using System.Threading.Tasks;
  11. using Microsoft.AspNetCore.Mvc;
  12. using SqlSugar;
  13. namespace TVShoppingCallCenter_ZLJ.Controllers.ManagementCenter
  14. {
  15. [Produces("application/json")]
  16. [Route("api/[controller]")]
  17. public class TodoManagementController : BaseController
  18. {
  19. private readonly ISys_TodoManagementRepository _sys_todomanagementrepository;
  20. private readonly ISMS_InternalMessagesReposytory _sys_internalMessagesrepository;
  21. private readonly ISys_UserAccountRepository _sys_useraccountRepository;
  22. public TodoManagementController(ISys_TodoManagementRepository sys_todomanagementrepository, ISys_UserAccountRepository sys_useraccountRepository, ISMS_InternalMessagesReposytory sys_internalMessagesrepository)
  23. {
  24. _sys_todomanagementrepository = sys_todomanagementrepository;
  25. _sys_useraccountRepository = sys_useraccountRepository;
  26. _sys_internalMessagesrepository = sys_internalMessagesrepository;
  27. }
  28. /// <summary>
  29. /// 添加待办
  30. /// </summary>
  31. /// <param name="input"></param>
  32. /// <returns></returns>
  33. [HttpPost("add")]
  34. public async Task<IActionResult> AddAsync(T_Sys_TodoManagement input)
  35. {
  36. if (input.F_Type < 0)
  37. return Error("请选择待办类型");
  38. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  39. input.F_CreateTime = DateTime.Now;
  40. input.F_CreateUser = user;
  41. input.F_IsDelete = 0;
  42. string title = "", count = "";
  43. if (input.F_Type == 0)
  44. {
  45. title = "日程提醒";
  46. count = input.F_Content;
  47. }
  48. else
  49. {
  50. title = "待联系人提醒";
  51. count = "待联系人"+ input.F_PeopleName ;
  52. }
  53. var res = await _sys_todomanagementrepository.Add(input);
  54. if (res > 0)
  55. {
  56. if (input .F_IsRemind >0)
  57. {
  58. try
  59. {
  60. bool n = new InternalMessages.InternalMessagesController(_sys_internalMessagesrepository, _sys_useraccountRepository).AddInternalMessagesInfo(res, title, count, user, DateTime.Parse(input.F_Remindertime.ToString()), 3, 1, 0, user, 1);
  61. }
  62. catch
  63. {
  64. }
  65. }
  66. return Success("添加成功");
  67. }
  68. else
  69. {
  70. return Error("添加失败");
  71. }
  72. }
  73. /// <summary>
  74. /// 修改待办
  75. /// </summary>
  76. [HttpPost("update")]
  77. public async Task<IActionResult> UpdateAsync(T_Sys_TodoManagement input)
  78. {
  79. if (input.F_ID <= 0)
  80. return Error("参数错误");
  81. if (input.F_Type < 0)
  82. return Error("请选择待办类型");
  83. var model = await _sys_todomanagementrepository.GetSingle(x => x.F_ID == input.F_ID);
  84. if (model == null)
  85. return Error("操作失败");
  86. // string user = "8000";
  87. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  88. input.F_IsDelete = 0;
  89. input.F_CreateUser = model.F_CreateUser;
  90. input.F_CreateTime = model.F_CreateTime;
  91. input.F_UpdateTime = DateTime.Now;
  92. input.F_UpdateUser = user;
  93. string title = "", count = "";
  94. if (input.F_Type == 0)
  95. {
  96. title = "日程提醒";
  97. count = input.F_Content;
  98. }
  99. else
  100. {
  101. title = "待联系人提醒";
  102. count = "待联系人" + input.F_PeopleName;
  103. }
  104. // model.F_UpdateUser = "8000";
  105. var b = await _sys_todomanagementrepository.Update(input);
  106. if (b)
  107. {
  108. if (input.F_IsRemind > 0)
  109. {
  110. try
  111. {
  112. var InternalMessages = _sys_internalMessagesrepository.GetListALL(x => x.F_ID == model.F_ID && x.SMS_IsDelete == 0).Result.FirstOrDefault();
  113. if (InternalMessages != null)
  114. {
  115. InternalMessages.SMS_Title = title;
  116. InternalMessages.SMS_Content = count;
  117. InternalMessages.SMS_Remindertime = input.F_Remindertime;
  118. InternalMessages.SMS_ReceiveUserCode = user;
  119. bool n = await _sys_internalMessagesrepository.Update(InternalMessages);
  120. }
  121. else
  122. {
  123. bool n = new InternalMessages.InternalMessagesController(_sys_internalMessagesrepository, _sys_useraccountRepository).AddInternalMessagesInfo(model.F_ID, title, count, user, DateTime.Parse(input.F_Remindertime.ToString()), 3, 1, 0, user, 1);
  124. }
  125. }
  126. catch
  127. {
  128. }
  129. }
  130. return Success("修改成功");
  131. }
  132. return Error("修改失败");
  133. }
  134. /// <summary>
  135. /// 删除待办
  136. /// </summary>
  137. /// <param name="ids"></param>
  138. /// <returns></returns>
  139. [HttpPost("delete")]
  140. public async Task<IActionResult> Remove(int[] ids)
  141. {
  142. var res = 0;
  143. if (ids != null && ids.Length > 0)
  144. {
  145. foreach (var item in ids)
  146. {
  147. var model = await _sys_todomanagementrepository.GetSingle(x => x.F_ID == item);
  148. var message = await _sys_internalMessagesrepository.GetListALL (x => x.F_ID == item);
  149. if (message!=null )
  150. {
  151. foreach (var it in message)
  152. {
  153. it .SMS_IsDelete = (int)EnumUserCountState.Delete;
  154. var n= _sys_internalMessagesrepository.Update(it);
  155. }
  156. }
  157. model.F_IsDelete = (int)EnumUserCountState.Delete;
  158. model.F_DeleteTime = DateTime.Now.ToLocalTime();
  159. model.F_DeleteUser = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  160. if (_sys_todomanagementrepository.Update(model).Result)
  161. res += 1;
  162. }
  163. if (res == ids.Length)
  164. return Success("删除成功");
  165. else if (res > 0 && res < ids.Length)
  166. return Error("部分删除失败,请查看后重新操作");
  167. else
  168. return Error("删除失败,请查看后重新操作");
  169. }
  170. else
  171. return Error("请选择要删除的记录");
  172. }
  173. /// <summary>
  174. /// 操作待办
  175. /// </summary>
  176. /// <param name="id">id</param>
  177. /// <returns></returns>
  178. [HttpPost("operation")]
  179. public async Task<IActionResult> GetOperationAsync(int[] ids, int state)
  180. {
  181. var res = 0;
  182. if (ids != null && ids.Length > 0)
  183. {
  184. foreach (var item in ids)
  185. {
  186. var model = await _sys_todomanagementrepository.GetSingle(x => x.F_ID == item);
  187. model.F_State = state;
  188. if (_sys_todomanagementrepository.Update(model).Result)
  189. res += 1;
  190. }
  191. if (res == ids.Length)
  192. return Success("操作成功");
  193. else if (res > 0 && res < ids.Length)
  194. return Error("部分操作败,请查看后重新操作");
  195. else
  196. return Error("操作失败,请查看后重新操作");
  197. }
  198. else
  199. return Error("请选择要操作的记录");
  200. }
  201. /// <summary>
  202. /// 获取待办列表
  203. /// </summary>
  204. /// <param name="keyword"></param>
  205. /// <param name="pageindex"></param>
  206. /// <param name="pagesize"></param>
  207. /// <returns></returns>
  208. [HttpGet("getlist")]
  209. public async Task<IActionResult> GetListMark(string keyword,int state=-1, int type = -1, int pageindex = 1, int pagesize = 20)
  210. {
  211. List<IConditionalModel> conModels = new List<IConditionalModel>();
  212. #region 条件筛选
  213. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
  214. if (!string.IsNullOrEmpty(keyword))
  215. {
  216. conModels.Add(new ConditionalCollections()
  217. {
  218. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  219. {
  220. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  221. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Content", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  222. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_PeopleName", ConditionalType = ConditionalType.Like, FieldValue = keyword })
  223. }
  224. });
  225. }
  226. if (type > -1)
  227. {
  228. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Like, FieldValue = type.ToString() });
  229. }
  230. if (state > -1)
  231. {
  232. conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Like, FieldValue = state.ToString() });
  233. }
  234. #endregion
  235. int recordCount = 0;
  236. var list = await _sys_todomanagementrepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount });
  237. var obj = new
  238. {
  239. state = "success",
  240. message = "成功",
  241. rows = list,
  242. total = list.Totals,
  243. };
  244. return Content(obj.ToJson());
  245. }
  246. /// <summary>
  247. /// 获取任务详情
  248. /// </summary>
  249. /// <param name="id">id</param>
  250. /// <returns></returns>
  251. [HttpGet("getdetails")]
  252. public async Task<IActionResult> GetDetailsAsync(int id)
  253. {
  254. if (id <= 0)
  255. return Error("参数错误");
  256. var model = await _sys_todomanagementrepository.GetSingle(x => x.F_ID == id);
  257. if (model == null)
  258. {
  259. return Error("获取失败");
  260. }
  261. return Success("获取成功!", model);
  262. }
  263. /// <summary>
  264. /// 上传文件并导入数据库
  265. /// </summary>
  266. /// <returns></returns>
  267. [HttpPost("importexcel")]
  268. public async Task<IActionResult> ImportExcel(int headrow = 0)
  269. {
  270. Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
  271. if (!_upfile.ContentType.Equals("application/vnd.ms-excel") && !_upfile.ContentType.Equals("application/x-xls") && !_upfile.ContentType.Equals("application/x-xlsx") && !_upfile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") && !_upfile.ContentType.Equals("application/octet-stream"))
  272. return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
  273. NPOIHelper npoi = new NPOIHelper();
  274. var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
  275. int num = dtExcel.Rows.Count;
  276. var cols = dtExcel.Columns;
  277. int colnum = cols.Count;
  278. string errmsg = string.Empty;
  279. if (num > 0)
  280. {
  281. int index = 1;
  282. foreach (DataRow dr in dtExcel.Rows)
  283. {
  284. var model = new T_Sys_TodoManagement();
  285. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  286. if (dr["分类"].ToString() == "日程")
  287. {
  288. model.F_Type = 0;
  289. model.F_Name = dr["待办标题"].ToString();
  290. model.F_Content = dr["待办内容"].ToString();
  291. }
  292. else
  293. {
  294. model.F_Type = 1;
  295. model.F_PeopleName = dr["待联系人姓名"].ToString();
  296. model.F_Tel = dr["待联系人电话"].ToString();
  297. }
  298. if (dr["任务状态"].ToString() == "未完成")
  299. model.F_State = 0;
  300. else
  301. model.F_State = 0;
  302. if (!string .IsNullOrEmpty (dr["待办提醒时间"].ToString()))
  303. {
  304. try
  305. {
  306. model.F_Remindertime = DateTime.Parse(dr["待办提醒时间"].ToString());
  307. }
  308. catch
  309. {
  310. errmsg = errmsg + "\r\n第" + index + "行导入失败!待办提醒时间格式错误";
  311. continue;
  312. }
  313. }
  314. model.F_CreateTime = DateTime.Now;
  315. model.F_CreateUser = user;
  316. model.F_IsDelete = 0;
  317. int b = await _sys_todomanagementrepository.Add(model);
  318. if (b <= 0)
  319. {
  320. if (!string.IsNullOrEmpty(errmsg))
  321. {
  322. errmsg = errmsg + "\r\n第" + index + "行导入失败!";
  323. }
  324. else
  325. {
  326. errmsg = "第" + index + "行导入失败!";
  327. }
  328. }
  329. index++;
  330. }
  331. }
  332. else
  333. {
  334. return Error("文件中无数据");
  335. }
  336. if (!string.IsNullOrEmpty(errmsg))
  337. {
  338. return Error(errmsg);
  339. }
  340. return Success("导入成功");
  341. }
  342. }
  343. }