package com.zd.alg.smartlock.controller;

import com.zd.alg.smartlock.domain.api.SlLockOnline;
import com.zd.alg.smartlock.domain.vo.SlSubjectRelationVo;
import com.zd.alg.smartlock.service.ISlSubjectRelationService;
import com.zd.alg.smartlock.utils.SmartlockUtil;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: xxf
 * @Date: 2022/09/07/9:43
 * @Description:
 */

@RestController
@Api(tags = "门锁相关信息查询")
@RequestMapping("/lockinfo")
public class SmartlockController extends BaseController {

    @Autowired
    private ISlSubjectRelationService slSubjectRelationService;

    /**
     * 查询实验室门锁信息
     */
    @GetMapping("/detalis")
    @ApiOperation(value = "查询实验室门锁信息")
    public TableDataInfo<SlLockOnline> list(Long subjectId)
    {
        List<SlLockOnline> lockOnlineslist = new ArrayList<>();

        //查询实验室绑定的门锁集合
        SlSubjectRelationVo subjectRelation = new SlSubjectRelationVo();
        subjectRelation.setSubjectId(subjectId);
        List<SlSubjectRelationVo> list = slSubjectRelationService.selectSlSubjectRelationList(subjectRelation);
        for (SlSubjectRelationVo sub: list ) {
            //查询门锁状态
            SlLockOnline lockOnline = SmartlockUtil.getRoomDetails(sub.getLockRoomId());
            lockOnlineslist.add(lockOnline);
        }
        return getDataTable(lockOnlineslist);
    }
}
