using JiepeiWMS.Common.Helper;
using JiepeiWMS.Common.HttpContextUser;
using JiepeiWMS.Extends;
using JiepeiWMS.IServices;
using JiepeiWMS.Model;
using JiepeiWMS.Model.Models;
using JiepeiWMS.Model.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace JiepeiWMS.Api.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize(Permissions.Name)]
public class WMProductClassController : ControllerBase
{
///
/// 商品分类
///
private readonly IWMProductClassServices _wMProductClassServices;
private readonly ISysOrgServices _BllSysOrg;
readonly IUser _user;
private readonly ISysUserInfoServices _sysUserInfoServices;
private readonly IWMProductListServices _wMProductListServices;
private readonly IUserRoleServices _userRole;
public WMProductClassController(IWMProductClassServices WMProductClassServices, ISysOrgServices BllSysOrg, IUser user, ISysUserInfoServices SysUserInfoServices, IWMProductListServices WMProductListServices, IUserRoleServices userRole)
{
_wMProductClassServices = WMProductClassServices;
_BllSysOrg = BllSysOrg;
_user = user;
_sysUserInfoServices = SysUserInfoServices;
_wMProductListServices = WMProductListServices;
_userRole = userRole;
}
///
/// 查询列表
///
/// 页数
/// 关键字
/// 条数
///
[HttpGet]
public async Task>> Index(int page = 1, string key = "", int intPageSize = 20)
{
PageModel productClass = new PageModel();
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.ClassName != null && s.ClassName.Contains(key.Trim()));
}
productClass = await _wMProductClassServices.QueryPage(whereExpression, page, intPageSize, " Id desc ");
var productClassView = productClass.data;
var productClassAll = await _wMProductClassServices.Query();
foreach (var item in productClassView)
{
List pidarr = new List
{
item.ParentId
};
if (item.ParentId > 0)
{
pidarr.Add(0);
}
var parent = productClassAll.FirstOrDefault(d => d.Id == item.ParentId);
while (parent != null)
{
pidarr.Add(parent.Id);
parent = productClassAll.FirstOrDefault(d => d.Id == parent.ParentId);
}
item.ParentIdArr = pidarr.OrderBy(d => d).Distinct().ToList();
}
productClass.data = productClassView;
return new MessageModel>()
{
msg = "获取成功",
success = productClass.dataCount >= 0,
response = productClass
};
}
///
/// 获取列表
///
///
[HttpGet]
[AllowAnonymous]
public async Task> Get(int id = 0)
{
var classList = await _wMProductClassServices.Query();
//classList = classList.Where(x => x.SysOrgId == _user.SysOrgId).ToList();
return new MessageModel