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.ZEngineeringMaterialVo;
import com.ruoyi.zdsz.domain.bo.ZEngineeringMaterialBo;
import com.ruoyi.zdsz.service.IZEngineeringMaterialService;
import com.ruoyi.common.core.page.TableDataInfo;

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

    private final IZEngineeringMaterialService iZEngineeringMaterialService;

    /**
     * 查询工程用料列表
     */
//    @SaCheckPermission("zdsz:engineeringMaterial:list")
    @GetMapping("/list")
    public TableDataInfo<ZEngineeringMaterialVo> list(ZEngineeringMaterialBo bo, PageQuery pageQuery) {
        return iZEngineeringMaterialService.queryPageList(bo, pageQuery);
    }

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

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

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

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

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