LqEmployeeProfileSubmissionService.cs 50.2 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
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(),
                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 => 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>
        /// showTail4=true 时身份证/银行卡/手机号仅展示后 4 位供审核比对,仍不返回完整明文。
        /// </remarks>
        /// <param name="id">申请 ID</param>
        /// <param name="showTail4">是否展示后 4 位(审核比对)</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)
        {
            var entity = await GetSubmissionOrThrowAsync(id);
            await EnsureCanEditOrganizeAsync(entity.OrganizeId);
            return MapInfoOutput(entity, showTail4);
        }

        /// <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 不能为空");
                }
            }

            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 (!input.entryDate.HasValue)
            {
                throw NCCException.Oh("申请入职日期不能为空");
            }

            if (string.IsNullOrWhiteSpace(input.organizeId))
            {
                throw NCCException.Oh("组织不能为空");
            }

            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.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("银行卡号格式不正确");
            }

            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.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 = input.regularizationDate?.Date,
                RecruitmentType = input.recruitmentType,
                BankName = input.bankName?.Trim(),
                BankCardCipher = string.IsNullOrWhiteSpace(input.bankCardNo)
                    ? null
                    : EmployeeProfileSensitiveHelper.EncryptSensitive(
                        EmployeeProfileSensitiveHelper.NormalizeBankCard(input.bankCardNo)),
                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)
        {
            var idPlain = EmployeeProfileSensitiveHelper.DecryptSensitive(entity.IdCardCipher);
            var bankPlain = EmployeeProfileSensitiveHelper.DecryptSensitive(entity.BankCardCipher);

            string MaskSensitive(string plain, Func<string, string> defaultMask)
            {
                if (string.IsNullOrWhiteSpace(plain))
                {
                    return "无";
                }

                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),
                gender = entity.Gender,
                birthday = entity.Birthday,
                nation = entity.Nation,
                nativePlace = entity.NativePlace,
                idCardNoMasked = MaskSensitive(idPlain, EmployeeProfileSensitiveHelper.MaskIdCard),
                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),
                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
                && !(userInfo.dataScope?.Any(x => x.organizeId == organizeId && x.Edit) ?? false))
            {
                throw NCCException.Oh(ErrorCode.D1013);
            }

            return userInfo;
        }

        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,
                    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.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
    }
}