فهرست منبع

优化项目设备月新增功能

Simon 1 سال پیش
والد
کامیت
4b4bf2ae73

+ 8 - 28
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TDataDisplayController.java

@@ -1,7 +1,6 @@
 package com.ruoyi.web.controller.system;
 
 import com.alibaba.fastjson.JSONObject;
-import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysDictData;
@@ -12,12 +11,15 @@ import com.ruoyi.system.domain.TEarlyWarning;
 import com.ruoyi.system.domain.dto.*;
 import com.ruoyi.system.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 import java.math.BigDecimal;
-import java.text.NumberFormat;
-import java.time.LocalDate;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -223,29 +225,7 @@ public class TDataDisplayController extends BaseController {
      */
     @GetMapping("/addDevice")
     public AjaxResult addDevice() {
-        List<AddDeviceDto> dtoList = tDeviceListService.selectAddDevice();
-        LocalDate currentDate = LocalDate.now();
-        LocalDate lastMonthDate = currentDate.minusMonths(1);
-        int year = currentDate.getYear();
-        if (dtoList.size() == 2) {
-            int lastMonth = lastMonthDate.getMonthValue() - 1;
-            AddDeviceDto dto = new AddDeviceDto();
-            dto.setMonth(year + "-0" + lastMonth);
-            dto.setCount(0);
-            dtoList.add(dto);
-        } else if (dtoList.size() == 1) {
-            int lastMonth = lastMonthDate.getMonthValue();
-            int lastlastMonth = lastMonthDate.getMonthValue() - 1;
-            AddDeviceDto dto = new AddDeviceDto();
-            dto.setMonth(year + "-0" + lastMonth);
-            dto.setCount(0);
-            dtoList.add(dto);
-            AddDeviceDto dto1 = new AddDeviceDto();
-            dto1.setMonth(year + "-0" + lastlastMonth);
-            dto1.setCount(0);
-            dtoList.add(dto1);
-        }
-        dtoList = dtoList.stream().sorted(Comparator.comparing(AddDeviceDto::getMonth)).collect(Collectors.toList());
+        List<AddDeviceDto> dtoList = tDeviceListService.selectAddDeviceV1();
         return success(dtoList);
     }
 

+ 9 - 2
ruoyi-system/src/main/java/com/ruoyi/system/mapper/TDeviceListMapper.java

@@ -1,10 +1,10 @@
 package com.ruoyi.system.mapper;
 
-import java.util.List;
-
 import com.ruoyi.system.domain.TDeviceList;
 import com.ruoyi.system.domain.dto.*;
 
+import java.util.List;
+
 /**
  * 设备列Mapper接口
  *
@@ -250,4 +250,11 @@ public interface TDeviceListMapper {
      * @return 结果
      */
     public List<AddDeviceDto> selectAddDevice();
+
+    /**
+     * 设备新增
+     *
+     * @return 结果
+     */
+    public List<AddDeviceDto> selectAddDeviceV1();
 }

+ 8 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ITDeviceListService.java

@@ -1,10 +1,10 @@
 package com.ruoyi.system.service;
 
-import java.util.List;
 import com.ruoyi.system.domain.TDeviceList;
-import com.ruoyi.system.domain.TServiceManage;
 import com.ruoyi.system.domain.dto.*;
 
+import java.util.List;
+
 /**
  * 设备列Service接口
  * 
@@ -169,6 +169,12 @@ public interface ITDeviceListService
      * @return 结果
      */
     public List<AddDeviceDto> selectAddDevice();
+    /**
+     * 设备新增
+     *
+     * @return 结果
+     */
+    public List<AddDeviceDto> selectAddDeviceV1();
 
     /**
      * 查询设备绑定用户数

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TDeviceListServiceImpl.java

@@ -505,6 +505,10 @@ public class TDeviceListServiceImpl implements ITDeviceListService {
     public List<AddDeviceDto> selectAddDevice() {
         return tDeviceListMapper.selectAddDevice();
     }
+    @Override
+    public List<AddDeviceDto> selectAddDeviceV1() {
+        return tDeviceListMapper.selectAddDeviceV1();
+    }
 
     @Override
     public Integer selectTDeviceListBandUser() {

+ 6 - 0
ruoyi-system/src/main/resources/mapper/system/TDeviceListMapper.xml

@@ -147,6 +147,12 @@
         WHERE createtime > DATE_SUB(NOW(), INTERVAL 3 MONTH)
         GROUP BY month;
     </select>
+    <select id="selectAddDeviceV1" resultType="com.ruoyi.system.domain.dto.AddDeviceDto">
+        SELECT DATE_FORMAT(createtime, '%Y-%m') AS month, COUNT(*) AS count
+        FROM t_device_list
+        GROUP BY month
+        ORDER BY month;
+    </select>
     <select id="selectTDeviceListBandUser" resultType="java.lang.Integer">
         select count(distinct userid)
         from t_device_list