package com.ruoyi.web.controller.zdsz;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
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.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zdsz.domain.bo.ZEngineeringGasOpeningBo;
import com.ruoyi.zdsz.domain.bo.ZEngineeringReviewBo;
import com.ruoyi.zdsz.domain.vo.ZEngineeringGasOpeningVo;
import com.ruoyi.zdsz.domain.vo.ZEngineeringIndustryTypeVo;
import com.ruoyi.zdsz.service.IZEngineeringGasOpeningService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 开栓施工
 *
 * @author ruoyi
 * @date 2024-01-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zdsz/engineeringGasOpening")
public class ZEngineeringGasOpeningController extends BaseController {

    private final IZEngineeringGasOpeningService iZEngineeringGasOpeningService;

    /**
     * 查询开栓施工列表
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:list")
    @GetMapping("/list")
    public TableDataInfo<ZEngineeringGasOpeningVo> list(ZEngineeringGasOpeningBo bo, PageQuery pageQuery, String enginType) {
//        bo.setType(type);
//        bo.setEnginType(enginType);
//        System.out.println("enginType==="+enginType);
        return iZEngineeringGasOpeningService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出开栓施工列表
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:export")
    @Log(title = "开栓施工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZEngineeringGasOpeningBo bo, HttpServletResponse response) {
        List<ZEngineeringGasOpeningVo> list = iZEngineeringGasOpeningService.queryList(bo);
        ExcelUtil.exportExcel(list, "带气封堵施工", ZEngineeringGasOpeningVo.class, response);
    }

    /**
     * 获取开栓施工详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:query")
    @GetMapping("/{id}")
    public R<ZEngineeringGasOpeningVo> getInfo(@NotNull(message = "主键不能为空")@PathVariable String id) {
        return R.ok(iZEngineeringGasOpeningService.queryById(id));
    }

    /**
     * 新增开栓施工
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:add")
    @Log(title = "开栓施工", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZEngineeringGasOpeningBo bo) {
        return toAjax(iZEngineeringGasOpeningService.insertByBo(bo));
    }

    /**
     * 修改开栓施工
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:edit")
    @Log(title = "开栓施工", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZEngineeringGasOpeningBo bo) {
        return toAjax(iZEngineeringGasOpeningService.updateByBo(bo));
    }

    /**
     * 删除开栓施工
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:remove")
    @Log(title = "开栓施工", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")@PathVariable String[] ids) {
        return toAjax(iZEngineeringGasOpeningService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 开栓施工历史
     *
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:query")
    @GetMapping("/{id}/{type}")
    public R<ZEngineeringGasOpeningVo> query(@NotNull(message = "主键不能为空") @PathVariable String id, @PathVariable String type) {
//        return R.ok(iZEngineeringGasOpeningService.query(id, type));
        return R.ok(iZEngineeringGasOpeningService.query(id, "带气封堵施工"));
    }

}
