AgvTaskService.cs
5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using Hh.Mes.Common.log;
using Hh.Mes.Common.Request;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
namespace Hh.Mes.Service.WebService.Task
{
public class AgvTaskService : RepositorySqlSugar<bus_agv_task>
{
/// <summary>
/// //获取列表
/// </summary>
public Response Load(PageReq pageReq, bus_agv_task model)
{
var result = new Response();
string orderBy = (pageReq == null || string.IsNullOrEmpty(pageReq.field)) ? " id desc" : $"{pageReq.field} {pageReq.order} ";
string sqlWhere = SqlWhere(model);
var stringBuilder = new StringBuilder();
//页码,页数
//Exel ture 不分页
if (!model.Exel && pageReq != null)
{
stringBuilder.Append("declare @pageIndex int,@pageSize int,@offset int");
stringBuilder.AppendLine($" select @pageIndex={pageReq.page}, @pageSize={pageReq.limit}, @offset=(@pageIndex - 1) * @pageSize");
}
stringBuilder.AppendLine($@" select t1.* ,startPositionState=t2.locationStatus,endPositionState=t3.locationStatus
from [dbo].bus_agv_task t1 with(nolock)
left join base_location t2 on t1.startPosition=t2.locationCode
left join base_location t3 on t1.endPosition=t3.locationCode
where {sqlWhere}
order by {orderBy} ");
//Exel ture 不分页
if (!model.Exel)
{
stringBuilder.AppendLine(" offset @offset row fetch next @pageSize row only ");
stringBuilder.Append($" select rowTotal= count(*) from bus_agv_task t1 with(nolock) where {sqlWhere}");
}
var ds = base.Context.Ado.GetDataSetAll(stringBuilder.ToString(), new List<SugarParameter>(){
//new SugarParameter("@lineCode", model.lineCode),
//new SugarParameter("@workStationName", model.workStationName),
});
result.Result = ds.Tables[0];
result.Count = model.Exel ? (int)result.Result.Rows.Count : (int)ds.Tables[1].Rows[0]["rowTotal"];
return result;
}
public string SqlWhere(bus_agv_task model)
{
var stringBuilder = new StringBuilder();
stringBuilder.Append("1=1");
if (!string.IsNullOrWhiteSpace(model.taskCode))
{
stringBuilder.Append($" and taskCode like '%{model.taskCode}%'");
}
return stringBuilder.ToString();
}
/// <summary>
/// 删除方法
/// </summary>
/// <param name="ids">需要删除的id</param>
/// <returns></returns>
public dynamic DelByIds(Guid[] ids)
{
var response = new Response();
return response;
}
/// <summary>
/// 手动结束agv任务
/// </summary>
/// <param name="keys"></param>
/// <returns></returns>
public dynamic HandlerTaskEnd(Guid keys)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
#region before
var agvTask = Context.Queryable<bus_agv_task>().First(x => x.keys == keys);
if (agvTask == null) return response.ResponseError("找不到对应的任务信息");
if (agvTask.state == (int)EnumAGVState.任务完成) return response.ResponseError("任务已经完成,不能重复操作");
#endregion
#region save
//如果是【上料配送】 人工装料点空闲、组队上料点锁定,
//如果是【上料配送】 人工装料点空闲、组队上料点锁定【料框回收】人工装料点锁定、组队上料点空闲
var kongXian = (int)EnumLocationStatus.空闲;
var lockx = (int)EnumLocationStatus.锁定;
if (agvTask.agvTaskType == (int)EnumAgvTaskType.上料配送)
{
Context.Updateable<base_location>().SetColumns(x => x.locationStatus == kongXian)
.Where(x => x.locationCode == agvTask.startPosition).AddQueue();
Context.Updateable<base_location>().SetColumns(x => x.locationStatus == lockx)
.Where(x => x.locationCode == agvTask.endPosition).AddQueue();
}
else if (agvTask.agvTaskType == (int)EnumAgvTaskType.料框回收)
{
Context.Updateable<base_location>().SetColumns(x => x.locationStatus == lockx)
.Where(x => x.locationCode == agvTask.startPosition).AddQueue();
Context.Updateable<base_location>().SetColumns(x => x.locationStatus == kongXian)
.Where(x => x.locationCode == agvTask.endPosition).AddQueue();
}
//设置任务状态为完成
agvTask.state = (int)EnumAGVState.任务完成;
Context.Updateable(agvTask).UpdateColumns(x => new { x.state }).AddQueue();
Context.SaveQueues();
#endregion
#region 通知agv结束任务
//
#endregion
return response;
});
}
/// <summary>
/// 导出
/// </summary>
public dynamic Export(PageReq page, bus_agv_task entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = Load(null, entity);
return response;
});
}
}
}