package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.oa.service.ISysOaTaskService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.vo.SysOaTaskItemVo;
import com.ruoyi.oa.domain.bo.SysOaTaskItemBo;
import com.ruoyi.oa.service.ISysOaTaskItemService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报工任务单元
 *
 * @author hdka
 * @date 2025-03-27
 */
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/oaTaskItem")
public class SysOaTaskItemController extends BaseController {

    private final ISysOaTaskItemService iSysOaTaskItemService;

    private final ISysOaTaskService iSysOaTaskService;

    /**
     * 查询报工任务单元列表
     */
    @GetMapping("/list")
    public TableDataInfo<SysOaTaskItemVo> list(SysOaTaskItemBo bo, PageQuery pageQuery) {
        return iSysOaTaskItemService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出报工任务单元列表
     */
    @Log(title = "报工任务单元", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysOaTaskItemBo bo, HttpServletResponse response) {
        List<SysOaTaskItemVo> list = iSysOaTaskItemService.queryList(bo);
        ExcelUtil.exportExcel(list, "报工任务单元", SysOaTaskItemVo.class, response);
    }

    /**
     * 获取报工任务单元详细信息
     *
     * @param itemId 主键
     */
    @GetMapping("/{itemId}")
    public R<SysOaTaskItemVo> getInfo(@NotNull(message = "主键不能为空")
                                      @PathVariable Long itemId) {
        System.out.println(itemId);
        return R.ok(iSysOaTaskItemService.queryById(itemId));
    }

    /**
     * 新增报工任务单元
     */
    @Log(title = "报工任务单元", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysOaTaskItemBo bo) {
        return toAjax(iSysOaTaskItemService.insertByBo(bo));
    }

    /**
     * 修改报工任务单元
     */
    @Log(title = "报工任务单元", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysOaTaskItemBo bo) {
        return toAjax(iSysOaTaskItemService.updateByBo(bo));
    }

    /**
     * 修改报工任务单元
     */
    @Log(title = "报工任务单元", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping("/reportSubmit")
    public R<Void> reportSubmit(@Validated(EditGroup.class) @RequestBody SysOaTaskItemBo bo) {
        return toAjax(iSysOaTaskItemService.reportSubmit(bo));
    }

    /**
     * 删除报工任务单元
     *
     * @param itemIds 主键串
     */
    @DeleteMapping("/{itemIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] itemIds) {
        return toAjax(iSysOaTaskItemService.deleteWithValidByIds(Arrays.asList(itemIds), true));
    }
}
