using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Api.Controllers; using Ropin.Inspection.Model; using Ropin.Inspection.Service; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Ropin.Inspection.Model.ViewModel; using Microsoft.AspNetCore.Authorization; using Ropin.Inspection.Model.Common; using static System.Net.Mime.MediaTypeNames; namespace Ropin.Inspection.Api { public class TmtnDevOpsController : BaseController { public ILogger _logger { get; } private readonly ITmtnDevOpsService _TmtnDevOpsService; private readonly IPushMsgService _pushMsgService; /// /// 构造函数 /// /// /// /// public TmtnDevOpsController(ITmtnDevOpsService TmtnDevOpsService, IPushMsgService pushMsgService, ILogger logger) { _TmtnDevOpsService = TmtnDevOpsService; _pushMsgService = pushMsgService; _logger = logger; } /// /// 通过id获取运维工单信息 /// /// /// [HttpGet("GetDevOpsAsync/{id}")] public async Task GetDevOpsAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TmtnDevOpsService.GetConditionAsync(new TmtnDevOpsSearchModel { C_ID = id }); return new ApiResult(content.FirstOrDefault()); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有运维工单 /// /// [HttpGet("GetDevOpssAsync/{name=}")] public async Task GetDevOpssAsync(string name) { try { var contentList = await _TmtnDevOpsService.GetAllAsync(); if (string.IsNullOrWhiteSpace(name)) return new ApiResult>(contentList); else return new ApiResult>(contentList.Where(x => x.C_Name.Contains(name))); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 条件查询运维工单 /// /// /// [HttpPost("GetDevOpsByAsync")] public async Task GetDevOpsByAsync(TmtnDevOpsSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TmtnDevOpsService.GetConditionAsync(searchModel); return new ApiResult>(new PagesModel(contentList, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 条件查询运维工单列表包含图片 /// /// /// [HttpPost("GetDevOpsWithImageAsync/{name=}")] public async Task GetDevOpsWithImageAsync(TmtnDevOpsOrderSearchModel searchModel, string name) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TmtnDevOpsService.GetDevOpsWithImageAsync(searchModel); if (string.IsNullOrWhiteSpace(name)) return new ApiResult>(new PagesModel(contentList, searchModel)); else return new ApiResult>(new PagesModel(contentList.Where(x => x.C_Name.Contains(name)), searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取30天运维完成统计 /// /// /// [HttpGet("Get30DaysDevOpsStatisticsAsync/{storeCode}")] public async Task GetRecords30DaysStatisticsAsync(string storeCode) { if (string.IsNullOrEmpty(storeCode)) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TmtnDevOpsService.GetRecords30DaysStatisticsAsync(storeCode); return new ApiResult(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取30天运维完成统计大屏 /// /// /// [HttpGet("GetRecords30DaysStatisticsFullScreenAsync/{storeCode}")] [AllowAnonymous] public async Task> GetRecords30DaysStatisticsFullScreenAsync(string storeCode) { if (string.IsNullOrEmpty(storeCode)) { return null; } try { var content = await _TmtnDevOpsService.GetRecords30DaysStatisticsFullScreenAsync(storeCode); return content; } catch (Exception ex) { return null; } } /// /// 创建运维工单 /// /// /// [HttpPost("CreateDevOpsAsync")] public async Task CreateDevOpsAsync(TmtnDevOpsViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _TmtnDevOpsService.CreateDevOpsAsync(content); await _pushMsgService.PushAlarmMsgAsync(new TpushMsgModel { C_DevStoreCode = content.C_DevStoreCode, C_MsgTypeCode = "MSG_TYPE_002", Msg = content.C_Name + " "+ content.C_Remark, Subject = "上报维保: " + content.C_Name, DevNumber = content.C_DevStoreCode, DevName = content.C_DevStoreName, GenerationType = 2, msgStatus = 0, }, "设备维保"); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除运维工单 /// /// /// [HttpDelete("DeleteDevOpsAsync/{id}")] public async Task DeleteDevOpsAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TmtnDevOpsService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新运维工单 /// /// /// /// [HttpPut("UpdateDevOpsAsync/{id}")] public async Task UpdateDevOpsAsync(string id, TmtnDevOpsUpdateModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TmtnDevOpsService.UpdateAsync(id, updateModel); await _pushMsgService.PushAlarmMsgAsync(new TpushMsgModel { C_DevStoreCode = updateModel.C_DevStoreCode, C_MsgTypeCode = "MSG_TYPE_009", Msg = updateModel.C_Name + " " + updateModel.C_Remark, Subject = updateModel.C_Status == "5"? "维保取消,设备名:": "维保确认,设备名:" + updateModel.C_DevStoreName, DevNumber = updateModel.C_DevStoreCode, DevName = updateModel.C_DevStoreName, GenerationType = 2, msgStatus = 0, }, "设备维保"); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 通过设备ID取运维内容及状态,大屏 /// /// /// [HttpPost("GetDevOpsFullScreenByDevIdAsync")] [AllowAnonymous] public async Task GetDevOpsFullScreenByDevIdAsync(DevOpsItemSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } try { var opslist = await _TmtnDevOpsService.GetDevOpsFullScreenByDevIdAsync(searchModel); var repairList = await _TmtnDevOpsService.GetDevRepairFullScreenByDevIdAsync(searchModel); var recordList = await _TmtnDevOpsService.GetISPRecordAsync(searchModel); IEnumerable list; if (opslist == null) opslist = new List(); if (repairList == null) repairList = new List(); if (recordList == null) recordList = new List(); list = opslist?.Concat(repairList).Concat(recordList).ToList().OrderByDescending(o => o.RecordTime); if (!list.Any()) { searchModel.TotalCount = 0; return new ApiResult>(new PagesModel(list, searchModel)); } searchModel.TotalCount = list.Count(); return new ApiResult>(new PagesModel(searchModel.IsPagination ? list.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : list, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过设备ID取运维内容及状态统计,大屏 /// /// /// [HttpPost("GetDevOpsCountFullScreenByDevIdAsync")] [AllowAnonymous] public async Task GetDevOpsCountFullScreenByDevIdAsync(DevOpsItemSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } try { var content = await _TmtnDevOpsService.GetDevOpsCountFullScreenByDevIdAsync(searchModel); //content.DevOpsRecordItem.Where(x => x.C_Status == "1").Count(); return new ApiResult(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过设备ID取维修内容及状态统计,大屏 /// /// /// [HttpPost("GetDevRepairCountFullScreenByDevIdAsync")] [AllowAnonymous] public async Task GetDevRepairCountFullScreenByDevIdAsync(DevOpsItemSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } try { var content = await _TmtnDevOpsService.GetDevRepairCountFullScreenByDevIdAsync(searchModel); //content.DevOpsRecordItem.Where(x => x.C_Status == "1").Count(); return new ApiResult(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } } }