using JiepeiWMS.Common.Enums;
using JiepeiWMS.Common.Helper;
using JiepeiWMS.Common.HttpContextUser;
using JiepeiWMS.Extends;
using JiepeiWMS.Filter;
using JiepeiWMS.IServices;
using JiepeiWMS.Model;
using JiepeiWMS.Model.Models;
using JiepeiWMS.Model.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SqlSugar;
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 WMQuoteInfoController : ControllerBase
{
///
/// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下
///
private readonly IWMQuoteInfoServices _BllWMQuoteInfo;
private readonly IWMQuoteInfoLogServices _BllWMQuoteInfoLog;
private readonly IWMPurchaseQuoteDetailServices _BllWMPurchaseQuoteDetail;
private readonly IWMSupplierServices _BllWMSupplier;
private readonly IWMPurchaseInfoServices _BllWMPurchase;
private readonly ISysUserInfoServices _BllSysUserInfo;
private readonly ISysOrgServices _BllSysOrg;
private readonly IWMProductUnitServices _BllWMProductUnit;
private readonly IUser _User;
ILogger _Logger;
public WMQuoteInfoController(
IWMQuoteInfoServices BllWMQuoteInfo,
IWMPurchaseQuoteDetailServices BllWMPurchaseQuoteDetail,
IWMSupplierServices BllWMSupplier,
ISysUserInfoServices BllSysUserInfo,
ISysOrgServices BllSysOrg,
IWMProductUnitServices BllWMProductUnit,
IUser User,
ILogger Logger,
IWMQuoteInfoLogServices BllWMQuoteInfoLog,
IWMPurchaseInfoServices BllWMPurchase
)
{
_BllWMQuoteInfo = BllWMQuoteInfo;
_BllWMPurchaseQuoteDetail = BllWMPurchaseQuoteDetail;
_BllWMSupplier = BllWMSupplier;
_BllSysUserInfo = BllSysUserInfo;
_BllSysOrg = BllSysOrg;
_BllWMProductUnit = BllWMProductUnit;
_User = User;
_Logger = Logger;
_BllWMQuoteInfoLog = BllWMQuoteInfoLog;
_BllWMPurchase = BllWMPurchase;
}
[HttpGet]
public async Task>> GetList(
int? Id = null, DateTime? StartTime = null, DateTime? EndTime = null,
string QuoteCode = null,
int PageIndex = 1, int PageSize = 20)
{
Expression> whereExpression =
(pg) => pg.SysOrgId == _User.SysOrgId;
if (Id != null) { whereExpression = whereExpression.And((pg) => pg.Id == Id); }
if (!string.IsNullOrEmpty(QuoteCode))
{
QuoteCode = QuoteCode.Trim();
whereExpression = whereExpression.And((pg) => pg.QuoteCode == QuoteCode);
}
if (StartTime.HasValue)
{
whereExpression = whereExpression.And((pg) => pg.CreateTime >= StartTime.Value);
}
if (EndTime.HasValue)
{
EndTime = EndTime.Value.AddSeconds(1);
whereExpression = whereExpression.And((pg) => pg.CreateTime < EndTime.Value);
}
var pglst = await _BllWMQuoteInfo.QueryTabsPage(
(pg, s, ue, uc) => new object[] {
JoinType.Left, pg.SupplierId==s.Id,
JoinType.Left,pg.EmployeeId==ue.uID,
JoinType.Left,pg.CheckAdminId==uc.uID
},
(pg, s, ue, uc) => new WMQuoteInfo
{
ActualAmount = pg.ActualAmount,
AddRemark = pg.AddRemark,
CheckAdminId = pg.CheckAdminId,
Bank = pg.Bank,
BankAccount = pg.BankAccount,
CheckKey = pg.CheckKey,
CheckRank = pg.CheckRank,
CheckRemark = pg.CheckRemark,
CreateTime = pg.CreateTime,
EmployeeId = pg.EmployeeId,
ExpectedArrivalTime = pg.ExpectedArrivalTime,
FileUrl = pg.FileUrl,
Payee = pg.Payee,
Id = pg.Id,
PayPic = pg.PayPic,
PayType = pg.PayType,
QuoteCode = pg.QuoteCode,
Remark = pg.Remark,
SettlementAmount = pg.SettlementAmount,
Status = pg.Status,
SupplierId = pg.SupplierId,
UpdateTime = pg.UpdateTime,
EmployeeName = ue.uRealName,
SupplierName = s.Name,
SysOrgId = pg.SysOrgId
},
whereExpression, PageIndex, PageSize, "pg.Id desc");
var dicstatus = typeof(EnumWMPurchaseDetailStatus)._GetValueDescriptionDicFromEnumType();
foreach (var i in pglst.data)
{
string name;
i.StatusName = dicstatus.TryGetValue((EnumWMPurchaseDetailStatus)i.Status, out name) ? name : string.Empty;
}
//测试接口
//var dsdfss = await _BllWMQuoteInfo.QueryById(2121);
//var sdd = await _BllWMPurchaseQuoteDetail.Query(x => x.QuoteId == dsdfss.Id);
//foreach (var item in sdd)
//{
// item.inputNum = 2;
//}
//var s = await _BllWMQuoteInfo.BeginPurchaseinInNC(dsdfss, sdd);
//var s = await _BllWMPurchaseQuoteDetail.BeginPurchaseinInNC(dsdfss, sdd);
return new MessageModel>()
{
msg = "获取成功",
success = true,
response = pglst
};
}
[HttpGet]
public async Task> GetParams()
{
var dicStatus = typeof(EnumWMPurchaseDetailStatus)._GetValueDescriptionDicFromEnumType().Select(t => new { Key = t.Key.GetHashCode(), t.Value });
var dicSupplierId = await _BllWMSupplier.Query();
var dicEmployeeId = await _BllSysUserInfo.Query(t => t.tdIsDelete == false);
var dicPurchaseUnit = await _BllWMProductUnit.Query();
var dicSysOrgId = await _BllSysOrg.Query();
var dicPayType = typeof(EnumPayType)._GetValueDescriptionDicFromEnumType().Select(t => new { Key = t.Key.GetHashCode(), t.Value });
return new MessageModel