You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

269 lines
9.4 KiB
C#

1 year ago
using Admin.Core.IService;
using Admin.Core.Service;
using Admin.Core.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Admin.Core.Common;
using System.Linq;
using S71500.Impl;
using Admin.Core.Model.ViewModels;
using log4net;
using Npgsql.TypeHandlers;
1 year ago
namespace Admin.Core.Api
{
/// <summary>
1 year ago
/// 小料料仓类型防差错
1 year ago
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize(Permissions.Name)]
[AllowAnonymous]
public class xl_materialController : BaseApiController
{
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(xl_materialServices));
int i = 0;
/// <summary>
/// 物料服务
/// </summary>
private readonly Ixl_materialServices _xl_materialService;
private readonly IPmt_BinServices _binServices;
private readonly IXlPlanServices _xlPlanServices;
#region 构造方法
/// <summary>
/// 构造方法
/// </summary>
/// <param></param>
public xl_materialController(Ixl_materialServices xl_materialServices, IPmt_BinServices binServices,
IXlPlanServices xlPlanServices)
{
_xl_materialService = xl_materialServices;
_binServices = binServices;
_xlPlanServices = xlPlanServices;
}
#endregion
#region 根据扫描的二维码查询小料物料
/// <summary>
/// 根据扫描的二维码查询小料物料
/// </summary>
/// <param name="code">物料条码信息</param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<xl_material>> GetByMaterialCode(string code)
{
if (!code.IsNotEmptyOrNull())
{
return Failed<xl_material>("传入参数为空!");
}
var query = await _xl_materialService.GetByMaterialCode(code.Trim());
log.Info(query == null);
if (query == null)
{
return Failed<xl_material>("查询失败!");
}
return Success(query);
}
#endregion
#region 根据扫描的二维码查询料仓
/// <summary>
/// 根据扫描的二维码查询料仓
/// </summary>
/// <param name="code">料仓条码信息</param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<BinView>> GetByBinCode(string code)
{
BinView view=new BinView();
log.Info(code);
if (!code.IsNotEmptyOrNull())
{
return Failed<BinView>("传入参数为空!");
}
var binList = await _binServices.QueryAsync();
var bin = binList.FirstOrDefault(d=>d.Bin_Code.Trim() == code.Trim());
if (bin == null) return Failed<BinView>("未查询到桶信息!");
var _materialList = await _xl_materialService.QueryAsync(d => d.IsEnable == "是");
xl_material mater = _materialList.Where(d => d.ID == bin.Material_ID).Take(1).FirstOrDefault(d => d.ID == bin.Material_ID);
if (_materialList == null) return Failed<BinView>("未查询到物料信息!");
view.Bin_Serial = bin.Bin_Serial;
view.Bin_Name = bin.Bin_Name;
view.Bin_Code = bin.Bin_Code;
view.Material_ID = mater.Material_code;
view.Material_Name = mater.Material_name;
view.Material_code = mater.Material_code;
return Success(view);
}
#endregion
#region 执行PLC
1 year ago
///<summary>
///执行PLC
1 year ago
/// <summary>
/// <param name="code">料仓排序Bin_Serial</param>
/// <param name="state">匹配状态条码匹配写“1”不匹配时写“2”</param>
/// <param name="materialCode">物料编码</param>
/// <param name="weight">物料重量</param>
9 months ago
/// <param name="barCode">物料二维码</param>
1 year ago
/// <returns></returns>
[HttpGet]
9 months ago
public async Task<MessageModel<bool>> ExecPlcCode(int code, int state,string materialCode,decimal weight,string? barCode)
1 year ago
{
//log.Info(code + "&" + state);
if (!code.IsNotEmptyOrNull())
{
return Failed<bool>("料仓条码信息传入参数为空!");
}
if (!state.IsNotEmptyOrNull())
{
return Failed<bool>("匹配状态传入参数为空!");
}
if (!materialCode.IsNotEmptyOrNull())
{
return Failed<bool>("匹配状态传入参数为空!");
}
if (!weight.IsNotEmptyOrNull())
{
return Failed<bool>("匹配状态传入参数为空!");
}
9 months ago
var result = await _xl_materialService.ExecPlcState(code, state, materialCode, weight, barCode);
if (result.success)
1 year ago
{
return result;
1 year ago
}
return Failed<bool>(result.msg);
1 year ago
}
#endregion
#region 检量称扫码绑定桶(新加)
/// <summary>
/// 检量称扫码绑定桶(新加)
/// </summary>
/// <param name="code">桶条码</param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<bool>> BindBarrel(string code)
{
if (!code.IsNotEmptyOrNull())
return Failed<bool>("桶条码信息传入参数为空!");
var result = await _xl_materialService.BindBarrel(code.Trim());
if (result == 0)
return Failed<bool>("未查询到正在执行的计划!");
if (result == 1)
return Failed<bool>("未查询到桶!");
if (result == 2)
return Failed<bool>($"未查询到[{code}]桶信息!");
if (result == 3)
return Failed<bool>("该桶已经绑定物料,请联系系统管理员处理!");
if (result == 6)
return Success(true);
if (result == 7)
return Failed<bool>("称重未完成!");
if (result == 8)
return Failed<bool>("PLC连接失败请检查PLC或者联系管理员处理");
if (result == 10)
return Failed<bool>("未知异常,请查看错误日志!");
if (result == 99)
return Failed<bool>("保存处理数据失败!");
if (result == 100)
return Failed<bool>("处理中....");
if (result == 110)
return Failed<bool>("执行批次未获取!");
return Failed<bool>("执行失败!");
}
#endregion
12 months ago
#region 获取当前正在称量的物料
1 year ago
/// <summary>
12 months ago
/// 获取当前正在称量的物料
1 year ago
/// </summary>
/// <returns></returns>
[HttpGet]
12 months ago
public Task<MessageModel<string>> GetCurrentMaterial()
1 year ago
{
12 months ago
MessageModel<string> ms=new MessageModel<string>();
return Task.FromResult(ms);
1 year ago
}
#endregion
#region 获取所有小料计划订单
/// <summary>
/// 获取所有小料计划订单
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<List<AllXlPlanView>>> GetXlPlanInfo()
{
MessageModel<List<AllXlPlanView>> message=new MessageModel<List<AllXlPlanView>>();
var list= await _xlPlanServices.GetAllXlPlanInfo();
if (list.Count>0)
{
message.success = true;
message.data = list;
}
else
{
message.success = false;
message.msg = "未查询到计划数据!";
}
return message;
}
#endregion
9 months ago
#region 料框防错验证——只验证单料
/// <summary>
/// 料框防错验证——只验证单料
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<bool>> MaterialVerification(string barCode)
{
MessageModel<bool> message = await _xl_materialService.MaterialVerification(barCode);
return message;
}
#endregion
/// <summary>
/// 小料同步MES物料信息
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<bool>> XlDownLoadMateralInfo(string materialCode, string materialName, int isEnable, DateTime createDateTime)
{
try
{
var result = await _xl_materialService.xlInsertMaterial(Guid.NewGuid().ToString("N"), materialCode, materialName, isEnable, createDateTime);
if (result)
{
return Success(result, "成功");
}
else
{
return Failed<bool>("执行失败!");
}
}
catch (Exception ex)
{
return Failed<bool>("执行失败!");
}
}
1 year ago
}
}