package com.dcsoft.system.consume.controller;

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

import com.dcsoft.system.consume.domain.ConsumeGroupRecord;
import com.dcsoft.system.consume.service.IConsumeGroupRecordService;
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.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.page.TableDataInfo;

/**
 * 分组餐补Controller
 *
 * @author nichun
 * @date 2024-04-12
 */
@RestController
@RequestMapping("/consumeGroupRecord")
public class ConsumeGroupRecordController extends BaseController
{
    @Autowired
    private IConsumeGroupRecordService consumeGroupRecordService;

    /**
     * 查询分组餐补列表
     */
    @RequiresPermissions("consume:groupRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(ConsumeGroupRecord consumeGroupRecord)
    {
        startPage();
        List<ConsumeGroupRecord> list = consumeGroupRecordService.selectConsumeGroupRecordList(consumeGroupRecord);
        return getDataTable(list);
    }

    /**
     * 导出分组餐补列表
     */
    @RequiresPermissions("consume:groupRecord:export")
    @Log(title = "分组餐补", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConsumeGroupRecord consumeGroupRecord)
    {
        List<ConsumeGroupRecord> list = consumeGroupRecordService.selectConsumeGroupRecordList(consumeGroupRecord);
        ExcelUtil<ConsumeGroupRecord> util = new ExcelUtil<ConsumeGroupRecord>(ConsumeGroupRecord.class);
        util.exportExcel(response, list, "分组餐补数据");
    }

    /**
     * 获取分组餐补详细信息
     */
    @RequiresPermissions("consume:groupRecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(consumeGroupRecordService.selectConsumeGroupRecordById(id));
    }

    /**
     * 新增分组餐补
     */
    @RequiresPermissions("consume:groupRecord:add")
    @Log(title = "分组餐补", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConsumeGroupRecord consumeGroupRecord)
    {
        return toAjax(consumeGroupRecordService.insertConsumeGroupRecord(consumeGroupRecord));
    }

    /**
     * 修改分组餐补
     */
    @RequiresPermissions("consume:groupRecord:edit")
    @Log(title = "分组餐补", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConsumeGroupRecord consumeGroupRecord)
    {
        return toAjax(consumeGroupRecordService.updateConsumeGroupRecord(consumeGroupRecord));
    }

    /**
     * 删除分组餐补
     */
    @RequiresPermissions("consume:groupRecord:remove")
    @Log(title = "分组餐补", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(consumeGroupRecordService.deleteConsumeGroupRecordByIds(ids));
    }
}
