package jnpf.personnels.controller.web.employmentapply;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageInfo;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.v3.oas.annotations.Operation;
import jnpf.base.ActionResult;
import jnpf.base.entity.SuperBaseEntity;
import jnpf.base.vo.DownloadVO;
import jnpf.base.vo.PageListVO;
import jnpf.config.ConfigValueUtil;
import jnpf.enums.personnel.FtbPersonnelsCheckStatusCodeEnum;
import jnpf.model.personnels.bo.FtbRosterImportConstants;
import jnpf.model.personnels.dto.base.SourcePhone;
import jnpf.model.personnels.dto.oa.FtbPersonnelsEmployInfoForOA;
import jnpf.model.personnels.dto.roster.FtbRosterImportDTO;
import jnpf.model.personnels.dto.staff.employment.FtbPersonnelsEmployApplyDto;
import jnpf.model.personnels.dto.staff.employment.FtbPersonnelsStaffEmploymentApplyDto;
import jnpf.model.personnels.po.FtbPersonnelsRegistrationFormField;
import jnpf.model.personnels.po.FtbPersonnelsStaffEmploymentApply;
import jnpf.model.personnels.po.FtbPersonnelsStaffRegistrationFormData;
import jnpf.model.personnels.req.employment.AddStaffEmploymentApplyReq;
import jnpf.model.personnels.req.employment.AddStaffEmploymentApplyResultDto;
import jnpf.model.personnels.req.employment.BatchByPrimaryIdReq;
import jnpf.model.personnels.req.employment.EmploymentApplyCheckDto;
import jnpf.model.personnels.req.employment.MyWebEmploymentApplyCheckListReq;
import jnpf.model.personnels.req.employment.QueryStaffEmploymentApplyListReq;
import jnpf.model.personnels.req.roster.CheckOrgAndPosAndRankExistVo;
import jnpf.model.personnels.req.roster.ConfirmOnDutyReq;
import jnpf.model.personnels.vo.employment.CheckPhoneStatusVo;
import jnpf.permission.OrganizeApi;
import jnpf.permission.entity.OrganizeEntity;
import jnpf.permission.entity.PositionEntity;
import jnpf.permission.model.position.PositionGradesInfoVO;
import jnpf.personnels.FtbPersonnelsEmploymentApplyApi;
import jnpf.personnels.mapper.FtbPersonnelsRegistrationFormFieldMapper;
import jnpf.personnels.mapper.FtbPersonnelsStaffRegistrationFormDataMapper;
import jnpf.personnels.service.FtbPersonnelsStaffEmploymentApplyService;
import jnpf.personnels.service.FtbPersonnelsStaffRosterService;
import jnpf.personnels.utils.PersonalizedTenantWhitelistUtils;
import jnpf.personnels.utils.PersonnelOrgUtils;
import jnpf.util.FtbUtil;
import jnpf.util.NoDataSourceBind;
import jnpf.util.StringUtil;
import jnpf.util.excel.EasyExcelUtils;
import jnpf.yozo.utils.HttpRequestUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * web员工入职表模块
 *
 * @author xxxxx
 */
@RestController
@Slf4j
@RequestMapping("/web/personnels-staff-employment-apply")
@Deprecated(since = "人事v2.0")
public class FtbPersonnelsStaffEmploymentApplyController implements FtbPersonnelsEmploymentApplyApi {


    @Autowired
    private FtbPersonnelsStaffEmploymentApplyService staffEmploymentApplyService;

    @Autowired
    private FtbPersonnelsStaffRosterService staffRosterService;

    @Autowired
    private ConfigValueUtil configValueUtil;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private PersonnelOrgUtils personnelOrgUtils;

    @Resource
    FtbPersonnelsRegistrationFormFieldMapper fieldMapper;

    @Resource
    FtbPersonnelsStaffRegistrationFormDataMapper dataMapper;

    @Resource
    OrganizeApi organizeApi;

    @Autowired
    PersonalizedTenantWhitelistUtils personalizedTenantWhitelistUtils;


