package cn.iocoder.yudao.module.configure.controller.admin.tracelink;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.configure.controller.admin.tracelink.vo.TraceLinkPageReqVO;
import cn.iocoder.yudao.module.configure.controller.admin.tracelink.vo.TraceLinkRespVO;
import cn.iocoder.yudao.module.configure.convert.tracelink.TraceLinkConvert;
import cn.iocoder.yudao.module.configure.dal.dataobject.tracelink.TraceLinkDO;
import cn.iocoder.yudao.module.configure.service.tracelink.TraceLinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 溯源模板-环节")
@RestController
@RequestMapping("/configure/trace-link")
@Validated
public class TraceLinkController {

    @Resource
    private TraceLinkService traceLinkService;

    @DeleteMapping("/delete")
    @ApiOperation("删除溯源模板-环节")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('configure:trace-link:delete')")
    public CommonResult<Boolean> deleteTraceLink(@RequestParam("id") Long id) {
        traceLinkService.deleteTraceLink(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得溯源模板-环节")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('configure:trace-link:query')")
    public CommonResult<TraceLinkRespVO> getTraceLink(@RequestParam("id") Long id) {
        TraceLinkDO traceLink = traceLinkService.getTraceLink(id);
        return success(TraceLinkConvert.INSTANCE.convert(traceLink));
    }

    @GetMapping("/page")
    @ApiOperation("获得溯源模板-环节分页")
    @PreAuthorize("@ss.hasPermission('configure:trace-link:query')")
    public CommonResult<PageResult<TraceLinkRespVO>> getTraceLinkPage(@Valid TraceLinkPageReqVO pageVO) {
        PageResult<TraceLinkDO> pageResult = traceLinkService.getTraceLinkPage(pageVO);
        return success(TraceLinkConvert.INSTANCE.convertPage(pageResult));
    }

}
