package com.ruoyi.web.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.CgYmq;
import com.ruoyi.web.service.ICgYmqService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购信息-羽毛球Controller
 * 
 * @author shenzx
 * @date 2025-09-28
 */
@RestController
@RequestMapping("/cg/ymq")
public class CgYmqController extends BaseController
{
    private ICgYmqService cgYmqService;
    @Autowired
    public void setCgYmqService(ICgYmqService cgYmqService) {
        this.cgYmqService = cgYmqService;
    }

    /**
     * 查询采购信息-羽毛球列表
     */
    @PreAuthorize("@ss.hasPermi('cg:ymq:list')")
    @GetMapping("/list")
    public TableDataInfo list(CgYmq cgYmq)
    {
        startPage();
        QueryWrapper<CgYmq> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(cgYmq);
        List<CgYmq> cgYmqList = cgYmqService.list(queryWrapper);
        return getDataTable(cgYmqList);
    }

    /**
     * 导出采购信息-羽毛球列表
     */
    @PreAuthorize("@ss.hasPermi('cg:ymq:export')")
    @Log(title = "采购信息-羽毛球", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CgYmq cgYmq)
    {
        QueryWrapper<CgYmq> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(cgYmq);
        List<CgYmq> list = cgYmqService.list(queryWrapper);
        ExcelUtil<CgYmq> util = new ExcelUtil<>(CgYmq.class);
        util.exportExcel(response, list, "采购信息-羽毛球数据");
    }

    /**
     * 获取采购信息-羽毛球详细信息
     */
    @PreAuthorize("@ss.hasPermi('cg:ymq:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cgYmqService.getById(id));
    }

    /**
     * 新增采购信息-羽毛球
     */
    @PreAuthorize("@ss.hasPermi('cg:ymq:add')")
    @Log(title = "采购信息-羽毛球", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CgYmq cgYmq)
    {
        cgYmqService.save(cgYmq);
        return success(cgYmq);
    }

    /**
     * 修改采购信息-羽毛球
     */
    @PreAuthorize("@ss.hasPermi('cg:ymq:edit')")
    @Log(title = "采购信息-羽毛球", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CgYmq cgYmq)
    {
        cgYmqService.updateById(cgYmq);
        return success(cgYmq);
    }

    /**
     * 删除采购信息-羽毛球
     */
    @PreAuthorize("@ss.hasPermi('cg:ymq:remove')")
    @Log(title = "采购信息-羽毛球", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cgYmqService.removeByIds(Arrays.asList(ids)));
    }
}