    /**
     * 预入职员工列表/入职审批列表
     *
     * @param req
     * @return {@link ActionResult}<{@link FtbPersonnelsStaffEmploymentApplyDto}>
     */
    @GetMapping("/query-list")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult<PageListVO<FtbPersonnelsStaffEmploymentApplyDto>> pageLists(@Validated QueryStaffEmploymentApplyListReq req) {
        PageInfo<FtbPersonnelsStaffEmploymentApplyDto> pageVo = staffEmploymentApplyService.getPageList(req);
        return ActionResult.page(pageVo.getList(), FtbUtil.getPagination(pageVo));
    }
    /**
     * 入职办理列表
     *
     */
    @GetMapping("/onboarding-list")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult<PageListVO<FtbPersonnelsEmployApplyDto>> onboardingList(@Validated QueryStaffEmploymentApplyListReq req) {
        PageListVO<FtbPersonnelsEmployApplyDto> pageVo = staffEmploymentApplyService.onboardingList(req);
        return ActionResult.success(pageVo);
    }
    /**
     * 入职办理列表-导出
     */
    @PostMapping("/onboarding-list-export")
    public void onboardingListExport(@RequestBody QueryStaffEmploymentApplyListReq req,HttpServletResponse response) throws IOException {
        req.setPageSize(-1);
        PageListVO<FtbPersonnelsEmployApplyDto> pageVo = staffEmploymentApplyService.onboardingList(req);
        List<FtbPersonnelsEmployApplyDto> list = pageVo.getList();
        list.forEach(item->{
            item.setSourceName(FtbPersonnelsEmployApplyDto.getSource(item.getSource()));
            item.setCheckStatusName(FtbPersonnelsEmployApplyDto.getCheckStatus(item.getCheckStatus()));
        });
        EasyExcelUtils.exportExcel(response, "入职办理列表", list, FtbPersonnelsEmployApplyDto.class);

    }

    /**
     * 我的审批（已审批/待审批）
     *
     * @param req
     * @return {@link ActionResult}<{@link FtbPersonnelsStaffEmploymentApplyDto}>
     */
    @GetMapping("/query-myCheck-list")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult<PageListVO<FtbPersonnelsStaffEmploymentApplyDto>> pageQueryMyCheckList(@Validated MyWebEmploymentApplyCheckListReq req) {
        PageInfo<FtbPersonnelsStaffEmploymentApplyDto> pageVo = staffEmploymentApplyService.getWebMyCheckList(req);
        return ActionResult.page(pageVo.getList(), FtbUtil.getPagination(pageVo));
    }


    /**
     * 办理入职
     *
     * @param req 入职参数
     * @return {@link ActionResult}<{@link String}>
     */
    @PostMapping("/handle-join-job")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult<String> handleJoinJob(@Validated @RequestBody AddStaffEmploymentApplyReq req) {
        String id = staffEmploymentApplyService.insertData(req);
        return ActionResult.success("成功", id);
    }
    /**
     * 办理入职(for oa)
     *
     * @param req 入职参数
     */
    @PostMapping("/handle-join-job-for-oa")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    @GlobalTransactional(rollbackFor = RuntimeException.class)
    public ActionResult<Void> handleJoinJobForOA(@Validated @RequestBody AddStaffEmploymentApplyReq req) {
        ActionResult<Void> map = staffEmploymentApplyService.handleJoinJobForOA(req);
        return map;
    }

    /**
     * 查询邀请码接口
     *
     * @return
     */
    @GetMapping("/query-code")
    public ActionResult<String> queryCode() {
        String code = staffEmploymentApplyService.queryCode();
        return ActionResult.success("成功", code);
    }

    /**
     * 获取员工入职记录详细信息
     *
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult<FtbPersonnelsStaffEmploymentApplyDto> get(@PathVariable("id") String id) {
        FtbPersonnelsStaffEmploymentApplyDto info = staffEmploymentApplyService.getInfo(id);
        return ActionResult.success(info);
    }


    /**
     * 删除员工入职记录
     *
     * @param id 主键id，必传
     * @return {@link ActionResult}
     */
    @DeleteMapping("/delete/{id}")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult delete(@PathVariable("id") String id) {
        staffEmploymentApplyService.deleteData(id);
        return ActionResult.success();
    }


