package jnpf.personnels.controller.web.roster;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fantaibao.permission.annotation.FtbCheckPermission;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import jnpf.base.ActionResult;
import jnpf.base.UserInfo;
import jnpf.base.vo.PageListVO;
import jnpf.config.ConfigValueUtil;
import jnpf.cultivate.service.FtbCultivatePositionForAppService;
import jnpf.database.util.TenantDataSourceUtil;
import jnpf.exception.LoginException;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.cultivate.dto.position.app.FtbCultivatePositionForAppNewDTO;
import jnpf.model.cultivate.resp.CanDeleteMsg;
import jnpf.model.cultivate.vo.identify.IdentifyApplyInfoApiVo;
import jnpf.model.cultivate.vo.position.app.FtbSubordinateLearningCoursesVO;
import jnpf.model.cultivate.vo.promotion.FtbCultivatePromotionWithPersonelVO;
import jnpf.model.personnels.bo.FtbRosterImportTemplateBO;
import jnpf.model.personnels.dto.roster.QueryCompanyAgeDto;
import jnpf.model.personnels.dto.staff.employment.FtbPersonnelsStaffEmploymentApplyDto;
import jnpf.model.personnels.dto.staff.roster.*;
import jnpf.model.personnels.po.FtbPersonnelsStaffRoster;
import jnpf.model.personnels.req.employment.BatchByPrimaryIdReq;
import jnpf.model.personnels.req.roster.StaffRosterListExportReq;
import jnpf.model.personnels.req.roster.StaffRosterListReq;
import jnpf.model.personnels.req.roster.StaffRosterReq;
import jnpf.permission.dto.QueryUserListDTO;
import jnpf.permission.model.user.UserListVO;
import jnpf.permission.model.user.UserQueryDto;
import jnpf.permission.vo.user.UserListMatchVO;
import jnpf.permission.vo.v2.user.UserPageListVO;
import jnpf.personnels.FtbPersonnelsRosterManagerApi;
import jnpf.personnels.service.FtbPersonnelsStaffRosterService;
import jnpf.util.FtbUtil;
import jnpf.util.NoDataSourceBind;
import jnpf.util.StringUtil;
import jnpf.util.UserProvider;
import jnpf.util.data.DataSourceContextHolder;
import jnpf.util.excel.EasyExcelUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * web员工花名册模块
 *
 * @author xxxxx
 */
@RestController
@Slf4j
@RequestMapping("/web/personnels-staff-roster")
public class FtbPersonnelsStaffRosterController implements FtbPersonnelsRosterManagerApi {
    @Autowired
    private FtbPersonnelsStaffRosterService staffRosterService;


    @Autowired
    private ConfigValueUtil configValueUtil;

    @Resource
    FtbCultivatePositionForAppService positionForAppService;

    /**
     * 花名册查询列表
     *
     * @param req
     * @return {@link ActionResult}<{@link FtbPersonnelsStaffEmploymentApplyDto}>
     */
    @GetMapping("/query-list")
    public ActionResult<PageListVO<FtbPersonnelsStaffRosterDto>> pageLists(@Validated StaffRosterListReq req) {            // 记录开始时间
        PageInfo<FtbPersonnelsStaffRosterDto> pageVo = staffRosterService.getPageList(req, false);
        return ActionResult.page(pageVo.getList(), FtbUtil.getPagination(pageVo));
    }

    /**
     * 花名册查询列表 _post
     *
     * @param req
     * @return {@link ActionResult}<{@link FtbPersonnelsStaffEmploymentApplyDto}>
     */
    @PostMapping("/query-list/post")
    @FtbCheckPermission("employeeRoster")
    public ActionResult<PageListVO<FtbPersonnelsStaffRosterDto>> pageListsPost(@Validated @RequestBody StaffRosterListReq req) {
        long startTime = System.currentTimeMillis();

        PageInfo<FtbPersonnelsStaffRosterDto> pageVo = staffRosterService.getPageList(req, false);

        // 记录结束时间
        long endTime = System.currentTimeMillis();
        // 计算执行时间
        long executionTime = endTime - startTime;
        // 打印执行时间
        System.out.println("Execution time: " + executionTime + " milliseconds");

        return ActionResult.page(pageVo.getList(), FtbUtil.getPagination(pageVo));
    }

