优化
This commit is contained in:
parent
45f09ac20a
commit
b76441fe3a
|
@ -23,6 +23,7 @@ import com.ruoyi.framework.web.service.SysLoginService;
|
||||||
import com.ruoyi.framework.web.service.TokenService;
|
import com.ruoyi.framework.web.service.TokenService;
|
||||||
import com.ruoyi.system.service.ISysUserService;
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@ -50,6 +51,9 @@ public class AsProfileController extends BaseController
|
||||||
@Resource
|
@Resource
|
||||||
private IAsDeviceService asDeviceService;
|
private IAsDeviceService asDeviceService;
|
||||||
|
|
||||||
|
@Value(value = "${watering.defaultName}")
|
||||||
|
private String defaultName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 个人信息
|
* 个人信息
|
||||||
*/
|
*/
|
||||||
|
@ -59,8 +63,7 @@ public class AsProfileController extends BaseController
|
||||||
LoginUser loginUser = getLoginUser();
|
LoginUser loginUser = getLoginUser();
|
||||||
AsUser user = loginUser.getAsUser();
|
AsUser user = loginUser.getAsUser();
|
||||||
AsUser asUser = asUserService.selectUserById(user.getUserId());
|
AsUser asUser = asUserService.selectUserById(user.getUserId());
|
||||||
AjaxResult ajax = AjaxResult.success(asUser);
|
return AjaxResult.success(asUser);
|
||||||
return ajax;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,7 +170,7 @@ public class AsProfileController extends BaseController
|
||||||
}
|
}
|
||||||
asDevice.setModel(asModel.getModel());
|
asDevice.setModel(asModel.getModel());
|
||||||
asDevice.setModelName(asModel.getModelName());
|
asDevice.setModelName(asModel.getModelName());
|
||||||
asDevice.setDeviceName("丁丁浇花器");
|
asDevice.setDeviceName(defaultName);
|
||||||
asDevice.setCreateTime(DateUtils.getNowDate());
|
asDevice.setCreateTime(DateUtils.getNowDate());
|
||||||
return toAjax(asDeviceService.bandSn(asDevice));
|
return toAjax(asDeviceService.bandSn(asDevice));
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,9 @@ watering:
|
||||||
token: tVpNdGKrAFHfKZNgpIWQfZukrcYHNfFM
|
token: tVpNdGKrAFHfKZNgpIWQfZukrcYHNfFM
|
||||||
# 创建设备地址
|
# 创建设备地址
|
||||||
deviceUrl: https://iot-api.heclouds.com/device
|
deviceUrl: https://iot-api.heclouds.com/device
|
||||||
|
# 默认名称
|
||||||
|
defaultName: 丁丁浇花器
|
||||||
|
|
||||||
# 百度植物识别
|
# 百度植物识别
|
||||||
baidu:
|
baidu:
|
||||||
tokenUrl: https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials
|
tokenUrl: https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials
|
||||||
|
@ -197,7 +200,7 @@ qiniu:
|
||||||
# 七牛云命名空间
|
# 七牛云命名空间
|
||||||
bucket: autosprout
|
bucket: autosprout
|
||||||
# 过期时间(秒)
|
# 过期时间(秒)
|
||||||
expireSeconds: 600
|
expireSeconds: 86400
|
||||||
# 七牛云GET请求域名
|
# 七牛云GET请求域名
|
||||||
domain: https://lxnapi.ccttiot.com
|
domain: https://lxnapi.ccttiot.com
|
||||||
xinzhi:
|
xinzhi:
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 辉
|
||||||
|
* 2024/3/4
|
||||||
|
*/
|
||||||
|
public class ServiceUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否满足条件,满足则抛出异常
|
||||||
|
* @param flag 条件
|
||||||
|
* @param msg 异常说明
|
||||||
|
*/
|
||||||
|
public static void assertion(boolean flag, String msg) {
|
||||||
|
assertion(flag, msg, 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否满足条件,满足则抛出异常
|
||||||
|
* @param flag 条件
|
||||||
|
* @param msg 异常说明
|
||||||
|
* @param code 业务代码
|
||||||
|
*/
|
||||||
|
public static void assertion(boolean flag, String msg, int code) {
|
||||||
|
if (flag) {
|
||||||
|
throw new ServiceException(msg, code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertion(boolean flag, String format, Object ...args) {
|
||||||
|
if (flag) {
|
||||||
|
throw new ServiceException(String.format(format, args), 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import com.ruoyi.common.utils.ip.IpUtils;
|
||||||
import com.ruoyi.common.utils.onenet.Token;
|
import com.ruoyi.common.utils.onenet.Token;
|
||||||
import com.ruoyi.device.domain.*;
|
import com.ruoyi.device.domain.*;
|
||||||
import com.ruoyi.device.domain.vo.IdentifyRes;
|
import com.ruoyi.device.domain.vo.IdentifyRes;
|
||||||
|
import com.ruoyi.device.domain.vo.IsBandVO;
|
||||||
import com.ruoyi.device.service.*;
|
import com.ruoyi.device.service.*;
|
||||||
import com.ruoyi.system.service.ISysConfigService;
|
import com.ruoyi.system.service.ISysConfigService;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
@ -210,6 +211,15 @@ public class AppController extends BaseController
|
||||||
{
|
{
|
||||||
return success(asDeviceService.bandDevice(asDevice));
|
return success(asDeviceService.bandDevice(asDevice));
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * 根据mac判断设备是否绑定
|
||||||
|
// */
|
||||||
|
// @GetMapping("/isBand")
|
||||||
|
// public AjaxResult isBand(List<String> macList)
|
||||||
|
// {
|
||||||
|
// return success(asDeviceService.isBand(macList));
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解绑设备
|
* 解绑设备
|
||||||
|
@ -420,13 +430,15 @@ public class AppController extends BaseController
|
||||||
Boolean collection = asUserCollectionService.isCollection(plantId, userId);
|
Boolean collection = asUserCollectionService.isCollection(plantId, userId);
|
||||||
return AjaxResult.success(collection);
|
return AjaxResult.success(collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据mac号查询设备是否被绑定
|
* 根据mac号查询设备是否被绑定
|
||||||
*/
|
*/
|
||||||
@GetMapping("/device/isBand/{mac}")
|
@GetMapping("/device/isBand/{mac}")
|
||||||
public AjaxResult isBand(@PathVariable String mac)
|
public AjaxResult isBand(@PathVariable List<String> mac)
|
||||||
{
|
{
|
||||||
Boolean isBand = asDeviceService.isBand(mac);
|
logger.info("根据mac号查询设备是否被绑定传参-----{}", JSON.toJSONString(mac));
|
||||||
|
List<IsBandVO> isBand = asDeviceService.isBand(mac);
|
||||||
return AjaxResult.success(isBand);
|
return AjaxResult.success(isBand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.ruoyi.device.domain.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class IsBandVO {
|
||||||
|
|
||||||
|
/** 设备mac */
|
||||||
|
private String mac;
|
||||||
|
|
||||||
|
/** 是否绑定 */
|
||||||
|
private Boolean isBand;
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.device.domain.AsDevice;
|
import com.ruoyi.device.domain.AsDevice;
|
||||||
import com.ruoyi.device.domain.AsDeviceQuery;
|
import com.ruoyi.device.domain.AsDeviceQuery;
|
||||||
|
import com.ruoyi.device.domain.vo.IsBandVO;
|
||||||
import com.ruoyi.device.domain.vo.WeatherResponse;
|
import com.ruoyi.device.domain.vo.WeatherResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,7 +111,8 @@ public interface IAsDeviceService
|
||||||
* @param mac 设备mac
|
* @param mac 设备mac
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
Boolean isBand(String mac);
|
List<IsBandVO> isBand(List<String> mac);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 切换默认展示设备
|
* 切换默认展示设备
|
||||||
|
|
|
@ -10,14 +10,15 @@ import com.ruoyi.common.core.domain.entity.AsUser;
|
||||||
import com.ruoyi.common.core.domain.onenet.*;
|
import com.ruoyi.common.core.domain.onenet.*;
|
||||||
import com.ruoyi.common.exception.ServiceException;
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
|
import com.ruoyi.common.utils.ServiceUtil;
|
||||||
import com.ruoyi.common.utils.http.HttpUtils;
|
import com.ruoyi.common.utils.http.HttpUtils;
|
||||||
import com.ruoyi.common.utils.onenet.CreateDeviceVo;
|
import com.ruoyi.common.utils.onenet.CreateDeviceVo;
|
||||||
import com.ruoyi.common.utils.onenet.IotUtil;
|
|
||||||
import com.ruoyi.common.utils.onenet.Token;
|
import com.ruoyi.common.utils.onenet.Token;
|
||||||
import com.ruoyi.common.utils.pinyin.PinyinUtils;
|
import com.ruoyi.common.utils.pinyin.PinyinUtils;
|
||||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
import com.ruoyi.device.domain.*;
|
import com.ruoyi.device.domain.*;
|
||||||
import com.ruoyi.device.domain.vo.IPVo;
|
import com.ruoyi.device.domain.vo.IPVo;
|
||||||
|
import com.ruoyi.device.domain.vo.IsBandVO;
|
||||||
import com.ruoyi.device.domain.vo.WeatherResponse;
|
import com.ruoyi.device.domain.vo.WeatherResponse;
|
||||||
import com.ruoyi.device.mapper.*;
|
import com.ruoyi.device.mapper.*;
|
||||||
import com.ruoyi.device.service.IAsDeviceService;
|
import com.ruoyi.device.service.IAsDeviceService;
|
||||||
|
@ -30,16 +31,18 @@ import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.support.TransactionTemplate;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -82,6 +85,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
@Resource
|
@Resource
|
||||||
private IAsWateringRecordService asWateringRecordService;
|
private IAsWateringRecordService asWateringRecordService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TransactionTemplate transactionTemplate;
|
||||||
|
|
||||||
@Value(value = "${watering.iotUrl}")
|
@Value(value = "${watering.iotUrl}")
|
||||||
private String iotUrl;
|
private String iotUrl;
|
||||||
|
|
||||||
|
@ -106,6 +112,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
@Value(value = "${watering.deviceUrl}")
|
@Value(value = "${watering.deviceUrl}")
|
||||||
private String deviceUrl;
|
private String deviceUrl;
|
||||||
|
|
||||||
|
@Value(value = "${watering.defaultName}")
|
||||||
|
private String defaultName;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询设备详情
|
* 查询设备详情
|
||||||
|
@ -123,7 +132,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
}
|
}
|
||||||
/** 请求onenet更新设备参数*/
|
/** 请求onenet更新设备参数*/
|
||||||
updateDeviceParam(device);
|
updateDeviceParam(device);
|
||||||
|
if(device.getModelId() != null){
|
||||||
device.setPicture(modelMapper.selectAsModelByModelId(device.getModelId()).getPicture());
|
device.setPicture(modelMapper.selectAsModelByModelId(device.getModelId()).getPicture());
|
||||||
|
}
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +210,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
List<DatapointValue.Ds> dsArray = value.getDsArray();
|
List<DatapointValue.Ds> dsArray = value.getDsArray();
|
||||||
//清除无效定时器
|
//清除无效定时器
|
||||||
List<DatapointValue.Ds> ds = asTimerService.cleanInvalidDs(dsArray);
|
List<DatapointValue.Ds> ds = asTimerService.cleanInvalidDs(dsArray);
|
||||||
if(sw && ds.size()>0){//如果定时器开启且定时器列表不为空
|
if(sw && !ds.isEmpty()){//如果定时器开启且定时器列表不为空
|
||||||
modeList.add("1");
|
modeList.add("1");
|
||||||
}
|
}
|
||||||
Boolean kaiguan = tr.getKaiguan();
|
Boolean kaiguan = tr.getKaiguan();
|
||||||
|
@ -211,7 +222,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
asDevice1.setCurrentSoilMoisture(value.getTuran_show());
|
asDevice1.setCurrentSoilMoisture(value.getTuran_show());
|
||||||
List<AsWateringRecord> asWateringRecords = asWateringRecordService.selectAsWateringRecordList(AsWateringRecord.builder().deviceId(asDevice1.getDeviceId()).build());
|
List<AsWateringRecord> asWateringRecords = asWateringRecordService.selectAsWateringRecordList(AsWateringRecord.builder().deviceId(asDevice1.getDeviceId()).build());
|
||||||
// 根据asWateringRecords查询最后一次浇水时间
|
// 根据asWateringRecords查询最后一次浇水时间
|
||||||
if(asWateringRecords.size()>0){
|
if(!asWateringRecords.isEmpty()){
|
||||||
asDevice1.setLastWatering(asWateringRecords.get(0).getWaterTime());
|
asDevice1.setLastWatering(asWateringRecords.get(0).getWaterTime());
|
||||||
}
|
}
|
||||||
/**将value转成device对象并保存到数据库*/
|
/**将value转成device对象并保存到数据库*/
|
||||||
|
@ -418,17 +429,17 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult watering(AsDevice device,Integer wateringSwitch) {
|
public AjaxResult watering(AsDevice device,Integer wateringSwitch) {
|
||||||
/** 1.拼接url */
|
/* 1.拼接url */
|
||||||
String deviceName = device.getMac();//mac地址就是产品名称
|
String deviceName = device.getMac();//mac地址就是产品名称
|
||||||
String param = "device_name=" + deviceName + "&product_id=" + productId +"&timeout=" + timeout;
|
String param = "device_name=" + deviceName + "&product_id=" + productId +"&timeout=" + timeout;
|
||||||
String sendUrl = iotUrl+ IotConstants.ADDS_COMMAND + "?"+param;
|
String sendUrl = iotUrl+ IotConstants.ADDS_COMMAND + "?"+param;
|
||||||
logger.info("IOT请求地址:【{}】", sendUrl);
|
logger.info("IOT请求地址:【{}】", sendUrl);
|
||||||
|
|
||||||
/** 2.获取token */
|
/* 2.获取token */
|
||||||
String token = Token.getToken();
|
String token = Token.getToken();
|
||||||
logger.info("IOT获取到Authorization:【{}】",token);
|
logger.info("IOT获取到Authorization:【{}】",token);
|
||||||
|
|
||||||
/** 3.请求下发 */
|
/* 3.请求下发 */
|
||||||
String command = wateringSwitch == 1 ? IotConstants.COMMAND_OPEN : IotConstants.COMMAND_CLOSE;
|
String command = wateringSwitch == 1 ? IotConstants.COMMAND_OPEN : IotConstants.COMMAND_CLOSE;
|
||||||
String result = HttpUtils.sendPostWithToken(sendUrl, command, token);
|
String result = HttpUtils.sendPostWithToken(sendUrl, command, token);
|
||||||
JSONObject paramsObj = JSON.parseObject(result);
|
JSONObject paramsObj = JSON.parseObject(result);
|
||||||
|
@ -463,12 +474,14 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean bandDevice(AsDevice asDevice) {
|
public Boolean bandDevice(AsDevice asDevice) {
|
||||||
/** 根据mac号获取到设备详情*/
|
AsDevice device = asDeviceMapper.selectAsDeviceByMac(asDevice.getMac());
|
||||||
String mac = asDevice.getMac();
|
/* 根据mac号获取到设备详情*/
|
||||||
AsDevice device = asDeviceMapper.selectAsDeviceByMac(mac);
|
Boolean execute = transactionTemplate.execute(e -> {
|
||||||
if(ObjectUtils.isEmpty(device)){
|
if(ObjectUtils.isEmpty(device)){
|
||||||
throw new ServiceException("该设备不存在");
|
asDevice.setDeviceName(defaultName);
|
||||||
}
|
int i = bandSn(asDevice);
|
||||||
|
ServiceUtil.assertion(i == 0, "录入失败!");
|
||||||
|
}else{
|
||||||
if(ObjectUtils.isNotEmpty(device.getUserId()) && device.getUserId()>0){
|
if(ObjectUtils.isNotEmpty(device.getUserId()) && device.getUserId()>0){
|
||||||
throw new ServiceException("该设备已经绑定用户,请先解绑!");
|
throw new ServiceException("该设备已经绑定用户,请先解绑!");
|
||||||
}
|
}
|
||||||
|
@ -476,12 +489,16 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
device.setBluetoothId(asDevice.getBluetoothId());
|
device.setBluetoothId(asDevice.getBluetoothId());
|
||||||
device.setBluetoothName(asDevice.getBluetoothName());
|
device.setBluetoothName(asDevice.getBluetoothName());
|
||||||
int i = asDeviceMapper.updateAsDevice(device);
|
int i = asDeviceMapper.updateAsDevice(device);
|
||||||
if(i>0){
|
ServiceUtil.assertion(i == 0, "绑定失败!");
|
||||||
|
|
||||||
|
// 切换默认设备
|
||||||
toggleDevice(asDevice.getUserId(), device.getDeviceId());
|
toggleDevice(asDevice.getUserId(), device.getDeviceId());
|
||||||
return true;
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
logger.info("=================【绑定设备】成功==================");
|
||||||
|
return Boolean.TRUE;
|
||||||
|
});
|
||||||
|
if(Boolean.FALSE.equals(execute))throw new ServiceException("绑定失败");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -500,7 +517,7 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
AsDeviceQuery asDeviceQuery = new AsDeviceQuery();
|
AsDeviceQuery asDeviceQuery = new AsDeviceQuery();
|
||||||
asDeviceQuery.setUserId(device2.getUserId());
|
asDeviceQuery.setUserId(device2.getUserId());
|
||||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(asDeviceQuery);
|
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(asDeviceQuery);
|
||||||
if(asDevices.size()>0){
|
if(!asDevices.isEmpty()){
|
||||||
AsDevice device1 = asDevices.get(0);
|
AsDevice device1 = asDevices.get(0);
|
||||||
device1.setIsDefault("1");
|
device1.setIsDefault("1");
|
||||||
asDeviceMapper.updateAsDevice(device1);
|
asDeviceMapper.updateAsDevice(device1);
|
||||||
|
@ -530,12 +547,24 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
* @param mac 设备mac
|
* @param mac 设备mac
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Boolean isBand(String mac) {
|
public Boolean isBand(String mac) {
|
||||||
int i = asDeviceMapper.isBandByMac(mac);
|
int i = asDeviceMapper.isBandByMac(mac);
|
||||||
return i>0;
|
return i>0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<IsBandVO> isBand(List<String> macList) {
|
||||||
|
List<IsBandVO> isBandVOS = new ArrayList<>();
|
||||||
|
for(String mac:macList){
|
||||||
|
IsBandVO isBandVO = new IsBandVO();
|
||||||
|
isBandVO.setMac(mac);
|
||||||
|
isBandVO.setIsBand(isBand(mac));
|
||||||
|
isBandVOS.add(isBandVO);
|
||||||
|
}
|
||||||
|
return isBandVOS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 切换默认展示设备
|
* 切换默认展示设备
|
||||||
|
@ -547,9 +576,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
asDeviceQuery.setUserId(userId);
|
asDeviceQuery.setUserId(userId);
|
||||||
asDeviceQuery.setIsDefault("1");
|
asDeviceQuery.setIsDefault("1");
|
||||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(asDeviceQuery);
|
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(asDeviceQuery);
|
||||||
if(ObjectUtils.isNotEmpty(asDevices) && asDevices.size()>0){
|
if(ObjectUtils.isNotEmpty(asDevices) && !asDevices.isEmpty()){
|
||||||
for(AsDevice device:asDevices){
|
for(AsDevice device:asDevices){
|
||||||
if(device.getDeviceId()!=deviceId){
|
if(!Objects.equals(device.getDeviceId(), deviceId)){
|
||||||
asDeviceMapper.updateAsDevice(AsDevice.builder().deviceId(device.getDeviceId()).isDefault("0").build());
|
asDeviceMapper.updateAsDevice(AsDevice.builder().deviceId(device.getDeviceId()).isDefault("0").build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -564,14 +593,14 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
public WeatherResponse getWeather(String ipAddr) {
|
public WeatherResponse getWeather(String ipAddr) {
|
||||||
String location = "";
|
String location = "";
|
||||||
if(StringUtils.isNotEmpty(ipAddr)){
|
if(StringUtils.isNotEmpty(ipAddr)){
|
||||||
/** 获取归属地 https://opendata.baidu.com/api.php?query=36.28.139.223&co=&resource_id=6006&oe=utf8*/
|
/* 获取归属地 https://opendata.baidu.com/api.php?query=36.28.139.223&co=&resource_id=6006&oe=utf8*/
|
||||||
String url = "https://opendata.baidu.com/api.php?query="+ ipAddr +"&co=&resource_id=6006&oe=utf8";
|
String url = "https://opendata.baidu.com/api.php?query="+ ipAddr +"&co=&resource_id=6006&oe=utf8";
|
||||||
String sendGet = HttpUtils.sendGet(url);
|
String sendGet = HttpUtils.sendGet(url);
|
||||||
logger.info("获取到ip响应:【{}】",sendGet);
|
logger.info("获取到ip响应:【{}】",sendGet);
|
||||||
IPVo vo = JSONObject.parseObject(sendGet,IPVo.class);
|
IPVo vo = JSONObject.parseObject(sendGet,IPVo.class);
|
||||||
logger.info("转换成IPVo对象:【{}】",JSON.toJSONString(vo));
|
logger.info("转换成IPVo对象:【{}】",JSON.toJSONString(vo));
|
||||||
List<IPVo.IpData> ipData = vo.getData();
|
List<IPVo.IpData> ipData = vo.getData();
|
||||||
if(ObjectUtils.isNotEmpty(ipData) && ipData.size()>0){
|
if(ObjectUtils.isNotEmpty(ipData) && !ipData.isEmpty()){
|
||||||
IPVo.IpData ip = ipData.get(0);
|
IPVo.IpData ip = ipData.get(0);
|
||||||
String locationStr = ip.getLocation();
|
String locationStr = ip.getLocation();
|
||||||
//将location中去掉'电信','联通','移动'字符串后去掉空格,再将字符串中的省份去掉,再将字符串中的市去掉
|
//将location中去掉'电信','联通','移动'字符串后去掉空格,再将字符串中的省份去掉,再将字符串中的市去掉
|
||||||
|
|
|
@ -85,7 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
|
||||||
<select id="isBandByMac" resultType="java.lang.Integer">
|
<select id="isBandByMac" resultType="java.lang.Integer">
|
||||||
select count(1) from as_device
|
select count(1) from as_device
|
||||||
where mac = #{mac} and user_id IS NOT NULL and is_network = 1 and user_id != 0
|
where mac = #{mac} and user_id IS NOT NULL and user_id != 0
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<insert id="insertAsDevice" parameterType="AsDevice" useGeneratedKeys="true" keyProperty="deviceId">
|
<insert id="insertAsDevice" parameterType="AsDevice" useGeneratedKeys="true" keyProperty="deviceId">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user