package cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeetingdetail;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeetingdetail.vo.*;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotoperationmeetingdetail.IotOperationMeetingDetailDO;
import cn.iocoder.yudao.module.pms.service.iotoperationmeetingdetail.IotOperationMeetingDetailService;

@Tag(name = "管理后台 - 生产运营会明细")
@RestController
@RequestMapping("/pms/iot-operation-meeting-detail")
@Validated
public class IotOperationMeetingDetailController {

    @Resource
    private IotOperationMeetingDetailService iotOperationMeetingDetailService;

    @PostMapping("/create")
    @Operation(summary = "创建生产运营会明细")
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-detail:create')")
    public CommonResult<Long> createIotOperationMeetingDetail(@Valid @RequestBody IotOperationMeetingDetailSaveReqVO createReqVO) {
        return success(iotOperationMeetingDetailService.createIotOperationMeetingDetail(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新生产运营会明细")
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-detail:update')")
    public CommonResult<Boolean> updateIotOperationMeetingDetail(@Valid @RequestBody IotOperationMeetingDetailSaveReqVO updateReqVO) {
        iotOperationMeetingDetailService.updateIotOperationMeetingDetail(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除生产运营会明细")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-detail:delete')")
    public CommonResult<Boolean> deleteIotOperationMeetingDetail(@RequestParam("id") Long id) {
        iotOperationMeetingDetailService.deleteIotOperationMeetingDetail(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得生产运营会明细")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-detail:query')")
    public CommonResult<IotOperationMeetingDetailRespVO> getIotOperationMeetingDetail(@RequestParam("id") Long id) {
        IotOperationMeetingDetailDO iotOperationMeetingDetail = iotOperationMeetingDetailService.getIotOperationMeetingDetail(id);
        return success(BeanUtils.toBean(iotOperationMeetingDetail, IotOperationMeetingDetailRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得生产运营会明细分页")
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-detail:query')")
    public CommonResult<PageResult<IotOperationMeetingDetailRespVO>> getIotOperationMeetingDetailPage(@Valid IotOperationMeetingDetailPageReqVO pageReqVO) {
        PageResult<IotOperationMeetingDetailDO> pageResult = iotOperationMeetingDetailService.getIotOperationMeetingDetailPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, IotOperationMeetingDetailRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出生产运营会明细 Excel")
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-detail:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportIotOperationMeetingDetailExcel(@Valid IotOperationMeetingDetailPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<IotOperationMeetingDetailDO> list = iotOperationMeetingDetailService.getIotOperationMeetingDetailPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "生产运营会明细.xls", "数据", IotOperationMeetingDetailRespVO.class,
                        BeanUtils.toBean(list, IotOperationMeetingDetailRespVO.class));
    }

}