|
@@ -1,14 +1,25 @@
|
|
|
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.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.TenantStaff;
|
|
|
+import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
|
|
|
+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.common.constant.SysConfigConstant;
|
|
|
import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
+import com.yonge.cooleshow.common.enums.SysUserType;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
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;
|
|
@@ -18,6 +29,7 @@ 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.stream.Collectors;
|
|
|
|
|
@@ -34,30 +46,41 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
@Autowired
|
|
|
TenantInfoMapper tenantInfoMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TenantStaffMapper tenantStaffMapper;
|
|
|
|
|
|
- /**
|
|
|
+
|
|
|
+ /**
|
|
|
* 查询详情
|
|
|
+ *
|
|
|
* @param id 详情ID
|
|
|
* @return TenantInfo
|
|
|
*/
|
|
|
- @Override
|
|
|
+ @Override
|
|
|
public TenantInfo detail(Long id) {
|
|
|
if (id == null || id == -1) {
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return baseMapper.selectById(id);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 分页查询
|
|
|
- * @param page IPage<TenantInfo>
|
|
|
+ *
|
|
|
+ * @param page IPage<TenantInfo>
|
|
|
* @param query TenantInfoWrapper.TenantInfoQuery
|
|
|
* @return IPage<TenantInfo>
|
|
|
*/
|
|
|
@Override
|
|
|
- public IPage<TenantInfoWrapper.TenantInfo> selectPage(IPage<TenantInfoWrapper.TenantInfo> page, TenantInfoWrapper.TenantInfoQuery query) {
|
|
|
+ public IPage<TenantInfoWrapper.TenantInfo> selectPage(IPage<TenantInfoWrapper.TenantInfo> page,
|
|
|
+ TenantInfoWrapper.TenantInfoQuery query) {
|
|
|
|
|
|
//分页查询
|
|
|
List<TenantInfoWrapper.TenantInfo> tenantInfos = baseMapper.selectPage(page, query);
|
|
@@ -66,15 +89,15 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
for (int i = 0; i < tenantInfos.size(); i++) {
|
|
|
TenantInfoWrapper.TenantInfo info = tenantInfos.get(i);
|
|
|
Integer id = info.getId();
|
|
|
- listId.add(i,id);
|
|
|
+ listId.add(i, id);
|
|
|
}
|
|
|
//查询对应机构的老师数量
|
|
|
List<Integer> listTeacher = new ArrayList<>();
|
|
|
//查询对应机构的学生数量
|
|
|
List<Integer> listStudent = new ArrayList<>();
|
|
|
- if (!CollectionUtils.isEmpty(listId)){
|
|
|
- listTeacher = tenantInfoMapper.queryTeacherCounts(listId);
|
|
|
- listStudent = tenantInfoMapper.queryStudentCounts(listId);
|
|
|
+ if (!CollectionUtils.isEmpty(listId)) {
|
|
|
+ listTeacher = tenantInfoMapper.queryTeacherCounts(listId);
|
|
|
+ listStudent = tenantInfoMapper.queryStudentCounts(listId);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -116,13 +139,57 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
|
|
|
/**
|
|
|
* 添加
|
|
|
+ *
|
|
|
* @param tenantInfo TenantInfoWrapper.TenantInfo
|
|
|
* @return Boolean
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean add(TenantInfo tenantInfo) {
|
|
|
- Boolean bool = tenantInfoMapper.insertInfo(tenantInfo);
|
|
|
- return bool;
|
|
|
+ getOrCreateAccount(tenantInfo);
|
|
|
+ tenantInfo.setEnableFlag(true);
|
|
|
+ tenantInfoMapper.insert(tenantInfo);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private SysUser getOrCreateAccount(TenantInfo tenantInfo) {
|
|
|
+ QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
|
|
|
+ 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());
|
|
|
+ if (tenantStaff != null) {
|
|
|
+ throw new BizException("手机号已经注册机构账号");
|
|
|
+ }
|
|
|
+ String userType = sysUser.getUserType();
|
|
|
+ String studentUserType = SysUserType.ORGANIZATION.getCode();
|
|
|
+ if (StringUtils.isEmpty(userType)) {
|
|
|
+ sysUser.setUserType(studentUserType);
|
|
|
+ } else if (!userType.contains(studentUserType)) {
|
|
|
+ sysUser.setUserType(userType + "," + studentUserType);
|
|
|
+ }
|
|
|
+ sysUserMapper.updateById(sysUser);
|
|
|
+ } else {
|
|
|
+ sysUser = new SysUser();
|
|
|
+ sysUser.setPhone(tenantInfo.getPhone());
|
|
|
+ sysUser.setAvatar(sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD));
|
|
|
+ sysUser.setUserType(SysUserType.ORGANIZATION.getCode());
|
|
|
+
|
|
|
+ String newPassword = MessageFormat.format("klxjg{0}", tenantInfo.getPhone().substring(7));
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -165,6 +232,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
|
|
|
/**
|
|
|
* 冻结
|
|
|
+ *
|
|
|
* @param query TenantInfoWrapper.TenantInfo
|
|
|
* @return Boolean
|
|
|
*/
|
|
@@ -181,27 +249,27 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
|
|
|
throw new BizException("机构信息不存在");
|
|
|
}
|
|
|
//获取是否冻结
|
|
|
- if (query.getIfFreeze() == 1){
|
|
|
- if (!info.getEnableFlag()){
|
|
|
- return false;
|
|
|
- }
|
|
|
- //修改机构账号冻结状态
|
|
|
- flag = tenantInfoMapper.updateFlag(id);
|
|
|
- //是否更改结算方式
|
|
|
- if (query.getIfMethod() == 1){
|
|
|
- tenantInfoMapper.updateMethod(id);
|
|
|
- }else {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if (query.getIfFreeze() == 1) {
|
|
|
+ if (!info.getEnableFlag()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //修改机构账号冻结状态
|
|
|
+ flag = tenantInfoMapper.updateFlag(id);
|
|
|
+ //是否更改结算方式
|
|
|
+ if (query.getIfMethod() == 1) {
|
|
|
+ tenantInfoMapper.updateMethod(id);
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新
|
|
|
+ *
|
|
|
* @param info TenantInfoWrapper.TenantInfo
|
|
|
* @return Boolean
|
|
|
*/
|