Bläddra i källkod

1、微校消息通知代码优化
2、寝室管理代码优化

binguoc 4 år sedan
förälder
incheckning
0869aeee93

+ 5 - 1
pom.xml

@@ -79,7 +79,11 @@
             <version>2.1.2</version>
         </dependency>
 
-
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>

+ 2 - 1
src/main/java/com/chuanghai/repair/RepairsApplication.java

@@ -12,11 +12,12 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 
 @SpringBootApplication
 @EnableScheduling //设置定时任务
+@EnableCaching
 public class RepairsApplication {
 
     public static void main(String[] args) {
 
-       SpringApplication.run(RepairsApplication.class, args);
+        SpringApplication.run(RepairsApplication.class, args);
 
     }
 

+ 40 - 0
src/main/java/com/chuanghai/repair/auth/CacheListener.java

@@ -0,0 +1,40 @@
+package com.chuanghai.repair.auth;
+
+import com.chuanghai.repair.service.ServiceImpl.CacheManagerImpl;
+import com.chuanghai.repair.utils.CreateTokenUtil;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.logging.Logger;
+
+/**
+ * @Author: bingo
+ * @Date: 2022/3/4 星期五 13:09
+ * @Description: com.chuanghai.repair.auth
+ * @version: 1.0
+ */
+public class CacheListener {
+    Logger logger = Logger.getLogger("cacheLog");
+    private CacheManagerImpl cacheManagerImpl;
+
+    public CacheListener(CacheManagerImpl cacheManagerImpl) {
+        this.cacheManagerImpl = cacheManagerImpl;
+    }
+
+    public void startListen() {
+        new Thread() {
+            public void run() {
+                    while (true) {
+                        for (String key : cacheManagerImpl.getAllKeys()) {
+                            if (cacheManagerImpl.isTimeOut(key)) {
+                                cacheManagerImpl.clearByKey(key);
+                                logger.info(key + "缓存被清除");
+                            }
+                        }
+                    }
+            }
+        }.start();
+
+    }
+}

+ 50 - 241
src/main/java/com/chuanghai/repair/controller/AutoSendOrderCentroller.java

@@ -2,12 +2,17 @@ package com.chuanghai.repair.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.chuanghai.repair.auth.CacheListener;
 import com.chuanghai.repair.entity.RepairsOrder;
 import com.chuanghai.repair.service.RepairsOrderService;
 import com.chuanghai.repair.service.RepairsWorkService;
+import com.chuanghai.repair.service.ServiceImpl.CacheManagerImpl;
 import com.chuanghai.repair.utils.CreateTokenUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.http.HttpEntity;
@@ -25,6 +30,7 @@ import javax.annotation.Resource;
 import java.net.URI;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @Author: bingo
@@ -37,7 +43,6 @@ import java.util.*;
  */
 
 
-@Api(tags = "自动派单管理")
 @RestController
 @RequestMapping("/auto")
 public class AutoSendOrderCentroller implements ApplicationListener<ContextRefreshedEvent> {
@@ -51,258 +56,62 @@ public class AutoSendOrderCentroller implements ApplicationListener<ContextRefre
 
     static HashMap<String, String> orderMap = new HashMap<>();
 
-    @ApiOperation("自动查询订单")
-    @Override
-    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
-
-    }
-
 
 
-}
-/**
-     * 优化: 在订单表加个字段(订单类型  水电工 木工等)对应维修工的类型       根据未接单  订单类型 将木工订单分配给木工师傅
-     *//*
-
-    @ApiOperation("自动分配订单")
-    @PostMapping(value = "/autoSendOrder")
     @Override
     public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
-        autoSends();
+        String accessTokenGlobal = CreateTokenUtil.getAccessTokenGlobal();
+        CacheManagerImpl cacheManagerImpl = new CacheManagerImpl();
+        CacheListener cacheListener = new CacheListener(cacheManagerImpl);
+        cacheManagerImpl.putCache("cache_token", accessTokenGlobal, 2*3610 * 1000L); //access_token 在2*3600*1000L 过期
+        cacheListener.startListen();
+        autoQueryOrder();
 
     }
 
-    */
-/**
-     * 设置每半小时执行一次
-     *//*
-
-    @Scheduled(cron="0 0/30 * * * ?")
-    public void autoSends(){
+    @Scheduled(cron = "0 0/30 * * * ?") //    0 0/30 * * * ?    30分钟调用一次
+    public void autoQueryOrder(){
+        String accessTokenGlobal = CreateTokenUtil.getAccessTokenGlobal();
+        CacheManagerImpl cacheManagerImpl = new CacheManagerImpl();
+        CacheListener cacheListener = new CacheListener(cacheManagerImpl);
+        cacheManagerImpl.putCache("cache_token", accessTokenGlobal, 2*3610 * 1000L); //access_token 在2*3600*1000L 过期
+        cacheListener.startListen();
         try {
-            //查询所有未接单的订单实体信息  木工订单
-            List<String> woodOrderList = repairsOrderService.queryOrderByType("2","0");
-            //查询所有在岗维修工  木工师傅
-            List<String> woodWork = repairsWorkService.queryAllWork("2");
-            autoSend(woodOrderList, woodWork);
-            //查询所有未接单的订单实体信息  空调订单
-            List<String> airOrderList = repairsOrderService.queryOrderByType("1","0");
-            //查询所有在岗维修工  空调师傅
-            List<String> airWork = repairsWorkService.queryAllWork("1");
-            autoSend(airOrderList, airWork);
-            //查询所有未接单的订单实体信息  水电订单
-            List<String> waterOrderList = repairsOrderService.queryOrderByType("0","0");
-            //查询所有在岗维修工  水电师傅
-            List<String> waterWork = repairsWorkService.queryAllWork("0");
-            autoSend(waterOrderList, waterWork);
-
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-    }
-    */
-/**
-     * 封装的自动派单方法 传入订单列表  和  员工列表
-     *
-     * @param orderLists
-     * @param workLists
-     *//*
-
-    private void autoSend(List<String> orderLists, List<String> workLists) {
-        try {
-
-            //创建任务列表
-            List<Task> taskList = new ArrayList<Task>();
-
-
-            //将木工订单实体信息中的订单ID存入任务集合中
-            for (String orderList : orderLists) {
-                taskList.add(new Task(orderList));
-
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            Calendar calendar = Calendar.getInstance();
+            String systemTime = sdf.format(calendar.getTime());
+            calendar.add(Calendar.MINUTE, 30);
+            String changeTime = sdf.format(calendar.getTime());
+
+            List<RepairsOrder> orderList = repairsOrderService.queryByTime(systemTime, changeTime);
+            String idList = orderList.stream().filter(e -> e.getRepairsStudent() != null)
+                    .map(e -> e.getRepairsStudent().getStudentId()).collect(Collectors.toSet()).toString();
+
+            String title = "寝室维修通知";
+            String content = "同学你好,你的寝室报修单已被维修师傅接单,维修师傅将于半小时后上门维修;请合理安排时间,谢谢合作。";
+            String sender = "寝室管理办公室";
+            String access_token = new CacheManagerImpl().getCacheByKey("cache_token").getDatas().toString();
+            System.out.println(access_token);
+            for (String key : cacheManagerImpl.getAllKeys()) {
+                System.out.println("key:------------value:  "+new CacheManagerImpl().getCacheByKey(key).getDatas().toString());
             }
-
-            //在岗木工维修工人数
-            int threadCount = workLists.size();
-            List[] taskPerThreadCount = distributeTasks(taskList, threadCount);
-            // System.out.println("实际要启动的工作线程:" + taskPerThreadCount.length);
-            if (taskPerThreadCount != null) {
-                for (int i = 0; i < taskPerThreadCount.length; i++) {
-                    Thread workThread = new WorkThread(taskPerThreadCount[i], i);
-
-                    workThread.setName(workLists.get(i));
-                    workThread.start();
-
-                }
-            }
-
-
+            Map<String, String> param = new HashMap<>();
+            param.put("title", title);
+            param.put("cards", idList);
+            param.put("content", content);
+            param.put("sender", sender);
+            String url = "https://open.wecard.qq.com/cgi-bin/notice/send?access_token=" + access_token;
+
+            RestTemplate restTemplate = new RestTemplate();
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity<Map<String, String>> request = new HttpEntity<>(param, headers);
+            ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
+
+            System.out.println(responseEntity.getBody());
         } catch (Exception e) {
             e.printStackTrace();
         }
-
-    }
-
-
-    */
-/**
-     * 线程分配任务
-     *
-     * @param taskList
-     * @param threadCount
-     * @return
-     *//*
-
-    public List[] distributeTasks(List<Task> taskList, int threadCount) {
-        // 每个线程至少要执行的任务数,如果不为零,则每个线程都会分到任务;
-        if (threadCount != 0) {
-            int minTaskCount = taskList.size() / threadCount;
-
-
-            //  System.out.println(minTaskCount + " minTaskCount");
-            // 剩下的任务数,如果不为零,则依个添加到前面的线程中.
-            int remainTaskCount = taskList.size() % threadCount;
-
-            //  System.out.println(remainTaskCount + " remainTaskCount");
-            // 实际要启动的线程个数,如果工作线程比较任务还多,则只需要启动与任务数相同的工作
-            // 线程,一对一工作,
-            int actualThreadCount = minTaskCount > 0 ? threadCount
-                    : remainTaskCount;
-            // System.out.println(actualThreadCount + " actualThreadCount");
-            // 要启动的线程数组,以及每个线程执行的任务列表.
-            List<Task>[] taskListPerThread = new List[actualThreadCount];
-            int taskIndex = 0;
-            int remainIndces = remainTaskCount;
-            for (int i = 0, n = taskListPerThread.length; i < n; i++) {
-                taskListPerThread[i] = new ArrayList();
-                if (minTaskCount > 0) {
-                    for (int j = taskIndex; j < minTaskCount + taskIndex; j++) {
-                        taskListPerThread[i].add(taskList.get(j));
-                    }
-                    taskIndex += minTaskCount;
-                }
-                if (remainIndces > 0) {
-                    taskListPerThread[i].add(taskList.get(taskIndex++));
-                    remainIndces--;
-                }
-            }
-            for (int i = 0, n = taskListPerThread.length; i < n; i++) {
-//                System.out.println("线程 "
-//                        + i
-//                        + " 的任务数:"
-//                        + taskListPerThread[i].size()
-//                        + " 区间["
-//                        + taskListPerThread[i].get(0).getTaskId()
-//                        + ","
-//                        + taskListPerThread[i].get(taskListPerThread[i].size() - 1)
-//                        .getTaskId() + "]");
-
-            }
-            return taskListPerThread;
-        }
-        return null;
-
-    }
-
-
-    */
-/**
-     * 订单的任务队列
-     *//*
-
-    public class Task {
-        private static final int READY = 0;
-        private static final int RUNNING = 1;
-        private static final int FINISHED = 2;
-        private int status;
-        private String taskId;
-
-
-        public Task(String taskid) {
-            this.status = READY;
-            this.taskId = taskid;
-        }
-
-
-        public void execute() {
-            try {
-                setStatus(RUNNING);
-
-
-                orderMap.put("orderId", taskId);
-                orderMap.put("workId", Thread.currentThread().getName());
-                if (orderMap != null) {
-                    // 将map中的所有键去取出来,用迭代器进行读取
-                    Set set = orderMap.keySet();
-                    if (set != null) {
-                        Iterator iterator = set.iterator();
-                        while (iterator.hasNext()) {
-                            // 取出单个的map键
-                            String key = (String) iterator.next();
-                            String value = orderMap.get(key);
-                            System.out.println("key = " + key + "value" + value);
-                        }
-                    }
-
-                }
-
-
-
-                repairsOrderService.updateOrderWorkId(orderMap);
-
-//                System.out.println("当前的线程ID是:" + Thread.currentThread().getName()
-//                        + "   任务ID是:" + taskId);
-                Thread.sleep(3000);
-                //orderMap.put("workId",Thread.currentThread().getName());
-
-
-            } catch (InterruptedException e) {
-                // TODO Auto-generated catch block
-                e.printStackTrace();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            setStatus(FINISHED);
-        }
-
-
-        public void setStatus(int status) {
-            this.status = status;
-        }
-
-        public String getTaskId() {
-            return taskId;
-        }
-
-
     }
 
-    */
-/**
-     * 维修工的任务队列
-     *//*
-
-    public class WorkThread extends Thread {
-        private List<Task> taskList = null;
-        private int threadId;
-
-        public WorkThread(List<Task> taskList, int threadid) {
-            this.taskList = taskList;
-            this.threadId = threadid;
-        }
-
-        @Override
-        public void run() {
-            // TODO Auto-generated method stub
-            for (Task task : taskList) {
-                task.execute();
-            }
-
-
-        }
-    }
-
-
 }
-*/

