Forráskód Böngészése

子账户功能后端结构

chenlei1231 1 hónapja
szülő
commit
ba2a12fa1d

+ 8 - 3
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/common/mapper/CommonMapper.java

@@ -1,10 +1,10 @@
 package org.jeecg.modules.adweb.common.mapper;
 
-import org.apache.ibatis.annotations.Select;
-import org.jeecg.modules.system.entity.SysUser;
-
 import java.util.Date;
 import java.util.List;
+import org.apache.ibatis.annotations.Select;
+import org.jeecg.modules.system.entity.SysPermission;
+import org.jeecg.modules.system.entity.SysUser;
 
 /**
  * 通用MyBatis mapper工具
@@ -30,4 +30,9 @@ public interface CommonMapper {
             "ON t3.id = t2.role_id\n" +
             "WHERE t3.role_code = 'adweb_vip' AND t1.del_flag = 0 AND t1.username != ''")
     List<SysUser> getAdwebVip();
+
+    /**
+     * 获取 adweb_vip 角色的权限
+     */
+    List<SysPermission> getAdwebVipPermission();
 }

+ 13 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/common/mapper/xml/CommonMapper.xml

@@ -14,4 +14,17 @@
         </where>
     </select>
 
+    <select id="getAdwebVipPermission" resultType="org.jeecg.modules.system.entity.SysPermission">
+        SELECT t3.*
+        FROM sys_role t1,
+             sys_role_permission t2,
+             sys_permission t3
+        WHERE t1.role_code = 'adweb_vip'
+          AND t1.id = t2.role_id
+          AND t2.permission_id = t3.id
+          AND t3.del_flag = 0
+          AND t3.url NOT IN ('/enterprise', '/enterprise/enterpriseUser', '/inquery/rules', '/account', '/tools')
+        ORDER BY t3.sort_no
+    </select>
+
 </mapper>

+ 190 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enterprise/controller/EnterpriseUserManageController.java

