use of com.ruoyi.iot.domain.ThingsModel in project wumei-smart by kerwincui.
the class ThingsModelServiceImpl method insertThingsModel.
/**
* 新增物模型
*
* @param thingsModel 物模型
* @return 结果
*/
@Override
public int insertThingsModel(ThingsModel thingsModel) {
// 物模型标识符不能重复 TODO 重复查询待优化
ThingsModel input = new ThingsModel();
input.setProductId(thingsModel.getProductId());
List<ThingsModel> list = thingsModelMapper.selectThingsModelList(input);
Boolean isRepeat = list.stream().anyMatch(x -> x.getIdentifier().equals(thingsModel.getIdentifier()));
if (!isRepeat) {
SysUser user = getLoginUser().getUser();
thingsModel.setTenantId(user.getUserId());
thingsModel.setTenantName(user.getUserName());
thingsModel.setCreateTime(DateUtils.getNowDate());
int result = thingsModelMapper.insertThingsModel(thingsModel);
// 更新redis缓存
setCacheThingsModelByProductId(thingsModel.getProductId());
return result;
}
return 2;
}
use of com.ruoyi.iot.domain.ThingsModel in project wumei-smart by kerwincui.
the class ThingsModelServiceImpl method importByTemplateIds.
/**
* 导入通用物模型
* @param input
* @return
*/
@Override
public int importByTemplateIds(ImportThingsModelInput input) {
// 物模型标识符不能重复 TODO 重复查询待优化
ThingsModel inputParameter = new ThingsModel();
inputParameter.setProductId(input.getProductId());
List<ThingsModel> dbList = thingsModelMapper.selectThingsModelList(inputParameter);
SysUser user = getLoginUser().getUser();
// 根据ID集合获取通用物模型列表
List<ThingsModelTemplate> templateList = thingsModelTemplateMapper.selectThingsModelTemplateByTemplateIds(input.getTemplateIds());
// 转换为产品物模型,并批量插入
List<ThingsModel> list = new ArrayList<>();
int repeatCount = 0;
for (ThingsModelTemplate template : templateList) {
ThingsModel thingsModel = new ThingsModel();
BeanUtils.copyProperties(template, thingsModel);
thingsModel.setTenantId(user.getUserId());
thingsModel.setTenantName(user.getUserName());
thingsModel.setCreateTime(DateUtils.getNowDate());
thingsModel.setProductId(input.getProductId());
thingsModel.setProductName(input.getProductName());
thingsModel.setModelId(template.getTemplateId());
thingsModel.setModelName(template.getTemplateName());
Boolean isRepeat = dbList.stream().anyMatch(x -> x.getIdentifier().equals(thingsModel.getIdentifier()));
if (isRepeat) {
repeatCount = repeatCount + 1;
} else {
list.add(thingsModel);
}
}
if (list.size() > 0) {
thingsModelMapper.insertBatchThingsModel(list);
// 更新redis缓存
setCacheThingsModelByProductId(input.getProductId());
}
return repeatCount;
}
use of com.ruoyi.iot.domain.ThingsModel in project wumei-smart by kerwincui.
the class ThingsModelServiceImpl method updateThingsModel.
/**
* 修改物模型
*
* @param thingsModel 物模型
* @return 结果
*/
@Override
public int updateThingsModel(ThingsModel thingsModel) {
// 物模型标识符不能重复 TODO 重复查询待优化
ThingsModel input = new ThingsModel();
input.setProductId(thingsModel.getProductId());
List<ThingsModel> list = thingsModelMapper.selectThingsModelList(input);
Boolean isRepeat = list.stream().anyMatch(x -> x.getIdentifier().equals(thingsModel.getIdentifier()) && x.getModelId().longValue() != thingsModel.getModelId());
if (!isRepeat) {
thingsModel.setUpdateTime(DateUtils.getNowDate());
int result = thingsModelMapper.updateThingsModel(thingsModel);
// 更新redis缓存
setCacheThingsModelByProductId(thingsModel.getProductId());
return result;
}
return 2;
}
use of com.ruoyi.iot.domain.ThingsModel in project wumei-smart by kerwincui.
the class ThingsModelServiceImpl method setCacheThingsModelByProductId.
/**
* 根据产品ID更新JSON物模型
* @param productId
* @return
*/
private String setCacheThingsModelByProductId(Long productId) {
// 数据库查询物模型集合
ThingsModel model = new ThingsModel();
model.setProductId(productId);
List<ThingsModel> thingsModels = thingsModelMapper.selectThingsModelList(model);
// 转换为物模型
ThingsModelsDto thingsModelsDto = new ThingsModelsDto();
for (int i = 0; i < thingsModels.size(); i++) {
if (thingsModels.get(i).getType() == 1) {
// 属性
PropertyDto propertyDto = new PropertyDto();
propertyDto.setId(thingsModels.get(i).getIdentifier());
propertyDto.setName(thingsModels.get(i).getModelName());
propertyDto.setIsMonitor(thingsModels.get(i).getIsMonitor());
propertyDto.setIsTop(thingsModels.get(i).getIsTop());
propertyDto.setDatatype(JSONObject.parseObject(thingsModels.get(i).getSpecs()));
thingsModelsDto.getProperties().add(propertyDto);
} else if (thingsModels.get(i).getType() == 2) {
// 功能
FunctionDto functionDto = new FunctionDto();
functionDto.setId(thingsModels.get(i).getIdentifier());
functionDto.setName(thingsModels.get(i).getModelName());
functionDto.setIsTop(thingsModels.get(i).getIsTop());
functionDto.setDatatype(JSONObject.parseObject(thingsModels.get(i).getSpecs()));
thingsModelsDto.getFunctions().add(functionDto);
} else if (thingsModels.get(i).getType() == 3) {
// 事件
EventDto eventDto = new EventDto();
eventDto.setId(thingsModels.get(i).getIdentifier());
eventDto.setName(thingsModels.get(i).getModelName());
eventDto.setDatatype(JSONObject.parseObject(thingsModels.get(i).getSpecs()));
thingsModelsDto.getEvents().add(eventDto);
}
}
JSONObject tslObject = (JSONObject) JSONObject.toJSON(thingsModelsDto);
redisCache.setCacheObject(tslPreKey + productId, tslObject.toJSONString());
Product product = new Product();
product.setProductId(productId);
product.setThingsModelsJson(tslObject.toJSONString());
productMapper.updateThingsModelJson(product);
return tslObject.toJSONString();
}
use of com.ruoyi.iot.domain.ThingsModel in project wumei-smart by kerwincui.
the class ThingsModelServiceImpl method deleteThingsModelByModelId.
/**
* 删除物模型信息
*
* @param modelId 物模型主键
* @return 结果
*/
@Override
public int deleteThingsModelByModelId(Long modelId) {
ThingsModel thingsModel = thingsModelMapper.selectThingsModelByModelId(modelId);
int result = thingsModelMapper.deleteThingsModelByModelId(modelId);
// 更新redis缓存
setCacheThingsModelByProductId(thingsModel.getProductId());
return result;
}
Aggregations