Browse Source

Merge remote-tracking branch 'origin/saas' into saas

hgw 3 years ago
parent
commit
649d6b4dac

+ 2 - 2
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/dal/dao/SysRoleDao.java

@@ -20,12 +20,12 @@ public interface SysRoleDao extends BaseDAO<Integer, SysRole> {
      * @param code
      * @return
      */
-    SysRole findRoleByCode(@Param("code") String code);
+    SysRole findRoleByCode(@Param("code") String code, @Param("tenantId") Integer tenantId);
 
     /**
      * 根据角色名称获取角色
      * @param roleName
      * @return
      */
-    SysRole findByRoleName(String roleName);
+    SysRole findByRoleName(String roleName, @Param("tenantId") Integer tenantId);
 }

+ 1 - 1
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/service/SysRoleService.java

@@ -19,7 +19,7 @@ public interface SysRoleService extends BaseService<Integer, SysRole> {
      * @param code
      * @return
      */
-    SysRole findRoleByCode(String code);
+    SysRole findRoleByCode(String code, Integer tenantId);
 
     /**
      * 添加角色

+ 6 - 4
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/service/impl/SysRoleServiceImpl.java

@@ -8,6 +8,8 @@ import com.ym.mec.auth.service.SysRoleService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.common.tenant.TenantContextHolder;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -34,14 +36,14 @@ public class SysRoleServiceImpl extends BaseServiceImpl<Integer, SysRole>  imple
 	}
 
 	@Override
-	public SysRole findRoleByCode(String code){
-		return sysRoleDao.findRoleByCode(code);
+	public SysRole findRoleByCode(String code, Integer tenantId){
+		return sysRoleDao.findRoleByCode(code, tenantId);
 	}
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void addRole(SysRole sysRole) {
-		SysRole findByName = sysRoleDao.findByRoleName(sysRole.getRoleName());
+		SysRole findByName = sysRoleDao.findByRoleName(sysRole.getRoleName(), sysRole.getTenantId());
 		if(findByName != null){
 			throw new BizException("操作失败:角色 {} 已存在",sysRole.getRoleName());
 		}
@@ -52,7 +54,7 @@ public class SysRoleServiceImpl extends BaseServiceImpl<Integer, SysRole>  imple
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void updateRole(SysRole sysRole) {
-		SysRole findByName = sysRoleDao.findByRoleName(sysRole.getRoleName());
+		SysRole findByName = sysRoleDao.findByRoleName(sysRole.getRoleName(), sysRole.getTenantId());
 		if(findByName != null && !findByName.getId().equals(sysRole.getId())){
 			throw new BizException("操作失败:角色 {} 已存在",sysRole.getRoleName());
 		}

+ 9 - 8
mec-auth/mec-auth-server/src/main/resources/config/mybatis/SysRoleMapper.xml

@@ -15,6 +15,7 @@
         <result column="update_time_" property="updateTime"/>
         <result column="del_flag_" property="delFlag"/>
         <result column="organ_id_" property="organId"/>
+        <result column="tenant_id_" property="tenantId"/>
     </resultMap>
 
     <!-- 根据主键查询一条记录 -->
@@ -24,14 +25,14 @@
 
     <!-- 全查询 -->
     <select id="findAll" resultMap="SysRole">
-		SELECT * FROM sys_role WHERE del_flag_ = 0 ORDER BY upate_time_ DESC
+		SELECT * FROM sys_role WHERE del_flag_ = 0 and tenant_id_ = #{tenantId} ORDER BY upate_time_ DESC
 	</select>
 
     <!-- 向数据库增加一条记录 -->
     <insert id="insert" parameterType="com.ym.mec.auth.api.entity.SysRole" useGeneratedKeys="true" keyColumn="id"
             keyProperty="id">
-        INSERT INTO sys_role (id_,role_name_,role_code_,role_desc_,create_time_,update_time_,organ_id_)
-        VALUES(#{id},#{roleName},#{roleCode},#{roleDesc},now(),now(),#{organId})
+        INSERT INTO sys_role (id_,role_name_,role_code_,role_desc_,create_time_,update_time_,organ_id_,tenant_id_)
+        VALUES(#{id},#{roleName},#{roleCode},#{roleDesc},now(),now(),#{organId},#{tenantId})
     </insert>
 
     <!-- 根据主键查询一条记录 -->
@@ -57,7 +58,7 @@
                 organ_id_ = #{organId},
             </if>
         </set>
-        WHERE id_ = #{id}
+        WHERE id_ = #{id} and tenant_id_ = #{tenantId}
     </update>
 
     <!-- 根据主键删除一条记录 -->
@@ -67,13 +68,13 @@
 
     <!-- 分页查询 -->
     <select id="queryPage" resultMap="SysRole" parameterType="map">
-        SELECT * FROM sys_role WHERE del_flag_ = 0 ORDER BY update_time_ DESC
+        SELECT * FROM sys_role WHERE del_flag_ = 0 and tenant_id_ = #{tenantId} ORDER BY update_time_ DESC
         <include refid="global.limit"/>
     </select>
 
     <!-- 查询当前表的总记录数 -->
     <select id="queryCount" resultType="int">
-		SELECT COUNT(*) FROM sys_role WHERE del_flag_ = 0
+		SELECT COUNT(*) FROM sys_role WHERE del_flag_ = 0 and tenant_id_ = #{tenantId}
 	</select>
 
     <select id="findRoleByUserId" resultMap="SysRole">
@@ -81,9 +82,9 @@
 	</select>
 
     <select id="findRoleByCode" resultMap="SysRole">
-        SELECT sr.* FROM sys_role WHERE role_code_ = #{code} AND sr.del_flag_ = 0
+        SELECT sr.* FROM sys_role WHERE role_code_ = #{code} AND sr.del_flag_ = 0 and tenant_id_ = #{tenantId}
     </select>
     <select id="findByRoleName" resultMap="SysRole">
-        SELECT * FROM sys_role WHERE role_name_ = #{roleName} AND del_flag_ = 0 LIMIT 1
+        SELECT * FROM sys_role WHERE role_name_ = #{roleName} AND del_flag_ = 0 and tenant_id_ = #{tenantId} LIMIT 1
     </select>
 </mapper>

+ 2 - 2
mec-biz/src/main/resources/config/mybatis/PracticeGroupMapper.xml

@@ -305,7 +305,7 @@
                 AND pg.user_id_=#{teacherId}
             </if>
             <if test="tenantId != null">
-                AND pg.tenanr_id_ = #{tenantId}
+                AND pg.tenant_id_ = #{tenantId}
             </if>
             <if test="studentId != null">
                 AND pg.student_id_ = #{studentId}
@@ -370,7 +370,7 @@
     <sql id="practiceGroupReviewsQueryCondition">
         <where>
             pg.group_status_ != 'LOCK'
-            AND pg.tenanr_id_ = #{tenantId}
+            AND pg.tenant_id_ = #{tenantId}
             <if test="month != null">
                 AND DATE_FORMAT(cse.create_time_, '%Y-%m') = #{month}
             </if>

+ 6 - 0
mec-thirdparty/pom.xml

@@ -87,6 +87,12 @@
 			<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
 			<version>1.2.0</version>
 		</dependency>
+		
+		<dependency>
+		    <groupId>org.apache.commons</groupId>
+		    <artifactId>commons-email</artifactId>
+		    <version>1.5</version>
+		</dependency>
 
 		<dependency>
 			<groupId>org.springframework.cloud</groupId>

+ 106 - 0
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/message/provider/CommEmailPlugin.java

@@ -0,0 +1,106 @@
+package com.ym.mec.thirdparty.message.provider;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.mail.DefaultAuthenticator;
+import org.apache.commons.mail.Email;
+import org.apache.commons.mail.EmailException;
+import org.apache.commons.mail.SimpleEmail;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.stereotype.Service;
+
+import com.ym.mec.thirdparty.message.MessageSenderPlugin;
+
+//@Service
+public class CommEmailPlugin implements MessageSenderPlugin, InitializingBean {
+	
+	private String hostName;
+
+	private int smtpPort;
+
+	private String userName;
+
+	private String password;
+
+	private String from;
+
+	private String fromName;
+
+	public void setHostName(String hostName) {
+		this.hostName = hostName;
+	}
+
+	public void setSmtpPort(int smtpPort) {
+		this.smtpPort = smtpPort;
+	}
+
+	public void setUserName(String userName) {
+		this.userName = userName;
+	}
+
+	public void setPassword(String password) {
+		this.password = password;
+	}
+
+	public void setFrom(String from) {
+		this.from = from;
+	}
+
+	public void setFromName(String fromName) {
+		this.fromName = fromName;
+	}
+
+	@Override
+	public void afterPropertiesSet() throws Exception {
+		if (StringUtils.isBlank(hostName)) {
+			throw new RuntimeException("SMTP服务器没有配置");
+		}
+
+		if (smtpPort == 0) {
+			throw new RuntimeException("SMTP服务器端口没有配置");
+		}
+
+		if (StringUtils.isBlank(userName)) {
+			throw new RuntimeException("SMTP服务器认证用户名没有配置");
+		}
+
+		if (StringUtils.isBlank(password)) {
+			throw new RuntimeException("SMTP服务器认证密码没有配置");
+		}
+
+		if (StringUtils.isBlank(from)) {
+			throw new RuntimeException("发件人邮箱没有配置");
+		}
+
+		if (StringUtils.isBlank(fromName)) {
+			fromName = from;
+		}
+	}
+
+	@Override
+	public boolean send(String subject, String content, String receiver, String url, String jpushType, String sound, String channelId) throws Exception {
+		Email email = new SimpleEmail();
+		email.setHostName(hostName);
+		email.setSslSmtpPort(smtpPort + "");
+		email.setAuthenticator(new DefaultAuthenticator(userName, password));
+		// email.setSSLOnConnect(true);
+		try {
+			email.setFrom(from, fromName);
+			email.setSubject(subject);
+			email.setMsg(content);
+			email.addTo(receiver);
+			email.send();
+			return true;
+		} catch (EmailException e) {
+			throw new RuntimeException("发送邮件出现异常", e);
+		}
+	}
+
+	@Override
+	public boolean batchSend(String subject, String content, String[] receivers, String url, String jpushType, String sound, String channelId) throws Exception {
+		for (String rev : receivers) {
+			send(subject, content, rev, url, jpushType, sound, channelId);
+		}
+		return true;
+	}
+
+}