|
@@ -1,18 +1,30 @@
|
|
|
package com.persagy.controller;
|
|
|
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.persagy.domain.*;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.persagy.domain.ReservationCustom;
|
|
|
+import com.persagy.domain.ReservationVo;
|
|
|
+import com.persagy.domain.Room;
|
|
|
import com.persagy.service.ReservationService;
|
|
|
import com.persagy.service.RoomService;
|
|
|
-import com.persagy.service.UserService;
|
|
|
+import com.persagy.util.PinyinUtils;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.client.methods.HttpUriRequest;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* Created by Admiral on 2018/1/20.
|
|
@@ -27,13 +39,23 @@ public class OrdinaryController {
|
|
|
|
|
|
@Resource(name = "reservationServiceImpl")
|
|
|
private ReservationService reservationService;
|
|
|
+ //获取CorpAccessToken URL
|
|
|
+ private String corpAccessTokenURL = "https://open.fxiaoke.com/cgi/corpAccessToken/get/V2";
|
|
|
+ //部门列表
|
|
|
+ private String departmentURL = "https://open.fxiaoke.com/cgi/department/list";
|
|
|
+ //部门下人员列表
|
|
|
+ private String userURL = "https://open.fxiaoke.com/cgi/user/list";
|
|
|
+ //消息
|
|
|
+ private String messageURL = "https://open.fxiaoke.com/cgi/message/send";
|
|
|
+ private String corpAccessToken = null;
|
|
|
+ private String corpId = null;
|
|
|
|
|
|
/**
|
|
|
* 获取会议室列表
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- @RequestMapping(value="/roomList", method=RequestMethod.GET)
|
|
|
+ @RequestMapping(value="/roomList", method=RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
public List<Room> roomList() throws Exception {
|
|
|
List<Room> list = roomService.findByPaging(1);
|
|
@@ -47,8 +69,10 @@ public class OrdinaryController {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@RequestMapping(value = "/queryRoomByName", method = {RequestMethod.POST,RequestMethod.GET})
|
|
|
- private List<Room> queryRoomByName(String roomName) throws Exception {
|
|
|
- List<Room> list = roomService.findByName(roomName);
|
|
|
+ private List<Room> queryRoomByName(@RequestBody String roomName) throws Exception {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(roomName);
|
|
|
+ String name = jsonObject.getString("roomName");
|
|
|
+ List<Room> list = roomService.findByName(name);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
@@ -59,8 +83,10 @@ public class OrdinaryController {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@RequestMapping(value = "/queryRoomById", method = {RequestMethod.POST,RequestMethod.GET})
|
|
|
- private Room queryRoomById(Integer roomID) throws Exception {
|
|
|
- Room room = roomService.findById(roomID);
|
|
|
+ private Room queryRoomById(@RequestBody String roomID) throws Exception {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(roomID);
|
|
|
+ Integer id = jsonObject.getInteger("roomID");
|
|
|
+ Room room = roomService.findById(id);
|
|
|
return room;
|
|
|
}
|
|
|
|
|
@@ -83,9 +109,11 @@ public class OrdinaryController {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@RequestMapping("/showRecordByRoomId")
|
|
|
- public List<ReservationVo> findAllReservationByRoomId(Integer id) throws Exception {
|
|
|
+ public List<ReservationVo> findAllReservationByRoomId(@RequestBody String id) throws Exception {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(id);
|
|
|
+ Integer roomId = jsonObject.getInteger("id");
|
|
|
List<ReservationVo> list = null;
|
|
|
- list = reservationService.findByRoomId(id);
|
|
|
+ list = reservationService.findByRoomId(roomId);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
@@ -97,9 +125,11 @@ public class OrdinaryController {
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- @RequestMapping(value = "/queryByUser")
|
|
|
- private List<ReservationVo> queryUser(String userName) throws Exception {
|
|
|
- List<ReservationVo> list = reservationService.queryByUser(userName);
|
|
|
+ @RequestMapping(value = "/queryByUser",method = RequestMethod.POST)
|
|
|
+ private List<ReservationVo> queryUser(@RequestBody String userName) throws Exception {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(userName);
|
|
|
+ String name = jsonObject.getString("userName");
|
|
|
+ List<ReservationVo> list = reservationService.queryByUser(name);
|
|
|
return list;
|
|
|
}
|
|
|
|
|
@@ -113,13 +143,39 @@ public class OrdinaryController {
|
|
|
return "/ordinary/reserveRoom";
|
|
|
}
|
|
|
|
|
|
- //预约会议室功能实现
|
|
|
+ /**
|
|
|
+ * 预约会议室功能实现
|
|
|
+ * @param reservation
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
@RequestMapping(value = "/reserveRoom", method = RequestMethod.POST)
|
|
|
- public String reserveRoom(ReservationCustom reservationCustom) throws Exception {
|
|
|
+ public String reserveRoom(@RequestBody String reservation) throws Exception {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(reservation);
|
|
|
+ String roomName = jsonObject.getString("roomName");
|
|
|
+ int roomId = jsonObject.getIntValue("roomId");
|
|
|
+ int userID = jsonObject.getIntValue("userID");
|
|
|
+ String userName = jsonObject.getString("userName");
|
|
|
+
|
|
|
+ JSONArray dateArray = jsonObject.getJSONArray("dateArray");
|
|
|
+ for (int i = 0; i <dateArray.size() ; i++) {
|
|
|
+ JSONObject json = dateArray.getJSONObject(i);
|
|
|
+ String date = json.getString("date");
|
|
|
+ String beginTime = json.getString("beginTime");
|
|
|
+ String endTime = json.getString("endTime");
|
|
|
+ ReservationCustom reservationCustom = new ReservationCustom();
|
|
|
+ reservationCustom.setDate(date);
|
|
|
+ reservationCustom.setBeginTime(beginTime);
|
|
|
+ reservationCustom.setEndTime(endTime);
|
|
|
+ reservationCustom.setUser(userName);
|
|
|
+ reservationCustom.setRoomId(roomId);
|
|
|
+ reservationCustom.setMark("待审核");
|
|
|
+ reservationCustom.setName(roomName);
|
|
|
+ reservationService.addReservation(reservationCustom);
|
|
|
+ }
|
|
|
|
|
|
- reservationService.addReservation(reservationCustom);
|
|
|
|
|
|
- return "redirect:/ordinary/showRecord";
|
|
|
+ return "success";
|
|
|
}
|
|
|
|
|
|
//取消预约申请页面跳转
|
|
@@ -132,11 +188,186 @@ public class OrdinaryController {
|
|
|
}
|
|
|
|
|
|
//取消预约申请业务实现
|
|
|
- @RequestMapping("/cancelApply")
|
|
|
- public String cancelApplication(Integer id) throws Exception{
|
|
|
- reservationService.cancelApplication(id);
|
|
|
+ @RequestMapping(value = "/cancelApply", method = RequestMethod.POST)
|
|
|
+ public String cancelApplication(@RequestBody String id) throws Exception{
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(id);
|
|
|
+ Integer cancelID = jsonObject.getInteger("id");
|
|
|
+ reservationService.cancelApplication(cancelID);
|
|
|
+ return "success";
|
|
|
+ }
|
|
|
+ //获取数字签名
|
|
|
+ public void getSignature() throws Exception{
|
|
|
+ //appId
|
|
|
+ String appId = "FSAID_131860e";
|
|
|
+ //appSecret
|
|
|
+ String appSecret = "e1c53d3c6dff4e96b9ec155a031889af";
|
|
|
+ //永久授权码
|
|
|
+ String permanentCode = "B83ED308137C9653E543303740DB2533";
|
|
|
+ JSONObject corpAccessTokenObj = getCorpAccessToken(appId,appSecret,permanentCode);
|
|
|
+ corpAccessToken = corpAccessTokenObj.getString("corpAccessToken");
|
|
|
+ corpId = corpAccessTokenObj.getString("corpId");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有部门
|
|
|
+ */
|
|
|
+ @RequestMapping(value="/departmentList", method=RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public String departmentList() throws Exception {
|
|
|
+ getSignature();
|
|
|
+ Map<String,Object> obj = new HashMap<String, Object>();
|
|
|
+ obj.put("corpAccessToken",corpAccessToken);
|
|
|
+ obj.put("corpId",corpId);
|
|
|
+ String result = httpPostRequest(departmentURL, obj);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取部门下所有人员
|
|
|
+ */
|
|
|
+ @RequestMapping(value="/usertList", method=RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public String usertList(@RequestBody String jsonStr) throws Exception {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
|
|
+ String departmentId = jsonObject.getString("departmentId");
|
|
|
+ Map<String,Object> obj = new HashMap<String, Object>();
|
|
|
+ obj.put("corpAccessToken",corpAccessToken);
|
|
|
+ obj.put("corpId",corpId);
|
|
|
+ obj.put("departmentId",Integer.valueOf(departmentId));
|
|
|
+ String result = httpPostRequest(userURL, obj);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- return "redirect:/ordinary/showRecord";
|
|
|
+
|
|
|
+
|
|
|
+ private JSONObject getCorpAccessToken(String appId, String appSecret, String permanentCode) throws Exception{
|
|
|
+ Map<String,Object> obj = new HashMap<String, Object>();
|
|
|
+ obj.put("appId",appId);
|
|
|
+ obj.put("appSecret",appSecret);
|
|
|
+ obj.put("permanentCode",permanentCode);
|
|
|
+ String result = httpPostRequest(corpAccessTokenURL, obj);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行http请求
|
|
|
+ * @param httpClient
|
|
|
+ * @param httpRequest
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String executeHttpRequest(CloseableHttpClient httpClient, HttpUriRequest httpRequest){
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
+ String respContent = null;
|
|
|
+ try {
|
|
|
+ response = httpClient.execute(httpRequest);
|
|
|
+ respContent = EntityUtils.toString(response.getEntity(), "utf-8");
|
|
|
+ } catch (Exception e) {
|
|
|
+ }finally {
|
|
|
+ try {
|
|
|
+ httpClient.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ if(response != null) {
|
|
|
+ try {
|
|
|
+ response.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return respContent;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String httpPostRequest(String url, Map<String, Object> params) throws Exception {
|
|
|
+ String respContent = null;
|
|
|
+ CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
+ httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
|
|
|
+ // 设置请求的的参数
|
|
|
+ JSONObject jsonParam = new JSONObject();
|
|
|
+ Set<String> keySet = params.keySet();
|
|
|
+ for (String key : keySet) {
|
|
|
+ jsonParam.put(key, params.get(key));
|
|
|
+ }
|
|
|
+ httpPost.setEntity(new StringEntity(jsonParam.toString(), "utf-8"));
|
|
|
+ // 执行请求
|
|
|
+ respContent = executeHttpRequest(httpclient, httpPost);
|
|
|
+ return respContent;
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 所有人员
|
|
|
+ */
|
|
|
+ @RequestMapping(value="/usertListFirst", method=RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public String usertList() throws Exception {
|
|
|
+ Map<String,Object> obj = new HashMap<String, Object>();
|
|
|
+ obj.put("corpAccessToken",corpAccessToken);
|
|
|
+ obj.put("corpId",corpId);
|
|
|
+ String result = httpPostRequest(departmentURL, obj);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ JSONArray departments = jsonObject.getJSONArray("departments");
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ Integer departmentId = 0;
|
|
|
+ for (int i = 0; i < departments.size(); i++) {
|
|
|
+ JSONObject department = (JSONObject)departments.get(i);
|
|
|
+ Boolean isStop = department.getBoolean("isStop");
|
|
|
+ if(isStop){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ departmentId = department.getInteger("id");
|
|
|
+ //获取人员
|
|
|
+ Map<String,Object> personobj = new HashMap<String, Object>();
|
|
|
+ personobj.put("corpAccessToken",corpAccessToken);
|
|
|
+ personobj.put("corpId",corpId);
|
|
|
+ personobj.put("departmentId",departmentId);
|
|
|
+ String resultStr = httpPostRequest(userURL, personobj);
|
|
|
+ jsonObject = JSONObject.parseObject(resultStr);
|
|
|
+ JSONArray userList = jsonObject.getJSONArray("userList");
|
|
|
+ for (int j = 0; j < userList.size(); j++) {
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ JSONObject user = (JSONObject)userList.get(j);
|
|
|
+ Boolean stop = user.getBoolean("isStop");
|
|
|
+ if(stop){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String name = user.getString("name");
|
|
|
+ String openUserId = user.getString("openUserId");
|
|
|
+ String first = name;
|
|
|
+ jsonObject1.put("name",name);
|
|
|
+ jsonObject1.put("openUserId",openUserId);
|
|
|
+ System.out.println(PinyinUtils.getPinYinHeadChar(name));
|
|
|
+ jsonObject1.put("first", PinyinUtils.getPinYinHeadChar(name));
|
|
|
+ jsonArray.add(jsonObject1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return jsonArray.toJSONString();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 发送消息
|
|
|
+ */
|
|
|
+ @RequestMapping(value="/sendMessage", method=RequestMethod.POST)
|
|
|
+ @ResponseBody
|
|
|
+ public String sendMessage(@RequestBody String jsonStr) throws Exception {
|
|
|
+ getSignature();
|
|
|
+ Map<String,Object> obj = new HashMap<String, Object>();
|
|
|
+ obj.put("corpAccessToken",corpAccessToken);
|
|
|
+ obj.put("corpId",corpId);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
|
|
+ //消息内容
|
|
|
+ String text = jsonObject.getString("text");
|
|
|
+ //发送人
|
|
|
+ JSONArray users = jsonObject.getJSONArray("users");
|
|
|
+// JSONArray users = new JSONArray();
|
|
|
+// users.add("FSUID_782A9585B3CEB91B9DC0C709FA4D3119");
|
|
|
|
|
|
+ obj.put("toUser",users);
|
|
|
+ obj.put("msgType","text");
|
|
|
+ JSONObject content = new JSONObject();
|
|
|
+ content.put("content","luo nb");
|
|
|
+ obj.put("text",content);
|
|
|
+
|
|
|
+ String result = httpPostRequest(messageURL, obj);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|