|
@@ -0,0 +1,178 @@
|
|
|
+/*
|
|
|
+package com.zcxk.rmcp.web.service;
|
|
|
+
|
|
|
+import com.bz.zoneiot.core.common.util.BeanCopyUtils;
|
|
|
+import com.bz.zoneiot.core.mongo.utils.StringUtil;
|
|
|
+import com.bz.zoneiot.core.utils.util.RedisUtils;
|
|
|
+import com.bz.zoneiot.iot.sync.service.SyncProductService;
|
|
|
+import com.bz.zoneiot.iot.sync.vo.ProductDetailVo;
|
|
|
+import com.bz.zoneiot.iot.sync.vo.ProductVo;
|
|
|
+import com.bz.zoneiot.water.core.dao.DeviceTypeMapper;
|
|
|
+import com.bz.zoneiot.water.core.entity.DeviceTypeEntity;
|
|
|
+import com.bz.zoneiot.water.web.config.ProductSyncConfig;
|
|
|
+import com.bz.zoneiot.water.web.constants.RedisConstants;
|
|
|
+import com.bz.zoneiot.water.web.service.SyncService;
|
|
|
+import com.bz.zoneiot.water.web.util.SyncUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+*/
|
|
|
+/**
|
|
|
+ * @author Andy
|
|
|
+ * @version V1.0
|
|
|
+ * @description: TODO
|
|
|
+ * @date 2021/10/25
|
|
|
+ **//*
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+public abstract class AbstractProductSyncService implements SyncService {
|
|
|
+
|
|
|
+ */
|
|
|
+/**
|
|
|
+ * 产品信息
|
|
|
+ *//*
|
|
|
+
|
|
|
+ protected static List<ProductDetailVo> detailVoList = new ArrayList<>();
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ protected ProductSyncConfig productSyncConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ protected SyncProductService syncProductService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ protected DeviceTypeMapper deviceTypeMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ protected RedisUtils redisUtils;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sync() {
|
|
|
+ if (!productSyncConfig.isSyncOnOff()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (detailVoList.size() == 0 ){
|
|
|
+ this.syncProduct();
|
|
|
+ }
|
|
|
+ this.sync(detailVoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ */
|
|
|
+/**
|
|
|
+ * 清除产品信息
|
|
|
+ * @author Andy
|
|
|
+ * @date 11:48 2021/10/25
|
|
|
+ * @param :
|
|
|
+ * @return void
|
|
|
+ **//*
|
|
|
+
|
|
|
+ public void clean(){
|
|
|
+ detailVoList.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ */
|
|
|
+/**
|
|
|
+ * 同步成品
|
|
|
+ * @author Andy
|
|
|
+ * @date 11:06 2021/10/25
|
|
|
+ * @param :
|
|
|
+ * @return void
|
|
|
+ **//*
|
|
|
+
|
|
|
+ private void syncProduct(){
|
|
|
+ List<ProductVo> productVos = syncProductService.queryProduct();
|
|
|
+ if (CollectionUtils.isEmpty(productVos)){
|
|
|
+ log.info("同步产品为空,退出产品同步");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (ProductVo productVo : productVos) {
|
|
|
+ ProductDetailVo productDetailVo = syncProductService.queryProductAttributes(productVo);
|
|
|
+ if (productDetailVo == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ productDetailVo.setProductId(productVo.getProductId());
|
|
|
+ detailVoList.add(productDetailVo);
|
|
|
+ }
|
|
|
+ this.incrementAddProduct(productVos);
|
|
|
+ }
|
|
|
+
|
|
|
+ */
|
|
|
+/**
|
|
|
+ * 增量添加产品
|
|
|
+ * @author Andy
|
|
|
+ * @date 18:35 2021/10/21
|
|
|
+ * @param :
|
|
|
+ * @return void
|
|
|
+ **//*
|
|
|
+
|
|
|
+ private void incrementAddProduct(List<ProductVo> productVos){
|
|
|
+ List<DeviceTypeEntity> entities = new ArrayList<>();
|
|
|
+ for (ProductVo productVo : productVos) {
|
|
|
+ String productId = redisUtils.get(SyncUtils.getProductKey(productVo.getProductId()));
|
|
|
+ if (StringUtil.isNotEmpty(productId)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ entities.add(this.convertDeviceTypeEntity(productVo));
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(entities)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.saveDeviceTypeEntity(entities);
|
|
|
+ }
|
|
|
+
|
|
|
+ */
|
|
|
+/**
|
|
|
+ * 转换设备类型实体
|
|
|
+ * @author Andy
|
|
|
+ * @date 18:35 2021/10/21
|
|
|
+ * @param productVo:
|
|
|
+ * @return DeviceTypeEntity
|
|
|
+ **//*
|
|
|
+
|
|
|
+ private DeviceTypeEntity convertDeviceTypeEntity(ProductVo productVo){
|
|
|
+ DeviceTypeEntity entity = BeanCopyUtils.copy(productVo, DeviceTypeEntity.class);
|
|
|
+ entity.setIotProductId(productVo.getProductId());
|
|
|
+ entity.setDeviceMode(productVo.getProductModel());
|
|
|
+ entity.setDeviceType(productVo.getProductName());
|
|
|
+ entity.setBaseEntity();
|
|
|
+ return entity;
|
|
|
+ }
|
|
|
+
|
|
|
+ */
|
|
|
+/**
|
|
|
+ * 保存产品
|
|
|
+ * @author Andy
|
|
|
+ * @date 18:23 2021/10/21
|
|
|
+ * @param entities:
|
|
|
+ * @return void
|
|
|
+ **//*
|
|
|
+
|
|
|
+ private void saveDeviceTypeEntity(List<DeviceTypeEntity> entities) {
|
|
|
+ if (CollectionUtils.isEmpty(entities)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ deviceTypeMapper.batchInsert(entities);
|
|
|
+ for (DeviceTypeEntity entity : entities) {
|
|
|
+ redisUtils.set(String.format(RedisConstants.SYNC_PRODUCT_ID, entity.getIotProductId()), entity.getId().toString());
|
|
|
+ log.info("同步产品:" + entity.getManufacturerName() +"-" + entity.getDeviceType() +"-"+ entity.getDeviceMode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ */
|
|
|
+/**
|
|
|
+ * 同步产品下面的其他属性
|
|
|
+ * @author Andy
|
|
|
+ * @date 10:40 2021/10/25
|
|
|
+ * @param voList:
|
|
|
+ * @return void
|
|
|
+ **//*
|
|
|
+
|
|
|
+ abstract void sync(List<ProductDetailVo> voList);
|
|
|
+
|
|
|
+}
|
|
|
+*/
|