Bladeren bron

学校功能

TRX 1 jaar geleden
bovenliggende
commit
bfee20e158

+ 43 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/school/CardInfoModel.java

@@ -0,0 +1,43 @@
+package com.zhongshu.card.client.model.school;
+
+import com.zhongshu.card.client.model.base.SuperModel;
+import com.zhongshu.card.client.model.org.OrganizationModel;
+import com.zhongshu.card.client.model.org.UserCountModel;
+import com.zhongshu.card.client.utils.type.school.CardState;
+import com.zhongshu.card.client.utils.type.school.CardType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * @author TRX
+ * @date 2024/6/13
+ */
+@Data
+public class CardInfoModel extends SuperModel {
+    @Schema(description = "卡片名称")
+    private String name;
+
+    @Schema(description = "卡片类型")
+    private CardType cardType;
+
+    @Schema(description = "卡片号码")
+    private String code;
+
+    @Schema(description = "卡片uid")
+    private String cardUid;
+
+    @Schema(description = "卡片Rfid")
+    private String cardRfid;
+
+    @Schema(description = "卡片状态")
+    private CardState cardState;
+
+    @Schema(description = "所属用户")
+    private UserCountModel userAccount;
+
+    @Schema(description = "所属用户UserId")
+    private String userId;
+
+    @Schema(description = "所属机构")
+    private OrganizationModel organization;
+}

+ 35 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/school/CardInfoParam.java

@@ -0,0 +1,35 @@
+package com.zhongshu.card.client.model.school;
+
+import com.zhongshu.card.client.model.base.SuperParam;
+import com.zhongshu.card.client.utils.type.school.CardState;
+import com.zhongshu.card.client.utils.type.school.CardType;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * @author TRX
+ * @date 2024/6/13
+ */
+@Data
+public class CardInfoParam extends SuperParam {
+    @Schema(description = "卡片名称")
+    private String name;
+
+    @Schema(description = "卡片类型")
+    private CardType cardType;
+
+    @Schema(description = "卡片号码")
+    private String code;
+
+    @Schema(description = "卡片uid")
+    private String cardUid;
+
+    @Schema(description = "卡片Rfid")
+    private String cardRfid;
+
+    @Schema(description = "卡片状态")
+    private CardState cardState;
+
+    @Schema(description = "所属用户userId", hidden = true)
+    private String userId;
+}

+ 21 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/service/school/CardInfoService.java

@@ -0,0 +1,21 @@
+package com.zhongshu.card.client.service.school;
+
+import com.zhongshu.card.client.model.school.CardInfoModel;
+import com.zhongshu.card.client.model.school.CardInfoParam;
+import com.zhongshu.card.client.ret.ResultContent;
+
+import java.util.List;
+
+/**
+ * @author TRX
+ * @date 2024/6/13
+ */
+public interface CardInfoService {
+
+    ResultContent addCardInfo(CardInfoParam param);
+
+    ResultContent<List<CardInfoModel>> getCurrentUserOrgAll();
+
+    List<CardInfoModel> getUserOrgAllCard(String userId, String oid);
+
+}

+ 20 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/utils/type/school/CardState.java

@@ -0,0 +1,20 @@
+package com.zhongshu.card.client.utils.type.school;
+
+import lombok.Getter;
+
+/**
+ *
+ */
+public enum CardState {
+    Enable("正常"),
+    Lock("锁定"),
+    Loss("已挂失"),
+    ;
+
+    @Getter
+    private String remark;
+
+    CardState(String remark) {
+        this.remark = remark;
+    }
+}

+ 18 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/utils/type/school/CardType.java

@@ -0,0 +1,18 @@
+package com.zhongshu.card.client.utils.type.school;
+
+import lombok.Getter;
+
+/**
+ * 字典类型
+ */
+public enum CardType {
+    SevenCard("七芯卡"),
+    ;
+
+    @Getter
+    private String remark;
+
+    CardType(String remark) {
+        this.remark = remark;
+    }
+}

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

