Browse Source

添加机构时动态添加机构管理员

zsf 1 year ago
parent
commit
5091f47a1b

+ 7 - 2
src/main/java/com/rf/psychological/dao/vo/SaveInstitutionVO.java

@@ -1,9 +1,12 @@
 package com.rf.psychological.dao.vo;
 
+import com.alibaba.fastjson.JSONObject;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
+import java.util.List;
+
 /**
  * @author lpf
  * @description: 添加机构实体类
@@ -18,11 +21,13 @@ public class SaveInstitutionVO {
 
     private String institutionNo;
 
-    private String loginName;
+   // private String loginName;
 
     private String institutionDesc;
 
-    private String superAdminPassword;
+    //private String superAdminPassword;
+
+    List<JSONObject> adminList;
 
     private int flag;
 

+ 0 - 48
src/main/java/com/rf/psychological/institution/model/InstitutionUserEntity.java

@@ -1,48 +0,0 @@
-package com.rf.psychological.institution.model;
-
-import com.rf.psychological.base.model.BaseEntity;
-import lombok.*;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Table;
-
-@Entity
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@EqualsAndHashCode(callSuper=false)
-@Table(name = "t_institution_user")
-@org.hibernate.annotations.Table(appliesTo = "t_institution_user", comment = "机构管理员表")
-public class InstitutionUserEntity extends BaseEntity {
-
-    @Column(name = "phone",columnDefinition = "varchar(11) not null comment '手机号(唯一)'")
-    private String phone;
-
-    @Column(name = "institution_name", columnDefinition = "varchar(50) comment '所属机构名称'")
-    private String institutionName;
-
-    @Column(name = "institution_no", columnDefinition = "varchar(50) comment '所属机构编码'")
-    private String institutionNo;
-
-    @Column(name = "password", columnDefinition = "varchar(50) comment '登陆密码'")
-    private String password;
-
-    @Column(name = "gender", columnDefinition = "varchar(2)   not null comment '性别(0-男;1-女)'")
-    private String gender;
-
-    @Column(name = "pet_name", columnDefinition = "varchar(10) not null comment '昵称'")
-    private String petName;
-
-    @Column(name = "birthday", columnDefinition = "varchar(15) not null comment '出生日期'")
-    private String birthday;
-
-    @Column(name = "profession", columnDefinition = "varchar(50) comment '职业'")
-    private String profession;
-
-    @Column(name = "user_status", columnDefinition = "varchar(2) comment '用户状态,1-待审核 2-审核通过 3-密码被重置状态'")
-    private String userStatus = "1";
-
-    @Column(name = "addition_info", columnDefinition = "varchar(500) comment '附加信息'")
-    private String additionInfo;
-}

+ 0 - 104
src/main/java/com/rf/psychological/institution/repository/InstitutionUserRepository.java

@@ -1,104 +0,0 @@
-package com.rf.psychological.institution.repository;
-
-import com.rf.psychological.base.repository.BaseRepository;
-import com.rf.psychological.institution.model.InstitutionUserEntity;
-import org.springframework.data.jpa.repository.Modifying;
-import org.springframework.data.jpa.repository.Query;
-import org.springframework.data.repository.query.Param;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-
-public interface InstitutionUserRepository extends BaseRepository<InstitutionUserEntity, String> {
-
-    /**
-     * 根据机构编号
-     *
-     * @return
-     */
-    @Query(value = "select id, institution_name, institution_no, password, gender, pet_name, phone, birthday, profession, addition_info, user_status from t_institution_user where institution_no = :institutionNo ", nativeQuery = true)
-    InstitutionUserEntity findInstitutionByNo(@Param("institutionNo") String institutionNo);
-
-    /**
-     * 根据手机号登录
-     *
-     * @param phone
-     * @param password
-     * @return
-     */
-    InstitutionUserEntity findByPhoneAndPassword(String phone, String password);
-
-    /**
-     * 根据手机号修改密码
-     *
-     * @param phone
-     * @param password
-     */
-    @Transactional
-    @Modifying(clearAutomatically = true)
-    @Query(value = "update t_institution_user set password = :password where phone = :phone and institution_no=:institutionNo", nativeQuery = true)
-    void updatePassword(@Param("phone") String phone, @Param("password") String password, @Param("institutionNo") String institutionNo);
-
-    /**
-     * 根据手机号
-     *
-     * @param phone
-     * @return
-     */
-    InstitutionUserEntity findByPhone(String phone);
-
-    InstitutionUserEntity findByInstitutionNoAndPhone(String institutionNo, String phone);
-
-    /**
-     * 分页查询所有机构管理员信息
-     *
-     * @param pageNum
-     * @param pageSize
-     * @return
-     */
-    @Query(value = "select id, institution_name, institution_no, password, gender, pet_name, phone, birthday, profession, addition_info, user_status from t_institution_user limit :pageNum ,:pageSize ", nativeQuery = true)
-    List<InstitutionUserEntity> findAll(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize);
-
-    /**
-     * 可以模糊查询所有机构管理员
-     *
-     * @param pageNum
-     * @param pageSize
-     * @param searchKey
-     * @return
-     */
-    @Query(value = "select id, institution_name, institution_no, password, gender, pet_name, phone, birthday, profession, addition_info, user_status from t_institution_user  where phone like %:searchKey% or institution_name like %:searchKey%   limit :pageNum ,:pageSize", nativeQuery = true)
-    List<InstitutionUserEntity> findAllByName(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("searchKey") String searchKey);
-
-    @Query(value = "select count(1) from t_institution_user  where phone like %:searchKey% or institution_name like %:searchKey%", nativeQuery = true)
-    int allNum(@Param("searchKey") String searchKey);
-
-    @Query(value = "select id, institution_name, institution_no, password, gender, pet_name, phone, birthday, profession, addition_info, user_status from t_institution_user  where institution_no =:institutionNo and" +
-            " if(:searchKey is not null and :searchKey!='',(pet_name like CONCAT('%',:searchKey,'%') or phone like CONCAT('%',:searchKey,'%') ) ,1=1)  limit :pageNum ,:pageSize", nativeQuery = true)
-    List<InstitutionUserEntity> findAllByInNo(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("institutionNo") String institutionNo, @Param("searchKey") String searchKey);
-
-    @Query(value = "select count(1) from t_institution_user  where institution_no =:institutionNo and" +
-            " if(:searchKey is not null and :searchKey!='',(pet_name like CONCAT('%',:searchKey,'%') or phone like CONCAT('%',:searchKey,'%') ) ,1=1)", nativeQuery = true)
-    int numAllByInNo(@Param("institutionNo") String institutionNo, @Param("searchKey") String searchKey);
-
-    /**
-     * 根据手机号删除机构用户
-     *
-     * @param phone
-     */
-    @Transactional
-    @Modifying(clearAutomatically = true)
-    void deleteByPhoneAndInstitutionNo(String phone, String institutionNo);
-
-
-    /**
-     * 审核机构用户
-     *
-     * @param phone
-     * @param userStatus
-     */
-    @Transactional
-    @Modifying(clearAutomatically = true)
-    @Query(value = "update t_institution_user set user_status = :userStatus where phone = :phone and institution_no=:institutionNo", nativeQuery = true)
-    void updateUserStatusByPhone(@Param("phone") String phone, @Param("userStatus") String userStatus, @Param("institutionNo") String institutionNo);
-}

