添加项目文件。
This commit is contained in:
30
src/BarCode.Web.Repositories/BarCode.Web.Repositories.csproj
Normal file
30
src/BarCode.Web.Repositories/BarCode.Web.Repositories.csproj
Normal file
@@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<ServerGarbageCollection>true</ServerGarbageCollection>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="MySqlDataAccess.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Impatient.EntityFrameworkCore.SqlServer" Version="2.1.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BarCode.Web.Core\BarCode.Web.Core.csproj" />
|
||||
<ProjectReference Include="..\BarCode.Web.Domain\BarCode.Web.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
197
src/BarCode.Web.Repositories/BasicsRepositories.cs
Normal file
197
src/BarCode.Web.Repositories/BasicsRepositories.cs
Normal file
@@ -0,0 +1,197 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BarCode.Web.Core.Dto.SingleData;
|
||||
using BarCode.Web.Core.Internal.Results;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Domain.Values;
|
||||
using BarCode.Web.Domain.Values.Single;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
using System.ComponentModel.Design;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础数据
|
||||
/// </summary>
|
||||
public class BasicsRepositories : IBasicsRepositories
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private RepositoryDbContext _context;
|
||||
private readonly ILoginRepositories _loginService;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
|
||||
public BasicsRepositories(RepositoryDbContext context, IMapper mapper, IServiceProvider serviceProvider,
|
||||
ILoginRepositories loginService, ISingleDataService singleDataService,
|
||||
IMemoryCache memoryCache)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_serviceProvider = serviceProvider;
|
||||
_loginService = loginService;
|
||||
_singleDataService = singleDataService;
|
||||
_memoryCache = memoryCache;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取所有人员
|
||||
/// </summary>
|
||||
/// <param name="CompanyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<SysStaffResponse>> GetStaffListAsync(int CompanyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<SysStaffResponse>, SingleDataRequest>
|
||||
(new SingleDataRequest(CompanyId),
|
||||
SysConfigAction.GetStaffByCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<UcStockResponse>> GetSubUcStockAsync(int stockId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<UcStockResponse>, SubStockRequest>
|
||||
(new SubStockRequest(stockId),
|
||||
SysConfigAction.GetChildWarehouseByPid);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
|
||||
public async Task<List<UcSubStockResponse>> GetSubUcStockAsync(string systemCode, string name, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<UcSubStockResponse>, SystemCodeRequest>
|
||||
(new SystemCodeRequest(systemCode, name, companyId),
|
||||
SysConfigAction.GetWmsSubWarehouseBySystemCodeAndNameAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取仓位详情:根据仓位ID和公司ID
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="companyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<UcSubStockResponse> GetSubUcStockAsync(int id, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<Result<UcSubStockResponse>, IdRequest>
|
||||
(new IdRequest(id, companyId),
|
||||
SysConfigAction.GetWmsSubWarehouseByIdAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取仓位集合:根据仓位ID集合和公司ID
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="companyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<UcSubStockResponse>> GetSubUcStockAsync(List<int> ids, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<UcSubStockResponse>, IdsRequest>
|
||||
(new IdsRequest(ids, companyId),
|
||||
SysConfigAction.GetWmsSubWarehouseByIdsAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取仓位详情:根据仓位编码和公司ID
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="companyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<UcSubStockResponse> GetSubUcStockAsync(string code, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<Result<UcSubStockResponse>, CodeRequest>
|
||||
(new CodeRequest(code, companyId),
|
||||
SysConfigAction.GetWmsSubWarehouseByCodeAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取仓位集合:根据仓位编码集合和公司ID
|
||||
/// </summary>
|
||||
/// <param name="codes"></param>
|
||||
/// <param name="companyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<UcSubStockResponse>> GetSubUcStockAsync(List<string> codes, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<UcSubStockResponse>, CodesRequest>
|
||||
(new CodesRequest(codes, companyId),
|
||||
SysConfigAction.GetWmsSubWarehouseByCodesAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
public async Task<List<UcStockResponse>> GetUcStockAsync(string systemCode, string name, int companyId)
|
||||
{
|
||||
var result = await _singleDataService.GetSysConfigData<ResultList<UcStockResponse>, SystemCodeRequest>
|
||||
(new SystemCodeRequest(systemCode, name, companyId),
|
||||
SysConfigAction.GetWmsWarehouseBySystemCodeAndNameAndCompany);
|
||||
if (!result.Success)
|
||||
return null;
|
||||
return result.Data.ToList();
|
||||
}
|
||||
|
||||
public IDbContextTransaction GetTransaction()
|
||||
{
|
||||
return _context.Database.BeginTransaction();
|
||||
}
|
||||
|
||||
public bool CommitTransaction(bool isRollback, IDbContextTransaction transaction)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (transaction == null)
|
||||
return true;
|
||||
|
||||
if (isRollback)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据用户名精确匹配用户
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public Task<List<int>> GetUserIdsAsync(string name, int companyId)
|
||||
{
|
||||
var cache_key = SingleAction.Users + "_" + companyId + "_IdGetName";
|
||||
var dic = _memoryCache.Get<Dictionary<int, string>>(cache_key);
|
||||
if (dic == null)
|
||||
{
|
||||
var str = _singleDataService.GetSingleData(SingleAction.Users, companyId, 0);
|
||||
dic = _memoryCache.Get<Dictionary<int, string>>(cache_key);
|
||||
if (dic == null)
|
||||
return Task.FromResult(new List<int>());
|
||||
}
|
||||
|
||||
var v = from d in dic where d.Value.Equals(name) select d;
|
||||
return Task.FromResult(v.Select(s => s.Key).ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
312
src/BarCode.Web.Repositories/BoxMarkRepositories.cs
Normal file
312
src/BarCode.Web.Repositories/BoxMarkRepositories.cs
Normal file
@@ -0,0 +1,312 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BarCode.Web.Core.Dto;
|
||||
using BarCode.Web.Core.Dto.Erp;
|
||||
using BarCode.Web.Domain.Entitys;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Domain.Values.Single;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
using BarCode.Web.Core.Dto.Login;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 箱唛-仓储
|
||||
/// </summary>
|
||||
public class BoxMarkRepositories : IBoxMarkRepositories
|
||||
{
|
||||
private readonly ILoginRepositories _loginRepositories;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
private readonly IErpService _erpService;
|
||||
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
|
||||
|
||||
public BoxMarkRepositories(RepositoryDbContext context,
|
||||
IErpService erpService,
|
||||
ILoginRepositories loginRepositories,
|
||||
ISingleDataService singleDataService,
|
||||
IBasicsRepositories basicsRepositories,
|
||||
IErpBasicDataExtendService erpBasicDataExtendService)
|
||||
{
|
||||
_context = context;
|
||||
_erpService = erpService;
|
||||
_basicsRepositories = basicsRepositories;
|
||||
_loginRepositories = loginRepositories;
|
||||
_singleDataService = singleDataService;
|
||||
_erpBasicDataExtendService = erpBasicDataExtendService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表-分页
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<(List<BoxMarkQueryResponse> list, int total)> GetPagedList(BoxMarkQueryRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
//1.获取物料集合和组织集合和供应商的集合
|
||||
var materials = new List<ErpMaterialDto>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
List<string> materialNumbs = new List<string>();
|
||||
|
||||
//物料集合;模糊查询后的物料集合
|
||||
if (!string.IsNullOrEmpty(dto.Material))
|
||||
materialNumbs = materials.Where(w => w.MaterialNumber.Contains(dto.Material) || w.MaterialName.Contains(dto.Material) || w.Specifications.Contains(dto.Material)).Select(x => x.MaterialNumber).ToList();
|
||||
|
||||
List<int> cr_ids = new List<int>();
|
||||
if (!string.IsNullOrEmpty(dto.Creator))
|
||||
{
|
||||
cr_ids = await _basicsRepositories.GetUserIdsAsync(dto.Creator, loginInfo.UserInfo.CompanyId);
|
||||
}
|
||||
var query = _context.BoxMarkBillNo
|
||||
.GroupJoin(_context.BoxMark, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders })
|
||||
.SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order })
|
||||
.OrderByDescending(x => x.order.Id).ThenByDescending(x => x.detail.FirstBillNo).ThenByDescending(x => x.detail.LastBillNo)
|
||||
.Where(adv => 1 == 1);
|
||||
|
||||
if (loginInfo.UserInfo.IsAdmin != true && !string.IsNullOrEmpty(dto.OrgCode))
|
||||
{
|
||||
var rec_type = dto.OrgCode.Substring(0, 1);
|
||||
var rec_code = dto.OrgCode.Substring(2, dto.OrgCode.Length - 2);
|
||||
|
||||
if (rec_type.Equals("s"))//供应商
|
||||
query = query.Where(w => rec_code == w.order.SupplierCode);
|
||||
else//查其他单据(组织)
|
||||
query = query.Where(w => rec_code == w.order.OrgCode);
|
||||
}
|
||||
////编号查询
|
||||
//if (!string.IsNullOrEmpty(dto.BeginBillNo) &&
|
||||
// !string.IsNullOrEmpty(dto.EndBillNo))
|
||||
//{
|
||||
// if (dto.BeginBillNo.ToString().Length >= 13 && dto.EndBillNo.ToString().Length >= 13)
|
||||
// {
|
||||
// var begYMD = Convert.ToInt32(dto.BeginBillNo.Substring(2, 6));
|
||||
// var endYMD = Convert.ToInt32(dto.EndBillNo.Substring(2, 6));
|
||||
|
||||
// var begNo = Convert.ToInt32(dto.BeginBillNo.Substring(8));
|
||||
// var endNo = Convert.ToInt32(dto.EndBillNo.Substring(8));
|
||||
// query = query.Where(w => w.detail.FirstBillNo >= begYMD && w.detail.FirstBillNo <= endYMD && w.detail.LastBillNo >= begNo && w.detail.LastBillNo <= endNo);
|
||||
// }
|
||||
// else
|
||||
// query = query.Where(w => w.detail.BillNo == dto.BeginBillNo || w.detail.BillNo == dto.EndBillNo);
|
||||
//}
|
||||
//else if (!string.IsNullOrEmpty(dto.BeginBillNo))
|
||||
// query = query.Where(w => w.detail.BillNo == dto.BeginBillNo);
|
||||
//else if (!string.IsNullOrEmpty(dto.EndBillNo))
|
||||
// query = query.Where(w => w.detail.BillNo == dto.EndBillNo);
|
||||
if (!string.IsNullOrEmpty(dto.BeginBillNo) && dto.BeginBillNo.ToString().Length >= 13)
|
||||
{
|
||||
var begYMD = Convert.ToInt32(dto.BeginBillNo.Substring(2, 6));
|
||||
|
||||
var begNo = Convert.ToInt32(dto.BeginBillNo.Substring(8));
|
||||
|
||||
query = query.Where(w => w.detail.FirstBillNo >= begYMD
|
||||
&& w.detail.LastBillNo >= begNo);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dto.EndBillNo) && dto.EndBillNo.ToString().Length >= 13)
|
||||
{
|
||||
var endYMD = Convert.ToInt32(dto.EndBillNo.Substring(2, 6));
|
||||
var endNo = Convert.ToInt32(dto.EndBillNo.Substring(8));
|
||||
|
||||
query = query.Where(w => w.detail.FirstBillNo <= endYMD
|
||||
&& w.detail.LastBillNo <= endNo);
|
||||
}
|
||||
|
||||
|
||||
//订单号查询
|
||||
if (!string.IsNullOrEmpty(dto.OrderBillNos))
|
||||
{
|
||||
var orderBNS = dto.OrderBillNos.Replace(",", ",");
|
||||
var orderBillNoList = orderBNS.Split(",").Where(x => !string.IsNullOrEmpty(x)).ToList();
|
||||
if (orderBillNoList != null && orderBillNoList.Count != 0)
|
||||
{
|
||||
query = query.Where(w => orderBillNoList.Contains(w.order.OrderBillNo));
|
||||
}
|
||||
}
|
||||
|
||||
//物料ID在模糊后的物料
|
||||
if (!string.IsNullOrEmpty(dto.Material))
|
||||
{
|
||||
query = query.Where(w => materialNumbs.Contains(w.order.MaterialNumber));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(dto.Creator))
|
||||
query = query.Where(w => cr_ids.Contains(w.order.CreatorId));
|
||||
if (dto.CreateBeginDate != null)
|
||||
query = query.Where(w => w.order.CreateTime.Date >= dto.CreateBeginDate.Value);
|
||||
if (dto.CreateEndDate != null)
|
||||
query = query.Where(w => w.order.CreateTime.Date <= dto.CreateEndDate.Value);
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query.Select(s => new BoxMarkQueryResponse()
|
||||
{
|
||||
Id = s.order.Id,
|
||||
DetailId=s.detail.Id,
|
||||
BillNo = s.detail.BillNo,
|
||||
OrderBillNo = s.order.OrderBillNo,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.order.MaterialNumber),
|
||||
MaterialNumber = s.order.MaterialNumber,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.order.MaterialNumber),
|
||||
BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.order.MaterialNumber),
|
||||
|
||||
CratingQty = s.order.CratingQty,
|
||||
CratingNetWeightQty = s.order.CratingNetWeightQty,
|
||||
CratingGrossWeightQty = s.order.CratingGrossWeightQty,
|
||||
|
||||
TailboxQty = s.order.TailboxQty,
|
||||
TailboxNetWeightQty = s.order.TailboxNetWeightQty,
|
||||
TailboxGrossWeightQty = s.order.TailboxGrossWeightQty,
|
||||
IsTail=s.detail.IsTail,
|
||||
Sort = s.detail.Sort,
|
||||
Creator = _singleDataService.GetSingleData(SingleAction.Users, loginInfo.UserInfo.CompanyId, s.order.CreatorId),
|
||||
CreateTime = s.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
Remark = s.order.Remark,
|
||||
ProductQty=s.order.ProductQty,
|
||||
BeginNumber=s.detail.BeginNumber,
|
||||
EndNumber=s.detail.EndNumber
|
||||
|
||||
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
|
||||
return (list, total);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BoxMark> Add(BoxMark entity, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
await _context.BoxMark.AddAsync(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return entity;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 详情-根据最新的ID
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BoxMark> GetBy()
|
||||
{
|
||||
var entity = await _context.BoxMark.OrderByDescending(x => x.Id).FirstOrDefaultAsync();
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表-详情信息列表
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="companyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<BoxMarkQueryResponse>> GetListInfoBy(int id, int companyId)
|
||||
{
|
||||
//1.获取物料集合和组织集合和供应商的集合
|
||||
var materials = new List<ErpMaterialDto>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
var query = _context.BoxMarkBillNo
|
||||
.GroupJoin(_context.BoxMark, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders })
|
||||
.SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order })
|
||||
.OrderByDescending(x => x.order.Id).ThenByDescending(x => x.detail.FirstBillNo).ThenByDescending(x => x.detail.LastBillNo)
|
||||
.Where(adv => adv.order.Id == id);
|
||||
var list = await query.Select(s => new BoxMarkQueryResponse()
|
||||
{
|
||||
Id = s.order.Id,
|
||||
DetailId = s.detail.Id,
|
||||
BillNo = s.detail.BillNo,
|
||||
OrderBillNo = s.order.OrderBillNo,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.order.MaterialNumber),
|
||||
MaterialNumber = s.order.MaterialNumber,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.order.MaterialNumber),
|
||||
BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.order.MaterialNumber),
|
||||
|
||||
CratingQty = s.order.CratingQty,
|
||||
CratingNetWeightQty = s.order.CratingNetWeightQty,
|
||||
CratingGrossWeightQty = s.order.CratingGrossWeightQty,
|
||||
|
||||
TailboxQty = s.order.TailboxQty,
|
||||
TailboxNetWeightQty = s.order.TailboxNetWeightQty,
|
||||
TailboxGrossWeightQty = s.order.TailboxGrossWeightQty,
|
||||
IsTail = s.detail.IsTail,
|
||||
Sort=s.detail.Sort,
|
||||
Creator = _singleDataService.GetSingleData(SingleAction.Users, companyId, s.order.CreatorId),
|
||||
CreateTime = s.order.CreateTime.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
Remark = s.order.Remark,
|
||||
ProductQty = s.order.ProductQty,
|
||||
BeginNumber = s.detail.BeginNumber,
|
||||
EndNumber = s.detail.EndNumber
|
||||
}).ToListAsync();
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 详情-根据最新的ID
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<BoxMarkBillNo> GetLastBillNo()
|
||||
{
|
||||
var entity = await _context.BoxMarkBillNo.OrderByDescending(x => x.Id).FirstOrDefaultAsync();
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> DeleteRange(List<int> ids, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var list = await _context.BoxMark.Include(x=>x.BillNos).Where(f => ids.Contains(f.Id)).ToListAsync();
|
||||
_context.BoxMark.RemoveRange(list);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
381
src/BarCode.Web.Repositories/BoxRepositories.cs
Normal file
381
src/BarCode.Web.Repositories/BoxRepositories.cs
Normal file
@@ -0,0 +1,381 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BarCode.Web.Core.Dto;
|
||||
using BarCode.Web.Core.Help;
|
||||
using BarCode.Web.Domain.Entitys;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Domain.Mappers;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
using BarCode.Web.Core.Dto.Box;
|
||||
using BarCode.Web.Core.Dto.Erp;
|
||||
using BarCode.Web.Core.Dto.Erp.Supplier;
|
||||
using BarCode.Web.Core.Dto.Erp.Org;
|
||||
using BarCode.Web.Core.Dto.SerialNumbers;
|
||||
using BarCode.Web.Domain.Values.Single;
|
||||
using BarCode.Web.Core;
|
||||
using BarCode.Web.Domain.Values;
|
||||
using NPOI.OpenXmlFormats.Wordprocessing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.ComponentModel.Design;
|
||||
using BarCode.Web.Core.Dto.Login;
|
||||
using BarCode.Web.Core.Dto.SingleData;
|
||||
using BarCode.Web.Core.Internal.Results;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 老ops箱信息
|
||||
/// </summary>
|
||||
public class BoxRepositories : IBoxRepositories
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
private readonly ILoginRepositories _loginRepositories;
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
|
||||
private readonly IErpService _erpService;
|
||||
public BoxRepositories(RepositoryDbContext context, IMapper mapper, IServiceProvider serviceProvider,
|
||||
ISingleDataService singleDataService, ILoginRepositories loginRepositories,
|
||||
IBasicsRepositories basicsRepositories, IErpBasicDataExtendService erpBasicDataExtendService,
|
||||
IErpService erpServic)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_serviceProvider = serviceProvider;
|
||||
_singleDataService = singleDataService;
|
||||
_loginRepositories = loginRepositories;
|
||||
_basicsRepositories = basicsRepositories;
|
||||
_erpBasicDataExtendService = erpBasicDataExtendService;
|
||||
_erpService = erpServic;
|
||||
}
|
||||
public async Task<Box?> Get(int id)
|
||||
{
|
||||
return await _context.Box.AsNoTracking()
|
||||
.Include(x => x.Details)
|
||||
.FirstOrDefaultAsync(f => f.Id.Equals(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量修改
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> EditEntityList(List<Box> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
List<int> list = entitys.Select(s => s.Id).ToList();
|
||||
|
||||
var res = await _context.Box
|
||||
.Include(s => s.Details)
|
||||
.Where(f => list.Contains(f.Id)).ToListAsync();
|
||||
|
||||
_mapper.ToMapList(entitys, res);
|
||||
//_mapper.ToMapList(entitys.SelectMany(s => s.Details).ToList(), res.SelectMany(s => s.Details).ToList());
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public async Task<Box?> GetByNo(string billNo)
|
||||
{
|
||||
return await _context.Box.AsNoTracking()
|
||||
.Include(x => x.Details)
|
||||
.FirstOrDefaultAsync(f => f.BoxBillNo.Equals(billNo));
|
||||
}
|
||||
public async Task<List<Box>> GetEntityListByNos(List<string> billNos)
|
||||
{
|
||||
return await _context.Box.AsNoTracking()
|
||||
.Include(x => x.Details)
|
||||
.Where(f => billNos.Contains(f.BoxBillNo)).ToListAsync();
|
||||
}
|
||||
//根据箱号搜索 用来比对确定是否箱号信息是否存在
|
||||
public async Task<List<string>> GetByNos(List<string> billNos)
|
||||
{
|
||||
return await _context.Box.AsNoTracking()
|
||||
.Where(w => billNos.Contains(w.BoxBillNo)).Select(s => s.BoxBillNo).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> AddRange(List<Box> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
if (entitys != null && entitys.Count != 0)
|
||||
{
|
||||
await _context.Box.AddRangeAsync(entitys);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
foreach (var e in entitys)
|
||||
{
|
||||
e.GenerateNo();
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取箱集合
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<Box>> GetEntityList(List<int> ids)
|
||||
{
|
||||
return await _context.Box.AsNoTracking()
|
||||
.Include(s => s.Details)
|
||||
.Where(f => ids.Contains(f.Id))
|
||||
.ToListAsync();
|
||||
}
|
||||
/// <summary>
|
||||
/// 列表
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="companyId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<(List<BoxInfoResponse> list, int total)> GetListAsync(BoxQueryRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
int companyId = loginInfo.UserInfo.CompanyId;
|
||||
List<string> mNumber = new List<string>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
//物料集合;模糊查询后的物料集合
|
||||
if (!string.IsNullOrEmpty(dto.MaterialNumber))
|
||||
{
|
||||
if (materials != null)
|
||||
mNumber = materials.Where(w => w.MaterialNumber.Contains(dto.MaterialNumber)
|
||||
|| w.MaterialName.Contains(dto.MaterialNumber)
|
||||
|| w.Specifications.Contains(dto.MaterialNumber)
|
||||
).Select(s => s.MaterialNumber).ToList();
|
||||
}
|
||||
|
||||
////供应商
|
||||
//var supplier_result = await _erpService.BillQueryForSupplier();
|
||||
//List<ErpSupplierDto> suppliers = new List<ErpSupplierDto>();
|
||||
//if (supplier_result.IsSuccess)
|
||||
// suppliers = supplier_result.Data.ToList();
|
||||
////取组织
|
||||
//var org_result = await _erpService.BillQueryForOrg();
|
||||
//List<ErpOrgDto> orgs = new List<ErpOrgDto>();
|
||||
//if (org_result.IsSuccess)
|
||||
// orgs = org_result.Data.ToList();
|
||||
var result = await _singleDataService.GetSingleData<ResultList<SysOrgResponse>, SingleDataRequest, SysConfigAction>(
|
||||
new SingleDataRequest(loginInfo.UserInfo.CompanyId), SysConfigAction.GetOrgByCompany, SingleControllerType.SysConfig);
|
||||
List<SysOrgResponse> orgs = new List<SysOrgResponse>();
|
||||
if (result.IsSuccess)
|
||||
orgs = result.Data.ToList();
|
||||
|
||||
List<int> cr_ids = new List<int>();
|
||||
if (!string.IsNullOrEmpty(dto.CreateUser))
|
||||
{
|
||||
cr_ids = await _basicsRepositories.GetUserIdsAsync(dto.CreateUser, loginInfo.UserInfo.CompanyId);
|
||||
}
|
||||
List<int> s_ids = new List<int>();
|
||||
if (dto.SerialNumbers != null && dto.SerialNumbers.Count() > 0)
|
||||
{
|
||||
var details = await GetDetailIdBySerialNumbers(dto.SerialNumbers);
|
||||
s_ids = details.Select(s => s.Id).ToList();
|
||||
}
|
||||
var query = _context.Box
|
||||
.GroupJoin(_context.BoxDetails, box => box.Id, detail => detail.Fid, (box, detail) => new { box, detail })
|
||||
.SelectMany(x => x.detail.DefaultIfEmpty(), (p, detail) => new { p.box, detail })
|
||||
.OrderByDescending(o => o.box.Id)
|
||||
.Where(f => 1 == 1);
|
||||
|
||||
if (loginInfo.UserInfo.IsAdmin != true && !string.IsNullOrEmpty(dto.OrgCode))
|
||||
{
|
||||
var rec_type = dto.OrgCode.Substring(0, 1);
|
||||
var rec_code = dto.OrgCode.Substring(2, dto.OrgCode.Length - 2);
|
||||
|
||||
if (rec_type.Equals("s"))//供应商
|
||||
query = query.Where(w => rec_code == w.box.SupplierCode);
|
||||
else//查其他单据(组织)
|
||||
query = query.Where(w => rec_code == w.box.OrgCode);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(dto.SupplierOrOrg))
|
||||
{
|
||||
var rec_type = dto.SupplierOrOrg.Substring(0, 1);
|
||||
var rec_code = dto.SupplierOrOrg.Substring(2, dto.SupplierOrOrg.Length - 2);
|
||||
|
||||
if (rec_type.Equals("s"))//供应商
|
||||
query = query.Where(w => rec_code == w.box.SupplierCode);
|
||||
else//查其他单据(组织)
|
||||
query = query.Where(w => rec_code == w.box.OrgCode);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dto.MaterialNumber))
|
||||
query = query.Where(w => mNumber.Contains(w.detail.MaterialNumber));
|
||||
if (!string.IsNullOrEmpty(dto.BoxBeginNo))
|
||||
{
|
||||
//V01.05.00: 只输入一个框则只查输入值,不做区间查询
|
||||
var id = Convert.ToInt32(dto.BoxBeginNo.ToUpper().Replace("CTN", ""));
|
||||
if (!string.IsNullOrEmpty(dto.BoxEndNo))
|
||||
query = query.Where(w => w.box.Id >= id);
|
||||
else
|
||||
query = query.Where(w => w.box.Id == id);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dto.BoxEndNo))
|
||||
{
|
||||
//V01.05.00: 只输入一个框则只查输入值,不做区间查询
|
||||
var id = Convert.ToInt32(dto.BoxEndNo.ToUpper().Replace("CTN", ""));
|
||||
if (!string.IsNullOrEmpty(dto.BoxBeginNo))
|
||||
query = query.Where(w => w.box.Id <= id);
|
||||
else
|
||||
query = query.Where(w => w.box.Id == id);
|
||||
}
|
||||
if (dto.Status != null)
|
||||
query = query.Where(w => w.box.Status == (BoxStatus)dto.Status);
|
||||
if (dto.CreateBeginDate != null)
|
||||
query = query.Where(w => w.box.CreateTime >= dto.CreateBeginDate);
|
||||
if (dto.CreateEndDate != null)
|
||||
{
|
||||
DateTime dt_end = ((DateTime)dto.CreateEndDate).AddDays(1);
|
||||
query = query.Where(w => w.box.CreateTime <= dt_end);
|
||||
}
|
||||
if (dto.CartonBeginDate != null)
|
||||
query = query.Where(w => w.box.CartonEndTime >= dto.CartonBeginDate);
|
||||
if (dto.CartonEndDate != null)
|
||||
{
|
||||
DateTime dt_end = ((DateTime)dto.CartonEndDate).AddDays(1);
|
||||
query = query.Where(w => w.box.CartonEndTime <= dt_end);
|
||||
}
|
||||
|
||||
if (dto.SerialNumbers != null && dto.SerialNumbers.Count() > 0)
|
||||
query = query.Where(w => s_ids.Contains(w.detail.Id));
|
||||
if (dto.BoxPrintStatus != null)
|
||||
query = query.Where(w => dto.BoxPrintStatus == true ? w.box.PrintNumber > 0 : w.box.PrintNumber <= 0);
|
||||
if (!string.IsNullOrEmpty(dto.CreateUser))
|
||||
query = query.Where(w => cr_ids.Contains(w.box.CreatorId));
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query.Select(s => new BoxInfoResponse()
|
||||
{
|
||||
Id = s.box.Id,
|
||||
DetailId = s.detail == null ? 0 : s.detail.Id,
|
||||
BoxBillNo = s.box.BoxBillNo,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.detail == null ? "" : s.detail.MaterialNumber),
|
||||
MaterialNumber = s.detail == null ? "" : s.detail.MaterialNumber,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.detail == null ? "" : s.detail.MaterialNumber),
|
||||
BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.detail == null ? "" : s.detail.MaterialNumber),
|
||||
SerialNumbers = s.detail == null ? "" : string.Join(",", s.detail.SerialNumbers),
|
||||
Qty = s.detail == null ? 0 : s.detail.Qty,
|
||||
Status = s.box.Status.GetRemark(),
|
||||
CartonBeginTime = s.box.CartonBeginTime.DateToStringSeconds(),
|
||||
CartonEndTime = s.box.CartonEndTime.DateToStringSeconds(),
|
||||
CartonUser = _singleDataService.GetSingleData(SingleAction.Users, companyId, s.box.CartonUserId),
|
||||
Creator = _singleDataService.GetSingleData(SingleAction.Users, companyId, s.box.CreatorId),
|
||||
CreateTime = s.box.CreateTime.DateToStringSeconds(),
|
||||
PrintNumber = s.box.PrintNumber,
|
||||
SupplierOrOrg = string.IsNullOrEmpty(s.box.SupplierCode) ? _erpBasicDataExtendService.GetSingleOrgName(orgs, s.box.OrgCode)
|
||||
: _singleDataService.GetSingleData(SingleAction.Suppliers, companyId, s.box.SupplierCode)//供应商取单点的
|
||||
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
return (list, total);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据序列号获取明细
|
||||
/// </summary>
|
||||
/// <param name="serialNumbers"></param>
|
||||
/// <returns></returns>
|
||||
private Task<List<BoxDetails>> GetDetailIdBySerialNumbers(List<string> serialNumbers)
|
||||
{
|
||||
if (serialNumbers.Count() == 0) Task.FromResult(new List<BoxDetails>());
|
||||
string str = $"select * from t_barcode_box_details where ";
|
||||
for (int i = 0; i < serialNumbers.Count(); i++)
|
||||
{
|
||||
if (i == 0)
|
||||
str += $"SerialNumbers like '%\"{serialNumbers[i]}\"%'";
|
||||
else
|
||||
str += $" or SerialNumbers like '%\"{serialNumbers[i]}\"%'";
|
||||
}
|
||||
var fs = FormattableStringFactory.Create(str);
|
||||
var list = _context.Set<BoxDetails>().FromSqlInterpolated(fs).ToList();
|
||||
return Task.FromResult(list);
|
||||
}
|
||||
/// <summary>
|
||||
/// 编辑
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Box> Edit(Box entity, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
var res = await _context.Box
|
||||
.Include(s => s.Details)
|
||||
.FirstOrDefaultAsync(f => f.Id == entity.Id);
|
||||
if (res == null) return null;
|
||||
|
||||
_mapper.Map(entity, res);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取装箱完成的箱信息
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<(List<Box>, int tota)> GetEntityByWmsList(WmsBoxRequest dto)
|
||||
{
|
||||
var query = _context.Box.Include(x => x.Details)
|
||||
.Where(w => w.Status == BoxStatus.Complete);
|
||||
|
||||
if (!string.IsNullOrEmpty(dto.BoxBillNo))
|
||||
query = query.Where(w => w.BoxBillNo.Equals(dto.BoxBillNo));
|
||||
if (dto.StrartTime != null)
|
||||
query = query.Where(w => w.CartonEndTime >= dto.StrartTime);
|
||||
if (dto.EndTime != null)
|
||||
query = query.Where(w => w.CartonEndTime <= dto.EndTime);
|
||||
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query.Skip((dto.Page - 1) * dto.Limit).Take(dto.Limit).ToListAsync();
|
||||
return (list, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
87
src/BarCode.Web.Repositories/CenerateDataRepositories.cs
Normal file
87
src/BarCode.Web.Repositories/CenerateDataRepositories.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using AutoMapper;
|
||||
using BarCode.Web.Domain.Entitys;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.Values;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CenerateDataRepositories : ICenerateDataRepositories
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly RepositoryDbContext _context;
|
||||
|
||||
public CenerateDataRepositories(RepositoryDbContext context, IMapper mapper, IServiceProvider serviceProvider)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<CenerateData> Add(CenerateData entity, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
await _context.CenerateData.AddAsync(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return entity;
|
||||
}
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<CenerateData> Edit(CenerateData entity, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
var res = await _context.CenerateData
|
||||
.FirstOrDefaultAsync(f => f.Id == entity.Id);
|
||||
if (res == null) return null;
|
||||
|
||||
_mapper.Map(entity, res);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public async Task<CenerateData?> Get(CenerateDataType type)
|
||||
{
|
||||
var entity = await _context.CenerateData
|
||||
.FirstOrDefaultAsync(f => f.Type == type);
|
||||
if (entity == null)
|
||||
{
|
||||
entity = await this.Add(new CenerateData(type));
|
||||
return entity;
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
using Microsoft.Data.SqlClient;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BarCode.Web.Repositories.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// db上下文扩展类
|
||||
/// </summary>
|
||||
public static class DbContextExtensions
|
||||
{
|
||||
public static IEnumerable<T> SqlQuery<T>(this DatabaseFacade facade, string sql, bool isAlias = false, params object[] parameters) where T : class, new()
|
||||
{
|
||||
var dt = SqlQuery(facade, sql, parameters);
|
||||
if (isAlias)
|
||||
return dt.ToEnumerableAlias<T>();
|
||||
return dt.ToEnumerable<T>();
|
||||
}
|
||||
|
||||
public static async Task<IEnumerable<T>> SqlQueryAsync<T>(this DatabaseFacade facade, string sql, bool isAlias = false, params object[] parameters) where T : class, new()
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
var dt = SqlQuery(facade, sql, parameters);
|
||||
if (isAlias)
|
||||
return dt.ToEnumerableAlias<T>();
|
||||
return dt.ToEnumerable<T>();
|
||||
});
|
||||
}
|
||||
|
||||
public static IEnumerable<T> ToEnumerable<T>(this DataTable dt) where T : class, new()
|
||||
{
|
||||
var propertyInfos = typeof(T).GetProperties();
|
||||
var ts = new T[dt.Rows.Count];
|
||||
var i = 0;
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var t = new T();
|
||||
foreach (var p in propertyInfos)
|
||||
if (dt.Columns.IndexOf(p.Name) != -1 && row[p.Name] != DBNull.Value)
|
||||
p.SetValue(t, row[p.Name], null);
|
||||
|
||||
ts[i] = t;
|
||||
i++;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对象属性别名的映射关系
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<T> ToEnumerableAlias<T>(this DataTable dt) where T : class, new()
|
||||
{
|
||||
var propertyInfos = typeof(T).GetProperties();
|
||||
var ts = new T[dt.Rows.Count];
|
||||
var i = 0;
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
var t = new T();
|
||||
foreach (var p in propertyInfos)
|
||||
{
|
||||
var attrs = p.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.Schema.ColumnAttribute), true);
|
||||
if (attrs.Length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var name = ((System.ComponentModel.DataAnnotations.Schema.ColumnAttribute)attrs[0]).Name;
|
||||
if (dt.Columns.IndexOf(name) != -1 && row[name] != DBNull.Value)
|
||||
p.SetValue(t, row[name], null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ts[i] = t;
|
||||
i++;
|
||||
}
|
||||
|
||||
return ts;
|
||||
}
|
||||
|
||||
public static DataTable SqlQuery(this DatabaseFacade facade, string sql, params object[] parameters)
|
||||
{
|
||||
var cmd = CreateCommand(facade, sql, out var conn, parameters);
|
||||
var reader = cmd.ExecuteReader();
|
||||
var dt = new DataTable();
|
||||
dt.Load(reader);
|
||||
reader.Close();
|
||||
conn.Close();
|
||||
return dt;
|
||||
}
|
||||
|
||||
private static DbCommand CreateCommand(DatabaseFacade facade, string sql, out DbConnection dbConn, params object[] parameters)
|
||||
{
|
||||
var conn = facade.GetDbConnection();
|
||||
dbConn = conn;
|
||||
conn.Open();
|
||||
var cmd = conn.CreateCommand();
|
||||
if (facade.IsMySql())
|
||||
{
|
||||
cmd.CommandText = sql;
|
||||
CombineParamsMySql(ref cmd, parameters);
|
||||
}
|
||||
if (facade.IsSqlServer())
|
||||
{
|
||||
cmd.CommandText = sql;
|
||||
CombineParams(ref cmd, parameters);
|
||||
}
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
private static void CombineParams(ref DbCommand command, params object[] parameters)
|
||||
{
|
||||
if (parameters != null)
|
||||
foreach (SqlParameter parameter in parameters)
|
||||
{
|
||||
if (!parameter.ParameterName.Contains("@"))
|
||||
parameter.ParameterName = $"@{parameter.ParameterName}";
|
||||
command.Parameters.Add(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CombineParamsMySql(ref DbCommand command, params object[] parameters)
|
||||
{
|
||||
if (parameters != null)
|
||||
foreach (MySqlConnector.MySqlParameter parameter in parameters)
|
||||
{
|
||||
if (!parameter.ParameterName.Contains("@"))
|
||||
parameter.ParameterName = $"@{parameter.ParameterName}";
|
||||
command.Parameters.Add(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ExecuteSqlCommand(this DatabaseFacade facade, string sql, params object[] parameters)
|
||||
{
|
||||
var cmd = CreateCommand(facade, sql, out var conn, parameters);
|
||||
try
|
||||
{
|
||||
cmd.ExecuteNonQuery();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = ex.Message;
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
conn.Close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static IQueryable<T> SortBy<T>(this IQueryable<T> source, string sortExpression)
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
throw new ArgumentNullException("source");
|
||||
}
|
||||
|
||||
string sortDirection = String.Empty;
|
||||
string propertyName = String.Empty;
|
||||
|
||||
sortExpression = sortExpression.Trim();
|
||||
int spaceIndex = sortExpression.Trim().IndexOf(" ");
|
||||
if (spaceIndex < 0)
|
||||
{
|
||||
propertyName = sortExpression;
|
||||
sortDirection = "ASC";
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyName = sortExpression.Substring(0, spaceIndex);
|
||||
sortDirection = sortExpression.Substring(spaceIndex + 1).Trim();
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(propertyName))
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
ParameterExpression parameter = Expression.Parameter(source.ElementType, String.Empty);
|
||||
MemberExpression property = Expression.Property(parameter, propertyName);
|
||||
LambdaExpression lambda = Expression.Lambda(property, parameter);
|
||||
|
||||
string methodName = (sortDirection == "ASC") ? "OrderBy" : "OrderByDescending";
|
||||
|
||||
Expression methodCallExpression = Expression.Call(typeof(Queryable), methodName,
|
||||
new Type[] { source.ElementType, property.Type },
|
||||
source.Expression, Expression.Quote(lambda));
|
||||
|
||||
return source.Provider.CreateQuery<T>(methodCallExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace BarCode.Web.Repositories.Configuration.EFLog
|
||||
{
|
||||
public class EFCoreLogger : ILogger
|
||||
{
|
||||
private readonly string categoryName;
|
||||
|
||||
public EFCoreLogger(string categoryName) => this.categoryName = categoryName;
|
||||
|
||||
public bool IsEnabled(LogLevel logLevel) => true;
|
||||
|
||||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
||||
{
|
||||
if (categoryName == "Microsoft.EntityFrameworkCore.Database.Command" && logLevel == LogLevel.Information)
|
||||
{
|
||||
var logContent = formatter(state, exception);
|
||||
var str = logContent.ToLower();
|
||||
if ((str.Contains("update") || str.Contains("delete") || str.Contains("insert")) &&
|
||||
(str.Contains("t_sub_ppbom") || str.Contains("t_sub_ppbomentry") || str.Contains("t_sub_ppbomentry_l")
|
||||
|| str.Contains("t_prd_ppbom") || str.Contains("t_prd_ppbomentry") || str.Contains("t_prd_ppbomentry_l")
|
||||
|| str.Contains("t_eng_bom") || str.Contains("t_eng_bomchild")))
|
||||
{
|
||||
if (!Directory.Exists("D:/Logs"))
|
||||
Directory.CreateDirectory("D:/Logs");
|
||||
|
||||
logContent = "\r\n\r\n" + DateTime.Now + "--" + logContent;
|
||||
//没有文件会自动创建,有就追加
|
||||
System.IO.File.AppendAllText("D:/Logs/增删改记录.txt", logContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
public IDisposable BeginScope<TState>(TState state) => null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BarCode.Web.Repositories.Configuration.EFLog
|
||||
{
|
||||
public class EFCoreLoggerProvider : ILoggerProvider
|
||||
{
|
||||
public ILogger CreateLogger(string categoryName) => new EFCoreLogger(categoryName);
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Debug;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using BarCode.Web.Domain.Entitys;
|
||||
using BarCode.Web.Repositories.Configuration.EFLog;
|
||||
|
||||
namespace BarCode.Web.Repositories.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// db上下文
|
||||
/// </summary>
|
||||
public class RepositoryDbContext : DbContext
|
||||
{
|
||||
[Obsolete]
|
||||
public readonly LoggerFactory LoggerFactory = new LoggerFactory(new[] { new DebugLoggerProvider() });
|
||||
public RepositoryDbContext(DbContextOptions<RepositoryDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
LoggerFactory.AddProvider(new EFCoreLoggerProvider());
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
optionsBuilder.UseLoggerFactory(LoggerFactory).EnableSensitiveDataLogging();
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.Entity<FileDownManager>(ent =>
|
||||
{
|
||||
ent.ToTable("t_barcode_file_down_manager");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
|
||||
//箱唛表
|
||||
builder.Entity<BoxMark>(ent =>
|
||||
{
|
||||
ent.ToTable("t_barcode_box_mark");
|
||||
ent.HasKey(x => x.Id);
|
||||
|
||||
ent.HasMany(p => p.BillNos)
|
||||
.WithOne()
|
||||
.HasForeignKey(p => p.Fid)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
//箱唛表-编号表
|
||||
builder.Entity<BoxMarkBillNo>(ent =>
|
||||
{
|
||||
ent.ToTable("t_barcode_box_mark_billno");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
//物料
|
||||
builder.Entity<Materials>(ent =>
|
||||
{
|
||||
ent.ToTable("t_barcode_materials");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
//序列号生成记录
|
||||
builder.Entity<SerialNumberGenerateRecord>(ent =>
|
||||
{
|
||||
ent.ToTable("t_barcode_serialnumbergeneraterecord");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
//序列号
|
||||
builder.Entity<SerialNumbers>(ent =>
|
||||
{
|
||||
ent.ToTable("t_barcode_serialnumbers");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
//防伪码生成记录
|
||||
builder.Entity<SecurityNumberGenerateRecord>(ent =>
|
||||
{
|
||||
ent.ToTable("t_barcode_securitynumbergeneraterecord");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
//防伪码
|
||||
builder.Entity<SecurityNumbers>(ent =>
|
||||
{
|
||||
ent.ToTable("t_barcode_securitynumbers");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
#region 箱信息
|
||||
builder.Entity<Box>(ent =>
|
||||
{
|
||||
ent.ToTable("t_barcode_box");
|
||||
ent.HasKey(x => x.Id);
|
||||
|
||||
ent.HasMany(p => p.Details)
|
||||
.WithOne()
|
||||
.HasForeignKey(p => p.Fid)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
builder.Entity<BoxDetails>(ent =>
|
||||
{
|
||||
ent.ToTable("t_barcode_box_details");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
#endregion
|
||||
|
||||
//生成数据管理
|
||||
builder.Entity<CenerateData>(ent =>
|
||||
{
|
||||
ent.ToTable("t_wms_cenerate_date");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
base.OnModelCreating(builder);
|
||||
}
|
||||
public DbSet<Materials> Materials { get; set; }
|
||||
public DbSet<BoxMarkBillNo> BoxMarkBillNo { get; set; }
|
||||
public DbSet<BoxMark> BoxMark { get; set; }
|
||||
public DbSet<FileDownManager> FileDownManager { get; set; }
|
||||
public DbSet<SerialNumberGenerateRecord> SerialNumberGenerateRecord { get; set; }
|
||||
public DbSet<SerialNumbers> SerialNumbers { get; set; }
|
||||
public DbSet<Box> Box { get; set; }
|
||||
public DbSet<BoxDetails> BoxDetails { get; set; }
|
||||
public DbSet<SecurityNumberGenerateRecord> SecurityNumberGenerateRecord { get; set; }
|
||||
public DbSet<SecurityNumbers> SecurityNumbers { get; set; }
|
||||
public DbSet<CenerateData> CenerateData { get; set; }
|
||||
}
|
||||
}
|
||||
300
src/BarCode.Web.Repositories/DependencyInjection/AppBuilder.cs
Normal file
300
src/BarCode.Web.Repositories/DependencyInjection/AppBuilder.cs
Normal file
@@ -0,0 +1,300 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Quartz;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using BarCode.Web.Core.Help;
|
||||
using BarCode.Web.Domain.IService;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Domain.Mappers;
|
||||
using BarCode.Web.Domain.Options;
|
||||
using BarCode.Web.Domain.QuartzJob;
|
||||
using BarCode.Web.Domain.Services;
|
||||
using BarCode.Web.Domain.Services.Public;
|
||||
using Quartz.AspNetCore;
|
||||
|
||||
namespace BarCode.Web.Repositories.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// App服务
|
||||
/// </summary>
|
||||
public class AppBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务集合
|
||||
/// </summary>
|
||||
public IServiceCollection Services { get; }
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public bool _IsDevelopment { get; }
|
||||
|
||||
/// <summary>
|
||||
/// asf 服务
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
public AppBuilder(IServiceCollection services, IConfiguration configuration, bool IsDevelopment)
|
||||
{
|
||||
Services = services;
|
||||
Configuration = configuration;
|
||||
_IsDevelopment = IsDevelopment;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编译服务
|
||||
/// </summary>
|
||||
public void Build()
|
||||
{
|
||||
this.AddCors();
|
||||
this.InitRedis();
|
||||
this.AddSwagger();
|
||||
this.AddOther();
|
||||
this.AddConfigOptions();
|
||||
this.AddServiceRepositories();
|
||||
this.AddQuartzService();
|
||||
}
|
||||
/// <summary>
|
||||
/// 其它功能注入:AutoMapper等其它
|
||||
/// </summary>
|
||||
private void AddOther()
|
||||
{
|
||||
Services.AddMvc().AddNewtonsoftJson(opt =>
|
||||
{
|
||||
//// 忽略循环引用
|
||||
//opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
|
||||
//// 不使用驼峰
|
||||
//opt.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||
});
|
||||
|
||||
//AutoMapper映射关系
|
||||
Services.AddAutoMapper(typeof(AppMapper).Assembly);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 跨域注入
|
||||
/// </summary>
|
||||
private void AddCors()
|
||||
{
|
||||
// 全局跨域注入
|
||||
Services.AddCors(opt =>
|
||||
{
|
||||
string[] urls = Configuration.GetSection("AllowedCores").Value.Split(',');
|
||||
opt.AddPolicy("AllowAllOrigin", builder =>
|
||||
{
|
||||
|
||||
builder.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.AllowCredentials()
|
||||
.WithOrigins(urls);
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化redis
|
||||
/// </summary>
|
||||
private void InitRedis()
|
||||
{
|
||||
var option = Configuration.GetSection("AppOptions").Get<AppOptions>();
|
||||
var option_soa = Configuration.GetSection("SoaOptions").Get<SoaOptions>();
|
||||
//初始化redis
|
||||
RedisClient.redisClient.InitConnect(option.RedisConnectionString);
|
||||
Services.AddHttpClient("ops_client", c =>
|
||||
{
|
||||
c.BaseAddress = new Uri(option_soa.Url);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注册swagger
|
||||
/// </summary>
|
||||
private void AddSwagger()
|
||||
{
|
||||
if (_IsDevelopment)
|
||||
{
|
||||
// 注册Swagger服务
|
||||
Services.AddSwaggerGen(c =>
|
||||
{
|
||||
// 添加文档信息
|
||||
c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo
|
||||
{
|
||||
Title = "BarCode",
|
||||
Version = "v1",
|
||||
Description = "BarCode-Api"
|
||||
});
|
||||
#region 读取xml信息
|
||||
// 使用反射获取xml文件。并构造出文件的路径
|
||||
//// 启用xml注释. 该方法第二个参数启用控制器的注释,默认为false.
|
||||
foreach (var file in Directory.GetFiles(AppContext.BaseDirectory, "BarCode.*.xml")) c.IncludeXmlComments(file, true);
|
||||
#endregion
|
||||
|
||||
#region 启用swagger验证功能
|
||||
//添加一个必须的全局安全信息,和AddSecurityDefinition方法指定的方案名称一致即可,CoreAPI。
|
||||
var securit = new OpenApiSecurityRequirement()
|
||||
{
|
||||
{
|
||||
new OpenApiSecurityScheme
|
||||
{
|
||||
Reference=new OpenApiReference { Type=ReferenceType.SecurityScheme,Id= "WMSAPI" }
|
||||
},
|
||||
new string[] { }
|
||||
}
|
||||
};
|
||||
c.AddSecurityRequirement(securit);
|
||||
c.AddSecurityDefinition("WMSAPI", new OpenApiSecurityScheme
|
||||
{
|
||||
Description = "JWT授权(数据将在请求头中进行传输) 在下方输入Bearer {token} 即可",
|
||||
Name = "Authorization",//jwt默认的参数名称
|
||||
In = ParameterLocation.Header,//jwt默认存放Authorization信息的位置(请求头中)
|
||||
Type = SecuritySchemeType.ApiKey
|
||||
});
|
||||
#endregion
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 系统配置
|
||||
/// </summary>
|
||||
private void AddConfigOptions()
|
||||
{
|
||||
//系统配置注册
|
||||
Services.AddOptions<AppOptions>();
|
||||
Services.Configure<AppOptions>(Configuration.GetSection("AppOptions"));
|
||||
Services.AddOptions<SoaOptions>();
|
||||
Services.Configure<SoaOptions>(Configuration.GetSection("SoaOptions"));
|
||||
Services.AddOptions<ErpOptions>();
|
||||
Services.Configure<ErpOptions>(Configuration.GetSection("ErpOptions"));
|
||||
Services.AddOptions<WmsOptions>();
|
||||
Services.Configure<WmsOptions>(Configuration.GetSection("WmsOptions"));
|
||||
Services.AddOptions<QiniuOptions>();
|
||||
Services.Configure<QiniuOptions>(Configuration.GetSection("Qiniu"));
|
||||
//Services.AddOptions<EmailOptions>();
|
||||
//Services.Configure<EmailOptions>(Configuration.GetSection("EmailOptions"));
|
||||
//Services.AddOptions<SmsOptions>();
|
||||
//Services.Configure<SmsOptions>(Configuration.GetSection("SmsOptions"));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Quartz定时任务-可分布式集群
|
||||
/// </summary>
|
||||
private void AddQuartzService()
|
||||
{
|
||||
var options = Configuration.GetSection("QuartzJobOptions").Get<QuartzJobOptions>();
|
||||
|
||||
Services.AddTransient<MaterialsBarQuartzJob>();//添加注入定时服务
|
||||
Services.AddTransient<MaterialsQuartzJob>();//添加注入定时服务
|
||||
Services.AddTransient<CenerateDataQuartzJob>();//添加注入定时服务
|
||||
Services.AddQuartz(q =>
|
||||
{
|
||||
q.UsePersistentStore(x =>
|
||||
{
|
||||
//存储类型
|
||||
x.Properties[options.JobStoreTypeKey] = options.JobStoreTypeValue;
|
||||
//数据库驱动类型-这里是mysql
|
||||
x.Properties[options.JobStoreDriverDelegateTypeKey] = options.JobStoreDriverDelegateTypeValue;
|
||||
//表名前缀
|
||||
x.Properties[options.JobStoreTablePrefixKey] = options.JobStoreTablePrefixValue;
|
||||
//数据源名称
|
||||
x.Properties[options.JobStoreDataSourceKey] = options.JobStoreDataSourceValue;
|
||||
//连接字符串
|
||||
x.Properties[options.JobStoreConnectionStringKey] = options.JobStoreConnectionStringValue;
|
||||
//sqlserver版本
|
||||
x.Properties[options.JobStoreProviderKey] = options.JobStoreProviderValue;
|
||||
//是否启用集群:是
|
||||
x.Properties[options.JobStoreClusteredKey] = options.JobStoreClusteredValue;
|
||||
//集群节点都必须有一个唯一ID
|
||||
x.Properties[options.JobStoreInstanceIdKey] = options.JobStoreInstanceIdValue;
|
||||
x.UseProperties = true;
|
||||
x.UseClustering();
|
||||
x.UseJsonSerializer();
|
||||
});
|
||||
//用于注入
|
||||
q.UseMicrosoftDependencyInjectionJobFactory();
|
||||
|
||||
#region 同步新物料id32进制信息
|
||||
var jobKey_materialbar = new JobKey("MaterialsBarQuartzJob", options.QuartzJobValue);
|
||||
q.AddJob<MaterialsBarQuartzJob>(jobKey_materialbar, j => j.WithDescription("MaterialsBarQuartzJob"));
|
||||
q.AddTrigger(t => t
|
||||
.WithIdentity("MaterialsBarQuartzJobTrigger")
|
||||
.ForJob(jobKey_materialbar)
|
||||
.StartNow()
|
||||
.WithCronSchedule(options.JobStartExpre)
|
||||
//.WithCronSchedule(CronScheduleBuilder.DailyAtHourAndMinute(options.JobStartHour[5], options.JobStartMinute[5]))
|
||||
.WithDescription("MaterialsBarQuartzJobTriggerDecs"));
|
||||
#endregion
|
||||
|
||||
#region 同步新物料信息
|
||||
var jobKey_material = new JobKey("MaterialsQuartzJob", options.QuartzJobValue);
|
||||
q.AddJob<MaterialsQuartzJob>(jobKey_material, j => j.WithDescription("MaterialsQuartzJob"));
|
||||
q.AddTrigger(t => t
|
||||
.WithIdentity("MaterialsQuartzJobTrigger")
|
||||
.ForJob(jobKey_material)
|
||||
.StartNow()
|
||||
.WithCronSchedule(options.JobStartExpreMaterial)
|
||||
//.WithCronSchedule(CronScheduleBuilder.DailyAtHourAndMinute(options.JobStartHour[5], options.JobStartMinute[5]))
|
||||
.WithDescription("MaterialsQuartzJobTriggerDecs"));
|
||||
#endregion
|
||||
|
||||
#region 维护自动生成数据管理
|
||||
var jobKey_cenerate = new JobKey("CenerateQuartzJob", options.QuartzJobValue);
|
||||
q.AddJob<CenerateDataQuartzJob>(jobKey_cenerate, j => j.WithDescription("CenerateQuartzJob"));
|
||||
q.AddTrigger(t => t
|
||||
.WithIdentity("CenerateQuartzJobTrigger")
|
||||
.ForJob(jobKey_cenerate)
|
||||
.StartNow()
|
||||
.WithCronSchedule(options.JobStartExpreCenerateData)
|
||||
.WithDescription("CenerateQuartzJobTriggerDecs"));
|
||||
#endregion
|
||||
});
|
||||
//.net core核心托管-添加Quartz服务器
|
||||
Services.AddQuartzServer(options =>
|
||||
{
|
||||
//关闭时,我们希望作业正常完成
|
||||
options.WaitForJobsToComplete = false;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注入服务层
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
private void AddServiceRepositories()
|
||||
{
|
||||
Services.AddSingleton<RedisClientService>();
|
||||
Services.AddTransient<HttpClientHelp>();
|
||||
Services.AddHostedService<HostedService>();
|
||||
//注入服务
|
||||
Services.AddTransient<ILoginService, LoginService>();
|
||||
Services.AddTransient<IHttpClientService, HttpClientService>();
|
||||
Services.AddTransient<ISingleDataService, SingleDataService>();
|
||||
Services.AddTransient<IErpService, ErpService>();
|
||||
Services.AddTransient<IWmsService, WmsService>();
|
||||
|
||||
Services.AddTransient<IErpBasicDataExtendService, ErpBasicDataExtendService>();
|
||||
Services.AddTransient<IExportExcelService, ExportExcelService>();
|
||||
Services.AddTransient<IQiniuUploadService, QiniuUploadService>();
|
||||
Services.AddTransient<IBoxMarkService, BoxMarkService>();
|
||||
Services.AddTransient<IMaterialService, MaterialService>();
|
||||
Services.AddTransient<IRedisConcurrentProcessService, RedisConcurrentProcessService>();
|
||||
|
||||
Services.AddTransient<ISerialNumberService, SerialNumberService>();
|
||||
Services.AddTransient<IBoxService, BoxService>();
|
||||
Services.AddTransient<ISecurityNumberService, SecurityNumberService>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using BarCode.Web.Core.Dto;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Repositories;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
using BarCode.Web.Repositories.DependencyInjection;
|
||||
using BarCode.Web.Core.Dto.SerialNumbers;
|
||||
using BarCode.Web.Core.Dto.SecurityNumbers;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class AppBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置数据库
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
/// <param name="configureDbContext"></param>
|
||||
/// <returns></returns>
|
||||
public static AppBuilder AddDbContext(this AppBuilder builder, Action<DbContextOptionsBuilder> configureDbContext)
|
||||
{
|
||||
builder.Services.AddDbContext<RepositoryDbContext>(configureDbContext);
|
||||
builder.Services.AddRepositories();
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 注入仓储层
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
private static void AddRepositories(this IServiceCollection services)
|
||||
{
|
||||
services.AddHttpContextAccessor();
|
||||
services.AddScoped<ILoginRepositories, LoginRepositories>();
|
||||
services.AddTransient<IBasicsRepositories, BasicsRepositories>();
|
||||
services.AddTransient<ITransactionRepositories, TransactionRepositories>();
|
||||
|
||||
#region 导出
|
||||
services.AddTransient<IAllFielRepositories<SerialNumbersExportRequest>, SerialNumbersRepositories>();
|
||||
services.AddTransient<IAllFielRepositories<SerialNumberQueryRequest>, SerialNumbersRepositories>();
|
||||
services.AddTransient<IAllFielRepositories<SecurityNumbersExportRequest>, SecurityNumbersRepositories>();
|
||||
services.AddTransient<IAllFielRepositories<SecurityNumberQueryRequest>, SecurityNumbersRepositories>();
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
services.AddTransient<IFileDownManagerRepositories, FileDownManagerRepositories>();
|
||||
|
||||
|
||||
services.AddTransient<IBoxRepositories, BoxRepositories>();
|
||||
services.AddTransient<IBoxMarkRepositories, BoxMarkRepositories>();
|
||||
services.AddTransient<IMaterialsRepositories, MaterialsRepositories>();
|
||||
services.AddTransient<ISerialNumbersRepositories, SerialNumbersRepositories>();
|
||||
services.AddTransient<ISGenerateRecordRepositories, SGenerateRecordRepositories>();
|
||||
services.AddTransient<ISecurityNumbersRepositories, SecurityNumbersRepositories>();
|
||||
services.AddTransient<ISecurityGenerateRecordRepositories, SecurityGenerateRecordRepositories>();
|
||||
services.AddTransient<ICenerateDataRepositories, CenerateDataRepositories>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BarCode.Web.Core.Dto.Login;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Domain.Services.Public;
|
||||
using crypto;
|
||||
|
||||
namespace BarCode.Web.Repositories.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// token 黑名单中间件
|
||||
/// </summary>
|
||||
public class AuthorizationTokenSecurityPolicy
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private readonly IMemoryCache _cache;
|
||||
private ILogger<AuthorizationTokenSecurityPolicy> _logger;
|
||||
private DateTime _refreshTime = DateTime.Now.AddYears(-5);
|
||||
private readonly RedisClientService _redisClientService;
|
||||
|
||||
/// <summary>
|
||||
/// token黑名单中间件
|
||||
/// </summary>
|
||||
/// <param name="next"></param>
|
||||
/// <param name="cache"></param>
|
||||
public AuthorizationTokenSecurityPolicy(RequestDelegate next, ILogger<AuthorizationTokenSecurityPolicy> logger, IMemoryCache cache, RedisClientService redisClientService)
|
||||
{
|
||||
_next = next;
|
||||
_cache = cache;
|
||||
this._logger = logger;
|
||||
_redisClientService = redisClientService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 事件
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Invoke(HttpContext context, ILoginService loginService)
|
||||
{
|
||||
string authorization = context.Request.Headers["Authorization"];
|
||||
string path = context.Request.Path.Value.ToLower();
|
||||
string[] pathlist = path.Split('/');
|
||||
bool isLogin = pathlist.Where(x => x == "login" || x.ToLower() == "heart"
|
||||
|| x.ToLower() == "test" || x.ToLower() == "swagger" || x.ToLower() == "wmsbox" || x.ToLower() == "security"
|
||||
|| x.ToLower() == "material"||x.ToLower()== "filedownmanager").Any();
|
||||
if (isLogin)
|
||||
{
|
||||
context.Response.StatusCode = 200;
|
||||
await _next(context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(authorization))
|
||||
{
|
||||
context.Response.StatusCode = 401;
|
||||
var result = JsonConvert.SerializeObject(new { status = 401, data = string.Empty, message = "授权失败,请重新登录" });
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
await context.Response.WriteAsync(result);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
string token = string.Empty;
|
||||
if (authorization.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
token = authorization.Substring("Bearer ".Length).Trim();
|
||||
}
|
||||
|
||||
//判断前端过来的token
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
context.Response.StatusCode = 401;
|
||||
var result = JsonConvert.SerializeObject(new { status = 401, data = string.Empty, message = "授权失败,请重新登录" });
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
await context.Response.WriteAsync(result);
|
||||
return;
|
||||
}
|
||||
|
||||
//1.验证是否有登录数据缓存
|
||||
var logininfo = _redisClientService.GetStringKey<LoginInDto>($"wms_login_{token}");
|
||||
if (logininfo == null)
|
||||
{
|
||||
context.Response.StatusCode = 401;
|
||||
var result = JsonConvert.SerializeObject(new { status = 401, data = string.Empty, message = "授权失败,请重新登录" });
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
await context.Response.WriteAsync(result);
|
||||
return;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//验证响应状态为401的就调用单点退出接口
|
||||
if (context.Response.StatusCode == 401 || context.Response.StatusCode == 403)
|
||||
{
|
||||
if (logininfo.UserInfo != null && logininfo.TokenInfo != null)
|
||||
{
|
||||
//调用单点的退出接口
|
||||
var dto = new LoginOutDto()
|
||||
{
|
||||
UcId = logininfo.UserInfo.UcId.ToString(),
|
||||
SessionId = logininfo.UserInfo.SeesionId,
|
||||
Token = logininfo.TokenInfo.Token,
|
||||
RefreshToken = logininfo.TokenInfo.RefreshToken,
|
||||
AccessToken = logininfo.TokenInfo.PhpToken,
|
||||
ExpiresIn = logininfo.TokenInfo.Expired
|
||||
|
||||
};
|
||||
var res = await loginService.LoginOut(dto);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
TimeSpan jiange_timespan = TimeSpan.Zero;
|
||||
if (logininfo.TokenInfo.Expired < now)
|
||||
{
|
||||
jiange_timespan = now - logininfo.TokenInfo.Expired;
|
||||
var info = _redisClientService.GetStringKey<LoginInDto>($"wms_login_{token}");
|
||||
|
||||
if (info != null)
|
||||
{
|
||||
//超过16个小时的,就要移除缓存
|
||||
if (jiange_timespan.TotalHours >= 16)
|
||||
_redisClientService.RemoveStringKey($"wms_login_{token}");
|
||||
//超过1个小时的,就要刷新token
|
||||
else if (!string.IsNullOrEmpty(logininfo.TokenInfo.Token) && jiange_timespan.TotalHours >= 1)
|
||||
this.RefreshToken(logininfo.TokenInfo.Token, logininfo.TokenInfo.RefreshToken, loginService);
|
||||
|
||||
}
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// //刷新token:距离过期时间还有10分钟就进行刷新token
|
||||
// jiange_timespan = logininfo.TokenInfo.Expired - now;
|
||||
// if (!string.IsNullOrEmpty(logininfo.TokenInfo.Token) && jiange_timespan.TotalMinutes<=10)
|
||||
// this.RefreshToken(logininfo.TokenInfo.Token, logininfo.TokenInfo.RefreshToken, loginService);
|
||||
//}
|
||||
|
||||
//3.验证检查是否有黑名单的token缓存
|
||||
string blacktoken = _redisClientService.GetStringKey($"wms_black_token_{logininfo.UserInfo.UcId}");
|
||||
if (string.IsNullOrEmpty(blacktoken))
|
||||
{
|
||||
context.Response.StatusCode = 200;
|
||||
await _next(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveRedisLoginInfo(token);
|
||||
context.Response.StatusCode = 403;
|
||||
var result = JsonConvert.SerializeObject(new { status = 403, data = string.Empty, message = "拒绝用户证书试图访问此web站点,请与站点管理员联系以建立用户证书权限" });
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
await context.Response.WriteAsync(result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 过期,或者失效,移出token
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
private void RemoveRedisLoginInfo(string token)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
var info = _redisClientService.GetStringKey<LoginInDto>($"wms_login_{token}");
|
||||
if (info != null)
|
||||
{
|
||||
_redisClientService.RemoveStringKey($"wms_login_{token}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 刷新token
|
||||
/// </summary>
|
||||
/// <param name="RefreshToken"></param>
|
||||
/// <returns></returns>
|
||||
private bool RefreshToken(string OldToken, string RefreshToken, ILoginService _loginService)
|
||||
{
|
||||
var res = _loginService.RefreshTokenNew(OldToken, RefreshToken);
|
||||
if (!res.Result.Success)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BarCode.Web.Repositories.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// 统一全局错误拦截
|
||||
/// </summary>
|
||||
public class ErrorHandlingMiddleware
|
||||
{
|
||||
private readonly RequestDelegate next;
|
||||
private readonly ILogger<ErrorHandlingMiddleware> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// 统一错误处理中间件
|
||||
/// </summary>
|
||||
public ErrorHandlingMiddleware(RequestDelegate next, ILogger<ErrorHandlingMiddleware> logger)
|
||||
{
|
||||
this.next = next;
|
||||
_logger = logger;
|
||||
}
|
||||
private string bodyStr = "";
|
||||
/// <summary>
|
||||
/// 激活
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
//默认 请求body只能读取一次 所以在这里需要手动把他设置成读取多次 并且 不能使用using 释放
|
||||
context.Request.EnableBuffering();
|
||||
StreamReader requestReader = new StreamReader(context.Request.Body, Encoding.UTF8);
|
||||
bodyStr = await requestReader.ReadToEndAsync();
|
||||
context.Request.Body.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
await next(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// var statusCode = context.Response.StatusCode;
|
||||
var statusCode = 500;
|
||||
if (ex is ArgumentException) statusCode = 200;
|
||||
|
||||
_logger.LogError($"统一拦截异常处理: {ex.Message}, StackTrace:{ex.StackTrace},Path:{context.Request.Path},Parame:{bodyStr}");
|
||||
|
||||
await HandleExceptionAsync(context, statusCode, "服务器错误,不能执行此请求,请稍后重试,若问题一直存在,请与站点管理员联系");
|
||||
// await HandleExceptionAsync(context, statusCode, "服务器错误");
|
||||
}
|
||||
finally
|
||||
{
|
||||
var statusCode = context.Response.StatusCode;
|
||||
var msg = "";
|
||||
// if (statusCode == 401)
|
||||
// {
|
||||
// msg = "未授权";
|
||||
// }
|
||||
if (statusCode == 404)
|
||||
msg = "服务器暂无响应,请稍后重试,若问题一直存在,请与站点管理员联系";
|
||||
else if (statusCode == 502) msg = "网关出错,请与站点管理员联系";
|
||||
// else if (statusCode != 200)
|
||||
// {
|
||||
// msg = "未知错误";
|
||||
// }
|
||||
if (!string.IsNullOrWhiteSpace(msg)) await HandleExceptionAsync(context, statusCode, msg);
|
||||
}
|
||||
}
|
||||
|
||||
private static Task HandleExceptionAsync(HttpContext context, int statusCode, string msg)
|
||||
{
|
||||
string data = null;
|
||||
var result = JsonConvert.SerializeObject(new { status = statusCode, result = data, message = msg });
|
||||
context.Response.StatusCode = statusCode;
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
return context.Response.WriteAsync(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using BarCode.Web.Core.Internal.Results;
|
||||
using BarCode.Web.Domain.Services.Public;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BarCode.Web.Repositories.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// 防重复提交
|
||||
/// </summary>
|
||||
public class PlatformActionMiddleware
|
||||
{
|
||||
private readonly RequestDelegate next;
|
||||
private readonly ILogger<PlatformActionMiddleware> _logger;
|
||||
private readonly RedisClientService _redisClientService;
|
||||
/// <summary>
|
||||
/// 统一错误处理中间件
|
||||
/// </summary>
|
||||
public PlatformActionMiddleware(RequestDelegate next, ILogger<PlatformActionMiddleware> logger, RedisClientService redisClientService)
|
||||
{
|
||||
this.next = next;
|
||||
_logger = logger;
|
||||
_redisClientService = redisClientService;
|
||||
}
|
||||
private string bodyStr = "";
|
||||
|
||||
/// <summary>
|
||||
/// 激活
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
//默认 请求body只能读取一次 所以在这里需要手动把他设置成读取多次 并且 不能使用using 释放
|
||||
context.Request.EnableBuffering();
|
||||
StreamReader requestReader = new StreamReader(context.Request.Body, Encoding.UTF8);
|
||||
bodyStr = await requestReader.ReadToEndAsync();
|
||||
context.Request.Body.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
string httpMethod = WebUtility.HtmlEncode(context.Request.Method);
|
||||
if (httpMethod == "POST")
|
||||
{
|
||||
//使用请求路径作为唯一key
|
||||
string path = context.Request.Path;
|
||||
string authorization = context.Request.Headers["Authorization"];
|
||||
string cacheToken = $"{authorization}_{path}";
|
||||
string keyValue = string.IsNullOrEmpty(bodyStr) ? "yc" : bodyStr;
|
||||
|
||||
if (path != null)
|
||||
{
|
||||
//var cache = iZen.Utils.Core.iCache.CacheManager.GetCacheValue(cacheToken);
|
||||
string cv = _redisClientService.GetStringKey(cacheToken);
|
||||
if (cv == null && bodyStr != cv)
|
||||
{
|
||||
//iZen.Utils.Core.iCache.CacheManager.SetChacheValueSeconds(cacheToken, keyValue, 1);
|
||||
//设置缓存10秒过期
|
||||
_redisClientService.SetStringKey(cacheToken, keyValue, TimeSpan.FromSeconds(10));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Response.StatusCode = 200;
|
||||
var result = JsonConvert.SerializeObject(new { status = 888888, data = string.Empty, message = "重复提交" });
|
||||
context.Response.ContentType = "application/json;charset=utf-8";
|
||||
await context.Response.WriteAsync(result);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
await next(context);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using BarCode.Web.Repositories.DependencyInjection;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加app框架
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="startupAction"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection AddApp(this IServiceCollection services, IConfiguration configuration, bool IsDevelopment, Action<AppBuilder> startupAction)
|
||||
{
|
||||
services.AddAppCore(configuration, IsDevelopment, startupAction);
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加app核心服务
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="startupAction">ASF启动配置函数</param>
|
||||
/// <returns></returns>
|
||||
internal static IServiceCollection AddAppCore(this IServiceCollection services, IConfiguration configuration, bool IsDevelopment, Action<AppBuilder> startupAction)
|
||||
{
|
||||
var builder = new AppBuilder(services, configuration, IsDevelopment);
|
||||
startupAction?.Invoke(builder);
|
||||
builder.Build();
|
||||
return services;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
110
src/BarCode.Web.Repositories/FileDownManagerRepositories.cs
Normal file
110
src/BarCode.Web.Repositories/FileDownManagerRepositories.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BarCode.Web.Core;
|
||||
using BarCode.Web.Core.Dto;
|
||||
using BarCode.Web.Domain.Entitys;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Domain.Values;
|
||||
using BarCode.Web.Domain.Values.Single;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
using BarCode.Web.Core.Dto.Login;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
public class FileDownManagerRepositories : IFileDownManagerRepositories
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
public FileDownManagerRepositories(RepositoryDbContext context, IMapper mapper, ISingleDataService singleDataService)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
_singleDataService = singleDataService;
|
||||
}
|
||||
|
||||
public async Task<FileDownManager> Add(FileDownManager entity)
|
||||
{
|
||||
await _context.FileDownManager.AddAsync(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<FileDownManager> Edit(FileDownManager entity)
|
||||
{
|
||||
var res = await _context.FileDownManager
|
||||
.FirstOrDefaultAsync(f => f.Id == entity.Id);
|
||||
if (res == null) return null;
|
||||
|
||||
_mapper.Map(entity, res);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return res;
|
||||
}
|
||||
|
||||
public async Task<FileDownManagerResponse> GetList(FileDownManagerRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
List<int> userIds = new List<int>();
|
||||
if (!string.IsNullOrEmpty(dto.User))
|
||||
userIds = _singleDataService.GetIdsBySingleName(SingleAction.Users, loginInfo.UserInfo.CompanyId, dto.User);
|
||||
|
||||
var res = _context.FileDownManager
|
||||
//.GroupJoin(_context.UcStaff, manager => manager.UserId, user => user.Id, (manager, user) => new { manager, user })
|
||||
// .SelectMany(x => x.user.DefaultIfEmpty(), (d, user) => new { d.manager, user })
|
||||
.OrderByDescending(o => o.Date)
|
||||
.Where(w => w.CompanyId == loginInfo.UserInfo.CompanyId);
|
||||
|
||||
|
||||
#region 条件
|
||||
if (loginInfo.UserInfo.IsAdmin != true && !string.IsNullOrEmpty(dto.OrgCode))
|
||||
{
|
||||
var rec_type = dto.OrgCode.Substring(0, 1);
|
||||
var rec_code = dto.OrgCode.Substring(2, dto.OrgCode.Length - 2);
|
||||
|
||||
if (rec_type.Equals("s"))//供应商
|
||||
res = res.Where(w => rec_code == w.SupplierCode);
|
||||
else//查其他单据(组织)
|
||||
res = res.Where(w => rec_code == w.OrgCode);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dto.User))
|
||||
res = res.Where(w => userIds.Contains(w.UserId));
|
||||
if (dto.BeginDate != null)
|
||||
res = res.Where(w => w.Date >= dto.BeginDate);
|
||||
if (dto.EndDate != null)
|
||||
res = res.Where(w => w.Date <= (dto.EndDate ?? DateTime.Now).AddHours(23).AddMinutes(59).AddSeconds(59));
|
||||
if (dto.Type != null)
|
||||
res = res.Where(w => w.Type == (FileDownLoadOrderType)dto.Type);
|
||||
|
||||
if (dto.Status != null)
|
||||
{
|
||||
if ((ExportStatus)dto.Status == ExportStatus.Ing)
|
||||
res = res.Where(w => w.Status == ExportStatus.Ing && w.Date >= DateTime.Now.AddHours(-1));
|
||||
else if ((ExportStatus)dto.Status == ExportStatus.Fail)
|
||||
res = res.Where(w => (w.Status == ExportStatus.Fail) || (w.Status == ExportStatus.Ing && w.Date < DateTime.Now.AddHours(-1)));
|
||||
else
|
||||
res = res.Where(w => w.Status == (ExportStatus)dto.Status);
|
||||
}
|
||||
#endregion
|
||||
|
||||
int total = await res.CountAsync();
|
||||
var list = await res.Select(s => new FileDownInfoManagerResponse(_mapper.Map<FileDownInfoManagerResponse>(s))
|
||||
{
|
||||
StatusKey = (s.Status == ExportStatus.Ing && s.Date < DateTime.Now.AddHours(-1)) ? (int)ExportStatus.Fail : (int)s.Status,
|
||||
Status = (s.Status == ExportStatus.Ing && s.Date < DateTime.Now.AddHours(-1)) ? ExportStatus.Fail.GetRemark() : s.Status.GetRemark(),
|
||||
UserName = _singleDataService.GetSingleData(SingleAction.Users, loginInfo.UserInfo.CompanyId, s.UserId)
|
||||
})
|
||||
.Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize)
|
||||
.ToListAsync();
|
||||
|
||||
return new FileDownManagerResponse(list, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
49
src/BarCode.Web.Repositories/LoginRepositories.cs
Normal file
49
src/BarCode.Web.Repositories/LoginRepositories.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using BarCode.Web.Core.Dto.Login;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.Services.Public;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录仓储
|
||||
/// </summary>
|
||||
public class LoginRepositories:ILoginRepositories
|
||||
{
|
||||
public int CompanyId { get; set; } = 0;
|
||||
public int StaffId { get; set; } = 0;
|
||||
public LoginInDto loginInfo { get; set; }
|
||||
private readonly RedisClientService _redisClientService;
|
||||
public LoginRepositories(ILogger<LoginRepositories> logger, IHttpContextAccessor httpContextAccessor, RedisClientService redisClientService)
|
||||
{
|
||||
try
|
||||
{
|
||||
string authorization = httpContextAccessor?.HttpContext?.Request?.Headers["Authorization"] ?? "";
|
||||
if (string.IsNullOrEmpty(authorization)) return;
|
||||
|
||||
string token = string.Empty;
|
||||
if (authorization.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
token = authorization.Substring("Bearer ".Length).Trim();
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
this.CompanyId = 0;
|
||||
this.StaffId = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
_redisClientService = redisClientService;
|
||||
var logininfo = _redisClientService.GetStringKey<LoginInDto>($"wms_login_{token}");
|
||||
this.loginInfo = loginInfo;
|
||||
this.CompanyId = logininfo == null ? 0 : logininfo.UserInfo.CompanyId;
|
||||
this.StaffId = logininfo == null ? 0 : logininfo.UserInfo.StaffId;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
177
src/BarCode.Web.Repositories/MaterialsRepositories.cs
Normal file
177
src/BarCode.Web.Repositories/MaterialsRepositories.cs
Normal file
@@ -0,0 +1,177 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BarCode.Web.Core.Help;
|
||||
using BarCode.Web.Domain.Entitys;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Domain.Mappers;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 物料仓储
|
||||
/// </summary>
|
||||
public class MaterialsRepositories : IMaterialsRepositories
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public MaterialsRepositories(RepositoryDbContext context, IServiceProvider serviceProvider,
|
||||
IMapper mapper)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AddRange(List<Materials> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
if (entitys != null && entitys.Count != 0)
|
||||
{
|
||||
await _context.Materials.AddRangeAsync(entitys);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取集合
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<Materials>> GetEntityList(int? orgId = null)
|
||||
{
|
||||
var query = _context.Materials.AsNoTracking()
|
||||
.Where(x => 1 == 1);
|
||||
if (orgId.HasValue)
|
||||
query = query.Where(x => x.OrgId == orgId.Value);
|
||||
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Materials> Get(int mid)
|
||||
{
|
||||
var query = _context.Materials.AsNoTracking().Where(x => 1 == 1);
|
||||
|
||||
query = query.Where(x => x.MaterialId == mid);
|
||||
|
||||
return await query.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Materials> Get(string code, int orgId)
|
||||
{
|
||||
var query = _context.Materials.AsNoTracking().Where(x => x.MaterialNumber == code && x.OrgId == orgId);
|
||||
|
||||
return await query.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全部的物料编码
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<string>> GetAllNumbers()
|
||||
{
|
||||
var numbers = await _context.Materials.AsNoTracking()
|
||||
.Select(x => x.MaterialNumber).ToListAsync();
|
||||
if (numbers.Count() <= 0) return numbers;
|
||||
|
||||
return numbers.Distinct().ToList();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全部的物料编码
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<Materials>> GetEntityList(List<string> materNumbers, bool isBatchManage)
|
||||
{
|
||||
var entitys = await _context.Materials.Where(x => materNumbers.Contains(x.MaterialNumber) && x.IsBatchManage == isBatchManage).ToListAsync();
|
||||
return entitys;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改物料
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> UpdateRange(List<Materials> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
{
|
||||
try
|
||||
{
|
||||
List<int> list = entitys.Select(s => s.Id).ToList();
|
||||
var res = await _context.Materials.Where(f => list.Contains(f.Id)).ToListAsync();
|
||||
_mapper.ToMapList(entitys, res);
|
||||
await _context.SaveChangesAsync();
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取所有没有id32进制的物料
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<Materials>> GetEntityListByNoBar()
|
||||
{
|
||||
var entitys = await _context.Materials.AsNoTracking().Where(x =>string.IsNullOrEmpty(x.IdConvertBar.Trim())).ToListAsync();
|
||||
return entitys;
|
||||
}
|
||||
|
||||
public async Task<List<Materials>> GetEntityList(List<string> materNumbers)
|
||||
{
|
||||
var entitys = await _context.Materials.Where(x => materNumbers.Contains(x.MaterialNumber)).ToListAsync();
|
||||
return entitys;
|
||||
}
|
||||
}
|
||||
}
|
||||
68
src/BarCode.Web.Repositories/MySqlDataAccess.cs
Normal file
68
src/BarCode.Web.Repositories/MySqlDataAccess.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MySqlConnector;
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
public class MySqlDataAccess
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
|
||||
public MySqlDataAccess(string connectionString)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行查询并返回 DataTable
|
||||
/// </summary>
|
||||
/// <param name="query">SQL 查询语句</param>
|
||||
/// <returns>查询结果的 DataTable</returns>
|
||||
public DataTable ExecuteQuery(string query)
|
||||
{
|
||||
using (MySqlConnection connection = new MySqlConnection(_connectionString))
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
MySqlCommand command = new MySqlCommand(query, connection);
|
||||
MySqlDataAdapter adapter = new MySqlDataAdapter(command);
|
||||
DataTable dataTable = new DataTable();
|
||||
adapter.Fill(dataTable);
|
||||
return dataTable;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"查询出错: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行非查询操作(如 INSERT、UPDATE、DELETE)
|
||||
/// </summary>
|
||||
/// <param name="query">SQL 非查询语句</param>
|
||||
/// <returns>受影响的行数</returns>
|
||||
public int ExecuteNonQuery(string query)
|
||||
{
|
||||
using (MySqlConnection connection = new MySqlConnection(_connectionString))
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
MySqlCommand command = new MySqlCommand(query, connection);
|
||||
return command.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"执行非查询操作出错: {ex.Message}");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
339
src/BarCode.Web.Repositories/SGenerateRecordRepositories.cs
Normal file
339
src/BarCode.Web.Repositories/SGenerateRecordRepositories.cs
Normal file
@@ -0,0 +1,339 @@
|
||||
using AutoMapper;
|
||||
using BarCode.Web.Core.Dto.Erp.Org;
|
||||
using BarCode.Web.Core.Dto.Erp.Supplier;
|
||||
using BarCode.Web.Core.Dto.Erp;
|
||||
using BarCode.Web.Core.Dto.SerialNumbers;
|
||||
using BarCode.Web.Domain.Entitys;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.Mappers;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Newtonsoft.Json;
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Core.Dto.Box;
|
||||
using BarCode.Web.Domain.Services.Public;
|
||||
using BarCode.Web.Domain.Values.Single;
|
||||
using System.ComponentModel.Design;
|
||||
using BarCode.Web.Core.Help;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using BarCode.Web.Core.Dto.Login;
|
||||
using BarCode.Web.Core.Dto.SingleData;
|
||||
using BarCode.Web.Core.Internal.Results;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 序列号生成记录
|
||||
/// </summary>
|
||||
public class SGenerateRecordRepositories : ISGenerateRecordRepositories
|
||||
{
|
||||
private readonly ILoginRepositories _loginRepositories;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IErpService _erpService;
|
||||
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
|
||||
public SGenerateRecordRepositories(RepositoryDbContext context,
|
||||
ILoginRepositories loginRepositories,
|
||||
IBasicsRepositories basicsRepositories, IMapper mapper, IErpService erpService,
|
||||
IErpBasicDataExtendService erpBasicDataExtendService, ISingleDataService singleDataService)
|
||||
{
|
||||
_context = context;
|
||||
_basicsRepositories = basicsRepositories;
|
||||
_loginRepositories = loginRepositories;
|
||||
_mapper = mapper;
|
||||
_erpService = erpService;
|
||||
_erpBasicDataExtendService = erpBasicDataExtendService;
|
||||
_singleDataService = singleDataService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 新增
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<SerialNumberGenerateRecord> Add(SerialNumberGenerateRecord entity, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
await _context.SerialNumberGenerateRecord.AddAsync(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return entity;
|
||||
}
|
||||
/// <summary>
|
||||
/// 批量添加
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AddRange(List<SerialNumberGenerateRecord> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
if (entitys != null && entitys.Count != 0)
|
||||
{
|
||||
await _context.SerialNumberGenerateRecord.AddRangeAsync(entitys);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<SerialNumberGenerateRecord> Edit(SerialNumberGenerateRecord entity, bool isTransaction = true)
|
||||
{
|
||||
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
var res = await _context.SerialNumberGenerateRecord
|
||||
.FirstOrDefaultAsync(f => f.Id == entity.Id);
|
||||
if (res == null) return null;
|
||||
|
||||
_mapper.Map(entity, res);
|
||||
var result = await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
|
||||
return res;
|
||||
}
|
||||
/// <summary>
|
||||
/// 批量修改
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> EditEntityList(List<SerialNumberGenerateRecord> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
List<int> list = entitys.Select(s => s.Id).ToList();
|
||||
var res = await _context.SerialNumberGenerateRecord
|
||||
.Where(f => list.Contains(f.Id)).ToListAsync();
|
||||
|
||||
_mapper.ToMapList(entitys, res);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询实体
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<SerialNumberGenerateRecord?> GetEntity(int id)
|
||||
{
|
||||
return await _context.SerialNumberGenerateRecord.AsNoTracking()
|
||||
.FirstOrDefaultAsync(f => f.Id == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取集合
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<List<SerialNumberGenerateRecord>> GetEntityList(List<int> ids)
|
||||
{
|
||||
return await _context.SerialNumberGenerateRecord.AsNoTracking()
|
||||
.Where(f => ids.Contains(f.Id))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<(List<SGenerateRecordInfoResponse> list, int total)> GetListAsync(SGenerateRecordQueryRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
int companyId = loginInfo.UserInfo.CompanyId;
|
||||
|
||||
List<string> mNumber = new List<string>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
//物料集合;模糊查询后的物料集合
|
||||
if (!string.IsNullOrEmpty(dto.MaterialNumber))
|
||||
{
|
||||
if (materials != null)
|
||||
mNumber = materials.Where(w => w.MaterialNumber.Contains(dto.MaterialNumber)
|
||||
|| w.MaterialName.Contains(dto.MaterialNumber)
|
||||
|| w.Specifications.Contains(dto.MaterialNumber)
|
||||
).Select(s => s.MaterialNumber).ToList();
|
||||
}
|
||||
List<int> cr_ids = new List<int>();
|
||||
if (!string.IsNullOrEmpty(dto.CreateUser))
|
||||
{
|
||||
cr_ids = await _basicsRepositories.GetUserIdsAsync(dto.CreateUser, loginInfo.UserInfo.CompanyId);
|
||||
}
|
||||
List<int> sIds = new List<int>();
|
||||
if (dto.SerialNumbers != null && dto.SerialNumbers.Count() > 0)
|
||||
{
|
||||
sIds = await _context.SerialNumbers.Where(w => dto.SerialNumbers.Contains(w.SerialNumber))
|
||||
.GroupBy(g => g.GenerateRecordId).Select(s => s.Key).ToListAsync();
|
||||
}
|
||||
|
||||
List<int> nIds = new List<int>();
|
||||
if (dto.NumberCodes != null && dto.NumberCodes.Count() > 0)
|
||||
{
|
||||
nIds = await _context.SerialNumbers.Where(w => dto.NumberCodes.Contains(w.NumberCode))
|
||||
.GroupBy(g => g.GenerateRecordId).Select(s => s.Key).ToListAsync();
|
||||
}
|
||||
|
||||
List<int> bIds = new List<int>();
|
||||
if (dto.BoxBillNos != null && dto.BoxBillNos.Count() > 0)
|
||||
{
|
||||
bIds = await _context.SerialNumbers
|
||||
.GroupJoin(_context.Box, serial => serial.BoxId, box => box.Id, (serial, box) => new { serial, box })
|
||||
.SelectMany(x => x.box.DefaultIfEmpty(), (p, box) => new { p.serial, box })
|
||||
.Where(w => dto.BoxBillNos.Contains(w.box.BoxBillNo))
|
||||
.Select(s => s.serial.GenerateRecordId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
//供应商
|
||||
//var supplier_result = await _erpService.BillQueryForSupplier();
|
||||
//List<ErpSupplierDto> suppliers = new List<ErpSupplierDto>();
|
||||
//if (supplier_result.IsSuccess)
|
||||
// suppliers = supplier_result.Data.ToList();
|
||||
//取组织
|
||||
//var org_result = await _erpService.BillQueryForOrg();
|
||||
//List<ErpOrgDto> orgs = new List<ErpOrgDto>();
|
||||
//if (org_result.IsSuccess)
|
||||
// orgs = org_result.Data.ToList();
|
||||
var result = await _singleDataService.GetSingleData<ResultList<SysOrgResponse>, SingleDataRequest, SysConfigAction>(
|
||||
new SingleDataRequest(loginInfo.UserInfo.CompanyId), SysConfigAction.GetOrgByCompany, SingleControllerType.SysConfig);
|
||||
List<SysOrgResponse> orgs = new List<SysOrgResponse>();
|
||||
if (result.IsSuccess)
|
||||
orgs = result.Data.ToList();
|
||||
|
||||
var query = _context.SerialNumberGenerateRecord
|
||||
.OrderByDescending(o => o.Id)
|
||||
.Where(f => 1 == 1);
|
||||
if (loginInfo.UserInfo.IsAdmin != true && !string.IsNullOrEmpty(dto.OrgCode))
|
||||
{
|
||||
var rec_type = dto.OrgCode.Substring(0, 1);
|
||||
var rec_code = dto.OrgCode.Substring(2, dto.OrgCode.Length - 2);
|
||||
|
||||
if (rec_type.Equals("s"))//供应商
|
||||
query = query.Where(w => rec_code == w.SupplierCode);
|
||||
else//查其他单据(组织)
|
||||
query = query.Where(w => rec_code == w.OrgCode);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dto.SupplierOrOrg))
|
||||
{
|
||||
var rec_type = dto.SupplierOrOrg.Substring(0, 1);
|
||||
var rec_code = dto.SupplierOrOrg.Substring(2, dto.SupplierOrOrg.Length - 2);
|
||||
|
||||
if (rec_type.Equals("s"))//供应商
|
||||
query = query.Where(w => rec_code == w.SupplierCode);
|
||||
else//查其他单据(组织)
|
||||
query = query.Where(w => rec_code == w.OrgCode);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dto.MaterialNumber))
|
||||
query = query.Where(w => mNumber.Contains(w.MaterialNumber));
|
||||
if (dto.CreateBeginDate != null)
|
||||
query = query.Where(w => w.GenerateCompleteTime >= dto.CreateBeginDate);
|
||||
if (dto.CreateEndDate != null)
|
||||
{
|
||||
DateTime dt_end = ((DateTime)dto.CreateEndDate).AddDays(1);
|
||||
query = query.Where(w => w.GenerateCompleteTime <= dt_end);
|
||||
}
|
||||
if (dto.SerialNumbers != null && dto.SerialNumbers.Count() > 0)
|
||||
query = query.Where(w => sIds.Contains(w.Id));
|
||||
if (dto.NumberCodes != null && dto.NumberCodes.Count() > 0)
|
||||
query = query.Where(w => nIds.Contains(w.Id));
|
||||
if (dto.BoxBillNos != null && dto.BoxBillNos.Count() > 0)
|
||||
query = query.Where(w => bIds.Contains(w.Id));
|
||||
if (dto.PurchaseBillNos != null && dto.PurchaseBillNos.Count() > 0)
|
||||
query = query.Where(w => dto.PurchaseBillNos.Contains(w.PurchaseBillNo));
|
||||
if (dto.GenerateComplete != null)
|
||||
query = query.Where(w => dto.GenerateComplete == w.IsGenerateComplete);
|
||||
if (!string.IsNullOrEmpty(dto.CreateUser))
|
||||
query = query.Where(w => cr_ids.Contains(w.CreatorId));
|
||||
if (dto.IsUpdateMaterial != null)
|
||||
{
|
||||
if (dto.IsUpdateMaterial == true)
|
||||
query = query.Where(w => w.IsUpdateMaterial == true);
|
||||
else
|
||||
query = query.Where(w => w.IsUpdateMaterial == false || w.IsUpdateMaterial == null);
|
||||
}
|
||||
|
||||
if (dto.IsTwo > 1)
|
||||
{
|
||||
query = query.Where(w => w.IsTwo > 1);
|
||||
}
|
||||
else if (dto.IsTwo == 1)
|
||||
{
|
||||
query = query.Where(w => w.IsTwo == 1);
|
||||
}
|
||||
else if (dto.IsTwo == 0)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
//query = query.Where(w => w.IsTwo == 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query.Select(s => new SGenerateRecordInfoResponse()
|
||||
{
|
||||
Id = s.Id,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.MaterialNumber),
|
||||
MaterialNumber = s.MaterialNumber,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.MaterialNumber),
|
||||
BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.MaterialNumber),
|
||||
PurchaseBillNo = s.PurchaseBillNo,
|
||||
GenerateComplete = s.IsGenerateComplete == true ? "已完成" : "生成中",
|
||||
Number = s.Number,
|
||||
DownLoadNumber = s.DownLoadNumber,
|
||||
UseNumber = s.UseNumber,
|
||||
IsUpdateMaterial = s.IsUpdateMaterial,
|
||||
Creator = _singleDataService.GetSingleData(SingleAction.Users, companyId, s.CreatorId),
|
||||
CreateTime = s.CreateTime.DateToStringSeconds(),
|
||||
GenerateCompleteTime = s.GenerateCompleteTime.DateToStringSeconds(),
|
||||
PrintNumber = s.PrintNumber,
|
||||
IsTwo= s.IsTwo,//add by yzh
|
||||
SupplierOrOrg = string.IsNullOrEmpty(s.SupplierCode) ? _erpBasicDataExtendService.GetSingleOrgName(orgs, s.OrgCode)
|
||||
: _singleDataService.GetSingleData(SingleAction.Suppliers, companyId, s.SupplierCode)//供应商取单点的
|
||||
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
return (list, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
using AutoMapper;
|
||||
using BarCode.Web.Core.Dto.Erp.Org;
|
||||
using BarCode.Web.Core.Dto.Erp.Supplier;
|
||||
using BarCode.Web.Core.Dto.Erp;
|
||||
using BarCode.Web.Core.Dto.SerialNumbers;
|
||||
using BarCode.Web.Domain.Entitys;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.Mappers;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Newtonsoft.Json;
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Core.Dto.Box;
|
||||
using BarCode.Web.Domain.Services.Public;
|
||||
using BarCode.Web.Domain.Values.Single;
|
||||
using System.ComponentModel.Design;
|
||||
using BarCode.Web.Core.Help;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using BarCode.Web.Core.Dto.SecurityNumbers;
|
||||
using NPOI.OpenXmlFormats.Wordprocessing;
|
||||
using BarCode.Web.Core.Dto.Login;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 防伪码生成记录
|
||||
/// </summary>
|
||||
public class SecurityGenerateRecordRepositories : ISecurityGenerateRecordRepositories
|
||||
{
|
||||
private readonly ILoginRepositories _loginRepositories;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IErpService _erpService;
|
||||
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
public SecurityGenerateRecordRepositories(RepositoryDbContext context,
|
||||
ILoginRepositories loginRepositories,
|
||||
IBasicsRepositories basicsRepositories, IMapper mapper, IErpService erpService,
|
||||
IErpBasicDataExtendService erpBasicDataExtendService, ISingleDataService singleDataService)
|
||||
{
|
||||
_context = context;
|
||||
_basicsRepositories = basicsRepositories;
|
||||
_loginRepositories = loginRepositories;
|
||||
_mapper = mapper;
|
||||
_erpService = erpService;
|
||||
_erpBasicDataExtendService = erpBasicDataExtendService;
|
||||
_singleDataService = singleDataService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 新增
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<SecurityNumberGenerateRecord> Add(SecurityNumberGenerateRecord entity, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
await _context.SecurityNumberGenerateRecord.AddAsync(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return entity;
|
||||
}
|
||||
/// <summary>
|
||||
/// 批量添加
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AddRange(List<SecurityNumberGenerateRecord> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
if (entitys != null && entitys.Count != 0)
|
||||
{
|
||||
await _context.SecurityNumberGenerateRecord.AddRangeAsync(entitys);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<SecurityNumberGenerateRecord> Edit(SecurityNumberGenerateRecord entity, bool isTransaction = true)
|
||||
{
|
||||
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
var res = await _context.SecurityNumberGenerateRecord
|
||||
.FirstOrDefaultAsync(f => f.Id == entity.Id);
|
||||
if (res == null) return null;
|
||||
|
||||
_mapper.Map(entity, res);
|
||||
var result = await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
|
||||
return res;
|
||||
}
|
||||
/// <summary>
|
||||
/// 批量修改
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> EditEntityList(List<SecurityNumberGenerateRecord> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
List<int> list = entitys.Select(s => s.Id).ToList();
|
||||
var res = await _context.SecurityNumberGenerateRecord
|
||||
.Where(f => list.Contains(f.Id)).ToListAsync();
|
||||
|
||||
_mapper.ToMapList(entitys, res);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询实体
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<SecurityNumberGenerateRecord?> GetEntity(int id)
|
||||
{
|
||||
return await _context.SecurityNumberGenerateRecord.AsNoTracking()
|
||||
.FirstOrDefaultAsync(f => f.Id == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取集合
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<List<SecurityNumberGenerateRecord>> GetEntityList(List<int> ids)
|
||||
{
|
||||
return await _context.SecurityNumberGenerateRecord.AsNoTracking()
|
||||
.Where(f => ids.Contains(f.Id))
|
||||
.ToListAsync();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取当天生成记录条数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<int> GetGenerateRecordDayCount()
|
||||
{
|
||||
return await _context.SecurityNumberGenerateRecord.AsNoTracking()
|
||||
.Where(f => f.CreateTime >= DateTime.Now.Date).CountAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<(List<SecurityGenerateRecordInfoResponse> list, int total)> GetListAsync(SecurityGenerateRecordQueryRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
int companyId = loginInfo.UserInfo.CompanyId;
|
||||
|
||||
List<string> mNumber = new List<string>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
//物料集合;模糊查询后的物料集合
|
||||
if (!string.IsNullOrEmpty(dto.MaterialNumber))
|
||||
{
|
||||
if (materials != null)
|
||||
mNumber = materials.Where(w => w.MaterialNumber.Contains(dto.MaterialNumber)
|
||||
|| w.MaterialName.Contains(dto.MaterialNumber)
|
||||
|| w.Specifications.Contains(dto.MaterialNumber)
|
||||
).Select(s => s.MaterialNumber).ToList();
|
||||
}
|
||||
List<int> sIds = new List<int>();
|
||||
if (dto.SecurityNumbers != null && dto.SecurityNumbers.Count() > 0)
|
||||
{
|
||||
sIds = await _context.SecurityNumbers.Where(w => dto.SecurityNumbers.Contains(w.SecurityNumber))
|
||||
.GroupBy(g => g.GenerateRecordId).Select(s => s.Key).ToListAsync();
|
||||
}
|
||||
|
||||
////供应商
|
||||
//var supplier_result = await _erpService.BillQueryForSupplier();
|
||||
//List<ErpSupplierDto> suppliers = new List<ErpSupplierDto>();
|
||||
//if (supplier_result.IsSuccess)
|
||||
// suppliers = supplier_result.Data.ToList();
|
||||
////取组织
|
||||
//var org_result = await _erpService.BillQueryForOrg();
|
||||
//List<ErpOrgDto> orgs = new List<ErpOrgDto>();
|
||||
//if (org_result.IsSuccess)
|
||||
// orgs = org_result.Data.ToList();
|
||||
|
||||
var query = _context.SecurityNumberGenerateRecord
|
||||
.OrderByDescending(o => o.Id)
|
||||
.Where(f => 1==1);
|
||||
if (loginInfo.UserInfo.IsAdmin != true && !string.IsNullOrEmpty(dto.OrgCode))
|
||||
{
|
||||
var rec_type = dto.OrgCode.Substring(0, 1);
|
||||
var rec_code = dto.OrgCode.Substring(2, dto.OrgCode.Length - 2);
|
||||
|
||||
if (rec_type.Equals("s"))//供应商
|
||||
query = query.Where(w => rec_code == w.SupplierCode);
|
||||
else//查其他单据(组织)
|
||||
query = query.Where(w => rec_code == w.OrgCode);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dto.MaterialNumber))
|
||||
query = query.Where(w => mNumber.Contains(w.MaterialNumber));
|
||||
if (dto.CreateBeginDate != null)
|
||||
query = query.Where(w => w.GenerateCompleteTime >= dto.CreateBeginDate);
|
||||
if (dto.CreateEndDate != null)
|
||||
{
|
||||
DateTime dt_end = ((DateTime)dto.CreateEndDate).AddDays(1);
|
||||
query = query.Where(w => w.GenerateCompleteTime <= dt_end);
|
||||
}
|
||||
if (mNumber.Count() > 0)
|
||||
query = query.Where(w => mNumber.Contains(w.MaterialNumber));
|
||||
if (dto.GenerateComplete != null)
|
||||
query = query.Where(w => dto.GenerateComplete == w.IsGenerateComplete);
|
||||
if (dto.LotNumbers != null && dto.LotNumbers.Count() > 0)
|
||||
query = query.Where(w => dto.LotNumbers.Contains(w.LotNumber));
|
||||
if (dto.SecurityNumbers != null && dto.SecurityNumbers.Count() > 0)
|
||||
query = query.Where(w => sIds.Contains(w.Id));
|
||||
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query.Select(s => new SecurityGenerateRecordInfoResponse()
|
||||
{
|
||||
Id = s.Id,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.MaterialNumber),
|
||||
MaterialNumber = s.MaterialNumber,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.MaterialNumber),
|
||||
BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.MaterialNumber),
|
||||
LotNumber = s.LotNumber,
|
||||
GenerateComplete = s.IsGenerateComplete == true ? "已完成" : "生成中",
|
||||
Number = s.Number,
|
||||
DownLoadNumber = s.DownLoadNumber,
|
||||
Creator = _singleDataService.GetSingleData(SingleAction.Users, companyId, s.CreatorId),
|
||||
CreateTime = s.CreateTime.DateToStringSeconds(),
|
||||
GenerateCompleteTime = s.GenerateCompleteTime.DateToStringSeconds()
|
||||
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
return (list, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
315
src/BarCode.Web.Repositories/SecurityNumbersRepositories.cs
Normal file
315
src/BarCode.Web.Repositories/SecurityNumbersRepositories.cs
Normal file
@@ -0,0 +1,315 @@
|
||||
using AutoMapper;
|
||||
using BarCode.Web.Core.Dto.Erp;
|
||||
using BarCode.Web.Core.Dto.Erp.Org;
|
||||
using BarCode.Web.Core.Dto.Erp.Supplier;
|
||||
using BarCode.Web.Core.Dto.Login;
|
||||
using BarCode.Web.Core.Dto.SecurityNumbers;
|
||||
using BarCode.Web.Core.Dto.SerialNumbers;
|
||||
using BarCode.Web.Core.Help;
|
||||
using BarCode.Web.Domain.Entitys;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Domain.Mappers;
|
||||
using BarCode.Web.Domain.Services.Public;
|
||||
using BarCode.Web.Domain.Values.Single;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
public class SecurityNumbersRepositories : IAllFielRepositories<SecurityNumbersExportRequest>, IAllFielRepositories<SecurityNumberQueryRequest>, ISecurityNumbersRepositories
|
||||
{
|
||||
|
||||
private readonly ILoginRepositories _loginRepositories;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IErpService _erpService;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
|
||||
|
||||
public SecurityNumbersRepositories(RepositoryDbContext context,
|
||||
ILoginRepositories loginRepositories,
|
||||
IBasicsRepositories basicsRepositories, IMapper mapper, IErpService erpService,
|
||||
ISingleDataService singleDataService, IErpBasicDataExtendService erpBasicDataExtendService)
|
||||
{
|
||||
_context = context;
|
||||
_basicsRepositories = basicsRepositories;
|
||||
_loginRepositories = loginRepositories;
|
||||
_mapper = mapper;
|
||||
_erpService = erpService;
|
||||
_singleDataService = singleDataService;
|
||||
_erpBasicDataExtendService = erpBasicDataExtendService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 批量添加
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<bool> AddRange(List<SecurityNumbers> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
if (entitys != null && entitys.Count != 0)
|
||||
{
|
||||
await _context.SecurityNumbers.AddRangeAsync(entitys);
|
||||
await _context.SaveChangesAsync();
|
||||
foreach (var item in entitys)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item.SecurityNumber))
|
||||
{
|
||||
//自动生成序列码
|
||||
item.GenerateSecurityNumber();
|
||||
//item.GenerateNumberCode();
|
||||
}
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 批量修改
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<bool> EditEntityList(List<SecurityNumbers> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
List<long> list = entitys.Select(s => s.Id).ToList();
|
||||
var res = await _context.SecurityNumbers
|
||||
.Where(f => list.Contains(f.Id)).ToListAsync();
|
||||
|
||||
_mapper.ToMapLongList(entitys, res);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取集合
|
||||
/// </summary>
|
||||
/// <param name="SecurityNumbers"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<List<SecurityNumbers>> GetEntityList(List<string> SecurityNumbers)
|
||||
{
|
||||
return await _context.SecurityNumbers.AsNoTracking()
|
||||
.Where(f => SecurityNumbers.Contains(f.SecurityNumber))
|
||||
.ToListAsync();
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据生成记录Id查询序列号
|
||||
/// </summary>
|
||||
/// <param name="gRIds"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<SecurityNumbers>> GetEntityListByGRIds(List<int> gRIds)
|
||||
{
|
||||
return await _context.SecurityNumbers.AsNoTracking()
|
||||
.Where(f => gRIds.Contains(f.GenerateRecordId))
|
||||
.ToListAsync();
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据生成记录Id查询序列号
|
||||
/// </summary>
|
||||
/// <param name="gRIds"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<SecurityNumbers>> GetEntityListByGRId(int gRId)
|
||||
{
|
||||
return await _context.SecurityNumbers.AsNoTracking()
|
||||
.Where(f => gRId == f.GenerateRecordId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<(List<SecurityNumberInfoResponse> list, int total)> GetListAsync(SecurityNumberQueryRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
int companyId = loginInfo.UserInfo.CompanyId;
|
||||
List<string> mNumber = new List<string>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
var query = _context.SecurityNumbers.AsNoTracking()
|
||||
.GroupJoin(_context.SecurityNumberGenerateRecord, serial => serial.GenerateRecordId, sg => sg.Id, (serial, sg) => new { serial, sg })
|
||||
.SelectMany(x => x.sg.DefaultIfEmpty(), (p, sg) => new { p.serial, sg })
|
||||
.OrderByDescending(o => o.serial.Id)
|
||||
.Where(f => dto.GenerateRecordId == f.serial.GenerateRecordId);
|
||||
if (loginInfo.UserInfo.IsAdmin != true && !string.IsNullOrEmpty(dto.OrgCode))
|
||||
{
|
||||
var rec_type = dto.OrgCode.Substring(0, 1);
|
||||
var rec_code = dto.OrgCode.Substring(2, dto.OrgCode.Length - 2);
|
||||
|
||||
if (rec_type.Equals("s"))//供应商
|
||||
query = query.Where(w => rec_code == w.serial.SupplierCode);
|
||||
else//查其他单据(组织)
|
||||
query = query.Where(w => rec_code == w.serial.OrgCode);
|
||||
}
|
||||
if (dto.IsDownLoad != null)
|
||||
query = query.Where(w => dto.IsDownLoad == true ? w.serial.DownLoadNumber > 0 : w.serial.DownLoadNumber <= 0);
|
||||
if (dto.SecurityNumbers != null && dto.SecurityNumbers.Count() > 0)
|
||||
query = query.Where(w => dto.SecurityNumbers.Contains(w.serial.SecurityNumber));
|
||||
if (dto.IdBegin != null && dto.IdBegin != 0)
|
||||
query = query.Where(w => w.serial.Id >= dto.IdBegin);
|
||||
if (dto.IdEnd != null && dto.IdEnd != 0)
|
||||
query = query.Where(w => w.serial.Id <= dto.IdEnd);
|
||||
if (dto.DownLoadBeginDate != null)
|
||||
query = query.Where(w => w.serial.DownLoadTime >= dto.DownLoadBeginDate);
|
||||
if (dto.DownLoadEndDate != null)
|
||||
{
|
||||
DateTime dt_end = ((DateTime)dto.DownLoadEndDate).AddDays(1);
|
||||
query = query.Where(w => w.serial.DownLoadTime <= dt_end);
|
||||
}
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query.Select(s => new SecurityNumberInfoResponse()
|
||||
{
|
||||
Id = s.serial.Id,
|
||||
GenerateRecordId = s.serial.GenerateRecordId,
|
||||
SecurityNumber = s.serial.SecurityNumber,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.serial.MaterialNumber),
|
||||
Number = s.sg == null ? 0 : s.sg.Number,
|
||||
Creator = _singleDataService.GetSingleData(SingleAction.Users, companyId, s.serial.CreatorId),
|
||||
CreateTime = s.serial.CreateTime.DateToStringSeconds(),
|
||||
DownLoadNumber = s.serial.DownLoadNumber,
|
||||
DownLoadTime = s.serial.DownLoadTime.DateToStringSeconds()
|
||||
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
return (list, total);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出列表
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="companyId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<(object obj, int total)> GetListField(SecurityNumbersExportRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
List<string> mNumber = new List<string>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
//供应商
|
||||
var supplier_result = await _erpService.BillQueryForSupplier();
|
||||
List<ErpSupplierDto> suppliers = new List<ErpSupplierDto>();
|
||||
if (supplier_result.IsSuccess)
|
||||
suppliers = supplier_result.Data.ToList();
|
||||
//取组织
|
||||
var org_result = await _erpService.BillQueryForOrg();
|
||||
List<ErpOrgDto> orgs = new List<ErpOrgDto>();
|
||||
if (org_result.IsSuccess)
|
||||
orgs = org_result.Data.ToList();
|
||||
|
||||
var query = _context.SecurityNumbers.AsNoTracking()
|
||||
.GroupJoin(_context.SecurityNumberGenerateRecord, serial => serial.GenerateRecordId, sg => sg.Id, (serial, sg) => new { serial, sg })
|
||||
.SelectMany(x => x.sg.DefaultIfEmpty(), (p, sg) => new { p.serial, sg })
|
||||
.OrderByDescending(o => o.serial.Id)
|
||||
.Where(f => dto.Ids.Contains(f.serial.GenerateRecordId));
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query.Select(s => new SecurityNumbersExportReponse()
|
||||
{
|
||||
SecurityNumber = s.serial.SecurityNumber,
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.serial.MaterialNumber),
|
||||
Number = s.sg == null ? 0 : s.sg.Number,
|
||||
DownLoadNumber = s.serial.DownLoadNumber,
|
||||
DownLoadTime = s.serial.DownLoadTime.DateToStringSeconds()
|
||||
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
return (list, total);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 条码列表导出
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="loginInfo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<(object obj, int total)> GetListField(SecurityNumberQueryRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
return await GetListAsync(dto, loginInfo);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取防伪码
|
||||
/// </summary>
|
||||
/// <param name="securityNumbers"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<SecurityNumbers> GetEntity(string securityNumbers)
|
||||
{
|
||||
var entity = await _context.SecurityNumbers.AsNoTracking()
|
||||
.FirstOrDefaultAsync(f => f.SecurityNumber.Equals(securityNumbers));
|
||||
return entity;
|
||||
}
|
||||
/// <summary>
|
||||
/// 修改防伪码
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<SecurityNumbers> Edit(SecurityNumbers entity, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
var res = await _context.SecurityNumbers
|
||||
.FirstOrDefaultAsync(f => f.Id == entity.Id);
|
||||
if (res == null) return null;
|
||||
|
||||
_mapper.Map(entity, res);
|
||||
var result = await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public async Task<bool> DownLoad(List<int> ids, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
string dt = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
|
||||
foreach (var id in ids)
|
||||
{
|
||||
FormattableString fs = @$"update t_barcode_securitynumbers set DownLoadNumber=DownLoadNumber+1,DownLoadTime={dt} where GenerateRecordId = {id};";
|
||||
var result = _context.Database.ExecuteSqlInterpolated(fs);
|
||||
}
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
723
src/BarCode.Web.Repositories/SerialNumbersRepositories.cs
Normal file
723
src/BarCode.Web.Repositories/SerialNumbersRepositories.cs
Normal file
@@ -0,0 +1,723 @@
|
||||
using AutoMapper;
|
||||
using BarCode.Web.Core.Dto.Erp;
|
||||
using BarCode.Web.Core.Dto.Erp.Org;
|
||||
using BarCode.Web.Core.Dto.Erp.Supplier;
|
||||
using BarCode.Web.Core.Dto.Login;
|
||||
using BarCode.Web.Core.Dto.SerialNumbers;
|
||||
using BarCode.Web.Core.Help;
|
||||
using BarCode.Web.Domain.Entitys;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Domain.IService.Public;
|
||||
using BarCode.Web.Domain.Mappers;
|
||||
using BarCode.Web.Domain.Services.Public;
|
||||
using BarCode.Web.Domain.Values.Single;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Npoi.Mapper;
|
||||
using NPOI.POIFS.FileSystem;
|
||||
using Quartz.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 序列码
|
||||
/// </summary>
|
||||
public class SerialNumbersRepositories : IAllFielRepositories<SerialNumbersExportRequest>, IAllFielRepositories<SerialNumberQueryRequest>, ISerialNumbersRepositories
|
||||
{
|
||||
private readonly ILoginRepositories _loginRepositories;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IErpService _erpService;
|
||||
private readonly ISingleDataService _singleDataService;
|
||||
private readonly IErpBasicDataExtendService _erpBasicDataExtendService;
|
||||
|
||||
public SerialNumbersRepositories(RepositoryDbContext context,
|
||||
ILoginRepositories loginRepositories,
|
||||
IBasicsRepositories basicsRepositories, IMapper mapper, IErpService erpService,
|
||||
ISingleDataService singleDataService, IErpBasicDataExtendService erpBasicDataExtendService)
|
||||
{
|
||||
_context = context;
|
||||
_basicsRepositories = basicsRepositories;
|
||||
_loginRepositories = loginRepositories;
|
||||
_mapper = mapper;
|
||||
_erpService = erpService;
|
||||
_singleDataService = singleDataService;
|
||||
_erpBasicDataExtendService = erpBasicDataExtendService;
|
||||
}
|
||||
/// <summary>
|
||||
/// 批量添加
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<bool> AddRange(List<SerialNumbers> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
if (entitys != null && entitys.Count != 0)
|
||||
{
|
||||
await _context.SerialNumbers.AddRangeAsync(entitys);
|
||||
await _context.SaveChangesAsync();
|
||||
string newSuitNumber = "";
|
||||
string oldSuitNumber = "";
|
||||
foreach (var item in entitys)
|
||||
{
|
||||
//自动生成序列码
|
||||
string sn= item.GenerateSerialNumber();//alter by yzh
|
||||
item.GenerateNumberCode();
|
||||
|
||||
|
||||
if(item.IsTwo>1)//大于1说明是套装
|
||||
{
|
||||
if (item.thisNumber % item.IsTwo == 0)
|
||||
{
|
||||
newSuitNumber = oldSuitNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
oldSuitNumber = sn;
|
||||
newSuitNumber = sn;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newSuitNumber = sn;
|
||||
newSuitNumber = sn;
|
||||
}
|
||||
item.GenerateSuitNumber(newSuitNumber);
|
||||
item.GenerateTwoSerialNumber(newSuitNumber);
|
||||
}
|
||||
foreach (var item in entitys)
|
||||
{
|
||||
|
||||
string s = GetTwoSerialNumber(entitys, item.SuitNumber);
|
||||
item.GenerateTwoSerialNumber(s);
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
||||
}
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 产生套装条码
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="SuitNumber"></param>
|
||||
public string GetTwoSerialNumber(List<SerialNumbers> entitys, string SuitNumber)
|
||||
{
|
||||
string strReturn = "";
|
||||
foreach (var item in entitys)
|
||||
{
|
||||
|
||||
if (item.SuitNumber == SuitNumber)
|
||||
{
|
||||
if (strReturn == "")
|
||||
{
|
||||
strReturn = item.SerialNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
strReturn = strReturn + "," + item.SerialNumber;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return strReturn;
|
||||
}
|
||||
/// <summary>
|
||||
/// 批量修改
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<bool> EditEntityList(List<SerialNumbers> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
|
||||
List<long> list = entitys.Select(s => s.Id).ToList();
|
||||
var res = await _context.SerialNumbers
|
||||
.Where(f => list.Contains(f.Id)).ToListAsync();
|
||||
|
||||
_mapper.ToMapLongList(entitys, res);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取集合
|
||||
/// </summary>
|
||||
/// <param name="serialNumbers"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<List<SerialNumbers>> GetEntityList(List<string> serialNumbers)
|
||||
{
|
||||
return await _context.SerialNumbers.AsNoTracking()
|
||||
.Where(f => serialNumbers.Contains(f.SerialNumber))
|
||||
.ToListAsync();
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据生成记录Id查询序列号
|
||||
/// </summary>
|
||||
/// <param name="gRIds"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<SerialNumbers>> GetEntityListByGRIds(List<int> gRIds)
|
||||
{
|
||||
return await _context.SerialNumbers.AsNoTracking()
|
||||
.Where(f => gRIds.Contains(f.GenerateRecordId))
|
||||
.ToListAsync();
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据生成记录Id查询序列号
|
||||
/// </summary>
|
||||
/// <param name="gRIds"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<SerialNumbers>> GetEntityListByGRId(int gRId)
|
||||
{
|
||||
return await _context.SerialNumbers.AsNoTracking()
|
||||
.Where(f => gRId == f.GenerateRecordId)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<(List<SerialNumberInfoResponse> list, int total)> GetListAsync(SerialNumberQueryRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
int companyId = loginInfo.UserInfo.CompanyId;
|
||||
List<string> mNumber = new List<string>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
var query = _context.SerialNumbers.AsNoTracking()
|
||||
.GroupJoin(_context.Box, serial => serial.BoxId, box => box.Id, (serial, box) => new { serial, box })
|
||||
.SelectMany(x => x.box.DefaultIfEmpty(), (p, box) => new { p.serial, box })
|
||||
.GroupJoin(_context.SerialNumberGenerateRecord, s => s.serial.GenerateRecordId, sg => sg.Id, (serial, sg) => new { serial.serial, serial.box, sg })
|
||||
.SelectMany(x => x.sg.DefaultIfEmpty(), (p, sg) => new { p.serial, p.box, sg })
|
||||
.OrderByDescending(o => o.serial.Id)
|
||||
.Where(f => dto.GenerateRecordId == f.serial.GenerateRecordId);
|
||||
if (loginInfo.UserInfo.IsAdmin != true && !string.IsNullOrEmpty(dto.OrgCode))
|
||||
{
|
||||
var rec_type = dto.OrgCode.Substring(0, 1);
|
||||
var rec_code = dto.OrgCode.Substring(2, dto.OrgCode.Length - 2);
|
||||
|
||||
if (rec_type.Equals("s"))//供应商
|
||||
query = query.Where(w => rec_code == w.serial.SupplierCode);
|
||||
else//查其他单据(组织)
|
||||
query = query.Where(w => rec_code == w.serial.OrgCode);
|
||||
}
|
||||
if (dto.IsPrint != null)
|
||||
query = query.Where(w => dto.IsPrint == true ? w.serial.PrintNumber > 0 : w.serial.PrintNumber <= 0);
|
||||
if (dto.IsUse != null)
|
||||
query = query.Where(w => w.serial.IsUse == dto.IsUse);
|
||||
if (dto.SerialNumbers != null && dto.SerialNumbers.Count() > 0)
|
||||
query = query.Where(w => dto.SerialNumbers.Contains(w.serial.SerialNumber));
|
||||
if (dto.NumberCodes != null && dto.NumberCodes.Count() > 0)
|
||||
query = query.Where(w => dto.NumberCodes.Contains(w.serial.NumberCode));
|
||||
if (!string.IsNullOrEmpty(dto.BoxBillNo))
|
||||
query = query.Where(w => w.box.BoxBillNo.Equals(dto.BoxBillNo));
|
||||
if (dto.SerialNumberBegin != null && dto.SerialNumberBegin != 0)
|
||||
{
|
||||
if (dto.SerialNumberEnd != null && dto.SerialNumberEnd != 0)
|
||||
query = query.Where(w => w.serial.Id >= dto.SerialNumberBegin);
|
||||
else
|
||||
query = query.Where(w => w.serial.Id == dto.SerialNumberBegin);
|
||||
}
|
||||
if (dto.SerialNumberEnd != null && dto.SerialNumberEnd != 0)
|
||||
{
|
||||
if (dto.SerialNumberBegin != null && dto.SerialNumberBegin != 0)
|
||||
query = query.Where(w => w.serial.Id <= dto.SerialNumberEnd);
|
||||
else
|
||||
query = query.Where(w => w.serial.Id == dto.SerialNumberEnd);
|
||||
}
|
||||
//V01.05.00: 数字序列号区间查询
|
||||
if (!string.IsNullOrEmpty(dto.NumberCodeBegin))
|
||||
{
|
||||
int number = Convert.ToInt32(dto.NumberCodeBegin.Substring(6, dto.NumberCodeBegin.Length - 6));
|
||||
if (!string.IsNullOrEmpty(dto.NumberCodeEnd))
|
||||
query = query.Where(w => w.serial.Number >= number);
|
||||
else
|
||||
query = query.Where(w => w.serial.Number == number);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(dto.NumberCodeEnd))
|
||||
{
|
||||
int number = Convert.ToInt32(dto.NumberCodeEnd.Substring(6, dto.NumberCodeEnd.Length - 6));
|
||||
if (!string.IsNullOrEmpty(dto.NumberCodeBegin))
|
||||
query = query.Where(w => w.serial.Number <= number);
|
||||
else
|
||||
query = query.Where(w => w.serial.Number == number);
|
||||
}
|
||||
|
||||
|
||||
if (dto.DownLoadBeginDate != null)
|
||||
query = query.Where(w => w.serial.DownLoadTime >= dto.DownLoadBeginDate);
|
||||
if (dto.DownLoadEndDate != null)
|
||||
{
|
||||
DateTime dt_end = ((DateTime)dto.DownLoadEndDate).AddDays(1);
|
||||
query = query.Where(w => w.serial.DownLoadTime <= dt_end);
|
||||
}
|
||||
if (dto.PrintBeginDate != null)
|
||||
query = query.Where(w => w.serial.PrintTime >= dto.PrintBeginDate);
|
||||
if (dto.PrintEndDate != null)
|
||||
{
|
||||
DateTime dt_end = ((DateTime)dto.PrintEndDate).AddDays(1);
|
||||
query = query.Where(w => w.serial.PrintTime <= dt_end);
|
||||
}
|
||||
if (dto.IsUpdateMaterial != null)
|
||||
{
|
||||
if (dto.IsUpdateMaterial == true)
|
||||
query = query.Where(w => !string.IsNullOrEmpty(w.serial.Old_MaterialNumber));
|
||||
else
|
||||
query = query.Where(w => string.IsNullOrEmpty(w.serial.Old_MaterialNumber));
|
||||
}
|
||||
|
||||
|
||||
if(dto.isTwo>1)//是否为两件装,如果大于1说明为两件装
|
||||
{
|
||||
query = query.Where(w => w.serial.IsTwo>1);
|
||||
}
|
||||
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query.Select(s => new SerialNumberInfoResponse()
|
||||
{
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.serial.MaterialNumber),
|
||||
Old_Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.serial.Old_MaterialNumber == null ? "" : s.serial.Old_MaterialNumber),
|
||||
MaterialNumber = s.serial.MaterialNumber,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.serial.MaterialNumber),
|
||||
BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.serial.MaterialNumber),
|
||||
SerialNumber = s.serial.SerialNumber,
|
||||
NumberCode = s.serial.NumberCode,
|
||||
Number = s.sg == null ? 0 : s.sg.Number,
|
||||
Id = s.serial.Id,
|
||||
IsUse = s.serial.IsUse,
|
||||
IsUseStr = s.serial.IsUse == true ? "是" : "否",
|
||||
//序列码已经被使用 但没有箱号,那么就是被wms系统拉去使用了,不能再被打印
|
||||
IsEnablePrint = (s.serial.BoxId <= 0 && s.serial.IsUse == true) ? false : true,
|
||||
Box = s.box == null ? "" : s.box.BoxBillNo,
|
||||
Creator = _singleDataService.GetSingleData(SingleAction.Users, companyId, s.serial.CreatorId),
|
||||
CreateTime = s.serial.CreateTime.DateToStringSeconds(),
|
||||
PrintNumber = s.serial.PrintNumber,
|
||||
DownLoadNumber = s.serial.DownLoadNumber,
|
||||
DownLoadTime = s.serial.DownLoadTime.DateToStringSeconds(),
|
||||
PrintTime = s.serial.PrintTime.DateToStringSeconds(),
|
||||
IsTwo=s.serial.IsTwo,
|
||||
TwoSerialNumber = s.serial.TwoSerialNumber.Replace(s.serial.SerialNumber,"").Replace(",","")
|
||||
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
return (list, total);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出列表
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="loginInfo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<(object obj, int total)> GetListField(SerialNumbersExportRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
List<string> mNumber = new List<string>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
//供应商
|
||||
var supplier_result = await _erpService.BillQueryForSupplier();
|
||||
List<ErpSupplierDto> suppliers = new List<ErpSupplierDto>();
|
||||
if (supplier_result.IsSuccess)
|
||||
suppliers = supplier_result.Data.ToList();
|
||||
//取组织
|
||||
var org_result = await _erpService.BillQueryForOrg();
|
||||
List<ErpOrgDto> orgs = new List<ErpOrgDto>();
|
||||
if (org_result.IsSuccess)
|
||||
orgs = org_result.Data.ToList();
|
||||
|
||||
var query = _context.SerialNumbers.AsNoTracking()
|
||||
.GroupJoin(_context.SerialNumberGenerateRecord, serial => serial.GenerateRecordId, sg => sg.Id, (serial, sg) => new { serial, sg })
|
||||
.SelectMany(x => x.sg.DefaultIfEmpty(), (p, sg) => new { p.serial, sg })
|
||||
.OrderByDescending(o => o.serial.Id)
|
||||
.Where(f => dto.Ids.Contains(f.serial.GenerateRecordId));
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query.Select(s => new SerialNumbersExportReponse()
|
||||
{
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.serial.MaterialNumber),
|
||||
MaterialNumber = s.serial.MaterialNumber,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.serial.MaterialNumber),
|
||||
BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.serial.MaterialNumber),
|
||||
SerialNumber = s.serial.SerialNumber,
|
||||
NumberCode = s.serial.NumberCode,
|
||||
Number = s.sg == null ? 0 : s.sg.Number,
|
||||
SupplierOrOrg = string.IsNullOrEmpty(s.sg.SupplierCode) ? _erpBasicDataExtendService.GetOrgName(orgs, s.sg.OrgCode)
|
||||
: _erpBasicDataExtendService.GetSupplierName(suppliers, s.sg.SupplierCode)
|
||||
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
return (list, total);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据箱Id来搜索序列号
|
||||
/// </summary>
|
||||
/// <param name="boxId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<(List<SerialNumbersResponse> list, int total)> GetEntityListByBoxId(SerialNumberByBoxIdQueryRequest dto)
|
||||
{
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
var query = _context.SerialNumbers.AsNoTracking()
|
||||
.OrderByDescending(o => o.CompleteCartonTime)//以装箱时间先后排序
|
||||
.Where(f => f.BoxId == dto.BoxId);
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query.Select(s => new SerialNumbersResponse()
|
||||
{
|
||||
BoxId = s.BoxId,
|
||||
IsCarton = (s.BoxId > 0 || s.IsUse == true) ? true : false,
|
||||
IsOldData = true,//扫箱号获取 默认就是老数据
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.MaterialNumber),
|
||||
MaterialNumber = s.MaterialNumber,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.MaterialNumber),
|
||||
BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.MaterialNumber),
|
||||
SerialNumber = s.SerialNumber,
|
||||
IsUseNumber = s.IsUseNumber,
|
||||
NumberCode = s.NumberCode,
|
||||
TwoSerialNumber=s.TwoSerialNumber.Replace(s.SerialNumber,"").Replace(",","")
|
||||
}).Skip((dto.PageNo - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync();
|
||||
return (list, total);
|
||||
}
|
||||
|
||||
public async Task<List<SerialNumbersResponse>?> GetEntityList(string serialNumber, string orgCode, LoginInDto loginInfo)
|
||||
{
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
var query = _context.SerialNumbers.AsNoTracking().Where(w => 1 == 1);
|
||||
|
||||
//if (loginInfo.UserInfo.IsAdmin != true && !string.IsNullOrEmpty(orgCode))
|
||||
//{
|
||||
// var rec_type = orgCode.Substring(0, 1);
|
||||
// var rec_code = orgCode.Substring(2, orgCode.Length - 2);
|
||||
|
||||
// if (rec_type.Equals("s"))//供应商
|
||||
// query = query.Where(w => rec_code == w.SupplierCode);
|
||||
// else//查其他单据(组织)
|
||||
// query = query.Where(w => rec_code == w.OrgCode);
|
||||
//}
|
||||
|
||||
|
||||
query = query.Where(f => f.SerialNumber.Equals(serialNumber)
|
||||
|| f.NumberCode.Equals(serialNumber));
|
||||
|
||||
var entity = await query.FirstOrDefaultAsync();
|
||||
if (entity == null) return null;
|
||||
|
||||
////如果为单套产品,那就直接取就行了。
|
||||
if (entity.IsTwo < 2)
|
||||
{
|
||||
List<SerialNumbersResponse> list = new List<SerialNumbersResponse>();
|
||||
SerialNumbersResponse s=new SerialNumbersResponse();
|
||||
s.BoxId = entity.BoxId;
|
||||
s.IsCarton = (entity.BoxId > 0 || entity.IsUse == true) ? true : false;
|
||||
s.IsOldData = false;//根据序列号获取 默认是false
|
||||
s.Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, entity.MaterialNumber);
|
||||
s.MaterialNumber = entity.MaterialNumber;
|
||||
s.MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, entity.MaterialNumber);
|
||||
s.BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, entity.MaterialNumber);
|
||||
s.SerialNumber = entity.SerialNumber;
|
||||
s.IsUseNumber = entity.IsUseNumber;
|
||||
s.NumberCode = entity.NumberCode;
|
||||
s.IsTwo = entity.IsTwo;
|
||||
s.SuitNumber = entity.SuitNumber;
|
||||
list.Add(s);
|
||||
return list;
|
||||
|
||||
//return new SerialNumbersResponse()
|
||||
//{
|
||||
// BoxId = entity.BoxId,
|
||||
// IsCarton = (entity.BoxId > 0 || entity.IsUse == true) ? true : false,
|
||||
// IsOldData = false,//根据序列号获取 默认是false
|
||||
// Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, entity.MaterialNumber),
|
||||
// MaterialNumber = entity.MaterialNumber,
|
||||
// MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, entity.MaterialNumber),
|
||||
// BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, entity.MaterialNumber),
|
||||
// SerialNumber = entity.SerialNumber,
|
||||
// IsUseNumber = entity.IsUseNumber,
|
||||
// NumberCode = entity.NumberCode,
|
||||
// IsTwo = entity.IsTwo,
|
||||
// SuitNumber = entity.SuitNumber
|
||||
//};
|
||||
}
|
||||
else//跟据套装去查对应的
|
||||
{
|
||||
string suitNumber = entity.SuitNumber;
|
||||
|
||||
|
||||
|
||||
var query2 = _context.SerialNumbers.AsNoTracking()
|
||||
//.OrderByDescending(o => o.CompleteCartonTime)//以装箱时间先后排序
|
||||
.Where(f => f.SuitNumber == suitNumber);
|
||||
|
||||
int total = await query.CountAsync();
|
||||
var list = await query2.Select(s => new SerialNumbersResponse()
|
||||
{
|
||||
BoxId = s.BoxId,
|
||||
IsCarton = (s.BoxId > 0 || s.IsUse == true) ? true : false,
|
||||
IsOldData = false,//扫箱号获取 默认就是老数据
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.MaterialNumber),
|
||||
MaterialNumber = s.MaterialNumber,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.MaterialNumber),
|
||||
BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.MaterialNumber),
|
||||
SerialNumber = s.SerialNumber,
|
||||
IsUseNumber = s.IsUseNumber,
|
||||
NumberCode = s.NumberCode,
|
||||
IsTwo = s.IsTwo,
|
||||
SuitNumber = s.SuitNumber
|
||||
}).ToListAsync();
|
||||
|
||||
|
||||
return list;
|
||||
|
||||
|
||||
// //var query2 = _context.SerialNumbers.AsNoTracking().Where(w => 1 == 1);
|
||||
// //query2 = query2.Where(f => f.SuitNumber.Equals(suitNumber)
|
||||
// //);
|
||||
// //var entity2 = await query2.FirstOrDefaultAsync();
|
||||
// //if (entity2 == null) return null;
|
||||
|
||||
// //return new SerialNumbersResponse()
|
||||
// //{
|
||||
// // BoxId = entity2.BoxId,
|
||||
// // IsCarton = (entity2.BoxId > 0 || entity2.IsUse == true) ? true : false,
|
||||
// // IsOldData = false,//根据序列号获取 默认是false
|
||||
// // Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, entity2.MaterialNumber),
|
||||
// // MaterialNumber = entity2.MaterialNumber,
|
||||
// // MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, entity2.MaterialNumber),
|
||||
// // BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, entity2.MaterialNumber),
|
||||
// // SerialNumber = entity2.SerialNumber,
|
||||
// // IsUseNumber = entity2.IsUseNumber,
|
||||
// // NumberCode = entity2.NumberCode,
|
||||
// // IsTwo = entity2.IsTwo,
|
||||
// // SuitNumber = entity2.SuitNumber
|
||||
// //};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<SerialNumbersResponse?> GetEntity(string serialNumber, string orgCode, LoginInDto loginInfo)
|
||||
{
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
var query = _context.SerialNumbers.AsNoTracking().Where(w => 1 == 1);
|
||||
|
||||
//if (loginInfo.UserInfo.IsAdmin != true && !string.IsNullOrEmpty(orgCode))
|
||||
//{
|
||||
// var rec_type = orgCode.Substring(0, 1);
|
||||
// var rec_code = orgCode.Substring(2, orgCode.Length - 2);
|
||||
|
||||
// if (rec_type.Equals("s"))//供应商
|
||||
// query = query.Where(w => rec_code == w.SupplierCode);
|
||||
// else//查其他单据(组织)
|
||||
// query = query.Where(w => rec_code == w.OrgCode);
|
||||
//}
|
||||
|
||||
|
||||
query = query.Where(f => f.SerialNumber.Equals(serialNumber)
|
||||
|| f.NumberCode.Equals(serialNumber));
|
||||
|
||||
var entity = await query.FirstOrDefaultAsync();
|
||||
if (entity == null) return null;
|
||||
|
||||
////如果为单套产品,那就直接取就行了。
|
||||
//if (entity.IsTwo < 2)
|
||||
//{
|
||||
return new SerialNumbersResponse()
|
||||
{
|
||||
BoxId = entity.BoxId,
|
||||
IsCarton = (entity.BoxId > 0 || entity.IsUse == true) ? true : false,
|
||||
IsOldData = false,//根据序列号获取 默认是false
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, entity.MaterialNumber),
|
||||
MaterialNumber = entity.MaterialNumber,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, entity.MaterialNumber),
|
||||
BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, entity.MaterialNumber),
|
||||
SerialNumber = entity.SerialNumber,
|
||||
IsUseNumber = entity.IsUseNumber,
|
||||
NumberCode = entity.NumberCode,
|
||||
IsTwo = entity.IsTwo,
|
||||
SuitNumber = entity.SuitNumber,
|
||||
TwoSerialNumber= entity.TwoSerialNumber.Replace(entity.SerialNumber,"").Replace(",","")
|
||||
};
|
||||
//}
|
||||
// else//跟据套装去查对应的
|
||||
// {
|
||||
// string suitNumber=entity.SuitNumber;
|
||||
|
||||
|
||||
|
||||
// var query2 = _context.SerialNumbers.AsNoTracking()
|
||||
// //.OrderByDescending(o => o.CompleteCartonTime)//以装箱时间先后排序
|
||||
//.Where(f => f.SuitNumber == suitNumber);
|
||||
|
||||
// int total = await query.CountAsync();
|
||||
// var list = await query2.Select(s => new SerialNumbersResponse()
|
||||
// {
|
||||
// BoxId = s.BoxId,
|
||||
// IsCarton = (s.BoxId > 0 || s.IsUse == true) ? true : false,
|
||||
// IsOldData = false,//扫箱号获取 默认就是老数据
|
||||
// Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.MaterialNumber),
|
||||
// MaterialNumber = s.MaterialNumber,
|
||||
// MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.MaterialNumber),
|
||||
// BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, s.MaterialNumber),
|
||||
// SerialNumber = s.SerialNumber,
|
||||
// IsUseNumber = s.IsUseNumber,
|
||||
// NumberCode = s.NumberCode
|
||||
// }).ToListAsync();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// //var query2 = _context.SerialNumbers.AsNoTracking().Where(w => 1 == 1);
|
||||
// //query2 = query2.Where(f => f.SuitNumber.Equals(suitNumber)
|
||||
// //);
|
||||
// //var entity2 = await query2.FirstOrDefaultAsync();
|
||||
// //if (entity2 == null) return null;
|
||||
|
||||
// //return new SerialNumbersResponse()
|
||||
// //{
|
||||
// // BoxId = entity2.BoxId,
|
||||
// // IsCarton = (entity2.BoxId > 0 || entity2.IsUse == true) ? true : false,
|
||||
// // IsOldData = false,//根据序列号获取 默认是false
|
||||
// // Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, entity2.MaterialNumber),
|
||||
// // MaterialNumber = entity2.MaterialNumber,
|
||||
// // MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, entity2.MaterialNumber),
|
||||
// // BarCode = _erpBasicDataExtendService.GetMaterialBarCode(materials, entity2.MaterialNumber),
|
||||
// // SerialNumber = entity2.SerialNumber,
|
||||
// // IsUseNumber = entity2.IsUseNumber,
|
||||
// // NumberCode = entity2.NumberCode,
|
||||
// // IsTwo = entity2.IsTwo,
|
||||
// // SuitNumber = entity2.SuitNumber
|
||||
// //};
|
||||
|
||||
|
||||
// }
|
||||
}
|
||||
/// <summary>
|
||||
/// 条码列表导出
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="loginInfo"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<(object obj, int total)> GetListField(SerialNumberQueryRequest dto, LoginInDto loginInfo)
|
||||
{
|
||||
return await GetListAsync(dto, loginInfo);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据箱Id获取序列码
|
||||
/// </summary>
|
||||
/// <param name="boxIds"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<SerialNumbers>> GetEntityListByBoxIds(List<int> boxIds)
|
||||
{
|
||||
return await _context.SerialNumbers.AsNoTracking()
|
||||
.Where(f => boxIds.Contains(f.BoxId))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据套装码获取序列码
|
||||
/// </summary>
|
||||
/// <param name="boxIds"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<SerialNumbers>> GetEntityListBySuitNumber(string suitNumber)
|
||||
{
|
||||
return await _context.SerialNumbers.AsNoTracking()
|
||||
.Where(f => f.TwoSerialNumber.Contains(suitNumber))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// wms系统查询序列码 支持数字序列码
|
||||
/// </summary>
|
||||
/// <param name="serialNumbers"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<SerialNumbers> GetEntityWms(string serialNumbers)
|
||||
{
|
||||
var entity = await _context.SerialNumbers.AsNoTracking()
|
||||
.FirstOrDefaultAsync(f => serialNumbers.Equals(f.SerialNumber) || serialNumbers.Equals(f.NumberCode));
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<List<SerialNumbers>> GetEntityListContainNumber(List<string> serialNumbers)
|
||||
{
|
||||
return await _context.SerialNumbers.AsNoTracking()
|
||||
// .Where(f => serialNumbers.Contains(f.SerialNumber) || serialNumbers.Contains(f.NumberCode) || serialNumbers.Contains(f.TwoSerialNumber))//alter by yzh
|
||||
.Where(f => serialNumbers.Contains(f.SerialNumber) || serialNumbers.Contains(f.NumberCode))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<SerialNumbersExternalResponse> GetExternal(string serialNumber)
|
||||
{
|
||||
List<string> mNumber = new List<string>();
|
||||
var materials_result = await _erpService.BillQueryForMaterial();
|
||||
List<ErpMaterialDto> materials = new List<ErpMaterialDto>();
|
||||
if (materials_result.IsSuccess)
|
||||
materials = materials_result.Data.ToList();
|
||||
|
||||
var query = _context.SerialNumbers.AsNoTracking()
|
||||
.GroupJoin(_context.SerialNumberGenerateRecord, serial => serial.GenerateRecordId, sg => sg.Id, (serial, sg) => new { serial, sg })
|
||||
.SelectMany(x => x.sg.DefaultIfEmpty(), (p, sg) => new { p.serial, sg })
|
||||
.OrderByDescending(o => o.serial.Id)
|
||||
.Where(f => serialNumber.Equals(f.serial.SerialNumber) || serialNumber.Equals(f.serial.NumberCode));
|
||||
|
||||
var res = await query.Select(s => new SerialNumbersExternalResponse()
|
||||
{
|
||||
Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, s.serial.MaterialNumber),
|
||||
MaterialNumber = s.serial.MaterialNumber,
|
||||
MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, s.serial.MaterialNumber),
|
||||
CreateTime = s.serial.CreateTime.DateToStringSeconds(),
|
||||
PurchaseBillNo = s.sg.PurchaseBillNo,
|
||||
SerialNumber = serialNumber,
|
||||
Supplier = _singleDataService.GetSingleData(SingleAction.Suppliers, s.sg.CompanyId, s.serial.SupplierCode)
|
||||
}).FirstOrDefaultAsync();
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
47
src/BarCode.Web.Repositories/TransactionRepositories.cs
Normal file
47
src/BarCode.Web.Repositories/TransactionRepositories.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using BarCode.Web.Domain.Infrastructure;
|
||||
using BarCode.Web.Repositories.Configuration;
|
||||
|
||||
namespace BarCode.Web.Repositories
|
||||
{
|
||||
public class TransactionRepositories: ITransactionRepositories
|
||||
{
|
||||
private RepositoryDbContext _context;
|
||||
|
||||
|
||||
public TransactionRepositories(RepositoryDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
public IDbContextTransaction GetTransaction()
|
||||
{
|
||||
return _context.Database.BeginTransaction();
|
||||
}
|
||||
|
||||
public bool CommitTransaction(bool isRollback, IDbContextTransaction transaction)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (transaction == null)
|
||||
return true;
|
||||
|
||||
if (isRollback)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user