using Tiger.Model;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq.Expressions;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Rhea.Common;
|
using System.Net;
|
using System.Linq;
|
using Newtonsoft.Json;
|
using Tiger.IBusiness;
|
using Microsoft.AspNetCore.Http;
|
using Tiger.Model.Entitys.MES.BizMesWoBatch;
|
using Tiger.Model.Entitys.MES.BizMesWo;
|
|
namespace Tiger.Business.MES
|
{
|
public partial class BizMesWo : IBIZ_MES_WO
|
{
|
/// <summary>
|
/// 保存
|
/// </summary>
|
/// <param name="wo"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> SaveMesWo(BIZ_MES_WO wo)
|
{
|
var result = new ApiAction();
|
try
|
{
|
var _wo = Biz.Db.Queryable<BIZ_MES_WO>().Where(x => x.ORDER_NO == wo.ORDER_NO).First();
|
if (_wo != null && _wo.STATUS != (int)BIZ_MES_WO.STATUSs.Init)
|
{
|
result.IsSuccessed = false;
|
result.LocaleMsg = new($"工单已经存在且不是初始化状态,不能保存修改!");
|
return result;
|
}
|
var db = Biz.Db;
|
var dbTran = db.UseTran(() =>
|
{
|
var y = db.Storageable(wo)
|
.WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW })
|
.ToStorage();
|
y.AsInsertable.ExecuteCommand();
|
y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
|
});
|
if (!dbTran.IsSuccess)
|
{
|
result.IsSuccessed = false;
|
result.Message = $"保存工单异常";
|
}
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "保存工单异常");
|
}
|
return await Task.FromResult(result);
|
}
|
|
/// <summary>
|
/// 删除工单
|
/// </summary>
|
/// <param name="woId"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> DeleteMesWo(string woId)
|
{
|
var result = new ApiAction();
|
try
|
{
|
//查询是否已经有工单在用
|
var _wo = Biz.Db.Queryable<BIZ_MES_WO>().Where(x => x.ID == woId).First();
|
if (_wo != null && _wo.STATUS != (int)BIZ_MES_WO.STATUSs.Init)
|
{
|
result.IsSuccessed = false;
|
result.LocaleMsg = new($"工单不是初始化状态,不能删除!");
|
return result;
|
}
|
var db = Biz.Db;
|
var dbTran = db.UseTran(() =>
|
{
|
db.Deleteable<BIZ_MES_WO>().Where(x => x.ID == woId).ExecuteCommand();
|
});
|
if (!dbTran.IsSuccess)
|
{
|
result.IsSuccessed = false;
|
result.LocaleMsg = new($"删除工单异常");
|
}
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "删除工单异常");
|
}
|
return await Task.FromResult(result);
|
}
|
|
/// <summary>
|
/// 下发时保存批次工单信息
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
public async Task<ApiAction> SaveMesBatchWo(SaveWoBatchInput input)
|
{
|
var result = new ApiAction();
|
try
|
{
|
WoContext.RemoveBatch(input.WoBatch.BATCH_NO);
|
//保存前的判断,并生成批次号
|
var _wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(x => x.ORDER_NO == input.Wo.ORDER_NO).FirstAsync();
|
//if (_wo.STATUS > (int)BIZ_MES_WO.STATUSs.Init)
|
//{
|
// result.IsSuccessed = false;
|
// result.LocaleMsg = new($"工单不是初始化状态,不能下发!");
|
// return result;
|
//}
|
if (_wo.STATUS > (int)BIZ_MES_WO.STATUSs.Working)
|
{
|
result.IsSuccessed = false;
|
result.LocaleMsg = new($"工单不是初始化状态,不能下发!");
|
return result;
|
}
|
var batchs = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.ORDER_NO == input.Wo.ORDER_NO).ToListAsync();
|
if (batchs.Count > 0 && batchs.Sum(x => x.PLAN_QTY) + input.WoBatch.PLAN_QTY > _wo.PLAN_QTY)
|
{
|
result.IsSuccessed = false;
|
result.LocaleMsg = new($"工单下发的数量超过工单计划数量,不能下发!");
|
return result;
|
}
|
var _batchWos = await Biz.Db.Queryable<V_MES_WO_BATCH>().Where(x => x.ORDER_NO == input.WoBatch.ORDER_NO).ToListAsync();
|
if (_batchWos.Count > 0)
|
{
|
input.WoBatch.BATCH_NO = $"{input.WoBatch.ORDER_NO}-{(_batchWos.Max(x => x.BATCH) + 1).ToString("D2")}";
|
}
|
else
|
{
|
input.WoBatch.BATCH_NO = $"{input.WoBatch.ORDER_NO}-01";
|
}
|
|
var db = Biz.Db;
|
var dbTran = db.UseTran(() =>
|
{
|
var y = db.Storageable(input.Wo)
|
.WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW })
|
.ToStorage();
|
y.AsInsertable.ExecuteCommand();
|
y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
|
|
db.Insertable(input.WoBatch).ExecuteCommand();
|
});
|
if (!dbTran.IsSuccess)
|
{
|
result.IsSuccessed = false;
|
result.LocaleMsg = new($"保存批次工单异常");
|
}
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "保存批次工单异常");
|
}
|
return result;
|
}
|
|
/// <summary>
|
/// 更新工单状态
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public async Task<ApiAction> UpdateWoStatus(BizMesWoInput input)
|
{
|
var result = new ApiAction();
|
try
|
{
|
//保存前的判断,并生成批次号
|
var _wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(x => x.ORDER_NO == input.WorkOrder).FirstAsync();
|
if (_wo != null)
|
{
|
_wo.STATUS = input.Status < 0 ? _wo.STATUS : input.Status;
|
_wo.ROUTE_STATUS = input.RouteStatus;
|
}
|
else
|
{
|
result.IsSuccessed = false;
|
result.LocaleMsg = new($"工单[{input.WorkOrder}]不存在");
|
return result;
|
}
|
|
var db = Biz.Db;
|
var dbTran = db.UseTran(() =>
|
{
|
db.Updateable(_wo, input.UserId).ExecuteCommand();
|
});
|
if (!dbTran.IsSuccess)
|
{
|
result.IsSuccessed = false;
|
result.LocaleMsg = new($"更新工单状态异常");
|
}
|
}
|
catch (Exception ex)
|
{
|
result.CatchExceptionWithLog(ex, "更新工单状态异常");
|
}
|
return result;
|
}
|
}
|
}
|