Search in sources :

Example 1 with ThingsModel

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;
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) ThingsModel(com.ruoyi.iot.domain.ThingsModel)

Example 2 with ThingsModel

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;
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) ThingsModel(com.ruoyi.iot.domain.ThingsModel) ArrayList(java.util.ArrayList) ThingsModelTemplate(com.ruoyi.iot.domain.ThingsModelTemplate)

Example 3 with ThingsModel

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;
}
Also used : ThingsModel(com.ruoyi.iot.domain.ThingsModel)

Example 4 with ThingsModel

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();
}
Also used : FunctionDto(com.ruoyi.iot.model.ThingsModels.FunctionDto) ThingsModelsDto(com.ruoyi.iot.model.ThingsModels.ThingsModelsDto) JSONObject(com.alibaba.fastjson.JSONObject) ThingsModel(com.ruoyi.iot.domain.ThingsModel) EventDto(com.ruoyi.iot.model.ThingsModels.EventDto) Product(com.ruoyi.iot.domain.Product) PropertyDto(com.ruoyi.iot.model.ThingsModels.PropertyDto)

Example 5 with ThingsModel

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;
}
Also used : ThingsModel(com.ruoyi.iot.domain.ThingsModel)

Aggregations

ThingsModel (com.ruoyi.iot.domain.ThingsModel)6 SysUser (com.ruoyi.common.core.domain.entity.SysUser)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Product (com.ruoyi.iot.domain.Product)1 ThingsModelTemplate (com.ruoyi.iot.domain.ThingsModelTemplate)1 EventDto (com.ruoyi.iot.model.ThingsModels.EventDto)1 FunctionDto (com.ruoyi.iot.model.ThingsModels.FunctionDto)1 PropertyDto (com.ruoyi.iot.model.ThingsModels.PropertyDto)1 ThingsModelsDto (com.ruoyi.iot.model.ThingsModels.ThingsModelsDto)1 ArrayList (java.util.ArrayList)1