TRX 1 年間 前
コミット
a9fe7e8877

+ 66 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/org/OrganizationUserModel.java

@@ -0,0 +1,66 @@
+package com.zhongshu.card.client.model.org;
+
+import com.github.microservice.auth.security.type.AuthType;
+import com.zhongshu.card.client.model.base.SuperModel;
+import com.zhongshu.card.client.utils.type.UserState;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 击鼓用户详情
+ *
+ * @author TRX
+ * @date 2024/6/6
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class OrganizationUserModel extends SuperModel {
+
+    @Schema(description = "机构信息")
+    private OrganizationModel organization;
+
+    @Schema(description = "用户信息")
+    private UserCountModel user;
+
+    @Schema(description = "用户ID")
+    private String userId;
+
+    @Schema(description = "工号")
+    private String code;
+
+    @Schema(description = "用户手机号")
+    private String phone;
+
+    @Schema(description = "姓名")
+    private String name;
+
+    @Schema(description = "用户状态")
+    private UserState state = UserState.Normal;
+
+    private String stateStr;
+
+    public String getStateStr() {
+        if (state != null) {
+            return state.getRemark();
+        }
+        return "";
+    }
+
+    @Schema(description = "是否是企业管理员")
+    private Boolean isAdmin = Boolean.FALSE;
+
+    @Schema(description = "机构类型")
+    private AuthType authType = AuthType.Enterprise;
+
+    @Schema(description = "角色信息")
+    private List<RoleModel> roles = new ArrayList<>();
+
+    @Schema(description = "部门信息")
+    private List<DepartmentModel> departments = new ArrayList<>();
+}

+ 3 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/org/OrganizationUserSearch.java

