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;
using APT.BaseData.Domain.IServices.FM;
using APT.Infrastructure.Core;
using APT.MS.Domain.Entities.FO;
using APT.MS.Domain.Entities.SC.PE;
using APT.MS.Domain.Entities.SC.PR;
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.PRController
{
///
/// 变化管理任务落实表
///
[Route("api/PR/PRChangeTaskImplement")]
public partial class ChangeTaskImplementController : AuthorizeApiController
{
IPFCodeRuleService CodeRuleService { get; set; }
IFMNotificationTaskService NotificationTaskService { get; set; }
IFMFlowPermitService MFlowPermitService { get; set; }
IPFApproveCallBackService ApproveCallBackService { get; set; }
///
/// 变化管理任务落实表
///
///
public ChangeTaskImplementController(IPFCodeRuleService codeRuleService, IFMNotificationTaskService notificationTaskService, IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService)
{
CodeRuleService = codeRuleService;
NotificationTaskService = notificationTaskService;
MFlowPermitService = mFlowPermitService;
ApproveCallBackService = approveCallBackService;
}
///
/// 落实人员获取
///
///
///
[HttpPost, Route("GetUserEdit")]
public JsonActionResult GetUserEdit([FromBody] KeywordFilter filter)
{
return SafeExecute(() => {
var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString();
if (string.IsNullOrEmpty(id))
this.ThrowError("030017");
var result = this.GetEntity(id, new string[] { "Nav_User", "Nav_Department","Nav_Task",
"Nav_Users","Nav_Users.Nav_User","Nav_Files","Nav_Files.Nav_ImgFile","Nav_Change","Nav_Change.Nav_Types.Nav_Type"});
if (result != null && result.Nav_Change!=null)
{
result.CODE = result.Nav_Change.CODE;
result.DESCRIPTION = result.Nav_Change.DESCRIPTION;
if (result.Nav_Change.Nav_Types != null && result.Nav_Change.Nav_Types.Any())
{
result.Nav_Types = result.Nav_Change.Nav_Types;
}
//if (result.Nav_Change.Nav_Tasks != null && result.Nav_Change.Nav_Tasks.Any())
//{
// result.Nav_Tasks = result.Nav_Change.Nav_Tasks;
// var loginUserId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
// result.Nav_Tasks = result.Nav_Tasks.Where(t => t.USER_ID == loginUserId).ToList();
//}
}
return result;
});
}
///
/// 新增/编辑
///
///
///
[HttpPost, Route("FullUpdate")]
public JsonActionResult FullUpdate([FromBody] T_PR_CHANGE_TASK_IMPLEMENT entity)
{
return SafeExecute(() =>
{
entity.TIME = DateTime.Now;
entity.STATUS = PFStandardStatus.Draft;
var users = entity.Nav_Users;
var files = entity.Nav_Files;
if (files != null && files.Any())
{
files.Where(t => !t.IS_DELETED).ForEach(t =>
{
t.ORG_ID = entity.ORG_ID; t.CHANGE_TASK_IMPLEMENT_ID = entity.ID;
});
}
if (users != null && users.Any())
{
users.Where(t => !t.IS_DELETED).ForEach(t =>
{
t.ORG_ID = entity.ORG_ID; t.CHANGE_TASK_IMPLEMENT_ID = entity.ID;
t.Nav_User = null;
});
}
else
{
if (entity.PERFORM_STATUS == PRPerformStatusEnum.OK)
this.ThrowError("040052");
}
if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify"))
{
entity.STATUS = PFStandardStatus.Approving;
entity.Nav_Types = null;
entity.Nav_Files = null;
entity.Nav_Users = null;
//取审批流水码
var sysFilter = new SystemCodeFilter();
sysFilter.CodeType = (int)PFCodeRuleType.审批流编码;
sysFilter.Count = 1;
sysFilter.OrgId = entity.ORG_ID;
var codes = CodeRuleService.NewGenSerial(sysFilter);
var serialCode = codes.Split(new char[] { ',' });
//var idetity = this.GetEntity(t => t.ID == entity.CHANGE_IDENTIFY_EVALUATION_ID);
MFlowPermitService.InsertApprove(serialCode[0], "PR026", "", entity.ID, "PR026_SHOWPRINT", entity.TaskID, true, () =>
{
if (entity != null)
this.UpdateEntityNoCommit(entity);
if (files != null && files.Any())
this.BantchSaveEntityNoCommit(files);
if (users != null && users.Any())
this.BantchSaveEntityNoCommit(users);
}, null, null, null, null, null, "PR026_SHOWPRINT", null);
return true;
}
entity.Nav_Types = null;
entity.Nav_Files = null;
entity.Nav_Users = null;
UnifiedCommit(() =>
{
if (entity != null)
this.UpdateEntityNoCommit(entity);
if (files != null && files.Any())
this.BantchSaveEntityNoCommit(files);
if (users != null && users.Any())
this.BantchSaveEntityNoCommit(users);
});
return true;
});
}
///
/// 回调函数
///
///
///
[HttpGet, Route("BackUpdate")]
public JsonActionResult BackUpdate(string id)
{
return SafeExecute(() =>
{
return ApproveCallBackService.CallBack("PR/PRChangeTaskImplement/BackUpdate", id);
});
}
///
/// 驳回
///
///
///
[HttpPost, Route("RejectUpdate")]
public JsonActionResult RejectUpdate([FromBody] T_PF_APPROVE model)
{
return SafeExecute(() =>
{
//公共 获取审批流信息
T_PF_APPROVE modelApp = null;
List listAppDetail = null;
T_FM_NOTIFICATION_TASK taskFinish = null;
string Msg = string.Empty;
bool ResultGetInfo = ApproveCallBackService.GetApproject(model, ref modelApp, ref listAppDetail, ref taskFinish, ref Msg);
if (!ResultGetInfo)
throw new Exception("驳回失败!");
if (modelApp == null || listAppDetail == null)
throw new Exception("获取驳回信息失败!");
var entity = this.GetEntity(model.DATA_ID);
entity.STATUS = PFStandardStatus.Rejected;
var persons = this.GetEntities(t => t.CHANGE_TASK_IMPLEMENT_ID == model.DATA_ID, new BaseFilter(entity.ORG_ID));
if (persons.Any())
persons.ForEach(t => { t.DEAL_STATUS = 0; t.Nav_User = null; });
//直接驳回给申请人
var user = this.GetEntity(t => t.ID == entity.USER_ID && t.ENABLE_STATUS == 0);
T_FM_NOTIFICATION_TASK notice = NotificationTaskService.InsertUserNoticeTaskModel("变化管理任务落实表已被驳回", entity.ID, entity.ORG_ID, (Guid)user.ID, user.NAME, DateTime.Now,
DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "PR026");
//当前节点其他审核人待办消除
var taskOtherIds = this.GetEntities(t => t.SOURCE_DATA_ID == model.ID && t.NOTICE_STATUS == 0, new BaseFilter(entity.ORG_ID)).Select(t => t.ID).ToList();
UnifiedCommit(() =>
{
if (entity != null)
this.UpdateEntityNoCommit(entity);
if (notice != null)
this.UpdateEntityNoCommit(notice);
if (modelApp != null)
UpdateEntityNoCommit(modelApp);
if (listAppDetail != null && listAppDetail.Count > 0)
BantchUpdateEntityNoCommit(listAppDetail);
if (persons != null && persons.Any())
BantchUpdateEntityNoCommit(persons);
if (taskOtherIds != null && taskOtherIds.Any())
BantchDeleteEntityNoCommit(taskOtherIds);
if (taskFinish != null)
UpdateEntityNoCommit(taskFinish);
});
return true;
//return ApproveCallBackService.CallReject("FO/FOCrucialLicenseJob/RejectUpdate", id);
});
}
}
}