package com.ktg.iscs.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.pojo.CommonResult;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.iscs.domain.TestIscs;
import com.ktg.iscs.service.ITestIscsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 测试用Controller
 *
 * @author yinjinlu
 * @date 2024-10-14
 */
@Api(tags = "测试用")
@RestController
@RequestMapping("/test/iscs")
public class TestIscsController extends BaseController
{
    @Autowired
    private ITestIscsService testIscsService;

    /**
     * 查询测试用分页
     */
    @ApiOperation("查询测试用-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "sysTeam", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('test:iscs:list')")
    @GetMapping("/getTestIscsPage")
    public CommonResult<Page<TestIscs>> getTestIscsPage(Page<TestIscs> page, TestIscs testIscs)
    {
        Page<TestIscs> result = testIscsService.page(page, Wrappers.<TestIscs>lambdaQuery()
                .orderByDesc(TestIscs::getId));
        return CommonResult.success(result);
    }

    /**
     * 导出测试用列表
     */
    @ApiOperation("导出测试用列表")
    @Parameter(name = "testIscs", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('test:iscs:export')")
    @Log(title = "测试用", businessType = BusinessType.EXPORT)
    @PostMapping("/exportTestIscs")
    public void exportTestIscs(HttpServletResponse response, TestIscs testIscs)
    {
        List<TestIscs> list = testIscsService.selectTestIscsList(testIscs);
        ExcelUtil<TestIscs> util = new ExcelUtil<TestIscs>(TestIscs.class);
        util.exportExcel(response, list, "测试用数据");
    }

    /**
     * 获取测试用详细信息
     */
    @ApiOperation("获取测试用详细信息")
    @Parameter(name = "id", description = "id")
    @PreAuthorize("@ss.hasPermi('test:iscs:query')")
    @GetMapping(value = "/selectTestIscsById")
    public CommonResult<TestIscs> selectTestIscsById(@PathVariable("id") Long id)
    {
        return CommonResult.success(testIscsService.selectTestIscsById(id));
    }

    /**
     * 新增测试用
     */
    @ApiOperation("新增测试用")
    @PreAuthorize("@ss.hasPermi('test:iscs:add')")
    @Log(title = "测试用", businessType = BusinessType.INSERT)
    @PostMapping("/insertTestIscs")
    public CommonResult<Boolean> insertTestIscs(@RequestBody @Parameter(name = "testIscs", description = "新增数据类,放到body") TestIscs testIscs)
    {
        return CommonResult.success(testIscsService.insertTestIscs(testIscs) == 1);
    }

    /**
     * 修改测试用
     */
    @ApiOperation("修改测试用")
    @PreAuthorize("@ss.hasPermi('test:iscs:edit')")
    @Log(title = "测试用", businessType = BusinessType.UPDATE)
    @PostMapping("/updateTestIscs")
    public CommonResult<Boolean> updateTestIscs(@RequestBody @Parameter(name = "testIscs", description = "修改数据类,放到body") TestIscs testIscs)
    {
        return CommonResult.success(testIscsService.updateTestIscs(testIscs) == 1);
    }

    /**
     * 删除测试用
     */
    @ApiOperation("删除测试用")
    @PreAuthorize("@ss.hasPermi('test:iscs:remove')")
    @Log(title = "测试用", businessType = BusinessType.DELETE)
	@PostMapping("/deleteTestIscsByIds")
    public CommonResult<Boolean> deleteTestIscsByIds(@PathVariable Long[] ids)
    {
        return CommonResult.success(testIscsService.deleteTestIscsByIds(ids) == 1);
    }
}
