package com.ktg.web.controller.iscs;

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.system.domain.SysTeam;
import com.ktg.system.service.ISysTeamService;
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.Arrays;
import java.util.List;

/**
 * 小组Controller
 *
 * @author cc
 * @date 2024-09-13
 */
@Api(tags = "小组")
@RestController
@RequestMapping("/iscs/team")
public class SysTeamController extends BaseController
{
    @Autowired
    private ISysTeamService sysTeamService;

    /**
     * 查询小组分页
     */
    @ApiOperation("查询小组-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "sysTeam", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:team:list')")
    @GetMapping("/getSysTeamPage")
    public CommonResult<Page<SysTeam>> getSysTeamPage(Page<SysTeam> page, SysTeam sysTeam)
    {
        Page<SysTeam> result = sysTeamService.page(page, Wrappers.<SysTeam>lambdaQuery()
                .orderByDesc(SysTeam::getId));
        return CommonResult.success(result);
    }

    /**
     * 导出小组列表
     */
    @ApiOperation("导出小组列表")
    @Parameter(name = "sysTeam", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:team:export')")
    @Log(title = "小组", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSysTeam")
    public void exportSysTeam(HttpServletResponse response, SysTeam sysTeam)
    {
        List<SysTeam> list = sysTeamService.selectSysTeamList(sysTeam);
        ExcelUtil<SysTeam> util = new ExcelUtil<SysTeam>(SysTeam.class);
        util.exportExcel(response, list, "小组数据");
    }

    /**
     * 获取小组详细信息
     */
    @ApiOperation("获取小组详细信息")
    @Parameter(name = "id", description = "id")
    @PreAuthorize("@ss.hasPermi('iscs:team:query')")
    @GetMapping(value = "/{id}")
    public CommonResult<SysTeam> selectSysTeamById(@PathVariable("id") Long id)
    {
        return CommonResult.success(sysTeamService.selectSysTeamById(id));
    }

    /**
     * 新增小组
     */
    @ApiOperation("新增小组")
    @PreAuthorize("@ss.hasPermi('iscs:team:add')")
    @Log(title = "小组", businessType = BusinessType.INSERT)
    @PostMapping("/insertSysTeam")
    public CommonResult<Boolean> insertSysTeam(@RequestBody @Parameter(name = "sysTeam", description = "新增数据类,放到body") SysTeam sysTeam)
    {
        int i = sysTeamService.insertSysTeam(sysTeam);
        return CommonResult.success(i == 1);
    }

    /**
     * 修改小组
     */
    @ApiOperation("修改小组")
    @PreAuthorize("@ss.hasPermi('iscs:team:edit')")
    @Log(title = "小组", businessType = BusinessType.UPDATE)
    @PutMapping("/updateSysTeam")
    public CommonResult<Boolean> updateSysTeam(@RequestBody @Parameter(name = "sysTeam", description = "修改数据类,放到body") SysTeam sysTeam)
    {
        return CommonResult.success(sysTeamService.updateSysTeam(sysTeam) == 1);
    }

    /**
     * 删除小组
     */
    @ApiOperation("删除小组")
    @PreAuthorize("@ss.hasPermi('iscs:team:remove')")
    @Log(title = "小组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public CommonResult<Boolean> deleteSysTeamByIds(@PathVariable Long[] ids)
    {
        // return CommonResult.success(sysTeamService.deleteSysTeamByIds(ids) == 1);
        boolean b = sysTeamService.removeByIds(Arrays.asList(ids));
        return CommonResult.success(b);
    }

    @ApiOperation("测试")
    @GetMapping("/testaaaaaaaa")
    public CommonResult<Boolean> testaaaaaaaa()
    {
        return CommonResult.success(true);
    }

}
