109 lines
3.5 KiB
C#
109 lines
3.5 KiB
C#
using LangGuan.Command.Model;
|
|
using LangGuan.Command.Model.EntityModel;
|
|
using LangGuan.Command.Model.RequestModel;
|
|
using LangGuan.Services;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LangGuan.Controllers
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[ApiVersion("1.0")]
|
|
[Route("api/[controller]/v{version:apiVersion}")]
|
|
[ApiController]
|
|
public class EmployeeController : ControllerBase
|
|
{
|
|
private readonly ILogger<EmployeeController> _logger;
|
|
private readonly EmployeeService _employee;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="employee"></param>
|
|
public EmployeeController(EmployeeService employee)
|
|
{
|
|
_employee = employee;
|
|
}
|
|
/// <summary>
|
|
/// 登录
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("login")]
|
|
public async Task<IActionResult> Login(RequestLogin request)
|
|
{
|
|
request.Pwd = ToMD5(request.Pwd);
|
|
var result = await _employee.Login(request.Account, request.Pwd);
|
|
return Ok(result);
|
|
}
|
|
/// <summary>
|
|
/// 列表查询
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("list")]
|
|
public async Task<IActionResult> Check([FromQuery] RqeustPaging request)
|
|
{
|
|
var result = await _employee.GetList(request);
|
|
return Ok(result);
|
|
}
|
|
/// <summary>
|
|
/// 新加
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("add")]
|
|
public async Task<IActionResult> Add(Employee request)
|
|
{
|
|
var result = await _employee.Add(request.Account, ToMD5(request.Pwd), request.NickName);
|
|
return Ok(result);
|
|
}
|
|
/// <summary>
|
|
/// 修改密码
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Update")]
|
|
public async Task<IActionResult> Update(RequestUpdateAccount request)
|
|
{
|
|
request.Pwd = ToMD5(request.Pwd);
|
|
request.NewPwd = ToMD5(request.NewPwd);
|
|
var result = await _employee.Update(request.Account, request.Pwd, request.NewPwd);
|
|
return Ok(result);
|
|
}
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="ids"></param>
|
|
/// <returns></returns>
|
|
[HttpDelete("remove")]
|
|
public async Task<IActionResult> remove(IEnumerable<string> ids)
|
|
{
|
|
if (ids.Any())
|
|
{
|
|
foreach (var item in ids)
|
|
{
|
|
await _employee.RemoveAsync(item);
|
|
}
|
|
}
|
|
return Ok(new ApiResult() { code = 0, msg = "" });
|
|
}
|
|
|
|
string ToMD5(string strs)
|
|
{
|
|
MD5 md5 = new MD5CryptoServiceProvider();
|
|
byte[] bytes = Encoding.Default.GetBytes(strs);//将要加密的字符串转换为字节数组
|
|
byte[] encryptdata = md5.ComputeHash(bytes);//将字符串加密后也转换为字符数组
|
|
return Convert.ToBase64String(encryptdata);//将加密后的字节数组转换为加密字符串
|
|
}
|
|
}
|
|
}
|