123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- 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;
- namespace Ropin.Inspection.Api
- {
- public class TdevDevSpotController : BaseController
- {
- public ILogger<TdevDevSpotController> _logger { get; }
- private readonly ITdevDevSpotService _TdevDevSpotService;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="TdevDevSpotService"></param>
- /// <param name="logger"></param>
- public TdevDevSpotController(ITdevDevSpotService TdevDevSpotService, ILogger<TdevDevSpotController> logger)
- {
- _TdevDevSpotService = TdevDevSpotService;
- _logger = logger;
- }
- /// <summary>
- /// 通过id获取业主设备点信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("GetDevSpotAsync/{id}")]
- public async Task<ApiResult> GetDevSpotAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var content = await _TdevDevSpotService.GetConditionAsync(new TdevDevSpotSearchModel { C_ID = id });
- return new ApiResult<TdevDevSpotViewModel>(content.FirstOrDefault());
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取所有业主设备点
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetDevSpotsAsync")]
- public async Task<ApiResult> GetDevSpotsAsync()
- {
- try
- {
- var contentList = await _TdevDevSpotService.GetAllAsync();
- return new ApiResult<IEnumerable<TdevDevSpotViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过业主设备点名称条件查询
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetDevSpotsByAsync")]
- public async Task<ApiResult> GetDevSpotsByAsync(TdevDevSpotSearchModel searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- searchModel.IsPagination = false;
- try
- {
- var contentList = await _TdevDevSpotService.GetConditionAsync(searchModel);
- return new ApiResult<PagesModel<TdevDevSpotViewModel>>(new PagesModel<TdevDevSpotViewModel>(contentList, searchModel));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建业主设备点
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateDevSpotAsync")]
- public async Task<ApiResult> CreateDevSpotAsync(TdevDevSpotViewModel content)
- {
- if (content == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _TdevDevSpotService.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("DeleteDevSpotAsync/{id}")]
- public async Task<ApiResult> DeleteDevSpotAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TdevDevSpotService.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("UpdateDevSpotAsync/{id}")]
- public async Task<ApiResult> UpdateDevSpotAsync(string id, TdevDevSpotUpdateModel updateModel)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TdevDevSpotService.UpdateAsync(id, updateModel);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 更新业主设备点列表
- /// </summary>
- /// <param name="updateModel"></param>
- /// <returns></returns>
- [HttpPost("UpdateDevSpotAsync")]
- public async Task<ApiResult> UpdateDevSpotAsync(TdevDevSpotsUpdateModel updateModel)
- {
- if (updateModel == null || updateModel.SpotCodeList == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _TdevDevSpotService.UpdateDevSpotAsync(updateModel);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- }
- }
|