using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ropin.Inspection.Api.Common; using Ropin.Inspection.Api.Controllers; using Ropin.Inspection.Model; using Ropin.Inspection.Model.Entities; using Ropin.Inspection.Model.ViewModel; using Ropin.Inspection.Service; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Ropin.Inspection.Api { public class TmtnDevOperateRecordController : BaseController { public ILogger _logger { get; } private readonly ITmtnDevOperateRecordService _TmtnDevOperateRecordService; /// /// 构造函数 /// /// /// public TmtnDevOperateRecordController(ITmtnDevOperateRecordService TmtnDevOperateRecordService, ILogger logger) { _TmtnDevOperateRecordService = TmtnDevOperateRecordService; _logger = logger; } /// /// 取运维工单统计 /// /// /// [HttpGet("GetDevOpsStatisticsAsync/{storeCode}")] public async Task GetDevOpsStatisticsAsync(string storeCode) { if (string.IsNullOrEmpty(storeCode)) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TmtnDevOperateRecordService.GetDevOpsStatisticsAsync(storeCode); return new ApiResult(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 维保次数统计,大屏 /// /// /// [HttpGet("GetDevOpsStatisticsFullScreenAsync/{storeCode}")] [AllowAnonymous] public async Task> GetDevOpsStatisticsFullScreenAsync(string storeCode) { if (string.IsNullOrEmpty(storeCode)) { return new FullScreenRecordItem[0]; } try { var content = await _TmtnDevOperateRecordService.GetDevOpsStatisticsFullScreenAsync(storeCode); return content; } catch { return new FullScreenRecordItem[0]; } } /// /// 通过id获取设备操作记录信息 /// /// /// [HttpGet("GetDevOperateRecordAsync/{id}")] public async Task GetDevOperateRecordAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { var content = await _TmtnDevOperateRecordService.GetConditionAsync(new TmtnDevOperateRecordSearchModel { C_ID = id }); return new ApiResult(content.FirstOrDefault()); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 获取所有设备操作记录 /// /// [HttpGet("GetDevOperateRecordsAsync")] public async Task GetDevOperateRecordsAsync() { try { var contentList = await _TmtnDevOperateRecordService.GetAllAsync(); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 通过设备操作记录名称条件查询 /// /// /// [HttpPost("GetDevOperateRecordsByAsync")] public async Task GetDevOperateRecordsByAsync(TmtnDevOperateRecordSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TmtnDevOperateRecordService.GetConditionAsync(searchModel); return new ApiResult>(new PagesModel(contentList, searchModel)); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建设备操作记录 /// /// /// [HttpPost("CreateDevOperateRecordAsync")] public async Task CreateDevOperateRecordAsync(TmtnDevOperateRecordViewModel content) { if (content == null) { return new ApiResult(ReturnCode.ArgsError); } try { await _TmtnDevOperateRecordService.CreateOneAsync(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 删除设备操作记录 /// /// /// [HttpDelete("DeleteDevOperateRecordAsync/{id}")] public async Task DeleteDevOperateRecordAsync(string id) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TmtnDevOperateRecordService.DeleteAsync(id); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 更新设备操作记录 /// /// /// /// [HttpPut("UpdateDevOperateRecordAsync/{id}")] public async Task UpdateDevOperateRecordAsync(string id, TmtnDevOperateRecordUpdateModel updateModel) { if (string.IsNullOrEmpty(id)) { return new ApiResult(ReturnCode.GeneralError); } try { await _TmtnDevOperateRecordService.UpdateAsync(id, updateModel); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } return new ApiResult(ReturnCode.Success); } /// /// 通过维保id获取维保列表 /// /// /// /// [HttpGet("GetDevOpsRecordItemAsync/{devId}/{repairId}")] public async Task GetRepairOrderItemViewAsync(string devId, string repairId) { if (string.IsNullOrEmpty(devId)) return new ApiResult(ReturnCode.GeneralError); if (string.IsNullOrEmpty(repairId)) return new ApiResult(ReturnCode.GeneralError); try { var content = await _TmtnDevOperateRecordService.GetDevOpsRecordItemAsync(devId, repairId); return new ApiResult(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } } }