Browse Source

修改停机时间有负数的问题,增加日统计

wukai 4 months ago
parent
commit
e54a7c16dc

+ 19 - 9
jjt-admin/src/test/java/com/jjt/task/TaskTest.java

@@ -2,6 +2,7 @@ package com.jjt.task;
 
 import com.jjt.JjtApplication;
 import com.jjt.biz.service.IApiService;
+import com.jjt.calc.service.ITwinCalcDayService;
 import com.jjt.calc.service.ITwinCalcHourService;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -22,25 +23,34 @@ public class TaskTest {
     @Resource
     private IApiService apiService;
 
+    @Resource
+    private ITwinCalcHourService calcHourService;
+    @Resource
+    private ITwinCalcDayService dayService;
+
     @Test
     public void curr() {
         apiService.curr();
     }
 
-    @Resource
-    private ITwinCalcHourService calcHourService;
 
     @Test
     public void last() {
+
         String date = "2025-01-17";
-//        calcHourService.calc(date, 15);
+//        for (int i = 3; i < 6; i++) {
+//            calcHourService.calc("2025-01-18", i);
+//        }
+//        calcHourService.calc(date, 22);
         LocalDate localDate = LocalDate.parse(date);
-        LocalDateTime ldt = LocalDateTime.of(localDate, LocalTime.MIN);
-        ldt = ldt.plusHours(7);
-        for (int i = 0; i < 24; i++) {
-            ldt = ldt.plusHours(0);
-            calcHourService.calc(ldt.toLocalDate().toString(), ldt.getHour());
-        }
+        dayService.day(localDate);
+//        LocalDateTime ldt = LocalDateTime.of(localDate, LocalTime.MIN);
+//        ldt = ldt.plusHours(7);
+//        for (int i = 0; i < 24; i++) {
+//            LocalDateTime tt = ldt.plusHours(i);
+//            System.err.println(tt.toLocalDate().toString() + tt.getHour());
+//            calcHourService.calc(tt.toLocalDate().toString(), tt.getHour());
+//        }
 
 //        calcHourService.last();
     }

+ 271 - 42
jjt-biz/src/main/java/com/jjt/calc/domain/TwinCalcDay.java

@@ -1,16 +1,21 @@
 package com.jjt.calc.domain;
 
-import java.math.BigDecimal;
-import java.util.Date;
-import com.fasterxml.jackson.annotation.JsonFormat;
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.jjt.common.annotation.Excel;
+import com.jjt.common.core.domain.BaseEntity;
+import com.jjt.common.utils.DateUtils;
+import com.jjt.utils.Tools;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-import com.jjt.common.annotation.Excel;
-import com.jjt.common.core.domain.BaseEntity;
+import lombok.NoArgsConstructor;
+import org.apache.poi.ss.usermodel.Cell;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Date;
+import java.util.List;
 
 /**
  * 日统计数据对象 TWIN_CALC_DAY
@@ -20,160 +25,384 @@ import com.jjt.common.core.domain.BaseEntity;
  */
 @ApiModel(value = "TwinCalcDay", description = "日统计数据")
 @Data
-public class TwinCalcDay extends BaseEntity{
+@NoArgsConstructor
+public class TwinCalcDay extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
-    /** ID */
+    public TwinCalcDay(Date date) {
+        this.time = date;
+        this.length = BigDecimal.ZERO;
+        this.weight = BigDecimal.ZERO;
+        this.kwh = BigDecimal.ZERO;
+
+        this.lengthA = BigDecimal.ZERO;
+        this.weightA = BigDecimal.ZERO;
+        this.kwhA = BigDecimal.ZERO;
+
+        this.lengthB = BigDecimal.ZERO;
+        this.weightB = BigDecimal.ZERO;
+        this.kwhB = BigDecimal.ZERO;
+
+        this.alarm = 0L;
+        this.openTimeA = BigDecimal.ZERO;
+        this.openTimeB = BigDecimal.ZERO;
+        this.closeTimeA = BigDecimal.ZERO;
+        this.closeTimeB = BigDecimal.ZERO;
+        this.stop1A = 0L;
+        this.stop1B = 0L;
+        this.stop2A = 0L;
+        this.stop2B = 0L;
+        this.stop3A = 0L;
+        this.stop3B = 0L;
+
+        this.setEfficiencyA(BigDecimal.ZERO);
+        this.setEfficiencyB(BigDecimal.ZERO);
+    }
+
+    /**
+     * ID
+     */
     @ApiModelProperty("ID")
     @TableId
     private Long id;
 
-    /** 时间 */
+    /**
+     * 时间
+     */
     @ApiModelProperty("时间")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @Excel(name = "时间", width = 30, dateFormat = "yyyy-MM-dd")
     private Date time;
 
-    /** 设备ID */
+    /**
+     * 设备ID
+     */
     @ApiModelProperty("设备ID")
     @Excel(name = "设备ID")
     private Long deviceId;
 
-    /** 总米长 */
+    /**
+     * 总米长
+     */
     @ApiModelProperty("总米长")
     @Excel(name = "总米长")
     private BigDecimal length;
 
-    /** 总重量 */
+    /**
+     * 总重量
+     */
     @ApiModelProperty("总重量")
     @Excel(name = "总重量")
     private BigDecimal weight;
 
-    /** 稼动率 */
+    /**
+     * 稼动率
+     */
     @ApiModelProperty("稼动率")
     @Excel(name = "稼动率")
     private BigDecimal efficiency;
 
-    /** 总电量 */
+    /**
+     * 总电量
+     */
     @ApiModelProperty("总电量")
     @Excel(name = "总电量")
     private BigDecimal kwh;
 
-    /** 告警数量 */
+    /**
+     * 告警数量
+     */
     @ApiModelProperty("告警数量")
     @Excel(name = "告警数量")
     private Long alarm;
 
-    /** A班米长 */
+    /**
+     * A班米长
+     */
     @ApiModelProperty("A班米长")
     @Excel(name = "A班米长")
     private BigDecimal lengthA;
 
-    /** A班重量 */
+    /**
+     * A班重量
+     */
     @ApiModelProperty("A班重量")
     @Excel(name = "A班重量")
     private BigDecimal weightA;
 
-    /** A班稼动率 */
+    /**
+     * A班稼动率
+     */
     @ApiModelProperty("A班稼动率")
     @Excel(name = "A班稼动率")
     private BigDecimal efficiencyA;
 
-    /** A班开机时间 */
+    /**
+     * A班开机时间
+     */
     @ApiModelProperty("A班开机时间")
     @Excel(name = "A班开机时间")
-    private Long openTimeA;
+    private BigDecimal openTimeA;
 
-    /** A班停机时间 */
+    /**
+     * A班停机时间
+     */
     @ApiModelProperty("A班停机时间")
     @Excel(name = "A班停机时间")
-    private Long closeTimeA;
+    private BigDecimal closeTimeA;
 
-    /** A班电量 */
+    /**
+     * A班电量
+     */
     @ApiModelProperty("A班电量")
     @Excel(name = "A班电量")
     private BigDecimal kwhA;
 
-    /** A班停经片停机 */
+    /**
+     * A班停经片停机
+     */
     @ApiModelProperty("A班停经片停机")
     @Excel(name = "A班停经片停机")
     private Long stop1A;
 
-    /** A班CCD停机 */
+    /**
+     * A班CCD停机
+     */
     @ApiModelProperty("A班CCD停机")
     @Excel(name = "A班CCD停机")
     private Long stop2A;
 
-    /** A班人工停机 */
+    /**
+     * A班人工停机
+     */
     @ApiModelProperty("A班人工停机")
     @Excel(name = "A班人工停机")
     private Long stop3A;
 
-    /** B班米长 */
+    /**
+     * B班米长
+     */
     @ApiModelProperty("B班米长")
     @Excel(name = "B班米长")
     private BigDecimal lengthB;
 
-    /** B班重量 */
+    /**
+     * B班重量
+     */
     @ApiModelProperty("B班重量")
     @Excel(name = "B班重量")
     private BigDecimal weightB;
 
-    /** B班稼动率 */
+    /**
+     * B班稼动率
+     */
     @ApiModelProperty("B班稼动率")
     @Excel(name = "B班稼动率")
     private BigDecimal efficiencyB;
 
-    /** B班开机时间 */
+    /**
+     * B班开机时间
+     */
     @ApiModelProperty("B班开机时间")
     @Excel(name = "B班开机时间")
-    private Long openTimeB;
+    private BigDecimal openTimeB;
 
-    /** B班停机时间 */
+    /**
+     * B班停机时间
+     */
     @ApiModelProperty("B班停机时间")
     @Excel(name = "B班停机时间")
-    private Long closeTimeB;
+    private BigDecimal closeTimeB;
 
-    /** B班电量 */
+    /**
+     * B班电量
+     */
     @ApiModelProperty("B班电量")
     @Excel(name = "B班电量")
     private BigDecimal kwhB;
 
-    /** B班停经片停机 */
+    /**
+     * B班停经片停机
+     */
     @ApiModelProperty("B班停经片停机")
     @Excel(name = "B班停经片停机")
     private Long stop1B;
 
-    /** B班CCD停机 */
+    /**
+     * B班CCD停机
+     */
     @ApiModelProperty("B班CCD停机")
     @Excel(name = "B班CCD停机")
     private Long stop2B;
 
-    /** B班人工停机 */
+    /**
+     * B班人工停机
+     */
     @ApiModelProperty("B班人工停机")
     @Excel(name = "B班人工停机")
     private Long stop3B;
 
-    /** 创建人 */
+    /**
+     * 创建人
+     */
     @ApiModelProperty("创建人")
     @Excel(name = "创建人")
     private String createdBy;
 
-    /** 创建时间 */
+    /**
+     * 创建时间
+     */
     @ApiModelProperty("创建时间")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd")
     private Date createdTime;
 
-    /** 更新人 */
+    /**
+     * 更新人
+     */
     @ApiModelProperty("更新人")
     @Excel(name = "更新人")
     private String updatedBy;
 
-    /** 更新时间 */
+    /**
+     * 更新时间
+     */
     @ApiModelProperty("更新时间")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @Excel(name = "更新时间", width = 30, dateFormat = "yyyy-MM-dd")
     private Date updatedTime;
 
+
+    /**
+     * 计算产量数据
+     *
+     * @param hours 1小时统计数据
+     */
+    public void calcHours(List<TwinCalcHour> hours) {
+        hours.forEach(hour -> {
+            this.length = length.add(hour.getLength());
+            this.weight = weight.add(hour.getWeight());
+            this.kwh = kwh.add(hour.getKwh());
+            if (hour.getHour() >= 7 && hour.getHour() < 19) {
+                //A班
+                this.lengthA = lengthA.add(hour.getLength());
+                this.weightA = weightA.add(hour.getWeight());
+                this.kwhA = kwhA.add(hour.getKwh());
+                this.openTimeA = openTimeA.add(BigDecimal.valueOf(hour.getOpenTime()));
+                this.closeTimeA = closeTimeA.add(BigDecimal.valueOf(hour.getCloseTime()));
+            } else {
+                //B班
+                this.lengthB = lengthB.add(hour.getLength());
+                this.weightB = weightB.add(hour.getWeight());
+                this.kwhB = kwhB.add(hour.getKwh());
+                this.openTimeB = openTimeB.add(BigDecimal.valueOf(hour.getOpenTime()));
+                this.closeTimeB = closeTimeB.add(BigDecimal.valueOf(hour.getCloseTime()));
+            }
+        });
+    }
+
+    /**
+     * 计算天统计数据
+     *
+     * @param days 天数据
+     */
+    public void calcDays(List<TwinCalcDay> days) {
+        days.forEach(day -> {
+            this.weight = weight.add(day.getLength());
+            this.weightA = weightA.add(day.getLengthA());
+            this.weightB = weightB.add(day.getLengthB());
+
+            this.kwh = kwh.add(day.getKwh());
+            this.kwhA = kwhA.add(day.getKwhA());
+            this.kwhB = kwhB.add(day.getKwhB());
+
+            this.stop1A += day.getStop1A();
+            this.stop1B += day.getStop1B();
+            this.stop2A += day.getStop2A();
+            this.stop2B += day.getStop2B();
+            this.stop3A += day.getStop3A();
+            this.stop3B += day.getStop3B();
+
+            this.alarm += day.getAlarm();
+            this.closeTimeA = closeTimeA.add(day.getCloseTimeA());
+            this.closeTimeB = closeTimeB.add(day.getCloseTimeB());
+            this.openTimeA = openTimeA.add(day.getOpenTimeA());
+            this.openTimeB = openTimeB.add(day.getOpenTimeB());
+        });
+        BigDecimal teamTimeA = this.openTimeA.add(this.closeTimeA);
+        BigDecimal teamTimeB = this.openTimeB.add(this.closeTimeB);
+        BigDecimal totalTeamTime = teamTimeA.add(teamTimeB);
+        BigDecimal totalOpenTime = this.openTimeA.add(openTimeB);
+        if (teamTimeA.intValue() == 0) {
+            this.efficiencyA = BigDecimal.ZERO;
+        } else {
+            this.efficiencyA = openTimeA.divide(teamTimeA, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
+        }
+        if (teamTimeB.intValue() == 0) {
+            this.efficiencyB = BigDecimal.ZERO;
+        } else {
+            this.efficiencyB = openTimeB.divide(teamTimeB, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
+        }
+        if (totalTeamTime.intValue() == 0) {
+            this.efficiency = BigDecimal.ZERO;
+        } else {
+            this.efficiency = totalOpenTime.divide(totalTeamTime, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
+        }
+    }
+
+    public void setCells(Cell[] cells) {
+        //设备名称
+        cells[0].setCellValue(this.getRemark());
+        //时间
+        cells[1].setCellValue(DateUtils.parseDateToStr(this.getTime()));
+        //总长
+        cells[2].setCellValue(this.getLengthA().add(this.getLengthB()).floatValue());
+        //总重
+        cells[3].setCellValue(this.getWeightA().add(this.getWeightB()).floatValue());
+        //总稼动率
+        BigDecimal totalOpenTime = this.getOpenTimeA().add(this.getOpenTimeB());
+        BigDecimal totalCloseTime = this.getCloseTimeA().add(this.getCloseTimeB());
+        cells[4].setCellValue(Tools.calcPercent(totalOpenTime, totalCloseTime).floatValue());
+        // 总电量
+        cells[5].setCellValue(this.getKwh().floatValue());
+        //告警次数
+        cells[6].setCellValue(this.getAlarm());
+        //A班米长
+        cells[7].setCellValue(this.getLengthA().floatValue());
+        //A班重量
+        cells[8].setCellValue(this.getWeightA().floatValue());
+        //A班开机时间
+        cells[9].setCellValue(this.getOpenTimeA().floatValue());
+        //A班停机时间
+        cells[10].setCellValue(this.getCloseTimeA().floatValue());
+        //A班稼动率
+        cells[11].setCellValue(Tools.calcPercent(this.getOpenTimeA(), this.getCloseTimeA()).floatValue());
+        //A班电量
+        cells[12].setCellValue(this.getKwhA().floatValue());
+        //A班停经片停机次数
+        cells[13].setCellValue(this.getStop1A());
+        //A班CCD停机次数
+        cells[14].setCellValue(this.getStop2A());
+        //A班人工停机次数
+        cells[15].setCellValue(this.getStop3A());
+        //B班米长
+        cells[16].setCellValue(this.getLengthB().floatValue());
+        //B班重量
+        cells[17].setCellValue(this.getWeightB().floatValue());
+        //B班开机时间
+        cells[18].setCellValue(this.getOpenTimeB().floatValue());
+        //B班停机时间
+        cells[19].setCellValue(this.getCloseTimeB().floatValue());
+        //B班稼动率
+        cells[20].setCellValue(Tools.calcPercent(this.getOpenTimeB(), this.getCloseTimeB()).floatValue());
+        //B班电量
+        cells[21].setCellValue(this.getKwhB().floatValue());
+        //B班停经片停机次数
+        cells[22].setCellValue(this.getStop1B());
+        //B班CCD停机次数
+        cells[23].setCellValue(this.getStop2B());
+        //B班人工停机次数
+        cells[24].setCellValue(this.getStop3B());
+    }
+
 }

+ 32 - 7
jjt-biz/src/main/java/com/jjt/calc/mapper/TwinCalcDayMapper.java

@@ -1,12 +1,14 @@
 package com.jjt.calc.mapper;
 
+import java.util.Date;
 import java.util.List;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.jjt.calc.domain.TwinCalcDay;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * 日统计数据Mapper接口
- * 
+ *
  * @author wukai
  * @date 2025-01-18
  */
@@ -14,7 +16,7 @@ public interface TwinCalcDayMapper extends BaseMapper<TwinCalcDay>
 {
     /**
      * 查询日统计数据
-     * 
+     *
      * @param id 日统计数据主键
      * @return 日统计数据
      */
@@ -22,7 +24,7 @@ public interface TwinCalcDayMapper extends BaseMapper<TwinCalcDay>
 
     /**
      * 查询日统计数据列表
-     * 
+     *
      * @param twinCalcDay 日统计数据
      * @return 日统计数据集合
      */
@@ -30,7 +32,7 @@ public interface TwinCalcDayMapper extends BaseMapper<TwinCalcDay>
 
     /**
      * 新增日统计数据
-     * 
+     *
      * @param twinCalcDay 日统计数据
      * @return 结果
      */
@@ -38,7 +40,7 @@ public interface TwinCalcDayMapper extends BaseMapper<TwinCalcDay>
 
     /**
      * 修改日统计数据
-     * 
+     *
      * @param twinCalcDay 日统计数据
      * @return 结果
      */
@@ -46,7 +48,7 @@ public interface TwinCalcDayMapper extends BaseMapper<TwinCalcDay>
 
     /**
      * 删除日统计数据
-     * 
+     *
      * @param id 日统计数据主键
      * @return 结果
      */
@@ -54,9 +56,32 @@ public interface TwinCalcDayMapper extends BaseMapper<TwinCalcDay>
 
     /**
      * 批量删除日统计数据
-     * 
+     *
      * @param ids 需要删除的数据主键集合
      * @return 结果
      */
     public int deleteTwinCalcDayByIds(Long[] ids);
+    /**
+     * 查询指定日期及之后的数据
+     *
+     * @param sd 开始日期
+     * @param ed 结束日期
+     * @return 列表
+     */
+    List<TwinCalcDay> selectTwinCalcDayListByTime(@Param("sd") Date sd, @Param("ed") Date ed);
+
+
+    /**
+     * 按日期删除数据
+     *
+     * @param date
+     */
+    void delete4date(Date date);
+    /**
+     * 按月度查询
+     *
+     * @param month 月份
+     * @return 结果
+     */
+    List<TwinCalcDay> selectTwinCalcDayListByMonth(String month);
 }

+ 6 - 0
jjt-biz/src/main/java/com/jjt/calc/mapper/TwinCalcHourMapper.java

@@ -60,4 +60,10 @@ public interface TwinCalcHourMapper extends BaseMapper<TwinCalcHour> {
      * @return 结果
      */
     public int deleteTwinCalcHourByIds(Long[] ids);
+    /**
+     * 获取数据库最后一条记录
+     *
+     * @return 对象
+     */
+    TwinCalcHour lastHour();
 }

+ 9 - 0
jjt-biz/src/main/java/com/jjt/calc/service/ITwinCalcAlarmsService.java

@@ -1,6 +1,7 @@
 package com.jjt.calc.service;
 
 import java.time.LocalDateTime;
+import java.util.Date;
 import java.util.List;
 
 import com.jjt.biz.domain.TwinDevice;
@@ -68,4 +69,12 @@ public interface ITwinCalcAlarmsService {
      * @param deviceList 设备列表
      */
     void process(LocalDateTime startTime, List<TwinDevice> deviceList);
+    /**
+     * 按开始和结束时间查询数据
+     *
+     * @param sTime 开始时间
+     * @param eTime 结束时间
+     * @return 查询列表
+     */
+    List<TwinCalcAlarms> selectTwinCalcAlarmsListByDate(Date sTime, Date eTime);
 }

+ 17 - 0
jjt-biz/src/main/java/com/jjt/calc/service/ITwinCalcHourService.java

@@ -2,6 +2,7 @@ package com.jjt.calc.service;
 
 import com.jjt.calc.domain.TwinCalcHour;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -70,4 +71,20 @@ public interface ITwinCalcHourService {
      * @param period 时段
      */
     public void calc(String date, int period);
+
+    /**
+     * 按开始和结束时间查询数据
+     *
+     * @param sTime 开始时间
+     * @param eTime 结束时间
+     * @return 查询列表
+     */
+    List<TwinCalcHour> selectTwinCalcHourListByDate(Date sTime, Date eTime);
+
+    /**
+     * 获取数据库最后一条记录
+     *
+     * @return 对象
+     */
+    TwinCalcHour lastHour();
 }

+ 19 - 0
jjt-biz/src/main/java/com/jjt/calc/service/ITwinCalcStopService.java

@@ -1,6 +1,7 @@
 package com.jjt.calc.service;
 
 import java.time.LocalDateTime;
+import java.util.Date;
 import java.util.List;
 
 import com.jjt.biz.domain.TwinDevice;
@@ -68,4 +69,22 @@ public interface ITwinCalcStopService {
      * @param deviceList 设备列表
      */
     void process(LocalDateTime startTime, LocalDateTime endTime, List<TwinDevice> deviceList);
+    /**
+     * 按开始和结束时间查询数据
+     *
+     * @param sTime 开始时间
+     * @param eTime 结束时间
+     * @return 查询列表
+     */
+    List<TwinCalcStop> selectTwinCalcStopListByDate(Date sTime, Date eTime);
+
+    /**
+     * 按开始和结束时间查询数据--停机类型)
+     *
+     * @param sTime 开始时间
+     * @param eTime 结束时间
+     * @param type  停机类型
+     * @return 查询列表
+     */
+    List<TwinCalcStop> selectTwinCalcStopListByDate(Date sTime, Date eTime, int type);
 }

+ 37 - 4
jjt-biz/src/main/java/com/jjt/calc/service/impl/TwinCalcAlarmsServiceImpl.java

@@ -6,6 +6,7 @@ import com.jjt.calc.domain.TwinRecordAlarms;
 import com.jjt.calc.mapper.TwinCalcAlarmsMapper;
 import com.jjt.calc.service.ITwinCalcAlarmsService;
 import com.jjt.calc.service.ITwinRecordAlarmsService;
+import com.jjt.common.utils.StringUtils;
 import com.jjt.common.utils.bean.BeanUtils;
 import com.jjt.system.service.ISysConfigService;
 import org.apache.ibatis.session.ExecutorType;
@@ -113,7 +114,6 @@ public class TwinCalcAlarmsServiceImpl implements ITwinCalcAlarmsService {
         String config = configService.selectConfigByKey("data.legal.time");
         int legalTime = Integer.parseInt(config) * 1000;
         Date date = Date.from(startTime.toLocalDate().atStartOfDay(ZoneOffset.of("+8")).toInstant());
-        String oldStr = "old";
         //先处理上次未统计完整的数据
         TwinCalcAlarms calcSearch = new TwinCalcAlarms();
         calcSearch.setCalcStatus("1");
@@ -129,13 +129,16 @@ public class TwinCalcAlarmsServiceImpl implements ITwinCalcAlarmsService {
         List<TwinCalcAlarms> insertList = new ArrayList<>();
         List<TwinCalcAlarms> updateList = new ArrayList<>();
         List<TwinRecordAlarms> recordList = new ArrayList<>();
+        //需要删除的数据
+        List<Long> delIds = new ArrayList<>();
         deviceList.forEach(device -> {
             List<TwinRecordAlarms> list = new ArrayList<>();
             if (oldMap.get(device.getDeviceId()) != null) {
                 oldMap.get(device.getDeviceId()).forEach(old -> {
                     TwinRecordAlarms alarms = new TwinRecordAlarms();
                     BeanUtils.copyProperties(old, alarms);
-                    alarms.setRemark(oldStr);
+                    //这里存ID,方便后面需要删除,判断是否之前的记录,则直接判断remark是否为空即可
+                    alarms.setRemark(old.getId() + "");
                     list.add(alarms);
                 });
             }
@@ -166,6 +169,10 @@ public class TwinCalcAlarmsServiceImpl implements ITwinCalcAlarmsService {
                             if (lastAlarms.getEndTime().getTime() - lastAlarms.getStartTime().getTime() > legalTime) {
                                 recordList.add(lastAlarms);
                             }
+                            //如果无效数据是未统计完成的记录,则需要删除统计里面的数据
+                            if (StringUtils.isNotEmpty(lastAlarms.getRemark())) {
+                                delIds.add(Long.parseLong(lastAlarms.getRemark()));
+                            }
                             lastAlarms = currAlarms;
                         }
                         if (i + 1 == temp.size()) {
@@ -173,6 +180,10 @@ public class TwinCalcAlarmsServiceImpl implements ITwinCalcAlarmsService {
                             if ("1".equals(lastAlarms.getCalcStatus()) || lastAlarms.getEndTime().getTime() - lastAlarms.getStartTime().getTime() > legalTime) {
                                 recordList.add(lastAlarms);
                             }
+                            //如果无效数据是未统计完成的记录,则需要删除统计里面的数据
+                            if (StringUtils.isNotEmpty(lastAlarms.getRemark())) {
+                                delIds.add(Long.parseLong(lastAlarms.getRemark()));
+                            }
                         }
                     }
                 }
@@ -181,7 +192,7 @@ public class TwinCalcAlarmsServiceImpl implements ITwinCalcAlarmsService {
         for (TwinRecordAlarms stop : recordList) {
             TwinCalcAlarms v = new TwinCalcAlarms();
             BeanUtils.copyProperties(stop, v);
-            if (oldStr.equals(stop.getRemark())) {
+            if (StringUtils.isNotEmpty(stop.getRemark())) {
                 v.setCalcStatus("0");
                 v.setRemark("");
                 updateList.add(v);
@@ -190,14 +201,36 @@ public class TwinCalcAlarmsServiceImpl implements ITwinCalcAlarmsService {
                 insertList.add(v);
             }
         }
+
         try (SqlSession sqlSession = factory.openSession(ExecutorType.BATCH, false)) {
             TwinCalcAlarmsMapper mapper = sqlSession.getMapper(TwinCalcAlarmsMapper.class);
             insertList.forEach(mapper::insertTwinCalcAlarms);
             updateList.forEach(mapper::updateTwinCalcAlarms);
             sqlSession.commit();
         }
+        if (delIds.size() > 0) {
+            deleteTwinCalcAlarmsByIds(delIds.toArray(new Long[]{}));
+        }
+
 
         //统计完成删除记录数据,避免记录超长
-//        alarmsService.deleteTwinRecordAlarms(date, startTime.getHour());
+        alarmsService.deleteTwinRecordAlarms(date, startTime.getHour());
+    }
+
+    /**
+     * 按开始和结束时间查询数据
+     *
+     * @param sTime 开始时间
+     * @param eTime 结束时间
+     * @return 查询列表
+     */
+    @Override
+    public List<TwinCalcAlarms> selectTwinCalcAlarmsListByDate(Date sTime, Date eTime) {
+        TwinCalcAlarms alarms = new TwinCalcAlarms();
+        Map<String, Object> params = new HashMap<>(16);
+        params.put("sTime", sTime);
+        params.put("eTime", eTime);
+        alarms.setParams(params);
+        return selectTwinCalcAlarmsList(alarms);
     }
 }

+ 175 - 4
jjt-biz/src/main/java/com/jjt/calc/service/impl/TwinCalcDayServiceImpl.java

@@ -1,11 +1,31 @@
 package com.jjt.calc.service.impl;
 
-import java.util.List;
-import org.springframework.stereotype.Service;
-import com.jjt.calc.mapper.TwinCalcDayMapper;
+import com.jjt.calc.domain.TwinCalcAlarms;
 import com.jjt.calc.domain.TwinCalcDay;
+import com.jjt.calc.domain.TwinCalcHour;
+import com.jjt.calc.domain.TwinCalcStop;
+import com.jjt.calc.mapper.TwinCalcAlarmsMapper;
+import com.jjt.calc.mapper.TwinCalcDayMapper;
+import com.jjt.calc.service.ITwinCalcAlarmsService;
 import com.jjt.calc.service.ITwinCalcDayService;
+import com.jjt.calc.service.ITwinCalcHourService;
+import com.jjt.calc.service.ITwinCalcStopService;
+import com.jjt.common.utils.DateUtils;
+import com.jjt.utils.Tools;
+import javafx.util.Pair;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.springframework.stereotype.Service;
+
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.time.LocalDate;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.BiConsumer;
+import java.util.stream.Collectors;
 
 /**
  * 日统计数据Service业务层处理
@@ -17,6 +37,14 @@ import javax.annotation.Resource;
 public class TwinCalcDayServiceImpl implements ITwinCalcDayService {
     @Resource
     private TwinCalcDayMapper twinCalcDayMapper;
+    @Resource
+    private ITwinCalcHourService hourService;
+    @Resource
+    private ITwinCalcStopService stopService;
+    @Resource
+    private ITwinCalcAlarmsService alarmsService;
+    @Resource
+    private SqlSessionFactory factory;
 
     /**
      * 查询日统计数据
@@ -48,7 +76,7 @@ public class TwinCalcDayServiceImpl implements ITwinCalcDayService {
      */
     @Override
     public int insertTwinCalcDay(TwinCalcDay twinCalcDay) {
-            return twinCalcDayMapper.insertTwinCalcDay(twinCalcDay);
+        return twinCalcDayMapper.insertTwinCalcDay(twinCalcDay);
     }
 
     /**
@@ -83,4 +111,147 @@ public class TwinCalcDayServiceImpl implements ITwinCalcDayService {
     public int deleteTwinCalcDayById(Long id) {
         return twinCalcDayMapper.deleteTwinCalcDayById(id);
     }
+
+    /**
+     * 近日统计数据
+     *
+     * @param localDate 日期
+     */
+    @Override
+    public void day(LocalDate localDate) {
+        Date date = DateUtils.toDate(localDate);
+        //先删除当前日期数据
+        twinCalcDayMapper.delete4date(date);
+        //计算统计时间
+        Pair<Date, Date> pair = Tools.calcDay(localDate);
+        Date sTime = pair.getKey();
+        Date eTime = pair.getValue();
+        List<TwinCalcHour> hourList = hourService.selectTwinCalcHourListByDate(sTime, eTime);
+        List<TwinCalcStop> stopList = stopService.selectTwinCalcStopListByDate(sTime, eTime);
+        List<TwinCalcAlarms> alarmsList = alarmsService.selectTwinCalcAlarmsListByDate(sTime, eTime);
+        Pair<Date, Date> teamPairA = Tools.teamA(localDate);
+        Pair<Date, Date> teamPairB = Tools.teamB(localDate);
+        // 提取A班和B班的开始和结束时间,避免在循环中重复调用
+        Date startTimeA = teamPairA.getKey();
+        Date endTimeA = teamPairA.getValue();
+        Date startTimeB = teamPairB.getKey();
+        Date endTimeB = teamPairB.getValue();
+        Map<Long, List<TwinCalcHour>> hourDeviceGroup = hourList.stream().collect(Collectors.groupingBy(TwinCalcHour::getDeviceId, LinkedHashMap::new, Collectors.toList()));
+
+        List<TwinCalcDay> dayList = new ArrayList<>();
+        for (Map.Entry<Long, List<TwinCalcHour>> entry : hourDeviceGroup.entrySet()) {
+            List<TwinCalcHour> hours = entry.getValue();
+            TwinCalcDay day = new TwinCalcDay(date);
+            day.setDeviceId(entry.getKey());
+            //计算产量数据
+            day.calcHours(hours);
+            //计算停机数据
+            List<TwinCalcStop> stops = stopList.stream().filter(s -> s.getDeviceId().equals(entry.getKey())).collect(Collectors.toList());
+            AtomicLong closeA = new AtomicLong(0L);
+            AtomicLong closeB = new AtomicLong(0L);
+            //A班停机计数
+            BiConsumer<Integer, Integer> updateDayA = (type, count) -> {
+                switch (type) {
+                    case 1:
+                        day.setStop1A(day.getStop1A() + count);
+                        break;
+                    case 2:
+                        day.setStop2A(day.getStop2A() + count);
+                        break;
+                    case 3:
+                        day.setStop3A(day.getStop3A() + count);
+                        break;
+                    default:
+                }
+            };
+
+            BiConsumer<Integer, Integer> updateDayB = (type, count) -> {
+                switch (type) {
+                    case 1:
+                        day.setStop1B(day.getStop1B() + count);
+                        break;
+                    case 2:
+                        day.setStop2B(day.getStop2B() + count);
+                        break;
+                    case 3:
+                        day.setStop3B(day.getStop3B() + count);
+                        break;
+                    default:
+                }
+            };
+
+            // 使用Stream API,结合if-else逻辑的优化
+            stops.forEach(stop -> {
+                // 根据停机时间判断属于哪个班次
+                boolean isAshift = !stop.getStartTime().after(endTimeA) && !stop.getEndTime().before(startTimeA);
+                Date shiftStart = isAshift ? startTimeA : startTimeB;
+                Date shiftEnd = isAshift ? endTimeA : endTimeB;
+                AtomicLong totalStopTime = isAshift ? closeA : closeB;
+                BiConsumer<Integer, Integer> eventCounter = isAshift ? updateDayA : updateDayB;
+
+                // 调整停机时间
+                if (stop.getEndTime().compareTo(shiftEnd) > 0) {
+                    stop.setEndTime(shiftEnd);
+                }
+                if (stop.getStartTime().compareTo(shiftStart) < 0) {
+                    stop.setStartTime(shiftStart);
+                }
+
+                // 计算并更新停机时间和事件计数
+                long stopTime = (stop.getEndTime().getTime() - stop.getStartTime().getTime()) / 1000;
+                updateStopCounters(stopTime, stop.getStopType(), totalStopTime, eventCounter);
+            });
+
+            //计算稼动率
+            //AB班排班时间,要乘以设备总数
+            long teamTimeA = 12L * 60 * 60;
+            long teamTimeB = 12L * 60 * 60;
+            long totalTeamTime = teamTimeA + teamTimeB;
+
+            long openTimeA = teamTimeA - closeA.get();
+            long openTimeB = teamTimeB - closeB.get();
+            long totalOpenTime = openTimeA + openTimeB;
+            BigDecimal ea = BigDecimal.valueOf(openTimeA).divide(BigDecimal.valueOf(teamTimeA), 4, RoundingMode.HALF_UP);
+            BigDecimal eb = BigDecimal.valueOf(openTimeB).divide(BigDecimal.valueOf(teamTimeB), 4, RoundingMode.HALF_UP);
+            BigDecimal ee = BigDecimal.valueOf(totalOpenTime).divide(BigDecimal.valueOf(totalTeamTime), 4, RoundingMode.HALF_UP);
+            day.setOpenTimeA(BigDecimal.valueOf(openTimeA));
+            day.setOpenTimeB(BigDecimal.valueOf(openTimeB));
+            day.setCloseTimeA(BigDecimal.valueOf(closeA.get()));
+            day.setCloseTimeB(BigDecimal.valueOf(closeB.get()));
+            day.setEfficiencyA(ea);
+            day.setEfficiencyB(eb);
+            day.setEfficiency(ee);
+            if (day.getLength().intValue() == 0) {
+                day.setOpenTimeA(BigDecimal.ZERO);
+                day.setOpenTimeB(BigDecimal.ZERO);
+                day.setCloseTimeA(BigDecimal.ZERO);
+                day.setCloseTimeB(BigDecimal.ZERO);
+                day.setEfficiencyA(BigDecimal.ZERO);
+                day.setEfficiencyB(BigDecimal.ZERO);
+                day.setEfficiency(BigDecimal.ZERO);
+            }
+            List<TwinCalcAlarms> alarms = alarmsList.stream().filter(a -> a.getDeviceId().equals(entry.getKey())).collect(Collectors.toList());
+            day.setAlarm((long) alarms.size());
+            dayList.add(day);
+        }
+        try (SqlSession sqlSession = factory.openSession(ExecutorType.BATCH, false)) {
+            TwinCalcDayMapper mapper = sqlSession.getMapper(TwinCalcDayMapper.class);
+            dayList.forEach(mapper::insertTwinCalcDay);
+            sqlSession.commit();
+        }
+    }
+
+    /**
+     * 用于更新停机时间计数器和事件计数
+     *
+     * @param stopTime            停机时间
+     * @param stopType            停机类型
+     * @param totalTimeCounter    停机总时间
+     * @param eventCounterUpdater 抽象方法
+     */
+    private void updateStopCounters(long stopTime, int stopType, AtomicLong
+            totalTimeCounter, BiConsumer<Integer, Integer> eventCounterUpdater) {
+        totalTimeCounter.addAndGet(stopTime);
+        eventCounterUpdater.accept(stopType, 1);
+    }
 }

+ 28 - 56
jjt-biz/src/main/java/com/jjt/calc/service/impl/TwinCalcHourServiceImpl.java

@@ -19,10 +19,7 @@ import javax.annotation.Resource;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
@@ -158,7 +155,7 @@ public class TwinCalcHourServiceImpl implements ITwinCalcHourService {
         //查询所有在线的设备
         search.setOnline("1");
         //TODO 临时设置单个设备,上线需取消
-//        search.setDeviceId(1L);
+//        search.setDeviceId(75L);
         List<TwinDevice> list = deviceService.selectTwinDeviceList(search);
         List<TwinDevice> errList = exec(list, start, end);
         //重试2次
@@ -258,55 +255,30 @@ public class TwinCalcHourServiceImpl implements ITwinCalcHourService {
         return errList;
     }
 
-//    /**
-//     * 执行数据获取操作
-//     *
-//     * @param list         设备列表
-//     * @param date         日期
-//     * @param startTime    开始时间
-//     * @param endTime      结束时间
-//     * @param period       小时数
-//     * @param calcHourList 1小时统计数据
-//     * @param stopList     停机数据
-//     * @param panList      盘头数据
-//     * @param alarmsList   告警数据
-//     * @return 返回未获取成功的数据列表
-//     */
-//
-//    private List<TwinDevice> exec(List<TwinDevice> list, Date date, Long startTime, Long endTime, int period, List<Object[]> calcHourList, List<TwinRecordStop> stopList, List<Object[]> panList, List<TwinRecordAlarms> alarmsList, List<TwinCalcHourSpec> specList) {
-//        List<Future<Map<String, List<?>>>> futureList = new ArrayList<>();
-//        for (int i = 0; i < list.size(); i++) {
-//            TwinDevice twinDevice = list.get(i);
-//            futureList.add(asyncService.process(twinDevice, date, startTime, endTime, period));
-//        }
-//
-//        List<TwinDevice> errList = new ArrayList<>();
-//        try {
-//            for (Future<Map<String, List<?>>> future : futureList) {
-//                // 任务完成后获取结果
-//                try {
-//                    Map<String, List<?>> map = future.get(10L, TimeUnit.SECONDS);
-//                    List<TwinCalcHour> calcHours = (List<TwinCalcHour>) map.get("calc");
-//                    List<TwinRecordStop> stops = (List<TwinRecordStop>) map.get("stopRecord");
-//
-//                    List<TwinRecordAlarms> alarms = (List<TwinRecordAlarms>) map.get("alarmRecord");
-//                    List<TwinPanHeadInfo> panHeadInfoList = (List<TwinPanHeadInfo>) map.get("panHead");
-//                    List<TwinCalcHourSpec> specs = (List<TwinCalcHourSpec>) map.get("specList");
-//                    specList.addAll(specs);
-//                    calcHours.forEach(calcHour -> calcHourList.add(calcHour.toArray()));
-//                    stopList.addAll(stops);
-//                    alarmsList.addAll(alarms);
-//                    panHeadInfoList.forEach(pan -> panList.add(pan.toArray()));
-//                } catch (TimeoutException e) {
-//                    errList.add(list.get(futureList.indexOf(future)));
-//                }
-//            }
-//        } catch (InterruptedException e) {
-//            throw new RuntimeException(e);
-//        } catch (ExecutionException e) {
-//            throw new RuntimeException(e);
-//        }
-//
-//        return errList;
-//    }
+
+    /**
+     * 按开始和结束时间查询数据
+     *
+     * @param sTime 开始时间
+     * @param eTime 结束时间
+     */
+    @Override
+    public List<TwinCalcHour> selectTwinCalcHourListByDate(Date sTime, Date eTime) {
+        TwinCalcHour hour = new TwinCalcHour();
+        Map<String, Object> params = new HashMap<>(16);
+        params.put("sTime", sTime);
+        params.put("eTime", eTime);
+        hour.setParams(params);
+        return selectTwinCalcHourList(hour);
+    }
+
+    /**
+     * 获取数据库最后一条记录
+     *
+     * @return 对象
+     */
+    @Override
+    public TwinCalcHour lastHour() {
+        return twinCalcHourMapper.lastHour();
+    }
 }

+ 67 - 12
jjt-biz/src/main/java/com/jjt/calc/service/impl/TwinCalcStopServiceImpl.java

@@ -1,27 +1,28 @@
 package com.jjt.calc.service.impl;
 
-import java.time.LocalDateTime;
-import java.time.ZoneOffset;
-import java.util.*;
-import java.util.stream.Collectors;
-
 import com.jjt.biz.domain.TwinDevice;
 import com.jjt.calc.domain.TwinCalcHour;
+import com.jjt.calc.domain.TwinCalcStop;
 import com.jjt.calc.domain.TwinRecordStop;
 import com.jjt.calc.mapper.TwinCalcHourMapper;
+import com.jjt.calc.mapper.TwinCalcStopMapper;
 import com.jjt.calc.service.ITwinCalcHourService;
+import com.jjt.calc.service.ITwinCalcStopService;
 import com.jjt.calc.service.ITwinRecordStopService;
 import com.jjt.common.utils.DateUtils;
+import com.jjt.common.utils.StringUtils;
 import com.jjt.common.utils.bean.BeanUtils;
 import com.jjt.system.service.ISysConfigService;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
 import org.springframework.stereotype.Service;
-import com.jjt.calc.mapper.TwinCalcStopMapper;
-import com.jjt.calc.domain.TwinCalcStop;
-import com.jjt.calc.service.ITwinCalcStopService;
+
 import javax.annotation.Resource;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 停机数据统计Service业务层处理
@@ -41,6 +42,7 @@ public class TwinCalcStopServiceImpl implements ITwinCalcStopService {
     private SqlSessionFactory factory;
     @Resource
     private ITwinCalcHourService calcHourService;
+
     /**
      * 查询停机数据统计
      *
@@ -71,7 +73,7 @@ public class TwinCalcStopServiceImpl implements ITwinCalcStopService {
      */
     @Override
     public int insertTwinCalcStop(TwinCalcStop twinCalcStop) {
-            return twinCalcStopMapper.insertTwinCalcStop(twinCalcStop);
+        return twinCalcStopMapper.insertTwinCalcStop(twinCalcStop);
     }
 
     /**
@@ -124,7 +126,6 @@ public class TwinCalcStopServiceImpl implements ITwinCalcStopService {
         Date endDate = DateUtils.toDate(endTime);
         List<TwinCalcStop> insertList = new ArrayList<>();
         List<TwinCalcStop> updateList = new ArrayList<>();
-        String oldStr = "old";
         //查询上次未统计完整的数据
         TwinCalcStop calcSearch = new TwinCalcStop();
         calcSearch.setCalcStatus("1");
@@ -144,6 +145,8 @@ public class TwinCalcStopServiceImpl implements ITwinCalcStopService {
 
         List<TwinCalcHour> calcStopTimeList = new ArrayList<>();
         List<TwinRecordStop> recordList = new ArrayList<>();
+        //需要删除的数据
+        List<Long> delIds = new ArrayList<>();
         for (TwinDevice device : deviceList) {
             //先处理上次未统计完整的数据
             List<TwinRecordStop> list = new ArrayList<>();
@@ -152,7 +155,8 @@ public class TwinCalcStopServiceImpl implements ITwinCalcStopService {
                     if (!old.getEndTime().after(endDate)) {
                         TwinRecordStop stop = new TwinRecordStop();
                         BeanUtils.copyProperties(old, stop);
-                        stop.setRemark(oldStr);
+                        //这里存ID,方便后面需要删除,判断是否之前的记录,则直接判断remark是否为空即可
+                        stop.setRemark(old.getId() + "");
                         list.add(stop);
                     }
                 }
@@ -184,6 +188,12 @@ public class TwinCalcStopServiceImpl implements ITwinCalcStopService {
                             if (lastStop.getEndTime().getTime() - lastStop.getStartTime().getTime() > legalTime) {
                                 recordList.add(lastStop);
                             }
+
+                            if (StringUtils.isNotEmpty(lastStop.getRemark())) {
+                                //如果无效数据是未统计完成的记录,则需要删除统计里面的数据
+                                delIds.add(Long.parseLong(lastStop.getRemark()));
+                            }
+
                             lastStop = currStop;
                         }
                         if (i + 1 == temp.size()) {
@@ -191,6 +201,11 @@ public class TwinCalcStopServiceImpl implements ITwinCalcStopService {
                             if ("1".equals(lastStop.getCalcStatus()) || lastStop.getEndTime().getTime() - lastStop.getStartTime().getTime() > legalTime) {
                                 recordList.add(lastStop);
                             }
+
+                            //如果无效数据是未统计完成的记录,则需要删除统计里面的数据
+                            if (StringUtils.isNotEmpty(lastStop.getRemark())) {
+                                delIds.add(Long.parseLong(lastStop.getRemark()));
+                            }
                         }
                     }
                 }
@@ -211,7 +226,7 @@ public class TwinCalcStopServiceImpl implements ITwinCalcStopService {
             calcHour.setCloseTime(stopTime);
             calcStopTimeList.add(calcHour);
 
-            if (oldStr.equals(stop.getRemark())) {
+            if (StringUtils.isNotEmpty(stop.getRemark())) {
                 //需要判断 这次是否还是未处理完成的数据,如果结束时间小于数据结束时间,则完成
                 if (v.getEndTime().before(endDate)) {
                     v.setCalcStatus("0");
@@ -250,7 +265,47 @@ public class TwinCalcStopServiceImpl implements ITwinCalcStopService {
             sqlSession.commit();
         }
 
+        if (delIds.size() > 0) {
+            deleteTwinCalcStopByIds(delIds.toArray(new Long[]{}));
+        }
+
         //统计完成删除记录数据,避免记录超长
         stopService.deleteTwinRecordStop(date, startTime.getHour());
     }
+
+
+    /**
+     * 按开始和结束时间查询数据
+     *
+     * @param sTime 开始时间
+     * @param eTime 结束时间
+     * @return 查询列表
+     */
+    @Override
+    public List<TwinCalcStop> selectTwinCalcStopListByDate(Date sTime, Date eTime) {
+        TwinCalcStop stop = new TwinCalcStop();
+        Map<String, Object> params = new HashMap<>(16);
+        params.put("sTime", sTime);
+        params.put("eTime", eTime);
+        stop.setParams(params);
+        return selectTwinCalcStopList(stop);
+    }
+
+    /**
+     * 按开始和结束时间查询数据(生产天)
+     *
+     * @param sTime 开始时间
+     * @param eTime 结束时间
+     * @return 查询列表
+     */
+    @Override
+    public List<TwinCalcStop> selectTwinCalcStopListByDate(Date sTime, Date eTime, int type) {
+        TwinCalcStop stop = new TwinCalcStop();
+        stop.setStopType(type);
+        Map<String, Object> params = new HashMap<>(16);
+        params.put("sTime", sTime);
+        params.put("eTime", eTime);
+        stop.setParams(params);
+        return selectTwinCalcStopList(stop);
+    }
 }

+ 1 - 1
jjt-biz/src/main/java/com/jjt/utils/AsyncService.java

@@ -204,7 +204,7 @@ public class AsyncService {
         long s = System.currentTimeMillis();
         JSONObject jsonObject = iotService.query(sql);
         long e = System.currentTimeMillis();
-        log.info("接口耗时:{}ms,table:{},time:{}", e - s, table, new Date(endTime));
+        log.info("接口耗时:{}ms,table:{},time:{}", e - s, table, DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date(endTime)));
         JSONObject data = jsonObject.getJSONObject("data");
         JSONArray values = data.getJSONArray("values");
         JSONArray timestamps = data.getJSONArray("timestamps");

+ 3 - 0
jjt-biz/src/main/resources/mapper/calc/TwinCalcAlarmsMapper.xml

@@ -39,6 +39,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updatedBy != null  and updatedBy != ''"> and UPDATED_BY = #{updatedBy}</if>
             <if test="updatedTime != null "> and UPDATED_TIME = #{updatedTime}</if>
             <if test="remark != null  and remark != ''"> and REMARK = #{remark}</if>
+            <if test="params.sTime != null and params.eTime != null">
+                and (start_time&lt;=#{params.eTime} and end_time>=#{params.sTime})
+            </if>
         </where>
     </select>
 

+ 22 - 6
jjt-biz/src/main/resources/mapper/calc/TwinCalcDayMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.jjt.calc.mapper.TwinCalcDayMapper">
-    
+
     <resultMap type="TwinCalcDay" id="TwinCalcDayResult">
         <result property="id"    column="ID"    />
         <result property="time"    column="TIME"    />
@@ -44,7 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectTwinCalcDayList" parameterType="TwinCalcDay" resultMap="TwinCalcDayResult">
         <include refid="selectTwinCalcDayVo"/>
-        <where>  
+        <where>
             <if test="time != null "> and TIME = #{time}</if>
             <if test="deviceId != null "> and DEVICE_ID = #{deviceId}</if>
             <if test="length != null "> and LENGTH = #{length}</if>
@@ -77,13 +77,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="remark != null  and remark != ''"> and REMARK = #{remark}</if>
         </where>
     </select>
-    
+
     <select id="selectTwinCalcDayById" parameterType="Long" resultMap="TwinCalcDayResult">
         <include refid="selectTwinCalcDayVo"/>
         where ID = #{id}
     </select>
 
-    <insert id="insertTwinCalcDay" parameterType="TwinCalcDay" useGeneratedKeys="true" keyProperty="id">
+    <insert id="insertTwinCalcDay" parameterType="TwinCalcDay">
         insert into TWIN_CALC_DAY
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="time != null">TIME,</if>
@@ -193,9 +193,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteTwinCalcDayByIds" parameterType="String">
-        delete from TWIN_CALC_DAY where ID in 
+        delete from TWIN_CALC_DAY where ID in
         <foreach item="id" collection="array" open="(" separator="," close=")">
             #{id}
         </foreach>
     </delete>
-</mapper>
+    <delete id="delete4date" parameterType="Date">
+        DELETE
+        FROM TWIN_CALC_DAY
+        WHERE TIME =#{date}
+    </delete>
+    <select id="selectTwinCalcDayListByMonth" resultMap="TwinCalcDayResult">
+        <include refid="selectTwinCalcDayVo"/>
+        where FORMAT(time, 'yyyy-MM') = #{month}
+        order by time
+    </select>
+    <select id="selectTwinCalcDayListByTime" resultMap="TwinCalcDayResult">
+        <include refid="selectTwinCalcDayVo"/>
+        where time>=#{sd}
+        <if test="ed != null ">and time&lt;=#{ed}</if>
+        order by time
+    </select>
+</mapper>

+ 7 - 0
jjt-biz/src/main/resources/mapper/calc/TwinCalcHourMapper.xml

@@ -99,6 +99,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="updatedBy != null">UPDATED_BY = #{updatedBy},</if>
             <if test="updatedTime != null">UPDATED_TIME = #{updatedTime},</if>
             <if test="remark != null">REMARK = #{remark},</if>
+            <if test="params.sTime != null and params.eTime != null">
+                and DATEADD(hour, HOUR, DATA_DATE) between #{params.sTime} and #{params.eTime}
+            </if>
         </trim>
         where ID = #{id}
     </update>
@@ -113,4 +116,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{id}
         </foreach>
     </delete>
+
+    <select id="lastHour" resultMap="TwinCalcHourResult">
+        select top 1 * from TWIN_CALC_HOUR order by id desc
+    </select>
 </mapper>