package jnpf.cultivate.controller.web.promotion;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import jnpf.base.ActionResult;
import jnpf.cultivate.service.FtbCultivatePromotionPostService;
import jnpf.model.cultivate.po.promotion.FtbCultivatePromotionPost;
import org.springframework.web.bind.annotation.*;

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

/**
 * web晋升通道级别模块
 *
 * @author peng.hao
 */
@RestController
@RequestMapping("/cul_pro_post")
public class FtbCultivatePromotionPostController {
    /**
     * 服务对象
     */
    @Resource
    private FtbCultivatePromotionPostService postService;


    /**
     * 晋升通道级别列表查询
     * @param promotionId 晋升通道id
     * @return
     */
    @Operation(summary = "晋升通道级别列表查询")
    @GetMapping("/list")
    public ActionResult<List<FtbCultivatePromotionPost>> list(@RequestParam("promotionId") String promotionId ) {

        List<FtbCultivatePromotionPost> list = postService.getList(promotionId);
        return ActionResult.success(list);
    }


    /**
     * 新增晋升通道级别
     * @param creatDto
     * @return
     */
    @Operation(summary = "新增晋升通道级别")
    @PostMapping("/save")
    public ActionResult<String> save(@RequestBody FtbCultivatePromotionPost creatDto) {
        postService.savePost(creatDto);
        return ActionResult.success("新增成功");

    }


    /**
     * 修改晋升通道级别
     * @param dto
     * @return
     */
    @Operation(summary = "修改晋升通道级别")
    @PutMapping("/update")
    public ActionResult<String> update(@RequestBody FtbCultivatePromotionPost dto) {
        postService.updatePost(dto);
            return ActionResult.success("修改成功");
    }

    /**
     * 删除岗位级别
     * @param id 主键id
     * @return
     *
     */
    @Operation(summary = "删除岗位级别")
    @DeleteMapping("/{id}")
    @Parameter(name = "id", description = "主键", required = true)
    public ActionResult<String> delete(@PathVariable("id") String id) {
        if (postService.removeById(id)) {
            return ActionResult.success("删除成功");
        }
        return ActionResult.fail("删除失败");
    }
}
