package com.ruoyi.web.work.api;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.work.api.config.BaseController;
import com.ruoyi.web.work.domain.Position;
import com.ruoyi.web.work.domain.dto.PositionDto;
import com.ruoyi.web.work.domain.dto.PositionQueryDto;
import com.ruoyi.web.work.domain.dto.PositionStateDto;
import com.ruoyi.web.work.domain.vo.PositionListVo;
import com.ruoyi.web.work.service.IPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 职位管理
 *
 * @author lsw
 * @date 2024-06-07
 */
@RestController
@RequestMapping("/app/position")
public class Api_PositionController extends BaseController {
    @Autowired
    private IPositionService positionService;

    @GetMapping("/list")
    public TableDataInfo list(@Validated PositionQueryDto dto) {
        startPage();
        List<PositionListVo> list = positionService.indexList(dto);
        return getDataTable(list);
    }

    @GetMapping("/map")
    public AjaxResult map(@Validated PositionQueryDto dto) {
        List<PositionListVo> list = positionService.indexList(dto);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id) {
        return positionService.detail(id);
    }

    @GetMapping("/manage/list")
    public TableDataInfo manageList(Position position) {
        startPage();
        List<Position> list = positionService.manageList(position);
        return getDataTable(list);
    }

    @GetMapping("/manage/detail/{id}")
    public AjaxResult manageDetail(@PathVariable("id") Long id) {
        return positionService.manageDetail(id);
    }

    @PostMapping("/manage/add")
    public AjaxResult manageAdd(@Validated @RequestBody PositionDto dto) {
        return positionService.manageAdd(dto);
    }

    @PostMapping("/manage/edit")
    public AjaxResult manageEdit(@Validated @RequestBody PositionDto dto) {
        return positionService.manageEdit(dto);
    }


    @GetMapping("/manage/remove/{id}")
    public AjaxResult manageRemove(@PathVariable("id") Long id) {
        return positionService.manageRemove(id);
    }

    @PostMapping("/manage/state")
    public AjaxResult manageState(@Validated @RequestBody PositionStateDto dto) {
        return positionService.manageState(dto);
    }
}
