package com.srs.web.controller.stureg;

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

import com.srs.stureg.domain.SrsStuSize;
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.SrsRegPhoto;
import com.srs.stureg.service.ISrsRegPhotoService;
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-04-02
 */
@RestController
@RequestMapping("/stureg/photo")
@Api(value = "新生照片管理", tags = "新生照片管理")
public class SrsRegPhotoController extends BaseController {
    @Autowired
    private ISrsRegPhotoService srsRegPhotoService;



    //新生照片提交
    @PostMapping("/submitOwnPhoto")
    @ApiOperation("学生提交自己的照片")
    public AjaxResult submitOwnPhoto(@RequestBody SrsRegPhoto param){
        param.setKsh(getUsername());
        return srsRegPhotoService.submitOwnPhoto(param);
    }



    //新生照片查询
    @GetMapping("/getOwnPhoto")
    @ApiOperation("查询学生自己的照片")
    public AjaxResult getOwnPhoto(){
        //使用用户名查询
        return srsRegPhotoService.getRegPhoto(getUsername());
    }

    /**
     * 查询新生照片列表
     */
    @PreAuthorize("@ss.hasPermi('stureg:photo:list')")
    @GetMapping("/list")
    @ApiOperation("查询新生照片列表")
    public TableDataInfo list(SrsRegPhoto srsRegPhoto) {
        startPage();
        List<SrsRegPhoto> list = srsRegPhotoService.selectSrsRegPhotoList(srsRegPhoto);
        return getDataTable(list);
    }

    /**
     * 导出新生照片列表
     */
    @PreAuthorize("@ss.hasPermi('stureg:photo:export')")
    @Log(title = "新生照片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出新生照片列表")
    public void export(HttpServletResponse response, SrsRegPhoto srsRegPhoto) {
        List<SrsRegPhoto> list = srsRegPhotoService.selectSrsRegPhotoList(srsRegPhoto);
        ExcelUtil<SrsRegPhoto> util = new ExcelUtil<SrsRegPhoto>(SrsRegPhoto.class);
        util.exportExcel(response, list, "新生照片数据");
    }

    /**
     * 获取新生照片详细信息
     */
    @PreAuthorize("@ss.hasPermi('stureg:photo:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取新生照片详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(srsRegPhotoService.selectSrsRegPhotoById(id));
    }

    /**
     * 新增新生照片
     */
    @PreAuthorize("@ss.hasPermi('stureg:photo:add')")
    @Log(title = "新生照片", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增新生照片")
    public AjaxResult add(@RequestBody SrsRegPhoto srsRegPhoto) {
        return toAjax(srsRegPhotoService.insertSrsRegPhoto(srsRegPhoto));
    }

    /**
     * 修改新生照片
     */
    @PreAuthorize("@ss.hasPermi('stureg:photo:edit')")
    @Log(title = "新生照片", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改新生照片")
    public AjaxResult edit(@RequestBody SrsRegPhoto srsRegPhoto) {
        return toAjax(srsRegPhotoService.updateSrsRegPhoto(srsRegPhoto));
    }

    /**
     * 删除新生照片
     */
    @PreAuthorize("@ss.hasPermi('stureg:photo:remove')")
    @Log(title = "新生照片", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除新生照片")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(srsRegPhotoService.deleteSrsRegPhotoByIds(ids));
    }
}
