123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- using log4net;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Ropin.Inspection.Api.Common;
- using Ropin.Inspection.Model.SearchModel.LGS;
- using Ropin.Inspection.Model.ViewModel.LGS;
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Service.LGS.Interface;
- using System.Threading.Tasks;
- using System;
- using Ropin.Core.Extensions.Redis;
- using Ropin.Inspection.Common.Accessor.Interface;
- using System.Security.Claims;
- using NPOI.POIFS.Crypt.Dsig;
- using System.Collections.Generic;
- namespace Ropin.Inspection.Api.Controllers.LGS
- {
- public class LargeScreenControlController : BaseController
- {
- private readonly ILargeScreenControlService _repository;
- private static readonly ILog log = LogManager.GetLogger(typeof(LargeScreenControlController));
- private readonly IRedisBasketRepository _redisService;
- private readonly IClaimsAccessor _claims;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="repository"></param>
- public LargeScreenControlController(ILargeScreenControlService repository, IRedisBasketRepository redisService, IClaimsAccessor claims)
- {
- _repository = repository;
- _redisService = redisService;
- _claims = claims;
- }
- /// <summary>
- /// 创建大屏控件
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateLargeScreenControlAsync")]
- public async Task<ApiResult> CreateLargeScreenControlAsync(LargeScreenControlViewModel content)
- {
- if (content == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _repository.CreateOneAsync(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 删除大屏控件
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpDelete("DeleteLargeScreenControlAsync/{id}")]
- public async Task<ApiResult> DeleteLargeScreenControlAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _repository.DeleteAsync(id);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 更新大屏控件
- /// </summary>
- /// <param name="id"></param>
- /// <param name="updateModel"></param>
- /// <returns></returns>
- [HttpPut("UpdateLargeScreenControlAsync/{id}")]
- [AllowAnonymous]
- public async Task<ApiResult> UpdateLargeScreenControlAsync(string id, LargeScreenControlViewModel updateModel)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _repository.UpdateAsync(updateModel, id);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 保存大屏控件
- /// </summary>
- /// <param name="id"></param>
- /// <param name="updateModel"></param>
- /// <returns></returns>
- [HttpPut("SaveLargeScreenControlAsync/{id}")]
- [AllowAnonymous]
- public async Task<ApiResult> SaveLargeScreenControlAsync(string id, List<LargeScreenControlViewModel> updateModel)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- if (updateModel == null || updateModel.Count <= 0)
- {
- await _repository.DeleteByLargeScreenCodeAsync(id);
- }
- else
- {
- await _repository.SaveAsync(updateModel);
- }
- return new ApiResult(ReturnCode.Success);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 更新大屏控件样式
- /// </summary>
- /// <param name="id"></param>
- /// <param name="updateModel"></param>
- /// <returns></returns>
- [HttpPut("UpdateLargeScreenControlStyleAsync/{id}")]
- [AllowAnonymous]
- public async Task<ApiResult> UpdateLargeScreenControlStyleAsync(string id, LargeScreenControlViewModel updateModel)
- {
- if (string.IsNullOrEmpty(id)|| updateModel==null||string.IsNullOrEmpty(updateModel.C_Style))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- LargeScreenControlViewModel data = await _repository.GetByIdAsync(id);
- data.C_Style = updateModel.C_Style;
- await _repository.UpdateAsync(updateModel, id);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 获取大屏控件列表
- /// </summary>
- /// <returns></returns>
- [HttpPost("GetLargeScreenControlAsync")]
- [AllowAnonymous]
- public async Task<ApiResult> GetLargeScreenControlAsync(LargeScreenControlSearch searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var contentList = await _repository.GetConditionAsync(searchModel);
- return new ApiResult<PagesModel<LargeScreenControlViewModel>>(new PagesModel<LargeScreenControlViewModel>(contentList, searchModel));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过id获取大屏控件详情
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetLargeScreenControlByIDAsync")]
- [AllowAnonymous]
- public async Task<ApiResult> GetLargeScreenControlByIDAsync(string Id)
- {
- if (string.IsNullOrEmpty(Id))
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- LargeScreenControlViewModel data = await _repository.GetByIdAsync(Id);
- return new ApiResult<LargeScreenControlViewModel>(data);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 将ID值存入缓存中
- /// </summary>
- /// <returns></returns>
- [HttpGet("RedisSetLargeScreenControlID")]
- [AllowAnonymous]
- public async Task<ApiResult> RedisSetLargeScreenControlID(string Id)
- {
- if (string.IsNullOrEmpty(Id))
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- string key= "LargeScreenControl_ID";
- await _redisService.Set(key, Id, TimeSpan.FromDays(7));
- return new ApiResult(ReturnCode.Success);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取存入缓存中ID
- /// </summary>
- /// <returns></returns>
- [HttpGet("RedisGetLargeScreenControlID")]
- [AllowAnonymous]
- public async Task<ApiResult> RedisGetLargeScreenControlID()
- {
- try
- {
- string key = "LargeScreenControl_ID";
- string val= await _redisService.GetValue(key);
- var data = new
- {
- Value = val
- };
- return new ApiResult<object>(data);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- }
- }
|