236 lines
9.2 KiB
C#
236 lines
9.2 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.AE;
|
||
using APT.BaseData.Domain.IServices.FM;
|
||
using APT.Infrastructure.Core;
|
||
using APT.MS.Domain.Entities.DM;
|
||
using APT.MS.Domain.Enums;
|
||
using APT.Utility;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Linq.Expressions;
|
||
|
||
namespace APT.SC.WebApi.Controllers.Api.DM
|
||
{
|
||
[Route("api/DM/DMDeviceMaintenancePlan")]
|
||
public class DMDeviceMaintenancePlanController : AuthorizeApiController<T_DM_DEVICE_MAINTENANCE_PLAN>
|
||
{
|
||
IFMNotificationTaskService NotificationTaskService { get; set; }
|
||
public DMDeviceMaintenancePlanController(IFMNotificationTaskService notificationTaskService)
|
||
{
|
||
NotificationTaskService = notificationTaskService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设备设施维保计划 修改
|
||
/// </summary>
|
||
/// <param name="entity"></param>
|
||
/// <returns></returns>
|
||
[HttpPost, Route("FullUpdate")]
|
||
public JsonActionResult<bool> FullUpdate([FromBody] T_DM_DEVICE_MAINTENANCE_PLAN entity)
|
||
{
|
||
return SafeExecute<bool>(() =>
|
||
{
|
||
var Files = entity.Nav_Files;
|
||
entity.Nav_Files = null;
|
||
var FilesPlan = entity.Nav_FilesPlan;
|
||
entity.Nav_FilesPlan = null;
|
||
var ListUser = entity.Nav_ListUser;
|
||
entity.Nav_ListUser = null;
|
||
if (!entity.DEVICEBASE_ID.HasValue)
|
||
{
|
||
throw new Exception("请选择设备设施!");
|
||
}
|
||
if (string.IsNullOrEmpty(entity.POSITION))
|
||
{
|
||
throw new Exception("请填写位置!");
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(entity.CONTENT))
|
||
{
|
||
throw new Exception("请填写维保内容!");
|
||
}
|
||
else if (entity.CONTENT.Length > 500)
|
||
{
|
||
throw new Exception("维保内容不能超过500字符!");
|
||
}
|
||
List<T_FM_NOTIFICATION_TASK> listTask = null;
|
||
|
||
if (entity.STATUS_APPROVE != PFStandardStatus.Draft)
|
||
{
|
||
if (ListUser == null || !ListUser.Any())
|
||
{
|
||
throw new Exception("请选择计划检查人员!");
|
||
}
|
||
else if (ListUser.Count() < 2)
|
||
{
|
||
throw new Exception("计划检查人员最少2人!");
|
||
}
|
||
|
||
#region 周期提示
|
||
|
||
string Msg = string.Empty;
|
||
switch (entity.PLANCHECKFREQUENCY)
|
||
{
|
||
case BSPLANCHECKFREQUENCYEnum.None:
|
||
Msg = "请选频率";
|
||
break;
|
||
//case BSPLANCHECKFREQUENCYEnum.OneTime:
|
||
case BSPLANCHECKFREQUENCYEnum.Year:
|
||
case BSPLANCHECKFREQUENCYEnum.HalfYear:
|
||
if (string.IsNullOrEmpty(entity.RUNDATA))
|
||
{
|
||
Msg = "请选择触发日期";
|
||
}
|
||
break;
|
||
case BSPLANCHECKFREQUENCYEnum.Date:
|
||
if (entity.RUNSETTIME == DateTime.MinValue)
|
||
{
|
||
Msg = "请选择执行时间";
|
||
}
|
||
break;
|
||
case BSPLANCHECKFREQUENCYEnum.Week:
|
||
if (!entity.WEEKDATA.HasValue)
|
||
{
|
||
Msg = "请选择星期";
|
||
}
|
||
break;
|
||
case BSPLANCHECKFREQUENCYEnum.Month:
|
||
case BSPLANCHECKFREQUENCYEnum.Quarter:
|
||
if (!entity.DATA.HasValue)
|
||
{
|
||
Msg = "请选择日";
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
if (!string.IsNullOrEmpty(Msg))
|
||
{
|
||
throw new Exception(Msg);
|
||
}
|
||
|
||
#endregion
|
||
|
||
List<Guid> UserId = new List<Guid>();
|
||
List<string> userName = new List<string>();
|
||
|
||
//var listUserID = ListUser.Select(e => e.USER_ID);
|
||
//var listUser = GetEntities<T_FM_USER>(e => listUserID.Contains(e.ID), null, null);
|
||
foreach (var item in ListUser)
|
||
{
|
||
if (item.IS_DELETED)
|
||
{
|
||
continue;
|
||
}
|
||
UserId.Add(item.USER_ID);
|
||
userName.Add(item.Nav_User.NAME);
|
||
}
|
||
|
||
listTask = NotificationTaskService.InsertUserNoticeTaskModels("设备设施维保计划确认", entity.ID, entity.ORG_ID, UserId, userName, DateTime.Now, DateTime.Now.AddDays(1), 1, "DM008_SHOWPRINT");
|
||
}
|
||
|
||
int RowIndex = 0;//第一个 计划检查人员 为记录人
|
||
foreach (var item in ListUser)
|
||
{
|
||
if (item.IS_DELETED)
|
||
{
|
||
continue;
|
||
}
|
||
if (RowIndex == 0)
|
||
{
|
||
item.ISMAIN = true;
|
||
}
|
||
item.Nav_User = null;
|
||
RowIndex++;
|
||
}
|
||
|
||
this.UnifiedCommit(() =>
|
||
{
|
||
if (entity != null)
|
||
UpdateEntityNoCommit(entity);
|
||
if (Files != null && Files.Any())//维保工作方案
|
||
BantchSaveEntityNoCommit(Files);
|
||
if (FilesPlan != null && FilesPlan.Any())//维保工作方案
|
||
BantchSaveEntityNoCommit(FilesPlan);
|
||
if (ListUser != null && ListUser.Any())//维保工作方案
|
||
BantchSaveEntityNoCommit(ListUser);
|
||
if (listTask != null && listTask.Any())//维保工作方案
|
||
BantchSaveEntityNoCommit(listTask);
|
||
});
|
||
return true;
|
||
});
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 点检人 确认
|
||
/// </summary>
|
||
[HttpPost, Route("Check")]
|
||
public JsonActionResult<bool> Check([FromBody] KeywordFilter filter)
|
||
{
|
||
return SafeExecute<bool>(() =>
|
||
{
|
||
if (string.IsNullOrEmpty(filter.Keyword) || string.IsNullOrEmpty(filter.Parameter1))
|
||
{
|
||
throw new Exception("传参有误!");
|
||
}
|
||
var guid = new Guid(filter.Keyword);
|
||
var taskID = new Guid(filter.Parameter1);
|
||
if (guid == Guid.Empty || taskID == Guid.Empty)
|
||
{
|
||
throw new Exception("传参有误!");
|
||
}
|
||
var task = NotificationTaskService.GetEntityTask(taskID);
|
||
|
||
var loginID = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
|
||
var Check = GetEntity<T_DM_DEVICE_MAINTENANCE_PLAN_USER>(e => e.USER_ID == loginID && e.PLAN_ID == guid);
|
||
|
||
if (Check == null)
|
||
{
|
||
this.UnifiedCommit(() =>
|
||
{
|
||
if (task != null)
|
||
UpdateEntityNoCommit(task);
|
||
});
|
||
}
|
||
else if (Check.ISCHECK)
|
||
{
|
||
this.UnifiedCommit(() =>
|
||
{
|
||
if (task != null)
|
||
UpdateEntityNoCommit(task);
|
||
});
|
||
throw new Exception("您已审阅,无需再次操作!");
|
||
}
|
||
else
|
||
{
|
||
Check.ISCHECK = true;
|
||
var UnCheck = GetEntity<T_DM_DEVICE_MAINTENANCE_PLAN_USER>(e => e.USER_ID != loginID && e.PLAN_ID == guid && !e.ISCHECK);
|
||
T_DM_DEVICE_MAINTENANCE_PLAN plan = null;
|
||
if (UnCheck == null)
|
||
{
|
||
plan = GetEntity<T_DM_DEVICE_MAINTENANCE_PLAN>(e => e.ID == guid);
|
||
plan.STATUS_APPROVE = PFStandardStatus.Archived;
|
||
}
|
||
|
||
//还有别人未 确认
|
||
this.UnifiedCommit(() =>
|
||
{
|
||
if (task != null)
|
||
UpdateEntityNoCommit(task);
|
||
if (Check != null)
|
||
UpdateEntityNoCommit(Check);
|
||
if (plan != null)//状态修改
|
||
UpdateEntityNoCommit(plan);
|
||
});
|
||
}
|
||
return true;
|
||
});
|
||
}
|
||
}
|
||
} |