package com.maintain.business.controller;

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

import com.maintain.business.domain.ErpMaterialPickingInfo;
import com.maintain.business.domain.bo.ErpMaterialReturnsInfoBo;
import com.maintain.business.domain.vo.ErpMaterialReturnsInfoVo;
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.maintain.common.annotation.RepeatSubmit;
import com.maintain.common.annotation.Log;
import com.maintain.common.core.controller.BaseController;
import com.maintain.common.core.domain.PageQuery;
import com.maintain.common.core.domain.R;
import com.maintain.common.core.validate.AddGroup;
import com.maintain.common.core.validate.EditGroup;
import com.maintain.common.enums.BusinessType;
import com.maintain.common.utils.poi.ExcelUtil;
import com.maintain.business.domain.vo.ErpMaterialPickingInfoVo;
import com.maintain.business.domain.bo.ErpMaterialPickingInfoBo;
import com.maintain.business.service.IErpMaterialPickingInfoService;
import com.maintain.common.core.page.TableDataInfo;

/**
 * 物料出库明细
 *
 * @author liushuai
 * @date 2025-04-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/materialPickingInfo")
public class ErpMaterialPickingInfoController extends BaseController {

    private final IErpMaterialPickingInfoService iErpMaterialPickingInfoService;

    /**
     * 查询物料出库明细列表
     */
    @SaCheckPermission("business:materialPickingInfo:list")
    @GetMapping("/list")
    public TableDataInfo<ErpMaterialPickingInfoVo> list(ErpMaterialPickingInfoBo bo, PageQuery pageQuery) {
        return iErpMaterialPickingInfoService.customQueryPageList(bo, pageQuery);
    }


    /**
     * 查询物料退货明细列表
     */
    @GetMapping("/listAll")
    public R<List<ErpMaterialPickingInfoVo>> listAll(ErpMaterialPickingInfoBo bo) {
        return R.ok(iErpMaterialPickingInfoService.customQueryList(bo));
    }

    /**
     * 导出物料出库明细列表
     */
    @SaCheckPermission("business:materialPickingInfo:export")
    @Log(title = "物料出库明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpMaterialPickingInfoBo bo, HttpServletResponse response) {
        List<ErpMaterialPickingInfoVo> list = iErpMaterialPickingInfoService.customQueryList(bo);
        ExcelUtil.exportExcel(list, "物料出库明细", ErpMaterialPickingInfoVo.class, response);
    }

    /**
     * 获取物料出库明细详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:materialPickingInfo:query")
    @GetMapping("/{id}")
    public R<ErpMaterialPickingInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpMaterialPickingInfoService.queryById(id));
    }

    /**
     * 新增物料出库明细
     */
    @SaCheckPermission("business:materialPickingInfo:add")
    @Log(title = "物料出库明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpMaterialPickingInfoBo bo) {
        return toAjax(iErpMaterialPickingInfoService.insertByBo(bo));
    }

    /**
     * 修改物料出库明细
     */
    @SaCheckPermission("business:materialPickingInfo:edit")
    @Log(title = "物料出库明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpMaterialPickingInfoBo bo) {
        return toAjax(iErpMaterialPickingInfoService.updateByBo(bo));
    }

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