395 lines
18 KiB
C#
395 lines
18 KiB
C#
using APT.BaseData.Domain.Entities.FM;
|
|
using APT.BaseData.Domain.Entities;
|
|
using APT.BaseData.Domain.Enums.PF;
|
|
using APT.BaseData.Domain.Enums;
|
|
using APT.BaseData.Domain.IServices.FM;
|
|
using APT.Infrastructure.Core;
|
|
using APT.MS.Domain.Entities.SC.PT;
|
|
using APT.MS.Domain.Enums;
|
|
using APT.Utility;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System;
|
|
using APT.BaseData.Services.DomainServices;
|
|
using APT.BaseData.Services.Services.FM;
|
|
using APT.BaseData.Domain.IServices;
|
|
using APT.MS.Domain.Entities.HM;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace APT.SC.WebApi.Controllers.Api.PTController
|
|
{
|
|
/// <summary>
|
|
/// 安全生产目标与指标制定表
|
|
/// </summary>
|
|
[Route("api/PT/PTIndicatorFormulation")]
|
|
public partial class IndicatorFormulationController : AuthorizeApiController<T_PT_INDICATOR_FORMULATION>
|
|
{
|
|
IPFCodeRuleService CodeRuleService { get; set; }
|
|
IFMNotificationTaskService NotificationTaskService { get; set; }
|
|
IFMFlowPermitService MFlowPermitService { get; set; }
|
|
IPFApproveCallBackService ApproveCallBackService { get; set; }
|
|
public IndicatorFormulationController(IPFCodeRuleService codeRuleService, IFMNotificationTaskService notificationTaskService, IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService)
|
|
{
|
|
CodeRuleService = codeRuleService;
|
|
NotificationTaskService = notificationTaskService;
|
|
MFlowPermitService = mFlowPermitService;
|
|
ApproveCallBackService = approveCallBackService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增/编辑
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("FullUpdate")]
|
|
public JsonActionResult<bool> FullUpdate([FromBody] T_PT_INDICATOR_FORMULATION entity)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
var goals = entity.Nav_Goals.Where(t => !t.IS_DELETED).ToList();
|
|
var files = entity.Nav_Files.Where(t => !t.IS_DELETED).ToList();
|
|
var planFiles = entity.Nav_PlanFiles.Where(t => !t.IS_DELETED).ToList();
|
|
var formulates = entity.Nav_Formulates.Where(t => !t.IS_DELETED).ToList();
|
|
var planResources = entity.Nav_PlanResources.Where(t => !t.IS_DELETED).ToList();
|
|
entity.NAME = "安全生产目标与指标制定";
|
|
entity.STATUS = PFStandardStatus.Draft;
|
|
entity.YEAR = DateTime.Now.Year.ToString();
|
|
var loginUserId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
|
|
entity.USER_ID = loginUserId;
|
|
//var departmentId = this.GetEntity<T_FM_USER>(t => t.ID == loginUserId.Value && t.ENABLE_STATUS == 0)?.DEPARTMENT_ID;
|
|
entity.VERSION = (entity.VERSION == null || entity.VERSION == 0) ? 1:entity.VERSION;
|
|
entity.DEPARTMENT_ID = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID;
|
|
entity.SET_TIME = DateTime.Now;
|
|
List<T_FM_NOTIFICATION_TASK> notices = new List<T_FM_NOTIFICATION_TASK>();
|
|
T_FM_NOTIFICATION_TASK task = null;
|
|
if (goals != null && goals.Any())
|
|
{
|
|
goals.ForEach(t =>
|
|
{
|
|
t.ORG_ID = entity.ORG_ID; t.INDICATOR_FORMULATION_ID = entity.ID;
|
|
});
|
|
}
|
|
if (files != null && files.Any())
|
|
{
|
|
files.ForEach(t =>
|
|
{
|
|
t.ORG_ID = entity.ORG_ID; t.INDICATOR_FORMULATION_ID = entity.ID;
|
|
t.Nav_ImgFile = null;
|
|
});
|
|
}
|
|
if (planFiles != null && planFiles.Any())
|
|
{
|
|
planFiles.ForEach(t =>
|
|
{
|
|
t.ORG_ID = entity.ORG_ID; t.INDICATOR_FORMULATION_ID = entity.ID;
|
|
t.Nav_ImgFile = null;
|
|
});
|
|
}
|
|
if (formulates != null && formulates.Any())
|
|
{
|
|
formulates.ForEach(t =>
|
|
{
|
|
t.ORG_ID = entity.ORG_ID; t.INDICATOR_FORMULATION_ID = entity.ID;
|
|
t.Nav_Formulate = null;
|
|
});
|
|
}
|
|
if (planResources != null && planResources.Any())
|
|
{
|
|
planResources.ForEach(t =>
|
|
{
|
|
t.ORG_ID = entity.ORG_ID; t.INDICATOR_FORMULATION_ID = entity.ID;
|
|
t.Nav_Resources = null;
|
|
});
|
|
}
|
|
if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify"))
|
|
{
|
|
entity.STATUS = PFStandardStatus.Approving;
|
|
entity.Nav_Goals = null;
|
|
entity.Nav_Files = null;
|
|
entity.Nav_PlanFiles = null;
|
|
entity.Nav_Formulates = null;
|
|
entity.Nav_PlanResources = 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[] { ',' });
|
|
MFlowPermitService.InsertApprove(serialCode[0], "PT017", "", entity.ID, "PT017_SHOWPRINT", entity.TaskID, true, () =>
|
|
{
|
|
if (entity != null)
|
|
this.UpdateEntityNoCommit(entity);
|
|
if (goals != null && goals.Any())
|
|
this.BantchSaveEntityNoCommit(goals);
|
|
if (files != null && files.Any())
|
|
this.BantchSaveEntityNoCommit(files);
|
|
if (planFiles != null && planFiles.Any())
|
|
this.BantchSaveEntityNoCommit(planFiles);
|
|
if (formulates != null && formulates.Any())
|
|
this.BantchSaveEntityNoCommit(formulates);
|
|
if (planResources != null && planResources.Any())
|
|
this.BantchSaveEntityNoCommit(planResources);
|
|
if (task != null)
|
|
this.UpdateEntityNoCommit(task);
|
|
}, null, null, null, null, null, "PT017_SHOWPRINT",null);
|
|
return true;
|
|
}
|
|
//if (entity.TaskID != Guid.Empty)
|
|
//{
|
|
// task = NotificationTaskService.GetTaskFinishModel(entity.TaskID);
|
|
// task.SOURCE_FORMCODE = "PT017_SHOWPRINT";
|
|
//}
|
|
entity.Nav_Goals = null;
|
|
entity.Nav_Files = null;
|
|
entity.Nav_PlanFiles = null;
|
|
entity.Nav_Formulates = null;
|
|
entity.Nav_PlanResources = null;
|
|
UnifiedCommit(() =>
|
|
{
|
|
if (entity != null)
|
|
this.UpdateEntityNoCommit(entity);
|
|
if (goals != null && goals.Any())
|
|
this.BantchSaveEntityNoCommit(goals);
|
|
if (files != null && files.Any())
|
|
this.BantchSaveEntityNoCommit(files);
|
|
if (planFiles != null && planFiles.Any())
|
|
this.BantchSaveEntityNoCommit(planFiles);
|
|
if (formulates != null && formulates.Any())
|
|
this.BantchSaveEntityNoCommit(formulates);
|
|
if (planResources != null && planResources.Any())
|
|
this.BantchSaveEntityNoCommit(planResources);
|
|
if (task != null)
|
|
this.UpdateEntityNoCommit(task);
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 回调函数
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("BackUpdate")]
|
|
public JsonActionResult<bool> BackUpdate(string id)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
return ApproveCallBackService.CallBack("PT/PTIndicatorFormulation/BackUpdate", id);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修订
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("FullRevisionUpdate")]
|
|
public JsonActionResult<bool> FullRevisionUpdate([FromBody] T_PT_INDICATOR_FORMULATION entity)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
var indecator = this.GetEntity<T_PT_INDICATOR_FORMULATION>(entity.ID.ToString());
|
|
if (indecator != null)
|
|
{
|
|
if (indecator.STATUS != PFStandardStatus.Archived)
|
|
this.ThrowError("040003");
|
|
}
|
|
var goals = entity.Nav_Goals;
|
|
var files = entity.Nav_Files;
|
|
var planFiles = entity.Nav_PlanFiles;
|
|
var formulates = entity.Nav_Formulates;
|
|
var planResources = entity.Nav_PlanResources;
|
|
entity.ID = Guid.NewGuid();
|
|
entity.NAME = "安全生产目标与指标";
|
|
entity.STATUS = PFStandardStatus.Draft;
|
|
entity.YEAR = DateTime.Now.Year.ToString();
|
|
var loginUserId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
|
|
entity.USER_ID = loginUserId;
|
|
var departmentId = this.GetEntity<T_FM_USER>(t => t.ID == (Guid)loginUserId && t.ENABLE_STATUS == 0)?.DEPARTMENT_ID;
|
|
entity.DEPARTMENT_ID = departmentId;
|
|
List<T_FM_NOTIFICATION_TASK> notices = new List<T_FM_NOTIFICATION_TASK>();
|
|
T_FM_NOTIFICATION_TASK task = null;
|
|
if (goals != null && goals.Any())
|
|
{
|
|
goals.ForEach(t =>
|
|
{
|
|
t.ORG_ID = entity.ORG_ID; t.INDICATOR_FORMULATION_ID = entity.ID;
|
|
});
|
|
}
|
|
if (files != null && files.Any())
|
|
{
|
|
files.ForEach(t =>
|
|
{
|
|
t.ORG_ID = entity.ORG_ID; t.INDICATOR_FORMULATION_ID = entity.ID;
|
|
t.Nav_ImgFile = null;
|
|
});
|
|
}
|
|
if (planFiles != null && planFiles.Any())
|
|
{
|
|
planFiles.ForEach(t =>
|
|
{
|
|
t.ORG_ID = entity.ORG_ID; t.INDICATOR_FORMULATION_ID = entity.ID;
|
|
t.Nav_ImgFile = null;
|
|
});
|
|
}
|
|
if (formulates != null && formulates.Any())
|
|
{
|
|
formulates.ForEach(t =>
|
|
{
|
|
t.ORG_ID = entity.ORG_ID; t.INDICATOR_FORMULATION_ID = entity.ID;
|
|
t.Nav_Formulate = null;
|
|
});
|
|
}
|
|
if (planResources != null && planResources.Any())
|
|
{
|
|
planResources.ForEach(t =>
|
|
{
|
|
t.ORG_ID = entity.ORG_ID; t.INDICATOR_FORMULATION_ID = entity.ID;
|
|
t.Nav_Resources = null;
|
|
});
|
|
}
|
|
if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify"))
|
|
{
|
|
entity.STATUS = PFStandardStatus.Approving;
|
|
entity.Nav_Goals = null;
|
|
entity.Nav_Files = null;
|
|
entity.Nav_PlanFiles = null;
|
|
entity.Nav_Formulates = null;
|
|
entity.Nav_PlanResources = 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[] { ',' });
|
|
MFlowPermitService.InsertApprove(serialCode[0], "PT017", "", entity.ID, "PT017_SHOWPRINT", entity.TaskID, true, () =>
|
|
{
|
|
if (entity != null)
|
|
this.UpdateEntityNoCommit(entity);
|
|
if (goals != null && goals.Any())
|
|
this.BantchSaveEntityNoCommit(goals);
|
|
if (files != null && files.Any())
|
|
this.BantchSaveEntityNoCommit(files);
|
|
if (planFiles != null && planFiles.Any())
|
|
this.BantchSaveEntityNoCommit(planFiles);
|
|
if (formulates != null && formulates.Any())
|
|
this.BantchSaveEntityNoCommit(formulates);
|
|
if (planResources != null && planResources.Any())
|
|
this.BantchSaveEntityNoCommit(planResources);
|
|
if (task != null)
|
|
this.UpdateEntityNoCommit(task);
|
|
}, null, null, null, null, null, "PT017_SHOWPRINT", null);
|
|
return true;
|
|
}
|
|
if (entity.TaskID != Guid.Empty)
|
|
{
|
|
task = NotificationTaskService.GetTaskFinishModel(entity.TaskID);
|
|
task.SOURCE_FORMCODE = "PT017_SHOWPRINT";
|
|
}
|
|
entity.Nav_Goals = null;
|
|
entity.Nav_Files = null;
|
|
entity.Nav_PlanFiles = null;
|
|
entity.Nav_Formulates = null;
|
|
entity.Nav_PlanResources = null;
|
|
UnifiedCommit(() =>
|
|
{
|
|
if (entity != null)
|
|
this.UpdateEntityNoCommit(entity);
|
|
if (goals != null && goals.Any())
|
|
this.BantchSaveEntityNoCommit(goals);
|
|
if (files != null && files.Any())
|
|
this.BantchSaveEntityNoCommit(files);
|
|
if (planFiles != null && planFiles.Any())
|
|
this.BantchSaveEntityNoCommit(planFiles);
|
|
if (formulates != null && formulates.Any())
|
|
this.BantchSaveEntityNoCommit(formulates);
|
|
if (planResources != null && planResources.Any())
|
|
this.BantchSaveEntityNoCommit(planResources);
|
|
if (task != null)
|
|
this.UpdateEntityNoCommit(task);
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取版本号
|
|
/// </summary>
|
|
/// <param name="filter"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("GetVersionEdit")]
|
|
public JsonActionResult<T_PT_INDICATOR_FORMULATION> GetVersionEdit([FromBody] KeywordFilter filter)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
T_PT_INDICATOR_FORMULATION entity = new T_PT_INDICATOR_FORMULATION();
|
|
filter.IgnoreDataRule = true;
|
|
//取最大时间的数据
|
|
var maxInfo = this.GetEntities<T_PT_INDICATOR_FORMULATION>(t=>!t.IS_DELETED, filter).OrderByDescending(m => m.CREATE_TIME).FirstOrDefault();
|
|
if (maxInfo != null)
|
|
{
|
|
entity = this.GetEntity<T_PT_INDICATOR_FORMULATION>(maxInfo.ID, new string[] { "Nav_User", "Nav_Department", "Nav_Formulates", "Nav_Formulates.Nav_Formulate", "Nav_PlanResources", "Nav_PlanResources.Nav_Resources", "Nav_Files", "Nav_Files.Nav_ImgFile", "Nav_Files.Nav_ImgFile.Nav_File",
|
|
"Nav_PlanFiles", "Nav_PlanFiles.Nav_ImgFile", "Nav_PlanFiles.Nav_ImgFile.Nav_File","Nav_Goals"});
|
|
entity.VERSION = entity.VERSION + 1;
|
|
}
|
|
return entity;
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 驳回
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("RejectUpdate")]
|
|
public JsonActionResult<bool> RejectUpdate(string id)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
var entity = this.GetEntity<T_PT_INDICATOR_FORMULATION>(id);
|
|
entity.STATUS = PFStandardStatus.Rejected;
|
|
//发消息
|
|
T_FM_NOTIFICATION_TASK notice = new T_FM_NOTIFICATION_TASK();
|
|
var user = this.GetEntity<T_FM_USER>(t => t.ID == entity.CREATER_ID && t.ENABLE_STATUS == 0);
|
|
if (user != null)
|
|
{
|
|
notice = NotificationTaskService.InsertUserNoticeTaskModel("安全生产目标与指标已被驳回", entity.ID, entity.ORG_ID, user.ID, user.NAME, DateTime.Now,
|
|
DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "PT017");
|
|
}
|
|
UnifiedCommit(() =>
|
|
{
|
|
if (entity != null)
|
|
this.UpdateEntityNoCommit(entity);
|
|
if (notice != null)
|
|
this.UpdateEntityNoCommit(notice);
|
|
});
|
|
return true;
|
|
//return ApproveCallBackService.CallReject("PT/PTIndicatorFormulation/RejectUpdate", id);
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 归档
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("ArchiveUpdate")]
|
|
public JsonActionResult<bool> ArchiveUpdate(string id)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
var entity = this.GetEntity<T_PT_INDICATOR_FORMULATION>(id);
|
|
entity.STATUS = PFStandardStatus.Archived;
|
|
UnifiedCommit(() =>
|
|
{
|
|
if (entity != null)
|
|
this.UpdateEntityNoCommit(entity);
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
}
|
|
}
|