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 APT.BaseData.Domain.Entities; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace APT.SC.WebApi.Controllers.Api.OG { [Route("api/OG/OGInnerContact")] public class OGInnerContactController : AuthorizeApiController { IFMNotificationTaskService NotificationTaskService { get; set; } public OGInnerContactController(IFMNotificationTaskService notificationTaskService, IPFCodeRuleService codeRuleService) { NotificationTaskService = notificationTaskService; } /// /// 更新 /// /// /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody]T_OG_INNER_CONTACT entity) { return SafeExecute(() => { if (entity.USER_ID == null) { if (entity.STATUS == (int)OGEmployeeOpinionStatus.草稿) { entity.USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; } } if (entity.USER_ID == null) { throw new Exception("用户信息错误"); } List sendNotice = new List(); if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify")) { if (entity.STATUS != (int)OGInnerContactStatus.草稿 && entity.STATUS != OGInnerContactStatus.落实中) { throw new Exception("当前状态不可提交"); } if (entity.STATUS == (int)OGInnerContactStatus.草稿) { if (entity.FORM_DEPARTMENT_ID == null) { throw new Exception("请指定责任部门"); } if (entity.FROM_USER_ID == null) { throw new Exception("请指定沟通人员"); } if (entity.TO_USER_ID == null) { throw new Exception("请指定被沟通人员"); } if (entity.DO_DEPARTMENT_ID != null && entity.DO_USER_ID == null) { throw new Exception("当前已选落实部门,请指定落实人员"); } if (entity.DO_USER_ID != null && entity.DO_DEPARTMENT_ID == null) { var u = GetEntity(entity.DO_USER_ID.Value); if (u != null) { entity.DO_DEPARTMENT_ID = u.DEPARTMENT_ID; } } } if(entity.FROM_USER_ID == APT.Infrastructure.Api.AppContext.CurrentSession.UserID) { entity.FORM_USER_TIME = DateTime.Now; } else { sendNotice.Add(NotificationTaskService.InsertUserNoticeTaskModel("内部联系沟通确认", entity.ID, entity.ORG_ID, entity.FROM_USER_ID.Value, GetEntity(entity.FROM_USER_ID.Value).NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "OG015_SHOWPRINT")); } sendNotice.Add(NotificationTaskService.InsertUserNoticeTaskModel("内部联系沟通确认", entity.ID, entity.ORG_ID, entity.TO_USER_ID.Value, GetEntity(entity.TO_USER_ID.Value).NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "OG015_SHOWPRINT")); if (entity.STATUS == (int)OGInnerContactStatus.草稿) { if (entity.DO_USER_ID == null) { entity.STATUS = OGInnerContactStatus.完成; return true; } entity.STATUS = OGInnerContactStatus.落实中; } else { entity.STATUS = OGInnerContactStatus.完成; } } var Nav_ItemFiles = entity.Nav_ItemFiles; entity.Nav_ItemFiles = null; var Nav_DoFiles = entity.Nav_DoFiles; entity.Nav_DoFiles = null; UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (Nav_ItemFiles != null) BantchSaveEntityNoCommit(Nav_ItemFiles); if (Nav_DoFiles != null) BantchSaveEntityNoCommit(Nav_DoFiles); if (sendNotice != null) BantchSaveEntityNoCommit(sendNotice); }); return true; }); } /// /// 内部联系确认 /// /// /// [HttpPost, Route("PersonalAgree")] public JsonActionResult PersonalAgree([FromBody] T_OG_INNER_CONTACT entity) { return SafeExecute(() => { var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId; var userID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID; var taskID = entity.TaskID; entity = GetEntity(entity.ID); T_FM_NOTIFICATION_TASK sendNotice = null; T_FM_NOTIFICATION_TASK finishNotice = null; if (entity != null) { if(userID == entity.FROM_USER_ID) { entity.FORM_USER_TIME=DateTime.Now; } else { entity.TO_USER_TIME = DateTime.Now; } if (entity.FORM_USER_TIME != DateTime.MinValue && entity.TO_USER_TIME != DateTime.MinValue) { sendNotice=NotificationTaskService.InsertUserNoticeTaskModel("内部联系沟通落实", entity.ID, entity.ORG_ID, entity.DO_USER_ID.Value, GetEntity(entity.DO_USER_ID.Value).NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "OG016_EDIT"); } } if (taskID != Guid.Empty) { finishNotice = NotificationTaskService.FOGetTaskFinishModel(taskID, entity.ID); } UnifiedCommit(() => { AddEntityNoCommit(sendNotice); UpdateEntityNoCommit(entity); UpdateEntityNoCommit(finishNotice); }); return true; }); } /// /// 落实人员填写 /// /// /// [HttpPost, Route("FullUpdateConfirm")] public JsonActionResult FullUpdateConfirm([FromBody] T_OG_INNER_CONTACT entity) { return SafeExecute(() => { List sendNotice = new List(); T_FM_NOTIFICATION_TASK finishNotice = null; if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify")) { if (entity.STATUS != (int)OGInnerContactStatus.草稿 && entity.STATUS != OGInnerContactStatus.落实中) { throw new Exception("当前状态不可提交"); } sendNotice.Add(NotificationTaskService.InsertUserNoticeTaskModel("内部联系沟通完成确认", entity.ID, entity.ORG_ID, entity.FROM_USER_ID.Value, GetEntity(entity.FROM_USER_ID.Value).NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "OG015_SHOWPRINT")); sendNotice.Add(NotificationTaskService.InsertUserNoticeTaskModel("内部联系沟通完成确认", entity.ID, entity.ORG_ID, entity.TO_USER_ID.Value, GetEntity(entity.TO_USER_ID.Value).NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "OG015_SHOWPRINT")); entity.STATUS = OGInnerContactStatus.完成; if (entity.TaskID != Guid.Empty) { finishNotice = NotificationTaskService.FOGetTaskFinishModel(entity.TaskID, entity.ID); } } var Nav_ItemFiles = entity.Nav_ItemFiles; entity.Nav_ItemFiles = null; var Nav_DoFiles = entity.Nav_DoFiles; entity.Nav_DoFiles = null; UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (Nav_ItemFiles != null) BantchSaveEntityNoCommit(Nav_ItemFiles); if (Nav_DoFiles != null) BantchSaveEntityNoCommit(Nav_DoFiles); if (sendNotice != null) BantchSaveEntityNoCommit(sendNotice); UpdateEntityNoCommit(finishNotice); }); return true; }); } } }