Sfoglia il codice sorgente

add 疼痛小管家

18339543638 3 anni fa
parent
commit
58a31f0003

+ 1 - 1
nb-service-api/app-doctor-api/src/main/java/com/nb/app/doctor/api/entity/AppDoctorUserEntity.java

@@ -76,5 +76,5 @@ public class AppDoctorUserEntity extends TenantGenericEntity<String,String> {
     @TableField(fill = FieldFill.INSERT)
     @ApiModelProperty(hidden = true)
     @TableLogic(value = "0",delval = "1")
-    private Boolean isDel;
+    private Integer isDelete;
 }

+ 43 - 4
nb-service/app-doctor/src/main/java/com/nb/app/doctor/service/LocalAppDoctorUserService.java

@@ -1,17 +1,25 @@
 package com.nb.app.doctor.service;
 
-import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.enums.SqlMethod;
 import com.nb.app.doctor.api.entity.AppDoctorUserEntity;
 import com.nb.app.doctor.api.feign.IAppDoctorUserClient;
 import com.nb.app.doctor.mapper.AppDoctorUserMapper;
 import com.nb.auth.utils.SecurityUtil;
 import com.nb.common.crud.BaseService;
-import com.nb.core.enums.YesNoEnum;
 import com.nb.core.exception.CustomException;
+import org.hibernate.validator.constraints.Length;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * @author lifang
@@ -24,7 +32,19 @@ import java.util.List;
 public class LocalAppDoctorUserService extends BaseService<AppDoctorUserMapper, AppDoctorUserEntity,String> implements IAppDoctorUserClient {
     @Override
     public void validateBeforeSave(AppDoctorUserEntity entity) {
-
+        if(StrUtil.isEmpty(entity.getUsername())){
+            throw new CustomException("新增医生账号用户名不能为空");
+        }
+        if(StrUtil.isEmpty(entity.getTenantId())){
+            throw new CustomException("新增医生账号租户id不能为空");
+        }
+         String username = entity.getUsername();
+        AppDoctorUserEntity doctor = this.getOne(new QueryWrapper<AppDoctorUserEntity>()
+                .lambda().eq(AppDoctorUserEntity::getUsername, username)
+                .last("limit 1"));
+        if(doctor!=null){
+            throw new CustomException(String.format("用户名{%s}已存在,不可重复添加",username));
+        }
     }
 
     @Override
@@ -38,8 +58,27 @@ public class LocalAppDoctorUserService extends BaseService<AppDoctorUserMapper,
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public boolean saveBatch(List<AppDoctorUserEntity> sources) {
-        return false;
+        if(CollectionUtil.isEmpty(sources)){
+            return true;
+        }
+        List<String> userNames = sources.stream().map(AppDoctorUserEntity::getUsername).collect(Collectors.toList());
+        Set<String> userNameDistinct = new HashSet<>(userNames);
+        if(CollectionUtil.size(userNames)!=CollectionUtil.size(userNameDistinct)){
+            throw new CustomException("请检查新增的医生账户中是否存在重复用户名");
+        }
+        List<AppDoctorUserEntity> existUsers = this.list(new QueryWrapper<AppDoctorUserEntity>()
+                .lambda()
+                .select(AppDoctorUserEntity::getUsername)
+                .in(AppDoctorUserEntity::getUsername, userNameDistinct));
+        if (CollectionUtil.isNotEmpty(existUsers)) {
+            Set<String> existUsername = existUsers.stream().map(AppDoctorUserEntity::getUsername).collect(Collectors.toSet());
+            Collection<String> intersection = CollectionUtil.intersection(existUsername, userNameDistinct);
+            throw new CustomException(String.format("用户名%s已存在,不可重复添加", JSONUtil.toJsonStr(intersection)));
+        }
+        String sqlStatement = super.getSqlStatement(SqlMethod.INSERT_ONE);
+        return executeBatch(sources, DEFAULT_BATCH_SIZE, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity));
     }
 
     @Override