15928045575 %!s(int64=2) %!d(string=hai) anos
pai
achega
3f10be741f

+ 3 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/mysql/KwsReportTemplateMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate;
 import com.sckw.slope.detection.model.param.StatementQuery;
+import com.sckw.slope.detection.model.vo.DeviceVo;
 import com.sckw.slope.detection.model.vo.ReportDetailVO;
 import com.sckw.slope.detection.model.vo.ReportStatementVO;
 import org.apache.ibatis.annotations.Mapper;
@@ -29,4 +30,6 @@ public interface KwsReportTemplateMapper extends BaseMapper<KwsReportTemplate> {
     List<ReportStatementVO> selectListByReportNameAndProjectId(@Param("query") StatementQuery query, @Param("companyId") String companyId);
 
     ReportDetailVO selectDataAndTemplate(@Param("id") Long id);
+
+    List<DeviceVo> selectDeviceByProjectId(@Param("projectId") String projectId,@Param("list") List<String> list);
 }

+ 2 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/dao/tdengine/SlopeDataMapper.java

@@ -32,6 +32,8 @@ public interface SlopeDataMapper extends BaseMapper<SlopeData> {
 
     List<SlopeData> selectLineListByArray(@Param("snCode") String snCode, @Param("parts") String[] parts, @Param("dateStart") String dateStart, @Param("dateEnd") String dateEnd);
 
+    List<SlopeData> selectLineListByList(@Param("snCode") String snCode, @Param("parts") List<String> parts, @Param("dateStart") String dateStart, @Param("dateEnd") String dateEnd);
+
     int insertData(@Param("slopeData") SlopeData slopeData);
 
     List<SlopeData> selectListByLineOrderByCreateTime(@Param("snCode") String snCode, @Param("item") String item);

+ 5 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/model/vo/DeviceVo.java

@@ -194,6 +194,11 @@ public class DeviceVo implements Serializable {
      */
     private List<DevicePartModelVo> part;
 
+    /**
+     * data
+     */
+    private List<Object> data;
+
 
 
 

+ 2 - 2
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java

@@ -66,7 +66,7 @@ public class CommonService {
 //        }
         String message = new String(Base64.getDecoder().decode(uInfo));
         HeaderData headerData = JSONObject.parseObject(message, HeaderData.class);
-        if (headerData.getMountainId().isBlank()) {
+        /*if (headerData.getMountainId().isBlank()) {
             throw new BusinessException("矿山id不能为空");
         }
         if (headerData.getCompanyId().isBlank()) {
@@ -74,7 +74,7 @@ public class CommonService {
         }
         if (headerData.getCompanyName().isBlank()) {
             throw new BusinessException("企业名称不能为空");
-        }
+        }*/
         return headerData;
     }
 

+ 0 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java

@@ -269,7 +269,6 @@ public class DeviceService {
         HeaderData headerData = commonService.getHeaderData(response);
         List<KwsDeviceReference> references = deviceReferenceMapper.selectList(new LambdaQueryWrapper<KwsDeviceReference>()
                 .eq(KwsDeviceReference::getDeviceId, id)
-                .eq(KwsDeviceReference::getMountainId, headerData.getMountainId())
                 .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)
         );
         String snCode = device.getSnCode();

+ 47 - 4
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/task/ReportTemplateTaskService.java

@@ -5,15 +5,24 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.sckw.core.model.enums.ReportTypeEnum;
 import com.sckw.slope.detection.dao.mysql.KwsReportTemplateMapper;
 import com.sckw.slope.detection.model.dos.mysql.KwsReportTemplate;
+import com.sckw.slope.detection.model.dos.mysql.KwsThreshold;
+import com.sckw.slope.detection.model.dos.tdengine.SlopeData;
+import com.sckw.slope.detection.model.vo.DeviceVo;
 import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
+import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
 
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
-import java.util.List;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author lfdc
@@ -29,10 +38,13 @@ public class ReportTemplateTaskService {
     @Resource
     KwsReportTemplateMapper reportTemplateMapper;
 
+    @Autowired
+    SlopeDataMapper slopeDataMapper;
+
     /**
      * 报表生成定时任务-天
      */
-        // @Scheduled(cron = "* * * * * *")
+    //@Scheduled(cron = "* * * * * *")
     public void templateTaskDay() {
         List<KwsReportTemplate> kwsReportTemplates = reportTemplateMapper.selectList(new LambdaQueryWrapper<KwsReportTemplate>()
                 .eq(KwsReportTemplate::getStatus, 0)
@@ -44,9 +56,40 @@ public class ReportTemplateTaskService {
                     LocalDateTime localDateTime = LocalDateTime.now().minusDays(1);
                     LocalDateTime dateEnd = com.sckw.excel.utils.DateUtil.localDateToLocalDateTimeEnd(localDateTime.toLocalDate());
                     LocalDateTime dateStart = com.sckw.excel.utils.DateUtil.localDateToLocalDateTimeStart(localDateTime.toLocalDate());
-                    //
-                }
+                    String date1 = dateStart.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                    String date2 = dateEnd.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                    String[] part = kwsReportTemplate.getPartNames().split(",");
+                    String[] intergration = kwsReportTemplate.getIntergrationNames().split(",");
+                    List<String> list = new ArrayList<>();
+                    list.addAll(Arrays.asList(part));
+                    list.addAll(Arrays.asList(intergration));
+                    String projectId = kwsReportTemplate.getProjectId();
+                    //首先查询模板中的要素关联的设备-项目中的设备
+                    List<DeviceVo> devices = reportTemplateMapper.selectDeviceByProjectId(projectId,list);
+                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                    for (DeviceVo vo : devices){
+                        List<SlopeData> selectedData = slopeDataMapper.selectLineListByList(vo.getSnCode(), list, "2022-1-1 00:00:00", date2);
+                        if(Objects.nonNull(selectedData)){
+                            Map<String,List<SlopeData>> map = selectedData.stream().collect(Collectors.groupingBy(SlopeData::getMsgId));
 
+                            List<Object> list1 = new ArrayList<>();
+                            map.forEach((key,value) -> {
+                                Map<Object,Object> mapdata = new HashMap<>();
+                                value.forEach(valuetemp->{
+                                    mapdata.put("ts",sdf.format(valuetemp.getTs()));
+                                    for (int i = 0;i< list.size();i++){
+                                       // if(valuetemp.getLine().equals(list[i].get("line"))){
+                                            mapdata.put(valuetemp.getLine(),valuetemp.getVal());
+                                        //}
+                                    }
+                                });
+                                list1.add(map);
+                            });
+                            vo.setData(list1);
+                        }
+                    }
+                    log.info("aaa:{}",devices);
+                }
             }
         }
     }

+ 4 - 1
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml

@@ -57,8 +57,11 @@
                left join kws_project as p on pd.project_id = p.id
       WHERE d.del_flag = 0
         and m.del_flag = 0
-        and d.mountain_id = #{deviceQuery.mountainId}
 
+      <if test="deviceQuery.mountainId != null and deviceQuery.mountainId != ''">
+          and d.mountain_id = #{deviceQuery.mountainId,jdbcType=BIGINT}
+          , '%')
+      </if>
           <if test="deviceQuery.deviceName != null and deviceQuery.deviceName != ''">
               and d.name like concat('%', #{deviceQuery.deviceName}
                    , '%')

+ 3 - 1
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceModelMapper.xml

@@ -43,13 +43,15 @@
         <include refid="Base_Column_List"/>
         from kws_device_model
         where del_flag = 0
-          and mountain_id = #{deviceModelQuery.mountainId}
         <if test="deviceModelQuery.name != null and deviceModelQuery.name != ''">
             and name like concat('%', #{deviceModelQuery.name}, '%')
         </if>
         <if test="deviceModelQuery.status != null and deviceModelQuery.status != ''">
             and status = #{deviceModelQuery.Status,jdbcType=TINYINT}
         </if>
+        <if test="deviceModelQuery.mountainId != null and deviceModelQuery.mountainId != ''">
+            and mountain_id = #{deviceModelQuery.mountainId,jdbcType=BIGINT}
+        </if>
         order by create_time desc
     </select>
     <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">

+ 14 - 0
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsReportTemplateMapper.xml

@@ -219,4 +219,18 @@
                  LEFT JOIN kws_report_data b ON a.id = b.template_id
         WHERE id = #{id,jdbcType=BIGINT}
     </select>
+
+    <select id="selectDeviceByProjectId" resultType="com.sckw.slope.detection.model.vo.DeviceVo">
+        select DISTINCT d.id,d.sn_code from kws_device_reference as r
+            inner join kws_device as d on r.device_id=d.id
+            inner join kws_project_device as p on p.device_id=d.id
+        where p.del_flag=0 and d.del_flag=0 and r.del_flag=0
+        and project_id=#{projectId}
+        <if test="list != null">
+            and r.item in
+            <foreach collection="list" index="index" separator="," open="(" close=")" item="list">
+                #{list}
+            </foreach>
+        </if>
+    </select>
 </mapper>

+ 19 - 0
slope-modules/slope-detection/src/main/resources/mapper/tdengine/SlopeDataMapper.xml

@@ -91,6 +91,25 @@
         order by ts desc limit 0,1000
     </select>
 
+    <select id="selectLineListByList" resultType="com.sckw.slope.detection.model.dos.tdengine.SlopeData">
+        SELECT
+        line,
+        val,
+        msg_id      as msgId,
+        ts
+        FROM devicesv2.device_#{snCode}
+        where  ts &gt;= #{dateStart} and ts &lt;= #{dateEnd}
+
+        <if test="parts != null">
+            and line in
+            <foreach collection="parts" index="index" separator="," open="(" close=")" item="parts">
+                #{parts}
+            </foreach>
+        </if>
+
+        order by ts desc limit 0,50
+    </select>
+
     <select id="selectTableIsExit">
         select * from information_schema.ins_tables a where a.db_name = 'devices' and a.table_name = #{name}
     </select>