/*
|
*所有关于Dt_agvtask类的业务代码应在此处编写
|
*可使用repository.调用常用方法,获取EF/Dapper等信息
|
*如果需要事务请使用repository.DbContextBeginTransaction
|
*也可使用DBServerProvider.手动获取数据库相关信息
|
*用户信息、权限、角色等使用UserContext.Current操作
|
*Dt_agvtaskService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
|
*/
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using WIDESEA_Common;
|
using WIDESEA_Common.DBHelper;
|
using WIDESEA_Common.Tools;
|
using WIDESEA_Core.EFDbContext;
|
using WIDESEA_Core.ManageUser;
|
using WIDESEA_Core.Utilities;
|
using WIDESEA_Entity.DomainModels;
|
using WIDESEA_Services.IRepositories;
|
using WIDESEA_Services.Repositories;
|
|
namespace WIDESEA_Services.Services
|
{
|
public partial class dt_agvtaskService
|
{
|
FreeDB freeDB = new FreeDB();
|
|
/// <summary>
|
/// 取消任务
|
/// </summary>
|
/// <param name="keys"></param>
|
/// <param name="delList"></param>
|
/// <returns></returns>
|
public override WebResponseContent Del(object[] keys, bool delList = true)
|
{
|
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
var task = dt_agvtaskRepository.Instance
|
.Find(t => t.agv_tasknum == keys[0].ToString())
|
.FirstOrDefault();
|
VOLContext Context = new VOLContext();
|
Ibase_ware_locationRepository locationRepository = new base_ware_locationRepository(Context);
|
Idt_stationinfoRepository stationinfoRepository=new dt_stationinfoRepository(Context);
|
if (task != null)
|
{
|
|
base_ware_location loc_from = locationRepository.FindFirst(t => t.upper_code == task.agv_fromaddress);
|
base_ware_location loc_to = locationRepository.FindFirst(t => t.upper_code == task.agv_toaddress);
|
if (loc_from != null && loc_to != null)
|
{
|
if (loc_to.upper_code.Contains("GFHCJ"))
|
{
|
if (loc_to.upper_code.Contains("ZJ-GFHCJ10-"))
|
{
|
//string NUM = loc_to.upper_code.Remove(11) + "4";
|
//base_ware_location loc_gf = locationRepository.FindFirst(t => t.upper_code == NUM);
|
//if (loc_gf != null)
|
//{
|
|
loc_to.logic_col = 0;
|
loc_to.task = 2;
|
freeDB.Update(loc_to).UpdateColumns(t => new { t.location_state, t.logic_col, t.task }).ExecuteAffrows();
|
|
|
}
|
else
|
{
|
//string NUM = loc_to.upper_code.Remove(10) + "4";
|
//base_ware_location loc_gf = locationRepository.FindFirst(t => t.upper_code == NUM);
|
//if (loc_gf != null) {
|
dt_agvtask Agvtask = dt_agvtaskRepository.Instance.FindFirst(d => d.agv_tasknum != task.agv_tasknum && d.agv_toaddress.Contains(loc_to.upper_code));
|
if (Agvtask == null)
|
{
|
loc_to.logic_col = 0;
|
loc_to.task = 2;
|
int A = freeDB.Update(loc_from).UpdateColumns(t => new { t.logic_col, t.task }).ExecuteAffrows();
|
}
|
|
}
|
|
}
|
}
|
else if (loc_from != null && loc_to == null)
|
{
|
if (task.agv_toaddress.Contains("GFHCJ"))
|
{
|
string NUM = "";
|
string upcode = "";
|
if (task.agv_toaddress.Contains("ZJ-GFHCJ10-"))
|
{
|
NUM = task.agv_toaddress.Remove(11);
|
}
|
else
|
{
|
NUM = task.agv_toaddress.Remove(10);
|
}
|
if (NUM != "")
|
{
|
upcode = NUM + "4";
|
}
|
base_ware_location loc_gf = locationRepository.FindFirst(t => t.upper_code == upcode);
|
if (loc_gf != null)
|
{
|
|
loc_gf.logic_col = 0;
|
loc_gf.task = 2;
|
freeDB.Update(loc_gf).UpdateColumns(t => new { t.logic_col, t.task }).ExecuteAffrows();
|
|
}
|
AddHtyTask(task, "手动取消");
|
return content.OK($"任务{keys[0]},取消成功");
|
}
|
}
|
if (loc_from != null)
|
{
|
loc_from.logic_col = 0;
|
loc_from.task = 2;
|
//loc_from.light_color = "0";
|
int a = freeDB.Update(loc_from).UpdateColumns(t => new { t.logic_col, t.task }).ExecuteAffrows();
|
|
}
|
if (loc_to != null)
|
{
|
loc_to.logic_col = 0;
|
loc_to.task = 2;
|
int a = freeDB.Update(loc_to).UpdateColumns(t => new { t.logic_col, t.task }).ExecuteAffrows();
|
}
|
|
//一二楼铝壳缓存架任务取消
|
dt_stationinfo Stationinfo_from = stationinfoRepository.FindFirst(d => d.stationCode== task.agv_fromaddress);
|
dt_stationinfo Stationinfo_to = stationinfoRepository.FindFirst(d => d.stationCode == task.agv_toaddress);
|
if (Stationinfo_from != null)
|
{
|
Stationinfo_from.task = false;
|
//loc_from.light_color = "0";
|
int a = freeDB.Update(Stationinfo_from).UpdateColumns(t => new { t.task }).ExecuteAffrows();
|
|
}
|
if (Stationinfo_to != null)
|
{
|
Stationinfo_to.task = false;
|
int a = freeDB.Update(Stationinfo_to).UpdateColumns(t => new { t.task }).ExecuteAffrows();
|
}
|
|
AddHtyTask(task, "手动取消");
|
content.OK($"任务{keys[0]},取消成功");
|
//}
|
|
}
|
else
|
{
|
content.Error($"未找到任务信息");
|
}
|
//}
|
//else
|
//{
|
// task.agv_taskstate = AGVTaskStateEnum.WaitCancel.ToString();
|
// freeDB.Update(task).UpdateColumns(t => t.agv_taskstate).ExecuteAffrows();
|
//}
|
|
//else
|
//{
|
// throw new Exception($"任务{keys[0]},已不存在");
|
//}
|
}
|
catch (Exception ex)
|
{
|
//if (ex.Message.Contains("成功"))
|
//{
|
// content.OK(ex.Message);
|
//}
|
//else
|
//{
|
// content.Error(ex.Message);
|
//}
|
|
}
|
return content;
|
}
|
|
private void AddHtyTask(dt_agvtask task, string agv_taskstate)
|
{
|
freeDB.Add(new dt_agvtask_hty()
|
{
|
hty_pkid = Guid.NewGuid(),
|
agv_id = Guid.Empty,
|
agv_tasknum = task.agv_tasknum,
|
agv_materielid = task.agv_materielid,
|
agv_qty = task.agv_qty,
|
agv_createtime = task.agv_createtime,
|
agv_realesstime = task.agv_realesstime,
|
agv_executingBeginTime = task.agv_executingBeginTime,
|
agv_executingEndTime = task.agv_executingEndTime,
|
agv_completeBeginTime = task.agv_completeBeginTime,
|
agv_finishedtime = DateTime.Now,
|
agv_taskstate = agv_taskstate,
|
agv_tasktype = task.agv_tasktype,
|
agv_fromaddress = task.agv_fromaddress,
|
agv_toaddress = task.agv_toaddress,
|
agv_operatetype = string.Empty,
|
agv_compeletor = "wcs",
|
agv_completedate = DateTime.Now,
|
agv_grade = task.agv_grade,
|
agv_userid = UserContext.Current.UserName,
|
agv_barcode = task.agv_barcode,
|
agv_code = task.agv_code,
|
agv_worktype = task.agv_worktype
|
});
|
int a = freeDB.Remove(task);
|
}
|
|
|
/// <summary>
|
/// 手动任务完成
|
/// </summary>
|
/// <param name="agv_tasknum"></param>
|
public WebResponseContent FinishTask(string agv_tasknum)
|
{
|
VOLContext Context = new VOLContext();
|
Ibase_ware_locationRepository locRepository = new base_ware_locationRepository(Context);
|
List<base_ware_location> base_Ware_Locations_zj = locRepository.Find(t => t.upper_code.Contains("ZJ-BC") || t.upper_code.Contains("ZJ-TB")).OrderBy(t => t.order_num).ToList();
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
var task = dt_agvtaskRepository.Instance
|
.Find(t => t.agv_tasknum == agv_tasknum)
|
.FirstOrDefault();
|
if (task != null)
|
{
|
AddHtyTask(task, "手动完成");
|
//更新最后操作时间
|
FreeDB.DB.Update<dt_stationinfo>()
|
.Set(t => t.lastUpdateTime, DateTime.Now)
|
.Where(t => t.stationCode == task.agv_fromaddress || t.stationCode == task.agv_toaddress)
|
.ExecuteAffrows();
|
}
|
else
|
{
|
throw new Exception($"任务{agv_tasknum},已不存在");
|
}
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 手动下发任务
|
/// </summary>
|
/// <param name="agv_tasknum"></param>
|
public WebResponseContent sendTask(string fromaddress, string toaddress)
|
{
|
WebResponseContent content = new WebResponseContent();
|
FreeDB freeDB = new FreeDB();
|
try
|
{
|
if (fromaddress == null || toaddress == null)
|
{
|
content.Message = "数据不完整!";
|
content.Status = false;
|
throw new Exception(content.Message);
|
}
|
var from_location = freeDB.Select<base_ware_location>().Where(x => x.upper_code == fromaddress);
|
var to_location = freeDB.Select<base_ware_location>().Where(x => x.upper_code == toaddress);
|
//var from_location = base_ware_locationRepository.Instance.FindFirst(x => x.upper_code == fromaddress);
|
//var to_location = base_ware_locationRepository.Instance.FindFirst(x => x.upper_code == toaddress);
|
if (from_location == null)
|
{
|
content.Message = "起点地址不存在!";
|
content.Status = false;
|
throw new Exception(content.Message);
|
}
|
if (to_location == null)
|
{
|
content.Message = "终点地址不存在!";
|
content.Status = false;
|
throw new Exception(content.Message);
|
}
|
//if ((!fromaddress.Contains("ZJ-JKHCJ") && !fromaddress.Contains("ZJ-QJHCJ")))
|
//{
|
// content.Message = "起始货位不允许手动下发";
|
// content.Status = false;
|
// throw new Exception(content.Message);
|
//}
|
//if ((!toaddress.Contains("ZJ-JKHCJ") && !toaddress.Contains("ZJ-QJHCJ")))
|
//{
|
// content.Message = "目的货位不允许手动下发";
|
// content.Status = false;
|
// throw new Exception(content.Message);
|
//}
|
//判断首尾地址是否存在执行中任务
|
var task_to = dt_agvtaskRepository.Instance
|
.Find(t => t.agv_toaddress == toaddress || t.agv_fromaddress == toaddress)
|
.FirstOrDefault();
|
var task_from = dt_agvtaskRepository.Instance
|
.Find(t => t.agv_fromaddress == fromaddress || t.agv_toaddress == fromaddress)
|
.FirstOrDefault();
|
|
// var location_to=base_ware_locationRepository.Instance.Find(t=>t)
|
|
//判断路由合法性
|
//var rout = base_routing_tableRepository.Instance.Find(t => t.route_began == fromaddress && t.route_end == toaddress).FirstOrDefault();
|
|
if (task_to == null && task_from == null)//&& rout != null)
|
{
|
dt_agvtask agvtask = new dt_agvtask();
|
agvtask.agv_id = Guid.NewGuid();
|
agvtask.agv_fromaddress = fromaddress;
|
agvtask.agv_toaddress = toaddress;
|
agvtask.agv_tasknum = "KH-" + IdenxManager.GetTaskNo();
|
agvtask.agv_code = "组装AGV调度";
|
agvtask.agv_taskstate = AGVTaskStateEnum.Create.ToString();
|
agvtask.agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString();
|
agvtask.agv_worktype = 2;//工作类型
|
agvtask.agv_materielid = "A23";
|
agvtask.agv_qty = 1;
|
agvtask.agv_createtime = DateTime.Now;
|
agvtask.agv_grade = 0;//任务优先级
|
agvtask.agv_userid = UserContext.Current.UserName;
|
agvtask.agv_remark = "手动生成";
|
|
freeDB.Add(agvtask);
|
|
content.Status = true;
|
content.Message = "任务创建成功,正在通知AGV调度中心";
|
}
|
else
|
{
|
if (task_from != null)
|
{
|
content.Status = false;
|
content.Message += "起始地址正在执行任务! ";
|
}
|
if (task_to != null)
|
{
|
content.Status = false;
|
content.Message += "目的地址正在执行任务! ";
|
}
|
//if (rout == null)
|
//{
|
// content.Status = false;
|
// content.Message += "非法的路由规则! ";
|
//}
|
throw new Exception(content.Message);
|
}
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
|
public List<dt_agvtask> PDATask(List<dt_agvtask> agvtask)
|
{
|
WebResponseContent content = new WebResponseContent();
|
VOLContext Context = new VOLContext();
|
Ibase_pda_locationRepository pdaloctionRepository = new base_pda_locationRepository(Context);
|
Idt_containerRepository containerRepository = new dt_containerRepository(Context);
|
IVV_ContainerInfoRepository VV_ContainerInfoRepository = new VV_ContainerInfoRepository(Context);
|
Idt_materielinfoRepository materielinfoRepository = new dt_materielinfoRepository(Context);
|
Idt_agvtaskRepository agvRepository = new dt_agvtaskRepository(Context);
|
Ibase_routing_tableRepository routingRepository = new base_routing_tableRepository(Context);
|
Ibase_ware_locationRepository ibase_Ware_Location = new base_ware_locationRepository(Context);
|
try
|
{
|
List<dt_agvtask> agvtasks = agvRepository.Find(d => d.agv_remark.Contains("PDA")).ToList();
|
return agvtasks;
|
}
|
catch (Exception ex)
|
{
|
|
throw;
|
}
|
|
|
}
|
}
|
}
|