|
@@ -6,18 +6,28 @@ import com.dayaedu.cbs.openfeign.client.MessageFeignClientService;
|
|
|
import com.dayaedu.cbs.openfeign.wrapper.message.CbsMessageWrapper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.microsvc.toolkit.common.response.template.R;
|
|
|
+import com.yonge.cooleshow.api.feign.MallPortalFeignService;
|
|
|
+import com.yonge.cooleshow.api.feign.dto.OmsOrderDetail;
|
|
|
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
|
import com.yonge.cooleshow.auth.api.dto.RealnameAuthReq;
|
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.CourseGroup;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.ImGroup;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.ImGroupMember;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.ImUserFriend;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.Student;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.Subject;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.Teacher;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.UserOrder;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.UserOrderRefund;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.VideoLessonGroup;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.AuthStatusEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.ImGroupType;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.OrderStatusEnum;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.im.EImGroupMemberRoleType;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.StudentService;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.SysUserContractRecordService;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.SysUserService;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.TeacherService;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.*;
|
|
|
+import com.yonge.cooleshow.biz.dal.vo.UserAccountVo;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.UserInfoWrapper;
|
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
import com.yonge.cooleshow.common.enums.ContractTemplateTypeEnum;
|
|
@@ -27,16 +37,24 @@ import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.yonge.toolset.thirdparty.user.realname.RealnameAuthenticationPlugin;
|
|
|
import com.yonge.toolset.utils.idcard.IdcardInfoExtractor;
|
|
|
import com.yonge.toolset.utils.idcard.IdcardValidator;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class SysUserServiceImpl implements SysUserService {
|
|
|
|
|
@@ -56,6 +74,34 @@ public class SysUserServiceImpl implements SysUserService {
|
|
|
private MessageSenderPluginContext messageSenderPluginContext;
|
|
|
@Resource
|
|
|
private MessageFeignClientService messageFeignClientService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserOrderService userOrderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserOrderRefundService userOrderRefundService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ImGroupMemberService imGroupMemberService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ImGroupService imGroupService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CourseGroupService courseGroupService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private VideoLessonGroupService videoLessonGroupService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private UserAccountService userAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MallPortalFeignService mallPortalFeignService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ImUserFriendService imUserFriendService;
|
|
|
+
|
|
|
@Override
|
|
|
public SysUserMapper getDao() {
|
|
|
return sysUserMapper;
|
|
@@ -201,4 +247,159 @@ public class SysUserServiceImpl implements SysUserService {
|
|
|
return EClientType.BACKEND;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> accountLogoffCheck(String phone) {
|
|
|
+ SysUser sysUser = this.getDao().findUserByPhone(phone);
|
|
|
+ if (sysUser == null || Boolean.TRUE.equals(sysUser.getDelFlag())) {
|
|
|
+ throw new BizException("账号不存在");
|
|
|
+ }
|
|
|
+ List<String> errMsg = new ArrayList<>();
|
|
|
+ Long userId = sysUser.getId();
|
|
|
+
|
|
|
+ // 存在待支付、未确认收货、售后处理的订单
|
|
|
+ if(hasUnfinishedOrder(userId)){
|
|
|
+ errMsg.add("账户存在未支付、未确认收货、售后处理中的订单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 存在进行中的课程
|
|
|
+ // 陪练课
|
|
|
+ Integer course = courseGroupService.lambdaQuery()
|
|
|
+ .eq(CourseGroup::getTeacherId, userId)
|
|
|
+ .in(CourseGroup::getType, Arrays.asList("PRACTICE", "LIVE", "PIANO_ROOM_CLASS"))
|
|
|
+ .in(CourseGroup::getStatus, Arrays.asList("ING", "APPLY"))
|
|
|
+ .count();
|
|
|
+ // 视频课
|
|
|
+ Integer videoCourse = videoLessonGroupService.lambdaQuery()
|
|
|
+ .eq(VideoLessonGroup::getTeacherId, userId)
|
|
|
+ .eq(VideoLessonGroup::getShelvesFlag, 1)
|
|
|
+ .count();
|
|
|
+
|
|
|
+ if (course > 0 || videoCourse > 0) {
|
|
|
+ errMsg.add("存在进行中的课程");
|
|
|
+ }
|
|
|
+
|
|
|
+ Teacher teacher = teacherService.getById(userId);
|
|
|
+
|
|
|
+ if (teacher != null) {
|
|
|
+ // 存在群主身份
|
|
|
+ List<ImGroupMember> groupMembers = imGroupMemberService.lambdaQuery()
|
|
|
+ .eq(ImGroupMember::getUserId, userId)
|
|
|
+ .eq(ImGroupMember::getGroupRoleType, EImGroupMemberRoleType.Owner)
|
|
|
+ .list();
|
|
|
+ List<String> groupIdList = groupMembers.stream().map(ImGroupMember::getGroupId).collect(Collectors.toList());
|
|
|
+ if (!groupIdList.isEmpty()) {
|
|
|
+ Collection<ImGroup> imGroups = imGroupService.listByIds(groupIdList);
|
|
|
+ long orgGroups = imGroups.stream().filter(next -> ImGroupType.ORG.equals(next.getType())).count();
|
|
|
+ if (orgGroups > 0) {
|
|
|
+ errMsg.add("账户为机构群群主、需要庄毅群主或解散群聊");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 存在未提现的金额
|
|
|
+ UserAccountVo detail = userAccountService.detail(userId);
|
|
|
+ if (detail != null && (detail.getAmountTotal().compareTo(BigDecimal.ZERO) > 0 || detail.getAmountUnrecorded().compareTo(BigDecimal.ZERO) > 0)) {
|
|
|
+ errMsg.add("收入未结算/推广计划未入账");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return errMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean hasUnfinishedOrder(Long userId) {
|
|
|
+ // 商城订单 0->待付款;1->待发货;2->已发货
|
|
|
+ HttpResponseResult<List<OmsOrderDetail>> httpResponseResult = mallPortalFeignService.queryOrderList("0,1,2", userId);
|
|
|
+ if (httpResponseResult == null) {
|
|
|
+ throw new BizException("检查订单信息失败");
|
|
|
+ }
|
|
|
+ List<OmsOrderDetail> data = httpResponseResult.getData();
|
|
|
+ if (!CollectionUtils.isEmpty(data)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 酷乐秀订单
|
|
|
+ Integer count = userOrderService.lambdaQuery()
|
|
|
+ .eq(UserOrder::getUserId, userId)
|
|
|
+ .in(UserOrder::getStatus, Arrays.asList(OrderStatusEnum.WAIT_PAY, OrderStatusEnum.PAYING))
|
|
|
+ .count();
|
|
|
+ if (count > 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ Integer refundCount = userOrderRefundService.lambdaQuery()
|
|
|
+ .eq(UserOrderRefund::getUserId, userId)
|
|
|
+ .eq(UserOrderRefund::getStatus, AuthStatusEnum.DOING)
|
|
|
+ .count();
|
|
|
+ return refundCount > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 账号注销,群聊处理
|
|
|
+ * 学生:退群,删除好友关系
|
|
|
+ * 老师:非机构群 群主,注销群,删除好友
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void logoffQuitImGroup(String phone) {
|
|
|
+ SysUser sysUser = this.getDao().findUserByPhone(phone);
|
|
|
+ if (sysUser == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long userId = sysUser.getId();
|
|
|
+ Student student = studentService.getById(userId);
|
|
|
+ if (student != null) {
|
|
|
+ List<ImGroupMember> groupMembers = imGroupMemberService.lambdaQuery()
|
|
|
+ .eq(ImGroupMember::getUserId, sysUser.getId())
|
|
|
+ .eq(ImGroupMember::getGroupRoleType, EImGroupMemberRoleType.Member)
|
|
|
+ .list();
|
|
|
+ List<String> groupIdList = groupMembers.stream().map(ImGroupMember::getGroupId).collect(Collectors.toList());
|
|
|
+ // 退群
|
|
|
+ for (String groupId : groupIdList) {
|
|
|
+ try {
|
|
|
+ imGroupService.quit(groupId, userId, ClientEnum.STUDENT, true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("学生注销退群失败->学生:" + userId + "," + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 删除好友
|
|
|
+ imUserFriendService.lambdaUpdate()
|
|
|
+ .eq(ImUserFriend::getUserId, userId)
|
|
|
+ .eq(ImUserFriend::getClientType, EClientType.STUDENT)
|
|
|
+ .remove();
|
|
|
+ imUserFriendService.lambdaUpdate()
|
|
|
+ .eq(ImUserFriend::getFriendId, userId)
|
|
|
+ .eq(ImUserFriend::getFriendType, EClientType.STUDENT)
|
|
|
+ .remove();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Teacher teacher = teacherService.getById(sysUser.getId());
|
|
|
+ if (teacher != null) {
|
|
|
+ List<ImGroupMember> groupMembers = imGroupMemberService.lambdaQuery()
|
|
|
+ .eq(ImGroupMember::getUserId, sysUser.getId())
|
|
|
+ .eq(ImGroupMember::getGroupRoleType, EImGroupMemberRoleType.Owner)
|
|
|
+ .list();
|
|
|
+ List<String> groupIdList = groupMembers.stream().map(ImGroupMember::getGroupId).collect(Collectors.toList());
|
|
|
+ if (groupIdList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Collection<ImGroup> imGroups = imGroupService.listByIds(groupIdList);
|
|
|
+ List<String> groupIds = imGroups.stream().filter(next -> ImGroupType.FAN.equals(next.getType()) || ImGroupType.COURSE.equals(next.getType()))
|
|
|
+ .map(ImGroup::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (String groupId : groupIds) {
|
|
|
+ try {
|
|
|
+ imGroupService.dismiss(groupId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("群解散失败:" + groupId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 删除好友
|
|
|
+ imUserFriendService.lambdaUpdate()
|
|
|
+ .eq(ImUserFriend::getUserId, userId)
|
|
|
+ .eq(ImUserFriend::getClientType, EClientType.TEACHER)
|
|
|
+ .remove();
|
|
|
+ imUserFriendService.lambdaUpdate()
|
|
|
+ .eq(ImUserFriend::getFriendId, userId)
|
|
|
+ .eq(ImUserFriend::getFriendType, EClientType.TEACHER)
|
|
|
+ .remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|