package com.srs.web.controller.comprehensive;

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

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.comprehensive.domain.CphDormitoryGood;
import com.srs.comprehensive.service.ICphDormitoryGoodService;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 优秀宿舍Controller
 * 
 * @author srs
 * @date 2023-07-04
 */
@RestController
@RequestMapping("/system/good")
@Api(tags = "优秀宿舍")
public class CphDormitoryGoodController extends BaseController
{
    @Autowired
    private ICphDormitoryGoodService cphDormitoryGoodService;

    /**
     * 查询优秀宿舍列表
     */
//    @PreAuthorize("@ss.hasPermi('system:good:list')")
    @GetMapping("/list")
    @ApiOperation(value = "优秀宿舍列表", httpMethod = "GET", notes = "优秀宿舍列表")
    public TableDataInfo list(CphDormitoryGood cphDormitoryGood)
    {
        startPage();
        List<CphDormitoryGood> list = cphDormitoryGoodService.selectCphDormitoryGoodList(cphDormitoryGood);
        return getDataTable(list);
    }

    /**
     * 导出优秀宿舍列表
     */
//    @PreAuthorize("@ss.hasPermi('system:good:export')")
    @Log(title = "优秀宿舍", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
//    @ApiOperation(value = "导出优秀宿舍列表", httpMethod = "POST", notes = "导出优秀宿舍列表")
    public void export(HttpServletResponse response, CphDormitoryGood cphDormitoryGood)
    {
        List<CphDormitoryGood> list = cphDormitoryGoodService.selectCphDormitoryGoodList(cphDormitoryGood);
        ExcelUtil<CphDormitoryGood> util = new ExcelUtil<CphDormitoryGood>(CphDormitoryGood.class);
        util.exportExcel(response, list, "优秀宿舍数据");
    }

    /**
     * 获取优秀宿舍详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:good:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cphDormitoryGoodService.selectCphDormitoryGoodById(id));
    }

    /**
     * 新增优秀宿舍
     */
//    @PreAuthorize("@ss.hasPermi('system:good:add')")
    @Log(title = "优秀宿舍", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增优秀宿舍", httpMethod = "POST", notes = "新增优秀宿舍")
    public AjaxResult add(@RequestBody CphDormitoryGood cphDormitoryGood)
    {
        return toAjax(cphDormitoryGoodService.insertCphDormitoryGood(cphDormitoryGood));
    }

    /**
     * 修改优秀宿舍
     */
//    @PreAuthorize("@ss.hasPermi('system:good:edit')")
    @Log(title = "优秀宿舍", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改优秀宿舍", httpMethod = "PUT", notes = "修改优秀宿舍")
    public AjaxResult edit(@RequestBody CphDormitoryGood cphDormitoryGood)
    {
        return toAjax(cphDormitoryGoodService.updateCphDormitoryGood(cphDormitoryGood));
    }

    /**
     * 删除优秀宿舍
     */
//    @PreAuthorize("@ss.hasPermi('system:good:remove')")
    @Log(title = "优秀宿舍", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value = "删除优秀宿舍", httpMethod = "DELETE", notes = "删除优秀宿舍")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cphDormitoryGoodService.deleteCphDormitoryGoodByIds(ids));
    }
}