+ 1 - 37
src/main/java/com/rf/psychological/institution/rest/InstitutionController.java

@@ -119,38 +119,6 @@ public class InstitutionController extends BaseController {
         return success(jsonObject);
     }
 
-    @SafetyProcess
-    @PostMapping("/saveUser")
-    @ApiOperation(value = "机构管理员(注:非机构超级管理员)保存")
-    public Result institutionSaveUser(@RequestBody String json) throws Exception {
-        String data = AesEncryptUtils.decrypt(JSONObject.parseObject(json).getString("data"));
-        JSONObject jsonData = JSONObject.parseObject(data);
-        JSONObject jsonInstitutionUserEntity = jsonData.getJSONObject("data");
-        UserEntity institutionUserEntity = jsonInstitutionUserEntity.toJavaObject(UserEntity.class);
-        log.info("institutionUserEntity--->" + institutionUserEntity);
-        if(StringUtils.isEmpty(institutionUserEntity.getPhone()) ||
-                StringUtils.isEmpty(institutionUserEntity.getPassword()) ||
-                StringUtils.isEmpty(institutionUserEntity.getGender()) ||
-                StringUtils.isEmpty(institutionUserEntity.getPetName()) ||
-                StringUtils.isEmpty(institutionUserEntity.getBirthday()) ){
-            return fail("", "请按要求填写所需信息");
-        }
-
-        InstitutionEntity byInstitutionId = this.institutionService.findByInstitutionId(institutionUserEntity.getInstitutionNo());
-        if (byInstitutionId == null) {
-            return fail("", "机构编号不存在");
-        }
-        UserEntity byPhone = this.userService.findPhoneAndInstitutionNo( institutionUserEntity.getPhone(),institutionUserEntity.getInstitutionNo());
-        if (byPhone == null) {
-            institutionUserEntity.setInstitutionName(byInstitutionId.getInstitutionName());
-            this.userService.save(institutionUserEntity);
-            return success();
-        } else {
-            return fail("", "用户名已注册");
-        }
-
-    }
-
     @SafetyProcess
     @Deprecated
 @OperationLogAnnotation
