mh_jy_safe/APT.MicroApi/APT.SC.WebApi/Controllers/Api/OGController/17OGEventGetController.cs

226 lines
10 KiB
C#
Raw Normal View History

2025-08-25 09:56:57 +08:00
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<T_OG_EVENT_GET>
{
IFMNotificationTaskService NotificationTaskService { get; set; }
public OGEventGetController(IFMNotificationTaskService notificationTaskService, IPFCodeRuleService codeRuleService)
{
NotificationTaskService = notificationTaskService;
}
/// <summary>
/// 更新
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost, Route("FullUpdate")]
public JsonActionResult<bool> FullUpdate([FromBody] T_OG_EVENT_GET entity)
{
return SafeExecute<bool>(() =>
{
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<T_FM_NOTIFICATION_TASK> sendNotices = null;
T_FM_NOTIFICATION_TASK finishNotice = null;
List<T_OG_EVENT_GET_DETAIL> lists = new List<T_OG_EVENT_GET_DETAIL>();
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_FM_USER>(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<string>();
var allSendDataIds = new List<Guid>();
var allSendUserIds = new List<Guid>();
var allSendUserNames = new List<string>();
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;
});
}
/// <summary>
/// 用户数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost, Route("GetUser")]
public JsonActionResult<T_OG_EVENT_GET_DETAIL> GetUser([FromBody] KeywordFilter filter)
{
return SafeExecute(() =>
{
return GetEntity<T_OG_EVENT_GET_DETAIL>(null, filter);
});
}
/// <summary>
/// 用户数据提交
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost, Route("UpdateUser")]
public JsonActionResult<bool> UpdateUser([FromBody] T_OG_EVENT_GET_DETAIL entity)
{
return SafeExecute(() =>
{
var curUid = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
var eventGet = GetEntity<T_OG_EVENT_GET>(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<T_FM_USER>(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;
});
}
/// <summary>
/// 用户数据提交
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost, Route("Agree")]
public JsonActionResult<bool> Agree([FromBody] KeywordFilter filter)
{
return SafeExecute(() =>
{
var entity = GetEntity<T_OG_EVENT_GET>(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<T_FM_USER>(entity.USER_ID.Value).NAME, DateTime.Now,DateTime.Now.AddDays(1), (int)FMNoticeTypeEnum.,"PF135");
UnifiedCommit(() =>
{
UpdateEntityNoCommit(entity);
UpdateEntityNoCommit(finishNotice);
AddEntityNoCommit(sendNotice);
});
return true;
});
}
}
}