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.HsPurchaseFlowRecord;
import com.willalp.flow.service.IHsPurchaseFlowRecordService;
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-04-23
 */
@RestController
@RequestMapping("/flow/purchaseRecord")
public class HsPurchaseFlowRecordController extends BaseController
{
    @Resource
    private IHsPurchaseFlowRecordService hsPurchaseFlowRecordService;

    /**
     * 查询采购流程记录列表
     */
    @PreAuthorize("@ss.hasPermi('flow:purchaseRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsPurchaseFlowRecord hsPurchaseFlowRecord)
    {
        startPage();
        List<HsPurchaseFlowRecord> list = hsPurchaseFlowRecordService.selectHsPurchaseFlowRecordList(hsPurchaseFlowRecord);
        return getDataTable(list);
    }

    /**
     * 导出采购流程记录列表
     */
    @PreAuthorize("@ss.hasPermi('flow:purchaseRecord:export')")
    @Log(title = "采购流程记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsPurchaseFlowRecord hsPurchaseFlowRecord)
    {
        List<HsPurchaseFlowRecord> list = hsPurchaseFlowRecordService.selectHsPurchaseFlowRecordList(hsPurchaseFlowRecord);
        ExcelUtil<HsPurchaseFlowRecord> util = new ExcelUtil<HsPurchaseFlowRecord>(HsPurchaseFlowRecord.class);
        return util.exportExcel(list, "采购流程记录数据");
    }

    /**
     * 获取采购流程记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('flow:purchaseRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsPurchaseFlowRecordService.getById(id));
    }

    /**
     * 新增采购流程记录
     */
    @PreAuthorize("@ss.hasPermi('flow:purchaseRecord:add')")
    @Log(title = "采购流程记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsPurchaseFlowRecord hsPurchaseFlowRecord)
    {
        hsPurchaseFlowRecord.setCreateBy(SecurityUtils.getUsername());
        hsPurchaseFlowRecord.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsPurchaseFlowRecordService.save(hsPurchaseFlowRecord));
    }

    /**
     * 修改采购流程记录
     */
    @PreAuthorize("@ss.hasPermi('flow:purchaseRecord:edit')")
    @Log(title = "采购流程记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsPurchaseFlowRecord hsPurchaseFlowRecord)
    {
        hsPurchaseFlowRecord.setUpdateBy(SecurityUtils.getUsername());
        hsPurchaseFlowRecord.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsPurchaseFlowRecordService.updateById(hsPurchaseFlowRecord));
    }

    /**
     * 删除采购流程记录
     */
    @PreAuthorize("@ss.hasPermi('flow:purchaseRecord:remove')")
    @Log(title = "采购流程记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hsPurchaseFlowRecordService.removeByIds(Arrays.asList(ids)));
    }
}