@@ -3,6 +3,7 @@ package com.zhongshu.card.server.core.controller.org;
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;
 import com.zhongshu.card.client.model.base.IDParam;
+import com.zhongshu.card.client.model.base.OidModel;
 import com.zhongshu.card.client.model.org.*;
 import com.zhongshu.card.client.ret.ResultContent;
 import com.zhongshu.card.server.core.service.org.RoleServiceImpl;
@@ -46,6 +47,13 @@ public class RoleController {
         return roleService.page(param, pageable);
     }
 
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "得到机构所有角色", description = "得到机构所有角色")
+    @RequestMapping(value = "getAllRoles", method = {RequestMethod.POST})
+    public ResultContent getAllRoles(@RequestBody OidModel param) {
+        return this.roleService.getAllRoles(param.getOid());
+    }
+
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "删除角色", description = "删除角色")
     @RequestMapping(value = "deleteRole", method = {RequestMethod.POST})

+ 25 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/CardInfoDao.java

@@ -0,0 +1,25 @@
+package com.zhongshu.card.server.core.dao;
+
+import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.card.server.core.domain.org.UserAccount;
+import com.zhongshu.card.server.core.domain.school.Area;
+import com.zhongshu.card.server.core.domain.school.CardInfo;
+
+import java.util.List;
+
+/**
+ * 卡片Dao
+ *
+ * @author TRX
+ * @date 2024/3/21
+ */
+public interface CardInfoDao extends MongoDao<CardInfo> {
+
+    CardInfo findTopById(String id);
+
+    // 查询用户code的卡片
+    CardInfo findTopByCodeAndOidAndUserAccount(String code, String oid, UserAccount userAccount);
+
+    // 查询用户所有的卡片
+    List<CardInfo> findTopByUserIdAndOid(String userId, String oid);
+}

+ 2 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/DepartmentDao.java

@@ -24,4 +24,6 @@ public interface DepartmentDao extends MongoDao<Department> {
     List<Department> findByParentIdAndOid(String parentId, String oid);
 
     List<Department> findByOidAndIdIn(String oid, List<String> ids);
+
+    List<Department> findByIdIn(List<String> ids);
 }

+ 4 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/org/RoleDao.java

@@ -16,9 +16,13 @@ public interface RoleDao extends MongoDao<Role>, RoleDaoExtend {
 
     Role findTopById(String id);
 
+    List<Role> findByOidOrderBySortAsc(String oid);
+
     Role findTopByNameAndOid(String name, String oid);
 
     Role findTopByCodeAndOid(String code, String oid);
 
     List<Role> findByOidAndIdIn(String oid, List<String> ids);
+
+    List<Role> findByIdIn(List<String> ids);
 }

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

@@ -3,8 +3,12 @@ package com.zhongshu.card.server.core.dao.org.impl;
 import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
 import com.zhongshu.card.client.model.org.OrganizationUserSearch;
 import com.zhongshu.card.server.core.dao.BaseImpl;
+import com.zhongshu.card.server.core.dao.org.DepartmentDao;
+import com.zhongshu.card.server.core.dao.org.RoleDao;
 import com.zhongshu.card.server.core.dao.org.extend.OrganizationUserDaoExtend;
+import com.zhongshu.card.server.core.domain.org.Department;
 import com.zhongshu.card.server.core.domain.org.OrganizationUser;
+import com.zhongshu.card.server.core.domain.org.Role;
 import com.zhongshu.card.server.core.util.CommonUtil;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -34,6 +38,12 @@ public class OrganizationUserDaoImpl extends BaseImpl implements OrganizationUse
     @Autowired
     private DBHelper dbHelper;
 
+    @Autowired
+    RoleDao roleDao;
+
+    @Autowired
+    DepartmentDao departmentDao;
+
     @Override
     public Page<OrganizationUser> page(Pageable pageable, OrganizationUserSearch param) {
         Criteria criteria = new Criteria();
@@ -68,6 +78,18 @@ public class OrganizationUserDaoImpl extends BaseImpl implements OrganizationUse
             criteria.and("position.id").is(param.getPositionId());
         }
 
