package com.jeeplus.business.humanResources.service;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
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.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.business.humanResources.domain.RegularApply;
import com.jeeplus.business.humanResources.domain.StaffUserInfo;
import com.jeeplus.business.humanResources.mapper.RegularApplyMapper;
import com.jeeplus.business.humanResources.mapper.StaffUserInfoMapper;
import com.jeeplus.business.humanResources.service.dto.StaffUserInfoDTO;
import com.jeeplus.common.SecurityUtils;
import com.jeeplus.common.TokenProvider;
import com.jeeplus.core.query.QueryWrapperGenerator;
import com.jeeplus.sys.domain.WorkAttachmentInfo;
import com.jeeplus.sys.feign.IPostApi;
import com.jeeplus.sys.feign.IRoleApi;
import com.jeeplus.sys.feign.IUserApi;
import com.jeeplus.sys.feign.IWorkAttachmentApi;
import com.jeeplus.sys.service.dto.OfficeDTO;
import com.jeeplus.sys.service.dto.PostDTO;
import com.jeeplus.sys.service.dto.RoleDTO;
import com.jeeplus.sys.service.dto.UserDTO;
import com.jeeplus.utils.StringUtils;
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 StaffUserInfoService {

    @Resource
    private StaffUserInfoMapper staffUserInfoMapper;

    @Resource
    private RegularApplyMapper regularApplyMapper;

    public IPage<StaffUserInfoDTO> findPageList(StaffUserInfoDTO userInfoDTO, Page<StaffUserInfoDTO> page) throws Exception {
        QueryWrapper<StaffUserInfoDTO> queryWrapper = QueryWrapperGenerator.buildQueryCondition(userInfoDTO, StaffUserInfoDTO.class);
        queryWrapper.eq("a.del_flag",0);
        //姓名查询
        if (StringUtils.isNotBlank(userInfoDTO.getName())){
            queryWrapper.like("a.name",userInfoDTO.getName());
        }
        //手机号查询
        if (StringUtils.isNotBlank(userInfoDTO.getMobilePhone())){
            queryWrapper.like("a.mobile_phone",userInfoDTO.getMobilePhone());
        }
        //部门
        if (StringUtils.isNotBlank(userInfoDTO.getOfficeId())){
            queryWrapper.eq("so.id",userInfoDTO.getOfficeId());
        }
        //员工类型
        if (StringUtils.isNotBlank(userInfoDTO.getOnJobStatus())){
            queryWrapper.eq("a.on_job_status",userInfoDTO.getOnJobStatus());
        }
        //员工状态
        if (StringUtils.isNotBlank(userInfoDTO.getLoginFlag())){
            queryWrapper.eq("su.login_flag",userInfoDTO.getLoginFlag());
        }
        //创建人
        if (StringUtils.isNotBlank(userInfoDTO.getCreateById())){
            queryWrapper.eq("a.create_by_id",userInfoDTO.getCreateById());
        }
        //创建时间
        if (userInfoDTO.getCreateDates() != null && userInfoDTO.getCreateDates().length>0){
            queryWrapper.between("a.create_time",userInfoDTO.getCreateDates()[0],userInfoDTO.getCreateDates()[1]);
        }
        IPage<StaffUserInfoDTO> dtoList=staffUserInfoMapper.findPageList(queryWrapper,page);
        return dtoList;
    }

    /**
     * 根据id进行查询
     * @param id
     * @return
     */
    public StaffUserInfoDTO findById(String id) {
        StaffUserInfoDTO staffUserInfoDTO=staffUserInfoMapper.findById(id);
        if (ObjectUtils.isNotEmpty(staffUserInfoDTO)){
         //将角色放入集合中
            if (StringUtils.isNotBlank(staffUserInfoDTO.getRoleId())){
                List<String> roles = new ArrayList<>();
                String[] split = staffUserInfoDTO.getRoleId().split(",");
                for (String s : split) {
                    if (StringUtils.isNotBlank(s)){
                        roles.add(s);
                    }
                }
                staffUserInfoDTO.setRoleIdList(roles);
            }
           if (StringUtils.isNotBlank(staffUserInfoDTO.getPostId())){
               //将岗位放入集合中
               ArrayList<String> posts = new ArrayList<>();
               String[] split1 = staffUserInfoDTO.getPostId().split(",");
               for (String s : split1) {
                   if (StringUtils.isNotBlank(s)){
                       posts.add(s);
                   }
               }
               staffUserInfoDTO.setPostIdList(posts);
           }

        }
        //查询附件
        List<WorkAttachmentInfo> files = staffUserInfoMapper.findDtos(id,"humanResources");
        if (CollectionUtils.isNotEmpty(files)) {
            for (WorkAttachmentInfo i : files) {
                i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
            }
            staffUserInfoDTO.setFiles(files);
        }
        //查询承诺书
        List<WorkAttachmentInfo> commitment = staffUserInfoMapper.findDtos(id,"commitment");
        if (CollectionUtils.isNotEmpty(commitment)) {
            for (WorkAttachmentInfo i : commitment) {
                i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
            }
            staffUserInfoDTO.setCommitment(commitment);
        }
        //查询申请表
        List<WorkAttachmentInfo> applys = staffUserInfoMapper.findDtos(id,"applys");
        if (CollectionUtils.isNotEmpty(applys)) {
            for (WorkAttachmentInfo i : applys) {
                i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
            }
            staffUserInfoDTO.setApplys(applys);
        }
        //查询学历证明
        List<WorkAttachmentInfo> certificates = staffUserInfoMapper.findDtos(id,"certificates");
        if (CollectionUtils.isNotEmpty(certificates)) {
            for (WorkAttachmentInfo i : certificates) {
                i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
            }
            staffUserInfoDTO.setCertificates(certificates);
        }
        //查询身份证
        List<WorkAttachmentInfo> idCards = staffUserInfoMapper.findDtos(id,"idCards");
        if (CollectionUtils.isNotEmpty(idCards)) {
            for (WorkAttachmentInfo i : idCards) {
                i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
            }
            staffUserInfoDTO.setIdCards(idCards);
        }
        //查询培训证书
        List<WorkAttachmentInfo> trainings = staffUserInfoMapper.findDtos(id,"trainings");
        if (CollectionUtils.isNotEmpty(trainings)) {
            for (WorkAttachmentInfo i : trainings) {
                i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
            }
            staffUserInfoDTO.setTrainings(trainings);
        }
        //查询职称
        List<WorkAttachmentInfo> professional = staffUserInfoMapper.findDtos(id,"professional");
        if (CollectionUtils.isNotEmpty(professional)) {
            for (WorkAttachmentInfo i : professional) {
                i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
            }
            staffUserInfoDTO.setProfessional(professional);
        }
        //查询离职证明
        List<WorkAttachmentInfo> resignation = staffUserInfoMapper.findDtos(id,"resignation");
        if (CollectionUtils.isNotEmpty(resignation)) {
            for (WorkAttachmentInfo i : resignation) {
                i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
            }
            staffUserInfoDTO.setResignation(resignation);
        }
        return staffUserInfoDTO;
    }


    /**
     * 新增或修改
     * @param staffUserInfoDTO
     * @return
     */
    public String saveForm(StaffUserInfoDTO staffUserInfoDTO) {
        String id="";
        //获取当前登陆人信息
        UserDTO userDTO = SpringUtil.getBean(IUserApi.class).getByToken(TokenProvider.getCurrentToken());
        String userId="";
        StaffUserInfo staffUserInfo = new StaffUserInfo();

        BeanUtils.copyProperties(staffUserInfoDTO,staffUserInfo);

        staffUserInfo.setUpdateById(userDTO.getId());
        staffUserInfo.setUpdateTime(new Date());
        String roleId="";
        ArrayList<RoleDTO> roleDTOS = new ArrayList<>();
        //获取角色
        if (ObjectUtils.isNotEmpty(staffUserInfoDTO.getRoleIdList())){
            for (String role : staffUserInfoDTO.getRoleIdList()) {
                RoleDTO roleDTO = SpringUtil.getBean(IRoleApi.class).getRoleDTOById(role);
                roleDTOS.add(roleDTO);
                roleId+=role+",";
            }
        }
        //获取岗位
        String postId="";
        ArrayList<PostDTO> postDTOS = new ArrayList<>();
        PostDTO postDTO = new PostDTO();
        if (ObjectUtils.isNotEmpty(staffUserInfoDTO.getPostIdList())){
            for (String post : staffUserInfoDTO.getPostIdList()) {
                postDTO.setId(post);
                postId+=post+",";
            }
        }
        postDTOS.addAll(postDTOS);
        staffUserInfo.setPostId(postId);
        staffUserInfo.setRoleId(roleId);

        //审核通过的时候往用户表中新增一条数据
        if (StringUtils.isNotBlank(staffUserInfo.getType())){
            if ("5".equals(staffUserInfo.getType())){
                StaffUserInfoDTO staffUserInfoDTO1=staffUserInfoMapper.findById(staffUserInfo.getId());
                if (StringUtils.isNotBlank(staffUserInfoDTO1.getUserId())){
                    userId=staffUserInfoDTO1.getUserId();
                }else {

                    //userId = UUID.randomUUID().toString().replace("-", "");
                    // 获取UUID的字符串表示形式并移除所有非数字字符
                    userId = UUID.randomUUID().toString().replaceAll("[^0-9]", "");

                    while (userId.length() < 19) {
                        userId = userId + UUID.randomUUID().toString().replaceAll("[^0-9]", "");
                    }
                    /*do{
                        userId = userId + UUID.randomUUID().toString().replaceAll("[^0-9]", "");
                    }while (userId.length() > 19);*/

                    userId = userId.substring(0, 19);
                }
                UserDTO dto = new UserDTO();
                dto.setId(userId);
                dto.setName(staffUserInfo.getName());
                dto.setLoginName(staffUserInfo.getName());
                dto.setLoginFlag("1");
                dto.setPassword(SecurityUtils.encryptPassword("123456"));
                dto.setMobile(staffUserInfo.getMobilePhone());
                dto.setTenantDTO(userDTO.getTenantDTO());
                dto.setCompanyDTO(userDTO.getCompanyDTO());
                OfficeDTO officeDTO = new OfficeDTO();
                officeDTO.setId(staffUserInfo.getDepartment());
                dto.setOfficeDTO(officeDTO);
                dto.setManageOfficeIds(staffUserInfo.getManagerOffice());
                dto.setPostDTOList(postDTOS);
                dto.setRoleDTOList(roleDTOS);
                SpringUtil.getBean(IUserApi.class).saveOrUpdate(dto);

                staffUserInfo.setUserId(userId);

                //如果是员工状态为试用的话,则往转正申请表中添加一条数据
                if ("1".equals(staffUserInfo.getOnJobStatus())){
                    //先判断转正表中有没有数据
                    LambdaQueryWrapper<RegularApply> queryWrapper = new LambdaQueryWrapper<>();
                    queryWrapper.eq(RegularApply::getInfoId,staffUserInfo.getId());
                    RegularApply regularApply = regularApplyMapper.selectOne(queryWrapper);
                    if (ObjectUtil.isEmpty(regularApply)){
                        RegularApply regularApply1 = new RegularApply();
                        regularApply1.setInfoId(staffUserInfo.getId());
                        regularApply1.setCreateById(staffUserInfo.getUserId());
                        regularApply1.setCreateTime(new Date());
                        regularApply1.setUpdateById(staffUserInfo.getUserId());
                        regularApply1.setUpdateTime(new Date());
                        regularApply1.setStatus("0");
                        regularApplyMapper.insert(regularApply1);
                    }
                }

            }

        }

        if (StringUtils.isNotBlank(staffUserInfoDTO.getId())){
            id=staffUserInfoDTO.getId();
            staffUserInfoMapper.updateById(staffUserInfo);
        }else {
            //获取id
            id = UUID.randomUUID().toString().replace("-", "");
            staffUserInfo.setId(id);
            staffUserInfoMapper.insert(staffUserInfo);
        }

        if (ObjectUtils.isNotEmpty(staffUserInfoDTO)){
            Map<String,String> map = new HashMap<>();
            //承诺书
            String fileList = JSON.toJSONString((staffUserInfoDTO.getCommitment()));
            String attachmentId = id;
            String attachmentFlag = "commitment";
            map.put("fileList",fileList);
            map.put("attachmentId",attachmentId);
            map.put("attachmentFlag",attachmentFlag);
            map.put("currentToken", TokenProvider.getCurrentToken ( ));
            SpringUtil.getBean ( IWorkAttachmentApi.class ).saveOrUpdateFileListFlag(map);
            //附件
            fileList = JSON.toJSONString((staffUserInfoDTO.getFiles()));
            attachmentFlag = "humanResources";
            map.put("fileList",fileList);
            map.put("attachmentFlag",attachmentFlag);
            SpringUtil.getBean ( IWorkAttachmentApi.class ).saveOrUpdateFileListFlag(map);
            //申请表
            fileList = JSON.toJSONString((staffUserInfoDTO.getApplys()));
            attachmentFlag = "applys";
            map.put("fileList",fileList);
            map.put("attachmentFlag",attachmentFlag);
            SpringUtil.getBean ( IWorkAttachmentApi.class ).saveOrUpdateFileListFlag(map);
            //学历证明
            fileList = JSON.toJSONString((staffUserInfoDTO.getCertificates()));
            attachmentFlag = "certificates";
            map.put("fileList",fileList);
            map.put("attachmentFlag",attachmentFlag);
            SpringUtil.getBean ( IWorkAttachmentApi.class ).saveOrUpdateFileListFlag(map);
            //学历证明
            fileList = JSON.toJSONString((staffUserInfoDTO.getIdCards()));
            attachmentFlag = "idCards";
            map.put("fileList",fileList);
            map.put("attachmentFlag",attachmentFlag);
            SpringUtil.getBean ( IWorkAttachmentApi.class ).saveOrUpdateFileListFlag(map);
            //培训证书
            fileList = JSON.toJSONString((staffUserInfoDTO.getTrainings()));
            attachmentFlag = "trainings";
            map.put("fileList",fileList);
            map.put("attachmentFlag",attachmentFlag);
            SpringUtil.getBean ( IWorkAttachmentApi.class ).saveOrUpdateFileListFlag(map);
            //职称
            fileList = JSON.toJSONString((staffUserInfoDTO.getProfessional()));
            attachmentFlag = "professional";
            map.put("fileList",fileList);
            map.put("attachmentFlag",attachmentFlag);
            SpringUtil.getBean ( IWorkAttachmentApi.class ).saveOrUpdateFileListFlag(map);
            //离职证明
            fileList = JSON.toJSONString((staffUserInfoDTO.getResignation()));
            attachmentFlag = "resignation";
            map.put("fileList",fileList);
            map.put("attachmentFlag",attachmentFlag);
            SpringUtil.getBean ( IWorkAttachmentApi.class ).saveOrUpdateFileListFlag(map);
        }
        return id;
    }

    /**
     * 根据id修改状态
     * @param staffUserInfoDTO
     */
    public void updateStatusById(StaffUserInfoDTO staffUserInfoDTO) {
        staffUserInfoMapper.updatestatusById(staffUserInfoDTO.getType(),staffUserInfoDTO.getId());
    }

    /**
     * 根据id进行删除
     * @param id
     * @return
     */
    public String deleteById(String id) {
        staffUserInfoMapper.deleteById(id);
        return "操作成功";
    }

    /**
     * 根据id查询转正信息
     * @param id
     * @return
     */
    public RegularApply findByApplyId(String id) {
        RegularApply regularApply=staffUserInfoMapper.findByApplyId(id);
        // 查询附件信息
        List<WorkAttachmentInfo> files = staffUserInfoMapper.findFiles(id);
        if (CollectionUtils.isNotEmpty(files)) {
            for (WorkAttachmentInfo i : files) {
                i.setCreateBy(SpringUtil.getBean ( IUserApi.class ).getById(i.getBy()));
            }
            regularApply.setFiles(files);
        }

        return regularApply;
    }

    /**
     * 保存/修改转正信息
     * @param regularApply
     * @return
     */
    public RegularApply saveApplyForm(RegularApply regularApply) {
        RegularApply applyId = findByApplyId(regularApply.getId());
        if ("2".equals(regularApply.getStatus())){
            if (ObjectUtil.isNotEmpty(applyId)){
                //判断此次转正申请是否是第一次发起
                //不是第一次发起则清空对应的内容并删除附件
                if ("5".equals(applyId.getStatus()) && "1".equals(applyId.getIsPass()) && "0".equals(applyId.getIsEmploy()) && "0".equals(applyId.getIsPostpone())){
                    applyId.setIsEmploy("");
                    applyId.setIsPass("");
                    applyId.setIsPostpone("");
                    applyId.setReason("");
                    regularApplyMapper.updateById(applyId);
                    SpringUtil.getBean ( IWorkAttachmentApi.class ).deleteById(applyId.getId());
                }
            }
        }
        //获取当前登录人信息
        UserDTO userDTO = SpringUtil.getBean(IUserApi.class).getByToken(TokenProvider.getCurrentToken());
        RegularApply apply = new RegularApply();
        BeanUtils.copyProperties(regularApply,apply);
        apply.setUpdateTime(new Date());
        apply.setUpdateById(userDTO.getId());
        if (StringUtils.isNotBlank(regularApply.getId())){
            regularApplyMapper.updateById(apply);
            // 修改附件信息列表
            if (CollectionUtils.isNotEmpty(regularApply.getFiles())) {
                updateFiles(regularApply.getFiles(), userDTO, apply.getId());
            }
        }else {
            apply.setId(UUID.randomUUID().toString().replace("-",""));
            regularApplyMapper.insert(apply);
            // 保存附件列表信息
            if (CollectionUtils.isNotEmpty(regularApply.getFiles())) {
                saveFiles(regularApply.getFiles(), userDTO, apply.getId());
            }
        }
        if(StringUtils.isNotBlank(regularApply.getId())){
            if (ObjectUtil.isNotEmpty(applyId)){
                //查询入职表中的信息
                StaffUserInfoDTO infoDTO = findById(applyId.getInfoId());
                //判断是否通过
                if (StringUtils.isNotBlank(regularApply.getIsPass()) ){
                    if (regularApply.getIsPass().equals("1")){
                        //不通过则去判断是否留用
                        if (StringUtils.isNotBlank(regularApply.getIsEmploy())){
                            //不通过也不留用同时状态为5 则将该员工账号冻结
                            if (regularApply.getIsPass().equals("1")&& regularApply.getIsEmploy().equals("1") && regularApply.getStatus().equals("5")){
                                UserDTO dto = new UserDTO();
                                dto.setLoginFlag("0");
                                dto.setId(infoDTO.getUserId());
                                SpringUtil.getBean(IUserApi.class).saveOrUpdate(dto);
                            }
                            if (regularApply.getIsPass().equals("1") && regularApply.getIsEmploy().equals("0") && regularApply.getStatus().equals("5")){
                                //不通过  留用  但发起人驳回的情况下获取当前登录人所属岗位是否是人事部  若是人事部则冻结账号
                                for (PostDTO postDTO : userDTO.getPostDTOList()) {
                                    if ("人事部".equals(postDTO.getId()) && regularApply.getStatus().equals("5")){
                                        UserDTO dto = new UserDTO();
                                        dto.setLoginFlag("0");
                                        dto.setId(infoDTO.getUserId());
                                        SpringUtil.getBean(IUserApi.class).saveOrUpdate(dto);
                                        break;
                                    }else if ("分管领导".equals(postDTO.getId()) && regularApply.getStatus().equals("5")){
                                        //否则的话则顺延一个月
                                        if (regularApply.getIsPostpone().equals("0")){
                                            StaffUserInfo staffUserInfo = new StaffUserInfo();
                                            staffUserInfo.setId(applyId.getInfoId());
                                            //获取到原本的试用期限
                                            int parseInt = Integer.parseInt(infoDTO.getTimeLimit());
                                            //顺延一个月
                                            int limit = parseInt+1;
                                            staffUserInfo.setTimeLimit(limit+"");
                                            //修改员工信息
                                            staffUserInfoMapper.updateById(staffUserInfo);
                                        }
                                    }
                                }


                            }

                        }
                    }else {
                        if (regularApply.getStatus().equals("5")){
                            //将员工状态改为正式
                            StaffUserInfo staffUserInfo = new StaffUserInfo();
                            staffUserInfo.setOnJobStatus("2");
                            staffUserInfo.setId(applyId.getInfoId());
                            staffUserInfoMapper.updateById(staffUserInfo);
                        }

                    }

                }
            }
        }




        return apply;
    }

    /**
     * 修改附件信息
     * @param list 待修改的附件列表
     * @param userDTO 当前登录用户
     * @param id 关联id
     */
    @Transactional(rollbackFor = Exception.class)
    public void updateFiles(List<WorkAttachmentInfo> list, UserDTO userDTO, String id) {
        int j = 1;
        String names = new String();
        //表中存在，但是传过来不存在，说明已删除，表中数据也要删除
        for (WorkAttachmentInfo dto : list) {
            names = names + "," +dto.getUrl();
        }
        //查询保存的附件信息
        List<WorkAttachmentInfo> infoList = staffUserInfoMapper.findList(id);
        if (org.flowable.editor.language.json.converter.util.CollectionUtils.isNotEmpty(infoList)) {
            for (WorkAttachmentInfo i : infoList) {
                if (!names.contains(i.getUrl())) {
//                    ossServiceMapper.deleteById(i.getId());
                    SpringUtil.getBean ( IWorkAttachmentApi.class ).deleteById(i.getId());
                }
            }
        }
        //保存信息
        for (WorkAttachmentInfo dto : list) {
            //判断是否存在
            Integer isExit = staffUserInfoMapper.findIsExit(id, dto.getName());
            if (isExit == 0) {
                WorkAttachmentInfo i = new WorkAttachmentInfo();
                //包含了url、size、name
                i.setId(UUID.randomUUID().toString().replace("-", ""));
//                i.getCreateBy().setId(userDTO.getId());
                i.setCreateTime(new Date());
//                i.getUpdateBy().setId(userDTO.getId());
                i.setUpdateTime(new Date());
                i.setDelFlag(0);
                i.setUrl(dto.getUrl());
                //文件类型处理
                List<String> strings = Arrays.asList(dto.getName().split("\\."));
                if (org.flowable.editor.language.json.converter.util.CollectionUtils.isNotEmpty(strings)) {
                    i.setType(strings.get(1));
                }
                i.setAttachmentId(id);
                i.setAttachmentName(dto.getName());
                i.setAttachmentFlag("regular");
                i.setFileSize(dto.getSize());
                i.setSort(j);
                Map<String,String> map = new HashMap<>();
                String workAttachment = JSON.toJSONString((i));
                String userDTOInfo = JSON.toJSONString((userDTO));
                map.put("workAttachment",workAttachment);
                map.put("userDTO",userDTOInfo);
                SpringUtil.getBean ( IWorkAttachmentApi.class ).insertWorkAttachment(map);
//                ossServiceMapper.insertWorkAttachment(i, userDTO);
                j++;
            }
        }
    }

    /**
     * 保存附件信息
     * @param list 待保存的附件列表
     * @param userDTO 当前登录用户
     * @param id 关联id
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveFiles(List<WorkAttachmentInfo> list, UserDTO userDTO, String id) {
        int j = 1;
        for (WorkAttachmentInfo dto : list) {
            WorkAttachmentInfo i = new WorkAttachmentInfo();
            //包含了url、size、name
            i.setId(UUID.randomUUID().toString().replace("-", ""));
//            i.getCreateBy().setId(userDTO.getId());
            i.setCreateTime(new Date());
//            i.getUpdateBy().setId(userDTO.getId());
            i.setUpdateTime(new Date());
            i.setDelFlag(0);
            i.setUrl(dto.getUrl());
            //文件类型处理
            List<String> strings = Arrays.asList(dto.getName().split("\\."));
            if (org.flowable.editor.language.json.converter.util.CollectionUtils.isNotEmpty(strings)) {
                i.setType(strings.get(1));
            }
            i.setAttachmentId(id);
            i.setAttachmentName(dto.getName());
            i.setAttachmentFlag("regular");
            i.setFileSize(dto.getSize());
            i.setSort(j);
//            ossServiceMapper.insertWorkAttachment(i, userDTO);
            Map<String,String> map = new HashMap<>();
            String workAttachment = JSON.toJSONString((i));
            String userDTOInfo = JSON.toJSONString((userDTO));
            map.put("workAttachment",workAttachment);
            map.put("userDTO",userDTOInfo);
            SpringUtil.getBean ( IWorkAttachmentApi.class ).insertWorkAttachment(map);
            j++;
        }
    }

    /**
     * 根据id修改转正状态
     * @param regularApply
     */
    public void updateStatusByApplyId(RegularApply regularApply) {
        staffUserInfoMapper.updateStatusByApplyId(regularApply.getId(),regularApply.getStatus());
    }

    /**
     * 获取试用期的所有人员信息
     * @return
     */
    public List<StaffUserInfoDTO> getList() {
        List<StaffUserInfoDTO> list=staffUserInfoMapper.getList();
        return list;
    }

    /**
     * 根据联系电话进行判重
     * @return
     */
    public boolean getByPhone(String mobilePhone) {
        List<StaffUserInfoDTO> userInfoDTO = staffUserInfoMapper.getByPhone(mobilePhone);
        if (CollectionUtils.isNotEmpty(userInfoDTO)){
            return true;
        }
        return false;
    }
}