@@ -0,0 +1,190 @@
+package org.jeecg.modules.adweb.enterprise.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletRequest;
+import java.util.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.common.system.api.ISysBaseAPI;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.modules.adweb.common.mapper.CommonMapper;
+import org.jeecg.modules.adweb.enquiry.service.IAdwebEnquiryService;
+import org.jeecg.modules.adweb.enquiry.service.ISubUserEmailService;
+import org.jeecg.modules.adweb.enterprise.service.SysUserPermissionService;
+import org.jeecg.modules.adweb.enterprise.vo.User;
+import org.jeecg.modules.adweb.site.entity.AdwebSite;
+import org.jeecg.modules.adweb.site.service.IAdwebSiteService;
+import org.jeecg.modules.adweb.site.service.IAdwebUserWpsiteService;
+import org.jeecg.modules.adweb.site.service.ISiteUserPermissionService;
+import org.jeecg.modules.adweb.system.service.IMasterSubAccountRelationService;
+import org.jeecg.modules.system.entity.SysUser;
+import org.jeecg.modules.system.service.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @Description: 企业用户管理 @Author: jeecg-boot @Date: 2022-06-10 @Version: V1.0
+ */
+@Tag(name = "企业用户管理")
+@RestController
+@RequestMapping("/enterprise/user")
+@Slf4j
+public class EnterpriseUserManageController {
+  @Autowired private ISysUserService sysUserService;
+
+  @Autowired private IMasterSubAccountRelationService masterSubAccountRelationService;
+
+  @Autowired private ISysRoleService sysRoleService;
+
+  @Autowired private ISysUserRoleService sysUserRoleService;
+
+  @Autowired private ISiteUserPermissionService siteUserPermissionService;
+
+  @Autowired private IAdwebSiteService adwebSiteService;
+
+  @Resource private SysUserPermissionService sysUserPermissionService;
+
+  @Resource private CommonMapper adwebCommonMapper;
+
+  @Resource private IAdwebEnquiryService adwebEnquiryService;
+
+  @Autowired private ISysBaseAPI sysBaseAPI;
+
+  @Autowired private IAdwebUserWpsiteService adwebUserWpsiteService;
+
+  @Autowired private ISubUserEmailService subUserEmailService;
+
+  /**
+   * 子账户分页列表查询
+   *
+   * @param user
+   * @param pageNo
+   * @param pageSize
+   * @param req
+   * @return
+   */
+  @AutoLog(value = "企业用户管理-子账户分页列表查询")
+  @Operation(summary = "企业用户管理-子账户分页列表查询")
+  @GetMapping(value = "/sub/list")
+  public Result<IPage<User>> querySubPageList(
+      SysUser user,
+      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+      @RequestParam String siteCode,
+      HttpServletRequest req) {
+    Map<String, String[]> map = new HashMap(req.getParameterMap());
+    map.put("order", new String[] {"asc"});
+
+    LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+    List<String> idList =
+        masterSubAccountRelationService.getSubAccountIdByMaster(loginUser.getId());
+    // 获取当前站点主账号
+    QueryWrapper<AdwebSite> adwebSiteQueryWrapper = new QueryWrapper<>();
+    adwebSiteQueryWrapper.eq("code", siteCode);
+    AdwebSite adwebSite = adwebSiteService.getOne(adwebSiteQueryWrapper);
+    if (adwebSite != null) {
+      idList.add(adwebSite.getUid());
+    }
+    //        idList.add(loginUser.getId());
+    if (CollectionUtils.isEmpty(idList)) {
+      return Result.OK();
+    }
+    QueryWrapper<SysUser> queryWrapper = QueryGenerator.initQueryWrapper(user, map);
+    queryWrapper.ne("username", "_reserve_user_external");
+    queryWrapper.in("id", idList);
+    queryWrapper.eq("status", 1);
+    String queryCondition = req.getParameter("queryCondition");
+    if (StringUtils.isNotEmpty(queryCondition)) {
+      queryWrapper.and(
+          wrapper ->
+              wrapper
+                  .like("username", queryCondition)
+                  .or()
+                  .like("realname", queryCondition)
+                  .or()
+                  .like("phone", queryCondition));
+    }
+    Page<SysUser> page = new Page<SysUser>(pageNo, pageSize);
+    IPage<SysUser> pageList = sysUserService.page(page, queryWrapper);
+    // 类型转换
+    IPage<User> pageList2 = converseType(pageList);
+    // 序号
+    this.addSeqNumber(pageList2.getRecords(), pageNo, pageSize);
+    // 统计管理的询盘和产品数量
+    /*Map<String, Integer> map1 = adwebEnquiryService.getEnquiryCount(idList);
+    Map<String, Integer> map2 = adwebMaterialProductService.getProductCount(idList);
+    for (User user1 : pageList2.getRecords()) {
+        if (map1.get(user1.getId()) != null) {
+            user1.setEnquiryNum(map1.get(user1.getId()));
+        }
+        if (map2.get(user1.getId()) != null) {
+            user1.setProductNum(map2.get(user1.getId()));
+        }
+    }*/
+    // 主账户产品和询盘数量统计规则不同
+    if (pageNo == 1 && CollectionUtils.isNotEmpty(pageList2.getRecords())) {
+      User user1 = pageList2.getRecords().get(0);
+      if (user1.getId().equals(adwebSite.getUid())) {
+        user1.setPrimaryAccount(true);
+        user1.setIsInquiry(2);
+      }
+    }
+    return Result.OK(pageList2);
+  }
+
+  private IPage<User> converseType(IPage<SysUser> pageList) {
+    IPage<User> pageList2 = new Page<>();
+    pageList2.setPages(pageList.getPages());
+    pageList2.setCurrent(pageList.getCurrent());
+    pageList2.setSize(pageList.getSize());
+    pageList2.setTotal(pageList.getTotal());
+    if (CollectionUtils.isEmpty(pageList.getRecords())) {
+      pageList2.setRecords(new ArrayList<>());
+      return pageList2;
+    }
+    List<User> users = new ArrayList<>();
+    for (SysUser sysUser : pageList.getRecords()) {
+      User user = new User();
+      user.setId(sysUser.getId());
+      user.setUsername(sysUser.getUsername());
+      user.setRealname(sysUser.getRealname());
+      user.setAvatar(sysUser.getAvatar());
+      user.setPhone(sysUser.getPhone());
+      user.setEmail(sysUser.getEmail());
+      user.setUpdateTime(sysUser.getUpdateTime());
+      user.setCreateTime(sysUser.getCreateTime());
+      //      user.setIsInquiry(sysUser.getIsInquiry());
+      user.setSex(sysUser.getSex());
+      users.add(user);
+    }
+    pageList2.setRecords(users);
+    return pageList2;
+  }
+
+  /**
+   * 增加序号
+   *
+   * @param productList 结果集合
+   * @param pageNum 页号
+   * @param pageSize 页长
+   */
+  public void addSeqNumber(List<User> productList, int pageNum, int pageSize) {
+    if (CollectionUtils.isEmpty(productList)) {
+      return;
+    }
+    int index = (pageNum - 1) * pageSize + 1;
+    for (User user : productList) {
+      user.setSeqNumber(index++);
+    }
+  }
+}