+ 42 - 95
src/main/java/com/chuanghai/repair/controller/LoginController.java

@@ -2,31 +2,28 @@ package com.chuanghai.repair.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.chuanghai.repair.entity.RepairsAdmin;
-import com.chuanghai.repair.entity.RepairsOrder;
-import com.chuanghai.repair.entity.RepairsStudent;
-import com.chuanghai.repair.entity.RepairsWork;
+import com.chuanghai.repair.auth.CacheListener;
+import com.chuanghai.repair.entity.*;
 import com.chuanghai.repair.service.RepairsAdminService;
 import com.chuanghai.repair.service.RepairsOrderService;
 import com.chuanghai.repair.service.RepairsStudentService;
 import com.chuanghai.repair.service.RepairsWorkService;
+import com.chuanghai.repair.service.ServiceImpl.CacheManagerImpl;
+import com.chuanghai.repair.utils.CreateTokenUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
-import lombok.Getter;
-import lombok.Setter;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.*;
 import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
-import java.net.URI;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Logger;
 import java.util.stream.Collectors;
 
 /**
@@ -53,10 +50,6 @@ public class LoginController {
     @Resource(name = "repairsOrderService")
     private RepairsOrderService repairsOrderService;
 
-    @Setter
-    @Getter
-    private String accessToken;
-
 
     /**
      * 管理员登录
@@ -71,7 +64,7 @@ public class LoginController {
         String adminIdToken = "";
         try {
             RepairsAdmin repairsAdmin = repairsAdminService.loginAdmin(phone, password);
-         //   adminIdToken = CreateTokenUtil.getToken(String.valueOf(repairsAdmin.getAdminId()));
+            adminIdToken = CreateTokenUtil.getToken(String.valueOf(repairsAdmin.getAdminId()));
 
         } catch (Exception e) {
             e.printStackTrace();
@@ -89,11 +82,11 @@ public class LoginController {
     @ApiOperation("维修工登录")
     @PostMapping(value = "/loginWork")
     public String loginWork(@ApiParam(name = "维修工手机号码", required = true) String phone,
-                                 @ApiParam(name = "维修工登录密码", required = true) String password) {
+                            @ApiParam(name = "维修工登录密码", required = true) String password) {
         String workIdToken = "";
         try {
             RepairsWork repairsWork = repairsWorkService.loginWork(phone, password);
-          //  workIdToken = CreateTokenUtil.getToken(String.valueOf(repairsWork.getWorkId()));
+            workIdToken = CreateTokenUtil.getToken(String.valueOf(repairsWork.getWorkId()));
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -103,37 +96,30 @@ public class LoginController {
     @ApiOperation("获取学生CardNumber")
     @GetMapping("/getCardNumber")
     public JSONObject getCardNumber(String wxcode, String state) {
+
         JSONObject cardNumberJson = new JSONObject();
+        String accessToken = "";
         try {
-            wxcode = "wxcode=" + wxcode + "&";
-            String app_key = "app_key=EE28EE2C93296F4E&";
-            String app_secret = "app_secret=5071958561AA629530AAA31503088330&";
-            String grant_type = "grant_type=authorization_code&";
-            String redirect_uri = "redirect_uri=http://binguo.vaiwan.com/login/getCardNumber";
-            String url = "https://open.wecard.qq.com/connect/oauth2/token?";
-            String accessTokenUrl = url + wxcode + app_key + app_secret + grant_type + redirect_uri;
-            // -------------------------------> 获取Rest客户端实例
+
+            String app_key = "EE28EE2C93296F4E";
+            String app_secret = "5071958561AA629530AAA31503088330";
+            String grant_type = "authorization_code";
+            String redirect_uri = "http://binguo.vaiwan.com/login/getCardNumber";
+            String url = "https://open.wecard.qq.com/connect/oauth2/token"; //用于用户 获取基础的access_token
+            Map<String, String> param = new HashMap<>();
+            param.put("wxcode", wxcode);
+            param.put("app_key", app_key);
+            param.put("app_secret", app_secret);
+            param.put("grant_type", grant_type);
+            param.put("redirect_uri", redirect_uri);
+
             RestTemplate restTemplate = new RestTemplate();
-            // -------------------------------> (选择性设置)请求头信息
-            // HttpHeaders实现了MultiValueMap接口
-            HttpHeaders httpHeaders = new HttpHeaders();
-            // 设置contentType
-           // httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
-            httpHeaders.setContentType(MediaType.APPLICATION_JSON);
-            // 给请求header中添加一些数据
-            // ------------------------------->将请求头、请求体数据,放入HttpEntity中
-            // 请求体的类型任选即可;只要保证 请求体 的类型与HttpEntity类的泛型保持一致即可
-            Map<String, Object> paramMap = new HashMap<>();
-            HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(paramMap, httpHeaders);
-            StringBuffer paramsURL = new StringBuffer(accessTokenUrl);
-            // 字符数据最好encoding一下;这样一来,某些特殊字符才能传过去(如:flag的参数值就是“&”,不encoding的话,传不过去)
-            // paramsURL.append("?flag=" + URLEncoder.encode("&&", "utf-8"));
-            URI uri = URI.create(paramsURL.toString());
-            //  -------------------------------> 执行请求并返回结果
-            // 此处的泛型  对应 响应体数据   类型;即:这里指定响应体的数据装配为String
-            ResponseEntity<String> response = restTemplate.postForEntity(uri, httpEntity, String.class);
-            JSONObject objParam = JSON.parseObject(response.getBody());
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity<Map<String, String>> request = new HttpEntity<>(param, headers);
+            ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
 
+            JSONObject objParam = JSON.parseObject(responseEntity.getBody());
             for (Map.Entry<String, Object> entry : objParam.entrySet()) {
                 Object o = entry.getValue();
                 if (o instanceof String) {
@@ -142,15 +128,15 @@ public class LoginController {
                     }
                 }
             }
-
-            String userInfoUrl = "https://open.wecard.qq.com/connect/oauth/get-user-info?access_token=" + accessToken + "&scope=snsapi_base";
-            StringBuffer userInfoURl = new StringBuffer(userInfoUrl);
-            // 字符数据最好encoding一下;这样一来,某些特殊字符才能传过去(如:flag的参数值就是“&”,不encoding的话,传不过去)
-            // paramsURL.append("?flag=" + URLEncoder.encode("&&", "utf-8"));
-            URI urm = URI.create(userInfoURl.toString());
-            // 此处的泛型  对应 响应体数据   类型;即:这里指定响应体的数据装配为String
-            ResponseEntity<String> responsem = restTemplate.postForEntity(urm, httpEntity, String.class);
+            System.out.println(accessToken);
+            Map<String, String> paramCardNumber = new HashMap<>();
+            paramCardNumber.put("access_token", accessToken);
+            paramCardNumber.put("scope", "snsapi_base");
+            HttpEntity<Map<String, String>> requestM = new HttpEntity<>(paramCardNumber, headers);
+            String userInfoUrl = "https://open.wecard.qq.com/connect/oauth/get-user-info";
+            ResponseEntity<String> responsem = restTemplate.postForEntity(userInfoUrl, requestM, String.class);
             JSONObject obj = JSON.parseObject(responsem.getBody());
+
             String studentId = "";
             String studentName = "";
             String studentSex = "";
@@ -197,58 +183,19 @@ public class LoginController {
 
             }
             RepairsStudent repairsStudent = new RepairsStudent(studentId, studentName, studentSex,
-            studentPhone, studentOtherPhone, studentClazz, dormNumber,
-            studentDormitory, studentStatus, studentCampus,cardNumber);
+                    studentPhone, studentOtherPhone, studentClazz, dormNumber,
+                    studentDormitory, studentStatus, studentCampus, cardNumber);
             RepairsStudent student = repairsStudentService.queryByStudentId(studentId);
-            if(student==null){
+            if (student == null) {
                 repairsStudentService.insertStudent(repairsStudent);
             }
-            cardNumberJson.put("card_number",cardNumber);
-            autoQueryOrder();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return cardNumberJson;
-    }
-
-    @Scheduled(cron = "0 0/30 * * * ?")
-    public void autoQueryOrder() {
+            cardNumberJson.put("card_number", cardNumber);
 
-        try {
-//            LocalDateTime now = LocalDateTime.now();
-//            now.plusMinutes(30);
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-            Calendar calendar = Calendar.getInstance();
-            String systemTime = sdf.format(calendar.getTime());
-            calendar.add(Calendar.MINUTE, 30);
-            String changeTime = sdf.format(calendar.getTime());
-
-            List<RepairsOrder> orderList = repairsOrderService.queryByTime(systemTime,changeTime);
-            Set<String> idList = orderList.stream().filter(e -> e.getRepairsStudent() != null)
-                    .map(e -> e.getRepairsStudent().getStudentId()).collect(Collectors.toSet());
-
-            String title = "寝室维修通知";
-            String content = "同学你好,你的寝室报修单已被维修师傅接单,维修师傅将于半小时后上门维修;请合理安排时间,谢谢合作。";
-            String sender = "寝室管理办公室";
-            MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
-            param.add("title", title);
-            param.add("cards", idList);
-            param.add("content", content);
-            param.add("sender", sender);
-            String url = "https://open.wecard.qq.com/cgi-bin/notice/send?access_token="+accessToken;
-
-            RestTemplate restTemplate = new RestTemplate();
-            HttpHeaders headers = new HttpHeaders();
-            headers.setContentType(MediaType.APPLICATION_JSON);
-            HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(param, headers);
-            ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
-            System.out.println(responseEntity.getBody());
         } catch (Exception e) {
             e.printStackTrace();
         }
+        return cardNumberJson;
     }
 
 
-
-
 }

+ 49 - 0
src/main/java/com/chuanghai/repair/entity/EntityCache.java

@@ -0,0 +1,49 @@
+package com.chuanghai.repair.entity;
+
+/**
+ * @Author: bingo
+ * @Date: 2022/3/4 星期五 13:06
+ * @Description: com.chuanghai.repair.entity
+ * @version: 1.0
+ */
+public class EntityCache {
+    /**
+     * 保存的数据
+     */
+    private Object datas;
+
+    /**
+     * 设置数据失效时间,为0表示永不失效
+     */
+    private long timeOut;
+
+    /**
+     * 最后刷新时间
+     */
+    private long lastRefeshTime;
+
+    public EntityCache(Object datas, long timeOut, long lastRefeshTime) {
+        this.datas = datas;
+        this.timeOut = timeOut;
+        this.lastRefeshTime = lastRefeshTime;
+    }
+    public Object getDatas() {
+        return datas;
+    }
+    public void setDatas(Object datas) {
+        this.datas = datas;
+    }
+    public long getTimeOut() {
+        return timeOut;
+    }
+    public void setTimeOut(long timeOut) {
+        this.timeOut = timeOut;
+    }
+    public long getLastRefeshTime() {
+        return lastRefeshTime;
+    }
+    public void setLastRefeshTime(long lastRefeshTime) {
+        this.lastRefeshTime = lastRefeshTime;
+    }
+
+}

