123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using Ropin.Inspection.Api.Common;
- using Ropin.Inspection.Api.Helper;
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Model.SearchModel;
- using Ropin.Inspection.Model.ViewModel;
- using Ropin.Inspection.Service.Interface;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Api.Controllers
- {
- /// <summary>
- /// 巡检点
- /// </summary>
- public class TispSpotController : BaseController
- {
- private readonly ILogger<TispSpotController> _logger;
- private readonly ITispSpotService _tispSpotService;
- private readonly ITispSpotContentService _tispSpotContentService;
-
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="tispSpotService"></param>
- /// <param name="tispSpotContentService"></param>
- /// <param name="logger"></param>
- public TispSpotController(ITispSpotService tispSpotService, ITispSpotContentService tispSpotContentService, ILogger<TispSpotController> logger)
- {
- _tispSpotService = tispSpotService;
- _tispSpotContentService = tispSpotContentService;
- _logger = logger;
- }
- /// <summary>
- /// 通过ID获取巡检点信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("GetSpotAsync/{id}")]
- public async Task<ApiResult> GetSpotAsync(Guid id)
- {
- if (Guid.Empty == id)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var spot = await _tispSpotService.GetByIdAsync(id);
- return new ApiResult<TispSpotViewModel>(spot);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取所有巡检点
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetSpotsAsync")]
- public async Task<ApiResult> GetSpotsAsync()
- {
- try
- {
- var spotList = await _tispSpotService.GetAllAsync();
- return new ApiResult<IEnumerable<TispSpotViewModel>>(spotList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 条件查询巡检点
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetSpotsConditionAsync")]
- public async Task<ApiResult> GetSpotsConditionAsync(TispSpotSearchModel searchModel)
- {
- if (null == searchModel || string.IsNullOrEmpty(searchModel.C_StoreCode))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var spotList = await _tispSpotService.GetSpotsConditionAsync(searchModel);
- return new ApiResult<PagesModel<TispSpotViewModel>>(new PagesModel<TispSpotViewModel>(spotList?.ToList(), searchModel));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 条件查询巡检点【设备运维点配置-排除业主设备运维点重复的】
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetSpotsConditionNoDevSpotRepeatAsync")]
- public async Task<ApiResult> GetSpotsConditionNoDevSpotRepeatAsync(TispSpotSearchModel searchModel)
- {
- if (null == searchModel || string.IsNullOrEmpty(searchModel.C_StoreCode))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var spotList = await _tispSpotService.GetSpotsConditionNoDevSpotRepeatAsync(searchModel);
- return new ApiResult<PagesModel<TispSpotViewModel>>(new PagesModel<TispSpotViewModel>(spotList?.ToList(), searchModel));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过二维码获取巡检点
- /// </summary>
- /// <param name="qRCode"></param>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpGet("GetSpotByQRCodeTAsync/{qRCode}/{storeCode}")]
- public async Task<ApiResult> GetSpotByQRCodeTAsync(string qRCode,string storeCode)
- {
- try
- {
- if (string.IsNullOrEmpty(qRCode)|| string.IsNullOrEmpty(storeCode))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- var spot = await _tispSpotService.GetSpotByQRCodeAsync(qRCode, storeCode);
- if (null == spot)
- {
- return new ApiResult<TispSpotViewModel>(spot, ReturnCode.ResultError, "没找到此二维码对应的巡检点,请联系管理员!");
- }
- return new ApiResult<TispSpotViewModel>(spot);
- }
- catch (Exception ex)
- {
- if (ex.Message == "此巡检点没有分配给您!")
- {
- return new ApiResult(ReturnCode.ResultError, ex.Message);
- }
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过二维码获取巡检点器具
- /// </summary>
- /// <param name="qRCode"></param>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpGet("GetSpotProductByQRCodeTAsync/{qRCode}/{storeCode}")]
- public async Task<ApiResult> GetSpotProductByQRCodeTAsync(string qRCode, string storeCode)
- {
- try
- {
- if (string.IsNullOrEmpty(qRCode) || string.IsNullOrEmpty(storeCode))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- var spot = await _tispSpotService.GetSpotProductByQRCodeTAsync(qRCode, storeCode);
- if (null == spot)
- {
- return new ApiResult<TispSpotViewModel>(spot, ReturnCode.ResultError, "没找到此二维码对应的巡检点,请联系管理员!");
- }
- return new ApiResult<TispSpotViewModel>(spot);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过二维码获取点及设备信息
- /// </summary>
- /// <param name="qRCode"></param>
- /// <param name="storeCode"></param>
- /// <returns></returns>
- [HttpGet("GetDevStoreByQRCodeAsync/{qRCode}/{storeCode}")]
- 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 _tispSpotService.GetDevStoreByQRCodeAsync(qRCode, storeCode);
- if (null == spot)
- {
- return new ApiResult<TispSpotDevStoreViewModel>(spot, ReturnCode.ResultError, "没找到此二维码对应的点,请联系管理员!");
- }
- return new ApiResult<TispSpotDevStoreViewModel>(spot);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建巡检点
- /// </summary>
- /// <param name="spot">巡检点</param>
- /// <returns></returns>
- //public async Task<ApiResult> CreateSpotAsync([FromQuery] TispSpotCreateViewModel spot, [FromQuery] List<Guid> contentList)
- [Route("CreateSpotAsync")]
- [HttpPost]
- public async Task<ApiResult> CreateSpotAsync(TispSpotCreateViewModel spot)
- {
- if (spot == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- Guid spotId = Guid.NewGuid();
- spot.C_Code = spotId;
- await _tispSpotService.CreateOneAsync(spot);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 创建设备巡检运维点
- /// </summary>
- /// <param name="spot"></param>
- /// <returns></returns>
- [Route("CreateOneByDevAsync")]
- [HttpPost]
- public async Task<ApiResult> CreateOneByDevAsync(TispSpotByDevCreateViewModel spot)
- {
- if (spot == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- Guid spotId = Guid.NewGuid();
- spot.C_Code = spotId;
- await _tispSpotService.CreateOneByDevAsync(spot);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 删除巡检点
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpDelete("DeleteSpotAsync/{id}")]
- public async Task<ApiResult> DeleteSpotAsync(Guid id)
- {
- if (Guid.Empty == id)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _tispSpotService.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("UpdateSpotAsync/{id}")]
- public async Task<ApiResult> UpdateSpotAsync(Guid id, TispSpotUpdateViewModel updateModel)
- {
- if (Guid.Empty == id)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _tispSpotService.UpdateAsync(id, updateModel);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 扫码绑定,包括二维码,GPS,照片
- /// </summary>
- /// <param name="id"></param>
- /// <param name="updateModel"></param>
- /// <returns></returns>
- [HttpPut("UpdateConfigureSpotAsync/{id}")]
- public async Task<ApiResult> UpdateConfigureSpotAsync(Guid id, TispSpotConfigureUpdateViewModel updateModel)
- {
- if (Guid.Empty == id)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _tispSpotService.UpdateConfigureSpotAsync(id, updateModel);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 更新巡检点图片
- /// </summary>
- /// <param name="spotId"></param>
- /// <param name="Files"></param>
- /// <returns></returns>
- [HttpPost("UploadSpotImageAsync/{spotId}")]
- public async Task<ApiResult> UploadSpotImageAsync(Guid spotId, IFormCollection Files)
- {
- try
- {
- if (Guid.Empty.Equals(spotId)|| null == Files)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- Hashtable hash = new Hashtable();
- IFormFileCollection cols = Request.Form.Files;
- if (cols == null || cols.Count == 0)
- {
- return new ApiResult(ReturnCode.GeneralError, "没有上传文件");
- }
- foreach (IFormFile file in cols)
- {
- //定义图片数组后缀格式
- string[] LimitPictureType = { ".JPG", ".JPEG", ".GIF", ".PNG", ".BMP" };
- //获取图片后缀是否存在数组中
- string currentPictureExtension = Path.GetExtension(file.FileName).ToUpper();
- if (LimitPictureType.Contains(currentPictureExtension))
- {
- var new_path = Path.Combine("uploads/images/spots/", file.FileName);
- var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", new_path);
- using (var stream = new FileStream(path, FileMode.Create))
- {
- await Task.Run(() => { file.CopyTo(stream); hash.Add("file", "/" + new_path); });
- }
- }
- else
- {
- return new ApiResult(ReturnCode.GeneralError, "请上传指定格式的图片");
- }
- }
- return new ApiResult<Hashtable>(new Hashtable(hash));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message + ex.InnerException);
- }
- }
- }
- }
|