using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Filter; using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.Extend.Entitys; using JNPF.Extend.Entitys.Dto.ProjectGantt; using JNPF.FriendlyException; using JNPF.Systems.Entitys.Permission; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; namespace JNPF.Extend; /// /// 项目计划 /// 版 本:V3.2 /// 版 权:拓通智联科技有限公司(http://www.tuotong-tech.com) /// 日 期:2021-06-01 . /// [ApiDescriptionSettings(Tag = "Extend", Name = "ProjectGantt", Order = 600)] [Route("api/extend/[controller]")] public class ProjectGanttService : IDynamicApiController, ITransient { private readonly ISqlSugarRepository _repository; public ProjectGanttService(ISqlSugarRepository repository) { _repository = repository; } #region GET /// /// 项目列表. /// /// 请求参数 /// [HttpGet("")] public async Task GetList([FromQuery] KeywordInput input) { var data = await _repository.AsQueryable().Where(x => x.Type == 1 && x.DeleteMark == null) .WhereIF(input.keyword.IsNotEmptyOrNull(), x => x.FullName.Contains(input.keyword)) .OrderBy(x => x.SortCode).OrderBy(x => x.CreatorTime, OrderByType.Desc) .OrderByIF(!string.IsNullOrEmpty(input.keyword), t => t.LastModifyTime, OrderByType.Desc).ToListAsync(); var output = data.Adapt>(); await GetManagersInfo(output); return new { list = output }; } /// /// 任务列表. /// /// 请求参数. /// 项目Id. /// [HttpGet("{projectId}/Task")] public async Task GetTaskList([FromQuery] KeywordInput input, string projectId) { var data = await _repository.AsQueryable() .Where(x => x.Type == 2 && x.ProjectId == projectId && x.DeleteMark == null) .OrderBy(x => x.SortCode).OrderBy(x => x.CreatorTime, OrderByType.Desc) .OrderByIF(!string.IsNullOrEmpty(input.keyword), t => t.LastModifyTime, OrderByType.Desc).ToListAsync(); data.Add(await _repository.GetFirstAsync(x => x.Id == projectId)); if (!string.IsNullOrEmpty(input.keyword)) { data = data.TreeWhere(t => t.FullName.Contains(input.keyword), t => t.Id, t => t.ParentId); } var output = data.Adapt>(); return new { list = output.ToTree() }; } /// /// 任务树形. /// /// 项目Id. /// [HttpGet("{projectId}/Task/Selector/{id}")] public async Task GetTaskTreeView(string projectId, string id) { var data = (await _repository.AsQueryable().Where(x => x.Type == 2 && x.ProjectId == projectId && x.DeleteMark == null).OrderBy(x => x.CreatorTime, OrderByType.Desc).ToListAsync()); data.Add(await _repository.GetFirstAsync(x => x.Id == projectId)); if (!id.Equals("0")) { data.RemoveAll(x => x.Id == id); } var output = data.Adapt>(); return new { list = output.ToTree() }; } /// /// 信息. /// /// 主键值. /// [HttpGet("{id}")] public async Task GetInfo(string id) { var data = (await _repository.GetFirstAsync(x => x.Id == id && x.DeleteMark == null)).Adapt(); return data; } /// /// 项目任务信息. /// /// 主键值. /// [HttpGet("Task/{taskId}")] public async Task GetTaskInfo(string taskId) { return (await _repository.GetFirstAsync(x => x.Id == taskId && x.DeleteMark == null)).Adapt(); } #endregion #region POST /// /// 删除. /// /// 主键值 /// [HttpDelete("{id}")] public async Task Delete(string id) { if (await _repository.IsAnyAsync(x => x.ParentId != id && x.DeleteMark == null)) { var entity = await _repository.GetFirstAsync(x => x.Id == id && x.DeleteMark == null); if (entity != null) { int isOk = await _repository.AsSugarClient().Updateable(entity).CallEntityMethod(m => m.Delete()).UpdateColumns(it => new { it.DeleteMark, it.DeleteTime, it.DeleteUserId }).ExecuteCommandAsync(); if (isOk < 1) throw Oops.Oh(ErrorCode.COM1002); } else { throw Oops.Oh(ErrorCode.COM1005); } } else { throw Oops.Oh(ErrorCode.D1007); } } /// /// 创建. /// /// 实体对象. /// [HttpPost("")] public async Task Create([FromBody] ProjectGanttCrInput input) { if (await _repository.IsAnyAsync(x => x.EnCode == input.enCode && x.DeleteMark == null) || await _repository.IsAnyAsync(x => x.FullName == input.fullName && x.DeleteMark == null)) throw Oops.Oh(ErrorCode.COM1004); var entity = input.Adapt(); entity.Type = 1; entity.ParentId = "0"; var isOk = await _repository.AsSugarClient().Insertable(entity).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync(); if (isOk < 1) throw Oops.Oh(ErrorCode.COM1000); } /// /// 编辑. /// /// 主键值. /// 实体对象. /// [HttpPut("{id}")] public async Task Update(string id, [FromBody] ProjectGanttUpInput input) { if (await _repository.IsAnyAsync(x => x.Id != id && x.EnCode == input.enCode && x.DeleteMark == null) || await _repository.IsAnyAsync(x => x.Id != id && x.FullName == input.fullName && x.DeleteMark == null)) throw Oops.Oh(ErrorCode.COM1004); var entity = input.Adapt(); var isOk = await _repository.AsSugarClient().Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync(); if (isOk < 1) throw Oops.Oh(ErrorCode.COM1001); } /// /// 创建. /// /// 实体对象. /// [HttpPost("Task")] public async Task CreateTask([FromBody] ProjectGanttTaskCrInput input) { var entity = input.Adapt(); entity.Type = 2; var isOk = await _repository.AsSugarClient().Insertable(entity).CallEntityMethod(m => m.Creator()).ExecuteCommandAsync(); if (isOk < 1) throw Oops.Oh(ErrorCode.COM1000); } /// /// 编辑. /// /// 主键值. /// 实体对象. /// [HttpPut("Task/{id}")] public async Task UpdateTask(string id, [FromBody] ProjectGanttTaskUpInput input) { var entity = input.Adapt(); var isOk = await _repository.AsSugarClient().Updateable(entity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync(); if (isOk < 1) throw Oops.Oh(ErrorCode.COM1001); } #endregion #region PrivateMethod /// /// 项目参与人员. /// /// /// private async Task GetManagersInfo(List outputList) { foreach (var output in outputList) { foreach (var id in output.managerIds.Split(",")) { var managerInfo = new ManagersInfo(); var userInfo = await _repository.AsSugarClient().Queryable().FirstAsync(x => x.Id == id && x.DeleteMark == null); if (userInfo != null) { managerInfo.account = userInfo.RealName + "/" + userInfo.Account; managerInfo.headIcon = string.IsNullOrEmpty(userInfo.HeadIcon) ? string.Empty : "/api/file/Image/userAvatar/" + userInfo.HeadIcon; output.managersInfo.Add(managerInfo); } } } } #endregion }