lin há 3 anos atrás
pai
commit
86be0de29d

+ 8 - 8
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/mapper/AlarmTypeDetailMapper.xml

@@ -3,32 +3,32 @@
 <mapper namespace="com.zcxk.rmcp.core.dao.AlarmTypeDetailMapper">
 
     <sql id="permissionCondition">
-        <if test="userCondition.tenantId != null">and sat.tenant_id = #{userCondition.tenantId}</if>
+        <if test="userCondition.tenantId != null">and sd.tenant_id = #{userCondition.tenantId}</if>
         <if test="userCondition.userType!=null and userCondition.userType!=-999 and userCondition.userType!=-9999 and  userCondition.programItems != null and userCondition.programItems.size() > 0">
             <if test="userCondition.permissionType == 5 or userCondition.permissionType == 2">
-                and ( sat.dept_org_id in
+                and ( sd.dept_org_id in
                 <foreach collection="userCondition.programItems" item="item" open="(" close=")" separator=",">
                     #{item.orgId}
                 </foreach>
                 or
-                sat.company_org_id in
+                sd.company_org_id in
                 <foreach collection="userCondition.programItems" item="item" open="(" close=")" separator=",">
                     #{item.orgId}
                 </foreach>
                 )
             </if>
             <if test="userCondition.permissionType == 4 or userCondition.permissionType == 3">
-                and sat.dept_org_id in
+                and sd.dept_org_id in
                 <foreach collection="userCondition.programItems" item="item" open="(" close=")" separator=",">
                     #{item.orgId}
                 </foreach>
             </if>
             <if test="userCondition.permissionType == 1">
-                and sat.company_org_id in
+                and sd.company_org_id in
                 <foreach collection="userCondition.programItems" item="item" open="(" close=")" separator=",">
                     #{item.orgId}
                 </foreach>
-                and (sat.dept_org_id is null or sat.dept_org_id =0)
+                and (sd.dept_org_id is null or sd.dept_org_id =0)
             </if>
         </if>
     </sql>
@@ -68,10 +68,10 @@
             <if test="dto.alarmCategory != null and dto.alarmCategory!=''" >
                 and sat.alarm_category like concat('%', #{dto.alarmCategory}, '%')
             </if>
-            <if test="dto.startTime != null">
+            <if test="dto.startTime != null and dto.startTime!=''">
                 and sad.alarm_start_time >=#{dto.startTime}
             </if>
-            <if test="dto.endTime != null">
+            <if test="dto.endTime != null and dto.endTime!=''">
                 and sad.alarm_end_time &lt;= #{dto.endTime}
             </if>
             <if test="dto.state != null">

+ 178 - 0
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/AbstractProductSyncService.java

@@ -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);
+
+}
+*/

+ 3 - 1
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/DeviceServiceImpl.java

@@ -209,9 +209,11 @@ public class DeviceServiceImpl implements DeviceService{
         }
 
         Product product = productService.findById(dto.getProductId());
+        Device deviceTemp = deviceMapper.findById(dto.getId());
 
         DeviceDTO deviceDTO = this.covertDeviceDTO(dto, product,null);
-        deviceDTO.setId(dto.getId());
+        deviceDTO.setId(deviceTemp.getIotDeviceId());
+
         Long iotDeviceId = syncDeviceService.updateDevice(deviceDTO);
         if (iotDeviceId== null || iotDeviceId == 0) {
             throw BusinessException.builder(500, "同步更新物联网失败");