Pārlūkot izejas kodu

Merge branch 'develop' of http://git.dayaedu.com/yonge/cooleshow

zouxuan 1 gadu atpakaļ
vecāks
revīzija
87d7b67a7d

+ 17 - 3
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/StudentController.java

@@ -33,6 +33,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -206,16 +207,29 @@ public class StudentController extends BaseController {
         if (user == null || null == user.getId()) {
             return failed(HttpStatus.FORBIDDEN, "请登录");
         }
-        if (user.getTenantId() == null || user.getTenantId() == -1L) {
-            return failed("非机构用户不允许更换机构");
-        }
 
         Student student = studentService.getById(user.getId());
         if (student == null) {
             return failed("未查询到学生的信息");
         }
 
+        if (student.getTenantId() == null || student.getTenantId() == -1L) {
+            return failed("非机构用户不允许更换机构");
+        }
+
         studentService.updateTenant(student, updateTenant.getTenantId());
         return succeed();
     }
+
+
+    @PostMapping("/add")
+    @ApiOperation(value = "新增", notes = "传入Student")
+    public HttpResponseResult<Boolean> add(@Validated @RequestBody StudentWrapper.Student student) {
+        SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone());
+        if (sysUser != null && sysUser.getUserType().contains(ClientEnum.STUDENT.getCode())) {
+            throw new BizException("学生账号已经存在");
+        }
+        studentService.addStudent(student);
+        return succeed();
+    }
 }

+ 37 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/ImGroupController.java

