package com.ruoyi.web.controller.zdsz;

import java.util.Date;
import java.util.List;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.zdsz.domain.vo.ZEngineeringIndustryVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.beans.factory.annotation.Autowired;
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.ZEngineeringDangerousVo;
import com.ruoyi.zdsz.domain.bo.ZEngineeringDangerousBo;
import com.ruoyi.zdsz.service.IZEngineeringDangerousService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 危险工程
 *
 * @author ruoyi
 * @date 2024-01-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zdsz/engineeringDangerous")
public class ZEngineeringDangerousController extends BaseController {

    @Autowired
    private IZEngineeringDangerousService iZEngineeringDangerousService;

    @PostMapping("review")
    public R<?> review(@RequestBody ZEngineeringDangerousBo zEngineeringDangerousBo) {
        boolean review = iZEngineeringDangerousService.review(zEngineeringDangerousBo);
        return toAjax(review);
    }

    /**
     * 查询危险工程列表
     */
//    @SaCheckPermission("zdsz:engineeringDangerous:list")
    @GetMapping("/list")
    public TableDataInfo<ZEngineeringDangerousVo> list(ZEngineeringDangerousBo bo, PageQuery pageQuery) {
        return iZEngineeringDangerousService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出危险工程列表
     */
//    @SaCheckPermission("zdsz:engineeringDangerous:export")
    @Log(title = "危险工程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZEngineeringDangerousBo bo, HttpServletResponse response) {
        List<ZEngineeringDangerousVo> list = iZEngineeringDangerousService.queryList(bo);
        ExcelUtil.exportExcel(list, "危险工程", ZEngineeringDangerousVo.class, response);
    }

    /**
     * 获取危险工程详细信息
     *
     * @param
     */
//    @SaCheckPermission("zdsz:engineeringDangerous:query")
    @GetMapping("/query/{id}")
    public R<ZEngineeringDangerousVo> query(@NotNull(message = "主键不能为空")
                                                @PathVariable String id) {
        return R.ok(iZEngineeringDangerousService.queryById(id));
    }

    /**
     * 新增危险工程
     */
//    @SaCheckPermission("zdsz:engineeringDangerous:add")
    @Log(title = "危险工程", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZEngineeringDangerousBo bo) {
        bo.setCreateTime(new Date());
        return toAjax(iZEngineeringDangerousService.insertByBo(bo));
    }

    /**
     * 修改危险工程
     */
//    @SaCheckPermission("zdsz:engineeringDangerous:edit")
    @Log(title = "危险工程", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZEngineeringDangerousBo bo) {
        return toAjax(iZEngineeringDangerousService.updateByBo(bo));
    }

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

    /**
     * 危险工程历史
     *
     */
//    @SaCheckPermission("zdsz:engineeringIndustry:query")
    @GetMapping("/{id}")
    public R<ZEngineeringDangerousVo> queryEngineeringDangerous(@NotNull(message = "主键不能为空") @PathVariable String id) {
        return R.ok(iZEngineeringDangerousService.queryEngineeringDangerous(id));
    }

    /**
     * 危险工程-下拉
     *
     */
//    @SaCheckPermission("zdsz:engineeringDangerous:list")
    @GetMapping("/nameAndIdList")
    public R<List<Map<String, Object>>> selectEnginNameAndId(ZEngineeringDangerousBo bo) {
        return R.ok(iZEngineeringDangerousService.selectEnginNameAndId(bo));
    }
}
