package com.ruoyi.oa.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.oa.domain.bo.SysOaOutWarehouseBoList;
import com.ruoyi.oa.domain.vo.SysOaOutWarehouseListVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
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.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.oa.domain.vo.SysOaWarehouseDetailVo;
import com.ruoyi.oa.domain.bo.SysOaWarehouseDetailBo;
import com.ruoyi.oa.service.ISysOaWarehouseDetailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库出库
 *
 * @author liuzongkun999
 * @date 2024-11-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oa/oaOutWarehouse")
public class SysOaWarehouseDetailController extends BaseController {

    private final ISysOaWarehouseDetailService iSysOaWarehouseDetailService;



    /**
     * 查询仓库出库列表
     */
    @GetMapping("/list")
    public TableDataInfo<SysOaOutWarehouseListVo> list(SysOaWarehouseDetailBo bo, PageQuery pageQuery) {
        return iSysOaWarehouseDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出仓库出库列表
     */
    @Log(title = "仓库出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysOaWarehouseDetailBo bo, HttpServletResponse response) {
        List<SysOaWarehouseDetailVo> list = iSysOaWarehouseDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "仓库出库", SysOaWarehouseDetailVo.class, response);
    }

    /**
     * 获取仓库出库详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<SysOaWarehouseDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iSysOaWarehouseDetailService.queryById(id));
    }

    /**
     * 查询仓库出库产品id的列表
     *
     * @param WarehouseId 出库产品id
     */
    @GetMapping("/WarehouseIdList/{WarehouseId}")
    public TableDataInfo<SysOaWarehouseDetailVo> ListByWarehouseId(@NotNull(message = "出库产品ID不能为空")
                                                                    @PathVariable Long WarehouseId) {
        return iSysOaWarehouseDetailService.queryWarehouseIdList(WarehouseId);
    }

    /**
     * 查询仓库出库产品id的列表
     *
     * @param projectId 出库产品id
     */
    @GetMapping("/project/{projectId}")
    public TableDataInfo<SysOaWarehouseDetailVo> queryOutWarehouseByProjectId(@NotNull(message = "项目名不能为空")
                                                                    @PathVariable Long projectId) {
        return iSysOaWarehouseDetailService.queryOutWarehouseByProjectId(projectId);
    }



    /**
     * 新增仓库出库
     */
    @Log(title = "仓库出库", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysOaWarehouseDetailBo bo) {
        return toAjax(iSysOaWarehouseDetailService.insertByBo(bo));
    }

    /**
     * 修改仓库出库
     */
    @Log(title = "仓库出库", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysOaWarehouseDetailBo bo) {
        return toAjax(iSysOaWarehouseDetailService.updateByBo(bo));
    }

    /**
     * 删除仓库出库
     *
     * @param ids 主键串
     */
    @Log(title = "仓库出库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSysOaWarehouseDetailService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
