using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.IServices.FM; using APT.BaseData.Domain.IServices; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.OG; using APT.MS.Domain.Enums; using APT.Utility; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.Enums; using InfluxData.Net.InfluxDb.Models.Responses; namespace APT.SC.WebApi.Controllers.Api.OG { [Route("api/OG/OGEventGet")] public class OGEventGetController : AuthorizeApiController { IFMNotificationTaskService NotificationTaskService { get; set; } public OGEventGetController(IFMNotificationTaskService notificationTaskService, IPFCodeRuleService codeRuleService) { NotificationTaskService = notificationTaskService; } /// /// 更新 /// /// /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_OG_EVENT_GET entity) { return SafeExecute(() => { if (entity.USER_ID == Guid.Empty) { entity.USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; } if (entity.DEPARTMENT_ID == Guid.Empty) { entity.DEPARTMENT_ID = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID; } if (entity.START_TIME == null) { entity.START_TIME = DateTime.Now; } List sendNotices = null; T_FM_NOTIFICATION_TASK finishNotice = null; List lists = new List(); if (entity.STATUS != (int)OGEventStatus.草稿) { throw new Exception("当前状态不可提交"); } if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify")) { if (entity.TaskID != Guid.Empty) { finishNotice = NotificationTaskService.GetTaskFinishModel(entity.TaskID, "OG030_SHOWPRINT"); } entity.STATUS = OGEventStatus.征集中; var allUsers = GetEntities(t => t.DEPARTMENT_ID != null && t.ENABLE_STATUS == (int)FMEnableStatusEnum.启用&& !t.CODE.Contains("admin"), new BaseFilter(entity.ORG_ID), new string[] { "Nav_Department" }).ToList(); var allSendUserTitles = new List(); var allSendDataIds = new List(); var allSendUserIds = new List(); var allSendUserNames = new List(); foreach (var user in allUsers) { T_OG_EVENT_GET_DETAIL item = new T_OG_EVENT_GET_DETAIL { ID = Guid.NewGuid(), EVENT_ID = entity.ID, ORG_ID = entity.ORG_ID, USER_ID = user.ID, REPLY_USER_ID = user.Nav_Department.USER_ID, STATUS = 0, }; lists.Add(item); allSendUserTitles.Add("工余事件征集意见填写"); allSendDataIds.Add(item.ID); allSendUserIds.Add(user.ID); allSendUserNames.Add(user.NAME); } sendNotices = NotificationTaskService.InsertUserNoticeTaskModels(allSendUserTitles, allSendDataIds, entity.ORG_ID.Value, allSendUserIds, allSendUserNames, DateTime.Now, (DateTime)entity.END_TIME, 1, "OG030_EDIT"); } UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (lists != null && lists.Any()) BantchSaveEntityNoCommit(lists); if (finishNotice != null) UpdateEntityNoCommit(finishNotice); if (sendNotices != null && sendNotices.Any()) BantchAddEntityNoCommit(sendNotices); }); return true; }); } /// /// 用户数据 /// /// /// [HttpPost, Route("GetUser")] public JsonActionResult GetUser([FromBody] KeywordFilter filter) { return SafeExecute(() => { return GetEntity(null, filter); }); } /// /// 用户数据提交 /// /// /// [HttpPost, Route("UpdateUser")] public JsonActionResult UpdateUser([FromBody] T_OG_EVENT_GET_DETAIL entity) { return SafeExecute(() => { var curUid = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; var eventGet = GetEntity(t => t.ID == entity.EVENT_ID); if (entity.STATUS == OGEventGetUserStatus.未填写) { if (curUid != entity.USER_ID) { throw new Exception("您无权限修改他人的数据"); } } else if (entity.STATUS == OGEventGetUserStatus.反馈中) { if (curUid != entity.REPLY_USER_ID) { throw new Exception("您无权限对数据进行反馈"); } } T_FM_NOTIFICATION_TASK sendNotice = null; T_FM_NOTIFICATION_TASK finishNotice = null; if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify")) { if (eventGet.STATUS != OGEventStatus.征集中 || DateTime.Now > eventGet.END_TIME.Value) { throw new Exception("当前状态不可提交数据,已超过截止征集时间!"); } if (entity.TaskID != Guid.Empty) { finishNotice = NotificationTaskService.GetTaskFinishModel(entity.TaskID, "OG030_REPLYVIEW"); } if (entity.STATUS == OGEventGetUserStatus.未填写) { if (entity.Nav_Items.Any()) { entity.STATUS = OGEventGetUserStatus.反馈中; sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("工余事件征集反馈", entity.ID, entity.ORG_ID.Value, (Guid)entity.REPLY_USER_ID, GetEntity(entity.REPLY_USER_ID.Value).NAME, DateTime.Now, (DateTime)eventGet.END_TIME, 1, "OG030_REPLY"); } else { entity.STATUS = OGEventGetUserStatus.完成; } } else if (entity.STATUS == OGEventGetUserStatus.反馈中) { entity.STATUS = OGEventGetUserStatus.完成; } } var Nav_Items = entity.Nav_Items; entity.Nav_Items = null; var Nav_Files = entity.Nav_Files; entity.Nav_Files = null; UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (Nav_Files != null) BantchSaveEntityNoCommit(Nav_Files); if (Nav_Items != null) BantchSaveEntityNoCommit(Nav_Items); if (finishNotice != null) UpdateEntityNoCommit(finishNotice); if (sendNotice != null) AddEntityNoCommit(sendNotice); }); return true; }); } /// /// 用户数据提交 /// /// /// [HttpPost, Route("Agree")] public JsonActionResult Agree([FromBody] KeywordFilter filter) { return SafeExecute(() => { var entity = GetEntity(filter.Keyword); if (entity == null) { throw new Exception("未查到相应数据"); } var curUid = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; if (entity.USER_ID != curUid) { throw new Exception("您无权限编辑当前数据"); } if (entity.STATUS != OGEventStatus.汇总中) { throw new Exception("当前状态无法提交,可能您已经提交过当前数据,请刷新页面重试"); } entity.STATUS = OGEventStatus.完成; Guid TASK_ID = Guid.Parse(filter.Parameter1); var finishNotice = NotificationTaskService.GetTaskFinishModel(TASK_ID); var sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("请组织预防工余意外培训", entity.ID, filter.GetOrgId(), (Guid)entity.USER_ID, GetEntity(entity.USER_ID.Value).NAME, DateTime.Now,DateTime.Now.AddDays(1), (int)FMNoticeTypeEnum.今日提醒,"PF135"); UnifiedCommit(() => { UpdateEntityNoCommit(entity); UpdateEntityNoCommit(finishNotice); AddEntityNoCommit(sendNotice); }); return true; }); } } }