@@ -173,7 +141,6 @@ public class InstitutionController extends BaseController {
         if (institutionUserEntityByNo == null) {
             return fail("", "请先注册");
         } else {
-            //userService.updatePassword(phone, password, institutionNo);
             return success();
         }
     }
@@ -198,8 +165,6 @@ public class InstitutionController extends BaseController {
             userEntity.setPassword(DigestUtils.md5DigestAsHex(Constant.DEFAULT_PASSWORD.getBytes(StandardCharsets.UTF_8)));
             userEntity.setUserStatus(UserStatus.UPDATE.getType());
             userService.save(userEntity);
-            //userService.updatePassword(phone, DigestUtils.md5DigestAsHex(Constant.DEFAULT_PASSWORD.getBytes(StandardCharsets.UTF_8)), institutionNo,UserRole.ADMIN.getType());
-            //userService.updateUserStatus(UserStatus.UPDATE.getType(), userEntity.getId());
             return success();
         }
     }
@@ -370,7 +335,6 @@ public class InstitutionController extends BaseController {
 
     /**
      * 添加机构信息
-     *
      * @param json
      * @return
      * @throws Exception
@@ -378,7 +342,7 @@ public class InstitutionController extends BaseController {
     @SafetyProcess
     @OperationLogAnnotation
     @PostMapping("/save")
-    @ApiOperation(value = "添加机构管理员信息")
+    @ApiOperation(value = "添加机信息")
     @Transactional(rollbackFor = Exception.class)
     public Result institutionSave(@RequestBody String json) throws Exception {
         String data = AesEncryptUtils.decrypt(JSONObject.parseObject(json).getString("data"));

+ 0 - 73
src/main/java/com/rf/psychological/institution/service/InstitutionUserService.java

@@ -1,73 +0,0 @@
-package com.rf.psychological.institution.service;
-
-import com.rf.psychological.institution.model.InstitutionUserEntity;
-
-import java.util.List;
-
-public interface InstitutionUserService {
-
-    /**
-     * 根据手机号查询
-     *
-     * @return
-     */
-    InstitutionUserEntity findInstitutionByNo(String institutionNo);
-
-    /**
-     * 根据机构id
-     *
-     * @return
-     */
-    InstitutionUserEntity getOne(String institutionId);
-
-    InstitutionUserEntity findByPhoneAndPassword(String phone, String password);
-
-    InstitutionUserEntity findByPhone(String phone);
-
-    InstitutionUserEntity findByInstitutionNoAndPhone(String institutionNo, String phone);
-
-    /**
-     * 保存机构用户
-     *
-     * @param institutionUserEntity
-     */
-    void save(InstitutionUserEntity institutionUserEntity);
-
-
-    /**
-     * 根据手机号修改密码
-     *
-     * @return
-     */
-    void updatePassword(String phone, String password, String institutionNo);
-
-    /**
-     * 可以模糊查询所有机构用户
-     *
-     * @return
-     */
-    List<InstitutionUserEntity> findAllByName(int pageNum, int pageSize, String searchKey);
-
-    int allNum(String searchKey);
-
-    List<InstitutionUserEntity> findAllInAdminByInNo(int pageNum, int pageSize, String institutionNo, String searchKey);
-
-    int numAllInAdminByInNo(String institutionNo, String searchKey);
-
-    /**
-     * 根据手机号删除机构用户
-     *
-     * @param phone
-     */
-    void deleteByPhoneAndInstitutionNo(String phone, String institutionNo);
-
-
-    /**
-     * 审核机构用户
-     *
-     * @param phone
-     * @param userStatus
-     */
-    void updateUserStatusByPhone(String phone, String userStatus, String institutionNo);
-
-}

