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.Entitys.System; 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; using Tnb.ProductionMgr.Entities.Entity; using Tnb.ProductionMgr.Entities.Entity.ErpEntity; 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 _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 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 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; } /// /// 注塑空载具出库 /// /// [HttpGet] [AllowAnonymous] public async Task EmptyCarryOutStk() { string state = await _redisData.TryGetValueByKeyField("YTCS", "State"); if ("OK" != state) return "YTCS没开机"; string result = ""; bool? cs01 = await _redisData.TryGetValueByKeyField("YTCS", "CallCtuEmptyIn_CS01"); bool? cs03 = await _redisData.TryGetValueByKeyField("YTCS", "CallCtuEmptyIn_CS03"); bool? cs06 = await _redisData.TryGetValueByKeyField("YTCS", "CallCtuEmptyIn_CS06"); // bool cs01Flag = _redisData.Get("YTCS_CallCtuEmptyIn_CS01_flag"); // bool cs03Flag = _redisData.Get("YTCS_CallCtuEmptyIn_CS03_flag"); // bool cs06Flag = _redisData.Get("YTCS_CallCtuEmptyIn_CS06_flag"); List statusList = new List(){WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID,WmsWareHouseConst.PRETASK_BILL_STATUS_YXF_ID,WmsWareHouseConst.PRETASK_BILL_STATUS_START_ID}; bool cs01Flag = await _db.Queryable().AnyAsync(x => x.endlocation_code == "SSX-021-001" && statusList.Contains(x.status) ); bool cs03Flag = await _db.Queryable().AnyAsync(x => x.endlocation_code == "SSX-021-003" && statusList.Contains(x.status) ); bool cs06Flag = await _db.Queryable().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().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(response); result += authResponse.data.ToString(); } if (cs03==true && !cs03Flag) { BasFactoryConfig config = await _repository.AsSugarClient().Queryable().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(response); result += authResponse.data.ToString(); } if (cs06==true && !cs06Flag) { BasFactoryConfig config = await _repository.AsSugarClient().Queryable().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(response); result += authResponse.data.ToString(); } return result; } [HttpGet] [AllowAnonymous] public async Task EmptyCarryOutStkCtu1() { string msg = ""; BasFactoryConfig config = await _db.Queryable().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 EmptyCarryOutStkCtu3() { string msg = ""; BasFactoryConfig config = await _db.Queryable().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 EmptyCarryOutStkCtu6() { string msg = ""; BasFactoryConfig config = await _db.Queryable().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 FixedPointDelivery() // { // string state = await _redisData.TryGetValueByKeyField("YTCS", "State"); // if ("OK" != state) // { // Log.Error($"TCS没开机"); // return "YTCS没开机"; // } // string stateHxja = await _redisData.TryGetValueByKeyField("hxjA", "State"); // string stateHxjc = await _redisData.TryGetValueByKeyField("hxjC", "State"); // List hxjList = new List(); // 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 equipments = await _db.Queryable() // .InnerJoin((x, y) => x.id == y.equip_type_id) // .Where((x, y) => x.code == "ZSJ") // .Select((x, y) => y).ToListAsync(); // // int? cs01Count = await _redisData.TryGetValueByKeyField("YTCS", "EmptyNo_CS01"); // int? cs03Count = await _redisData.TryGetValueByKeyField("YTCS", "EmptyNo_CS03"); // // List eqpIds = equipments.Select(x => x.id).ToList(); // List eqpDaqs = await _db.Queryable().Where(x => eqpIds.Contains(x.equip_id) && x.label_name.Contains("允许入空箱")).ToListAsync(); // //BasFactoryConfig config = await _db.Queryable().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().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(eqpDaq.equip_code, eqpDaq.label_name); // bool valueFlag = _redisData.Get($"{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("YTCS", "AllowAgvEmptyOut_CS01"); // bool? cs03 = await _redisData.TryGetValueByKeyField("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("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().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(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 FixedPointDelivery() { string state = await _redisData.TryGetValueByKeyField("YTCS", "State"); if ("OK" != state) { Log.Error($"TCS没开机"); return "YTCS没开机"; } string stateHxja = await _redisData.TryGetValueByKeyField("hxjA", "State"); string stateHxjc = await _redisData.TryGetValueByKeyField("hxjC", "State"); List hxjList = new List(); 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 equipments = await _db.Queryable() .InnerJoin((x, y) => x.id == y.equip_type_id) .Where((x, y) => x.code == "ZSJ") .Select((x, y) => y).ToListAsync(); int cs01Count = await _redisData.TryGetValueByKeyField("YTCS", "EmptyNo_CS01"); int cs03Count = await _redisData.TryGetValueByKeyField("YTCS", "EmptyNo_CS03"); Log.Information($"注塑定点配送cs01数量:{cs01Count},cs03数量:{cs03Count}"); List eqpIds = equipments.Select(x => x.id).ToList(); List eqpDaqs = await _db.Queryable().Where(x => eqpIds.Contains(x.equip_id) && x.label_name.Contains("允许入空箱")).ToListAsync(); //BasFactoryConfig config = await _db.Queryable().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().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(eqpDaq.equip_code, eqpDaq.label_name); bool valueFlag = _redisData.Get($"{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("YTCS", "AllowAgvEmptyOut_CS01"); bool? cs03 = await _redisData.TryGetValueByKeyField("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("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().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(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 AutoPrdReport() { BasFactoryConfig config = await _repository.AsSugarClient().Queryable().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN); bool qu1 = await _redisData.TryGetValueByKeyField("外包装箱码垛线", "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("外包装箱码垛线", "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 X1AutoPrdReport() { string carryCode = await _redisData.TryGetValueByKeyField("外包装箱码垛线", "WBZX_x1_take_tp"); int num = await _redisData.TryGetValueByKeyField("外包装箱码垛线", "WBZX_x1_Enquantity"); if (string.IsNullOrEmpty(carryCode) || num<=0) { Log.Information("血路管1线无载具或数量为0"); return "无载具或数量为0"; } PrdMoTask prdMoTask = await _db.Queryable().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 X2AutoPrdReport() { string carryCode = await _redisData.TryGetValueByKeyField("外包装箱码垛线", "WBZX_x2_take_tp"); int num = await _redisData.TryGetValueByKeyField("外包装箱码垛线", "WBZX_x2_Enquantity"); if (string.IsNullOrEmpty(carryCode) || num<=0) { Log.Information("血路管2线无载具或数量为0"); return "无载具或数量为0"; } PrdMoTask prdMoTask = await _db.Queryable().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 SendThirdApi(string thirdNmaes) { string[] thirdNameArr = thirdNmaes.Split("-"); List records = await _db.Queryable().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(response); } catch (Exception e) { thirdResult.Code = 500; thirdResult.msgResult = response; } if (thirdResult.Code == 200) { await _db.Updateable() .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() .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"; } /// /// 同步基础数据 /// /// [HttpGet] [AllowAnonymous] public async Task SyncBaseData() { var mysqlDb = _db.AsTenant().GetConnection("erpdb"); List list = await mysqlDb.Queryable().ToListAsync(); List erpExtendFields = await _db.Queryable().ToListAsync(); List materials = await _db.Queryable().ToListAsync(); List insertMaterial = new List(); List insertExtendFields = new List(); foreach (ErpBdMaterial erpBdMaterial in list) { if (erpExtendFields.All(x => x.cmaterialoid != erpBdMaterial.ID)) { insertMaterial.Add(new BasMaterial() { id = SnowflakeIdHelper.NextId(), name = erpBdMaterial.NAME, code = erpBdMaterial.CODE, org_id = WmsWareHouseConst.AdministratorOrgId, material_specification = erpBdMaterial.MATERIALSPEC, material_standard = erpBdMaterial.MATERIALTYPE }); } } return "true"; } /// /// 同步单位 /// /// [HttpGet] [AllowAnonymous] public async Task SyncUnit() { // var mysqlDb = _db.AsTenant().GetConnection("erpdb"); // List list = await mysqlDb.Queryable().ToListAsync(); // List erpExtendFields = await _db.Queryable().ToListAsync(); // List insertMaterial = new List(); // List insertExtendFields = new List(); // foreach (ErpBdMaterial erpBdMaterial in list) // { // if (erpExtendFields.All(x => x.cmaterialoid != erpBdMaterial.ID)) // { // insertMaterial.Add(new BasMaterial() // { // id = SnowflakeIdHelper.NextId(), // name = erpBdMaterial.NAME, // code = erpBdMaterial.CODE, // org_id = WmsWareHouseConst.AdministratorOrgId, // material_specification = erpBdMaterial.MATERIALSPEC, // material_standard = erpBdMaterial.MATERIALTYPE // }); // } // } return "true"; } } }