package com.maintain.business.controller;

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

import com.maintain.business.domain.bo.ErpRepairFormProjectDispatchBatchBo;
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.ErpRepairFormProjectDispatchVo;
import com.maintain.business.domain.bo.ErpRepairFormProjectDispatchBo;
import com.maintain.business.service.IErpRepairFormProjectDispatchService;
import com.maintain.common.core.page.TableDataInfo;

/**
 * 报修单-报修项目-派工
 *
 * @author liushuai
 * @date 2025-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/repairFormProjectDispatch")
public class ErpRepairFormProjectDispatchController extends BaseController {

    private final IErpRepairFormProjectDispatchService iErpRepairFormProjectDispatchService;

    /**
     * 查询报修单-报修项目-派工列表
     */
    @SaCheckPermission("business:repairFormProjectDispatch:list")
    @GetMapping("/list")
    public TableDataInfo<ErpRepairFormProjectDispatchVo> list(ErpRepairFormProjectDispatchBo bo, PageQuery pageQuery) {
        return iErpRepairFormProjectDispatchService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出报修单-报修项目-派工列表
     */
    @SaCheckPermission("business:repairFormProjectDispatch:export")
    @Log(title = "报修单-报修项目-派工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpRepairFormProjectDispatchBo bo, HttpServletResponse response) {
        List<ErpRepairFormProjectDispatchVo> list = iErpRepairFormProjectDispatchService.queryList(bo);
        ExcelUtil.exportExcel(list, "报修单-报修项目-派工", ErpRepairFormProjectDispatchVo.class, response);
    }

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

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

    /**
     * 报修项目-派工批量创建
     */
    @SaCheckPermission("business:repairFormProjectDispatch:add")
    @Log(title = "报修单-报修项目-派工", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/dispatch")
    public R<Void> addBatch(@Validated(AddGroup.class) @RequestBody ErpRepairFormProjectDispatchBatchBo bo) {
        return toAjax(iErpRepairFormProjectDispatchService.insertBatchByBo(bo));
    }

    /**
     * 修改报修单-报修项目-派工
     */
    @SaCheckPermission("business:repairFormProjectDispatch:edit")
    @Log(title = "报修单-报修项目-派工", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpRepairFormProjectDispatchBo bo) {
        return toAjax(iErpRepairFormProjectDispatchService.updateByBo(bo));
    }

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