yangys
2024-09-02 03c9023f1e373060d6cbf5df7a18de90440399be
增加聚合状态;获取calendar数据的代码
已修改13个文件
已添加23个文件
3320 ■■■■■ 文件已修改
collect/pom.xml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/cache/TimeSliceCache.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/cache/WorkstationCache.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/controller/JobTestController.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/controller/MqttController.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/controller/StateController.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/dto/CacheBuildDTO.java 142 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/dto/CalendarShiftTimeSlicesDTO.java 272 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/dto/StateAggregateTimeDTO.java 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/dto/TimestampToProductionTimeCacheDto.java 157 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/entity/iotdb/AggregateState.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/entity/mgr/ProductionCalendarDay.java 364 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/entity/mgr/ProductionCalendarDaytime.java 487 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/handler/DeviceStatusDataHandler.java 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/job/ProductionTimeCacheXxlJob.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/mapper/iotdb/AggregateStateMapper.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/mapper/iotdb/DeviceStateMapper.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/mapper/mgr/CalendarDayMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/mapper/mgr/CalendarDaytimeMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/CalendarDayService.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/CalendarDaytimeService.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/CalendarService.java 124 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/CollectDataService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateAggregateNoFeedbackService.java 161 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateAggregateService.java 198 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateFixPointService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateService.java 134 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/IOTMqttReceiveService.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/service/PackedDataService.java 115 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/utils/CommonUtil.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/utils/FeedbackAnalyseUtils.java 355 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/utils/WorkstationStateAggregateNoFeedbackUtils.java 149 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/java/com/qianwen/mdc/collect/utils/redis/RedisUtil.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/resources/application-dev.yml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/resources/application.yml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/src/main/resources/com/qianwen/mdc/collect/mapper/iotdb/DeviceStateMapper.xml 98 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
collect/pom.xml
@@ -14,7 +14,10 @@
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <!--
        <druid.version>1.1.18</druid.version>
        -->
        <druid.version>1.2.8</druid.version>
        <fastjson.version>1.2.58</fastjson.version>
        <commons-io.version>2.10.0</commons-io.version>
        <commons-codec.version>1.10</commons-codec.version>
collect/src/main/java/com/qianwen/mdc/collect/cache/TimeSliceCache.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,65 @@
package com.qianwen.mdc.collect.cache;
import cn.hutool.core.date.DateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
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.Component;
import com.qianwen.core.tool.utils.SpringUtil;
import com.qianwen.mdc.collect.dto.CacheBuildDTO;
import com.qianwen.mdc.collect.dto.CalendarShiftTimeSlicesDTO;
import com.qianwen.mdc.collect.dto.TimestampToProductionTimeCacheDto;
import com.qianwen.mdc.collect.service.CalendarService;
import com.qianwen.mdc.collect.utils.CommonUtil;
import com.qianwen.mdc.collect.utils.redis.RedisUtil;
/*
import com.qianwen.posting.dto.CacheBuildDTO;
import com.qianwen.posting.dto.CalendarShiftTimeSlicesDTO;
import com.qianwen.posting.dto.TimestampToProductionTimeCacheDto;
import com.qianwen.posting.service.ICalendarService;
import com.qianwen.posting.utils.CommonUtil;
*/
@Component
public class TimeSliceCache {
    public static final String CALENDAR = "calendar";
    public static final String CALENDARS_CODE = "calendar:code:";
    public static final String MINUTE_POINT = "minute-point:";
    private static final Logger log = LoggerFactory.getLogger(TimeSliceCache.class);
    //private static final BladeRedis bladeRedis = (BladeRedis) SpringUtil.getBean(BladeRedis.class);
    //private static final ICalendarService calendarService = (ICalendarService) SpringUtil.getBean(ICalendarService.class);
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private CalendarService calendarService;
    public CalendarShiftTimeSlicesDTO getTimeSliceShift(String calendarCode, Date date) {
        int minutes = (DateTime.of(date).hour(true) * 60) + DateTime.of(date).minute();//日期转化为分钟数,作为hash key从redis取切片数据数据
        String redisKey = CommonUtil.getReallyCacheName("posting:calendar", CALENDARS_CODE.concat(calendarCode).concat(":").concat(MINUTE_POINT), DateTime.of(date).toDateStr());
        //return (CalendarShiftTimeSlicesDTO) bladeRedis.hGet(redisKey, Integer.valueOf(minutes));
        return (CalendarShiftTimeSlicesDTO) redisUtil.hget(redisKey, minutes+"");
    }
    //构建并保存时间切片,保存到redis
    public void build(CacheBuildDTO cacheBuildDTO) {
        String key = cacheBuildDTO.getTargetDate().format(DateTimeFormatter.ISO_LOCAL_DATE);
        List<TimestampToProductionTimeCacheDto> data = calendarService.buildProductionTimeCache(cacheBuildDTO);//查询生产日历,并计算出时间切片
        data.forEach(t -> {
            String redisKey = CommonUtil.getReallyCacheName("posting:calendar", CALENDARS_CODE.concat(t.getCalendarCode()).concat(":").concat(MINUTE_POINT), key);
            Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesDtoMap = t.getTimeSlicesDTOMap();
            //bladeRedis.getRedisTemplate().opsForHash().putAll(redisKey, timeSlicesDtoMap);
            //bladeRedis.expire(redisKey, 259200L);
            redisUtil.hmset(redisKey, timeSlicesDtoMap, 259200L);
        });
    }
}
collect/src/main/java/com/qianwen/mdc/collect/cache/WorkstationCache.java
@@ -48,7 +48,7 @@
    @Autowired
    private GlobalWcsOfRpsMapper globalWcsOfRpsMapper;
    @Autowired
    private WorkstationService workStationService;
    private WorkstationService workstationService;
    //private static final EmployeeOnOffWorkMapper employeeOnOffWorkMapper = (EmployeeOnOffWorkMapper) SpringUtil.getBean(EmployeeOnOffWorkMapper.class);
    
