package com.willalp.web.controller.clockingin;

import com.willalp.common.annotation.Log;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.core.page.TableDataInfo;
import com.willalp.common.enums.BusinessType;
import com.willalp.common.utils.DateUtils;
import com.willalp.common.utils.SecurityUtils;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.flow.domain.ReserveConsumingRecord;
import com.willalp.flow.service.IReserveConsumingRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 物资领用申请业务数据记录Controller
 *
 * @author willalp
 * @date 2023-01-12
 */
@RestController
@RequestMapping("/flow/reserve")
public class ReserveConsumingRecordController extends BaseController
{
    @Resource
    private IReserveConsumingRecordService reserveConsumingRecordService;

    /**
     * 查询物资领用申请业务数据记录列表
     */
    @PreAuthorize("@ss.hasPermi('flow:reserve:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReserveConsumingRecord reserveConsumingRecord)
    {
        startPage();
        List<ReserveConsumingRecord> list = reserveConsumingRecordService.selectReserveConsumingRecordList(reserveConsumingRecord);
        return getDataTable(list);
    }

    /**
     * 导出物资领用申请业务数据记录列表
     */
    @PreAuthorize("@ss.hasPermi('flow:reserve:export')")
    @Log(title = "物资领用申请业务数据记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ReserveConsumingRecord reserveConsumingRecord)
    {
        List<ReserveConsumingRecord> list = reserveConsumingRecordService.selectReserveConsumingRecordList(reserveConsumingRecord);
        ExcelUtil<ReserveConsumingRecord> util = new ExcelUtil<ReserveConsumingRecord>(ReserveConsumingRecord.class);
        return util.exportExcel(list, "物资领用申请业务数据记录数据");
    }

    /**
     * 获取物资领用申请业务数据记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:reserve:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(reserveConsumingRecordService.getById(id));
    }

    /**
     * 新增物资领用申请业务数据记录
     */
    @PreAuthorize("@ss.hasPermi('flow:reserve:add')")
    @Log(title = "物资领用申请业务数据记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReserveConsumingRecord reserveConsumingRecord)
    {
        reserveConsumingRecord.setCreateBy(SecurityUtils.getUsername());
        reserveConsumingRecord.setCreateTime(DateUtils.getNowDate());
        return toAjax(reserveConsumingRecordService.save(reserveConsumingRecord));
    }

    /**
     * 修改物资领用申请业务数据记录
     */
    @PreAuthorize("@ss.hasPermi('flow:reserve:edit')")
    @Log(title = "物资领用申请业务数据记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReserveConsumingRecord reserveConsumingRecord)
    {
        reserveConsumingRecord.setUpdateBy(SecurityUtils.getUsername());
        reserveConsumingRecord.setUpdateTime(DateUtils.getNowDate());
        return toAjax(reserveConsumingRecordService.updateById(reserveConsumingRecord));
    }

    /**
     * 删除物资领用申请业务数据记录
     */
    @PreAuthorize("@ss.hasPermi('flow:reserve:remove')")
    @Log(title = "物资领用申请业务数据记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(reserveConsumingRecordService.removeByIds(Arrays.asList(ids)));
    }
}
