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.ZEngineeringMaterialsResetsVo;
import com.ruoyi.zdsz.domain.bo.ZEngineeringMaterialsResetsBo;
import com.ruoyi.zdsz.service.IZEngineeringMaterialsResetsService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工程用料预设
 *
 * @author ruoyi
 * @date 2023-12-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zdsz/engineeringMaterialsResets")
public class ZEngineeringMaterialsResetsController extends BaseController {

    private final IZEngineeringMaterialsResetsService iZEngineeringMaterialsResetsService;

    /**
     * 查询工程用料预设列表
     */
//    @SaCheckPermission("zdsz:engineeringMaterialsResets:list")
    @GetMapping("/list")
    public TableDataInfo<ZEngineeringMaterialsResetsVo> list(ZEngineeringMaterialsResetsBo bo, PageQuery pageQuery) {
        return iZEngineeringMaterialsResetsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出工程用料预设列表
     */
//    @SaCheckPermission("zdsz:engineeringMaterialsResets:export")
    @Log(title = "工程用料预设", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZEngineeringMaterialsResetsBo bo, HttpServletResponse response) {
        List<ZEngineeringMaterialsResetsVo> list = iZEngineeringMaterialsResetsService.queryList(bo);
        ExcelUtil.exportExcel(list, "工程用料预设", ZEngineeringMaterialsResetsVo.class, response);
    }

    /**
     * 获取工程用料预设详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("zdsz:engineeringMaterialsResets:query")
    @GetMapping("/{id}")
    public R<ZEngineeringMaterialsResetsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iZEngineeringMaterialsResetsService.queryById(id));
    }

    /**
     * 新增工程用料预设
     */
//    @SaCheckPermission("zdsz:engineeringMaterialsResets:add")
    @Log(title = "工程用料预设", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZEngineeringMaterialsResetsBo bo) {
        return toAjax(iZEngineeringMaterialsResetsService.insertByBo(bo));
    }

    /**
     * 修改工程用料预设
     */
//    @SaCheckPermission("zdsz:engineeringMaterialsResets:edit")
    @Log(title = "工程用料预设", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZEngineeringMaterialsResetsBo bo) {
        return toAjax(iZEngineeringMaterialsResetsService.updateByBo(bo));
    }

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