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

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeetingattrs.vo.IotOperationMeetingAttrsPageReqVO;
import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeetingattrs.vo.IotOperationMeetingAttrsRespVO;
import cn.iocoder.yudao.module.pms.controller.admin.iotoperationmeetingattrs.vo.IotOperationMeetingAttrsSaveReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotoperationmeetingattrs.IotOperationMeetingAttrsDO;
import cn.iocoder.yudao.module.pms.service.iotoperationmeetingattrs.IotOperationMeetingAttrsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 专业公司工作量扩展属性")
@RestController
@RequestMapping("/pms/iot-operation-meeting-attrs")
@Validated
public class IotOperationMeetingAttrsController {

    @Resource
    private IotOperationMeetingAttrsService iotOperationMeetingAttrsService;

    @PostMapping("/create")
    @Operation(summary = "创建专业公司工作量扩展属性")
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-attrs:create')")
    public CommonResult<Long> createIotOperationMeetingAttrs(@Valid @RequestBody IotOperationMeetingAttrsSaveReqVO createReqVO) {
        return success(iotOperationMeetingAttrsService.createIotOperationMeetingAttrs(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新专业公司工作量扩展属性")
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-attrs:update')")
    public CommonResult<Boolean> updateIotOperationMeetingAttrs(@Valid @RequestBody IotOperationMeetingAttrsSaveReqVO updateReqVO) {
        iotOperationMeetingAttrsService.updateIotOperationMeetingAttrs(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除专业公司工作量扩展属性")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-attrs:delete')")
    public CommonResult<Boolean> deleteIotOperationMeetingAttrs(@RequestParam("id") Long id) {
        iotOperationMeetingAttrsService.deleteIotOperationMeetingAttrs(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得专业公司工作量扩展属性")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-attrs:query')")
    public CommonResult<IotOperationMeetingAttrsRespVO> getIotOperationMeetingAttrs(@RequestParam("id") Long id) {
        IotOperationMeetingAttrsDO iotOperationMeetingAttrs = iotOperationMeetingAttrsService.getIotOperationMeetingAttrs(id);
        return success(BeanUtils.toBean(iotOperationMeetingAttrs, IotOperationMeetingAttrsRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得专业公司工作量扩展属性分页")
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-attrs:query')")
    public CommonResult<PageResult<IotOperationMeetingAttrsRespVO>> getIotOperationMeetingAttrsPage(@Valid IotOperationMeetingAttrsPageReqVO pageReqVO) {
        PageResult<IotOperationMeetingAttrsDO> pageResult = iotOperationMeetingAttrsService.getIotOperationMeetingAttrsPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, IotOperationMeetingAttrsRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出专业公司工作量扩展属性 Excel")
    @PreAuthorize("@ss.hasPermission('pms:iot-operation-meeting-attrs:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportIotOperationMeetingAttrsExcel(@Valid IotOperationMeetingAttrsPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<IotOperationMeetingAttrsDO> list = iotOperationMeetingAttrsService.getIotOperationMeetingAttrsPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "专业公司工作量扩展属性.xls", "数据", IotOperationMeetingAttrsRespVO.class,
                        BeanUtils.toBean(list, IotOperationMeetingAttrsRespVO.class));
    }

}