@@ -74,7 +74,7 @@
    }
    
    private Map<Long, WorkstationDTO> setWorkStations() {
        List<Workstation> list = workStationService.list();
        List<Workstation> list = workstationService.list();
        String redisKey = "posting:workstation".concat("::").concat(WORKSTATION_ALL);
       
        list.forEach(ws -> {
@@ -109,19 +109,29 @@
        String redisKey = "posting:workstation".concat("::").concat(WORKSTATION_ALL);
        return bladeRedis.del(redisKey);
    }
    public static String getWorkstationCalendarCodeForDate(Long workstationId, String date) {
    */
    /**
     * èŽ·å–æŒ‡å®šæ—¥æœŸçš„æ—¥åŽ†ä»£ç 
     * @param workstationId
     * @param date
     * @return
     */
    public String getWorkstationCalendarCodeForDate(Long workstationId, String date) {
        String redisKey = "posting:workstation".concat("::").concat(WORKSTATION_ID).concat(workstationId.toString().concat(CALENDAR_DATE)).concat(date);
        String calendarCode = (String) bladeRedis.get(redisKey);
        if (Func.isEmpty(calendarCode)) {
            log.warn("获取工位{}指定日期{}日历缓存不存在", workstationId, date);
            Optional.ofNullable(workStationService.getById(workstationId)).ifPresent(workStation -> {
                bladeRedis.setEx(redisKey, workStation.getCalendarCode(), 259200L);
        //String calendarCode = (String) bladeRedis.get(redisKey);
        String calendarCode = (String) redisUtil.get(redisKey);
        if (ObjectUtil.isEmpty(calendarCode)) {
            log.warn("获取工位{}指定日期{}日历缓存不存在,从数据库内获取并生成缓存", workstationId, date);
            Optional.ofNullable(workstationService.getById(workstationId)).ifPresent(workStation -> {
                //bladeRedis.setEx(redisKey, workStation.getCalendarCode(), 259200L);
                redisUtil.set(redisKey, workStation.getCalendarCode(), 259200L);
            });
        }
        return (String) bladeRedis.get(redisKey);
        //return (String) bladeRedis.get(redisKey);
        return calendarCode;
    }
    */
    public GlobalWcsOfRps getWorkstationWcsSetting(Long workstationId, String code) {
        String redisKey = "posting:workstation".concat("::").concat(WORKSTATION_ID).concat(workstationId.toString()
            .concat(WCS_SETTING));
collect/src/main/java/com/qianwen/mdc/collect/controller/JobTestController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,59 @@
package com.qianwen.mdc.collect.controller;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.google.common.collect.Sets;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.mdc.collect.cache.TimeSliceCache;
import com.qianwen.mdc.collect.config.IotDBSessionConfig;
import com.qianwen.mdc.collect.dto.CacheBuildDTO;
import com.qianwen.mdc.collect.dto.CalendarShiftInfoDTO;
import com.qianwen.mdc.collect.entity.iotdb.Output;
import com.qianwen.mdc.collect.entity.iotdb.ProcessParam;
import com.qianwen.mdc.collect.mapper.iotdb.OutputMapper;
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.DeviceStateAggregateService;
import com.qianwen.mdc.collect.service.DeviceStateFixPointService;
import com.qianwen.mdc.collect.service.IOTMqttReceiveService;
import com.qianwen.mdc.collect.service.IotDBCommonService;
import com.qianwen.mdc.collect.service.OutputAggregateService;
import com.qianwen.mdc.collect.utils.redis.RedisUtil;
import com.xxl.job.core.log.XxlJobLogger;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
@RestController
public class JobTestController {
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private TimeSliceCache timeSliceCache;
    @GetMapping("/timecache")
    public Object stateagg(Long workstationId) {
        LocalDate targetDate = LocalDate.now();//.plusDays(1L);
        CacheBuildDTO cacheBuildDTO = CacheBuildDTO.builder().tenantIds(Sets.newHashSet(new String[]{"000000"})).targetDate(targetDate).build();
        if (Func.isNotEmpty(cacheBuildDTO)) {
            timeSliceCache.build(cacheBuildDTO);
        } else {
            log.error("[生产日历切片缓存构建失败...],构建时间{},构建租户:{}", targetDate, "000000");
        }
        return "1";
    }
}
collect/src/main/java/com/qianwen/mdc/collect/controller/MqttController.java
@@ -53,38 +53,11 @@
    public void testRec2() {
        //数据格式:{"174":[{"values":{"d1":12},"ts":"1721978780449"}]} 174是应用id
        //多条格式:{"174":[{"values":{"DeviceStatus":2},"ts":"1722478128278"},{"values":{"spindleSpeed":22},"ts":"1722478128281"}]}
        String payload = "{\"174\":[{\"values\":{\"DeviceStatus\":2,\"Output\":34},\"ts\":\"1723709061525\"}]}";
        String payload = "{\"174\":[{\"values\":{\"DeviceStatus\":2,\"Output\":34},\"ts\":\"1725247557768\"}]}";
        //payload = "{\"174\":[{\"values\":{\"Output\":11},\"ts\":\"1722478128278\"},{\"values\":{\"SpindleSpeed\":22},\"ts\":\"1722478128281\"}]}";
        recService.handle(payload);
    }
    @GetMapping("/rec")
    public void testRec() {
        ////数据格式:{"174":[{"values":{"d1":12},"ts":"1721978780449"}]} 174是应用id
        //多条格式:{"174":[{"values":{"output":11},"ts":"1722478128278"},{"values":{"spindleSpeed":22},"ts":"1722478128281"}]}
        String payload = "{\"174\":[{\"values\":{\"output\":12},\"ts\":\"1721978780449\"}]}";
        JSONObject jsonObj = JSONObject.parseObject(payload);
        //数据格式:{"174":[{"values":{"d1":12},"ts":"1721978780449"}]} 174是应用id
        Set<String> keys = jsonObj.keySet();
        String appId = keys.toArray(new String[] {})[0];
        JSONArray dtArr = jsonObj.getJSONArray(appId);
        JSONObject data = dtArr.getJSONObject(0);
        long time = data.getLong("ts");
        String output = data.getJSONObject("values").getString("output");
        //AggrgateData ad = recService.fillFactoryData(payload);
        List<String> fields = new ArrayList<>();
        List<String> values = new ArrayList<>();
        //long time = System.currentTimeMillis();
        fields.add("output");
        fields.add("factory_year");
        fields.add("factory_month");
        fields.add("factory_date");//INT64, INT64,factory_date INT64,factory_week
        values.add(output);
        //iotdbCfg.insertRecord("root.qa.myoutput_"+ad.getWorkstationId(), time, fields, values);
    }
    
    @GetMapping("/tpl")
    public Object tpl(String tplname) throws StatementExecutionException, IoTDBConnectionException {
collect/src/main/java/com/qianwen/mdc/collect/controller/StateController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,43 @@
package com.qianwen.mdc.collect.controller;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.qianwen.mdc.collect.config.IotDBSessionConfig;
import com.qianwen.mdc.collect.dto.CalendarShiftInfoDTO;
import com.qianwen.mdc.collect.entity.iotdb.Output;
import com.qianwen.mdc.collect.entity.iotdb.ProcessParam;
import com.qianwen.mdc.collect.mapper.iotdb.OutputMapper;
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.DeviceStateAggregateService;
import com.qianwen.mdc.collect.service.DeviceStateFixPointService;
import com.qianwen.mdc.collect.service.IOTMqttReceiveService;
import com.qianwen.mdc.collect.service.IotDBCommonService;
import com.qianwen.mdc.collect.service.OutputAggregateService;
import com.qianwen.mdc.collect.utils.redis.RedisUtil;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
@RestController
public class StateController {
    @Autowired
    private DeviceStateAggregateService stateAggregateService;
    @GetMapping("/stateagg")
    public Object stateagg(Long workstationId) {
        stateAggregateService.stateAggregate(workstationId);
        return "1";
    }
}
collect/src/main/java/com/qianwen/mdc/collect/dto/CacheBuildDTO.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,142 @@
package com.qianwen.mdc.collect.dto;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import io.swagger.annotations.ApiModel;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Set;
@ApiModel(value = "生产日历校验入参", description = "生产日历校验入参")
public class CacheBuildDTO implements Serializable {
    private static final long serialVersionUID = 1;
    private Set<String> tenantIds;
    private String calendarCode;
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    private LocalDate targetDate;
    public static class CacheBuildDTOBuilder {
        private Set<String> tenantIds;
        private String calendarCode;
        private LocalDate targetDate;
        CacheBuildDTOBuilder() {
        }
        public CacheBuildDTOBuilder tenantIds(final Set<String> tenantIds) {
            this.tenantIds = tenantIds;
            return this;
        }
        public CacheBuildDTOBuilder calendarCode(final String calendarCode) {
            this.calendarCode = calendarCode;
            return this;
        }
        @JsonDeserialize(using = LocalDateDeserializer.class)
        public CacheBuildDTOBuilder targetDate(final LocalDate targetDate) {
            this.targetDate = targetDate;
            return this;
        }
        public CacheBuildDTO build() {
            return new CacheBuildDTO(this.tenantIds, this.calendarCode, this.targetDate);
        }
        public String toString() {
            return "CacheBuildDTO.CacheBuildDTOBuilder(tenantIds=" + this.tenantIds + ", calendarCode=" + this.calendarCode + ", targetDate=" + this.targetDate + ")";
        }
    }
    public void setTenantIds(final Set<String> tenantIds) {
        this.tenantIds = tenantIds;
    }
    public void setCalendarCode(final String calendarCode) {
        this.calendarCode = calendarCode;
    }
    @JsonDeserialize(using = LocalDateDeserializer.class)
    public void setTargetDate(final LocalDate targetDate) {
        this.targetDate = targetDate;
    }
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        }
        if (o instanceof CacheBuildDTO) {
            CacheBuildDTO other = (CacheBuildDTO) o;
            if (other.canEqual(this)) {
                Object this$tenantIds = getTenantIds();
                Object other$tenantIds = other.getTenantIds();
                if (this$tenantIds == null) {
                    if (other$tenantIds != null) {
                        return false;
                    }
                } else if (!this$tenantIds.equals(other$tenantIds)) {
                    return false;
                }
                Object this$calendarCode = getCalendarCode();
                Object other$calendarCode = other.getCalendarCode();
                if (this$calendarCode == null) {
                    if (other$calendarCode != null) {
                        return false;
                    }
                } else if (!this$calendarCode.equals(other$calendarCode)) {
                    return false;
                }
                Object this$targetDate = getTargetDate();
                Object other$targetDate = other.getTargetDate();
                return this$targetDate == null ? other$targetDate == null : this$targetDate.equals(other$targetDate);
            }
            return false;
        }
        return false;
    }
    protected boolean canEqual(final Object other) {
        return other instanceof CacheBuildDTO;
    }
    public int hashCode() {
        Object $tenantIds = getTenantIds();
        int result = (1 * 59) + ($tenantIds == null ? 43 : $tenantIds.hashCode());
        Object $calendarCode = getCalendarCode();
        int result2 = (result * 59) + ($calendarCode == null ? 43 : $calendarCode.hashCode());
        Object $targetDate = getTargetDate();
        return (result2 * 59) + ($targetDate == null ? 43 : $targetDate.hashCode());
    }
    public String toString() {
        return "CacheBuildDTO(tenantIds=" + getTenantIds() + ", calendarCode=" + getCalendarCode() + ", targetDate=" + getTargetDate() + ")";
    }
    public static CacheBuildDTOBuilder builder() {
        return new CacheBuildDTOBuilder();
    }
    public CacheBuildDTO() {
    }
    public CacheBuildDTO(final Set<String> tenantIds, final String calendarCode, final LocalDate targetDate) {
        this.tenantIds = tenantIds;
        this.calendarCode = calendarCode;
        this.targetDate = targetDate;
    }
    public Set<String> getTenantIds() {
        return this.tenantIds;
    }
    public String getCalendarCode() {
        return this.calendarCode;
    }
    public LocalDate getTargetDate() {
        return this.targetDate;
    }
}
collect/src/main/java/com/qianwen/mdc/collect/dto/CalendarShiftTimeSlicesDTO.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,272 @@
package com.qianwen.mdc.collect.dto;
import java.util.Date;
public class CalendarShiftTimeSlicesDTO {
    private String factoryDate;
    private Integer shiftIndex;
    private String shiftTimeType;
    private Integer factoryWeek;
    private Integer factoryMonth;
    private Integer factoryYear;
    private Date startTime;
    private Date endTime;
    public CalendarShiftTimeSlicesDTO setFactoryDate(final String factoryDate) {
        this.factoryDate = factoryDate;
        return this;
    }
    public CalendarShiftTimeSlicesDTO setShiftIndex(final Integer shiftIndex) {
        this.shiftIndex = shiftIndex;
        return this;
    }
    public CalendarShiftTimeSlicesDTO setShiftTimeType(final String shiftTimeType) {
        this.shiftTimeType = shiftTimeType;
        return this;
    }
    public CalendarShiftTimeSlicesDTO setFactoryWeek(final Integer factoryWeek) {
        this.factoryWeek = factoryWeek;
        return this;
    }
    public CalendarShiftTimeSlicesDTO setFactoryMonth(final Integer factoryMonth) {
        this.factoryMonth = factoryMonth;
        return this;
    }
    public CalendarShiftTimeSlicesDTO setFactoryYear(final Integer factoryYear) {
        this.factoryYear = factoryYear;
        return this;
    }
    public CalendarShiftTimeSlicesDTO setStartTime(final Date startTime) {
        this.startTime = startTime;
        return this;
    }
    public CalendarShiftTimeSlicesDTO setEndTime(final Date endTime) {
        this.endTime = endTime;
        return this;
    }
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        }
        if (o instanceof CalendarShiftTimeSlicesDTO) {
            CalendarShiftTimeSlicesDTO other = (CalendarShiftTimeSlicesDTO) o;
            if (other.canEqual(this)) {
                Object this$shiftIndex = getShiftIndex();
                Object other$shiftIndex = other.getShiftIndex();
                if (this$shiftIndex == null) {
                    if (other$shiftIndex != null) {
                        return false;
                    }
                } else if (!this$shiftIndex.equals(other$shiftIndex)) {
                    return false;
                }
                Object this$factoryWeek = getFactoryWeek();
                Object other$factoryWeek = other.getFactoryWeek();
                if (this$factoryWeek == null) {
                    if (other$factoryWeek != null) {
                        return false;
                    }
                } else if (!this$factoryWeek.equals(other$factoryWeek)) {
                    return false;
                }
                Object this$factoryMonth = getFactoryMonth();
                Object other$factoryMonth = other.getFactoryMonth();
                if (this$factoryMonth == null) {
                    if (other$factoryMonth != null) {
                        return false;
                    }
                } else if (!this$factoryMonth.equals(other$factoryMonth)) {
                    return false;
                }
                Object this$factoryYear = getFactoryYear();
                Object other$factoryYear = other.getFactoryYear();
                if (this$factoryYear == null) {
                    if (other$factoryYear != null) {
                        return false;
                    }
                } else if (!this$factoryYear.equals(other$factoryYear)) {
                    return false;
                }
                Object this$factoryDate = getFactoryDate();
                Object other$factoryDate = other.getFactoryDate();
                if (this$factoryDate == null) {
                    if (other$factoryDate != null) {
                        return false;
                    }
                } else if (!this$factoryDate.equals(other$factoryDate)) {
                    return false;
                }
                Object this$shiftTimeType = getShiftTimeType();
                Object other$shiftTimeType = other.getShiftTimeType();
                if (this$shiftTimeType == null) {
                    if (other$shiftTimeType != null) {
                        return false;
                    }
                } else if (!this$shiftTimeType.equals(other$shiftTimeType)) {
                    return false;
                }
                Object this$startTime = getStartTime();
                Object other$startTime = other.getStartTime();
                if (this$startTime == null) {
                    if (other$startTime != null) {
                        return false;
                    }
                } else if (!this$startTime.equals(other$startTime)) {
                    return false;
                }
                Object this$endTime = getEndTime();
                Object other$endTime = other.getEndTime();
                return this$endTime == null ? other$endTime == null : this$endTime.equals(other$endTime);
            }
            return false;
        }
        return false;
    }
    protected boolean canEqual(final Object other) {
        return other instanceof CalendarShiftTimeSlicesDTO;
    }
    public int hashCode() {
        Object $shiftIndex = getShiftIndex();
        int result = (1 * 59) + ($shiftIndex == null ? 43 : $shiftIndex.hashCode());
        Object $factoryWeek = getFactoryWeek();
        int result2 = (result * 59) + ($factoryWeek == null ? 43 : $factoryWeek.hashCode());
        Object $factoryMonth = getFactoryMonth();
        int result3 = (result2 * 59) + ($factoryMonth == null ? 43 : $factoryMonth.hashCode());
        Object $factoryYear = getFactoryYear();
        int result4 = (result3 * 59) + ($factoryYear == null ? 43 : $factoryYear.hashCode());
        Object $factoryDate = getFactoryDate();
        int result5 = (result4 * 59) + ($factoryDate == null ? 43 : $factoryDate.hashCode());
        Object $shiftTimeType = getShiftTimeType();
        int result6 = (result5 * 59) + ($shiftTimeType == null ? 43 : $shiftTimeType.hashCode());
        Object $startTime = getStartTime();
        int result7 = (result6 * 59) + ($startTime == null ? 43 : $startTime.hashCode());
        Object $endTime = getEndTime();
        return (result7 * 59) + ($endTime == null ? 43 : $endTime.hashCode());
    }
    public static class CalendarShiftTimeSlicesDTOBuilder {
        private String factoryDate;
        private Integer shiftIndex;
        private String shiftTimeType;
        private Integer factoryWeek;
        private Integer factoryMonth;
        private Integer factoryYear;
        private Date startTime;
        private Date endTime;
        CalendarShiftTimeSlicesDTOBuilder() {
        }
        public CalendarShiftTimeSlicesDTOBuilder factoryDate(final String factoryDate) {
            this.factoryDate = factoryDate;
            return this;
        }
        public CalendarShiftTimeSlicesDTOBuilder shiftIndex(final Integer shiftIndex) {
            this.shiftIndex = shiftIndex;
            return this;
        }
        public CalendarShiftTimeSlicesDTOBuilder shiftTimeType(final String shiftTimeType) {
            this.shiftTimeType = shiftTimeType;
            return this;
        }
        public CalendarShiftTimeSlicesDTOBuilder factoryWeek(final Integer factoryWeek) {
            this.factoryWeek = factoryWeek;
            return this;
        }
        public CalendarShiftTimeSlicesDTOBuilder factoryMonth(final Integer factoryMonth) {
            this.factoryMonth = factoryMonth;
            return this;
        }
        public CalendarShiftTimeSlicesDTOBuilder factoryYear(final Integer factoryYear) {
            this.factoryYear = factoryYear;
            return this;
        }
        public CalendarShiftTimeSlicesDTOBuilder startTime(final Date startTime) {
            this.startTime = startTime;
            return this;
        }
        public CalendarShiftTimeSlicesDTOBuilder endTime(final Date endTime) {
            this.endTime = endTime;
            return this;
        }
        public CalendarShiftTimeSlicesDTO build() {
            return new CalendarShiftTimeSlicesDTO(this.factoryDate, this.shiftIndex, this.shiftTimeType, this.factoryWeek, this.factoryMonth, this.factoryYear, this.startTime, this.endTime);
        }
        public String toString() {
            return "CalendarShiftTimeSlicesDTO.CalendarShiftTimeSlicesDTOBuilder(factoryDate=" + this.factoryDate + ", shiftIndex=" + this.shiftIndex + ", shiftTimeType=" + this.shiftTimeType + ", factoryWeek=" + this.factoryWeek + ", factoryMonth=" + this.factoryMonth + ", factoryYear=" + this.factoryYear + ", startTime=" + this.startTime + ", endTime=" + this.endTime + ")";
        }
    }
    public static CalendarShiftTimeSlicesDTOBuilder builder() {
        return new CalendarShiftTimeSlicesDTOBuilder();
    }
    public CalendarShiftTimeSlicesDTO(final String factoryDate, final Integer shiftIndex, final String shiftTimeType, final Integer factoryWeek, final Integer factoryMonth, final Integer factoryYear, final Date startTime, final Date endTime) {
        this.factoryDate = factoryDate;
        this.shiftIndex = shiftIndex;
        this.shiftTimeType = shiftTimeType;
        this.factoryWeek = factoryWeek;
        this.factoryMonth = factoryMonth;
        this.factoryYear = factoryYear;
        this.startTime = startTime;
        this.endTime = endTime;
    }
    public CalendarShiftTimeSlicesDTO() {
    }
    public String toString() {
        return "CalendarShiftTimeSlicesDTO(factoryDate=" + getFactoryDate() + ", shiftIndex=" + getShiftIndex() + ", shiftTimeType=" + getShiftTimeType() + ", factoryWeek=" + getFactoryWeek() + ", factoryMonth=" + getFactoryMonth() + ", factoryYear=" + getFactoryYear() + ", startTime=" + getStartTime() + ", endTime=" + getEndTime() + ")";
    }
    public String getFactoryDate() {
        return this.factoryDate;
    }
    public Integer getShiftIndex() {
        return this.shiftIndex;
    }
    public String getShiftTimeType() {
        return this.shiftTimeType;
    }
    public Integer getFactoryWeek() {
        return this.factoryWeek;
    }
    public Integer getFactoryMonth() {
        return this.factoryMonth;
    }
    public Integer getFactoryYear() {
        return this.factoryYear;
    }
    public Date getStartTime() {
        return this.startTime;
    }
    public Date getEndTime() {
        return this.endTime;
    }
}
collect/src/main/java/com/qianwen/mdc/collect/dto/StateAggregateTimeDTO.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,82 @@
package com.qianwen.mdc.collect.dto;
public class StateAggregateTimeDTO {
    private Long startTime;
    private Long endTime;
    private Boolean noFeedbackTime;
    public void setStartTime(final Long startTime) {
        this.startTime = startTime;
    }
    public void setEndTime(final Long endTime) {
        this.endTime = endTime;
    }
    public void setNoFeedbackTime(final Boolean noFeedbackTime) {
        this.noFeedbackTime = noFeedbackTime;
    }
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        }
        if (o instanceof StateAggregateTimeDTO) {
            StateAggregateTimeDTO other = (StateAggregateTimeDTO) o;
            if (other.canEqual(this)) {
                Object this$startTime = getStartTime();
                Object other$startTime = other.getStartTime();
                if (this$startTime == null) {
                    if (other$startTime != null) {
                        return false;
                    }
                } else if (!this$startTime.equals(other$startTime)) {
                    return false;
                }
                Object this$endTime = getEndTime();
                Object other$endTime = other.getEndTime();
                if (this$endTime == null) {
                    if (other$endTime != null) {
                        return false;
                    }
                } else if (!this$endTime.equals(other$endTime)) {
                    return false;
                }
                Object this$noFeedbackTime = getNoFeedbackTime();
                Object other$noFeedbackTime = other.getNoFeedbackTime();
                return this$noFeedbackTime == null ? other$noFeedbackTime == null : this$noFeedbackTime.equals(other$noFeedbackTime);
            }
            return false;
        }
        return false;
    }
    protected boolean canEqual(final Object other) {
        return other instanceof StateAggregateTimeDTO;
    }
    public int hashCode() {
        Object $startTime = getStartTime();
        int result = (1 * 59) + ($startTime == null ? 43 : $startTime.hashCode());
        Object $endTime = getEndTime();
        int result2 = (result * 59) + ($endTime == null ? 43 : $endTime.hashCode());
        Object $noFeedbackTime = getNoFeedbackTime();
        return (result2 * 59) + ($noFeedbackTime == null ? 43 : $noFeedbackTime.hashCode());
    }
    public String toString() {
        return "WorkstationStateAggregateTimeDTO(startTime=" + getStartTime() + ", endTime=" + getEndTime() + ", noFeedbackTime=" + getNoFeedbackTime() + ")";
    }
    public Long getStartTime() {
        return this.startTime;
    }
    public Long getEndTime() {
        return this.endTime;
    }
    public Boolean getNoFeedbackTime() {
        return this.noFeedbackTime;
    }
}
collect/src/main/java/com/qianwen/mdc/collect/dto/TimestampToProductionTimeCacheDto.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,157 @@
package com.qianwen.mdc.collect.dto;
import java.time.LocalDate;
import java.util.Map;
public class TimestampToProductionTimeCacheDto {
    private String TenantId;
    private String CalendarCode;
    private LocalDate NaturalDay;
    private Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesDTOMap;
    public static class TimestampToProductionTimeCacheDtoBuilder {
        private String TenantId;
        private String CalendarCode;
        private LocalDate NaturalDay;
        private Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesDTOMap;
        TimestampToProductionTimeCacheDtoBuilder() {
        }
        public TimestampToProductionTimeCacheDtoBuilder TenantId(final String TenantId) {
            this.TenantId = TenantId;
            return this;
        }
        public TimestampToProductionTimeCacheDtoBuilder CalendarCode(final String CalendarCode) {
            this.CalendarCode = CalendarCode;
            return this;
        }
        public TimestampToProductionTimeCacheDtoBuilder NaturalDay(final LocalDate NaturalDay) {
            this.NaturalDay = NaturalDay;
            return this;
        }
        public TimestampToProductionTimeCacheDtoBuilder timeSlicesDTOMap(final Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesDTOMap) {
            this.timeSlicesDTOMap = timeSlicesDTOMap;
            return this;
        }
        public TimestampToProductionTimeCacheDto build() {
            return new TimestampToProductionTimeCacheDto(this.TenantId, this.CalendarCode, this.NaturalDay, this.timeSlicesDTOMap);
        }
        public String toString() {
            return "TimestampToProductionTimeCacheDto.TimestampToProductionTimeCacheDtoBuilder(TenantId=" + this.TenantId + ", CalendarCode=" + this.CalendarCode + ", NaturalDay=" + this.NaturalDay + ", timeSlicesDTOMap=" + this.timeSlicesDTOMap + ")";
        }
    }
    public void setTenantId(final String TenantId) {
        this.TenantId = TenantId;
    }
    public void setCalendarCode(final String CalendarCode) {
        this.CalendarCode = CalendarCode;
    }
    public void setNaturalDay(final LocalDate NaturalDay) {
        this.NaturalDay = NaturalDay;
    }
    public void setTimeSlicesDTOMap(final Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesDTOMap) {
        this.timeSlicesDTOMap = timeSlicesDTOMap;
    }
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        }
        if (o instanceof TimestampToProductionTimeCacheDto) {
            TimestampToProductionTimeCacheDto other = (TimestampToProductionTimeCacheDto) o;
            if (other.canEqual(this)) {
                Object this$TenantId = getTenantId();
                Object other$TenantId = other.getTenantId();
                if (this$TenantId == null) {
                    if (other$TenantId != null) {
                        return false;
                    }
                } else if (!this$TenantId.equals(other$TenantId)) {
                    return false;
                }
                Object this$CalendarCode = getCalendarCode();
                Object other$CalendarCode = other.getCalendarCode();
                if (this$CalendarCode == null) {
                    if (other$CalendarCode != null) {
                        return false;
                    }
                } else if (!this$CalendarCode.equals(other$CalendarCode)) {
                    return false;
                }
                Object this$NaturalDay = getNaturalDay();
                Object other$NaturalDay = other.getNaturalDay();
                if (this$NaturalDay == null) {
                    if (other$NaturalDay != null) {
                        return false;
                    }
                } else if (!this$NaturalDay.equals(other$NaturalDay)) {
                    return false;
                }
                Object this$timeSlicesDTOMap = getTimeSlicesDTOMap();
                Object other$timeSlicesDTOMap = other.getTimeSlicesDTOMap();
                return this$timeSlicesDTOMap == null ? other$timeSlicesDTOMap == null : this$timeSlicesDTOMap.equals(other$timeSlicesDTOMap);
            }
            return false;
        }
        return false;
    }
    protected boolean canEqual(final Object other) {
        return other instanceof TimestampToProductionTimeCacheDto;
    }
    public int hashCode() {
        Object $TenantId = getTenantId();
        int result = (1 * 59) + ($TenantId == null ? 43 : $TenantId.hashCode());
        Object $CalendarCode = getCalendarCode();
        int result2 = (result * 59) + ($CalendarCode == null ? 43 : $CalendarCode.hashCode());
        Object $NaturalDay = getNaturalDay();
        int result3 = (result2 * 59) + ($NaturalDay == null ? 43 : $NaturalDay.hashCode());
        Object $timeSlicesDTOMap = getTimeSlicesDTOMap();
        return (result3 * 59) + ($timeSlicesDTOMap == null ? 43 : $timeSlicesDTOMap.hashCode());
    }
    public static TimestampToProductionTimeCacheDtoBuilder builder() {
        return new TimestampToProductionTimeCacheDtoBuilder();
    }
    public TimestampToProductionTimeCacheDto() {
    }
    public TimestampToProductionTimeCacheDto(final String TenantId, final String CalendarCode, final LocalDate NaturalDay, final Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesDTOMap) {
        this.TenantId = TenantId;
        this.CalendarCode = CalendarCode;
        this.NaturalDay = NaturalDay;
        this.timeSlicesDTOMap = timeSlicesDTOMap;
    }
    public String toString() {
        return "TimestampToProductionTimeCacheDto(TenantId=" + getTenantId() + ", CalendarCode=" + getCalendarCode() + ", NaturalDay=" + getNaturalDay() + ", timeSlicesDTOMap=" + getTimeSlicesDTOMap() + ")";
    }
    public String getTenantId() {
        return this.TenantId;
    }
    public String getCalendarCode() {
        return this.CalendarCode;
    }
    public LocalDate getNaturalDay() {
        return this.NaturalDay;
    }
    public Map<Integer, CalendarShiftTimeSlicesDTO> getTimeSlicesDTOMap() {
        return this.timeSlicesDTOMap;
    }
}
collect/src/main/java/com/qianwen/mdc/collect/entity/iotdb/AggregateState.java
@@ -8,7 +8,8 @@
    private Long time;
    private Long workstationId;
    private Integer valueCollect;
    private Long durationCollect;
    private Long endTime;
    private String calendarCode;
    private Integer factoryYear;
    private Integer factoryMonth;
