package com.ruoyi.web.controller.system;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.domain.dto.employmentData.EmploymentDataAddRequest;
import com.ruoyi.web.domain.dto.employmentData.EmploymentDataEditRequest;
import com.ruoyi.web.domain.dto.employmentData.EmploymentDataQueryRequest;
import com.ruoyi.web.domain.entity.EmploymentData;
import com.ruoyi.web.service.EmploymentDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;

@Api(tags ="就业数据管理")
@RestController
@RequestMapping("/system/employment")
public class EmploymentController {

    @Autowired
    private EmploymentDataService employmentDataService;

    /**
     * 添加就业数据
     *
     * @param employmentDataAddRequest
     * @return
     */
    @ApiOperation("添加就业数据")
    @PostMapping("/add")
    public AjaxResult addEmploymentData(@RequestBody EmploymentDataAddRequest employmentDataAddRequest) {
        if (employmentDataAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = employmentDataService.addEmploymentData(employmentDataAddRequest);
        return success(id);
    }

    /**
     * 删除就业数据
     *
     * @param paramsMap
     * @return
     */
    @ApiOperation("删除就业数据")
    @PostMapping("/delete")
    public AjaxResult deleteEmploymentData(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        if (StrUtil.isBlank(ids)) {
            return error("请求参数为空");
        }
        boolean b = employmentDataService.deleteEmploymentData(ids);
        if (b) {
            return success("删除成功");
        }
        return error("删除失败");
    }


    /**
     * 编辑就业数据
     *
     * @param employmentDataEditRequest
     * @return
     */
    @ApiOperation("编辑就业数据")
    @PostMapping("/edit")
    public AjaxResult editEmploymentData(@RequestBody EmploymentDataEditRequest employmentDataEditRequest) {
        if (employmentDataEditRequest == null) {
            return error("请求参数为空");
        }
        employmentDataService.editEmploymentData(employmentDataEditRequest);
        return AjaxResult.success();
    }

    /**
     * 根据id获取就业数据
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取就业数据")
    @GetMapping("/get")
    public AjaxResult getEmploymentDataById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        EmploymentData employmentData = employmentDataService.getEmploymentDataById(id);
        return success(employmentData);
    }

    /**
     * 分页获取就业数据列表
     *
     * @param employmentDataQueryRequest
     * @return
     */
    @ApiOperation("分页获取就业数据列表")
    @PostMapping("/list/page")
    public AjaxResult listEmploymentDataByPage(@RequestBody EmploymentDataQueryRequest employmentDataQueryRequest) {
        if (employmentDataQueryRequest == null) {
            return error("请求参数为空");
        }
        Page<EmploymentData> listEmploymentDataByPage = employmentDataService.getListEmploymentDataByPage(employmentDataQueryRequest);
        return success(listEmploymentDataByPage);
    }
}
