作者 朱兆平

用户登录后菜单获取优化

... ... @@ -2,10 +2,12 @@
web:
upload-path: upload/
server:
port: 8002
port: 8066
servlet:
context-path: ${SERVER_CONTEXTPATH:}
spring:
devtools:
add-properties: false
profiles:
active: dev
mvc:
... ... @@ -17,7 +19,7 @@ spring:
static-locations: classpath:/META-INF/resources/,classpath:/static,classpath:/resources/,file:${web.upload-path}
application:
name: hqpt-user-center
name: cloud-user-center
redis:
host: 192.168.1.53
port: 6379
... ... @@ -50,10 +52,10 @@ spring:
#username=CGOETL
#password=1q2w3e4r
#spring datasource mysql,注意编码配置,缺少数据库编码配置容易引起中文入库乱码
url: jdbc:mysql://118.31.66.166:3306/HQPT_USER?useUnicode=true&characterEncoding=utf8
url: jdbc:mysql://118.31.66.166:3306/statistics?useUnicode=true&characterEncoding=utf8
username: 110
password: QAHqCJf2kFYCLirM
driver-class-name: com.mysql.jdbc.Driver
driver-class-name: com.mysql.cj.jdbc.Driver
max-idle: 10
max-wait: 10000
min-idle: 5
... ... @@ -85,16 +87,29 @@ eureka:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
hostname: ${spring.cloud.client.ip-address}
lease-renewal-interval-in-seconds: 15
lease-expiration-duration-in-seconds: 45
health-check-url-path: /actuator/health
client:
#eureka注册中心服务器地址
service-url:
defaultZone: http://192.168.1.53:12345/eureka/
registry-fetch-interval-seconds: 30
lease-renewal-interval-in-seconds: 15
lease-expiration-duration-in-seconds: 45
management:
endpoints:
enabled-by-default: true
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
shutdown:
enabled: true
mybatis:
mapper-locations: classpath:mapping/*.xml
type-aliases-package: com.tianbo.warehouse.model
... ... @@ -125,3 +140,7 @@ logging:
#Java Web Token 时效时间,单位秒
jwt:
max-alive: 30000
info:
version: 2.0
description: "具有公司及部门管理级别的用户管理中心"
... ...
FROM java:8u111
VOLUME /tmp
ENV PINPOINT_VERSION="2.3.1"
ENV AGENT_ID="usercenter-master1.0"
ENV APP_NAME="usercenter-master"
ENV JAVA_OPTS="-javaagent:/pinpoint-agent/pinpoint-bootstrap-${PINPOINT_VERSION}.jar -Dpinpoint.agentId=${AGENT_ID} -Dpinpoint.applicationName=${APP_NAME} -Dspring.profiles.active=${SPRING_PROFILES}"
ADD *.jar app.jar
EXPOSE 8066
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo "Asia/Shanghai" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
#ENTRYPOINT ["java","$JAVA_OPTS","-jar","/app.jar"]
ENTRYPOINT java $JAVA_OPTS -jar /app.jar
# Ubuntu 时区
... ...
... ... @@ -289,6 +289,22 @@
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions> <execution>
<id>gen-webadmin</id>
<phase>package</phase>
<configuration>
<tasks>
<copy todir="docker" file="target/${project.artifactId}-${project.version}.${project.packaging}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
... ...
... ... @@ -94,4 +94,11 @@ public class PermssionController {
}
return resultJson;
}
@GetMapping("/userMenu")
public ResultJson<List<PERMISSION>> userMenu(
@RequestParam(value = "userId", required = true) Integer userId){
return new ResultJson<List<PERMISSION>>("200","success",permissionService.getUserMenuTreeByUserId(userId));
}
}
... ...
... ... @@ -25,7 +25,11 @@ public interface PERMISSIONMapper {
List<PERMISSION> findByUserId(Integer userId);
List<PERMISSION> getUserMenuTreeByUserId(Integer userId);
List<PERMISSION> getChildMenu(Integer parentId);
List<String> findRoleListByUrl(String permissionUrl);
List<PERMISSION> getRolePermisson(Integer roleId);
}
\ No newline at end of file
}
... ...
package com.tianbo.warehouse.model;
import lombok.Data;
import java.util.List;
@Data
public class PERMISSION {
private Integer permissionId;
... ... @@ -120,4 +123,4 @@ public class PERMISSION {
public void setChildren(List<PERMISSION> children) {
this.children = children;
}
}
\ No newline at end of file
}
... ...
... ... @@ -23,4 +23,11 @@ public interface PermissionService {
int updateByPrimaryKeySelective(PERMISSION permission);
int deleteByPrimaryKey(String companyId);
/**
* 用户菜单树形
* @param userId
* @return
*/
List<PERMISSION> getUserMenuTreeByUserId(Integer userId);
}
... ...
... ... @@ -10,12 +10,13 @@ import com.tianbo.warehouse.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
@Service("PermissionService")
public class PermissionServiceImp implements PermissionService{
@Autowired
@Resource
PERMISSIONMapper permissionMapper;
@Override
... ... @@ -121,4 +122,8 @@ public class PermissionServiceImp implements PermissionService{
}
}
@Override
public List<PERMISSION> getUserMenuTreeByUserId(Integer userId) {
return permissionMapper.getUserMenuTreeByUserId(userId);
}
}
... ...
... ... @@ -15,6 +15,9 @@
<result column="iconCls" property="iconCls" jdbcType="VARCHAR" />
<result column="component" property="component" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="treeMap" type="com.tianbo.warehouse.model.PERMISSION" extends="BaseResultMap">
<collection property="children" ofType="com.tianbo.warehouse.model.PERMISSION" javaType="java.util.ArrayList" column="permission_id" select="getChildMenu"></collection>
</resultMap>
<sql id="Base_Column_List" >
permission_id, name, permission_order, description, ismenu,hidden,parent_id,
path, url, method, iconCls, component
... ... @@ -112,6 +115,53 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order
)
) ORDER BY permission_order
</select>
<select id="getUserMenuTreeByUserId" parameterType="java.lang.Integer" resultMap="treeMap">
SELECT
P.*
FROM
permission P
WHERE
parent_id = 0
AND
ismenu = 1
AND
P.permission_id IN (
SELECT
RP.permission_id
FROM
role_permission RP
WHERE
RP.role_id IN (
SELECT
R.role_id
FROM
role R
WHERE
R.role_id IN (
SELECT
UR.role_id
FROM
user_role UR
WHERE
UR.user_id = #{userId,jdbcType=INTEGER}
)
)
)
ORDER BY
permission_order
</select>
<select id="getChildMenu" parameterType="java.lang.Integer" resultMap="BaseResultMap">
SELECT
*
FROM
permission
WHERE
ismenu = 1
AND
parent_id = #{parentId,jdbcType=INTEGER}
ORDER BY
permission_order
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from permission
where permission_id = #{permissionId,jdbcType=INTEGER}
... ...