فهرست منبع

物管日历功能完善

wanghaicheng 5 سال پیش
والد
کامیت
b32b875bef

+ 7 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/controller/PropertyMaintenanceController.java

@@ -3,6 +3,7 @@ package cn.com.ty.lift.business.maintenance.controller;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.request.PropertyMaintenanceVO;
 import cn.com.ty.lift.business.maintenance.dao.entity.model.response.PropertyMtResponse;
 import cn.com.ty.lift.business.maintenance.dao.mapper.PropertyMaintenanceMapper;
+import cn.com.ty.lift.business.maintenance.service.PropertyMaintenanceService;
 import cn.com.ty.lift.common.constants.ApiConstants;
 import cn.com.xwy.boot.web.dto.RestResponse;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
 @RequestMapping("property")
 public class PropertyMaintenanceController {
     private final PropertyMaintenanceMapper propertyMaintenanceMapper;
+    private final PropertyMaintenanceService propertyMaintenanceService;
 
     @PostMapping("maintenance")
     public RestResponse maintenance(@RequestBody PropertyMaintenanceVO propertyMaintenanceVO) {
@@ -55,4 +57,9 @@ public class PropertyMaintenanceController {
                         propertyMaintenanceVO.getUserId());
         return page;
     }
+
+    @PostMapping("maintenance/num/month")
+    public RestResponse<?> maintenanceNumForMonth(@RequestBody PropertyMaintenanceVO propertyMaintenanceVO) {
+        return propertyMaintenanceService.queryMaintenancePlanMonth(propertyMaintenanceVO);
+    }
 }

+ 1 - 1
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/entity/model/dto/MaintenancePlanMonthTaskNum.java

@@ -4,7 +4,7 @@ import lombok.Data;
 
 @Data
 public class MaintenancePlanMonthTaskNum {
-    private Integer month;
+    private Integer day;
     private Integer status;
     private Integer count;
 }

+ 5 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/entity/model/request/PropertyMaintenanceVO.java

@@ -28,4 +28,9 @@ public class PropertyMaintenanceVO {
      */
     private Long pageNum = 1L;
     private Long pageSize = 10L;
+
+    /**
+     * 年月  例 202005  2020年5月
+     */
+    private String yearMonth;
 }

+ 19 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/entity/model/response/PropertyCalendarResponse.java

@@ -0,0 +1,19 @@
+package cn.com.ty.lift.business.maintenance.dao.entity.model.response;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+public class PropertyCalendarResponse {
+    private Integer key;
+    private List<Values> value = new ArrayList<>();
+
+    @Data
+    public static class Values {
+        private Integer key;
+        private Integer value;
+    }
+}
+

+ 81 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/service/PropertyMaintenanceService.java

@@ -0,0 +1,81 @@
+package cn.com.ty.lift.business.maintenance.service;
+
+import cn.com.ty.lift.business.maintenance.dao.entity.model.dto.MaintenancePlanMonthTaskNum;
+import cn.com.ty.lift.business.maintenance.dao.entity.model.request.PropertyMaintenanceVO;
+import cn.com.ty.lift.business.maintenance.dao.entity.model.response.PropertyCalendarResponse;
+import cn.com.ty.lift.business.maintenance.dao.mapper.PropertyMaintenanceMapper;
+import cn.com.xwy.boot.web.dto.RestResponse;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+@AllArgsConstructor
+@Slf4j
+public class PropertyMaintenanceService {
+    private final PropertyMaintenanceMapper propertyMaintenanceMapper;
+
+    /**
+     * @param propertyMaintenanceVO userId用户id,yearMonth年月 例202005即2020年5月
+     * @return 日历
+     */
+    public RestResponse<?> queryMaintenancePlanMonth(PropertyMaintenanceVO propertyMaintenanceVO) {
+        List<MaintenancePlanMonthTaskNum> planNums = propertyMaintenanceMapper.queryMaintenancePlanMonth(propertyMaintenanceVO.getUserId(), propertyMaintenanceVO.getYearMonth());
+        if (planNums.isEmpty()) {
+            return RestResponse.success();
+        }
+        log.info(planNums.toString());
+        List<PropertyCalendarResponse> calendar = new ArrayList<>();
+        //循环每日,每种状态的维保计划
+        for (MaintenancePlanMonthTaskNum planNum : planNums) {
+            numToCalendar(calendar, planNum);
+        }
+        return RestResponse.success(calendar);
+    }
+
+    /**
+     * 维保计划每日每个状态的数量转前端日历所需格式
+     *
+     * @param calendar 日历
+     * @param planNum  计划数量
+     */
+    private void numToCalendar(List<PropertyCalendarResponse> calendar, MaintenancePlanMonthTaskNum planNum) {
+        boolean hasDay = false;
+        boolean hasStatus = false;
+        //遍历每日
+        for (PropertyCalendarResponse day : calendar) {
+            if (day.getKey().equals(planNum.getDay())) {
+                hasDay = true;
+                //遍历每日的每个状态
+                for (PropertyCalendarResponse.Values status : day.getValue()) {
+                    if (status.getKey().equals(planNum.getStatus())) {
+                        hasStatus = true;
+                        status.setValue(planNum.getCount());
+                    }
+                }
+                //如果遍历到的日期,没有这个状态,新增这个状态
+                if (!hasStatus) {
+                    PropertyCalendarResponse.Values status = new PropertyCalendarResponse.Values();
+                    status.setKey(planNum.getStatus());
+                    status.setValue(planNum.getCount());
+                    day.getValue().add(status);
+                }
+            }
+        }
+        //如果日历中没有这个日期,新增这个日期
+        if (!hasDay) {
+            PropertyCalendarResponse day = new PropertyCalendarResponse();
+            day.setKey(planNum.getDay());
+            List<PropertyCalendarResponse.Values> statuses = day.getValue();
+            PropertyCalendarResponse.Values status = new PropertyCalendarResponse.Values();
+            status.setKey(planNum.getStatus());
+            status.setValue(planNum.getCount());
+            statuses.add(status);
+            day.setValue(statuses);
+            calendar.add(day);
+        }
+    }
+}

+ 4 - 4
lift-common/src/main/java/cn.com.ty.lift.common/constants/ApiConstants.java

@@ -419,10 +419,10 @@ public class ApiConstants {
 
         //物管,根据用户id和月份,查询那一月每天的(待保养/保养中/已完成/计划超期/法规超期)的数量
         String QUERY_MAINTENANCE_PLAN_MONTH_TASK_NUM =
-                "select DATE_FORMAT(plan_date, '%m') month, status, count(status) count" +
-                        "from maintenance_plan" +
-                        "where project_id in (select project_id from project_user where user_id = #{userId})" +
+                "select DATE_FORMAT(plan_date, '%d') day, status, count(status) count" +
+                        "   from maintenance_plan" +
+                        "   where project_id in (select project_id from project_user where user_id = #{userId})" +
                         "  and DATE_FORMAT(plan_date, '%Y%m') = #{yearMonth}" +
-                        "group by plan_date, status";
+                        "   group by plan_date, status";
     }
 }