168 lines
6.8 KiB
C#
168 lines
6.8 KiB
C#
using APT.BaseData.Domain.Entities;
|
|
using APT.BaseData.Domain.Entities.FM;
|
|
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.SC;
|
|
using APT.MS.Domain.Entities.TI;
|
|
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.SC
|
|
{
|
|
[Route("api/TI/TIPlan")]
|
|
public class TIPlanController : AuthorizeApiController<T_TI_PLAN>
|
|
{
|
|
IFMFlowPermitService MFlowPermitService { get; set; }
|
|
IPFApproveCallBackService ApproveCallBackService { get; set; }
|
|
IFMNotificationTaskService NotificationTaskService { get; set; }
|
|
public TIPlanController(IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService, IFMNotificationTaskService notificationTaskService)
|
|
{
|
|
MFlowPermitService = mFlowPermitService;
|
|
ApproveCallBackService = approveCallBackService;
|
|
NotificationTaskService = notificationTaskService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 安全生产费用使用 修改
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("FullUpdate")]
|
|
public JsonActionResult<bool> FullUpdate([FromBody] T_TI_PLAN entity)
|
|
{
|
|
return SafeExecute<bool>(() =>
|
|
{
|
|
if (entity.BEGINTIME.HasValue)
|
|
{
|
|
if (entity.BEGINTIME.Value >= DateTime.Now)
|
|
{
|
|
throw new Exception("使用日期不能大于当前时间!");
|
|
}
|
|
}
|
|
if (entity.DEPARTMENT_ID == null)
|
|
{
|
|
throw new Exception("请选择发起部门!");
|
|
}
|
|
if (entity.USER_ID == null)
|
|
{
|
|
throw new Exception("请选择发起人!");
|
|
}
|
|
if (entity.YEAR == 0)
|
|
{
|
|
throw new Exception("请选择计划年度!");
|
|
}
|
|
else if (entity.YEAR < DateTime.Now.Year)
|
|
{
|
|
throw new Exception("计划年度不能小于当年!");
|
|
}
|
|
|
|
|
|
var files = entity.Nav_Files;//附件
|
|
entity.Nav_Files = null;
|
|
if (files == null || !files.Any())
|
|
{
|
|
throw new Exception("请上传附件!");
|
|
}
|
|
var listProject = entity.Nav_ListProject;
|
|
entity.Nav_ListProject = null;
|
|
if (listProject == null || !listProject.Any())
|
|
{
|
|
throw new Exception("请添加计划明细!");
|
|
}
|
|
var Ranges = entity.Nav_Ranges;
|
|
entity.Nav_Ranges = null;
|
|
var Sources = entity.Nav_Sources;
|
|
entity.Nav_Sources = null;
|
|
if (Ranges != null && Ranges.Any())
|
|
{
|
|
foreach (var range in Ranges)
|
|
{
|
|
range.Nav_Range = null;
|
|
}
|
|
}
|
|
if (Sources != null && Sources.Any())
|
|
{
|
|
foreach (var source in Sources)
|
|
{
|
|
source.Nav_Source = null;
|
|
}
|
|
}
|
|
if (entity.STATUS == PFStandardStatus.Archived)
|
|
{
|
|
int row = 1;
|
|
foreach (var item in listProject)
|
|
{
|
|
if (string.IsNullOrEmpty(item.CODE))
|
|
{
|
|
throw new Exception("行【" + row + "】项目编号不能为空!");
|
|
}
|
|
if (string.IsNullOrEmpty(item.NAME))
|
|
{
|
|
throw new Exception("行【" + row + "】项目名称不能为空!");
|
|
}
|
|
if (!item.MONEY.HasValue)
|
|
{
|
|
throw new Exception("行【" + row + "】申报经费不能为空!");
|
|
}
|
|
if (!item.MANAGER_ID.HasValue)
|
|
{
|
|
throw new Exception("请选择行【" + row + "】的项目负责人!");
|
|
}
|
|
row++;
|
|
}
|
|
}
|
|
foreach (var item in listProject)
|
|
{
|
|
item.YEAR = entity.YEAR;
|
|
item.PLAN_ID = entity.ID;
|
|
item.STATUS = PFStandardStatus.Draft;
|
|
}
|
|
|
|
#region 给每个明细对应负责人发送待办
|
|
|
|
List<T_FM_NOTIFICATION_TASK> listTask = null;
|
|
if (entity.STATUS == PFStandardStatus.Archived)
|
|
{
|
|
var listUserID = listProject.Where(e => e.MANAGER_ID.HasValue).Select(e => e.MANAGER_ID);
|
|
var listUser = GetEntities<T_FM_USER>(e => listUserID.Contains(e.ID), null);
|
|
T_FM_USER modelUser = null;
|
|
listTask = new List<T_FM_NOTIFICATION_TASK>();
|
|
foreach (var item in listProject)
|
|
{
|
|
modelUser = listUser.FirstOrDefault(e => e.ID == item.MANAGER_ID);
|
|
if (modelUser != null)
|
|
{
|
|
listTask.Add(NotificationTaskService.InsertUserNoticeTaskModel("立项申请/任务书上报", item.ID, item.ORG_ID.Value, item.MANAGER_ID.Value, modelUser.NAME, DateTime.Now, 0, "TI012", BaseData.Domain.Enums.FMTASKTYPE.TI_PROJECT));
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
this.UnifiedCommit(() =>
|
|
{
|
|
if (entity != null)
|
|
UpdateEntityNoCommit(entity); //保存主表 NoCommit
|
|
if (Ranges != null && Ranges.Any())//费用类型
|
|
BantchSaveEntityNoCommit(Ranges);
|
|
if (Sources != null && Sources.Any())//费用类型
|
|
BantchSaveEntityNoCommit(Sources);
|
|
if (files != null && files.Any())//附件
|
|
BantchSaveEntityNoCommit(files);
|
|
if (listProject != null && listProject.Any())//附件
|
|
BantchSaveEntityNoCommit(listProject);
|
|
if (listTask != null && listTask.Any())//给 项目负责人发送 立项申请/任务书上报
|
|
BantchSaveEntityNoCommit(listTask);
|
|
});
|
|
|
|
return true;
|
|
});
|
|
}
|
|
}
|
|
} |