+ 41 - 0
src/main/java/com/chuanghai/repair/entity/RepairsFloor.java

@@ -0,0 +1,41 @@
+package com.chuanghai.repair.entity;
+
+import lombok.*;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * @Author: bingo
+ * @Date: 2022/3/4 星期五 14:50
+ * @Description: com.chuanghai.repair.entity
+ * @version: 1.0
+ */
+@NoArgsConstructor
+@AllArgsConstructor
+@Setter
+@Getter
+@ToString
+@Table(name = "repairs_floor")
+public class RepairsFloor {
+    /**
+     * 楼层ID
+     */
+    @Id
+    @Column(name = "floor_id")
+    private Integer floorId;
+
+    /**
+     * 楼层名称
+     */
+    @Column(name = "floor_name")
+    private String floorName;
+
+    /**
+     * 楼栋ID
+     */
+    @Column(name = "build_id")
+    private RepairsBuild repairsBuild;
+
+}

+ 2 - 2
src/main/java/com/chuanghai/repair/entity/RepairsRoom.java

@@ -27,8 +27,8 @@ public class RepairsRoom {
     /**
      * 楼栋ID
      */
-    @Column(name = "build_id")
-    private RepairsBuild repairsBuild;
+    @Column(name = "floor_id")
+    private RepairsFloor repairsFloor;
 
 
 }

