Files
tnb.server/ProductionMgr/Tnb.ProductionMgr/TimeWorkService.cs
2024-07-17 14:12:52 +08:00

660 lines
33 KiB
C#

using System.Diagnostics;
using Aop.Api.Domain;
using JNPF;
using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.Common.Extension;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Extras.CollectiveOAuth.Models;
using JNPF.Extras.CollectiveOAuth.Utils;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Interfaces.Permission;
using JNPF.Systems.Interfaces.System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SqlSugar;
using SqlSugar.Extensions;
using Tnb.BasicData.Entities;
using Tnb.Common.Redis;
using Tnb.WarehouseMgr.Interfaces;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Entities.Consts;
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
using Result = Tnb.WarehouseMgr.Entities.Dto.Outputs.Result;
using Tnb.BasicData;
using Tnb.EquipMgr.Entities;
using Tnb.WarehouseMgr;
using Tnb.WarehouseMgr.Entities;
using Tnb.ProductionMgr.Entities;
using Tnb.ProductionMgr.Interfaces;
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
namespace Tnb.ProductionMgr
{
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
[Route("api/[area]/[controller]/[action]")]
public class TimeWorkService : IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<BasMaterial> _repository;
private readonly ISqlSugarClient _db;
private readonly IOrganizeService _organizeService;
private readonly IBillRullService _billRullService;
private readonly RedisData _redisData;
private readonly IWmsEmptyOutstockService _wmsEmptyOutstockService;
private readonly IWareHouseService _wareHouseService;
private readonly IPrdMoTaskService _prdMoTaskService;
public TimeWorkService(
RedisData redisData,
ISqlSugarRepository<BasMaterial> repository,
IBillRullService billRullService,
IOrganizeService organizeService,
IWmsEmptyOutstockService wmsEmptyOutstockService,
IPrdMoTaskService prdMoTaskService,
IWareHouseService wareHouseService
)
{
_redisData = redisData;
_repository = repository;
_db = repository.AsSugarClient();
_organizeService = organizeService;
_billRullService = billRullService;
_wmsEmptyOutstockService = wmsEmptyOutstockService;
_wareHouseService = wareHouseService;
_prdMoTaskService = prdMoTaskService;
}
[HttpGet]
[AllowAnonymous]
public async Task<dynamic> test()
{
var db = _repository.AsSugarClient();
await db.Ado.BeginTranAsync();
BasUnit basUnit = new BasUnit();
basUnit.id = SnowflakeIdHelper.NextId();
basUnit.unit_name = "aaa";
basUnit.unit_code = "bbb";
await db.Insertable(basUnit).ExecuteCommandAsync();
await db.Ado.CommitTranAsync();
await db.Ado.BeginTranAsync();
BasUnit basUnit2 = new BasUnit();
basUnit2.id = SnowflakeIdHelper.NextId();
basUnit2.unit_name = "ccc";
basUnit2.unit_code = "ddd";
await db.Insertable(basUnit2).ExecuteCommandAsync();
await db.Ado.CommitTranAsync();
return Task.CompletedTask;
}
/// <summary>
/// 注塑空载具出库
/// </summary>
/// <returns></returns>
[HttpGet]
[AllowAnonymous]
public async Task<string> EmptyCarryOutStk()
{
string state = await _redisData.TryGetValueByKeyField<string>("YTCS", "State");
if ("OK" != state) return "YTCS没开机";
string result = "";
bool? cs01 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "CallCtuEmptyIn_CS01");
bool? cs03 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "CallCtuEmptyIn_CS03");
bool? cs06 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "CallCtuEmptyIn_CS06");
// bool cs01Flag = _redisData.Get<bool>("YTCS_CallCtuEmptyIn_CS01_flag");
// bool cs03Flag = _redisData.Get<bool>("YTCS_CallCtuEmptyIn_CS03_flag");
// bool cs06Flag = _redisData.Get<bool>("YTCS_CallCtuEmptyIn_CS06_flag");
List<String> statusList = new List<string>(){WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID,WmsWareHouseConst.PRETASK_BILL_STATUS_YXF_ID,WmsWareHouseConst.PRETASK_BILL_STATUS_START_ID};
bool cs01Flag = await _db.Queryable<WmsPretaskH>().AnyAsync(x => x.endlocation_code == "SSX-021-001" && statusList.Contains(x.status) );
bool cs03Flag = await _db.Queryable<WmsPretaskH>().AnyAsync(x => x.endlocation_code == "SSX-021-003" && statusList.Contains(x.status) );
bool cs06Flag = await _db.Queryable<WmsPretaskH>().AnyAsync(x => x.endlocation_code == "SSX-011-006" && statusList.Contains(x.status) );
if (cs01Flag)
{
Log.Information($"【EmptyCarryOutStk】ctu1空箱入呼叫存在未完成的预任务,跳过此次自动呼叫");
}
if (cs03Flag)
{
Log.Information($"【EmptyCarryOutStk】ctu3空箱入呼叫存在未完成的预任务,跳过此次自动呼叫");
}
if (cs06Flag)
{
Log.Information($"【EmptyCarryOutStk】ctu6空箱入呼叫存在未完成的预任务,跳过此次自动呼叫");
}
if (cs01==true && !cs01Flag)
{
BasFactoryConfig config = await _repository.AsSugarClient().Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN);
string response = HttpUtils.RequestGet($"{config.value}/api/production/time-work/empty-carry-out-stk-ctu1");
// string response = HttpUtils.RequestGet($"http://localhost:9232/api/production/time-work/empty-carry-out-stk-left");
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(response);
result += authResponse.data.ToString();
}
if (cs03==true && !cs03Flag)
{
BasFactoryConfig config = await _repository.AsSugarClient().Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN);
string response = HttpUtils.RequestGet($"{config.value}/api/production/time-work/empty-carry-out-stk-ctu3");
// string response = HttpUtils.RequestGet($"http://localhost:9232/api/production/time-work/empty-carry-out-stk-right");
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(response);
result += authResponse.data.ToString();
}
if (cs06==true && !cs06Flag)
{
BasFactoryConfig config = await _repository.AsSugarClient().Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN);
string response = HttpUtils.RequestGet($"{config.value}/api/production/time-work/empty-carry-out-stk-ctu6");
// string response = HttpUtils.RequestGet($"http://localhost:9232/api/production/time-work/empty-carry-out-stk-right");
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(response);
result += authResponse.data.ToString();
}
return result;
}
[HttpGet]
[AllowAnonymous]
public async Task<string> EmptyCarryOutStkCtu1()
{
string msg = "";
BasFactoryConfig config = await _db.Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.EmptyCarryOutNum);
MESEmptyCarryOutStkInput input = new MESEmptyCarryOutStkInput();
input.org_id = WmsWareHouseConst.AdministratorOrgId;
input.location_code = "SSX-021-001";
input.warehouse_id = WmsWareHouseConst.WAREHOUSE_ZC_ID;
input.carrystd_id = WmsWareHouseConst.LIAOXIANGID;
input.qty = int.Parse(config?.value ?? "5");
input.create_id = WmsWareHouseConst.AdministratorUserId;
Log.Information($"【EmptyCarryOutStk】ctu1空箱入呼叫开始,参数:{JsonConvert.SerializeObject(input)}");
Result result = await _wmsEmptyOutstockService.MESEmptyCarryOutStk(input);
if (result.code == HttpStatusCode.OK)
{
msg = "ctu1空箱入呼叫成功";
Log.Information("【EmptyCarryOutStk】ctu1空箱入呼叫成功");
//_redisData.Set("YTCS_CallCtuEmptyIn_CS01_flag", true, TimeSpan.FromMinutes(20));
}
else
{
msg = $"ctu1空箱入呼叫失败:{result.msg}";
Log.Error($"【EmptyCarryOutStk】ctu1空箱入呼叫失败:{result.msg}");
}
return msg;
}
[HttpGet]
[AllowAnonymous]
public async Task<string> EmptyCarryOutStkCtu3()
{
string msg = "";
BasFactoryConfig config = await _db.Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.EmptyCarryOutNum);
MESEmptyCarryOutStkInput input = new MESEmptyCarryOutStkInput();
input.org_id = WmsWareHouseConst.AdministratorOrgId;
input.location_code = "SSX-021-003";
input.warehouse_id = WmsWareHouseConst.WAREHOUSE_ZC_ID;
input.carrystd_id = WmsWareHouseConst.LIAOXIANGID;
input.qty = int.Parse(config?.value ?? "5");
input.create_id = WmsWareHouseConst.AdministratorUserId;
Log.Information($"【EmptyCarryOutStk】ctu3空箱入呼叫开始,参数:{JsonConvert.SerializeObject(input)}");
Result result = await _wmsEmptyOutstockService.MESEmptyCarryOutStk(input);
if (result.code == HttpStatusCode.OK)
{
msg = "ctu3空箱入呼叫成功";
Log.Information("【EmptyCarryOutStk】ctu3空箱入呼叫成功");
//_redisData.Set("YTCS_CallCtuEmptyIn_CS03_flag", true, TimeSpan.FromMinutes(20));
}
else
{
msg = $"ctu3空箱入呼叫失败:{result.msg}";
Log.Error($"【EmptyCarryOutStk】ctu3空箱入呼叫失败:{result.msg}");
}
return msg;
}
[HttpGet]
[AllowAnonymous]
public async Task<string> EmptyCarryOutStkCtu6()
{
string msg = "";
BasFactoryConfig config = await _db.Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.EmptyCarryOutNum);
MESEmptyCarryOutStkInput input = new MESEmptyCarryOutStkInput();
input.org_id = WmsWareHouseConst.AdministratorOrgId;
input.location_code = "SSX-011-006";
input.warehouse_id = WmsWareHouseConst.WAREHOUSE_ZC_ID;
input.carrystd_id = WmsWareHouseConst.LIAOXIANGID;
input.qty = int.Parse(config?.value ?? "5");
input.create_id = WmsWareHouseConst.AdministratorUserId;
Log.Information($"【EmptyCarryOutStk】ctu6空箱入呼叫开始,参数:{JsonConvert.SerializeObject(input)}");
Result result = await _wmsEmptyOutstockService.MESEmptyCarryOutStk(input);
if (result.code == HttpStatusCode.OK)
{
msg = "ctu6空箱入呼叫成功";
Log.Information("【EmptyCarryOutStk】ctu6空箱入呼叫成功");
//_redisData.Set("YTCS_CallCtuEmptyIn_CS06_flag", true, TimeSpan.FromMinutes(20));
}
else
{
msg = $"ctu6空箱入呼叫失败:{result.msg}";
Log.Error($"【EmptyCarryOutStk】ctu6空箱入呼叫失败:{result.msg}");
}
return msg;
}
// [HttpGet]
// [AllowAnonymous]
// public async Task<string> FixedPointDelivery()
// {
// string state = await _redisData.TryGetValueByKeyField<string>("YTCS", "State");
// if ("OK" != state)
// {
// Log.Error($"TCS没开机");
// return "YTCS没开机";
// }
// string stateHxja = await _redisData.TryGetValueByKeyField<string>("hxjA", "State");
// string stateHxjc = await _redisData.TryGetValueByKeyField<string>("hxjC", "State");
// List<String> hxjList = new List<string>();
// if ("OK" == stateHxja)
// {
// hxjList.Add("hxjA");
// }
// if ("OK" == stateHxjc)
// {
// hxjList.Add("hxjC");
// }
//
// if (hxjList.IsEmpty())
// {
// Log.Error($"hxjA,hxjC不正常");
// return "hxjA,hxjC不正常";
// }
// string msg = "";
// List<EqpEquipment> equipments = await _db.Queryable<EqpEquipType>()
// .InnerJoin<EqpEquipment>((x, y) => x.id == y.equip_type_id)
// .Where((x, y) => x.code == "ZSJ")
// .Select((x, y) => y).ToListAsync();
//
// int? cs01Count = await _redisData.TryGetValueByKeyField<int?>("YTCS", "EmptyNo_CS01");
// int? cs03Count = await _redisData.TryGetValueByKeyField<int?>("YTCS", "EmptyNo_CS03");
//
// List<String> eqpIds = equipments.Select(x => x.id).ToList();
// List<EqpDaq> eqpDaqs = await _db.Queryable<EqpDaq>().Where(x => eqpIds.Contains(x.equip_id) && x.label_name.Contains("允许入空箱")).ToListAsync();
// //BasFactoryConfig config = await _db.Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN);
// foreach (var equipment in equipments)
// {
// EqpDaq eqpDaq = eqpDaqs.FirstOrDefault(x => x.equip_id==equipment.id);
// if (eqpDaq == null)
// {
// Log.Error($"{equipment.name}没配置允许入空箱");
// continue;
// }
// if (!hxjList.Contains(eqpDaq.equip_code))
// {
// Log.Error($"{eqpDaq.equip_code}状态不正常");
// continue;
// }
// if (string.IsNullOrEmpty(equipment.upmat_location_id))
// {
// Log.Error($"{equipment.name}未配置上料库位");
// continue;
// }
// if (await _db.Queryable<WmsPretaskH>().AnyAsync(x =>
// x.endlocation_id == equipment.upmat_location_id &&
// x.biz_type == WmsWareHouseConst.BIZTYPE_WMSDELIVERY_ID &&
// (x.status == WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID
// || x.status == WmsWareHouseConst.PRETASK_BILL_STATUS_YXF_ID
// || x.status == WmsWareHouseConst.PRETASK_BILL_STATUS_START_ID
// )
// ))
// {
// Log.Error($"{equipment.name}存在未完成的任务");
// continue;
// }
// bool? value = await _redisData.TryGetValueByKeyField<bool?>(eqpDaq.equip_code, eqpDaq.label_name);
// bool valueFlag = _redisData.Get<bool>($"{eqpDaq.equip_code}_{eqpDaq.label_name}_flag");
// Log.Information($"机台号{eqpDaq.equip_code},标签名{eqpDaq.label_name}redis的值为{value.ToString()}");
//
// if (value==true && !valueFlag)
// {
// bool? cs01 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "AllowAgvEmptyOut_CS01");
// bool? cs03 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "AllowAgvEmptyOut_CS03");
// string startLocationCode = cs01==true ? "ZSSSXCTU01" : cs03==true ? "ZSSSXCTU02" : "";
// if (cs01==true && cs03==true)
// {
// string last_fixed_point_delivery = _redisData.Exists("last_fixed_point_delivery") ? _redisData.Get<string>("last_fixed_point_delivery") : "";
// if (string.IsNullOrEmpty(last_fixed_point_delivery))
// {
// startLocationCode = "ZSSSXCTU01";
// }
// else
// {
// startLocationCode = "ZSSSXCTU01ZSSSXCTU02".Replace(last_fixed_point_delivery, "");
// }
// }
// if (startLocationCode.IsEmpty())
// {
// Log.Error($"输送线无空载具");
// return "输送线无空载具";
// }
//
// BasLocation startLocation = await _db.Queryable<BasLocation>().Where(x=>x.location_code==startLocationCode).FirstAsync();
// CommonCreatePretaskInput postData = new CommonCreatePretaskInput();
// postData.startlocation_id = startLocation.id;
// postData.endlocation_id = equipment.upmat_location_id;
// postData.biz_type = WmsWareHouseConst.BIZTYPE_WMSDELIVERY_ID;
// postData.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID;
// Log.Information($"【FixedPointDelivery】注塑定点配送,参数:{JsonConvert.SerializeObject(postData)}");
// Result result = await _wareHouseService.CommonCreatePretask(postData);
// // string sendResult = HttpUtils.RequestPost($"{config.value}/api/wms/ware-house/common-create-pretask", JsonConvert.SerializeObject(postData), null);
// // string sendResult = HttpUtils.RequestPost($"http://localhost:9232/api/wms/ware-house/common-create-pretask", JsonConvert.SerializeObject(postData), null);
// // AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(sendResult);
// if(result.code == HttpStatusCode.OK)
// {
// msg += $"{equipment.name}注塑定点配送成功,";
// Log.Information($"【FixedPointDelivery】{equipment.name}注塑定点配送成功");
// _redisData.Set($"{eqpDaq.equip_code}_{eqpDaq.label_name}_flag", true, TimeSpan.FromMinutes(20));
// _redisData.Set($"last_fixed_point_delivery", startLocationCode);
// }
// else
// {
// msg += $"{equipment.name}注塑定点配送失败:{result.msg},";
// Log.Error($"【FixedPointDelivery】{equipment.name}注塑定点配送失败:{result.msg}");
// }
//
// }
// }
//
// return msg;
// }
[HttpGet]
[AllowAnonymous]
public async Task<string> FixedPointDelivery()
{
string state = await _redisData.TryGetValueByKeyField<string>("YTCS", "State");
if ("OK" != state)
{
Log.Error($"TCS没开机");
return "YTCS没开机";
}
string stateHxja = await _redisData.TryGetValueByKeyField<string>("hxjA", "State");
string stateHxjc = await _redisData.TryGetValueByKeyField<string>("hxjC", "State");
List<String> hxjList = new List<string>();
if ("OK" == stateHxja)
{
hxjList.Add("hxjA");
}
if ("OK" == stateHxjc)
{
hxjList.Add("hxjC");
}
if (hxjList.IsEmpty())
{
Log.Error($"hxjA,hxjC不正常");
return "hxjA,hxjC不正常";
}
string msg = "";
List<EqpEquipment> equipments = await _db.Queryable<EqpEquipType>()
.InnerJoin<EqpEquipment>((x, y) => x.id == y.equip_type_id)
.Where((x, y) => x.code == "ZSJ")
.Select((x, y) => y).ToListAsync();
int cs01Count = await _redisData.TryGetValueByKeyField<int>("YTCS", "EmptyNo_CS01");
int cs03Count = await _redisData.TryGetValueByKeyField<int>("YTCS", "EmptyNo_CS03");
List<String> eqpIds = equipments.Select(x => x.id).ToList();
List<EqpDaq> eqpDaqs = await _db.Queryable<EqpDaq>().Where(x => eqpIds.Contains(x.equip_id) && x.label_name.Contains("允许入空箱")).ToListAsync();
//BasFactoryConfig config = await _db.Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN);
foreach (var equipment in equipments)
{
EqpDaq eqpDaq = eqpDaqs.FirstOrDefault(x => x.equip_id==equipment.id);
if (eqpDaq == null)
{
Log.Error($"{equipment.name}没配置允许入空箱");
continue;
}
if (!hxjList.Contains(eqpDaq.equip_code))
{
Log.Error($"{eqpDaq.equip_code}状态不正常");
continue;
}
if (string.IsNullOrEmpty(equipment.upmat_location_id))
{
Log.Error($"{equipment.name}未配置上料库位");
continue;
}
if (await _db.Queryable<WmsPretaskH>().AnyAsync(x =>
x.endlocation_id == equipment.upmat_location_id &&
x.biz_type == WmsWareHouseConst.BIZTYPE_WMSDELIVERY_ID &&
(x.status == WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID
|| x.status == WmsWareHouseConst.PRETASK_BILL_STATUS_YXF_ID
|| x.status == WmsWareHouseConst.PRETASK_BILL_STATUS_START_ID
)
))
{
Log.Error($"{equipment.name}存在未完成的任务");
continue;
}
bool? value = await _redisData.TryGetValueByKeyField<bool?>(eqpDaq.equip_code, eqpDaq.label_name);
bool valueFlag = _redisData.Get<bool>($"{eqpDaq.equip_code}_{eqpDaq.label_name}_flag");
Log.Information($"机台号{eqpDaq.equip_code},标签名{eqpDaq.label_name}redis的值为{value.ToString()}");
if (value==true && !valueFlag)
{
bool? cs01 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "AllowAgvEmptyOut_CS01");
bool? cs03 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "AllowAgvEmptyOut_CS03");
string startLocationCode = "";
if (cs01==true && cs03==true && cs01Count>0 && cs03Count>0)
{
string last_fixed_point_delivery = _redisData.Exists("last_fixed_point_delivery") ? _redisData.Get<string>("last_fixed_point_delivery") : "";
if (string.IsNullOrEmpty(last_fixed_point_delivery))
{
startLocationCode = "ZSSSXCTU01";
}
else
{
startLocationCode = "ZSSSXCTU01ZSSSXCTU02".Replace(last_fixed_point_delivery, "");
}
}
else
{
if (cs01==true && cs01Count > 0)
{
startLocationCode = "ZSSSXCTU01";
cs01Count--;
}else if (cs03==true && cs03Count > 0)
{
startLocationCode = "ZSSSXCTU02";
cs03Count--;
}
}
if (startLocationCode.IsEmpty())
{
Log.Error($"输送线无空载具");
return "输送线无空载具";
}
BasLocation startLocation = await _db.Queryable<BasLocation>().Where(x=>x.location_code==startLocationCode).FirstAsync();
CommonCreatePretaskInput postData = new CommonCreatePretaskInput();
postData.startlocation_id = startLocation.id;
postData.endlocation_id = equipment.upmat_location_id;
postData.biz_type = WmsWareHouseConst.BIZTYPE_WMSDELIVERY_ID;
postData.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID;
Log.Information($"【FixedPointDelivery】注塑定点配送,参数:{JsonConvert.SerializeObject(postData)}");
Result result = await _wareHouseService.CommonCreatePretask(postData);
// string sendResult = HttpUtils.RequestPost($"{config.value}/api/wms/ware-house/common-create-pretask", JsonConvert.SerializeObject(postData), null);
// string sendResult = HttpUtils.RequestPost($"http://localhost:9232/api/wms/ware-house/common-create-pretask", JsonConvert.SerializeObject(postData), null);
// AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(sendResult);
if(result.code == HttpStatusCode.OK)
{
msg += $"{equipment.name}注塑定点配送成功,";
Log.Information($"【FixedPointDelivery】{equipment.name}注塑定点配送成功");
_redisData.Set($"{eqpDaq.equip_code}_{eqpDaq.label_name}_flag", true, TimeSpan.FromMinutes(20));
_redisData.Set($"last_fixed_point_delivery", startLocationCode);
}
else
{
msg += $"{equipment.name}注塑定点配送失败:{result.msg},";
Log.Error($"【FixedPointDelivery】{equipment.name}注塑定点配送失败:{result.msg}");
}
}
}
return msg;
}
[HttpGet]
[AllowAnonymous]
public async Task<String> AutoPrdReport()
{
BasFactoryConfig config = await _repository.AsSugarClient().Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN);
bool qu1 = await _redisData.TryGetValueByKeyField<bool>("外包装箱码垛线", "WBZX_x1_AGV_qu");
if (qu1)
{
Log.Information("血路管1线取");
HttpUtils.RequestGet($"{config.value}/api/production/time-work/x1-auto-prd-report");
}
bool qu2 = await _redisData.TryGetValueByKeyField<bool>("外包装箱码垛线", "WBZX_x2_AGV_qu");
if (qu2)
{
Log.Information("血路管2线取");
HttpUtils.RequestGet($"{config.value}/api/production/time-work/x2-auto-prd-report");
}
return "true";
}
[HttpGet]
[AllowAnonymous]
public async Task<string> X1AutoPrdReport()
{
string carryCode = await _redisData.TryGetValueByKeyField<string>("外包装箱码垛线", "WBZX_x1_take_tp");
int num = await _redisData.TryGetValueByKeyField<int>("外包装箱码垛线", "WBZX_x1_Enquantity");
if (string.IsNullOrEmpty(carryCode) || num<=0)
{
Log.Information("血路管1线无载具或数量为0");
return "无载具或数量为0";
}
PrdMoTask prdMoTask = await _db.Queryable<PrdMoTask>().Where(x => x.workline_id == WmsWareHouseConst.XUELUGUAN1XIAN && x.mo_task_status == DictConst.InProgressEnCode && x.parent_id != null).FirstAsync();
if (prdMoTask == null)
{
Log.Information("血路管1线没有进行中的任务单");
return "血路管1线没有进行中的任务单";
}
PrdReportCrInput input = new PrdReportCrInput();
input.mo_task_code = prdMoTask.mo_task_code;
input.mo_task_id = prdMoTask.id;
input.reported_qty = num;
input.station = "";
input.material_box_code = carryCode;
await _prdMoTaskService.PrdReport(input);
return "true";
}
[HttpGet]
[AllowAnonymous]
public async Task<string> X2AutoPrdReport()
{
string carryCode = await _redisData.TryGetValueByKeyField<string>("外包装箱码垛线", "WBZX_x2_take_tp");
int num = await _redisData.TryGetValueByKeyField<int>("外包装箱码垛线", "WBZX_x2_Enquantity");
if (string.IsNullOrEmpty(carryCode) || num<=0)
{
Log.Information("血路管2线无载具或数量为0");
return "无载具或数量为0";
}
PrdMoTask prdMoTask = await _db.Queryable<PrdMoTask>().Where(x => x.workline_id == WmsWareHouseConst.XUELUGUAN2XIAN && x.mo_task_status == DictConst.InProgressEnCode && x.parent_id != null).FirstAsync();
if (prdMoTask == null)
{
Log.Information("血路管2线没有进行中的任务单");
return "血路管2线没有进行中的任务单";
}
PrdReportCrInput input = new PrdReportCrInput();
input.mo_task_code = prdMoTask.mo_task_code;
input.mo_task_id = prdMoTask.id;
input.reported_qty = num;
input.station = "";
input.material_box_code = carryCode;
await _prdMoTaskService.PrdReport(input);
return "true";
}
[HttpGet]
[AllowAnonymous]
public async Task<string> SendThirdApi(string thirdNmaes)
{
string[] thirdNameArr = thirdNmaes.Split("-");
List<ThirdWebapiRecord> records = await _db.Queryable<ThirdWebapiRecord>().Where(x => thirdNameArr.Contains(x.third_name) && x.status == 0 && x.is_send == 1).ToListAsync();
DateTime now = DateTime.Now;
Stopwatch stopwatch = null;
string response = "";
var elapsedMilliseconds = 0l;
ThirdResult thirdResult = new ThirdResult();
foreach (var record in records)
{
now = DateTime.Now;
stopwatch = Stopwatch.StartNew();
switch (record.method.ToUpper())
{
case "GET":
response = HttpUtils.RequestGet(record.url);
break;
case "POST":
response = HttpUtils.RequestPost(record.url, record.request_data);
break;
}
stopwatch.Stop();
elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
try
{
thirdResult = JsonConvert.DeserializeObject<ThirdResult>(response);
}
catch (Exception e)
{
thirdResult.Code = 500;
thirdResult.msgResult = response;
}
if (thirdResult.Code == 200)
{
await _db.Updateable<ThirdWebapiRecord>()
.SetColumns(x => x.response_data == response)
.SetColumns(x => x.response_code == thirdResult.Code)
.SetColumns(x => x.last_send_time == now)
.SetColumns(x => x.response_time == elapsedMilliseconds)
.SetColumns(x => x.send_type == "自动")
.SetColumns(x => x.status == 1)
.Where(x=>x.id==record.id)
.ExecuteCommandAsync();
}
else
{
await _db.Updateable<ThirdWebapiRecord>()
.SetColumns(x => x.response_data == response)
.SetColumns(x => x.response_code == thirdResult.Code)
.SetColumns(x => x.last_send_time == now)
.SetColumns(x => x.response_time == elapsedMilliseconds)
.Where(x=>x.id==record.id)
.ExecuteCommandAsync();
}
}
return "true";
}
}
}