/*
|
*所有关于dt_agvtask类的业务代码应在此处编写
|
*可使用repository.调用常用方法,获取EF/Dapper等信息
|
*如果需要事务请使用repository.DbContextBeginTransaction
|
*也可使用DBServerProvider.手动获取数据库相关信息
|
*用户信息、权限、角色等使用UserContext.Current操作
|
*dt_agvtaskService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
|
*/
|
using WIDESEA_Core.BaseProvider;
|
using WIDESEA_Core.Extensions.AutofacManager;
|
using WIDESEA_Entity.DomainModels;
|
using System.Linq;
|
using WIDESEA_Core.Utilities;
|
using System.Linq.Expressions;
|
using WIDESEA_Core.Extensions;
|
using Microsoft.EntityFrameworkCore;
|
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.AspNetCore.Http;
|
using WIDESEA_WMS.IRepositories;
|
using WIDESEA_WMS.Repositories;
|
using WIDESEA_Core.EFDbContext;
|
using static System.Collections.Specialized.BitVector32;
|
using WIDESEA_Comm.TaskNo;
|
using WIDESEA_Common;
|
using WIDESEA_Core.ManageUser;
|
using WIDESEA_Comm.LogInfo;
|
|
namespace WIDESEA_WMS.Services
|
{
|
public partial class dt_agvtaskService
|
{
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly Idt_agvtaskRepository _repository;//访问数据库
|
|
[ActivatorUtilitiesConstructor]
|
public dt_agvtaskService(
|
Idt_agvtaskRepository dbRepository,
|
IHttpContextAccessor httpContextAccessor
|
)
|
: base(dbRepository)
|
{
|
_httpContextAccessor = httpContextAccessor;
|
_repository = dbRepository;
|
//多租户会用到这init代码,其他情况可以不用
|
//base.Init(dbRepository);
|
}
|
/// <summary>
|
/// 添加任务
|
/// </summary>
|
/// <param name="saveDataModel"></param>
|
/// <returns></returns>
|
public override WebResponseContent Add(SaveModel saveDataModel)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
VOLContext context = new VOLContext();
|
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
|
var fromaddress = saveDataModel.MainData["agv_fromaddress"].ToString();
|
var toaddress = saveDataModel.MainData["agv_toaddress"].ToString();
|
var tasktype = saveDataModel.MainData["agv_tasktype"].ToString();
|
var grade = saveDataModel.MainData["agv_grade"].ToInt();
|
var station1 = stationinfoRepository.FindFirst(x => x.stationCode == fromaddress);
|
var station2 = stationinfoRepository.FindFirst(x => x.stationCode == toaddress);
|
if (station1 == null || station2 == null)
|
throw new Exception($"起点地址{fromaddress}或终点地址{toaddress}不存在!");
|
if (string.IsNullOrEmpty(station1.stationType))
|
throw new Exception($"起点{fromaddress}未绑定物料类型!");
|
var task = _repository.Find(t => t.agv_fromaddress == fromaddress
|
|| t.agv_fromaddress == toaddress
|
|| t.agv_toaddress == fromaddress
|
|| t.agv_toaddress == toaddress
|
).Any();
|
if (task)
|
throw new Exception("起始或目的地址,已存在任务中!");
|
dt_agvtask agvtask = new dt_agvtask();
|
agvtask.agv_id = Guid.NewGuid();
|
agvtask.agv_fromaddress = fromaddress;
|
agvtask.agv_toaddress = toaddress;
|
agvtask.agv_tasknum = IdenxManager.GetTaskNo("KH-");
|
agvtask.agv_code = "AGV";
|
agvtask.agv_taskstate = AGVTaskStateEnum.Create.ToString();
|
agvtask.agv_tasktype = tasktype;
|
agvtask.agv_worktype = 1;//工作类型
|
agvtask.agv_materielid = station1.stationType;//物料类型
|
agvtask.agv_qty = station1.quantity;
|
agvtask.agv_createtime = DateTime.Now;
|
agvtask.agv_grade = grade;//任务优先级
|
agvtask.agv_userid = UserContext.Current.UserName;
|
_repository.Add(agvtask, true);
|
content.OK();
|
WriteDBLog.Success($"手动添加任务", new { 数据 = saveDataModel }, "WMS", UserContext.Current.UserName);
|
}
|
catch (Exception ex)
|
{
|
WriteDBLog.Error($"手动添加任务", new { 数据 = saveDataModel, 异常信息 = ex.Message }, "WMS", UserContext.Current.UserName);
|
content.Error(ex.Message);
|
}
|
|
return content;
|
}
|
}
|
}
|