using JiepeiWMS.Common;
using JiepeiWMS.Common.Helper;
using JiepeiWMS.Common.HttpContextUser;
using JiepeiWMS.Common.HttpRestSharp;
using JiepeiWMS.Extends;
using JiepeiWMS.IRepository.UnitOfWork;
using JiepeiWMS.IServices;
using JiepeiWMS.Model;
using JiepeiWMS.Model.BllModels;
using JiepeiWMS.Model.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
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 WMSupplierController : ControllerBase
{
///
/// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下
///
private readonly IUnitOfWork _unitOfWork;
private readonly IWMSupplierServices _wMSupplierServices;
private readonly IUser _user;
private readonly ISysUserInfoServices _sysUserInfoServices;
private readonly IWMSupplierTypeServices _wMSupplierTypeServices;
private readonly IWMSupplier_TypeServices _wMSupplier_TypeServices;
private readonly ILogger _logger;
private readonly ISysOrgServices _SysOrgServices;
private readonly IUserRoleServices _userRole;
#region 视图
public WMSupplierController(IWMSupplierServices WMSupplierServices,
IUser user,
ISysUserInfoServices SysUserInfoServices,
IWMSupplierTypeServices WMSupplierTypeServices,
IWMSupplier_TypeServices WMSupplier_TypeServices,
ILogger logger,
IUnitOfWork unitOfWork,
ISysOrgServices SysOrgServices,
IUserRoleServices userRole)
{
_wMSupplierServices = WMSupplierServices;
_user = user;
_sysUserInfoServices = SysUserInfoServices;
_wMSupplierTypeServices = WMSupplierTypeServices;
_wMSupplier_TypeServices = WMSupplier_TypeServices;
_logger = logger;
_unitOfWork = unitOfWork;
_SysOrgServices = SysOrgServices;
_userRole = userRole;
}
///
/// 供应商列表
///
/// 默认第几页
/// 供应商名称
/// 开始时间
/// 结束时间
/// 一夜多少条数据
///
[HttpGet]
public async Task>> Get(int page = 1, string key = "", DateTime? startdate = null, DateTime? enddate = null, int intPageSize = 20)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
{
key = "";
}
Expression> whereExpression = Supplier => Supplier.Id > 0;
//供应商名称
if (!string.IsNullOrWhiteSpace(key))
{
whereExpression = whereExpression.And(Supplier => Supplier.Name.Contains(key.Trim()));
}
//开始时间
if (startdate != null)
{
whereExpression = whereExpression.And(Supplier => Supplier.CreatedTime >= startdate);
}
//结束时间
if (enddate != null)
{
whereExpression = whereExpression.And(Supplier => Supplier.CreatedTime <= enddate);
}
whereExpression = whereExpression.And(Supplier => Supplier.Status > 0);
//显示当前操作人的主体ID
//whereExpression = whereExpression.And(Supplier => Supplier.SysOrgId == _user.SysOrgId);
var PageList = await _wMSupplierServices.QueryTabsPage(
(Supplier, UserInfo) => new object[]
{
JoinType.Left,Supplier.CreatedBy==UserInfo.uID
},
(Supplier, UserInfo) => new WMSupplier()
{
Id = Supplier.Id,
Sort = Supplier.Sort,
Name = Supplier.Name,
Address = Supplier.Address,
Phone = Supplier.Phone,
UnifiedCode = Supplier.UnifiedCode,
FileUrl = Supplier.FileUrl,
PostalCode = Supplier.PostalCode,
ConstactPerson = Supplier.ConstactPerson,
IsEnable = Supplier.IsEnable,
Status = Supplier.Status,
CreatedTime = Supplier.CreatedTime,
CreatedBy = Supplier.CreatedBy,
UpdatedBy = Supplier.UpdatedBy,
UpdatedTime = Supplier.UpdatedTime,
CompanyID = Supplier.CompanyID,
ShortName = Supplier.ShortName,
SysOrgId = Supplier.SysOrgId,
CreatedName = UserInfo.uRealName,
SupplierAttributes = Supplier.SupplierAttributes,
SettlementmMethod = Supplier.SettlementmMethod,
BusinessScope = Supplier.BusinessScope,
DateofEstablishment = Supplier.DateofEstablishment,
Grade = Supplier.Grade,
InvoiceType = Supplier.InvoiceType,
IsCooperation = Supplier.IsCooperation,
LeadTime = Supplier.LeadTime,
LegalRepresentative = Supplier.LegalRepresentative,
LegalTelephone = Supplier.LegalTelephone,
MainProducts = Supplier.MainProducts,
PayType = Supplier.PayType,
Position = Supplier.Position,
RegisteredCapital = Supplier.RegisteredCapital,
TaxRate = Supplier.TaxRate,
WeChat = Supplier.WeChat,
OASupplierId = Supplier.OASupplierId,
},
whereExpression,
page,
intPageSize,
" Supplier.Id desc"
);
//获取供应商的所有集合
foreach (var item in PageList.data)
{
//获取供应商和供应商类型中间表的所有信息
var allWMSupplier_Types = await _wMSupplier_TypeServices.Query(d => d.IsDeleted == false);
//获取所有供应商类型
var allTypes = await _wMSupplierTypeServices.Query(d => d.IsEnable == true);
var currentWMSupplier_Types = allWMSupplier_Types.Where(d => d.WMSupplierId == item.Id).Select(d => d.WMSupplierTypeId).ToList();
item.TypeIDs = currentWMSupplier_Types;
item.TypeNames = allTypes.Where(d => item.TypeIDs.Contains(d.OASupplierTypeId)).Select(d => d.SupTypeName).ToList();
if (!string.IsNullOrEmpty(item.FileUrl))
{
var strs = item.FileUrl.Split(';');
int count = strs.Count();
item.FileUrl1 = strs[0];
item.FileUrl2 = count > 1 ? strs[1] : "";
item.FileUrl3 = count > 2 ? strs[2] : "";
item.FileUrl4 = count > 3 ? strs[3] : "";
item.FileUrl5 = count > 4 ? strs[4] : "";
}
}
return new MessageModel>()
{
msg = "获取成功",
success = PageList.dataCount >= 0,
response = PageList
};
}
[HttpGet]
[AllowAnonymous]
public async Task> GetList(int id = 0)
{
var supplierList = await _wMSupplierServices.Query();
return new MessageModel