TaskAllocationRepository.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. using AutoMapper;
  2. using EnumsNET;
  3. using Microsoft.VisualBasic;
  4. using NPOI.SS.Formula.Functions;
  5. using OASystem.Domain;
  6. using OASystem.Domain.Dtos.PersonnelModule;
  7. using OASystem.Domain.Entities.Groups;
  8. using OASystem.Domain.Entities.PersonnelModule;
  9. using OASystem.Domain.Entities.System;
  10. using OASystem.Domain.ViewModels.PersonnelModule;
  11. using Org.BouncyCastle.Ocsp;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. namespace OASystem.Infrastructure.Repositories.PersonnelModule
  18. {
  19. /// <summary>
  20. /// 任务分配
  21. /// 仓库
  22. /// </summary>
  23. public class TaskAllocationRepository : BaseRepository<Pm_TaskAllocation, TaskAllocationView>
  24. {
  25. private readonly IMapper _mapper;
  26. private Result _result;
  27. public TaskAllocationRepository(SqlSugarClient sqlSugar, IMapper mapper)
  28. : base(sqlSugar)
  29. {
  30. _mapper = mapper;
  31. _result = new Result() { Code = -1, Msg = "操作失败!" };
  32. }
  33. /// <summary>
  34. /// 任务操作权限(任务创建人才可以进行操作)
  35. /// </summary>
  36. /// <param name="taskAllocation"></param>
  37. /// <param name="userId"></param>
  38. /// <returns></returns>
  39. public TaskOperationAudit _TaskOperationAudit(Pm_TaskAllocation taskAllocation, int userId)
  40. {
  41. TaskOperationAudit taskOperationAudit = new TaskOperationAudit();
  42. if (taskAllocation.CreateUserId == userId)
  43. {
  44. taskOperationAudit.TaskAddAudit = 1;
  45. taskOperationAudit.TaskDelAudit = 1;
  46. taskOperationAudit.TasStopAudit = 1;
  47. taskOperationAudit.TaskComfirmAudit = 1;
  48. taskOperationAudit.TaskScoreAudit = 1;
  49. }
  50. return taskOperationAudit;
  51. }
  52. /// <summary>
  53. /// 基础数据源
  54. /// </summary>
  55. /// <returns></returns>
  56. public async Task<Result> _Init(int portType, int userId)
  57. {
  58. if (portType == 1 || portType == 2 || portType == 3)
  59. {
  60. if (userId < 1)
  61. {
  62. _result.Msg = string.Format("请传入有效的UserId参数!");
  63. return _result;
  64. }
  65. //任务名称
  66. List<string> _TaskNameInfos = new List<string>();
  67. _TaskNameInfos = _sqlSugar.Queryable<Pm_TaskAllocation, Pm_TaskRelevanceUser>((ta, tau) => new JoinQueryInfos(JoinType.Left, ta.Id == tau.TAId))
  68. .Where((ta, tau) => ta.IsDel == 0 && tau.IsDel == 0)
  69. .Where((ta, tau) => ta.CreateUserId == userId || tau.UserId == userId)
  70. .Select(ta => ta.TaskName).ToList()
  71. .Distinct().ToList();
  72. //团组名称
  73. List<ValueInfo> _GroupNameInfos = new List<ValueInfo>();
  74. _GroupNameInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0)
  75. .OrderByDescending(it => it.CreateTime)
  76. .Select(it => new ValueInfo { Id = it.Id, Name = it.TeamName })
  77. .ToList();
  78. _GroupNameInfos.Insert(0, new ValueInfo() { Id = -1, Name = "未选择" });
  79. //部门名称
  80. ValueInfo _DepartmentNameInfos = new ValueInfo();
  81. _DepartmentNameInfos = _sqlSugar.Queryable<Sys_Users, Sys_Department>((u, d) => new JoinQueryInfos(JoinType.Left, u.DepId == d.Id))
  82. .Select((u, d) => new ValueInfo() { Id = d.Id, Name = d.DepName })
  83. .First();
  84. //执行任务人员信息 1 公司总经理/副总 可分配 所有人的任务 2 公司 部门经理/主管 可分配 部门下的人员的任务
  85. List<ExecuteTaskUserInfo> _ExecuteTaskUserInfos = new List<ExecuteTaskUserInfo>();
  86. TaskOperationAudit _TaskOpertionAudit = new TaskOperationAudit();
  87. List<Pm_TaskJobRelevancy> taskAudits = new List<Pm_TaskJobRelevancy>();
  88. taskAudits = _sqlSugar.Queryable<Pm_TaskJobRelevancy>().Where(it => it.IsDel == 0 && it.PrimaryUserId == userId).ToList();
  89. if (taskAudits.Count > 0)
  90. {
  91. //任务权限
  92. _TaskOpertionAudit.TaskAddAudit = 1;
  93. _TaskOpertionAudit.TaskDelAudit = 1;
  94. _TaskOpertionAudit.TasStopAudit = 1;
  95. List<int> userIds = taskAudits.Select(it => it.SubUserId).ToList();
  96. string userSql = string.Format(@"Select u.Id,u.CnName As Name,c.CompanyName,
  97. d.DepName As DepartmentName,jp.JobName
  98. From Sys_Users u
  99. Left Join Sys_Company c On u.CompanyId = c.Id
  100. Left Join Sys_Department d On u.DepId = d.Id
  101. Left Join Sys_JobPost jp On u.JobPostId = jp.Id
  102. Where u.IsDel = 0 ");
  103. _ExecuteTaskUserInfos = _sqlSugar.SqlQueryable<ExecuteTaskUserInfo>(userSql).Where(it => userIds.Contains(it.Id)).ToList();
  104. }
  105. InitView _view = new InitView()
  106. {
  107. TaskOperationAudit = _TaskOpertionAudit,
  108. TaskNameInfos = _TaskNameInfos,
  109. ExecuteTaskUserInfos = _ExecuteTaskUserInfos,
  110. GroupNameInfos = _GroupNameInfos,
  111. DepartmentNameInfo = _DepartmentNameInfos
  112. };
  113. _result.Code = 0;
  114. _result.Data = _view;
  115. }
  116. else
  117. {
  118. _result.Msg = string.Format("请传入有效的PortType参数!");
  119. }
  120. return _result;
  121. }
  122. /// <summary>
  123. /// 任务指派
  124. /// 详情
  125. /// </summary>
  126. /// <param name="portType"></param>
  127. /// <param name="Id"></param>
  128. /// <returns></returns>
  129. public async Task<Result> _Details(int portType, int Id)
  130. {
  131. if (Id < 1)
  132. {
  133. _result.Msg = string.Format("请传入有效的Id参数!");
  134. return _result;
  135. }
  136. if (portType == 1 || portType == 2 || portType == 3)
  137. {
  138. //团组名称
  139. List<ValueInfo> _GroupNameInfos = new List<ValueInfo>();
  140. _GroupNameInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0)
  141. .OrderByDescending(it => it.CreateTime)
  142. .Select(it => new ValueInfo { Id = it.Id, Name = it.TeamName })
  143. .ToList();
  144. _GroupNameInfos.Insert(0, new ValueInfo() { Id = -1, Name = "未选择" });
  145. //部门名称
  146. List<ValueInfo> _DepartmentNameInfos = new List<ValueInfo>();
  147. _DepartmentNameInfos = _sqlSugar.Queryable<Sys_Department>()
  148. .Select(d => new ValueInfo() { Id = d.Id, Name = d.DepName })
  149. .ToList();
  150. //用户名称
  151. List<ValueInfo> _UserNameInfos = new List<ValueInfo>();
  152. _UserNameInfos = _sqlSugar.Queryable<Sys_Users>()
  153. .Select(d => new ValueInfo() { Id = d.Id, Name = d.CnName })
  154. .ToList();
  155. TaskDetailsView _view = _sqlSugar.Queryable<Pm_TaskAllocation>()
  156. .Where(it => it.IsDel == 0 && it.Id == Id)
  157. .Select(it => new TaskDetailsView
  158. {
  159. Id = it.Id,
  160. DiId = it.DiId,
  161. DepId = it.DepId,
  162. CreateUserId = it.CreateUserId,
  163. CreateTime = it.CreateTime,
  164. TaskName = it.TaskName,
  165. TaskContent = it.TaskContent,
  166. TaskPriority = it.TaskPriority,
  167. PredictBeginTime = it.PredictBeginTime,
  168. PredictEndTime = it.PredictEndTime,
  169. IsIntoPerformance = it.IsIntoPerformance,
  170. Remark = it.Remark,
  171. })
  172. .First();
  173. if (_view != null)
  174. {
  175. List<TaskUserDetailsView> taskUserDetailsViews = new List<TaskUserDetailsView>();
  176. taskUserDetailsViews = _sqlSugar.Queryable<Pm_TaskRelevanceUser>()
  177. .Where(it => it.IsDel == 0 && it.TAId == _view.Id)
  178. .Select(it => new TaskUserDetailsView
  179. {
  180. Id = it.Id,
  181. TAId = it.TAId,
  182. UserId = it.UserId,
  183. BeginTime = it.BeginTime,
  184. OverTime = it.OverTime,
  185. TaskStatus = it.TaskStatus,
  186. Cause = it.Cause,
  187. Remark = it.Remark
  188. })
  189. .ToList();
  190. _view.UserTaskInfos = taskUserDetailsViews;
  191. _result.Data = _view;
  192. _result.Code = 0;
  193. _result.Msg = "查询成功!";
  194. }
  195. }
  196. else
  197. {
  198. _result.Msg = string.Format("请传入有效的PortType参数!");
  199. }
  200. return _result;
  201. }
  202. /// <summary>
  203. /// Add Or Edit
  204. /// </summary>
  205. /// <param name="dto"></param>
  206. /// <returns></returns>
  207. public async Task<Result> _AddOrEdit(TaskAllocationAddOrEditDto dto)
  208. {
  209. if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
  210. {
  211. if (dto.UserIds.Count < 1)
  212. {
  213. _result.Msg = string.Format("指派人员不能为空!");
  214. return _result;
  215. }
  216. #region 参数处理
  217. Pm_TaskAllocation _TaskAllocation = new Pm_TaskAllocation();
  218. List<Pm_TaskRelevanceUser> _TaskRelevanceUsers = new List<Pm_TaskRelevanceUser>();
  219. _TaskAllocation = _mapper.Map<Pm_TaskAllocation>(dto);
  220. _TaskAllocation.CreateUserId = dto.UserId;
  221. _TaskAllocation.Status = TaskEnum.NotStarted;
  222. foreach (var item in dto.UserIds)
  223. {
  224. _TaskRelevanceUsers.Add(new Pm_TaskRelevanceUser() {
  225. TAId = dto.Id,
  226. UserId = item,
  227. TaskStatus = TaskerEnum.NotStarted,
  228. CreateUserId = dto.UserId,
  229. });
  230. }
  231. #endregion
  232. if (dto.Id == 0) //添加
  233. {
  234. // 1 按 任务名称 查询重
  235. Pm_TaskAllocation taskAllocation1 = await _sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.IsDel == 0 && it.TaskName.Equals(_TaskAllocation.TaskName)).FirstAsync();
  236. if (taskAllocation1 != null)
  237. {
  238. _result.Msg = string.Format("任务名称重复,请重命名!");
  239. return _result;
  240. }
  241. _sqlSugar.BeginTran();
  242. int addId = await _sqlSugar.Insertable<Pm_TaskAllocation>(_TaskAllocation).ExecuteReturnIdentityAsync();
  243. if (addId < 1)
  244. {
  245. _sqlSugar.RollbackTran();
  246. _result.Msg = string.Format("任务发布失败!");
  247. return _result;
  248. }
  249. foreach (var item in _TaskRelevanceUsers)
  250. {
  251. item.TAId = addId;
  252. }
  253. int addSub = await _sqlSugar.Insertable<Pm_TaskRelevanceUser>(_TaskRelevanceUsers).ExecuteCommandAsync();
  254. if (addSub < 1)
  255. {
  256. _sqlSugar.RollbackTran();
  257. _result.Msg = string.Format("任务发布失败!");
  258. return _result;
  259. }
  260. _result.Code = 0;
  261. _result.Msg = "添加成功!";
  262. _sqlSugar.CommitTran();
  263. }
  264. else if (dto.Id > 0) //修改
  265. {
  266. _sqlSugar.BeginTran();
  267. int updateStatus1 = await _sqlSugar.Updateable<Pm_TaskAllocation>(_TaskAllocation)
  268. .UpdateColumns(it => new
  269. {
  270. it.DepId,
  271. it.DiId,
  272. it.TaskPriority,
  273. it.TaskName,
  274. it.TaskContent,
  275. it.PredictBeginTime,
  276. it.PredictEndTime,
  277. it.IsIntoPerformance,
  278. })
  279. .Where(it => it.Id == _TaskAllocation.Id)
  280. .ExecuteCommandAsync();
  281. if (updateStatus1 < 1)
  282. {
  283. _sqlSugar.RollbackTran();
  284. _result.Msg = string.Format("任务编辑失败!");
  285. return _result;
  286. }
  287. List<int> selectUserId = new List<int>();
  288. selectUserId = await _sqlSugar.Queryable<Pm_TaskRelevanceUser>()
  289. .Where(it => it.IsDel == 0 && it.TAId == _TaskAllocation.Id)
  290. .Select(it => it.UserId)
  291. .ToListAsync();
  292. if (selectUserId.Count < 1)
  293. {
  294. int addSub1 = await _sqlSugar.Insertable<Pm_TaskRelevanceUser>(_TaskRelevanceUsers).ExecuteCommandAsync();
  295. if (addSub1 < 1)
  296. {
  297. _sqlSugar.RollbackTran();
  298. _result.Msg = string.Format("任务编辑失败!");
  299. return _result;
  300. }
  301. }
  302. else
  303. {
  304. List<int> SelectUserIdDiff = new List<int>(); //select 差集
  305. SelectUserIdDiff = selectUserId.Except(dto.UserIds).ToList();
  306. if (SelectUserIdDiff.Count > 0) //删除
  307. {
  308. List<Pm_TaskRelevanceUser> _TaskRelevanceUsers1 = new List<Pm_TaskRelevanceUser>();
  309. _TaskRelevanceUsers1 = await _sqlSugar.Queryable<Pm_TaskRelevanceUser>()
  310. .Where(it => it.IsDel == 0 &&
  311. it.TAId == _TaskAllocation.Id &&
  312. SelectUserIdDiff.Contains(it.UserId))
  313. .ToListAsync();
  314. if (_TaskRelevanceUsers1.Count > 0)
  315. {
  316. foreach (var item in _TaskRelevanceUsers1)
  317. {
  318. item.IsDel = 1;
  319. }
  320. var updateIsDel = await _sqlSugar.Updateable(_TaskRelevanceUsers1)
  321. .UpdateColumns(it => it.IsDel)
  322. .WhereColumns(it => new { it.Id, it.TAId })
  323. .ExecuteCommandAsync();
  324. if (updateIsDel < 1)
  325. {
  326. _sqlSugar.RollbackTran();
  327. _result.Msg = string.Format("任务编辑失败!");
  328. return _result;
  329. }
  330. }
  331. }
  332. List<int> ParaUserIdDiff = new List<int>(); //para 差集
  333. ParaUserIdDiff = dto.UserIds.Except(selectUserId).ToList();
  334. if (ParaUserIdDiff.Count > 0)
  335. {
  336. List<Pm_TaskRelevanceUser> _TaskRelevanceUsers1 = new List<Pm_TaskRelevanceUser>();
  337. _TaskRelevanceUsers1 = _TaskRelevanceUsers.Where(it => ParaUserIdDiff.Contains(it.UserId)).ToList();
  338. if (_TaskRelevanceUsers1.Count > 0)
  339. {
  340. int addSub1 = await _sqlSugar.Insertable<Pm_TaskRelevanceUser>(_TaskRelevanceUsers1).ExecuteCommandAsync();
  341. if (addSub1 < 1)
  342. {
  343. _sqlSugar.RollbackTran();
  344. _result.Msg = string.Format("任务编辑失败!");
  345. return _result;
  346. }
  347. }
  348. }
  349. }
  350. /*
  351. * 发送消息
  352. */
  353. _result.Code = 0;
  354. _result.Msg = "编辑成功!";
  355. _sqlSugar.CommitTran();
  356. }
  357. else
  358. {
  359. _result.Msg = string.Format("请传入有效的Id参数!");
  360. return _result;
  361. }
  362. }
  363. else
  364. {
  365. _result.Msg = string.Format("请传入有效的PortType参数!");
  366. }
  367. return _result;
  368. }
  369. /// <summary>
  370. /// 任务归属人状态 Items
  371. /// </summary>
  372. /// <param name="id"></param>
  373. /// <returns></returns>
  374. public async Task<Result> _TaskerDetails(int id)
  375. {
  376. if (id < 1)
  377. {
  378. _result.Msg = string.Format("请传入有效的Id参数!");
  379. return _result;
  380. }
  381. string sql = string.Format(@"Select tau.Id,u.CnName As UserName,tau.BeginTime,tau.OverTime,tau.TaskStatus,
  382. tau.Cause,tau.Score,tau.Remark As ScoreRemark,tau.CreateUserId As TaskCreateUserId
  383. From Pm_TaskRelevanceUser tau
  384. Left Join Sys_Users u On tau.UserId = u.Id
  385. Where tau.IsDel = 0 And tau.TAId = {0}", id);
  386. var data = await _sqlSugar.SqlQueryable<TaskerDetailsView>(sql).ToListAsync();
  387. _result.Data = data;
  388. _result.Msg = string.Format("操作成功!");
  389. _result.Code = 0;
  390. return _result;
  391. }
  392. /// <summary>
  393. /// 任务归属人状态
  394. /// </summary>
  395. /// <param name="id"></param>
  396. /// <returns></returns>
  397. public async Task<Result> _TaskerStatus(int id)
  398. {
  399. if (id < 1)
  400. {
  401. _result.Msg = string.Format("请传入有效的Id参数!");
  402. return _result;
  403. }
  404. var data1 = await _sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.IsDel == 0 && it.Id == id).FirstAsync();
  405. if (data1 == null)
  406. {
  407. _result.Msg = string.Format("该任务不存在!");
  408. return _result;
  409. }
  410. var data2 = await _sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.IsDel == 0 && it.Id == data1.TAId).FirstAsync();
  411. _sqlSugar.BeginTran();
  412. var update1 = await _sqlSugar.Updateable<Pm_TaskRelevanceUser>()
  413. .SetColumns(it => it.TaskStatus == TaskerEnum.HaveKnown)
  414. .ExecuteCommandAsync();
  415. if (update1 < 1)
  416. {
  417. _result.Msg = string.Format("操作失败!");
  418. return _result;
  419. }
  420. _result.Msg = string.Format("操作成功!");
  421. _result.Code = 0;
  422. _sqlSugar.CommitTran();
  423. return _result;
  424. }
  425. /// <summary>
  426. /// 任务归属人设置开始状态
  427. /// </summary>
  428. /// <param name="id"></param>
  429. /// <returns></returns>
  430. public async Task<Result> _TaskerSetStartStatus(int userId, int id)
  431. {
  432. if (id < 1)
  433. {
  434. _result.Msg = string.Format("请传入有效的Id参数!");
  435. return _result;
  436. }
  437. //状态限制
  438. var selectData = await _sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.IsDel == 0 && it.UserId == userId && it.TAId == id).FirstAsync();
  439. if (selectData == null)
  440. {
  441. _result.Msg = string.Format("该任务不在!");
  442. return _result;
  443. }
  444. if (selectData.TaskStatus >= TaskerEnum.UnderWay)
  445. {
  446. _result.Msg = string.Format("该任务已知晓,不可重复设置!");
  447. return _result;
  448. }
  449. _sqlSugar.BeginTran();
  450. var update1 = await _sqlSugar.Updateable<Pm_TaskRelevanceUser>()
  451. .SetColumns(it => it.TaskStatus == TaskerEnum.UnderWay)
  452. .SetColumns(it => it.BeginTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  453. .Where(it => it.TAId == id)
  454. .Where(it => it.UserId == userId )
  455. .ExecuteCommandAsync();
  456. if (update1 < 1)
  457. {
  458. _result.Msg = string.Format("操作失败!");
  459. _sqlSugar.RollbackTran();
  460. return _result;
  461. }
  462. var update2 = await _sqlSugar.Updateable<Pm_TaskAllocation>()
  463. .SetColumns(it => it.Status == TaskEnum.UnderWay)
  464. .Where(it => it.Id == id)
  465. .ExecuteCommandAsync();
  466. if (update2 < 1)
  467. {
  468. _result.Msg = string.Format("操作失败!");
  469. _sqlSugar.RollbackTran();
  470. return _result;
  471. }
  472. _sqlSugar.CommitTran();
  473. _result.Msg = string.Format("操作成功!");
  474. _result.Code = 0;
  475. return _result;
  476. }
  477. /// <summary>
  478. /// 任务归属人设置完成状态
  479. /// 1.待审核
  480. /// </summary>
  481. /// <param name="id"></param>
  482. /// <returns></returns>
  483. public async Task<Result> _TaskerSetOverStatus(int userId, int id)
  484. {
  485. if (id < 1)
  486. {
  487. _result.Msg = string.Format("请传入有效的Id参数!");
  488. return _result;
  489. }
  490. //状态限制
  491. var selectData = await _sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.IsDel == 0 && it.UserId == userId && it.TAId == id).FirstAsync();
  492. if (selectData == null)
  493. {
  494. _result.Msg = string.Format("该任务不在!");
  495. return _result;
  496. }
  497. if (selectData.TaskStatus != TaskerEnum.UnderWay)
  498. {
  499. _result.Msg = string.Format("该任务已提交待审核状态,不可重复提交!");
  500. return _result;
  501. }
  502. _sqlSugar.BeginTran();
  503. var update1 = await _sqlSugar.Updateable<Pm_TaskRelevanceUser>()
  504. .SetColumns(it => it.TaskStatus == TaskerEnum.WaitConfirm)
  505. .SetColumns(it => it.OverTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  506. .Where(it => it.TAId == id)
  507. .Where(it => it.UserId == userId)
  508. .ExecuteCommandAsync();
  509. if (update1 < 1)
  510. {
  511. _result.Msg = string.Format("操作失败!");
  512. _sqlSugar.RollbackTran();
  513. return _result;
  514. }
  515. var update2 = await _sqlSugar.Updateable<Pm_TaskAllocation>()
  516. .SetColumns(it => it.Status == TaskEnum.UnderWay)
  517. .Where(it => it.Id == id)
  518. .ExecuteCommandAsync();
  519. if (update2 < 1)
  520. {
  521. _result.Msg = string.Format("操作失败!");
  522. _sqlSugar.RollbackTran();
  523. return _result;
  524. }
  525. _sqlSugar.CommitTran();
  526. _result.Msg = string.Format("操作成功!");
  527. _result.Code = 0;
  528. return _result;
  529. }
  530. /// <summary>
  531. /// 设置任务知晓
  532. /// </summary>
  533. /// <param name="id"></param>
  534. /// <returns></returns>
  535. public async Task<Result> _TaskSetHaveStatus(int id)
  536. {
  537. if (id < 1)
  538. {
  539. _result.Msg = string.Format("请传入有效的Id参数!");
  540. return _result;
  541. }
  542. var data1 = await _sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.IsDel == 0 && it.Id == id).FirstAsync();
  543. if (data1 == null)
  544. {
  545. _result.Msg = string.Format("该任务不存在!");
  546. return _result;
  547. }
  548. var data2 = await _sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.IsDel == 0 && it.Id == data1.TAId).FirstAsync();
  549. var update1 = await _sqlSugar.Updateable<Pm_TaskRelevanceUser>()
  550. .SetColumns(it => it.TaskStatus == TaskerEnum.HaveKnown)
  551. .ExecuteCommandAsync();
  552. if (update1 < 1)
  553. {
  554. _result.Msg = string.Format("操作失败!");
  555. return _result;
  556. }
  557. _result.Msg = string.Format("操作成功!");
  558. _result.Code = 0;
  559. _sqlSugar.CommitTran();
  560. return _result;
  561. }
  562. /// <summary>
  563. /// 设置任务审批状态
  564. /// </summary>
  565. /// <param name="id"></param>
  566. /// <returns></returns>
  567. public async Task<Result> _TaskSetAuditStatus(int id)
  568. {
  569. if (id < 1)
  570. {
  571. _result.Msg = string.Format("请传入有效的Id参数!");
  572. return _result;
  573. }
  574. var data1 = _sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.IsDel == 0 && it.Id == id).First();
  575. if (data1 == null)
  576. {
  577. _result.Msg = string.Format("该任务不存在或者该任务未分配给你!");
  578. return _result;
  579. }
  580. int _taId = data1.TAId;
  581. _sqlSugar.BeginTran();
  582. var update1 = _sqlSugar.Updateable<Pm_TaskRelevanceUser>()
  583. .SetColumns(it => it.TaskStatus == TaskerEnum.Finished)
  584. .Where(it => it.Id == id)
  585. .ExecuteCommand();
  586. if (update1 < 1)
  587. {
  588. _result.Msg = string.Format("操作失败!");
  589. _sqlSugar.RollbackTran();
  590. return _result;
  591. }
  592. //设置任务状态
  593. TaskEnum taskStatus = TaskEnum.Finished;
  594. var data2 = _sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.IsDel == 0 && it.TAId == _taId).ToList();
  595. var data3 = data2.Where(it => it.TaskStatus == TaskerEnum.Finished && it.Id != id).ToList();
  596. var data4 = data2.Where(it => it.TaskStatus == TaskerEnum.UnFinished && it.Id != id).ToList();
  597. if (data4.Count > 0) taskStatus = TaskEnum.UnFinished;
  598. if ((data2.Count - 1) == (data3.Count + data4.Count))
  599. {
  600. var update2 = _sqlSugar.Updateable<Pm_TaskAllocation>()
  601. .SetColumns(it => it.Status == taskStatus)
  602. .Where(it => it.Id == _taId)
  603. .ExecuteCommand();
  604. if (update2 < 1)
  605. {
  606. _result.Msg = string.Format("操作失败!");
  607. _sqlSugar.RollbackTran();
  608. return _result;
  609. }
  610. }
  611. _result.Msg = string.Format("操作成功!");
  612. _result.Code = 0;
  613. _sqlSugar.CommitTran();
  614. return _result;
  615. }
  616. /// <summary>
  617. /// 设置任务未完成状态
  618. /// </summary>
  619. /// <param name="id"></param>
  620. /// <returns></returns>
  621. public async Task<Result> _TaskSetUnFinishedStatus(int id, string cause)
  622. {
  623. if (id < 1)
  624. {
  625. _result.Msg = string.Format("请传入有效的Id参数!");
  626. return _result;
  627. }
  628. var data1 = await _sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.IsDel == 0 && it.Id == id).FirstAsync();
  629. if (data1 == null)
  630. {
  631. _result.Msg = string.Format("该任务不存在或者该任务未分配给你!");
  632. return _result;
  633. }
  634. int _taId = data1.TAId;
  635. _sqlSugar.BeginTran();
  636. var update1 = await _sqlSugar.Updateable<Pm_TaskRelevanceUser>()
  637. .SetColumns(it => it.TaskStatus == TaskerEnum.UnFinished)
  638. .SetColumns(it => it.Cause == cause)
  639. .Where(it => it.Id == id)
  640. .ExecuteCommandAsync();
  641. if (update1 < 1)
  642. {
  643. _result.Msg = string.Format("操作失败!");
  644. _sqlSugar.RollbackTran();
  645. return _result;
  646. }
  647. //设置任务状态
  648. var data2 = _sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.IsDel == 0 && it.TAId == _taId).ToList();
  649. var data3 = data2.Where(it => it.TaskStatus == TaskerEnum.Finished && it.Id != id).ToList();
  650. var data4 = data2.Where(it => it.TaskStatus == TaskerEnum.UnFinished && it.Id != id).ToList();
  651. if ((data2.Count - 1) == (data3.Count + data4.Count))
  652. {
  653. var update2 = _sqlSugar.Updateable<Pm_TaskAllocation>()
  654. .SetColumns(it => it.Status == TaskEnum.UnFinished)
  655. .Where(it => it.Id == _taId)
  656. .ExecuteCommand();
  657. if (update2 < 1)
  658. {
  659. _result.Msg = string.Format("操作失败!");
  660. _sqlSugar.RollbackTran();
  661. return _result;
  662. }
  663. }
  664. _result.Msg = string.Format("操作成功!");
  665. _result.Code = 0;
  666. _sqlSugar.CommitTran();
  667. return _result;
  668. }
  669. /// <summary>
  670. /// 任务确认完成
  671. /// </summary>
  672. /// <param name="dto"></param>
  673. /// <returns></returns>
  674. public async Task<Result> _TaskConfirmCompletion(int portType,int id)
  675. {
  676. if (portType == 1 || portType == 2 || portType == 3)
  677. {
  678. if (id < 1)
  679. {
  680. _result.Msg = string.Format("请传入有效的Id参数!");
  681. return _result;
  682. }
  683. var data = await _sqlSugar.Queryable<Pm_TaskRelevanceUser>()
  684. .Where(it => it.IsDel == 0 && it.Id == id && it.TaskStatus <= TaskerEnum.UnFinished)
  685. .ToListAsync();
  686. if (data.Count > 0)
  687. {
  688. _result.Msg = string.Format("本任务参与人员并未全部完成,不可确认任务完成!");
  689. return _result;
  690. }
  691. var update = await _sqlSugar.Updateable<Pm_TaskAllocation>()
  692. .SetColumns(it => it.IsComplete == 1)
  693. .SetColumns(it => it.Status == TaskEnum.Finished)
  694. .Where(it => it.Id == id)
  695. .ExecuteCommandAsync();
  696. if (update > 0)
  697. {
  698. _result.Code = 0;
  699. return _result;
  700. }
  701. else _result.Msg = "确认完成失败!";
  702. }
  703. else
  704. {
  705. _result.Msg = string.Format("请传入有效的PortType参数!");
  706. }
  707. return _result;
  708. }
  709. /// <summary>
  710. /// 任务评分
  711. /// </summary>
  712. /// <param name="dto"></param>
  713. /// <returns></returns>
  714. public async Task<Result> _TaskScore(TaskAllocationScoreDto dto)
  715. {
  716. int portType = dto.PortType;
  717. if (portType == 1 || portType == 2 || portType == 3)
  718. {
  719. if (dto.SubId < 1)
  720. {
  721. _result.Msg = string.Format("请传入有效的SubId参数!");
  722. return _result;
  723. }
  724. //var data = await _sqlSugar.Queryable<Pm_TaskAllocation>()
  725. // .Where(it => it.IsDel == 0 )
  726. // .FirstAsync();
  727. //if (data == null)
  728. //{
  729. // _result.Msg = string.Format("本任务尚未由发布人确认任务完成,不可评分!");
  730. // return _result;
  731. //}
  732. var data = _sqlSugar.Queryable<Pm_TaskRelevanceUser>()
  733. .Where(it => it.IsDel == 0 && it.Id == dto.SubId)
  734. .First();
  735. if (data == null)
  736. {
  737. _result.Msg = string.Format("本任务尚未由发布人确认任务完成,不可评分!");
  738. return _result;
  739. }
  740. if (data.TaskStatus != TaskerEnum.Finished)
  741. {
  742. _result.Msg = string.Format("本任务尚未由发布人确认任务完成,不可评分!");
  743. return _result;
  744. }
  745. Pm_TaskRelevanceUser _TaskRelevanceUser = new Pm_TaskRelevanceUser() {
  746. Id = dto.SubId,
  747. Score = dto.Score,
  748. Remark = dto.ScoreRemark
  749. };
  750. var update = await _sqlSugar.Updateable<Pm_TaskRelevanceUser>(_TaskRelevanceUser)
  751. .UpdateColumns(it => new { it.Score, it.Remark })
  752. .WhereColumns(it => it.Id)
  753. .ExecuteCommandAsync();
  754. if (update > 0)
  755. {
  756. _result.Code = 0;
  757. return _result;
  758. }
  759. else _result.Msg = "评分失败!";
  760. }
  761. else
  762. {
  763. _result.Msg = string.Format("请传入有效的PortType参数!");
  764. }
  765. return _result;
  766. }
  767. /// <summary>
  768. /// 任务终止
  769. /// </summary>
  770. /// <param name="dto"></param>
  771. /// <returns></returns>
  772. public async Task<Result> _TaskTermination(int taskId)
  773. {
  774. if (taskId < 1)
  775. {
  776. _result.Msg = string.Format("请传入有效的taskId参数!");
  777. return _result;
  778. }
  779. _sqlSugar.BeginTran();
  780. var taskUpdate = _sqlSugar.Updateable<Pm_TaskAllocation>()
  781. .SetColumns(it => it.Status == TaskEnum.TaskStop)
  782. .Where(it => it.Id == taskId)
  783. .ExecuteCommand();
  784. if (taskUpdate < 1)
  785. {
  786. _result.Msg = "任务终止失败!";
  787. _sqlSugar.RollbackTran();
  788. return _result;
  789. }
  790. var subTaskUpdate = _sqlSugar.Updateable<Pm_TaskRelevanceUser>()
  791. .SetColumns(it => it.TaskStatus == TaskerEnum.TaskStop)
  792. .Where(it => it.TAId == taskId)
  793. .ExecuteCommand();
  794. if (taskUpdate < 1)
  795. {
  796. _result.Msg = "任务终止失败!";
  797. _sqlSugar.RollbackTran();
  798. return _result;
  799. }
  800. _result.Msg = "操作成功!";
  801. _result.Code = 0;
  802. _sqlSugar.CommitTran();
  803. return _result;
  804. }
  805. /// <summary>
  806. /// 任务删除
  807. /// </summary>
  808. /// <param name="dto"></param>
  809. /// <returns></returns>
  810. public async Task<Result> _TaskDel(int taskId)
  811. {
  812. if (taskId < 1)
  813. {
  814. _result.Msg = string.Format("请传入有效的taskId参数!");
  815. return _result;
  816. }
  817. _sqlSugar.BeginTran();
  818. var taskUpdate = _sqlSugar.Updateable<Pm_TaskAllocation>()
  819. .SetColumns(it => it.IsDel == 1)
  820. .Where(it => it.Id == taskId)
  821. .ExecuteCommand();
  822. if (taskUpdate < 1)
  823. {
  824. _result.Msg = "任务删除失败!";
  825. _sqlSugar.RollbackTran();
  826. return _result;
  827. }
  828. var subTaskUpdate = _sqlSugar.Updateable<Pm_TaskRelevanceUser>()
  829. .SetColumns(it => it.IsDel == 1)
  830. .Where(it => it.TAId == taskId)
  831. .ExecuteCommand();
  832. if (taskUpdate < 1)
  833. {
  834. _result.Msg = "任务删除失败!";
  835. _sqlSugar.RollbackTran();
  836. return _result;
  837. }
  838. _result.Msg = "操作成功!";
  839. _result.Code = 0;
  840. _sqlSugar.CommitTran();
  841. return _result;
  842. }
  843. }
  844. }