package com.ruoyi.pay.controller;

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

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.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.pay.domain.vo.PayProductMaterialVo;
import com.ruoyi.pay.domain.bo.PayProductMaterialBo;
import com.ruoyi.pay.service.IPayProductMaterialService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品毛料关联
 *
 * @author ruoyi
 * @date 2025-05-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pay/productMaterial")
public class PayProductMaterialController extends BaseController {

    private final IPayProductMaterialService iPayProductMaterialService;

    /**
     * 查询产品毛料关联列表
     */
    @SaCheckPermission("pay:productMaterial:list")
    @GetMapping("/list")
    public TableDataInfo<PayProductMaterialVo> list(PayProductMaterialBo bo, PageQuery pageQuery) {
        return iPayProductMaterialService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出产品毛料关联列表
     */
    @SaCheckPermission("pay:productMaterial:export")
    @Log(title = "产品毛料关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PayProductMaterialBo bo, HttpServletResponse response) {
        List<PayProductMaterialVo> list = iPayProductMaterialService.queryList(bo);
        ExcelUtil.exportExcel(list, "产品毛料关联", PayProductMaterialVo.class, response);
    }

    /**
     * 获取产品毛料关联详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("pay:productMaterial:query")
    @GetMapping("/{id}")
    public R<PayProductMaterialVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iPayProductMaterialService.queryById(id));
    }

    /**
     * 新增产品毛料关联
     */
    @SaCheckPermission("pay:productMaterial:add")
    @Log(title = "产品毛料关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PayProductMaterialBo bo) {
        return toAjax(iPayProductMaterialService.insertByBo(bo));
    }

    /**
     * 修改产品毛料关联
     */
    @SaCheckPermission("pay:productMaterial:edit")
    @Log(title = "产品毛料关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PayProductMaterialBo bo) {
        return toAjax(iPayProductMaterialService.updateByBo(bo));
    }

    /**
     * 删除产品毛料关联
     *
     * @param ids 主键串
     */
    @SaCheckPermission("pay:productMaterial:remove")
    @Log(title = "产品毛料关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iPayProductMaterialService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