@@ -177,5 +178,21 @@
    public void setFeedbackId(Long feedbackId) {
        this.feedbackId = feedbackId;
    }
    public Long getDurationCollect() {
        return durationCollect;
    }
    public void setDurationCollect(Long durationCollect) {
        this.durationCollect = durationCollect;
    }
    public Long getEndTime() {
        return endTime;
    }
    public void setEndTime(Long endTime) {
        this.endTime = endTime;
    }
    
}
collect/src/main/java/com/qianwen/mdc/collect/entity/mgr/ProductionCalendarDay.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,364 @@
package com.qianwen.mdc.collect.entity.mgr;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
@ApiModel(value = "班次日entity", description = "班次日entity")
@TableName("blade_production_calendar_day")
public class ProductionCalendarDay implements Serializable {
    private static final long serialVersionUID = 6935830020987594867L;
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty("主键")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;
    @ApiModelProperty("生产日历id")
    private Long calendarId;
    @ApiModelProperty("生产日历日期")
    private LocalDate calendarDate;
    @ApiModelProperty("班次日开始时间")
    private LocalDateTime startTime;
    @ApiModelProperty("班次日结束时间")
    private LocalDateTime endTime;
    @ApiModelProperty("属于第几周")
    private Integer week;
    @ApiModelProperty("属于第几月")
    private Integer month;
    @ApiModelProperty("属于第几年")
    private Integer year;
    @ApiModelProperty("班次模型Id")
    private Long modelId;
    @ApiModelProperty("是否高优先级")
    private Integer isHighPriority;
    @TableLogic
    @TableField(value = "is_deleted", fill = FieldFill.INSERT)
    private boolean isDeleted;
    public static class ProductionCalendarDayBuilder {
        private Long id;
        private Long calendarId;
        private LocalDate calendarDate;
        private LocalDateTime startTime;
        private LocalDateTime endTime;
        private Integer week;
        private Integer month;
        private Integer year;
        private Long modelId;
        private Integer isHighPriority;
        private boolean isDeleted;
        ProductionCalendarDayBuilder() {
        }
        public ProductionCalendarDayBuilder id(final Long id) {
            this.id = id;
            return this;
        }
        public ProductionCalendarDayBuilder calendarId(final Long calendarId) {
            this.calendarId = calendarId;
            return this;
        }
        public ProductionCalendarDayBuilder calendarDate(final LocalDate calendarDate) {
            this.calendarDate = calendarDate;
            return this;
        }
        public ProductionCalendarDayBuilder startTime(final LocalDateTime startTime) {
            this.startTime = startTime;
            return this;
        }
        public ProductionCalendarDayBuilder endTime(final LocalDateTime endTime) {
            this.endTime = endTime;
            return this;
        }
        public ProductionCalendarDayBuilder week(final Integer week) {
            this.week = week;
            return this;
        }
        public ProductionCalendarDayBuilder month(final Integer month) {
            this.month = month;
            return this;
        }
        public ProductionCalendarDayBuilder year(final Integer year) {
            this.year = year;
            return this;
        }
        public ProductionCalendarDayBuilder modelId(final Long modelId) {
            this.modelId = modelId;
            return this;
        }
        public ProductionCalendarDayBuilder isHighPriority(final Integer isHighPriority) {
            this.isHighPriority = isHighPriority;
            return this;
        }
        public ProductionCalendarDayBuilder isDeleted(final boolean isDeleted) {
            this.isDeleted = isDeleted;
            return this;
        }
        public ProductionCalendarDay build() {
            return new ProductionCalendarDay(this.id, this.calendarId, this.calendarDate, this.startTime, this.endTime, this.week, this.month, this.year, this.modelId, this.isHighPriority, this.isDeleted);
        }
        public String toString() {
            return "ProductionCalendarDay.ProductionCalendarDayBuilder(id=" + this.id + ", calendarId=" + this.calendarId + ", calendarDate=" + this.calendarDate + ", startTime=" + this.startTime + ", endTime=" + this.endTime + ", week=" + this.week + ", month=" + this.month + ", year=" + this.year + ", modelId=" + this.modelId + ", isHighPriority=" + this.isHighPriority + ", isDeleted=" + this.isDeleted + ")";
        }
    }
    public void setId(final Long id) {
        this.id = id;
    }
    public void setCalendarId(final Long calendarId) {
        this.calendarId = calendarId;
    }
    public void setCalendarDate(final LocalDate calendarDate) {
        this.calendarDate = calendarDate;
    }
    public void setStartTime(final LocalDateTime startTime) {
        this.startTime = startTime;
    }
    public void setEndTime(final LocalDateTime endTime) {
        this.endTime = endTime;
    }
    public void setWeek(final Integer week) {
        this.week = week;
    }
    public void setMonth(final Integer month) {
        this.month = month;
    }
    public void setYear(final Integer year) {
        this.year = year;
    }
    public void setModelId(final Long modelId) {
        this.modelId = modelId;
    }
    public void setIsHighPriority(final Integer isHighPriority) {
        this.isHighPriority = isHighPriority;
    }
    public void setDeleted(final boolean isDeleted) {
        this.isDeleted = isDeleted;
    }
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        }
        if (o instanceof ProductionCalendarDay) {
            ProductionCalendarDay other = (ProductionCalendarDay) o;
            if (other.canEqual(this) && isDeleted() == other.isDeleted()) {
                Object this$id = getId();
                Object other$id = other.getId();
                if (this$id == null) {
                    if (other$id != null) {
                        return false;
                    }
                } else if (!this$id.equals(other$id)) {
                    return false;
                }
                Object this$calendarId = getCalendarId();
                Object other$calendarId = other.getCalendarId();
                if (this$calendarId == null) {
                    if (other$calendarId != null) {
                        return false;
                    }
                } else if (!this$calendarId.equals(other$calendarId)) {
                    return false;
                }
                Object this$week = getWeek();
                Object other$week = other.getWeek();
                if (this$week == null) {
                    if (other$week != null) {
                        return false;
                    }
                } else if (!this$week.equals(other$week)) {
                    return false;
                }
                Object this$month = getMonth();
                Object other$month = other.getMonth();
                if (this$month == null) {
                    if (other$month != null) {
                        return false;
                    }
                } else if (!this$month.equals(other$month)) {
                    return false;
                }
                Object this$year = getYear();
                Object other$year = other.getYear();
                if (this$year == null) {
                    if (other$year != null) {
                        return false;
                    }
                } else if (!this$year.equals(other$year)) {
                    return false;
                }
                Object this$modelId = getModelId();
                Object other$modelId = other.getModelId();
                if (this$modelId == null) {
                    if (other$modelId != null) {
                        return false;
                    }
                } else if (!this$modelId.equals(other$modelId)) {
                    return false;
                }
                Object this$isHighPriority = getIsHighPriority();
                Object other$isHighPriority = other.getIsHighPriority();
                if (this$isHighPriority == null) {
                    if (other$isHighPriority != null) {
                        return false;
                    }
                } else if (!this$isHighPriority.equals(other$isHighPriority)) {
                    return false;
                }
                Object this$calendarDate = getCalendarDate();
                Object other$calendarDate = other.getCalendarDate();
                if (this$calendarDate == null) {
                    if (other$calendarDate != null) {
                        return false;
                    }
                } else if (!this$calendarDate.equals(other$calendarDate)) {
                    return false;
                }
                Object this$startTime = getStartTime();
                Object other$startTime = other.getStartTime();
                if (this$startTime == null) {
                    if (other$startTime != null) {
                        return false;
                    }
                } else if (!this$startTime.equals(other$startTime)) {
                    return false;
                }
                Object this$endTime = getEndTime();
                Object other$endTime = other.getEndTime();
                return this$endTime == null ? other$endTime == null : this$endTime.equals(other$endTime);
            }
            return false;
        }
        return false;
    }
    protected boolean canEqual(final Object other) {
        return other instanceof ProductionCalendarDay;
    }
    public int hashCode() {
        int result = (1 * 59) + (isDeleted() ? 79 : 97);
        Object $id = getId();
        int result2 = (result * 59) + ($id == null ? 43 : $id.hashCode());
        Object $calendarId = getCalendarId();
        int result3 = (result2 * 59) + ($calendarId == null ? 43 : $calendarId.hashCode());
        Object $week = getWeek();
        int result4 = (result3 * 59) + ($week == null ? 43 : $week.hashCode());
        Object $month = getMonth();
        int result5 = (result4 * 59) + ($month == null ? 43 : $month.hashCode());
        Object $year = getYear();
        int result6 = (result5 * 59) + ($year == null ? 43 : $year.hashCode());
        Object $modelId = getModelId();
        int result7 = (result6 * 59) + ($modelId == null ? 43 : $modelId.hashCode());
        Object $isHighPriority = getIsHighPriority();
        int result8 = (result7 * 59) + ($isHighPriority == null ? 43 : $isHighPriority.hashCode());
        Object $calendarDate = getCalendarDate();
        int result9 = (result8 * 59) + ($calendarDate == null ? 43 : $calendarDate.hashCode());
        Object $startTime = getStartTime();
        int result10 = (result9 * 59) + ($startTime == null ? 43 : $startTime.hashCode());
        Object $endTime = getEndTime();
        return (result10 * 59) + ($endTime == null ? 43 : $endTime.hashCode());
    }
    public String toString() {
        return "ProductionCalendarDay(id=" + getId() + ", calendarId=" + getCalendarId() + ", calendarDate=" + getCalendarDate() + ", startTime=" + getStartTime() + ", endTime=" + getEndTime() + ", week=" + getWeek() + ", month=" + getMonth() + ", year=" + getYear() + ", modelId=" + getModelId() + ", isHighPriority=" + getIsHighPriority() + ", isDeleted=" + isDeleted() + ")";
    }
    public static ProductionCalendarDayBuilder builder() {
        return new ProductionCalendarDayBuilder();
    }
    public ProductionCalendarDay() {
    }
    public ProductionCalendarDay(final Long id, final Long calendarId, final LocalDate calendarDate, final LocalDateTime startTime, final LocalDateTime endTime, final Integer week, final Integer month, final Integer year, final Long modelId, final Integer isHighPriority, final boolean isDeleted) {
        this.id = id;
        this.calendarId = calendarId;
        this.calendarDate = calendarDate;
        this.startTime = startTime;
        this.endTime = endTime;
        this.week = week;
        this.month = month;
        this.year = year;
        this.modelId = modelId;
        this.isHighPriority = isHighPriority;
        this.isDeleted = isDeleted;
    }
    public Long getId() {
        return this.id;
    }
    public Long getCalendarId() {
        return this.calendarId;
    }
    public LocalDate getCalendarDate() {
        return this.calendarDate;
    }
    public LocalDateTime getStartTime() {
        return this.startTime;
    }
    public LocalDateTime getEndTime() {
        return this.endTime;
    }
    public Integer getWeek() {
        return this.week;
    }
    public Integer getMonth() {
        return this.month;
    }
    public Integer getYear() {
        return this.year;
    }
    public Long getModelId() {
        return this.modelId;
    }
    public Integer getIsHighPriority() {
        return this.isHighPriority;
    }
    public boolean isDeleted() {
        return this.isDeleted;
    }
}
collect/src/main/java/com/qianwen/mdc/collect/entity/mgr/ProductionCalendarDaytime.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,487 @@
package com.qianwen.mdc.collect.entity.mgr;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
@ApiModel(value = "班次日切片entity", description = "班次日切片entity")
@TableName("blade_production_calendar_daytime")
public class ProductionCalendarDaytime implements Serializable {
    private static final long serialVersionUID = 2597571287144588437L;
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty("主键")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;
    @ApiModelProperty("生产日历id")
    private Long calendarId;
    @ApiModelProperty("班次日id")
    private Long calendarDayId;
    @ApiModelProperty("班次日期")
    private LocalDate calendarDate;
    @ApiModelProperty("班次开始时间")
    private LocalDateTime startTime;
    @ApiModelProperty("班次结束时间")
    private LocalDateTime endTime;
    @ApiModelProperty("班次序号")
    private Integer shiftIndex;
    @ApiModelProperty("班次类型(1-工作时段,2-休息时段)")
    private Integer shiftType;
    @ApiModelProperty("属于第几周")
    private Integer week;
    @ApiModelProperty("属于第几月")
    private Integer month;
    @ApiModelProperty("属于第几年")
    private Integer year;
    @ApiModelProperty("是否是未定义工厂日")
    private Integer isUndefined;
    @ApiModelProperty("是否高优先级")
    private Integer isHighPriority;
    @TableField(value = "create_user", fill = FieldFill.INSERT)
    @ApiModelProperty("创建人")
    private Long createUser;
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @ApiModelProperty("创建时间")
    private Date createTime;
    public static class ProductionCalendarDaytimeBuilder {
        private Long id;
        private Long calendarId;
        private Long calendarDayId;
        private LocalDate calendarDate;
        private LocalDateTime startTime;
        private LocalDateTime endTime;
        private Integer shiftIndex;
        private Integer shiftType;
        private Integer week;
        private Integer month;
        private Integer year;
        private Integer isUndefined;
        private Integer isHighPriority;
        private Long createUser;
        private Date createTime;
        ProductionCalendarDaytimeBuilder() {
        }
        public ProductionCalendarDaytimeBuilder id(final Long id) {
            this.id = id;
            return this;
        }
        public ProductionCalendarDaytimeBuilder calendarId(final Long calendarId) {
            this.calendarId = calendarId;
            return this;
        }
        public ProductionCalendarDaytimeBuilder calendarDayId(final Long calendarDayId) {
            this.calendarDayId = calendarDayId;
            return this;
        }
        public ProductionCalendarDaytimeBuilder calendarDate(final LocalDate calendarDate) {
            this.calendarDate = calendarDate;
            return this;
        }
        public ProductionCalendarDaytimeBuilder startTime(final LocalDateTime startTime) {
            this.startTime = startTime;
            return this;
        }
        public ProductionCalendarDaytimeBuilder endTime(final LocalDateTime endTime) {
            this.endTime = endTime;
            return this;
        }
        public ProductionCalendarDaytimeBuilder shiftIndex(final Integer shiftIndex) {
            this.shiftIndex = shiftIndex;
            return this;
        }
        public ProductionCalendarDaytimeBuilder shiftType(final Integer shiftType) {
            this.shiftType = shiftType;
            return this;
        }
        public ProductionCalendarDaytimeBuilder week(final Integer week) {
            this.week = week;
            return this;
        }
        public ProductionCalendarDaytimeBuilder month(final Integer month) {
            this.month = month;
            return this;
        }
        public ProductionCalendarDaytimeBuilder year(final Integer year) {
            this.year = year;
            return this;
        }
        public ProductionCalendarDaytimeBuilder isUndefined(final Integer isUndefined) {
            this.isUndefined = isUndefined;
            return this;
        }
        public ProductionCalendarDaytimeBuilder isHighPriority(final Integer isHighPriority) {
            this.isHighPriority = isHighPriority;
            return this;
        }
        public ProductionCalendarDaytimeBuilder createUser(final Long createUser) {
            this.createUser = createUser;
            return this;
        }
        public ProductionCalendarDaytimeBuilder createTime(final Date createTime) {
            this.createTime = createTime;
            return this;
        }
        public ProductionCalendarDaytime build() {
            return new ProductionCalendarDaytime(this.id, this.calendarId, this.calendarDayId, this.calendarDate, this.startTime, this.endTime, this.shiftIndex, this.shiftType, this.week, this.month, this.year, this.isUndefined, this.isHighPriority, this.createUser, this.createTime);
        }
        public String toString() {
            return "ProductionCalendarDaytime.ProductionCalendarDaytimeBuilder(id=" + this.id + ", calendarId=" + this.calendarId + ", calendarDayId=" + this.calendarDayId + ", calendarDate=" + this.calendarDate + ", startTime=" + this.startTime + ", endTime=" + this.endTime + ", shiftIndex=" + this.shiftIndex + ", shiftType=" + this.shiftType + ", week=" + this.week + ", month=" + this.month + ", year=" + this.year + ", isUndefined=" + this.isUndefined + ", isHighPriority=" + this.isHighPriority + ", createUser=" + this.createUser + ", createTime=" + this.createTime + ")";
        }
    }
    public void setId(final Long id) {
        this.id = id;
    }
    public void setCalendarId(final Long calendarId) {
        this.calendarId = calendarId;
    }
    public void setCalendarDayId(final Long calendarDayId) {
        this.calendarDayId = calendarDayId;
    }
    public void setCalendarDate(final LocalDate calendarDate) {
        this.calendarDate = calendarDate;
    }
    public void setStartTime(final LocalDateTime startTime) {
        this.startTime = startTime;
    }
    public void setEndTime(final LocalDateTime endTime) {
        this.endTime = endTime;
    }
    public void setShiftIndex(final Integer shiftIndex) {
        this.shiftIndex = shiftIndex;
    }
    public void setShiftType(final Integer shiftType) {
        this.shiftType = shiftType;
    }
    public void setWeek(final Integer week) {
        this.week = week;
    }
    public void setMonth(final Integer month) {
        this.month = month;
    }
    public void setYear(final Integer year) {
        this.year = year;
    }
    public void setIsUndefined(final Integer isUndefined) {
        this.isUndefined = isUndefined;
    }
    public void setIsHighPriority(final Integer isHighPriority) {
        this.isHighPriority = isHighPriority;
    }
    public void setCreateUser(final Long createUser) {
        this.createUser = createUser;
    }
    public void setCreateTime(final Date createTime) {
        this.createTime = createTime;
    }
    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        }
        if (o instanceof ProductionCalendarDaytime) {
            ProductionCalendarDaytime other = (ProductionCalendarDaytime) o;
            if (other.canEqual(this)) {
                Object this$id = getId();
                Object other$id = other.getId();
                if (this$id == null) {
                    if (other$id != null) {
                        return false;
                    }
                } else if (!this$id.equals(other$id)) {
                    return false;
                }
                Object this$calendarId = getCalendarId();
                Object other$calendarId = other.getCalendarId();
                if (this$calendarId == null) {
                    if (other$calendarId != null) {
                        return false;
                    }
                } else if (!this$calendarId.equals(other$calendarId)) {
                    return false;
                }
                Object this$calendarDayId = getCalendarDayId();
                Object other$calendarDayId = other.getCalendarDayId();
                if (this$calendarDayId == null) {
                    if (other$calendarDayId != null) {
                        return false;
                    }
                } else if (!this$calendarDayId.equals(other$calendarDayId)) {
                    return false;
                }
                Object this$shiftIndex = getShiftIndex();
                Object other$shiftIndex = other.getShiftIndex();
                if (this$shiftIndex == null) {
                    if (other$shiftIndex != null) {
                        return false;
                    }
                } else if (!this$shiftIndex.equals(other$shiftIndex)) {
                    return false;
                }
                Object this$shiftType = getShiftType();
                Object other$shiftType = other.getShiftType();
                if (this$shiftType == null) {
                    if (other$shiftType != null) {
                        return false;
                    }
                } else if (!this$shiftType.equals(other$shiftType)) {
                    return false;
                }
                Object this$week = getWeek();
                Object other$week = other.getWeek();
                if (this$week == null) {
                    if (other$week != null) {
                        return false;
                    }
                } else if (!this$week.equals(other$week)) {
                    return false;
                }
                Object this$month = getMonth();
                Object other$month = other.getMonth();
                if (this$month == null) {
                    if (other$month != null) {
                        return false;
                    }
                } else if (!this$month.equals(other$month)) {
                    return false;
                }
                Object this$year = getYear();
                Object other$year = other.getYear();
                if (this$year == null) {
                    if (other$year != null) {
                        return false;
                    }
                } else if (!this$year.equals(other$year)) {
                    return false;
                }
                Object this$isUndefined = getIsUndefined();
                Object other$isUndefined = other.getIsUndefined();
                if (this$isUndefined == null) {
                    if (other$isUndefined != null) {
                        return false;
                    }
                } else if (!this$isUndefined.equals(other$isUndefined)) {
                    return false;
                }
                Object this$isHighPriority = getIsHighPriority();
                Object other$isHighPriority = other.getIsHighPriority();
                if (this$isHighPriority == null) {
                    if (other$isHighPriority != null) {
                        return false;
                    }
                } else if (!this$isHighPriority.equals(other$isHighPriority)) {
                    return false;
                }
                Object this$createUser = getCreateUser();
                Object other$createUser = other.getCreateUser();
                if (this$createUser == null) {
                    if (other$createUser != null) {
                        return false;
                    }
                } else if (!this$createUser.equals(other$createUser)) {
                    return false;
                }
                Object this$calendarDate = getCalendarDate();
                Object other$calendarDate = other.getCalendarDate();
                if (this$calendarDate == null) {
                    if (other$calendarDate != null) {
                        return false;
                    }
                } else if (!this$calendarDate.equals(other$calendarDate)) {
                    return false;
                }
                Object this$startTime = getStartTime();
                Object other$startTime = other.getStartTime();
                if (this$startTime == null) {
                    if (other$startTime != null) {
                        return false;
                    }
                } else if (!this$startTime.equals(other$startTime)) {
                    return false;
                }
                Object this$endTime = getEndTime();
                Object other$endTime = other.getEndTime();
                if (this$endTime == null) {
                    if (other$endTime != null) {
                        return false;
                    }
                } else if (!this$endTime.equals(other$endTime)) {
                    return false;
                }
                Object this$createTime = getCreateTime();
                Object other$createTime = other.getCreateTime();
                return this$createTime == null ? other$createTime == null : this$createTime.equals(other$createTime);
            }
            return false;
        }
        return false;
    }
    protected boolean canEqual(final Object other) {
        return other instanceof ProductionCalendarDaytime;
    }
    public int hashCode() {
        Object $id = getId();
        int result = (1 * 59) + ($id == null ? 43 : $id.hashCode());
        Object $calendarId = getCalendarId();
        int result2 = (result * 59) + ($calendarId == null ? 43 : $calendarId.hashCode());
        Object $calendarDayId = getCalendarDayId();
        int result3 = (result2 * 59) + ($calendarDayId == null ? 43 : $calendarDayId.hashCode());
        Object $shiftIndex = getShiftIndex();
        int result4 = (result3 * 59) + ($shiftIndex == null ? 43 : $shiftIndex.hashCode());
        Object $shiftType = getShiftType();
        int result5 = (result4 * 59) + ($shiftType == null ? 43 : $shiftType.hashCode());
        Object $week = getWeek();
        int result6 = (result5 * 59) + ($week == null ? 43 : $week.hashCode());
        Object $month = getMonth();
        int result7 = (result6 * 59) + ($month == null ? 43 : $month.hashCode());
        Object $year = getYear();
        int result8 = (result7 * 59) + ($year == null ? 43 : $year.hashCode());
        Object $isUndefined = getIsUndefined();
        int result9 = (result8 * 59) + ($isUndefined == null ? 43 : $isUndefined.hashCode());
        Object $isHighPriority = getIsHighPriority();
        int result10 = (result9 * 59) + ($isHighPriority == null ? 43 : $isHighPriority.hashCode());
        Object $createUser = getCreateUser();
        int result11 = (result10 * 59) + ($createUser == null ? 43 : $createUser.hashCode());
        Object $calendarDate = getCalendarDate();
        int result12 = (result11 * 59) + ($calendarDate == null ? 43 : $calendarDate.hashCode());
        Object $startTime = getStartTime();
        int result13 = (result12 * 59) + ($startTime == null ? 43 : $startTime.hashCode());
        Object $endTime = getEndTime();
        int result14 = (result13 * 59) + ($endTime == null ? 43 : $endTime.hashCode());
        Object $createTime = getCreateTime();
        return (result14 * 59) + ($createTime == null ? 43 : $createTime.hashCode());
    }
    public String toString() {
        return "ProductionCalendarDaytime(id=" + getId() + ", calendarId=" + getCalendarId() + ", calendarDayId=" + getCalendarDayId() + ", calendarDate=" + getCalendarDate() + ", startTime=" + getStartTime() + ", endTime=" + getEndTime() + ", shiftIndex=" + getShiftIndex() + ", shiftType=" + getShiftType() + ", week=" + getWeek() + ", month=" + getMonth() + ", year=" + getYear() + ", isUndefined=" + getIsUndefined() + ", isHighPriority=" + getIsHighPriority() + ", createUser=" + getCreateUser() + ", createTime=" + getCreateTime() + ")";
    }
    public static ProductionCalendarDaytimeBuilder builder() {
        return new ProductionCalendarDaytimeBuilder();
    }
    public ProductionCalendarDaytime() {
    }
    public ProductionCalendarDaytime(final Long id, final Long calendarId, final Long calendarDayId, final LocalDate calendarDate, final LocalDateTime startTime, final LocalDateTime endTime, final Integer shiftIndex, final Integer shiftType, final Integer week, final Integer month, final Integer year, final Integer isUndefined, final Integer isHighPriority, final Long createUser, final Date createTime) {
        this.id = id;
        this.calendarId = calendarId;
        this.calendarDayId = calendarDayId;
        this.calendarDate = calendarDate;
        this.startTime = startTime;
        this.endTime = endTime;
        this.shiftIndex = shiftIndex;
        this.shiftType = shiftType;
        this.week = week;
        this.month = month;
        this.year = year;
        this.isUndefined = isUndefined;
        this.isHighPriority = isHighPriority;
        this.createUser = createUser;
        this.createTime = createTime;
    }
    public Long getId() {
        return this.id;
    }
    public Long getCalendarId() {
        return this.calendarId;
    }
    public Long getCalendarDayId() {
        return this.calendarDayId;
    }
    public LocalDate getCalendarDate() {
        return this.calendarDate;
    }
    public LocalDateTime getStartTime() {
        return this.startTime;
    }
    public LocalDateTime getEndTime() {
        return this.endTime;
    }
    public Integer getShiftIndex() {
        return this.shiftIndex;
    }
    public Integer getShiftType() {
        return this.shiftType;
    }
    public Integer getWeek() {
        return this.week;
    }
    public Integer getMonth() {
        return this.month;
    }
    public Integer getYear() {
        return this.year;
    }
    public Integer getIsUndefined() {
        return this.isUndefined;
    }
    public Integer getIsHighPriority() {
        return this.isHighPriority;
    }
    public Long getCreateUser() {
        return this.createUser;
    }
    public Date getCreateTime() {
        return this.createTime;
    }
}
collect/src/main/java/com/qianwen/mdc/collect/handler/DeviceStatusDataHandler.java
@@ -1,6 +1,7 @@
package com.qianwen.mdc.collect.handler;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
@@ -18,6 +19,7 @@
import com.qianwen.mdc.collect.entity.iotdb.DeviceState;
import com.qianwen.mdc.collect.entity.mgr.GlobalWcsOfRps;
import com.qianwen.mdc.collect.enums.FeedbackTimePointEnum;
import com.qianwen.mdc.collect.service.DeviceStateService;
import com.qianwen.mdc.collect.service.IotDBCommonService;
@Component
@@ -29,6 +31,8 @@
    private IotDBSessionConfig iotdbCfg;
    @Autowired
    private IotDBCommonService iotDBCommonService;
    @Autowired
    private DeviceStateService deviceStateService;
    @Override
    public void handleData(PackedTelemetryData data) {
        DeviceState state = new DeviceState();
@@ -48,9 +52,13 @@
        state.setValueCollect(Integer.valueOf(data.getValue()));
        state.setWcs(state.getValueCollect());
        state.setWorkstationId(data.getWorkstationId());
        state.setShiftIndex(data.getShiftIndex());
        state.setShiftTimeType(data.getShiftTimeType());
        fillWorkStationCondition(data, state);
       
        insertState(state);
        //insertState(state);
        deviceStateService.saveDeviceStates(Arrays.asList(state));
        
        log.info("状态聚合聚合完成:数据");
    }
