package com.genersoft.iot.vmp.service.impl; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.service.IAccountService; import com.genersoft.iot.vmp.storager.dao.AccountMapper; import com.genersoft.iot.vmp.storager.dao.DeviceMapper; import com.genersoft.iot.vmp.storager.dao.dto.UserAccount; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service public class AccountServiceImpl implements IAccountService { private Logger logger = LoggerFactory.getLogger(AccountServiceImpl.class); @Autowired private AccountMapper accountMapper; @Autowired private DeviceMapper deviceMapper; /** * 注册设备 * @param name * @param account * @param password * @return */ public boolean registerAccount(String name, String account, String password) { UserAccount userAccount = accountMapper.findByAccount(account); if (userAccount != null) { return false; } // 注册设备 return accountMapper.register(name, account, password) > 0; } /** * 获取设备 * @param account * @return */ public UserAccount checkAccount(String account) { return accountMapper.findByAccount(account); } /** * 登录 * @param account * @param password * @return */ public UserAccount login(String account, String password) { return accountMapper.login(account, password); } public int bindDevice(String id, String devId, String devCode) { return accountMapper.bindDevice(id, devId, devCode); } public int unBindDevice(String userId, String devId) { return accountMapper.unBindDevice(userId, devId); } public Boolean checkIsAllowBind(String bindCode) { if (deviceMapper.getDeviceByBindCode(bindCode) == null) { logger.warn("not find device"); return false; } Device device = accountMapper.findDeviceByDevCode(bindCode); logger.info("device: {}", device); return device == null; } public PageInfo getAccountDevices(String accountId, int page, int count) { PageHelper.startPage(page, count); List devices = accountMapper.getAccountDevices(accountId); return new PageInfo<>(devices); } public Device getAccountDevice(String accountId, String deviceId) { return accountMapper.getAccountDevice(accountId, deviceId); } }