Browse Source

首页保修曲线

LIVE_YE 4 months ago
parent
commit
f8b70c1937

+ 9 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/propertyRepair/PropertyRepairController.java

@@ -109,4 +109,13 @@ public class PropertyRepairController extends BaseController {
     public AjaxResult assign(@RequestBody PropertyRepair propertyRepair) {
         return propertyRepairService.assign(propertyRepair);
     }
+
+    /**
+     * 物业保修一周统计(当前时间往前推7天)
+     */
+    @PreAuthorize("@ss.hasPermi('wuYe:repair:statistics:qx')")
+    @GetMapping("/statistics/qx")
+    public AjaxResult statisticsQx() {
+        return propertyRepairService.statisticsQx();
+    }
 }

+ 16 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java

@@ -6,7 +6,10 @@ import java.lang.management.ManagementFactory;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.*;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 时间工具类
@@ -190,4 +193,17 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
         return Date.from(zdt.toInstant());
     }
+
+    // 返回过去7天的日期字符串列表,包含今天(自定义格式)
+    public static List<String> getPreviousSevenDays(String pattern) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
+        List<String> dateStrings = new ArrayList<>(7);
+        LocalDate today = LocalDate.now();
+        for (int i = 6; i >= 0; i--) {
+            dateStrings.add(today.minusDays(i).format(formatter));
+        }
+        return dateStrings;
+    }
+
+
 }

+ 3 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PropertyRepairMapper.java

@@ -1,6 +1,7 @@
 package com.ruoyi.system.mapper;
 
 import com.ruoyi.system.domain.propertyRepair.PropertyRepair;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -60,4 +61,6 @@ public interface PropertyRepairMapper
      * @return 结果
      */
     public int deletePropertyRepairByRepairIds(Long[] repairIds);
+
+    public List<PropertyRepair> selectPropertyRepairListByTime(@Param("starTime") String starTime, @Param("endTime")String endTime);
 }

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IPropertyRepairService.java

@@ -66,4 +66,6 @@ public interface IPropertyRepairService
      * @return 结果
      */
     public int deletePropertyRepairByRepairId(Long repairId);
+
+    AjaxResult statisticsQx();
 }

+ 27 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PropertyRepairServiceImpl.java

@@ -10,7 +10,10 @@ import com.ruoyi.system.service.IPropertyRepairService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import static com.ruoyi.common.constant.Constants.*;
 
@@ -132,4 +135,28 @@ public class PropertyRepairServiceImpl implements IPropertyRepairService
     {
         return propertyRepairMapper.deletePropertyRepairByRepairId(repairId);
     }
+
+    @Override
+    public AjaxResult statisticsQx() {
+        List<Map<String,Object>> mapList = new ArrayList<>();
+        List<String> weekDays = DateUtils.getPreviousSevenDays(DateUtils.YYYY_MM_DD);
+        String starTime = weekDays.get(0);
+        String endTime = weekDays.get(weekDays.size()-1);
+        //查询两个日期内的保修数据
+        List<PropertyRepair> propertyRepairs = propertyRepairMapper.selectPropertyRepairListByTime(starTime, endTime);
+        for (int i = 0; i < weekDays.size(); i++) {
+            Map<String,Object> map = new HashMap<>();
+            map.put("time",weekDays.get(i));
+            int num = 0;
+            for (PropertyRepair propertyRepair : propertyRepairs) {
+                String day = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, propertyRepair.getRepairTime());
+                if(day.equals(weekDays.get(i))){
+                    num++;
+                }
+            }
+            map.put("num",num);
+            mapList.add(map);
+        }
+        return AjaxResult.success(mapList);
+    }
 }

+ 5 - 0
ruoyi-system/src/main/resources/mapper/system/PropertyRepairMapper.xml

@@ -61,6 +61,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectPropertyRepairVo"/>
         where repair_id = #{repairId}
     </select>
+    <select id="selectPropertyRepairListByTime" parameterType="PropertyRepair" resultMap="PropertyRepairResult">
+        <include refid="selectPropertyRepairVo"/>
+        where date_format(repair_time,'%Y%m%d') &gt;= date_format(#{starTime},'%Y%m%d')
+              AND date_format(repair_time,'%Y%m%d') &lt;= date_format(#{endTime},'%Y%m%d')
+    </select>
 
     <insert id="insertPropertyRepair" parameterType="PropertyRepair" useGeneratedKeys="true" keyProperty="repairId">
         insert into property_repair