    /**
     * 花名册查询列表 postWithSalary
     *
     * @param req
     * @return {@link ActionResult}<{@link FtbPersonnelsStaffEmploymentApplyDto}>
     */
    @PostMapping("/query-list/postWithSalary")
    public ActionResult<PageListVO<FtbPersonnelsStaffRosterDto>> postWithSalary(@Validated @RequestBody StaffRosterListReq req) {
        PageInfo<FtbPersonnelsStaffRosterDto> pageVo = staffRosterService.postWithSalary(req);
        return ActionResult.page(pageVo.getList(), FtbUtil.getPagination(pageVo));
    }


    @PostMapping("/query-list/post-with-salary-no-page")
    public List<FtbPersonnelsStaffRosterDto> postWithSalaryNoPage(@Validated @RequestBody StaffRosterListReq req) {
        try {
            return staffRosterService.postWithSalaryNoPage(req);
        } catch (Exception e) {
            log.error("查询花名册权限异常 :{}", e.getMessage());
            return new ArrayList<>();
        }
    }

    /**
     * 花名册列表查询-无权限
     * @param req
     * @return ActionResult<FtbPersonnelsStaffRosterDto>
     */
    @PostMapping("/query-list/byUserIds")
    @Override
    public ActionResult<List<FtbPersonnelsStaffRosterDto>> getPersonnelByUserIds(@RequestBody StaffRosterListReq req) {
        List<FtbPersonnelsStaffRosterDto> personnelUserList = staffRosterService.getPersonnelUserList(req);
        return ActionResult.success(personnelUserList);
    }

    /**
     * 获取员工花名册详情
     *
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public ActionResult<FtbPersonnelsStaffRosterDto> get(@PathVariable("id") String id) {
        FtbPersonnelsStaffRosterDto info = staffRosterService.getInfo(id);
        return ActionResult.success(info);
    }

    /**
     * 获取员工花名册详情（参数）
     *
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/getInfo")
    public ActionResult<StaffHomeDto> getInfo(@RequestParam("userId") String userId) {
        StaffHomeDto info = staffRosterService.queryWorkerHomeDetail(userId);
        return ActionResult.success(info);
    }

    /**
     * 获取员工花名册详情(数组查询第一个)
     *
     * @param userIds 用户ID
     * @return
     */
    @GetMapping("/getInfoForListOne")
    public ActionResult<StaffHomeDto> getInfoForListOne(@RequestParam("userIds") String userIds) {

        StaffHomeDto info = staffRosterService.queryWorkerHomeDetail(userIds);
        return ActionResult.success(info);
    }


    /**
     * 查询员工信息（返回指定字段相关字段）
     *
     * @param userIds 用户ID
     * @return
     */
    @GetMapping("/getInfoForUserIdOneField")
    public ActionResult<Map<String,Object>> getInfoForUserIdOneField(@RequestParam("field") String field, @RequestParam("userIds") String userIds) {

        Map<String,Object> info = staffRosterService.getInfoForUserIdOneField(field,userIds);
        return ActionResult.success(info);
    }

    /**
     * 从花名册中批量删除
     *
     * @param req
     * @return {@link ActionResult}
     */
    @DeleteMapping("/batch-delete")
    public ActionResult batchDelete(@RequestBody @Validated BatchByPrimaryIdReq req) {
        if (CollectionUtil.isEmpty(req.getIds())) {
            throw new IllegalArgumentException("参数错误");
        }
        long controllerStart = System.currentTimeMillis();
        staffRosterService.deleteBatchData(req.getIds());
        long controllerEnd = System.currentTimeMillis();
        log.error("花名册批量删除(batch-delete) 控制层调用deleteBatchData 条数={} 耗时={}ms",
                req.getIds().size(), controllerEnd - controllerStart);
        return ActionResult.success();
    }


    /**
     * 检测花名册是否可以删除
     *
     * @param req
     * @return {@link ActionResult}
     */
    @PostMapping("/check-batch-delete")
    public ActionResult<List<CheckRosterDeleteVo>> checkBatchDelete(@RequestBody @Validated BatchByPrimaryIdReq req) {
        CanDeleteMsg dto = staffRosterService.checkBatchDelete(req.getIds());
        List<CheckRosterDeleteVo> dtoData = (List<CheckRosterDeleteVo>) dto.getData();
        return ActionResult.success(dtoData);
    }


