123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using Newtonsoft.Json;
- 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.Core.Extensions.Redis;
- using Ropin.Core.Common;
- using Ropin.Inspection.Service.DEV.Interface;
- using Ropin.Inspection.Model.ViewModel.DEV;
- using Newtonsoft.Json.Linq;
- using Ropin.Inspection.Model.SearchModel.DEV;
- namespace Ropin.Inspection.Api
- {
- public class TdevDevStoreController : BaseController
- {
- public ILogger<TdevDevStoreController> _logger { get; }
- private readonly ITdevDevStoreService _TdevDevStoreService;
- private readonly IPushMsgService _pushMsgService;
- private readonly IRedisBasketRepository _redisBasketRepository;
- private readonly ITdevDevOpeAccountService _tdevDevOpeAccountService;
- private readonly IDevDevOpeAccountConfigService _devDevOpeAccountConfigService;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="TdevDevStoreService"></param>
- /// <param name="logger"></param>
- public TdevDevStoreController(ITdevDevStoreService TdevDevStoreService, ITdevDevOpeAccountService tdevDevOpeAccountService,IRedisBasketRepository redisBasketRepository, IPushMsgService pushMsgService, ILogger<TdevDevStoreController> logger, IDevDevOpeAccountConfigService devDevOpeAccountConfigService)
- {
- _TdevDevStoreService = TdevDevStoreService;
- _logger = logger;
- _pushMsgService = pushMsgService;
- _redisBasketRepository = redisBasketRepository;
- _tdevDevOpeAccountService = tdevDevOpeAccountService;
- _devDevOpeAccountConfigService = devDevOpeAccountConfigService;
- }
- /// <summary>
- /// 通过id获取业主设备信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("GetDevStoreAsync/{id}")]
- [AllowAnonymous]
- public async Task<ApiResult> GetDevStoreAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var content = await _TdevDevStoreService.GetConditionAsync(new TdevDevStoreSearchModel { C_ID = id, type= "details" });
- var dev = content.FirstOrDefault();
-
- var user = await _TdevDevStoreService.GetUserByDevStoreIdAndRoleNameAsync(id,"设备管理员");
- if(dev != null)
- dev.DevManager = user?.C_Name;
- return new ApiResult<TdevDevStoreViewModel>(dev);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过id获取业主设备二维码地址信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("GetDevStoreQRCodeAsync/{id}")]
- public async Task<ApiResult> GetDevStoreQRCodeAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var content = await _TdevDevStoreService.GetDevStoreQRCodeAsync(id);
- return new ApiResult<string>(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取所有业主设备
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetDevStoresAsync")]
- public async Task<ApiResult> GetDevStoresAsync()
- {
- try
- {
- var contentList = await _TdevDevStoreService.GetAllAsync();
- return new ApiResult<IEnumerable<TdevDevStoreViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过业主设备名称条件查询
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetDevStoresByAsync")]
- public async Task<ApiResult> GetDevStoresByAsync(TdevDevStoreSearchModel searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- //searchModel.IsPagination = false;
- try
- {
- var contentList = await _TdevDevStoreService.GetConditionAsync(searchModel);
- PagesModel<TdevDevStoreViewModel> pages = new PagesModel<TdevDevStoreViewModel>(searchModel.IsPagination ? contentList.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : contentList, searchModel);
- return new ApiResult<PagesModel<TdevDevStoreViewModel>>(pages);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过业主设备名称条件查询(数据包时间)
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetDevStoresByAsync1")]
- public async Task<ApiResult> GetDevStoresByAsync1(TdevDevStoreSearchModel searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- //searchModel.IsPagination = false;
- try
- {
- var contentList = await _TdevDevStoreService.GetConditionAsync(searchModel);
- foreach (var item in contentList)
- {
- if (item!=null)
- {
- var content = await _redisBasketRepository.GetValue(RedisKey.Fanyibox_DevStore_ + item.C_ID);
- if (content!=null)
- {
- try
- {
- JObject jsonObj = JObject.Parse(content);
- if (jsonObj != null&& jsonObj["package"].Any())
- {
- JObject address = (JObject)jsonObj["package"];
- item.packageTime = address["time"].ToString();
- }
- }
- catch
- {
- }
- }
- }
- }
- PagesModel<TdevDevStoreViewModel> pages = new PagesModel<TdevDevStoreViewModel>(searchModel.IsPagination ? contentList.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : contentList, searchModel);
- return new ApiResult<PagesModel<TdevDevStoreViewModel>>(pages);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
-
- /// <summary>
- /// 业主设备状态统计
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetDevStoreStatusCount")]
- public async Task<ApiResult> GetDevStoreStatusCount(TdevDevStoreSearchModel searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var contentList = await _TdevDevStoreService.GetDevStoreStatusCount(searchModel);
- PagesModel<DevStoreStatusGroup> pages = new PagesModel<DevStoreStatusGroup>(searchModel.IsPagination ? contentList.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : contentList, searchModel);
- return new ApiResult<PagesModel<DevStoreStatusGroup>>(pages);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建业主设备
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateDevStoreAsync")]
- public async Task<ApiResult> CreateDevStoreAsync(TdevDevStoreViewModel content)
- {
- if (content == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _TdevDevStoreService.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("DeleteDevStoreAsync/{id}")]
- public async Task<ApiResult> DeleteDevStoreAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TdevDevStoreService.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("UpdateDevStoreAsync/{id}")]
- [AllowAnonymous]
- public async Task<ApiResult> UpdateDevStoreAsync(string id, TdevDevStoreUpdateModel updateModel)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TdevDevStoreService.UpdateAsync(id, updateModel);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 通过二维码获取点及设备信息
- /// </summary>
- /// <param name="qRCode"></param>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpGet("GetDevStoreByQRCodeAsync/{qRCode}/{storeCode}")]
- [AllowAnonymous]
- public async Task<ApiResult> GetDevStoreByQRCodeAsync(string qRCode, string storeCode)
- {
- try
- {
- if (string.IsNullOrEmpty(qRCode) || string.IsNullOrEmpty(storeCode))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- var spot = await _TdevDevStoreService.GetDevStoreByQRCodeAsync(qRCode, storeCode);
- if (null == spot)
- {
- return new ApiResult<TdevDevStoreDetailViewModel>(spot, ReturnCode.ResultError, "没找到此二维码对应的点,请联系管理员!");
- }
- return new ApiResult<TdevDevStoreDetailViewModel>(spot);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 操作设备
- /// </summary>
- /// <param name="mode"></param>
- /// <returns></returns>
- [HttpPost("DevOperateByQRCodeAsync")]
- [AllowAnonymous]
- public async Task<ApiResult> DevOperateByQRCodeAsync(DevOperateCreateModel mode)
- {
- if (mode == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _TdevDevStoreService.DevOperateByQRCodeAsync(mode);
- //await _redisBasketRepository.Set(RedisKey.Fanyibox_Ope_DevStore + mode.C_DevStoreCode, mode.C_Type, TimeSpan.FromDays(7));
- await _pushMsgService.PushAlarmMsgAsync(new TpushMsgModel
- {
- C_DevStoreCode = mode.C_DevStoreCode,
- C_MsgTypeCode = "MSG_TYPE_011",
- Msg = mode.C_Remark,
- Subject = "设备启停 " + mode.C_LogMsg,
- DevNumber = String.Empty,
- DevName =String.Empty,
- GenerationType = 2,
- msgStatus = 4,
- }, "设备启停");
- //string strContent = "";
- //await _tdevDevOpeAccountService.CreateOneAsync(new TdevDevOpeAccountViewModel{ C_DevStoreCode = mode.C_DevStoreCode,C_Content = strContent });
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 获取设备运行点配置
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("GetDevStoreRunSpotConfigAsync/{id}")]
- [AllowAnonymous]
- public async Task<ApiResult> GetDevStoreRunSpotConfigAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- //TDEV_DevRunSpot
- //var content = await _TdevDevStoreService.GetConditionAsync(new TdevDevStoreSearchModel { C_ID = id });
- //TdevDevStoreRunSpotConfigViewModel mode = new TdevDevStoreRunSpotConfigViewModel();
- ////RunSpotConfig f1 = new RunSpotConfig() { Name = "排污口编号",Value = "325465465" };
- ////RunSpotConfig f2 = new RunSpotConfig() { Name = "设施名称",Value = "VOCs治理设施" };
- ////mode.RunSpotConfigList = new List<RunSpotConfig>() { f1,f2};
- //if (content.FirstOrDefault().C_RunSpotConfig == null)
- // return new ApiResult<IEnumerable<string>>(new List<string>());
- //else
- //return new ApiResult<TdevDevStoreRunSpotConfigViewModel>(JsonConvert.DeserializeObject<TdevDevStoreRunSpotConfigViewModel>(content.FirstOrDefault().C_RunSpotConfig));
- var content = await _devDevOpeAccountConfigService.GetDevOpeAccountConfigModelAsync(id);
- if (content == null|| string.IsNullOrEmpty(content.C_Config))
- {
- return new ApiResult<IEnumerable<string>>(new List<string>());
- }
- else
- {
- return new ApiResult<TdevDevOpeAccountConfigViewModel>(JsonConvert.DeserializeObject<TdevDevOpeAccountConfigViewModel>(content.C_Config));
- }
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 更新设备运行点配置
- /// </summary>
- /// <param name="id"></param>
- /// <param name="updateModel"></param>
- /// <returns></returns>
- [HttpPut("UpdateDevStoreRunSpotConfigAsync/{id}")]
- public async Task<ApiResult> UpdateDevStoreRunSpotConfigAsync(string id, TdevDevStoreRunSpotConfigViewModel updateModel)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TdevDevStoreService.UpdateDevStoreRunSpotConfigAsync(id, updateModel);
- }
- 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("UpdateDevStoreUserConfigAsync/{id}")]
- [AllowAnonymous]
- public async Task<ApiResult> UpdateDevStoreUserConfigAsync(string id, TdevDevStoreUserConfigViewModel updateModel)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TdevDevStoreService.UpdateDevStoreUserConfigAsync(id, updateModel);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 获取设备用户配置
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("GetDevStoreUserConfigAsync/{id}")]
- [AllowAnonymous]
- public async Task<ApiResult> GetDevStoreUserConfigAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var content = await _TdevDevStoreService.GetConditionAsync(new TdevDevStoreSearchModel { C_ID = id });
- if(content.FirstOrDefault().C_UserConfig == null)
- {
- return new ApiResult<IEnumerable<DevStoreUser>>(new List<DevStoreUser>());
- }
- else
- {
- IEnumerable<DevStoreUser> users = JsonConvert.DeserializeObject<IEnumerable<DevStoreUser>>(content.FirstOrDefault().C_UserConfig).OrderBy(t=>t.Sort);
- return new ApiResult<IEnumerable<DevStoreUser>>(users);
- }
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 拷贝业主设备信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpPost("CopyDevStoreInfo")]
- [AllowAnonymous]
- public async Task<ApiResult> CopyDevStoreInfo(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TdevDevStoreService.CopyCreateOneAsync(id);
- return new ApiResult(ReturnCode.Success);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- }
- }
|