任务添加zoneid

添加物料打印
添加物料工序
添加库存出库
修改状态返回接口
wcs请求添加 重量和入口
This commit is contained in:
zhougf committed 2025-07-09 01:11:10 +08:00
1 parent 42c26b2800
commit b12ed2d5e5
54 files changed
+1442 -393

No files matched your search

@@ -6,6 +6,7 @@ using System.Collections.Generic;
using HHWMS.Web.Models;
using System.Threading.Tasks;
using System.Linq;
using Aliyun.OSS;
using Microsoft.EntityFrameworkCore;
using WalkingTec.Mvvm.Core.Extensions;
@@ -16,10 +17,17 @@ namespace HHWMS.Web.Controllers
public partial class ReceiptInController : BaseController
{
private readonly IUnitWork _unitWork;
private readonly Dictionary<string, LineRange> _materialZones;
public ReceiptInController(IUnitWork unitwork)
{
_unitWork = unitwork;
_materialZones = new Dictionary<string, LineRange>
{
{ "zone1", new LineRange { BeginLine = 1, EndLine = 25 } },
{ "zone2", new LineRange { BeginLine = 26, EndLine = 57 } },
{ "zone3", new LineRange { BeginLine = 58, EndLine = 96 } },
};
}
#region Index
@@ -37,32 +45,68 @@ namespace HHWMS.Web.Controllers
[HttpPost]
public IActionResult GetOperators()
{
// TODO: 从数据库获取操作员列表
var operators = new List<object>
{
new { value = "1", label = "张三" },
new { value = "2", label = "李四" }
};
return Json(new { Code = 200, Data = operators });
var users = _unitWork.Find<FrameworkUser>(x => x.ITCode != "Admin")
.Select(x => new {x.ITCode,x.Name})
.ToList();
return Json(new { Code = 200, Data = users});
}
[HttpPost]
public IActionResult GetProcesses()
{
// TODO: 从数据库获取工序列表
var processes = new List<object>
try
{
new { value = "1", label = "工序1" },
new { value = "2", label = "工序2" }
};
return Json(new { Code = 200, Data = processes });
var processes = _unitWork.Find<MaterialProcess>(x => x.IsActive)
.OrderBy(x => x.ProcessOrder)
.Select(x => new {
value = x.ID.ToString(),
label = x.ProcessName,
processCode = x.ProcessCode,
processName = x.ProcessName
})
.ToList();
return Json(new { Code = 200, Data = processes });
}
catch (Exception ex)
{
return Json(new { Code = 500, Msg = $"获取工序列表失败:{ex.Message}" });
}
}
[HttpPost]
public IActionResult GetProcessesByMaterial(string materialCode)
{
try
{
if (string.IsNullOrWhiteSpace(materialCode))
{
return Json(new { Code = 200, Data = new object[] { } });
}
var processes = _unitWork.Find<MaterialProcess>(x => x.MaterialCode == materialCode && x.IsActive)
.OrderBy(x => x.ProcessOrder)
.Select(x => new {
value = x.ID.ToString(),
label = x.ProcessName,
processCode = x.ProcessCode,
processName = x.ProcessName
})
.ToList();
return Json(new { Code = 200, Data = processes });
}
catch (Exception ex)
{
return Json(new { Code = 500, Msg = $"获取物料工序失败:{ex.Message}" });
}
}
[HttpPost]
public IActionResult GetOperatorInfo()
{
// TODO: 获取当前登录用户信息
return Json(new { Code = 200, Data = "当前操作员:张三" });
var users = _unitWork.Find<FrameworkUser>(x => x.ITCode != "Admin")
.Select(x => new {x.ITCode,x.Name})
.ToList();
return Json(new { Code = 200, Data = users});
}
[HttpPost]
@@ -80,38 +124,13 @@ namespace HHWMS.Web.Controllers
[HttpPost]
public IActionResult SubmitReceipt([FromBody] ReceiptInModel model)
{
// 1. 查找可用库位信息 - 使用LocationVM的GetLocation方法
var locationVM = Wtm.CreateVM<LocationVM>();
// 创建WcsRequest对象,设置巷道号为1
var wcsRequest = new WcsRequest { RoadWay = 1 };
// 调用GetLocation方法获取可用库位
var locationResult = locationVM.GetLocation(wcsRequest);
if (!locationResult.Status)
{
return Json(new { Code = 500, Msg = locationResult.Message });
}
// 获取返回的库位编码
string locationCode = locationResult.Data.LocationCode;
// 根据库位编码获取完整的库位信息,使用AsNoTracking()避免实体跟踪冲突
// var availableLocation = DC.Set<Location>().AsNoTracking().FirstOrDefault(l => l.Code == locationCode);
//
// if (availableLocation == null)
// {
// return Json(new { Code = 500, Msg = "没有可用库位" });
// }
// 获取物料信息
var material = _unitWork.FindSingle<Material>(m => m.MaterialCode == model.MaterialCode);
if (material == null)
{
return Json(new { Code = 500, Msg = "物料不存在" });
}
// 获取容器信息
var container = _unitWork.FindSingle<Container>(c => c.Code == model.PalletCode);
if (container == null)
@@ -119,15 +138,35 @@ namespace HHWMS.Web.Controllers
return Json(new { Code = 500, Msg = "容器不存在" });
}
// 从字典查询工序对应的区域
var processName = _unitWork.FindSingle<SysDictData>(x => x.DictType == "ProcessZone"
&& x.DictLabel == model.ProcessName)?.DictValue;
if (string.IsNullOrEmpty(processName))
{
return Json(new { Code = 500, Msg = "未找到此工序配置" });
}
// 1. 查找可用库位信息
var locationVm = Wtm.CreateVM<LocationVM>();
var locationCode = locationVm.GetEmptyLocationFromXb(_materialZones[processName].BeginLine, _materialZones[processName].EndLine);
if (string.IsNullOrWhiteSpace(locationCode))
{
return Json(new { Code = 500, Msg = "未找到可用的空仓位" });
}
// 使用事务
using (var tran = DC.BeginTransaction())
{
try
{
var zone = _unitWork.FindSingle<LocationZone>(x => x.Name == "线边库");
// 2. 生成入库任务
var taskNo = _unitWork.GetSerialNumber("In", 6);
var taskHeader = new TaskHeader
{
ZoneId = zone.ID,
TaskNo = taskNo,
TaskType = TaskTypeEnum.入库,
FromLocation = "",
@@ -144,13 +183,15 @@ namespace HHWMS.Web.Controllers
// 3. 创建库存信息
var inventory = new Inventory
{
ZoneId = zone.ID,
ContainerCode = model.PalletCode,
LocationCode = locationCode,
MaterialCode = model.MaterialCode,
MaterialName = material.MaterialName,
MaterialSpec = material.MaterialSpec,
MaterialUnit = material.MaterialUnit,
Qty = model.Quantity,
Batch = model.ProcessName,
Lot = model.ProcessId.ToString(),
TaskStatus = InventoryTaskStatusEnum.Locked,
CreateBy = model.OperatorId,
CreateTime = DateTime.Now
@@ -158,33 +199,32 @@ namespace HHWMS.Web.Controllers
_unitWork.Add(inventory);
// 4. 创建库存交易记录
var transaction = new InventoryTransaction
{
Type = InventoryTranType.入库,
ContainerCode = model.PalletCode,
LocationCode = locationCode,
MaterialCode = model.MaterialCode,
MaterialName = material.MaterialName,
MaterialSpec = material.MaterialSpec,
MaterialUnit = material.MaterialUnit,
Qty = model.Quantity,
CreateBy = model.OperatorId,
CreateTime = DateTime.Now
};
_unitWork.Add(transaction);
// 5. 锁定容器和库位
container.IsLock = ContainerLockEnum.任务锁;
container.Status = ContainerStatus.有;
container.LocationCode = locationCode;
_unitWork.Update(container);
// 从数据库中重新获取库位实体,避免实体跟踪冲突
var locationToUpdate = _unitWork.FindSingle<Location>(l => l.Code == locationCode);
locationToUpdate.Status = LocationStatusEnum.Locked;
locationToUpdate.ContainerCode = model.PalletCode;
_unitWork.Update(locationToUpdate);
var resultNum = _unitWork.BatchUpdate<Location>(x => x.Code == locationCode && x.Version == locationToUpdate.Version,
x => new Location()
{
Status = LocationStatusEnum.锁定,
ContainerStatus = LocationStatus.有货,
ContainerCode = model.PalletCode,
UpdateTime = DateTime.Now,
UpdateBy = "WMS",
Version = Guid.NewGuid()
});
if (resultNum == 0)
{
//失败 回滚
tran.Rollback();
return Json(new { Code = 500, Msg = "更新仓位失败!请重新提交!"});
}
// 6. 调用WCS接口下发任务
var wcsTaskModel = new WCSTaskModel
@@ -196,7 +236,7 @@ namespace HHWMS.Web.Controllers
};
// 调用WCS任务下发接口
var wcsResult = Wtm.CallAPI<WCSTaskResponse>("WCS", "TaskAssign", HttpMethodEnum.POST, wcsTaskModel).Result.Data;
var wcsResult = Wtm.CallAPI<WCSTaskResponse>("WCSXB", "TaskAssign", HttpMethodEnum.POST, wcsTaskModel).Result.Data;
if (wcsResult != null && wcsResult.Success)
{
@@ -220,6 +260,115 @@ namespace HHWMS.Web.Controllers
}
}
/// <summary>
/// 空托盘入库
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public IActionResult SubmitEmptyPallet([FromBody] ReceiptInModel model)
{
// 获取容器信息
var container = _unitWork.FindSingle<Container>(c => c.Code == model.PalletCode);
if (container == null)
{
return Json(new { Code = 500, Msg = "容器不存在" });
}
// 1. 查找可用库位信息
var locationVm = Wtm.CreateVM<LocationVM>();
var locationCode = locationVm.GetEmptyLocationFromXb(_materialZones["zone1"].BeginLine, _materialZones["zone1"].EndLine);
if (string.IsNullOrWhiteSpace(locationCode))
{
return Json(new { Code = 500, Msg = "未找到可用的空仓位" });
}
// 使用事务
using (var tran = DC.BeginTransaction())
{
try
{
var zone = _unitWork.FindSingle<LocationZone>(x => x.Name == "线边库");
// 2. 生成入库任务
var taskNo = _unitWork.GetSerialNumber("In", 6);
var taskHeader = new TaskHeader
{
ZoneId = zone.ID,
TaskNo = taskNo,
TaskType = TaskTypeEnum.入库,
FromLocation = "",
ToLocation = locationCode,
ContainerCode = model.PalletCode,
RoadWay = 1,
Status = TaskStatusEnum.新建,
CreateBy = model.OperatorId,
CreateTime = DateTime.Now
};
_unitWork.Add(taskHeader);
// 5. 锁定容器和库位
container.IsLock = ContainerLockEnum.任务锁;
container.LocationCode = locationCode;
container.Status = ContainerStatus.空;
_unitWork.Update(container);
// 从数据库中重新获取库位实体,避免实体跟踪冲突
var locationToUpdate = _unitWork.FindSingle<Location>(l => l.Code == locationCode);
var resultNum = _unitWork.BatchUpdate<Location>(x => x.Code == locationCode && x.Version == locationToUpdate.Version,
x => new Location()
{
Status = LocationStatusEnum.锁定,
ContainerStatus = LocationStatus.空仓位,
ContainerCode = model.PalletCode,
UpdateTime = DateTime.Now,
UpdateBy = "WMS",
Version = Guid.NewGuid()
});
if (resultNum == 0)
{
//失败 回滚
tran.Rollback();
return Json(new { Code = 500, Msg = "更新仓位失败!请重新提交!"});
}
// 6. 调用WCS接口下发任务
var wcsTaskModel = new WCSTaskModel
{
TaskNo = taskNo,
PalletNo = model.PalletCode,
FromLocation = "", // 入库任务起始位置为空
ToLocation = locationCode,
};
// 调用WCS任务下发接口
var wcsResult = Wtm.CallAPI<WCSTaskResponse>("WCSXB", "TaskAssign", HttpMethodEnum.POST, wcsTaskModel).Result.Data;
if (wcsResult != null && wcsResult.Success)
{
// WCS任务下发成功,提交事务
tran.Commit();
return Json(new { Code = 200, Msg = "入库成功", Data = new { TaskNo = taskNo } });
}
else
{
// WCS任务下发失败,回滚事务
tran.Rollback();
return Json(new { Code = 500, Msg = wcsResult?.Msg ?? "WCS任务下发失败" });
}
}
catch (System.Exception ex)
{
// 发生异常,回滚事务
tran.Rollback();
return Json(new { Code = 500, Msg = ex.Message });
}
}}
/// <summary>
/// 搜索物料
/// </summary>
@@ -260,9 +409,16 @@ namespace HHWMS.Web.Controllers
public string MaterialCode { get; set; }
public string OrderId { get; set; }
public string OperatorId { get; set; }
public string ProcessId { get; set; }
public int Quantity { get; set; }
public int ProcessId { get; set; }
public string ProcessName { get; set; }
public bool IsQualified { get; set; }
public string OperatorInfo { get; set; }
}
public class LineRange
{
public int BeginLine { get; set; }
public int EndLine { get; set; }
}
}
@@ -4,34 +4,23 @@
<a-card class="general-card">
<a-form :model="form" :rules="rules" ref="formRef" auto-label-width>
<a-form-item label="托盘码" field="palletCode">
<a-input v-model="form.palletCode" @@change="scanPallet" ref="palletCodeRef" placeholder="请扫描托盘码" @@keydown.enter.prevent="focusNext('materialCodeRef')" />
<a-input v-model="form.palletCode" ref="palletCodeRef" placeholder="请扫描托盘码" @@change="scanPallet" @@keydown.enter="focusNext('materialCodeRef')" />
</a-form-item>
<a-form-item label="物料码" field="materialCode">
<a-auto-complete
v-model="form.materialCode"
:data="materialOptions"
ref="materialCodeRef"
placeholder="请扫描或输入物料码"
@@search="handleMaterialSearch"
@@select="handleMaterialSelect"
ref="materialCodeRef"
@@keydown.enter.prevent="focusNext('quantityInput')"
>
</a-auto-complete>
</a-form-item>
<a-form-item label="生产订单" field="orderId">
<a-select v-model="form.orderId" placeholder="请选择生产订单" @@change="handleOrderChange" ref="orderSelect">
<a-option v-for="item in orderOptions"
:key="item.value"
:value="item.value">
{{ item.label }}
</a-option>
</a-select>
</a-form-item>
<a-form-item label="当前工序" field="processId">
<a-select v-model="form.processId" placeholder="请选择工序" ref="processSelect">
<a-select v-model="form.processId" placeholder="请选择工序" @@change="processSelect">
<a-option v-for="item in processOptions"
:key="item.value"
:value="item.value">
@@ -40,31 +29,26 @@
</a-select>
</a-form-item>
<a-form-item label="入库数量" field="quantity">
<a-input-number v-model="form.quantity" :min="1" :precision="0" ref="quantityInput" />
<a-form-item label="工序名称" field="processName" v-show="false">
<a-input v-model="form.processName" />
</a-form-item>
<a-form-item label="是否合格" field="isQualified">
<a-switch v-model="form.isQualified" ref="isQualifiedSwitch" />
<a-switch v-model="form.isQualified" />
</a-form-item>
<a-form-item label="操作员工" field="operatorId">
<a-select v-model="form.operatorId" placeholder="请选择操作员工" ref="operatorSelect">
<a-option v-for="item in operatorOptions"
:key="item.value"
:value="item.value">
{{ item.label }}
</a-option>
</a-select>
<a-input v-model="form.operatorId" ref="operatorIdRef" placeholder="请扫描员工码" @@keydown.enter="focusNext('operatorInfoRef')" />
</a-form-item>
<a-form-item label="检验员信息" field="operatorInfo">
<a-input v-model="form.operatorInfo" placeholder="请输入检验员信息" />
<a-input v-model="form.operatorInfo" ref="operatorInfoRef" placeholder="请扫描检验员信息" @@keydown.enter="submitForm" />
</a-form-item>
<a-form-item>
<a-space>
<a-button type="primary" @@click="submitForm" :loading="loading">上架入库</a-button>
<a-button type="success" @@click="submitEmptyPallet" :loading="loading">空托盘入库</a-button>
<a-button @@click="resetForm">重置</a-button>
</a-space>
</a-form-item>
@@ -81,14 +65,26 @@
const app = createApp({
setup() {
const formRef = ref(null);
const loading = ref(false);
const palletCodeRef = ref(null);
const materialCodeRef = ref(null);
const orderSelect = ref(null);
const processSelect = ref(null);
const operatorSelect = ref(null);
const quantityInput = ref(null);
const isQualifiedSwitch = ref(null);
const loading = ref(false);
const operatorIdRef = ref(null);
const operatorInfoRef = ref(null);
const inputRefs = {
palletCodeRef,
materialCodeRef,
operatorIdRef,
operatorInfoRef
};
const focusNext = (nextRefName) => {
nextTick(() => {
if (inputRefs[nextRefName] && inputRefs[nextRefName].value && inputRefs[nextRefName].value.focus) {
inputRefs[nextRefName].value.focus();
}
});
};
const form = reactive({
palletCode: '',
@@ -96,15 +92,11 @@
orderId: '',
operatorId: '',
processId: '',
quantity: 1,
processName:'',
isQualified: true,
operatorInfo: ''
});
const orderOptions = ref([]);
const operatorOptions = ref([]);
const processOptions = ref([]);
const materialOptions = ref([]);
let searchTimer = null;
@@ -115,35 +107,24 @@
materialCode: [
{ required: true, message: '请输入物料码', trigger: ['change', 'blur'] }
],
orderId: [
{ required: true, message: '请选择生产订单', trigger: ['change', 'blur'] }
],
operatorId: [
{ required: true, message: '请选择操作员工', trigger: ['change', 'blur'] }
],
processId: [
{ required: true, message: '请选择工序', trigger: ['change', 'blur'] }
],
quantity: [
{ required: true, type: 'number', message: '请输入数量', trigger: ['change', 'blur'] }
operatorId: [
{ required: true, message: '请输入操作员工信息', trigger: ['change', 'blur'] }
],
operatorInfo: [
{ required: true, message: '请输入检验员信息', trigger: ['change', 'blur'] }
]
};
// 加载操作员列表
const loadOperators = () => {
$.ajax({
type: "post",
dataType: "json",
url: "/receipt/ReceiptIn/GetOperators",
success: (json) => {
operatorOptions.value = json.Data;
}
});
};
const processSelect = (value) => {
form.processName = processOptions.value.find(item => item.value === value).processName;
focusNext('operatorIdRef');
}
// 加载工序列表
const loadProcesses = () => {
$.ajax({
@@ -151,19 +132,41 @@
dataType: "json",
url: "/receipt/ReceiptIn/GetProcesses",
success: (json) => {
processOptions.value = json.Data;
if (json.Code == 200) {
processOptions.value = json.Data;
} else {
Message.error(json.Msg || '加载工序列表失败');
}
},
error: (xhr, status, error) => {
Message.error('加载工序列表失败:' + error);
}
});
};
// 加载当前操作员信息
const loadOperatorInfo = () => {
// 根据物料加载工序列表
const loadProcessesByMaterial = (materialCode) => {
if (!materialCode) {
processOptions.value = [];
return;
}
$.ajax({
type: "post",
dataType: "json",
url: "/receipt/ReceiptIn/GetOperatorInfo",
data: { materialCode: materialCode },
url: "/receipt/ReceiptIn/GetProcessesByMaterial",
success: (json) => {
form.operatorInfo = json.Data;
if (json.Code == 200) {
processOptions.value = json.Data;
} else {
Message.error(json.Msg || '加载物料工序失败');
processOptions.value = [];
}
},
error: (xhr, status, error) => {
Message.error('加载物料工序失败:' + error);
processOptions.value = [];
}
});
};
@@ -220,28 +223,15 @@
const selectedMaterial = materialOptions.value.find(item => item.value === value);
if (selectedMaterial) {
form.materialCode = selectedMaterial.MaterialCode;
// 选择物料后加载相关订单
scanMaterial();
// 选择物料后加载相关工序
loadProcessesByMaterial(selectedMaterial.MaterialCode);
}
};
// 扫描物料码
const scanMaterial = () => {
if (!form.materialCode) return;
$.ajax({
type: "post",
dataType: "json",
data: { materialCode: form.materialCode },
url: "/receipt/ReceiptIn/GetOrdersByMaterial",
success: (json) => {
orderOptions.value = json.Data;
}
});
};
// 生产订单变更
const handleOrderChange = () => {
loadProcesses();
loadProcessesByMaterial(form.materialCode);
};
// 提交表单
@@ -260,7 +250,10 @@
Message.success('入库成功!');
resetForm();
} else {
Message.error(json.Msg || '入库失败!');
Message.error({
content: json.Msg || '入库失败!',
duration: 5000 // 设置为 5 秒
});
}
},
error: (xhr, status, error) => {
@@ -276,10 +269,48 @@
});
};
// 空托盘入库
const submitEmptyPallet = () => {
if (!form.palletCode) {
Message.error('请输入托盘码!');
return;
}
loading.value = true;
const emptyPalletData = {
palletCode: form.palletCode,
operatorId: form.operatorId || 'SYSTEM'
};
$.ajax({
type: "post",
dataType: "json",
contentType: "application/json",
data: JSON.stringify(emptyPalletData),
url: "/receipt/ReceiptIn/SubmitEmptyPallet",
success: (json) => {
if (json.Code == 200) {
Message.success('空托盘入库成功!');
resetForm();
} else {
Message.error({
content: json.Msg || '空托盘入库失败!',
duration: 5000
});
}
},
error: (xhr, status, error) => {
Message.error('提交失败:' + error);
},
complete: () => {
loading.value = false;
}
});
};
// 重置表单
const resetForm = () => {
formRef.value.resetFields();
orderOptions.value = [];
processOptions.value = [];
setTimeout(() => {
if (palletCodeRef.value) {
@@ -288,40 +319,9 @@
}, 100);
};
// 焦点跳转到下一个输入框
const focusNext = (nextRef) => {
const refMap = {
materialCodeRef: materialCodeRef,
quantityInput: quantityInput
};
const nextElement = refMap[nextRef];
if (nextElement?.value) {
// 先让当前元素失去焦点
if (document.activeElement) {
document.activeElement.blur();
}
// 使用 nextTick 确保 DOM 更新完成
nextTick(() => {
if (nextElement.value.$el) {
// 处理 Input 组件
const input = nextElement.value.$el.querySelector('input');
if (input) {
input.focus();
}
} else {
// 处理基础组件
nextElement.value.focus();
}
});
}
};
// 生命周期钩子
onMounted(() => {
loadOperators();
loadOperatorInfo();
// 页面加载时自动聚焦第一个输入框
setTimeout(() => {
if (palletCodeRef.value) {
@@ -332,28 +332,26 @@
return {
formRef,
palletCodeRef,
materialCodeRef,
orderSelect,
processSelect,
operatorSelect,
quantityInput,
isQualifiedSwitch,
form,
loading,
orderOptions,
operatorOptions,
processOptions,
rules,
scanPallet,
scanMaterial,
handleOrderChange,
submitForm,
submitEmptyPallet,
resetForm,
focusNext,
materialOptions,
handleMaterialSearch,
handleMaterialSelect
handleMaterialSelect,
palletCodeRef,
materialCodeRef,
operatorIdRef,
operatorInfoRef,
focusNext,
loadProcesses,
loadProcessesByMaterial,
processSelect
};
}
});