516 lines
21 KiB
C#
516 lines
21 KiB
C#
|
|
using ERP;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.ServiceModel;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using WMS.Web.Core.Dto;
|
|
using WMS.Web.Core.Dto.Erp.Customer;
|
|
using WMS.Web.Core.Internal.Results;
|
|
using WMS.Web.Domain.Entitys;
|
|
using WMS.Web.Domain.Infrastructure;
|
|
using WMS.Web.Domain.IService;
|
|
using WMS.Web.Domain.IService.Public;
|
|
using Microsoft.Extensions.Hosting;
|
|
using WMS.Web.Domain.Options;
|
|
using Microsoft.Extensions.Options;
|
|
using WMS.Web.Domain.Values;
|
|
using WMS.Web.Core.Dto.Erp;
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
using System.Reflection;
|
|
using WMS.Web.Domain.Services;
|
|
using SkiaSharp;
|
|
using Google.Protobuf.Collections;
|
|
using NPOI.SS.Formula.Functions;
|
|
using System.Text.Json;
|
|
using WMS.Web.Core.Dto.LingXing;
|
|
using WMS.Web.Domain.Services.Public;
|
|
|
|
namespace WMS.Web.Api.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class TestController : ControllerBase
|
|
{
|
|
private readonly IErpService _erpService;
|
|
private IInStockTaskService _inStockTaskService;
|
|
private readonly IBasicsRepositories _basicsRepositories;
|
|
private IBasicsRepositories _transactionRepositories;
|
|
private readonly IOpsService _opsService;
|
|
private readonly IBoxService _boxService;
|
|
private readonly IOutStockTaskRepositories _outStockTaskRepositories;
|
|
private readonly IOutStockRepositories _outStockRepositories;
|
|
private readonly IOutStockTaskService _outStockTaskService;
|
|
private readonly IBoxInventoryRepositories _boxInventoryRepositories;
|
|
private readonly ITakeStockService _takeStockService;
|
|
private readonly ITakeStockRepositories _takeStockRepositories;
|
|
private readonly IInStockTaskRepositories _inStockTaskRepositories;
|
|
private readonly IOutStockService _outStockService;
|
|
private readonly IWebHostEnvironment _env;
|
|
private readonly ILoginService _loginService;
|
|
private readonly AppOptions _options;
|
|
private readonly ISendMessageService _sendMessageService;
|
|
private readonly IMaterialService _materialService;
|
|
private readonly IMemoryCache _memoryCache;
|
|
private readonly IRedisConcurrentProcessService _redisConcurrentProcessService;
|
|
private IInStockService _inStockService;
|
|
private readonly ILingXingService _lingXingService;
|
|
private readonly IProductInventoryService _productInventoryService;
|
|
private readonly IJuShuiTanService _juShuiTanService;
|
|
private readonly IErpInventoryService _erpInventoryService;
|
|
public TestController(IErpService erpService, IInStockTaskService inStockTaskService, IBoxInventoryRepositories boxInventoryRepositories, IRedisConcurrentProcessService redisConcurrentProcessService,
|
|
IBasicsRepositories transactionRepositories, IOpsService opsService, IBoxService boxService, IBasicsRepositories basicsRepositories, IMemoryCache memoryCache,
|
|
IOutStockTaskRepositories outStockTaskRepositories, IOutStockTaskService outStockTaskService, IOptions<AppOptions> options, ILoginService loginService, ISendMessageService sendMessageService,
|
|
ITakeStockService takeStockService, ITakeStockRepositories takeStockRepositories, IOutStockService outStockService, IInStockTaskRepositories inStockTaskRepositories,
|
|
IWebHostEnvironment env, IMaterialService materialService, IOutStockRepositories outStockRepositories, IInStockService inStockService, ILingXingService lingXingService
|
|
, IProductInventoryService productInventoryService, IJuShuiTanService juShuiTanService, IErpInventoryService erpInventoryService)
|
|
{
|
|
_inStockService = inStockService;
|
|
_redisConcurrentProcessService = redisConcurrentProcessService;
|
|
_memoryCache = memoryCache;
|
|
_materialService = materialService;
|
|
_loginService = loginService;
|
|
_sendMessageService = sendMessageService;
|
|
_inStockTaskRepositories = inStockTaskRepositories;
|
|
_basicsRepositories = basicsRepositories;
|
|
_options = options?.Value;
|
|
_boxInventoryRepositories = boxInventoryRepositories;
|
|
this._erpService = erpService;
|
|
this._inStockTaskService = inStockTaskService;
|
|
this._transactionRepositories = transactionRepositories;
|
|
_opsService = opsService;
|
|
_boxService = boxService;
|
|
_outStockTaskRepositories = outStockTaskRepositories;
|
|
_outStockTaskService = outStockTaskService;
|
|
_takeStockService = takeStockService;
|
|
_takeStockRepositories = takeStockRepositories;
|
|
_outStockService = outStockService;
|
|
_outStockRepositories = outStockRepositories;
|
|
_env = env;
|
|
_lingXingService = lingXingService;
|
|
_productInventoryService = productInventoryService;
|
|
_juShuiTanService = juShuiTanService;
|
|
_erpInventoryService = erpInventoryService;
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("hj")]
|
|
public async Task<string> TestHJ()
|
|
{
|
|
////var myJson = "{\"name\":\"小明\",\"address\":\"威海\"}";//json字符串
|
|
//var myJson= "{\"code\":\"200\",\"msg\":\"OK\",\"data\":{\"access_token\":\"05895ad6-e318-41da-9b2c-579dedd18fd1\",\"refresh_token\":\"ad9145cf-8af9-4617-9dbe-187b0ff3edf9\",\"expires_in\":7162}}";
|
|
//var myObj = JsonConvert.DeserializeObject<dynamic>(myJson);//反序列化为 dynamic 对象
|
|
//var my2 = System.Text.Json.JsonSerializer.Deserialize<dynamic>(myJson);
|
|
//string m = myObj.code;
|
|
//var m2 = my2.Object;
|
|
//var md = m2.code;
|
|
|
|
//var b33= await _juShuiTanService.GetStock();
|
|
// var bc = await _lingXingService.GetStock();
|
|
|
|
//List<(string orgCode, string stockCode)> request = new List<(string orgCode, string stockCode)>();
|
|
//request.Add(("101", "CK001"));
|
|
//request.Add(("101", "CK002"));
|
|
//var list = await _erpService.BillQueryForInventory(request);
|
|
//var b33 = await _juShuiTanService.GetStock();
|
|
//var b = b33.Data.Where(w => w.Id == 10923342).FirstOrDefault();
|
|
//await _juShuiTanService.GetTest();
|
|
//string codes = "AD";
|
|
//var b = await _erpInventoryService.GetInventory(codes);
|
|
//var bcd=await _productInventoryService.Refresh();
|
|
|
|
//LingXingResponse<LingXingStockResponse> r = new LingXingResponse<LingXingStockResponse>();
|
|
|
|
//string str = "{\"code\":0,\"message\":\"success\",\"error_details\":[],\"request_id\":\"7A739491-8740-01AC-304E-0203AF887AE2\",\"response_time\":\"2024-10-16 17:58:57\",\"data\":[{\"wid\":437,\"type\":1,\"name\":\"ORICO_OD\",\"is_delete\":0}],\"total\":1}";
|
|
//var ss=JsonConvert.DeserializeObject<LingXingResponse<LingXingStockResponse>>(str);
|
|
//var b = System.Text.Json.JsonSerializer.Deserialize<LingXingResponse<LingXingStockResponse>>(str);
|
|
//await _productInventoryService.LingXing();
|
|
//var s = await _lingXingService.GetSeller();
|
|
//var ns = s.Data.Where(w =>w.Id== "2101").ToList();
|
|
//string str = string.Join(",", s.Data.Select(s => s.Id).ToList());
|
|
//var sd= await _lingXingService.GetInventory(new LingXingInventoryRequest() { wid = "437" });
|
|
//string sdsdf = sd.Message;
|
|
//List<string> list = new List<string>();
|
|
//list.Add("GD-02-15");
|
|
//list.Add("GD-01-15");
|
|
//list.Add("AB-02-23");
|
|
//list.Add("AB-01-23");
|
|
//list.Add("AB-01");
|
|
//list.Add("AB-1-06");
|
|
//list.Add("AB-3-15");
|
|
//list.Add("C-3-15");
|
|
//List<string> list2 = new List<string>();
|
|
//list.ForEach(f => list2.Add(f.Replace("-0", "-")));
|
|
//var ss = list2.OrderBy(s => s).ToList();
|
|
|
|
//await _inStockTaskService.ErpDel();
|
|
//await _outStockTaskService.BillQueryForMisDeliveryOutStock(true, new List<string>() { "QTCK026812" });
|
|
//await _inStockTaskService.SysnMiscellaneous(new List<string>() { "QTRK028204" }, true);
|
|
|
|
|
|
// List<int> boxIds = new List<int>();
|
|
// boxIds.Add(5324);
|
|
//var b= await _inStockService.UnBind(boxIds, true);
|
|
//var b= await _boxService.Sync(null);
|
|
//var list = await _outStockTaskRepositories.GetEntityList(new List<int> { 14321 });
|
|
|
|
//await _outStockRepositories.GetEntityListBySerialNumbers(new List<string>() { "131VU-32C5A" });
|
|
//await _outStockRepositories.GetEntityListByBoxBillNos(new List<string>() { "CTN0002187" });
|
|
|
|
|
|
//list[0].Details[0].ErpDetails[0].AccruedQty = 2;
|
|
//list[0].Details[0].ErpDetails.Add(new OutStockTaskErpDetails()
|
|
//{
|
|
// Erp_DetailId = 1
|
|
//});
|
|
//list[0].Details.Add(new OutStockTaskDetails()
|
|
//{
|
|
// AccruedQty = 2
|
|
//});
|
|
//var b = await _outStockTaskRepositories.EditEntityList(list);
|
|
|
|
//List<string> s = new List<string>();
|
|
//s.Add("XSCKD10629693");
|
|
//var st = await _outStockTaskService.BillQueryForSalOutStock(true, s);
|
|
return "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 出库任务单手动同步金蝶数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("Refresh")]
|
|
public async Task<string> Refresh()
|
|
{
|
|
if (!_env.IsDevelopment()) return "";
|
|
var result = await this._outStockTaskService.Sync(null);
|
|
return "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 手动同步老ops箱信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("RefreshOpsBox")]
|
|
public async Task<string> RefreshOpsBox()
|
|
{
|
|
if (!_env.IsDevelopment()) return "";
|
|
var result = await _boxService.Sync();
|
|
return "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 手动同步金蝶删单信息
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("RefreshErpDelete")]
|
|
public async Task<string> RefreshErpDelete()
|
|
{
|
|
if (!_env.IsDevelopment()) return "";
|
|
await _inStockTaskService.ErpDel();
|
|
await _outStockTaskService.ErpDel();
|
|
return "";
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("tf")]
|
|
public async Task<string> TestTF()
|
|
{
|
|
if (!_env.IsDevelopment()) return "";
|
|
////var result = await this._erpService.BillQueryForOrg();
|
|
//var result = await this._erpService.BillQueryForBillType();
|
|
var result = await this._erpService.BillQueryForMaterial();
|
|
//var list = new List<TestMar>();
|
|
//foreach (var item in result.Data.ToList())
|
|
//{
|
|
// var t = new TestMar();
|
|
// t.MaterialNumber = item.MaterialNumber;
|
|
// t.BarCode = item.BarCode;
|
|
// list.Add(t);
|
|
//}
|
|
|
|
var tt = JsonConvert.SerializeObject(result);
|
|
|
|
return tt;
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// 根据物料Id获取物料编码
|
|
/// </summary>
|
|
/// <param name="materialIds"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("GetMaterial")]
|
|
public async Task<List<(int Id, string Number, string name)>> GetMaterial([FromQuery] List<int> materialIds)
|
|
{
|
|
List<(int Id, string Number, string name)> mList = new List<(int Id, string Number, string name)>();
|
|
if (!_env.IsDevelopment()) return mList;
|
|
var materials_result = await _erpService.BillQueryForMaterial();
|
|
var materials = materials_result.Data.ToList();
|
|
foreach (var mid in materialIds)
|
|
{
|
|
var m = materials.FirstOrDefault(f => f.MaterialId == mid);
|
|
mList.Add((m.MaterialId, m.MaterialNumber, m.MaterialName));
|
|
}
|
|
return mList;
|
|
}
|
|
/// <summary>
|
|
/// 根据物料编码获取物料Id
|
|
/// </summary>
|
|
/// <param name="number"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("GetMaterialId/{number}")]
|
|
public async Task<List<(int Id, string Number, string name)>> GetMaterialId([FromRoute] string number)
|
|
{
|
|
List<(int Id, string Number, string name)> mList = new List<(int Id, string Number, string name)>();
|
|
if (!_env.IsDevelopment()) return mList;
|
|
var materials_result = await _erpService.BillQueryForMaterial();
|
|
var materials = materials_result.Data.ToList();
|
|
|
|
var mL = materials.Where(f => f.MaterialNumber.Contains(number))
|
|
.Select(s => new
|
|
{
|
|
Id = s.MaterialId,
|
|
Number = s.MaterialNumber,
|
|
name = s.MaterialName
|
|
}).ToList();
|
|
foreach (var m in mL)
|
|
{
|
|
mList.Add((m.Id, m.Number, m.name));
|
|
}
|
|
return mList;
|
|
}
|
|
/// <summary>
|
|
/// 自动生成箱信息
|
|
/// </summary>
|
|
/// <param name="str">箱前缀</param>
|
|
/// <param name="number">数量(明细条数)</param>
|
|
/// <param name="materialNumbers">物料编码</param>
|
|
/// <param name="orgCode">组织编码</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("SCBox/{str}/{number}")]
|
|
public async Task<Result> SCBox([FromRoute] string str, [FromRoute] int number, [FromQuery] List<string> materialNumbers, [FromQuery] string orgCode)
|
|
{
|
|
if (!_env.IsDevelopment()) return Result.ReSuccess();
|
|
if (materialNumbers == null)
|
|
materialNumbers = new List<string>();
|
|
var list = await GetList(str, number, materialNumbers, orgCode);
|
|
await _boxService.Sync(list);
|
|
return Result.ReSuccess();
|
|
}
|
|
private async Task<List<OpsBoxResponse>> GetList(string str, int number, List<string> materialNumbers, string orgCode)
|
|
{
|
|
var materials_result = await _erpService.BillQueryForMaterial();
|
|
var materials = materials_result.Data.ToList();
|
|
|
|
List<string> mIds = materials.Where(w => materialNumbers.Contains(w.MaterialNumber) && w.OrgCode == orgCode).Select(s => s.MaterialNumber).ToList();
|
|
int jn = 3;
|
|
if (mIds.Count() <= 0)
|
|
mIds = materials.Where(w => w.OrgCode == orgCode).Skip((new Random()).Next(1000, 10000)).Take(4).Select(s => s.MaterialNumber).ToList();
|
|
jn = mIds.Count() - 1;
|
|
List<OpsBoxResponse> list = new List<OpsBoxResponse>();
|
|
for (int i = 0; i < number; i++)
|
|
{
|
|
List<OpsBoxDetailsResponse> Details = new List<OpsBoxDetailsResponse>();
|
|
for (int j = 0; j <= jn; j++)
|
|
{
|
|
var ran = (new Random()).Next(5, 10);
|
|
List<OpsSerialNumbersResponse> SerialNumbers = new List<OpsSerialNumbersResponse>();
|
|
for (int g = 0; g < ran; g++)
|
|
{
|
|
OpsSerialNumbersResponse or = new OpsSerialNumbersResponse()
|
|
{
|
|
SerialNumber = await GetStr(),
|
|
BarCereateUser = "01",
|
|
BarCreateTime = DateTime.Now
|
|
};
|
|
SerialNumbers.Add(or);
|
|
}
|
|
var mi = (new Random()).Next(1000, 20000);
|
|
OpsBoxDetailsResponse d = new OpsBoxDetailsResponse()
|
|
{
|
|
MaterialNumber = mIds[j],
|
|
Qty = ran,
|
|
SerialNumbers = SerialNumbers
|
|
};
|
|
Details.Add(d);
|
|
}
|
|
|
|
OpsBoxResponse response = new OpsBoxResponse()
|
|
{
|
|
BoxBillNo = str + ((new Random()).Next(500, 2000) + i).ToString(),
|
|
OpsBoxId = 100 + i,
|
|
CompleteCartonTime = DateTime.Now,
|
|
CompleteCartonUser = "02",
|
|
CreateTime = DateTime.Now,
|
|
CreateUser = "01",
|
|
OrgId = 0,
|
|
SupplierId = 10897,
|
|
Details = Details
|
|
};
|
|
list.Add(response);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
private Task<string> GetStr()
|
|
{
|
|
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
var Charsarr = new char[11];
|
|
var random = new Random();
|
|
|
|
for (int i = 0; i < Charsarr.Length; i++)
|
|
{
|
|
Charsarr[i] = characters[random.Next(characters.Length)];
|
|
}
|
|
|
|
return Task.FromResult(new String(Charsarr));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试:同步入库单
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("InStock")]
|
|
public async Task<Result> InStock()
|
|
{
|
|
if (!_env.IsDevelopment()) return Result.ReSuccess();
|
|
//3.同步数据
|
|
var result = await _inStockTaskService.Sysn();
|
|
return result;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试-接口是否正常
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("lst")]
|
|
public string Lst()
|
|
{
|
|
var successStr = "tongfei test lst->数据库链接地址:" + _options.DBConnectionString + ",单点项目链接地址:" + _options.SingleBaseUrl;
|
|
return successStr;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试-单点接口是否正常
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("lst1")]
|
|
public async Task<string> Lst1()
|
|
{
|
|
var result = await _basicsRepositories.GetUcStockAsync(ManagementSystemCode.GLXT0004.ToString(), "", 1);
|
|
return JsonConvert.SerializeObject(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 测试-单点接口是否正常
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("lst2")]
|
|
public async Task<string> Lst2()
|
|
{
|
|
var oldtoken = "3d046dc06a3f4f1ebcda93e921012c82";
|
|
var retoken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTEwNzIwNjksImlhdCI6MTcxMDk4NTY2OSwianRpIjoiMDA1NTFmM2ItNDQ5Ny00NzU1LTljNGQtNTNiODUxMDBjOTk5In0.XjHDfHhqvfap5MZPqTd45zi1L2_mgxu-lLnyqTKrhD0";
|
|
await _loginService.RefreshTokenNew(oldtoken, retoken);
|
|
return "";
|
|
}
|
|
/// <summary>
|
|
/// 测试发送
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("Send")]
|
|
public async Task<Result> Send()
|
|
{
|
|
return await _sendMessageService.Execute();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 同步新物料-和修改已启用批号管理的物料
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("SyscMats")]
|
|
public async Task<Result> SyscMats()
|
|
{
|
|
return await _materialService.SyncNewMaterials();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("getmt")]
|
|
public async Task<bool> GetMaterial()
|
|
{
|
|
var materials_result = await _erpService.BillQueryForMaterial();
|
|
var materials = materials_result.Data.ToList();
|
|
|
|
var tt = "";
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清空缓存
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("ClearCache")]
|
|
public Result ClearCache()
|
|
{
|
|
//通过反射调用清空缓存方法
|
|
PropertyInfo prop = _memoryCache.GetType().GetProperty("EntriesCollection", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public);
|
|
object innerCache = prop.GetValue(_memoryCache);
|
|
MethodInfo clearMethod = innerCache.GetType().GetMethod("Clear", BindingFlags.Instance | BindingFlags.Public);
|
|
clearMethod.Invoke(innerCache, null);
|
|
return Result.ReSuccess();
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("binfa")]
|
|
public Result<bool> BinFa()
|
|
{
|
|
var cacheKey = "instock_shelf_" + 1;
|
|
var IscanAccess = _redisConcurrentProcessService.GetRedisKeyValue(cacheKey);
|
|
if (IscanAccess)
|
|
return Result<bool>.ReFailure(ResultCodes.Concurrent_Instock);
|
|
|
|
Console.WriteLine("process..." + IscanAccess);
|
|
_redisConcurrentProcessService.UpdateAccessStatus(cacheKey, true);
|
|
var tt2 = _redisConcurrentProcessService.GetRedisKeyValue(cacheKey);
|
|
Console.WriteLine("redis1:" + tt2);
|
|
return Result<bool>.ReSuccess(tt2);
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("lst3")]
|
|
public async Task<bool> lst3()
|
|
{
|
|
var data = await _erpService.BillQueryForPurchaseInStockBy("1541693", null);
|
|
return true;
|
|
}
|
|
}
|
|
}
|