package com.maintain.business.controller;

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

import com.maintain.business.domain.bo.ErpRepairFormProjectBatchBo;
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.ErpRepairFormProjectVo;
import com.maintain.business.domain.bo.ErpRepairFormProjectBo;
import com.maintain.business.service.IErpRepairFormProjectService;
import com.maintain.common.core.page.TableDataInfo;

/**
 * 报修单-维修项目\检验项目
 *
 * @author liushuai
 * @date 2025-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/repairFormProject")
public class ErpRepairFormProjectController extends BaseController {

    private final IErpRepairFormProjectService iErpRepairFormProjectService;

    /**
     * 查询报修单-维修项目\检验项目列表
     */
    @SaCheckPermission("business:repairFormProject:list")
    @GetMapping("/list")
    public TableDataInfo<ErpRepairFormProjectVo> list(ErpRepairFormProjectBo bo, PageQuery pageQuery) {
        return iErpRepairFormProjectService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出报修单-维修项目/检验项目列表
     */
    @SaCheckPermission("business:repairFormProject:export")
    @Log(title = "报修单-维修项目/检验项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpRepairFormProjectBo bo, HttpServletResponse response) {
        List<ErpRepairFormProjectVo> list = iErpRepairFormProjectService.queryList(bo);
        ExcelUtil.exportExcel(list, "报修单-维修项目/检验项目", ErpRepairFormProjectVo.class, response);
    }

    /**
     * 获取报修单-维修项目\检验项目详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:repairFormProject:query")
    @GetMapping("/{id}")
    public R<ErpRepairFormProjectVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpRepairFormProjectService.queryById(id));
    }

    /**
     * 批量新增维修项目
     */
    @SaCheckPermission("business:repairFormProject:add")
    @Log(title = "批量新增维修项目", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/batch")
    public R<Void> addBatch(@Validated(AddGroup.class) @RequestBody ErpRepairFormProjectBatchBo bo) {
        return toAjax(iErpRepairFormProjectService.insertBatchByBo(bo));
    }

    /**
     * 新增报修单-维修项目/检验项目
     */
    @SaCheckPermission("business:repairFormProject:add")
    @Log(title = "报修单-维修项目/检验项目", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpRepairFormProjectBo bo) {
        return toAjax(iErpRepairFormProjectService.insertByBo(bo));
    }

    /**
     * 修改报修单-维修项目/检验项目
     */
    @SaCheckPermission("business:repairFormProject:edit")
    @Log(title = "报修单-维修项目/检验项目", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpRepairFormProjectBo bo) {
        return toAjax(iErpRepairFormProjectService.updateByBo(bo));
    }

    /**
     * 删除报修单-维修项目/检验项目
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:repairFormProject:remove")
    @Log(title = "报修单-维修项目/检验项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpRepairFormProjectService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
