Files
WMS-Api/src/WMS.Web.Domain/Services/BoxMarkService.cs
tongfei a802b6e29c 优化
2024-03-16 16:11:21 +08:00

125 lines
4.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AutoMapper;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WMS.Web.Core.Dto;
using WMS.Web.Core.Dto.Login;
using WMS.Web.Core.Internal.Results;
using WMS.Web.Domain.Entitys;
using WMS.Web.Domain.Infrastructure;
using WMS.Web.Domain.IService;
using WMS.Web.Domain.IService.Public;
using WMS.Web.Domain.Values;
namespace WMS.Web.Domain.Services
{
/// <summary>
/// 箱唛-服务
/// </summary>
public class BoxMarkService : IBoxMarkService
{
private readonly IMapper _mapper;
public readonly IBasicsRepositories _transactionRepositories;
private readonly IBoxMarkRepositories _boxMarkRepositories;
private readonly ILogger<BoxMarkService> _logger;
public BoxMarkService(IMapper mapper, ILogger<BoxMarkService> logger,
IBasicsRepositories transactionRepositories,
IBoxMarkRepositories boxMarkRepositories)
{
_mapper = mapper;
_logger = logger;
_transactionRepositories = transactionRepositories;
_boxMarkRepositories = boxMarkRepositories;
}
/// <summary>
/// 生成
/// </summary>
/// <param name="dto"></param>
/// <param name="loginInfo"></param>
/// <returns></returns>
public async Task<ResultList<BoxMarkQueryResponse>> Generate(GenerateBoxMarkDto dto, LoginInDto loginInfo)
{
_logger.LogInformation($"箱唛生成:{JsonConvert.SerializeObject(dto)} 操作人:{loginInfo.UserInfo.StaffId + loginInfo.UserInfo.Nickname}");
//1.获取最新的箱唛信息
var billNo_new = await _boxMarkRepositories.GetLastBillNo();
//2.dto映射实体
var entity = new BoxMark();
entity= _mapper.Map(dto, entity);
entity.Create(loginInfo.UserInfo.StaffId);
int new_firstBillNo = billNo_new == null ? 0 : billNo_new.FirstBillNo;
int new_lastBillNo = billNo_new == null ? 0 : billNo_new.LastBillNo;
entity.GenerateBillNo(new_firstBillNo, new_lastBillNo);
//添加
var model = await _boxMarkRepositories.Add(entity);
if (model==null)
return ResultList<BoxMarkQueryResponse>.ReFailure(ResultCodes.DateWriteError);
//返回列表-对应刚刚生成的数据和编号集合
var list= await _boxMarkRepositories.GetListInfoBy(model.Id, loginInfo.UserInfo.CompanyId);
if (list != null && list.Count != 0)
{
//处理-总数量
list.ForEach(x =>
{
x.BoxSortCount = this.GetSortCount(x.ProductQty, x.CratingQty);
});
}
return ResultList<BoxMarkQueryResponse>.ReSuccess(list);
}
/// <summary>
/// 列表分页
/// </summary>
/// <param name="dto"></param>
/// <param name="companyId"></param>
/// <returns></returns>
public async Task<(List<BoxMarkQueryResponse> list, int total)> GetPagedList(BoxMarkQueryRequest dto, int companyId)
{
var (list, count) = await _boxMarkRepositories.GetPagedList(dto, companyId);
if (list != null && list.Count != 0)
{
list.ForEach(x =>
{
x.BoxSortCount = this.GetSortCount(x.ProductQty, x.CratingQty);
});
}
return (list, count);
}
/// <summary>
/// 装箱总数
/// </summary>
/// <param name="productQty"></param>
/// <param name="cratingQty"></param>
/// <returns></returns>
private int GetSortCount(decimal productQty, decimal cratingQty)
{
//计算要装的箱数量
var boxCount_tag = productQty / cratingQty;
var boxCount = Convert.ToInt32(boxCount_tag);
//判断是否存在小数点true表明有尾箱数,false没有尾箱数
var hasPart = Math.Floor(boxCount_tag) != boxCount_tag;
//有小数点向上取整
if (hasPart)
boxCount = Convert.ToInt32(Math.Ceiling(boxCount_tag));
return boxCount;
}
}
}