Browse Source

修改物业端公众号BUG

yang 4 years ago
parent
commit
8df996215e

+ 32 - 0
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/dao/mapper/PropertyMapper.java

@@ -10,6 +10,38 @@ import java.time.LocalDate;
 import java.util.List;
 
 public interface PropertyMapper {
+
+    /**
+     * @param userId    用户ID
+     * @param yearMonth 月份
+     * @return
+     */
+    @Select(SqlConstants.queryData)
+    List<MaintenancePlanMonthTaskNum> queryData(Long userId, String yearMonth);
+
+    /**
+     * 查询待保养和超期数据
+     *
+     * @param page
+     * @param planDate
+     * @param userId
+     * @return
+     */
+    @Select(SqlConstants.queryDataByPlanTB)
+    IPage<PropertyMtResponse> queryDataByPlanTB(IPage<PropertyMtResponse> page, Integer status, LocalDate planDate, Long userId);
+
+
+    /**
+     * 查询待保养中和已完成数据
+     *
+     * @param page
+     * @param planDate
+     * @param userId
+     * @return
+     */
+    @Select(SqlConstants.queryDataByRecordTB)
+    IPage<PropertyMtResponse> queryDataByRecordTB(IPage<PropertyMtResponse> page, Integer status, LocalDate planDate, Long userId);
+
     @Select(SqlConstants.QUERY_MAINTENANCE_PLAN_EVERYDAY)
     IPage<PropertyMtResponse> queryMaintenancePlanEveryDay(IPage<PropertyMtResponse> page, Integer status, LocalDate planDate, Long userId);
 

+ 21 - 9
lift-business-service/src/main/java/cn/com/ty/lift/business/maintenance/service/PropertyService.java

@@ -65,7 +65,20 @@ public class PropertyService {
      * @return 日历
      */
     public RestResponse<?> queryMaintenancePlanMonth(PropertyMaintenanceVO propertyMaintenanceVO) {
-        List<MaintenancePlanMonthTaskNum> planNums = propertyMapper.queryMaintenancePlanMonth(propertyMaintenanceVO.getUserId(), propertyMaintenanceVO.getYearMonth());
+
+        //用户ID
+        Long userId = propertyMaintenanceVO.getUserId();
+        //月份
+        String yearMonth = propertyMaintenanceVO.getYearMonth();
+
+        /**
+         * 状态 为key 1.已完成
+         *      2.保养中
+         *      0.待保养
+         *      -1 计划超期  响应到前端为3
+         */
+        List<MaintenancePlanMonthTaskNum> planNums = propertyMapper.queryData(userId, yearMonth);
+
         if (planNums.isEmpty()) {
             return RestResponse.success();
         }
@@ -130,7 +143,7 @@ public class PropertyService {
      * @return 分页查询某人加入的项目下电梯某天(待保养 / 保养中 / 已完成 / 超期 / 法规超期)的维保任务
      */
     public IPage<PropertyMtResponse> propertyMtResponsePage(IPage<PropertyMtResponse> propertyMtResponsePage, PropertyMaintenanceVO propertyMaintenanceVO) {
-        IPage<PropertyMtResponse> page;
+        IPage<PropertyMtResponse> page = null;
         Integer maintenanceStatus = ApiConstants.Maintenance.WAITING_MAINTENANCE;
         switch (propertyMaintenanceVO.getType()) {
             case 1:
@@ -155,13 +168,12 @@ public class PropertyService {
                             propertyMtResponsePage,
                             propertyMaintenanceVO.getPlanDate(),
                             propertyMaintenanceVO.getUserId());
-        } else {
-            page = propertyMapper
-                    .queryMaintenancePlanEveryDay(
-                            propertyMtResponsePage,
-                            maintenanceStatus,
-                            propertyMaintenanceVO.getPlanDate(),
-                            propertyMaintenanceVO.getUserId());
+        } else if (Objects.equals(maintenanceStatus, 0) || Objects.equals(maintenanceStatus, -1)) {
+            //待保养和超期查询计划表
+            page = propertyMapper.queryDataByPlanTB(propertyMtResponsePage, maintenanceStatus, propertyMaintenanceVO.getPlanDate(), propertyMaintenanceVO.getUserId());
+        } else if (Objects.equals(maintenanceStatus, 1) || Objects.equals(maintenanceStatus, 2)) {
+            //保养中和已完成查询记录表
+            page = propertyMapper.queryDataByRecordTB(propertyMtResponsePage, maintenanceStatus, propertyMaintenanceVO.getPlanDate(), propertyMaintenanceVO.getUserId());
         }
         return page;
     }

+ 40 - 0
lift-common/src/main/java/cn/com/ty/lift/common/constants/SqlConstants.java

@@ -1,6 +1,46 @@
 package cn.com.ty.lift.common.constants;
 
 public interface SqlConstants {
+
+    /**
+     * 查询某日待保养或超期的数据
+     */
+    String queryDataByPlanTB =
+            "SELECT p.project_name as projectName,l.registration_code as registrationCode ,l.device_position as devicePosition,\n" +
+            "l.lift_type as liftType ,l.category,ui.`name` as workerName ,mp.plan_date  as planDate\n" +
+            "FROM maintenance_plan as mp LEFT JOIN lift as l on mp.lift_id=l.id\n" +
+            "LEFT JOIN user_info as ui on  mp.worker_id=ui.user_id\n" +
+            "LEFT JOIN project as p on mp.project_id=p.id where project_id IN (SELECT project_id FROM project_user WHERE user_id =   #{userId})\n" +
+            "and  mp.plan_date=#{planDate} and mp.`status`=#{status}";
+
+    /**
+     * 查询某日保养中或已完成的数据
+     */
+    String queryDataByRecordTB =
+            "SELECT mr.id as recordId,p.project_name as projectName,l.registration_code as registrationCode ,l.device_position as devicePosition,\n" +
+            "l.lift_type as liftType ,l.category,ui.`name` as workerName ,mp.plan_date  as planDate ,\n" +
+            "mr.recovery_date as recoveryDate,mr.has_evaluate as hasEvaluate\n" +
+            "from maintenance_record as mr LEFT JOIN maintenance_plan as mp on mr.mt_plan_id=mp.id LEFT JOIN lift as l on mp.lift_id=l.id\n" +
+            "LEFT JOIN user_info as ui on  mp.worker_id=ui.user_id\n" +
+            "LEFT JOIN project as p on mp.project_id=p.id \n" +
+            "where mp.project_id IN (SELECT project_id FROM project_user WHERE user_id =  #{userId})\n" +
+            "and DATE_FORMAT(mr.work_date, '%Y-%m-%d') = #{planDate} and IF(mr.recovery_date is null,2,1)= #{status}";
+
+    /**
+     * 查询日历
+     */
+    String queryData =
+            "-- 待保养和超期查询计划表\n" +
+                    "SELECT DATE_FORMAT(plan_date, '%d') DAY,`status` `status`,count(`status`) count\n" +
+                    "FROM maintenance_plan WHERE project_id IN ( SELECT project_id\tFROM\tproject_user\tWHERE\tuser_id = #{userId})\n" +
+                    "AND DATE_FORMAT(plan_date, '%Y-%m') =#{yearMonth} AND `status` IN (0 ,-1) GROUP BY\tplan_date,\t`status`\n" +
+                    "UNION ALL\n" +
+                    "--  保养中和已完成查询记录表\n" +
+                    "SELECT DAY,`status`, count(`status`) AS count FROM(SELECT\tIF (recovery_date IS NULL, 2, 1) AS `status`,\tDATE_FORMAT(work_date, '%d') DAY\n" +
+                    "FROM\tmaintenance_record\tWHERE\tproject_id IN (\tSELECT project_id FROM project_user WHERE\tuser_id = #{userId})\n" +
+                    "AND DATE_FORMAT(work_date, '%Y-%m') = #{yearMonth}) AS a GROUP BY DAY,`status`";
+
+
     //根据用户id和维保计划时间和状态查询用户那一天的各种类型维保任务(待保养/保养中/已完成/计划超期)
     String QUERY_MAINTENANCE_PLAN_EVERYDAY =
             "select         mr.id recordId," +