package com.jeeplus.test.user.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.sys.service.dto.UserDTO;
import com.jeeplus.sys.utils.StringUtils;
import com.jeeplus.sys.utils.UserUtils;
import com.jeeplus.test.oss.service.OssService;
import com.jeeplus.test.user.domain.*;
import com.jeeplus.test.user.service.dto.UserInfoDetailDto;
import com.jeeplus.test.user.service.dto.UserListDto;
import com.jeeplus.test.user.mapper.*;
import com.jeeplus.test.workClientInfo.domain.WorkClientInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;

@Service
public class UserInfoService {

    @Resource
    private SysUserInfoMapper sysUserInfoMapper;
    @Resource
    private SysUserEducationMapper sysUserEducationMapper;
    @Resource
    private SysUserContractMapper sysUserContractMapper;
    @Resource
    private SysUserLanguagesMapper sysUserLanguagesMapper;
    @Resource
    private SysUserWorkMapper sysUserWorkMapper;
    @Resource
    private SysUserCertificateMapper sysUserCertificateMapper;
    @Resource
    private SysUserTitleMapper sysUserTitleMapper;
    @Resource
    private SysUserFamilyMapper sysUserFamilyMapper;
    @Resource
    private SysUserTrainMapper sysUserTrainMapper;
    @Resource
    private SysUserDutiesMapper sysUserDutiesMapper;
    @Resource
    private SysUserRewardsMapper sysUserRewardsMapper;
    @Resource
    private SysUserAchievementMapper sysUserAchievementMapper;
    @Resource
    private SysUserArchivesMapper sysUserArchivesMapper;
    @Resource
    private OssService ossService;

    private static final String USER_STATUS = "sys_user_status";

    private static final String ALIYUNURL = "http://oss.gangwaninfo.com";

    /**
     * 用户信息列表
     * @param page
     * @param queryWrapper
     * @return
     */
    public IPage<SysUserInfo> list(Page<SysUserInfo> page, QueryWrapper<SysUserInfo> queryWrapper) {
        queryWrapper.eq("a.del_flag",0);
        IPage<SysUserInfo> pageList = sysUserInfoMapper.findPageList(page, queryWrapper, USER_STATUS);
        return pageList;
    }

