package com.srs.web.controller.stureg;

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

import com.srs.common.annotation.Anonymous;
import com.srs.stureg.domain.SrsFeedback;
import com.srs.stureg.service.ISrsFeedbackService;
import org.springframework.security.access.prepost.PreAuthorize;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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 com.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 新生报到反馈Controller
 * 
 * @author srs
 * @date 2023-07-31
 */
@RestController
@RequestMapping("/system/feedback")
public class SrsFeedbackController extends BaseController
{
    @Autowired
    private ISrsFeedbackService srsFeedbackService;

    /**
     * 查询新生报到反馈列表
     */
//    @PreAuthorize("@ss.hasPermi('system:feedback:list')")
    @GetMapping("/list")
    public TableDataInfo list(SrsFeedback srsFeedback)
    {
        startPage();
        List<SrsFeedback> list = srsFeedbackService.selectSrsFeedbackList(srsFeedback);
        return getDataTable(list);
    }

    /**
     * 导出新生报到反馈列表
     */
//    @PreAuthorize("@ss.hasPermi('system:feedback:export')")
    @Log(title = "新生报到反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SrsFeedback srsFeedback)
    {
        List<SrsFeedback> list = srsFeedbackService.selectSrsFeedbackList(srsFeedback);
        ExcelUtil<SrsFeedback> util = new ExcelUtil<SrsFeedback>(SrsFeedback.class);
        util.exportExcel(response, list, "新生报到反馈数据");
    }

    /**
     * 获取新生报到反馈详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:feedback:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(srsFeedbackService.selectSrsFeedbackById(id));
    }

    /**
     * 新增新生报到反馈
     */

    //@PreAuthorize("@ss.hasPermi('system:feedback:add')")
    @Log(title = "新生报到反馈", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SrsFeedback srsFeedback, HttpServletRequest request)
    {
        int i = srsFeedbackService.insertSrsFeedback(srsFeedback, request);
        if (i==0){
            return error("反馈失败，今日反馈次数已用完，请明天在来");
        }else if (i==2){
            return error("未知错误");
        }
        return success();
    }

    /**
     * 修改新生报到反馈
     */
//    @PreAuthorize("@ss.hasPermi('system:feedback:edit')")
    @Log(title = "新生报到反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SrsFeedback srsFeedback)
    {
        return toAjax(srsFeedbackService.updateSrsFeedback(srsFeedback));
    }

    /**
     * 删除新生报到反馈
     */
//    @PreAuthorize("@ss.hasPermi('system:feedback:remove')")
    @Log(title = "新生报到反馈", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(srsFeedbackService.deleteSrsFeedbackByIds(ids));
    }
}
