package com.ruoyi.web.controller.zdsz;

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

import com.dtflys.forest.annotation.Post;
import com.ruoyi.zdsz.domain.vo.MaterialStatisticsListVo;
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.ZMaterialStatisticsVo;
import com.ruoyi.zdsz.domain.bo.ZMaterialStatisticsBo;
import com.ruoyi.zdsz.service.IZMaterialStatisticsService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用料统计
 *
 * @author ruoyi
 * @date 2023-12-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zdsz/materialStatistics")
public class ZMaterialStatisticsController extends BaseController {

    private final IZMaterialStatisticsService iZMaterialStatisticsService;

    /**
     * 查询用料统计列表
     */
    //@SaCheckPermission("zdsz:materialStatistics:list")
    @PostMapping("/list")
    public R list(@RequestBody ZMaterialStatisticsBo bo) {
        return R.ok(iZMaterialStatisticsService.queryList(bo));
    }

    /**
     * 导出用料统计列表
     */
//    @SaCheckPermission("zdsz:materialStatistics:export")
    @Log(title = "用料统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZMaterialStatisticsBo bo, HttpServletResponse response) {
        List<MaterialStatisticsListVo> list = iZMaterialStatisticsService.queryList(bo);
        ExcelUtil.exportExcel(list, "用料统计", MaterialStatisticsListVo.class, response);
    }

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

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

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

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