package com.srs.web.controller.stureg;

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

import com.srs.stureg.domain.VO.SrsStuSizeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;

import com.srs.stureg.domain.SrsStuSize;
import com.srs.stureg.service.ISrsStuSizeService;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.enums.BusinessType;
import com.srs.common.annotation.Log;
import com.srs.common.core.page.TableDataInfo;

/**
 * 学生尺码Controller
 *
 * @author srs
 * @date 2024-03-31
 */
@RestController
@RequestMapping("/stureg/size")
@Api(value = "学生尺码管理", tags = "学生尺码管理")
public class SrsStuSizeController extends BaseController {
    @Autowired
    private ISrsStuSizeService srsStuSizeService;


    @PostMapping("/submitOwnSize")
    @ApiOperation("学生提交自己的尺码")
    public AjaxResult submitOwnSize(@RequestBody SrsStuSize param){
        param.setKsh(getUsername());
        return srsStuSizeService.submitOwnSize(param);
    }

    @GetMapping("/getOwnSize")
    @ApiOperation("查询学生自己的尺码")
    public AjaxResult getOwnSize(){
        return srsStuSizeService.getStuSize(getUsername());
    }



    /**
     * 查询学生尺码列表
     */
//    @PreAuthorize("@ss.hasPermi('stureg:size:list')")
    @GetMapping("/list")
    @ApiOperation("查询学生尺码列表")
    public TableDataInfo list(SrsStuSize srsStuSize) {
        startPage();
        List<SrsStuSize> list = srsStuSizeService.selectSrsStuSizeList(srsStuSize);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('stureg:size:list')")
    @GetMapping("/listVo")
    @ApiOperation("查询学生尺码列表")
    public TableDataInfo listVo(SrsStuSizeVo srsStuSize) {
        startPage();
        List<SrsStuSizeVo> list = srsStuSizeService.selectSrsStuSizeListVo(srsStuSize);
        return getDataTable(list);
    }

    /**
     * 导出学生尺码列表
     */
    @PreAuthorize("@ss.hasPermi('stureg:size:export')")
    @Log(title = "学生尺码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出学生尺码列表")
    public void export(HttpServletResponse response, SrsStuSize srsStuSize) {
        List<SrsStuSize> list = srsStuSizeService.selectSrsStuSizeList(srsStuSize);
        ExcelUtil<SrsStuSize> util = new ExcelUtil<SrsStuSize>(SrsStuSize.class);
        util.exportExcel(response, list, "学生尺码数据");
    }

    /**
     * 获取学生尺码详细信息
     */
    @PreAuthorize("@ss.hasPermi('stureg:size:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取学生尺码详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(srsStuSizeService.selectSrsStuSizeById(id));
    }

    /**
     * 新增学生尺码
     */
    @PreAuthorize("@ss.hasPermi('stureg:size:add')")
    @Log(title = "学生尺码", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增学生尺码")
    public AjaxResult add(@RequestBody SrsStuSize srsStuSize) {
        return toAjax(srsStuSizeService.insertSrsStuSize(srsStuSize));
    }

    /**
     * 修改学生尺码
     */
    @PreAuthorize("@ss.hasPermi('stureg:size:edit')")
    @Log(title = "学生尺码", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改学生尺码")
    public AjaxResult edit(@RequestBody SrsStuSize srsStuSize) {
        return toAjax(srsStuSizeService.updateSrsStuSize(srsStuSize));
    }

    /**
     * 删除学生尺码
     */
    @PreAuthorize("@ss.hasPermi('stureg:size:remove')")
    @Log(title = "学生尺码", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除学生尺码")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(srsStuSizeService.deleteSrsStuSizeByIds(ids));
    }
}
