269 lines
13 KiB
C#
269 lines
13 KiB
C#
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;
|
|
|
|
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 IOrganizeService _organizeService;
|
|
private readonly IBillRullService _billRullService;
|
|
private readonly RedisData _redisData;
|
|
private readonly IWmsEmptyOutstockService _wmsEmptyOutstockService;
|
|
|
|
public TimeWorkService(
|
|
RedisData redisData,
|
|
ISqlSugarRepository<BasMaterial> repository,
|
|
IBillRullService billRullService,
|
|
IOrganizeService organizeService,
|
|
IWmsEmptyOutstockService wmsEmptyOutstockService
|
|
)
|
|
{
|
|
_redisData = redisData;
|
|
_repository = repository;
|
|
_organizeService = organizeService;
|
|
_billRullService = billRullService;
|
|
_wmsEmptyOutstockService = wmsEmptyOutstockService;
|
|
}
|
|
|
|
[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 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");
|
|
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 = "";
|
|
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 = 1;
|
|
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 = "";
|
|
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 = 1;
|
|
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 = "";
|
|
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 = 1;
|
|
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_CS03_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 msg = "";
|
|
bool? value = await _redisData.TryGetValueByKeyField<bool?>("hxjC", "DB100.132.3");
|
|
bool valueFlag = _redisData.Get<bool>("hxjC_DB100.132.3_flag");
|
|
if (value==true && !valueFlag)
|
|
{
|
|
bool? cs01 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "CallCtuEmptyIn_CS01");
|
|
bool? cs03 = await _redisData.TryGetValueByKeyField<bool?>("YTCS", "CallCtuEmptyIn_CS03");
|
|
string startLocationCode = cs01==false ? "ZSSSXCTU01" : cs03==false ? "ZSSSXCTU02" : "";
|
|
if (startLocationCode.IsEmpty())
|
|
{
|
|
Log.Error($"输送线无空载具");
|
|
return "输送线无空载具";
|
|
}
|
|
|
|
var db = _repository.AsSugarClient();
|
|
BasLocation startLocation = await db.Queryable<BasLocation>().Where(x=>x.location_code==startLocationCode).FirstAsync();
|
|
EqpEquipment equipment = await db.Queryable<EqpEquipment>().Where(x=>x.code=="TYZS001").FirstAsync();
|
|
if (equipment == null)
|
|
{
|
|
Log.Error($"未找到设备编号为TYZS001的设备");
|
|
return "未找到设备编号为TYZS001的设备";
|
|
|
|
}
|
|
CommonCreatePretaskInput postData = new CommonCreatePretaskInput();
|
|
postData.startlocation_id = startLocation.id;
|
|
postData.endlocation_id = equipment.as_location_id;
|
|
postData.biz_type = WmsWareHouseConst.BIZTYPE_WMSDELIVERY_ID;
|
|
postData.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID;
|
|
Log.Information($"【FixedPointDelivery】注塑定点配送,参数:{JsonConvert.SerializeObject(postData)}");
|
|
BasFactoryConfig config = await db.Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN);
|
|
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(authResponse.code == 200 && authResponse.data.ObjToBool())
|
|
{
|
|
msg = "注塑定点配送成功";
|
|
Log.Information("【FixedPointDelivery】注塑定点配送成功");
|
|
//_redisData.Set("hxjC_DB100.132.3_flag", true, TimeSpan.FromMinutes(20));
|
|
}
|
|
else
|
|
{
|
|
msg = $"注塑定点配送失败:{authResponse.msg}";
|
|
Log.Error($"【FixedPointDelivery】注塑定点配送失败:{authResponse.msg}");
|
|
}
|
|
|
|
}
|
|
|
|
return msg;
|
|
}
|
|
|
|
}
|
|
} |