This commit is contained in:
qianjiawei
2024-03-14 17:28:33 +08:00
parent f37ad2bfa3
commit 501a39dda5
6 changed files with 359 additions and 26 deletions

View File

@@ -5,11 +5,15 @@ using JNPF.FriendlyException;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys.Dto.VisualDev;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.Common.Redis;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Dto;
namespace Tnb.WarehouseMgr
{
@@ -21,11 +25,13 @@ namespace Tnb.WarehouseMgr
{
private readonly ISqlSugarClient _db;
private readonly IUserManager _userManager;
public LocationDefinitionService(ISqlSugarRepository<BasLocation> repository, IUserManager userManager)
private readonly RedisData _redisData;
public LocationDefinitionService(ISqlSugarRepository<BasLocation> repository, IUserManager userManager, RedisData redisData)
{
_db = repository.AsSugarClient();
_userManager = userManager;
OverideFuncs.ImportDataAsync = DataImport;
_redisData=redisData;
}
private async Task<dynamic> DataImport(VisualDevImportDataInput input)
@@ -162,5 +168,168 @@ namespace Tnb.WarehouseMgr
return result;
}
[HttpPost]
[AllowAnonymous]
public async Task<dynamic> GetYCLlocation()
{
List<List<LocationOutput>> LocationOutputss=new List<List<LocationOutput>>();
var list =await _db.Queryable<BasLocation>().Where(p=> p.wh_id == "1" && p.region_id== "26125793924133"&& p.is_type == "0" && p.location_code.Length==9).OrderBy(p=>p.location_code).ToListAsync();
var carrys=await _db.Queryable<WmsCarryH>().ToListAsync();
var carrycodes=await _db.Queryable<WmsCarryCode>().ToListAsync();
var lastdata=string.Empty;
List<LocationOutput> LocationOutputs = new List<LocationOutput>();
foreach (var data in list)
{
if (!string.IsNullOrEmpty(lastdata)&& data.location_code.Substring(4,1)!= lastdata.Substring(4, 1))
{
LocationOutputss.Add(LocationOutputs);
LocationOutputs = new List<LocationOutput>();
}
LocationOutput locationOutput = new LocationOutput();
locationOutput.location_code = data.location_code;
locationOutput.layers = data.layers;
locationOutput.type = 0;
if (carrys.Where(p => p.location_id == data.id).Any())
{
var carry= carrys.Where(p => p.location_id == data.id).First();
locationOutput.carry_code = carry.carry_code;
locationOutput.type = 1;
if (carrycodes.Where(p => p.carry_id == carry.id).Any())
{
var carrycode = carrycodes.Where(p => p.carry_id == carry.id).First();
locationOutput.type = 2;
locationOutput.material_code = carrycode.material_code;
locationOutput.num = carrycode.codeqty;
}
}
lastdata = data.location_code;
LocationOutputs.Add(locationOutput);
}
return LocationOutputss;
}
[HttpPost]
[AllowAnonymous]
public async Task<dynamic> GetCTUlocation()
{
List<List<LocationOutput>> LocationOutputss = new List<List<LocationOutput>>();
var list = await _db.Queryable<BasLocation>().Where(p => p.wh_id == "2" && p.region_id == "27010227520021" && p.is_type == "0" && p.location_code.Length == 13).OrderBy(p =>new { p.loc_column, p.location_code } ).ToListAsync();
var carrys = await _db.Queryable<WmsCarryH>().ToListAsync();
var carrycodes = await _db.Queryable<WmsCarryCode>().ToListAsync();
int loc_column = 0;
List<LocationOutput> LocationOutputs = new List<LocationOutput>();
foreach (var data in list)
{
if (loc_column!=0&& data.loc_column!=loc_column)
{
LocationOutputss.Add(LocationOutputs);
LocationOutputs = new List<LocationOutput>();
}
LocationOutput locationOutput = new LocationOutput();
locationOutput.location_code = data.location_code;
locationOutput.layers = data.layers;
locationOutput.type = 0;
if (carrys.Where(p => p.location_id == data.id).Any())
{
var carry = carrys.Where(p => p.location_id == data.id).First();
locationOutput.carry_code = carry.carry_code;
locationOutput.type = 1;
if (carrycodes.Where(p => p.carry_id == carry.id).Any())
{
var carrycode = carrycodes.Where(p => p.carry_id == carry.id).First();
locationOutput.type = 2;
locationOutput.material_code = carrycode.material_code;
locationOutput.num = carrycode.codeqty;
}
}
loc_column = data.loc_column;
LocationOutputs.Add(locationOutput);
}
return LocationOutputss;
}
[HttpPost]
[AllowAnonymous]
public async Task<dynamic> GetCPlocation()
{
List<List<LocationOutput>> LocationOutputss = new List<List<LocationOutput>>();
var list = await _db.Queryable<BasLocation>().Where(p => p.wh_id == "26103372441637" && p.region_id == "28598002137877" && p.is_type == "0" && p.location_code.Length == 9).OrderBy(p => p.location_code).ToListAsync();
var carrys = await _db.Queryable<WmsCarryH>().ToListAsync();
var carrycodes = await _db.Queryable<WmsCarryCode>().ToListAsync();
var lastdata = string.Empty;
List<LocationOutput> LocationOutputs = new List<LocationOutput>();
foreach (var data in list)
{
if (!string.IsNullOrEmpty(lastdata) && data.location_code.Substring(3, 3) != lastdata.Substring(3, 3))
{
LocationOutputss.Add(LocationOutputs);
LocationOutputs = new List<LocationOutput>();
}
LocationOutput locationOutput = new LocationOutput();
locationOutput.location_code = data.location_code;
locationOutput.layers = data.layers;
locationOutput.type = 0;
if (carrys.Where(p => p.location_id == data.id).Any())
{
var carry = carrys.Where(p => p.location_id == data.id).First();
locationOutput.carry_code = carry.carry_code;
locationOutput.type = 1;
if (carrycodes.Where(p => p.carry_id == carry.id).Any())
{
var carrycode = carrycodes.Where(p => p.carry_id == carry.id).First();
locationOutput.type = 2;
locationOutput.material_code = carrycode.material_code;
locationOutput.num = carrycode.codeqty;
}
}
lastdata = data.location_code;
LocationOutputs.Add(locationOutput);
}
return LocationOutputss;
}
[HttpPost]
[AllowAnonymous]
public async Task<dynamic> GetZSJData()
{
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("device_state", "事件");
dic.Add("temp1", "前部[゚C]");
dic.Add("temp3", "后部1[゚C]");
dic.Add("temp5", "落下口[゚C]");
dic.Add("zsspeed", "V1[mm/s]");
dic.Add("sjspeed", "V2[mm/s]");
dic.Add("cxtime", "周期时间[s]");
var keys = _redisData.GetAllKeys().Where(p => p.Contains("TYSC-ZSJ")).ToList();
List<ZsjOutput> datas = new List<ZsjOutput>();
foreach (var key in keys)
{
var data = datas.Where(p => p.device_code == key.Substring(0, 12)).FirstOrDefault();
if (data != null)
{
foreach (var d in dic)
{
bool flag = await _redisData.HashExist(key, d.Value);
if (flag)
data.GetType().GetProperty(d.Key)!.SetValue(data,_redisData.GetHash(key, d.Value).Result);
}
}
else
{
ZsjOutput zsjOutput = new ZsjOutput();
zsjOutput.device_code = key.Substring(0, 12);
foreach (var d in dic)
{
bool flag = await _redisData.HashExist(key, d.Value);
if (flag)
zsjOutput.GetType().GetProperty(d.Key)!.SetValue(zsjOutput, _redisData.GetHash(key, d.Value).Result);
}
datas.Add(zsjOutput);
}
}
return datas;
}
}
}