LqEmployeeProfileSubmissionService.cs
61.1 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NCC;
using NCC.Code;
using NCC.Common.Const;
using NCC.Common.Core.Manager;
using NCC.Common.Enum;
using NCC.Common.Filter;
using NCC.Common.Util;
using NCC.Common.Extension;
using NCC.DataEncryption;
using NCC.Dependency;
using NCC.DynamicApiController;
using NCC.Extend.Entitys.Dto.LqEmployeeProfileSubmission;
using NCC.Extend.Entitys.Enum;
using NCC.Extend.Entitys.lq_employee_profile;
using NCC.Extend.Entitys.lq_employee_profile_submission;
using NCC.Extend.Entitys.lq_mdxx;
using NCC.Extend.Interfaces.BusinessOperationLog;
using NCC.Extend.Interfaces.EmployeeStore;
using NCC.Extend.Interfaces.UserProfileAudit;
using NCC.Extend.Interfaces.UserProfileVersion;
using NCC.FriendlyException;
using NCC.System.Entitys.Permission;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SqlSugar;
using Yitter.IdGenerator;
namespace NCC.Extend
{
/// <summary>
/// 员工档案扫码入职匿名提交与人事审核
/// </summary>
[ApiDescriptionSettings(Tag = "员工档案-扫码入职", Name = "LqEmployeeProfileSubmission", Order = 211)]
[Route("api/Extend/LqEmployeeProfileSubmission")]
public class LqEmployeeProfileSubmissionService : IDynamicApiController, ITransient
{
private const string BizLogModule = "员工档案";
private const string BizTypeSubmission = "lq_employee_profile_submission";
private const string AuditSource = "EMPLOYEE_PROFILE_SUBMISSION";
private readonly ISqlSugarClient _db;
private readonly IUserManager _userManager;
private readonly IBusinessOperationLogService _businessOperationLogService;
private readonly IUserProfileAuditAppender _userProfileAuditAppender;
private readonly IUserProfileVersionAppender _userProfileVersionAppender;
private readonly IEmployeeStoreAssignmentHook _employeeStoreAssignmentHook;
/// <summary>
/// 初始化扫码入职提交服务
/// </summary>
public LqEmployeeProfileSubmissionService(
ISqlSugarClient db,
IUserManager userManager,
IBusinessOperationLogService businessOperationLogService,
IUserProfileAuditAppender userProfileAuditAppender,
IUserProfileVersionAppender userProfileVersionAppender,
IEmployeeStoreAssignmentHook employeeStoreAssignmentHook)
{
_db = db;
_userManager = userManager;
_businessOperationLogService = businessOperationLogService;
_userProfileAuditAppender = userProfileAuditAppender;
_userProfileVersionAppender = userProfileVersionAppender;
_employeeStoreAssignmentHook = employeeStoreAssignmentHook;
}
#region 公开接口
/// <summary>
/// 获取扫码入职公开表单配置
/// </summary>
/// <remarks>
/// 匿名页面初始化时调用,返回表单枚举、必填项,以及当前有效的组织和门店下拉项。
/// 组织和门店仅返回ID与名称,不包含主管、电话、地址等内部或敏感字段。
///
/// 示例请求:
/// ```json
/// {}
/// ```
///
/// 参数说明:
/// - 无请求参数
/// </remarks>
/// <returns>不含敏感信息的公开表单配置</returns>
/// <response code="200">成功返回公开表单配置</response>
/// <response code="500">服务器查询配置失败</response>
[AllowAnonymous]
[HttpGet("GetPublicConfig")]
public async Task<LqEmployeeProfileSubmissionPublicConfigOutput> GetPublicConfigAsync()
{
var organizeOptions = await _db.Queryable<OrganizeEntity>()
.Where(x => x.DeleteMark == null && x.EnabledMark == 1)
.OrderBy(x => x.SortCode)
.OrderBy(x => x.FullName)
.Select(x => new EmployeeProfilePublicOption
{
id = x.Id,
name = x.FullName
})
.ToListAsync();
var storeOptions = await _db.Queryable<LqMdxxEntity>()
.Where(x => x.Zxzt == "开店")
.Where(x => x.Status == null || x.Status != -1)
.OrderBy(x => x.Dm)
.Select(x => new EmployeeProfilePublicOption
{
id = x.Id,
name = x.Dm
})
.ToListAsync();
return new LqEmployeeProfileSubmissionPublicConfigOutput
{
certificatesTypeName = "身份证",
requiredFields = EmployeeProfileSensitiveHelper.PublicRequiredFields.ToList(),
educationOptions = EmployeeProfileSensitiveHelper.EducationLevels.ToList(),
maritalStatusOptions = BuildEnumOptions<EmployeeMaritalStatusEnum>(),
politicalStatusOptions = BuildEnumOptions<EmployeePoliticalStatusEnum>(),
householdTypeOptions = BuildEnumOptions<EmployeeHouseholdTypeEnum>(),
employeeTypeOptions = BuildEnumOptions<EmployeeTypeEnum>(),
employeeStatusOptions = BuildEnumOptions<EmployeeProfileStatusEnum>(),
probationMonthsOptions = BuildEnumOptions<EmployeeProbationMonthsEnum>(),
recruitmentTypeOptions = BuildEnumOptions<EmployeeRecruitmentTypeEnum>(),
organizeOptions = organizeOptions,
storeOptions = storeOptions,
submitHint = "提交后进入待审核,组织、岗位等信息由人事审核时填写;审核通过后才会创建/更新员工账号,请勿重复提交。"
};
}
/// <summary>
/// 校验扫码入职表单(不落库)
/// </summary>
/// <remarks>
/// 匿名提交前调用,校验字段格式、枚举值,并确认组织和可选门店仍处于有效状态。
///
/// 示例请求:
/// ```json
/// {
/// "realName": "张三",
/// "organizeId": "组织ID",
/// "mdid": "门店ID"
/// }
/// ```
///
/// 参数说明:
/// - input: 扫码入职公开填报数据
/// </remarks>
/// <param name="input">表单数据</param>
/// <returns>校验结果</returns>
/// <response code="200">校验通过</response>
/// <response code="400">校验失败</response>
/// <response code="500">服务器错误</response>
[AllowAnonymous]
[HttpPost("ValidateSubmit")]
public async Task<dynamic> ValidateSubmitAsync([FromBody] LqEmployeeProfileSubmissionCrInput input)
{
await ValidateSubmissionInputAsync(input, false);
return new { valid = true, message = "校验通过" };
}
/// <summary>
/// 匿名提交扫码入职申请
/// </summary>
/// <remarks>
/// 校验公开填报数据及组织、门店有效性后创建待审核申请,不会直接创建或更新员工账号。
///
/// 示例请求:
/// ```json
/// {
/// "realName": "张三",
/// "organizeId": "组织ID",
/// "mdid": "门店ID"
/// }
/// ```
///
/// 参数说明:
/// - input: 扫码入职公开填报数据
/// </remarks>
/// <param name="input">表单数据</param>
/// <returns>申请编号</returns>
/// <response code="200">提交成功</response>
/// <response code="400">校验失败或重复提交</response>
/// <response code="500">服务器错误</response>
[AllowAnonymous]
[HttpPost("Submit")]
public async Task<LqEmployeeProfileSubmissionSubmitOutput> SubmitAsync([FromBody] LqEmployeeProfileSubmissionCrInput input)
{
await ValidateSubmissionInputAsync(input, true);
var idCard = EmployeeProfileSensitiveHelper.NormalizeIdCard(input.idCardNo);
var idCardHash = EmployeeProfileSensitiveHelper.ComputeIdCardHash(idCard);
var mobile = EmployeeProfileSensitiveHelper.NormalizeMobile(input.mobilePhone);
var (submitIp, userAgent) = EmployeeProfileSensitiveHelper.ResolveSubmitClient();
await EnsureNotDuplicateSubmitAsync(idCardHash, submitIp);
var now = DateTime.Now;
var entity = MapSubmissionEntity(input, idCard, idCardHash, mobile, submitIp, userAgent, now);
entity.Id = YitIdHelper.NextId().ToString();
entity.SubmissionNo = EmployeeProfileSensitiveHelper.GenerateSubmissionNo();
entity.Status = (int)EmployeeProfileSubmissionStatusEnum.待审核;
entity.SubmitSource = (int)EmployeeProfileSubmissionSourceEnum.扫码填报;
entity.SubmitTime = now;
entity.CreateTime = now;
entity.UpdateTime = now;
entity.FormSnapshotJson = BuildSanitizedSnapshotJson(input, idCard, idCardHash);
var ok = await _db.Insertable(entity).ExecuteCommandAsync();
if (ok <= 0)
{
throw NCCException.Oh("提交失败,请稍后重试");
}
return new LqEmployeeProfileSubmissionSubmitOutput
{
submissionNo = entity.SubmissionNo,
message = "提交成功,请等待人事审核"
};
}
#endregion
#region 人事端
/// <summary>
/// 分页查询扫码入职申请
/// </summary>
/// <param name="input">查询条件</param>
/// <returns>分页列表</returns>
/// <response code="200">成功</response>
/// <response code="500">服务器错误</response>
[HttpGet("GetList")]
public async Task<dynamic> GetListAsync([FromQuery] LqEmployeeProfileSubmissionListQueryInput input)
{
input ??= new LqEmployeeProfileSubmissionListQueryInput();
var kw = string.IsNullOrWhiteSpace(input.keyword) ? null : input.keyword.Trim();
var endExclusive = input.submitTimeEnd?.Date.AddDays(1);
var userInfo = await _userManager.GetUserInfo();
var allowedOrganizeIds = userInfo.isAdministrator
? new List<string>()
: (userInfo.dataScope ?? new List<NCC.System.Entitys.Model.Permission.User.UserDataScope>())
.Where(x => x.Edit)
.Select(x => x.organizeId)
.Where(x => !string.IsNullOrWhiteSpace(x))
.Distinct()
.ToList();
var data = await _db.Queryable<LqEmployeeProfileSubmissionEntity>()
.WhereIF(!userInfo.isAdministrator, x =>
string.IsNullOrEmpty(x.OrganizeId) || allowedOrganizeIds.Contains(x.OrganizeId))
.WhereIF(input.status.HasValue, x => x.Status == input.status.Value)
.WhereIF(input.submitTimeStart.HasValue, x => x.SubmitTime >= input.submitTimeStart.Value)
.WhereIF(endExclusive.HasValue, x => x.SubmitTime < endExclusive.Value)
.WhereIF(kw != null, x => x.RealName.Contains(kw) || x.MobilePhone.Contains(kw) || x.SubmissionNo.Contains(kw))
.OrderBy(x => x.SubmitTime, OrderByType.Desc)
.Select(x => new LqEmployeeProfileSubmissionListOutput
{
id = x.Id,
submissionNo = x.SubmissionNo,
status = x.Status,
realName = x.RealName,
mobilePhoneMasked = x.MobilePhone,
idCardNoMasked = x.IdCardCipher,
entryDate = x.EntryDate,
employeeNo = x.EmployeeNo,
submitSource = x.SubmitSource,
submitTime = x.SubmitTime,
reviewUserName = x.ReviewUserName,
reviewTime = x.ReviewTime,
linkedUserId = x.LinkedUserId
})
.ToPagedListAsync(input.currentPage, input.pageSize);
foreach (var row in data.list)
{
row.statusName = EnumHelper.GetEnumDesc<EmployeeProfileSubmissionStatusEnum>(row.status);
row.submitSourceName = EnumHelper.GetEnumDesc<EmployeeProfileSubmissionSourceEnum>(row.submitSource);
row.mobilePhoneMasked = EmployeeProfileSensitiveHelper.MaskPhone(row.mobilePhoneMasked);
var idPlain = EmployeeProfileSensitiveHelper.DecryptSensitive(row.idCardNoMasked);
row.idCardNoMasked = EmployeeProfileSensitiveHelper.MaskIdCard(idPlain);
}
return PageResult<LqEmployeeProfileSubmissionListOutput>.SqlSugarPageResult(data);
}
/// <summary>
/// 获取扫码入职申请详情(敏感字段默认脱敏)
/// </summary>
/// <remarks>
/// 人事审核弹窗传 revealSensitive=true 返回手机号/身份证完整明文(需组织权限);
/// showTail4=true 时仅展示后 4 位;二者都不传则常规脱敏。
/// </remarks>
/// <param name="id">申请 ID</param>
/// <param name="showTail4">是否展示后 4 位(审核比对)</param>
/// <param name="revealSensitive">是否返回手机号/身份证完整明文(人事审核)</param>
/// <returns>详情</returns>
/// <response code="200">成功</response>
/// <response code="400">记录不存在</response>
/// <response code="500">服务器错误</response>
[HttpGet("GetInfo")]
public async Task<LqEmployeeProfileSubmissionInfoOutput> GetInfoAsync(
[FromQuery] string id,
[FromQuery] bool showTail4 = false,
[FromQuery] bool revealSensitive = false)
{
var entity = await GetSubmissionOrThrowAsync(id);
await EnsureCanEditOrganizeAsync(entity.OrganizeId);
return MapInfoOutput(entity, showTail4, revealSensitive);
}
/// <summary>
/// 审核通过(事务+幂等;可关联已有用户或创建新用户)
/// </summary>
/// <param name="input">审核参数</param>
/// <returns>关联用户 ID</returns>
/// <response code="200">审核成功</response>
/// <response code="400">状态或参数错误</response>
/// <response code="500">服务器错误</response>
[HttpPost("Approve")]
public async Task<dynamic> ApproveAsync([FromBody] LqEmployeeProfileSubmissionApproveInput input)
{
if (input == null || string.IsNullOrWhiteSpace(input.id))
{
throw NCCException.Oh("id 不能为空");
}
var submission = await GetSubmissionOrThrowAsync(input.id);
var reviewer = await EnsureCanEditOrganizeAsync(submission.OrganizeId);
if (submission.Status == (int)EmployeeProfileSubmissionStatusEnum.已通过
&& !string.IsNullOrWhiteSpace(submission.LinkedUserId))
{
return new
{
linkedUserId = submission.LinkedUserId,
message = "该申请已通过,无需重复操作",
idempotent = true
};
}
if (submission.Status != (int)EmployeeProfileSubmissionStatusEnum.待审核)
{
throw NCCException.Oh("仅待审核申请可通过");
}
if (input.linkExistingUser)
{
if (string.IsNullOrWhiteSpace(input.linkedUserId))
{
throw NCCException.Oh("关联已有用户时 linkedUserId 不能为空");
}
}
await ApplyApproveHrFieldsAsync(submission, input);
reviewer = await EnsureCanEditOrganizeAsync(submission.OrganizeId);
var idCardPlain = EmployeeProfileSensitiveHelper.DecryptSensitive(submission.IdCardCipher);
if (string.IsNullOrWhiteSpace(idCardPlain))
{
throw NCCException.Oh("申请身份证密文无效,无法审核");
}
if (!input.linkExistingUser
&& !reviewer.isAdministrator
&& !(reviewer.dataScope?.Any(x => x.organizeId == submission.OrganizeId && x.Add) ?? false))
{
throw NCCException.Oh(ErrorCode.D1013);
}
var reviewerId = reviewer.userId;
var reviewerName = reviewer.userName;
var now = DateTime.Now;
string linkedUserId;
UserEntity beforeUser = null;
UserEntity afterUser;
try
{
_db.Ado.BeginTran();
if (input.linkExistingUser)
{
var loadedUser = await _db.Queryable<UserEntity>()
.Where(x => x.Id == input.linkedUserId && x.DeleteMark == null)
.FirstAsync();
if (loadedUser == null)
{
throw NCCException.Oh("关联用户不存在");
}
if (!reviewer.isAdministrator
&& !(reviewer.dataScope?.Any(x => x.organizeId == loadedUser.OrganizeId && x.Edit) ?? false))
{
throw NCCException.Oh(ErrorCode.D1013);
}
beforeUser = UserProfileAuditAppenderService.CloneUser(loadedUser);
afterUser = UserProfileAuditAppenderService.CloneUser(loadedUser);
ApplySubmissionToUser(afterUser, submission, idCardPlain, keepAccount: true);
await _db.Updateable(afterUser).ExecuteCommandAsync();
linkedUserId = afterUser.Id;
}
else
{
var candidate = await FindCandidateUserAsync(submission, idCardPlain);
if (candidate != null)
{
throw NCCException.Oh($"检测到已有账号({candidate.Account}),请勾选关联已有用户并指定 linkedUserId={candidate.Id}");
}
afterUser = BuildNewUserFromSubmission(submission, idCardPlain);
afterUser.Id = YitIdHelper.NextId().ToString();
afterUser.CreatorTime = now;
afterUser.CreatorUserId = reviewerId;
await _db.Insertable(afterUser).ExecuteCommandAsync();
linkedUserId = afterUser.Id;
beforeUser = null;
}
await UpsertProfileFromSubmissionAsync(submission, linkedUserId, reviewerId, reviewerName, now);
submission.Status = (int)EmployeeProfileSubmissionStatusEnum.已通过;
submission.LinkedUserId = linkedUserId;
submission.ReviewUserId = reviewerId;
submission.ReviewUserName = reviewerName;
submission.ReviewTime = now;
submission.UpdateTime = now;
await _db.Updateable(submission).ExecuteCommandAsync();
await _userProfileAuditAppender.AppendProfileDiffAsync(
beforeUser,
afterUser,
"USER_ONBOARD_APPROVE",
AuditSource,
submission.Id,
input.remark);
await _userProfileVersionAppender.AfterUserProfilePersistedAsync(linkedUserId, AuditSource);
if (!string.IsNullOrWhiteSpace(afterUser.Mdid))
{
var oldMdid = beforeUser?.Mdid;
await _employeeStoreAssignmentHook.OnMdidChangedAsync(
linkedUserId,
oldMdid,
afterUser.Mdid.Trim(),
reviewerId,
reviewerName);
}
_db.Ado.CommitTran();
}
catch (Exception)
{
_db.Ado.RollbackTran();
throw;
}
var detailJson = JsonConvert.SerializeObject(new
{
submissionId = submission.Id,
submissionNo = submission.SubmissionNo,
linkedUserId,
linkExistingUser = input.linkExistingUser,
remark = input.remark
});
await _businessOperationLogService.WriteAsync(
BizLogModule,
"审核通过扫码入职",
BizTypeSubmission,
submission.Id,
$"审核通过扫码入职申请 {submission.SubmissionNo},关联用户 {linkedUserId}",
detailJson);
return new { linkedUserId, message = "审核通过", idempotent = false };
}
/// <summary>
/// 驳回扫码入职申请
/// </summary>
/// <param name="input">驳回参数</param>
/// <returns>操作结果</returns>
/// <response code="200">驳回成功</response>
/// <response code="400">状态或参数错误</response>
/// <response code="500">服务器错误</response>
[HttpPost("Reject")]
public async Task<dynamic> RejectAsync([FromBody] LqEmployeeProfileSubmissionRejectInput input)
{
if (input == null || string.IsNullOrWhiteSpace(input.id))
{
throw NCCException.Oh("id 不能为空");
}
if (string.IsNullOrWhiteSpace(input.rejectReason))
{
throw NCCException.Oh("驳回原因不能为空");
}
var submission = await GetSubmissionOrThrowAsync(input.id);
await EnsureCanEditOrganizeAsync(submission.OrganizeId);
if (submission.Status == (int)EmployeeProfileSubmissionStatusEnum.已驳回)
{
return new { message = "该申请已驳回", idempotent = true };
}
if (submission.Status != (int)EmployeeProfileSubmissionStatusEnum.待审核)
{
throw NCCException.Oh("仅待审核申请可驳回");
}
var before = new { submission.Status, submission.RejectReason };
var now = DateTime.Now;
submission.Status = (int)EmployeeProfileSubmissionStatusEnum.已驳回;
submission.RejectReason = input.rejectReason.Trim();
submission.ReviewUserId = _userManager.UserId;
submission.ReviewUserName = _userManager.RealName ?? _userManager.Account;
submission.ReviewTime = now;
submission.UpdateTime = now;
await _db.Updateable(submission).ExecuteCommandAsync();
await _businessOperationLogService.WriteAsync(
BizLogModule,
"驳回扫码入职",
BizTypeSubmission,
submission.Id,
$"驳回扫码入职申请 {submission.SubmissionNo},原因:{submission.RejectReason}",
JsonConvert.SerializeObject(new { before, after = new { submission.Status, submission.RejectReason } }));
return new { message = "已驳回", idempotent = false };
}
/// <summary>
/// 作废扫码入职申请
/// </summary>
/// <param name="input">作废参数</param>
/// <returns>操作结果</returns>
/// <response code="200">作废成功</response>
/// <response code="400">状态错误</response>
/// <response code="500">服务器错误</response>
[HttpPost("Void")]
public async Task<dynamic> VoidAsync([FromBody] LqEmployeeProfileSubmissionVoidInput input)
{
if (input == null || string.IsNullOrWhiteSpace(input.id))
{
throw NCCException.Oh("id 不能为空");
}
var submission = await GetSubmissionOrThrowAsync(input.id);
await EnsureCanEditOrganizeAsync(submission.OrganizeId);
if (submission.Status == (int)EmployeeProfileSubmissionStatusEnum.已作废)
{
return new { message = "该申请已作废", idempotent = true };
}
if (submission.Status == (int)EmployeeProfileSubmissionStatusEnum.已通过)
{
throw NCCException.Oh("已通过的申请不可作废,请走用户管理处理");
}
var beforeStatus = submission.Status;
var now = DateTime.Now;
submission.Status = (int)EmployeeProfileSubmissionStatusEnum.已作废;
submission.VoidUserId = _userManager.UserId;
submission.VoidTime = now;
submission.UpdateTime = now;
await _db.Updateable(submission).ExecuteCommandAsync();
await _businessOperationLogService.WriteAsync(
BizLogModule,
"作废扫码入职",
BizTypeSubmission,
submission.Id,
$"作废扫码入职申请 {submission.SubmissionNo}" + (string.IsNullOrWhiteSpace(input.reason) ? "" : $",原因:{input.reason}"),
JsonConvert.SerializeObject(new
{
before = new { status = beforeStatus },
after = new { status = submission.Status },
reason = input.reason
}));
return new { message = "已作废", idempotent = false };
}
#endregion
#region 私有方法
private async Task<LqEmployeeProfileSubmissionEntity> GetSubmissionOrThrowAsync(string id)
{
if (string.IsNullOrWhiteSpace(id))
{
throw NCCException.Oh("id 不能为空");
}
var entity = await _db.Queryable<LqEmployeeProfileSubmissionEntity>()
.Where(x => x.Id == id)
.FirstAsync();
if (entity == null)
{
throw NCCException.Oh("申请记录不存在");
}
return entity;
}
private static List<EmployeeProfileEnumOption> BuildEnumOptions<T>() where T : struct, Enum
{
return Enum.GetValues(typeof(T))
.Cast<T>()
.Select(e => new EmployeeProfileEnumOption
{
value = Convert.ToInt32(e),
label = EnumHelper.GetEnumDesc(e)
})
.ToList();
}
private async Task ValidateSubmissionInputAsync(
LqEmployeeProfileSubmissionCrInput input,
bool checkDuplicatePending)
{
if (input == null)
{
throw NCCException.Oh("参数不能为空");
}
if (string.IsNullOrWhiteSpace(input.realName))
{
throw NCCException.Oh("姓名不能为空");
}
if (!EmployeeProfileSensitiveHelper.IsValidMobile(input.mobilePhone))
{
throw NCCException.Oh("手机号格式不正确");
}
if (!input.gender.HasValue || (input.gender.Value != 1 && input.gender.Value != 2))
{
throw NCCException.Oh("性别只能为男或女");
}
var idCard = EmployeeProfileSensitiveHelper.NormalizeIdCard(input.idCardNo);
if (string.IsNullOrEmpty(idCard) || !idCard.IsIdentityCardId())
{
throw NCCException.Oh("身份证号不合法");
}
var idCardGender = EmployeeProfileSensitiveHelper.ParseGenderFromIdCard(idCard);
if (idCardGender.HasValue && idCardGender.Value != input.gender.Value)
{
throw NCCException.Oh("性别与身份证号不一致");
}
if (!string.IsNullOrWhiteSpace(input.organizeId))
{
input.organizeId = input.organizeId.Trim();
var organizeExists = await _db.Queryable<OrganizeEntity>()
.AnyAsync(x => x.Id == input.organizeId && x.DeleteMark == null && x.EnabledMark == 1);
if (!organizeExists)
{
throw NCCException.Oh("所选组织不存在或已停用");
}
}
if (!string.IsNullOrWhiteSpace(input.mdid))
{
input.mdid = input.mdid.Trim();
var storeExists = await _db.Queryable<LqMdxxEntity>()
.AnyAsync(x => x.Id == input.mdid
&& x.Zxzt == "开店"
&& (x.Status == null || x.Status != -1));
if (!storeExists)
{
throw NCCException.Oh("所选门店不存在或已停用");
}
}
if (string.IsNullOrWhiteSpace(input.urgentContacts))
{
throw NCCException.Oh("紧急联系人不能为空");
}
if (!EmployeeProfileSensitiveHelper.IsValidMobile(input.urgentTelePhone))
{
throw NCCException.Oh("紧急联系人电话格式不正确");
}
if (EmployeeProfileSensitiveHelper.IsSamePhoneAfterNormalize(input.mobilePhone, input.urgentTelePhone))
{
throw NCCException.Oh("紧急联系人电话不能与员工手机号相同");
}
if (!EmployeeProfileSensitiveHelper.IsValidEducation(input.education))
{
throw NCCException.Oh("文化程度取值无效,请选择:博士、硕士、本科、大专、中专、技校、高中、初中、小学");
}
if (string.IsNullOrWhiteSpace(input.currentAddress))
{
throw NCCException.Oh("现居住地址不能为空");
}
if (!EmployeeProfileSensitiveHelper.IsValidFullAddress(input.idCardAddress))
{
throw NCCException.Oh("身份证地址不能为空,且须填写完整地址(含区/县/街道/门牌等详细信息)");
}
if (!EmployeeProfileSensitiveHelper.IsValidHttpUrl(input.idCardFrontUrl))
{
throw NCCException.Oh("身份证正面照片不能为空且须为有效 URL");
}
if (!EmployeeProfileSensitiveHelper.IsValidHttpUrl(input.idCardBackUrl))
{
throw NCCException.Oh("身份证反面照片不能为空且须为有效 URL");
}
if (string.IsNullOrWhiteSpace(input.bankName))
{
throw NCCException.Oh("开户行不能为空");
}
if (string.IsNullOrWhiteSpace(input.bankCardNo))
{
throw NCCException.Oh("银行卡号不能为空");
}
if (string.IsNullOrWhiteSpace(input.bankAccountName))
{
throw NCCException.Oh("开户实名不能为空");
}
if (!EmployeeProfileSensitiveHelper.IsEnumDefined<EmployeeMaritalStatusEnum>(input.maritalStatus))
{
throw NCCException.Oh("婚姻状况枚举无效");
}
if (!EmployeeProfileSensitiveHelper.IsEnumDefined<EmployeePoliticalStatusEnum>(input.politicalStatus))
{
throw NCCException.Oh("政治面貌枚举无效");
}
if (!EmployeeProfileSensitiveHelper.IsEnumDefined<EmployeeHouseholdTypeEnum>(input.householdType))
{
throw NCCException.Oh("户口类型枚举无效");
}
if (!EmployeeProfileSensitiveHelper.IsEnumDefined<EmployeeTypeEnum>(input.employeeType))
{
throw NCCException.Oh("员工类型枚举无效");
}
if (!EmployeeProfileSensitiveHelper.IsEnumDefined<EmployeeProfileStatusEnum>(input.employeeStatus))
{
throw NCCException.Oh("员工状态枚举无效");
}
if (!EmployeeProfileSensitiveHelper.IsEnumDefined<EmployeeProbationMonthsEnum>(input.probationMonths))
{
throw NCCException.Oh("试用期月数枚举无效");
}
if (!EmployeeProfileSensitiveHelper.IsEnumDefined<EmployeeRecruitmentTypeEnum>(input.recruitmentType))
{
throw NCCException.Oh("招聘类型枚举无效");
}
if (!string.IsNullOrWhiteSpace(input.bankCardNo)
&& !EmployeeProfileSensitiveHelper.IsValidBankCard(input.bankCardNo))
{
throw NCCException.Oh("银行卡号格式不正确");
}
var autoRegularizationDate = EmployeeProfileSensitiveHelper.CalcRegularizationDate(
input.entryDate, input.probationMonths);
if (autoRegularizationDate.HasValue)
{
input.regularizationDate = autoRegularizationDate;
}
if (input.birthday.HasValue)
{
var idBirth = EmployeeProfileSensitiveHelper.ParseBirthdayFromIdCard(idCard);
if (idBirth.HasValue && idBirth.Value.Date != input.birthday.Value.Date)
{
throw NCCException.Oh("出生日期与身份证号不一致");
}
}
if (input.enrollmentDate.HasValue && input.graduationDate.HasValue
&& input.graduationDate.Value.Date < input.enrollmentDate.Value.Date)
{
throw NCCException.Oh("毕业时间不能早于入学时间");
}
if (input.previousStartDate.HasValue && input.previousEndDate.HasValue
&& input.previousEndDate.Value.Date < input.previousStartDate.Value.Date)
{
throw NCCException.Oh("前公司结束时间不能早于开始时间");
}
if (input.regularizationDate.HasValue && input.entryDate.HasValue
&& input.regularizationDate.Value.Date < input.entryDate.Value.Date)
{
throw NCCException.Oh("转正日期不能早于入职日期");
}
if (checkDuplicatePending)
{
return;
}
}
private async Task EnsureNotDuplicateSubmitAsync(string idCardHash, string submitIp)
{
var pending = await _db.Queryable<LqEmployeeProfileSubmissionEntity>()
.Where(x => x.IdCardHash == idCardHash
&& x.Status == (int)EmployeeProfileSubmissionStatusEnum.待审核)
.AnyAsync();
if (pending)
{
throw NCCException.Oh("该身份证已有待审核申请,请勿重复提交");
}
var windowStart = DateTime.Now.AddMinutes(-EmployeeProfileSensitiveHelper.DuplicateSubmitWindowMinutes);
var recentSameId = await _db.Queryable<LqEmployeeProfileSubmissionEntity>()
.Where(x => x.IdCardHash == idCardHash && x.SubmitTime >= windowStart)
.AnyAsync();
if (recentSameId)
{
throw NCCException.Oh("提交过于频繁,请稍后再试");
}
if (!string.IsNullOrWhiteSpace(submitIp))
{
var ipWindow = DateTime.Now.AddMinutes(-EmployeeProfileSensitiveHelper.SameIpSubmitWindowMinutes);
var recentIp = await _db.Queryable<LqEmployeeProfileSubmissionEntity>()
.Where(x => x.SubmitIp == submitIp && x.IdCardHash == idCardHash && x.SubmitTime >= ipWindow)
.AnyAsync();
if (recentIp)
{
throw NCCException.Oh("同一网络下提交过于频繁,请稍后再试");
}
}
}
private static LqEmployeeProfileSubmissionEntity MapSubmissionEntity(
LqEmployeeProfileSubmissionCrInput input,
string idCard,
string idCardHash,
string mobile,
string submitIp,
string userAgent,
DateTime now)
{
return new LqEmployeeProfileSubmissionEntity
{
RealName = input.realName?.Trim(),
MobilePhone = mobile,
Gender = input.gender,
Birthday = input.birthday?.Date ?? EmployeeProfileSensitiveHelper.ParseBirthdayFromIdCard(idCard),
Nation = input.nation?.Trim(),
NativePlace = input.nativePlace?.Trim(),
IdCardCipher = EmployeeProfileSensitiveHelper.EncryptSensitive(idCard),
IdCardHash = idCardHash,
Education = input.education?.Trim(),
EntryDate = input.entryDate?.Date,
OrganizeId = input.organizeId?.Trim(),
Mdid = input.mdid?.Trim(),
Zw = input.zw?.Trim(),
Gwfl = input.gwfl?.Trim(),
Gw = input.gw?.Trim(),
TelePhone = input.telePhone?.Trim(),
Landline = input.landline?.Trim(),
UrgentContacts = input.urgentContacts?.Trim(),
UrgentTelePhone = EmployeeProfileSensitiveHelper.NormalizeMobile(input.urgentTelePhone),
PostalAddress = input.postalAddress?.Trim(),
MaritalStatus = input.maritalStatus,
PoliticalStatus = input.politicalStatus,
HouseholdType = input.householdType,
CurrentAddress = input.currentAddress?.Trim(),
EmployeeNo = string.IsNullOrWhiteSpace(input.employeeNo) ? null : input.employeeNo.Trim(),
EmployeeType = input.employeeType,
EmployeeStatus = input.employeeStatus,
ProbationMonths = input.probationMonths,
RegularizationDate = EmployeeProfileSensitiveHelper.CalcRegularizationDate(input.entryDate, input.probationMonths)
?? input.regularizationDate?.Date,
RecruitmentType = input.recruitmentType,
BankName = input.bankName?.Trim(),
BankCardCipher = string.IsNullOrWhiteSpace(input.bankCardNo)
? null
: EmployeeProfileSensitiveHelper.EncryptSensitive(
EmployeeProfileSensitiveHelper.NormalizeBankCard(input.bankCardNo)),
BankAccountName = input.bankAccountName?.Trim(),
IdCardAddress = input.idCardAddress?.Trim(),
IdCardFrontUrl = input.idCardFrontUrl?.Trim(),
IdCardBackUrl = input.idCardBackUrl?.Trim(),
GraduateSchool = input.graduateSchool?.Trim(),
EnrollmentDate = input.enrollmentDate?.Date,
GraduationDate = input.graduationDate?.Date,
Major = input.major?.Trim(),
PreviousCompany = input.previousCompany?.Trim(),
PreviousPosition = input.previousPosition?.Trim(),
PreviousStartDate = input.previousStartDate?.Date,
PreviousEndDate = input.previousEndDate?.Date,
EmergencyContactRelation = input.emergencyContactRelation?.Trim(),
EmergencyContactAddress = input.emergencyContactAddress?.Trim(),
SubmitIp = submitIp,
UserAgent = userAgent
};
}
private static string BuildSanitizedSnapshotJson(
LqEmployeeProfileSubmissionCrInput input,
string idCard,
string idCardHash)
{
var snapshot = JObject.FromObject(input);
snapshot[nameof(input.idCardNo)] = EmployeeProfileSensitiveHelper.MaskIdCard(idCard);
snapshot[nameof(input.bankCardNo)] = string.IsNullOrWhiteSpace(input.bankCardNo)
? null
: EmployeeProfileSensitiveHelper.MaskBankCard(
EmployeeProfileSensitiveHelper.NormalizeBankCard(input.bankCardNo));
snapshot["idCardHash"] = idCardHash;
return snapshot.ToString(Formatting.None);
}
private static LqEmployeeProfileSubmissionInfoOutput MapInfoOutput(
LqEmployeeProfileSubmissionEntity entity,
bool showTail4,
bool revealSensitive = false)
{
var idPlain = EmployeeProfileSensitiveHelper.DecryptSensitive(entity.IdCardCipher);
var bankPlain = EmployeeProfileSensitiveHelper.DecryptSensitive(entity.BankCardCipher);
string MaskSensitive(string plain, Func<string, string> defaultMask, bool allowReveal)
{
if (string.IsNullOrWhiteSpace(plain))
{
return "无";
}
// 人事审核:手机号/身份证返回完整明文
if (allowReveal && revealSensitive)
{
return plain.Trim();
}
return showTail4 ? EmployeeProfileSensitiveHelper.MaskTail4(plain) : defaultMask(plain);
}
return new LqEmployeeProfileSubmissionInfoOutput
{
id = entity.Id,
submissionNo = entity.SubmissionNo,
status = entity.Status,
statusName = EnumHelper.GetEnumDesc<EmployeeProfileSubmissionStatusEnum>(entity.Status),
rejectReason = entity.RejectReason,
linkedUserId = entity.LinkedUserId,
reviewUserName = entity.ReviewUserName,
reviewTime = entity.ReviewTime,
submitSource = entity.SubmitSource,
submitSourceName = EnumHelper.GetEnumDesc<EmployeeProfileSubmissionSourceEnum>(entity.SubmitSource),
submitIp = entity.SubmitIp,
submitTime = entity.SubmitTime,
realName = entity.RealName,
mobilePhoneMasked = MaskSensitive(entity.MobilePhone, EmployeeProfileSensitiveHelper.MaskPhone, allowReveal: true),
gender = entity.Gender,
birthday = entity.Birthday,
nation = entity.Nation,
nativePlace = entity.NativePlace,
idCardNoMasked = MaskSensitive(idPlain, EmployeeProfileSensitiveHelper.MaskIdCard, allowReveal: true),
education = entity.Education,
entryDate = entity.EntryDate,
organizeId = entity.OrganizeId,
mdid = entity.Mdid,
zw = entity.Zw,
gwfl = entity.Gwfl,
gw = entity.Gw,
telePhone = entity.TelePhone,
landline = entity.Landline,
urgentContacts = entity.UrgentContacts,
urgentTelePhone = entity.UrgentTelePhone,
postalAddress = entity.PostalAddress,
maritalStatus = entity.MaritalStatus,
politicalStatus = entity.PoliticalStatus,
householdType = entity.HouseholdType,
currentAddress = entity.CurrentAddress,
employeeNo = entity.EmployeeNo,
employeeType = entity.EmployeeType,
employeeStatus = entity.EmployeeStatus,
probationMonths = entity.ProbationMonths,
regularizationDate = entity.RegularizationDate,
recruitmentType = entity.RecruitmentType,
bankName = entity.BankName,
bankCardNoMasked = MaskSensitive(bankPlain, EmployeeProfileSensitiveHelper.MaskBankCard, allowReveal: false),
bankAccountName = entity.BankAccountName,
idCardAddress = entity.IdCardAddress,
idCardFrontUrl = entity.IdCardFrontUrl,
idCardBackUrl = entity.IdCardBackUrl,
graduateSchool = entity.GraduateSchool,
enrollmentDate = entity.EnrollmentDate,
graduationDate = entity.GraduationDate,
major = entity.Major,
previousCompany = entity.PreviousCompany,
previousPosition = entity.PreviousPosition,
previousStartDate = entity.PreviousStartDate,
previousEndDate = entity.PreviousEndDate,
emergencyContactRelation = entity.EmergencyContactRelation,
emergencyContactAddress = entity.EmergencyContactAddress
};
}
private async Task<UserEntity> FindCandidateUserAsync(LqEmployeeProfileSubmissionEntity submission, string idCardPlain)
{
var byCert = await _db.Queryable<UserEntity>()
.Where(x => x.DeleteMark == null && x.CertificatesNumber == idCardPlain)
.FirstAsync();
if (byCert != null)
{
return byCert;
}
var byMobile = await _db.Queryable<UserEntity>()
.Where(x => x.DeleteMark == null && x.MobilePhone == submission.MobilePhone)
.FirstAsync();
if (byMobile != null)
{
return byMobile;
}
var byAccount = await _db.Queryable<UserEntity>()
.Where(x => x.DeleteMark == null && x.Account == submission.MobilePhone)
.FirstAsync();
if (byAccount != null)
{
return byAccount;
}
return null;
}
private async Task<NCC.System.Entitys.Model.Permission.User.UserInfo> EnsureCanEditOrganizeAsync(
string organizeId)
{
var userInfo = await _userManager.GetUserInfo();
if (userInfo.isAdministrator)
{
return userInfo;
}
if (string.IsNullOrWhiteSpace(organizeId))
{
if (userInfo.dataScope?.Any(x => x.Edit) ?? false)
{
return userInfo;
}
throw NCCException.Oh(ErrorCode.D1013);
}
if (!(userInfo.dataScope?.Any(x => x.organizeId == organizeId && x.Edit) ?? false))
{
throw NCCException.Oh(ErrorCode.D1013);
}
return userInfo;
}
private async Task ApplyApproveHrFieldsAsync(
LqEmployeeProfileSubmissionEntity submission,
LqEmployeeProfileSubmissionApproveInput input)
{
if (input.entryDate.HasValue)
{
submission.EntryDate = input.entryDate.Value.Date;
}
if (!string.IsNullOrWhiteSpace(input.organizeId))
{
submission.OrganizeId = input.organizeId.Trim();
}
if (input.mdid != null)
{
submission.Mdid = string.IsNullOrWhiteSpace(input.mdid) ? null : input.mdid.Trim();
}
if (input.zw != null)
{
submission.Zw = string.IsNullOrWhiteSpace(input.zw) ? null : input.zw.Trim();
}
if (input.gwfl != null)
{
submission.Gwfl = string.IsNullOrWhiteSpace(input.gwfl) ? null : input.gwfl.Trim();
}
if (input.gw != null)
{
submission.Gw = string.IsNullOrWhiteSpace(input.gw) ? null : input.gw.Trim();
}
if (input.employeeNo != null)
{
submission.EmployeeNo = string.IsNullOrWhiteSpace(input.employeeNo) ? null : input.employeeNo.Trim();
}
if (input.employeeType.HasValue)
{
submission.EmployeeType = input.employeeType;
}
if (input.employeeStatus.HasValue)
{
submission.EmployeeStatus = input.employeeStatus;
}
if (input.probationMonths.HasValue)
{
submission.ProbationMonths = input.probationMonths;
}
if (input.regularizationDate.HasValue)
{
submission.RegularizationDate = input.regularizationDate.Value.Date;
}
var autoRegularizationDate = EmployeeProfileSensitiveHelper.CalcRegularizationDate(
submission.EntryDate, submission.ProbationMonths);
if (autoRegularizationDate.HasValue)
{
submission.RegularizationDate = autoRegularizationDate;
}
if (input.recruitmentType.HasValue)
{
submission.RecruitmentType = input.recruitmentType;
}
if (!submission.EntryDate.HasValue)
{
throw NCCException.Oh("审核通过前必须填写入职日期");
}
if (string.IsNullOrWhiteSpace(submission.OrganizeId))
{
throw NCCException.Oh("审核通过前必须选择组织");
}
var organizeExists = await _db.Queryable<OrganizeEntity>()
.AnyAsync(x => x.Id == submission.OrganizeId && x.DeleteMark == null && x.EnabledMark == 1);
if (!organizeExists)
{
throw NCCException.Oh("所选组织不存在或已停用");
}
if (!string.IsNullOrWhiteSpace(submission.Mdid))
{
var storeExists = await _db.Queryable<LqMdxxEntity>()
.AnyAsync(x => x.Id == submission.Mdid
&& x.Zxzt == "开店"
&& (x.Status == null || x.Status != -1));
if (!storeExists)
{
throw NCCException.Oh("所选门店不存在或已停用");
}
}
if (!EmployeeProfileSensitiveHelper.IsEnumDefined<EmployeeTypeEnum>(submission.EmployeeType))
{
throw NCCException.Oh("员工类型枚举无效");
}
if (!EmployeeProfileSensitiveHelper.IsEnumDefined<EmployeeProfileStatusEnum>(submission.EmployeeStatus))
{
throw NCCException.Oh("员工状态枚举无效");
}
if (!EmployeeProfileSensitiveHelper.IsEnumDefined<EmployeeProbationMonthsEnum>(submission.ProbationMonths))
{
throw NCCException.Oh("试用期月数枚举无效");
}
if (!EmployeeProfileSensitiveHelper.IsEnumDefined<EmployeeRecruitmentTypeEnum>(submission.RecruitmentType))
{
throw NCCException.Oh("招聘类型枚举无效");
}
ValidateSubmissionProfileFields(submission);
if (submission.RegularizationDate.HasValue
&& submission.RegularizationDate.Value.Date < submission.EntryDate.Value.Date)
{
throw NCCException.Oh("转正日期不能早于入职日期");
}
}
private static void ValidateSubmissionProfileFields(LqEmployeeProfileSubmissionEntity submission)
{
if (!EmployeeProfileSensitiveHelper.IsValidEducation(submission.Education))
{
throw NCCException.Oh("文化程度取值无效,请选择:博士、硕士、本科、大专、中专、技校、高中、初中、小学");
}
if (string.IsNullOrWhiteSpace(submission.CurrentAddress))
{
throw NCCException.Oh("现居住地址不能为空");
}
if (!EmployeeProfileSensitiveHelper.IsValidFullAddress(submission.IdCardAddress))
{
throw NCCException.Oh("身份证地址不能为空,且须填写完整地址(含区/县/街道/门牌等详细信息)");
}
if (!EmployeeProfileSensitiveHelper.IsValidHttpUrl(submission.IdCardFrontUrl))
{
throw NCCException.Oh("身份证正面照片不能为空且须为有效 URL");
}
if (!EmployeeProfileSensitiveHelper.IsValidHttpUrl(submission.IdCardBackUrl))
{
throw NCCException.Oh("身份证反面照片不能为空且须为有效 URL");
}
if (string.IsNullOrWhiteSpace(submission.BankName))
{
throw NCCException.Oh("开户行不能为空");
}
if (string.IsNullOrWhiteSpace(submission.BankCardCipher))
{
throw NCCException.Oh("银行卡号不能为空");
}
if (string.IsNullOrWhiteSpace(submission.BankAccountName))
{
throw NCCException.Oh("开户实名不能为空");
}
if (EmployeeProfileSensitiveHelper.IsSamePhoneAfterNormalize(
submission.MobilePhone, submission.UrgentTelePhone))
{
throw NCCException.Oh("紧急联系人电话不能与员工手机号相同");
}
}
private static UserEntity BuildNewUserFromSubmission(LqEmployeeProfileSubmissionEntity submission, string idCardPlain)
{
var mobile = submission.MobilePhone;
var entity = new UserEntity
{
Account = mobile,
RealName = submission.RealName,
NickName = submission.RealName,
Gender = submission.Gender,
Birthday = submission.Birthday,
MobilePhone = mobile,
TelePhone = submission.TelePhone,
Landline = submission.Landline,
Nation = submission.Nation,
NativePlace = submission.NativePlace,
CertificatesType = EmployeeProfileSensitiveHelper.IdCardCertificateTypeId,
CertificatesNumber = idCardPlain,
Education = submission.Education,
EntryDate = submission.EntryDate,
OrganizeId = submission.OrganizeId,
Mdid = submission.Mdid,
Zw = submission.Zw,
Gwfl = submission.Gwfl,
Gw = submission.Gw,
UrgentContacts = submission.UrgentContacts,
UrgentTelePhone = submission.UrgentTelePhone,
PostalAddress = submission.PostalAddress,
IsOnJob = 1,
LeaveDate = null,
EnabledMark = 1,
IsAdministrator = 0,
HeadIcon = "001.png",
QuickQuery = PinyinUtil.PinyinString(submission.RealName),
Secretkey = Guid.NewGuid().ToString(),
ExtensionLong = 1024L * 1024 * 1024
};
entity.Password = MD5Encryption.Encrypt(
MD5Encryption.Encrypt(CommonConst.DEFAULT_PASSWORD) + entity.Secretkey);
return entity;
}
private static void ApplySubmissionToUser(
UserEntity user,
LqEmployeeProfileSubmissionEntity submission,
string idCardPlain,
bool keepAccount)
{
if (!keepAccount)
{
user.Account = submission.MobilePhone;
}
user.RealName = submission.RealName;
user.NickName = submission.RealName;
user.Gender = submission.Gender;
user.Birthday = submission.Birthday;
user.MobilePhone = submission.MobilePhone;
user.TelePhone = submission.TelePhone;
user.Landline = submission.Landline;
user.Nation = submission.Nation;
user.NativePlace = submission.NativePlace;
user.CertificatesType = EmployeeProfileSensitiveHelper.IdCardCertificateTypeId;
user.CertificatesNumber = idCardPlain;
user.Education = submission.Education;
user.EntryDate = submission.EntryDate;
user.OrganizeId = submission.OrganizeId;
user.Mdid = submission.Mdid;
user.Zw = submission.Zw;
user.Gwfl = submission.Gwfl;
user.Gw = submission.Gw;
user.UrgentContacts = submission.UrgentContacts;
user.UrgentTelePhone = submission.UrgentTelePhone;
user.PostalAddress = submission.PostalAddress;
user.IsOnJob = 1;
user.LeaveDate = null;
user.LastModifyTime = DateTime.Now;
user.QuickQuery = PinyinUtil.PinyinString(submission.RealName);
}
private async Task UpsertProfileFromSubmissionAsync(
LqEmployeeProfileSubmissionEntity submission,
string userId,
string reviewerId,
string reviewerName,
DateTime now)
{
if (!string.IsNullOrWhiteSpace(submission.EmployeeNo))
{
var dup = await _db.Queryable<LqEmployeeProfileEntity>()
.Where(x => x.EmployeeNo == submission.EmployeeNo && x.UserId != userId)
.AnyAsync();
if (dup)
{
throw NCCException.Oh("工号已被其他员工使用");
}
}
var existing = await _db.Queryable<LqEmployeeProfileEntity>()
.Where(x => x.UserId == userId)
.FirstAsync();
if (existing == null)
{
var profile = new LqEmployeeProfileEntity
{
Id = YitIdHelper.NextId().ToString(),
UserId = userId,
MaritalStatus = submission.MaritalStatus,
PoliticalStatus = submission.PoliticalStatus,
HouseholdType = submission.HouseholdType,
CurrentAddress = submission.CurrentAddress,
EmployeeNo = submission.EmployeeNo,
EmployeeType = submission.EmployeeType,
EmployeeStatus = submission.EmployeeStatus,
ProbationMonths = submission.ProbationMonths,
RegularizationDate = submission.RegularizationDate,
RecruitmentType = submission.RecruitmentType,
BankName = submission.BankName,
BankCardCipher = submission.BankCardCipher,
BankAccountName = submission.BankAccountName,
IdCardAddress = submission.IdCardAddress,
IdCardFrontUrl = submission.IdCardFrontUrl,
IdCardBackUrl = submission.IdCardBackUrl,
GraduateSchool = submission.GraduateSchool,
EnrollmentDate = submission.EnrollmentDate,
GraduationDate = submission.GraduationDate,
Major = submission.Major,
PreviousCompany = submission.PreviousCompany,
PreviousPosition = submission.PreviousPosition,
PreviousStartDate = submission.PreviousStartDate,
PreviousEndDate = submission.PreviousEndDate,
EmergencyContactRelation = submission.EmergencyContactRelation,
EmergencyContactAddress = submission.EmergencyContactAddress,
CreateTime = now,
CreateUser = reviewerId,
UpdateTime = now,
UpdateUser = reviewerId,
LastReviewUserId = reviewerId,
LastReviewUserName = reviewerName,
LastReviewTime = now
};
await _db.Insertable(profile).ExecuteCommandAsync();
}
else
{
existing.MaritalStatus = submission.MaritalStatus;
existing.PoliticalStatus = submission.PoliticalStatus;
existing.HouseholdType = submission.HouseholdType;
existing.CurrentAddress = submission.CurrentAddress;
existing.EmployeeNo = submission.EmployeeNo;
existing.EmployeeType = submission.EmployeeType;
existing.EmployeeStatus = submission.EmployeeStatus;
existing.ProbationMonths = submission.ProbationMonths;
existing.RegularizationDate = submission.RegularizationDate;
existing.RecruitmentType = submission.RecruitmentType;
existing.BankName = submission.BankName;
if (!string.IsNullOrWhiteSpace(submission.BankCardCipher))
{
existing.BankCardCipher = submission.BankCardCipher;
}
existing.BankAccountName = submission.BankAccountName;
existing.IdCardAddress = submission.IdCardAddress;
existing.IdCardFrontUrl = submission.IdCardFrontUrl;
existing.IdCardBackUrl = submission.IdCardBackUrl;
existing.GraduateSchool = submission.GraduateSchool;
existing.EnrollmentDate = submission.EnrollmentDate;
existing.GraduationDate = submission.GraduationDate;
existing.Major = submission.Major;
existing.PreviousCompany = submission.PreviousCompany;
existing.PreviousPosition = submission.PreviousPosition;
existing.PreviousStartDate = submission.PreviousStartDate;
existing.PreviousEndDate = submission.PreviousEndDate;
existing.EmergencyContactRelation = submission.EmergencyContactRelation;
existing.EmergencyContactAddress = submission.EmergencyContactAddress;
existing.UpdateTime = now;
existing.UpdateUser = reviewerId;
existing.LastReviewUserId = reviewerId;
existing.LastReviewUserName = reviewerName;
existing.LastReviewTime = now;
await _db.Updateable(existing).ExecuteCommandAsync();
}
}
#endregion
}
}