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.BuyerEmpWorkhourMonth;
import com.ruoyi.buyerapi.service.IBuyerEmpWorkhourMonthService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工工时分摊月报Controller
 *
 * @author ruoyi
 * @date 2022-09-22
 */
@RestController
@RequestMapping("/buyer/empwhmonth")
public class BuyerEmpWorkhourMonthController extends BaseController
{
    @Autowired
    private IBuyerEmpWorkhourMonthService buyerEmpWorkhourMonthService;

    /**
     * 查询员工工时分摊月报列表
     */
    @PreAuthorize("@ss.hasPermi('buyer:empwhmonth:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuyerEmpWorkhourMonth buyerEmpWorkhourMonth)
    {
        startPage();
        buyerEmpWorkhourMonth.setCompanyId(SecurityUtils.getCompanyId());
        List<BuyerEmpWorkhourMonth> list = buyerEmpWorkhourMonthService.selectBuyerEmpWorkhourMonthList(buyerEmpWorkhourMonth);
        return getDataTable(list);
    }

    /**
     * 导出员工工时分摊月报列表
     */
    @PreAuthorize("@ss.hasPermi('buyer:empwhmonth:export')")
    @Log(title = "员工工时分摊月报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyerEmpWorkhourMonth buyerEmpWorkhourMonth)
    {
        List<BuyerEmpWorkhourMonth> list = buyerEmpWorkhourMonthService.selectBuyerEmpWorkhourMonthList(buyerEmpWorkhourMonth);
        ExcelUtil<BuyerEmpWorkhourMonth> util = new ExcelUtil<BuyerEmpWorkhourMonth>(BuyerEmpWorkhourMonth.class);
        util.exportExcel(response, list, "员工工时分摊月报数据");
    }

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

    /**
     * 新增员工工时分摊月报
     */
    @PreAuthorize("@ss.hasPermi('buyer:empwhmonth:add')")
    @Log(title = "员工工时分摊月报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyerEmpWorkhourMonth buyerEmpWorkhourMonth)
    {
        buyerEmpWorkhourMonth.setId(IdUtil.simpleUUID());
        buyerEmpWorkhourMonth.setCreateBy(getUsername());
        return toAjax(buyerEmpWorkhourMonthService.insertBuyerEmpWorkhourMonth(buyerEmpWorkhourMonth));
    }

    /**
     * 修改员工工时分摊月报
     */
    @PreAuthorize("@ss.hasPermi('buyer:empwhmonth:edit')")
    @Log(title = "员工工时分摊月报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyerEmpWorkhourMonth buyerEmpWorkhourMonth)
    {
        buyerEmpWorkhourMonth.setUpdateBy(getUsername());
        return toAjax(buyerEmpWorkhourMonthService.updateBuyerEmpWorkhourMonth(buyerEmpWorkhourMonth));
    }

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