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.HsDeviceRepairs;
import com.willalp.device.service.IHsDeviceRepairsService;
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-21
 */
@RestController
@RequestMapping("/device/repairs")
public class HsDeviceRepairsController extends BaseController
{
    @Resource
    private IHsDeviceRepairsService hsDeviceRepairsService;

    /**
     * 查询设备报修流程记录列表
     */
    @PreAuthorize("@ss.hasPermi('device:repairs:list')")
    @GetMapping("/list")
    public TableDataInfo list(HsDeviceRepairs hsDeviceRepairs)
    {
        startPage();
        List<HsDeviceRepairs> list = hsDeviceRepairsService.selectHsDeviceRepairsList(hsDeviceRepairs);
        return getDataTable(list);
    }

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

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

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

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

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