+ 32 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enterprise/dto/CreateUserParam.java

@@ -0,0 +1,32 @@
+package org.jeecg.modules.adweb.enterprise.dto;
+
+import lombok.Data;
+
+/** 请求创建用户的参数 */
+@Data
+public class CreateUserParam {
+
+  private String id;
+
+  private String username;
+
+  private String realname;
+
+  private String password;
+
+  private String phone;
+
+  private String email;
+
+  private String avatar;
+
+  private String masterId;
+
+  private String masterName;
+
+  private String masterEmail;
+
+  private String siteCode;
+
+  private Integer sex;
+}

+ 11 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enterprise/dto/EditPermissionParam.java

@@ -0,0 +1,11 @@
+package org.jeecg.modules.adweb.enterprise.dto;
+
+import lombok.Data;
+
+@Data
+public class EditPermissionParam {
+
+  private String userId;
+
+  private String permissionIds;
+}

+ 43 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enterprise/entity/SysUserPermission.java

@@ -0,0 +1,43 @@
+package org.jeecg.modules.adweb.enterprise.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
+
+/** 子用户权限表 */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class SysUserPermission implements Serializable {
+
+  private static final long serialVersionUID = 1L;
+
+  /** id */
+  @TableId(type = IdType.AUTO)
+  private Integer id;
+
+  /** 用户id */
+  private String userId;
+
+  /** 权限id */
+  private String permissionId;
+
+  /** 操作时间 */
+  @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+  @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+  private Date createTime;
+
+  public SysUserPermission() {}
+
+  public SysUserPermission(String userId, String permissionId) {
+    this.userId = userId;
+    this.permissionId = permissionId;
+    this.createTime = new Date();
+  }
+}

+ 6 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enterprise/mapper/SysUserPermissionMapper.java

@@ -0,0 +1,6 @@
+package org.jeecg.modules.adweb.enterprise.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.adweb.enterprise.entity.SysUserPermission;
+
+public interface SysUserPermissionMapper extends BaseMapper<SysUserPermission> {}

+ 24 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enterprise/service/SysUserPermissionService.java

@@ -0,0 +1,24 @@
+package org.jeecg.modules.adweb.enterprise.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import java.util.List;
+import org.jeecg.modules.adweb.enterprise.entity.SysUserPermission;
+import org.jeecg.modules.system.entity.SysPermission;
+
+public interface SysUserPermissionService extends IService<SysUserPermission> {
+
+  /**
+   * 删除原有权限,赋予新的权限
+   *
+   * @param userId 用户id
+   * @param permissionIds 给用户分配的权限
+   */
+  void editUserPermission(String userId, String permissionIds);
+
+  /**
+   * 获取用户菜单权限
+   *
+   * @param userId 用户id
+   */
+  List<SysPermission> getPermissionsByUserId(String userId);
+}

+ 91 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enterprise/service/impl/SysUserPermissionServiceImpl.java

