123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.Extensions.Logging;
- using Ropin.Inspection.Api.Common;
- using Ropin.Inspection.Model.ViewModel;
- using Ropin.Inspection.Service.Interface;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Api.Controllers
- {
- /// <summary>
- /// 岗位
- /// </summary>
- public class TsysPostController : BaseController
- {
- public ILogger<TsysPostController> _logger { get; }
- private readonly ITsysPostService _tsysPostService;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="tsysPostService"></param>
- /// <param name="logger"></param>
- public TsysPostController(ITsysPostService tsysPostService, ILogger<TsysPostController> logger)
- {
- _tsysPostService = tsysPostService;
- _logger = logger;
- }
- /// <summary>
- /// 通过岗位ID获取岗位信息
- /// </summary>
- /// <param name="PostId"></param>
- /// <returns></returns>
- [HttpGet("GetPostAsync/{PostId}")]
- public async Task<ApiResult> GetPostAsync(Guid PostId)
- {
- if (Guid.Empty == PostId)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- var Post = await _tsysPostService.GetByIdAsync(PostId);
- return new ApiResult<TsysPostViewModel>(Post);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取所有岗位
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetPostsAsync")]
- public async Task<ApiResult> GetPostsAsync()
- {
- try
- {
- var PostList = await _tsysPostService.GetAllAsync();
- return new ApiResult<IEnumerable<TsysPostViewModel>>(PostList?.ToList());
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 创建岗位
- /// </summary>
- /// <param name="Post"></param>
- /// <returns></returns>
- [Route("CreatePostAsync")]
- [HttpPost]
- public async Task<ApiResult> CreatePostAsync(TsysPostViewModel Post)
- {
- if (Post == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _tsysPostService.CreateOneAsync(Post);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 删除岗位
- /// </summary>
- /// <param name="PostId"></param>
- /// <returns></returns>
- [HttpDelete("DeletePostAsync/{PostId}")]
- public async Task<ApiResult> DeletePostAsync(Guid PostId)
- {
- if (Guid.Empty == PostId)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _tsysPostService.DeleteAsync(PostId);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 更新岗位
- /// </summary>
- /// <param name="PostId"></param>
- /// <param name="updatePost"></param>
- /// <returns></returns>
- [HttpPut("UpdatePostAsync/{PostId}")]
- public async Task<ApiResult> UpdatePostAsync(Guid PostId, TsysPostUpdateViewModel updatePost)
- {
- if (Guid.Empty == PostId)
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _tsysPostService.UpdateAsync(PostId, updatePost);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- }
- }
|