|
|
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;
|
|
|
|
|
|
namespace Admin.Core.Api
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 小料料仓类型防差错
|
|
|
/// </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;
|
|
|
_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
|
|
|
/// <summary>
|
|
|
/// <param name="code">料仓排序Bin_Serial</param>
|
|
|
/// <param name="state">匹配状态:条码匹配写“1”,不匹配时写“2”</param>
|
|
|
/// <param name="materialCode">物料编码</param>
|
|
|
/// <param name="weight">物料重量</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet]
|
|
|
public async Task<MessageModel<bool>> ExecPlcCode(int code, int state,string materialCode,decimal weight)
|
|
|
{
|
|
|
//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>("匹配状态传入参数为空!");
|
|
|
}
|
|
|
var result = await _xl_materialService.ExecPlcState(code, state, materialCode, weight);
|
|
|
if (result.success)
|
|
|
{
|
|
|
return result;
|
|
|
}
|
|
|
return Failed<bool>(result.msg);
|
|
|
}
|
|
|
#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
|
|
|
|
|
|
#region 测试
|
|
|
/// <summary>
|
|
|
/// 测试
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet]
|
|
|
public Task<int> BindBarrel2()
|
|
|
{
|
|
|
decimal we2 = Convert.ToDecimal(Adapter.ReadInt16("DB104.DBW164")) / 100;//检量秤重量
|
|
|
int tcheckBatch = Adapter.ReadInt32("DB110.DBW212");//当前执行的车次
|
|
|
return Task.FromResult(tcheckBatch);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 获取所有小料计划订单
|
|
|
/// <summary>
|
|
|
/// 获取所有小料计划订单
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet]
|
|
|
[Obsolete("废弃")]
|
|
|
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
|
|
|
}
|
|
|
} |