package jnpf.personnels.controller.web.recruitmentchannels;

import jnpf.base.ActionResult;
import jnpf.database.util.TenantDataSourceUtil;
import jnpf.exception.LoginException;
import jnpf.model.personnels.dto.recruitmentchannels.PersonnelsRecruitmentChannelsAddDTO;
import jnpf.model.personnels.po.FtbPersonnelsRecruitmentChannels;
import jnpf.personnels.service.FtbPersonnelsRecruitmentChannelsService;
import jnpf.util.NoDataSourceBind;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * web人事招聘渠道
 *
 * @author wcx
 */
@RestController
@RequestMapping("/web/ftb_personnels_recruitment_channels")
public class FtbPersonnelsRecruitmentChannelsController {

    @Resource
    private FtbPersonnelsRecruitmentChannelsService ftbPersonnelsRecruitmentChannelsService;

    /**
     * 添加人事招聘渠道
     *
     * @return {@link ActionResult }
     */
    @PostMapping("/add")
    public ActionResult add(@RequestBody @Validated PersonnelsRecruitmentChannelsAddDTO personnelsRecruitmentChannelsAddDTO) {
        ftbPersonnelsRecruitmentChannelsService.add(personnelsRecruitmentChannelsAddDTO);
        return ActionResult.success();
    }

    /**
     * 查询招聘渠道列表
     */
    @GetMapping("/query-list")
    public ActionResult<List<FtbPersonnelsRecruitmentChannels>> queryRecruitmentChannels() {
        List<FtbPersonnelsRecruitmentChannels> list = ftbPersonnelsRecruitmentChannelsService.queryRecruitmentChannels();
        return ActionResult.success(list);
    }

    /**
     * 查询招聘渠道列表(外部)
     */
    @GetMapping("/query-list-external")
    @NoDataSourceBind
    public ActionResult<List<FtbPersonnelsRecruitmentChannels>> queryRecruitmentChannelsExternal(@RequestParam(value = "tenantId") String tenantId) throws LoginException {
        TenantDataSourceUtil.switchTenant(tenantId);
        List<FtbPersonnelsRecruitmentChannels> list = ftbPersonnelsRecruitmentChannelsService.queryRecruitmentChannels();
        return ActionResult.success(list);
    }

}
