|
|
|
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)
|
|
|
|
{
|
|
|
|
IotThingsModelTemplate iotThingsModel = JSONObject.parseObject(JSONObject.toJSONString(iotThingsModelAddApi.getIotThingsModel()),IotThingsModelTemplate.class);
|
|
|
|
iotThingsModel.setCreate_by(getUsername());
|
|
|
|
ThingsModelItemBase thingsModelItemBase = null;
|
|
|
|
switch (iotThingsModel.getData_type())
|
|
|
|
{
|
|
|
|
return toAjax(iotThingsModelTemplateService.insertIotThingsModelTemplate(iotThingsModelTemplate));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|