package com.cyl.h5.controller;

import com.cyl.h5.config.SecurityUtil;
import com.cyl.h5.service.H5MemberDoorLockService;
import com.cyl.manager.ums.domain.Member;
import com.cyl.manager.ums.domain.MemberDoorLock;
import com.cyl.manager.ums.service.MemberDoorLockService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.config.LocalDataUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 门锁信息Controller
 * 
 * @author daixiande
 * @date 2024-07-07
 */
//@Api("门锁信息")
@RestController
@RequestMapping("/h5/memberDoorLock")
@Slf4j
public class H5MemberDoorLockController extends BaseController {

    @Autowired
    private H5MemberDoorLockService memberDoorLockService;

//    /**
//     * 获取门锁信息详细信息
//     */
//    //@ApiOperation("获取门锁信息详细信息")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id) {
//        return AjaxResult.success(memberDoorLockService.selectMemberDoorLockById(id));
//    }

    /**
     * 获取门锁信息详细信息
     */
    //@ApiOperation("获取门锁信息详细信息")
    @GetMapping
    public AjaxResult getInfo() {
        Member member = SecurityUtil.getLocalMember();
        return AjaxResult.success(memberDoorLockService.selectMemberDoorLockByOpenId(member.getId()));
    }

    /**
     * 新增门锁信息
     */
    //@ApiOperation("新增门锁信息")
    @PostMapping
    public AjaxResult add(@RequestBody MemberDoorLock memberDoorLock) {
        log.info("新增门锁信息：{}", memberDoorLock);
        Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO);
        assert member != null;
        memberDoorLock.setMemberId(member.getId());
        return toAjax(memberDoorLockService.insertMemberDoorLock(memberDoorLock));
    }

    /**
     * 修改门锁信息
     */
    //@ApiOperation("修改门锁信息")
    @PutMapping
    public AjaxResult edit(@RequestBody MemberDoorLock memberDoorLock) {
        log.info("更新门锁信息：{}", memberDoorLock);
        Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO);
        assert member != null;
        memberDoorLock.setMemberId(member.getId());
        return toAjax(memberDoorLockService.updateMemberDoorLock(memberDoorLock));
    }

}
