页面和权限规则调整

This commit is contained in:
2022-04-28 23:55:28 +08:00
parent 01ab4d2b4f
commit b1e3fabea3
133 changed files with 330 additions and 396 deletions
@@ -0,0 +1,126 @@
/**
* Copyright (C) 2018-2022
* All rights reserved, Designed By www.yixiang.co
* 注意:
* 本软件为www.yixiang.co开发研制,未经购买不得使用
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
*/
package cn.iocoder.yudao.framework.common.exception;
/**
* API 响应码
* @author hupeng
* @date 2020-04-30
*/
public enum ApiCode {
/**
* 操作成功
**/
SUCCESS(200, "操作成功"),
/**
* 非法访问
**/
UNAUTHORIZED(401, "非法访问"),
/**
* 没有权限
**/
NOT_PERMISSION(403, "没有权限"),
/**
* 你请求的资源不存在
**/
NOT_FOUND(404, "你请求的资源不存在"),
/**
* 操作失败
**/
FAIL(500, "操作失败"),
/**
* 登录失败
**/
LOGIN_EXCEPTION(4000, "登录失败"),
/**
* 系统异常
**/
SYSTEM_EXCEPTION(5000, "系统异常"),
/**
* 请求参数校验异常
**/
PARAMETER_EXCEPTION(5001, "请求参数校验异常"),
/**
* 请求参数解析异常
**/
PARAMETER_PARSE_EXCEPTION(5002, "请求参数解析异常"),
/**
* HTTP内容类型异常
**/
HTTP_MEDIA_TYPE_EXCEPTION(5003, "HTTP内容类型异常"),
/**
* 系统处理异常
**/
YSHOP_SYSTEM_EXCEPTION(5100, "系统处理异常"),
/**
* 业务处理异常
**/
BUSINESS_EXCEPTION(5101, "业务处理异常"),
/**
* 数据库处理异常
**/
DAO_EXCEPTION(5102, "数据库处理异常"),
/**
* 验证码校验异常
**/
VERIFICATION_CODE_EXCEPTION(5103, "验证码校验异常"),
/**
* 登录授权异常
**/
AUTHENTICATION_EXCEPTION(5104, "登录授权异常"),
/**
* 没有访问权限
**/
UNAUTHENTICATED_EXCEPTION(5105, "没有访问权限"),
/**
* 没有访问权限
**/
UNAUTHORIZED_EXCEPTION(5106, "没有访问权限"),
/**
* JWT Token解析异常
**/
JWTDECODE_EXCEPTION(5107, "Token解析异常"),
HTTP_REQUEST_METHOD_NOT_SUPPORTED_EXCEPTION(5108, "METHOD NOT SUPPORTED"),
/**
* 访问次数受限制
**/
BAD_LIMIT_EXCEPTION(5109, "访问次数受限制"),
;
private final int code;
private final String message;
ApiCode(final int code, final String message) {
this.code = code;
this.message = message;
}
public static ApiCode getApiCode(int code) {
ApiCode[] ecs = ApiCode.values();
for (ApiCode ec : ecs) {
if (ec.getCode() == code) {
return ec;
}
}
return SUCCESS;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
}
@@ -0,0 +1,59 @@
/**
* Copyright (C) 2018-2022
* All rights reserved, Designed By www.yixiang.co
* 注意:
* 本软件为www.yixiang.co开发研制,未经购买不得使用
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
*/
package cn.iocoder.yudao.framework.common.exception;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 自定义异常
* @author hupeng
* @date 2020-04-30
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class YshopException extends RuntimeException{
private static final long serialVersionUID = -2470461654663264392L;
private Integer errorCode;
private String message;
public YshopException() {
super();
}
public YshopException(String message) {
super(message);
this.errorCode = ApiCode.FAIL.getCode();
this.message = message;
}
public YshopException(Integer errorCode, String message) {
super(message);
this.errorCode = errorCode;
this.message = message;
}
public YshopException(ApiCode apiCode) {
super(apiCode.getMessage());
this.errorCode = apiCode.getCode();
this.message = apiCode.getMessage();
}
public YshopException(String message, Throwable cause) {
super(message, cause);
}
public YshopException(Throwable cause) {
super(cause);
}
}
@@ -3,11 +3,13 @@ package cn.iocoder.yudao.framework.mybatis.config;
import cn.iocoder.yudao.framework.mybatis.core.handler.DefaultDBFieldHandler;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.provider.DynamicDataSourceProvider;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
@@ -34,6 +36,7 @@ import java.util.Map;
lazyInitialization = "${mybatis.lazy-initialization:false}") // Mapper 懒加载,目前仅用于单元测试
})
@Configuration
@Slf4j
public class YudaoMybatisAutoConfiguration {
@Bean
@@ -55,11 +58,7 @@ public class YudaoMybatisAutoConfiguration {
MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();
Map<String, DataSource> map = dynamicDataSourceProvider.loadDataSources();
factory.setDataSource(map.get("master"));
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setMetaObjectHandler(defaultMetaObjectHandler());
factory.setPlugins(mybatisPlusInterceptor());
factory.setGlobalConfig(globalConfig);
return factory.getObject();
return getSqlSessionFactory(factory);
}
@Bean("shangcheng")
@@ -67,8 +66,19 @@ public class YudaoMybatisAutoConfiguration {
MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();
Map<String, DataSource> map = dynamicDataSourceProvider.loadDataSources();
factory.setDataSource(map.get("xiaohui"));
return factory.getObject();
return getSqlSessionFactory(factory);
}
private SqlSessionFactory getSqlSessionFactory(MybatisSqlSessionFactoryBean factory) throws Exception {
GlobalConfig globalConfig = new GlobalConfig();
GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig();
dbConfig.setIdType(IdType.AUTO);
log.error("dbConfig:{}",dbConfig);
globalConfig.setDbConfig(dbConfig);
globalConfig.setMetaObjectHandler(defaultMetaObjectHandler());
factory.setPlugins(mybatisPlusInterceptor());
factory.setGlobalConfig(globalConfig);
return factory.getObject();
}
}
@@ -0,0 +1,39 @@
package cn.iocoder.yudao.framework.mybatis.core.dataobject;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.Date;
/**
* @ClassName 公共模型
* @Author hupeng <610796224@qq.com>
* @Date 2020/6/13
**/
@Getter
@Setter
public class BaseDomain implements Serializable {
private static final long serialVersionUID = 1L;
@TableField(fill= FieldFill.INSERT)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date createTime;
@TableField(fill= FieldFill.UPDATE)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date updateTime;
@TableLogic
@JsonIgnore
@TableField(fill= FieldFill.INSERT)
private Integer isDel;
}
@@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.mybatis.core.handler;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import java.sql.Timestamp;
@@ -16,57 +17,61 @@ import java.util.Objects;
*
* @author hexiaowu
*/
@Slf4j
public class DefaultDBFieldHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof BaseDO) {
BaseDO baseDO = (BaseDO) metaObject.getOriginalObject();
// if (Objects.nonNull(metaObject) && metaObject.getOriginalObject() instanceof BaseDO) {
// BaseDO baseDO = (BaseDO) metaObject.getOriginalObject();
//
// Date current = new Date();
// // 创建时间为空,则以当前时间为插入时间
// if (Objects.isNull(baseDO.getCreateTime())) {
// baseDO.setCreateTime(current);
// }
// // 更新时间为空,则以当前时间为更新时间
// if (Objects.isNull(baseDO.getUpdateTime())) {
// baseDO.setUpdateTime(current);
// }
//
//
// }
Date current = new Date();
// 创建时间为空,则当前时间为插入时间
if (Objects.isNull(baseDO.getCreateTime())) {
baseDO.setCreateTime(current);
}
// 更新时间为空,则以当前时间为更新时间
if (Objects.isNull(baseDO.getUpdateTime())) {
baseDO.setUpdateTime(current);
}
Long userId = WebFrameworkUtils.getLoginUserId();
// 当前登录用户不为空,创建人为空,则当前登录用户为创建人
if (Objects.nonNull(userId) && Objects.isNull(baseDO.getCreator())) {
baseDO.setCreator(userId.toString());
}
// 当前登录用户不为空,更新人为空,则当前登录用户为更新人
if (Objects.nonNull(userId) && Objects.isNull(baseDO.getUpdater())) {
baseDO.setUpdater(userId.toString());
}
Timestamp time=new Timestamp(System.currentTimeMillis());
if (metaObject.hasSetter("createTime")) {
this.setFieldValByName("createTime", time, metaObject);
}
if (metaObject.hasSetter("updateTime")) {
this.setFieldValByName("updateTime", time, metaObject);
}
if (metaObject.hasSetter("createDate")) {
this.setFieldValByName("createDate", time, metaObject);
}
if (metaObject.hasSetter("updateDate")) {
this.setFieldValByName("updateDate", time, metaObject);
}
if (metaObject.hasSetter("delFlag")) {
this.setFieldValByName("delFlag", false, metaObject);
}
if (metaObject.hasSetter("isDel")) {
this.setFieldValByName("isDel", 0, metaObject);
}
if (metaObject.hasSetter("addTime")) {
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
this.setFieldValByName("addTime", Integer.valueOf(timestamp), metaObject);
}
Long userId = WebFrameworkUtils.getLoginUserId();
// 当前登录用户不为空,创建人为空,则当前登录用户为创建人
if (metaObject.hasSetter("creator")) {
this.setFieldValByName("creator", userId.toString(), metaObject);
}
if (metaObject.hasSetter("updater")) {
this.setFieldValByName("updater", userId.toString(), metaObject);
}
Timestamp time=new Timestamp(System.currentTimeMillis());
if (metaObject.hasSetter("createTime")) {
this.setFieldValByName("createTime", time, metaObject);
}
if (metaObject.hasSetter("updateTime")) {
this.setFieldValByName("updateTime", time, metaObject);
}
if (metaObject.hasSetter("createDate")) {
this.setFieldValByName("createDate", time, metaObject);
}
if (metaObject.hasSetter("updateDate")) {
this.setFieldValByName("updateDate", time, metaObject);
}
if (metaObject.hasSetter("delFlag")) {
this.setFieldValByName("delFlag", false, metaObject);
}
if (metaObject.hasSetter("isDel")) {
this.setFieldValByName("isDel", 0, metaObject);
}
if (metaObject.hasSetter("addTime")) {
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
this.setFieldValByName("addTime", Integer.valueOf(timestamp), metaObject);
}
}
@Override
@@ -132,7 +132,7 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap
.antMatchers("/common/**").permitAll()
// 忽略宝享购全部
.antMatchers("/bxgApp/**","/bxg/**").permitAll()
// .antMatchers("/bxgApp/**","/bxg/**").hasAnyRole()
// ②:每个项目的自定义规则
.and().authorizeRequests(registry -> // 下面,循环设置自定义规则
@@ -0,0 +1,26 @@
/**
* Copyright (C) 2018-2022
* All rights reserved, Designed By www.yixiang.co
* 注意:
* 本软件为www.yixiang.co开发研制,未经购买不得使用
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
*/
package cn.iocoder.yudao.framework.security.core.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @ClassName 自定义权限注解
* @Author hupeng <610796224@qq.com>
* @Date 2020/4/30
**/
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface AuthCheck {
int value() default 4;
}
@@ -4,6 +4,7 @@ import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.exception.YshopException;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateReqDTO;
@@ -215,6 +216,12 @@ public class GlobalExceptionHandler {
return CommonResult.error(ex.getCode(), ex.getMessage());
}
@ExceptionHandler(value = YshopException.class)
public CommonResult<?> yshopException(YshopException ex){
log.info("[YshopException]",ex);
return CommonResult.error(ex.getErrorCode(), ex.getMessage());
}
/**
* 处理系统异常,兜底处理所有的一切
*/