    /**
     * 批量删除员工入职记录
     *
     * @param req
     * @return {@link ActionResult}
     */
    @DeleteMapping("/batch-delete")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult batchDelete(@RequestBody @Validated BatchByPrimaryIdReq req) {
        if (CollectionUtil.isEmpty(req.getIds())) {
            throw new IllegalArgumentException("参数错误");
        }
        staffEmploymentApplyService.deleteBatchData(req.getIds());
        return ActionResult.success();
    }


    /**
     * 检测校验组织/岗位/职级是否存在
     *
     * @param vo
     * @return
     * * 0：成功
     * * 1：失败：组织被删除
     * * 2：失败：岗位被删除
     * * 3：失败：职等被删除
     */
    @GetMapping("/checkOrgPositionRankExist")
    public ActionResult<Integer> checkOrgPositionRankExist(CheckOrgAndPosAndRankExistVo vo) {
        ConfirmOnDutyReq confirmOnDutyReq = BeanUtil.copyProperties(vo, ConfirmOnDutyReq.class);
        Integer checkStatus = checkOrgPositionRank(confirmOnDutyReq);
        return ActionResult.success(checkStatus);
    }

    /**
     * 确认到岗
     *
     * @param req 入职参数
     * @return {@link ActionResult}<{@link String}>
     */
    @PostMapping("/confirm-on-duty")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult<AddStaffEmploymentApplyResultDto> confirmOnDuty(@Validated @RequestBody ConfirmOnDutyReq req) {
        Integer checkStatus = checkOrgPositionRank(req);
        if (!checkStatus.equals(0)) {
            AddStaffEmploymentApplyResultDto dto = new AddStaffEmploymentApplyResultDto();
            dto.setId("");
            dto.setStatus(checkStatus);
            return ActionResult.success("成功", dto);
        }
        String lockKey = "ConfirmOnDuty:" + req.getPhone();
        if (redisTemplate.opsForValue().setIfAbsent(lockKey, "1", 10, TimeUnit.SECONDS)) {
            try {
                String id = staffRosterService.confirmOnDuty(req);
                AddStaffEmploymentApplyResultDto dto = new AddStaffEmploymentApplyResultDto();
                dto.setId(id);
                dto.setStatus(0);
                return ActionResult.success("成功", dto);
            } catch (Exception e) {
                log.error("确认到岗失败", e);
                return ActionResult.fail(e.getMessage());
            } finally {
               redisTemplate.delete(lockKey);
            }
        } else {
            throw new RuntimeException("提交中,请稍候");
        }
    }

    private Integer checkOrgPositionRank(ConfirmOnDutyReq req) {
        OrganizeEntity organizeEntity = personnelOrgUtils.queryOrganizeInfo(req.getCurrOrg());
        if (null == organizeEntity) {
            return 1;
        }
        PositionEntity positionEntity = personnelOrgUtils.queryPosition(req.getCurrPosition());
        if (null == positionEntity) {
            return 2;
        }
        PositionGradesInfoVO positionGradesInfoVO = personnelOrgUtils.queryRank(req.getCurrRank());
        if (null == positionGradesInfoVO) {
            return 3;
        }
        return 0;
    }
    /**
     * 审批
     *
     * @param id 主键id，必传
     * @return
     */

    @PutMapping("/approval/{id}")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult approval(@PathVariable("id") String id, @RequestBody EmploymentApplyCheckDto dto) {
        dto.setId(id);
        staffEmploymentApplyService.approval( dto);
        return ActionResult.success();
    }

    /**
     * 审批 (for oa)
     *
     * @return
     */
    @PostMapping("/approval/id")
    public  ActionResult<Void> approvalForOA( @RequestBody EmploymentApplyCheckDto dto) {
        ActionResult<Void> map = staffEmploymentApplyService.approvalForOA(dto);
        return map;
    }


    /**
     * 重新办理
     *
     * @param id 主键id，必传
     * @return
     */

