|
@@ -1,20 +1,114 @@
|
|
|
package edu.travel.tenant.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import edu.travel.tenant.entity.EduTenant;
|
|
|
import edu.travel.tenant.entity.EduTenant;
|
|
|
+import edu.travel.tenant.enums.UserStatus;
|
|
|
import edu.travel.tenant.service.ITenantService;
|
|
|
import edu.travel.service.SysServiceImpl;
|
|
|
import edu.travel.tenant.mapper.EduTenantMapper;
|
|
|
+import edu.travel.tenant.vo.EduTenantVo;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ITenantServiceImpl extends SysServiceImpl<EduTenantMapper, EduTenant> implements ITenantService {
|
|
|
@Override
|
|
|
public EduTenant getTenantByID(String tenantID) {
|
|
|
-
|
|
|
return super.getOneLink(new QueryWrapper<EduTenant>().eq("tenant_phone",tenantID));
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void addTenant(EduTenant tenant) {
|
|
|
+ if (tenant == null) {
|
|
|
+ throw new RuntimeException("参数为空");
|
|
|
+ }
|
|
|
+ if (tenant.getTenantPhone() == null){
|
|
|
+ throw new RuntimeException("手机号为空");
|
|
|
+ }
|
|
|
+ EduTenant eduTenant = super.getOneLink(new QueryWrapper<EduTenant>().eq("tenant_phone", tenant.getTenantPhone()));
|
|
|
+ if (eduTenant != null&&eduTenant.getUserStatus()==0) {
|
|
|
+ throw new RuntimeException("该手机号已注册,用户状态为禁用");
|
|
|
+ }
|
|
|
+ if (eduTenant != null&&eduTenant.getUserStatus()==1) {
|
|
|
+ throw new RuntimeException("该手机号已注册,用户状态正常");
|
|
|
+ }
|
|
|
+ if (eduTenant == null){
|
|
|
+ this.save(tenant);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void deleteByIds(Set<Long> ids) {
|
|
|
+ if (ids==null || ids.isEmpty()) {
|
|
|
+ throw new RuntimeException("参数为空");
|
|
|
+ }
|
|
|
+ List<EduTenant> tenants = this.listByIds(ids);
|
|
|
+ if (tenants == null || tenants.isEmpty()) {
|
|
|
+ throw new RuntimeException("用户不存在或已注销");
|
|
|
+ }
|
|
|
+ List<EduTenantVo> eduTenantVos = fillStatus(tenants);
|
|
|
+ ArrayList<Long> longs = new ArrayList<>();
|
|
|
+ eduTenantVos.forEach(eduTenantVo -> {
|
|
|
+ if (Objects.equals(eduTenantVo.getStatus(), UserStatus.USER_STATUS_DELETED.getCode())) {
|
|
|
+ throw new RuntimeException("包含已删除用户");
|
|
|
+ } else if (Objects.equals(eduTenantVo.getStatus(), UserStatus.USER_STATUS_DISABLED.getCode())) {
|
|
|
+ throw new RuntimeException("包含已禁用用户");
|
|
|
+ } else {
|
|
|
+ longs.add(eduTenantVo.getId());
|
|
|
+ }
|
|
|
+ this.removeByIds(longs);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void updateTenant(EduTenant tenant) {
|
|
|
+ if (tenant == null) throw new RuntimeException("参数为空");
|
|
|
+ if (tenant.getId() == null) throw new RuntimeException("参数为空");
|
|
|
+ EduTenant eduTenant = super.getOneLink(new QueryWrapper<EduTenant>().eq("id", tenant.getId()));
|
|
|
+ if (eduTenant == null) throw new RuntimeException("用户不存在");
|
|
|
+ if (eduTenant.getDeleteFlag() == 1) throw new RuntimeException("用户已注销");
|
|
|
+ if (eduTenant.getUserStatus() == 0) throw new RuntimeException("用户已禁用");
|
|
|
+ if (tenant.getTenantPhone() != null){
|
|
|
+ EduTenant eduTenant1 = super.getOneLink(new QueryWrapper<EduTenant>().eq("tenant_phone", tenant.getTenantPhone()));
|
|
|
+ if (eduTenant1 != null) throw new RuntimeException("该手机号已注册");
|
|
|
+ }
|
|
|
+ this.updateById(tenant);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public EduTenant getTenantById(Long id) {
|
|
|
+ return super.getOneLink(new LambdaQueryWrapper<EduTenant>().eq(EduTenant::getId,id)
|
|
|
+ .eq(EduTenant::getDeleteFlag,0)
|
|
|
+ .eq(EduTenant::getUserStatus,1));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 填充用户状态
|
|
|
+ */
|
|
|
+ private List<EduTenantVo> fillStatus(List<EduTenant> list) {
|
|
|
+ List<EduTenantVo> eduTenantVos = BeanUtil.copyToList(list, EduTenantVo.class);
|
|
|
+ eduTenantVos.forEach(eduTenantVo -> {
|
|
|
+ if (eduTenantVo.getDeleteFlag() == 1) {
|
|
|
+ eduTenantVo.setStatus(UserStatus.USER_STATUS_DELETED.getCode());
|
|
|
+ } else if (eduTenantVo.getUserStatus() == 0) {
|
|
|
+ eduTenantVo.setStatus(UserStatus.USER_STATUS_DISABLED.getCode());
|
|
|
+ } else {
|
|
|
+ eduTenantVo.setStatus(UserStatus.USER_STATUS_NORMAL.getCode());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return eduTenantVos;
|
|
|
+ }
|
|
|
+
|
|
|
}
|