xushili 3 tuần trước cách đây
mục cha
commit
32d95d74c2

+ 35 - 0
runeconomy-xk/src/main/java/com/gyee/runeconomy/entity/StationInfoMonth.java

@@ -0,0 +1,35 @@
+package com.gyee.runeconomy.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author gfhd
+ * @since 2024-03-05
+ */
+@Data
+@TableName("station_info_month")
+public class StationInfoMonth implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    private String stationId;
+
+    private Date recordDate;
+
+    private Double mtbf;
+
+    private Double mttr;
+}

+ 16 - 0
runeconomy-xk/src/main/java/com/gyee/runeconomy/mapper/StationInfoMonthMapper.java

@@ -0,0 +1,16 @@
+package com.gyee.runeconomy.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.gyee.runeconomy.entity.StationInfoMonth;
+
+/**
+ * <p>
+ * Mapper 接口
+ * </p>
+ *
+ * @author gfhd
+ * @since 2024-03-05
+ */
+public interface StationInfoMonthMapper extends BaseMapper<StationInfoMonth> {
+
+}

+ 23 - 0
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/IStationInfoMonthService.java

@@ -0,0 +1,23 @@
+package com.gyee.runeconomy.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.gyee.runeconomy.entity.StationInfoMonth;
+import com.gyee.runeconomy.model.auto.PointInfo;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ * 服务类
+ * </p>
+ *
+ * @author gfhd
+ * @since 2024-03-05
+ */
+public interface IStationInfoMonthService extends IService<StationInfoMonth> {
+    List<StationInfoMonth> getInfoByDate(Date date);
+    List<StationInfoMonth> getInfoByDate(Date date, List<PointInfo> entity);
+    Map<String, StationInfoMonth> getInfoByDateMap(Date date, List<PointInfo> entity);
+}

+ 61 - 0
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/impl/StationInfoMonthServiceImpl.java

@@ -0,0 +1,61 @@
+package com.gyee.runeconomy.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.gyee.runeconomy.mapper.StationInfoMonthMapper;
+import org.springframework.stereotype.Service;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ * 服务实现类
+ * </p>
+ *
+ * @author gfhd
+ * @since 2024-03-05
+ */
+@Service
+public class StationInfoMonthServiceImpl extends ServiceImpl<StationInfoMonthMapper, StationInfoMonth> implements IStationInfoMonthService {
+
+    @Override
+    public boolean saveOrUpdateBatch(Collection<StationInfoMonth> entityList) {
+        return super.saveOrUpdateBatch(entityList);
+    }
+
+    @Override
+    public List<StationInfoMonth> list(Wrapper<StationInfoMonth> queryWrapper) {
+        return super.list(queryWrapper);
+    }
+
+    public List<StationInfoMonth> getInfoByDate(Date date) {
+        QueryWrapper<StationInfoMonth> wrapper = new QueryWrapper<>();
+        wrapper.eq("record_date", date);
+        return super.list(wrapper);
+    }
+
+    public List<StationInfoMonth> getInfoByDate(Date date, List<PointInfo> entity) {
+        List<StationInfoMonth> list = getInfoByDate(date);
+        if (CollUtil.isEmpty(list)) {
+            entity.forEach(pi -> {
+                StationInfoMonth day = new StationInfoMonth();
+                day.setStationId(pi.getStationId());
+                day.setRecordDate(date);
+                list.add(day);
+            });
+        }
+        return list;
+    }
+
+    public Map<String, StationInfoMonth> getInfoByDateMap(Date date, List<PointInfo> entity) {
+        List<StationInfoMonth> list = getInfoByDate(date, entity);
+        return list.stream().collect(Collectors.toMap(StationInfoMonth::getStationId, Function.identity()));
+    }
+}