|
@@ -1,36 +1,42 @@
|
|
|
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.biz.dal.entity.SysArea;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.SysUser;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.TenantInfo;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.TenantStaff;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
|
|
|
+import com.yonge.cooleshow.biz.dal.mapper.TenantInfoMapper;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.TenantStaffMapper;
|
|
|
import com.yonge.cooleshow.biz.dal.service.SysAreaService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.SysConfigService;
|
|
|
-import com.yonge.cooleshow.biz.dal.wrapper.StudentWrapper;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.TenantInfoService;
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper;
|
|
|
import com.yonge.cooleshow.common.constant.SysConfigConstant;
|
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
import com.yonge.cooleshow.common.enums.SysUserType;
|
|
|
+import com.yonge.cooleshow.common.enums.UserLockFlag;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.TenantInfo;
|
|
|
-import com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper;
|
|
|
-import com.yonge.cooleshow.biz.dal.mapper.TenantInfoMapper;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.TenantInfoService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.text.MessageFormat;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -88,8 +94,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
ArrayList<Integer> listId = new ArrayList<>();
|
|
|
for (int i = 0; i < tenantInfos.size(); i++) {
|
|
|
TenantInfoWrapper.TenantInfo info = tenantInfos.get(i);
|
|
|
- Integer id = info.getId();
|
|
|
- listId.add(i, id);
|
|
|
+ long id = info.getId();
|
|
|
+ listId.add(i, (int) id);
|
|
|
}
|
|
|
//查询对应机构的老师数量
|
|
|
List<Integer> listTeacher = new ArrayList<>();
|
|
@@ -113,30 +119,11 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
|
|
|
|
|
|
//获取省市区信息
|
|
|
- List<Integer> areaCodeList = tenantInfos.stream().map(next -> {
|
|
|
- Set<Integer> codes = new HashSet<>();
|
|
|
- codes.add(next.getCityCode());
|
|
|
- codes.add(next.getProvinceCode());
|
|
|
- codes.add(next.getRegionCode());
|
|
|
- return codes;
|
|
|
- }).flatMap(Collection::stream).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
-
|
|
|
- Map<Integer, String> codeNameMap = new HashMap<>();
|
|
|
-
|
|
|
- if (!CollectionUtils.isEmpty(areaCodeList)) {
|
|
|
- List<SysArea> sysAreaList = sysAreaService.queryByCodes(areaCodeList);
|
|
|
- codeNameMap = sysAreaList.stream().collect(Collectors.toMap(SysArea::getCode,
|
|
|
- SysArea::getName));
|
|
|
- }
|
|
|
-
|
|
|
- for (TenantInfoWrapper.TenantInfo next : tenantInfos) {
|
|
|
- next.setProvinceName(codeNameMap.getOrDefault(next.getProvinceCode(), ""));
|
|
|
- next.setCityName(codeNameMap.getOrDefault(next.getCityCode(), ""));
|
|
|
- next.setRegionName(codeNameMap.getOrDefault(next.getRegionCode(), ""));
|
|
|
- }
|
|
|
- return page.setRecords(tenantInfos);
|
|
|
+ List<TenantInfoWrapper.TenantInfo> tenantList = queryArea(tenantInfos);
|
|
|
+ return page.setRecords(tenantList);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 添加
|
|
|
*
|
|
@@ -145,7 +132,16 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean add(TenantInfo tenantInfo) {
|
|
|
- getOrCreateAccount(tenantInfo);
|
|
|
+ SysUser sysUser = getOrCreateAccount(tenantInfo);
|
|
|
+
|
|
|
+ TenantStaff tenantStaff = new TenantStaff();
|
|
|
+ tenantStaff.setTenantId(tenantStaff.getTenantId());
|
|
|
+ tenantStaff.setUserId(sysUser.getId());
|
|
|
+ tenantStaff.setAvatar(sysUser.getAvatar());
|
|
|
+ tenantStaff.setNickname(tenantInfo.getUsername());
|
|
|
+ tenantStaff.setStatus(UserLockFlag.NORMAL);
|
|
|
+ tenantStaffMapper.insert(tenantStaff);
|
|
|
+
|
|
|
tenantInfo.setEnableFlag(true);
|
|
|
tenantInfoMapper.insert(tenantInfo);
|
|
|
return true;
|
|
@@ -156,19 +152,26 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
sysUserQueryWrapper.lambda().eq(SysUser::getPhone, tenantInfo.getPhone());
|
|
|
List<SysUser> sysUsers = sysUserMapper.selectList(sysUserQueryWrapper);
|
|
|
SysUser sysUser;
|
|
|
+ //若存在信息
|
|
|
if (!sysUsers.isEmpty()) {
|
|
|
sysUser = sysUsers.get(0);
|
|
|
- TenantStaff tenantStaff = tenantStaffMapper.getByPhone(tenantInfo.getPhone());
|
|
|
+ TenantStaff tenantStaff = tenantStaffMapper.selectById(sysUser.getId());
|
|
|
if (tenantStaff != null) {
|
|
|
throw new BizException("手机号已经注册机构账号");
|
|
|
}
|
|
|
+ //获取当前账户的用户类型
|
|
|
String userType = sysUser.getUserType();
|
|
|
- String studentUserType = SysUserType.ORGANIZATION.getCode();
|
|
|
+ //设置默认机构类型
|
|
|
+ String tenantUserType = SysUserType.ORGANIZATION.getCode();
|
|
|
if (StringUtils.isEmpty(userType)) {
|
|
|
- sysUser.setUserType(studentUserType);
|
|
|
- } else if (!userType.contains(studentUserType)) {
|
|
|
- sysUser.setUserType(userType + "," + studentUserType);
|
|
|
+ sysUser.setUserType(tenantUserType);
|
|
|
+ } else if (!userType.contains(tenantUserType)) {
|
|
|
+ sysUser.setUserType(userType + "," + tenantUserType);
|
|
|
}
|
|
|
+
|
|
|
+ //更新当前账号的用户名
|
|
|
+ sysUser.setUsername(tenantInfo.getUsername());
|
|
|
+
|
|
|
sysUserMapper.updateById(sysUser);
|
|
|
} else {
|
|
|
sysUser = new SysUser();
|
|
@@ -180,14 +183,6 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
String password = new BCryptPasswordEncoder().encode(newPassword);
|
|
|
sysUser.setPassword(password);
|
|
|
sysUserMapper.insert(sysUser);
|
|
|
-
|
|
|
- TenantStaff tenantStaff = new TenantStaff();
|
|
|
- tenantStaff.setTenantId(tenantStaff.getTenantId());
|
|
|
- tenantStaff.setUserId(sysUser.getId());
|
|
|
- tenantStaff.setAvatar(sysUser.getAvatar());
|
|
|
- tenantStaff.setNickname(tenantInfo.getUsername());
|
|
|
- tenantStaff.setStatus("ACTIVE");
|
|
|
- tenantStaffMapper.insert(tenantStaff);
|
|
|
}
|
|
|
return sysUser;
|
|
|
}
|
|
@@ -240,9 +235,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
@Override
|
|
|
public Boolean state(TenantInfoWrapper.TenantInfoQuery query) {
|
|
|
Boolean flag;
|
|
|
- Integer id = query.getId();
|
|
|
- long longId = id.longValue();
|
|
|
- TenantInfo info = detail(longId);
|
|
|
+ long id = query.getId();
|
|
|
+ TenantInfo info = detail(id);
|
|
|
|
|
|
//TenantInfo info = this.getById(id);
|
|
|
if (Objects.isNull(info)) {
|
|
@@ -267,6 +261,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 更新
|
|
|
*
|
|
@@ -275,9 +270,145 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean updateTenantInfo(TenantInfo info) {
|
|
|
- Boolean bool = tenantInfoMapper.updateInfo(info);
|
|
|
- return bool;
|
|
|
+ SysUser sysUser = getOrCreateAccount(info);
|
|
|
+
|
|
|
+ TenantInfo oldTenantInfo = this.getById(info.getId());
|
|
|
+ tenantStaffMapper.update(null, Wrappers.<TenantStaff>lambdaUpdate()
|
|
|
+ .set(TenantStaff::getUserId, sysUser.getId())
|
|
|
+ .set(TenantStaff::getNickname, info.getUsername())
|
|
|
+ .eq(TenantStaff::getUserId, oldTenantInfo.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
+ tenantInfoMapper.update(null, Wrappers.<TenantInfo>lambdaUpdate()
|
|
|
+ .set(TenantInfo::getName, info.getName())
|
|
|
+ .set(TenantInfo::getLogo, info.getLogo())
|
|
|
+ .set(TenantInfo::getBriefIntroduction, info.getBriefIntroduction())
|
|
|
+ .set(TenantInfo::getProvinceCode, info.getProvinceCode())
|
|
|
+ .set(TenantInfo::getCityCode, info.getCityCode())
|
|
|
+ .set(TenantInfo::getRegionCode, info.getRegionCode())
|
|
|
+ .eq(TenantInfo::getId, info.getId())
|
|
|
+ );
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 机构申请分页查询
|
|
|
+ *
|
|
|
+ * @param query
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<TenantInfoWrapper.TenantInfo> applyPage(IPage<TenantInfoWrapper.TenantInfo> page,
|
|
|
+ TenantInfoWrapper.TenantInfoQuery query) {
|
|
|
+ //分页查询
|
|
|
+ List<TenantInfoWrapper.TenantInfo> tenantInfos = baseMapper.selectApplyPage(page, query);
|
|
|
+ List<TenantInfoWrapper.TenantInfo> infos = queryArea(tenantInfos);
|
|
|
+ return page.setRecords(infos);
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 机构入驻审核历史记录查询
|
|
|
+ *
|
|
|
+ * @param query
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public IPage<TenantInfoWrapper.TenantInfo> historyPage(IPage<TenantInfoWrapper.TenantInfo> page,
|
|
|
+ TenantInfoWrapper.TenantInfoQuery query) {
|
|
|
+ long id = query.getId();
|
|
|
+ //分页查询
|
|
|
+ List<TenantInfoWrapper.TenantInfo> tenantInfos = baseMapper.selectHistoryPage(page, id);
|
|
|
+ //查询对应省市区
|
|
|
+ List<TenantInfoWrapper.TenantInfo> infos = queryArea(tenantInfos);
|
|
|
+
|
|
|
+ return page.setRecords(infos);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 机构入驻审核本次提交查询
|
|
|
+ *
|
|
|
+ * @param query
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TenantInfoWrapper.TenantInfo queryNow(TenantInfoWrapper.TenantInfoQuery query) {
|
|
|
+ //查询本次提交记录
|
|
|
+ TenantInfoWrapper.TenantInfo info = tenantInfoMapper.queryNow(query);
|
|
|
+ Set<Integer> codes = new HashSet<>();
|
|
|
+ codes.add(info.getCityCode());
|
|
|
+ codes.add(info.getProvinceCode());
|
|
|
+ codes.add(info.getRegionCode());
|
|
|
+
|
|
|
+ //将地区码转化为对应的地名
|
|
|
+ List<Integer> areaCodeList = new ArrayList<>();
|
|
|
+ areaCodeList.addAll(codes);
|
|
|
+
|
|
|
+ Map<Integer, String> codeNameMap = new HashMap<>();
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(areaCodeList)) {
|
|
|
+ List<SysArea> sysAreaList = sysAreaService.queryByCodes(areaCodeList);
|
|
|
+ codeNameMap = sysAreaList.stream().collect(Collectors.toMap(SysArea::getCode,
|
|
|
+ SysArea::getName));
|
|
|
+ }
|
|
|
+
|
|
|
+ info.setProvinceName(codeNameMap.get(info.getProvinceCode()));
|
|
|
+ info.setCityName(codeNameMap.get(info.getCityCode()));
|
|
|
+ info.setRegionName(codeNameMap.get(info.getRegionCode()));
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean entry(TenantInfoWrapper.TenantInfoQuery query) {
|
|
|
+ Integer pass = query.getIfPass();
|
|
|
+ //审核通过
|
|
|
+ if (pass == 1) {
|
|
|
+ //查询本次提交记录,并插入审核表
|
|
|
+ TenantInfoWrapper.TenantInfo info = queryNow(query);
|
|
|
+ tenantInfoMapper.insertNow(info);
|
|
|
+ //更改当前记录的审核状态
|
|
|
+
|
|
|
+ //机构账户新增逻辑
|
|
|
+ } else {
|
|
|
+ //查询本次提交记录,并插入审核表
|
|
|
+ //更改当前记录的审核状态
|
|
|
+
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 匹配地区码与省市区
|
|
|
+ *
|
|
|
+ * @param tenantInfos
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<TenantInfoWrapper.TenantInfo> queryArea(List<TenantInfoWrapper.TenantInfo> tenantInfos) {
|
|
|
+ List<Integer> areaCodeList = tenantInfos.stream().map(next -> {
|
|
|
+ Set<Integer> codes = new HashSet<>();
|
|
|
+ codes.add(next.getCityCode());
|
|
|
+ codes.add(next.getProvinceCode());
|
|
|
+ codes.add(next.getRegionCode());
|
|
|
+ return codes;
|
|
|
+ }).flatMap(Collection::stream).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Integer, String> codeNameMap = new HashMap<>();
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(areaCodeList)) {
|
|
|
+ List<SysArea> sysAreaList = sysAreaService.queryByCodes(areaCodeList);
|
|
|
+ codeNameMap = sysAreaList.stream().collect(Collectors.toMap(SysArea::getCode,
|
|
|
+ SysArea::getName));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (TenantInfoWrapper.TenantInfo next : tenantInfos) {
|
|
|
+ next.setProvinceName(codeNameMap.getOrDefault(next.getProvinceCode(), ""));
|
|
|
+ next.setCityName(codeNameMap.getOrDefault(next.getCityCode(), ""));
|
|
|
+ next.setRegionName(codeNameMap.getOrDefault(next.getRegionCode(), ""));
|
|
|
+ }
|
|
|
+
|
|
|
+ return tenantInfos;
|
|
|
+ }
|
|
|
+
|
|
|
}
|