@@ -0,0 +1,91 @@
+package org.jeecg.modules.adweb.enterprise.service.impl;
+
+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 jakarta.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.jeecg.modules.adweb.enterprise.entity.SysUserPermission;
+import org.jeecg.modules.adweb.enterprise.mapper.SysUserPermissionMapper;
+import org.jeecg.modules.adweb.enterprise.service.SysUserPermissionService;
+import org.jeecg.modules.system.entity.SysPermission;
+import org.jeecg.modules.system.service.ISysPermissionService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+public class SysUserPermissionServiceImpl
+    extends ServiceImpl<SysUserPermissionMapper, SysUserPermission>
+    implements SysUserPermissionService {
+
+  @Resource private ISysPermissionService sysPermissionService;
+
+  /**
+   * 删除原有权限,赋予新的权限
+   *
+   * @param userId 用户id
+   * @param permissionIds 给用户分配的权限
+   */
+  @Override
+  @Transactional
+  public void editUserPermission(String userId, String permissionIds) {
+    QueryWrapper<SysUserPermission> queryWrapper = new QueryWrapper<>();
+    queryWrapper.eq("user_id", userId);
+    this.remove(queryWrapper);
+
+    List<SysUserPermission> permissions = new ArrayList<>();
+    String[] permissionIdArr = permissionIds.split(",");
+    for (String permissionId : permissionIdArr) {
+      permissions.add(new SysUserPermission(userId, permissionId));
+    }
+    // 如果没有首页权限,要增加首页权限
+    SysPermission indexMenu =
+        sysPermissionService
+            .list(new LambdaQueryWrapper<SysPermission>().eq(SysPermission::getName, "首页"))
+            .get(0);
+    if (!permissionIds.contains(indexMenu.getId())) {
+      permissions.add(new SysUserPermission(userId, indexMenu.getId()));
+    }
+    // 以下两个菜单为默认拥有的权限
+    List<SysPermission> fatherPermission =
+        sysPermissionService.list(
+            new LambdaQueryWrapper<SysPermission>()
+                .in(SysPermission::getUrl, Arrays.asList("/account", "/tools")));
+    List<String> fatherPermissionIds =
+        fatherPermission.stream().map(SysPermission::getId).collect(Collectors.toList());
+    List<SysPermission> subPermission =
+        sysPermissionService.list(
+            new LambdaQueryWrapper<SysPermission>()
+                .in(SysPermission::getParentId, fatherPermissionIds));
+    for (SysPermission permission : fatherPermission) {
+      permissions.add(new SysUserPermission(userId, permission.getId()));
+    }
+    for (SysPermission permission : subPermission) {
+      permissions.add(new SysUserPermission(userId, permission.getId()));
+    }
+    this.saveBatch(permissions);
+  }
+
+  /**
+   * 获取用户菜单权限
+   *
+   * @param userId 用户id
+   */
+  @Override
+  public List<SysPermission> getPermissionsByUserId(String userId) {
+    QueryWrapper<SysUserPermission> queryWrapper = new QueryWrapper<>();
+    queryWrapper.eq("user_id", userId);
+    List<SysUserPermission> permissions = this.list(queryWrapper);
+
+    List<String> ids =
+        permissions.stream().map(SysUserPermission::getPermissionId).collect(Collectors.toList());
+    QueryWrapper<SysPermission> permissionQueryWrapper = new QueryWrapper<>();
+    permissionQueryWrapper.in("id", ids);
+    permissionQueryWrapper.eq("del_flag", 0);
+    permissionQueryWrapper.orderByAsc("sort_no");
+    return sysPermissionService.list(permissionQueryWrapper);
+  }
+}

+ 35 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/enterprise/vo/User.java

@@ -0,0 +1,35 @@
+package org.jeecg.modules.adweb.enterprise.vo;
+
+import java.util.Date;
+import lombok.Data;
+
+@Data
+public class User {
+
+  private String id;
+
+  private String username;
+
+  private String realname;
+
+  private String avatar;
+
+  private String phone;
+
+  private String email;
+
+  private Date updateTime;
+
+  private Date createTime;
+
+  private boolean isPrimaryAccount;
+
+  private int productNum;
+
+  private int EnquiryNum;
+
+  private int seqNumber;
+
+  private Integer isInquiry;
+  private Integer sex;
+}