package thyyxxk.webserver.service.technologyArchives;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import thyyxxk.webserver.config.exception.ExceptionEnum;
import thyyxxk.webserver.dao.his.technologyArchives.*;
import thyyxxk.webserver.entity.ComplexSheetData;
import thyyxxk.webserver.entity.HeadInfo;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.login.UserInfo;
import thyyxxk.webserver.entity.technologyArchives.*;
import thyyxxk.webserver.service.archive.ArchiveServer;
import thyyxxk.webserver.service.hutoolcache.UserCache;
import thyyxxk.webserver.utils.ExcelUtil;
import thyyxxk.webserver.utils.ResultVoUtil;
import thyyxxk.webserver.utils.StringUtil;

import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @ClassName TechnologyArchivesService
 * @Author hsh
 * @Date 2024/7/4 15:35
 * @Version 1.0
 * @Description 技术档案管理
 **/
@Service
@Slf4j
@RequiredArgsConstructor
public class TechnologyArchivesService {

    private final TechnologyArchivesDao dao;

    private final TechnologyArchivesMainDao mainDao;

    private final UserCache userCache;

    private final TechnologyArchives1Dao firstDao;

    private final TechnologyArchives2Dao secondDao;

    private final TechnologyArchives3Dao thirdDao;

    private final TechnologyArchives4Dao fourthDao;

    private final TechnologyArchives5Dao fifthDao;

    private final TechnologyArchives6Dao sixthDao;

    private final TechnologyArchives7Dao seventhDao;

    private final TechnologyArchives9Dao ninthDao;

    private final TechnologyArchives10Dao tenthDao;

    private final TechnologyArchives12Dao twelfthDao;

    private final TechnologyArchives13Dao thirteenthDao;

    private final TechnologyArchives14Dao fourteenthDao;

    private final TechnologyArchives8Dao eighthDao;

    private final TechnologyArchives11Dao eleventhDao;

    private final TechnologyArchives15Dao fifteenthDao;

    private final TechnologyArchives16Dao sixteenthDao;

    private final ArchiveServer archiveServer;

    @Value("${is-prod}")
    private boolean isProd;

    /**
     * @param text 工号或者身份证号或姓名
     * @return TechnologyArchivesMain
     * @Description 根据工号或者身份证号或姓名查询基本信息
     * @Author hsh
     * @Date 2024/7/8 10:51
     */
    public ResultVo<TechnologyArchivesMain> selectEmployeeInfo(String text) {
        if (StringUtil.notBlank(text) && text.length() >= 5) {
            TechnologyArchivesMain main = mainDao.selectTechnologyArchivesMainBySocialNo(text);
            if (null != main) {
                return ResultVoUtil.success(main);
            }
        }
        TechnologyArchivesMain m = dao.selectEmployeeInfo(text);
        if (null == m) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "查不到基本信息！");
        }
        TechnologyArchivesMain m1 = mainDao.selectTechnologyArchivesMainBySocialNo(m.getSocialNo());
        if (null != m1) {
            return ResultVoUtil.success(m1);
        }
        TechnologyArchivesMain m2 = mainDao.selectTechnologyArchivesMainBySocialNo(m.getAccount());
        if (null != m2) {
            return ResultVoUtil.success(m2);
        }
        //添加姓名搜索
        TechnologyArchivesMain m3 = mainDao.selectTechnologyArchivesMainBySocialNo(m.getName());
        if (null != m3) {
            return ResultVoUtil.success(m3);
        }
        return ResultVoUtil.success(m);
    }

    /**
     * @return map
     * @Description 查询基本信息需要的字典信息
     * @Author hsh
     * @Date 2024/7/8 12:50
     */
    public ResultVo<Map<String, Object>> selectDictInfo() {
        Map<String, Object> resultMap = new HashMap<>();
        // 性别
        List<CodeName> sex = dao.getSexCode();
        resultMap.put("sex", sex);
        // 民族
        List<CodeName> nation = dao.getNation();
        resultMap.put("nation", nation);
        // 籍贯（市）
        List<CodeName> city = dao.getCity();
        resultMap.put("city", city);
        // 政治面貌
        List<CodeName> political = dao.getPolitical();
        resultMap.put("political", political);
        // 专业职称
        List<CodeName> title = dao.getTitle();
        resultMap.put("title", title);
        // 文化程度
        List<CodeName> education = dao.getEducation();
        resultMap.put("education", education);
        return ResultVoUtil.success(resultMap);
    }

    /**
     * @param tam 基本信息
     * @return map
     * @Description 更新技术文档基本信息
     * @Author hsh
     * @Date 2024/7/8 11:29
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchivesMain(TechnologyArchivesMain tam) {
        Map<String, Object> resultMap = new HashMap<>();

        if (null == tam || null == tam.getSocialNo()) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "技术文档基本信息不存在或者缺少身份证号，请检查！");
        }

        TechnologyArchivesMain main = mainDao.selectTechnologyArchivesMainBySocialNo(tam.getSocialNo());

        // 入库或更新操作
        int n;
        if (null == main) {
            UserInfo user = userCache.getUserInfoByToken();
            tam.setAccount(user.getCode());
            n = mainDao.insert(tam);
        } else {
            UpdateWrapper<TechnologyArchivesMain> updateWrapper = new UpdateWrapper<>();
            updateWrapper.eq("social_no",tam.getSocialNo());
            n = mainDao.update(tam, updateWrapper);
//            n = mainDao.updateTechnologyArchivesMainBySocialNo(tam);
        }
        if (n <= 0) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存指标结果失败！");
        }
        resultMap.put("cg", "保存指标结果成功");
        return ResultVoUtil.success(resultMap);
    }

    /**
     * @return TechnologyArchives1
     * @Description 根据工号查询专业技术职称晋升情况
     * @Author hsh
     * @Date 2024/7/9 10:49
     */
    public ResultVo<List<TechnologyArchives1>> selectTechnologyArchives1() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives1> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives1> list = firstDao.selectList(querywrapper);