@@ -64,7 +72,7 @@
        //log.info("获取包装工况以及绩效信息" + JsonUtil.toJson(workstationState));
       
    }
    /*
    void insertState(DeviceState state){
        String deviceId = IOTDBConstant.DB_PREFIX+IOTDBConstant.TEMPLATE_STATE+"_"+state.getWorkstationId();
        try {
@@ -83,6 +91,10 @@
            schemas.add(new MeasurementSchema("shift_time_type", TSDataType.INT32));
            schemas.add(new MeasurementSchema("wcs", TSDataType.INT32));
            schemas.add(new MeasurementSchema("rps", TSDataType.INT32));
            schemas.add(new MeasurementSchema("is_fix_point", TSDataType.BOOLEAN));
            schemas.add(new MeasurementSchema("is_sync", TSDataType.BOOLEAN));
            schemas.add(new MeasurementSchema("is_plan", TSDataType.INT32));
            schemas.add(new MeasurementSchema("feedback_point_type", TSDataType.INT32));
            schemas.add(new MeasurementSchema("feedback_id", TSDataType.INT64));
@@ -101,10 +113,14 @@
            tablet.addValue("factory_month", rowIndex, state.getFactoryMonth());
            tablet.addValue("factory_week", rowIndex, state.getFactoryWeek());
            tablet.addValue("factory_date", rowIndex, state.getFactoryDate());
            tablet.addValue("shift_index", rowIndex, state.getShiftIndex());
            tablet.addValue("shift_time_type", rowIndex, state.getShiftTimeType());
            tablet.addValue("shift_index", rowIndex, state.getShiftIndex());//TODO null
            tablet.addValue("shift_time_type", rowIndex, state.getShiftTimeType());//TODO null
            tablet.addValue("wcs", rowIndex, state.getWcs());
            tablet.addValue("rps", rowIndex, state.getRps());
            tablet.addValue("is_fix_point", rowIndex,state.getIsFixPoint());
            tablet.addValue("is_sync", rowIndex, state.getIsSync());
            tablet.addValue("is_plan", rowIndex, state.getIsPlan());
            tablet.addValue("feedback_point_type", rowIndex, state.getFeedbackPointType());
            tablet.addValue("feedback_id", rowIndex, state.getFeedbackId());
@@ -117,5 +133,5 @@
        } catch (Exception e) {
            log.error("聚合产量IODDB入库失败", e);
        }
    }
    }*/
}
collect/src/main/java/com/qianwen/mdc/collect/job/ProductionTimeCacheXxlJob.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,41 @@
package com.qianwen.mdc.collect.job;
import com.google.common.collect.Sets;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.mdc.collect.cache.TimeSliceCache;
import com.qianwen.mdc.collect.dto.CacheBuildDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class ProductionTimeCacheXxlJob {
    private static final Logger log = LoggerFactory.getLogger(ProductionTimeCacheXxlJob.class);
    @Autowired
    private TimeSliceCache timeSliceCache;
    @XxlJob("productionTimeCacheJobHandler")
    public ReturnT<String> productionTimeCacheJobHandler(String param) throws Exception {
        LocalDate targetDate = LocalDate.now().plusDays(1L);
        if (Func.isNotEmpty(param)) {
            targetDate = LocalDate.parse(param, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }
        XxlJobLogger.log("XXL-JOB, å®šæ—¶æž„建生产日历切片缓存,构建开始.....", new Object[0]);
        CacheBuildDTO cacheBuildDTO = CacheBuildDTO.builder().tenantIds(Sets.newHashSet(new String[]{"000000"})).targetDate(targetDate).build();
        if (Func.isNotEmpty(cacheBuildDTO)) {
            timeSliceCache.build(cacheBuildDTO);
        } else {
            log.error("[生产日历切片缓存构建失败...],构建时间{},构建租户:{}", targetDate, "000000");
        }
        XxlJobLogger.log("XXL-JOB, å®šæ—¶æž„建生产日历切片缓存,构建结束", new Object[0]);
        return ReturnT.SUCCESS;
    }
}
collect/src/main/java/com/qianwen/mdc/collect/mapper/iotdb/AggregateStateMapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,13 @@
package com.qianwen.mdc.collect.mapper.iotdb;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qianwen.mdc.collect.entity.iotdb.AggregateState;
@DS("iotdb")
@InterceptorIgnore(tenantLine = "true")
public interface AggregateStateMapper extends BaseMapper<AggregateState> {
}
collect/src/main/java/com/qianwen/mdc/collect/mapper/iotdb/DeviceStateMapper.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qianwen.mdc.collect.dto.StateAggregateTimeDTO;
import com.qianwen.mdc.collect.entity.iotdb.DeviceState;
import java.util.List;
@@ -26,7 +27,29 @@
    DeviceState getLastIsSyncNoFixPointState(@Param("workstationId") Long workstationId);
    DeviceState getLastWorkstationState(@Param("ew") Wrapper query);
    //DeviceState getLastWorkstationState(@Param("ew") Wrapper query);
    /**
     * èŽ·å–æœ€æ–°çš„å·²åŒæ­¥çš„éžåé¦ˆç‚¹çŠ¶æ€
     * @param workstationId
     * @return
     */
    DeviceState lastSyncedNoFeedbackPointState(Long workstationId);
    //DeviceState getFirstWorkstationState(@Param("ew") Wrapper query);
    /**
     * èŽ·å–ç¬¬ä¸€ä¸ªçš„æœªåŒæ­¥çš„éžåé¦ˆç‚¹çŠ¶æ€
     * @param workstationId
     * @return
     */
    DeviceState firstNotSyncedNofeedbackPointState(Long workstationId);
    DeviceState getFirstWorkstationState(@Param("ew") Wrapper query);
    /**
     * èŽ·å–æ—¶é—´åŒºé—´å†…çš„çŠ¶æ€æ•°æ®
     * @param workstationId
     * @param timeRange
     * @return
     */
    List<DeviceState> statesInTimeRange(@Param("workstationId")Long workstationId,@Param("timeRange") StateAggregateTimeDTO timeRange);
}
collect/src/main/java/com/qianwen/mdc/collect/mapper/mgr/CalendarDayMapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,7 @@
package com.qianwen.mdc.collect.mapper.mgr;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qianwen.mdc.collect.entity.mgr.ProductionCalendarDay;
public interface CalendarDayMapper extends BaseMapper<ProductionCalendarDay> {
}
collect/src/main/java/com/qianwen/mdc/collect/mapper/mgr/CalendarDaytimeMapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,7 @@
package com.qianwen.mdc.collect.mapper.mgr;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qianwen.mdc.collect.entity.mgr.ProductionCalendarDaytime;
public interface CalendarDaytimeMapper extends BaseMapper<ProductionCalendarDaytime> {
}
collect/src/main/java/com/qianwen/mdc/collect/service/CalendarDayService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,11 @@
package com.qianwen.mdc.collect.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianwen.mdc.collect.entity.mgr.ProductionCalendarDay;
import com.qianwen.mdc.collect.mapper.mgr.CalendarDayMapper;
import org.springframework.stereotype.Service;
@Service
public class CalendarDayService extends ServiceImpl<CalendarDayMapper, ProductionCalendarDay> {
}
collect/src/main/java/com/qianwen/mdc/collect/service/CalendarDaytimeService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,11 @@
package com.qianwen.mdc.collect.service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianwen.mdc.collect.entity.mgr.ProductionCalendarDaytime;
import com.qianwen.mdc.collect.mapper.mgr.CalendarDaytimeMapper;
import org.springframework.stereotype.Service;
@Service
public class CalendarDaytimeService extends ServiceImpl<CalendarDaytimeMapper, ProductionCalendarDaytime>{
}
collect/src/main/java/com/qianwen/mdc/collect/service/CalendarService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,124 @@
package com.qianwen.mdc.collect.service;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianwen.mdc.collect.constants.CommonConstant;
import com.qianwen.mdc.collect.dto.CacheBuildDTO;
import com.qianwen.mdc.collect.dto.CalendarShiftTimeSlicesDTO;
import com.qianwen.mdc.collect.dto.TimestampToProductionTimeCacheDto;
import com.qianwen.mdc.collect.entity.mgr.ProductionCalendar;
import com.qianwen.mdc.collect.entity.mgr.ProductionCalendarDaytime;
import com.qianwen.mdc.collect.mapper.mgr.CalendarMapper;
import com.qianwen.mdc.collect.utils.LocalDateTimeUtils;
import com.qianwen.core.secure.utils.AuthUtil;
import com.qianwen.core.tool.utils.Func;
/*
import com.qianwen.core.redis.cache.BladeRedis;
import com.qianwen.posting.constant.CommonConstant;
import com.qianwen.posting.dto.CacheBuildDTO;
import com.qianwen.posting.dto.CalendarShiftTimeSlicesDTO;
import com.qianwen.posting.dto.TimestampToProductionTimeCacheDto;
import com.qianwen.posting.entity.mysql.ProductionCalendar;
import com.qianwen.posting.entity.mysql.ProductionCalendarDaytime;
import com.qianwen.posting.service.ICalendarDayService;
import com.qianwen.posting.service.ICalendarDaytimeService;
import com.qianwen.posting.service.ICalendarService;
import com.qianwen.posting.utils.LocalDateTimeUtils;
*/
@Service
public class CalendarService extends ServiceImpl<CalendarMapper, ProductionCalendar>{
    private static final Logger log = LoggerFactory.getLogger(CalendarService.class);
    @Autowired
    private CalendarDayService calendarDayService;
    @Autowired
    private CalendarDaytimeService calendarDaytimeService;
    //private final BladeRedis bladeRedis;
    /*
    @Override
    public String getShiftIndexNameByCodeAndYear(String calendarCode, Integer year, Integer shiftIndex) {
        return ((CalendarMapper) this.baseMapper).getShiftIndexNameByCodeAndYear(calendarCode, year, shiftIndex, AuthUtil.getTenantId());
    }*/
    //构建生产日历切片(blade_production_calendar)
    public List<TimestampToProductionTimeCacheDto> buildProductionTimeCache(CacheBuildDTO cacheBuildDTO) {
        LocalDate targetDate = cacheBuildDTO.getTargetDate();
        Set<String> tenantIds = cacheBuildDTO.getTenantIds();
        String code = cacheBuildDTO.getCalendarCode();
        List<TimestampToProductionTimeCacheDto> timestampToProductionTimeCacheDtos = new ArrayList<>();
        List<ProductionCalendar> list = list((new QueryWrapper<ProductionCalendar>()).lambda()
            .in(ProductionCalendar::getTenantId, tenantIds)
            .eq(ProductionCalendar::getStatus, CommonConstant.ENABLE)
            .eq(StringUtils.isNotBlank(code), ProductionCalendar::getCode, code)
            .eq(ProductionCalendar::getYear, Integer.valueOf(targetDate.getYear())));
        LocalDateTime startTime = LocalDateTime.of(targetDate, LocalTime.MIN);//0分0秒开始
        LocalDateTime endTime = LocalDateTime.of(targetDate.plusDays(1L), LocalTime.of(0, 0));//第二天0点
        if (Func.isNotEmpty(list)) {
          Map<String, List<ProductionCalendar>> collect = (Map<String, List<ProductionCalendar>>)list.stream().collect(Collectors.groupingBy(ProductionCalendar::getTenantId));
            collect.forEach((tenantId, productionList) -> {
                productionList.forEach(productionCalendar -> {
                    TimestampToProductionTimeCacheDto timestampToProductionTimeCacheDto = TimestampToProductionTimeCacheDto.builder().TenantId(productionCalendar.getTenantId()).CalendarCode(productionCalendar.getCode()).NaturalDay(targetDate).build();
                    List<ProductionCalendarDaytime> dayTimeList = this.calendarDaytimeService.list(new QueryWrapper<ProductionCalendarDaytime>().lambda()
                            .eq(ProductionCalendarDaytime::getCalendarId, productionCalendar.getId()).or().and(i -> {
                        LambdaQueryWrapper lambdaQueryWrapper = i.between(ProductionCalendarDaytime::getStartTime, startTime, endTime).or()
                                .between(ProductionCalendarDaytime::getEndTime, startTime, endTime);
                    }).orderByAsc(ProductionCalendarDaytime::getStartTime));
                    List<ProductionCalendarDaytime> dayTimeList2 = dayTimeList.stream().filter(productionCalendarDaytime -> {
                        return (productionCalendarDaytime.getEndTime().equals(startTime) || productionCalendarDaytime.getStartTime().equals(endTime)) ? false : true;
                    }).collect(Collectors.toList());
                    Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesMap = new HashMap<>(1919);
                    for (int i2 = 0; i2 <= CommonConstant.MINUTE_STOP.intValue(); i2++) {//MINUTE_STOP=1439,差一分钟23小时59分的分钟数
                        buildTimeSlicesMap(startTime, endTime, dayTimeList2, timeSlicesMap, i2, targetDate);
                    }
                    timestampToProductionTimeCacheDto.setTimeSlicesDTOMap(timeSlicesMap);
                    timestampToProductionTimeCacheDtos.add(timestampToProductionTimeCacheDto);
                });
            });
        }
        return timestampToProductionTimeCacheDtos;
    }
    private void buildTimeSlicesMap(LocalDateTime startTime, LocalDateTime endTime, List<ProductionCalendarDaytime> dayTimeList, Map<Integer, CalendarShiftTimeSlicesDTO> timeSlicesDTOMap, int i, LocalDate targetDate) {
        LocalDateTime localDateTime = LocalDateTime.of(targetDate, LocalTime.MIN).plusMinutes(i).plusSeconds(1L);
        //在dayTimeList中过滤出在starttime,endtime之间的日期
        ProductionCalendarDaytime productionCalendarDaytime = dayTimeList.stream().filter(dayTime -> {
            return (localDateTime.isAfter(dayTime.getStartTime()) || localDateTime.equals(dayTime.getStartTime())) && (localDateTime.isBefore(dayTime.getEndTime()) || localDateTime.equals(dayTime.getEndTime()));
        }).findFirst().orElse(null);
        if (Func.isEmpty(productionCalendarDaytime)) {
            return;
        }
        LocalDateTime shiftStartTime = productionCalendarDaytime.getStartTime();
        LocalDateTime shiftEndTime = productionCalendarDaytime.getEndTime();
        if (shiftStartTime.isBefore(startTime)) {
            shiftStartTime = startTime;
        }
        if (shiftEndTime.isAfter(endTime)) {
            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(i), calendarShiftTimeSlicesDTO);
    }
}
collect/src/main/java/com/qianwen/mdc/collect/service/CollectDataService.java
@@ -38,8 +38,6 @@
    private IotDBSessionConfig iotdbConfig;
    @Autowired
    private IotDBCommonService iotDBCommonService;
    @Autowired
    private  RedisUtil redisUtil;
    
    private static String TEMPLATE_NAME = "process_param";
collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateAggregateNoFeedbackService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,161 @@
package com.qianwen.mdc.collect.service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.mdc.collect.config.IotDBSessionConfig;
import com.qianwen.mdc.collect.constants.IOTDBConstant;
import com.qianwen.mdc.collect.dto.StateAggregateTimeDTO;
import com.qianwen.mdc.collect.entity.iotdb.AggregateState;
import com.qianwen.mdc.collect.entity.iotdb.DeviceState;
import com.qianwen.mdc.collect.mapper.iotdb.AggregateStateMapper;
import com.qianwen.mdc.collect.mapper.iotdb.DeviceStateMapper;
import com.qianwen.mdc.collect.utils.WorkstationStateAggregateNoFeedbackUtils;
/**
 * éžåé¦ˆç‚¹ çŠ¶æ€èšåˆæœåŠ¡
 */
@Service
public class DeviceStateAggregateNoFeedbackService {
    private static final Logger log = LoggerFactory.getLogger(DeviceStateAggregateNoFeedbackService.class);
    @Autowired
    private DeviceStateMapper stateMapper;
    @Autowired
    private AggregateStateMapper workstationAggregateStateMapper;
    @Autowired
    private IotDBSessionConfig iotdbConfig;
    public List<AggregateState> stateAggregateForSpecialTimeRange(Long workstationId, StateAggregateTimeDTO timeRange, List<DeviceState> effectiveStateList) {
        //按timeRange查询时间区间内的状态数据,除了已删除的,其他数据都查出来了
        /*
        List<DeviceState> notSyncWorkstationStates = this.stateMapper.selectList(Wrappers.<DeviceState>lambdaQuery()
                .eq(DeviceState::getWorkstationId, workstationId).and(wrapper -> {
            LambdaQueryWrapper lambdaQueryWrapper = wrapper.eq(DeviceState::getIsDeleted, Boolean.FALSE).or().isNull(DeviceState::getIsDeleted);
        }).ge(Func.isNotEmpty(timeRange.getStartTime()), DeviceState::getTime, timeRange.getStartTime())
                .le(DeviceState::getTime, timeRange.getEndTime()).orderByAsc(DeviceState::getTime));
        */
        List<DeviceState> notSyncWorkstationStates = stateMapper.statesInTimeRange(workstationId,timeRange);
        effectiveStateList.addAll(notSyncWorkstationStates);//干嘛的?返回给调用者了?
        List<AggregateState> result = WorkstationStateAggregateNoFeedbackUtils.buildAggregateList(notSyncWorkstationStates);
        return result;
    }
    /**
     * è¿‡æ»¤å‡ºæœ‰æ•ˆèšåˆçŠ¶æ€æ•°æ®å¹¶ä¿å­˜
     * @param result
     * @param workstationId
     * @param effectTimeRangeList
     */
    public void handlerAggregateState(List<AggregateState> result, Long workstationId, StateAggregateTimeDTO timeRange) {
        /*
        if (Func.isNotEmpty(result)) {
            Map<String, List> stringListMap = CommonUtil.groupList(getFinallyAggregateStateList(result, workstationId, effectTimeRangeList), CommonConstant.MAX_RECORDS_FOR_SQL_LENGTH.intValue());
            stringListMap.forEach(k, v -> {
                this.workstationAggregateStateMapper.batchSave(workstationId, v);
            });
        }*/
        if(result.isEmpty()) {
            return;
        }
        List<AggregateState> aggStates = getFinallyAggregateStateList(result, workstationId, timeRange);
        List<MeasurementSchema> schemas = new ArrayList<>();
        schemas.add(new MeasurementSchema("workstation_id", TSDataType.INT64));
        schemas.add(new MeasurementSchema("value_collect", TSDataType.INT32));
        schemas.add(new MeasurementSchema("end_time", TSDataType.INT64));
        schemas.add(new MeasurementSchema("duration_collect", TSDataType.INT64));
        schemas.add(new MeasurementSchema("calendar_code", TSDataType.TEXT));
        schemas.add(new MeasurementSchema("factory_year", TSDataType.INT32));
        schemas.add(new MeasurementSchema("factory_month", TSDataType.INT32));
        schemas.add(new MeasurementSchema("factory_week", TSDataType.INT32));
        schemas.add(new MeasurementSchema("factory_date", TSDataType.INT32));
        schemas.add(new MeasurementSchema("shift_index", TSDataType.INT32));
        schemas.add(new MeasurementSchema("shift_time_type", TSDataType.INT32));
        schemas.add(new MeasurementSchema("wcs", TSDataType.INT32));
        schemas.add(new MeasurementSchema("rps", TSDataType.INT32));
        schemas.add(new MeasurementSchema("is_sync", TSDataType.BOOLEAN));
        schemas.add(new MeasurementSchema("is_plan", TSDataType.INT32));//TODO è¿™ä¸ªå±žæ€§åº”该是GlobalWcsOfRps中的值,如何填写?
        schemas.add(new MeasurementSchema("feedback_id", TSDataType.INT64));
        schemas.add(new MeasurementSchema("is_deleted", TSDataType.BOOLEAN));
        schemas.add(new MeasurementSchema("employee_id", TSDataType.INT64));
        //命名:aggregate_state_{workstation_id}
        String deviceId = IOTDBConstant.DB_PREFIX+"aggregate_state_"+workstationId;
        Tablet tablet = new Tablet(deviceId, schemas);
        //tablet.rowSize = aggStates.size();
        AggregateState aggState;
        for(int i=0;i<aggStates.size();i++) {
            aggState = aggStates.get(i);
            tablet.addTimestamp(i, aggState.getTime());
            tablet.addValue("workstation_id", i, aggState.getWorkstationId());
            tablet.addValue("value_collect", i, aggState.getValueCollect());
            tablet.addValue("end_time", i, aggState.getEndTime());
            tablet.addValue("duration_collect", i, aggState.getDurationCollect());
            tablet.addValue("calendar_code", i, aggState.getCalendarCode());
            tablet.addValue("factory_year", i, aggState.getFactoryYear());
            tablet.addValue("factory_month", i, aggState.getFactoryMonth());
            tablet.addValue("factory_week", i, aggState.getFactoryWeek());
            tablet.addValue("factory_date", i, aggState.getFactoryDate());
            tablet.addValue("shift_index", i, aggState.getShiftIndex());
            tablet.addValue("shift_time_type", i, aggState.getShiftTimeType());
            tablet.addValue("wcs", i, aggState.getWcs());
            tablet.addValue("rps", i, aggState.getRps());
            tablet.addValue("is_sync", i, aggState.getIsSync());
            tablet.addValue("is_plan", i, aggState.getIsPlan());
            tablet.addValue("feedback_id", i, aggState.getFeedbackId());
            tablet.addValue("is_deleted", i, aggState.getIsDeleted());
            tablet.addValue("employee_id", i, aggState.getEmployeeId());
        }
        try {
            this.iotdbConfig.getSessionPool().insertAlignedTablet(tablet);
        } catch (Exception e) {
            log.error("保存聚合状态数据异常",e);
        }
    }
    private List<AggregateState> getFinallyAggregateStateList(List<AggregateState> result, Long workstationId, StateAggregateTimeDTO timeRange) {
        /*
        List<StateAggregateTimeDTO> effectTimeRangeList2 = effectTimeRangeList.stream().filter(x -> {
            return Boolean.TRUE.equals(x.getNoFeedbackTime());
        }).collect(Collectors.toList());
        */
        List<AggregateState> finallyResult = new ArrayList<>();
        //for (StateAggregateTimeDTO item : effectTimeRangeList2) {
            List<AggregateState> temp = this.workstationAggregateStateMapper.selectList(Wrappers.<AggregateState>lambdaQuery()
                    .eq(AggregateState::getWorkstationId, workstationId).and(wrapper -> {
                LambdaQueryWrapper lambdaQueryWrapper = wrapper.eq(AggregateState::getIsDeleted, Boolean.FALSE).or().isNull(AggregateState::getIsDeleted);
                    }).
                    ge(Func.isNotEmpty(timeRange.getStartTime()), AggregateState::getTime, timeRange.getStartTime()).le(AggregateState::getTime, timeRange.getEndTime()).orderByAsc(AggregateState::getTime));
            if (Func.isNotEmpty(temp)) {
                finallyResult.addAll(temp);
            }
        //}
        List<AggregateState> deleteData = finallyResult.stream().map(x2 -> {
            x2.setIsDeleted(Boolean.TRUE);
            return x2;
        }).collect(Collectors.toList());
        return WorkstationStateAggregateNoFeedbackUtils.getReallyEffectWorkstationStateAggregateNoFeedbackList(result, deleteData);
    }
}
collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateAggregateService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,198 @@
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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
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.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.StateAggregateTimeDTO;
import com.qianwen.mdc.collect.dto.WorkstationDTO;
import com.qianwen.mdc.collect.entity.iotdb.AggregateState;
import com.qianwen.mdc.collect.entity.iotdb.DeviceState;
import com.qianwen.mdc.collect.enums.FeedbackTimePointEnum;
import com.qianwen.mdc.collect.mapper.iotdb.DeviceStateMapper;
import com.qianwen.mdc.collect.mapper.mgr.CalendarMapper;
import com.qianwen.mdc.collect.utils.FeedbackAnalyseUtils;
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;
/**
 * è®¾å¤‡çŠ¶æ€èšåˆæœåŠ¡
 */
