|
@@ -0,0 +1,96 @@
|
|
|
+package com.sky.ioc.service.meeting.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.sky.ioc.entity.domain.meeting.MeetingRoom;
|
|
|
+import com.sky.ioc.mapper.job.TokenMapper;
|
|
|
+import com.sky.ioc.mapper.meeting.MeetingRoomMapper;
|
|
|
+import com.sky.ioc.service.meeting.MeetingRoomService;
|
|
|
+import com.sky.ioc.tool.ReturnMsg;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class MeetingRoomServiceImpl implements MeetingRoomService {
|
|
|
+ @Resource
|
|
|
+ RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TokenMapper tokenMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ MeetingRoomMapper meetingRoomMapper;
|
|
|
+
|
|
|
+ final static String MEETTING_ROOM_URL="http://192.168.1.45:9001/api/meeting/MEETING/room/list?pageNum=1&pageSize=100";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReturnMsg getMeetingRoomList() {
|
|
|
+ Map<String,String> tokenMap = tokenMapper.getNewToken();
|
|
|
+ String token ="Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6IjUwZTU1NTRkLWJjYzYtNGRhMS1iZDUxLWFhNTc3YzU4YTFiNCIsInVzZXJuYW1lIjoiYWRtaW4ifQ.X10VPYJfeeRTka7OtqNPOGMpL4QkW3fR_TfCKXCmO-yXbIIrr_40fcwiVnpXfYVENo_BvXWEACRd-Y6nXsbkog";
|
|
|
+ if(tokenMap!=null){
|
|
|
+ token = "Bearer "+tokenMap.get("token");
|
|
|
+ }
|
|
|
+ // 创建一个请求头对象
|
|
|
+ HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
+ // 设置参数
|
|
|
+ httpHeaders.set("authorization", token);
|
|
|
+ // 创建一个响应体对象
|
|
|
+ HttpEntity<String> httpEntity = new HttpEntity(httpHeaders);
|
|
|
+ // 3.创建RestTemplate
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ // 发送GET请求
|
|
|
+ ResponseEntity<Map> responseEntity = restTemplate.exchange(MEETTING_ROOM_URL, HttpMethod.GET, httpEntity, Map.class);
|
|
|
+ // 获取响应对象里的 body 对象
|
|
|
+ Map<String, Object> body = responseEntity.getBody();
|
|
|
+ // 获取状态码
|
|
|
+ Integer code = (Integer)body.get("code");
|
|
|
+ // 获取响应信息
|
|
|
+ String message = (String)body.get("msg");
|
|
|
+ if(code==200){
|
|
|
+ ArrayList list = (ArrayList) body.get("rows");
|
|
|
+ if(list!=null&&list.size()>0){
|
|
|
+ meetingRoomMapper.delete(null);
|
|
|
+ for (int i=0;i<list.size();i++){
|
|
|
+ LinkedHashMap json = (LinkedHashMap) list.get(i);
|
|
|
+ MeetingRoom room = new MeetingRoom();
|
|
|
+ String name = (String) json.get("mrName");
|
|
|
+ Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
+ Matcher isNum = pattern.matcher(name.charAt(0)+"");
|
|
|
+ Integer floorId = 1;
|
|
|
+ if (isNum.matches()&&name.length()>2) {
|
|
|
+ floorId = Integer.valueOf(name.substring(0,2));
|
|
|
+ }
|
|
|
+ room.setId((Integer) json.get("id"));
|
|
|
+ room.setCapacity(8);
|
|
|
+ room.setName((String) json.get("mrName"));
|
|
|
+ room.setAuditTime((String) json.get("auditTime"));
|
|
|
+ room.setOpenTime((String) json.get("openTime"));
|
|
|
+ room.setCloseTime((String) json.get("closeTime"));
|
|
|
+ room.setRemark((String) json.get("remark"));
|
|
|
+ room.setFloorId(floorId);
|
|
|
+ room.setOrderNo((Integer)json.get("orderNo")+"");
|
|
|
+ room.setMrNo((String) json.get("mrNo"));
|
|
|
+ meetingRoomMapper.insert(room);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ log.info("获取会议室数据:"+message);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|