Procházet zdrojové kódy

用户导入前清空现有用户

xiatian před 1 rokem
rodič
revize
d16b628f32

+ 2 - 0
src/main/java/cn/com/qmth/mps/dao/UserCourseRelationDao.java

@@ -13,4 +13,6 @@ public interface UserCourseRelationDao extends MppBaseMapper<UserCourseRelationE
 
 	List<CourseInfo> getCourses(@Param("userId")Long userId);
 
+	void clearBySchool(@Param("schoolId")Long schoolId);
+
 }

+ 2 - 0
src/main/java/cn/com/qmth/mps/service/UserCourseRelationService.java

@@ -15,4 +15,6 @@ public interface UserCourseRelationService  extends IMppService<UserCourseRelati
 
 	List<CourseInfo> getCourses(Long userId);
 
+	void clearBySchool(Long schoolId);
+
 }

+ 6 - 0
src/main/java/cn/com/qmth/mps/service/impl/UserCourseRelationServiceImpl.java

@@ -57,5 +57,11 @@ public class UserCourseRelationServiceImpl extends
 		return this.baseMapper.getCourses(userId);
 	}
 
+	@Transactional
+	@Override
+	public void clearBySchool(Long schoolId) {
+		baseMapper.clearBySchool(schoolId);
+	}
+
 
 }

+ 10 - 0
src/main/java/cn/com/qmth/mps/service/impl/UserServiceImpl.java

@@ -213,6 +213,7 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
 				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 				return failRecords;
 			}
+			clearUser(schoolId);
 			for (int i = 0; i < userList.size(); i++) {
 				UserDomain cur = userList.get(i);
 				cur.setPasswd(DEFAULT_PASSWD);
@@ -243,6 +244,15 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
 		}
 	}
 
+	private void clearUser(Long schoolId) {
+		userCourseRelationService.clearBySchool(schoolId);
+		QueryWrapper<UserEntity> wrapper = new QueryWrapper<>();
+        LambdaQueryWrapper<UserEntity> lw = wrapper.lambda();
+        lw.eq(UserEntity::getSchoolId, schoolId);
+        lw.ne(UserEntity::getRoleId, Role.SUPER_ADMIN.getId());
+        this.remove(wrapper);
+	}
+
 	private String trimAndNullIfBlank(String s) {
 		if (StringUtils.isBlank(s)) {
 			return null;

binární
src/main/resources/importtemplates/userImport.xlsx


+ 5 - 0
src/main/resources/mapper/UserCourseRelationMapper.xml

@@ -12,4 +12,9 @@
 		t.user_id=#{userId}
 		order by t.course_id
 	</select>
+	<update id="clearBySchool">
+		delete mps_user_course_relation from mps_user,mps_user_course_relation
+		where mps_user.id=mps_user_course_relation.user_id and mps_user.school_id=#{schoolId}
+		and mps_user.role_id!=1
+	</update>
 </mapper>