230 lines
11 KiB
C#
230 lines
11 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.BaseData.Services.Services.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/DMDeviceBase")]
|
|
public class DMDeviceBaseController : AuthorizeApiController<T_DM_DEVICE_BASE>
|
|
{
|
|
IFMNotificationTaskService NotificationTaskService { get; set; }
|
|
public DMDeviceBaseController(IFMNotificationTaskService notificationTaskService)
|
|
{
|
|
NotificationTaskService = notificationTaskService;
|
|
}
|
|
/// <summary>
|
|
/// 设备设施维保计划 修改
|
|
/// </summary>
|
|
/// <param name="entity"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("FullUpdate")]
|
|
public JsonActionResult<bool> FullUpdate([FromBody] T_DM_DEVICE_BASE entity)
|
|
{
|
|
return SafeExecute<bool>(() =>
|
|
{
|
|
var Files = entity.Nav_Files;
|
|
entity.Nav_Files = null;
|
|
var ListCheck = entity.Nav_ListCheck;
|
|
entity.Nav_ListCheck = null;
|
|
var ListCheckCircle = entity.Nav_ListCheckCircle;
|
|
entity.Nav_ListCheckCircle = null;
|
|
var Purchases = entity.Nav_Purchases;
|
|
entity.Nav_Purchases = null;
|
|
List<T_DM_DEVICE_BASE_CHECK_USER> listCheckUser = new List<T_DM_DEVICE_BASE_CHECK_USER>();
|
|
int RowIndex = 1;
|
|
if (ListCheck != null && ListCheck.Any())
|
|
{
|
|
foreach (var item in ListCheck)
|
|
{
|
|
item.CHECKTYPE = CheckType.Check;
|
|
|
|
#region 周期判断
|
|
if (item.DATA == 0)
|
|
{
|
|
item.DATA = null;
|
|
}
|
|
if (item.PLANCHECKFREQUENCY == null)
|
|
{
|
|
throw new Exception("点检周期行:【" + RowIndex + "】不能为空!");
|
|
}
|
|
else if (item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.Week)
|
|
{
|
|
if (item.WEEKDATA == null)
|
|
{
|
|
throw new Exception("点检明细行:【" + RowIndex + "】【星期】不能为空!");
|
|
}
|
|
if (item.DATA != null)
|
|
{
|
|
throw new Exception("点检明细行:【" + RowIndex + "】【日】不能填写!");
|
|
}
|
|
}
|
|
else if (item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.Date)
|
|
{
|
|
if (item.WEEKDATA != null)
|
|
{
|
|
throw new Exception("点检明细行:【" + RowIndex + "】【星期】不能填写!");
|
|
}
|
|
if (item.DATA != null)
|
|
{
|
|
throw new Exception("点检明细行:【" + RowIndex + "】【日】不能填写!");
|
|
}
|
|
}
|
|
else if (item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.Quarter || item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.Month || item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.Year || item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.HalfYear)//OneTime
|
|
{
|
|
if (item.WEEKDATA != null)
|
|
{
|
|
throw new Exception("点检明细行:【" + RowIndex + "】【星期】不能填写!");
|
|
}
|
|
if (item.DATA == null)
|
|
{
|
|
throw new Exception("点检明细行:【" + RowIndex + "】【日】不能为空!");
|
|
}
|
|
if (item.DATA.Value < 1)
|
|
{
|
|
throw new Exception("点检明细行:【" + RowIndex + "】【日】必须大于零!");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
if (item.Nav_ListUser != null && item.Nav_ListUser.Any())
|
|
{
|
|
List<T_DM_DEVICE_BASE_CHECK_USER> listCheckUserTemp = item.Nav_ListUser.ToList();
|
|
listCheckUserTemp[0].ISMAIN = true;
|
|
listCheckUser.AddRange(listCheckUserTemp);
|
|
}
|
|
RowIndex++;
|
|
}
|
|
}
|
|
if (ListCheckCircle != null && ListCheckCircle.Any())
|
|
{
|
|
RowIndex = 1;
|
|
foreach (var item in ListCheckCircle)
|
|
{
|
|
item.CHECKTYPE = CheckType.CheckCircuit;
|
|
|
|
#region 周期判断
|
|
if (item.DATA == 0)
|
|
{
|
|
item.DATA = null;
|
|
}
|
|
if (item.PLANCHECKFREQUENCY == null)
|
|
{
|
|
throw new Exception("巡检周期行:【" + RowIndex + "】不能为空!");
|
|
}
|
|
else if (item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.Week)
|
|
{
|
|
if (item.WEEKDATA == null)
|
|
{
|
|
throw new Exception("巡检明细行:【" + RowIndex + "】【星期】不能为空!");
|
|
}
|
|
if (item.DATA != null)
|
|
{
|
|
throw new Exception("巡检明细行:【" + RowIndex + "】【日】不能填写!");
|
|
}
|
|
}
|
|
else if (item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.Date)
|
|
{
|
|
if (item.WEEKDATA != null)
|
|
{
|
|
throw new Exception("巡检明细行:【" + RowIndex + "】【星期】不能填写!");
|
|
}
|
|
if (item.DATA != null)
|
|
{
|
|
throw new Exception("巡检明细行:【" + RowIndex + "】【日】不能填写!");
|
|
}
|
|
}
|
|
else if (item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.Quarter || item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.Month || item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.Year|| item.PLANCHECKFREQUENCY.Value == BSPLANCHECKFREQUENCYEnum.HalfYear)
|
|
{
|
|
if (item.WEEKDATA != null)
|
|
{
|
|
throw new Exception("巡检明细行:【" + RowIndex + "】【星期】不能填写!");
|
|
}
|
|
if (item.DATA == null)
|
|
{
|
|
throw new Exception("巡检明细行:【" + RowIndex + "】【日】不能为空!");
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
if (item.Nav_ListUser != null && item.Nav_ListUser.Any())
|
|
{
|
|
List<T_DM_DEVICE_BASE_CHECK_USER> listCheckUserTemp = item.Nav_ListUser.ToList();
|
|
listCheckUserTemp[0].ISMAIN = true;
|
|
listCheckUser.AddRange(listCheckUserTemp);
|
|
}
|
|
}
|
|
}
|
|
var AHUser = GetEntity<T_FM_USER>(t => t.Nav_ApproveRole.NAME == "安环部负责人");
|
|
T_FM_NOTIFICATION_TASK sendNotice = null;
|
|
if (AHUser != null && entity.IS_SEND == 0)
|
|
{
|
|
entity.IS_SEND = 1;
|
|
sendNotice = NotificationTaskService.InsertUserNoticeTaskModel(GetEntity<T_FM_DEPARTMENT>(entity.DEPARTMENT_ID.Value).NAME + "新采购了设备设施,请进行风险辨识与评价", entity.ID, entity.ORG_ID, AHUser.ID, AHUser.NAME, DateTime.Now, DateTime.Now.AddDays(10), (int)FMNoticeTypeEnum.今日提醒, "PF135");
|
|
}
|
|
this.UnifiedCommit(() =>
|
|
{
|
|
if (entity != null)
|
|
UpdateEntityNoCommit(entity);
|
|
if (Files != null && Files.Any())//维保工作方案
|
|
BantchSaveEntityNoCommit(Files);
|
|
if (ListCheck != null && ListCheck.Any())//维保工作方案
|
|
BantchSaveEntityNoCommit(ListCheck);
|
|
if (ListCheckCircle != null && ListCheckCircle.Any())//维保工作方案
|
|
BantchSaveEntityNoCommit(ListCheckCircle);
|
|
if (Purchases != null && Purchases.Any())//维保工作方案
|
|
BantchSaveEntityNoCommit(Purchases);
|
|
if (listCheckUser != null && listCheckUser.Any())//检查人
|
|
BantchSaveEntityNoCommit(listCheckUser);
|
|
if (sendNotice != null)
|
|
AddEntityNoCommit(sendNotice);
|
|
});
|
|
|
|
return true;
|
|
});
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获得单条实体数据
|
|
/// </summary>
|
|
/// <param name="filter">过滤实体</param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("GetShow")]
|
|
public JsonActionResult<T_DM_DEVICE_BASE> GetShow([FromBody] KeywordFilter filter)
|
|
{
|
|
return SafeExecute(() =>
|
|
{
|
|
var result = GetEntity<T_DM_DEVICE_BASE>(null, filter, null);
|
|
if (result != null && result.Nav_ListCheck != null && result.Nav_ListCheck.Any())
|
|
{
|
|
foreach (var item in result.Nav_ListCheck)
|
|
{
|
|
if (item.Nav_ListUser != null && item.Nav_ListUser.Any())
|
|
{
|
|
item.Nav_ListUser = item.Nav_ListUser.OrderByDescending(e => e.ISMAIN).ToList();
|
|
}
|
|
}
|
|
|
|
result.Nav_ListCheckCircle = result.Nav_ListCheck.Where(e => e.CHECKTYPE == CheckType.CheckCircuit).ToList();
|
|
|
|
result.Nav_ListCheck = result.Nav_ListCheck.Where(e => e.CHECKTYPE == CheckType.Check).ToList();
|
|
}
|
|
return result;
|
|
});
|
|
}
|
|
}
|
|
} |