package cn.iocoder.yudao.module.pms.controller.admin.yanfan.thingsmodeltemplate;

import cn.iocoder.yudao.module.pms.controller.admin.yanfan.thingsmodeltemplate.vo.IotYfThingsModelTranslatePageReqVO;
import cn.iocoder.yudao.module.pms.controller.admin.yanfan.thingsmodeltemplate.vo.IotYfThingsModelTranslateRespVO;
import cn.iocoder.yudao.module.pms.controller.admin.yanfan.thingsmodeltemplate.vo.IotYfThingsModelTranslateSaveReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.thingsmodeltemplate.IotYfThingsModelTranslateDO;
import cn.iocoder.yudao.module.pms.service.yanfan.thingsmodeltemplate.IotThingsModelTranslateService;
import org.springframework.web.bind.annotation.*;
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 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 javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

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


@Tag(name = "管理后台 - yf物模型翻译")
@RestController
@RequestMapping("/rq/iot-things-model-translate")
@Validated
public class IotYfThingsModelTranslateController {

    @Resource
    private IotThingsModelTranslateService iotThingsModelTranslateService;

    @PostMapping("/create")
    @Operation(summary = "创建yf物模型翻译")
    @PreAuthorize("@ss.hasPermission('rq:iot-things-model-translate:create')")
    public CommonResult<Long> createIotThingsModelTranslate(@Valid @RequestBody IotYfThingsModelTranslateSaveReqVO createReqVO) {
        return success(iotThingsModelTranslateService.createIotThingsModelTranslate(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新yf物模型翻译")
    @PreAuthorize("@ss.hasPermission('rq:iot-things-model-translate:update')")
    public CommonResult<Boolean> updateIotThingsModelTranslate(@Valid @RequestBody IotYfThingsModelTranslateSaveReqVO updateReqVO) {
        iotThingsModelTranslateService.updateIotThingsModelTranslate(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除yf物模型翻译")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('rq:iot-things-model-translate:delete')")
    public CommonResult<Boolean> deleteIotThingsModelTranslate(@RequestParam("id") Long id) {
        iotThingsModelTranslateService.deleteIotThingsModelTranslate(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得yf物模型翻译")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('rq:iot-things-model-translate:query')")
    public CommonResult<IotYfThingsModelTranslateRespVO> getIotThingsModelTranslate(@RequestParam("id") Long id) {
        IotYfThingsModelTranslateDO iotThingsModelTranslate = iotThingsModelTranslateService.getIotThingsModelTranslate(id);
        return success(BeanUtils.toBean(iotThingsModelTranslate, IotYfThingsModelTranslateRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得yf物模型翻译分页")
    @PreAuthorize("@ss.hasPermission('rq:iot-things-model-translate:query')")
    public CommonResult<PageResult<IotYfThingsModelTranslateRespVO>> getIotThingsModelTranslatePage(@Valid IotYfThingsModelTranslatePageReqVO pageReqVO) {
        PageResult<IotYfThingsModelTranslateDO> pageResult = iotThingsModelTranslateService.getIotThingsModelTranslatePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, IotYfThingsModelTranslateRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出yf物模型翻译 Excel")
    @PreAuthorize("@ss.hasPermission('rq:iot-things-model-translate:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportIotThingsModelTranslateExcel(@Valid IotYfThingsModelTranslatePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<IotYfThingsModelTranslateDO> list = iotThingsModelTranslateService.getIotThingsModelTranslatePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "yf物模型翻译.xls", "数据", IotYfThingsModelTranslateRespVO.class,
                        BeanUtils.toBean(list, IotYfThingsModelTranslateRespVO.class));
    }

}
