LocationService.cs
4.7 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
using Hh.Mes.Common.log;
using Hh.Mes.Common.Request;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Hh.Mes.Service.Warehous
{
public class LocationService : RepositorySqlSugar<base_location>
{
/// <summary>
/// 获取列表数据
/// </summary>
/// <param name="pageReq"></param>
/// <param name="model"></param>
/// <returns></returns>
public Response Load(PageReq pageReq, base_location model)
{
var list = GetLoad(model);
var table = list;
if (pageReq != null)
{
table = list.OrderByDescending(x => x.createTime).Skip((pageReq.page - 1) * pageReq.limit).Take(pageReq.limit).ToList();
}
var result = new Response
{
Result = table,
Count = list.Count
};
return result;
}
/// <summary>
/// 查询条件
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<base_location> GetLoad(base_location model)
{
var exp = Expressionable.Create<base_location>();
if (!string.IsNullOrWhiteSpace(model.lineCode)) exp.And(x => x.lineCode==model.lineCode);
if (model.zoneCode!=0) exp.And(x => x.zoneCode == model.zoneCode);
if (!string.IsNullOrWhiteSpace(model.locationType)) exp.And(x => x.locationType == model.locationType);
if (model.locationStatus!=0) exp.And(x => x.locationStatus == model.locationStatus);
var wheres = exp.ToExpression();//拼接表达式
return GetList(wheres);
}
/// <summary>
/// 新增
/// </summary>
public dynamic Ins(base_location model)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
model.keys = Guid.NewGuid();
model.createBy = base.sysWebUser?.Account;
var inventory = base.Context.Queryable<base_inventory>().First(x => x.warehouseCode == model.warehouseCode);
model.lineCode = inventory.lineCode;
model.createTime = DateTime.Now;
response.Status = Add(model);
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response;
});
}
/// <summary>
/// 更新
/// </summary>
public dynamic Upd(base_location model)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
model.updateBy = base.sysWebUser?.Account;
model.updateTime = DateTime.Now;
response.Status = base.Context.Updateable(model).
IgnoreColumns(it => new { it.createBy, it.createTime,it.lineCode }).ExecuteCommand() > 0;
if (!response.Status) response.Message = SystemVariable.dataActionError;
return response;
});
}
/// <summary>
/// 删除 code
/// </summary>
public dynamic DelByIds(string[] ids)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var index = 0;
foreach (var code in ids)
{
var isExit = Context.Queryable<base_inventory>().Any(u => u.locationCode == code);//是否存在
if (isExit)
{
index++;
//提示
response.Code = 300;
response.Message += $"库位料点数据:{code}在库存里面存在数据不能删除 <br>";
}
}
if (index > 0) return response;
foreach (var code in ids)
{
var isExit = Context.Queryable<bus_agv_task>().Any(u => u.materialFrameCode == code);
if (isExit) return response.ResponseError($"库位料点数据:{code}在AGV任务数据里面存在数据不能删除 <br>");
}
var temp = Context.Deleteable<base_location>().In(x =>x.locationCode, ids).ExecuteCommand()>0;
if (!temp)
{
response.Message = SystemVariable.dataActionError;
}
return response;
});
}
}
}