    /**
     * 查询员工主页信息
     *
     * @param userId 手机号
     * @return
     */
    @GetMapping("/worker-home-detail/{userId}")
    public ActionResult<StaffHomeDto> queryWorkerHomeDetail(@PathVariable("userId") String userId) {
        StaffHomeDto info = staffRosterService.queryWorkerHomeDetail(userId);
        return ActionResult.success(info);
    }


    /**
     * 花名册员工数量统计
     *
     * @return
     */
    @GetMapping("/worker-number/statistics")
    public ActionResult<WorkerStatisticsDto> statisticsWorkerNumber() {

        return ActionResult.success(staffRosterService.statisticsWorkerNumber());
    }

    /**
     * 花名册用户数据导出
     *
     * @param req
     * @param response
     * @return
     * @throws IOException
     */
    @PostMapping("/roster-export")
    public void exportToExcel(@RequestBody StaffRosterListExportReq req, HttpServletResponse response) throws IOException {
        // 导出全部
        if (CollUtil.isEmpty(req.getIds())) {
            req.setPageSize(Integer.MAX_VALUE);
            PageInfo<FtbPersonnelsStaffRosterDto> pageList = staffRosterService.getPageList(req, true);
            List<String> rosterIds = pageList.getList().stream().map(FtbPersonnelsStaffRosterDto::getId).collect(Collectors.toList());
            req.setIds(rosterIds);
        }
        //查询数据
        List<FtbRosterImportTemplateBO> dataList = staffRosterService.queryRosterInfoByIds(req.getIds(), req.getFormFieldOptionIds(),null);
        EasyExcelUtils.dynamicHeaderGenerationRoster(response, "花名册数据导出", dataList);
    }

    /**
     * 花名册用户数据自定义方案导出
     *
     * @param req
     * @param response
     * @return
     * @throws IOException
     */
    @PostMapping("/roster-export-scheme")
    public void exportToExcelScheme(@RequestBody StaffRosterListExportReq req, HttpServletResponse response) throws IOException {
        if (StrUtil.isEmpty(req.getSchemeId())) {
            throw new IllegalArgumentException("请选择导出方案");
        }
        // 导出全部
        if (CollUtil.isEmpty(req.getIds())) {
            req.setPageSize(Integer.MAX_VALUE);
            PageInfo<FtbPersonnelsStaffRosterDto> pageList = staffRosterService.getPageList(req, true);
            List<String> rosterIds = pageList.getList().stream().map(FtbPersonnelsStaffRosterDto::getId).collect(Collectors.toList());
            req.setIds(rosterIds);
        }
        //查询数据
        List<FtbRosterImportTemplateBO> dataList = staffRosterService.queryRosterInfoByIds(req.getIds(), req.getFormFieldOptionIds(),req.getSchemeId());
        EasyExcelUtils.dynamicHeaderGeneration(response, "花名册数据导出", dataList);
    }

    /**
     * 检测当前登录用户是不是档案管理员
     *
     * @return {@link ActionResult}<{@link String}>
     */
    @GetMapping("/check-my-is-archive-manager")
    public ActionResult<Boolean> checkMyIsArchiveManager() {
        Boolean isManager = staffRosterService.checkCurrLoginUserArchiveManager();
        return ActionResult.success("成功", isManager);
    }

    /**
     * 检测当前花名册处于流程中【调岗、转正、离职】
     *
     * @param id 花名册ID
     * @return 0、无流程  ,1转正 2,调岗, 3离职, 4晋升
     */
    @GetMapping("/check-roster-run-task/{id}")
    public ActionResult<Integer> checksItInTheReviewProcess(@PathVariable("id") String id) {
        String loginUserId = UserProvider.getLoginUserId();
        Integer ty = staffRosterService.checksItInTheReviewProcess(id);
        return ActionResult.success("成功", ty);
    }