//        List<TechnologyArchives1> list = firstDao.selectFirstListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    //查找图片
    public ResultVo<Map<String, Object>> selectImage1(String socialNo, String getTime) {
        //为每张图片设置编号
//        for(int i = 0; i < imagelist.size(); i++){
//            imagelist.get(i).setImagenum(i+1); //从1开始计数
//        }
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> imgMap = firstDao.selectImage(socialNo, getTime);
        map.put("data", imgMap);
        return ResultVoUtil.success(map);
    }

    //删除图片
    public ResultVo<Map<String, Object>> deleteImage1(String socialNo, String getTime) {
        if (StringUtil.isBlank(socialNo) || StringUtil.isBlank(getTime)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号或者批准时间，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = firstDao.deleteImage(socialNo, getTime);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除图片失败！");
            }
            resultMap.put("cg", "删除图片成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除图片失败！");
        }
    }

    /**
     * @param first 专业技术职称晋升情况
     * @return map
     * @Description 更新专业技术职称晋升情况
     * @Author hsh
     * @Date 2024/7/9 17:14
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives1(TechnologyArchives1 first) {

        if (null == first || first.getSocialNo() == null || first.getGetTime() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "专业技术职称晋升情况信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = first.getSocialNo();
        String getTime = first.getGetTime();
        TechnologyArchives1 ta1 = firstDao.selectTechnologyArchives1ByGetTime(socialNo, getTime);

        int num;
        try {
            if (null != ta1) {
                UpdateWrapper<TechnologyArchives1> updateWrapper = new UpdateWrapper<>();
                updateWrapper.eq("social_no",first.getSocialNo());
                updateWrapper.eq("get_time",first.getGetTime());
                num = firstDao.update(first, updateWrapper);
//                num = firstDao.updateTechnologyArchives1ByGetTime(first);
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                first.setAccount(user.getCode());
                num = firstDao.insert(first);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存专业技术职称晋升情况失败！");
            }
            resultMap.put("cg", "保存专业技术职称晋升情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存专业技术职称晋升情况失败！");
        }
    }

    //职称证书图片
    public ResultVo<Map<String, Object>> putCertificateImage(MultipartFile[] files, String title) {
        UserInfo user = userCache.getUserInfoByToken();
        String code = user.getCode();
        String uploadDir = "/uploadimage/certificateImage/" + code + "/" + title;
        Map<String, Object> map = new HashMap<>();
        List<String> urls = new ArrayList<>();
        System.out.println(Arrays.toString(files));
        for (MultipartFile file : files){
            urls.add(archiveServer.uploadFile(file, uploadDir, !isProd).getPath());
        }
        map.put("urls",urls);
        return ResultVoUtil.success(map);
    }

    /**
     * @param socialNo  身份证号  getTime 批准时间 url 图片链接
     * @Description 根据身份证号, 批准时间来保存上传图片
     * @return map
     */
    public ResultVo<Map<String, Object>> setImage1(String socialNo, String getTime, String url) {
        Map<String, Object> map = new HashMap<>();
        int imgMap = firstDao.updateCertificateImage(url, socialNo, getTime);
        map.put("data", imgMap);
        return ResultVoUtil.success(map);
    }

    /**
     * @param socialNo 身份证号 getTime 批准时间
     * @return map
     * @Description 根据身份证号, 批准时间删除专业技术职称晋升情况
     * @Author hsh
     * @Date 2024/7/9 17:14
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives1ByCode(String socialNo, String getTime) {
        if (StringUtil.isBlank(socialNo) || StringUtil.isBlank(getTime)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号或者批准时间，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = firstDao.delTechnologyArchives1ByCode(socialNo, getTime);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除专业技术职称晋升情况失败！");
            }
            resultMap.put("cg", "删除专业技术职称晋升情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除专业技术职称晋升情况失败！");
        }
    }

    /**
     * @return TechnologyArchives2 其它资格证书取得情况
     * @Description 查询其它资格证书取得情况
     * @Author hsh
     * @Date 2024/7/10 15:11
     */
    public ResultVo<List<TechnologyArchives2>> selectTechnologyArchives2() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives2> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives2> list = secondDao.selectList(querywrapper);
