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 _logger; private readonly ITbdmCodeService _TbdmCodeService; /// /// 构造函数 /// /// /// public TbdmCodeController(ITbdmCodeService TbdmCodeService, ILogger logger) { _TbdmCodeService = TbdmCodeService; _logger = logger; } /// /// 获取公用代码树 /// /// [HttpGet("GetCodeListTreeAsync")] [AllowAnonymous] public async Task GetCodeListTreeAsync() { try { var content = await _TbdmCodeService.GetCodeListTreeAsync(); return new ApiResult>(content); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 条件查询获取基础数据-子表-不分页 /// /// /// [HttpPost("GetDetailCodeListByAsync")] public async Task GetDetailCodeListByAsync(TbdmCodeSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } searchModel.IsPagination = false; try { var contentList = await _TbdmCodeService.GetConditionDetailAsync(searchModel); return new ApiResult>(contentList); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 条件查询获取基础数据-子表-分页 /// /// /// [HttpPost("GetDetailCodePageByAsync")] public async Task GetDetailCodePageByAsync(TbdmCodeSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } try { var contentList = await _TbdmCodeService.GetConditionDetailAsync(searchModel); var datas = new PagesModel(contentList, searchModel); return new ApiResult>(datas); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 条件查询获取基础数据-主表-分页 /// /// /// [HttpPost("GetCodeListByAsync")] public async Task GetCodeListByAsync(TbdmCodeSearchModel searchModel) { if (searchModel == null) { return new ApiResult(ReturnCode.ArgsError); } try { var contentList = await _TbdmCodeService.GetConditionAsync(searchModel); var datas = new PagesModel(contentList, searchModel); return new ApiResult>(datas); } catch (Exception ex) { return new ApiResult(ReturnCode.GeneralError, ex.Message); } } /// /// 创建-主表 /// /// /// [HttpPost("CreateAsync")] public async Task 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); } /// /// 创建-子表 /// /// /// [HttpPost("CreateDetailAsync")] public async Task 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); } /// /// 删除-主表、子表 /// /// /// [HttpDelete("DeleteAsync/{id}")] public async Task 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); } /// /// 删除-子表 /// /// /// [HttpDelete("DeleteDetailAsync/{id}")] public async Task 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); } /// /// 禁用-主表、子表 /// /// /// [HttpPut("DisabledStatusAsync/{id}")] public async Task 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); } /// /// 禁用-子表 /// /// /// [HttpPut("DisabledDetailStatusAsync/{id}")] public async Task 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); } /// /// 更新-主表 /// /// /// /// [HttpPut("UpdateAsync/{id}")] public async Task 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); } /// /// 更新-子表 /// /// /// /// [HttpPut("UpdateDetailAsync/{id}")] public async Task 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); } } }