    /**
     * 定时任务修改员工司年龄
     *
     * @return
     */
    @Override
    @NoDataSourceBind
    @GetMapping("/updateCompanyAge")
    public ActionResult updateCompanyAge(@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());
            }
        }

        //检测健康证到期，发送短信
        staffRosterService.updateCompanyAge();
        //修改试岗结束
        staffRosterService.timingUpdateTrialJob(tenantId);
        //staffRosterService.updateWorkerAge();
        return ActionResult.success();
    }

    /**
     * 查询直属主管
     *
     * @param dto
     * @return
     */
    @GetMapping("/queryAllUserForOrgAndStatus")
    public ActionResult<List<UserPageListVO>> getAllUser(QueryUserListDTO dto) {
        List<UserPageListVO> list = staffRosterService.queryAllUserForOrgAndStatus(dto);
        return ActionResult.success("成功", list);
    }

    /**
     * 定时任务发动消息
     *
     * @param tenantId
     * @return
     */
    @NoDataSourceBind
    @GetMapping("/timingAlertTrialJob/{tenantId}")
    @Deprecated(since = "人事2.1废弃试岗状态")
    public ActionResult<List<UserListVO>> timingAlertTrialJob(@PathVariable("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());
            }
        }
        //staffRosterService.timingAlertTrialJob(tenantId);
        return ActionResult.success("成功");
    }

    /**
     * 修改员工司年龄
     *
     * @return
     */
    @NoDataSourceBind
    @PostMapping("/queryCompanyAge/{tenantId}")
    public ActionResult<List<QueryCompanyAgeDto>> queryCompanyAge(@RequestBody List<String> userIds, @PathVariable("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());
            }
        }

        //检测健康证到期，发送短信
        List<QueryCompanyAgeDto> list = staffRosterService.queryCompanyAge(userIds);
        return ActionResult.success("成功", list);
    }

    /**
     * 绑定手机号
     *
     * @param userId 用户ID
     * @param phone  手机号
     * @return
     */
    @Override
    @PostMapping("/bindPhone")
    @NoDataSourceBind
    public ActionResult<Boolean> bindPhone(@RequestParam("tenantCode") String tenantCode, @RequestParam("userId") String userId, @RequestParam("phone") String phone) {

        // 判断是否为多租户
        if (configValueUtil.isMultiTenancy()) {
            // 判断是不是从外面直接请求
            if (StringUtil.isNotEmpty(tenantCode)) {
                //切换成租户库
                try {
                    TenantDataSourceUtil.switchTenant(tenantCode);
                } catch (LoginException e) {
                    throw new RuntimeException("切换租户失败");
                }
            } else {
                UserInfo userInfo = UserProvider.getUser();
                Assert.notNull(userInfo.getUserId(), "缺少租户信息");
                DataSourceContextHolder.setDatasource(userInfo.getTenantId(), userInfo.getTenantDbConnectionString(), userInfo.isAssignDataSource());
            }
        }

        Boolean result = staffRosterService.bindPhone(userId, phone);
        return ActionResult.success("成功", result);
    }

    /**
     * 查看培训数据
     * 培训v1.1
     */
    @GetMapping("/queryTrainData")
    public ActionResult<FtbCultivatePromotionWithPersonelVO> queryTrainData(@RequestParam("userId") String userId,
                                                                            @RequestParam("postId") String postId) {
        FtbCultivatePromotionWithPersonelVO info = staffRosterService.queryTrainData(userId, postId);
        return ActionResult.success("成功", info);
    }

    /**
     * 查看课程培训数据(培训v1.1)
     */
    @GetMapping("/queryCourseTrainDataDetail")
    public ActionResult<PageListVO<FtbSubordinateLearningCoursesVO>> queryCourseTrainDataDetail(FtbCultivatePositionForAppNewDTO dto,
                                                                                                CultivatePage page) {
        Page<FtbSubordinateLearningCoursesVO> result = page.coverCultivatePage();
        result = positionForAppService.subordinateLearningCourses(dto, result);
        return ActionResult.success(CultivatePage.coverPageList(result));
    }


    /**
     * 查看鉴定培训数据(培训v1.1)
     */
    @GetMapping("/queryIdentityTrainDataDetail")
    public ActionResult<PageListVO<IdentifyApplyInfoApiVo>> queryIdentityTrainDataDetail(FtbCultivatePositionForAppNewDTO dto,
                                                                                         CultivatePage page) {
        PageListVO<IdentifyApplyInfoApiVo> result = positionForAppService.queryIdentityTrainDataDetail(dto, page);
        return ActionResult.success(result);
    }

    /**
     * 查询未提交入职登记表的用户
     *
     * @param tenantId
     * @return
     */
    @NoDataSourceBind
    @GetMapping("/queryNoSubmitForm")
    public ActionResult<List<StaffRosterInfoDto>> queryNoSubmitForm(@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());
            }
        }

        //检测健康证到期，发送短信
        List<StaffRosterInfoDto> list = staffRosterService.queryNoSubmitForm();
        return ActionResult.success("成功", list);
    }

    /**
     * 查询健康证到期的用户
     *
     * @param tenantId
     * @return
     */
    @NoDataSourceBind
    @GetMapping("/queryHealthExpire")
    public ActionResult<List<StaffRosterInfoDto>> queryHealthExpire(@RequestParam("tenantId") String tenantId, @RequestParam(value = "days", required = false) Long days, @RequestParam(value = "months", required = false) Long months) {

        // 判断是否为多租户
        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());
            }
        }

        //检测健康证到期，发送短信
        List<StaffRosterInfoDto> list = staffRosterService.queryHealthExpire(days, months);
        return ActionResult.success("成功", list);
    }

    /**
     * 查询公司所有用户(分页)
     *
     * @param queryDto 查询条件
     * @return jnpf.base.ActionResult<jnpf.permission.model.user.PartUserInfoVo>
     */
    @GetMapping(value = "/userInfo/page")
    public ActionResult<PageListVO<PartUserInfoVoAndWorkerNo>> getPartUserInfoPage(UserQueryDto queryDto) {
        return staffRosterService.getPartUserInfoPage(queryDto);
    }

    /**
     * 发送登记表填写邀请系统消息
     *
     * @param userId 目标用户
     * @return 执行位置
     */
    @GetMapping("/invitation/send/{userId}")
    public ActionResult<Boolean> sendInvitationInformation(@PathVariable("userId") String userId) {

        return ActionResult.success(staffRosterService.sendInvitationInformation(userId));
    }

    @Operation(summary = "[匹配]-指定user们哪些存在,哪些不存在, 包含花名册离职的用户")
    @PostMapping("/user/list/match/ids")
    public ActionResult<UserListMatchVO> getUserListByMatch(@RequestBody List<String> userIds){

        return ActionResult.success((staffRosterService.getUserListByMatch(userIds)));
    }
    /**
     * 查询离职人员信息
     *
     * @return
     */
    @PostMapping("/queryDepartUser")
    public ActionResult<List<FtbPersonnelsStaffRosterDto>> queryDepartUser(@RequestBody List<String> userIds) {
        if (CollectionUtil.isEmpty(userIds)) {
            return ActionResult.success("成功", new ArrayList<>());
        }
        List<FtbPersonnelsStaffRosterDto> list = staffRosterService.queryDepartUser(userIds);
        return ActionResult.success("成功", list);
    }

    /**
     * 根据用户ID查询所属门店负责人信息
     *
     * @param tenantId
     * @param userIds  用户ID
     * @return
     */
    @NoDataSourceBind
    @PostMapping("/queryShopManagerUser/{tenantId}")
    public ActionResult<ShopManagerUserDto> queryShopManagerUser(@PathVariable("tenantId") String tenantId, @RequestBody List<String> userIds) {
        // 判断是否为多租户
        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());
            }
        }


        ShopManagerUserDto dto = staffRosterService.queryShopManagerUser(userIds);
        log.error("userIds={},dto={}", JSONUtil.toJsonStr(userIds),JSONUtil.toJsonStr(dto));
        return ActionResult.success("成功", dto);
    }



    /**
     * 修改用户离职证明是否签署
     * @param userId 用户ID
     * @param status 签署状态 0-未签署 1-已签署
     * @return
     */
    @PutMapping("/updateSignSeparation/{userId}/{status}")
    public ActionResult updateSignSeparation(@PathVariable("userId") String userId,@PathVariable("status") Integer status) {
        staffRosterService.updateSignSeparation(userId, status);
        return ActionResult.success();
    }

    /**
     * 查询用户离职证明是否签署
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/querySignSeparation/{userId}")
    public ActionResult<Integer> querySignSeparation(@PathVariable("userId") String userId) {
        FtbPersonnelsStaffRoster roster = staffRosterService.queryRosterInfoByUserId(userId);
        if(null==roster){
            throw new RuntimeException("用户信息不存在");
        }
        return ActionResult.success(roster.getIsSignSeparation());
    }

    /**
     * 根据用户ID查询用户信息
     * @param req
     * @return
     */
    @PostMapping("/queryWithUserIds")
    public List<FtbPersonnelsStaffRosterDto> queryWithUserIds( @RequestBody StaffRosterListReq req){
        return staffRosterService.queryWithUserIds(req);
    }

    @PostMapping("/queryWithUserIds/post")
    public List<FtbPersonnelsStaffRosterDto> queryWithUserIdsPost( @RequestBody  StaffRosterReq req) {
        return staffRosterService.queryWithUserIdsPost(req);
    }

}
