UpstreamSendUser.cs
3.22 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
using Hh.Mes.Common;
using Hh.Mes.Common.log;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.ApiEntity;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using System;
using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;
namespace Hh.Mes.Service.ApiService
{
public partial class UpstreamService
{
public dynamic SendUser(SysUserEntity entity)
{
var response = new ResponseUpstream<string>(entity.plmeid);
var user = new sys_user
{
account = entity.code,
plmeid = entity.plmeid,
name = entity.name,
sex = entity.gender == "男" ? 1 : 0,
password = Encryption.Encrypt("123456"),
otherCode = entity.code,
phoneNumber = entity.tel,
remarks = entity.remarks,
status = 1,
};
return ExceptionsHelp.Instance.ExecuteT(() =>
{
int resultCount = 0;
if (entity.type == EnumAction.I.ToString())
{
if (Context.Queryable<sys_user>().Any(t => t.plmeid == user.plmeid && t.status == 1))
{
return response.ResponseError($"【MOM】【name,plmeid】用户信息[{entity.name},{entity.plmeid}]已经存在,请勿重复添加!");
}
user.createTime = DateTime.Now;
resultCount = Context.Insertable(user).ExecuteCommand();
if (resultCount > 0)
{
var deptId = Context.Queryable<sys_dept>().Select(x => x.id).First();
var userId = Context.Queryable<sys_user>().First(x => x.plmeid == user.plmeid && x.status == 1).id;
var relevance = new sys_relevance
{
relKey = "UserOrg",
firstId = userId,
secondId = deptId,
createTime = DateTime.Now,
createBy = entity.code,
};
Context.Insertable(relevance).ExecuteCommand();
}
}
else if (entity.type == EnumAction.U.ToString())
{
user.updateTime = DateTime.Now;
resultCount = Context.Updateable(user)
.IgnoreColumns(it => new { it.createBy, it.createTime })
.Where(x => x.plmeid == entity.plmeid && x.status == 1).ExecuteCommand();
}
else if (entity.type == EnumAction.D.ToString())
{
user.updateTime = DateTime.Now;
resultCount = Context.Updateable<sys_user>()
.SetColumns(t => t.status == 0)
.Where(x => x.plmeid == entity.plmeid && x.status == 1)
.ExecuteCommand();
}
return resultCount > 0 ? response.ResponseSuccess() : response.ResponseError();
});
}
}
}