123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using NPOI.HSSF.UserModel;
- using NPOI.SS.UserModel;
- using NPOI.XSSF.UserModel;
- using Renci.SshNet;
- using Ropin.Inspection.Api.Common;
- using Ropin.Inspection.Api.Controllers;
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Model.ViewModel.DEV;
- using Ropin.Inspection.Service;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Security.Claims;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Api
- {
- public class TmtnDevOpsContentController : BaseController
- {
- public ILogger<TmtnDevOpsContentController> _logger { get; }
- private readonly ITmtnDevOpsContentService _TmtnDevOpsContentService;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="TmtnDevOpsContentService"></param>
- /// <param name="logger"></param>
- public TmtnDevOpsContentController(ITmtnDevOpsContentService TmtnDevOpsContentService, ILogger<TmtnDevOpsContentController> logger)
- {
- _TmtnDevOpsContentService = TmtnDevOpsContentService;
- _logger = logger;
- }
- /// <summary>
- /// 通过id获取运维内容信息
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpGet("GetDevOpsContentAsync/{id}")]
- public async Task<ApiResult> GetDevOpsContentAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var content = await _TmtnDevOpsContentService.GetConditionAsync(new TmtnDevOpsContentSearchModel { C_ID = id });
- return new ApiResult<TmtnDevOpsContentViewModel>(content.FirstOrDefault());
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取所有运维内容
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetDevOpsContentsAsync")]
- public async Task<ApiResult> GetDevOpsContentsAsync()
- {
- try
- {
- var contentList = await _TmtnDevOpsContentService.GetAllAsync();
- return new ApiResult<IEnumerable<TmtnDevOpsContentViewModel>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过运维内容名称条件查询
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetDevOpsContentsByAsync")]
- public async Task<ApiResult> GetDevOpsContentsByAsync(TmtnDevOpsContentSearchModel searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- searchModel.IsPagination = false;
- try
- {
- var contentList = await _TmtnDevOpsContentService.GetConditionAsync(searchModel);
- return new ApiResult<PagesModel<TmtnDevOpsContentViewModel>>(new PagesModel<TmtnDevOpsContentViewModel>(contentList, searchModel));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建运维内容
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateDevOpsContentAsync")]
- public async Task<ApiResult> CreateDevOpsContentAsync(TmtnDevOpsContentViewModel content)
- {
- if (content == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _TmtnDevOpsContentService.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("DeleteDevOpsContentAsync/{id}")]
- public async Task<ApiResult> DeleteDevOpsContentAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TmtnDevOpsContentService.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("UpdateDevOpsContentAsync/{id}")]
- public async Task<ApiResult> UpdateDevOpsContentAsync(string id, TmtnDevOpsContentUpdateModel updateModel)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TmtnDevOpsContentService.UpdateAsync(id, updateModel);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- [HttpPost("ImportExcel")]
- public async Task<ApiResult> ImportExcel([Required]string storeCode, [Required] IFormFile file)
- {
- try
- {
- var exName = file.FileName.Split('.').Last().ToLower();
- if (exName != "xlsx" && exName != "xls")
- {
- throw new Exception(":不是Excel文件");
- }
- IWorkbook wk = null;
- if (exName == "xlsx")
- {
- wk = new XSSFWorkbook(file.OpenReadStream());
- }
- else
- {
- wk = new HSSFWorkbook(file.OpenReadStream());
- }
- DevOpsContentImportModel importModel = new DevOpsContentImportModel();
- importModel.DevOpsContents = new List<TmtnDevOpsContentViewModel>();
- //获取第一个sheet
- ISheet sheet = wk.GetSheetAt(0);
- for (int i = 1; i <= sheet.LastRowNum; i++)
- {
- var row = sheet.GetRow(i);
- importModel.DevOpsContents.Add(new TmtnDevOpsContentViewModel
- {
- C_ID = Guid.NewGuid().ToString(),
- C_Number = row.Cells[0].ToString(),
- I_Sort = Convert.ToInt32(row.Cells[1].ToString()),
- C_Name = row.Cells[2].ToString(),
- C_AlarmLevel = row.Cells[3].ToString(),
- C_Status = row.Cells[4].ToString(),
- C_Remark = row.Cells[5].ToString(),
- C_CreateBy = GetUserId(User),
- D_CreateOn = DateTime.Now,
- C_StoreCode = storeCode
- });
- }
- await _TmtnDevOpsContentService.ImportExecl(importModel);
- return new ApiResult(ReturnCode.Success);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- }
- }
|