+        List<String> roleIds = param.getRoleIds();
+        if (!CollectionUtils.isEmpty(roleIds)) {
+            List<Role> roles = roleDao.findByIdIn(roleIds);
+            criteria.and("roles").in(roles);
+        }
+
+        List<String> departmentIds = param.getDepartmentIds();
+        if (!CollectionUtils.isEmpty(departmentIds)) {
+            List<Department> roles = departmentDao.findByIdIn(departmentIds);
+            criteria.and("departments").in(roles);
+        }
+
         if (!CommonUtil.longIsEmpty(param.getStartTime()) && !CommonUtil.longIsEmpty(param.getEndTime())) {
             criteria.and("createTime").gte(param.getStartTime()).and("createTime").lte(param.getEndTime());
         }

+ 56 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/school/CardInfo.java

@@ -0,0 +1,56 @@
+package com.zhongshu.card.server.core.domain.school;
+
+import com.zhongshu.card.client.utils.type.school.CardState;
+import com.zhongshu.card.client.utils.type.school.CardType;
+import com.zhongshu.card.server.core.domain.base.SuperMain;
+import com.zhongshu.card.server.core.domain.org.Organization;
+import com.zhongshu.card.server.core.domain.org.UserAccount;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.checkerframework.common.aliasing.qual.NonLeaked;
+import org.springframework.data.mongodb.core.mapping.DBRef;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+/**
+ * @author TRX
+ * @date 2024/6/13
+ */
+@Data
+@Document
+@AllArgsConstructor
+@NoArgsConstructor
+@NonLeaked
+public class CardInfo extends SuperMain {
+
+    @Schema(description = "卡片名称")
+    private String name;
+
+    @Schema(description = "卡片类型")
+    private CardType cardType;
+
+    @Schema(description = "卡片号码")
+    private String code;
+
+    @Schema(description = "卡片uid")
+    private String cardUid;
+
+    @Schema(description = "卡片Rfid")
+    private String cardRfid;
+
+    @Schema(description = "卡片状态")
+    private CardState cardState;
+
+    @Schema(description = "所属用户")
+    @DBRef(lazy = true)
+    private UserAccount userAccount;
+
+    @Schema(description = "所属用户UserId")
+    private String userId;
+
+    @Schema(description = "所属机构")
+    @DBRef(lazy = true)
+    private Organization organization;
+
+}

+ 1 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/base/SuperService.java