@@ -32,8 +32,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Objects;
+import java.util.Set;
 
 /**
  * 即时通讯群组(ImGroup)表控制层
@@ -73,6 +75,41 @@ public class ImGroupController extends BaseController {
         return succeed();
     }
 
+    @ApiOperation("创建群聊")
+    @PostMapping(value = "/create/v2")
+    public HttpResponseResult createV2(@Valid @RequestBody ImGroupWrapper.ImGroup imGroup, BindingResult bindingResult) throws Exception {
+
+        // 将imUserId 转为userId
+        Set<String> imUserIdList = imGroup.getImUserIdList();
+
+        Set<Long> studentIdList = new HashSet<>();
+        for (String imUserId : imUserIdList) {
+            studentIdList.add(Long.parseLong(imGroupService.analysisImUserId(imUserId)));
+        }
+        imGroup.setStudentIdList(studentIdList);
+
+        ValidationKit.ignoreFields(bindingResult,"id");
+        imGroup.setCreateBy(sysUserService.getUserId());
+        imGroupService.create(imGroup);
+        return succeed();
+    }
+
+    @ApiOperation("添加群成员")
+    @PostMapping(value = "/addGroupMember/v2")
+    public HttpResponseResult addGroupMemberV2(@Valid @RequestBody ImGroupWrapper.ImGroup imGroup,
+                                               BindingResult bindingResult) throws Exception {
+        // 将imUserId 转为userId
+        Set<String> imUserIdList = imGroup.getImUserIdList();
+
+        Set<Long> studentIdList = new HashSet<>();
+        for (String imUserId : imUserIdList) {
+            studentIdList.add(Long.parseLong(imGroupService.analysisImUserId(imUserId)));
+        }
+        imGroup.setStudentIdList(studentIdList);
+
+        imGroupService.addGroupMember(imGroup.getGroupId(), imGroup.getStudentIdList());
+        return succeed();
+    }
     @ApiOperation("解散群聊")
     @PostMapping(value = "/dismiss/{groupId}")
     public HttpResponseResult dismiss(@ApiParam(value = "群编号", required = true) @PathVariable("groupId") String groupId) throws Exception {

+ 13 - 11
cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/controller/StudentController.java

@@ -47,6 +47,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -60,13 +61,12 @@ import java.util.stream.Collectors;
 @RequestMapping("${app-config.url.tenant:}/student")
 @Api(value = "学生表", tags = "学生表")
 public class StudentController extends BaseController {
+
     @Autowired
     private StudentService studentService;
-
     @Autowired
     private TeacherService teacherService;
-
-    @Autowired
+    @Resource
     private SysUserFeignService sysUserFeignService;
     @Autowired
     private ImUserFriendService imUserFriendService;
@@ -104,17 +104,18 @@ public class StudentController extends BaseController {
         });
 
 
-        Map<Long, List<TenantActivationCode>> groupByUserId = new HashMap<>();
+        Map<String, List<TenantActivationCode>> groupByPhone = new HashMap<>();
         if (!rows.isEmpty() && query.getTenantAlbumPurchaseId() != null) {
-            List<String> studentPhones = rows.stream().map(StudentVo::getPhone).collect(Collectors.toList());
-            groupByUserId = tenantActivationCodeService.lambdaQuery()
+            List<String> studentPhones =
+                    rows.stream().map(StudentVo::getPhone).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
+            groupByPhone = tenantActivationCodeService.lambdaQuery()
                     .eq(TenantActivationCode::getId, query.getTenantAlbumPurchaseId())
                     .in(TenantActivationCode::getActivationPhone, studentPhones)
-                    .list().stream().collect(Collectors.groupingBy(TenantActivationCode::getActivationUserId));
+                    .list().stream().collect(Collectors.groupingBy(TenantActivationCode::getActivationPhone));
         }
 
         for (StudentVo vo : rows) {
-            vo.setSendActiveCodeNum(groupByUserId.getOrDefault(vo.getUserId(), new ArrayList<>()).size());
+            vo.setSendActiveCodeNum(groupByPhone.getOrDefault(vo.getPhone(), new ArrayList<>()).size());
             if (StringUtils.isNotEmpty(vo.getPhone())) {
                 vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));
             }
@@ -165,11 +166,12 @@ public class StudentController extends BaseController {
         studentService.save(studentInfo);
 
         // 加好友
-        if (studentInfo.getId() == null) {
-            SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone());
+        SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone());
+        Student newStudent = studentService.getById(sysUser.getId());
+        if (newStudent.getTenantId()!= null && newStudent.getTenantId()!=-1L) {
             // 自动与机构老师成为好友
             List<Teacher> teacherList = teacherService.lambdaQuery()
-                    .eq(Teacher::getTenantId, studentInfo.getTenantId()).list();
+                    .eq(Teacher::getTenantId, newStudent.getTenantId()).list();
             teacherList.forEach(next -> imUserFriendService.saveUserFriend(next.getUserId(),
                     new HashSet<>(ImmutableList.of(sysUser.getId()))));
         }

+ 10 - 19
cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/controller/open/OpenStudentController.java

@@ -80,8 +80,7 @@ public class OpenStudentController extends BaseController {
         if (StringUtils.isEmpty(code)) {
             throw new BizException("验证码不能为空");
         }
-        if (!smsCodeService.verifyValidCode(student.getPhone(), code,
-                MessageTypeEnum.SMS_VERIFY_CODE_REGISTER.getCode())) {
+        if (!smsCodeService.verifyValidCode(student.getPhone(), code, "REGISTER")) {
             throw new BizException("验证码错误");
         }
         Long tenantId = student.getTenantId();
@@ -109,10 +108,10 @@ public class OpenStudentController extends BaseController {
                 if (one.getTenantId().equals(-1L)) {
                     throw new BizException("该手机号已经注册为平台学生");
                 }
-//                if (one.getTenantId().equals(tenantId)) {
-//                    //已经注册当前机构,请勿重复注册
-//                    throw new BizException(5004, tenantInfo.getName());
-//                }
+                if (one.getTenantId().equals(tenantId)) {
+                    //已经注册当前机构,请勿重复注册
+                    throw new BizException("已经注册当前机构,请勿重复注册");
+                }
                 // 转到其他机构
                 if ((!Objects.equals(student.getTenantId(), one.getTenantId()))) {
                     if(student.getUpdateTenant() == null || Boolean.FALSE.equals(student.getUpdateTenant())){
@@ -134,6 +133,8 @@ public class OpenStudentController extends BaseController {
                                 log.error("学生注册,切换机构退群失败:{}", e.getMessage());
                             }
                         });
+                        // 删除好友
+                        imUserFriendService.delFriendByTenantId(tenantId, one.getUserId());
                     }
                 }
 
@@ -145,25 +146,15 @@ public class OpenStudentController extends BaseController {
             student.setId(studentId);
         }
 
-        // 配置头像
-        String avatar = student.getAvatar();
-        if (StringUtils.isEmpty(avatar)) {
-            if (student.getGender().equals(1)) {
-                avatar = sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD_BOY);
-            } else {
-                avatar = sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD_GIRL);
-            }
-            student.setAvatar(avatar);
-        }
-
         StudentWrapper.Student studentInfo = JSON.parseObject(JSON.toJSONString(student), StudentWrapper.Student.class);
         studentInfo.setTenantId(tenantInfo.getId());
 
         studentService.save(studentInfo);
 
         // 加好友
-        if (student.getId() == null) {
-            SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone());
+        SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone());
+        Student newStudent = studentService.getById(sysUser.getId());
+        if (newStudent.getTenantId()!= null && newStudent.getTenantId()!=-1L) {
             // 自动与机构老师成为好友
             List<Teacher> teacherList = teacherService.lambdaQuery()
                     .eq(Teacher::getTenantId, tenantId).list();

+ 4 - 3
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/StudentController.java

@@ -207,15 +207,16 @@ public class StudentController extends BaseController {
         if (user == null || null == user.getId()) {
             return failed(HttpStatus.FORBIDDEN, "请登录");
         }
-        if (user.getTenantId() == null || user.getTenantId() == -1L) {
-            return failed("非机构用户不允许更换机构");
-        }
 
         Student student = studentService.getById(user.getId());
         if (student == null) {
             return failed("未查询到学生的信息");
         }
 
+        if (student.getTenantId() == null || student.getTenantId() == -1L) {
+            return failed("非机构用户不允许更换机构");
+        }
+
         studentService.updateTenant(student, updateTenant.getTenantId());
         return succeed();
     }

+ 20 - 8
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentServiceImpl.java

@@ -519,10 +519,11 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
     @Transactional(rollbackFor = Exception.class)
     @Override
     public void updateTenant(Student student, Long toTenantId) {
-        if (student.getTenantId().equals(toTenantId)) {
+        Long tenantId = student.getTenantId();
+        if (tenantId.equals(toTenantId)) {
             return;
         }
-        if (!student.getTenantId().equals(-1L)) {
+        if (!tenantId.equals(-1L)) {
             List<ImGroupMember> groupMembers = imGroupMemberService.lambdaQuery()
                     .eq(ImGroupMember::getUserId, student.getUserId())
                     .eq(ImGroupMember::getRoleType, ClientEnum.STUDENT.getCode())
@@ -536,6 +537,19 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
                     log.error("退出群聊失败", e);
                 }
             }
+            // 删除机构好友关系
+            imUserFriendService.delFriendByTenantId(tenantId, student.getUserId());
+        }
+        if (toTenantId != null && toTenantId != -1L) {
+            // 加好友
+            QueryWrapper<Teacher> query = new QueryWrapper<>();
+            query.lambda().eq(Teacher::getTenantId, toTenantId);
+            List<Teacher> teachers = teacherDao.selectList(query);
+            for (Teacher teacher : teachers) {
+                HashSet<Long> studentIds = new HashSet<>();
+                studentIds.add(student.getUserId());
+                imUserFriendService.saveUserFriend(teacher.getUserId(), studentIds);
+            }
         }
         this.lambdaUpdate().set(Student::getTenantId, toTenantId)
                 .eq(Student::getUserId, student.getUserId())
@@ -547,12 +561,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
     public void addStudent(StudentWrapper.Student student) {
         // 更新头像
         if (StringUtils.isEmpty(student.getAvatar())) {
-            String avatar;
-            if (student.getGender().equals(1)) {
-                avatar = sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD_BOY);
-            } else {
-                avatar = sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD_GIRL);
-            }
+            String avatar = sysConfigService.findConfigValue(SysConfigConstant.STUDENT_AVATAR);
             student.setAvatar(avatar);
         }
         SysUser sysUser = employeeDao.querySysUserByPhone(student.getPhone());
@@ -571,6 +580,9 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
             //插入
             employeeDao.insertSysUser(sysUser);
         } else {
+            if(StringUtils.isNotEmpty(sysUser.getUserType()) && sysUser.getUserType().contains(ClientEnum.STUDENT.getCode())){
+                throw new BizException("手机号已经注册学生账号");
+            }
             if (StringUtil.isEmpty(sysUser.getUserType())) {
                 sysUser.setUserType(ClientEnum.STUDENT.getCode());
             } else if (!sysUser.getUserType().contains(ClientEnum.STUDENT.getCode())) {

+ 5 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/im/ImGroupWrapper.java

@@ -122,6 +122,8 @@ public class ImGroupWrapper {
 
         private Set<Long> studentIdList = new HashSet<>();
 
+        private Set<String> imUserIdList = new HashSet<>();
+
         public static ImGroup from(String json) {
             return JSON.parseObject(json, ImGroup.class);
         }
@@ -166,3 +168,6 @@ public class ImGroupWrapper {
         }
     }
 }
+
+
+

+ 3 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/SysMusicCompareRecordMapper.xml

@@ -409,6 +409,9 @@
 		from student st
 		LEFT JOIN sys_music_compare_record smcr ON smcr.user_id_ = st.user_id_
 		<where>
+			<if test="queryInfo.clientId != null and queryInfo.clientId!= ''">
+				AND smcr.client_id_ = #{queryInfo.clientId}
+			</if>
 			<if test="queryInfo.startTime != null and queryInfo.startTime != ''">
 				AND smcr.create_time_ BETWEEN #{queryInfo.startTime} AND #{queryInfo.endTime}
 			</if>

+ 36 - 2
cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/ImGroupController.java

@@ -32,8 +32,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * 即时通讯群组(ImGroup)表控制层
@@ -73,6 +72,41 @@ public class ImGroupController extends BaseController {
         return succeed();
     }
 
+    @ApiOperation("创建群聊")
+    @PostMapping(value = "/create/v2")
+    public HttpResponseResult createV2(@Valid @RequestBody ImGroupWrapper.ImGroup imGroup, BindingResult bindingResult) throws Exception {
+
+        // 将imUserId 转为userId
+        Set<String> imUserIdList = imGroup.getImUserIdList();
+
+        Set<Long> studentIdList = new HashSet<>();
+        for (String imUserId : imUserIdList) {
+            studentIdList.add(Long.parseLong(imGroupService.analysisImUserId(imUserId)));
+        }
+        imGroup.setStudentIdList(studentIdList);
+
+        ValidationKit.ignoreFields(bindingResult,"id");
+        imGroup.setCreateBy(sysUserService.getUserId());
+        imGroupService.create(imGroup);
+        return succeed();
+    }
+
+    @ApiOperation("添加群成员")
+    @PostMapping(value = "/addGroupMember/v2")
+    public HttpResponseResult addGroupMemberV2(@Valid @RequestBody ImGroupWrapper.ImGroup imGroup,
+                                             BindingResult bindingResult) throws Exception {
+        // 将imUserId 转为userId
+        Set<String> imUserIdList = imGroup.getImUserIdList();
+
+        Set<Long> studentIdList = new HashSet<>();
+        for (String imUserId : imUserIdList) {
+            studentIdList.add(Long.parseLong(imGroupService.analysisImUserId(imUserId)));
+        }
+        imGroup.setStudentIdList(studentIdList);
+
+        imGroupService.addGroupMember(imGroup.getGroupId(), imGroup.getStudentIdList());
+        return succeed();
+    }
     @ApiOperation("解散群聊")
     @PostMapping(value = "/dismiss/{groupId}")
     public HttpResponseResult dismiss(@ApiParam(value = "群编号", required = true) @PathVariable("groupId") String groupId) throws Exception {

+ 10 - 8
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/StudentController.java

@@ -103,17 +103,18 @@ public class StudentController extends BaseController {
         });
 
 
-        Map<Long, List<TenantActivationCode>> groupByUserId = new HashMap<>();
+        Map<String, List<TenantActivationCode>> groupByPhone = new HashMap<>();
         if (!rows.isEmpty() && query.getTenantAlbumPurchaseId() != null) {
-            List<String> studentPhones = rows.stream().map(StudentVo::getPhone).collect(Collectors.toList());
-             groupByUserId = tenantActivationCodeService.lambdaQuery()
+            List<String> studentPhones =
+                    rows.stream().map(StudentVo::getPhone).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
+             groupByPhone = tenantActivationCodeService.lambdaQuery()
                     .eq(TenantActivationCode::getId, query.getTenantAlbumPurchaseId())
                     .in(TenantActivationCode::getActivationPhone, studentPhones)
-                    .list().stream().collect(Collectors.groupingBy(TenantActivationCode::getActivationUserId));
+                    .list().stream().collect(Collectors.groupingBy(TenantActivationCode::getActivationPhone));
         }
 
         for (StudentVo vo : rows) {
-            vo.setSendActiveCodeNum(groupByUserId.getOrDefault(vo.getUserId(), new ArrayList<>()).size());
+            vo.setSendActiveCodeNum(groupByPhone.getOrDefault(vo.getPhone(), new ArrayList<>()).size());
             if (StringUtils.isNotEmpty(vo.getPhone())) {
                 vo.setPhone(vo.getPhone().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));
             }
@@ -164,11 +165,12 @@ public class StudentController extends BaseController {
         studentService.save(studentInfo);
 
         // 加好友
-        if (studentInfo.getId() == null) {
-            SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone());
+        SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone());
+        Student newStudent = studentService.getById(sysUser.getId());
+        if (newStudent.getTenantId()!= null && newStudent.getTenantId()!=-1L) {
             // 自动与机构老师成为好友
             List<Teacher> teacherList = teacherService.lambdaQuery()
-                    .eq(Teacher::getTenantId, studentInfo.getTenantId()).list();
+                    .eq(Teacher::getTenantId, newStudent.getTenantId()).list();
             teacherList.forEach(next -> imUserFriendService.saveUserFriend(next.getUserId(),
                     new HashSet<>(ImmutableList.of(sysUser.getId()))));
         }

+ 5 - 2
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/open/OpenStudentController.java

@@ -133,6 +133,8 @@ public class OpenStudentController extends BaseController {
                                 log.error("学生注册,切换机构退群失败:{}", e.getMessage());
                             }
                         });
+                        // 删除好友
+                        imUserFriendService.delFriendByTenantId(tenantId, one.getUserId());
                     }
                 }
 
@@ -150,8 +152,9 @@ public class OpenStudentController extends BaseController {
         studentService.save(studentInfo);
 
         // 加好友
-        if (student.getId() == null) {
-            SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone());
+        SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone());
+        Student newStudent = studentService.getById(sysUser.getId());
+        if (newStudent.getTenantId()!= null && newStudent.getTenantId()!=-1L) {
             // 自动与机构老师成为好友
             List<Teacher> teacherList = teacherService.lambdaQuery()
                     .eq(Teacher::getTenantId, tenantId).list();