using JiepeiWMS.Common.HttpContextUser;
|
using JiepeiWMS.Extends;
|
using JiepeiWMS.IServices;
|
using JiepeiWMS.Model;
|
using JiepeiWMS.Model.Models;
|
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Mvc;
|
using System;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Threading.Tasks;
|
|
namespace JiepeiWMS.Api.Controllers
|
{
|
[Route("api/[controller]/[action]")]
|
[ApiController]
|
[Authorize(Permissions.Name)]
|
public class WMProductSpecController : ControllerBase
|
{
|
/// <summary>
|
/// 商品规格
|
/// </summary>
|
private readonly IWMProductSpecServices _wMProductSpecServices;
|
private readonly IWMProductListServices _wMProductListServices;
|
private readonly ISysUserInfoServices _sysUserInfoServices;
|
private readonly ISysOrgServices _BllSysOrg;
|
readonly IUser _user;
|
|
public WMProductSpecController(IWMProductSpecServices WMProductSpecServices, IWMProductListServices WMProductListServices, ISysUserInfoServices SysUserInfoServices, ISysOrgServices BllSysOrg, IUser user)
|
{
|
_wMProductSpecServices = WMProductSpecServices;
|
_wMProductListServices = WMProductListServices;
|
_sysUserInfoServices = SysUserInfoServices;
|
_BllSysOrg = BllSysOrg;
|
_user = user;
|
}
|
|
/// <summary>
|
/// 查询列表
|
/// </summary>
|
/// <param name="page">页数</param>
|
/// <param name="key">关键字</param>
|
/// <param name="intPageSize">条数</param>
|
/// <returns></returns>
|
[HttpGet]
|
public async Task<MessageModel<PageModel<WMProductSpec>>> Index(int page = 1, string key = "", int intPageSize = 20)
|
{
|
if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
|
{
|
key = "";
|
}
|
|
Expression<Func<WMProductSpec, bool>> whereExpression = s => s.Id > 0;
|
|
//筛选主体Id
|
//var userInfoModel = await _sysUserInfoServices.QueryById(_user.ID);
|
//if (userInfoModel != null)
|
//{
|
// whereExpression = whereExpression.And(s => s.SysOrgId == userInfoModel.SysOrgId);
|
//}
|
if (!string.IsNullOrWhiteSpace(key))
|
{
|
whereExpression = whereExpression.And(s => s.Name != null && s.Name.Contains(key.Trim()));
|
}
|
|
var productSpec = await _wMProductSpecServices.QueryPage(whereExpression, page, intPageSize, " Id desc ");
|
foreach (var item in productSpec.data)
|
{
|
var UserInfoModel = await _sysUserInfoServices.QueryById(item.AdminId);
|
if (UserInfoModel != null)
|
{
|
item.AdminName = UserInfoModel.uRealName;
|
}
|
}
|
|
return new MessageModel<PageModel<WMProductSpec>>()
|
{
|
msg = "获取成功",
|
success = productSpec.dataCount >= 0,
|
response = productSpec
|
};
|
}
|
|
/// <summary>
|
/// 获取列表
|
/// </summary>
|
/// <returns></returns>
|
[HttpGet]
|
[AllowAnonymous]
|
public async Task<MessageModel<object>> Get(int id = 0)
|
{
|
var specList = await _wMProductSpecServices.Query();
|
|
return new MessageModel<object>()
|
{
|
msg = "获取成功",
|
success = true,
|
response = new
|
{
|
specList
|
}
|
};
|
}
|
|
/// <summary>
|
/// 添加
|
/// </summary>
|
/// <param name="request"></param>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<MessageModel<string>> Add([FromBody] WMProductSpec request)
|
{
|
var data = new MessageModel<string>();
|
|
request.AdminId = _user.ID;
|
request.CreateTime = DateTime.Now;
|
|
request.SysOrgId = _user.SysOrgId;
|
var id = await _wMProductSpecServices.Add(request);
|
data.success = id > 0;
|
|
if (data.success)
|
{
|
data.response = id.ObjToString();
|
data.msg = "添加成功";
|
}
|
|
return data;
|
}
|
|
/// <summary>
|
/// 更新
|
/// </summary>
|
/// <param name="request"></param>
|
/// <returns></returns>
|
[HttpPut]
|
public async Task<MessageModel<string>> Update([FromBody] WMProductSpec request)
|
{
|
var data = new MessageModel<string>();
|
if (request.Id > 0)
|
{
|
data.success = await _wMProductSpecServices.Update(request);
|
if (data.success)
|
{
|
data.msg = "更新成功";
|
data.response = request?.Id.ObjToString();
|
}
|
}
|
|
return data;
|
}
|
|
/// <summary>
|
/// 删除
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
//[HttpDelete]
|
//public async Task<MessageModel<string>> Delete(int id)
|
//{
|
// var data = new MessageModel<string>();
|
// if (id > 0)
|
// {
|
// var productSpecModel = await _wMProductSpecServices.QueryById(id);
|
// var productSpecList = await _wMProductListServices.Query(x => x.SpecIds == productSpecModel.Id);
|
// if (productSpecList != null && productSpecList.Any())
|
// {
|
// data.success = false;
|
// data.msg = "请先删除商品列表内所关联的规格";
|
// }
|
// else
|
// {
|
// data.success = await _wMProductSpecServices.Delete(productSpecModel);
|
// if (data.success)
|
// {
|
// data.msg = "删除成功";
|
// data.response = productSpecModel?.Id.ObjToString();
|
// }
|
// }
|
// }
|
|
// return data;
|
//}
|
}
|
}
|