133 lines
5.2 KiB
C#
133 lines
5.2 KiB
C#
using AutoMapper;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using WMS.Web.Core.Dto;
|
|
using WMS.Web.Core.Dto.SubscribeNotification;
|
|
using WMS.Web.Core.Internal.Results;
|
|
using WMS.Web.Domain.Entitys;
|
|
using WMS.Web.Domain.Infrastructure;
|
|
using WMS.Web.Domain.IService.Public;
|
|
using WMS.Web.Domain.Values;
|
|
|
|
namespace WMS.Web.Api.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 订阅通知
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class SubscribeNotificationController : ControllerBase
|
|
{
|
|
private readonly IMapper _mapper;
|
|
private readonly ILoginService _loginService;
|
|
private readonly ISubscribeNotificationRepositories _repositories;
|
|
public SubscribeNotificationController(IMapper mapper, ILoginService loginService, ISubscribeNotificationRepositories repositories)
|
|
{
|
|
_mapper = mapper;
|
|
_loginService = loginService;
|
|
_repositories = repositories;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 列表
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("GetList")]
|
|
public async Task<ResultPagedList<SubscribeNotificationQueryInfoResponse>> GetPagedList([FromBody] SubscribeNotificationQueryRequest dto)
|
|
{
|
|
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
|
if (loginInfo == null || loginInfo.UserInfo == null)
|
|
return ResultPagedList<SubscribeNotificationQueryInfoResponse>.ReFailure(ResultCodes.Token_Invalid_Error);
|
|
|
|
var (list, count) = await _repositories.GetListAsync(dto);
|
|
var result = ResultPagedList<SubscribeNotificationQueryInfoResponse>.ReSuccess(list, count);
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// 新增
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("Save")]
|
|
public async Task<Result> Save(SaveSubscribeNotificationRequest dto)
|
|
{
|
|
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
|
if (loginInfo == null || loginInfo.UserInfo == null)
|
|
return Result.ReFailure(ResultCodes.Token_Invalid_Error);
|
|
|
|
//新增
|
|
var isExist = await _repositories.IsExist(dto.CustomerName, dto.CustomerNumber);
|
|
if (isExist) return Result.ReFailure($"客户名称:{dto.CustomerName} 客户编码:{dto.CustomerName} 已经存在,无需再次添加!", 700000);
|
|
|
|
var entity = _mapper.Map<SubscribeNotification>(dto);
|
|
entity.Create(loginInfo.UserInfo.StaffId);
|
|
var res = await _repositories.Add(entity, true);
|
|
|
|
if (res == null) Result.ReFailure(ResultCodes.DateWriteError);
|
|
return Result.ReSuccess();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("Edit")]
|
|
public async Task<Result> Edit(EditSubscribeNotificationRequest dto)
|
|
{
|
|
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
|
if (loginInfo == null || loginInfo.UserInfo == null)
|
|
return Result.ReFailure(ResultCodes.Token_Invalid_Error);
|
|
|
|
var entity = await _repositories.Get(dto.Id);
|
|
if (entity == null)
|
|
return Result.ReFailure(ResultCodes.SubscribeNotificationNoData);
|
|
//修改
|
|
//修改了名字或者编码后 验重
|
|
if (entity.CustomerName != dto.CustomerName || entity.CustomerNumber != dto.CustomerNumber)
|
|
{
|
|
var isExist = await _repositories.IsExist(dto.CustomerName, dto.CustomerNumber);
|
|
if (isExist) return Result.ReFailure($"客户名称:{dto.CustomerName} 客户编码:{dto.CustomerName} 已经存在,无需再次添加!", 700000);
|
|
}
|
|
_mapper.Map(dto, entity);
|
|
entity.Edit(loginInfo.UserInfo.StaffId);
|
|
var res = await _repositories.Edit(entity, true);
|
|
|
|
if (res == null) Result.ReFailure(ResultCodes.DateWriteError);
|
|
return Result.ReSuccess();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("Delete")]
|
|
public async Task<Result> Sync(OperateRequest dto)
|
|
{
|
|
var loginInfo = _loginService.GetLoginInfo(this.HttpContext.Request.Headers["Authorization"]);
|
|
if (loginInfo == null || loginInfo.UserInfo == null)
|
|
return Result.ReFailure(ResultCodes.Token_Invalid_Error);
|
|
|
|
var list = await _repositories.GetList(dto.Ids);
|
|
foreach (var e in list)
|
|
{
|
|
e.Delete(loginInfo.UserInfo.StaffId);
|
|
}
|
|
var res = await _repositories.EditList(list, true);
|
|
|
|
if (!res) Result.ReFailure(ResultCodes.DateWriteError);
|
|
return Result.ReSuccess();
|
|
}
|
|
}
|
|
}
|