作者 钟来

初始提交

... ... @@ -54,7 +54,7 @@ public class IotDeviceControlController {
@Log(title = "设备控制", businessType = BusinessType.UPDATE)
@ResponseBody
@PostMapping("/firmwareUp/{imei}")
public String firmwareUp(HttpServletResponse response,@PathVariable String imei,String firmwareVersion) throws IOException {
public String firmwareUp(HttpServletResponse response,@PathVariable String imei,String firmwareVersion,Integer code) throws IOException {
String url = getServiceAdrres(response,imei);
if(null == url)
{
... ... @@ -63,11 +63,9 @@ public class IotDeviceControlController {
Map<String,Object> map = new HashMap<>();
Map<String,Object> valueMap = new HashMap<>();
valueMap.put("firmwareVersion",firmwareVersion);
map.put("0",valueMap);
Response response1 = HttpUtils.postFromBody(url, builder -> {
}, formBody -> {
formBody.add("map", JSONObject.toJSONString(map));
valueMap.put("code",code);
Response response1 = HttpUtils.postJsonBody(url, formBody -> {
formBody.put("0", valueMap);
});
return response1.body().string();
}
... ... @@ -90,11 +88,8 @@ public class IotDeviceControlController {
Map<String,Object> map = new HashMap<>();
Map<String,Object> valueMap = new HashMap<>();
valueMap.put("restart",restart);
map.put("0",valueMap);
Response response1 = HttpUtils.postFromBody(url, builder -> {
}, formBody -> {
formBody.add("map", JSONObject.toJSONString(map));
Response response1 = HttpUtils.postJsonBody(url, formBody -> {
formBody.put("0",valueMap);
});
return response1.body().string();
}
... ... @@ -234,14 +229,10 @@ public class IotDeviceControlController {
{
return null;
}
Map<String,Object> map = new HashMap<>();
Map<String,Object> valueMap = new HashMap<>();
valueMap.put("summary",JSONObject.parseObject(summary));
map.put("0",valueMap);
Response response1 = HttpUtils.postFromBody(url, builder -> {
}, formBody -> {
formBody.add("map", JSONObject.toJSONString(map));
Response response1 = HttpUtils.postJsonBody(url,formBody -> {
formBody.put("0", valueMap);
});
return response1.body().string();
}
... ... @@ -302,10 +293,14 @@ public class IotDeviceControlController {
{
return null;
}
Response response1 = HttpUtils.postFromBody(url, builder -> {
Response response1 = HttpUtils.postJsonBody(url, builder -> {
}, formBody -> {
formBody.add("map", JSONObject.toJSONString(map));
for (String key:map.keySet())
{
formBody.put(key, map.get(key));
}
});
return response1.body().string();
}
... ...
... ... @@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.system.domain.DistributionCurrencyModel;
import com.ruoyi.system.domain.IotProduct;
import com.ruoyi.system.service.IIotProductService;
import com.zhonglai.luhui.admin.dto.IotThingsModelAddApi;
... ... @@ -225,4 +226,19 @@ public class IotThingsModelController extends BaseController
return toAjax(ri);
}
@ApiOperation("分配通用模型")
@PreAuthorize("@ss.hasPermi('iot:IotThingsModel:distributionTemplate')")
@Log(title = "物模型模板", businessType = BusinessType.INSERT)
@PostMapping("/distributionTemplate/{product_id}")
public AjaxResult distributionTemplate(@PathVariable Integer product_id,Integer[] tmplatemModel_ids)
{
DistributionCurrencyModel distributionCurrencyModel = new DistributionCurrencyModel();
IotProduct iotProduct = iIotProductService.selectIotProductById(product_id);
distributionCurrencyModel.setModel_ids(tmplatemModel_ids);
distributionCurrencyModel.setMqtt_username(iotProduct.getMqtt_username());
distributionCurrencyModel.setProduct_id(iotProduct.getId());
int ri = iotThingsModelService.distributionIotThingsModelTemplate(distributionCurrencyModel);
return toAjax(ri);
}
}
... ...
package com.zhonglai.luhui.admin.controller.iot;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.system.domain.IotProduct;
import com.ruoyi.system.domain.IotThingsModel;
import com.ruoyi.system.service.IIotProductService;
import com.zhonglai.luhui.admin.dto.IotThingsModelAddApi;
import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.ThingsModelItemBase;
import com.zhonglai.luhui.mqtt.comm.dto.thingsmodels.specs.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
... ... @@ -38,6 +47,9 @@ public class IotThingsModelTemplateController extends BaseController
@Autowired
private IIotThingsModelTemplateService iotThingsModelTemplateService;
@Autowired
private IIotProductService iIotProductService;
/**
* 查询物模型模板列表
*/
... ... @@ -83,9 +95,43 @@ public class IotThingsModelTemplateController extends BaseController
@PreAuthorize("@ss.hasPermi('iot:IotThingsModelTemplate:add')")
@Log(title = "物模型模板", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody IotThingsModelTemplate iotThingsModelTemplate)
public AjaxResult add(@RequestBody IotThingsModelAddApi iotThingsModelAddApi)
{
return toAjax(iotThingsModelTemplateService.insertIotThingsModelTemplate(iotThingsModelTemplate));
IotThingsModelTemplate iotThingsModel = JSONObject.parseObject(JSONObject.toJSONString(iotThingsModelAddApi.getIotThingsModel()),IotThingsModelTemplate.class);
iotThingsModel.setCreate_by(getUsername());
ThingsModelItemBase thingsModelItemBase = null;
switch (iotThingsModel.getData_type())
{
case "integer":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), IntegerModelOutput.class);
break;
case "decimal":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), DecimalModelOutput.class);
break;
case "string":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), StringModelOutput.class);
break;
case "bool":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), BoolModelOutput.class);
break;
case "array":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), ArrayModelOutput.class);
break;
case "enum":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), EnumModelOutput.class);
break;
}
if(null == thingsModelItemBase)
{
return AjaxResult.error("请输入数模型");
}
iotThingsModel.setSpecs(JSONObject.toJSONString(thingsModelItemBase));
iotThingsModel.setCreate_time(new Date());
int ri = iotThingsModelTemplateService.insertIotThingsModelTemplate(iotThingsModel);
return toAjax(ri);
}
/**
... ... @@ -95,9 +141,43 @@ public class IotThingsModelTemplateController extends BaseController
@PreAuthorize("@ss.hasPermi('iot:IotThingsModelTemplate:edit')")
@Log(title = "物模型模板", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody IotThingsModelTemplate iotThingsModelTemplate)
public AjaxResult edit(@RequestBody IotThingsModelAddApi iotThingsModelAddApi)
{
return toAjax(iotThingsModelTemplateService.updateIotThingsModelTemplate(iotThingsModelTemplate));
IotThingsModelTemplate iotThingsModel = JSONObject.parseObject(JSONObject.toJSONString(iotThingsModelAddApi.getIotThingsModel()),IotThingsModelTemplate.class);
iotThingsModel.setCreate_by(getUsername());
ThingsModelItemBase thingsModelItemBase = null;
switch (iotThingsModel.getData_type())
{
case "integer":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), IntegerModelOutput.class);
break;
case "decimal":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), DecimalModelOutput.class);
break;
case "string":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), StringModelOutput.class);
break;
case "bool":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), BoolModelOutput.class);
break;
case "array":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), ArrayModelOutput.class);
break;
case "enum":
thingsModelItemBase = JSONObject.parseObject(JSON.toJSONString(iotThingsModelAddApi.getThingsModelBase()), EnumModelOutput.class);
break;
}
if(null == thingsModelItemBase)
{
return AjaxResult.error("请输入数模型");
}
iotThingsModel.setSpecs(JSONObject.toJSONString(thingsModelItemBase));
int ri =iotThingsModelTemplateService.updateIotThingsModelTemplate(iotThingsModel);
return toAjax(ri);
}
/**
... ...
... ... @@ -73,6 +73,10 @@ public class BusinessDataUpdateService {
iotDevice.setListen_service_ip(SysParameter.service_ip+":"+port+contextPath);
}
logger.info("更新网关数据{}",iotDevice);
if(null== iotDevice.getStatus() || 1 == iotDevice.getStatus() || 4==iotDevice.getStatus())
{
iotDevice.setStatus(3);
}
deviceService.updataDevice(iotDevice);
}else{ //终端
IotTerminal iotTerminal = translateTerminal(type,key,olddevice,jsData,isOperLog,operateHisList,list);
... ...
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4" />
\ No newline at end of file
package com.ruoyi.system.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel("通用模型分配")
public class DistributionCurrencyModel {
@ApiModelProperty("产品id")
private Integer product_id;
@ApiModelProperty("mqtt用户名/设备类型")
private String mqtt_username;
@ApiModelProperty("模型id集合(多个用英文逗号分割)")
private Integer[] model_ids;
@ApiModelProperty("模型id集合(多个用英文逗号分割)")
private Integer model_id;
public Integer getModel_id() {
return model_id;
}
public void setModel_id(Integer model_id) {
this.model_id = model_id;
}
public Integer getProduct_id() {
return product_id;
}
public void setProduct_id(Integer product_id) {
this.product_id = product_id;
}
public String getMqtt_username() {
return mqtt_username;
}
public void setMqtt_username(String mqtt_username) {
this.mqtt_username = mqtt_username;
}
public Integer[] getModel_ids() {
return model_ids;
}
public void setModel_ids(Integer[] model_ids) {
this.model_ids = model_ids;
}
}
... ...
package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.domain.DistributionCurrencyModel;
import com.ruoyi.system.domain.IotThingsModel;
/**
... ... @@ -58,4 +60,6 @@ public interface IotThingsModelMapper
* @return 结果
*/
public int deleteIotThingsModelByModel_ids(Integer[] model_ids);
int distributionIotThingsModelTemplate(DistributionCurrencyModel distributionCurrencyModel);
}
... ...
package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.domain.DistributionCurrencyModel;
import com.ruoyi.system.domain.IotThingsModel;
/**
... ... @@ -60,4 +62,6 @@ public interface IIotThingsModelService
public int deleteIotThingsModelByModel_id(Integer model_id);
List<IotThingsModel> selectIotThingsModelListByIds(Integer[] model_ids);
int distributionIotThingsModelTemplate(DistributionCurrencyModel distributionCurrencyModel);
}
... ...
package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.domain.DistributionCurrencyModel;
import com.ruoyi.system.domain.IotThingsModelTemplate;
/**
... ...
package com.ruoyi.system.service.impl;
import java.util.List;
import com.ruoyi.system.domain.DistributionCurrencyModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.IotThingsModelMapper;
... ... @@ -95,4 +97,9 @@ public class IotThingsModelServiceImpl implements IIotThingsModelService
public List<IotThingsModel> selectIotThingsModelListByIds(Integer[] model_ids) {
return iotThingsModelMapper.selectIotThingsModelListByIds(model_ids);
}
@Override
public int distributionIotThingsModelTemplate(DistributionCurrencyModel distributionCurrencyModel) {
return iotThingsModelMapper.distributionIotThingsModelTemplate(distributionCurrencyModel);
}
}
... ...
... ... @@ -169,4 +169,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{model_id}
</foreach>
</delete>
<insert id="distributionIotThingsModelTemplate" parameterType="DistributionCurrencyModel">
INSERT INTO `iot_things_model`(`model_name`,`identifier`,`type`,`data_type`,`specs`,`is_top`,`is_monitor`,`del_flag`,`create_by`,`create_time`,`update_by`,`update_time`,`remark`,`product_id`,`mqtt_username`,`is_save_log`,`is_config`,`config_names`,`view_type`,`ascription`) SELECT `model_name`,`identifier`,`type`,`data_type`,`specs`,`is_top`,`is_monitor`,`del_flag`,`create_by`,`create_time`,`update_by`,`update_time`,`remark`,#{product_id,jdbcType=INTEGER} `product_id`,#{mqtt_username,jdbcType=VARCHAR} `mqtt_username`,`is_save_log`,`is_config`,`config_names`,`view_type`,`ascription` FROM `iot_things_model_template` WHERE `model_id` IN
<foreach item="model_id" collection="model_ids" open="(" separator="," close=")">
#{model_id}
</foreach>
</insert>
</mapper>
\ No newline at end of file
... ...
... ... @@ -110,7 +110,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="product_id != null">product_id = #{product_id},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="specs != null">specs = #{specs},</if>
<if test="type != null">type = #{type},</if>
<if test="type != null">`type` = #{type},</if>
<if test="update_by != null">update_by = #{update_by},</if>
<if test="update_time != null">update_time = #{update_time},</if>
<if test="view_type != null">view_type = #{view_type},</if>
... ... @@ -128,4 +128,5 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{model_id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
... ...