package jnpf.cultivate.controller.web.gained;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.base.ActionResult;
import jnpf.base.Pagination;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.cultivate.service.FtbCourseGainedReaderService;
import jnpf.model.cultivate.po.gained.FtbCourseGainedReaderEntity;
import jnpf.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * app岗位学习课程-心得可查看用户关联表
 *
 */
@RestController
@Tag(name = "心得可查看用户关联表", description = "心得可查看用户关联表")
@RequestMapping("/course_gained_reader")
public class FtbCourseGainedReaderController  {
    @Autowired
    private FtbCourseGainedReaderService ftbCourseGainedReaderService;

    @Operation(summary = "获取列表")
    @GetMapping("/list")
    public ActionResult<PageListVO<FtbCourseGainedReaderEntity>> list(Pagination pagination) {
        List<FtbCourseGainedReaderEntity> entity = ftbCourseGainedReaderService.getList(pagination);
        List<FtbCourseGainedReaderEntity> listVo = JsonUtil.getJsonToList(JsonUtil.getObjectToStringDateFormat(entity, "yyyy-MM-dd HH:mm:ss"), FtbCourseGainedReaderEntity.class);
        PaginationVO vo = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
        return ActionResult.page(listVo, vo);
    }

    @Operation(summary = "获取详情")
    @GetMapping("/{id}")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
    })
    public ActionResult<FtbCourseGainedReaderEntity> info(@PathVariable("id") String id) {
        FtbCourseGainedReaderEntity entity = ftbCourseGainedReaderService.getInfo(id);
        //ContractInfoVO vo = JsonUtil.getJsonToBean(entity, ContractInfoVO.class);
        return ActionResult.success(entity);
    }

    @Operation(summary = "新建")
    @PostMapping
    public ActionResult<String> create(@RequestBody @Valid FtbCourseGainedReaderEntity entity) {
        //ContractEntity entity = JsonUtil.getJsonToBean(contractForm, ContractEntity.class);
        ftbCourseGainedReaderService.create(entity);
        return ActionResult.success("保存成功");
    }

    @Operation(summary = "修改")
    @PutMapping("/{id}")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
    })
    public ActionResult<String>  update(@PathVariable("id") String id, @RequestBody @Valid FtbCourseGainedReaderEntity entity) {
        entity.setId(id);
        ftbCourseGainedReaderService.updateById(entity);
        return ActionResult.success("修改成功");
    }

    @Operation(summary = "删除")
    @DeleteMapping("/{id}")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true),
    })
    public ActionResult<String> delete(@PathVariable("id") String id) {
        ftbCourseGainedReaderService.removeById(id);
        return ActionResult.success("删除成功");
    }
}