package cn.ezhizao.project.business.onwork.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
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.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
import cn.ezhizao.project.business.onwork.domain.BizOnceworkDetail;
import cn.ezhizao.project.business.onwork.service.IBizOnceworkDetailService;
import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * 单次任务进度详情Controller
 *
 * @author ruoyi
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/business/onceWorkDetail")
public class BizOnceworkDetailController extends BaseController
{
    @Resource
    private IBizOnceworkDetailService bizOnceworkDetailService;

    /**
     * 查询单次任务进度详情列表
     */
    @PreAuthorize("@ss.hasPermi('business:production:onceWork:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizOnceworkDetail bizOnceworkDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizOnceworkDetail);
        List<BizOnceworkDetail> list = bizOnceworkDetailService.getList(bizOnceworkDetail);
        return getDataTable(list);
    }

    /**
     * 导出单次任务进度详情列表
     */
    @PreAuthorize("@ss.hasPermi('business:production:onceexport')")
    @Log(title = "单次任务进度详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizOnceworkDetail bizOnceworkDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizOnceworkDetail);
        List<BizOnceworkDetail> list = bizOnceworkDetailService.getList(bizOnceworkDetail);
        ExcelUtil<BizOnceworkDetail> util = new ExcelUtil<BizOnceworkDetail>(BizOnceworkDetail.class);
        util.exportExcel(response, list, "单次任务进度详情数据");
    }

    /**
     * 获取单次任务进度详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:production:onceWork:list')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizOnceworkDetailService.getById(id));
    }

    /**
     * 新增单次任务进度详情
     */
    @PreAuthorize("@ss.hasPermi('business:production:onceWork:edit')")
    @Log(title = "单次任务进度详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizOnceworkDetail bizOnceworkDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizOnceworkDetail);
        return toAjax(bizOnceworkDetailService.save(bizOnceworkDetail));
    }

    /**
     * 修改单次任务进度详情
     */
    @PreAuthorize("@ss.hasPermi('business:production:onceWork:edit')")
    @Log(title = "单次任务进度详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizOnceworkDetail bizOnceworkDetail) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizOnceworkDetail);
        return toAjax(bizOnceworkDetailService.updateById(bizOnceworkDetail));
    }

    /**
     * 删除单次任务进度详情
     */
    @PreAuthorize("@ss.hasPermi('business:production:onceWork:remove')")
    @Log(title = "单次任务进度详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizOnceworkDetailService.removeBatchByIds(ids));
    }
    @PreAuthorize("@ss.hasPermi('business:production:onceWork:insert')")
    @Log(title = "单次任务添加", businessType = BusinessType.INSERT)
    @RequestMapping("/addOnWorkDetail")
    public AjaxResult addOnWorkDetail(@RequestBody BizOnceworkDetail bizOnceworkDetail){
        bizOnceworkDetail.setUserName(getLoginUser().getUser().getNickName());
        bizOnceworkDetail.setTenantId(getTenantId());
        bizOnceworkDetail.setUserId(getUserId());
        return success(bizOnceworkDetailService.save(bizOnceworkDetail));
    }
    @PreAuthorize("@ss.hasPermi('business:production:onceWork:edit')")
    @Log(title = "单次任务详情修改", businessType = BusinessType.INSERT)
    @RequestMapping("/updateOnWorkDetail")
    public AjaxResult updateOnWorkDetail(@RequestBody BizOnceworkDetail bizOnceworkDetail){
        return success(bizOnceworkDetailService.updateById(bizOnceworkDetail));
    }

}
