package com.zjrs.ggfw.rlzysc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mohrss.leaf.core.framework.persistens.PageResult;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import org.mohrss.leaf.core.framework.web.exception.AppException;
import com.zjrs.ggfw.rlzysc.bpo.ZphglBPO;
import com.zjrs.ggfw.rlzysc.dto.QtzphQueryDTO;
import com.zjrs.ggfw.rlzysc.dto.ZphglQueryDTO;
import com.zjrs.ggfw.rlzysc.dto.dwzp.WlZphDetailDTO;
import com.zjrs.ggfw.rlzysc.po.RsRlzyXczphPO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.util.List;

@Api("招聘会管理")
@RestController
@RequestMapping("/api/rlzysc/xczph")
public class ZphglController {
    private static final Logger LOG = LoggerFactory.getLogger(ZphglController.class);
    @Resource
    private ZphglBPO zphglBPO;

//    按照时间先后顺序分页的所有的招聘会，提供求职者能选择查看某个时间招聘会里所有入驻的企业信息，并查看企业所招聘的职位信息
    @ApiOperation(value = "获取招聘会列表", notes = "获取招聘会列表")
    @PostMapping("/zphgl/list")
    public AjaxResponse getZphglList(@RequestBody @Valid ZphglQueryDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        Integer pagenum = dto.getPagenum();
        Integer pagesize = dto.getPagesize();
        try {
            PageResult pageResult = this.zphglBPO.getZphglList(dto, pagenum, pagesize);
            ajaxResponse.setData("data", pageResult);
            ajaxResponse.setData("pagesize", pagesize);
            ajaxResponse.setData("pagenum", pagenum);
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        System.out.println(ajaxResponse);
        return ajaxResponse;
    }


    @ApiOperation(value = "获取招聘会详细信息", notes = "获取招聘会详细信息")
    @PostMapping("/zphgl/query")
    public AjaxResponse getZphxxById(@RequestBody QtzphQueryDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            RsRlzyXczphPO result = this.zphglBPO.getZphxxById(dto);
            ajaxResponse.setData("data", result);
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }

    @ApiOperation(value = "获取其他招聘会列表", notes = "获取其他招聘会列表")
    @PostMapping("/zphgl/qtzph/list")   //其他招聘会
    public AjaxResponse getQtzphList(@RequestBody QtzphQueryDTO dto) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            List<RsRlzyXczphPO> list = this.zphglBPO.getQtzphList(dto);
            ajaxResponse.setData("data", list);
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        System.out.println(ajaxResponse);
        return ajaxResponse;
    }

    @ApiOperation(value = "获取加入招聘会的单位信息", notes = "获取加入招聘会的单位信息")
    @PostMapping("/zphgl/zpdw/list")   //获取加入招聘会的单位信息，传入招聘会流水号
    public AjaxResponse getQyxxList(@RequestBody @Valid QtzphQueryDTO dto) {
        LOG.info("获取加入招聘会的单位信息开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            List pageResult = this.zphglBPO.getQyxxList(dto);
            ajaxResponse.setData("data", pageResult);
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("获取加入招聘会的单位信息结束");
        return ajaxResponse;
    }

    @ApiOperation(value = "获取最新加入的招聘单位", notes = "获取最新加入的招聘单位")
    @GetMapping("/zphgl/zxjrdzph/list")
    public AjaxResponse getZxjrdZphList() {
        LOG.info("获取最新加入的招聘单位开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            List result = this.zphglBPO.getZxjrdZphList();
            ajaxResponse.setData("data", result);
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("获取最新加入的招聘单位结束");
        return ajaxResponse;
    }

    @ApiOperation(value = "获取最新加入的招聘单位", notes = "获取最新加入的招聘单位")
    @GetMapping("/zphgl/zxjrdzph/wllist")
    public AjaxResponse getZxjrdWlZphList() {
        LOG.info("获取最新加入的招聘单位开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            List result = this.zphglBPO.getZxjrdWlZphList();
            ajaxResponse.setData("data", result);
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("获取最新加入的招聘单位结束");
        return ajaxResponse;
    }

    @ApiOperation(value = "招聘会详细页面", notes = "招聘会详细页面")
    @PostMapping("/zphgl/index/detail")   //获取加入招聘会的单位信息，传入招聘会流水号
    public AjaxResponse getIndexDetail(@RequestBody @Valid QtzphQueryDTO dto) {
        LOG.info("招聘会详细页面开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            RsRlzyXczphPO zphDetail = this.zphglBPO.getZphxxById(dto);
            List<RsRlzyXczphPO> qtzphList = this.zphglBPO.getQtzphList(dto);
            List jrzphdwxx = this.zphglBPO.getQyxxList(dto);
            int kydxw = this.zphglBPO.getKydxw(dto);
            ajaxResponse.setData("zphDetail", zphDetail);
            ajaxResponse.setData("qtzphList", qtzphList);
            ajaxResponse.setData("jrzphdwxx", jrzphdwxx);
            ajaxResponse.setData("kydxw", kydxw);//剩余可预订席位
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("招聘会详细页面结束");
        return ajaxResponse;
    }

    @ApiOperation(value = "网络招聘会详细页面", notes = "网络招聘会详细页面")
    @PostMapping("/zphgl/index/wldetail")   //获取加入招聘会的单位信息，传入招聘会流水号
    public AjaxResponse getIndexWlDetail(@RequestBody @Valid WlZphDetailDTO dto) {
        LOG.info("招聘会详细页面开始");
        AjaxResponse ajaxResponse = new AjaxResponse();
        try {
            ajaxResponse.setData("data", zphglBPO.getIndexWlDetail(dto));
        } catch (AppException e) {
            ajaxResponse.setAppcode("1");
            LOG.error(e.getMessage());
            ajaxResponse.setErrorMsg(e.getMessage());
        } catch (Exception e) {
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        LOG.info("招聘会详细页面结束");
        return ajaxResponse;
    }
}

