Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加 用户关联表 #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.jsnjfz.manage.core.common.exception.BizExceptionEnum;
import com.jsnjfz.manage.core.common.node.ZTreeNode;
import com.jsnjfz.manage.core.shiro.ShiroKit;
import com.jsnjfz.manage.core.shiro.ShiroUser;
import com.jsnjfz.manage.modular.system.model.Category;
import com.jsnjfz.manage.modular.system.service.impl.CategoryServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -19,6 +21,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* @Author fz
Expand Down Expand Up @@ -51,6 +54,10 @@ public String index() {
public Object list(@RequestParam(required = false) String title) {
Map map = new HashMap();
map.put("title", title);
ShiroUser shiroUser = ShiroKit.getUser();
if (Objects.nonNull(shiroUser)){
map.put("userId", shiroUser.getId());
}
List<Map<String, Object>> mapList = categoryService.getCatogry(map);
return super.warpObject(new BaseControllerWrapper(mapList) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import cn.stylefeng.roses.core.base.controller.BaseController;
import com.jsnjfz.manage.core.common.node.MenuNode;
import com.jsnjfz.manage.core.shiro.ShiroKit;
import com.jsnjfz.manage.core.shiro.ShiroUser;
import com.jsnjfz.manage.modular.system.model.Category;
import com.jsnjfz.manage.modular.system.service.IOperationLogService;
import com.jsnjfz.manage.modular.system.service.impl.CategoryServiceImpl;
Expand All @@ -27,6 +29,8 @@

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;


/**
Expand All @@ -45,9 +49,14 @@ public class IndexController extends BaseController {
*/
@RequestMapping("/")
public String index(Model model) {
List<MenuNode> menus = categoryService.getCatogryNode(new HashMap<>());
ShiroUser shiroUser = ShiroKit.getUser();
Map<String, Object> params = new HashMap<>();
if (Objects.nonNull(shiroUser)){
params.put("userId", shiroUser.getId());
}
List<MenuNode> menus = categoryService.getCatogryNode(params);
List<MenuNode> titles = MenuNode.buildTitle(menus);
List<Category> categorySiteList = categoryService.getCatogrySite(null);
List<Category> categorySiteList = categoryService.getCatogrySite(params);
model.addAttribute("categorySiteList", categorySiteList);
model.addAttribute("titles", titles);
System.out.println(titles);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jsnjfz.manage.modular.system.dao;

import com.jsnjfz.manage.modular.system.model.UserCategoryRelation;

/**
* @author Administrator
* @description 针对表【user_category_relation】的数据库操作Mapper
* @createDate 2024-07-02 16:52:21
* @Entity com.jsnjfz.manage.modular.system.model.UserCategoryRelation
*/
public interface UserCategoryRelationMapper extends BaseDao<UserCategoryRelation> {

}




Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@
<select id="getCatogry" resultType="map" parameterType="map">
select
id,title,sort,icon,create_time createTime,parent_id parentId,levels
from category
from category left join user_category_relation ur on c.id = ur.category_id
where 1=1
<if test="userId != null and userId != ''">
and ur.user_id = #{userId}
</if>
<if test="title != null and title != ''">
and title like CONCAT('%',#{title},'%')
</if>
</select>

<select id="getList" resultType="com.jsnjfz.manage.modular.system.model.Category" parameterType="map">
select
id,title,sort,icon,create_time createTime,parent_id parentId,levels
from category
order by sort
c.id,c.title,c.sort,c.icon,c.create_time createTime,c.parent_id parentId,c.levels
from category c left join user_category_relation ur on c.id = ur.category_id
where 1=1
<if test="userId != null and userId != ''">
and ur.user_id = #{userId}
</if>
order by c.sort
</select>

<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
Expand Down Expand Up @@ -76,10 +83,23 @@
</select>

<select id="getCatogryNode" resultType="com.jsnjfz.manage.core.common.node.MenuNode" parameterType="map">
select
id,title name,sort num,icon,create_time createTime,parent_id parentId,levels,1 ismenu
from category
order by sort
SELECT
c.id,
c.title NAME,
c.sort num,
c.icon,
c.create_time createTime,
c.parent_id parentId,
c.levels,
1 ismenu
FROM
category c LEFT JOIN user_category_relation ur on c.id = ur.category_id
where 1=1
<if test="userId != null and userId != ''">
and ur.user_id = #{userId}
</if>
ORDER BY
sort
</select>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
<select id="getList" resultType="com.jsnjfz.manage.modular.system.model.Site" parameterType="map">
select s.*,c.title categoryTitle
from site s left join category c on s.category_id = c.id
LEFT JOIN user_category_relation ur on c.id = ur.category_id
where 1=1
<if test="userId != null and userId != ''">
and ur.user_id = #{userId}
</if>
<if test="title != null and title != ''">
and s.title like CONCAT('%',#{title},'%')
</if>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jsnjfz.manage.modular.system.dao.UserCategoryRelationMapper">

</mapper>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.jsnjfz.manage.modular.system.model;

import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.annotations.TableId;
import java.io.Serializable;
import java.util.Date;

import lombok.Data;

/**
*
* @TableName user_category_relation
*/
@TableName(value ="user_category_relation")
@Data
public class UserCategoryRelation implements Serializable {
/**
* 主键
*/
@TableId
private Integer id;

/**
* 用户id
*/
private Integer userId;

/**
* 网站id
*/
private Integer categoryId;

/**
* 创建时间
*/
private Date createTime;

/**
* 更新时间
*/
private Date updateTime;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.jsnjfz.manage.modular.system.service;

import com.jsnjfz.manage.modular.system.model.UserCategoryRelation;
import com.baomidou.mybatisplus.service.IService;

/**
* @author Administrator
* @description 针对表【user_category_relation】的数据库操作Service
* @createDate 2024-07-02 16:52:21
*/
public interface UserCategoryRelationService extends IService<UserCategoryRelation> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

/**
* @Author jsnjfz
Expand Down Expand Up @@ -48,12 +45,12 @@ public List<ZTreeNode> tree() {


public List<Category> getCatogrySite(Map<String, Object> map) {
List<Category> categoryList = categoryMapper.getList(null);
List<Site> siteList = siteMapper.getList(null);
List<Category> categoryList = categoryMapper.getList(map);
List<Site> siteList = siteMapper.getList(map);
for (Category category:categoryList) {
List<Site> sites = new ArrayList<>();
for (Site site:siteList){
if (site.getCategoryId() == category.getId()){
if (Objects.equals(site.getCategoryId(), category.getId())){
sites.add(site);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.jsnjfz.manage.modular.system.service.impl;

import com.jsnjfz.manage.modular.system.service.BaseService;
import com.jsnjfz.manage.modular.system.model.UserCategoryRelation;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【user_category_relation】的数据库操作Service实现
* @createDate 2024-07-02 16:52:21
*/
@Service
public class UserCategoryRelationServiceImpl extends BaseService<UserCategoryRelation>{

}