package cn.ezhizao.project.business.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.framework.web.page.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
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 cn.ezhizao.project.business.domain.BizDayworkItemHistory;
import cn.ezhizao.project.business.service.IBizDayworkItemHistoryService;

/**
 * 报工修改历史Controller
 *
 * @author ezhizao
 * @date 2024-07-17
 */
@RestController
@RequestMapping("/business/dayworkItemHistory")
public class BizDayworkItemHistoryController extends BaseController
{
    @Resource
    private IBizDayworkItemHistoryService bizDayworkItemHistoryService;

    /**
     * 查询报工修改历史列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BizDayworkItemHistory bizDayworkItemHistory) throws NoSuchFieldException, IllegalAccessException
    {
        List<BizDayworkItemHistory> list = bizDayworkItemHistoryService.getList(bizDayworkItemHistory);
        return getDataTable(list);
    }

    /**
     * 导出报工修改历史列表
     */
    @Log(title = "报工修改历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizDayworkItemHistory bizDayworkItemHistory) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizDayworkItemHistory);
        List<BizDayworkItemHistory> list = bizDayworkItemHistoryService.getList(bizDayworkItemHistory);
        ExcelUtil<BizDayworkItemHistory> util = new ExcelUtil<BizDayworkItemHistory>(BizDayworkItemHistory.class);
        util.exportExcel(response, list, "报工修改历史数据");
    }

    /**
     * 获取报工修改历史详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizDayworkItemHistoryService.getById(id));
    }

    /**
     * 新增报工修改历史
     */
    @PreAuthorize("@ss.hasPermi('business:dayworkItemHistory:add')")
    @Log(title = "报工修改历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizDayworkItemHistory bizDayworkItemHistory) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizDayworkItemHistory);
        return toAjax(bizDayworkItemHistoryService.save(bizDayworkItemHistory));
    }

    /**
     * 修改报工修改历史
     */
    @PreAuthorize("@ss.hasPermi('business:dayworkItemHistory:edit')")
    @Log(title = "报工修改历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizDayworkItemHistory bizDayworkItemHistory) throws NoSuchFieldException, IllegalAccessException
    {
        // 判断当前报工的历史记录
        setTenantId(bizDayworkItemHistory);
        return toAjax(bizDayworkItemHistoryService.updateById(bizDayworkItemHistory));
    }

    /**
     * 删除报工修改历史
     */
    @PreAuthorize("@ss.hasPermi('business:dayworkItemHistory:remove')")
    @Log(title = "报工修改历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizDayworkItemHistoryService.removeBatchByIds(ids));
    }
}