@Service
public class DeviceStateAggregateService{
    private static final Logger log = LoggerFactory.getLogger(DeviceStateAggregateService.class);
    @Autowired
    private CalendarMapper calendarMapper;
    @Autowired
    private DeviceStateMapper stateMapper;
    @Autowired
    private WorkstationCache workstationCache;
    @Autowired
    private IotDBCommonService iotDBCommonService;
    @Autowired
    private IotDBSessionConfig iotdbConfig;
    @Autowired
    private DeviceStateService deviceStateService;
    @Autowired
    private DeviceStateAggregateNoFeedbackService stateAggregateNoFeedbackService;
    public void stateAggregate(Long workstationId) {
        ////获取时间阶段列表(2个),一个noFeedbackTime=true,一个noFeedbackTime=false,我们自己返回一个startTime,endTime即可,noFeedbackTime=true的即可
        //List<StateAggregateTimeDTO> effective = getCurrentStateAggregateTimeRange(workstationId);
        StateAggregateTimeDTO timeRange = getAggregateTimeRange(workstationId);
        List<AggregateState> noFeedbackAggregateList = new ArrayList<>();
        //List<WorkstationAggregateStateWithFeedback> feedbackAggregateList = new ArrayList<>();//暂时不需要,没人填写反馈
        List<DeviceState> noFeedbackStateList = new ArrayList<>();//回填的列表
        noFeedbackAggregateList.addAll(this.stateAggregateNoFeedbackService.stateAggregateForSpecialTimeRange(workstationId, timeRange, noFeedbackStateList));
        /*
        Collection<DeviceState> effectiveState = getReallyEffectWorkstationStateList(noFeedbackStateList, feedbackStateList);
        List<DeviceState> effectiveStateList = effectiveState.stream().map(x -> {
            x.setIsSync(Boolean.TRUE);
            return x;
        }).collect(Collectors.toList());*/
        noFeedbackStateList.forEach(state -> {state.setIsSync(true);});//TODO æ˜¯å¦éœ€è¦ç”Ÿæˆæ–°åˆ—表?避免被修改数据
        //this.stateAggregateWithFeedbackService.handlerAggregateState(feedbackAggregateList, workstationId, effective);
        this.stateAggregateNoFeedbackService.handlerAggregateState(noFeedbackAggregateList, workstationId, timeRange);//过滤出有效状态数据并保存
        //更新isSync得状态
        /*
        if (Func.isNotEmpty(effectiveStateList)) {
            Map<String, List> stringListMap = CommonUtil.groupList(effectiveStateList, CommonConstant.MAX_RECORDS_FOR_SQL_LENGTH.intValue());
            stringListMap.forEach((k, v) -> {
                this.workstationStateMapper.batchSave(workstationId, v);
            });
        }*/
        deviceStateService.saveDeviceStates(noFeedbackStateList);//更新isSync=true
        ////使用workstationWcsFeedbackMapper更新反馈得状态,我们不需要
        //IWorkstationFeedbackService workstationFeedbackService = SpringUtil.getBean(IWorkstationFeedbackService.class);
        //workstationFeedbackService.handlerFeedbackComplete(workstationId);
    }
    private StateAggregateTimeDTO getAggregateTimeRange(Long workstationId) {
        Long normalStartTime = FeedbackAnalyseUtils.getNormalStartTimePoint(workstationId, stateMapper);//最后一个已同步的isFixPoint=false时间,或者最新一个未同步的。总之就是查找聚合开始时间点。
        //这个
        StateAggregateTimeDTO nofeedBackTimeRange2 = new StateAggregateTimeDTO();
        nofeedBackTimeRange2.setStartTime(normalStartTime);
        nofeedBackTimeRange2.setEndTime(System.currentTimeMillis());
        nofeedBackTimeRange2.setNoFeedbackTime(Boolean.FALSE);
        return nofeedBackTimeRange2;
    }
    /**
     * èŽ·å–æ—¶é—´èŒƒå›´ï¼Ÿï¼Ÿï¼Ÿ
     */
    /*
    private List<StateAggregateTimeDTO> getCurrentStateAggregateTimeRange(Long workstationId) {
        Long currentTime = Long.valueOf(System.currentTimeMillis());
        List<StateAggregateTimeDTO> effectiveTimeRangeList = new ArrayList<>();
        //WorkstationStateMapper stateMapper = SpringUtil.getBean(WorkstationStateMapper.class);
        //List<DeviceState> processingStateList = stateMapper.getProcessingFeedbackState(workstationId); // is_sync = false AND feedback_point_type != 0
        List<DeviceState> processingStateList = Collections.emptyList();//我们没有feedback_point_type != 0的数据,就是没有反馈点数据
        Long normalStartTime = FeedbackAnalyseUtils.getNormalStartTimePoint(workstationId, stateMapper);//最后一个已同步的isFixPoint=false时间,或者最新一个未同步的。总之就是查找聚合开始时间点。
        if (Func.isNotEmpty(processingStateList)) {//非空(有未同步的反馈点)
            //!!!这个IF里数据没用
            //查找starttime,endtime (sync=true,IsFixPoint=false) : startTime<  processingStateList < endTime
            //Long startTime = FeedbackAnalyseUtils.getStartFeedbackTimePoint(workstationId, stateMapper, processingStateList);
            //Long endTime = FeedbackAnalyseUtils.getEndFeedbackTimePoint(workstationId, stateMapper, processingStateList);
            Long startTime = 0L;//临时数据,没用
            Long endTime =0L;
            StateAggregateTimeDTO feedbackTimeRange = new StateAggregateTimeDTO();
            feedbackTimeRange.setNoFeedbackTime(Boolean.FALSE);
            feedbackTimeRange.setStartTime(startTime);
            if (Func.isNotEmpty(endTime)) {
                feedbackTimeRange.setEndTime(endTime);
            } else {
                endTime = currentTime;
                feedbackTimeRange.setEndTime(currentTime);
            }
            if (Func.isNotEmpty(normalStartTime)) {
                if (normalStartTime.longValue() <= startTime.longValue()) {
                    feedbackTimeRange.setStartTime(startTime);
                }
                if (startTime.longValue() >= normalStartTime.longValue() && endTime.longValue() >= normalStartTime.longValue()) {
                    feedbackTimeRange.setEndTime(currentTime);
                }
                if (normalStartTime.longValue() > endTime.longValue()) {
                    StateAggregateTimeDTO nofeedBackTimeRange = new StateAggregateTimeDTO();
                    nofeedBackTimeRange.setStartTime(normalStartTime);
                    nofeedBackTimeRange.setNoFeedbackTime(Boolean.FALSE);
                    nofeedBackTimeRange.setEndTime(currentTime);
                    effectiveTimeRangeList.add(nofeedBackTimeRange);
                }
            } else {
                feedbackTimeRange.setStartTime(null);
                feedbackTimeRange.setEndTime(currentTime);
            }
            effectiveTimeRangeList.add(feedbackTimeRange);
        } else {
            //这个
            StateAggregateTimeDTO nofeedBackTimeRange2 = new StateAggregateTimeDTO();
            nofeedBackTimeRange2.setStartTime(normalStartTime);
            nofeedBackTimeRange2.setEndTime(currentTime);
            nofeedBackTimeRange2.setNoFeedbackTime(Boolean.FALSE);
            effectiveTimeRangeList.add(nofeedBackTimeRange2);
        }
        StateAggregateTimeDTO nofeedBackTimeRange3 = new StateAggregateTimeDTO();
        nofeedBackTimeRange3.setStartTime(normalStartTime);
        nofeedBackTimeRange3.setEndTime(currentTime);
        nofeedBackTimeRange3.setNoFeedbackTime(Boolean.TRUE);
        effectiveTimeRangeList.add(nofeedBackTimeRange3);
        return effectiveTimeRangeList;
    }
    */
    /**
     * åŽ»é‡çš„ä½œç”¨ï¼Œå°†æ‰€æœ‰çŠ¶æ€æ•°æ®åŽ»é‡æ”¾åˆ°ä¸€ä¸ªåˆ—è¡¨
     * @param noFeedbackStateList
     * @param feedbackStateList
     * @return
     */
    /*
    private Collection<DeviceState> getReallyEffectWorkstationStateList(List<DeviceState> noFeedbackStateList, List<DeviceState> feedbackStateList) {
        HashMap<Long, DeviceState> workstationStateMap = new HashMap<>();
        if (Func.isNotEmpty(noFeedbackStateList)) {
            noFeedbackStateList.forEach(item -> {
                workstationStateMap.put(item.getTime(), item);
            });
        }
        if (Func.isNotEmpty(feedbackStateList)) {
            for (DeviceState state : feedbackStateList) {
                if (!workstationStateMap.containsKey(state.getTime())) {
                    workstationStateMap.put(state.getTime(), state);
                }
            }
        }
        return workstationStateMap.values();
    }*/
}
collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateFixPointService.java
@@ -216,8 +216,6 @@
            } 
            
        }
        
    }
    private List<DeviceState> getDefaultShift24HourPointDTOS(Long workStationId, String calendarCode, CalendarShiftInfoDTO shift) {
collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,134 @@
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 java.util.stream.Collectors;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
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.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;
/**
 * è®¾å¤‡çŠ¶æ€æ™®é€šæœåŠ¡
 */
@Service
public class DeviceStateService{
    private static final Logger log = LoggerFactory.getLogger(DeviceStateService.class);
    @Autowired
    private IotDBCommonService iotDBCommonService;
    @Autowired
    private IotDBSessionConfig iotdbConfig;
    static final List<MeasurementSchema> schemas;
    static {
        schemas = new ArrayList<>();
        schemas.add(new MeasurementSchema("workstation_id", TSDataType.INT64));
        schemas.add(new MeasurementSchema("value_collect", TSDataType.INT32));
        schemas.add(new MeasurementSchema("calendar_code", TSDataType.TEXT));
        schemas.add(new MeasurementSchema("factory_year", TSDataType.INT32));
        schemas.add(new MeasurementSchema("factory_month", TSDataType.INT32));
        schemas.add(new MeasurementSchema("factory_week", TSDataType.INT32));
        schemas.add(new MeasurementSchema("factory_date", TSDataType.INT32));
        schemas.add(new MeasurementSchema("shift_index", TSDataType.INT32));
        schemas.add(new MeasurementSchema("shift_time_type", TSDataType.INT32));
        schemas.add(new MeasurementSchema("wcs", TSDataType.INT32));
        schemas.add(new MeasurementSchema("rps", TSDataType.INT32));
        schemas.add(new MeasurementSchema("is_fix_point", TSDataType.BOOLEAN));
        schemas.add(new MeasurementSchema("is_sync", TSDataType.BOOLEAN));
        schemas.add(new MeasurementSchema("is_plan", TSDataType.INT32));//TODO è¿™ä¸ªå±žæ€§åº”该是GlobalWcsOfRps中的值,如何填写?
        schemas.add(new MeasurementSchema("feedback_point_type", TSDataType.INT32));
        schemas.add(new MeasurementSchema("feedback_id", TSDataType.INT64));
        schemas.add(new MeasurementSchema("is_deleted", TSDataType.BOOLEAN));
        schemas.add(new MeasurementSchema("employee_id", TSDataType.INT64));
    }
    /**
     * ä¿å­˜çŠ¶æ€å›ºå®šç‚¹æ•°æ®(state_{workstationId})
     * @param stateList
     */
    public void saveDeviceStates(List<DeviceState> stateList) {
        //将数据按照工位id分组
        Map<Long,List<DeviceState>> maps = stateList.stream().collect(Collectors.groupingBy(DeviceState::getWorkstationId));
        String deviceId;
        Long wid;
        List<DeviceState> states;
        for(Entry<Long, List<DeviceState>>  entry: maps.entrySet()) {
            wid = entry.getKey();
            deviceId = IOTDBConstant.DB_PREFIX+"state_"+wid;
            iotDBCommonService.setTemmplateIfNotSet(IOTDBConstant.TEMPLATE_STATE, deviceId);//挂载模板
            Tablet tablet = new Tablet(deviceId, schemas);
            states = entry.getValue();
            tablet.rowSize = states.size();
            DeviceState state;
            for(int i=0;i<states.size();i++) {
                state = states.get(i);
                tablet.addTimestamp(i, state.getTime());
                tablet.addValue("workstation_id", i, state.getWorkstationId());
                tablet.addValue("value_collect", i, state.getValueCollect());
                tablet.addValue("calendar_code", i, state.getCalendarCode());
                tablet.addValue("factory_year", i, state.getFactoryYear());
                tablet.addValue("factory_month", i, state.getFactoryMonth());
                tablet.addValue("factory_week", i, state.getFactoryWeek());
                tablet.addValue("factory_date", i, state.getFactoryDate());
                tablet.addValue("shift_index", i, state.getShiftIndex());
                tablet.addValue("shift_time_type", i, state.getShiftTimeType());
                tablet.addValue("wcs", i, state.getWcs());
                tablet.addValue("rps", i, state.getRps());
                tablet.addValue("is_fix_point", i, state.getIsFixPoint());
                tablet.addValue("is_sync", i, state.getIsSync());
                tablet.addValue("is_plan", i, state.getIsPlan());
                tablet.addValue("feedback_point_type", i, state.getFeedbackPointType());
                tablet.addValue("feedback_id", i, state.getFeedbackId());
                tablet.addValue("is_deleted", i, state.getIsDeleted());
                tablet.addValue("employee_id", i, state.getEmployeeId());
            }
            try {
                //每个工位批量插入一次数据
                this.iotdbConfig.getSessionPool().insertAlignedTablet(tablet);
            } catch (Exception e) {
                log.error("保存固定点数据异常",e);
            }
        }
    }
}
collect/src/main/java/com/qianwen/mdc/collect/service/IOTMqttReceiveService.java
@@ -27,12 +27,12 @@
    @Autowired
    private  RedisUtil redisUtil;
    /**
     * å¤„理收到的消息
     * å¤„理收到的消息,对应TelemetryDataPostingConsumer
     * @param payload
     */
    public void handle(String payload) {
        //System.out.println("Received message122: " + payload);
        //解析消息未
        //解析消息
        List<TelemetryData> teleList = parsePayload(payload);
        
        collectDataService.handleCollectData(teleList);
@@ -86,10 +86,15 @@
        return dtList;
    }
    
    /**
     * æ ¹æ®å¯¹åº”表缓存,获取appId对应的id
     * @param appId
     * @return
     */
    public long getWorkstationIdByAppId(String appId) {
        Object wid = redisUtil.hget("workstation-appid-map", appId);
        String workstationId = String.valueOf(Optional.ofNullable(wid).orElse("-1"));
        String workstationId = String.valueOf(Optional.ofNullable(wid).orElse(appId));
    
        return Long.parseLong(workstationId);
    }
collect/src/main/java/com/qianwen/mdc/collect/service/PackedDataService.java
@@ -1,31 +1,35 @@
package com.qianwen.mdc.collect.service;
import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
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.qianwen.mdc.collect.config.IotDBSessionConfig;
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 cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
/**
 * é‡‡é›†æ•°æ®å¡«å……,聚合和入库
@@ -34,16 +38,16 @@
public class PackedDataService {
    private static final Logger log = LoggerFactory.getLogger(PackedDataService.class);
    private String DB_PREFIX = "root.f2.";
    private static final Map<Integer, String> PROCESS_PARAM_MAP = new HashMap<>();
    @Autowired
    private IotDBSessionConfig iotdbConfig;
    @Autowired
    private IotDBCommonService iotDBCommonService;
    @Autowired
    private PackedTelemetryDataHandlerSelector handlerSelector;
    
    private static String TEMPLATE_NAME = "process_param";
    @Autowired
    private WorkstationCache workstationCache;
    @Autowired
    private TimeSliceCache timeSliceCache;
    //private static String TEMPLATE_NAME = "process_param";
    static {
        PROCESS_PARAM_MAP.put(1, "STATE");
@@ -114,16 +118,56 @@
    void fillByCalendar(PackedTelemetryData pdata) {
        //原来在TelemetryPropertyWrapper.packWorkstationCalendarInfo中完成
        //FIXME: å¡«å†™å®žé™…的数据还需要后续处理
        pdata.setCalendarCode("1");//临时,目前库内都是1
        Date collectTime = new Date(pdata.getTime());
        String calendarCode = workstationCache.getWorkstationCalendarCodeForDate(pdata.getWorkstationId(), DateUtil.formatDate(DateUtil.date(collectTime)));
        if (ObjectUtil.isNotEmpty(calendarCode)) {
            pdata.setCalendarCode(calendarCode);
            //telemetryData.setCalendarCode(calendarCode);
        } else {
            //telemetryData.setCalendarCode("#default#");
            pdata.setCalendarCode("#default#");
        }
        pdata.setShiftIndex(1);//临时
        pdata.setShiftTimeType(1);//临时
        
        // TelemetryPropertyWrapper中packWorkstationCalendarInfo
        Date collectTime = new Date(pdata.getTime());
        //------------start
        Boolean isDefaultCalendar = true;
        if (!"#default#".equals(pdata.getCalendarCode())) {
            CalendarShiftTimeSlicesDTO calendarShiftTimeSlicesDTO = timeSliceCache.getTimeSliceShift(pdata.getCalendarCode(), collectTime);//从redis中获得日历的时间切片
            if (ObjectUtil.isEmpty(calendarShiftTimeSlicesDTO)) {//如果没有时间切片,则使用TimeSliceCache.build(cacheBuildDTO);构建
                LocalDate targetDate = Instant.ofEpochMilli(pdata.getTime()).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(pdata.getCalendarCode(), collectTime);
            }
            if (ObjectUtil.isNotEmpty(calendarShiftTimeSlicesDTO)) {
                pdata.setShiftIndex(calendarShiftTimeSlicesDTO.getShiftIndex()).setShiftTimeType(Integer.valueOf(calendarShiftTimeSlicesDTO.getShiftTimeType())).setFactoryDate(Integer.valueOf(calendarShiftTimeSlicesDTO.getFactoryDate().replaceAll("-", ""))).setFactoryWeek(calendarShiftTimeSlicesDTO.getFactoryWeek()).setFactoryMonth(calendarShiftTimeSlicesDTO.getFactoryMonth()).setFactoryYear(calendarShiftTimeSlicesDTO.getFactoryYear());
                isDefaultCalendar = false;
            }
        }
        //无日历切片,使用采集时间填充factoryYear,month,date,week几个属性
        if (isDefaultCalendar.booleanValue()) {
            log.info("无日历切片");
            LocalDate localDate = Instant.ofEpochMilli(pdata.getTime().longValue()).atZone(ZoneOffset.systemDefault()).toLocalDate();
            pdata.setFactoryDate(Integer.valueOf(DatePattern.PURE_DATE_FORMAT.format(collectTime)))
            .setFactoryYear(DateUtil.year(collectTime))
            .setFactoryWeek(LocalDateTimeUtils.getWeek(localDate))
            .setFactoryMonth(DateUtil.month(collectTime) + 1)
            .setShiftIndex(CommonConstant.DEFAULT_SHIFT_INDEX)
            .setShiftTimeType(CommonConstant.DEFAULT_SHIFT_TYPE);
        }
        //----------------------end
        /*
        LocalDate localDate = Instant.ofEpochMilli(pdata.getTime()).atZone(ZoneOffset.systemDefault()).toLocalDate();
        String PURE_DATE_PATTERN = "yyyyMMdd";
        /** æ ‡å‡†æ—¥æœŸæ ¼å¼ {@link FastDateFormat}:yyyyMMdd */
        FastDateFormat PURE_DATE_FORMAT = FastDateFormat.getInstance(PURE_DATE_PATTERN);
        WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1);