@@ -13,6 +13,9 @@ import lombok.Data;
 @Data
 public class OrganizationUserSearch extends SuperSearch {
 
+    @Schema(description = "关键字")
+    private String keyWord;
+
     @Schema(description = "用户ID")
     private String userId;
 

+ 2 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/service/org/DepartmentService.java

@@ -1,5 +1,6 @@
 package com.zhongshu.card.client.service.org;
 
+import com.zhongshu.card.client.model.org.DepartmentModel;
 import com.zhongshu.card.client.model.org.DepartmentParam;
 import com.zhongshu.card.client.ret.ResultContent;
 import com.zhongshu.card.client.utils.ITree;
@@ -18,4 +19,5 @@ public interface DepartmentService {
 
     // 删除部门
     ResultContent deleteDepartment(String id);
+
 }

+ 3 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/service/org/UserAccountService.java

@@ -31,6 +31,9 @@ public interface UserAccountService {
     // 重置用户密码(默认密码)
     ResultContent resetPassWord(UserIdModel param);
 
+    // 查询结构用户列表
+    ResultContent<Page<OrganizationUserModel>> pageOrgUser(OrganizationUserSearch param, Pageable pageable);
+
     ResultContent<UserCountDetailsModel> getCurrentDetail(AuthTypeParam param);
 
     ResultContent<UserCountModel> getUserDetail(String userId);

+ 0 - 1
FullCardClient/src/main/java/com/zhongshu/card/client/utils/type/UserState.java

@@ -9,7 +9,6 @@ public enum UserState {
 
     Normal("正常"),
     Locked("锁定"),
-    Frozen("冻结"),
     ;
 
     @Getter

+ 1 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/org/IndexController.java

@@ -62,7 +62,7 @@ public class IndexController {
      * @param param
      * @return
      */
-    @Operation(summary = "登录--web端登录使用", description = "登录--web端登录使用")
+    @Operation(summary = "登录-用户名密码登录", description = "登录--用户名密码登录")
     @RequestMapping(value = "login", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
     public ResultContent login(@RequestBody LoginParam param, HttpServletRequest request, HttpServletResponse response) {
         ResultContent result = indexService.login(param);

+ 2 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/org/RoleController.java

@@ -5,7 +5,7 @@ import com.github.microservice.auth.security.type.AuthType;
 import com.zhongshu.card.client.model.base.IDParam;
 import com.zhongshu.card.client.model.org.*;
 import com.zhongshu.card.client.ret.ResultContent;
-import com.zhongshu.card.server.core.service.org.RoleService;
+import com.zhongshu.card.server.core.service.org.RoleServiceImpl;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
 public class RoleController {
 
     @Autowired
-    RoleService roleService;
+    RoleServiceImpl roleService;
 
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "添加-编辑角色", description = "添加-编辑角色")

+ 20 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/org/UserController.java

@@ -12,8 +12,12 @@ import com.zhongshu.card.client.service.org.UserAccountService;
 import com.zhongshu.card.client.utils.type.UserState;
 import com.zhongshu.card.server.core.service.org.IndexService;
 import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.web.PageableDefault;
 import org.springframework.util.Assert;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -43,6 +47,15 @@ public class UserController {
     @Autowired
     UserAccountService userAccountService;
 
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "机构用户列表-分页查询", description = "机构用户列表-分页查询")
+    @RequestMapping(value = {"pageOrgUser"}, method = {RequestMethod.POST})
+    public ResultContent<Page<OrganizationUserModel>> page(
+            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            @Parameter(required = false) OrganizationUserSearch param) {
+        return userAccountService.pageOrgUser(param, pageable);
+    }
+
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "添加-编辑用户", description = "添加-编辑用户")
     @RequestMapping(value = {"update"}, method = {RequestMethod.POST})
@@ -57,6 +70,13 @@ public class UserController {
         return userAccountService.deleteOrgUser(param);
     }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "禁用-启用用户", description = "禁用-启用用户")
+    @RequestMapping(value = {"updateOrgUserState"}, method = {RequestMethod.POST})
+    public ResultContent updateOrgUserState(@RequestBody UpdateUserStateParam param) {
+        return userAccountService.updateOrgUserState(param);
+    }
+
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "重置用户密码", description = "重置用户密码(重置为默认密码)")
     @RequestMapping(value = {"resetPassWord"}, method = {RequestMethod.POST})

+ 5 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/impl/OrganizationUserDaoImpl.java

@@ -82,6 +82,11 @@ public class OrganizationUserDaoImpl extends BaseImpl implements OrganizationUse
         if (!CollectionUtils.isEmpty(criterias)) {
             criteria.andOperator(criterias.toArray(new Criteria[]{}));
         }
+        // 关键字搜索
+        if (StringUtils.isNotEmpty(param.getKeyWord())) {
+            Pattern pattern = Pattern.compile("^.*" + param.getKeyWord() + ".*$");
+            criteria.orOperator(Criteria.where("name").regex(pattern), Criteria.where("phone").regex(pattern));
+        }
 
         criteria.and("isDelete").is(Boolean.FALSE);
         Sort sort = buildSort(param);

+ 2 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/IndexService.java

@@ -95,8 +95,8 @@ public class IndexService {
                 return ResultContent.buildFail("账号或密码不正确");
             }
             // 判断用户状态
-            if (userAccount.getState() == UserState.Frozen) {
-                return ResultContent.buildFail("该账号已被冻结,不能登录");
+            if (userAccount.getState() == UserState.Locked) {
+                return ResultContent.buildFail(String.format("该账号已被%s,不能登录", userAccount.getState().getRemark()));
             }
 
             if (userAccount.getIsDelete() != null && userAccount.getIsDelete()) {

+ 1 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/OrganizationServiceImpl.java

@@ -504,6 +504,7 @@ public class OrganizationServiceImpl extends SuperService implements Organizatio
             organizationUser.setCode("0000001");
             organizationUser.setUser(userAccount);
             organizationUser.setOrganization(organization);
+            organizationUser.setOid(organization.getOid());
             organizationUser.setName(userAccount.getName());
             organizationUser.setPhone(userAccount.getPhone());
             organizationUser.setIsAdmin(Boolean.TRUE);

+ 1 - 6
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/RoleService.java → FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/RoleServiceImpl.java

@@ -8,12 +8,9 @@ import com.zhongshu.card.client.ret.ResultContent;
 import com.zhongshu.card.client.ret.ResultMessage;
 import com.zhongshu.card.client.utils.type.RoleType;
 import com.zhongshu.card.server.core.dao.org.RoleDao;
-import com.zhongshu.card.server.core.dataConfig.CardDefault;
-import com.zhongshu.card.server.core.domain.org.Organization;
 import com.zhongshu.card.server.core.domain.org.Role;
 import com.zhongshu.card.server.core.service.base.SuperService;
 import com.zhongshu.card.server.core.util.BeanUtils;
-import com.zhongshu.card.server.core.util.DateUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -23,15 +20,13 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
 
-import java.util.List;
-
 /**
  * @author TRX
  * @date 2024/6/5
  */
 @Slf4j
 @Service
-public class RoleService extends SuperService {
+public class RoleServiceImpl extends SuperService {
 
     @Autowired
     RoleDao roleDao;

+ 97 - 39
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/UserAccountServiceImpl.java

@@ -5,13 +5,13 @@ import com.github.microservice.auth.client.model.UserAuthModel;
 import com.github.microservice.auth.client.service.RoleService;
 import com.github.microservice.auth.client.service.UserService;
 import com.github.microservice.auth.client.type.LoginType;
-import com.github.microservice.auth.security.type.AuthType;
 import com.github.microservice.components.data.base.util.PageEntityUtil;
 import com.zhongshu.card.client.model.base.AuthTypeParam;
 import com.zhongshu.card.client.model.base.UserIdModel;
 import com.zhongshu.card.client.model.org.*;
 import com.zhongshu.card.client.ret.ResultContent;
 import com.zhongshu.card.client.ret.ResultMessage;
+import com.zhongshu.card.client.service.org.DepartmentService;
 import com.zhongshu.card.client.service.org.OrganizationService;
 import com.zhongshu.card.client.service.org.UserAccountService;
 import com.zhongshu.card.client.utils.type.Sex;
@@ -23,13 +23,9 @@ import com.zhongshu.card.server.core.dataConfig.CardDefault;
 import com.zhongshu.card.server.core.domain.org.*;
 import com.zhongshu.card.server.core.service.base.SuperService;
 import com.zhongshu.card.server.core.util.BeanUtils;
+import com.zhongshu.card.server.core.util.CommonUtil;
+import com.zhongshu.card.server.core.util.DateUtils;
 import lombok.extern.slf4j.Slf4j;
-import net.sourceforge.pinyin4j.PinyinHelper;
-import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
-import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
-import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
-import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
-import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -77,6 +73,12 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
     @Autowired
     RoleService roleService;
 
+    @Autowired
+    RoleServiceImpl roleServiceImpl;
+
+    @Autowired
+    DepartmentServiceImpl departmentService;
+
     /**
      * 添加编辑用户
      *
@@ -135,7 +137,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
                 temp.setOid(null);
                 temp.setLoginName(loginName);
                 temp.setIsLogined(Boolean.FALSE);
-                temp.setSpellCode(getPinyin(param.getName()));
+                temp.setSpellCode(CommonUtil.getPinyin(param.getName()));
                 userCountDao.save(temp);
             }
         } else {
@@ -144,7 +146,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
                 return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, param.getId()));
             }
             BeanUtils.copyProperties(param, temp);
-            temp.setSpellCode(getPinyin(param.getName()));
+            temp.setSpellCode(CommonUtil.getPinyin(param.getName()));
             userCountDao.save(temp);
         }
 
@@ -185,6 +187,7 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         return ResultContent.buildSuccess();
     }
 
+
     /**
      * 删除机构用户
      *
@@ -193,7 +196,30 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
      */
     @Override
     public ResultContent deleteOrgUser(DelUserCountParam param) {
+        String userId = param.getUserId();
+        String oid = param.getOid();
+        if (StringUtils.isEmpty(oid)) {
+            oid = getCurrentOid();
+        }
+        Assert.hasText(oid, "oid不能为空");
+        Assert.hasText(userId, "userId不能为空");
 
+        Organization organization = organizationDao.findTopByOid(oid);
+        if (ObjectUtils.isEmpty(organization)) {
+            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, oid));
+        }
+        UserAccount temp = userCountDao.findTopByUserId(userId);
+        if (ObjectUtils.isEmpty(temp)) {
+            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, userId));
+        }
+        OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, temp);
+        if (ObjectUtils.isEmpty(organizationUser)) {
+            return ResultContent.buildFail(String.format("企业没有改用户:%s", oid));
+        }
+        if (organizationUser.getIsAdmin() != null && organizationUser.getIsAdmin()) {
+            return ResultContent.buildFail(String.format("管理员用户不能删除"));
+        }
+        organizationUserDao.delete(organizationUser);
         return ResultContent.buildSuccess();
     }
 
@@ -210,11 +236,22 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         if (StringUtils.isEmpty(oid)) {
             oid = getCurrentOid();
         }
+        Assert.hasText(oid, "oid不能为空");
+        Assert.hasText(userId, "userId不能为空");
+
         Organization organization = organizationDao.findTopByOid(oid);
+        if (ObjectUtils.isEmpty(organization)) {
+            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, oid));
+        }
         UserAccount temp = userCountDao.findTopByUserId(userId);
