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

TaskManagementController.cs 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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. using TVShoppingCallCenter_ZLJ.Models.Inputs;
  14. namespace TVShoppingCallCenter_ZLJ.Controllers.TaskManagement
  15. {
  16. [Produces("application/json")]
  17. [Route("api/[controller]")]
  18. public class TaskManagementController : BaseController
  19. {
  20. private readonly ISMS_InternalMessagesReposytory _sys_internalMessagesrepository;
  21. private readonly ISys_UserAccountRepository _sys_useraccountRepository;
  22. private readonly ISys_TaskManagementRepository _sys_taskmanagement_Repository;
  23. private readonly ISys_DepartmentRepository _sys_departmentRepository;
  24. public TaskManagementController(ISys_TaskManagementRepository sys_taskmanagement_Repository, ISys_DepartmentRepository sys_departmentRepository,
  25. ISys_UserAccountRepository sys_useraccountRepository, ISMS_InternalMessagesReposytory sys_internalMessagesrepository)
  26. {
  27. _sys_taskmanagement_Repository = sys_taskmanagement_Repository;
  28. _sys_departmentRepository = sys_departmentRepository;
  29. _sys_useraccountRepository = sys_useraccountRepository;
  30. _sys_internalMessagesrepository = sys_internalMessagesrepository;
  31. }
  32. /// <summary>
  33. /// 添加任务
  34. /// </summary>
  35. /// <param name="input"></param>
  36. /// <returns></returns>
  37. [HttpPost("add")]
  38. public async Task<IActionResult> AddAsync(T_Sys_TaskManagement input)
  39. {
  40. if (string.IsNullOrEmpty(input.F_Name))
  41. return Error("请输入任务名称");
  42. if (string.IsNullOrEmpty(input.F_Content))
  43. return Error("请输入任务内容");
  44. if (input.F_StartTime == null)
  45. return Error("请选择任务开始时间");
  46. if (input.F_EndTime == null)
  47. return Error("请选择任务结束时间");
  48. if (input.F_Type < 0)
  49. return Error("请选择任务类型");
  50. if (string .IsNullOrEmpty (input .F_Deptid ))
  51. return Error("请选择任务部门");
  52. if (input.F_Money < 0)
  53. return Error("请输入目标金额");
  54. // string user = "8000";
  55. if (input.F_Remindertime == null)
  56. input.F_Remindertime = input.F_EndTime.Value.AddDays(-3);
  57. if (input.F_Currentamount > 0)
  58. input.F_Taskprogress = string.Format("{0:f2}", input.F_Currentamount / input.F_Money * 100);
  59. else
  60. input.F_Taskprogress = "0";
  61. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  62. input.F_CreateTime = DateTime.Now;
  63. input.F_CreateUser = user;
  64. input.F_IsDelete = 0;
  65. var res = await _sys_taskmanagement_Repository.Add(input);
  66. if (res > 0)
  67. {
  68. try
  69. {
  70. DateTime time = DateTime.Parse(input.F_Remindertime.ToString());
  71. if (input .F_Tasker >0)
  72. {
  73. string usercode = _sys_useraccountRepository.GetSingle(x => x.F_UserId == input.F_Tasker).Result.F_UserCode;
  74. bool n = new InternalMessages.InternalMessagesController(_sys_internalMessagesrepository, _sys_useraccountRepository).AddInternalMessagesInfo(res, "任务提醒", input.F_Name + "任务提醒", user, time, 1, 1, 0, usercode, 1);
  75. }
  76. else
  77. {
  78. bool n = new InternalMessages.InternalMessagesController(_sys_internalMessagesrepository, _sys_useraccountRepository).AddInternalMessagesInfo(res, "任务提醒", input.F_Name + "任务提醒", user, time, 1, 1, int.Parse(input.F_Deptid.Split(',')[input.F_Deptid.Split(',').Length - 1]), "", 0);
  79. }
  80. }
  81. catch
  82. {
  83. }
  84. return Success("添加成功");
  85. }
  86. else
  87. {
  88. return Error("添加失败");
  89. }
  90. }
  91. /// <summary>
  92. /// 修改任务
  93. /// </summary>
  94. [HttpPost("update")]
  95. public async Task<IActionResult> UpdateAsync(T_Sys_TaskManagement input)
  96. {
  97. if (input.F_ID <= 0)
  98. return Error("参数错误");
  99. if (string.IsNullOrEmpty(input.F_Name))
  100. return Error("请输入任务名称");
  101. if (string.IsNullOrEmpty(input.F_Content))
  102. return Error("请输入任务内容");
  103. if (input.F_StartTime == null)
  104. return Error("请选择任务开始时间");
  105. if (input.F_EndTime == null)
  106. return Error("请选择任务结束时间");
  107. if (input.F_Type < 0)
  108. return Error("请选择任务类型");
  109. if (string.IsNullOrEmpty(input.F_Deptid))
  110. return Error("请选择任务部门");
  111. if (input.F_Money < 0)
  112. return Error("请输入目标金额");
  113. var model = await _sys_taskmanagement_Repository.GetSingle(x => x.F_ID == input.F_ID);
  114. if (model == null)
  115. return Error("操作失败");
  116. if (input.F_Remindertime == null)
  117. input.F_Remindertime = input.F_EndTime.Value.AddDays(-3);
  118. if (input.F_Currentamount > 0)
  119. input.F_Taskprogress = string.Format("{0:f2}", input.F_Currentamount / input.F_Money * 100);
  120. else
  121. input.F_Taskprogress = "0";
  122. // string user = "8000";
  123. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  124. input.F_IsDelete = 0;
  125. input.F_CreateUser = model.F_CreateUser;
  126. input.F_CreateTime = model.F_CreateTime ;
  127. input.F_UpdateTime = DateTime.Now;
  128. input.F_UpdateUser = user;
  129. // model.F_UpdateUser = "8000";
  130. var b = await _sys_taskmanagement_Repository.Update(input);
  131. if (b)
  132. {
  133. DateTime time = DateTime.Parse(input.F_Remindertime.ToString());
  134. var InternalMessages = _sys_internalMessagesrepository.GetSingle(x => x.F_ID == model.F_ID).Result;
  135. if (InternalMessages!=null )
  136. {
  137. try
  138. {
  139. if (input.F_Tasker > 0)
  140. {
  141. string usercode = _sys_useraccountRepository.GetSingle(x => x.F_UserId == input.F_Tasker).Result.F_UserCode;
  142. InternalMessages.SMS_Content = input.F_Name + "任务提醒";
  143. InternalMessages.SMS_Remindertime = input.F_Remindertime;
  144. InternalMessages.SMS_ReceiveUserCode = usercode;
  145. bool n = await _sys_internalMessagesrepository.Update(InternalMessages);
  146. }
  147. else
  148. {
  149. InternalMessages.SMS_Content = input.F_Name + "任务提醒";
  150. InternalMessages.SMS_Remindertime = input.F_Remindertime;
  151. InternalMessages.SMS_Deptid = int.Parse(input.F_Deptid.Split(',')[input.F_Deptid.Split(',').Length - 1]);
  152. bool n = await _sys_internalMessagesrepository.Update(InternalMessages);
  153. }
  154. }
  155. catch
  156. {
  157. }
  158. }
  159. else
  160. {
  161. try
  162. {
  163. if (input.F_Tasker > 0)
  164. {
  165. string usercode = _sys_useraccountRepository.GetSingle(x => x.F_UserId == input.F_Tasker).Result.F_UserCode;
  166. bool n = new InternalMessages.InternalMessagesController(_sys_internalMessagesrepository, _sys_useraccountRepository).AddInternalMessagesInfo(model.F_ID, "任务提醒", input.F_Name + "任务提醒", user, time, 1, 1, 0, usercode, 1);
  167. }
  168. else
  169. {
  170. bool n = new InternalMessages.InternalMessagesController(_sys_internalMessagesrepository, _sys_useraccountRepository).AddInternalMessagesInfo(model.F_ID, "任务提醒", input.F_Name + "任务提醒", user, time, 1, 1, int.Parse(input.F_Deptid.Split(',')[input.F_Deptid.Split(',').Length - 1]), "", 0);
  171. }
  172. }
  173. catch
  174. {
  175. }
  176. }
  177. return Success("修改成功");
  178. }
  179. return Error("修改失败");
  180. }
  181. /// <summary>
  182. /// 删除任务
  183. /// </summary>
  184. /// <param name="ids"></param>
  185. /// <returns></returns>
  186. [HttpPost("delete")]
  187. public async Task<IActionResult> Remove(int[] ids)
  188. {
  189. var res = 0;
  190. if (ids != null && ids.Length > 0)
  191. {
  192. foreach (var item in ids)
  193. {
  194. var model = await _sys_taskmanagement_Repository.GetSingle(x => x.F_ID == item);
  195. model.F_IsDelete = (int)EnumUserCountState.Delete;
  196. model.F_DeleteTime = DateTime.Now.ToLocalTime();
  197. model.F_DeleteUser = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  198. if (_sys_taskmanagement_Repository.Update(model).Result)
  199. res += 1;
  200. }
  201. if (res == ids.Length)
  202. return Success("删除成功");
  203. else if (res > 0 && res < ids.Length)
  204. return Error("部分删除失败,请查看后重新操作");
  205. else
  206. return Error("删除失败,请查看后重新操作");
  207. }
  208. else
  209. return Error("请选择要删除的记录");
  210. }
  211. /// <summary>
  212. /// 操作任务
  213. /// </summary>
  214. /// <param name="id">id</param>
  215. /// <returns></returns>
  216. [HttpGet("operation")]
  217. public async Task<IActionResult> GetOperationAsync(int id, int state)
  218. {
  219. if (id <= 0)
  220. return Error("参数错误");
  221. var model = await _sys_taskmanagement_Repository.GetSingle(x => x.F_ID == id);
  222. if (model == null)
  223. {
  224. return Error("获取失败");
  225. }
  226. model.F_State = state;
  227. var obj = await _sys_taskmanagement_Repository.Update(model);
  228. if (obj)
  229. return Success("操作成功");
  230. else
  231. return Error("操作失败");
  232. }
  233. /// <summary>
  234. /// 获取任务列表
  235. /// </summary>
  236. /// <param name="keyword"></param>
  237. /// <param name="pageindex"></param>
  238. /// <param name="pagesize"></param>
  239. /// <returns></returns>
  240. [HttpGet("getlist")]
  241. public async Task<IActionResult> GetListMark(string keyword, string name,string parentname, string starttime, string endtime, string tasker,
  242. string deptid , int parentid=0,int type = -1, int pageindex = 1, int pagesize = 20)
  243. {
  244. List<IConditionalModel> conModels = new List<IConditionalModel>();
  245. #region 条件筛选
  246. conModels.Add(new ConditionalModel() { FieldName = "F_IsDelete", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumUserCountState.Enabled).ToString() });
  247. if (!string.IsNullOrEmpty(name))
  248. {
  249. conModels.Add(new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = name });
  250. }
  251. if (!string.IsNullOrEmpty(tasker))
  252. {
  253. if (_sys_useraccountRepository .GetSingle(x => x.F_UserName == tasker).Result != null)
  254. {
  255. conModels.Add(new ConditionalModel() { FieldName = "F_Tasker", ConditionalType = ConditionalType.Like, FieldValue = _sys_useraccountRepository.GetSingle(x => x.F_UserName == tasker).Result.F_UserId .ToString () });
  256. }
  257. else
  258. {
  259. return Error("请输入正确的任务人");
  260. }
  261. }
  262. if (!string.IsNullOrEmpty(parentname))
  263. {
  264. if (_sys_taskmanagement_Repository.GetSingle (x=>x .F_Name == parentname).Result!=null )
  265. {
  266. conModels.Add(new ConditionalModel() { FieldName = "F_Parentid", ConditionalType = ConditionalType.Like, FieldValue = _sys_taskmanagement_Repository.GetSingle(x => x.F_Name == parentname).Result.F_ID .ToString () });
  267. }
  268. else
  269. {
  270. return Error("请输入正确的父级任务名称");
  271. }
  272. }
  273. if (type > -1)
  274. {
  275. conModels.Add(new ConditionalModel() { FieldName = "F_Type", ConditionalType = ConditionalType.Like, FieldValue = type.ToString() });
  276. }
  277. conModels.Add(new ConditionalModel() { FieldName = "F_Parentid", ConditionalType = ConditionalType.Equal , FieldValue = parentid.ToString() });
  278. if (!string.IsNullOrEmpty(keyword))
  279. {
  280. conModels.Add(new ConditionalCollections()
  281. {
  282. ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
  283. {
  284. new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
  285. new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Content", ConditionalType = ConditionalType.Like, FieldValue = keyword })
  286. }
  287. });
  288. }
  289. if (!string.IsNullOrEmpty(starttime))
  290. {
  291. conModels.Add(new ConditionalModel() { FieldName = "F_StartTime", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = starttime });
  292. }
  293. if (!string.IsNullOrEmpty(endtime))
  294. {
  295. conModels.Add(new ConditionalModel() { FieldName = "F_EndTime", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = endtime });
  296. }
  297. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  298. var dept = _sys_useraccountRepository.GetSingle(x => x.F_UserCode == user).Result != null ? _sys_useraccountRepository.GetSingle(x => x.F_UserCode == user).Result.F_DeptId : 0;
  299. if (!string .IsNullOrEmpty (deptid))
  300. {
  301. conModels.Add(new ConditionalModel() { FieldName = "F_Deptid", ConditionalType = ConditionalType.Equal, FieldValue = deptid });
  302. }
  303. else
  304. {
  305. conModels.Add(new ConditionalModel() { FieldName = "F_CreateUser", ConditionalType = ConditionalType.Equal , FieldValue = user });
  306. new KeyValuePair<WhereType, ConditionalModel>(WhereType.Or, new ConditionalModel() { FieldName = "F_Deptid", ConditionalType = ConditionalType.Like, FieldValue = dept.ToString() });
  307. }
  308. #endregion
  309. int recordCount = 0;
  310. var list = await _sys_taskmanagement_Repository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount });
  311. var obj = new
  312. {
  313. state = "success",
  314. message = "成功",
  315. rows = ConvertAsync(list.Rows ),
  316. total = list.Totals,
  317. };
  318. return Content(obj.ToJson());
  319. }
  320. /// <summary>
  321. /// 获取任务详情
  322. /// </summary>
  323. /// <param name="id">id</param>
  324. /// <returns></returns>
  325. [HttpGet("getdetails")]
  326. public async Task<IActionResult> GetDetailsAsync(int id)
  327. {
  328. if (id <= 0)
  329. return Error("参数错误");
  330. var model = await _sys_taskmanagement_Repository.GetSingle(x => x.F_ID == id);
  331. if (model == null)
  332. {
  333. return Error("获取失败");
  334. }
  335. return Success("获取成功!", Convert(model, 1));
  336. }
  337. /// <summary>
  338. /// 修改任务当前金额
  339. /// </summary>
  340. /// <param name="id"></param>
  341. /// <param name="money"></param>
  342. /// <returns></returns>
  343. public int UpdateTaskAmount(T_Bus_Order t_Bus_Order )
  344. {
  345. //0成功1任务暂停2任务终止3修改任务金额失败4任务不存在5父级任务不存在6父级任务修改失败7父级任务暂停8父级任务终止
  346. int n = 0;
  347. var model = _sys_taskmanagement_Repository.GetListALL (x => x.F_Tasker == t_Bus_Order.F_AddUser&& x.F_IsDelete ==0);
  348. if (model == null)
  349. return 4;
  350. foreach (var it in model.Result )
  351. {
  352. if (it.F_State == 0)
  353. {
  354. it.F_Currentamount +=(float ) t_Bus_Order.F_RealPrice;
  355. it.F_Taskprogress = string.Format("{0:f2}", it.F_Currentamount / it.F_Money * 100);
  356. var res = _sys_taskmanagement_Repository.Update(it);
  357. if (!res.Result)
  358. return 3;
  359. if (it.F_Parentid > 0)
  360. {
  361. n = TreeRecursion(it.F_Parentid, (float)t_Bus_Order.F_RealPrice);
  362. }
  363. }
  364. else
  365. n = (int)it .F_State;
  366. }
  367. return n;
  368. }
  369. /// <summary>
  370. /// 递归算法
  371. /// </summary>
  372. /// <param name="data"></param>
  373. /// <param name="parentId"></param>
  374. /// <returns></returns>
  375. private int TreeRecursion( int parentId = 0,float money=0)
  376. {
  377. int n = 0;
  378. var model = _sys_taskmanagement_Repository.GetSingle(x => x.F_ID == parentId).Result;
  379. if (model == null)
  380. return 5;
  381. if (model.F_State == 0)
  382. {
  383. model.F_Currentamount += money;
  384. model.F_Taskprogress = string.Format("{0:f2}", model.F_Currentamount / model.F_Money * 100);
  385. var res = _sys_taskmanagement_Repository.Update(model);
  386. if (!res.Result)
  387. return 6;
  388. if (model.F_Parentid > 0)
  389. {
  390. n = TreeRecursion(model.F_Parentid, money);
  391. }
  392. }
  393. else
  394. n = (int)model.F_State+6;
  395. return n;
  396. }
  397. /// <summary>
  398. /// 上传文件并导入数据库
  399. /// </summary>
  400. /// <returns></returns>
  401. [HttpPost("importexcel")]
  402. public async Task<IActionResult> ImportExcel(int headrow = 0,int parentid=0)
  403. {
  404. Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
  405. 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"))
  406. return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
  407. NPOIHelper npoi = new NPOIHelper();
  408. var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
  409. int num = dtExcel.Rows.Count;
  410. var cols = dtExcel.Columns;
  411. int colnum = cols.Count;
  412. string errmsg = string.Empty;
  413. if (num > 0)
  414. {
  415. int index = 1;
  416. foreach (DataRow dr in dtExcel.Rows)
  417. {
  418. var model = new T_Sys_TaskManagement();
  419. string user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
  420. model.F_Name = dr["任务名称"].ToString();
  421. model.F_Content = dr["任务内容"].ToString();
  422. if (string .IsNullOrEmpty (dr["任务开始时间"].ToString()))
  423. {
  424. errmsg = errmsg + "\r\n第" + index + "行导入失败!请输入任务开始时间";
  425. continue;
  426. }
  427. if (string.IsNullOrEmpty(dr["任务结束时间"].ToString()))
  428. {
  429. errmsg = errmsg + "\r\n第" + index + "行导入失败!请输入任务结束时间";
  430. continue;
  431. }
  432. if (string.IsNullOrEmpty(dr["目标金额"].ToString()))
  433. {
  434. errmsg = errmsg + "\r\n第" + index + "行导入失败!请输入目标金额";
  435. continue;
  436. }
  437. try
  438. {
  439. model.F_StartTime = DateTime.Parse(dr["任务开始时间"].ToString());
  440. }
  441. catch
  442. {
  443. errmsg = errmsg + "\r\n第" + index + "行导入失败!任务开始时间格式错误";
  444. continue;
  445. }
  446. try
  447. {
  448. model.F_EndTime = DateTime.Parse(dr["任务结束时间"].ToString());
  449. }
  450. catch
  451. {
  452. errmsg = errmsg + "\r\n第" + index + "行导入失败!任务结束时间格式错误";
  453. continue;
  454. }
  455. if (dr["任务类型"].ToString() == "月")
  456. model.F_Type = 2;
  457. else if (dr["任务类型"].ToString() == "周")
  458. model.F_Type = 1;
  459. else
  460. model.F_Type = 0;
  461. if (_sys_departmentRepository.GetSingle(x => x.F_DeptName == dr["任务部门"].ToString()).Result !=null )
  462. {
  463. model.F_Deptid = _sys_departmentRepository.GetSingle(x => x.F_DeptName == dr["任务部门"].ToString()).Result.F_DeptId.ToString ();
  464. }
  465. else
  466. {
  467. errmsg = errmsg + "\r\n第" + index + "行导入失败!请检查任务部门";
  468. continue;
  469. }
  470. if (_sys_useraccountRepository.GetSingle(x => x.F_UserName == dr["任务人"].ToString()).Result != null)
  471. {
  472. model.F_Tasker = _sys_useraccountRepository.GetSingle(x => x.F_UserName == dr["任务人"].ToString()).Result.F_UserId ;
  473. }
  474. else
  475. {
  476. errmsg = errmsg + "\r\n第" + index + "行导入失败!请检查任务人";
  477. continue;
  478. }
  479. try
  480. {
  481. model.F_Money = float .Parse(dr["目标金额"].ToString());
  482. }
  483. catch
  484. {
  485. errmsg = errmsg + "\r\n第" + index + "行导入失败!请输入正确的目标金额";
  486. continue;
  487. }
  488. if (string.IsNullOrEmpty(dr["当前金额"].ToString()))
  489. model.F_Currentamount = 0;
  490. try
  491. {
  492. model.F_Currentamount = float.Parse(dr["当前金额"].ToString());
  493. }
  494. catch
  495. {
  496. errmsg = errmsg + "\r\n第" + index + "行导入失败!请输入正确的当前金额";
  497. continue;
  498. }
  499. if (!string .IsNullOrEmpty (dr["任务提醒时间"].ToString()))
  500. {
  501. try
  502. {
  503. model.F_Remindertime = DateTime.Parse(dr["任务提醒时间"].ToString());
  504. }
  505. catch
  506. {
  507. errmsg = errmsg + "\r\n第" + index + "行导入失败!任务提醒时间格式错误";
  508. continue;
  509. }
  510. }
  511. else
  512. {
  513. model.F_Remindertime = model.F_EndTime.Value.AddDays(-3);
  514. }
  515. model.F_Taskprogress = string.Format("{0:f2}", model.F_Currentamount / model.F_Money * 100);
  516. if (dr["任务类型"].ToString() == "终止")
  517. model.F_State = 2;
  518. else if (dr["任务类型"].ToString() == "暂停")
  519. model.F_State = 1;
  520. else
  521. model.F_State = 0;
  522. model.F_CreateTime = DateTime.Now;
  523. model.F_CreateUser = user;
  524. model.F_IsDelete = 0;
  525. model.F_Parentid = parentid;
  526. int b = await _sys_taskmanagement_Repository.Add(model);
  527. if (b <= 0)
  528. {
  529. if (!string.IsNullOrEmpty(errmsg))
  530. {
  531. errmsg = errmsg + "\r\n第" + index + "行导入失败!";
  532. }
  533. else
  534. {
  535. errmsg = "第" + index + "行导入失败!";
  536. }
  537. }
  538. index++;
  539. }
  540. }
  541. else
  542. {
  543. return Error("文件中无数据");
  544. }
  545. if (!string.IsNullOrEmpty(errmsg))
  546. {
  547. return Error(errmsg);
  548. }
  549. return Success("导入成功");
  550. }
  551. #region 私有方法
  552. private TaskManagementInput Convert(T_Sys_TaskManagement it, int type = 0)
  553. {
  554. TaskManagementInput task = new TaskManagementInput();
  555. task.F_ID = it.F_ID;
  556. task.F_Name = it.F_Name;
  557. task.F_Content = it.F_Content;
  558. task.F_StartTime = it.F_StartTime;
  559. task.F_EndTime = it.F_EndTime;
  560. task.F_Type = it.F_Type;
  561. task.F_Deptid = it.F_Deptid;
  562. string deptmsg = "";
  563. if (!string.IsNullOrEmpty(it.F_Deptid))
  564. {
  565. try
  566. {
  567. string[] sprit = it.F_Deptid.Split(',');
  568. foreach (var iv in sprit)
  569. {
  570. if (deptmsg == "")
  571. deptmsg = _sys_departmentRepository.GetSingle(x => x.F_DeptId == int.Parse(iv)).Result != null ? _sys_departmentRepository.GetSingle(x => x.F_DeptId == int.Parse(iv)).Result.F_DeptName : "";
  572. else
  573. deptmsg = deptmsg + "," + _sys_departmentRepository.GetSingle(x => x.F_DeptId == int.Parse(iv)).Result != null ? _sys_departmentRepository.GetSingle(x => x.F_DeptId == int.Parse(iv)).Result.F_DeptName : "";
  574. }
  575. }
  576. catch
  577. {
  578. }
  579. }
  580. task.F_DeptName = deptmsg;// 部门名称
  581. task.F_Tasker = it.F_Tasker;
  582. task.F_TaskerName = _sys_useraccountRepository.GetSingle(x => x.F_UserId == it.F_Tasker).Result != null ? _sys_useraccountRepository.GetSingle(x => x.F_UserId == it.F_Tasker).Result .F_UserName : "";
  583. task.F_Money = it.F_Money;
  584. task.F_Currentamount = it.F_Currentamount;
  585. task.F_Taskprogress = it.F_Taskprogress;
  586. task.F_State = it.F_State;
  587. task.F_Remindertime = it.F_Remindertime;
  588. if (type ==0)
  589. {
  590. var taskcount = _sys_taskmanagement_Repository.GetListALL(x => x.F_Parentid == it.F_ID&&x.F_IsDelete ==0).Result != null ? _sys_taskmanagement_Repository.GetListALL(x => x.F_Parentid == it.F_ID && x.F_IsDelete == 0).Result: null ;
  591. if (taskcount!=null )
  592. {
  593. task.children = ConvertAsync(taskcount);
  594. }
  595. }
  596. task.F_Parentid = it.F_Parentid;
  597. task.F_ParentName = _sys_taskmanagement_Repository.GetSingle(x => x.F_ID == it.F_Parentid).Result != null ? _sys_taskmanagement_Repository.GetSingle(x => x.F_ID == it.F_Parentid).Result.F_Name : "";// 部门名称
  598. return task;
  599. }
  600. /// model转input
  601. /// </summary>
  602. /// <param name="input"></param>
  603. /// <returns></returns>
  604. private List<TaskManagementInput> ConvertAsync(List<T_Sys_TaskManagement> model)
  605. {
  606. List<TaskManagementInput> input = new List<TaskManagementInput>();
  607. if (model != null)
  608. {
  609. foreach (var it in model)
  610. {
  611. TaskManagementInput marketing = new TaskManagementInput();
  612. marketing = Convert(it);
  613. input.Add(marketing);
  614. }
  615. }
  616. return input;
  617. }
  618. #endregion
  619. }
  620. }