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

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

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

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.configure.controller.admin.tracelinkitem.vo.*;
import cn.iocoder.yudao.module.configure.dal.dataobject.tracelinkitem.TraceLinkItemDO;
import cn.iocoder.yudao.module.configure.convert.tracelinkitem.TraceLinkItemConvert;
import cn.iocoder.yudao.module.configure.service.tracelinkitem.TraceLinkItemService;

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

    @Resource
    private TraceLinkItemService traceLinkItemService;

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

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

    @GetMapping("/page")
    @ApiOperation("获得溯源模板环节item分页")
    @PreAuthorize("@ss.hasPermission('configure:trace-link-item:query')")
    public CommonResult<PageResult<TraceLinkItemRespVO>> getTraceLinkItemPage(@Valid TraceLinkItemPageReqVO pageVO) {
        PageResult<TraceLinkItemDO> pageResult = traceLinkItemService.getTraceLinkItemPage(pageVO);
        return success(TraceLinkItemConvert.INSTANCE.convertPage(pageResult));
    }

}
