package com.ruoyi.web.controller.zdsz;

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.zdsz.domain.vo.ZComprehensiveVo;
import com.ruoyi.zdsz.domain.bo.ZComprehensiveBo;
import com.ruoyi.zdsz.service.IZComprehensiveService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 开栓|安检|维修
 *
 * @author ruoyi
 * @date 2023-12-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zdsz/openbolt")
public class ZComprehensiveController extends BaseController {

    private final IZComprehensiveService iZComprehensiveService;

    /**
     * 查询开栓|安检|维修列表
     */
    @GetMapping("/list")
    public TableDataInfo<ZComprehensiveVo> list(@Validated(QueryGroup.class) ZComprehensiveBo bo, PageQuery pageQuery) {
        return iZComprehensiveService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出开栓|安检|维修列表
     */
    @Log(title = "开栓|安检|维修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZComprehensiveBo bo, HttpServletResponse response) {
        List<ZComprehensiveVo> list = iZComprehensiveService.queryList(bo);
        ExcelUtil.exportExcel(list, "开栓|安检|维修", ZComprehensiveVo.class, response);
    }

    /**
     * 获取开栓|安检|维修详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ZComprehensiveVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iZComprehensiveService.queryById(id));
    }

    /**
     * 新增开栓|安检|维修
     */
    @Log(title = "开栓|安检|维修", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZComprehensiveBo bo) {
        if (bo.getPicIds() == null || bo.getPicIds().isEmpty()) {
            return R.fail("照片必须上传！");
        }
        return toAjax(iZComprehensiveService.insertByBo(bo));
    }

    /**
     * 修改开栓|安检|维修
     */
    @Log(title = "开栓|安检|维修", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZComprehensiveBo bo) {
        if (bo.getPicIds() == null || bo.getPicIds().isEmpty()) {
            return R.fail("照片必须上传！");
        }
        return toAjax(iZComprehensiveService.updateByBo(bo));
    }

    /**
     * 删除开栓|安检|维修
     *
     * @param ids 主键串
     */
    @Log(title = "开栓|安检|维修", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iZComprehensiveService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