+        if (ObjectUtils.isEmpty(temp)) {
+            return ResultContent.buildFail(String.format(ResultMessage.DATA_NOT_EXIST, userId));
+        }
         OrganizationUser organizationUser = organizationUserDao.findTopByOrganizationAndUser(organization, temp);
-        organizationUser.setState(param.getUserState());
-        organizationUserDao.save(organizationUser);
+        if (ObjectUtils.isNotEmpty(organizationUser)) {
+            organizationUser.setState(param.getUserState());
+            organizationUserDao.save(organizationUser);
+        }
         return ResultContent.buildSuccess();
     }
 
@@ -263,6 +300,34 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         return ResultContent.buildSuccess();
     }
 
+    /**
+     * 查询结构用户列表
+     *
+     * @param param
+     * @param pageable
+     * @return
+     */
+    @Override
+    public ResultContent<Page<OrganizationUserModel>> pageOrgUser(OrganizationUserSearch param, Pageable pageable) {
+        String oid = param.getOid();
+        if (StringUtils.isEmpty(oid)) {
+            oid = getCurrentOid();
+        }
+        param.setOid(oid);
+        Assert.hasText(oid, "oid不能为空");
+        List<Long> times = param.getTimes();
+        if (ObjectUtils.isNotEmpty(times) && times.size() == 2) {
+            Long startTime = times.get(0);
+            startTime = DateUtils.getDayStartTime(startTime);
+            Long endTime = times.get(1);
+            endTime = DateUtils.getDayEndTime(endTime);
+            param.setStartTime(startTime);
+            param.setEndTime(endTime);
+        }
+        Page<OrganizationUser> page = organizationUserDao.page(pageable, param);
+        return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toOrgUserModel));
+    }
+
     /**
      * 初始化一个 账号信息 (创建机构时用)
      *
@@ -350,35 +415,28 @@ public class UserAccountServiceImpl extends SuperService implements UserAccountS
         return model;
     }
 
-    private String getPinyin(String chinaStr) {
-        if (StringUtils.isEmpty(chinaStr)) {
-            return "";
-        }
-        HanyuPinyinOutputFormat forMat = new HanyuPinyinOutputFormat();
-        forMat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
-        forMat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
-        forMat.setVCharType(HanyuPinyinVCharType.WITH_V);
-        char[] arrays = chinaStr.trim().toCharArray();
-        String result = "";
-        try {
-            for (int i = 0; i < arrays.length; i++) {
-                char ti = arrays[i];
-                if (Character.toString(ti).matches("[\\u4e00-\\u9fa5]")) { //匹配是否是中文
-                    String[] temp = PinyinHelper.toHanyuPinyinStringArray(ti, forMat);
-                    result += temp[0];
-                } else {
-                    result += ti;
-                }
+    public OrganizationUserModel toOrgUserModel(OrganizationUser entity) {
+        OrganizationUserModel model = new OrganizationUserModel();
+        if (ObjectUtils.isNotEmpty(entity)) {
+            BeanUtils.copyProperties(entity, model);
+
+            // 用户信息
+            UserCountModel userCountModel = toModel(entity.getUser());
+            model.setUser(userCountModel);
+
+            // 角色信息
+            if (ObjectUtils.isNotEmpty(entity.getRoles())) {
+                List<RoleModel> roleModels = entity.getRoles().stream().map(roleServiceImpl::toModel)
+                        .collect(Collectors.toList());
+                model.setRoles(roleModels);
+            }
+            // 部门信息
+            if (ObjectUtils.isNotEmpty(entity.getDepartments())) {
+                List<DepartmentModel> roleModels = entity.getDepartments().stream().map(departmentService::toModel)
+                        .collect(Collectors.toList());
+                model.setDepartments(roleModels);
             }
-        } catch (BadHanyuPinyinOutputFormatCombination e) {
-            e.printStackTrace();
-        }
-        //判断如果包含重庆,则替换拼音中的zhongqing为chongqing
-        if (chinaStr.indexOf("重庆") == -1) {
-            //do nothing
-        } else {
-            result = result.replace("zhongqing", "chongqing");
         }
-        return result;
+        return model;
     }
 }

+ 43 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/util/CommonUtil.java

@@ -10,6 +10,12 @@ import com.zhongshu.card.server.core.domain.base.SuperMain;
 import com.zhongshu.card.server.core.util.exception.BusinessException;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
+import net.sourceforge.pinyin4j.PinyinHelper;
+import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
+import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
+import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
+import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
+import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.bson.types.Decimal128;
@@ -380,4 +386,41 @@ public class CommonUtil {
         return String.format("wxApp=%s%s", phone, iv);
     }
 
+    /**
+     * 汉字转为拼音
+     *
+     * @param chinaStr
+     * @return
+     */
+    public static String getPinyin(String chinaStr) {
+        if (StringUtils.isEmpty(chinaStr)) {
+            return "";
+        }
+        HanyuPinyinOutputFormat forMat = new HanyuPinyinOutputFormat();
+        forMat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
+        forMat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
+        forMat.setVCharType(HanyuPinyinVCharType.WITH_V);
+        char[] arrays = chinaStr.trim().toCharArray();
+        String result = "";
+        try {
+            for (int i = 0; i < arrays.length; i++) {
+                char ti = arrays[i];
+                if (Character.toString(ti).matches("[\\u4e00-\\u9fa5]")) { //匹配是否是中文
+                    String[] temp = PinyinHelper.toHanyuPinyinStringArray(ti, forMat);
+                    result += temp[0];
+                } else {
+                    result += ti;
+                }
+            }
+        } catch (BadHanyuPinyinOutputFormatCombination e) {
+            e.printStackTrace();
+        }
+        //判断如果包含重庆,则替换拼音中的zhongqing为chongqing
+        if (chinaStr.indexOf("重庆") == -1) {
+            //do nothing
+        } else {
+            result = result.replace("zhongqing", "chongqing");
+        }
+        return result;
+    }
 }