package com.ruoyi.web.controller.buyerapi;

import java.util.List;
import cn.hutool.core.util.IdUtil;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.buyerapi.domain.BuyerDeviceWorkhourMonth;
import com.ruoyi.buyerapi.service.IBuyerDeviceWorkhourMonthService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备工时分摊月报Controller
 *
 * @author ruoyi
 * @date 2022-09-22
 */
@RestController
@RequestMapping("/buyer/devicewkmonth")
public class BuyerDeviceWorkhourMonthController extends BaseController
{
    @Autowired
    private IBuyerDeviceWorkhourMonthService buyerDeviceWorkhourMonthService;

    /**
     * 查询设备工时分摊月报列表
     */
    @PreAuthorize("@ss.hasPermi('buyer:devicewkmonth:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuyerDeviceWorkhourMonth buyerDeviceWorkhourMonth)
    {
        startPage();
        buyerDeviceWorkhourMonth.setCompanyId(SecurityUtils.getCompanyId());
        List<BuyerDeviceWorkhourMonth> list = buyerDeviceWorkhourMonthService.selectBuyerDeviceWorkhourMonthList(buyerDeviceWorkhourMonth);
        return getDataTable(list);
    }

    /**
     * 导出设备工时分摊月报列表
     */
    @PreAuthorize("@ss.hasPermi('buyer:devicewkmonth:export')")
    @Log(title = "设备工时分摊月报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerDeviceWorkhourMonth buyerDeviceWorkhourMonth)
    {
        List<BuyerDeviceWorkhourMonth> list = buyerDeviceWorkhourMonthService.selectBuyerDeviceWorkhourMonthList(buyerDeviceWorkhourMonth);
        ExcelUtil<BuyerDeviceWorkhourMonth> util = new ExcelUtil<BuyerDeviceWorkhourMonth>(BuyerDeviceWorkhourMonth.class);
        util.exportExcel(response, list, "设备工时分摊月报数据");
    }

    /**
     * 获取设备工时分摊月报详细信息
     */
    @PreAuthorize("@ss.hasPermi('buyer:devicewkmonth:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(buyerDeviceWorkhourMonthService.selectBuyerDeviceWorkhourMonthById(id));
    }

    /**
     * 新增设备工时分摊月报
     */
    @PreAuthorize("@ss.hasPermi('buyer:devicewkmonth:add')")
    @Log(title = "设备工时分摊月报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerDeviceWorkhourMonth buyerDeviceWorkhourMonth)
    {
        buyerDeviceWorkhourMonth.setId(IdUtil.simpleUUID());
        buyerDeviceWorkhourMonth.setCreateBy(getUsername());
        return toAjax(buyerDeviceWorkhourMonthService.insertBuyerDeviceWorkhourMonth(buyerDeviceWorkhourMonth));
    }

    /**
     * 修改设备工时分摊月报
     */
    @PreAuthorize("@ss.hasPermi('buyer:devicewkmonth:edit')")
    @Log(title = "设备工时分摊月报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerDeviceWorkhourMonth buyerDeviceWorkhourMonth)
    {
        buyerDeviceWorkhourMonth.setUpdateBy(getUsername());
        return toAjax(buyerDeviceWorkhourMonthService.updateBuyerDeviceWorkhourMonth(buyerDeviceWorkhourMonth));
    }

    /**
     * 删除设备工时分摊月报
     */
    @PreAuthorize("@ss.hasPermi('buyer:devicewkmonth:remove')")
    @Log(title = "设备工时分摊月报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(buyerDeviceWorkhourMonthService.deleteBuyerDeviceWorkhourMonthByIds(ids));
    }
}
