package cn.timer.api.controller.zpgl;

import cn.timer.api.bean.zpgl.ZpglCompany;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.config.exception.CustomException;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 招聘管理
 *
 * @author wuqingjun
 * @email 284718418@qq.com
 * @date 2022-03-18 15:14:40
 */
@Api(tags = "招聘管理")
@Transactional(rollbackOn = Exception.class)
@RestController
@RequestMapping(value = "/zpgl", produces = {"application/json"})
public class ZpglCompanyController {

    /**
     * 招聘-合同公司字典
     *
     * @param
     * @return
     */
    @GetMapping(value = "/conpany")
    @ApiOperation(value = "1.合同公司字典", httpMethod = "GET", notes = "合同公司字典")
    @ApiOperationSupport(order = 1)
    public Result<Object> fail(@CurrentUser UserBean userBean) {
        try {
            QueryWrapper<ZpglCompany> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(ZpglCompany::getDeleteFlag, 0).eq(ZpglCompany::getOrgCode, userBean.getOrgCode());
            List<ZpglCompany> zpglCompany = ZpglCompany.builder().build().selectList(queryWrapper);
            return ResultUtil.data(zpglCompany, "查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("招聘-合同公司字典失败");
        }
    }

    /**
     * 招聘-添加合同公司
     *
     * @param
     * @return
     */
    @PostMapping(value = "/company/save")
    @ApiOperation(value = "2.招聘-添加合同公司", httpMethod = "POST", notes = "招聘-添加合同公司")
    @ApiOperationSupport(order = 2)
    public Result<Object> save(@CurrentUser UserBean userBean, @RequestBody ZpglCompany zpglCompany) {
        try {
            zpglCompany.setCreateUserId(userBean.getEmpNum());
            zpglCompany.setUpdateUserId(userBean.getEmpNum());
            zpglCompany.setOrgCode(userBean.getOrgCode());
            return zpglCompany.insert() ? ResultUtil.success() : ResultUtil.error();
        } catch (Exception e) {
            e.printStackTrace();
            throw new CustomException("招聘-添加合同公司失败");
        }
    }

}