    @PutMapping("/re-approval/{id}")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult reApproval(@PathVariable("id") String id, @RequestBody AddStaffEmploymentApplyReq dto) {
        staffEmploymentApplyService.reApproval(id, dto);
        return ActionResult.success();
    }


    /**
     * 模版下载
     *
     * @return
     */
    @GetMapping("/download/template")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult<DownloadVO> templateDownload() {
        DownloadVO vo = DownloadVO.builder().build();
        try {
            vo.setName("预办理入职员工导出导入模板.xlsx");
            vo.setUrl("https://jnpf-resource-1304460613.cos.ap-chengdu.myqcloud.com/xgl/%E9%A2%84%E5%8A%9E%E7%90%86%E5%85%A5%E8%81%8C%E5%91%98%E5%B7%A5%E5%AF%BC%E5%87%BA%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx");
        } catch (Exception e) {
            log.error("下载模板错误:" + e.getMessage());
        }
        return ActionResult.success(vo);
    }


    /**
     * 导入
     *
     * @param file
     * @return
     */
    @PostMapping("/importData")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult<Object> importData(@RequestBody @Validated FtbRosterImportDTO file) {
        Map<String, Object> stringObjectMap;
        try (InputStream inputStream = EasyExcelUtils.checkExcelFile(file.getFileUrl())) {
            stringObjectMap = staffEmploymentApplyService.importData(inputStream);
        } catch (Exception e) {
            return ActionResult.fail(e.getMessage());
        }
        return ActionResult.success(stringObjectMap);
    }

    /**
     * 测试导入
     *
     * @param file
     * @return
     */
    @PostMapping("/importDataFile")
    public ActionResult<Object> importData(@RequestBody MultipartFile file) {
        Map<String, Object> stringObjectMap;
        try (InputStream inputStream = file.getInputStream()) {
            stringObjectMap = staffEmploymentApplyService.importData(inputStream);
        } catch (Exception e) {
            return ActionResult.fail(e.getMessage());
        }
        return ActionResult.success(stringObjectMap);
    }


    /**
     * 导入点击
     */
    @GetMapping("/importData/click")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult<Object> importDataClick() {
        staffEmploymentApplyService.importDataClick();
        return ActionResult.success();
    }

    /**
     * 导出错误数据
     */
    @GetMapping("/exportErrDate")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public void exportErrData(HttpServletResponse response) {
        staffEmploymentApplyService.exportErrData(response);
    }

    /**
     * 根据列表导出列表数据
     */
    @PostMapping("/exportDate")
    @Deprecated(since = "人事v1.2", forRemoval = true)
    public void exportDate(@RequestBody @Validated BatchByPrimaryIdReq req, HttpServletResponse response) {
        staffEmploymentApplyService.exportDate(req, response);
    }

    /**
     * 预入职列表导出全部数据
     */
    @GetMapping("/exportDate-new")
    public void exportDateNew(QueryStaffEmploymentApplyListReq req, HttpServletResponse response) throws IOException {
        staffEmploymentApplyService.exportDateNew(req, response);
    }

    /**
     * 办理入职发送短信
     *
     * @param phone 主键id，必传
     * @return
     */
    @PutMapping("/send-phone-msg/{phone}")
    @Deprecated(since = "人事v1.3", forRemoval = true)
    public ActionResult sendPhoneMsg(@PathVariable("phone") String phone) {
        staffEmploymentApplyService.sendPhoneMsg(phone);
        return ActionResult.success("发送成功");
    }


    /**
     * 修改入职状态
     *
     * @return
     */
    @Override
    @NoDataSourceBind
    @GetMapping("/updateEmploymentApplyStatus")
    @Deprecated(since = "v2.0废弃",forRemoval= true)
    public ActionResult updateEmploymentApplyStatus(@RequestParam("tenantId") String tenantId) {
//
//        // 判断是否为多租户
//        if (configValueUtil.isMultiTenancy()) {
//            // 判断是不是从外面直接请求
//            if (StringUtil.isNotEmpty(tenantId)) {
//                //切换成租户库
//                try {
//                    TenantDataSourceUtil.switchTenant(tenantId);
//                } catch (LoginException e) {
//                    throw new RuntimeException("切换租户失败");
//                }
//            } else {
//                UserInfo userInfo = UserProvider.getUser();
//                Assert.notNull(userInfo.getUserId(), "缺少租户信息");
//                DataSourceContextHolder.setDatasource(userInfo.getTenantId(), userInfo.getTenantDbConnectionString(), userInfo.isAssignDataSource());
//            }
//        }
//        //修改用户入职状态
//        staffEmploymentApplyService.updateEmploymentApplyStatus();

        return ActionResult.success();
    }

