联调
设备录入
This commit is contained in:
parent
7ae96df488
commit
0f1802049c
|
@ -8,10 +8,16 @@ import com.ruoyi.common.core.domain.entity.AsUser;
|
|||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.file.FileUploadUtils;
|
||||
import com.ruoyi.common.utils.file.MimeTypeUtils;
|
||||
import com.ruoyi.device.domain.AsDevice;
|
||||
import com.ruoyi.device.domain.AsModel;
|
||||
import com.ruoyi.device.service.IAsDeviceService;
|
||||
import com.ruoyi.device.service.IAsModelService;
|
||||
import com.ruoyi.device.service.IAsUserService;
|
||||
import com.ruoyi.framework.web.service.SysLoginService;
|
||||
import com.ruoyi.framework.web.service.TokenService;
|
||||
|
@ -38,6 +44,12 @@ public class AsProfileController extends BaseController
|
|||
@Resource
|
||||
private TokenService tokenService;
|
||||
|
||||
@Autowired
|
||||
private IAsModelService asModelService;
|
||||
|
||||
@Resource
|
||||
private IAsDeviceService asDeviceService;
|
||||
|
||||
/**
|
||||
* 个人信息
|
||||
*/
|
||||
|
@ -46,7 +58,8 @@ public class AsProfileController extends BaseController
|
|||
{
|
||||
LoginUser loginUser = getLoginUser();
|
||||
AsUser user = loginUser.getAsUser();
|
||||
AjaxResult ajax = AjaxResult.success(user);
|
||||
AsUser asUser = asUserService.selectUserById(user.getUserId());
|
||||
AjaxResult ajax = AjaxResult.success(asUser);
|
||||
return ajax;
|
||||
}
|
||||
|
||||
|
@ -130,4 +143,32 @@ public class AsProfileController extends BaseController
|
|||
}
|
||||
return error("上传图片异常,请联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备录入
|
||||
*/
|
||||
@Log(title = "设备录入", businessType = BusinessType.BAND)
|
||||
@PostMapping("/band")
|
||||
public AjaxResult bandSn(String mac,Long modelId)
|
||||
{
|
||||
logger.info("sn和mac号绑定:mac="+mac+"】,【modelId="+modelId+"】");
|
||||
if(StringUtils.isEmpty(mac)){
|
||||
throw new ServiceException("设备mac不能为空");
|
||||
}
|
||||
if(modelId == null){
|
||||
throw new ServiceException("设备型号不能为空");
|
||||
}
|
||||
AsDevice asDevice = new AsDevice();
|
||||
asDevice.setMac(mac);
|
||||
asDevice.setModelId(modelId);
|
||||
AsModel asModel = asModelService.selectAsModelByModelId(modelId);
|
||||
if (asModel == null) {
|
||||
throw new ServiceException("设备型号不存在");
|
||||
}
|
||||
asDevice.setModel(asModel.getModel());
|
||||
asDevice.setModelName(asModel.getModelName());
|
||||
asDevice.setDeviceName("丁丁浇花器");
|
||||
asDevice.setCreateTime(DateUtils.getNowDate());
|
||||
return toAjax(asDeviceService.bandSn(asDevice));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ watering:
|
|||
daysToExpire: 100
|
||||
# 推送消息token
|
||||
token: tVpNdGKrAFHfKZNgpIWQfZukrcYHNfFM
|
||||
# 创建设备地址
|
||||
deviceUrl: https://iot-api.heclouds.com/device
|
||||
# 百度植物识别
|
||||
baidu:
|
||||
tokenUrl: https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials
|
||||
|
|
|
@ -84,6 +84,17 @@ public class AsUser extends BaseEntity
|
|||
/** 微信openid */
|
||||
private String wxopenid;
|
||||
|
||||
/** 用户类型 */
|
||||
private String userType;
|
||||
|
||||
public String getUserType() {
|
||||
return userType;
|
||||
}
|
||||
|
||||
public void setUserType(String userType) {
|
||||
this.userType = userType;
|
||||
}
|
||||
|
||||
public String getWxopenid() {
|
||||
return wxopenid;
|
||||
}
|
||||
|
|
|
@ -60,5 +60,9 @@ public enum BusinessType
|
|||
/**
|
||||
* 意见反馈
|
||||
*/
|
||||
FEEDBACK
|
||||
FEEDBACK,
|
||||
/**
|
||||
* 绑定
|
||||
*/
|
||||
BAND,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.ruoyi.common.utils.onenet;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateDeviceVo {
|
||||
|
||||
private String device_name;
|
||||
|
||||
private String product_id;
|
||||
}
|
|
@ -117,12 +117,17 @@
|
|||
<el-table-column label="用户名称" align="center" key="userName" prop="userName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="用户昵称" align="center" key="nickName" prop="nickName" v-if="columns[2].visible" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="注册号码" align="center" key="phonenumber" prop="phonenumber" v-if="columns[3].visible" width="120" />
|
||||
<el-table-column label="注册时间" align="center" prop="createTime" v-if="columns[5].visible" width="160">
|
||||
<el-table-column label="注册时间" align="center" prop="createTime" v-if="columns[4].visible" width="160">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" align="center" key="status" v-if="columns[4].visible">
|
||||
<el-table-column label="用户类型" align="center" key="userType" prop="userType" v-if="columns[5].visible" :show-overflow-tooltip="true">
|
||||
<template slot-scope="scope">
|
||||
<dict-tag :options="dict.type.as_role" :value="scope.row.userType"/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" align="center" key="status" v-if="columns[6].visible">
|
||||
<template slot-scope="scope">
|
||||
<el-switch
|
||||
v-model="scope.row.status"
|
||||
|
@ -132,7 +137,7 @@
|
|||
></el-switch>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="绑定设备数" align="center" key="bindDeviceNum" prop="bindDeviceNum" v-if="columns[6].visible" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="绑定设备数" align="center" key="bindDeviceNum" prop="bindDeviceNum" v-if="columns[7].visible" :show-overflow-tooltip="true" />
|
||||
<el-table-column
|
||||
label="操作"
|
||||
align="center"
|
||||
|
@ -238,6 +243,20 @@
|
|||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="角色">
|
||||
<el-select v-model="form.userType" placeholder="请选择角色">
|
||||
<el-option
|
||||
v-for="dict in dict.type.as_role"
|
||||
:key="dict.value"
|
||||
:label="dict.label"
|
||||
:value="dict.value"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="备注">
|
||||
|
@ -290,7 +309,7 @@ import { getToken } from "@/utils/auth";
|
|||
|
||||
export default {
|
||||
name: "User",
|
||||
dicts: ['sys_normal_disable', 'sys_user_sex'],
|
||||
dicts: ['sys_normal_disable', 'sys_user_sex','as_role'],
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
|
@ -351,10 +370,11 @@ export default {
|
|||
{ key: 0, label: `用户编号`, visible: true },
|
||||
{ key: 1, label: `用户名称`, visible: true },
|
||||
{ key: 2, label: `用户昵称`, visible: true },
|
||||
{ key: 3, label: `手机号码`, visible: true },
|
||||
{ key: 4, label: `状态`, visible: true },
|
||||
{ key: 5, label: `创建时间`, visible: true },
|
||||
{ key: 6, label: `绑定设备数`, visible: true }
|
||||
{ key: 3, label: `注册号码`, visible: true },
|
||||
{ key: 4, label: `注册时间`, visible: true },
|
||||
{ key: 5, label: `用户类型`, visible: true },
|
||||
{ key: 6, label: `状态`, visible: true },
|
||||
{ key: 7, label: `绑定设备数`, visible: true }
|
||||
],
|
||||
// 表单校验
|
||||
rules: {
|
||||
|
@ -381,6 +401,7 @@ export default {
|
|||
}
|
||||
],
|
||||
phonenumber: [
|
||||
{ required: true, message: "手机号码不能为空", trigger: "blur" },
|
||||
{
|
||||
pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
|
||||
message: "请输入正确的手机号码",
|
||||
|
@ -445,6 +466,7 @@ export default {
|
|||
sex: undefined,
|
||||
status: "0",
|
||||
remark: undefined,
|
||||
userType: "01",
|
||||
postIds: [],
|
||||
roleIds: []
|
||||
};
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.ruoyi.common.enums.BusinessType;
|
|||
import com.ruoyi.common.utils.baidu.GetToken;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.common.utils.ip.IpUtils;
|
||||
import com.ruoyi.common.utils.onenet.Token;
|
||||
import com.ruoyi.device.domain.*;
|
||||
import com.ruoyi.device.domain.vo.IdentifyRes;
|
||||
import com.ruoyi.device.service.*;
|
||||
|
@ -23,13 +24,14 @@ import org.springframework.beans.factory.annotation.Value;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static sun.audio.AudioDevice.device;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
|
@ -455,6 +457,29 @@ public class AppController extends BaseController
|
|||
return AjaxResult.success(asDevices);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有型号列表
|
||||
*/
|
||||
@GetMapping("/getAllModelList")
|
||||
public AjaxResult getAllModelList()
|
||||
{
|
||||
logger.info("【所有型号列表】参数-----");
|
||||
List<AsModel> asModels = asModelService.selectAsModelList(new AsModel());
|
||||
return AjaxResult.success(asModels);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已录入设备列表
|
||||
*/
|
||||
@GetMapping("/getExistMac/{macs}")
|
||||
public AjaxResult getExistMac(@PathVariable List<String> macs)
|
||||
{
|
||||
logger.info("【获取已录入设备列表】参数-----macs=【{}】",macs);
|
||||
List<AsDevice> devices = asDeviceService.getExistMac(macs);
|
||||
return AjaxResult.success(devices);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 客服电话
|
||||
*/
|
||||
|
@ -478,5 +503,24 @@ public class AppController extends BaseController
|
|||
return toAjax(asFeedbackService.insertAsFeedback(asFeedback));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取onenet token
|
||||
*/
|
||||
@GetMapping("/getToken")
|
||||
public AjaxResult getToken()
|
||||
{
|
||||
logger.info("获取onenet token-----");
|
||||
AjaxResult success = AjaxResult.success();
|
||||
try {
|
||||
return success(Token.getToken());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.device.domain.AsDeviceQuery;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -25,7 +26,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
|
|||
|
||||
/**
|
||||
* 设备列表Controller
|
||||
*
|
||||
*
|
||||
* @author 邱贞招
|
||||
* @date 2023-11-11
|
||||
*/
|
||||
|
@ -41,7 +42,7 @@ public class AsDeviceController extends BaseController
|
|||
*/
|
||||
@PreAuthorize("@ss.hasPermi('device:device:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(AsDevice asDevice)
|
||||
public TableDataInfo list(AsDeviceQuery asDevice)
|
||||
{
|
||||
startPage();
|
||||
List<AsDevice> list = asDeviceService.selectAsDeviceList(asDevice);
|
||||
|
@ -54,7 +55,7 @@ public class AsDeviceController extends BaseController
|
|||
@PreAuthorize("@ss.hasPermi('device:device:export')")
|
||||
@Log(title = "设备列表", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, AsDevice asDevice)
|
||||
public void export(HttpServletResponse response, AsDeviceQuery asDevice)
|
||||
{
|
||||
List<AsDevice> list = asDeviceService.selectAsDeviceList(asDevice);
|
||||
ExcelUtil<AsDevice> util = new ExcelUtil<AsDevice>(AsDevice.class);
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package com.ruoyi.device.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class AsDeviceQuery extends AsDevice{
|
||||
private List<String> macList;
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.device.domain.AsDevice;
|
||||
import com.ruoyi.device.domain.AsDeviceQuery;
|
||||
import com.ruoyi.system.domain.SysStudent;
|
||||
|
||||
/**
|
||||
|
@ -36,7 +37,7 @@ public interface AsDeviceMapper extends BaseMapper<AsDevice>
|
|||
* @param asDevice 设备列表
|
||||
* @return 设备列表集合
|
||||
*/
|
||||
public List<AsDevice> selectAsDeviceList(AsDevice asDevice);
|
||||
public List<AsDevice> selectAsDeviceList(AsDeviceQuery asDevice);
|
||||
|
||||
/**
|
||||
* 新增设备列表
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.device.domain.AsDevice;
|
||||
import com.ruoyi.device.domain.AsDeviceQuery;
|
||||
import com.ruoyi.device.domain.vo.WeatherResponse;
|
||||
|
||||
/**
|
||||
|
@ -36,7 +37,7 @@ public interface IAsDeviceService
|
|||
* @param asDevice 设备列表
|
||||
* @return 设备列表集合
|
||||
*/
|
||||
public List<AsDevice> selectAsDeviceList(AsDevice asDevice);
|
||||
public List<AsDevice> selectAsDeviceList(AsDeviceQuery asDevice);
|
||||
|
||||
/**
|
||||
* 新增设备列表
|
||||
|
@ -116,10 +117,20 @@ public interface IAsDeviceService
|
|||
*/
|
||||
int toggleDevice(Long userId, Long deviceId);
|
||||
|
||||
|
||||
/**
|
||||
* 获取天气信息
|
||||
*/
|
||||
WeatherResponse getWeather(String ipAddr);
|
||||
|
||||
/**
|
||||
* 获取已录入设备列表
|
||||
*/
|
||||
List<AsDevice> getExistMac(List<String> mac);
|
||||
|
||||
/**
|
||||
* sn和mac号绑定
|
||||
*/
|
||||
int bandSn(AsDevice asDevice);
|
||||
// /**
|
||||
// * 构建命令
|
||||
// *
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.ruoyi.common.core.domain.onenet.*;
|
|||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
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.pinyin.PinyinUtils;
|
||||
|
@ -37,6 +38,7 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -101,6 +103,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
|||
@Value(value = "${watering.daysToExpire}")
|
||||
private Long daysToExpire;
|
||||
|
||||
@Value(value = "${watering.deviceUrl}")
|
||||
private String deviceUrl;
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备详情
|
||||
|
@ -227,29 +232,29 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
|||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public List<AsDevice> selectAsDeviceList(AsDevice asDevice)
|
||||
public List<AsDevice> selectAsDeviceList(AsDeviceQuery asDevice)
|
||||
{
|
||||
// 设备列表的图片是取型号的图片
|
||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(asDevice);
|
||||
for(AsDevice asDevice1 : asDevices){
|
||||
AsModel model = modelMapper.selectAsModelByModelId(asDevice1.getModelId());
|
||||
String picture = model.getPicture();
|
||||
asDevice1.setPicture(picture);
|
||||
// 查询onenet设备在线状态
|
||||
String sendUrl = iotUrl+ IotConstants.ADDS_COMMAND;
|
||||
String deviceName = asDevice1.getMac();//mac地址就是产品名称
|
||||
String param = "device_name=" + deviceName + "&product_id=" + productId +"&timeout=" + timeout;
|
||||
sendUrl = sendUrl + "?"+param;
|
||||
String token = Token.getToken();
|
||||
String result = HttpUtils.sendPostWithToken(sendUrl, "111", token);
|
||||
JSONObject paramsObj = JSON.parseObject(result);
|
||||
String code = paramsObj.getString("code");
|
||||
if (!HttpStatus.IOT_SUCCESS.equals(code)) {
|
||||
asDevice1.setOnlineStatus("不在线");
|
||||
}else{
|
||||
asDevice1.setOnlineStatus("在线");
|
||||
}
|
||||
}
|
||||
// for(AsDevice asDevice1 : asDevices){
|
||||
// AsModel model = modelMapper.selectAsModelByModelId(asDevice1.getModelId());
|
||||
// String picture = model.getPicture();
|
||||
// asDevice1.setPicture(picture);
|
||||
// // 查询onenet设备在线状态
|
||||
// String sendUrl = iotUrl+ IotConstants.ADDS_COMMAND;
|
||||
// String deviceName = asDevice1.getMac();//mac地址就是产品名称
|
||||
// String param = "device_name=" + deviceName + "&product_id=" + productId +"&timeout=" + timeout;
|
||||
// sendUrl = sendUrl + "?"+param;
|
||||
// String token = Token.getToken();
|
||||
// String result = HttpUtils.sendPostWithToken(sendUrl, "111", token);
|
||||
// JSONObject paramsObj = JSON.parseObject(result);
|
||||
// String code = paramsObj.getString("code");
|
||||
// if (!HttpStatus.IOT_SUCCESS.equals(code)) {
|
||||
// asDevice1.setOnlineStatus("不在线");
|
||||
// }else{
|
||||
// asDevice1.setOnlineStatus("在线");
|
||||
// }
|
||||
// }
|
||||
return asDevices;
|
||||
}
|
||||
|
||||
|
@ -492,7 +497,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
|||
int i = asDeviceMapper.updateAsDevice(device);
|
||||
//解绑成功后,该用户如果有其他的设备则随便找一个默认的
|
||||
if(i>0){
|
||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(AsDevice.builder().userId(device2.getUserId()).build());
|
||||
AsDeviceQuery asDeviceQuery = new AsDeviceQuery();
|
||||
asDeviceQuery.setUserId(device2.getUserId());
|
||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(asDeviceQuery);
|
||||
if(asDevices.size()>0){
|
||||
AsDevice device1 = asDevices.get(0);
|
||||
device1.setIsDefault("1");
|
||||
|
@ -536,7 +543,10 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
|||
@Override
|
||||
public int toggleDevice(Long userId,Long deviceId) {
|
||||
asDeviceMapper.updateAsDevice(AsDevice.builder().deviceId(deviceId).isDefault("1").build());
|
||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(AsDevice.builder().userId(userId).isDefault("1").build());
|
||||
AsDeviceQuery asDeviceQuery = new AsDeviceQuery();
|
||||
asDeviceQuery.setUserId(userId);
|
||||
asDeviceQuery.setIsDefault("1");
|
||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(asDeviceQuery);
|
||||
if(ObjectUtils.isNotEmpty(asDevices) && asDevices.size()>0){
|
||||
for(AsDevice device:asDevices){
|
||||
if(device.getDeviceId()!=deviceId){
|
||||
|
@ -584,4 +594,46 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
|||
logger.info("转换成weatherResponse对象:【{}】",JSON.toJSONString(weatherResponse));
|
||||
return weatherResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已录入设备列表
|
||||
*/
|
||||
@Override
|
||||
public List<AsDevice> getExistMac(List<String> macs) {
|
||||
AsDeviceQuery asDeviceQuery = new AsDeviceQuery();
|
||||
asDeviceQuery.setMacList(macs);
|
||||
return asDeviceMapper.selectAsDeviceList(asDeviceQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* sn和mac号绑定
|
||||
* 注册onenet设备
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public int bandSn(AsDevice asDevice) {
|
||||
AsDevice device = asDeviceMapper.selectAsDeviceByMac(asDevice.getMac());
|
||||
if(ObjectUtils.isNotEmpty(device)){
|
||||
throw new ServiceException("该MAC号已经存在");
|
||||
}else{
|
||||
// 调用onenet接口
|
||||
CreateDeviceVo createDeviceVo = new CreateDeviceVo();
|
||||
createDeviceVo.setDevice_name(asDevice.getMac());
|
||||
createDeviceVo.setProduct_id(productId);
|
||||
String result = HttpUtils.sendPostWithToken(deviceUrl+"/create",JSON.toJSONString(createDeviceVo), Token.getToken());
|
||||
logger.info("【sn和mac号绑定】===>IOT请求调用结果:【{}】",result);
|
||||
JSONObject paramsObj = JSON.parseObject(result);
|
||||
String code = paramsObj.getString("code");
|
||||
//记录命令
|
||||
if (!HttpStatus.IOT_SUCCESS.equals(code))
|
||||
{
|
||||
throw new ServiceException(code+"-----"+ paramsObj.getString("msg"));
|
||||
}
|
||||
int insert = asDeviceMapper.insert(asDevice);
|
||||
if(insert==0){
|
||||
throw new ServiceException("录入失败,插入数据失败!");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,16 +11,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.device.domain.AsDevice;
|
||||
import com.ruoyi.device.domain.AsDeviceClassify;
|
||||
import com.ruoyi.device.domain.AsDeviceVersion;
|
||||
import com.ruoyi.device.domain.*;
|
||||
import com.ruoyi.device.mapper.AsDeviceClassifyMapper;
|
||||
import com.ruoyi.device.mapper.AsDeviceMapper;
|
||||
import com.ruoyi.device.mapper.AsDeviceVersionMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.device.mapper.AsModelMapper;
|
||||
import com.ruoyi.device.domain.AsModel;
|
||||
import com.ruoyi.device.service.IAsModelService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -136,7 +133,7 @@ public class AsModelServiceImpl extends ServiceImpl<AsModelMapper, AsModel> impl
|
|||
String classifyName = deviceClassify.getClassifyName();
|
||||
asModel.setClassifyName(classifyName);
|
||||
int i = asModelMapper.updateAsModel(asModel);
|
||||
AsDevice device = new AsDevice();
|
||||
AsDeviceQuery device = new AsDeviceQuery();
|
||||
device.setModelId(asModel.getModelId());
|
||||
List<AsDevice> asDevices = deviceMapper.selectAsDeviceList(device);
|
||||
for(AsDevice device1: asDevices){
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.ruoyi.common.utils.http.HttpUtils;
|
|||
import com.ruoyi.common.utils.onenet.Token;
|
||||
import com.ruoyi.device.domain.AsDevice;
|
||||
import com.ruoyi.common.core.domain.entity.AsUser;
|
||||
import com.ruoyi.device.domain.AsDeviceQuery;
|
||||
import com.ruoyi.device.domain.AsWateringRecord;
|
||||
import com.ruoyi.device.mapper.AsDeviceMapper;
|
||||
import com.ruoyi.device.mapper.AsUserMapper;
|
||||
|
@ -439,7 +440,9 @@ public class AsUserServiceImpl implements IAsUserService
|
|||
@SneakyThrows
|
||||
@Override
|
||||
public List<AsDevice> selectDeviceInfoByUser(Long userId,String isDefault) {
|
||||
AsDevice asDevice = AsDevice.builder().userId(userId).isDefault(isDefault).build();
|
||||
AsDeviceQuery asDevice = new AsDeviceQuery();
|
||||
asDevice.setUserId(userId);
|
||||
asDevice.setIsDefault(isDefault);
|
||||
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(asDevice);
|
||||
// 查询onenet设备在线状态
|
||||
// String sendUrl = iotUrl+ IotConstants.ADDS_COMMAND;
|
||||
|
|
|
@ -43,7 +43,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<sql id="selectAsDeviceVo">
|
||||
select device_id, picture, device_name, classify_id, classify_name, model_id, model, mac, activation_time, online_status, user_id, user_name, nick_name, regular_watering, soil_moisture_open, soil_moisture_close, water_intensity, pulse_mode, pulse_mode_param, screen_rest_time, version, version_id, create_by, create_time, update_by, update_time, remark, regular_watering_json, soil_moisture, water_intensity_switch,is_network,is_default,mode_str,bluetooth_id,bluetooth_name from as_device
|
||||
select device_id, picture, device_name, classify_id, classify_name, model_id, model, mac, activation_time, online_status,
|
||||
user_id, user_name, nick_name, regular_watering, soil_moisture_open, soil_moisture_close, water_intensity, pulse_mode,
|
||||
pulse_mode_param, screen_rest_time, version, version_id, create_by, create_time, update_by, update_time, remark, regular_watering_json, soil_moisture, water_intensity_switch,is_network,is_default,mode_str,bluetooth_id,bluetooth_name from as_device
|
||||
</sql>
|
||||
|
||||
<select id="selectAsDeviceList" parameterType="AsDevice" resultMap="AsDeviceResult">
|
||||
|
@ -60,6 +62,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="deviceId != null "> and device_id = #{deviceId}</if>
|
||||
<if test="modelId != null "> and model_id = #{modelId}</if>
|
||||
<if test="isDefault != null and isDefault != ''"> and is_default = #{isDefault}</if>
|
||||
<if test="macList != null and macList.size() > 0">
|
||||
and mac in
|
||||
<foreach collection="macList" open="(" close=")" separator="," item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
order by is_default desc
|
||||
</select>
|
||||
|
|
|
@ -17,6 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="payPassword" column="pay_password" />
|
||||
<result property="status" column="status" />
|
||||
<result property="delFlag" column="del_flag" />
|
||||
<result property="userType" column="user_type" />
|
||||
<result property="loginIp" column="login_ip" />
|
||||
<result property="loginDate" column="login_date" />
|
||||
<result property="createBy" column="create_by" />
|
||||
|
@ -27,12 +28,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<sql id="selectUserVo">
|
||||
select u.user_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber,u.birthday, u.password, u.pay_password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark
|
||||
select u.user_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber,u.birthday, u.password, u.user_type,
|
||||
u.pay_password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark
|
||||
from as_user u
|
||||
</sql>
|
||||
|
||||
<select id="selectUserList" parameterType="AsUser" resultMap="AsUserResult">
|
||||
select u.user_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark from as_user u
|
||||
select u.user_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.user_type,
|
||||
u.login_date, u.create_by, u.create_time, u.remark from as_user u
|
||||
where u.del_flag = '0'
|
||||
<if test="userId != null and userId != 0">
|
||||
AND u.user_id = #{userId}
|
||||
|
@ -124,6 +127,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="status != null and status != ''">status,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
<if test="userType != null and userType != ''">user_type,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="userId != null and userId != ''">#{userId},</if>
|
||||
|
@ -138,6 +142,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="status != null and status != ''">#{status},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="userType != null and userType != ''">#{userType},</if>
|
||||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
@ -158,6 +163,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="loginDate != null">login_date = #{loginDate},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="userType != null and userType != ''">user_type = #{userType},</if>
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where user_id = #{userId}
|
||||
|
|
Loading…
Reference in New Issue
Block a user