package com.maintain.business.controller;

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

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.ErpSettlementMaintainRepairFormVo;
import com.maintain.business.domain.bo.ErpSettlementMaintainRepairFormBo;
import com.maintain.business.service.IErpSettlementMaintainRepairFormService;
import com.maintain.common.core.page.TableDataInfo;

/**
 * 结算单与报修单关联
 *
 * @author liushuai
 * @date 2025-04-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/settlementMaintainRepairForm")
public class ErpSettlementMaintainRepairFormController extends BaseController {

    private final IErpSettlementMaintainRepairFormService iErpSettlementMaintainRepairFormService;

    /**
     * 查询结算单与报修单关联列表
     */
    @SaCheckPermission("business:settlementMaintainRepairForm:list")
    @GetMapping("/list")
    public TableDataInfo<ErpSettlementMaintainRepairFormVo> list(ErpSettlementMaintainRepairFormBo bo, PageQuery pageQuery) {
        return iErpSettlementMaintainRepairFormService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出结算单与报修单关联列表
     */
    @SaCheckPermission("business:settlementMaintainRepairForm:export")
    @Log(title = "结算单与报修单关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpSettlementMaintainRepairFormBo bo, HttpServletResponse response) {
        List<ErpSettlementMaintainRepairFormVo> list = iErpSettlementMaintainRepairFormService.queryList(bo);
        ExcelUtil.exportExcel(list, "结算单与报修单关联", ErpSettlementMaintainRepairFormVo.class, response);
    }

    /**
     * 获取结算单与报修单关联详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:settlementMaintainRepairForm:query")
    @GetMapping("/{id}")
    public R<ErpSettlementMaintainRepairFormVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpSettlementMaintainRepairFormService.queryById(id));
    }

    /**
     * 新增结算单与报修单关联
     */
    @SaCheckPermission("business:settlementMaintainRepairForm:add")
    @Log(title = "结算单与报修单关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSettlementMaintainRepairFormBo bo) {
        return toAjax(iErpSettlementMaintainRepairFormService.insertByBo(bo));
    }
    /**
     * 新增结算单与报修单关联
     */
    @SaCheckPermission("business:settlementMaintainRepairForm:addBatch")
    @Log(title = "结算单与报修单关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/addBatch")
    public R<Void> addBatch(@Validated(AddGroup.class) @RequestBody List<ErpSettlementMaintainRepairFormBo> bos) {
        return toAjax(iErpSettlementMaintainRepairFormService.insertBatch(bos));
    }

    /**
     * 修改结算单与报修单关联
     */
    @SaCheckPermission("business:settlementMaintainRepairForm:edit")
    @Log(title = "结算单与报修单关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSettlementMaintainRepairFormBo bo) {
        return toAjax(iErpSettlementMaintainRepairFormService.updateByBo(bo));
    }

    /**
     * 删除结算单与报修单关联
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:settlementMaintainRepairForm:remove")
    @Log(title = "结算单与报修单关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSettlementMaintainRepairFormService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
    /**
     * 根据报修单主键删除结算单与报修单关联
     *
     * @param repairFormIds 主键串
     */
    @SaCheckPermission("business:settlementMaintainRepairForm:removeByRepairFormIds")
    @Log(title = "结算单与报修单关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{repairFormIds}")
    public R<Void> removeByRepairFormIds(@NotEmpty(message = "报修单主键不能为空")
                          @PathVariable Long[] repairFormIds) {
        return toAjax(iErpSettlementMaintainRepairFormService.deleteByRepairFormIds(Arrays.asList(repairFormIds), true));
    }

}
