| | |
| | | } |
| | | return result; |
| | | } |
| | | /* |
| | | public static Boolean clearWorkStationCache() { |
| | | String redisKey = "posting:workstation".concat("::").concat(WORKSTATION_ALL); |
| | | return bladeRedis.del(redisKey); |
| | | } |
| | | */ |
| | | |
| | | /** |
| | | * è·åæå®æ¥æçæ¥å代ç |
| | | * @param workstationId |
| | |
| | | return calendarCode; |
| | | } |
| | | |
| | | public GlobalWcsOfRps getWorkstationWcsSetting(Long workstationId, String code) { |
| | | public GlobalWcsOfRps getWorkstationWcsSetting(Long workstationId, String deviceStatusCode) { |
| | | String redisKey = COLLECT_WORKSTATION.concat("::").concat(WORKSTATION_ID).concat(workstationId.toString() |
| | | .concat(WCS_SETTING)); |
| | | |
| | | //GlobalWcsOfRps wcsSetting = (GlobalWcsOfRps)redisUtil.hGet(redisKey, code); |
| | | GlobalWcsOfRps wcsSetting = (GlobalWcsOfRps)redisUtil.hget(redisKey, code); |
| | | GlobalWcsOfRps wcsSetting = (GlobalWcsOfRps)redisUtil.hget(redisKey, deviceStatusCode); |
| | | if (wcsSetting == null) { |
| | | wcsSetting = globalWcsOfRpsMapper.selectOne(Wrappers.<GlobalWcsOfRps>lambdaQuery() |
| | | .eq(GlobalWcsOfRps::getCode, code) |
| | | .eq(GlobalWcsOfRps::getCode, deviceStatusCode) |
| | | .isNull(GlobalWcsOfRps::getPrecondition)); |
| | | if(wcsSetting == null) { |
| | | wcsSetting = new GlobalWcsOfRps(); |
| | |
| | | //wcsSetting = Func.isNotEmpty(wcsSetting) ? wcsSetting : GlobalWcsOfRps.builder().rps(0).isPlan(0).build(); |
| | | //bladeRedis.hSet(redisKey, code, wcsSetting); |
| | | //bladeRedis.expire(redisKey, Duration.ofDays(1L)); |
| | | redisUtil.hset(redisKey, code, wcsSetting, Duration.ofDays(1L).getSeconds()); |
| | | redisUtil.hset(redisKey, deviceStatusCode, wcsSetting, Duration.ofDays(1L).getSeconds()); |
| | | } |
| | | return wcsSetting; |
| | | } |
| | |
| | | |
| | | @Value("${mqtt.password:}") |
| | | private String mqttPassword; |
| | | |
| | | @Value("${mqtt.timeout:1000}") |
| | | private int timeout; |
| | | |
| | | @Autowired |
| | | private IOTMqttReceiveService recService; |
| | | @Autowired |
| | |
| | | DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory(); |
| | | MqttConnectOptions options = new MqttConnectOptions(); |
| | | options.setServerURIs(new String[] { mqttHost});//"tcp://82.156.1.83:1884" |
| | | options.setConnectionTimeout(timeout); |
| | | |
| | | if(ObjectUtil.isNotEmpty(mqttUserName)) { |
| | | options.setUserName(mqttUserName); |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.qianwen.mdc.collect.config; |
| | | |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Component |
| | | @ConfigurationProperties(prefix = "mqtt") |
| | | public class MqttProperties { |
| | | private String host; |
| | | private String username; |
| | | private String password; |
| | | private String connectionTimeout; |
| | | |
| | | private int keepalive; |
| | | private String dataReceiveTopic; |
| | | private int timeout; |
| | | private boolean cleansession; |
| | | |
| | | } |
| | |
| | | * åè¦æ¨¡æ¿åç§° alarm |
| | | */ |
| | | public static final String TEMPLATE_ALARM = "alarm"; |
| | | |
| | | /** |
| | | * è¿ç¨åæ°è¡¨æ¨¡æ¿ |
| | | */ |
| | | public static final String TEMPLATE_PROCESS_PARAM = "process_param"; |
| | | } |
| | |
| | | import com.qianwen.mdc.collect.mapper.iotdb.ProcessParamMapper; |
| | | import com.qianwen.mdc.collect.mapper.mgr.CalendarMapper; |
| | | import com.qianwen.mdc.collect.mqtt.MqttMessageSender; |
| | | import com.qianwen.mdc.collect.service.DeviceOfflineCheckService; |
| | | import com.qianwen.mdc.collect.service.DeviceStateFixPointService; |
| | | import com.qianwen.mdc.collect.service.IOTMqttReceiveService; |
| | | import com.qianwen.mdc.collect.service.IotDBCommonService; |
| | |
| | | public class CalController { |
| | | @Autowired |
| | | private TimeSliceCache timeSliceCache; |
| | | |
| | | @Autowired |
| | | DeviceOfflineCheckService offService; |
| | | String calCode= "1"; |
| | | |
| | | @GetMapping("/gett") |
| | |
| | | |
| | | return "settOK,targetDate="+targetDate; |
| | | } |
| | | |
| | | @GetMapping("/offline") |
| | | public Object off(long wid) { |
| | | offService.handleWorkstationOffline(wid); |
| | | return "1"; |
| | | } |
| | | } |
| | |
| | | |
| | | @GetMapping("/last") |
| | | public Object last() { |
| | | List<ProcessParam> list1= mapper.mylist(1656819188967653378L); |
| | | System.out.print(list1); |
| | | return list1; |
| | | //ProcessParam last= mapper.lastParamInDuration(1656819188967653378L,300000); |
| | | //System.out.print(list1); |
| | | return "dd"; |
| | | } |
| | | |
| | | @DS("iotdb") |
| | |
| | | package com.qianwen.mdc.collect.dto; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * ç产æ¥åççå¶ä¿¡æ¯ |
| | | */ |
| | | public class CalendarShiftInfoDTO { |
| | | private Long workstationId; |
| | | private String code; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.qianwen.mdc.collect.job; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.qianwen.mdc.collect.service.DeviceOfflineCheckService; |
| | | import com.xxl.job.core.biz.model.ReturnT; |
| | | import com.xxl.job.core.handler.annotation.XxlJob; |
| | | import com.xxl.job.core.log.XxlJobLogger; |
| | | |
| | | @Component |
| | | public class DeviceOfflineStatusCheckJob { |
| | | private static final Logger log = LoggerFactory.getLogger(DeviceOfflineStatusCheckJob.class); |
| | | @Resource |
| | | private DeviceOfflineCheckService offlineCheckService; |
| | | |
| | | |
| | | @XxlJob("offlineCheckJobHandler") |
| | | public ReturnT<String> offlineCheckJobHandler(String param) throws Exception { |
| | | XxlJobLogger.log("宿¶çæ§å·¥ä½æ¯å¦ç¦»çº¿",param); |
| | | |
| | | offlineCheckService.checkOffline(); |
| | | log.info("ç¦»çº¿ç¶æå¤çç»æ"); |
| | | XxlJobLogger.log("宿¶çæ§å·¥ä½æ¯å¦ç¦»çº¿å®æ", new Object[0]); |
| | | return ReturnT.SUCCESS; |
| | | } |
| | | } |
| | |
| | | package com.qianwen.mdc.collect.mapper.iotdb; |
| | | |
| | | import java.util.List; |
| | | |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | |
| | | @DS("iotdb") |
| | | public interface ProcessParamMapper { |
| | | |
| | | |
| | | List<ProcessParam> mylist(@Param("workstationId") Long workstationId); |
| | | /** |
| | | * æ¥è¯¢å·¥ä½å¨æè¿duration毫ç§å
æåä¸ä¸ªåæ° |
| | | * @param workstationId |
| | | * @param duration |
| | | * @return |
| | | */ |
| | | ProcessParam lastParamByWorstationId(@Param("workstationId") Long workstationId); |
| | | |
| | | } |
| | |
| | | shiftEndTime = endTime; |
| | | } |
| | | CalendarShiftTimeSlicesDTO calendarShiftTimeSlicesDTO = CalendarShiftTimeSlicesDTO.builder().shiftTimeType(productionCalendarDaytime.getShiftType().toString()).endTime(LocalDateTimeUtils.LocalDateTimeToDate(shiftEndTime)).startTime(LocalDateTimeUtils.LocalDateTimeToDate(shiftStartTime)).shiftIndex(productionCalendarDaytime.getShiftIndex()).shiftTimeType(productionCalendarDaytime.getShiftType().toString()).factoryDate(LocalDateTimeUtils.formatTimeLocalDate(productionCalendarDaytime.getCalendarDate(), "yyyy-MM-dd")).factoryMonth(productionCalendarDaytime.getMonth()).factoryWeek(productionCalendarDaytime.getWeek()).factoryYear(productionCalendarDaytime.getYear()).build(); |
| | | timeSlicesDTOMap.put(Integer.valueOf(minutesOfDay), calendarShiftTimeSlicesDTO); |
| | | timeSlicesDTOMap.put(minutesOfDay, calendarShiftTimeSlicesDTO); |
| | | } |
| | | } |
| | |
| | | Tablet tablet = new Tablet(deviceId, schemas); |
| | | for(TypedTelemetryData tdata : typeList) { |
| | | |
| | | |
| | | rowIndex = tablet.rowSize++; |
| | | tablet.addTimestamp(rowIndex, tdata.getTime()); |
| | | tablet.addValue("workstation_id",rowIndex,dt.getWorkstationId()); |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.qianwen.mdc.collect.service; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.qianwen.mdc.collect.cache.WorkstationCache; |
| | | import com.qianwen.mdc.collect.dto.WorkstationDTO; |
| | | import com.qianwen.mdc.collect.entity.iotdb.DeviceState; |
| | | import com.qianwen.mdc.collect.entity.iotdb.ProcessParam; |
| | | import com.qianwen.mdc.collect.enums.FeedbackTimePointEnum; |
| | | import com.qianwen.mdc.collect.mapper.iotdb.ProcessParamMapper; |
| | | import com.qianwen.mdc.collect.vo.FactoryDataVO; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | /** |
| | | * 设å¤ç¦»çº¿å¤çæå¡,è¶
è¿ä¸å®æ¶é´æ ééæ°æ®å¤å®ä¸ºç¦»çº¿ï¼æå
¥ç¦»çº¿ç¶ææ°æ® |
| | | */ |
| | | @Service |
| | | public class DeviceOfflineCheckService{ |
| | | private static final Logger log = LoggerFactory.getLogger(DeviceOfflineCheckService.class); |
| | | /** |
| | | * 离线å¤å®æ¶é¿ï¼é»è®¤5åé |
| | | */ |
| | | @Value("${offlineConfigDuration:3000000}") |
| | | private long offlineConfigDuration; |
| | | public static final String OFFLINE_VALUE = "4";//ç¦»çº¿ç¶æå¼ |
| | | @Autowired |
| | | private ProcessParamService paramService; |
| | | |
| | | @Autowired |
| | | private WorkstationCache workstationCache; |
| | | @Autowired |
| | | private ProcessParamMapper processParamMapper; |
| | | |
| | | @Autowired |
| | | private FactoryDataService factoryDataService; |
| | | /** |
| | | * ä¿åç¶æåºå®ç¹æ°æ®(state_{workstationId}) |
| | | * @param workstationIdList |
| | | */ |
| | | public void checkOffline() { |
| | | //å°æ°æ®æç
§å·¥ä½idåç» |
| | | Map<String, WorkstationDTO> workstationsMap = workstationCache.getWorkstations(); |
| | | if (ObjectUtil.isEmpty(workstationsMap)) { |
| | | log.info("ç¼åæ è®¾å¤æ°æ®ï¼éåº"); |
| | | return; |
| | | } |
| | | |
| | | Set<String> workstationIds = workstationsMap.keySet(); |
| | | |
| | | log.info("ç¦»çº¿æ£æ¥å·¥ä½æ»æ°:{}",workstationsMap.size()); |
| | | |
| | | for(String workstationId :workstationIds) { |
| | | log.info("å¼å§æ£æ¥å·¥ä½{}çç¦»çº¿ç¶æ",workstationId); |
| | | Long wid = Long.parseLong(workstationId); |
| | | handleWorkstationOffline(wid); |
| | | } |
| | | |
| | | } |
| | | /** |
| | | * æ£æ¥ä¸ä¸ªå·¥ä½æ¯å¦ç¦»çº¿ï¼ç¦»çº¿åå¡«å
ç¦»çº¿ç¶ææ°æ® |
| | | * @param workstationId |
| | | */ |
| | | public void handleWorkstationOffline(long workstationId) { |
| | | ProcessParam lastParam = processParamMapper.lastParamByWorstationId(workstationId); |
| | | |
| | | long nowMills = System.currentTimeMillis(); |
| | | long onlineRange = nowMills - offlineConfigDuration; |
| | | if(lastParam != null && lastParam.getTime()> onlineRange) { |
| | | //ææ°æ®ï¼ä¸å¨å¤å®æ¶é´å
-ãå¨çº¿ |
| | | return; |
| | | } |
| | | //TODO è¿éä¸ç´ç¦»çº¿æ¯ä»ä¹æ°æ® |
| | | |
| | | //æ¶é´æ®µå
æ åæ°ï¼è¯´æè®¾å¤æ²¡ééæ°æ®å¤å®ä¸ºç¦»çº¿ï¼æå
¥ç¶æï¼ç¶ååérealTimeæ¶æ¯ç»mdc |
| | | |
| | | ProcessParam statusParam = new ProcessParam(); |
| | | statusParam.setTime(nowMills); |
| | | statusParam.setN("DeviceStatus"); |
| | | statusParam.setV(OFFLINE_VALUE); |
| | | statusParam.setWorkstationId(workstationId); |
| | | if(lastParam == null || !lastParam.getN().equals("DeviceStatus")) { |
| | | //ä¹åæ ä»»ä½ééçæ°æ®(æè
ä¸ä¸æ¡ä¸æ¯ç¶ææ°æ®)ï¼æ°å 䏿¡ç¦»çº¿ç¶ææ°æ® |
| | | paramService.insertProcessParam(statusParam); |
| | | } |
| | | |
| | | //éç¥mdcæ´æ°å®æ¶ç¶æ |
| | | paramService.sendRealtimeDataMsg(statusParam); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | return default24HourPointDTOList; |
| | | } |
| | | |
| | | /** |
| | | * å¡«å
设å¤ç¶æççæ¬¡ä¿¡æ¯ |
| | | * @param calendarShiftList |
| | | * @param default24HourPointDTOList |
| | | * @param state |
| | | */ |
| | | private void packCalendarShiftInfoForTimePoint(List<CalendarShiftInfoDTO> calendarShiftList, List<DeviceState> default24HourPointDTOList, DeviceState state) { |
| | | if (Func.isNotEmpty(calendarShiftList)) { |
| | | if (Func.isEmpty(calendarShiftList)) { |
| | | log.error("å·¥ä½{} æ¥å{} æ æ¥æ:[{}]ççæ¬¡ä¿¡æ¯", new Object[]{state.getWorkstationId(), state.getCalendarCode(), state.getTime()}); |
| | | return; |
| | | } |
| | | |
| | | CalendarShiftInfoDTO relatedShift = calendarShiftList.stream().filter(item -> { |
| | | return item.getStartTime().getTime() <= state.getTime().longValue() && item.getEndTime().getTime() > state.getTime().longValue(); |
| | | return item.getStartTime().getTime() <= state.getTime() && item.getEndTime().getTime() > state.getTime(); |
| | | }).findFirst().orElse(null); |
| | | |
| | | if (Func.isNotEmpty(relatedShift)) { |
| | |
| | | String factoryDate = relatedShift.getFactoryDate(); |
| | | String[] split = Func.split(factoryDate, "-"); |
| | | state.setFactoryDate(Integer.valueOf(String.join("", split))); |
| | | state.setIsDeleted(Boolean.FALSE); |
| | | state.setIsDeleted(false); |
| | | default24HourPointDTOList.add(state); |
| | | return; |
| | | }else { |
| | | log.warn("å·¥ä½{} æ¥å{} æªæ¾å°åºå®ç¹ç次信æ¯", state.getWorkstationId(), state.getCalendarCode()); |
| | | } |
| | | log.warn("å·¥ä½{} æ¥å{} æªæ¾å°æ´ç¹ç次信æ¯", state.getWorkstationId(), state.getCalendarCode()); |
| | | return; |
| | | } |
| | | log.error("å·¥ä½{} æ¥å{} æ èªç¶å¤©{}çæ¬¡ä¿¡æ¯", new Object[]{state.getWorkstationId(), state.getCalendarCode(), state.getTime()}); |
| | | } |
| | | |
| | | //ä¸ä¸å®è½ç¨ä¸ |
| | |
| | | workstationState.setShiftIndex(CommonConstant.DEFAULT_SHIFT_INDEX); |
| | | workstationState.setShiftTimeType(CommonConstant.DEFAULT_SHIFT_TYPE); |
| | | workstationState.setFeedbackPointType(FeedbackTimePointEnum.NO_FEED_BACK_POINT.getValue()); |
| | | workstationState.setIsDeleted(Boolean.FALSE); |
| | | workstationState.setIsDeleted(false); |
| | | } |
| | | } |
| | | } |
| | |
| | | package com.qianwen.mdc.collect.service; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Map.Entry; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.google.common.collect.Lists; |
| | | import com.qianwen.core.tool.utils.Func; |
| | | import com.qianwen.core.tool.utils.SpringUtil; |
| | | import com.qianwen.mdc.collect.cache.WorkstationCache; |
| | | import com.qianwen.mdc.collect.config.IotDBSessionConfig; |
| | | import com.qianwen.mdc.collect.constants.CommonConstant; |
| | | import com.qianwen.mdc.collect.constants.IOTDBConstant; |
| | | import com.qianwen.mdc.collect.dto.CalendarShiftInfoDTO; |
| | | import com.qianwen.mdc.collect.dto.WorkstationDTO; |
| | | import com.qianwen.mdc.collect.entity.iotdb.DeviceState; |
| | | import com.qianwen.mdc.collect.enums.FeedbackTimePointEnum; |
| | | import com.qianwen.mdc.collect.mapper.mgr.CalendarMapper; |
| | | import com.qianwen.mdc.collect.utils.LocalDateTimeUtils; |
| | | |
| | | import cn.hutool.core.date.DatePattern; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | /** |
| | | * 设å¤ç¶ææ®éæå¡ |
| | | */ |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.qianwen.mdc.collect.service; |
| | | |
| | | import java.time.Instant; |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneOffset; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.google.common.collect.Sets; |
| | | import com.qianwen.mdc.collect.cache.TimeSliceCache; |
| | | import com.qianwen.mdc.collect.cache.WorkstationCache; |
| | | import com.qianwen.mdc.collect.constants.CommonConstant; |
| | | import com.qianwen.mdc.collect.domain.TelemetryData; |
| | | import com.qianwen.mdc.collect.domain.TelemetryDataItem; |
| | | import com.qianwen.mdc.collect.dto.CacheBuildDTO; |
| | | import com.qianwen.mdc.collect.dto.CalendarShiftTimeSlicesDTO; |
| | | import com.qianwen.mdc.collect.dto.PackedTelemetryData; |
| | | import com.qianwen.mdc.collect.handler.PackedTelemetryDataHandlerSelector; |
| | | import com.qianwen.mdc.collect.handler.TelemetryDataHandler; |
| | | import com.qianwen.mdc.collect.utils.LocalDateTimeUtils; |
| | | import com.qianwen.mdc.collect.vo.FactoryDataVO; |
| | | |
| | | import cn.hutool.core.date.DatePattern; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | |
| | | /** |
| | | * 工忰æ®è·å |
| | | */ |
| | | @Service |
| | | public class FactoryDataService { |
| | | private static final Logger log = LoggerFactory.getLogger(FactoryDataService.class); |
| | | |
| | | private static final Map<Integer, String> PROCESS_PARAM_MAP = new HashMap<>(); |
| | | |
| | | |
| | | @Autowired |
| | | private WorkstationCache workstationCache; |
| | | @Autowired |
| | | private TimeSliceCache timeSliceCache; |
| | | |
| | | /** |
| | | * å¡«å
ç产æ¥åcodeï¼ä»¥åfactoryyear |
| | | * |
| | | * @param pdata |
| | | */ |
| | | public FactoryDataVO getFactoryData(long workstationId,long dataCollectTime) { |
| | | //忥å¨TelemetryPropertyWrapper.packWorkstationCalendarInfoä¸å®æ |
| | | FactoryDataVO result = new FactoryDataVO(); |
| | | |
| | | Date collectTime = new Date(dataCollectTime); |
| | | String calendarCode = workstationCache.getWorkstationCalendarCodeForDate(workstationId, DateUtil.formatDate(DateUtil.date(collectTime))); |
| | | if (ObjectUtil.isNotEmpty(calendarCode)) { |
| | | result.setCalendarCode(calendarCode); |
| | | } else { |
| | | //telemetryData.setCalendarCode("#default#"); |
| | | result.setCalendarCode("#default#"); |
| | | } |
| | | |
| | | // TelemetryPropertyWrapperä¸packWorkstationCalendarInfo |
| | | //------------start |
| | | boolean isDefaultCalendar = true; |
| | | if (!"#default#".equals(result.getCalendarCode())) { |
| | | CalendarShiftTimeSlicesDTO calendarShiftTimeSlicesDTO = timeSliceCache.getTimeSliceShift(result.getCalendarCode(), collectTime);//ä»redisä¸è·å¾æ¥åçæ¶é´åç |
| | | if (ObjectUtil.isEmpty(calendarShiftTimeSlicesDTO)) {//å¦ææ²¡ææ¶é´åçï¼å使ç¨TimeSliceCache.build(cacheBuildDTO);æå»º |
| | | LocalDate targetDate = Instant.ofEpochMilli(dataCollectTime).atZone(ZoneOffset.systemDefault()).toLocalDate(); |
| | | CacheBuildDTO cacheBuildDTO = CacheBuildDTO.builder().tenantIds(Sets.newHashSet(new String[]{"000000"})).calendarCode(calendarCode).targetDate(targetDate).build(); |
| | | timeSliceCache.build(cacheBuildDTO); |
| | | calendarShiftTimeSlicesDTO = timeSliceCache.getTimeSliceShift(result.getCalendarCode(), collectTime); |
| | | } |
| | | if (ObjectUtil.isNotEmpty(calendarShiftTimeSlicesDTO)) { |
| | | result.setShiftIndex(calendarShiftTimeSlicesDTO.getShiftIndex()); |
| | | result.setShiftTimeType(Integer.valueOf(calendarShiftTimeSlicesDTO.getShiftTimeType())); |
| | | result.setFactoryDate(Integer.valueOf(calendarShiftTimeSlicesDTO.getFactoryDate().replaceAll("-", ""))); |
| | | result.setFactoryWeek(calendarShiftTimeSlicesDTO.getFactoryWeek()); |
| | | result.setFactoryMonth(calendarShiftTimeSlicesDTO.getFactoryMonth()); |
| | | result.setFactoryYear(calendarShiftTimeSlicesDTO.getFactoryYear()); |
| | | isDefaultCalendar = false; |
| | | } |
| | | } |
| | | |
| | | //æ æ¥ååçï¼ä½¿ç¨ééæ¶é´å¡«å
factoryYearï¼monthï¼dateï¼weekå ä¸ªå±æ§ |
| | | if (isDefaultCalendar) { |
| | | log.info("æ æ¥ååç"); |
| | | LocalDate localDate = Instant.ofEpochMilli(dataCollectTime).atZone(ZoneOffset.systemDefault()).toLocalDate(); |
| | | result.setFactoryDate(Integer.valueOf(DatePattern.PURE_DATE_FORMAT.format(collectTime))); |
| | | result.setFactoryYear(DateUtil.year(collectTime)); |
| | | result.setFactoryWeek(LocalDateTimeUtils.getWeek(localDate)); |
| | | result.setFactoryMonth(DateUtil.month(collectTime) + 1); |
| | | result.setShiftIndex(CommonConstant.DEFAULT_SHIFT_INDEX); |
| | | result.setShiftTimeType(CommonConstant.DEFAULT_SHIFT_TYPE); |
| | | } |
| | | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | } |
| | |
| | | try { |
| | | iotdbCfg.getSessionPool().setSchemaTemplate(template, deviceId); |
| | | } catch (Exception e) { |
| | | logger.error("è·å模æ¿ä½¿ç¨é误,template="+template+",deviceId="+deviceId,e); |
| | | logger.error("为deviceId设置模æ¿é误,template="+template+",deviceId="+deviceId,e); |
| | | } |
| | | } |
| | | } |
| | |
| | | private WorkstationCache workstationCache; |
| | | @Autowired |
| | | private TimeSliceCache timeSliceCache; |
| | | @Autowired |
| | | private WorkstationDatapointsService dpService; |
| | | |
| | | static { |
| | | PROCESS_PARAM_MAP.put(1, "STATE"); |
| | |
| | | //telemetryData.setCalendarCode("#default#"); |
| | | pdata.setCalendarCode("#default#"); |
| | | } |
| | | |
| | | //pdata.setShiftIndex(1);//ä¸´æ¶ |
| | | //pdata.setShiftTimeType(1);//ä¸´æ¶ |
| | | |
| | | // TelemetryPropertyWrapperä¸packWorkstationCalendarInfo |
| | | //------------start |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.qianwen.mdc.collect.service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import org.apache.iotdb.isession.pool.SessionDataSetWrapper; |
| | | import org.apache.iotdb.rpc.IoTDBConnectionException; |
| | | import org.apache.iotdb.rpc.StatementExecutionException; |
| | | import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; |
| | | import org.apache.iotdb.tsfile.read.common.RowRecord; |
| | | import org.apache.iotdb.tsfile.write.record.Tablet; |
| | | import org.apache.iotdb.tsfile.write.schema.MeasurementSchema; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.qianwen.core.tool.utils.ObjectUtil; |
| | | import com.qianwen.mdc.collect.config.IotDBSessionConfig; |
| | | import com.qianwen.mdc.collect.constants.IOTDBConstant; |
| | | import com.qianwen.mdc.collect.domain.TelemetryData; |
| | | import com.qianwen.mdc.collect.domain.TelemetryDataItem; |
| | | import com.qianwen.mdc.collect.entity.iotdb.ProcessParam; |
| | | import com.qianwen.mdc.collect.mqtt.MqttMessageSender; |
| | | import com.qianwen.mdc.collect.vo.WorkstationDatapointsVO; |
| | | |
| | | /** |
| | | * ééæ°æ®å¤çå
¥åº |
| | | */ |
| | | @Service |
| | | public class ProcessParamService { |
| | | private static final Logger log = LoggerFactory.getLogger(ProcessParamService.class); |
| | | |
| | | private static final Map<Integer, String> PROCESS_PARAM_MAP = new HashMap<>(); |
| | | @Autowired |
| | | private IotDBSessionConfig iotdbConfig; |
| | | @Autowired |
| | | private IotDBCommonService iotDBCommonService; |
| | | @Autowired |
| | | private MqttMessageSender mqttMessageSender; |
| | | |
| | | |
| | | public static List<MeasurementSchema> schemas = new ArrayList<>(); |
| | | static { |
| | | schemas.add(new MeasurementSchema("workstation_id", TSDataType.INT64)); |
| | | schemas.add(new MeasurementSchema("n", TSDataType.TEXT)); |
| | | schemas.add(new MeasurementSchema("v", TSDataType.TEXT)); |
| | | } |
| | | /** |
| | | * 宿¶æ°æ®topicï¼è¦ä¸mdcéé¢å¾ç¸å |
| | | */ |
| | | public static final String WOCKSTATION_REALTIMEDATA_TOPIC = "mdc/realtimedata"; |
| | | |
| | | |
| | | public void insertProcessParam(ProcessParam param) { |
| | | String deviceId = generateDeviceId(param.getWorkstationId(),param.getN()); |
| | | |
| | | iotDBCommonService.isTemplateSetOnPath(IOTDBConstant.TEMPLATE_PROCESS_PARAM, deviceId); |
| | | |
| | | Tablet tablet = new Tablet(deviceId, schemas); |
| | | int rowIndex = tablet.rowSize++; |
| | | tablet.addTimestamp(rowIndex, param.getTime()); |
| | | tablet.addValue("workstation_id",rowIndex,param.getWorkstationId()); |
| | | tablet.addValue("n",rowIndex,param.getN()); |
| | | tablet.addValue("v",rowIndex,param.getV()); |
| | | try { |
| | | iotdbConfig.getSessionPool().insertAlignedTablet(tablet); |
| | | //updateLastParam(dt.getWorkstationId(),typeList); |
| | | } catch (Exception e) { |
| | | log.error("IOTDBå
¥åºå¤±è´¥",e); |
| | | }finally { |
| | | //iotdbConfig.getSessionPool().clo1se(); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * åé宿¶æ°æ®æ¶æ¯ |
| | | * @param param |
| | | */ |
| | | public void sendRealtimeDataMsg(ProcessParam param) { |
| | | |
| | | //åémqttæ¶æ¯ï¼éç¥mdcæ¶æ¯æ¥äº |
| | | |
| | | JSONObject json = new JSONObject(); |
| | | json.put("workstationId",param.getWorkstationId()); |
| | | json.put("name", param.getN()); |
| | | json.put("value", param.getV()); |
| | | json.put("time", param.getTime()); |
| | | |
| | | mqttMessageSender.sendMessage(WOCKSTATION_REALTIMEDATA_TOPIC, json.toJSONString()); |
| | | |
| | | } |
| | | |
| | | |
| | | String generateDeviceId(long workstationId,String propertyName) { |
| | | return IOTDBConstant.DB_PREFIX+IOTDBConstant.TEMPLATE_PROCESS_PARAM+"_" + workstationId+"_"+propertyName; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.qianwen.mdc.collect.vo; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | |
| | | |
| | | /** |
| | | * 工忰æ®VO |
| | | */ |
| | | public class FactoryDataVO implements Serializable{ |
| | | |
| | | /** |
| | | * åºååï¼åºä¸ºéè¦springç¼å |
| | | */ |
| | | private static final long serialVersionUID = 6558493027948435061L; |
| | | |
| | | private String calendarCode; |
| | | private Integer factoryYear; |
| | | private Integer factoryMonth; |
| | | private Integer factoryWeek; |
| | | private Integer factoryDate; |
| | | private Integer shiftIndex; |
| | | private Integer shiftTimeType; |
| | | public String getCalendarCode() { |
| | | return calendarCode; |
| | | } |
| | | public void setCalendarCode(String calendarCode) { |
| | | this.calendarCode = calendarCode; |
| | | } |
| | | public Integer getFactoryYear() { |
| | | return factoryYear; |
| | | } |
| | | public void setFactoryYear(Integer factoryYear) { |
| | | this.factoryYear = factoryYear; |
| | | } |
| | | public Integer getFactoryMonth() { |
| | | return factoryMonth; |
| | | } |
| | | public void setFactoryMonth(Integer factoryMonth) { |
| | | this.factoryMonth = factoryMonth; |
| | | } |
| | | public Integer getFactoryWeek() { |
| | | return factoryWeek; |
| | | } |
| | | public void setFactoryWeek(Integer factoryWeek) { |
| | | this.factoryWeek = factoryWeek; |
| | | } |
| | | public Integer getFactoryDate() { |
| | | return factoryDate; |
| | | } |
| | | public void setFactoryDate(Integer factoryDate) { |
| | | this.factoryDate = factoryDate; |
| | | } |
| | | public Integer getShiftIndex() { |
| | | return shiftIndex; |
| | | } |
| | | public void setShiftIndex(Integer shiftIndex) { |
| | | this.shiftIndex = shiftIndex; |
| | | } |
| | | public Integer getShiftTimeType() { |
| | | return shiftTimeType; |
| | | } |
| | | public void setShiftTimeType(Integer shiftTimeType) { |
| | | this.shiftTimeType = shiftTimeType; |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | spring: |
| | | redis: |
| | | database: 5 |
| | | database: 2 |
| | | host: 120.46.212.231 |
| | | port: 6379 |
| | | password: root |
| | |
| | | #MQTT-å½å客æ·ç«¯çå¯ä¸æ è¯ |
| | | clientid: mqtt_publish |
| | | default_topic: TEST #å½å客æ·ç«¯çé»è®¤ä¸»é¢(大夿°æ¶å没ä»ä¹ç¨) |
| | | #åéè¶
æ¶æ¶é´ |
| | | mqtt.timeout: 1000 |
| | | #è¿æ¥è¶
æ¶æ¶é´ |
| | | timeout: 3000 |
| | | #å¿è·³æ¶é´ |
| | | keepalive: 10 |
| | | connectionTimeout: 3000 #è¿æ¥è¶
æ¶æ¶é´ |
| | |
| | | mapper-locations: classpath:mapper/*.xml |
| | | type-aliases-package: com.qianwen.mdc.collect.entity.iotdb,com.qianwen.mdc.collect.entity.mgr |
| | | #com.qianwen.mdc.collect.entity.iotdb |
| | | #离线å¤å®æ¶é¿(毫ç§),è¶
è¿è¿ä¸ªæ¶é¿æ ééæ°æ®å¤å®ä¸ºç¦»çº¿ |
| | | offlineConfigDuration: 3000000 |
| | | wfg: |
| | | # 请ä¸å®æ³¨æï¼ WorkerIdBitLength + SeqBitLength + DataCenterIdBitLength <= 22 |
| | | # 1表示éªè±æ¼ç§»ç®æ³ï¼2è¡¨ç¤ºä¼ ç»éªè±ç®æ³ |
| | |
| | | </resultMap> |
| | | |
| | | <!-- n,v,workstation_id --> |
| | | <select id="mylist" resultType="com.qianwen.mdc.collect.entity.iotdb.ProcessParam" |
| | | parameterType="java.lang.Long"> |
| | | select n,v,workstation_id from root.f2.process_param* |
| | | where workstation_id=#{workstationId} |
| | | order by time asc limit 1 align by device |
| | | |
| | | <select id="lastParamByWorstationId" resultType="com.qianwen.mdc.collect.entity.iotdb.ProcessParam"> |
| | | select n as n,v as v,workstation_id as workstationId from root.f2.process_param_${workstationId}_* order by time desc limit 1 align by device |
| | | </select> |
| | | |
| | | </mapper> |