signalr 取消,长时间会有问题,打开浏览器会白屏
对接erp,接口 线边任务完成根据detailid,分入库 出库报工 todo 成品的报工(定时器回传 or 入库/拣货的时候回传)
This commit is contained in:
1 parent
00119151c9
commit
c3ec557c4d
19 files changed
+371
-330
No files matched your search
@@ -131,7 +131,7 @@ namespace HHWMS.Web
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return ApiResultError(msg:res.Message);
|
return ApiResultError(msg: res.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +149,7 @@ namespace HHWMS.Web
|
|||||||
{
|
{
|
||||||
return ApiResultError(msg: "未找到任务!");
|
return ApiResultError(msg: "未找到任务!");
|
||||||
}
|
}
|
||||||
|
|
||||||
//1. 更新容器
|
//1. 更新容器
|
||||||
var container = _unitWork.FindSingle<Container>(x => x.Code == task.ContainerCode);
|
var container = _unitWork.FindSingle<Container>(x => x.Code == task.ContainerCode);
|
||||||
container.UpdateBy = "EmptyOut";
|
container.UpdateBy = "EmptyOut";
|
||||||
@@ -173,7 +174,7 @@ namespace HHWMS.Web
|
|||||||
_unitWork.Delete(task);
|
_unitWork.Delete(task);
|
||||||
|
|
||||||
//4. 更新库存
|
//4. 更新库存
|
||||||
_unitWork.BatchUpdate<Inventory>(x => x.ContainerCode == task.ContainerCode,x => new Inventory()
|
_unitWork.BatchUpdate<Inventory>(x => x.ContainerCode == task.ContainerCode, x => new Inventory()
|
||||||
{
|
{
|
||||||
LocationCode = "空出",
|
LocationCode = "空出",
|
||||||
UpdateBy = "EmptyOut",
|
UpdateBy = "EmptyOut",
|
||||||
@@ -196,6 +197,7 @@ namespace HHWMS.Web
|
|||||||
{
|
{
|
||||||
return ApiResultError(msg: "未找到任务!");
|
return ApiResultError(msg: "未找到任务!");
|
||||||
}
|
}
|
||||||
|
|
||||||
var outLoc = _unitWork.FindSingle<Location>(x => x.Code == task.FromLocation);
|
var outLoc = _unitWork.FindSingle<Location>(x => x.Code == task.FromLocation);
|
||||||
var outTask = _unitWork.FindSingle<TaskHeader>(x => x.FromLocation == outLoc.ContiguousCode);
|
var outTask = _unitWork.FindSingle<TaskHeader>(x => x.FromLocation == outLoc.ContiguousCode);
|
||||||
if (outTask != null)
|
if (outTask != null)
|
||||||
@@ -244,6 +246,7 @@ namespace HHWMS.Web
|
|||||||
|
|
||||||
return ApiResult();
|
return ApiResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 状态返回(带防抖)
|
/// 状态返回(带防抖)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -307,7 +310,7 @@ namespace HHWMS.Web
|
|||||||
request.RoadWay = 2;
|
request.RoadWay = 2;
|
||||||
|
|
||||||
// 默认1 模具2 低仓位3 高仓位4 成品大于4 超限 模具大于2 超限
|
// 默认1 模具2 低仓位3 高仓位4 成品大于4 超限 模具大于2 超限
|
||||||
if(request.Height == 2)
|
if (request.Height == 2)
|
||||||
request.Height = 999;
|
request.Height = 999;
|
||||||
else if (request.Height == 3)
|
else if (request.Height == 3)
|
||||||
request.Height = 1100;
|
request.Height = 1100;
|
||||||
@@ -331,6 +334,7 @@ namespace HHWMS.Web
|
|||||||
{
|
{
|
||||||
return ApiResultError(msg: "模具超高,未找到合适的仓位");
|
return ApiResultError(msg: "模具超高,未找到合适的仓位");
|
||||||
}
|
}
|
||||||
|
|
||||||
var location = locationVm.GetLocation(request).Data;
|
var location = locationVm.GetLocation(request).Data;
|
||||||
if (location != null)
|
if (location != null)
|
||||||
{
|
{
|
||||||
@@ -382,40 +386,67 @@ namespace HHWMS.Web
|
|||||||
{
|
{
|
||||||
var containerconfig = _unitWork.Find<SysDictData>(x => x.DictType == "ContainerConfig")
|
var containerconfig = _unitWork.Find<SysDictData>(x => x.DictType == "ContainerConfig")
|
||||||
.ToList();
|
.ToList();
|
||||||
int ContainerWeight = int.Parse(containerconfig.FirstOrDefault(x => x.DictLabelUs.ToLower() == "container")?.DictValue);
|
int ContainerWeight = int.Parse(containerconfig
|
||||||
int SmallContainerWeight = int.Parse(containerconfig.FirstOrDefault(x => x.ID == inventory.Flag)?.DictValue);
|
.FirstOrDefault(x => x.DictLabelUs.ToLower() == "container")?.DictValue);
|
||||||
|
int SmallContainerWeight =
|
||||||
|
int.Parse(containerconfig.FirstOrDefault(x => x.ID == inventory.Flag)?.DictValue);
|
||||||
|
|
||||||
var material =
|
var material =
|
||||||
_unitWork.FindSingle<Material>(x => x.MaterialCode == inventory.MaterialCode);
|
_unitWork.FindSingle<Material>(x => x.MaterialCode == inventory.MaterialCode);
|
||||||
inventory.Qty = (int)((request.Weight * 100 - ContainerWeight - inventory.TaskQty * SmallContainerWeight) / (material.Qty ?? 1));
|
inventory.Qty =
|
||||||
|
(int)((request.Weight * 100 - ContainerWeight -
|
||||||
|
inventory.TaskQty * SmallContainerWeight) / (material.Qty ?? 1));
|
||||||
inventory.Qty = inventory.Qty > 0 ? inventory.Qty : 0;
|
inventory.Qty = inventory.Qty > 0 ? inventory.Qty : 0;
|
||||||
|
}
|
||||||
|
|
||||||
// ERP相关
|
if (!string.IsNullOrEmpty(inventory.ReceiptDetailId))
|
||||||
|
{
|
||||||
|
// ERP相关 入库报工
|
||||||
var finishInRequest = new FinishInRequest
|
var finishInRequest = new FinishInRequest
|
||||||
{
|
{
|
||||||
Main = new FinishInMain
|
Main = new FinishInMain
|
||||||
{
|
{
|
||||||
ErpCode = "999", // 账套号
|
ErpCode = "002", // 账套号
|
||||||
InCode = _unitWork.GetSerialNumber(inventory.SourceCode), // 报工单号(上游单号)
|
InCode = _unitWork.GetSerialNumber("RW"), // 报工单号(上游单号)
|
||||||
InDate = (inventory.CreateTime ?? DateTime.Now).ToString("yyyy-MM-dd"), // 报工日期
|
InDate = (inventory.CreateTime ?? DateTime.Now)
|
||||||
StepCode = inventory.BatchCode, // 工序(批次编码)
|
.ToString("yyyy-MM-dd"), // 报工日期
|
||||||
WorkerCode = inventory.CreateBy, // 工人编码(创建人)
|
StepCode = inventory.BatchCode, // 工序(批次编码)
|
||||||
|
WorkerCode = inventory.CreateBy, // 工人编码(创建人)
|
||||||
Maker = _unitWork.FindSingle<FrameworkUser>(x =>
|
Maker = _unitWork.FindSingle<FrameworkUser>(x =>
|
||||||
x.ITCode == inventory.CreateBy).Name // 制单人(校验员)
|
x.ITCode == inventory.CreateBy).Name // 制单人(校验员)
|
||||||
},
|
},
|
||||||
Details = new List<FinishInDetail>()
|
Details = new List<FinishInDetail>()
|
||||||
};
|
};
|
||||||
|
if (task.TaskType == TaskTypeEnum.入库)
|
||||||
// 根据库存构建明细
|
|
||||||
finishInRequest.Details.Add(new FinishInDetail
|
|
||||||
{
|
{
|
||||||
MoDetailId = inventory.ReceiptDetailId, // 生产订单明细(ERP明细ID)
|
// 根据库存构建明细
|
||||||
InvCode = inventory.MaterialCode, // 物料号
|
finishInRequest.Details.Add(new FinishInDetail
|
||||||
Qty = inventory.Qty ?? 0 // 完工数量
|
{
|
||||||
});
|
MoDetailId = inventory.ReceiptDetailId, // 生产订单明细(ERP明细ID)
|
||||||
|
InvCode = inventory.MaterialCode, // 物料号
|
||||||
|
Qty = inventory.Qty ?? 0 // 完工数量
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (task.TaskType == TaskTypeEnum.出库)
|
||||||
|
{
|
||||||
|
finishInRequest.Details.Add(new FinishInDetail
|
||||||
|
{
|
||||||
|
MaterialDetails = new List<MaterialDetail>
|
||||||
|
{
|
||||||
|
new MaterialDetail
|
||||||
|
{
|
||||||
|
MoDetailId = inventory.ReceiptDetailId, // 生产订单明细ID
|
||||||
|
InvCode = inventory.MaterialCode, // 物料号
|
||||||
|
Qty = (decimal)inventory.Qty // 完工数量(空值兜底为0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 调用ERP接口
|
// 调用ERP接口
|
||||||
var apiResult = await Wtm.CallAPI<FinishInResponse>("ERP", "FinishIn", HttpMethodEnum.POST, finishInRequest);
|
var apiResult = await Wtm.CallAPI<FinishInResponse>("ERP", "FinishIn",
|
||||||
|
HttpMethodEnum.POST,
|
||||||
|
finishInRequest);
|
||||||
|
|
||||||
if (apiResult.Data != null && apiResult.Data.Result)
|
if (apiResult.Data != null && apiResult.Data.Result)
|
||||||
{
|
{
|
||||||
@@ -427,6 +458,7 @@ namespace HHWMS.Web
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (task.TaskType != TaskTypeEnum.移库)
|
if (task.TaskType != TaskTypeEnum.移库)
|
||||||
{
|
{
|
||||||
// 创建库存交易记录 放到任务完成,计算数量信息
|
// 创建库存交易记录 放到任务完成,计算数量信息
|
||||||
@@ -567,7 +599,6 @@ namespace HHWMS.Web
|
|||||||
|
|
||||||
#region 暂时无用
|
#region 暂时无用
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求入库(带防抖)
|
/// 请求入库(带防抖)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
<wt:row items-per-row="ItemsPerRowEnum.Two">
|
<wt:row items-per-row="ItemsPerRowEnum.Two">
|
||||||
<wt:textbox field="Entity.MaterialCode" disabled/>
|
<wt:textbox field="Entity.MaterialCode" disabled/>
|
||||||
<wt:textbox field="Entity.MaterialType" disabled/>
|
<wt:textbox field="Entity.MaterialType" disabled/>
|
||||||
<wt:textbox field="Entity.MaterialName" />
|
<wt:textbox field="Entity.MaterialName" disabled/>
|
||||||
<wt:textbox field="Entity.MaterialSpec" />
|
<wt:textbox field="Entity.MaterialSpec" disabled/>
|
||||||
<wt:textbox field="Entity.MaterialUnit" />
|
<wt:textbox field="Entity.MaterialUnit" disabled/>
|
||||||
<wt:textbox field="Entity.Batch" />
|
<wt:textbox field="Entity.Batch" />
|
||||||
<wt:textbox field="Entity.Lot" />
|
<wt:textbox field="Entity.Lot" />
|
||||||
<wt:textbox field="Entity.CompanyCode" />
|
<wt:textbox field="Entity.CompanyCode" />
|
||||||
<wt:textbox field="Entity.SupplierCode" />
|
<wt:textbox field="Entity.SupplierCode" disabled/>
|
||||||
<wt:textbox field="Entity.Qty" />
|
<wt:textbox field="Entity.Qty" />
|
||||||
</wt:row>
|
</wt:row>
|
||||||
<wt:hidden field="Entity.ID" />
|
<wt:hidden field="Entity.ID" />
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using WalkingTec.Mvvm.Core;
|
||||||
|
using WalkingTec.Mvvm.Core.Extensions;
|
||||||
|
using WalkingTec.Mvvm.Mvc;
|
||||||
|
using HHWMS.Web;
|
||||||
|
using HHWMS.Web.Models;
|
||||||
|
|
||||||
|
|
||||||
|
namespace HHWMS.Web.Controllers
|
||||||
|
{
|
||||||
|
[Area("inventory")]
|
||||||
|
[Public]
|
||||||
|
[ActionDescription("库存管理")]
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/Inventory")]
|
||||||
|
public partial class InventoryApiController : BaseApiController
|
||||||
|
{
|
||||||
|
[ActionDescription("Sys.Search")]
|
||||||
|
[HttpPost("Search")]
|
||||||
|
[Public]
|
||||||
|
public IActionResult Search(InventoryApiSearcher searcher)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var vm = Wtm.CreateVM<InventoryApiListVM>(passInit: true);
|
||||||
|
searcher.SortInfo = new SortInfo()
|
||||||
|
{
|
||||||
|
Property = "MaterialCode",
|
||||||
|
Direction = SortDir.Asc
|
||||||
|
};
|
||||||
|
searcher.IsPlainText = false;
|
||||||
|
searcher.IsEnumToString = true;
|
||||||
|
vm.Searcher = searcher;
|
||||||
|
|
||||||
|
if (searcher.WareHouse.ToLower() == "mj")
|
||||||
|
vm.Searcher.ZoneId = 1025;
|
||||||
|
else if (searcher.WareHouse.ToLower() == "xb")
|
||||||
|
vm.Searcher.ZoneId = 1027;
|
||||||
|
else if (searcher.WareHouse.ToLower() == "cp")
|
||||||
|
vm.Searcher.ZoneId = 1028;
|
||||||
|
|
||||||
|
var data = vm.GetJson();
|
||||||
|
return Content(data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return BadRequest(ModelState.GetErrorJson());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -549,6 +549,10 @@ namespace HHWMS.Web.Controllers
|
|||||||
{
|
{
|
||||||
return FFResult().Alert("所选库存没关联订单,无需回传!").RefreshGrid();
|
return FFResult().Alert("所选库存没关联订单,无需回传!").RefreshGrid();
|
||||||
}
|
}
|
||||||
|
if (inv.UploadErpFlag == 0)
|
||||||
|
{
|
||||||
|
return FFResult().Alert("所选库存已报工回传,无需再次回传!").RefreshGrid();
|
||||||
|
}
|
||||||
|
|
||||||
// 构建ERP请求
|
// 构建ERP请求
|
||||||
// 字段映射参照 ReceiptInController:
|
// 字段映射参照 ReceiptInController:
|
||||||
@@ -562,8 +566,8 @@ namespace HHWMS.Web.Controllers
|
|||||||
{
|
{
|
||||||
Main = new FinishInMain
|
Main = new FinishInMain
|
||||||
{
|
{
|
||||||
ErpCode = "999", // 账套号
|
ErpCode = "002", // 账套号
|
||||||
InCode = $"{inv.SourceCode}-{DateTime.Now.Ticks}", // 报工单号(上游单号)
|
InCode = _unitWork.GetSerialNumber("RW"), // 报工单号(上游单号)
|
||||||
InDate = (inv.CreateTime ?? DateTime.Now).ToString("yyyy-MM-dd"), // 报工日期
|
InDate = (inv.CreateTime ?? DateTime.Now).ToString("yyyy-MM-dd"), // 报工日期
|
||||||
StepCode = inv.BatchCode, // 工序(批次编码)
|
StepCode = inv.BatchCode, // 工序(批次编码)
|
||||||
WorkerCode = inv.CreateBy, // 工人编码(创建人)
|
WorkerCode = inv.CreateBy, // 工人编码(创建人)
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WalkingTec.Mvvm.Core;
|
||||||
|
using WalkingTec.Mvvm.Core.Extensions;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using HHWMS.Web.Models;
|
||||||
|
|
||||||
|
|
||||||
|
namespace HHWMS.Web
|
||||||
|
{
|
||||||
|
public partial class InventoryApiListVM : BasePagedListVM<InventoryApi_View, InventoryApiSearcher>
|
||||||
|
{
|
||||||
|
|
||||||
|
protected override IEnumerable<IGridColumn<InventoryApi_View>> InitGridHeader()
|
||||||
|
{
|
||||||
|
return new List<GridColumn<InventoryApi_View>>{
|
||||||
|
this.MakeGridHeader(x => x.WareHouse),
|
||||||
|
this.MakeGridHeader(x => x.MaterialCode),
|
||||||
|
this.MakeGridHeader(x => x.FigureNo),
|
||||||
|
this.MakeGridHeader(x => x.MaterialName),
|
||||||
|
this.MakeGridHeader(x => x.MaterialSpec),
|
||||||
|
this.MakeGridHeader(x => x.BatchCode),
|
||||||
|
this.MakeGridHeader(x => x.SuFigureNo),
|
||||||
|
this.MakeGridHeader(x => x.Qty),
|
||||||
|
this.MakeGridHeaderAction(width: 200)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IOrderedQueryable<InventoryApi_View> GetSearchQuery()
|
||||||
|
{
|
||||||
|
var query = DC.Set<Inventory>()
|
||||||
|
.Where(x => x.ZoneId == Searcher.ZoneId)
|
||||||
|
.CheckContain(Searcher.MaterialCode, x=>x.MaterialCode)
|
||||||
|
.CheckContain(Searcher.FigureNo, x=>x.MaterialType)
|
||||||
|
.CheckContain(Searcher.MaterialName, x=>x.MaterialName)
|
||||||
|
.CheckContain(Searcher.MaterialSpec, x=>x.MaterialSpec)
|
||||||
|
.CheckContain(Searcher.BatchCode, x=>x.BatchCode)
|
||||||
|
.CheckContain(Searcher.SuFigureNo, x=>x.SupplierCode)
|
||||||
|
.Select(x => new InventoryApi_View
|
||||||
|
{
|
||||||
|
WareHouse = x.ZoneId == 1027 ? "xb" : x.ZoneId == 1028 ? "cp" : "mj" ,
|
||||||
|
MaterialCode = x.MaterialCode,
|
||||||
|
FigureNo = x.MaterialType,
|
||||||
|
MaterialName = x.MaterialName,
|
||||||
|
MaterialSpec = x.MaterialSpec,
|
||||||
|
BatchCode = x.BatchCode,
|
||||||
|
SuFigureNo = x.SupplierCode,
|
||||||
|
LocationCode = x.LocationCode,
|
||||||
|
Qty = x.Qty,
|
||||||
|
}).OrderBy(x => x.MaterialCode);
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class InventoryApi_View : TopBasePoco {
|
||||||
|
public String WareHouse { get; set; }
|
||||||
|
public string MaterialCode { get; set; }
|
||||||
|
public string MaterialName { get; set; }
|
||||||
|
public string MaterialSpec { get; set; }
|
||||||
|
public string BatchCode { get; set; }
|
||||||
|
public string SuFigureNo { get; set; }
|
||||||
|
public string FigureNo { get; set; }
|
||||||
|
public string LocationCode { get; set; }
|
||||||
|
public decimal? Qty { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using WalkingTec.Mvvm.Core;
|
||||||
|
using WalkingTec.Mvvm.Core.Extensions;
|
||||||
|
using HHWMS.Web.Models;
|
||||||
|
|
||||||
|
|
||||||
|
namespace HHWMS.Web
|
||||||
|
{
|
||||||
|
public partial class InventoryApiSearcher : BaseSearcher
|
||||||
|
{
|
||||||
|
public int ZoneId { get; set; }
|
||||||
|
[Display(Name = "Inventory.MaterialCode")]
|
||||||
|
public String MaterialCode { get; set; }
|
||||||
|
[Display(Name = "Inventory.MaterialType")]
|
||||||
|
public String FigureNo { get; set; }
|
||||||
|
[Display(Name = "Inventory.MaterialName")]
|
||||||
|
public String MaterialName { get; set; }
|
||||||
|
[Display(Name = "Inventory.MaterialSpec")]
|
||||||
|
public String MaterialSpec { get; set; }
|
||||||
|
[Display(Name = "Inventory.Batch")]
|
||||||
|
public String BatchCode { get; set; }
|
||||||
|
[Display(Name = "Inventory.SupplierCode")]
|
||||||
|
public String SuFigureNo { get; set; }
|
||||||
|
public String WareHouse { get; set; }
|
||||||
|
|
||||||
|
protected override void InitVM()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,6 +40,10 @@ namespace HHWMS.Web
|
|||||||
[Display(Name = "Inventory.TaskStatus")]
|
[Display(Name = "Inventory.TaskStatus")]
|
||||||
public InventoryTaskStatusEnum? TaskStatus { get; set; }
|
public InventoryTaskStatusEnum? TaskStatus { get; set; }
|
||||||
|
|
||||||
|
public string SupplierCode { get; set; }
|
||||||
|
public string BatchCode { get; set; }
|
||||||
|
public string MaterialSpec { get; set; }
|
||||||
|
|
||||||
protected override void InitVM()
|
protected override void InitVM()
|
||||||
{
|
{
|
||||||
AllZones = DC.Set<LocationZone>().GetSelectListItems(Wtm, y => y.Name);
|
AllZones = DC.Set<LocationZone>().GetSelectListItems(Wtm, y => y.Name);
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ namespace HHWMS.Web.Controllers
|
|||||||
// 调用 ERP 接口获取该订单的最新数据
|
// 调用 ERP 接口获取该订单的最新数据
|
||||||
var request = new LoadMoDetailListRequest
|
var request = new LoadMoDetailListRequest
|
||||||
{
|
{
|
||||||
ErpCode = "999",
|
ErpCode = "002",
|
||||||
MoCode = receiptCode, // 使用生产订单号查询
|
MoCode = receiptCode, // 使用生产订单号查询
|
||||||
Size = 100,
|
Size = 100,
|
||||||
Page = 1
|
Page = 1
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace HHWMS.Web.Controllers
|
|||||||
{
|
{
|
||||||
var request = new LoadInventoryRequest
|
var request = new LoadInventoryRequest
|
||||||
{
|
{
|
||||||
ErpCode = "999",
|
ErpCode = "002",
|
||||||
InvDefine1 = keyword,
|
InvDefine1 = keyword,
|
||||||
Size = 15,
|
Size = 15,
|
||||||
Page = 1
|
Page = 1
|
||||||
@@ -185,7 +185,8 @@ namespace HHWMS.Web.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public IActionResult GetOperators()
|
public IActionResult GetOperators()
|
||||||
{
|
{
|
||||||
var users = _unitWork.Find<FrameworkUser>(x => x.ITCode != "Admin")
|
var users = _unitWork.Find<FrameworkUser>(x => x.ITCode != "Admin"
|
||||||
|
&& x.ITCode.Length > 5)
|
||||||
.Select(x => new
|
.Select(x => new
|
||||||
{
|
{
|
||||||
value = x.ITCode,
|
value = x.ITCode,
|
||||||
@@ -443,13 +444,13 @@ namespace HHWMS.Web.Controllers
|
|||||||
// 调用WCS任务下发接口
|
// 调用WCS任务下发接口
|
||||||
// tran.Commit();
|
// tran.Commit();
|
||||||
// return Json(new { Code = 200, Msg = "入库成功", Data = new { TaskNo = taskNo } });
|
// return Json(new { Code = 200, Msg = "入库成功", Data = new { TaskNo = taskNo } });
|
||||||
// var wcsResult = Wtm
|
var wcsResult = Wtm
|
||||||
// .CallAPI<WCSTaskResponse>("WCSXB", "TaskAssign", HttpMethodEnum.POST, wcsTaskModel).Result.Data;
|
.CallAPI<WCSTaskResponse>("WCSXB", "TaskAssign", HttpMethodEnum.POST, wcsTaskModel).Result.Data;
|
||||||
var wcsResult = new WCSTaskResponse()
|
// var wcsResult = new WCSTaskResponse()
|
||||||
{
|
// {
|
||||||
Success = true,
|
// Success = true,
|
||||||
Msg = "Success"
|
// Msg = "Success"
|
||||||
};
|
// };
|
||||||
if (wcsResult != null && wcsResult.Success)
|
if (wcsResult != null && wcsResult.Success)
|
||||||
{
|
{
|
||||||
// WCS任务下发成功,提交事务
|
// WCS任务下发成功,提交事务
|
||||||
|
|||||||
@@ -191,7 +191,8 @@ namespace HHWMS.Web.Controllers
|
|||||||
BatchCode = batchCode,
|
BatchCode = batchCode,
|
||||||
TaskStatus = InventoryTaskStatusEnum.Locked,
|
TaskStatus = InventoryTaskStatusEnum.Locked,
|
||||||
CreateTime = DateTime.Now,
|
CreateTime = DateTime.Now,
|
||||||
CreateBy = Wtm.LoginUserInfo.ITCode
|
CreateBy = Wtm.LoginUserInfo.ITCode,
|
||||||
|
UploadErpFlag = 0
|
||||||
};
|
};
|
||||||
_unitWork.Add(inventory);
|
_unitWork.Add(inventory);
|
||||||
|
|
||||||
|
|||||||
@@ -33,17 +33,17 @@ namespace HHWMS.Web
|
|||||||
//this.MakeGridHeader(x => x.Code_view),
|
//this.MakeGridHeader(x => x.Code_view),
|
||||||
//this.MakeGridHeader(x => x.ZoneCode),
|
//this.MakeGridHeader(x => x.ZoneCode),
|
||||||
this.MakeGridHeader(x => x.MaterialCode),
|
this.MakeGridHeader(x => x.MaterialCode),
|
||||||
//this.MakeGridHeader(x => x.MaterialType),
|
this.MakeGridHeader(x => x.MaterialType),
|
||||||
|
// this.MakeGridHeader(x => x.Batch),
|
||||||
this.MakeGridHeader(x => x.MaterialName),
|
this.MakeGridHeader(x => x.MaterialName),
|
||||||
//this.MakeGridHeader(x => x.MaterialSpec),
|
//this.MakeGridHeader(x => x.MaterialSpec),
|
||||||
this.MakeGridHeader(x => x.MaterialUnit),
|
this.MakeGridHeader(x => x.MaterialUnit),
|
||||||
this.MakeGridHeader(x => x.Batch),
|
|
||||||
//this.MakeGridHeader(x => x.Lot).SetHide(),
|
//this.MakeGridHeader(x => x.Lot).SetHide(),
|
||||||
//this.MakeGridHeader(x => x.ManufactureDate),
|
//this.MakeGridHeader(x => x.ManufactureDate),
|
||||||
//this.MakeGridHeader(x => x.ExpirationDate),
|
//this.MakeGridHeader(x => x.ExpirationDate),
|
||||||
//this.MakeGridHeader(x => x.CompanyCode),
|
//this.MakeGridHeader(x => x.CompanyCode),
|
||||||
this.MakeGridHeader(x => x.SupplierCode),
|
this.MakeGridHeader(x => x.SupplierCode),
|
||||||
this.MakeGridHeader(x => x.CompletedQty),
|
// this.MakeGridHeader(x => x.CompletedQty),
|
||||||
this.MakeGridHeader(x => x.Qty),
|
this.MakeGridHeader(x => x.Qty),
|
||||||
//this.MakeGridHeader(x => x.InventoryStatus),
|
//this.MakeGridHeader(x => x.InventoryStatus),
|
||||||
this.MakeGridHeader(x => x.Status)
|
this.MakeGridHeader(x => x.Status)
|
||||||
|
|||||||
@@ -38,12 +38,12 @@ namespace HHWMS.Web
|
|||||||
{
|
{
|
||||||
InitVM();
|
InitVM();
|
||||||
return new List<GridColumn<ReceiptHeader_View>>{
|
return new List<GridColumn<ReceiptHeader_View>>{
|
||||||
//this.MakeGridHeader(x => x.SourceCode),
|
|
||||||
this.MakeGridHeader(x => x.Code).SetFormat((a,b) =>
|
this.MakeGridHeader(x => x.Code).SetFormat((a,b) =>
|
||||||
{
|
{
|
||||||
string rv = UIService.MakeScriptButton(ButtonTypesEnum.Link,a.Code,$"details('{a.ID}')");
|
string rv = UIService.MakeScriptButton(ButtonTypesEnum.Link,a.Code,$"details('{a.ID}')");
|
||||||
return rv;
|
return rv;
|
||||||
}),
|
}),
|
||||||
|
this.MakeGridHeader(x => x.SourceCode),
|
||||||
this.MakeGridHeader(x => x.BillType)
|
this.MakeGridHeader(x => x.BillType)
|
||||||
.SetFormat((a, b) =>
|
.SetFormat((a, b) =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,7 +75,7 @@
|
|||||||
<template #operations="{ record }">
|
<template #operations="{ record }">
|
||||||
<a-space>
|
<a-space>
|
||||||
<a-button type="text" status="danger" @@click="handleDelete(record)">删除</a-button>
|
<a-button type="text" status="danger" @@click="handleDelete(record)">删除</a-button>
|
||||||
<a-button type="text" @@click="handleEdit(record)">修改</a-button>
|
@* <a-button type="text" @@click="handleEdit(record)">修改</a-button> *@
|
||||||
<a-button type="text" @@click="handleDeduct(record)">扣料</a-button>
|
<a-button type="text" @@click="handleDeduct(record)">扣料</a-button>
|
||||||
</a-space>
|
</a-space>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using HHWMS.Web.Models;
|
||||||
|
using Quartz;
|
||||||
|
using WalkingTec.Mvvm.Core;
|
||||||
|
using WalkingTec.Mvvm.Core.Support.Quartz;
|
||||||
|
|
||||||
|
namespace HHWMS.Web
|
||||||
|
{
|
||||||
|
//[QuartzRepeat(10,10, true, 30)]
|
||||||
|
[PersistJobDataAfterExecution]
|
||||||
|
[DisallowConcurrentExecution]
|
||||||
|
public class FinishInJob : WtmJob
|
||||||
|
{
|
||||||
|
public override async Task Execute(IJobExecutionContext context)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var _unitwork = new UnitWork(Wtm);
|
||||||
|
|
||||||
|
var inv = _unitwork.FindSingle<Inventory>(x => x.UploadErpFlag == 0
|
||||||
|
&& x.TaskStatus != InventoryTaskStatusEnum.Locked
|
||||||
|
&& !string.IsNullOrEmpty(x.SourceCode)
|
||||||
|
);
|
||||||
|
|
||||||
|
var request = new FinishInRequest
|
||||||
|
{
|
||||||
|
Main = new FinishInMain
|
||||||
|
{
|
||||||
|
ErpCode = "002", // 账套号
|
||||||
|
InCode = _unitwork.GetSerialNumber("RW"), // 报工单号(上游单号)
|
||||||
|
InDate = (inv.CreateTime ?? DateTime.Now).ToString("yyyy-MM-dd"), // 报工日期
|
||||||
|
StepCode = inv.BatchCode, // 工序(批次编码)
|
||||||
|
WorkerCode = inv.CreateBy, // 工人编码(创建人)
|
||||||
|
Maker = _unitwork.FindSingle<FrameworkUser>(x =>
|
||||||
|
x.ITCode == inv.CreateBy).Name // 制单人(校验员)
|
||||||
|
},
|
||||||
|
Details = new List<FinishInDetail>()
|
||||||
|
};
|
||||||
|
|
||||||
|
// 根据库存构建明细
|
||||||
|
request.Details.Add(new FinishInDetail
|
||||||
|
{
|
||||||
|
MoDetailId = inv.ReceiptDetailId, // 生产订单明细(ERP明细ID)
|
||||||
|
InvCode = inv.MaterialCode, // 物料号
|
||||||
|
Qty = inv.Qty ?? 0 // 完工数量
|
||||||
|
});
|
||||||
|
// 调用ERP接口
|
||||||
|
var apiResult = await Wtm.CallAPI<FinishInResponse>("ERP", "FinishIn", HttpMethodEnum.POST, request);
|
||||||
|
|
||||||
|
if (apiResult.Data != null && apiResult.Data.Result)
|
||||||
|
{
|
||||||
|
inv.UploadErpFlag = 1;
|
||||||
|
_unitwork.Update(inv);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
inv.UploadErpFlag = 0;
|
||||||
|
_unitwork.Update(inv);
|
||||||
|
}
|
||||||
|
#region 更新时间
|
||||||
|
var job = _unitwork.FindSingle<SysJob>(x =>
|
||||||
|
x.JobName == context.JobDetail.Key.Name
|
||||||
|
);
|
||||||
|
if (job != null)
|
||||||
|
{
|
||||||
|
job.LastFireTime = TimeZoneInfo.ConvertTimeFromUtc(
|
||||||
|
context.FireTimeUtc.DateTime,
|
||||||
|
TimeZoneInfo.Local
|
||||||
|
);
|
||||||
|
// 只执行一次 没有下次执行时间
|
||||||
|
if (context.NextFireTimeUtc != null)
|
||||||
|
{
|
||||||
|
job.NextFireTime = TimeZoneInfo.ConvertTimeFromUtc(
|
||||||
|
context.NextFireTimeUtc.Value.DateTime,
|
||||||
|
TimeZoneInfo.Local
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_unitwork.Update<SysJob>(job);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
catch(Exception ex) {
|
||||||
|
Wtm.DoLog("ERP报工失败", ActionLogTypesEnum.Job, "FinishInJob", request:"error", result:ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ namespace HHWMS.Web
|
|||||||
// 调用接口获取ERP订单数据
|
// 调用接口获取ERP订单数据
|
||||||
var request = new LoadMoDetailListRequest
|
var request = new LoadMoDetailListRequest
|
||||||
{
|
{
|
||||||
ErpCode = "999",
|
ErpCode = "002",
|
||||||
Size = 100,
|
Size = 100,
|
||||||
Page = 1
|
Page = 1
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace HHWMS.Web
|
|||||||
// 调用接口获取ERP用户数据
|
// 调用接口获取ERP用户数据
|
||||||
var request = new LoadPersonRequest
|
var request = new LoadPersonRequest
|
||||||
{
|
{
|
||||||
ErpCode = "999",
|
ErpCode = "002",
|
||||||
Size = 1000,
|
Size = 1000,
|
||||||
Page = 1
|
Page = 1
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -73,5 +73,32 @@ namespace HHWMS.Web.Models
|
|||||||
/// 完工数量,必填
|
/// 完工数量,必填
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public decimal Qty { get; set; }
|
public decimal Qty { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 出库明细
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
public List<MaterialDetail> MaterialDetails { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 出库明细
|
||||||
|
/// </summary>
|
||||||
|
public class MaterialDetail
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 生产订单明细,必填
|
||||||
|
/// </summary>
|
||||||
|
public string MoDetailId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 物料号,必填
|
||||||
|
/// </summary>
|
||||||
|
public string InvCode { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 完工数量,必填
|
||||||
|
/// </summary>
|
||||||
|
public decimal Qty { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1023,6 +1023,12 @@
|
|||||||
<data name="TaskType.Out" xml:space="preserve">
|
<data name="TaskType.Out" xml:space="preserve">
|
||||||
<value>出库</value>
|
<value>出库</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="FinishIn" xml:space="preserve">
|
||||||
|
<value>报工回传</value>
|
||||||
|
</data>
|
||||||
|
<data name="GetReceiptDetails" xml:space="preserve">
|
||||||
|
<value>获取ERP订单</value>
|
||||||
|
</data>
|
||||||
<data name="TaskType.Out1" xml:space="preserve">
|
<data name="TaskType.Out1" xml:space="preserve">
|
||||||
<value>出 库</value>
|
<value>出 库</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -1,285 +1 @@
|
|||||||
<script>layui.use('index')</script>
|
<script>layui.use('index')</script>
|
||||||
<script src="/front/signalr.min.js"></script>
|
|
||||||
<script>
|
|
||||||
// SignalR 登录状态管理
|
|
||||||
var loginConnection = null;
|
|
||||||
var heartbeatTimer = null;
|
|
||||||
var userId = '@ViewData["ITCode"]'; // 从后端获取当前用户ID
|
|
||||||
var isForceLogout = false;
|
|
||||||
|
|
||||||
// 服务异常检测
|
|
||||||
var reconnectAttempts = 0; // 重连尝试次数
|
|
||||||
var maxReconnectAttempts = 5; // 最大重连次数
|
|
||||||
var isServerDown = false; // 服务是否宕机
|
|
||||||
var serverDownAlertIndex = null; // 服务宕机弹窗索引
|
|
||||||
var reconnectTimer = null; // 重连定时器
|
|
||||||
|
|
||||||
// 初始化 SignalR 连接
|
|
||||||
function initLoginHub() {
|
|
||||||
loginConnection = new signalR.HubConnectionBuilder()
|
|
||||||
.withUrl("/loginHub")
|
|
||||||
.withAutomaticReconnect({
|
|
||||||
nextRetryDelayInMilliseconds: function(retryContext) {
|
|
||||||
// 自定义重连策略
|
|
||||||
if (retryContext.previousRetryCount < maxReconnectAttempts) {
|
|
||||||
return Math.min(1000 * Math.pow(2, retryContext.previousRetryCount), 30000);
|
|
||||||
}
|
|
||||||
return null; // 停止自动重连
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// 监听强制登出事件
|
|
||||||
loginConnection.on("ForceLogout", function(message) {
|
|
||||||
isForceLogout = true;
|
|
||||||
stopHeartbeat();
|
|
||||||
stopReconnect();
|
|
||||||
|
|
||||||
// 使用layer弹窗提示
|
|
||||||
layer.alert(message || "您的账号已在其他设备登录,请重新登录", {
|
|
||||||
icon: 0,
|
|
||||||
title: "登录提示",
|
|
||||||
closeBtn: 0,
|
|
||||||
btn: ['确定'],
|
|
||||||
yes: function(index) {
|
|
||||||
layer.close(index);
|
|
||||||
// 重定向到登录页
|
|
||||||
window.location.href = '/Login/Login';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// 监听注册成功
|
|
||||||
loginConnection.on("RegisterSuccess", function(message) {
|
|
||||||
console.log("SignalR 登录连接成功:", message);
|
|
||||||
onConnectionRestored();
|
|
||||||
startHeartbeat();
|
|
||||||
});
|
|
||||||
|
|
||||||
// 监听心跳响应
|
|
||||||
loginConnection.on("HeartbeatResponse", function(serverTime) {
|
|
||||||
//console.log("心跳响应:", serverTime);
|
|
||||||
});
|
|
||||||
|
|
||||||
// 连接关闭事件
|
|
||||||
loginConnection.onclose(function(error) {
|
|
||||||
console.log("SignalR 连接已关闭", error);
|
|
||||||
stopHeartbeat();
|
|
||||||
|
|
||||||
if (!isForceLogout) {
|
|
||||||
onConnectionLost();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 正在重连事件
|
|
||||||
loginConnection.onreconnecting(function(error) {
|
|
||||||
console.log("SignalR 正在重连...", error);
|
|
||||||
reconnectAttempts++;
|
|
||||||
showReconnectingStatus();
|
|
||||||
});
|
|
||||||
|
|
||||||
// 重连成功事件
|
|
||||||
loginConnection.onreconnected(function(connectionId) {
|
|
||||||
console.log("SignalR 重连成功:", connectionId);
|
|
||||||
onConnectionRestored();
|
|
||||||
// 重新注册
|
|
||||||
if (userId) {
|
|
||||||
loginConnection.invoke("Register", userId).catch(function(err) {
|
|
||||||
console.error("重新注册失败:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 开始连接
|
|
||||||
startConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 启动连接
|
|
||||||
function startConnection() {
|
|
||||||
if (isForceLogout) return;
|
|
||||||
|
|
||||||
loginConnection.start()
|
|
||||||
.then(function() {
|
|
||||||
console.log("SignalR 连接已建立");
|
|
||||||
onConnectionRestored();
|
|
||||||
// 注册当前用户
|
|
||||||
if (userId) {
|
|
||||||
loginConnection.invoke("Register", userId).catch(function(err) {
|
|
||||||
console.error("注册失败:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.error("SignalR 连接失败:", err);
|
|
||||||
reconnectAttempts++;
|
|
||||||
|
|
||||||
if (reconnectAttempts >= maxReconnectAttempts) {
|
|
||||||
// 达到最大重连次数,显示服务不可用
|
|
||||||
showServerDownAlert();
|
|
||||||
} else {
|
|
||||||
// 继续重连
|
|
||||||
showReconnectingStatus();
|
|
||||||
var delay = Math.min(1000 * Math.pow(2, reconnectAttempts), 30000);
|
|
||||||
reconnectTimer = setTimeout(function() {
|
|
||||||
startConnection();
|
|
||||||
}, delay);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 连接丢失处理
|
|
||||||
function onConnectionLost() {
|
|
||||||
reconnectAttempts = 0;
|
|
||||||
showReconnectingStatus();
|
|
||||||
|
|
||||||
// 手动启动重连
|
|
||||||
reconnectTimer = setTimeout(function() {
|
|
||||||
startConnection();
|
|
||||||
}, 2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 连接恢复处理
|
|
||||||
function onConnectionRestored() {
|
|
||||||
reconnectAttempts = 0;
|
|
||||||
isServerDown = false;
|
|
||||||
hideReconnectingStatus();
|
|
||||||
hideServerDownAlert();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 显示重连中状态
|
|
||||||
function showReconnectingStatus() {
|
|
||||||
if ($('#reconnecting-status').length === 0) {
|
|
||||||
$('body').append(
|
|
||||||
'<div id="reconnecting-status" style="position:fixed;top:0;left:0;right:0;background:#ff9800;color:#fff;text-align:center;padding:8px;z-index:99999;font-size:14px;">' +
|
|
||||||
'<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i> ' +
|
|
||||||
'正在连接服务器... (尝试 ' + reconnectAttempts + '/' + maxReconnectAttempts + ')' +
|
|
||||||
'</div>'
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$('#reconnecting-status').html(
|
|
||||||
'<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i> ' +
|
|
||||||
'正在连接服务器... (尝试 ' + reconnectAttempts + '/' + maxReconnectAttempts + ')'
|
|
||||||
).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 隐藏重连中状态
|
|
||||||
function hideReconnectingStatus() {
|
|
||||||
$('#reconnecting-status').hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 显示服务不可用弹窗
|
|
||||||
function showServerDownAlert() {
|
|
||||||
if (isServerDown) return;
|
|
||||||
isServerDown = true;
|
|
||||||
hideReconnectingStatus();
|
|
||||||
|
|
||||||
// 显示服务不可用状态栏
|
|
||||||
if ($('#server-down-status').length === 0) {
|
|
||||||
$('body').append(
|
|
||||||
'<div id="server-down-status" style="position:fixed;top:0;left:0;right:0;background:#f44336;color:#fff;text-align:center;padding:8px;z-index:99999;font-size:14px;">' +
|
|
||||||
'<i class="layui-icon layui-icon-close-fill"></i> ' +
|
|
||||||
'服务器连接已断开,请检查网络或联系管理员 ' +
|
|
||||||
'<button onclick="manualReconnect()" style="margin-left:10px;padding:2px 10px;cursor:pointer;background:#fff;color:#f44336;border:none;border-radius:3px;">重新连接</button>' +
|
|
||||||
'</div>'
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$('#server-down-status').show();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 弹窗提示
|
|
||||||
if (!serverDownAlertIndex) {
|
|
||||||
serverDownAlertIndex = layer.confirm('服务器连接已断开,可能是网络问题或服务器维护中。<br/>是否重新连接?', {
|
|
||||||
icon: 2,
|
|
||||||
title: "连接异常",
|
|
||||||
btn: ['重新连接', '稍后再试'],
|
|
||||||
closeBtn: 0
|
|
||||||
}, function(index) {
|
|
||||||
layer.close(index);
|
|
||||||
serverDownAlertIndex = null;
|
|
||||||
manualReconnect();
|
|
||||||
}, function(index) {
|
|
||||||
layer.close(index);
|
|
||||||
serverDownAlertIndex = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 隐藏服务不可用弹窗
|
|
||||||
function hideServerDownAlert() {
|
|
||||||
$('#server-down-status').hide();
|
|
||||||
if (serverDownAlertIndex) {
|
|
||||||
layer.close(serverDownAlertIndex);
|
|
||||||
serverDownAlertIndex = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 手动重连
|
|
||||||
function manualReconnect() {
|
|
||||||
reconnectAttempts = 0;
|
|
||||||
isServerDown = false;
|
|
||||||
hideServerDownAlert();
|
|
||||||
showReconnectingStatus();
|
|
||||||
startConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 停止重连
|
|
||||||
function stopReconnect() {
|
|
||||||
if (reconnectTimer) {
|
|
||||||
clearTimeout(reconnectTimer);
|
|
||||||
reconnectTimer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 开始心跳
|
|
||||||
function startHeartbeat() {
|
|
||||||
stopHeartbeat();
|
|
||||||
heartbeatTimer = setInterval(function() {
|
|
||||||
if (loginConnection && loginConnection.state === signalR.HubConnectionState.Connected) {
|
|
||||||
loginConnection.invoke("Heartbeat", userId).catch(function(err) {
|
|
||||||
console.error("心跳发送失败:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, 30000); // 每30秒发送一次心跳
|
|
||||||
}
|
|
||||||
|
|
||||||
// 停止心跳
|
|
||||||
function stopHeartbeat() {
|
|
||||||
if (heartbeatTimer) {
|
|
||||||
clearInterval(heartbeatTimer);
|
|
||||||
heartbeatTimer = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 页面加载完成后初始化
|
|
||||||
$(document).ready(function() {
|
|
||||||
if (userId) {
|
|
||||||
initLoginHub();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 页面关闭时断开连接
|
|
||||||
$(window).on('beforeunload', function() {
|
|
||||||
stopReconnect();
|
|
||||||
stopHeartbeat();
|
|
||||||
if (loginConnection) {
|
|
||||||
loginConnection.stop();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 页面从隐藏状态变为可见时,检查连接状态
|
|
||||||
$(document).on('visibilitychange', function() {
|
|
||||||
if (document.visibilityState === 'visible' && !isForceLogout) {
|
|
||||||
if (loginConnection && loginConnection.state !== signalR.HubConnectionState.Connected) {
|
|
||||||
if (!isServerDown) {
|
|
||||||
manualReconnect();
|
|
||||||
}
|
|
||||||
} else if (loginConnection && userId) {
|
|
||||||
// 页面可见时发送一次心跳
|
|
||||||
loginConnection.invoke("Heartbeat", userId).catch(function(err) {
|
|
||||||
console.error("心跳发送失败:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
Reference in new issue
Block a user