+ 81 - 0
src/main/java/com/chuanghai/repair/service/ICacheManager.java

@@ -0,0 +1,81 @@
+package com.chuanghai.repair.service;
+
+import com.chuanghai.repair.entity.EntityCache;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @Author: bingo
+ * @Date: 2022/3/4 星期五 13:07
+ * @Description: com.chuanghai.repair.service
+ * @version: 1.0
+ */
+public interface ICacheManager {
+    /**
+     * 存入缓存
+     * @param key
+     * @param cache
+     */
+    void putCache(String key, EntityCache cache);
+
+    /**
+     * 存入缓存
+     * @param key
+     * @param
+     */
+    void putCache(String key, Object datas, long timeOut);
+
+    /**
+     * 获取对应缓存
+     * @param key
+     * @return
+     */
+    EntityCache getCacheByKey(String key);
+
+    /**
+     * 获取对应缓存
+     * @param key
+     * @return
+     */
+    Object getCacheDataByKey(String key);
+
+    /**
+     * 获取所有缓存
+     * @param
+     * @return
+     */
+    Map<String, EntityCache> getCacheAll();
+
+    /**
+     * 判断是否在缓存中
+     * @param key
+     * @return
+     */
+    boolean isContains(String key);
+
+    /**
+     * 清除所有缓存
+     */
+    void clearAll();
+
+    /**
+     * 清除对应缓存
+     * @param key
+     */
+    void clearByKey(String key);
+
+    /**
+     * 缓存是否超时失效
+     * @param key
+     * @return
+     */
+    boolean isTimeOut(String key);
+
+    /**
+     * 获取所有key
+     * @return
+     */
+    Set<String> getAllKeys();
+
+}

