StationUserRelService.cs
5.09 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
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 System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;
namespace Hh.Mes.Service.Configure
{
/// <summary>
/// 工位人员
/// </summary>
public class StationUserRelService : RepositorySqlSugar<base_station_user_rel>
{
/// <summary>
/// //获取 列表
/// </summary>
public Task<DataSet> Load(PageReq pageReq, base_station_user_rel model)
{
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.id,t2.lineName,workStationCode ,workStationName,t1.createBy,t1.createTime,t1.updateBy,t1.updateTime
,stuff((select ','+t5.name from base_station_user_rel t3
join sys_user t5 on t3.userId=t5.id
where t1.id=t3.stationId for xml path('')),1,1,'') peopleStation
from base_work_station t1 left join base_line t2 on t1.lineCode=t2.lineCode
where {sqlWhere}
order by {orderBy} ");
//Exel false 分页
if (!model.Exel)
{
stringBuilder.AppendLine(" offset @offset row fetch next @pageSize row only ");
stringBuilder.Append($" select rowTotal= count(*) from base_work_station t1 left join base_line t2 on t1.lineCode=t2.lineCode where {sqlWhere}");
}
return base.Context.Ado.GetDataSetAllAsync(stringBuilder.ToString());
}
public string SqlWhere(base_station_user_rel model)
{
var stringBuilder = new StringBuilder();
stringBuilder.Append("1=1");
if (!string.IsNullOrEmpty(model.lineName))
{
stringBuilder.Append($" and t2.lineName like '%{model.lineName}%' ");
}
if (!string.IsNullOrEmpty(model.name))
{
stringBuilder.Append($" and t1.name like '%{model.name}%' ");
}
return stringBuilder.ToString();
}
/// <summary>
/// 查找工位符合条件的用户
/// </summary>
public dynamic GetStationUserById(int stationId)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var result = base.Context.Queryable<base_station_user_rel>()
.Where(x => x.stationId == stationId)
.Select(it => new
{
it.userId
}).ToList();
response.Result = result;
return response;
});
}
/// <summary>
/// 工位分配人员 删除后新增。 1个工位对应过个用户
/// </summary>
/// <param name="stationId"></param>
/// <param name="userId"></param>
/// <param name="flag">(check选择,uncheck 取消)</param>
public dynamic Assign(string stationId ,string userId, string flag)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
var tempStationId = int.Parse(stationId.Split(",")[0]);
var userIdS = userId.Split(",");
var rels = new List<base_station_user_rel>();
foreach (var t in userIdS)
{
var model = new base_station_user_rel
{
stationId = tempStationId,
userId = int.Parse(t),
createBy = sysWebUser?.Account,
createTime = DateTime.Now
};
rels.Add(model);
Context.Deleteable<base_station_user_rel>().Where(x => x.stationId == tempStationId && x.userId == model.userId).AddQueue();
}
if (flag.Equals("check")) Context.Insertable(rels).AddQueue();
response.Status = Context.SaveQueues() > 0;
if (!response.Status)
{
response.Message = SystemVariable.dataActionError;
}
return response;
});
}
}
}