package cn.iocoder.yudao.module.system.controller.admin.facedeviceinfo;

import cn.iocoder.yudao.module.system.controller.admin.facedeviceinfo.vo.FaceDeviceInfoPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.facedeviceinfo.vo.FaceDeviceInfoRespVO;
import cn.iocoder.yudao.module.system.controller.admin.facedeviceinfo.vo.FaceDeviceInfoSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.facedeviceinfo.FaceDeviceInfoDO;
import cn.iocoder.yudao.module.system.service.facedeviceinfo.FaceDeviceInfoService;
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.constraints.*;
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.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;



@Tag(name = "管理后台 - 人脸设备信息关联门店")
@RestController
@RequestMapping("/t/face-device-info")
@Validated
public class FaceDeviceInfoController {

    @Resource
    private FaceDeviceInfoService faceDeviceInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建人脸设备信息关联门店")
    @PreAuthorize("@ss.hasPermission('t:face-device-info:create')")
    public CommonResult<Long> createFaceDeviceInfo(@Valid @RequestBody FaceDeviceInfoSaveReqVO createReqVO) {
        return success(faceDeviceInfoService.createFaceDeviceInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新人脸设备信息关联门店")
    @PreAuthorize("@ss.hasPermission('t:face-device-info:update')")
    public CommonResult<Boolean> updateFaceDeviceInfo(@Valid @RequestBody FaceDeviceInfoSaveReqVO updateReqVO) {
        faceDeviceInfoService.updateFaceDeviceInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除人脸设备信息关联门店")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('t:face-device-info:delete')")
    public CommonResult<Boolean> deleteFaceDeviceInfo(@RequestParam("id") Long id) {
        faceDeviceInfoService.deleteFaceDeviceInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得人脸设备信息关联门店")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('t:face-device-info:query')")
    public CommonResult<FaceDeviceInfoRespVO> getFaceDeviceInfo(@RequestParam("id") Long id) {
        FaceDeviceInfoDO faceDeviceInfo = faceDeviceInfoService.getFaceDeviceInfo(id);
        return success(BeanUtils.toBean(faceDeviceInfo, FaceDeviceInfoRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得人脸设备信息关联门店分页")
    @PreAuthorize("@ss.hasPermission('t:face-device-info:query')")
    public CommonResult<PageResult<FaceDeviceInfoRespVO>> getFaceDeviceInfoPage(@Valid FaceDeviceInfoPageReqVO pageReqVO) {
        PageResult<FaceDeviceInfoDO> pageResult = faceDeviceInfoService.getFaceDeviceInfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, FaceDeviceInfoRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出人脸设备信息关联门店 Excel")
    @PreAuthorize("@ss.hasPermission('t:face-device-info:export')")
    @OperateLog(type = EXPORT)
    public void exportFaceDeviceInfoExcel(@Valid FaceDeviceInfoPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<FaceDeviceInfoDO> list = faceDeviceInfoService.getFaceDeviceInfoPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "人脸设备信息关联门店.xls", "数据", FaceDeviceInfoRespVO.class,
                        BeanUtils.toBean(list, FaceDeviceInfoRespVO.class));
    }

}