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.device.domain.HsDeviceScrapFlowRecord;
import com.willalp.device.service.IHsDeviceScrapFlowRecordService;
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("/device/scrapRecord")
public class HsDeviceScrapFlowRecordController extends BaseController
{
    @Resource
    private IHsDeviceScrapFlowRecordService hsDeviceScrapFlowRecordService;

    /**
     * 查询设备报废流程记录列表
     */
    @PreAuthorize("@ss.hasPermi('device:scrapRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsDeviceScrapFlowRecord hsDeviceScrapFlowRecord)
    {
        startPage();
        List<HsDeviceScrapFlowRecord> list = hsDeviceScrapFlowRecordService.selectHsDeviceScrapFlowRecordList(hsDeviceScrapFlowRecord);
        return getDataTable(list);
    }

    /**
     * 导出设备报废流程记录列表
     */
    @PreAuthorize("@ss.hasPermi('device:scrapRecord:export')")
    @Log(title = "设备报废流程记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HsDeviceScrapFlowRecord hsDeviceScrapFlowRecord)
    {
        List<HsDeviceScrapFlowRecord> list = hsDeviceScrapFlowRecordService.selectHsDeviceScrapFlowRecordList(hsDeviceScrapFlowRecord);
        ExcelUtil<HsDeviceScrapFlowRecord> util = new ExcelUtil<HsDeviceScrapFlowRecord>(HsDeviceScrapFlowRecord.class);
        return util.exportExcel(list, "设备报废流程记录数据");
    }

    /**
     * 获取设备报废流程记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('device:scrapRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(hsDeviceScrapFlowRecordService.getById(id));
    }

    /**
     * 新增设备报废流程记录
     */
    @PreAuthorize("@ss.hasPermi('device:scrapRecord:add')")
    @Log(title = "设备报废流程记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HsDeviceScrapFlowRecord hsDeviceScrapFlowRecord)
    {
        hsDeviceScrapFlowRecord.setCreateBy(SecurityUtils.getUsername());
        hsDeviceScrapFlowRecord.setCreateTime(DateUtils.getNowDate());
        return toAjax(hsDeviceScrapFlowRecordService.save(hsDeviceScrapFlowRecord));
    }

    /**
     * 修改设备报废流程记录
     */
    @PreAuthorize("@ss.hasPermi('device:scrapRecord:edit')")
    @Log(title = "设备报废流程记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HsDeviceScrapFlowRecord hsDeviceScrapFlowRecord)
    {
        hsDeviceScrapFlowRecord.setUpdateBy(SecurityUtils.getUsername());
        hsDeviceScrapFlowRecord.setUpdateTime(DateUtils.getNowDate());
        return toAjax(hsDeviceScrapFlowRecordService.updateById(hsDeviceScrapFlowRecord));
    }

    /**
     * 删除设备报废流程记录
     */
    @PreAuthorize("@ss.hasPermi('device:scrapRecord:remove')")
    @Log(title = "设备报废流程记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(hsDeviceScrapFlowRecordService.removeByIds(Arrays.asList(ids)));
    }
}
