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
{
///
/// 商品规格
///
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;
}
///
/// 查询列表
///
/// 页数
/// 关键字
/// 条数
///
[HttpGet]
public async Task>> Index(int page = 1, string key = "", int intPageSize = 20)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
{
key = "";
}
Expression> 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>()
{
msg = "获取成功",
success = productSpec.dataCount >= 0,
response = productSpec
};
}
///
/// 获取列表
///
///
[HttpGet]
[AllowAnonymous]
public async Task> Get(int id = 0)
{
var specList = await _wMProductSpecServices.Query();
return new MessageModel