package com.willalp.web.controller.canteen;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
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.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.enums.BusinessType;
import com.willalp.canteen.domain.HsCanteenScck;
import com.willalp.canteen.service.IHsCanteenScckService;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.common.core.page.TableDataInfo;

/**
 * 食材出库Controller
 *
 * @author songyu
 * @date 2021-11-26
 */
@RestController
@RequestMapping("/canteen/scck")
public class HsCanteenScckController extends BaseController
{
    @Autowired
    private IHsCanteenScckService hsCanteenScckService;

    /**
     * 查询食材出库列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:scck:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsCanteenScck hsCanteenScck)
    {
        startPage();
        List<HsCanteenScck> list = hsCanteenScckService.selectHsCanteenScckList(hsCanteenScck);
        return getDataTable(list);
    }

    /**
     * 导出食材出库列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:scck:export')")
    @Log(title = "食材出库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsCanteenScck hsCanteenScck)
    {
        List<HsCanteenScck> list = hsCanteenScckService.selectHsCanteenScckList(hsCanteenScck);
        ExcelUtil<HsCanteenScck> util = new ExcelUtil<HsCanteenScck>(HsCanteenScck.class);
        return util.exportExcel(list, "食材出库数据");
    }

    /**
     * 获取食材出库详细信息
     */
    @PreAuthorize("@ss.hasPermi('canteen:scck:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") String recordId)
    {
        return AjaxResult.success(hsCanteenScckService.getById(recordId));
    }

    /**
     * 新增食材出库
     */
    @PreAuthorize("@ss.hasPermi('canteen:scck:add')")
    @Log(title = "食材出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsCanteenScck hsCanteenScck)
    {
        while (true) {
            String idStr = IdWorker.getIdStr();
            HsCanteenScck byId = hsCanteenScckService.getById(idStr);
            if (null == byId) {
                hsCanteenScck.setRecordId(idStr);
                break;
            }
        }
        return toAjax(hsCanteenScckService.save(hsCanteenScck));
    }

    /**
     * 修改食材出库
     */
    @PreAuthorize("@ss.hasPermi('canteen:scck:edit')")
    @Log(title = "食材出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsCanteenScck hsCanteenScck)
    {
        return toAjax(hsCanteenScckService.updateById(hsCanteenScck));
    }

    /**
     * 删除食材出库
     */
    @PreAuthorize("@ss.hasPermi('canteen:scck:remove')")
    @Log(title = "食材出库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable String[] recordIds)
    {
        return toAjax(hsCanteenScckService.removeByIds(Arrays.asList(recordIds)));
    }
}