+ 124 - 0
src/main/java/com/chuanghai/repair/service/ServiceImpl/CacheManagerImpl.java

@@ -0,0 +1,124 @@
+package com.chuanghai.repair.service.ServiceImpl;
+
+import com.chuanghai.repair.entity.EntityCache;
+import com.chuanghai.repair.service.ICacheManager;
+import com.chuanghai.repair.utils.CreateTokenUtil;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @Author: bingo
+ * @Date: 2022/3/4 星期五 13:08
+ * @Description: com.chuanghai.repair.service.ServiceImpl
+ * @version: 1.0
+ */
+public class CacheManagerImpl implements ICacheManager {
+    private static Map<String, EntityCache> caches = new ConcurrentHashMap<String, EntityCache>();
+
+    /**
+     * 存入缓存
+     * @param key
+     * @param cache
+     */
+    public void putCache(String key, EntityCache cache) {
+        caches.put(key, cache);
+    }
+
+    /**
+     * 存入缓存
+     * @param key
+     * @param
+     */
+    public void putCache(String key, Object datas, long timeOut) {
+        timeOut = timeOut > 0 ? timeOut : 0L;
+        putCache(key, new EntityCache(datas, timeOut, System.currentTimeMillis()));
+    }
+
+    /**
+     * 获取对应缓存
+     * @param key
+     * @return
+     */
+    public EntityCache getCacheByKey(String key) {
+        if (this.isContains(key)) {
+            return caches.get(key);
+        }
+        return null;
+    }
+
+    /**
+     * 获取对应缓存
+     * @param key
+     * @return
+     */
+    public Object getCacheDataByKey(String key) {
+        if (this.isContains(key)) {
+            return caches.get(key).getDatas();
+        }
+        return null;
+    }
+
+    /**
+     * 获取所有缓存
+     * @param
+     * @return
+     */
+    public Map<String, EntityCache> getCacheAll() {
+        return caches;
+    }
+
+    /**
+     * 判断是否在缓存中
+     * @param key
+     * @return
+     */
+    public boolean isContains(String key) {
+        return caches.containsKey(key);
+    }
+
+    /**
+     * 清除所有缓存
+     */
+    public void clearAll() {
+        caches.clear();
+    }
+
+    /**
+     * 清除对应缓存
+     * @param key
+     */
+    public void clearByKey(String key) {
+        if (this.isContains(key)) {
+            caches.remove(key);
+        }
+    }
+
+    /**
+     * 缓存是否超时失效
+     * @param key
+     * @return
+     */
+    public boolean isTimeOut(String key) {
+        if (!caches.containsKey(key)) {
+            return true;
+        }
+        EntityCache cache = caches.get(key);
+        long timeOut = cache.getTimeOut();
+        long lastRefreshTime = cache.getLastRefeshTime();
+        if (timeOut == 0 || System.currentTimeMillis() - lastRefreshTime >= timeOut) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 获取所有key
+     * @return
+     */
+    public Set<String> getAllKeys() {
+        return caches.keySet();
+    }
+
+}

+ 106 - 96
src/main/java/com/chuanghai/repair/utils/CreateTokenUtil.java

@@ -3,15 +3,14 @@ package com.chuanghai.repair.utils;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.auth0.jwt.JWT;
-import com.auth0.jwt.JWTVerifier;
 import com.auth0.jwt.algorithms.Algorithm;
-import com.auth0.jwt.interfaces.DecodedJWT;
 import com.sun.deploy.net.URLEncoder;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
@@ -33,152 +32,162 @@ import java.util.Map;
 public class CreateTokenUtil {
 
     //设置过期时间
-    private static final long EXPIRE_DATE=30*60*100000;
+    private static final long EXPIRE_DATE = 30 * 60 * 100000;
     //token秘钥
     private static final String TOKEN_SECRET = "ZCfasfhuaUUHufguGuwu2020BQWE";
 
+
+
+
     /**
      * 数据加密生成token
+     *
      * @param userId
      * @return
      */
-    public static String getToken (String userId){
+    public static String getToken(String userId) {
         String token = "";
         try {
             //过期时间
-            Date date = new Date(System.currentTimeMillis()+EXPIRE_DATE);
+            Date date = new Date(System.currentTimeMillis() + EXPIRE_DATE);
             //秘钥及加密算法
             Algorithm algorithm = Algorithm.HMAC256(TOKEN_SECRET);
             //设置头部信息
-            Map<String,Object> header = new HashMap<>();
-            header.put("typ","JWT");
-            header.put("alg","HS256");
+            Map<String, Object> header = new HashMap<>();
+            header.put("typ", "JWT");
+            header.put("alg", "HS256");
             //携带username,password信息,生成签名
             token = JWT.create()
                     .withHeader(header)
-                  //  .withClaim("username",username)
-                    .withClaim("userId",userId).withExpiresAt(date)
+                    //  .withClaim("username",username)
+                    .withClaim("userId", userId).withExpiresAt(date)
                     .sign(algorithm);
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
-            return  null;
+            return null;
         }
         return token;
     }
 
     /**
      * 解析token
+     *
      * @param token
      * @param userId
      * @return
      */
 
-    public static String verify(String token,String userId) {
+    public static String verify(String token, String userId) {
         return JWT.decode(token).getClaim(userId).asString();
     }
 
 
     /**
-     * 微校小程序H5页面  通过 wxcode 获取 access_token
+     * 通过 wxcode 获取微信移动端H5  JSAPI中基础支持的ACCESS_TOKEN
      * 访问链接:https://open.wecard.qq.com/connect/oauth/authorize?app_key=EE28EE2C93296F4E&response_type=code
-     *          &scope=snsapi_base&ocode=1015730314&redirect_uri=http://binguo.vaiwan.com/login/getCardNumber&state=STATE
+     * &scope=snsapi_base&ocode=1015730314&redirect_uri=http://binguo.vaiwan.com/login/getCardNumber&state=STATE
+     *
      * @param wxcode
-     * @param state
+     * @param
      * @return
      */
-    public static String getAccessToken(String wxcode,String state) {
+    public static String getAccessToken(String wxcode) {
         String access_token = "";
-        System.out.println("before");
+
         try {
 
-            wxcode = "wxcode=" + wxcode + "&";
-            String app_key = "app_key=EE28EE2C93296F4E&";
-            String app_secret = "app_secret=5071958561AA629530AAA31503088330&";
-            String grant_type = "grant_type=authorization_code&";
-            String redirect_uri = "redirect_uri=http://binguo.vaiwan.com/login/getCardNumber";
-            String url = "https://open.wecard.qq.com/connect/oauth2/token?";
-            String accessTokenUrl = url + wxcode + app_key + app_secret + grant_type + redirect_uri;
-            // -------------------------------> 获取Rest客户端实例
+            String app_key = "EE28EE2C93296F4E";
+            String app_secret = "5071958561AA629530AAA31503088330";
+            String grant_type = "authorization_code";
+            String redirect_uri = "http://binguo.vaiwan.com/login/getAccessToken";
+            String url = "https://open.wecard.qq.com/connect/oauth2/token"; //用于用户 获取基础的access_token
+            MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
+            param.add("wxcode", wxcode);
+            param.add("app_key", app_key);
+            param.add("app_secret", app_secret);
+            param.add("grant_type", grant_type);
+            param.add("redirect_uri", redirect_uri);
+
             RestTemplate restTemplate = new RestTemplate();
-            // -------------------------------> (选择性设置)请求头信息
-            // HttpHeaders实现了MultiValueMap接口
-            HttpHeaders httpHeaders = new HttpHeaders();
-            // 设置contentType
-            // httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
-            httpHeaders.setContentType(MediaType.APPLICATION_JSON);
-            // 给请求header中添加一些数据
-            // ------------------------------->将请求头、请求体数据,放入HttpEntity中
-            // 请求体的类型任选即可;只要保证 请求体 的类型与HttpEntity类的泛型保持一致即可
-            Map<String, Object> paramMap = new HashMap<>();
-            HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(paramMap, httpHeaders);
-            StringBuffer paramsURL = new StringBuffer(accessTokenUrl);
-            // 字符数据最好encoding一下;这样一来,某些特殊字符才能传过去(如:flag的参数值就是“&”,不encoding的话,传不过去)
-            // paramsURL.append("?flag=" + URLEncoder.encode("&&", "utf-8"));
-            URI uri = URI.create(paramsURL.toString());
-            //  -------------------------------> 执行请求并返回结果
-            // 此处的泛型  对应 响应体数据   类型;即:这里指定响应体的数据装配为String
-            ResponseEntity<String> response = restTemplate.postForEntity(uri, httpEntity, String.class);
-            JSONObject objParam = JSON.parseObject(response.getBody());
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(param, headers);
+            ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
+            JSONObject objParam = JSON.parseObject(responseEntity.getBody());
             for (Map.Entry<String, Object> entry : objParam.entrySet()) {
                 Object o = entry.getValue();
                 if (o instanceof String) {
                     if (entry.getKey().equals("access_token")) {
                         access_token = (String) entry.getValue();
-                        System.out.println(access_token+"util ");
                     }
                 }
             }
-//            String app_key = "EE28EE2C93296F4E";
-//            String app_secret = "5071958561AA629530AAA31503088330";
-//            String grant_type = "authorization_code";
-//            String redirect_uri = "http://binguo.vaiwan.com/login/getAccessToken";
-//            String url = "https://open.wecard.qq.com/connect/oauth2/token";
-//            JSONObject accessTokenUrl = new JSONObject();
-//            accessTokenUrl.put("wxcode",wxcode);
-//            accessTokenUrl.put("app_key",app_key);
-//            accessTokenUrl.put("app_secret",app_secret);
-//            accessTokenUrl.put("grant_type",grant_type);
-//            accessTokenUrl.put("redirect_uri",redirect_uri);
-//            String urlToken = accessTokenUrl.toString();
-//            urlToken = urlToken.replace("\"", "%22")
-//                    .replace("{", "%7b").replace("}", "%7d");
-//            StringBuffer paramsURL = new StringBuffer(url);
-//            // 字符数据最好encoding一下;这样一来,某些特殊字符才能传过去(如:flag的参数值就是“&”,不encoding的话,传不过去)
-//            paramsURL.append("?flag=" + URLEncoder.encode("&&", "utf-8"));
-//            URI uri = URI.create(paramsURL.toString());
-//            // -------------------------------> 获取Rest客户端实例
-//            RestTemplate restTemplate = new RestTemplate();
-//            HttpHeaders headers = new HttpHeaders();
-//            headers.setContentType(MediaType.APPLICATION_JSON);
-//            HttpEntity<String> request = new HttpEntity< String>(urlToken, headers);
-//            ResponseEntity<String> responseEntity = restTemplate.postForEntity(uri, request, String.class);
-//            JSONObject objParam = JSON.parseObject(responseEntity.getBody());
-//            for (Map.Entry<String, Object> entry : objParam.entrySet()) {
-//                Object o = entry.getValue();
-//                if (o instanceof String) {
-//                    if (entry.getKey().equals("access_token")) {
-//                        access_token = (String) entry.getValue();
-//                    }
-//                }
-//            }
 
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
         }
         return access_token;
     }
 
     /**
+     * 获取应用凭证
+     *
+     * @return
+     */
+
+//    @Scheduled(cron = "0 */1 * * * ?")
+    @Scheduled(cron = "0 59 0/1 * * ?") //    每隔 1hour59minutes 执行一次刷新access_token
+    public static String getAccessTokenGlobal() {
+        String access_token_global = "";
+        try {
+
+            String app_key = "EE28EE2C93296F4E";
+            String app_secret = "5071958561AA629530AAA31503088330";
+            String grant_type = "client_credentials";
+            String scope = "base";
+            String ocode = "1015730314";
+            String url = "https://open.wecard.qq.com/cgi-bin/oauth2/token"; //用于获取应用有效凭证
+            Map<String, String> param = new HashMap<>();
+            param.put("app_key", app_key);
+            param.put("app_secret", app_secret);
+            param.put("grant_type", grant_type);
+            param.put("scope", scope);
+            param.put("ocode", ocode);
+
+            RestTemplate restTemplate = new RestTemplate();
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+            HttpEntity<Map<String, String>> request = new HttpEntity<>(param, headers);
+            ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
+            JSONObject objParam = JSON.parseObject(responseEntity.getBody());
+
+            for (Map.Entry<String, Object> entry : objParam.entrySet()) {
+                Object o = entry.getValue();
+                if (o instanceof String) {
+                    if (entry.getKey().equals("access_token")) {
+                        access_token_global = (String) entry.getValue();
+                    }
+                }
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return access_token_global;
+    }
+
+    /**
      * 微校小程序H5页面  通过 access_token 获取 用户信息
+     *
      * @param access_token
      * @return
      */
-    public static JSONObject getUserInfoJSON(String access_token){
+    public static JSONObject getUserInfoJSON(String access_token) {
         JSONObject userInfoJSON = null;
-        try{
+        try {
             String url = "https://open.wecard.qq.com/connect/oauth/get-user-info";
             JSONObject accessTokenUrl = new JSONObject();
-            accessTokenUrl.put("access_token",access_token);
+            accessTokenUrl.put("access_token", access_token);
             String urlToken = accessTokenUrl.toString();
             urlToken = urlToken.replace("\"", "%22")
                     .replace("{", "%7b").replace("}", "%7d");
@@ -190,13 +199,13 @@ public class CreateTokenUtil {
             RestTemplate restTemplate = new RestTemplate();
             HttpHeaders headers = new HttpHeaders();
             headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
-            HttpEntity<String> request = new HttpEntity< String>(urlToken, headers);
+            HttpEntity<String> request = new HttpEntity<String>(urlToken, headers);
             ResponseEntity<String> responseEntity = restTemplate.postForEntity(uri, request, String.class);
             userInfoJSON = JSON.parseObject(responseEntity.getBody());
             for (Map.Entry<String, Object> entry : userInfoJSON.entrySet()) {
                 Object o = entry.getValue();
                 if (o instanceof String) {
-                       System.out.println("key:"+entry.getKey()+":"+"value:"+entry.getValue());
+                    System.out.println("key:" + entry.getKey() + ":" + "value:" + entry.getValue());
                 }
             }
 //            RestTemplate restTemplate = new RestTemplate();
@@ -216,7 +225,7 @@ public class CreateTokenUtil {
 //                       System.out.println("key:"+entry.getKey()+":"+"value:"+entry.getValue());
 //                }
 //            }
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
         }
 
@@ -225,15 +234,16 @@ public class CreateTokenUtil {
 
     /**
      * 微校小程序H5页面  通过 access_token 获取 用户信息
+     *
      * @param url
      * @return
      */
-    public static JSONObject sendNotice(String url){
+    public static JSONObject sendNotice(String url) {
         JSONObject userInfoJSON = null;
-        try{
+        try {
             RestTemplate restTemplate = new RestTemplate();
-            MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>();
-            map.add("shopid","1");
+            MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
+            map.add("shopid", "1");
             HttpHeaders headers = new HttpHeaders();
             headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
             HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
@@ -247,7 +257,7 @@ public class CreateTokenUtil {
 //            URI urm = URI.create(unoticeURl.toString());
 //            ResponseEntity<String> responsem = restTemplate.postForEntity(urm, httpEntity, String.class);
 //            userInfoJSON = JSON.parseObject(responsem.getBody());
-        }catch (Exception e){
+        } catch (Exception e) {
             e.printStackTrace();
         }
 
@@ -256,6 +266,7 @@ public class CreateTokenUtil {
 
     /**
      * 获取请求头中的数据
+     *
      * @param request
      * @param
      * @return
@@ -269,8 +280,8 @@ public class CreateTokenUtil {
             String value = request.getHeader(key);
             map.put(key, value);
         }
-        for (Map.Entry<String, String> entry:map.entrySet()) {
-            if(entry.getKey().equals("access_token")){
+        for (Map.Entry<String, String> entry : map.entrySet()) {
+            if (entry.getKey().equals("access_token")) {
                 access_token = entry.getValue();
             }
         }
@@ -278,13 +289,12 @@ public class CreateTokenUtil {
     }
 
 
-
     public static void main(String[] args) {
-        String id ="1003";
+        String id = "1003";
         String userId = "userId";
         String token = getToken(id);
         System.out.println(token);
-        String s = verify(token,userId);
+        String s = verify(token, userId);
         System.out.println(s);
     }
 }

+ 7 - 0
src/main/resources/application.yml

@@ -1,3 +1,8 @@
+server:
+  port: 8084
+
+
+
 
 #数据源配置
 spring:
@@ -8,10 +13,12 @@ spring:
 #    driver-class-name: com.mysql.cj.jdbc.Driver
     username: root
     password: root
+#spring security 安全框架
   security:
     user:
       name: admin
       password: 123456
+#数据库方言
   jpa:
     database-platform: org.hibernate.dialect.MySQLDialect
 

+ 8 - 4
src/main/resources/mapper/RepairsBuildRoomMapper.xml

@@ -8,14 +8,18 @@
         <id column="room_id" property="roomId" jdbcType="INTEGER"/>
         <result column="room_name" property="roomName" jdbcType="VARCHAR"/>
         <!--        房间与楼栋之间是  N:1 关系-->
-        <association  property="repairsBuild"  javaType="com.chuanghai.repair.entity.RepairsBuild">
-            <id column="build_id" property="buildId"></id>
-            <result column="build_name" property="buildName" jdbcType="VARCHAR"/>
+        <association  property="repairsFloor"  javaType="com.chuanghai.repair.entity.RepairsFloor">
+            <id column="floor_id" property="floorId"></id>
+            <result column="floor_name" property="floorName" jdbcType="VARCHAR"/>
+            <association  property="repairsBuild"  javaType="com.chuanghai.repair.entity.RepairsBuild">
+                <id column="build_id" property="buildId"></id>
+                <result column="build_name" property="buildName" jdbcType="VARCHAR"/>
+            </association >
         </association >
     </resultMap>
 
 <!--    查询所有宿舍信息-->
     <select id="queryAllBuildRoom" resultMap="BaseResultMap">
-        select * from repairs_build bu,repairs_room ro where ro.build_id = bu.build_id
+        select * from repairs_build bu,repairs_floor fl, repairs_room ro where bu.build_id = fl.build_id and fl.floor_id = ro.floor_id
     </select>
 </mapper>