|
@@ -3,31 +3,48 @@ package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
|
import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
-import com.yonge.cooleshow.biz.dal.dao.StudentDao;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.SubjectDao;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.TeacherDao;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.*;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.Subject;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.SysArea;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.Teacher;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.TenantInfo;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.TenantUnbindRecord;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.*;
|
|
|
+import com.yonge.cooleshow.biz.dal.mapper.SysAreaMapper;
|
|
|
+import com.yonge.cooleshow.biz.dal.mapper.TenantUnbindRecordMapper;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.StudentService;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.SysConfigService;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.SysMessageService;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.TeacherService;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.TenantInfoService;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.TenantUnbindRecordService;
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.TenantUnbindRecordWrapper;
|
|
|
import com.yonge.cooleshow.common.constant.SysConfigConstant;
|
|
|
+import com.yonge.cooleshow.common.enums.ETenantUnBindAuditStatus;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
|
|
|
+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.beans.BeanUtils;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import com.yonge.cooleshow.biz.dal.wrapper.TenantUnbindRecordWrapper;
|
|
|
-import com.yonge.cooleshow.biz.dal.mapper.TenantUnbindRecordMapper;
|
|
|
-
|
|
|
-import java.util.*;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* 机构解绑申请记录
|
|
@@ -42,9 +59,6 @@ public class TenantUnbindRecordServiceImpl extends ServiceImpl<TenantUnbindRecor
|
|
|
private TeacherDao teacherDao;
|
|
|
|
|
|
@Autowired
|
|
|
- private StudentDao studentDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private SubjectDao subjectDao;
|
|
|
|
|
|
@Autowired
|
|
@@ -60,174 +74,166 @@ public class TenantUnbindRecordServiceImpl extends ServiceImpl<TenantUnbindRecor
|
|
|
private TeacherService teacherService;
|
|
|
|
|
|
@Autowired
|
|
|
- private SysMessageService sysMessageService;
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
|
|
|
@Autowired
|
|
|
- private SysConfigService sysConfigService;
|
|
|
+ private SysAreaMapper sysAreaMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private TenantInfoService tenantInfoService;
|
|
|
|
|
|
- /**
|
|
|
- * 查询详情
|
|
|
+ @Autowired
|
|
|
+ private SysMessageService sysMessageService;
|
|
|
+
|
|
|
+ /**
|
|
|
* @param id 详情ID
|
|
|
* @return TenantUnbindRecord
|
|
|
*/
|
|
|
- @Override
|
|
|
+ @Override
|
|
|
public TenantUnbindRecord detail(Long id) {
|
|
|
-
|
|
|
+
|
|
|
return baseMapper.selectById(id);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 分页查询
|
|
|
- * @param page IPage<TenantUnbindRecord>
|
|
|
+ *
|
|
|
+ * @param page IPage<TenantUnbindRecord>
|
|
|
* @param query TenantUnbindRecordWrapper.TenantUnbindRecordQuery
|
|
|
* @return IPage<TenantUnbindRecord>
|
|
|
*/
|
|
|
@Override
|
|
|
- public IPage<TenantUnbindRecordWrapper.TenantUnbindRecord> selectPage(IPage<TenantUnbindRecordWrapper.TenantUnbindRecord> page, TenantUnbindRecordWrapper.TenantUnbindRecordQuery query) {
|
|
|
+ public IPage<TenantUnbindRecordWrapper.TenantUnbindRecord> selectPage(
|
|
|
+ IPage<TenantUnbindRecordWrapper.TenantUnbindRecord> page,
|
|
|
+ TenantUnbindRecordWrapper.TenantUnbindRecordQuery query) {
|
|
|
|
|
|
List<TenantUnbindRecordWrapper.TenantUnbindRecord> records = baseMapper.selectPage(page, query);
|
|
|
- if(records.isEmpty()){
|
|
|
+ if (records.isEmpty()) {
|
|
|
return page.setRecords(records);
|
|
|
}
|
|
|
|
|
|
- Map<String, List<TenantUnbindRecordWrapper.TenantUnbindRecord>> gropuByUserType = records.stream().collect(Collectors.groupingBy(TenantUnbindRecordWrapper.TenantUnbindRecord::getUserType));
|
|
|
+ List<Integer> areaCodeList = records.stream().map(next -> {
|
|
|
+ HashSet<Integer> areaCodes = new HashSet<>();
|
|
|
+ areaCodes.add(next.getProvinceCode());
|
|
|
+ areaCodes.add(next.getCityCode());
|
|
|
+ areaCodes.add(next.getRegionCode());
|
|
|
+ return areaCodes;
|
|
|
+ }).flatMap(Collection::stream).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
+ if (!areaCodeList.isEmpty()) {
|
|
|
+ QueryWrapper<SysArea> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().in(SysArea::getCode, areaCodeList);
|
|
|
+
|
|
|
+ Map<Integer, String> codeNameMap = sysAreaMapper.selectList(queryWrapper)
|
|
|
+ .stream().collect(Collectors.toMap(SysArea::getCode, SysArea::getName));
|
|
|
+
|
|
|
+ records.forEach(next -> {
|
|
|
+ next.setProvinceName(codeNameMap.getOrDefault(next.getProvinceCode(), ""));
|
|
|
+ next.setCityName(codeNameMap.getOrDefault(next.getCityCode(), ""));
|
|
|
+ next.setRegionName(codeNameMap.getOrDefault(next.getRegionCode(), ""));
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- List<Long> teacherIds = new ArrayList<>();
|
|
|
- List<Long> studentIds = new ArrayList<>();
|
|
|
+ List<Long> teacherIdList = records.stream().map(TenantUnbindRecordWrapper.TenantUnbindRecord::getUserId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- for (Map.Entry<String, List<TenantUnbindRecordWrapper.TenantUnbindRecord>> entry : gropuByUserType.entrySet()) {
|
|
|
- if("TEACHER".equals(entry.getKey())){
|
|
|
- teacherIds.addAll(entry.getValue().stream().map(TenantUnbindRecordWrapper.TenantUnbindRecord::getUserId).collect(Collectors.toList()));
|
|
|
- }else{
|
|
|
- studentIds.addAll(entry.getValue().stream().map(TenantUnbindRecordWrapper.TenantUnbindRecord::getUserId).collect(Collectors.toList()));
|
|
|
+ QueryWrapper<Teacher> objectQueryWrapper = new QueryWrapper<>();
|
|
|
+ objectQueryWrapper.lambda().in(Teacher::getUserId, teacherIdList);
|
|
|
+ List<Teacher> teachers = teacherDao.selectList(objectQueryWrapper);
|
|
|
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
- List<Teacher> teachers = new ArrayList<>();
|
|
|
- List<Teacher> students = new ArrayList<>();
|
|
|
- List<Teacher> users = new ArrayList<>();
|
|
|
- if(!teacherIds.isEmpty()){
|
|
|
- QueryWrapper<Teacher>
|
|
|
- objectQueryWrapper = new QueryWrapper<>();
|
|
|
- objectQueryWrapper.lambda()
|
|
|
- .in(Teacher::getUserId,teacherIds);
|
|
|
- teachers = teacherDao.selectList(objectQueryWrapper);
|
|
|
- }else {
|
|
|
- QueryWrapper<Student>
|
|
|
- objectQueryWrapper = new QueryWrapper<>();
|
|
|
- objectQueryWrapper.lambda()
|
|
|
- .in(Student::getUserId,studentIds);
|
|
|
- List<Student> studentList = studentDao.selectList(objectQueryWrapper);
|
|
|
- students =studentList.stream().map(next->{
|
|
|
- Teacher teacher = new Teacher();
|
|
|
- teacher.setUserId(next.getUserId());
|
|
|
- teacher.setSubject(next.getSubjectId());
|
|
|
- return teacher;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- }
|
|
|
- users.addAll(students);
|
|
|
- users.addAll(teachers);
|
|
|
-
|
|
|
- List<Long> subjectIdList = users.stream().map(next -> {
|
|
|
- List<Long > list = new ArrayList<>();
|
|
|
- String subjectId = next.getSubjectId();
|
|
|
- if (StringUtils.isEmpty(subjectId)) {
|
|
|
- return list;
|
|
|
- }
|
|
|
- return Arrays.stream(next.getSubjectId().split(",")).map(Long::valueOf).collect(Collectors.toList());
|
|
|
- }).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
+ List<Long> subjectIdList = teachers.stream().filter(next -> StringUtils.isNotEmpty(next.getSubjectId()))
|
|
|
+ .map(next -> Arrays.stream(next.getSubjectId().split(",")).map(Long::valueOf).collect(Collectors.toList()))
|
|
|
+ .flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
|
|
|
- Map<Long,String> userIdSubjectNameMap = new HashMap<>();
|
|
|
- if(!subjectIdList.isEmpty()){
|
|
|
+ Map<Long, String> userIdSubjectNameMap = new HashMap<>();
|
|
|
+ Map<Long, String> userIdSubjectIdMap = new HashMap<>();
|
|
|
+ if (!subjectIdList.isEmpty()) {
|
|
|
List<Subject> subjectList = subjectDao.findBySubjectIds(subjectIdList);
|
|
|
- Map<Long, String> idNameMap = subjectList.stream().collect(Collectors.toMap(Subject::getId, Subject::getName));
|
|
|
+ Map<Long, String> idNameMap = subjectList.stream().collect(Collectors.toMap(Subject::getId,
|
|
|
+ Subject::getName));
|
|
|
|
|
|
- for (Teacher user : users) {
|
|
|
+ for (Teacher user : teachers) {
|
|
|
String subjectId = user.getSubjectId();
|
|
|
- if(StringUtils.isEmpty(subjectId)){
|
|
|
+ if (StringUtils.isEmpty(subjectId)) {
|
|
|
continue;
|
|
|
}
|
|
|
+ userIdSubjectIdMap.put(user.getUserId(), subjectId);
|
|
|
List<String> names = Arrays.stream(subjectId.split(",")).map(next ->
|
|
|
idNameMap.getOrDefault(Long.valueOf(next), "")).collect(Collectors.toList());
|
|
|
- userIdSubjectNameMap.put(user.getUserId(),String.join(",",names));
|
|
|
+ userIdSubjectNameMap.put(user.getUserId(), String.join(",", names));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- for (TenantUnbindRecordWrapper.TenantUnbindRecord record : records) {
|
|
|
- record.setSubjectName(userIdSubjectNameMap.getOrDefault(record.getUserId(),""));
|
|
|
-
|
|
|
+ for (TenantUnbindRecordWrapper.TenantUnbindRecord next : records) {
|
|
|
+ next.setSubjectId(userIdSubjectIdMap.getOrDefault(next.getUserId(), ""));
|
|
|
+ next.setSubjectName(userIdSubjectNameMap.getOrDefault(next.getUserId(), ""));
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
return page.setRecords(records);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 添加
|
|
|
+ *
|
|
|
* @param tenantUnbindRecord TenantUnbindRecordWrapper.TenantUnbindRecord
|
|
|
* @return Boolean
|
|
|
*/
|
|
|
@Override
|
|
|
- public Boolean add(TenantUnbindRecordWrapper.TenantUnbindRecord tenantUnbindRecord) {
|
|
|
-
|
|
|
+ public Boolean add(TenantUnbindRecordWrapper.TenantUnbindRecord tenantUnbindRecord) {
|
|
|
+
|
|
|
return this.save(JSON.parseObject(tenantUnbindRecord.jsonString(), TenantUnbindRecord.class));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新
|
|
|
+ *
|
|
|
* @param tenantUnbindRecord TenantUnbindRecordWrapper.TenantUnbindRecord
|
|
|
* @return Boolean
|
|
|
*/
|
|
|
@Override
|
|
|
- public Boolean update(TenantUnbindRecordWrapper.TenantUnbindRecord tenantUnbindRecord){
|
|
|
+ public Boolean update(TenantUnbindRecordWrapper.TenantUnbindRecord tenantUnbindRecord) {
|
|
|
|
|
|
- return this.updateById(JSON.parseObject(tenantUnbindRecord.jsonString(), TenantUnbindRecord.class));
|
|
|
+ return this.updateById(JSON.parseObject(tenantUnbindRecord.jsonString(), TenantUnbindRecord.class));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 机构用户解绑审核
|
|
|
+ *
|
|
|
+ * @param audio 审核信息
|
|
|
+ * @param verifyUserId 审核人
|
|
|
+ * @param intervene 是否平台介入审核 true:后台审核,false:机构管理员
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public Boolean entry(TenantUnbindRecordWrapper.Audio audio) {
|
|
|
+ public void tenantUserUnbindAudit(TenantUnbindRecordWrapper.Audio audio, Long verifyUserId, Boolean intervene) {
|
|
|
|
|
|
- TenantUnbindRecord record = getById(audio.getId());
|
|
|
- if (record == null) {
|
|
|
- throw new BizException("审核数据不存在");
|
|
|
- } else if (!"DOING".equals(record.getStatus())) {
|
|
|
- throw new BizException("审核数据已被处理");
|
|
|
+ TenantUnbindRecord unbindRecord = tenantUnbindRecordService.getById(audio.getId());
|
|
|
+ if (unbindRecord == null || !ETenantUnBindAuditStatus.DOING.equals(unbindRecord.getStatus())) {
|
|
|
+ throw new BizException("审核记录不存在");
|
|
|
}
|
|
|
-
|
|
|
- boolean update = tenantUnbindRecordService.lambdaUpdate()
|
|
|
- .set(TenantUnbindRecord::getStatus, audio.getStatus() ? "PASS" : "UNPASS")
|
|
|
+ // 平台介入审核,需要达到审批超时时间
|
|
|
+ if (Boolean.TRUE.equals(intervene)) {
|
|
|
+ String configValue = sysConfigService.findConfigValue(SysConfigConstant.TENANT_USER_UNBIND_EXPIRE_TIME);
|
|
|
+ if (StringUtils.isNotEmpty(configValue) &&
|
|
|
+ (System.currentTimeMillis() < (unbindRecord.getCreateTime().getTime() + Long.parseLong(configValue) * 60 * 1000))) {
|
|
|
+ throw new BizException("请联系机构管理人员审核");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.lambdaUpdate()
|
|
|
+ .set(TenantUnbindRecord::getStatus, Boolean.TRUE.equals(audio.getStatus()) ?
|
|
|
+ ETenantUnBindAuditStatus.PASS : ETenantUnBindAuditStatus.UNPASS)
|
|
|
.set(TenantUnbindRecord::getReason, audio.getReason())
|
|
|
- .set(TenantUnbindRecord::getVerifyUserId, sysUserFeignService.queryUserInfo().getId())
|
|
|
+ .set(TenantUnbindRecord::getInterveneTime, Boolean.TRUE.equals(intervene) ? new Date() : null)
|
|
|
+ .set(TenantUnbindRecord::getVerifyUserId, verifyUserId)
|
|
|
.eq(TenantUnbindRecord::getId, audio.getId())
|
|
|
- .eq(TenantUnbindRecord::getStatus, "DOING").update();
|
|
|
- if (!update) {
|
|
|
- throw new BizException("审核失败,请刷新后重试");
|
|
|
- }
|
|
|
-
|
|
|
- if (audio.getStatus()) {
|
|
|
- TenantUnbindRecord unbindRecord = tenantUnbindRecordService.getById(audio.getId());
|
|
|
- String userType = unbindRecord.getUserType();
|
|
|
- if ("STUDENT".equals(userType)) {
|
|
|
- studentService.lambdaUpdate()
|
|
|
- .set(Student::getTenantId, -1L)
|
|
|
- .eq(Student::getUserId, unbindRecord.getUserId()).update();
|
|
|
- } else if ("TEACHER".equals(userType)) {
|
|
|
- teacherService.lambdaUpdate()
|
|
|
- .set(Teacher::getTenantId, -1L)
|
|
|
- .eq(Teacher::getUserId, unbindRecord.getUserId()).update();
|
|
|
- }
|
|
|
+ .eq(TenantUnbindRecord::getStatus, ETenantUnBindAuditStatus.DOING)
|
|
|
+ .update();
|
|
|
+ if (Boolean.TRUE.equals(audio.getStatus())) {
|
|
|
+ teacherDao.update(null, Wrappers.<Teacher>lambdaUpdate()
|
|
|
+ .eq(Teacher::getUserId, audio.getId())
|
|
|
+ .set(Teacher::getTenantId, -1L));
|
|
|
}
|
|
|
-
|
|
|
// 老师端发送消息
|
|
|
- CompletableFuture.runAsync(() -> {
|
|
|
-
|
|
|
- sendTeacherUnBindMessage(audio, record);
|
|
|
- });
|
|
|
- return true;
|
|
|
+ CompletableFuture.runAsync(() -> sendTeacherUnBindMessage(audio, unbindRecord));
|
|
|
}
|
|
|
|
|
|
private void sendTeacherUnBindMessage(TenantUnbindRecordWrapper.Audio audio, TenantUnbindRecord record) {
|
|
@@ -242,15 +248,18 @@ public class TenantUnbindRecordServiceImpl extends ServiceImpl<TenantUnbindRecor
|
|
|
receivers.put(record.getUserId(), sysUser.getPhone());
|
|
|
if (Boolean.TRUE.equals(audio.getStatus())) {
|
|
|
try {
|
|
|
- sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.TEACHER_UNBIND_PASS,
|
|
|
- receivers, null, 0, null, ClientEnum.TEACHER.getCode(),tenantInfo.getName());
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG,
|
|
|
+ MessageTypeEnum.TEACHER_UNBIND_PASS,
|
|
|
+ receivers, null, 0, null, ClientEnum.TEACHER.getCode(), tenantInfo.getName());
|
|
|
} catch (Exception e) {
|
|
|
log.error("机构入驻审核极光消息推送异常");
|
|
|
}
|
|
|
try {
|
|
|
String serviceConfig = sysConfigService.findConfigValue(SysConfigConstant.CUSTOMER_SERVICE_PHONE);
|
|
|
- sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.TEACHER_UNBIND_UNPASS,
|
|
|
- receivers, null, 0, null, ClientEnum.TEACHER.getCode(),tenantInfo.getName(), audio.getReason(),serviceConfig);
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG,
|
|
|
+ MessageTypeEnum.TEACHER_UNBIND_UNPASS,
|
|
|
+ receivers, null, 0, null, ClientEnum.TEACHER.getCode(), tenantInfo.getName(),
|
|
|
+ audio.getReason(), serviceConfig);
|
|
|
} catch (Exception e) {
|
|
|
log.error("机构入驻审核极光消息推送异常");
|
|
|
}
|