using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Model.ViewModel.LGS; using Ropin.Inspection.Service.MTN.Interface; using System.Threading.Tasks; using System; using Ropin.Inspection.Model.ViewModel.MTN; using Microsoft.AspNetCore.Authorization; using Ropin.Inspection.Model; using Minio.DataModel.Args; using Minio; using System.Collections.Generic; using System.Linq; using Ropin.Inspection.Model.ViewModel; namespace Ropin.Inspection.Api.Controllers.MTN { public class DevOpsPlanController : BaseController { private readonly IDevOpsPlanService _devOpsPlanService; public DevOpsPlanController(IDevOpsPlanService devOpsPlanService) { _devOpsPlanService = devOpsPlanService; } /// /// 添加 /// /// /// [HttpPost("Add")] public async Task AddAsync(DevOpsPlanModel devOpsPlanModel) { try { await _devOpsPlanService.CreateOneAsync(devOpsPlanModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 分页列表 /// /// /// [HttpPost("Page")] public async Task PageAsync(DevOpsPlanInput input) { try { var libraryModels = await _devOpsPlanService.PageAsync(input); PagesModel pages = new PagesModel(libraryModels, input); return new ApiResult>(pages); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } [HttpGet("Detail/{id}")] public async Task DeatilAsync(string id) { var result = await _devOpsPlanService.GetByIdAsync(id); return new ApiResult(result); } /// /// 删除 /// /// /// [HttpDelete("Delete/{id}")] public async Task DeleteReportAsync(string id) { try { await _devOpsPlanService.DeleteAsync(id); return new ApiResult(ReturnCode.Success); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 更新 /// /// /// [HttpPost("Update")] public async Task UpdateAsync(DevOpsPlanModel devOpsPlanModel) { var result = await _devOpsPlanService.UpdateOneAsync(devOpsPlanModel); return new ApiResult(result >= 1); } /// /// 添加运维计划设备 /// /// /// [HttpPost("AddDevice")] public async Task AddDevice(DevOpsPlanDeviceModel devOpsPlanDeviceModel) { try { await _devOpsPlanService.AddDeviceAsync(devOpsPlanDeviceModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 设备列表 /// /// /// [HttpGet("DeviceList/{id}")] public async Task DeviceListAsync(string id) { try { var libraryModels = await _devOpsPlanService.DeviceListAsync(id); //var result = libraryModels // .GroupBy(x => new // { // x.CDevStoreCode, // x.DevStoreName, // x.Url, // x.CNumberCode, // }) // .Select(x => new DevOpsPlanDeviceGroupModel // { // CDevStoreCode = x.Key.CDevStoreCode, // DevStoreName = x.Key.DevStoreName, // Url = x.Key.Url, // CNumberCode = x.Key.CNumberCode, // }) // .ToList(); //result.ForEach(x => //{ // x.Spots = libraryModels.Where(y => y.CDevStoreCode == x.CDevStoreCode).Select(y=>new SpotGroupModel { CName=y.SpotName,CSpotCode=y.CSpotCode}).ToList(); //}); return new ApiResult>(libraryModels); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 删除设备 /// /// /// [HttpDelete("DeleteDeveice/{id}")] public async Task DeleteDeviceAsync(string id) { try { await _devOpsPlanService.DeleteDeviceAsync(id); return new ApiResult(ReturnCode.Success); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 删除运维点 /// /// /// [HttpDelete("DeleteDeviceSpot/{planId}/{spotId}")] public async Task DeleteDeviceSpotAsync(string planId, string spotId) { try { await _devOpsPlanService.DeleteDeviceSpotAsync(planId, spotId); return new ApiResult(ReturnCode.Success); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 添加运维计划设备内容 /// /// /// [HttpPost("AddDeviceContent")] public async Task AddDeviceContentAsync(DevOpsPlanContentModel devOpsPlanContentModel) { try { await _devOpsPlanService.AddDeviceContentAsync(devOpsPlanContentModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 设备内容列表 /// /// /// [HttpGet("DeviceContentList/{deviceId}/{id}")] public async Task DeviceContentListAsync(string deviceId ,string id) { try { var result = await _devOpsPlanService.DeviceContentListAsync(deviceId,id); return new ApiResult>(result); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 添加运维计划人员 /// /// /// [HttpPost("AddPlanPerson")] public async Task AddPlanPersonAsync(DevOpsPlanPersonModel devOpsPlanPersonModel) { try { await _devOpsPlanService.AddPlanPersonAsync(devOpsPlanPersonModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 计划人员列表 /// /// /// [HttpGet("PlanPersonList/{id}")] public async Task PlanPersonListAsync(string id) { try { var result = await _devOpsPlanService.PlanPersonListAsync(id); return new ApiResult>(result); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 取消计划 /// /// [HttpPost("CancelPlan/{id}")] public async Task CancelPlan(string id) { var result = await _devOpsPlanService.CancelPlan(id); return new ApiResult(result); } /// /// 确认计划 /// /// [HttpPost("ConfirmPlan/{id}")] public async Task ConfirmPlan(string id) { var result = await _devOpsPlanService.ConfirmPlan(id); return new ApiResult(result); } /// /// 生成工单 /// /// /// [HttpPost("GenerateWorkOrder/{id}")] public async Task GenerateWorkOrder(string id) { try { var result = await _devOpsPlanService.GenerateWorkOrder(id); return new ApiResult(result); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 查看工单 /// /// /// [HttpPost("GetDevOps/{id}")] public async Task GetDevOps(string id, BaseSearchModel searchModel) { List result = await _devOpsPlanService.GetDevOps(id, searchModel); return new ApiResult>(new PagesModel(result, searchModel)); } [HttpPost("SetOpsTime")] public async Task SetOpsTime(SetOpsModel model) { var result = await _devOpsPlanService.SetOpsTime(model); return new ApiResult(result); } /// /// 通过工单id获取巡检点内容. /// [HttpPost("GetSpotContent")] public async Task GetSpotContent(GetOpsSpotContentModel model) { try { if (string.IsNullOrEmpty(model.QrCode) || string.IsNullOrEmpty(model.StoreCode)) { return new ApiResult(ReturnCode.GeneralError); } var spot = await _devOpsPlanService.GetSpotContent(model); return new ApiResult(spot); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 设置点检工单状态 /// /// /// [HttpPost("SetWorkOrderStatus")] public async Task SetWorkOrderStatus(GetOpsSpotContentModel model) { try { await _devOpsPlanService.SetWorkOrderStatus(model); return new ApiResult(true); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } } }