package jnpf.personnels.controller.app.roster;

import cn.hutool.json.JSONUtil;
import jnpf.base.ActionResult;
import jnpf.model.personnels.dto.staff.field.FormTypeDto;
import jnpf.model.personnels.dto.staff.growth.FtbPersonnelsStaffGrowthLogDto;
import jnpf.model.personnels.vo.roster.FtbPersonnelsStaffArchivesHistoryVo;
import jnpf.personnels.service.FtbPersonnelsStaffArchivesHistoryService;
import jnpf.personnels.service.FtbPersonnelsStaffGrowthLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * App离职员工档案信息模块
 *
 * @author xxxxx
 */
@RestController
@Slf4j
@RequestMapping("/app/personnelsStaffArchivesHistory")
public class AppPersonnelsStaffArchivesHistoryController {

    @Autowired
    private FtbPersonnelsStaffGrowthLogService growthLogService;

    @Autowired
    private FtbPersonnelsStaffArchivesHistoryService archivesHistoryService;

    /**
     * 查询离职档案信息
     *
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/get/{userId}")
    public ActionResult<List<FormTypeDto>> get(@PathVariable("userId") String userId) {
        FtbPersonnelsStaffArchivesHistoryVo info = archivesHistoryService.getInfo(userId);
        if (null != info && StringUtils.isNotEmpty(info.getArchives())) {
            List<FormTypeDto> list = JSONUtil.toList(info.getArchives(), FormTypeDto.class);
            return ActionResult.success(list);
        }
        return ActionResult.fail("未查询到该用户的档案信息");
    }

    /**
     * 查询员工成长列表
     *
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/query-growth-list/{userId}")
    public ActionResult<List<FtbPersonnelsStaffGrowthLogDto>> queryGrowthList(@PathVariable("userId") String userId) {
        List<FtbPersonnelsStaffGrowthLogDto> list = growthLogService.queryAll(userId);
        return ActionResult.success(list);
    }

}