    /**
     * 删除用户信息
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String remove (String id) {
        //删除基本信息
        sysUserInfoMapper.deleteById(id);
        Map<String, Object> map = new HashMap<>();
        map.put("user_info_id", id);
        sysUserEducationMapper.deleteByMap(map);
        sysUserContractMapper.deleteByMap(map);
        sysUserLanguagesMapper.deleteByMap(map);
        sysUserWorkMapper.deleteByMap(map);
        sysUserCertificateMapper.deleteByMap(map);
        sysUserTitleMapper.deleteByMap(map);
        sysUserFamilyMapper.deleteByMap(map);
        sysUserTrainMapper.deleteByMap(map);
        sysUserDutiesMapper.deleteByMap(map);
        sysUserRewardsMapper.deleteByMap(map);
        sysUserAchievementMapper.deleteByMap(map);
        sysUserArchivesMapper.deleteByMap(map);
        return "操作成功";
    }

    /**
     * 根据id查询用户信息
     * @param id
     * @return
     */
    public UserInfoDetailDto getUserInfoById (String id) {
        UserInfoDetailDto detailDto = new UserInfoDetailDto();
        //查询基本信息
        SysUserInfo sysUserInfo = sysUserInfoMapper.selectById(id);
        BeanUtils.copyProperties(sysUserInfo, detailDto);
        if (StringUtils.isNotEmpty(detailDto.getHeadPortraitUrl())) {
            String lsUrl = ossService.getFileTemporaryLookUrl(ALIYUNURL + "/" + sysUserInfo.getHeadPortraitUrl());
            detailDto.setHeadPortraitLsUrl(lsUrl);
        }
        if (StringUtils.isNotEmpty(detailDto.getSignatureUrl())) {
            String lsUrl = ossService.getFileTemporaryLookUrl(ALIYUNURL + "/" + sysUserInfo.getSignatureUrl());
            detailDto.setSignatureLsUrl(lsUrl);
        }
        //查询用户教育经历
        LambdaQueryWrapper<SysUserEducation> wrapper1 = new LambdaQueryWrapper<>();
        wrapper1.eq(SysUserEducation::getUserInfoId, id);
        wrapper1.eq(SysUserEducation::getDelFlag, 0);
        List<SysUserEducation> sysUserEducations = sysUserEducationMapper.selectList(wrapper1);
        if (CollectionUtils.isNotEmpty(sysUserEducations)) {
            sysUserEducations.stream().forEach(i -> {
                if (StringUtils.isNotEmpty(i.getEducationCertificateUrl())) {
                    String lsUrl = ossService.getFileTemporaryLookUrl(ALIYUNURL + "/" + i.getEducationCertificateUrl());
                    i.setEducationCertificateLsUrl(lsUrl);
                }
                if (StringUtils.isNotEmpty(i.getDegreeCertificateUrl())) {
                    String lsUrl = ossService.getFileTemporaryLookUrl(ALIYUNURL + "/" + i.getDegreeCertificateUrl());
                    i.setDegreeCertificateLsUrl(lsUrl);
                }
            });
        }
        detailDto.setSysUserEducations(sysUserEducations);
        //查询用户劳动关系
        LambdaQueryWrapper<SysUserContract> wrapper2 = new LambdaQueryWrapper<>();
        wrapper2.eq(SysUserContract::getUserInfoId, id);
        wrapper2.eq(SysUserContract::getDelFlag, 0);
        List<SysUserContract> sysUserContracts = sysUserContractMapper.selectList(wrapper2);
        if (CollectionUtils.isNotEmpty(sysUserContracts)) {
            sysUserContracts.stream().forEach(i -> {
                if (StringUtils.isNotEmpty(i.getFileUrl())) {
                    String lsUrl = ossService.getFileTemporaryLookUrl(ALIYUNURL + "/" + i.getFileUrl());
                    i.setFileLsUrl(lsUrl);
                }
            });
        }
        detailDto.setSysUserContracts(sysUserContracts);
        //查询用户外语语种
        LambdaQueryWrapper<SysUserLanguages> wrapper3 = new LambdaQueryWrapper<>();
        wrapper3.eq(SysUserLanguages::getUserInfoId, id);
        wrapper3.eq(SysUserLanguages::getDelFlag, 0);
        List<SysUserLanguages> sysUserLanguages = sysUserLanguagesMapper.selectList(wrapper3);
        if (CollectionUtils.isNotEmpty(sysUserLanguages)) {
            sysUserLanguages.stream().forEach(i -> {
                if (StringUtils.isNotEmpty(i.getFileUrl())) {
                    String lsUrl = ossService.getFileTemporaryLookUrl(ALIYUNURL + "/" + i.getFileUrl());
                    i.setFileLsUrl(lsUrl);
                }
            });
        }
        detailDto.setSysUserLanguages(sysUserLanguages);
        //查询用户工作经历
        LambdaQueryWrapper<SysUserWork> wrapper4 = new LambdaQueryWrapper<>();
        wrapper4.eq(SysUserWork::getUserInfoId, id);
        wrapper4.eq(SysUserWork::getDelFlag, 0);
        List<SysUserWork> sysUserWorks = sysUserWorkMapper.selectList(wrapper4);
        detailDto.setSysUserWorks(sysUserWorks);
        //查询用户执业资格证书
        LambdaQueryWrapper<SysUserCertificate> wrapper5 = new LambdaQueryWrapper<>();
        wrapper5.eq(SysUserCertificate::getUserInfoId, id);
        wrapper5.eq(SysUserCertificate::getDelFlag, 0);
        List<SysUserCertificate> sysUserCertificates = sysUserCertificateMapper.selectList(wrapper5);
        if (CollectionUtils.isNotEmpty(sysUserCertificates)) {
            sysUserCertificates.stream().forEach(i -> {
                if (StringUtils.isNotEmpty(i.getFileUrl())) {
                    String lsUrl = ossService.getFileTemporaryLookUrl(ALIYUNURL + "/" + i.getFileUrl());
                    i.setFileLsUrl(lsUrl);
                }
            });
        }
        detailDto.setSysUserCertificates(sysUserCertificates);
        //查询用户职称
        LambdaQueryWrapper<SysUserTitle> wrapper6 = new LambdaQueryWrapper<>();
        wrapper6.eq(SysUserTitle::getUserInfoId, id);
        wrapper6.eq(SysUserTitle::getDelFlag, 0);
        List<SysUserTitle> sysUserTitles = sysUserTitleMapper.selectList(wrapper6);
        if (CollectionUtils.isNotEmpty(sysUserTitles)) {
            sysUserTitles.stream().forEach(i -> {
                if (StringUtils.isNotEmpty(i.getFileUrl())) {
                    String lsUrl = ossService.getFileTemporaryLookUrl(ALIYUNURL + "/" + i.getFileUrl());
                    i.setFileLsUrl(lsUrl);
                }
            });
        }
        detailDto.setSysUserTitles(sysUserTitles);
        //查询用户家庭情况
        LambdaQueryWrapper<SysUserFamily> wrapper7 = new LambdaQueryWrapper<>();
        wrapper7.eq(SysUserFamily::getUserInfoId, id);
        wrapper7.eq(SysUserFamily::getDelFlag, 0);
        List<SysUserFamily> sysUserFamilies = sysUserFamilyMapper.selectList(wrapper7);
        detailDto.setSysUserFamilies(sysUserFamilies);
        //查询用户培训经历
        LambdaQueryWrapper<SysUserTrain> wrapper8 = new LambdaQueryWrapper<>();
        wrapper8.eq(SysUserTrain::getUserInfoId, id);
        wrapper8.eq(SysUserTrain::getDelFlag, 0);
        List<SysUserTrain> sysUserTrains = sysUserTrainMapper.selectList(wrapper8);
        if (CollectionUtils.isNotEmpty(sysUserTrains)) {
            sysUserTrains.stream().forEach(i -> {
                if (StringUtils.isNotEmpty(i.getFileUrl())) {
                    String lsUrl = ossService.getFileTemporaryLookUrl(ALIYUNURL + "/" + i.getFileUrl());
                    i.setFileLsUrl(lsUrl);
                }
            });
        }
        detailDto.setSysUserTrains(sysUserTrains);
        //查询用户社会及行业职务
        LambdaQueryWrapper<SysUserDuties> wrapper9 = new LambdaQueryWrapper<>();
        wrapper9.eq(SysUserDuties::getUserInfoId, id);
        wrapper9.eq(SysUserDuties::getDelFlag, 0);
        List<SysUserDuties> sysUserDuties = sysUserDutiesMapper.selectList(wrapper9);
        detailDto.setSysUserDuties(sysUserDuties);
        //查询用户奖惩情况
        LambdaQueryWrapper<SysUserRewards> wrapper10 = new LambdaQueryWrapper<>();
        wrapper10.eq(SysUserRewards::getUserInfoId, id);
        wrapper10.eq(SysUserRewards::getDelFlag, 0);
        List<SysUserRewards> sysUserRewards = sysUserRewardsMapper.selectList(wrapper10);
        detailDto.setSysUserRewards(sysUserRewards);
        //查询用户工作业绩
        LambdaQueryWrapper<SysUserAchievement> wrapper11 = new LambdaQueryWrapper<>();
        wrapper11.eq(SysUserAchievement::getUserInfoId, id);
        wrapper11.eq(SysUserAchievement::getDelFlag, 0);
        List<SysUserAchievement> sysUserAchievements = sysUserAchievementMapper.selectList(wrapper11);
        detailDto.setSysUserAchievements(sysUserAchievements);
        //查询用户电子档案
        LambdaQueryWrapper<SysUserArchives> wrapper12 = new LambdaQueryWrapper<>();
        wrapper12.eq(SysUserArchives::getUserInfoId, id);
        wrapper12.eq(SysUserArchives::getDelFlag, 0);
        List<SysUserArchives> sysUserArchives = sysUserArchivesMapper.selectList(wrapper12);
        if (CollectionUtils.isNotEmpty(sysUserArchives)) {
            sysUserArchives.stream().forEach(i -> {
                if (StringUtils.isNotEmpty(i.getFileUrl())) {
                    String lsUrl = ossService.getFileTemporaryLookUrl(ALIYUNURL + "/" + i.getFileUrl());
                    i.setFileLsUrl(lsUrl);
                }
            });
        }
        detailDto.setSysUserArchives(sysUserArchives);
        return detailDto;
    }

