123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using Newtonsoft.Json;
- using NPOI.SS.Formula.Functions;
- using Ropin.Inspection.Api.Common;
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Model.ViewModel.MTN;
- using Ropin.Inspection.Service;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Api.Controllers
- {
- public class TbdmCodeController : BaseController
- {
- public readonly ILogger<TbdmCodeController> _logger;
- private readonly ITbdmCodeService _TbdmCodeService;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="TbdmCodeService"></param>
- /// <param name="logger"></param>
- public TbdmCodeController(ITbdmCodeService TbdmCodeService, ILogger<TbdmCodeController> logger)
- {
- _TbdmCodeService = TbdmCodeService;
- _logger = logger;
- }
- /// <summary>
- /// 获取公用代码树
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetCodeListTreeAsync")]
- [AllowAnonymous]
- public async Task<ApiResult> GetCodeListTreeAsync()
- {
- try
- {
- var content = await _TbdmCodeService.GetCodeListTreeAsync();
- return new ApiResult<List<TbdmCodeViewModel>>(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 条件查询获取基础数据-子表-不分页
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetDetailCodeListByAsync")]
- public async Task<ApiResult> GetDetailCodeListByAsync(TbdmCodeSearchModel searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- searchModel.IsPagination = false;
- try
- {
- var contentList = await _TbdmCodeService.GetConditionDetailAsync(searchModel);
- return new ApiResult<IEnumerable<TbdmDetailCode>>(contentList);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 条件查询获取基础数据-子表-分页
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetDetailCodePageByAsync")]
- public async Task<ApiResult> GetDetailCodePageByAsync(TbdmCodeSearchModel searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var contentList = await _TbdmCodeService.GetConditionDetailAsync(searchModel);
- var datas = new PagesModel<TbdmDetailCode>(contentList, searchModel);
- return new ApiResult<PagesModel<TbdmDetailCode>>(datas);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 条件查询获取基础数据-主表-分页
- /// </summary>
- /// <param name="searchModel"></param>
- /// <returns></returns>
- [HttpPost("GetCodeListByAsync")]
- public async Task<ApiResult> GetCodeListByAsync(TbdmCodeSearchModel searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var contentList = await _TbdmCodeService.GetConditionAsync(searchModel);
- var datas = new PagesModel<TbdmCodeViewModel>(contentList, searchModel);
- return new ApiResult<PagesModel<TbdmCodeViewModel>>(datas);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建-主表
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateAsync")]
- public async Task<ApiResult> CreateAsync(TbdmCodeViewModel content)
- {
- if (content == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _TbdmCodeService.CreateOneAsync(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 创建-子表
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateDetailAsync")]
- public async Task<ApiResult> CreateDetailAsync(TbdmCodeDetailCreateModel content)
- {
- if (content == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _TbdmCodeService.CreateDetailAsync(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("DeleteAsync/{id}")]
- public async Task<ApiResult> DeleteAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TbdmCodeService.DeleteAsync(id);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 删除-子表
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpDelete("DeleteDetailAsync/{id}")]
- public async Task<ApiResult> DeleteDetailAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TbdmCodeService.DeleteDetailAsync(id);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 禁用-主表、子表
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpPut("DisabledStatusAsync/{id}")]
- public async Task<ApiResult> DisabledStatusAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TbdmCodeService.DisabledStatusAsync(id);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 禁用-子表
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpPut("DisabledDetailStatusAsync/{id}")]
- public async Task<ApiResult> DisabledDetailStatusAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TbdmCodeService.DisabledDetailStatusAsync(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("UpdateAsync/{id}")]
- public async Task<ApiResult> UpdateAsync(string id, TbdmCodeViewModel updateModel)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TbdmCodeService.UpdateAsync(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("UpdateDetailAsync/{id}")]
- public async Task<ApiResult> UpdateDetailAsync(string id, TbdmCodeDetailUpdateModel updateModel)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _TbdmCodeService.UpdateDetailAsync(id, updateModel);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- }
- }
|