317 lines
15 KiB
C#
317 lines
15 KiB
C#
using APT.BaseData.Domain.Entities;
|
|
using APT.BaseData.Domain.Entities.FM;
|
|
using APT.BaseData.Domain.Enums;
|
|
using APT.BaseData.Domain.Enums.PF;
|
|
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;
|
|
|
|
|
|
namespace APT.SC.WebApi.Controllers.Api.OG
|
|
{
|
|
[Route("api/OG/OGSafePdtSigned")]
|
|
public class OGSafePdtSignedController : AuthorizeApiController<T_OG_SAFE_PDT_SIGNED>
|
|
{
|
|
IFMNotificationTaskService NotificationTaskService { get; set; }
|
|
public OGSafePdtSignedController(IFMNotificationTaskService notificationTaskService, IPFCodeRuleService codeRuleService)
|
|
{
|
|
NotificationTaskService = notificationTaskService;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 更新
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("FullUpdate")]
|
|
public JsonActionResult<bool> FullUpdate([FromBody] T_OG_SAFE_PDT_SIGNED entity)
|
|
{
|
|
return SafeExecute<bool>(() =>
|
|
{
|
|
|
|
var Nav_SafePdtSignedPost = entity.Nav_SafePdtSignedPost;
|
|
entity.Nav_SafePdtSignedPost = null;
|
|
List<T_FM_NOTIFICATION_TASK> notices = new List<T_FM_NOTIFICATION_TASK>();
|
|
if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify"))
|
|
{
|
|
if (entity.STATUS != PFStandardStatus.Draft)
|
|
{
|
|
throw new Exception("已发送!");
|
|
}
|
|
entity.STATUS = PFStandardStatus.Sign;
|
|
entity.ANNUAL = DateTime.Now.Year;
|
|
var allSendUserTitles = new List<string>();
|
|
var allSendDataIds = new List<Guid>();
|
|
var allSendUserIds = new List<Guid>();
|
|
var allSendUserNames = new List<string>();
|
|
foreach (var user in Nav_SafePdtSignedPost.Where(t => t.IS_DELETED == false))
|
|
{
|
|
if (user.CHARGE_USER_ID == Guid.Empty || user.CHARGE_USER_ID == null)
|
|
{
|
|
throw new Exception("签订人员负责人不能为空!");
|
|
}
|
|
allSendUserTitles.Add(DateTime.Now.ToShortDateString() + "安全生产责任制个人签订表");
|
|
allSendDataIds.Add(entity.ID);
|
|
allSendUserIds.Add(user.ID);
|
|
allSendUserNames.Add("");
|
|
}
|
|
notices = NotificationTaskService.InsertUserNoticeTaskModels(allSendUserTitles, allSendDataIds, entity.ORG_ID, allSendUserIds, allSendUserNames, DateTime.Now, DateTime.Now.AddDays(7), 1, "OG001_SHOWPRINT");
|
|
}
|
|
UnifiedCommit(() =>
|
|
{
|
|
UpdateEntityNoCommit(entity);
|
|
if (Nav_SafePdtSignedPost != null && Nav_SafePdtSignedPost.Any())
|
|
BantchSaveEntityNoCommit(Nav_SafePdtSignedPost);
|
|
if (notices != null && notices.Any())
|
|
BantchAddEntityNoCommit(notices);
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 安环部负责人审阅
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("Agree")]
|
|
public JsonActionResult<bool> Agree([FromBody] T_OG_SAFE_PDT_SIGNED entity)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
|
|
var signeds = GetEntities<T_OG_SAFE_PDT_SIGNED>(t => t.TRIGGER_TYPE == OGPersonalSignedTriggerType.任务触发 &&
|
|
t.STATUS == PFStandardStatus.Sign &&
|
|
t.ANNUAL == DateTime.Now.Year,
|
|
new BaseFilter(entity.ORG_ID)).ToList();
|
|
if (signeds == null || signeds.Count == 0)
|
|
{
|
|
return true;
|
|
}
|
|
var signedPosts = GetEntities<T_OG_SAFE_PDT_SIGNED_POST>(t => t.Nav_SafePdtSigned.TRIGGER_TYPE == OGPersonalSignedTriggerType.任务触发 &&
|
|
t.Nav_SafePdtSigned.STATUS == PFStandardStatus.Sign &&
|
|
t.Nav_SafePdtSigned.ANNUAL == DateTime.Now.Year,
|
|
new BaseFilter(entity.ORG_ID),
|
|
new string[] { "Nav_SCPost", "Nav_ChargeUser.Nav_Department" }).ToList();
|
|
signeds.ForEach(signed =>
|
|
{
|
|
signed.STATUS = PFStandardStatus.Archived;
|
|
});
|
|
var finishNotice = NotificationTaskService.FOGetTaskFinishModel(entity.TaskID, entity.ID);
|
|
var checkList = new List<T_OG_SAFE_PDT_ASSESS_PLAN_CHECK>();
|
|
var allSendUserTitles = new List<string>();
|
|
var allSendDataIds = new List<Guid>();
|
|
var allSendUserIds = new List<Guid>();
|
|
var allSendUserNames = new List<string>();
|
|
foreach (var item in signedPosts)
|
|
{
|
|
var isExist = checkList.Where(t => t.USER_ID == item.CHARGE_USER_ID);
|
|
if (!isExist.Any())
|
|
{
|
|
T_OG_SAFE_PDT_ASSESS_PLAN_CHECK check = new T_OG_SAFE_PDT_ASSESS_PLAN_CHECK
|
|
{
|
|
ID = Guid.NewGuid(),
|
|
TIME = DateTime.Now,
|
|
DEPARTMENT_ID = item.Nav_ChargeUser.DEPARTMENT_ID,
|
|
USER_ID = item.CHARGE_USER_ID,
|
|
LEVEL = (FMDepartmentType)item.Nav_ChargeUser.Nav_Department.DEPARTMENT_TYPE,
|
|
STATUS = PFStandardStatus.Draft,
|
|
ORG_ID = item.ORG_ID,
|
|
ANNUAL = DateTime.Now.Year,
|
|
};
|
|
checkList.Add(check);
|
|
allSendUserTitles.Add("安全生产责任制考核方案审核");
|
|
allSendDataIds.Add(check.ID);
|
|
allSendUserIds.Add((Guid)item.CHARGE_USER_ID);
|
|
allSendUserNames.Add(item.Nav_ChargeUser.NAME);
|
|
}
|
|
}
|
|
var sendNotices = NotificationTaskService.InsertUserNoticeTaskModels(allSendUserTitles, allSendDataIds, entity.ORG_ID.Value, allSendUserIds, allSendUserNames, DateTime.Now, DateTime.Now.AddDays(1), 1, "OG004");
|
|
UnifiedCommit(() =>
|
|
{
|
|
BantchSaveEntityNoCommit(signeds);
|
|
if (finishNotice != null)
|
|
UpdateEntityNoCommit(finishNotice);
|
|
if (checkList.Any())
|
|
BantchSaveEntityNoCommit(checkList);
|
|
if (sendNotices.Any())
|
|
BantchSaveEntityNoCommit(sendNotices);
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
public class SafePdtSignedModel
|
|
{
|
|
public List<T_OG_SAFE_PDT_SIGNED> Nav_Signed { get; set; }
|
|
|
|
public int SafePdtSignedStatus { get; set; }
|
|
}
|
|
/// <summary>
|
|
/// 获得单条实体数据
|
|
/// </summary>
|
|
/// <param name="filter">过滤实体</param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("FullGet")]
|
|
public JsonActionResult<T_OG_SAFE_PDT_SIGNED> FullGet([FromBody] KeywordFilter filter)
|
|
{
|
|
JsonActionResult<T_OG_SAFE_PDT_SIGNED> jsonActionResult = new JsonActionResult<T_OG_SAFE_PDT_SIGNED>();
|
|
var data = WitEntity(null, filter);
|
|
if (data.Data == null)
|
|
{
|
|
var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString();
|
|
var signpost = GetEntity<T_OG_SAFE_PDT_SIGNED_POST>(id);
|
|
filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value = signpost.SAFE_PDT_SIGNED_ID;
|
|
data = WitEntity(null, filter);
|
|
T_OG_SAFE_PDT_SIGNED model = data.Data;
|
|
jsonActionResult.Data = model;
|
|
}
|
|
else
|
|
{
|
|
T_OG_SAFE_PDT_SIGNED model = data.Data;
|
|
if (model != null && model.Nav_SafePdtSignedPost != null && model.Nav_SafePdtSignedPost.Count() > 0)
|
|
{
|
|
var Nav_SafePdtSignedPost = model.Nav_SafePdtSignedPost;
|
|
var user_id = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
|
|
var isChargeUser = Nav_SafePdtSignedPost.FirstOrDefault(t => t.USER_ID == user_id);
|
|
Guid? charge_user = Guid.Empty;
|
|
if (isChargeUser == null)
|
|
{
|
|
charge_user = user_id;
|
|
}
|
|
else
|
|
{
|
|
charge_user = isChargeUser.CHARGE_USER_ID;
|
|
}
|
|
model.Nav_SafePdtSignedPost = Nav_SafePdtSignedPost.Where(t => t.CHARGE_USER_ID == charge_user).ToList();
|
|
}
|
|
jsonActionResult.Data = model;
|
|
}
|
|
return jsonActionResult;
|
|
}
|
|
/// <summary>
|
|
/// 责任人签订
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("UserAgree")]
|
|
public JsonActionResult<bool> UserAgree([FromBody] T_OG_SAFE_PDT_SIGNED entity)
|
|
{
|
|
return SafeExecute<bool>(() =>
|
|
{
|
|
var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId;
|
|
var userID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
|
|
var baseFilter = new BaseFilter(orgId);
|
|
baseFilter.Include = new string[] { "Nav_ChargeUser" };
|
|
var signedPosts = GetEntities<T_OG_SAFE_PDT_SIGNED_POST>(t => t.SAFE_PDT_SIGNED_ID == entity.ID, baseFilter);
|
|
var currUser = signedPosts.Where(t => t.USER_ID == userID);
|
|
T_FM_NOTIFICATION_TASK finishNotice = null;
|
|
T_FM_NOTIFICATION_TASK sendNotice = null;
|
|
T_OG_SAFE_PDT_SIGNED signed = null;
|
|
if (currUser != null && currUser.Any())
|
|
{
|
|
signed = GetEntity<T_OG_SAFE_PDT_SIGNED>(entity.ID);
|
|
signed.STATUS = PFStandardStatus.Sign;
|
|
var chargeUser = currUser.FirstOrDefault().CHARGE_USER_ID;
|
|
if (chargeUser == null)
|
|
{
|
|
var tempUser = GetEntity<T_FM_USER>((Guid)currUser.FirstOrDefault().USER_ID);
|
|
if (tempUser != null)
|
|
{
|
|
var tempDepartment = GetEntity<T_FM_DEPARTMENT>((Guid)tempUser.DEPARTMENT_ID);
|
|
if (tempDepartment != null)
|
|
{
|
|
chargeUser = tempDepartment.USER_ID;
|
|
}
|
|
}
|
|
}
|
|
foreach(var item in currUser)
|
|
{
|
|
item.CHARGE_USER_ID= chargeUser;
|
|
}
|
|
foreach (var signedPost in currUser)
|
|
{
|
|
signedPost.DEAL_STATUS = PdtSignStatus.已签订;
|
|
signedPost.SIGNED_TIME = DateTime.Now;
|
|
}
|
|
var leftuser = signedPosts.Where(t => t.CHARGE_USER_ID == chargeUser && t.DEAL_STATUS == PdtSignStatus.未签订);
|
|
if (leftuser.Count() == 0)
|
|
{
|
|
sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("安全生产责任制签订-负责人签订", entity.ID, orgId, (Guid)chargeUser, "", DateTime.Now, DateTime.Now.AddDays(1), 0, "OG001_SHOWPRINT");
|
|
}
|
|
}
|
|
if (entity.TaskID != Guid.Empty)
|
|
{
|
|
finishNotice = NotificationTaskService.FOGetTaskFinishModel(entity.TaskID, entity.ID);
|
|
}
|
|
this.UnifiedCommit(() =>
|
|
{
|
|
if (finishNotice != null)
|
|
UpdateEntityNoCommit(finishNotice);
|
|
if (currUser != null && currUser.Any())
|
|
BantchUpdateEntityNoCommit(currUser);
|
|
if (sendNotice != null)
|
|
AddEntityNoCommit(sendNotice);
|
|
if (signed != null)
|
|
UpdateEntityNoCommit(signed);
|
|
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 负责人签订
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("ChargeUserAgree")]
|
|
public JsonActionResult<bool> ChargeUserAgree([FromBody] T_OG_SAFE_PDT_SIGNED entity)
|
|
{
|
|
return SafeExecute<bool>(() =>
|
|
{
|
|
var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId;
|
|
var userID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
|
|
T_FM_NOTIFICATION_TASK finishNotice = null;
|
|
T_FM_NOTIFICATION_TASK sendNotice = null;
|
|
T_OG_SAFE_PDT_SIGNED signed = null;
|
|
var signedPost = GetEntities<T_OG_SAFE_PDT_SIGNED_POST>(t => t.Nav_SafePdtSigned.ANNUAL == DateTime.Now.Year && t.SAFE_PDT_SIGNED_ID == entity.ID && t.CHARGE_USER_ID == userID && t.CHARGE_DEAL_STATUS == PdtSignStatus.未签订, new BaseFilter(orgId));
|
|
if (signedPost != null && signedPost.Any())
|
|
{
|
|
foreach (var item in signedPost)
|
|
{
|
|
item.CHARGE_DEAL_STATUS = PdtSignStatus.已签订;
|
|
item.CHARGE_SIGNED_TIME = DateTime.Now;
|
|
}
|
|
signed = GetEntity<T_OG_SAFE_PDT_SIGNED>(entity.ID);
|
|
signed.STATUS = PFStandardStatus.Archived;
|
|
//20230727去掉审核环节
|
|
//var AHUser = GetEntity<T_FM_USER>(t => t.Nav_ApproveRole.NAME == "安环部负责人" && t.ENABLE_STATUS == 0);
|
|
// sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("安全生产责任制签订-审核", entity.ID, orgId, AHUser.ID, AHUser.NAME, DateTime.Now, DateTime.Now.AddDays(1), 0, "OG001_REPORT");
|
|
}
|
|
if (entity.TaskID != Guid.Empty)
|
|
{
|
|
finishNotice = NotificationTaskService.FOGetTaskFinishModel(entity.TaskID, entity.ID);
|
|
}
|
|
this.UnifiedCommit(() =>
|
|
{
|
|
if (finishNotice != null)
|
|
UpdateEntityNoCommit(finishNotice);
|
|
if (signedPost != null)
|
|
BantchUpdateEntityNoCommit(signedPost);
|
|
if (sendNotice != null)
|
|
AddEntityNoCommit(sendNotice);
|
|
if (signed != null)
|
|
UpdateEntityNoCommit(signed);
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
}
|
|
}
|