//        List<TechnologyArchives2> list = secondDao.selectSecondListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /**
     * @param second 其它资格证书取得情况
     * @return map
     * @Description 更新其它资格证书取得情况
     * @Author hsh
     * @Date 2024/7/10 15:12
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives2(TechnologyArchives2 second) {

        if (null == second || second.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "其它资格证书取得情况信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = second.getSocialNo();
        Integer no = second.getNo();
        TechnologyArchives2 ta2 = secondDao.selectTechnologyArchives2ByNo(socialNo, no);

        int num;
        try {
            if (null != ta2) {
                UpdateWrapper<TechnologyArchives2> updateWrapper = new UpdateWrapper<>();
                updateWrapper.eq("social_no",second.getSocialNo());
                updateWrapper.eq("no",second.getNo());
                num = secondDao.update(second, updateWrapper);
//                num = secondDao.updateTechnologyArchives2ByNo(second);
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                second.setAccount(user.getCode());
                num = secondDao.insert(second);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存其它资格证书取得情况失败！");
            }
            resultMap.put("cg", "保存其它资格证书取得情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存其它资格证书取得情况失败！");
        }
    }

    //查找图片
    public ResultVo<Map<String, Object>> selectImage2(String socialNo, Integer no) {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> imgMap = secondDao.selectImage(socialNo, no);
        map.put("data", imgMap);
        return ResultVoUtil.success(map);
    }

    //其他证书图片
    public ResultVo<Map<String, Object>> putProImage(MultipartFile[] files, String name) {
        UserInfo user = userCache.getUserInfoByToken();
        String code = user.getCode();
        String uploadDir = "/uploadimage/proImage/" + code + "/" + name;
        Map<String, Object> map = new HashMap<>();
        List<String> urls = new ArrayList<>();
        System.out.println(Arrays.toString(files));
        for (MultipartFile file : files){
            urls.add(archiveServer.uploadFile(file, uploadDir, !isProd).getPath());
        }
        map.put("urls",urls);
        return ResultVoUtil.success(map);
    }

    public ResultVo<Map<String, Object>> setImage2(String socialNo, Integer no, String url) {
        Map<String, Object> map = new HashMap<>();
        int imgMap = secondDao.updateProImage(url, socialNo, no);
        map.put("data", imgMap);
        return ResultVoUtil.success(map);
    }

    /**
     * @param socialNo 身份证号  no 序号
     * @return map
     * @Description 根据身份证号, 序号删除其它资格证书取得情况
     * @Author hsh
     * @Date 2024/7/10 15:13
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives2ByCode(String socialNo, Integer no) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = secondDao.delTechnologyArchives2ByCode(socialNo, no);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除其它资格证书取得情况失败！");
            }
            resultMap.put("cg", "删除其它资格证书取得情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除其它资格证书取得情况失败！");
        }
    }

    /**
     * @return TechnologyArchives3
     * @Description 查询工作经历
     * @Author hsh
     * @Date 2024/7/11 10:53
     */
    public ResultVo<List<TechnologyArchives3>> selectTechnologyArchives3() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives3> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives3> list = thirdDao.selectList(querywrapper);
//        List<TechnologyArchives3> list = thirdDao.selectThirdListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /**
     * @param third 工作经历
     * @return map
     * @Description 根据身份证号更新工作经历
     * @Author hsh
     * @Date 2024/7/11 10:54
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives3(TechnologyArchives3 third) {

        if (null == third || third.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "工作经历信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = third.getSocialNo();
        Integer id = third.getId();
        TechnologyArchives3 ta3 = thirdDao.selectTechnologyArchives3ById(socialNo, id);

        int num;
        try {
            if (null != ta3) {
                String oldSocialNo = third.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives3 oldTa3 = thirdDao.selectTechnologyArchives3ById(oldSocialNo, id);
                    oldTa3.setSocialNo(socialNo);
                    int maxId = thirdDao.selectTechnologyArchives3MaxId(socialNo);
                    oldTa3.setId(maxId + 1);
                    num = thirdDao.insert(oldTa3);
                    thirdDao.delTechnologyArchives3ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives3> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",third.getSocialNo());
                    updateWrapper.eq("id",third.getId());
                    num = thirdDao.update(third, updateWrapper);
//                    num = thirdDao.updateTechnologyArchives3ById(third);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = thirdDao.selectTechnologyArchives3MaxId(socialNo);
                third.setAccount(user.getCode());
                third.setId(maxId + 1);
                num = thirdDao.insert(third);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存工作经历失败！");
            }
            resultMap.put("cg", "保存工作经历成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存工作经历失败！");
        }
    }

    /**
     * @param socialNo 身份证号  id
     * @return map
     * @Description 根据身份证号, id删除其它资格证书取得情况
     * @Author hsh
     * @Date 2024/7/11 10:55
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives3ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = thirdDao.delTechnologyArchives3ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除工作经历失败！");
            }
            resultMap.put("cg", "删除工作经历成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除工作经历失败！");
        }
    }

    /**
     * @return TechnologyArchives4 （院内、院外）学习培训情况
     * @Description 查询（院内、院外）学习培训情况
     * @Author hsh
     * @Date 2024/7/11 16:07
     */
    public ResultVo<List<TechnologyArchives4>> selectTechnologyArchives4() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives4> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives4> list = fourthDao.selectList(querywrapper);
//        List<TechnologyArchives4> list = fourthDao.selectFourthListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    //查找图片
    public ResultVo<Map<String, Object>> selectTrainingImage(String socialNo, Integer id) {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> imgMap = fourthDao.selectTrainingImage(socialNo, id);
        map.put("data", imgMap);
        return ResultVoUtil.success(map);
    }

    public ResultVo<Map<String, Object>> putTrainingCertificateImage(MultipartFile[] files, String learningContent) {
        UserInfo user = userCache.getUserInfoByToken();
        String code = user.getCode();
        String uploadDir = "/uploadimage/trainingcertificateImage/" + code + '/' + learningContent;
        Map<String, Object> map = new HashMap<>();
        List<String> urls = new ArrayList<>();
        System.out.println(Arrays.toString(files));
        for (MultipartFile file : files){
            urls.add(archiveServer.uploadFile(file, uploadDir, !isProd).getPath());
        }
        map.put("urls",urls);
        return ResultVoUtil.success(map);
    }

    /**
     * @param socialNo  身份证号   url 图片链接
     * @Description 根据身份证号 来保存上传图片
     * @return map
     */
    public ResultVo<Map<String, Object>> setTrainingImage(String socialNo, String beginTime, String url) {
        Map<String, Object> map = new HashMap<>();
        int imgMap = fourthDao.updateTrainingImage(socialNo, beginTime, url);
        map.put("data", imgMap);
        return ResultVoUtil.success(map);
    }

    /**
     * @param fourth （院内、院外）学习培训情况
     * @return map
     * @Description 根据身份证号更新（院内、院外）学习培训情况
     * @Author hsh
     * @Date 2024/7/11 16:07
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives4(TechnologyArchives4 fourth) {

        if (null == fourth || fourth.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "（院内、院外）学习培训情况信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = fourth.getSocialNo();
        Integer id = fourth.getId();
        TechnologyArchives4 ta4 = fourthDao.selectTechnologyArchives4ById(socialNo, id);

        int num;
        try {
            if (null != ta4) {
                String oldSocialNo = fourth.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives4 oldTa4 = fourthDao.selectTechnologyArchives4ById(oldSocialNo, id);
                    oldTa4.setSocialNo(socialNo);
                    int maxId = fourthDao.selectTechnologyArchives4MaxId(socialNo);
                    oldTa4.setId(maxId + 1);
                    num = fourthDao.insert(oldTa4);
                    fourthDao.delTechnologyArchives4ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives4> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",fourth.getSocialNo());
                    updateWrapper.eq("id",fourth.getId());
                    num = fourthDao.update(fourth, updateWrapper);
//                    num = fourthDao.updateTechnologyArchives4ById(fourth);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = fourthDao.selectTechnologyArchives4MaxId(socialNo);
                fourth.setAccount(user.getCode());
                fourth.setId(maxId + 1);
                num = fourthDao.insert(fourth);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存（院内、院外）学习培训情况失败！");
            }
            resultMap.put("cg", "保存（院内、院外）学习培训情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存（院内、院外）学习培训情况失败！");
        }
    }

    /**
     * @param socialNo 身份证号  id
     * @return map
     * @Description 根据身份证号, id删除（院内、院外）学习培训情况
     * @Author hsh
     * @Date 2024/7/11 16:08
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives4ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = fourthDao.delTechnologyArchives4ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除（院内、院外）学习培训情况失败！");
            }
            resultMap.put("cg", "删除（院内、院外）学习培训情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除（院内、院外）学习培训情况失败！");
        }
    }

    /**
     * @return TechnologyArchives5 发表论文与专著情况
     * @Description 查询发表论文与专著情况
     * @Author hsh
     * @Date 2024/7/12 10:00
     */
    public ResultVo<List<TechnologyArchives5>> selectTechnologyArchives5() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives5> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives5> list = fifthDao.selectList(querywrapper);
//        List<TechnologyArchives5> list = fifthDao.selectFifthListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /**
     * @param fifth 发表论文与专著情况
     * @return map
     * @Description 更新发表论文与专著情况
     * @Author hsh
     * @Date 2024/7/12 10:06
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives5(TechnologyArchives5 fifth) {

        if (null == fifth || fifth.getSocialNo() == null || fifth.getTime() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "发表论文与专著情况信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = fifth.getSocialNo();
        String time = fifth.getTime();
        TechnologyArchives5 ta5 = fifthDao.selectTechnologyArchives5ByTime(socialNo, time);

        int num;
        try {
            if (null != ta5) {
                UpdateWrapper<TechnologyArchives5> updateWrapper = new UpdateWrapper<>();
                updateWrapper.eq("social_no",fifth.getSocialNo());
                updateWrapper.eq("time",fifth.getTime());
                num = fifthDao.update(fifth, updateWrapper);
//                num = fifthDao.updateTechnologyArchives5ByTime(fifth);
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                fifth.setAccount(user.getCode());
                num = fifthDao.insert(fifth);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存发表论文与专著情况失败！");
            }
            resultMap.put("cg", "保存发表论文与专著情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存发表论文与专著情况失败！");
        }
    }

    /**
     * @param socialNo 身份证号 time 发表时间
     * @return map
     * @Description 根据身份证号, 发表时间删除发表论文与专著情况
     * @Author hsh
     * @Date 2024/7/12 10:07
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives5ByCode(String socialNo, String time) {
        if (StringUtil.isBlank(socialNo) || StringUtil.isBlank(time)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号或者发表时间，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = fifthDao.delTechnologyArchives5ByCode(socialNo, time);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除发表论文与专著情况失败！");
            }
            resultMap.put("cg", "删除发表论文与专著情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除发表论文与专著情况失败！");
        }
    }

    /**
     * @return TechnologyArchives6 科研情况
     * @Description 查询科研情况
     * @Author hsh
     * @Date 2024/7/12 11:41
     */
    public ResultVo<List<TechnologyArchives6>> selectTechnologyArchives6() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives6> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives6> list = sixthDao.selectList(querywrapper);
//        List<TechnologyArchives6> list = sixthDao.selectSixthListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /**
     * @param sixth 科研情况
     * @return map
     * @Description 根据身份证号更新科研情况
     * @Author hsh
     * @Date 2024/7/12 11:41
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives6(TechnologyArchives6 sixth) {

        if (null == sixth || sixth.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "科研情况信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = sixth.getSocialNo();
        Integer id = sixth.getId();
        TechnologyArchives6 ta6 = sixthDao.selectTechnologyArchives6ById(socialNo, id);

        int num;
        try {
            if (null != ta6) {
                String oldSocialNo = sixth.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives6 oldTa6 = sixthDao.selectTechnologyArchives6ById(oldSocialNo, id);
                    oldTa6.setSocialNo(socialNo);
                    int maxId = sixthDao.selectTechnologyArchives6MaxId(socialNo);
                    oldTa6.setId(maxId + 1);
                    num = sixthDao.insert(oldTa6);
                    sixthDao.delTechnologyArchives6ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives6> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",sixth.getSocialNo());
                    updateWrapper.eq("id",sixth.getId());
                    num = sixthDao.update(sixth, updateWrapper);
//                    num = sixthDao.updateTechnologyArchives6ById(sixth);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = sixthDao.selectTechnologyArchives6MaxId(socialNo);
                sixth.setAccount(user.getCode());
                sixth.setId(maxId + 1);
                num = sixthDao.insert(sixth);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存科研情况失败！");
            }
            resultMap.put("cg", "保存科研情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存科研情况失败！");
        }
    }

    /**
     * @param socialNo 身份证号  id
     * @return map
     * @Description 根据身份证号, id删除科研情况
     * @Author hsh
     * @Date 2024/7/12 11:42
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives6ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = sixthDao.delTechnologyArchives6ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除科研情况失败！");
            }
            resultMap.put("cg", "删除科研情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除科研情况失败！");
        }
    }

    /**
     * @return TechnologyArchives7 开展新技术情况
     * @Description 查询开展新技术情况
     * @Author hsh
     * @Date 2024/7/12 15:42
     */
    public ResultVo<List<TechnologyArchives7>> selectTechnologyArchives7() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives7> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives7> list = seventhDao.selectList(querywrapper);
//        List<TechnologyArchives7> list = seventhDao.selectSeventhListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /**
     * @param seventh 开展新技术情况
     * @return map
     * @Description 根据身份证号更新开展新技术情况
     * @Author hsh
     * @Date 2024/7/12 15:43
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives7(TechnologyArchives7 seventh) {

        if (null == seventh || seventh.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "开展新技术情况信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = seventh.getSocialNo();
        Integer id = seventh.getId();
        TechnologyArchives7 ta7 = seventhDao.selectTechnologyArchives7ById(socialNo, id);

        int num;
        try {
            if (null != ta7) {
                String oldSocialNo = seventh.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives7 oldTa7 = seventhDao.selectTechnologyArchives7ById(oldSocialNo, id);
                    oldTa7.setSocialNo(socialNo);
                    int maxId = seventhDao.selectTechnologyArchives7MaxId(socialNo);
                    oldTa7.setId(maxId + 1);
                    num = seventhDao.insert(oldTa7);
                    seventhDao.delTechnologyArchives7ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives7> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",seventh.getSocialNo());
                    updateWrapper.eq("id",seventh.getId());
                    num = seventhDao.update(seventh, updateWrapper);
//                    num = seventhDao.updateTechnologyArchives7ById(seventh);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = seventhDao.selectTechnologyArchives7MaxId(socialNo);
                seventh.setAccount(user.getCode());
                seventh.setId(maxId + 1);
                num = seventhDao.insert(seventh);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存开展新技术情况失败！");
            }
            resultMap.put("cg", "保存开展新技术情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存开展新技术情况失败！");
        }
    }

    /**
     * @param socialNo 身份证号 id
     * @return map
     * @Description 根据身份证号, id删除开展新技术情况
     * @Author hsh
     * @Date 2024/7/12 15:44
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives7ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = seventhDao.delTechnologyArchives7ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除开展新技术情况失败！");
            }
            resultMap.put("cg", "删除开展新技术情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除开展新技术情况失败！");
        }
    }

    /**
     * @return TechnologyArchives9 开展新技术情况
     * @Description 查询开展新技术情况
     * @Author hsh
     * @Date 2024/7/12 15:41
     */
    public ResultVo<List<TechnologyArchives9>> selectTechnologyArchives9() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives9> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives9> list = ninthDao.selectList(querywrapper);
//        List<TechnologyArchives9> list = ninthDao.selectNinthListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /**
     * @param ninth 培训考试考核情况
     * @return map
     * @Description 根据身份证号更新培训考试考核情况
     * @Author hsh
     * @Date 2024/7/12 15:43
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives9(TechnologyArchives9 ninth) {

        if (null == ninth || ninth.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "培训考试考核情况信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = ninth.getSocialNo();
        Integer id = ninth.getId();
        TechnologyArchives9 ta9 = ninthDao.selectTechnologyArchives9ById(socialNo, id);

        int num;
        try {
            if (null != ta9) {
                String oldSocialNo = ninth.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives9 oldTa9 = ninthDao.selectTechnologyArchives9ById(oldSocialNo, id);
                    oldTa9.setSocialNo(socialNo);
                    int maxId = ninthDao.selectTechnologyArchives9MaxId(socialNo);
                    oldTa9.setId(maxId + 1);
                    num = ninthDao.insert(oldTa9);
                    ninthDao.delTechnologyArchives9ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives9> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",ninth.getSocialNo());
                    updateWrapper.eq("id",ninth.getId());
                    num = ninthDao.update(ninth, updateWrapper);
//                    num = ninthDao.updateTechnologyArchives9ById(ninth);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = ninthDao.selectTechnologyArchives9MaxId(socialNo);
                ninth.setAccount(user.getCode());
                ninth.setId(maxId + 1);
                num = ninthDao.insert(ninth);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存培训考试考核情况失败！");
            }
            resultMap.put("cg", "保存培训考试考核情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存培训考试考核情况失败！");
        }
    }

    //查找图片
    public ResultVo<Map<String, Object>> selectExamineImage(String socialNo, Integer id) {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> imgMap = ninthDao.selectImage9(socialNo, id);
        map.put("data", imgMap);
        return ResultVoUtil.success(map);
    }

    public ResultVo<Map<String, Object>> putExamineImage(MultipartFile[] files, String content) {
        UserInfo user = userCache.getUserInfoByToken();
        String code = user.getCode();
        String uploadDir = "/uploadimage/examinecertificateImage/" + code + '/' + content;
        Map<String, Object> map = new HashMap<>();
        List<String> urls = new ArrayList<>();
        System.out.println(Arrays.toString(files));
        for (MultipartFile file : files){
            urls.add(archiveServer.uploadFile(file, uploadDir, !isProd).getPath());
        }
        map.put("urls",urls);
        return ResultVoUtil.success(map);
    }

    /**
     * @param socialNo  身份证号   url 图片链接
     * @Description 根据身份证号 来保存上传图片
     * @return map
     */
    public ResultVo<Map<String, Object>> setExamineImage(String socialNo, String time, String url) {
        Map<String, Object> map = new HashMap<>();
        int imgMap = ninthDao.updateImage9(socialNo, time, url);
        map.put("data", imgMap);
        return ResultVoUtil.success(map);
    }

    /**
     * @param socialNo 身份证号 id
     * @return map
     * @Description 根据身份证号, id删除开展新技术情况
     * @Author hsh
     * @Date 2024/7/12 15:44
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives9ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = ninthDao.delTechnologyArchives9ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除培训考试考核情况失败！");
            }
            resultMap.put("cg", "删除开展新技术情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除培训考试考核情况失败！");
        }
    }

    /**
     * @return TechnologyArchives10 各种医疗活动记录
     * @Description 查询各种医疗活动记录
     * @Author hsh
     * @Date 2024/7/16 9:49
     */
    public ResultVo<List<TechnologyArchives10>> selectTechnologyArchives10() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives10> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives10> list = tenthDao.selectList(querywrapper);
//        List<TechnologyArchives10> list = tenthDao.selectTenthListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /***
     * @Description 根据身份证号更新各种医疗活动记录
     * @Author hsh
     * @param tenth 各种医疗活动记录
     * @return map
     * @Date 2024/7/16 9:50
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives10(TechnologyArchives10 tenth) {

        if (null == tenth || tenth.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "各种医疗活动记录信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = tenth.getSocialNo();
        Integer id = tenth.getId();
        TechnologyArchives10 ta10 = tenthDao.selectTechnologyArchives10ById(socialNo, id);

        int num;
        try {
            if (null != ta10) {
                String oldSocialNo = tenth.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives10 oldTa10 = tenthDao.selectTechnologyArchives10ById(oldSocialNo, id);
                    oldTa10.setSocialNo(socialNo);
                    int maxId = tenthDao.selectTechnologyArchives10MaxId(socialNo);
                    oldTa10.setId(maxId + 1);
                    num = tenthDao.insert(oldTa10);
                    tenthDao.delTechnologyArchives10ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives10> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",tenth.getSocialNo());
                    updateWrapper.eq("id",tenth.getId());
                    num = tenthDao.update(tenth, updateWrapper);
//                    num = tenthDao.updateTechnologyArchives10ById(tenth);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = tenthDao.selectTechnologyArchives10MaxId(socialNo);
                tenth.setAccount(user.getCode());
                tenth.setId(maxId + 1);
                num = tenthDao.insert(tenth);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存各种医疗活动记录失败！");
            }
            resultMap.put("cg", "保存各种医疗活动记录成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存各种医疗活动记录失败！");
        }
    }

    /**
     * @param socialNo 身份证号  id
     * @return map
     * @Description 根据身份证号, id删除各种医疗活动记录
     * @Author hsh
     * @Date 2024/7/16 9:51
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives10ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = tenthDao.delTechnologyArchives10ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除各种医疗活动记录失败！");
            }
            resultMap.put("cg", "删除各种医疗活动记录成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除各种医疗活动记录失败！");
        }
    }

    /**
     * @return TechnologyArchives12 奖惩情况
     * @Description 查询奖惩情况
     * @Author hsh
     * @Date 2024/7/16 14:59
     */
    public ResultVo<List<TechnologyArchives12>> selectTechnologyArchives12() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives12> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives12> list = twelfthDao.selectList(querywrapper);
//        List<TechnologyArchives12> list = twelfthDao.selectTwelfthListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /**
     * @param twelfth 奖惩情况
     * @return map
     * @Description 根据身份证号更新奖惩情况
     * @Author hsh
     * @Date 2024/7/16 15:00
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives12(TechnologyArchives12 twelfth) {

        if (null == twelfth || twelfth.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "奖惩情况信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = twelfth.getSocialNo();
        Integer id = twelfth.getId();
        TechnologyArchives12 ta12 = twelfthDao.selectTechnologyArchives12ById(socialNo, id);

        int num;
        try {
            if (null != ta12) {
                String oldSocialNo = twelfth.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives12 oldTa12 = twelfthDao.selectTechnologyArchives12ById(oldSocialNo, id);
                    oldTa12.setSocialNo(socialNo);
                    int maxId = twelfthDao.selectTechnologyArchives12MaxId(socialNo);
                    oldTa12.setId(maxId + 1);
                    num = twelfthDao.insert(oldTa12);
                    twelfthDao.delTechnologyArchives12ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives12> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",twelfth.getSocialNo());
                    updateWrapper.eq("id",twelfth.getId());
                    num = twelfthDao.update(twelfth, updateWrapper);
//                    num = twelfthDao.updateTechnologyArchives12ById(twelfth);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = twelfthDao.selectTechnologyArchives12MaxId(socialNo);
                twelfth.setAccount(user.getCode());
                twelfth.setId(maxId + 1);
                num = twelfthDao.insert(twelfth);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存奖惩情况失败！");
            }
            resultMap.put("cg", "保存奖惩情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存奖惩情况失败！");
        }
    }

    /**
     * @param socialNo 身份证号  id
     * @return map
     * @Description 根据身份证号, id删除奖惩情况
     * @Author hsh
     * @Date 2024/7/16 15:02
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives12ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = twelfthDao.delTechnologyArchives12ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除奖惩情况失败！");
            }
            resultMap.put("cg", "删除奖惩情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除奖惩情况失败！");
        }
    }

    /**
     * @return TechnologyArchives13 专业学会任职情况
     * @Description 查询专业学会任职情况
     * @Author hsh
     * @Date 2024/7/16 16:48
     */
    public ResultVo<List<TechnologyArchives13>> selectTechnologyArchives13() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives13> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives13> list = thirteenthDao.selectList(querywrapper);
//        List<TechnologyArchives13> list = thirteenthDao.selectThirteenthListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }


    /**
     * @param socialNo 身份证号 name 专业学会名称
     * @return map
     * @Description 通过身份证号以及专业学会名称查找委任聘书图片
     * @Author XU
     * @Date 2025/4/17 15:00
     */

    public ResultVo<Map<String, Object>> selectAppointmentImage(String socialNo, String name) {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> imgMap = thirteenthDao.selectAppointmentImage(socialNo, name);
        map.put("data", imgMap);
        return ResultVoUtil.success(map);
    }
    public ResultVo<Map<String, Object>> putAppointmentImage(MultipartFile[] files, String name) {
        UserInfo user = userCache.getUserInfoByToken();
        String code = user.getCode();
        String uploadDir = "/uploadimage/appoinmentImage/" + code + "/" + name;
        Map<String, Object> map = new HashMap<>();
        List<String> urls = new ArrayList<>();
        System.out.println(Arrays.toString(files));
        for (MultipartFile file : files){
            urls.add(archiveServer.uploadFile(file, uploadDir, !isProd).getPath());
        }
        map.put("urls",urls);
        return ResultVoUtil.success(map);
    }

    /**
     * @param socialNo 身份证号 name 专业学会名称 url 图片链接
     * @return map
     * @Description 通过身份证号以及专业学会名称设定委任聘书
     * @Author XU
     * @Date 2025/4/17 14:58
     */

    public ResultVo<Map<String, Object>> setAppointmentImage(String socialNo, String name, String url) {
        Map<String, Object> map = new HashMap<>();
        int imgMap = thirteenthDao.updateAppointmentImage(url, socialNo, name);
        map.put("data", imgMap);
        return ResultVoUtil.success(map);
    }

    /**
     * @param thirteenth 专业学会任职情况
     * @return map
     * @Description 根据身份证号更新专业学会任职情况
     * @Author hsh
     * @Date 2024/7/16 16:49
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives13(TechnologyArchives13 thirteenth) {

        if (null == thirteenth || thirteenth.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "专业学会任职情况信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = thirteenth.getSocialNo();
        Integer id = thirteenth.getId();
        TechnologyArchives13 ta13 = thirteenthDao.selectTechnologyArchives13ById(socialNo, id);

        int num;
        try {
            if (null != ta13) {
                String oldSocialNo = thirteenth.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives13 oldTa13 = thirteenthDao.selectTechnologyArchives13ById(oldSocialNo, id);
                    oldTa13.setSocialNo(socialNo);
                    int maxId = thirteenthDao.selectTechnologyArchives13MaxId(socialNo);
                    oldTa13.setId(maxId + 1);
                    num = thirteenthDao.insert(oldTa13);
                    thirteenthDao.delTechnologyArchives13ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives13> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",thirteenth.getSocialNo());
                    updateWrapper.eq("id",thirteenth.getId());
                    num = thirteenthDao.update(thirteenth, updateWrapper);
//                    num = thirteenthDao.updateTechnologyArchives13ById(thirteenth);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = thirteenthDao.selectTechnologyArchives13MaxId(socialNo);
                thirteenth.setAccount(user.getCode());
                thirteenth.setId(maxId + 1);
                num = thirteenthDao.insert(thirteenth);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存专业学会任职情况失败！");
            }
            resultMap.put("cg", "保存专业学会任职情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存专业学会任职情况失败！");
        }
    }

    /**
     * @param socialNo 身份证号  id
     * @return map
     * @Description 根据身份证号, id删除专业学会任职情况
     * @Author hsh
     * @Date 2024/7/16 16:56
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives13ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = thirteenthDao.delTechnologyArchives13ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除专业学会任职情况失败！");
            }
            resultMap.put("cg", "删除专业学会任职情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除专业学会任职情况失败！");
        }
    }

    /**
     * @return TechnologyArchives14 继续教育学分获得情况
     * @Description 查询继续教育学分获得情况
     * @Author hsh
     * @Date 2024/7/17 9:48
     */
    public ResultVo<List<TechnologyArchives14>> selectTechnologyArchives14() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives14> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives14> list = fourteenthDao.selectList(querywrapper);
//        List<TechnologyArchives14> list = fourteenthDao.selectFourteenthListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /**
     * @param fourteenth 继续教育学分获得情况
     * @return map
     * @Description 根据身份证号更新继续教育学分获得情况
     * @Author hsh
     * @Date 2024/7/17 9:49
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives14(TechnologyArchives14 fourteenth) {

        if (null == fourteenth || fourteenth.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "继续教育学分获得情况信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = fourteenth.getSocialNo();
        Integer id = fourteenth.getId();
        TechnologyArchives14 ta14 = fourteenthDao.selectTechnologyArchives14ById(socialNo, id);

        int num;
        try {
            if (null != ta14) {
                String oldSocialNo = fourteenth.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives14 oldTa14 = fourteenthDao.selectTechnologyArchives14ById(oldSocialNo, id);
                    oldTa14.setSocialNo(socialNo);
                    int maxId = fourteenthDao.selectTechnologyArchives14MaxId(socialNo);
                    oldTa14.setId(maxId + 1);
                    num = fourteenthDao.insert(oldTa14);
                    fourteenthDao.delTechnologyArchives14ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives14> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",fourteenth.getSocialNo());
                    updateWrapper.eq("id",fourteenth.getId());
                    num = fourteenthDao.update(fourteenth, updateWrapper);
//                    num = fourteenthDao.updateTechnologyArchives14ById(fourteenth);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = fourteenthDao.selectTechnologyArchives14MaxId(socialNo);
                fourteenth.setAccount(user.getCode());
                fourteenth.setId(maxId + 1);
                num = fourteenthDao.insert(fourteenth);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存继续教育学分获得情况失败！");
            }
            resultMap.put("cg", "保存继续教育学分获得情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存继续教育学分获得情况失败！");
        }
    }

    /**
     * @param socialNo 身份证号  id
     * @return map
     * @Description 根据身份证号, id删除继续教育学分获得情况
     * @Author hsh
     * @Date 2024/7/17 9:49
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives14ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = fourteenthDao.delTechnologyArchives14ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除继续教育学分获得情况失败！");
            }
            resultMap.put("cg", "删除继续教育学分获得情况成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除继续教育学分获得情况失败！");
        }
    }

    /**
     * @return TechnologyArchives8 限制类医疗技术档案
     * @Description 查询限制类医疗技术档案
     * @Author hsh
     * @Date 2024/7/18 9:59
     */
    public ResultVo<List<TechnologyArchives8>> selectTechnologyArchives8() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives8> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives8> list = eighthDao.selectList(querywrapper);
//        List<TechnologyArchives8> list = eighthDao.selectEighthListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /**
     * @param eighth 限制类医疗技术档案
     * @return map
     * @Description 根据身份证号更新限制类医疗技术档案
     * @Author hsh
     * @Date 2024/7/18 10:05
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives8(TechnologyArchives8 eighth) {

        if (null == eighth || eighth.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "限制类医疗技术档案信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = eighth.getSocialNo();
        Integer id = eighth.getId();
        TechnologyArchives8 ta8 = eighthDao.selectTechnologyArchives8ById(socialNo, id);

        int num;
        try {
            if (null != ta8) {
                String oldSocialNo = eighth.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives8 oldTa8 = eighthDao.selectTechnologyArchives8ById(oldSocialNo, id);
                    oldTa8.setSocialNo(socialNo);
                    int maxId = eighthDao.selectTechnologyArchives8MaxId(socialNo);
                    oldTa8.setId(maxId + 1);
                    num = eighthDao.insert(oldTa8);
                    eighthDao.delTechnologyArchives8ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives8> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",eighth.getSocialNo());
                    updateWrapper.eq("id",eighth.getId());
                    num = eighthDao.update(eighth, updateWrapper);
//                    num = eighthDao.updateTechnologyArchives8ById(eighth);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = eighthDao.selectTechnologyArchives8MaxId(socialNo);
                eighth.setAccount(user.getCode());
                eighth.setId(maxId + 1);
                num = eighthDao.insert(eighth);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存限制类医疗技术档案失败！");
            }
            resultMap.put("cg", "保存限制类医疗技术档案成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存限制类医疗技术档案失败！");
        }
    }

    /**
     * @param socialNo 身份证号  id
     * @return map
     * @Description 根据身份证号, id删除限制类医疗技术档案
     * @Author hsh
     * @Date 2024/7/18 10:06
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives8ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = eighthDao.delTechnologyArchives8ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除限制类医疗技术档案失败！");
            }
            resultMap.put("cg", "删除限制类医疗技术档案成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除限制类医疗技术档案失败！");
        }
    }

    /**
     * @return TechnologyArchives11 医疗安全行为记录
     * @Description 查询医疗安全行为记录
     * @Author hsh
     * @Date 2024/7/18 11:31
     */
    public ResultVo<List<TechnologyArchives11>> selectTechnologyArchives11() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives11> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives11> list = eleventhDao.selectList(querywrapper);
//        List<TechnologyArchives11> list = eleventhDao.selectEleventhListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /**
     * @param eleventh 医疗安全行为记录
     * @return map
     * @Description 根据身份证号更新医疗安全行为记录
     * @Author hsh
     * @Date 2024/7/18 11:32
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives11(TechnologyArchives11 eleventh) {

        if (null == eleventh || eleventh.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医疗安全行为记录信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = eleventh.getSocialNo();
        Integer id = eleventh.getId();
        TechnologyArchives11 ta11 = eleventhDao.selectTechnologyArchives11ById(socialNo, id);

        int num;
        try {
            if (null != ta11) {
                String oldSocialNo = eleventh.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives11 oldTa11 = eleventhDao.selectTechnologyArchives11ById(oldSocialNo, id);
                    oldTa11.setSocialNo(socialNo);
                    int maxId = eleventhDao.selectTechnologyArchives11MaxId(socialNo);
                    oldTa11.setId(maxId + 1);
                    num = eleventhDao.insert(oldTa11);
                    eleventhDao.delTechnologyArchives11ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives11> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",eleventh.getSocialNo());
                    updateWrapper.eq("id",eleventh.getId());
                    num = eleventhDao.update(eleventh, updateWrapper);
//                    num = eleventhDao.updateTechnologyArchives11ById(eleventh);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = eleventhDao.selectTechnologyArchives11MaxId(socialNo);
                eleventh.setAccount(user.getCode());
                eleventh.setId(maxId + 1);
                num = eleventhDao.insert(eleventh);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存医疗安全行为记录失败！");
            }
            resultMap.put("cg", "保存医疗安全行为记录成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存医疗安全行为记录失败！");
        }
    }

    /**
     * @param socialNo 身份证号  id
     * @return map
     * @Description 根据身份证号, id删除医疗安全行为记录
     * @Author hsh
     * @Date 2024/7/18 11:34
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives11ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = eleventhDao.delTechnologyArchives11ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除医疗安全行为记录失败！");
            }
            resultMap.put("cg", "删除医疗安全行为记录成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除医疗安全行为记录失败！");
        }
    }

    /**
     * @return TechnologyArchives15 应用医疗技术权限记录
     * @Description 查询应用医疗技术权限记录
     * @Author hsh
     * @Date 2024/7/18 15:42
     */
    public ResultVo<List<TechnologyArchives15>> selectTechnologyArchives15() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives15> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives15> list = fifteenthDao.selectList(querywrapper);
//        List<TechnologyArchives15> list = fifteenthDao.selectFifteenthListByCode(null, user.getCode());
        return ResultVoUtil.success(list);
    }

    /**
     * @param fifteenth 应用医疗技术权限记录
     * @return map
     * @Description 根据身份证号更新应用医疗技术权限记录
     * @Author hsh
     * @Date 2024/7/18 15:46
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives15(TechnologyArchives15 fifteenth) {

        if (null == fifteenth || fifteenth.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "应用医疗技术权限记录信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = fifteenth.getSocialNo();
        Integer id = fifteenth.getId();
        TechnologyArchives15 ta15 = fifteenthDao.selectTechnologyArchives15ById(socialNo, id);

        int num;
        try {
            if (null != ta15) {
                String oldSocialNo = fifteenth.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives15 oldTa15 = fifteenthDao.selectTechnologyArchives15ById(oldSocialNo, id);
                    oldTa15.setSocialNo(socialNo);
                    int maxId = fifteenthDao.selectTechnologyArchives15MaxId(socialNo);
                    oldTa15.setId(maxId + 1);
                    num = fifteenthDao.insert(oldTa15);
                    fifteenthDao.delTechnologyArchives15ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives15> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",fifteenth.getSocialNo());
                    updateWrapper.eq("id",fifteenth.getId());
                    num = fifteenthDao.update(fifteenth, updateWrapper);
//                    num = fifteenthDao.updateTechnologyArchives15ById(fifteenth);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = fifteenthDao.selectTechnologyArchives15MaxId(socialNo);
                fifteenth.setAccount(user.getCode());
                fifteenth.setId(maxId + 1);
                num = fifteenthDao.insert(fifteenth);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存应用医疗技术权限记录失败！");
            }
            resultMap.put("cg", "保存应用医疗技术权限记录成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存应用医疗技术权限记录失败！");
        }
    }

    /**
     * @param socialNo 身份证号  id
     * @return map
     * @Description 根据身份证号, id删除应用医疗技术权限记录
     * @Author hsh
     * @Date 2024/7/18 15:48
     */
    public ResultVo<Map<String, Object>> delTechnologyArchives15ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = fifteenthDao.delTechnologyArchives15ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除医疗安全行为记录失败！");
            }
            resultMap.put("cg", "删除医疗安全行为记录成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除医疗安全行为记录失败！");
        }
    }

    /**
     * @return TechnologyArchives16 教育经历
     * @Description 查询教育经历
     * @Author XU
     * @Date 2025/4/28 11:01
     */
    public ResultVo<List<TechnologyArchives16>> selectTechnologyArchives16() {
        UserInfo user = userCache.getUserInfoByToken();
        QueryWrapper<TechnologyArchives16> querywrapper = new QueryWrapper<>();
        querywrapper.eq("account",user.getCode());
        List<TechnologyArchives16> list = sixteenthDao.selectList(querywrapper);
        return ResultVoUtil.success(list);
    }

    /**
     * @param
     * @return 
     * @Description 
     * @Author XU
     * @Date 2025/4/28 11:03
     */
    public ResultVo<Map<String, Object>> saveTechnologyArchives16(TechnologyArchives16 sixteenth) {

        if (null == sixteenth || sixteenth.getSocialNo() == null) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "信息不全，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        String socialNo = sixteenth.getSocialNo();
        Integer id = sixteenth.getId();
        TechnologyArchives16 ta16 = sixteenthDao.selectTechnologyArchives16ById(socialNo, id);

        int num;
        try {
            if (null != ta16) {
                String oldSocialNo = sixteenth.getOldSocialNo();
                if (StringUtil.notBlank(oldSocialNo)) {
                    TechnologyArchives16 oldTa16 = sixteenthDao.selectTechnologyArchives16ById(oldSocialNo, id);
                    oldTa16.setSocialNo(socialNo);
                    int maxId = sixteenthDao.selectTechnologyArchives16MaxId(socialNo);
                    oldTa16.setId(maxId + 1);
                    num = sixteenthDao.insert(oldTa16);
                    sixteenthDao.delTechnologyArchives16ByCode(oldSocialNo, id);
                } else {
                    UpdateWrapper<TechnologyArchives16> updateWrapper = new UpdateWrapper<>();
                    updateWrapper.eq("social_no",sixteenth.getSocialNo());
                    updateWrapper.eq("id",sixteenth.getId());
                    num = sixteenthDao.update(sixteenth, updateWrapper);
                }
            } else {
                UserInfo user = userCache.getUserInfoByToken();
                int maxId = sixteenthDao.selectTechnologyArchives16MaxId(socialNo);
                sixteenth.setAccount(user.getCode());
                sixteenth.setId(maxId + 1);
                num = sixteenthDao.insert(sixteenth);
            }
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存教育经历失败！");
            }
            resultMap.put("cg", "保存教育经历成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存教育经历失败！");
        }
    }

    /**
     * @param socialNo 身份证号码 id
     * @return map
     * @Description 根据身份证号码，id删除教育经历
     * @Author XU
     * @Date 2025/4/28 11:39
     */

    public ResultVo<Map<String, Object>> delTechnologyArchives16ByCode(String socialNo, Integer id) {
        if (StringUtil.isBlank(socialNo)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有身份证号，请检查！");
        }

        Map<String, Object> resultMap = new HashMap<>();
        try {
            int num = sixteenthDao.delTechnologyArchives16ByCode(socialNo, id);
            if (num == 0) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除教育经历失败！");
            }
            resultMap.put("cg", "删除学习教育成功！");
            return ResultVoUtil.success(resultMap);
        } catch (Exception e) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除教育经历失败！");
        }
    }

    /**
     * @param type 类型
     * @return map
     * @Description 查询技术档案种类
     * @Author hsh
     * @Date 2024/8/1 15:26
     */
    public ResultVo<Map<String, Object>> selectTechnologyArchivesType(String type) {
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list;
        if ("all".equals(type)) {
            list = dao.selectTechnologyArchivesTypeAll();
        } else {
            list = dao.selectTechnologyArchivesType(type);
        }
        map.put("taList", list);
        return ResultVoUtil.success(map);
    }

    /**
     * @param vo (textType 文档类型 text 关键字)
     * @return map
     * @Description 根据文档类型查询技术文档信息
     * @Author hsh
     * @Date 2024/8/7 16:30
     */
    public ResultVo<Map<String, Object>> selectTechnologyArchivesInfo(TechnologyArchivesVo vo) {
        if (StringUtil.isBlank(vo.getTextType())) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到文档类型，请检查！");
        }
        UserInfo user = userCache.getUserInfoByToken();
        int dd = dao.selectTechnologyArchivesTypeQx(user.getCode().trim());
        Map<String, Object> map = new HashMap<>();
        List<Map<String, Object>> list;
        TechnologyArchivesType t = dao.selectTechnologyArchivesTypeInfo(vo.getTextType());
        if (null == t) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有检索到登录者的技术档案。");
        }
        String sql = t.getTableSql();
        if (dd == 0) {
            // 没有审核权限，只能查询自己的记录
            String sfz;
            if (null == user.getSocialNo() || StringUtil.isBlank(user.getSocialNo())) {
                TechnologyArchivesMain mainSelf = mainDao.selectTechnologyArchivesMainBySocialNo(user.getCode().trim());
                sfz = mainSelf.getSocialNo();
            } else {
                sfz = user.getSocialNo().trim();
            }
            if (StringUtil.isBlank(sfz)) {
                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有检索到登录者技术档案的身份证信息，请检查！");
            }
            if (t.getTableName().endsWith("main")) {
                if (StringUtil.notBlank(sql)) {
                    list = dao.selectTechnologyArchivesInfoBySql(sql, null, sfz);
                } else {
                    list = dao.selectTechnologyArchivesMainInfo(t.getTableName(), null, sfz);
                }
            } else {
                if (StringUtil.notBlank(sql)) {
                    list = dao.selectTechnologyArchivesInfoBySql(sql, null, sfz);
                } else {
                    list = dao.selectTechnologyArchivesInfo(t.getTableName(), null, sfz);
                }
            }
        } else {
            // 查询所有的文档
            String sfz = null;
            String xm = null;
            if (StringUtil.notBlank(vo.getText())) {
                TechnologyArchivesMain mainSelf = mainDao.selectTechnologyArchivesMainBySocialNo(vo.getText());
                if (null == mainSelf || StringUtil.isBlank(mainSelf.getSocialNo())) {
                    TechnologyArchivesMain main = dao.selectEmployeeInfo(vo.getText());
                    if (null != main && StringUtil.notBlank(main.getSocialNo())) {
                        sfz = main.getSocialNo().trim();
                    }
                } else {
                    sfz = mainSelf.getSocialNo();
                }
                if (StringUtil.isBlank(sfz)) {
                    return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有检索到查询技术档案的身份证信息，请检查！");
                }

            }
            if (t.getTableName().endsWith("main")) {
                if (StringUtil.notBlank(sql)) {
                    list = dao.selectTechnologyArchivesInfoBySql(sql, null, StringUtil.notBlank(vo.getText()) ? sfz : null);
                } else {
                    list = dao.selectTechnologyArchivesMainInfo(t.getTableName(), null, StringUtil.notBlank(vo.getText()) ? sfz : null);
                }
            } else {
                if (StringUtil.notBlank(sql)) {
                    list = dao.selectTechnologyArchivesInfoBySql(sql, null, StringUtil.notBlank(vo.getText()) ? sfz : null);
                } else {
                    list = dao.selectTechnologyArchivesInfo(t.getTableName(), null, StringUtil.notBlank(vo.getText()) ? sfz : null);
                }
            }
        }

        // 拼接展示的字段prop以及字段label
        String tableProp = t.getTableProp();
        String tableLabel = t.getTableLabel();
        String showLabel = t.getShowLabel();
        if (StringUtil.isBlank(tableProp)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, t.getName() + "没有配置显示字段prop，请联系管理员！");
        }
        if (StringUtil.isBlank(tableLabel)) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, t.getName() + "没有配置显示字段label，请联系管理员！");
        }
        List<String> propList = Arrays.asList(tableProp.split(","));
        List<String> labelList = Arrays.asList(tableLabel.split(","));
        List<String> showList = new ArrayList<>();
        if (StringUtil.notBlank(showLabel)) {
            showList = Arrays.asList(showLabel.split(","));
        }
        if (propList.size() != labelList.size()) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, t.getName() + "配置显示字段display和label数量不一致，请联系管理员！");
        }

        List<HeadInfo> display = new ArrayList<>();
        // 文档资料都需要显示姓名
        HeadInfo h = new HeadInfo();
        h.setDisplay("姓名");
        h.setName("xm");
        h.setWidth("100");
        h.setSort(1);
        display.add(h);
        for (int i = 0; i < propList.size(); i++) {
            HeadInfo info = getHeadInfo(propList, i, labelList, showList);
            display.add(info);
        }

        map.put("taData", list);
        map.put("displayData", display);
        return ResultVoUtil.success(map);
    }

    /**
     * @param propList  显示的字段属性集合
     * @param i         序号
     * @param labelList 显示的字段名称集合
     * @param showList  是否需要鼠标悬停显示全部信息
     * @return HeadInfo 一个表头信息
     * @Description 组装表头信息
     * @Author hsh
     * @Date 2024/8/7 17:04
     */
    @NotNull
    private static HeadInfo getHeadInfo(List<String> propList, int i, List<String> labelList, List<String> showList) {
        HeadInfo info = new HeadInfo();
        String p = propList.get(i);
        String l = labelList.get(i);
        if (p.contains("|")) {
            String f1 = p.split("\\|")[0];
            String c1 = p.split("\\|")[1];
            String f2 = l.split("\\|")[0];
            String c2 = l.split("\\|")[1];
            List<HeadInfo> displaysC = new ArrayList<>();
            // 添加二级表头的标记（以“-t”结尾）
            setShowInfo(showList, info, i, info, f1, f2);
            List<String> propListC = Arrays.asList(c1.split(":"));
            List<String> labelListC = Arrays.asList(c2.split(":"));
            for (int j = 0; j < propListC.size(); j++) {
                HeadInfo infoC = new HeadInfo();
                String dc = propListC.get(j);
                String lc = labelListC.get(j);
                setShowInfo(showList, info, j, infoC, dc, lc);
                displaysC.add(infoC);
            }
            info.setColumns(displaysC);
        } else {
            setShowInfo(showList, info, i, info, p, l);
        }
        return info;
    }

    /**
     * @param showList  需要显示字段集合
     * @param info      第一层显示数据（存在子级目录的话）
     * @param o         序号
     * @param infoChild 第二层显示数据（存在子级目录的话）或者第一层显示数据（不存在子级目录的话）
     * @param prop      显示字段属性（可能带|，:符号 其中|表示后面拼接子级目录，:表示子级目录显示字典属性拼接）
     * @param label     显示字段名称（可能带|，:，/符号 其中|表示后面拼接子级目录，:表示子级目录显示字典名称拼接，/表示后面拼接字段显示宽度）
     * @Description 组成数据（备注：|，:，/需要按顺序拼接，否则会导致表格显示错误, 基本信息name一栏不用配置显示字段且所有字段属性不能出现xm）
     * @Author hsh
     * @Date 2024/8/7 18:33
     */
    private static void setShowInfo(List<String> showList, HeadInfo info, int o, HeadInfo infoChild, String prop, String label) {
        infoChild.setName(prop);
        if (!showList.isEmpty()) {
            for (String str : showList) {
                if (prop.equals(str)) {
                    info.setShow(true);
                    break;
                }
            }
        }
        String[] l = label.split("/");
        infoChild.setDisplay(l[0]);
        if (l.length == 2) {
            infoChild.setWidth(l[1]);
        }
        infoChild.setSort(o + 2);
    }

    /**
     * @param dto (textType 文档类型 text 关键字)
     * @return map
     * @Description 导出技术档案信息
     * @Author hsh
     * @Date 2024/8/9 11:03
     */
    public ResultVo<Map<String, Object>> exportTechnologyArchivesInfo(HttpServletResponse response, TechnologyArchivesVo dto) {
        Map<String, Object> map = new HashMap<>();
        ResultVo<Map<String, Object>> resultVo = selectTechnologyArchivesInfo(dto);
        Map<String, Object> data = resultVo.getData();
        // 数据
        List<Map<String, Object>> list = (List<Map<String, Object>>) data.get("taData");

        if (null == list || list.isEmpty()) {
            map.put("code", 1);
            map.put("massage", "查询数据为空，导出失败！");
            return ResultVoUtil.success(map);
        }

        // 导出标题
        String exportName = dto.getExportName();

        // 组装表头
        List<HeadInfo> headInfoList = (List<HeadInfo>) data.get("displayData");
        List<HeadInfo> sortHeadInfo = headInfoList.stream().sorted(Comparator.comparing(HeadInfo::getSort)).collect(Collectors.toList());

        // 导出
        if (true) {
            ExcelUtil.exportExcelReport(response, list, sortHeadInfo, exportName);
            return null;
        }


        map.put("code", 0);
        map.put("massage", "导出成功！");
        return ResultVoUtil.success(map);
    }

    /**
     * @param  exportVo (ExportTypes 文档类型 ExportNames 关键字)
     * @return map
     * @Description 导出所有档案的信息
     * @Author XU
     * @Date 2025/4/2
     */
    public ResultVo<Map<String, Object>> exportMultiTechnologyArchives(HttpServletResponse response, TechnologyArchivesMultiVo exportVo) {
        Map<String, Object> map = new HashMap<>();
        List<ComplexSheetData> sheets = new ArrayList<>();

        // 参数校验
        if (exportVo.getExportTypes() == null || exportVo.getExportTypes().isEmpty()) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请选择要导出的文档类型");
        }
        if (exportVo.getExportNames() == null || exportVo.getExportNames().size() != exportVo.getExportTypes().size()) {
            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "每个导出类型必须对应一个名称");
        }
        String text = exportVo.getText();

        // 遍历类型和名称
        for (int i = 0; i < exportVo.getExportTypes().size(); i++) {
            String textType = exportVo.getExportTypes().get(i);
            String exportName = exportVo.getExportNames().get(i); // 获取自定义名称

            TechnologyArchivesVo vo = new TechnologyArchivesVo();
            vo.setText(text);
            vo.setTextType(textType);
            vo.setExportName(exportName); // 设置当前Sheet的名称

            ResultVo<Map<String, Object>> result = selectTechnologyArchivesInfo(vo);
            if (!result.isSuccess()) continue;

            ComplexSheetData sheet = new ComplexSheetData();
            sheet.setSheetName(exportName); // 直接使用自定义名称，无需拼接
            sheet.setHeaders((List<HeadInfo>) result.getData().get("displayData"));
            sheet.setData((List<Map<String, Object>>) result.getData().get("taData"));
            sheets.add(sheet);
        }

        if (null == sheets || sheets.isEmpty()) {
            map.put("code", 1);
            map.put("massage", "查询数据为空，导出失败！");
            return ResultVoUtil.success(map);
        }

        if (true) {
            ExcelUtil.exportMultiSheetReport(response, sheets, "技术档案汇总报告.xls");
            return null;
        }

        map.put("code", 0);
        map.put("massage", "导出成功！");
        return ResultVoUtil.success(map);
    }

    /**
     * @return list
     * @Description 查询所有技术档案Ⅰ类人员主要信息(账号 ， 身份证号 ， 姓名)
     * @Author hsh
     * @Date 2024/8/12 16:19
     */
    public ResultVo<List<Map<String, Object>>> selectTechnologyArchivesMainDict() {
        List<Map<String, Object>> list = mainDao.selectTechnologyArchivesMainDict();
        return ResultVoUtil.success(list);
    }

}
