zouxuan 5 anni fa
parent
commit
8c3e6ff18c

+ 5 - 5
edu-auth/edu-auth-api/src/main/java/com/keao/edu/auth/api/entity/SysUser.java

@@ -1,12 +1,12 @@
 package com.keao.edu.auth.api.entity;
 
 import io.swagger.annotations.ApiModelProperty;
+import org.apache.commons.lang3.builder.ToStringBuilder;
 
 import java.io.Serializable;
 import java.util.Date;
 import java.util.List;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
+import java.util.Set;
 
 /**
  * 对应数据库表(sys_user):
@@ -95,7 +95,7 @@ public class SysUser implements Serializable{
 	private Boolean isSuperAdmin = false;
 
 	@ApiModelProperty(value = "用户角色",required = false)
-	private List<Integer> roles;
+	private Set<Integer> roles;
 
 	private String tenantId;
 
@@ -299,11 +299,11 @@ public class SysUser implements Serializable{
 		this.isSuperAdmin = isSuperAdmin;
 	}
 
-	public List<Integer> getRoles() {
+	public Set<Integer> getRoles() {
 		return roles;
 	}
 
-	public void setRoles(List<Integer> roles) {
+	public void setRoles(Set<Integer> roles) {
 		this.roles = roles;
 	}
 

+ 1 - 0
edu-im/edu-im-server/src/main/java/com/keao/edu/im/config/IMProperties.java

@@ -14,4 +14,5 @@ public class IMProperties {
     private String appKey;
     private String secret;
     private String host;
+    private String rtcHost;
 }

+ 39 - 0
edu-im/edu-im-server/src/main/java/com/keao/edu/im/http/HttpHelper.java

@@ -144,6 +144,38 @@ public class HttpHelper {
         return conn;
     }
 
+    public HttpURLConnection createCommonRtcPostHttpConnection(String host, String appKey,
+        String appSecret, String uri, String contentType,String roomId)
+        throws MalformedURLException, IOException, ProtocolException {
+        String nonce = String.valueOf(Math.random() * 1000000);
+        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
+        StringBuilder toSign = new StringBuilder(appSecret).append(nonce).append(timestamp);
+        String sign = CodeUtil.hexSHA1(toSign.toString());
+        uri = host + uri;
+        URL url = new URL(uri);
+        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+        if (conn == null) {
+            log.info("open url connectin fail, url={}", uri);
+            return null;
+        }
+
+        conn.setUseCaches(false);
+        conn.setDoInput(true);
+        conn.setDoOutput(true);
+        conn.setRequestMethod("POST");
+        conn.setInstanceFollowRedirects(true);
+        conn.setConnectTimeout(30000);
+        conn.setReadTimeout(30000);
+
+        conn.setRequestProperty("App-Key", appKey);
+        conn.setRequestProperty("Nonce", nonce);
+        conn.setRequestProperty("Timestamp", timestamp);
+        conn.setRequestProperty("Signature", sign);
+        conn.setRequestProperty("Room-Id", roomId);
+        conn.setRequestProperty("Content-Type", contentType);
+        return conn;
+    }
+
     public HttpURLConnection createCommonGetHttpConnection(String host, String appKey,
         String appSecret, String uri, String contentType)
         throws MalformedURLException, IOException, ProtocolException {
@@ -189,6 +221,13 @@ public class HttpHelper {
             contentType);
     }
 
+    public HttpURLConnection createIMRtcPostHttpConnection(String uri, String contentType,String roomId)
+        throws MalformedURLException, IOException, ProtocolException {
+        return createCommonRtcPostHttpConnection(imProperties.getRtcHost(),
+                imProperties.getAppKey(), imProperties.getSecret(), uri,
+            contentType,roomId);
+    }
+
     public byte[] readInputStream(InputStream inStream) throws Exception {
         ByteArrayOutputStream outStream = new ByteArrayOutputStream();
         byte[] buffer = new byte[1024];

+ 72 - 0
edu-im/edu-im-server/src/main/java/com/keao/edu/im/mec/im/IMHelper.java

@@ -1,6 +1,8 @@
 package com.keao.edu.im.mec.im;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonObject;
 import com.keao.edu.im.http.HttpHelper;
 import com.keao.edu.im.pojo.IMApiResultInfo;
 import com.keao.edu.im.pojo.IMTokenInfo;
@@ -216,6 +218,76 @@ public class IMHelper {
         return JSON.parseObject(httpHelper.returnResult(conn, body), IMApiResultInfo.class);
     }
 
+    /**
+     * 开始录制
+     * @param hostUserId
+     * @param sessionId
+     * @return
+     * @throws Exception
+     */
+    public IMApiResultInfo startRecord(String hostUserId, String sessionId, String roomId) throws Exception {
+        if (hostUserId == null) {
+            throw new IllegalArgumentException("Paramer 'userId' is required");
+        }
+
+        if (hostUserId == null) {
+            throw new IllegalArgumentException("Paramer 'groupId' is required");
+        }
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("mode","3");
+        jsonObject.put("videoFormat","mp4");
+        jsonObject.put("audioFormat","mp3");
+        jsonObject.put("videoResolution","640x480");
+        jsonObject.put("mixLayout","3");
+        jsonObject.put("sliceMin","60");
+        jsonObject.put("hostUserId",hostUserId);
+        JSONObject json = new JSONObject();
+        json.put("sessionId",sessionId);
+        json.put("config",jsonObject);
+
+        String body = json.toJSONString();
+
+        HttpURLConnection conn = httpHelper.createIMRtcPostHttpConnection("/rtc/record/start.json", "application/x-www-form-urlencoded",roomId);
+        httpHelper.setBodyParameter(body, conn);
+
+        return JSON.parseObject(httpHelper.returnResult(conn, body), IMApiResultInfo.class);
+    }
+
+    /**
+     * 结束录制
+     * @param hostUserId
+     * @param sessionId
+     * @return
+     * @throws Exception
+     */
+    public IMApiResultInfo stopRecord(String hostUserId, String sessionId, String roomId) throws Exception {
+        if (hostUserId == null) {
+            throw new IllegalArgumentException("Paramer 'userId' is required");
+        }
+
+        if (hostUserId == null) {
+            throw new IllegalArgumentException("Paramer 'groupId' is required");
+        }
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("mode","3");
+        jsonObject.put("videoFormat","mp4");
+        jsonObject.put("audioFormat","mp3");
+        jsonObject.put("videoResolution","640x480");
+        jsonObject.put("mixLayout","3");
+        jsonObject.put("sliceMin","60");
+        jsonObject.put("hostUserId",hostUserId);
+        JSONObject json = new JSONObject();
+        json.put("sessionId",sessionId);
+        json.put("config",jsonObject);
+
+        String body = json.toJSONString();
+
+        HttpURLConnection conn = httpHelper.createIMRtcPostHttpConnection("/rtc/record/stop.json", "application/x-www-form-urlencoded",roomId);
+        httpHelper.setBodyParameter(body, conn);
+
+        return JSON.parseObject(httpHelper.returnResult(conn, body), IMApiResultInfo.class);
+    }
+
 
     /**
      * 发送群组消息方法(以一个用户身份向群组发送消息,单条消息最大 128k.每秒钟最多发送 20 条消息,每次最多向 3 个群组发送,如:一次向 3 个群组发送消息,示为 3 条消息。)

+ 1 - 0
edu-im/edu-im-server/src/main/resources/application.yml

@@ -98,6 +98,7 @@ cn:
       appkey: 8luwapkv84g3l
       secret: 7s6m56VCL6Pi
       host: http://api-cn.ronghub.com
+      rtcHost: http://rtcapi-cn.ronghub.com
     whiteboard:
       host: https://sealclass.rongcloud.cn/ewb
     hereWhite:

+ 2 - 1
edu-user/edu-user-server/src/main/java/com/keao/edu/user/dao/SysUserDao.java

@@ -6,6 +6,7 @@ import com.keao.edu.common.dal.BaseDAO;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Set;
 
 public interface SysUserDao extends BaseDAO<Integer, SysUser> {
 
@@ -48,6 +49,6 @@ public interface SysUserDao extends BaseDAO<Integer, SysUser> {
 	 * @param id
 	 * @param roles
 	 */