    /**
     * 办理入职,检测用户在系统中的状态
     * 0、系统不存在该用户  1、该手机号等待入职 2、该手机号等待入职审批  302、试用 303、正式  304、待离职  305 离职
     *
     * @param phone 手机号
     * @return
     */
    @GetMapping("/check-phone-status/{phone}")
    public ActionResult<CheckPhoneStatusVo> checkPhoneStatus(@PathVariable("phone") String phone) {
        String status = staffEmploymentApplyService.checkPhoneStatus(phone);
        CheckPhoneStatusVo vo = new CheckPhoneStatusVo();
        vo.setStatus(status);
        return ActionResult.success(vo);
    }
    /**
     * 办理入职,检测用户在系统中的状态
     * 0、系统不存在该用户  1、该手机号等待入职 2、该手机号等待入职审批  302、试用 303、正式  304、待离职  305 离职 306 试岗
     *
     * @param phone 手机号
     * @return
     */
    @GetMapping("/check-phone-status")
    public ActionResult<Void> checkPhoneStatusWithId(@RequestParam("phone") String phone,@RequestParam("name") String name) {
        SourcePhone sourcePhone = JSONObject.parseObject(phone, SourcePhone.class);
        String status = staffEmploymentApplyService.checkPhoneStatus(sourcePhone.getPhone());
        ActionResult<Void> result = new ActionResult<>();
        if ("1".equals(status)){
            result.setMsg( "该手机号等待入职");
            result.setCode(FtbPersonnelsCheckStatusCodeEnum.CHECK_REFUSE.getCode());
            return result;
        }else if ("2".equals(status)){
            result.setMsg( "该手机号等待入职审批");
            result.setCode(FtbPersonnelsCheckStatusCodeEnum.CHECK_REFUSE.getCode());
            return result;
        }else if ("302".equals(status) || "303".equals(status) || "304".equals(status) || "306".equals(status)){
            result.setMsg( "该员工已经到岗，请勿重复操作");
            result.setCode(FtbPersonnelsCheckStatusCodeEnum.CHECK_REFUSE.getCode());
            return result;
        }
        // 校验前后是否有空格
        Pattern spacesCheck = Pattern.compile(FtbRosterImportConstants.NAME_REGEX);
        Matcher spacesCheckMatcher = spacesCheck.matcher(name);
        if (!spacesCheckMatcher.matches()){
            result.setCode(FtbPersonnelsCheckStatusCodeEnum.CHECK_REFUSE.getCode());
            result.setMsg("请使用标准格式的中文名或英文名!");
            return  result;
        }
        return ActionResult.success();
    }
    @Operation(summary = "[校验]该岗位是否入职列表是否有人使用, 有则阻塞")
    @GetMapping("/verify/user_bound")
    public ActionResult<String> verifyUserBound(@RequestParam(required = false, name = "positionId") String positionId,
                                                @RequestParam(required = false, name = "positionGradesId") String positionGradesId) {
        staffEmploymentApplyService.verifyUserBound(positionId, positionGradesId);
        return ActionResult.success();
    }