+ 10 - 4
src/main/java/com/rf/psychological/institution/service/impl/InstitutionServiceImpl.java

@@ -11,6 +11,7 @@ import com.rf.psychological.user.dao.model.UserEntity;
 import com.rf.psychological.user.service.UserService;
 import com.rf.psychological.utils.Constant;
 import com.rf.psychological.utils.PageRequestUtil;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.CacheEvict;
@@ -97,11 +98,16 @@ public class InstitutionServiceImpl implements InstitutionService {
         InstitutionEntity institutionEntity =
                 new InstitutionEntity(institutionName, institutionNo, saveInstitutionVO.getInstitutionDesc(), 1,saveInstitutionVO.getFlag(), DateUtil.now(),DateUtil.now());
         this.save(institutionEntity);
-        UserEntity institutionUserEntity =
-                new UserEntity(institutionNo,institutionName, saveInstitutionVO.getLoginName(),
-                        saveInstitutionVO.getLoginName(), DigestUtils.md5DigestAsHex(saveInstitutionVO.getSuperAdminPassword().getBytes()),
+        //添加管理员
+        if(CollectionUtils.isNotEmpty(saveInstitutionVO.getAdminList())){
+            saveInstitutionVO.getAdminList().forEach(item->{
+                        UserEntity institutionUserEntity = new UserEntity(institutionNo,institutionName, item.get("loginName").toString(),
+                        item.get("loginName").toString(), DigestUtils.md5DigestAsHex(item.get("password").toString().getBytes()),
                         LocalDate.now().toString(),Constant.DEFAULT_VALUE_ZERO, UserStatus.PASS.getType(), UserRole.SUPERADMIN.getType());
-        userService.save(institutionUserEntity);
+                        userService.save(institutionUserEntity);
+            });
+        }
+
     }
     /**
      * 根据机构编号查询机构信息

+ 0 - 88
src/main/java/com/rf/psychological/institution/service/impl/InstitutionUserServiceImpl.java

@@ -1,88 +0,0 @@
-package com.rf.psychological.institution.service.impl;
-
-import com.rf.psychological.institution.model.InstitutionUserEntity;
-import com.rf.psychological.institution.repository.InstitutionUserRepository;
-import com.rf.psychological.institution.service.InstitutionUserService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-@Service
-public class InstitutionUserServiceImpl implements InstitutionUserService {
-
-    @Autowired
-    private InstitutionUserRepository institutionUserRepository;
-
-    @Override
-    public InstitutionUserEntity findInstitutionByNo(String institutionNo) {
-        return this.institutionUserRepository.findInstitutionByNo(institutionNo);
-    }
-
-    @Override
-    public InstitutionUserEntity getOne(String institutionId) {
-        return this.institutionUserRepository.findById(institutionId).get();
-    }
-
-    @Override
-    public InstitutionUserEntity findByPhoneAndPassword(String phone, String password) {
-        return this.institutionUserRepository.findByPhoneAndPassword(phone, password);
-    }
-
-    @Override
-    public InstitutionUserEntity findByPhone(String phone) {
-        return this.institutionUserRepository.findByPhone(phone);
-    }
-
-    @Override
-    public InstitutionUserEntity findByInstitutionNoAndPhone(String institutionNo, String phone) {
-        return this.institutionUserRepository.findByInstitutionNoAndPhone(institutionNo, phone);
-    }
-
-    @Override
-    public void save(InstitutionUserEntity institutionUserEntity) {
-        this.institutionUserRepository.save(institutionUserEntity);
-    }
-
-
-    @Override
-    public void updatePassword(String phone, String password, String institutionNo) {
-        this.institutionUserRepository.updatePassword(phone, password, institutionNo);
-    }
-
-    @Override
-    public List<InstitutionUserEntity> findAllByName(int pageNum, int pageSize, String searchKey) {
-        int beginIndex = (pageNum - 1) * pageSize;
-        if (searchKey != null && !"".equals(searchKey)) {
-            return this.institutionUserRepository.findAllByName(beginIndex, pageSize, searchKey);
-        } else {
-            return this.institutionUserRepository.findAll(beginIndex, pageSize);
-        }
-    }
-
-    @Override
-    public int allNum(String searchKey) {
-        return this.institutionUserRepository.allNum(searchKey);
-    }
-
-    @Override
-    public List<InstitutionUserEntity> findAllInAdminByInNo(int pageNum, int pageSize, String institutionNo, String searchKey) {
-        return this.institutionUserRepository.findAllByInNo((pageNum - 1) * pageSize, pageSize, institutionNo, searchKey);
-    }
-
-    @Override
-    public int numAllInAdminByInNo(String institutionNo, String searchKey) {
-        return this.institutionUserRepository.numAllByInNo(institutionNo, searchKey);
-    }
-
-    @Override
-    public void deleteByPhoneAndInstitutionNo(String phone, String institutionNo) {
-        this.institutionUserRepository.deleteByPhoneAndInstitutionNo(phone, institutionNo);
-    }
-
-    @Override
-    public void updateUserStatusByPhone(String phone, String userStatus, String institutionNo) {
-        this.institutionUserRepository.updateUserStatusByPhone(phone, userStatus, institutionNo);
-    }
-
-}

+ 0 - 2
src/main/java/com/rf/psychological/opLog/aspect/UserLogAspect.java

@@ -9,8 +9,6 @@ import com.rf.psychological.utils.DateUtil;
 import com.rf.psychological.utils.IPUtiles;
 import com.rf.psychological.utils.JWTUtil;
 import com.rf.psychological.utils.Result;
-import com.rf.psychological.institution.model.InstitutionEntity;
-import com.rf.psychological.institution.model.InstitutionUserEntity;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.aspectj.lang.JoinPoint;

+ 1 - 3
src/main/java/com/rf/psychological/rest/ServerController.java

@@ -13,7 +13,6 @@ import com.rf.psychological.dao.model.CategorySubjectEntity;
 import com.rf.psychological.dao.model.CognitiveTaskEntity;
 import com.rf.psychological.enums.UserRole;
 import com.rf.psychological.group.service.GroupAuthService;
-import com.rf.psychological.group.service.GroupInfoService;
 import com.rf.psychological.institution.model.InstitutionEntity;
 import com.rf.psychological.institution.service.InstitutionAuthService;
 import com.rf.psychological.institution.service.InstitutionService;
@@ -106,8 +105,7 @@ public class ServerController extends BaseController {
     @Autowired
     private GroupAuthService groupAuthService;
 
-    @Autowired
-    private GroupInfoService groupInfoService;
+
 
     @Autowired
     private InstitutionService institutionService;

+ 1 - 1
src/main/java/com/rf/psychological/user/dao/repository/UserRepository.java

@@ -79,7 +79,7 @@ public interface UserRepository extends BaseRepository<UserEntity, String> {
      * @param searchKey
      * @return
      */
-    @Query(value = "select distinct tui.id,gender,password,pet_name,tui.phone,birthday,profession,addition_info,institution_name,tui.institution_no,user_status,g_id,model_phone,role_type from t_user_info tui join t_user_record tur on  tui.phone=tur.phone and tui.institution_no=tur.institution_no " +
+    @Query(value = "select distinct tui.id,gender,password,pet_name,tui.phone,birthday,profession,institution_name,tui.institution_no,user_status,g_id,model_phone,role_type from t_user_info tui join t_user_record tur on  tui.phone=tur.phone and tui.institution_no=tur.institution_no " +
             " where tui.institution_no = :institutionNo  and role_type ='1' and (pet_name like %:searchKey% or tui.phone like %:searchKey% ) order by id  limit :pageNum ,:pageSize ", nativeQuery = true)
     List<UserEntity> getTestListByInstitutionNo(@Param("pageNum") int pageNum, @Param("pageSize") int pageSize, @Param("institutionNo") String institutionNo, @Param("searchKey") String searchKey);