-	void batchAddEmployeeRole(@Param("userId") Integer id, @Param("roles") List<Integer> roles);
+	void batchAddEmployeeRole(@Param("userId") Integer id, @Param("roles") Set<Integer> roles);
 
 }

+ 3 - 2
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/TenantInfoServiceImpl.java

@@ -73,7 +73,7 @@ public class TenantInfoServiceImpl extends BaseServiceImpl<Integer, TenantInfo>
 		sysUser.setRoles(tenantInfo.getSysUser().getRoles());
 		sysUserDao.insert(sysUser);
 		if(StringUtils.isNotBlank(tenantInfo.getRoleIds())){
-			List<Integer> roleIds = Arrays.stream(tenantInfo.getRoleIds().split(",")).map(e -> Integer.valueOf(e)).collect(Collectors.toList());
+			Set<Integer> roleIds = Arrays.stream(tenantInfo.getRoleIds().split(",")).map(e -> Integer.valueOf(e)).collect(Collectors.toSet());
 			sysUserDao.batchAddEmployeeRole(sysUser.getId(), roleIds);
 		}
 
@@ -113,7 +113,8 @@ public class TenantInfoServiceImpl extends BaseServiceImpl<Integer, TenantInfo>
 			throw new BizException("机构账户不存在");
 		}
 		if(StringUtils.isNotBlank(newTenantInfo.getRoleIds())){
-			List<Integer> roleIds = Arrays.stream(newTenantInfo.getRoleIds().split(",")).map(e -> Integer.valueOf(e)).collect(Collectors.toList());
+
+			Set<Integer> roleIds = Arrays.stream(newTenantInfo.getRoleIds().split(",")).map(e -> Integer.valueOf(e)).collect(Collectors.toSet());
 			//删除当前用户角色
 			sysUserDao.delEmployeeRole(sysUser.getId());
 			//新增用户角色