    /**
     *  入职办理列表查询 ForOA 回显 姓名 手机
     */
    @GetMapping("/inquire-about-the-entry-list")
    public ActionResult<List<FtbPersonnelsEmployInfoForOA>> inquireAboutTheEntryList(@RequestParam(required = false, name = "keyWords") String keyWords,
                                                                                     @RequestParam(required = false,name =  "phone")String phone,
                                                                                     @RequestParam(required = false,name =  "workerName")String workerName) {
        LambdaQueryWrapper<FtbPersonnelsStaffEmploymentApply> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(FtbPersonnelsStaffEmploymentApply::getCheckStatus,0,3);
        queryWrapper.eq(FtbPersonnelsStaffEmploymentApply::getIsNeedCheck,0);
        queryWrapper.like(StringUtil.isNotEmpty(keyWords), FtbPersonnelsStaffEmploymentApply::getWorkerName,keyWords);
        queryWrapper.eq(HttpRequestUtils.StringUtils.isNotEmpty(phone),FtbPersonnelsStaffEmploymentApply::getPhone,phone);
        queryWrapper.eq(HttpRequestUtils.StringUtils.isNotEmpty(workerName),FtbPersonnelsStaffEmploymentApply::getWorkerName,workerName);
        queryWrapper.orderByDesc(SuperBaseEntity.SuperCBaseEntity::getCreatorTime);
        List<FtbPersonnelsStaffEmploymentApply> list = staffEmploymentApplyService.list(queryWrapper);
        Boolean itOnTheWhitelist = personalizedTenantWhitelistUtils.isItOnTheWhitelist();
        if (!itOnTheWhitelist){
            List<FtbPersonnelsEmployInfoForOA> infoForOAS = list.stream().map(FtbPersonnelsEmployInfoForOA::covert).collect(Collectors.toList());
            return ActionResult.success(infoForOAS);
        }
        // 租户扩展
        LambdaQueryWrapper<FtbPersonnelsRegistrationFormField> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(FtbPersonnelsRegistrationFormField::getEnabledMark,0);
        wrapper.eq(FtbPersonnelsRegistrationFormField::getStatus,0);
        wrapper.eq(FtbPersonnelsRegistrationFormField::getName,"意向组织");
        FtbPersonnelsRegistrationFormField field = fieldMapper.selectOne(wrapper);
        List<String> phoneList = list.stream().map(FtbPersonnelsStaffEmploymentApply::getPhone).collect(Collectors.toList());
        if (CollectionUtil.isEmpty(phoneList)){
            List<FtbPersonnelsEmployInfoForOA> infoForOAS = list.stream().map(FtbPersonnelsEmployInfoForOA::covert).collect(Collectors.toList());
            return ActionResult.success(infoForOAS);
        }
        LambdaQueryWrapper<FtbPersonnelsStaffRegistrationFormData> registrationFormDataLambdaQueryWrapper = Wrappers.lambdaQuery();
        registrationFormDataLambdaQueryWrapper.eq(FtbPersonnelsStaffRegistrationFormData::getFormFieldId,field.getId());
        registrationFormDataLambdaQueryWrapper.in(FtbPersonnelsStaffRegistrationFormData::getPhone, phoneList);
        List<FtbPersonnelsStaffRegistrationFormData> formData = dataMapper.selectList(registrationFormDataLambdaQueryWrapper);
        Map<String, String> phoneMap = formData.stream().filter(vo->vo.getPhone() !=null).collect(Collectors.toMap(FtbPersonnelsStaffRegistrationFormData::getPhone, FtbPersonnelsStaffRegistrationFormData::getValue));
        List<String> orgIds = new ArrayList<>(phoneMap.values());
        List<OrganizeEntity> organizeName = organizeApi.getOrganizeName(orgIds);
        Map<String, String> orgMap = organizeName.stream().collect(Collectors.toMap(OrganizeEntity::getId, OrganizeEntity::getFullName));
        List<FtbPersonnelsEmployInfoForOA> infoForOAS = list.stream().map(item->{
            FtbPersonnelsEmployInfoForOA covered = FtbPersonnelsEmployInfoForOA.covert(item);
            if (phoneMap.containsKey(covered.getPhone()) && orgMap.containsKey(phoneMap.get(covered.getPhone()))){
                String orgName = orgMap.get( phoneMap.get(covered.getPhone()));
                String name = covered.getName() + "-意向组织:" + orgName;
                covered.setName(name);
            }
            return covered;
        }).collect(Collectors.toList());
        return ActionResult.success(infoForOAS);
    }
}
