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.ZEnginMaterialQualityVo;
import com.ruoyi.zdsz.domain.bo.ZEnginMaterialQualityBo;
import com.ruoyi.zdsz.service.IZEnginMaterialQualityService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工程材质
 *
 * @author ruoyi
 * @date 2023-12-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zdsz/enginMaterialQuality")
public class ZEnginMaterialQualityController extends BaseController {

    private final IZEnginMaterialQualityService iZEnginMaterialQualityService;

    /**
     * 查询工程材质列表
     */
//    @SaCheckPermission("zdsz:enginMaterialQuality:list")
    @GetMapping("/list")
    public TableDataInfo<ZEnginMaterialQualityVo> list(ZEnginMaterialQualityBo bo, PageQuery pageQuery) {
        return iZEnginMaterialQualityService.queryPageList(bo, pageQuery);
    }
    /**
     * 工程材质下拉
     */
    @GetMapping("/getEnginMaterialQualityList")
    public R getEnginMaterialQualityList(ZEnginMaterialQualityBo enginType) {
        return R.ok(iZEnginMaterialQualityService.getEnginMaterialQualityList(enginType));
    }

    /**
     * 导出工程材质列表
     */
//    @SaCheckPermission("zdsz:enginMaterialQuality:export")
    @Log(title = "工程材质", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZEnginMaterialQualityBo bo, HttpServletResponse response) {
        List<ZEnginMaterialQualityVo> list = iZEnginMaterialQualityService.queryList(bo);
        ExcelUtil.exportExcel(list, "工程材质", ZEnginMaterialQualityVo.class, response);
    }

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

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

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

    /**
     * 删除工程材质
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("zdsz:enginMaterialQuality:remove")
    @Log(title = "工程材质", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        Boolean b = iZEnginMaterialQualityService.deleteWithValidByIds(Arrays.asList(ids), true);
        if (!b){
            return R.fail("材质已绑定规格,不能删除");
        }
        return R.ok("删除成功");
    }
}