    /**
     * 用户信息新增
     * @param detailDto
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String add (UserInfoDetailDto detailDto) {
        //获取当前登录人信息
        UserDTO dto = UserUtils.getCurrentUserDTO();
        SysUserInfo sysUserInfo = new SysUserInfo();
        BeanUtils.copyProperties(detailDto, sysUserInfo);
        String id = UUID.randomUUID().toString().replace("-", "");
        sysUserInfo.setId(id);
        sysUserInfo.setJobNo(detailDto.getMobilePhone());
        sysUserInfo.setCreateBy(dto.getId());
        sysUserInfo.setCreateDate(new Date());
        sysUserInfo.setUpdateBy(dto.getId());
        sysUserInfo.setUpdateDate(new Date());
        sysUserInfo.setDelFlag(0);
        sysUserInfoMapper.insert(sysUserInfo);
        //用户教育经历
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserEducations())) {
            for (SysUserEducation education : detailDto.getSysUserEducations()) {
                education.setId(UUID.randomUUID().toString().replace("-", ""));
                education.setUserInfoId(id);
                education.setCreateBy(dto.getId());
                education.setCreateDate(new Date());
                education.setUpdateBy(dto.getId());
                education.setUpdateDate(new Date());
                education.setDelFlag(0);
                sysUserEducationMapper.insert(education);
            }
         }
        //用户劳动关系
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserContracts())) {
            for (SysUserContract contract : detailDto.getSysUserContracts()) {
                contract.setId(UUID.randomUUID().toString().replace("-", ""));
                contract.setUserInfoId(id);
                contract.setCreateBy(dto.getId());
                contract.setCreateDate(new Date());
                contract.setUpdateBy(dto.getId());
                contract.setUpdateDate(new Date());
                contract.setDelFlag(0);
                sysUserContractMapper.insert(contract);
            }
        }
        //用户外语语种
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserLanguages())) {
            for (SysUserLanguages languages : detailDto.getSysUserLanguages()) {
                languages.setId(UUID.randomUUID().toString().replace("-", ""));
                languages.setUserInfoId(id);
                languages.setCreateBy(dto.getId());
                languages.setCreateDate(new Date());
                languages.setUpdateBy(dto.getId());
                languages.setUpdateDate(new Date());
                languages.setDelFlag(0);
                sysUserLanguagesMapper.insert(languages);
            }
        }
        //用户工作经历
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserWorks())) {
            for (SysUserWork work : detailDto.getSysUserWorks()) {
                work.setId(UUID.randomUUID().toString().replace("-", ""));
                work.setUserInfoId(id);
                work.setCreateBy(dto.getId());
                work.setCreateDate(new Date());
                work.setUpdateBy(dto.getId());
                work.setUpdateDate(new Date());
                work.setDelFlag(0);
                sysUserWorkMapper.insert(work);
            }
        }
        //用户执业资格证书
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserCertificates())) {
            for (SysUserCertificate certificate : detailDto.getSysUserCertificates()) {
                certificate.setId(UUID.randomUUID().toString().replace("-", ""));
                certificate.setUserInfoId(id);
                certificate.setCreateBy(dto.getId());
                certificate.setCreateDate(new Date());
                certificate.setUpdateBy(dto.getId());
                certificate.setUpdateDate(new Date());
                certificate.setDelFlag(0);
                sysUserCertificateMapper.insert(certificate);
            }
        }
        //用户职称
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserTitles())) {
            for (SysUserTitle title : detailDto.getSysUserTitles()) {
                title.setId(UUID.randomUUID().toString().replace("-", ""));
                title.setUserInfoId(id);
                title.setCreateBy(dto.getId());
                title.setCreateDate(new Date());
                title.setUpdateBy(dto.getId());
                title.setUpdateDate(new Date());
                title.setDelFlag(0);
                sysUserTitleMapper.insert(title);
            }
        }
        //用户家庭情况
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserFamilies())) {
            for (SysUserFamily family : detailDto.getSysUserFamilies()) {
                family.setId(UUID.randomUUID().toString().replace("-", ""));
                family.setUserInfoId(id);
                family.setCreateBy(dto.getId());
                family.setCreateDate(new Date());
                family.setUpdateBy(dto.getId());
                family.setUpdateDate(new Date());
                family.setDelFlag(0);
                sysUserFamilyMapper.insert(family);
            }
        }
        //用户培训经历
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserTrains())) {
            for (SysUserTrain train : detailDto.getSysUserTrains()) {
                train.setId(UUID.randomUUID().toString().replace("-", ""));
                train.setUserInfoId(id);
                train.setCreateBy(dto.getId());
                train.setCreateDate(new Date());
                train.setUpdateBy(dto.getId());
                train.setUpdateDate(new Date());
                train.setDelFlag(0);
                sysUserTrainMapper.insert(train);
            }
        }
        //用户社会及行业职务
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserDuties())) {
            for (SysUserDuties duties : detailDto.getSysUserDuties()) {
                duties.setId(UUID.randomUUID().toString().replace("-", ""));
                duties.setUserInfoId(id);
                duties.setCreateBy(dto.getId());
                duties.setCreateDate(new Date());
                duties.setUpdateBy(dto.getId());
                duties.setUpdateDate(new Date());
                duties.setDelFlag(0);
                sysUserDutiesMapper.insert(duties);
            }
        }
        //用户奖惩情况
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserRewards())) {
            for (SysUserRewards rewards : detailDto.getSysUserRewards()) {
                rewards.setId(UUID.randomUUID().toString().replace("-", ""));
                rewards.setUserInfoId(id);
                rewards.setCreateBy(dto.getId());
                rewards.setCreateDate(new Date());
                rewards.setUpdateBy(dto.getId());
                rewards.setUpdateDate(new Date());
                rewards.setDelFlag(0);
                sysUserRewardsMapper.insert(rewards);
            }
        }
        //用户工作业绩
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserAchievements())) {
            for (SysUserAchievement achievement : detailDto.getSysUserAchievements()) {
                achievement.setId(UUID.randomUUID().toString().replace("-", ""));
                achievement.setUserInfoId(id);
                achievement.setCreateBy(dto.getId());
                achievement.setCreateDate(new Date());
                achievement.setUpdateBy(dto.getId());
                achievement.setUpdateDate(new Date());
                achievement.setDelFlag(0);
                sysUserAchievementMapper.insert(achievement);
            }
        }
        //用户电子档案
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserArchives())) {
            for (SysUserArchives archives : detailDto.getSysUserArchives()) {
                archives.setId(UUID.randomUUID().toString().replace("-", ""));
                archives.setUserInfoId(id);
                archives.setCreateBy(dto.getId());
                archives.setCreateDate(new Date());
                archives.setUpdateBy(dto.getId());
                archives.setUpdateDate(new Date());
                archives.setDelFlag(0);
                sysUserArchivesMapper.insert(archives);
            }
        }
        return "操作成功";
    }

    /**
     * 用户信息修改
     * @param detailDto
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String modify (UserInfoDetailDto detailDto) {
        //获取当前登录人信息
        UserDTO dto = UserUtils.getCurrentUserDTO();
        SysUserInfo sysUserInfo = new SysUserInfo();
        BeanUtils.copyProperties(detailDto, sysUserInfo);
        sysUserInfo.setJobNo(detailDto.getMobilePhone());
        sysUserInfo.setUpdateBy(dto.getId());
        sysUserInfo.setUpdateDate(new Date());
        sysUserInfoMapper.updateById(sysUserInfo);
        //用户教育经历
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserEducations())) {
            LambdaQueryWrapper<SysUserEducation> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserEducation::getUserInfoId, sysUserInfo.getId());
            sysUserEducationMapper.delete(wrapper);
            for (SysUserEducation education : detailDto.getSysUserEducations()) {
                education.setId(UUID.randomUUID().toString().replace("-", ""));
                education.setUserInfoId(sysUserInfo.getId());
                education.setCreateBy(dto.getId());
                education.setCreateDate(new Date());
                education.setUpdateBy(dto.getId());
                education.setUpdateDate(new Date());
                education.setDelFlag(0);
                sysUserEducationMapper.insert(education);
            }
        }
        //用户劳动关系
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserContracts())) {
            LambdaQueryWrapper<SysUserContract> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserContract::getUserInfoId, sysUserInfo.getId());
            sysUserContractMapper.delete(wrapper);
            for (SysUserContract contract : detailDto.getSysUserContracts()) {
                contract.setId(UUID.randomUUID().toString().replace("-", ""));
                contract.setUserInfoId(sysUserInfo.getId());
                contract.setCreateBy(dto.getId());
                contract.setCreateDate(new Date());
                contract.setUpdateBy(dto.getId());
                contract.setUpdateDate(new Date());
                contract.setDelFlag(0);
                sysUserContractMapper.insert(contract);
            }
        }
        //用户外语语种
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserLanguages())) {
            LambdaQueryWrapper<SysUserLanguages> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserLanguages::getUserInfoId, sysUserInfo.getId());
            sysUserLanguagesMapper.delete(wrapper);
            for (SysUserLanguages languages : detailDto.getSysUserLanguages()) {
                languages.setId(UUID.randomUUID().toString().replace("-", ""));
                languages.setUserInfoId(sysUserInfo.getId());
                languages.setCreateBy(dto.getId());
                languages.setCreateDate(new Date());
                languages.setUpdateBy(dto.getId());
                languages.setUpdateDate(new Date());
                languages.setDelFlag(0);
                sysUserLanguagesMapper.insert(languages);
            }
        }
        //用户工作经历
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserWorks())) {
            LambdaQueryWrapper<SysUserWork> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserWork::getUserInfoId, sysUserInfo.getId());
            sysUserWorkMapper.delete(wrapper);
            for (SysUserWork work : detailDto.getSysUserWorks()) {
                work.setId(UUID.randomUUID().toString().replace("-", ""));
                work.setUserInfoId(sysUserInfo.getId());
                work.setCreateBy(dto.getId());
                work.setCreateDate(new Date());
                work.setUpdateBy(dto.getId());
                work.setUpdateDate(new Date());
                work.setDelFlag(0);
                sysUserWorkMapper.insert(work);
            }
        }
        //用户执业资格证书
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserCertificates())) {
            LambdaQueryWrapper<SysUserCertificate> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserCertificate::getUserInfoId, sysUserInfo.getId());
            sysUserCertificateMapper.delete(wrapper);
            for (SysUserCertificate certificate : detailDto.getSysUserCertificates()) {
                certificate.setId(UUID.randomUUID().toString().replace("-", ""));
                certificate.setUserInfoId(sysUserInfo.getId());
                certificate.setCreateBy(dto.getId());
                certificate.setCreateDate(new Date());
                certificate.setUpdateBy(dto.getId());
                certificate.setUpdateDate(new Date());
                certificate.setDelFlag(0);
                sysUserCertificateMapper.insert(certificate);
            }
        }
        //用户职称
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserTitles())) {
            LambdaQueryWrapper<SysUserTitle> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserTitle::getUserInfoId, sysUserInfo.getId());
            sysUserTitleMapper.delete(wrapper);
            for (SysUserTitle title : detailDto.getSysUserTitles()) {
                title.setId(UUID.randomUUID().toString().replace("-", ""));
                title.setUserInfoId(sysUserInfo.getId());
                title.setCreateBy(dto.getId());
                title.setCreateDate(new Date());
                title.setUpdateBy(dto.getId());
                title.setUpdateDate(new Date());
                title.setDelFlag(0);
                sysUserTitleMapper.insert(title);
            }
        }
        //用户家庭情况
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserFamilies())) {
            LambdaQueryWrapper<SysUserFamily> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserFamily::getUserInfoId, sysUserInfo.getId());
            sysUserFamilyMapper.delete(wrapper);
            for (SysUserFamily family : detailDto.getSysUserFamilies()) {
                family.setId(UUID.randomUUID().toString().replace("-", ""));
                family.setUserInfoId(sysUserInfo.getId());
                family.setCreateBy(dto.getId());
                family.setCreateDate(new Date());
                family.setUpdateBy(dto.getId());
                family.setUpdateDate(new Date());
                family.setDelFlag(0);
                sysUserFamilyMapper.insert(family);
            }
        }
        //用户培训经历
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserTrains())) {
            LambdaQueryWrapper<SysUserTrain> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserTrain::getUserInfoId, sysUserInfo.getId());
            sysUserTrainMapper.delete(wrapper);
            for (SysUserTrain train : detailDto.getSysUserTrains()) {
                train.setId(UUID.randomUUID().toString().replace("-", ""));
                train.setUserInfoId(sysUserInfo.getId());
                train.setCreateBy(dto.getId());
                train.setCreateDate(new Date());
                train.setUpdateBy(dto.getId());
                train.setUpdateDate(new Date());
                train.setDelFlag(0);
                sysUserTrainMapper.insert(train);
            }
        }
        //用户社会及行业职务
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserDuties())) {
            LambdaQueryWrapper<SysUserDuties> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserDuties::getUserInfoId, sysUserInfo.getId());
            sysUserDutiesMapper.delete(wrapper);
            for (SysUserDuties duties : detailDto.getSysUserDuties()) {
                duties.setId(UUID.randomUUID().toString().replace("-", ""));
                duties.setUserInfoId(sysUserInfo.getId());
                duties.setCreateBy(dto.getId());
                duties.setCreateDate(new Date());
                duties.setUpdateBy(dto.getId());
                duties.setUpdateDate(new Date());
                duties.setDelFlag(0);
                sysUserDutiesMapper.insert(duties);
            }
        }
        //用户奖惩情况
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserRewards())) {
            LambdaQueryWrapper<SysUserRewards> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserRewards::getUserInfoId, sysUserInfo.getId());
            sysUserRewardsMapper.delete(wrapper);
            for (SysUserRewards rewards : detailDto.getSysUserRewards()) {
                rewards.setId(UUID.randomUUID().toString().replace("-", ""));
                rewards.setUserInfoId(sysUserInfo.getId());
                rewards.setCreateBy(dto.getId());
                rewards.setCreateDate(new Date());
                rewards.setUpdateBy(dto.getId());
                rewards.setUpdateDate(new Date());
                rewards.setDelFlag(0);
                sysUserRewardsMapper.insert(rewards);
            }
        }
        //用户工作业绩
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserAchievements())) {
            LambdaQueryWrapper<SysUserAchievement> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserAchievement::getUserInfoId, sysUserInfo.getId());
            sysUserAchievementMapper.delete(wrapper);
            for (SysUserAchievement achievement : detailDto.getSysUserAchievements()) {
                achievement.setId(UUID.randomUUID().toString().replace("-", ""));
                achievement.setUserInfoId(sysUserInfo.getId());
                achievement.setCreateBy(dto.getId());
                achievement.setCreateDate(new Date());
                achievement.setUpdateBy(dto.getId());
                achievement.setUpdateDate(new Date());
                achievement.setDelFlag(0);
                sysUserAchievementMapper.insert(achievement);
            }
        }
        //用户电子档案
        if (CollectionUtils.isNotEmpty(detailDto.getSysUserArchives())) {
            LambdaQueryWrapper<SysUserArchives> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(SysUserArchives::getUserInfoId, sysUserInfo.getId());
            sysUserArchivesMapper.delete(wrapper);
            for (SysUserArchives archives : detailDto.getSysUserArchives()) {
                archives.setId(UUID.randomUUID().toString().replace("-", ""));
                archives.setUserInfoId(sysUserInfo.getId());
                archives.setCreateBy(dto.getId());
                archives.setCreateDate(new Date());
                archives.setUpdateBy(dto.getId());
                archives.setUpdateDate(new Date());
                archives.setDelFlag(0);
                sysUserArchivesMapper.insert(archives);
            }
        }
        return "操作成功";
    }
}