@@ -131,44 +175,7 @@
        pdata.setFactoryYear(localDate.getYear()).setFactoryMonth(localDate.getMonthValue())
                .setFactoryDate(Integer.valueOf(PURE_DATE_FORMAT.format(collectTime)))
                .setFactoryWeek(localDate.get(weekFields.weekOfYear()));
        */
    }
    void handleOneWorkstationXX(TelemetryData dt) {
        String deviceId = DB_PREFIX + TEMPLATE_NAME + "_" + dt.getWorkstationId();
        // æŒ‚载模板
        iotDBCommonService.setTemmplateIfNotSet(TEMPLATE_NAME, deviceId);
        List<MeasurementSchema> schemas = new ArrayList<>();
        schemas.add(new MeasurementSchema("workstation_id", TSDataType.INT64));
        schemas.add(new MeasurementSchema("n", TSDataType.TEXT));
        schemas.add(new MeasurementSchema("v", TSDataType.TEXT));
        Tablet tablet = new Tablet(deviceId, schemas);
        int rowIndex = 0;
        for (TelemetryDataItem dataItem : dt.getDataItems()) {
            for (Map<String, String> point : dataItem.getDataPoints()) {
                String[] keys = point.keySet().toArray(new String[0]);
                for (int i = 0; i < keys.length; i++) {
                    rowIndex = tablet.rowSize++;
                    tablet.addTimestamp(rowIndex, dataItem.getTime());
                    tablet.addValue("workstation_id", rowIndex, new Long(dt.getWorkstationId()));
                    tablet.addValue("n", rowIndex, keys[i]);
                    tablet.addValue("v", rowIndex, point.get(keys[i]));
                }
            }
            try {
                iotdbConfig.getSessionPool().insertAlignedTablet(tablet);
            } catch (Exception e) {
                log.error("IODDB入库失败", e);
                e.printStackTrace();
            }
        }
    }
}
collect/src/main/java/com/qianwen/mdc/collect/utils/CommonUtil.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,49 @@
package com.qianwen.mdc.collect.utils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
//import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
//import org.apache.rocketmq.common.UtilAll;
import com.qianwen.core.tool.utils.StringUtil;
public class CommonUtil {
    /*
    public static String changeInstanceNameToPID(DefaultMQPushConsumer consumer) {
        String instanceName = consumer.getInstanceName();
        if (consumer.getInstanceName().equals("DEFAULT")) {
            instanceName = UtilAll.getPid() + "#" + System.nanoTime();
        }
        return instanceName;
    }
    */
    public static String getReallyCacheName(String cacheName, String keyPrefix, String key) {
        return cacheName.concat("::").concat(keyPrefix).concat(key);
    }
    public static String getReallyCacheName(String cacheName, String keyPrefix, String key, Object... args) {
        return StringUtil.format(cacheName.concat("::").concat(keyPrefix).concat(key), args);
    }
    /*
    public static Map<String, List> groupList(List list, int size) {
        int listSize = list.size();
        int index = size;
        int keyToken = 0;
        Map map = new HashMap();
        int i = 0;
        while (true) {
            int i2 = i;
            if (i2 < list.size()) {
                if (i2 + size > listSize) {
                    index = listSize - i2;
                }
                List newList = list.subList(i2, i2 + index);
                map.put("keyName" + keyToken, newList);
                keyToken++;
                i = i2 + size;
            } else {
                return map;
            }
        }
    }*/
}
collect/src/main/java/com/qianwen/mdc/collect/utils/FeedbackAnalyseUtils.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,355 @@
package com.qianwen.mdc.collect.utils;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.lang.invoke.SerializedLambda;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qianwen.core.tool.utils.BeanUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.mdc.collect.entity.iotdb.DeviceState;
import com.qianwen.mdc.collect.enums.FeedbackTimePointEnum;
import com.qianwen.mdc.collect.mapper.iotdb.DeviceStateMapper;
public class FeedbackAnalyseUtils {
    private static final Logger log = LoggerFactory.getLogger(FeedbackAnalyseUtils.class);
    /*
    public static List<WorkstationFeedbackTimeQuantumDTO> getRelatedFeedbackTimeQuantumInfo(List<WorkstationFeedbackViewDTO> workstationFeedbackViewList) {
        List<WorkstationFeedbackTimeQuantumDTO> result = new ArrayList<>();
        if (Func.isNotEmpty(workstationFeedbackViewList)) {
            workstationFeedbackViewList.forEach(item -> {
                WorkstationFeedbackTimeQuantumDTO temp = new WorkstationFeedbackTimeQuantumDTO();
                temp.setFeedbackId(item.getWorkstationWcsFeedback().getId());
                temp.setFeedbackTime(item.getWorkstationWcsFeedback().getFeedbackTime());
                temp.setWcs(item.getWorkstationWcsFeedback().getWcs());
                if (Func.isNotEmpty(item.getWorkstationWcsFeedbackDetails())) {
                    item.getWorkstationWcsFeedbackDetails().forEach(detail -> {
                        WorkstationFeedbackTimeQuantumDTO tempTime = (WorkstationFeedbackTimeQuantumDTO) BeanUtil.copyProperties(temp, WorkstationFeedbackTimeQuantumDTO.class);
                        tempTime.setStartTime(detail.getStartTime());
                        tempTime.setFeedbackDetailId(detail.getId());
                        tempTime.setEndTime(detail.getEndTime());
                        result.add(tempTime);
                    });
                } else if (!item.getIsDeleted().booleanValue()) {
                    temp.setStartTime(item.getWorkstationWcsFeedback().getStartTime());
                    temp.setEndTime(item.getWorkstationWcsFeedback().getEndTime());
                    result.add(temp);
                }
            });
        }
        return result;
    }
    // JADX WARN: Multi-variable type inference failed
    public static List<WorkstationFeedbackTimePointDTO> buildFeedbackTimePointInfo(List<WorkstationFeedbackTimeQuantumDTO> feedbackTimeQuantumDTOList) {
        List<WorkstationFeedbackTimePointDTO> result = new ArrayList<>();
        List<WorkstationFeedbackTimePointDTO> remove = new ArrayList<>();
        if (Func.isNotEmpty(feedbackTimeQuantumDTOList)) {
            for (int i = 0; i < feedbackTimeQuantumDTOList.size(); i++) {
                WorkstationFeedbackTimeQuantumDTO x = feedbackTimeQuantumDTOList.get(i);
                WorkstationFeedbackTimePointDTO startTimePoint = new WorkstationFeedbackTimePointDTO().setFeedbackId(x.getFeedbackId()).setReportTime(x.getFeedbackTime()).setFeedbackDetailId(x.getFeedbackDetailId()).setFeedbackTime(x.getStartTime()).setWcs(x.getWcs());
                WorkstationFeedbackTimePointDTO endTimePoint = new WorkstationFeedbackTimePointDTO().setFeedbackId(x.getFeedbackId()).setReportTime(x.getFeedbackTime()).setFeedbackTime(x.getEndTime()).setFeedbackDetailId(x.getFeedbackDetailId()).setWcs(x.getWcs());
                result.add(startTimePoint);
                result.add(endTimePoint);
            }
        }
        if (Func.isNotEmpty(result)) {
            result = (List) result.stream().sorted(Comparator.comparing((v0) -> {
                return v0.getReportTime();
            }).thenComparing((v0) -> {
                return v0.getFeedbackTime();
            })).collect(Collectors.toList());
        }
        for (int i2 = 0; i2 < result.size(); i2++) {
            result.get(i2).setIndex(Integer.valueOf(i2));
        }
        getCrossFeedbackTimePoints(result);
        List<WorkstationFeedbackTimePointDTO> finalResult = getEffectFeedbackTimePoints(result, remove);
        return fixFeedbackTimePointInfo(feedbackTimeQuantumDTOList, buildFeedbackTimePointsCompleteInfo(finalResult, remove));
    }
    private static List<WorkstationFeedbackTimePointDTO> fixFeedbackTimePointInfo(List<WorkstationFeedbackTimeQuantumDTO> feedbackTimeQuantumDTOList, List<WorkstationFeedbackTimePointDTO> finalResult) {
        List<WorkstationFeedbackTimePointDTO> result = new ArrayList<>();
        List<WorkstationFeedbackTimePointDTO> finallyResult = new ArrayList<>();
        new ArrayList();
        List<WorkstationFeedbackTimeQuantumDTO> effectFeedbackTimeQuantumList = (List) feedbackTimeQuantumDTOList.stream().sorted(Comparator.comparing((v0) -> {
            return v0.getFeedbackTime();
        }).thenComparing((v0) -> {
            return v0.getStartTime();
        }).reversed()).collect(Collectors.toList());
        for (WorkstationFeedbackTimePointDTO item : finalResult) {
            if (FeedbackTimePointEnum.CROSS_POINT.isEqual(item.getPointEnum().getValue())) {
                WorkstationFeedbackTimeQuantumDTO matchDto = effectFeedbackTimeQuantumList.stream().filter(x -> {
                    return x.getStartTime().getTime() <= item.getFeedbackTime().getTime() && x.getEndTime().getTime() > item.getFeedbackTime().getTime();
                }).findFirst().orElse(null);
                if (Func.isNotEmpty(matchDto)) {
                    WorkstationFeedbackTimePointDTO tempTime = (WorkstationFeedbackTimePointDTO) BeanUtil.copyProperties(item, WorkstationFeedbackTimePointDTO.class);
                    tempTime.setFeedbackId(matchDto.getFeedbackId());
                    tempTime.setFeedbackDetailId(matchDto.getFeedbackDetailId());
                    tempTime.setWcs(matchDto.getWcs());
                    result.add(tempTime);
                }
            } else {
                result.add(item);
            }
        }
        for (int i = 0; i < result.size(); i++) {
            WorkstationFeedbackTimePointDTO temp = result.get(i);
            if (FeedbackTimePointEnum.CROSS_POINT.isEqual(temp.getPointEnum().getValue()) && FeedbackTimePointEnum.END_POINT.isEqual(result.get(i + 1).getPointEnum().getValue())) {
                temp.setWcs(result.get(i + 1).getWcs());
                temp.setFeedbackId(result.get(i + 1).getFeedbackId());
            }
            finallyResult.add(temp);
        }
        return finallyResult;
    }
    private static void getCrossFeedbackTimePoints(List<WorkstationFeedbackTimePointDTO> timePointList) {
        new ArrayList();
        if (Func.isNotEmpty(timePointList)) {
            for (WorkstationFeedbackTimePointDTO item : timePointList) {
                WorkstationFeedbackTimePointDTO start = timePointList.stream().filter(x -> {
                    return x.getFeedbackTime().getTime() < item.getFeedbackTime().getTime() && x.getIndex().intValue() < item.getIndex().intValue() && !x.getFeedbackId().equals(item.getFeedbackId());
                }).max(Comparator.comparing((v0) -> {
                    return v0.getIndex();
                })).orElse(null);
                WorkstationFeedbackTimePointDTO end = timePointList.stream().filter(x2 -> {
                    return x2.getFeedbackTime().getTime() > item.getFeedbackTime().getTime() && x2.getIndex().intValue() < item.getIndex().intValue() && !x2.getFeedbackId().equals(item.getFeedbackId());
                }).min(Comparator.comparing((v0) -> {
                    return v0.getIndex();
                })).orElse(null);
                if (Func.isNotEmpty(start) && Func.isNotEmpty(end) && start.getFeedbackId().equals(end.getFeedbackId())) {
                    item.setPointEnum(FeedbackTimePointEnum.CROSS_POINT);
                }
            }
        }
    }
    private static List<WorkstationFeedbackTimePointDTO> buildFeedbackTimePointsCompleteInfo(List<WorkstationFeedbackTimePointDTO> effectFeedbackList, List<WorkstationFeedbackTimePointDTO> removeList) {
        new ArrayList();
        if (Func.isNotEmpty(effectFeedbackList)) {
            effectFeedbackList = (List) effectFeedbackList.stream().sorted(Comparator.comparing((v0) -> {
                return v0.getFeedbackTime();
            })).collect(Collectors.toList());
            for (int i = 0; i < effectFeedbackList.size(); i++) {
                if (i == 0) {
                    effectFeedbackList.get(0).setPointEnum(FeedbackTimePointEnum.START_POINT);
                } else if (i == effectFeedbackList.size() - 1) {
                    effectFeedbackList.get(i).setPointEnum(FeedbackTimePointEnum.END_POINT);
                } else {
                    WorkstationFeedbackTimePointDTO prePoint = effectFeedbackList.get(i - 1);
                    WorkstationFeedbackTimePointDTO currentPoint = effectFeedbackList.get(i);
                    WorkstationFeedbackTimePointDTO start = effectFeedbackList.stream().filter(x -> {
                        return x.getFeedbackTime().getTime() < currentPoint.getFeedbackTime().getTime() && !x.getFeedbackId().equals(currentPoint.getFeedbackId());
                    }).max(Comparator.comparing((v0) -> {
                        return v0.getFeedbackTime();
                    })).orElse(null);
                    WorkstationFeedbackTimePointDTO end = effectFeedbackList.stream().filter(x2 -> {
                        return x2.getFeedbackTime().getTime() > currentPoint.getFeedbackTime().getTime() && !x2.getFeedbackId().equals(currentPoint.getFeedbackId());
                    }).min(Comparator.comparing((v0) -> {
                        return v0.getFeedbackTime();
                    })).orElse(null);
                    if (Func.isNotEmpty(start) && Func.isNotEmpty(end) && start.getFeedbackId().equals(end.getFeedbackId())) {
                        currentPoint.setPointEnum(FeedbackTimePointEnum.CROSS_POINT);
                    }
                    if (checkIsCrossFeedbackTimePoint(currentPoint, effectFeedbackList, removeList)) {
                        currentPoint.setPointEnum(FeedbackTimePointEnum.CROSS_POINT);
                    }
                    if (!Func.isNotEmpty(currentPoint.getPointEnum())) {
                        if (Func.isNotEmpty(prePoint.getPointEnum()) && FeedbackTimePointEnum.CROSS_POINT.isEqual(prePoint.getPointEnum().getValue())) {
                            effectFeedbackList.get(i).setPointEnum(FeedbackTimePointEnum.END_POINT);
                        }
                        if (prePoint.getFeedbackId().equals(currentPoint.getFeedbackId())) {
                            effectFeedbackList.get(i).setPointEnum(FeedbackTimePointEnum.END_POINT);
                        } else {
                            if (prePoint.getPointEnum().isEqual(FeedbackTimePointEnum.START_POINT.getValue())) {
                                effectFeedbackList.get(i).setPointEnum(FeedbackTimePointEnum.CROSS_POINT);
                            }
                            if (prePoint.getPointEnum().isEqual(FeedbackTimePointEnum.END_POINT.getValue())) {
                                effectFeedbackList.get(i).setPointEnum(FeedbackTimePointEnum.START_POINT);
                            }
                        }
                    }
                }
            }
        }
        return effectFeedbackList;
    }
    private static List<WorkstationFeedbackTimePointDTO> getEffectFeedbackTimePoints(List<WorkstationFeedbackTimePointDTO> originalPointsList, List<WorkstationFeedbackTimePointDTO> removeList) {
        List<WorkstationFeedbackTimePointDTO> result = new ArrayList<>();
        for (WorkstationFeedbackTimePointDTO item : originalPointsList) {
            if (checkIsKeepFeedbackTimePoint(item, originalPointsList)) {
                result.add(item);
            } else {
                removeList.add(item);
            }
        }
        return result;
    }
    private static boolean checkIsKeepFeedbackTimePoint(WorkstationFeedbackTimePointDTO pointDTO, List<WorkstationFeedbackTimePointDTO> originalPointsList) {
        long min = originalPointsList.stream().filter(x -> {
            return x.getIndex().intValue() > pointDTO.getIndex().intValue() && x.getFeedbackTime().getTime() <= pointDTO.getFeedbackTime().getTime();
        }).count();
        if (min <= 0) {
            return true;
        }
        long max = originalPointsList.stream().filter(x2 -> {
            return x2.getIndex().intValue() > pointDTO.getIndex().intValue() && x2.getFeedbackTime().getTime() >= pointDTO.getFeedbackTime().getTime();
        }).count();
        if (max <= 0) {
            return true;
        }
        return false;
    }
    private static boolean checkIsCrossFeedbackTimePoint(WorkstationFeedbackTimePointDTO pointDTO, List<WorkstationFeedbackTimePointDTO> originalPointsList, List<WorkstationFeedbackTimePointDTO> removeList) {
        WorkstationFeedbackTimePointDTO exits;
        List<WorkstationFeedbackTimePointDTO> minList = (List) originalPointsList.stream().filter(x -> {
            return x.getFeedbackTime().getTime() < pointDTO.getFeedbackTime().getTime();
        }).collect(Collectors.toList());
        if (Func.isEmpty(minList)) {
            return false;
        }
        List<WorkstationFeedbackTimePointDTO> maxList = (List) originalPointsList.stream().filter(x2 -> {
            return x2.getFeedbackTime().getTime() > pointDTO.getFeedbackTime().getTime();
        }).collect(Collectors.toList());
        if (Func.isEmpty(maxList)) {
            return false;
        }
        for (WorkstationFeedbackTimePointDTO item : minList) {
            WorkstationFeedbackTimePointDTO exits2 = maxList.stream().filter(x3 -> {
                return x3.getFeedbackId().equals(item.getFeedbackId());
            }).findAny().orElse(null);
            if (Func.isNotEmpty(exits2)) {
                return true;
            }
        }
        for (WorkstationFeedbackTimePointDTO item2 : maxList) {
            if (Func.isNotEmpty(item2.getFeedbackDetailId())) {
                exits = removeList.stream().filter(x4 -> {
                    return Func.isNotEmpty(x4.getFeedbackDetailId()) && x4.getFeedbackDetailId().equals(item2.getFeedbackDetailId()) && x4.getFeedbackTime().getTime() <= pointDTO.getFeedbackTime().getTime();
                }).findAny().orElse(null);
            } else {
                exits = removeList.stream().filter(x5 -> {
                    return x5.getFeedbackId().equals(item2.getFeedbackId()) && x5.getFeedbackTime().getTime() <= pointDTO.getFeedbackTime().getTime();
                }).findAny().orElse(null);
            }
            if (Func.isNotEmpty(exits)) {
                return true;
            }
        }
        return false;
    }
    public static List<WorkstationFeedbackTimeQuantumDTO> buildFeedbackTimeQuantum(List<WorkstationFeedbackTimePointDTO> effectFeedbackList) {
        List<WorkstationFeedbackTimeQuantumDTO> result = new ArrayList<>();
        List<WorkstationFeedbackTimePointDTO> effectFeedbackList2 = (List) effectFeedbackList.stream().sorted(Comparator.comparing((v0) -> {
            return v0.getFeedbackTime();
        })).collect(Collectors.toList());
        for (int i = 0; i < effectFeedbackList2.size() - 1; i++) {
            WorkstationFeedbackTimePointDTO currentFeedbackPoint = effectFeedbackList2.get(i);
            if (FeedbackTimePointEnum.END_POINT.isEqual(currentFeedbackPoint.getPointEnum().getValue())) {
                break;
            }
            WorkstationFeedbackTimePointDTO nextFeedbackPoint = effectFeedbackList2.get(i + 1);
            WorkstationFeedbackTimeQuantumDTO tempFeedback = new WorkstationFeedbackTimeQuantumDTO();
            tempFeedback.setFeedbackId(currentFeedbackPoint.getFeedbackId());
            tempFeedback.setStartTime(currentFeedbackPoint.getFeedbackTime());
            tempFeedback.setEndTime(nextFeedbackPoint.getFeedbackTime());
            tempFeedback.setWcs(currentFeedbackPoint.getWcs());
            result.add(tempFeedback);
        }
        return result;
    }
    public static Long getStartFeedbackTimePoint(Long workstationId, WorkstationStateMapper stateMapper, List<WorkstationState> processingStateList) {
        if (Func.isNotEmpty(processingStateList)) {
            //未同步反馈点的最早一条数据
            Long startTime = processingStateList.stream().sorted(Comparator.comparing(WorkstationState::getTs)).collect(Collectors.toList()).get(0).getTs();//最早一条的ts
            //查询在反馈点之前一条已同步的数据(小于startTime的最后一条、已同步,IsFixPoint=false的数据)
            WorkstationState startNoFixpoint = stateMapper.getLastWorkstationState(Wrappers.<WorkstationState>lambdaQuery()
                    .eq(WorkstationState::getWorkstationId, workstationId)
                    .lt(WorkstationState::getTs, startTime)
                    .eq(WorkstationState::getIsSync, Boolean.TRUE)
                    .eq(WorkstationState::getIsFixPoint, Boolean.FALSE)
                    .ne(WorkstationState::getIsDeleted, Boolean.TRUE));
            if (Func.isNotEmpty(startNoFixpoint)) {
                startTime = startNoFixpoint.getTs();
            }
            return startTime;
        }
        return null;
    }
    */
    /**
     *
     * @param workstationId
     * @param stateMapper
     * @param processingStateList æœªåŒæ­¥åé¦ˆç‚¹é›†åˆ
     * @return
     */
    /*
    public static Long getEndFeedbackTimePoint(Long workstationId, WorkstationStateMapper stateMapper, List<WorkstationState> processingStateList) {
        Long result = null;
        if (Func.isNotEmpty(processingStateList)) {
            List<WorkstationState> processingStateList2 = processingStateList.stream().sorted(Comparator.comparing(WorkstationState::getTs)).collect(Collectors.toList());
            WorkstationState endTimePoint = processingStateList2.get(processingStateList2.size() - 1);//最晚的一条时间
            if (FeedbackTimePointEnum.END_POINT.isEqual(endTimePoint.getFeedbackPointType())) {//如果该反馈点是结束时间,则查找 ç¬¬ä¸€ä¸ª æ—¶é—´æ™šäºŽè¯¥åé¦ˆç‚¹çš„已同步状态点
                WorkstationState endNoFixPoint = stateMapper.getFirstWorkstationState(Wrappers.<WorkstationState>lambdaQuery()
                        .eq(WorkstationState::getWorkstationId, workstationId).
                        gt(WorkstationState::getTs, endTimePoint.getTs())
                        .eq(WorkstationState::getIsSync, Boolean.TRUE)
                        .eq(WorkstationState::getIsFixPoint, Boolean.FALSE)
                        .ne(WorkstationState::getIsDeleted, Boolean.TRUE));
                if (Func.isNotEmpty(endNoFixPoint)) {
                    result = endNoFixPoint.getTs();
                }
            }
        }
        return result;
    }
    */
    /**
     * èŽ·å¾—æœ€åŽä¸€ä¸ªå·²åŒæ­¥éžåé¦ˆç‚¹çš„æ—¶é—´ï¼Œæˆ–è€…æœ€æ—©ä¸€ä¸ªæœªåŒæ­¥éžåé¦ˆç‚¹æ—¶é—´
     * @param workstationId
     * @param stateMapper
     * @return
     */
    public static Long getNormalStartTimePoint(Long workstationId, DeviceStateMapper stateMapper) {
        //isFixPoint å¿…须是false
        //获取isSync=true,NO_FEED_BACK_POINT的状态数据
        /*
        DeviceState resultTimePoint = stateMapper.getLastWorkstationState( Wrappers.<DeviceState>lambdaQuery()
                .eq(DeviceState::getWorkstationId, workstationId).eq(DeviceState::getIsSync, Boolean.TRUE).eq(DeviceState::getIsFixPoint, Boolean.FALSE)
                .eq(DeviceState::getFeedbackPointType, FeedbackTimePointEnum.NO_FEED_BACK_POINT.getValue()).ne(DeviceState::getIsDeleted, Boolean.TRUE));
                */
        DeviceState resultTimePoint = stateMapper.lastSyncedNoFeedbackPointState(workstationId);
        if (Func.isEmpty(resultTimePoint)) {
            //获取isSync=false,fixpoint=false,NO_FEED_BACK_POINT的数据
            /*
            resultTimePoint = stateMapper.getFirstWorkstationState(Wrappers.<DeviceState>lambdaQuery().eq(DeviceState::getWorkstationId, workstationId)
                    .eq(DeviceState::getIsSync, Boolean.FALSE)
                    .eq(DeviceState::getIsFixPoint, Boolean.FALSE)
                    .eq(DeviceState::getFeedbackPointType, FeedbackTimePointEnum.NO_FEED_BACK_POINT.getValue())
                    .ne(DeviceState::getIsDeleted, Boolean.TRUE));
                    */
            resultTimePoint = stateMapper.firstNotSyncedNofeedbackPointState(workstationId);
        }
        if (Func.isNotEmpty(resultTimePoint)) {
            return resultTimePoint.getTime();
        }
        return null;
    }
}
collect/src/main/java/com/qianwen/mdc/collect/utils/WorkstationStateAggregateNoFeedbackUtils.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,149 @@
package com.qianwen.mdc.collect.utils;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qianwen.core.tool.utils.BeanUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.mdc.collect.entity.iotdb.AggregateState;
import com.qianwen.mdc.collect.entity.iotdb.DeviceState;
import com.qianwen.mdc.collect.enums.FeedbackTimePointEnum;
/**
 * æ— åé¦ˆå¾—状态聚合 util
 *
 */