@@ -96,7 +96,7 @@ public abstract class SuperService {
     }
 
     public void initDefaultUserParam(SuperParam param) {
-        if (authHelper != null && authHelper.getCurrentUser() != null) {
+        if (authHelper != null && authHelper.getCurrentUser() != null && StringUtils.isEmpty(param.getCreateUserId())) {
             param.setCreateUserId(authHelper.getCurrentUser().getUserId());
             param.setCreateUserName(authHelper.getCurrentUser().getUserName());
             param.setCreatePhone(authHelper.getCurrentUser().getPhone());

+ 24 - 4
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/org/RoleServiceImpl.java

@@ -20,6 +20,10 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
 /**
  * @author TRX
  * @date 2024/6/5
@@ -168,15 +172,31 @@ public class RoleServiceImpl extends SuperService {
      * @return
      */
     public ResultContent<Page<RoleModel>> page(RoleSearchParam param, Pageable pageable) {
-        if (StringUtils.isEmpty(param.getOid())) {
-            param.setOid(getCurrentOid());
-        }
-        Assert.hasText(param.getOid(), "oid为空");
+        initOidSearchParam(param);
         param.setIsSortDesc(Boolean.FALSE);
         Page<Role> page = roleDao.page(pageable, param);
         return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
     }
 
+    /**
+     * 得到机构所有的角色
+     *
+     * @param oid
+     * @return
+     */
+    public ResultContent<List<RoleModel>> getAllRoles(String oid) {
+        if (StringUtils.isEmpty(oid)) {
+            oid = getCurrentOid();
+        }
+        Assert.hasText(oid, "oid不能为空");
+        List<Role> list = roleDao.findByOidOrderBySortAsc(oid);
+        List<RoleModel> models = new ArrayList<>();
+        if (ObjectUtils.isNotEmpty(list)) {
+            models = list.stream().map(this::toModel).collect(Collectors.toList());
+        }
+        return ResultContent.buildSuccess(models);
+    }
+
     public RoleModel toModel(Role role) {
         RoleModel roleModel = new RoleModel();
         if (ObjectUtils.isNotEmpty(role)) {

+ 94 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/school/CardInfoServiceImpl.java

@@ -0,0 +1,94 @@
+package com.zhongshu.card.server.core.service.school;
+
+import com.zhongshu.card.client.model.school.CardInfoModel;
+import com.zhongshu.card.client.model.school.CardInfoParam;
+import com.zhongshu.card.client.ret.ResultContent;
+import com.zhongshu.card.client.service.school.CardInfoService;
+import com.zhongshu.card.server.core.dao.CardInfoDao;
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
+import com.zhongshu.card.server.core.dao.org.UserCountDao;
+import com.zhongshu.card.server.core.domain.org.Organization;
+import com.zhongshu.card.server.core.domain.org.UserAccount;
+import com.zhongshu.card.server.core.domain.school.CardInfo;
+import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.util.BeanUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 卡片管理Service
+ *
+ * @author TRX
+ * @date 2024/6/13
+ */
+@Slf4j
+@Service
+public class CardInfoServiceImpl extends SuperService implements CardInfoService {
+
+    @Autowired
+    private CardInfoDao cardInfoDao;
+
+    @Autowired
+    OrganizationDao organizationDao;
+
+    @Autowired
+    UserCountDao userCountDao;
+
+    /**
+     * 添加或修改卡片信息
+     *
+     * @param param
+     * @return
+     */
+    @Override
+    public ResultContent addCardInfo(CardInfoParam param) {
+        initDefaultUserAndOid(param);
+        CardInfo cardInfo = null;
+        if (StringUtils.isNotEmpty(param.getId())) {
+            cardInfo = cardInfoDao.findTopById(param.getId());
+        }
+        if (ObjectUtils.isEmpty(cardInfo)) {
+            cardInfo = new CardInfo();
+        }
+        BeanUtils.copyProperties(param, cardInfo);
+        Organization organization = organizationDao.findTopByOid(param.getOid());
+        UserAccount account = userCountDao.findTopByUserId(param.getUserId());
+        cardInfo.setUserAccount(account);
+        cardInfo.setOrganization(organization);
+        cardInfoDao.save(cardInfo);
+        return ResultContent.buildSuccess();
+    }
+
+    @Override
+    public ResultContent<List<CardInfoModel>> getCurrentUserOrgAll() {
+        String userId = getCurrentUserId();
+        String oid = getCurrentOid();
+        return ResultContent.buildSuccess(getUserOrgAllCard(userId, oid));
+    }
+
+    @Override
+    public List<CardInfoModel> getUserOrgAllCard(String userId, String oid) {
+        List<CardInfoModel> models = new ArrayList<>();
+        List<CardInfo> list = cardInfoDao.findTopByUserIdAndOid(userId, oid);
+        if (ObjectUtils.isNotEmpty(list)) {
+            models = list.stream().map(this::toModel).collect(Collectors.toList());
+        }
+        return models;
+    }
+
+    public CardInfoModel toModel(CardInfo entity) {
+        CardInfoModel model = null;
+        if (ObjectUtils.isNotEmpty(entity)) {
+            model = new CardInfoModel();
+            BeanUtils.copyProperties(entity, model);
+        }
+        return model;
+    }
+}