292 lines
13 KiB
C#
292 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using APT.BaseData.Domain.Entities.FM;
|
|
using APT.Infrastructure.Core;
|
|
using APT.MS.Domain.Entities.SE;
|
|
using APT.Utility;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using NPOI.HSSF.Util;
|
|
using NPOI.SS.UserModel;
|
|
using NPOI.XSSF.UserModel;
|
|
using System.IO;
|
|
using APT.Infrastructure.Api;
|
|
using APT.BaseData.Domain.Enums;
|
|
using APT.BaseData.Domain.Enums.PF;
|
|
using System.Linq.Expressions;
|
|
using APT.BaseData.Domain.IServices;
|
|
using APT.BaseData.Domain.IServices.FM;
|
|
using APT.BaseData.Domain.Entities;
|
|
using APT.MS.Domain.Enums;
|
|
|
|
namespace APT.SC.WebApi.Controllers.Api.SE
|
|
{
|
|
[Route("api/SE/SETrainPlan")]
|
|
public class SETrainPlanController : AuthorizeApiController<T_SE_TRAIN_PLAN>
|
|
{
|
|
IFMNotificationTaskService NotificationTaskService { get; set; }
|
|
//IFMDepartmentService DepartmentService { get; set; }
|
|
//IPFSysLogService SysLogService { get; set; }
|
|
//IFMUserService UserService { get; set; }
|
|
IFMFlowPermitService MFlowPermitService { get; set; }
|
|
//IPFCodeRuleService CodeRuleService { get; set; }
|
|
IPFApproveCallBackService ApproveCallBackService { get; set; }
|
|
//IBSOperateLogService OperateLogService { get; set; }
|
|
public SETrainPlanController(IPFApproveCallBackService approveCallBackService, IFMFlowPermitService mFlowPermitService, IFMNotificationTaskService notificationTaskService)
|
|
{
|
|
NotificationTaskService = notificationTaskService;
|
|
//DepartmentService = departmentService;
|
|
//SysLogService = sysLogService;
|
|
//UserService = userService;
|
|
//IBSOperateLogService operateLogService,
|
|
|
|
MFlowPermitService = mFlowPermitService;
|
|
//CodeRuleService = codeRuleService;
|
|
ApproveCallBackService = approveCallBackService;
|
|
//OperateLogService = operateLogService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("FullUpdate")]
|
|
public JsonActionResult<bool> FullUpdate([FromBody] T_SE_TRAIN_PLAN entity)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
var Files = entity.Nav_Files;
|
|
entity.Nav_Files = null;
|
|
var ListPlanDetail = entity.Nav_ListPlanDetail;
|
|
entity.Nav_ListPlanDetail = null;
|
|
List<T_SE_TRAIN_PLAN_DETAIL_DEPARTMENT> ListDetailDepartment = new List<T_SE_TRAIN_PLAN_DETAIL_DEPARTMENT>();
|
|
Expression<Func<T_SE_TRAIN_PLAN, bool>> expression = e => e.ID != entity.ID && e.YEAR == entity.YEAR && !e.IS_DELETED;
|
|
if (entity.TYPE == MS.Domain.Enums.PlanType.Company)
|
|
{
|
|
expression = expression.And(e => e.TYPE == entity.TYPE);
|
|
}
|
|
else
|
|
{
|
|
expression = expression.And(e => e.DEPARTMENT_ID == APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID);
|
|
}
|
|
var check = GetEntity(expression);
|
|
if (check != null)
|
|
{
|
|
throw new Exception("您所在层级/组织当年度已经制定过培训计划,请勿多次提交!");
|
|
}
|
|
if (ListPlanDetail != null && ListPlanDetail.Count() > 0)
|
|
{
|
|
foreach (var item in ListPlanDetail)
|
|
{
|
|
item.DATE_TRAIN = Convert.ToDateTime(entity.YEAR + "-" + item.MONTH + "-01 00:00:00");
|
|
}
|
|
}
|
|
if (ListPlanDetail != null && ListPlanDetail.Count() > 0)
|
|
{
|
|
foreach (var item in ListPlanDetail)
|
|
{
|
|
if (item.Nav_ListDetailDepartment != null && item.Nav_ListDetailDepartment.Count() > 0)
|
|
{
|
|
ListDetailDepartment.AddRange(item.Nav_ListDetailDepartment.ToList());
|
|
item.Nav_ListDetailDepartment = null;
|
|
}
|
|
item.Nav_ListDetailDepartment = null;
|
|
item.Nav_Department = null;
|
|
}
|
|
}
|
|
if (ListDetailDepartment != null && ListDetailDepartment.Any())
|
|
{
|
|
foreach (var item in ListDetailDepartment)
|
|
{
|
|
item.Nav_Department = null;
|
|
}
|
|
}
|
|
if (entity.STATUS == PFStandardStatus.Sign)
|
|
{
|
|
//审批
|
|
if (ListPlanDetail != null && ListPlanDetail.Count() > 0)
|
|
{
|
|
int rowIndex = 0;
|
|
foreach (var item in ListPlanDetail)
|
|
{
|
|
rowIndex++;
|
|
if (item.CLASSHOUR <= 0)
|
|
{
|
|
throw new Exception("培训学时必须大于0!行:" + rowIndex);
|
|
}
|
|
if (!item.DEPARTMENT_ID.HasValue)
|
|
{
|
|
throw new Exception("请选择培训组织!行:" + rowIndex);
|
|
}
|
|
}
|
|
}
|
|
|
|
MFlowPermitService.InsertApprove(null, "SE071", ((int)entity.TYPE).ToString(), entity.ID, "SE071_SHOWPRINT", entity.TaskID, true, () =>
|
|
{
|
|
UpdateEntityNoCommit(entity);
|
|
if (Files != null && Files.Any())
|
|
BantchSaveEntityNoCommit(Files);
|
|
if (ListPlanDetail != null && ListPlanDetail.Any())
|
|
BantchSaveEntityNoCommit(ListPlanDetail);
|
|
if (ListDetailDepartment != null && ListDetailDepartment.Any())
|
|
BantchSaveEntityNoCommit(ListDetailDepartment);
|
|
}, null, APT.Infrastructure.Api.AppContext.CurrentSession.UserID, null, null, null, "SE071_SHOWPRINT", null, null, FMTASKTYPE.Default);
|
|
}
|
|
this.UnifiedCommit(() =>
|
|
{
|
|
UpdateEntityNoCommit(entity);
|
|
if (Files != null && Files.Any())
|
|
BantchSaveEntityNoCommit(Files);
|
|
if (ListPlanDetail != null && ListPlanDetail.Any())
|
|
BantchSaveEntityNoCommit(ListPlanDetail);
|
|
if (ListDetailDepartment != null && ListDetailDepartment.Any())
|
|
BantchSaveEntityNoCommit(ListDetailDepartment);
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获得单条实体数据
|
|
/// </summary>
|
|
/// <param name="filter">过滤实体</param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("GetSuit")]
|
|
public JsonActionResult<T_SE_TRAIN_PLAN> Get([FromBody] KeywordFilter filter)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
var result = GetEntity<T_SE_TRAIN_PLAN>(null, filter, null);
|
|
if (result.Nav_ListPlanDetail != null && result.Nav_ListPlanDetail.Any())
|
|
{
|
|
foreach (var item in result.Nav_ListPlanDetail)
|
|
{
|
|
item.MONTH = item.DATE_TRAIN.Month;
|
|
}
|
|
result.Nav_ListPlanDetail = result.Nav_ListPlanDetail.OrderBy(e => e.DEPARTMENT_ID).ThenBy(e => e.DATE_TRAIN).ToList();
|
|
}
|
|
return result;
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 部门级培训计划新增时 默认带出 公司级的信息
|
|
/// </summary>
|
|
/// <param name="filter">过滤实体</param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("GetIni")]
|
|
public JsonActionResult<T_SE_TRAIN_PLAN> GetIni([FromBody] KeywordFilter filter)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
T_SE_TRAIN_PLAN result = new T_SE_TRAIN_PLAN();
|
|
result.ID = Guid.NewGuid();
|
|
int Year = DateTime.Now.Year;
|
|
if (!string.IsNullOrEmpty(filter.Parameter1))
|
|
{
|
|
try
|
|
{
|
|
Year = int.Parse(filter.Parameter1);
|
|
}
|
|
catch
|
|
{
|
|
Year = DateTime.Now.Year;
|
|
}
|
|
}
|
|
DateTime dtMax = Convert.ToDateTime(Year + "-12-31 23:59:59");
|
|
DateTime dtMin = dtMax.AddMilliseconds(1).AddYears(-1);
|
|
result.TYPE = MS.Domain.Enums.PlanType.Department;
|
|
result.YEAR = Year;
|
|
result.LAUNCH_USER_ID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
|
|
result.DEPARTMENT_ID = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID;
|
|
result.LAUNCH_TIME = DateTime.Now;
|
|
var detail = GetEntities<T_SE_TRAIN_PLAN_DETAIL>(e => e.DATE_TRAIN >= dtMin && e.DATE_TRAIN <= dtMax && e.DEPARTMENT_ID.HasValue && e.DEPARTMENT_ID.Value == APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID && !e.IS_DELETED && e.STATUS != PFStandardStatus.Draft && e.Nav_Plan.STATUS == PFStandardStatus.Archived, null, "Nav_Plan").ToList();
|
|
if (detail != null && detail.Count() > 0)
|
|
{
|
|
detail = detail.OrderBy(e => e.DATE_TRAIN).ToList();
|
|
if (detail != null && detail.Count() > 0 && !result.PLAN_ID.HasValue)
|
|
{
|
|
result.PLAN_ID = detail[0].PLAN_ID;
|
|
}
|
|
foreach (var item in detail)
|
|
{
|
|
item.PLAN_DETAIL_ID = item.ID;
|
|
item.ID = Guid.NewGuid();
|
|
item.CREATE_TIME = DateTime.Now;
|
|
item.PLAN_ID = result.ID;
|
|
item.MONTH = item.DATE_TRAIN.Month;
|
|
item.DEPARTMENT_ID = null;
|
|
item.STATUS = PFStandardStatus.Draft;
|
|
item.Nav_Plan = null;
|
|
}
|
|
result.Nav_ListPlanDetail = detail;
|
|
}
|
|
return result;
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 隐患上报 审核通过 给每个通知负责人发送通知
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("PlanAuditNew")]
|
|
public JsonActionResult<bool> PlanAuditNew([FromBody] T_PF_APPROVE entity)
|
|
{
|
|
return SafeExecute<bool>(() =>
|
|
{
|
|
return ApproveCallBackService.CallBackNew("SE/SETrainPlan/PlanAuditNew", entity);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 年度培训计划驳回
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("PlanAuditBack")]
|
|
public JsonActionResult<bool> PlanAuditBack([FromBody] T_PF_APPROVE model)
|
|
{
|
|
return SafeExecute<bool>(() =>
|
|
{
|
|
T_PF_APPROVE modelApp = null;
|
|
List<T_PF_APPROVE_DETAIL> 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<T_SE_TRAIN_PLAN>(model.DATA_ID);
|
|
string NAME = string.Empty;
|
|
if (entity.LAUNCH_USER_ID.HasValue)
|
|
{
|
|
NAME= GetEntity<T_FM_USER>(entity.LAUNCH_USER_ID.Value)?.NAME;
|
|
}
|
|
|
|
entity.STATUS = PFStandardStatus.Rejected;
|
|
T_FM_NOTIFICATION_TASK noticeBack = NotificationTaskService.InsertUserNoticeTaskModel("(驳回)年度培训计划", entity.ID, entity.ORG_ID, (Guid)entity.LAUNCH_USER_ID, NAME, DateTime.Now, (int)FMNoticeTypeEnum.消息, "SE071", FMTASKTYPE.Default);
|
|
//entity.Nav_User = null;
|
|
|
|
UnifiedCommit(() =>
|
|
{
|
|
if (entity != null)
|
|
this.UpdateEntityNoCommit(entity);
|
|
if (noticeBack != null)
|
|
this.UpdateEntityNoCommit(noticeBack);
|
|
if (modelApp != null)
|
|
UpdateEntityNoCommit(modelApp);
|
|
if (listAppDetail != null && listAppDetail.Count > 0)
|
|
BantchUpdateEntityNoCommit(listAppDetail);
|
|
if (taskFinish != null)
|
|
UpdateEntityNoCommit(taskFinish);
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
}
|
|
}
|