public class WorkstationStateAggregateNoFeedbackUtils {
    private static final Logger log = LoggerFactory.getLogger(WorkstationStateAggregateNoFeedbackUtils.class);
    public static List<AggregateState> buildAggregateList(List<DeviceState> notSyncWorkstationStates) {
        List<AggregateState> workstationAggregateStateList = new ArrayList<>();
        List<DeviceState> notSyncWorkstationStates2 = rebuildNotSyncWorkstationStates(notSyncWorkstationStates);
        if (Func.isNotEmpty(notSyncWorkstationStates2)) {
            int resultCount = notSyncWorkstationStates2.size();
            for (int i = 0; i < notSyncWorkstationStates2.size() - 1; i++) {
                DeviceState current = notSyncWorkstationStates2.get(i);
                DeviceState nextState = notSyncWorkstationStates2.get(i + 1);
                //使用ts的差,构建durationCollect,其余使用current的属性
                AggregateState aggState =new AggregateState();
                //workstationAggregateStateList.add(AggregateState.builder().ts(current.getTs()).workstationId(current.getWorkstationId()).isDeleted(Boolean.FALSE).valueCollect(current.getValueCollect()).rps(current.getRps()).wcs(current.getWcs()).isPlan(current.getIsPlan()).shiftIndex(current.getShiftIndex()).shiftTimeType(current.getShiftTimeType()).calendarCode(current.getCalendarCode()).factoryDate(current.getFactoryDate()).factoryMonth(current.getFactoryMonth()).factoryWeek(current.getFactoryWeek()).factoryYear(current.getFactoryYear()).durationCollect(Long.valueOf(TimeUnit.MILLISECONDS.toSeconds(nextState.getTs().longValue() - current.getTs().longValue()))).employeeId(current.getEmployeeId()).endTime(nextState.getTs()).build());
                aggState.setTime(current.getTime());
                aggState.setWorkstationId(current.getWorkstationId());
                aggState.setIsDeleted(false);
                aggState.setValueCollect(current.getValueCollect());
                aggState.setRps(current.getRps());
                aggState.setWcs(current.getWcs());
                aggState.setIsPlan(current.getIsPlan());
                aggState.setShiftIndex(current.getShiftIndex());
                aggState.setShiftTimeType(current.getShiftTimeType());
                aggState.setCalendarCode(current.getCalendarCode());
                aggState.setFactoryDate(current.getFactoryDate());
                aggState.setFactoryMonth(current.getFactoryMonth());
                aggState.setFactoryWeek(current.getFactoryWeek());
                aggState.setFactoryYear(current.getFactoryYear());
                aggState.setDurationCollect(Long.valueOf(TimeUnit.MILLISECONDS.toSeconds(nextState.getTime().longValue() - current.getTime().longValue())));
                aggState.setEmployeeId(current.getEmployeeId());
                aggState.setEndTime(nextState.getTime());
                workstationAggregateStateList.add(aggState);
            }
            //构建最后一条,无durationCollect
            DeviceState lastNoSyncWorkstationState = notSyncWorkstationStates2.get(resultCount - 1);
            AggregateState lastAggState = new AggregateState();
            //workstationAggregateStateList.add(AggregateState.builder().ts(lastNoSyncWorkstationState.getTime()).workstationId(lastNoSyncWorkstationState.getWorkstationId()).isDeleted(Boolean.FALSE).valueCollect(lastNoSyncWorkstationState.getValueCollect()).rps(lastNoSyncWorkstationState.getRps()).wcs(lastNoSyncWorkstationState.getWcs()).isPlan(lastNoSyncWorkstationState.getIsPlan()).shiftIndex(lastNoSyncWorkstationState.getShiftIndex()).shiftTimeType(lastNoSyncWorkstationState.getShiftTimeType()).calendarCode(lastNoSyncWorkstationState.getCalendarCode()).factoryDate(lastNoSyncWorkstationState.getFactoryDate()).factoryMonth(lastNoSyncWorkstationState.getFactoryMonth()).factoryWeek(lastNoSyncWorkstationState.getFactoryWeek()).factoryYear(lastNoSyncWorkstationState.getFactoryYear()).employeeId(lastNoSyncWorkstationState.getEmployeeId()).build());
            lastAggState.setTime(lastNoSyncWorkstationState.getTime());
            lastAggState.setWorkstationId(lastNoSyncWorkstationState.getWorkstationId());
            lastAggState.setIsDeleted(false);
            lastAggState.setValueCollect(lastNoSyncWorkstationState.getValueCollect());
            lastAggState.setRps(lastNoSyncWorkstationState.getRps());
            lastAggState.setWcs(lastNoSyncWorkstationState.getWcs());
            lastAggState.setIsPlan(lastNoSyncWorkstationState.getIsPlan());
            lastAggState.setShiftIndex(lastNoSyncWorkstationState.getShiftIndex());
            lastAggState.setShiftTimeType(lastNoSyncWorkstationState.getShiftTimeType());
            lastAggState.setCalendarCode(lastNoSyncWorkstationState.getCalendarCode());
            lastAggState.setFactoryDate(lastNoSyncWorkstationState.getFactoryDate());
            lastAggState.setFactoryMonth(lastNoSyncWorkstationState.getFactoryMonth());
            lastAggState.setFactoryWeek(lastNoSyncWorkstationState.getFactoryWeek());
            lastAggState.setFactoryYear(lastNoSyncWorkstationState.getFactoryYear());
            lastAggState.setEmployeeId(lastNoSyncWorkstationState.getEmployeeId());
            workstationAggregateStateList.add(lastAggState);
        }
        return workstationAggregateStateList;
    }
    /**
     * é‡æ–°æž„建未同步状态列表数据
     * @param originalDeviceStates
     * @return
     */
    private static List<DeviceState> rebuildNotSyncWorkstationStates(List<DeviceState> originalDeviceStates) {
        List<DeviceState> stateList = new ArrayList<>();
        if (Func.isNotEmpty(originalDeviceStates)) {
            List<DeviceState> notSyncWorkstationStates = originalDeviceStates.stream().filter(x -> {
                //含义未选取fixpoint æˆ–者非反馈点,其他类型的采集数据不处理了,我们自己就不用过滤了,因为都是NO_FEED_BACK_POINT,且isFixPoint=false
                return Boolean.TRUE.equals(x.getIsFixPoint()) || x.getFeedbackPointType() == null || x.getFeedbackPointType().equals(FeedbackTimePointEnum.NO_FEED_BACK_POINT.getValue());
            }).map(x2 -> {
                //固定点,设置wcs,rps=0
                if (x2.getIsFixPoint().booleanValue()) {
                    x2.setWcs(0);
                    x2.setRps(0);
                    x2.setIsPlan(null);
                }
                return x2;
            }).collect(Collectors.toList()).stream().sorted(Comparator.comparing(DeviceState::getTime)).collect(Collectors.toList());
            notSyncWorkstationStates.forEach(x3 -> {
                if (x3.getIsFixPoint().booleanValue()) {
                    //是固定点,找出不晚于该固定点的最后一个点,加入stateList;如果没有找到,则将该固定点加入stateList
                    List<DeviceState> collect = notSyncWorkstationStates.stream().filter(y -> {
                        //在列表中找出时间不晚于(<=)该固定点(x3)的非固定点(为了获取最后一条的数据)
                        return !y.getIsFixPoint().booleanValue() && y.getTime().longValue() <= x3.getTime().longValue();
                    }).collect(Collectors.toList());
                    if (Func.isNotEmpty(collect)) {//除非之前没有过数据,否则这个条件(isNotEmpty)都成立
                        DeviceState temp = (DeviceState) BeanUtil.copy(x3, DeviceState.class);
                        temp.setValueCollect(collect.get(collect.size() - 1).getValueCollect());
                        temp.setWcs(collect.get(collect.size() - 1).getWcs());
                        temp.setRps(collect.get(collect.size() - 1).getRps());
                        temp.setIsPlan(collect.get(collect.size() - 1).getIsPlan());
                        stateList.add(temp);
                        return;
                    }
                    stateList.add(x3);
                    return;
                }
                //非固定点,直接加入列表
                stateList.add(x3);
            });
        }
        return stateList;
    }
    public static List<AggregateState> getReallyEffectWorkstationStateAggregateNoFeedbackList(List<AggregateState> insertData, List<AggregateState> deleteData) {
        HashMap<Long, AggregateState> workstationStateMap = new HashMap<>();
        if (Func.isNotEmpty(insertData)) {
            insertData.forEach(item -> {
                workstationStateMap.put(item.getTime(), item);
            });
        }
        if (Func.isNotEmpty(deleteData)) {
            for (AggregateState state : deleteData) {
                if (!workstationStateMap.containsKey(state.getTime())) {
                    workstationStateMap.put(state.getTime(), state);
                }
            }
        }
        return workstationStateMap.values().stream().collect(Collectors.toList());
    }
}
collect/src/main/java/com/qianwen/mdc/collect/utils/redis/RedisUtil.java
@@ -192,7 +192,7 @@
     * @param time æ—¶é—´(秒)
     * @return true成功 false失败
     */
    public boolean hmset(String key, Map<String,Object> map, long time){
    public boolean hmsetold(String key, Map<String,Object> map, long time){
        try {
            redisTemplate.opsForHash().putAll(key, map);
            if (time > 0) {
@@ -204,6 +204,19 @@
            return false;
        }
    }
    public boolean hmset(String key, Map<? extends Object, ? extends Object> map, long time){
        try {
            redisTemplate.opsForHash().putAll(key, map);
            if (time > 0) {
                expire(key, time);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * å‘一张hash表中放入数据,如果不存在将创建
collect/src/main/resources/application-dev.yml
@@ -43,9 +43,9 @@
#iotdb ä»¥åŠå…¶jdbc一起配置
iotdb:
  driver: org.apache.iotdb.jdbc.IoTDBDriver
  host: localhost
  host: 127.0.0.1
  port: 6667
  maxSize: 10
  maxSize: 300
  username: root
  password: root
collect/src/main/resources/application.yml
@@ -32,12 +32,12 @@
          type: com.zaxxer.hikari.HikariDataSource
          hikari:
            minimum-idle: 5
            maximum-pool-size: 15
            maximum-pool-size: 50
            auto-commit: true
            idle-timeout: 30000
            pool-name: DatebookHikariCP
            max-lifetime: 1800000
            connection-timeout: 30000
            connection-timeout: 10000
            connection-test-query: select count(*) from root.test
mybatis:
  configuration:
collect/src/main/resources/com/qianwen/mdc/collect/mapper/iotdb/DeviceStateMapper.xml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.qianwen.mdc.collect.mapper.iotdb.DeviceStateMapper">
    <resultMap id="BaseResultMap" type="com.qianwen.mdc.collect.entity.iotdb.DeviceState">
        <result column="workstation_id" jdbcType="BIGINT" property="workstationId"/>
        <result column="value_collect" jdbcType="BIGINT" property="valueCollect"/>
        <result column="param_type" jdbcType="INTEGER" property="paramType"/>
        <result column="calendar_code" jdbcType="VARCHAR" property="calendarCode"/>
        <result column="factory_year" jdbcType="INTEGER" property="factoryYear"/>
        <result column="factory_month" jdbcType="INTEGER" property="factoryMonth"/>
        <result column="factory_week" jdbcType="INTEGER" property="factoryWeek"/>
        <result column="factory_date" jdbcType="INTEGER" property="factoryDate"/>
        <result column="shift_index" jdbcType="INTEGER" property="shiftIndex"/>
        <result column="shift_time_type" jdbcType="INTEGER" property="shiftTimeType"/>
        <result column="wcs" jdbcType="INTEGER" property="wcs"/>
        <result column="rps" jdbcType="INTEGER" property="wcs"/>
        <result column="is_sync" jdbcType="BOOLEAN" property="isSync"/>
        <result column="feedback_id" jdbcType="BIGINT" property="feedbackId"/>
        <result column="is_deleted" jdbcType="BOOLEAN" property="isDeleted"/>
        <result column="employee_id" jdbcType="BIGINT" property="employeeId"/>
    </resultMap>
    <!--
    <select id="getProcessingFeedbackState" resultType="org.springblade.posting.entity.tdengine.WorkstationState"
            parameterType="java.lang.Long">
        select *  FROM iot_data.super_state  WHERE workstation_id = #{workstationId} AND is_deleted != true  AND is_sync = false AND feedback_point_type != 0
    </select>
    <insert id="insert" parameterType="org.springblade.posting.entity.tdengine.WorkstationState">
        insert into iot_data.state_${workstationId} USING iot_data.super_state TAGS (${workstationId})
        values (#{ts}, #{valueCollect}, #{calendarCode}, #{factoryYear}, #{factoryMonth}, #{factoryWeek}, #{factoryDate},
            #{shiftIndex}, #{shiftTimeType}, #{wcs}, #{rps},#{isFixPoint},#{isSync}, #{isPlan},#{feedbackPointType},#{feedbackId},#{isDeleted}, #{employeeId})
    </insert>
    <insert id="batchInsert" >
        insert into
        <foreach separator=" " collection="list" item="item" index="index" >
            iot_data.state_${item.workstationId} USING iot_data.super_state TAGS (${item.workstationId}) values
             (#{item.ts}, #{item.valueCollect},#{item.calendarCode}, #{item.factoryYear}, #{item.factoryMonth}, #{item.factoryWeek}, #{item.factoryDate},
            #{item.shiftIndex}, #{item.shiftTimeType}, #{item.wcs}, #{item.rps},#{item.isFixPoint}, #{item.isSync}, #{item.isPlan},#{item.feedbackPointType},#{item.feedbackId},#{item.isDeleted}, #{item.employeeId})
        </foreach>
    </insert>
    <insert id="batchSave">
        insert into iot_data.state_${workstationId} USING iot_data.super_state TAGS (${workstationId}) values
        <foreach separator="," collection="list" item="item" index="index" >
            (#{item.ts}, #{item.valueCollect},#{item.calendarCode}, #{item.factoryYear}, #{item.factoryMonth}, #{item.factoryWeek}, #{item.factoryDate},
            #{item.shiftIndex}, #{item.shiftTimeType}, #{item.wcs}, #{item.rps}, #{item.isFixPoint},
             #{item.isSync}, #{item.isPlan},#{item.feedbackPointType},#{item.feedbackId},#{item.isDeleted}, #{item.employeeId})
        </foreach>
    </insert>
    <select id="getLastIsSyncNoFixPointState"
            resultType="org.springblade.posting.entity.tdengine.WorkstationState">
        select LAST_ROW(*), workstation_Id FROM iot_data.super_state  WHERE workstation_id = #{workstationId} AND is_deleted != true  AND is_sync = true and is_fix_point=false
    </select>
    <select id="getFirstWorkstationState" resultType="org.springblade.posting.entity.tdengine.WorkstationState"
            parameterType="com.baomidou.mybatisplus.core.conditions.Wrapper">
        select First(*) FROM iot_data.super_state
            ${ew.customSqlSegment}
    </select>
    -->
    <sql id="all_columns">
    workstation_id,value_collect,calendar_code,factory_year,factory_month,factory_date,factory_week,shift_index,shift_time_type,wcs,rps,is_fix_point,is_sync,is_plan,feedback_point_type,feedback_id,is_deleted,employee_id
    </sql>
    <!--  resultType="com.qianwen.mdc.collect.entity.iotdb.DeviceState" -->
    <select id="lastSyncedNoFeedbackPointState" resultMap="BaseResultMap">
        select <include refid="all_columns" /> FROM root.f2.aggregate_state_${workstationId}
        where is_sync=true and is_fix_point=false and feedback_point_type=0 and is_deleted=false
        order by time desc limit 1
    </select>
    <select id="firstNotSyncedNofeedbackPointState" resultMap="BaseResultMap">
        select <include refid="all_columns" /> FROM root.f2.aggregate_state_${workstationId}
        where is_sync=false and is_fix_point=false and feedback_point_type=0 and is_deleted=false
        order by time asc limit 1
    </select>
     <select id="statesInTimeRange" resultMap="BaseResultMap">
        select <include refid="all_columns" /> FROM root.f2.aggregate_state_${workstationId}
        <where>
            is_deleted=false
            <if test="timeRange.startTime != null">
                AND time &gt;= #{timeRange.startTime}
            </if>
             AND time &lt;= #{timeRange.endTime}
        </where>
        order by time asc
    </select>
</mapper>