362 lines
12 KiB
C#
362 lines
12 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
||
using DOAN.Model.Dto;
|
||
|
||
using DOAN.Service.MES.dev.IService;
|
||
using DOAN.Model.MES.dev.Dto;
|
||
using DOAN.Admin.WebApi.Filters;
|
||
using MiniExcelLibs;
|
||
using DOAN.Model.MES.dev.Dto;
|
||
using DOAN.Model.MES.dev;
|
||
using Org.BouncyCastle.Crypto;
|
||
|
||
//创建时间:2024-05-31
|
||
namespace DOAN.Admin.WebApi.Controllers
|
||
{
|
||
/// <summary>
|
||
/// 任务执行
|
||
/// </summary>
|
||
[Verify]
|
||
[Route("mes/deviceManagement/DeviceTaskExecute")]
|
||
public class DeviceTaskExecuteController : BaseController
|
||
{
|
||
/// <summary>
|
||
/// 任务执行接口
|
||
/// </summary>
|
||
private readonly IDeviceTaskExecuteService _DeviceTaskExecuteService;
|
||
|
||
public DeviceTaskExecuteController(IDeviceTaskExecuteService DeviceTaskExecuteService)
|
||
{
|
||
_DeviceTaskExecuteService = DeviceTaskExecuteService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询任务执行列表
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
[HttpPost("list")]
|
||
|
||
public IActionResult QueryDeviceTaskExecute([FromBody] DeviceTaskExecuteQueryDto parm)
|
||
{
|
||
var response = _DeviceTaskExecuteService.GetList(parm);
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 查询任务执行详情
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("{Id}")]
|
||
[ActionPermissionFilter(Permission = "deviceManagement:devicetaskexecute:query")]
|
||
public IActionResult GetDeviceTaskExecute(string Id)
|
||
{
|
||
var response = _DeviceTaskExecuteService.GetInfo(Id);
|
||
|
||
var info = response.Adapt<DeviceTaskExecute>();
|
||
return SUCCESS(info);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加任务执行
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[ActionPermissionFilter(Permission = "deviceManagement:devicetaskexecute:add")]
|
||
[Log(Title = "任务执行", BusinessType = BusinessType.INSERT)]
|
||
public IActionResult AddDeviceTaskExecute([FromBody] DeviceTaskExecuteDto parm)
|
||
{
|
||
var modal = parm.Adapt<DeviceTaskExecute>().ToCreate(HttpContext).ToUpdate(HttpContext);
|
||
|
||
var response = _DeviceTaskExecuteService.AddDeviceTaskExecute(modal);
|
||
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新任务执行
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPut]
|
||
[ActionPermissionFilter(Permission = "deviceManagement:devicetaskexecute:edit")]
|
||
[Log(Title = "任务执行", BusinessType = BusinessType.UPDATE)]
|
||
public IActionResult UpdateDeviceTaskExecute([FromBody] DeviceTaskExecuteDto parm)
|
||
{
|
||
|
||
Console.WriteLine(HttpContext.User?.Identity?.Name);
|
||
var modal = parm.Adapt<DeviceTaskExecute>().ToUpdate(HttpContext);
|
||
var response = _DeviceTaskExecuteService.UpdateDeviceTaskExecute(modal);
|
||
|
||
return ToResponse(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更改任务状态
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("update_task_status")]
|
||
public IActionResult Update_task_status([FromQuery]DeviceTaskExecuteQueryDto2 parm)
|
||
{
|
||
if(parm == null)
|
||
{
|
||
return SUCCESS(null);
|
||
}
|
||
parm.ToUpdate();
|
||
var response = _DeviceTaskExecuteService.Update_task_status(parm);
|
||
|
||
return ToResponse(response);
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除任务执行
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpDelete("{ids}")]
|
||
[ActionPermissionFilter(Permission = "deviceManagement:devicetaskexecute:delete")]
|
||
[Log(Title = "任务执行", BusinessType = BusinessType.DELETE)]
|
||
public IActionResult DeleteDeviceTaskExecute(string ids)
|
||
{
|
||
|
||
if(string.IsNullOrEmpty(ids))
|
||
{
|
||
return SUCCESS(null);
|
||
}
|
||
string[] idsArr = ids.Split(",");
|
||
if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
|
||
|
||
var response = _DeviceTaskExecuteService.Delete(idsArr);
|
||
|
||
return ToResponse(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 导出任务执行
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Log(Title = "任务执行", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||
[HttpGet("export")]
|
||
[ActionPermissionFilter(Permission = "deviceManagement:devicetaskexecute:export")]
|
||
public IActionResult Export([FromQuery] DeviceTaskExecuteQueryDto parm)
|
||
{
|
||
parm.PageNum = 1;
|
||
parm.PageSize = 100000;
|
||
var list = _DeviceTaskExecuteService.GetList(parm).Result;
|
||
if (list == null || list.Count <= 0)
|
||
{
|
||
return ToResponse(ResultCode.FAIL, "没有要导出的数据");
|
||
}
|
||
var result = ExportExcelMini(list, "任务执行", "任务执行");
|
||
return ExportExcel(result.Item2, result.Item1);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清空任务执行
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Log(Title = "任务执行", BusinessType = BusinessType.CLEAN)]
|
||
[ActionPermissionFilter(Permission = "deviceManagement:devicetaskexecute:delete")]
|
||
[HttpDelete("clean")]
|
||
public IActionResult Clear()
|
||
{
|
||
if (!HttpContextExtension.IsAdmin(HttpContext))
|
||
{
|
||
return ToResponse(ResultCode.FAIL, "操作失败");
|
||
}
|
||
return SUCCESS(_DeviceTaskExecuteService.TruncateDeviceTaskExecute());
|
||
}
|
||
|
||
/// <summary>
|
||
/// 导入
|
||
/// </summary>
|
||
/// <param name="formFile"></param>
|
||
/// <returns></returns>
|
||
[HttpPost("importData")]
|
||
[Log(Title = "任务执行导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false)]
|
||
[ActionPermissionFilter(Permission = "deviceManagement:devicetaskexecute:import")]
|
||
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||
{
|
||
List<DeviceTaskExecuteDto> list = new();
|
||
using (var stream = formFile.OpenReadStream())
|
||
{
|
||
list = stream.Query<DeviceTaskExecuteDto>(startCell: "A1").ToList();
|
||
}
|
||
|
||
return SUCCESS(_DeviceTaskExecuteService.ImportDeviceTaskExecute(list.Adapt<List<DeviceTaskExecute>>()));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 任务执行导入模板下载
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpGet("importTemplate")]
|
||
[Log(Title = "任务执行模板", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||
[AllowAnonymous]
|
||
public IActionResult ImportTemplateExcel()
|
||
{
|
||
var result = DownloadImportTemplate(new List<DeviceTaskExecuteDto>() { }, "DeviceTaskExecute");
|
||
return ExportExcel(result.Item2, result.Item1);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 立刻派发任务
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
|
||
[HttpGet("dispatch/{id}")]
|
||
[Log(Title = "任务立刻执行")]
|
||
[AllowAnonymous]
|
||
public IActionResult ExecutionTask_point(string id)
|
||
{
|
||
if(string.IsNullOrEmpty(id))
|
||
{
|
||
return SUCCESS(null);
|
||
}
|
||
var response = _DeviceTaskExecuteService.ExecutionTask_point(id);
|
||
|
||
return SUCCESS(response);
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 获取任务执行绑定的巡检任务和点检任务绑定的设备
|
||
/// </summary>
|
||
/// <param name="id">device_task_execute表的主键</param>
|
||
/// <returns></returns>
|
||
[HttpGet("get_bind_device/{id}")]
|
||
public IActionResult AchieveTaskbindDevice(string id)
|
||
{
|
||
|
||
if (string.IsNullOrEmpty(id))
|
||
{
|
||
return SUCCESS(null);
|
||
}
|
||
var response = _DeviceTaskExecuteService.AchieveTaskbindDevice(id);
|
||
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取设备绑定的检查项
|
||
/// </summary>
|
||
/// <param name="fk_device_id">device_rel_account_inspect表的fk_account_id 属性</param>
|
||
/// <param name="planType">保养,检查</param>
|
||
/// <returns></returns>
|
||
[HttpGet("get_bind_inspect")]
|
||
public IActionResult AchieveDevicebindInspect(int? fk_account_id,string fkPlanId,int planType)
|
||
{
|
||
if (fk_account_id == null)
|
||
{
|
||
return SUCCESS(null);
|
||
}
|
||
var response = _DeviceTaskExecuteService.AchieveDevicebindInspect(fk_account_id ?? 0, fkPlanId, planType);
|
||
|
||
return SUCCESS(response);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取检查项绑定的检查表单
|
||
/// </summary>
|
||
/// <param name="fk_device_inspect_id">device_form_config表的fk_device_inspect_id字段</param>
|
||
/// <returns></returns>
|
||
[HttpGet("bind_form/{fk_device_inspect_id}")]
|
||
public IActionResult AchieveInspectbindForm(int? fk_device_inspect_id)
|
||
{
|
||
if (fk_device_inspect_id==null)
|
||
{
|
||
return SUCCESS(null);
|
||
}
|
||
|
||
var response = _DeviceTaskExecuteService.AchieveInspectbindForm(fk_device_inspect_id??0);
|
||
|
||
return SUCCESS(response);
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取表单结果
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost("get_form_result")]
|
||
public IActionResult AchieveFormResult([FromBody] DeviceTaskExecuteResult1QueryDto_TaskExecute query)
|
||
{
|
||
if(query==null)
|
||
{
|
||
return SUCCESS(null);
|
||
}
|
||
if(query.PlanType!=1&&query.PlanType!=2)
|
||
{
|
||
|
||
return ToResponse(ResultCode.CUSTOM_ERROR, "数据不合法:只能是1或者2");
|
||
}
|
||
|
||
var response = _DeviceTaskExecuteService.AchieveFormResult2(query);
|
||
|
||
return SUCCESS(response);
|
||
|
||
}
|
||
/// <summary>
|
||
/// 修改表单结果
|
||
/// </summary>
|
||
/// <param name="result"></param>
|
||
/// <returns></returns>
|
||
[HttpPost("update_form_result")]
|
||
[AllowAnonymous]
|
||
public IActionResult UpdateFormResult([FromBody] DeviceTaskExecuteResultDto result)
|
||
{
|
||
if(result==null)
|
||
{
|
||
return SUCCESS(null);
|
||
}
|
||
result.ToUpdate_nickName(HttpContext);
|
||
int res=_DeviceTaskExecuteService.UpdateFormResult(result);
|
||
return SUCCESS(res);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 增加任务开始时间
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("add_task_start")]
|
||
public IActionResult AddTaskStartTime(string Id)
|
||
{
|
||
if(string.IsNullOrEmpty(Id))
|
||
{
|
||
return SUCCESS(null);
|
||
}
|
||
|
||
int res = _DeviceTaskExecuteService.AddDeviceTaskExecute(Id,HttpContext.GetNickName());
|
||
return SUCCESS(res);
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 增加任务结束时间
|
||
/// </summary>
|
||
/// <param name="Id"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("add_task_finally")]
|
||
public IActionResult AddTaskFinallyTime(string Id)
|
||
{
|
||
if (string.IsNullOrEmpty(Id))
|
||
{
|
||
return SUCCESS(null);
|
||
}
|
||
|
||
int res = _DeviceTaskExecuteService.AddTaskFinallyTime(Id);
|
||
return SUCCESS(res);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
} |