This commit is contained in:
wuchunlei
2025-12-10 15:32:48 +08:00
commit aa5fad5c0b
41 changed files with 2222 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.zmzm.financial;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FinancialApplication {
public static void main(String[] args) {
SpringApplication.run(FinancialApplication.class, args);
}
}

View File

@@ -0,0 +1,67 @@
package com.zmzm.financial.common.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zmzm.financial.common.entity.User;
import com.zmzm.financial.common.entity.UserToken;
import com.zmzm.financial.common.service.IUserService;
import com.zmzm.financial.common.service.IUserTokenService;
import com.zmzm.financial.util.MD5Utils;
import com.zmzm.financial.util.R;
import com.zmzm.financial.util.ShiroUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@Slf4j
@RestController("auth")
@RequestMapping("auth")
public class AuthController {
@Autowired
private IUserService userService;
@Autowired
private IUserTokenService userTokenService;
//登录
@RequestMapping("/login")
public R login(@RequestBody User user){
User userEntity = userService.getOne(new LambdaQueryWrapper<User>()
.eq(User::getAccount, user.getAccount()));
if(userEntity == null){
return R.error(500,"账号不存在");
}else {
if (MD5Utils.getSaltverifyMD5(user.getPassword(),userEntity.getPassword())){
UserToken userToken = userTokenService.createToken(userEntity.getId());
return R.ok("登录成功").put("userToken",userToken);
}else {
return R.error(500,"密码不正确,请重试");
}
}
}
//注册
@RequestMapping("/register")
public R register(@RequestBody User user){
long count = userService.count(new LambdaQueryWrapper<User>().eq(User::getAccount, user.getAccount()));
if(count>0){
return R.error(500,"账号已注册");
}
String saltMD5 = MD5Utils.getSaltMD5(user.getPassword());
user.setPassword(saltMD5);
userService.save(user);
return R.ok();
}
//退出
@RequestMapping("/logout")
public R logout(){
UserToken userToken = userTokenService.getById(ShiroUtils.getUserId());
userToken.setExpireTime(new Date());
userTokenService.updateById(userToken);
return R.ok();
}
}

View File

@@ -0,0 +1,34 @@
package com.zmzm.financial.common.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import com.zmzm.financial.common.entity.Customer;
import com.zmzm.financial.common.entity.WumenUser;
import com.zmzm.financial.common.service.CustomerService;
import com.zmzm.financial.common.service.WumenUserService;
import com.zmzm.financial.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController("commonUser")
@RequestMapping("common/user")
public class UserController {
@Autowired
private WumenUserService wumenUserService;
@Autowired
private CustomerService customerService;
//获取我的湖分列表
@RequestMapping("/getUser")
public R getUserContribution(){
WumenUser wumenUser = wumenUserService.getById("12301");
Customer customer = customerService.getOne(new LambdaQueryWrapper<Customer>()
.eq(Customer::getCellPhone,"15674886255"));
return R.ok().put("wumenUser",wumenUser).put("customer",customer);
}
}

View File

@@ -0,0 +1,18 @@
package com.zmzm.financial.common.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 用户token 前端控制器
* </p>
*
* @author baomidou
* @since 2025-12-10
*/
@RestController
@RequestMapping("/common/userToken")
public class UserTokenController {
}

View File

@@ -0,0 +1,11 @@
package com.zmzm.financial.common.dao;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import com.zmzm.financial.common.entity.Customer;
@Mapper
@DS("yljk")
public interface CustomerDao extends MPJBaseMapper<Customer> {
}

View File

@@ -0,0 +1,18 @@
package com.zmzm.financial.common.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zmzm.financial.common.entity.User;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author baomidou
* @since 2025-12-10
*/
@Mapper
public interface UserMapper extends BaseMapper<User> {
}

View File

@@ -0,0 +1,18 @@
package com.zmzm.financial.common.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zmzm.financial.common.entity.UserToken;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* 用户token Mapper 接口
* </p>
*
* @author baomidou
* @since 2025-12-10
*/
@Mapper
public interface UserTokenMapper extends BaseMapper<UserToken> {
}

View File

@@ -0,0 +1,11 @@
package com.zmzm.financial.common.dao;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import com.zmzm.financial.common.entity.WumenUser;
@Mapper
@DS("wumen")
public interface WumenUserDao extends MPJBaseMapper<WumenUser> {
}

View File

@@ -0,0 +1,131 @@
package com.zmzm.financial.common.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@TableName("t_customer")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@TableId("oid")
private String oid;
@TableField("description")
private String description = "";
// 客户编号
@TableField("customerID")
private String customerID = "";
// 创建日期
@TableField("createDate")
private Date createDate = new Date();
// 唯一码
@TableField("uniqueKey")
private String uniqueKey = "";
// 邀请码
@TableField("inviteCode")
private String inviteCode = "";
// 推荐人
@TableField("commendCode")
private String commendCode = "";
// 客户类型健康人群H 肿瘤患者C 医生D
@TableField("customerType")
private String customerType = "";
// 昵称
@TableField("nickName")
private String nickName = "";
// 真实姓名
@TableField("nameCN")
private String nameCN = "";
// 电话
@TableField("cellPhone")
private String cellPhone = "";
// 头像
@TableField("icons")
private String icons = "";
// 登录密码
@TableField("loginPwd")
private String loginPwd = "";
// 灵兰币
@TableField("point")
private int point = 0;
// 总灵兰币
@TableField("totalPoint")
private int totalPoint = 0;
// 积分
@TableField("pointByJF")
private int pointByJF = 0;
// 总积分
@TableField("totalPointByJF")
private int totalPointByJF = 0;
// 省oid
@TableField("provinceOid")
private String provinceOid = "";
// 市oid
@TableField("cityOid")
private String cityOid = "";
// 设备类型苹果i 安卓a
@TableField("deviceType")
private String deviceType = "";
// 推送状态不推送0 推送1
@TableField("pushStatus")
private String pushStatus = "1";
// 推送标识
@TableField("pushCID")
private String pushCID = "";
// 付费状态未付费0 付费1 VIP2
@TableField("payStatus")
private String payStatus = "0";
// 付费日期
@TableField("payDate")
private Date payDate;
// 付费有效日期
@TableField("payValidDate")
private Date payValidDate;
// 登录中是1 否0
@TableField("isLogin")
private String isLogin = "1";
// 最后登录时间
@TableField("loginDateTime")
private Date loginDateTime;
// 当天已登录是1 否0
@TableField("logined")
private String logined = "1";
// 设备版本
@TableField("deviceVersion")
private String deviceVersion = "";
// 推荐日期
@TableField("commendDate")
private Date commendDate;
// 推荐批次号
@TableField("commendBatchNo")
private String commendBatchNo = "";
// 推荐人数差
@TableField("subCommends")
private int subCommends = 9;
// 超级VIP
@TableField("superVIP")
private String superVIP = "0";
// 学生标志
@TableField("studentFlg")
private String studentFlg = "0";
// 学生证截止日期
@TableField("endDateByStudent")
private Date endDateByStudent = null;
// 公司标志
@TableField("companyFlg")
private String companyFlg = "0";
// 公司
@TableField("companyOid")
private String companyOid = "";
//
@TableField("luckFlg")
private String luckFlg = "";
// 邀请人数
@TableField("inviteNum")
private int inviteNum = 0;
}

View File

@@ -0,0 +1,62 @@
package com.zmzm.financial.common.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* <p>
*
* </p>
*
* @author baomidou
* @since 2025-12-10
*/
@Getter
@Setter
@ToString
public class User implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* 用户名
*/
private String name;
/**
* 账户
*/
private String account;
/**
* 密码
*/
private String password;
/**
* 0管理员1财务
*/
private Byte role;
/**
* 最后登录时间
*/
private LocalDateTime lastTime;
/**
* 状态0初始1删除
*/
private Byte state;
}

View File

@@ -0,0 +1,35 @@
package com.zmzm.financial.common.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
* 用户token
* </p>
*
* @author baomidou
* @since 2025-12-10
*/
@Getter
@Setter
@ToString
@TableName("user_token")
public class UserToken implements Serializable {
private static final long serialVersionUID = 1L;
@TableId("user_id")
private Integer userId;
private Date expireTime;
private String token;
private Date updateTime;
}

View File

@@ -0,0 +1,140 @@
package com.zmzm.financial.common.entity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
@Data
@TableName("user")
public class WumenUser implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
@TableId
private Integer id;
/**
* 姓名
*/
private String name;
/**
* 证件照
*/
private String photo;
/**
* 年龄
*/
private Integer age;
/**
* 性别
*/
private Integer sex;
/**
* 头像
*/
private String avatar;
/**
* 昵称
*/
private String nickname;
/**
* 电话
*/
private String tel;
/**
* 邮箱
*/
private String email;
/**
* 密码
*/
private String password;
/**
* 0-普通 1-vip //0-普通 1超级vip 2医学vip 3国学vip
*/
private String vip;
/**
* vip 有效期
*/
private Date vipStartTime;
/**
* vip 有效期
*/
private Date vipValidtime;
/**
* 花生币
*/
private BigDecimal peanutCoin;
/**
* 积分
*/
private BigDecimal jf;
/**
* 邀请码
*/
private String inviteCode;
/**
* 阅读时间
*/
private Date readTime;
/**
* 最后登录时间
*/
private Date lastLoginTime;
/**
* 一路健康oid
*/
private String yljkOid;
/**
* 是否有脉穴的查看权限
*/
private Integer pointPower;
/**
* 是否有时辰取穴的权限
*/
private Integer tgdzPower;
/**
* 五运六气权限
*/
private Integer wylqPower;
/**
* 吴门验方权限
*/
private Integer prescriptAPower;
/**
* 肿瘤古方权限
*/
private Integer prescriptBPower;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)//创建注解
private Date createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)//更新注解
private Date updateTime;
/**
* 删除标记
*/
@TableLogic
private Integer delFlag;
private String migrationCode;
private String remark;
}

View File

@@ -0,0 +1,5 @@
<?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.zmzm.financial.common.dao.UserTokenMapper">
</mapper>

View File

@@ -0,0 +1,7 @@
package com.zmzm.financial.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zmzm.financial.common.entity.Customer;
public interface CustomerService extends IService<Customer> {
}

View File

@@ -0,0 +1,16 @@
package com.zmzm.financial.common.service;
import com.zmzm.financial.common.entity.User;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 服务类
* </p>
*
* @author baomidou
* @since 2025-12-10
*/
public interface IUserService extends IService<User> {
}

View File

@@ -0,0 +1,18 @@
package com.zmzm.financial.common.service;
import com.zmzm.financial.common.entity.UserToken;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 用户token 服务类
* </p>
*
* @author baomidou
* @since 2025-12-10
*/
public interface IUserTokenService extends IService<UserToken> {
UserToken createToken(int userId);
}

View File

@@ -0,0 +1,7 @@
package com.zmzm.financial.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zmzm.financial.common.entity.WumenUser;
public interface WumenUserService extends IService<WumenUser> {
}

View File

@@ -0,0 +1,13 @@
package com.zmzm.financial.common.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import com.zmzm.financial.common.dao.CustomerDao;
import com.zmzm.financial.common.entity.Customer;
import com.zmzm.financial.common.service.CustomerService;
import org.springframework.stereotype.Service;
@Slf4j
@Service("commonCustomerService")
public class CustomerServiceImpl extends ServiceImpl<CustomerDao, Customer> implements CustomerService {
}

View File

@@ -0,0 +1,20 @@
package com.zmzm.financial.common.service.impl;
import com.zmzm.financial.common.entity.User;
import com.zmzm.financial.common.dao.UserMapper;
import com.zmzm.financial.common.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author baomidou
* @since 2025-12-10
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
}

View File

@@ -0,0 +1,40 @@
package com.zmzm.financial.common.service.impl;
import com.zmzm.financial.common.entity.UserToken;
import com.zmzm.financial.common.dao.UserTokenMapper;
import com.zmzm.financial.common.service.IUserTokenService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zmzm.financial.util.TokenGenerator;
import org.springframework.stereotype.Service;
import java.util.Date;
/**
* <p>
* 用户token 服务实现类
* </p>
*
* @author baomidou
* @since 2025-12-10
*/
@Service
public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken> implements IUserTokenService {
@Override
public UserToken createToken(int userId) {
String token = TokenGenerator.generateValue();
Date now = new Date();
Date expireTime = new Date(now.getTime() + 3600 * 3 * 1000);
//判断是否生成过token
UserToken userToken = this.getById(userId);
if (userToken == null) {
userToken = new UserToken();
userToken.setUserId(userId);
}
userToken.setExpireTime(expireTime);
userToken.setToken(token);
userToken.setUpdateTime(now);
this.saveOrUpdate(userToken);
return userToken;
}
}

View File

@@ -0,0 +1,13 @@
package com.zmzm.financial.common.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import com.zmzm.financial.common.dao.WumenUserDao;
import com.zmzm.financial.common.entity.WumenUser;
import com.zmzm.financial.common.service.WumenUserService;
import org.springframework.stereotype.Service;
@Slf4j
@Service("commonWumenUserService")
public class WumenUserServiceImpl extends ServiceImpl<WumenUserDao, WumenUser> implements WumenUserService {
}

View File

@@ -0,0 +1,18 @@
package com.zmzm.financial.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.maxAge(3600);
}
}

View File

@@ -0,0 +1,63 @@
package com.zmzm.financial.config;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zmzm.financial.common.entity.User;
import com.zmzm.financial.common.entity.UserToken;
import com.zmzm.financial.common.service.IUserService;
import com.zmzm.financial.common.service.IUserTokenService;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
public class CustomRealm extends AuthorizingRealm {
@Autowired
private IUserService userService;
@Autowired
private IUserTokenService userTokenService;
@Override
public boolean supports(AuthenticationToken token) {
return token instanceof OAuth2Token;
}
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
String account = (String) principals.getPrimaryPrincipal();
User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getAccount, account));
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
// info.addRoles(user.getRole());
return info;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
throws AuthenticationException {
String accessToken = token.getPrincipal().toString();
UserToken userToken = userTokenService.getOne(new LambdaQueryWrapper<UserToken>()
.eq(UserToken::getToken, accessToken));
//token失效
if(userToken == null || userToken.getExpireTime().getTime() < System.currentTimeMillis()){
throw new IncorrectCredentialsException("token失效请重新登录");
}
User user = userService.getById(userToken.getUserId());
if (user == null) throw new UnknownAccountException();
Long timeout = (userToken.getExpireTime().getTime() - System.currentTimeMillis())/(1000 * 60 * 60);
if (timeout <= 1){
// token 续期
Date now = new Date();
Date expireTime = new Date(now.getTime() + (3600 * 3 * 1000) );
userToken.setExpireTime(expireTime);
userTokenService.updateById(userToken);
}
return new SimpleAuthenticationInfo(user, token.getCredentials(), getName());
}
}

View File

@@ -0,0 +1,19 @@
package com.zmzm.financial.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 添加分页插件
interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return interceptor;
}
}

View File

@@ -0,0 +1,95 @@
package com.zmzm.financial.config;
import com.google.gson.Gson;
import com.zmzm.financial.util.HttpContextUtils;
import com.zmzm.financial.util.R;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
import org.springframework.web.bind.annotation.RequestMethod;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* oauth2过滤器
*
* @author Mark sunlightcs@gmail.com
*/
public class OAuth2Filter extends AuthenticatingFilter {
@Override
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {
//获取请求token
String token = getRequestToken((HttpServletRequest) request);
if(StringUtils.isBlank(token)){
return null;
}
return new OAuth2Token(token);
}
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
if(((HttpServletRequest) request).getMethod().equals(RequestMethod.OPTIONS.name())){
return true;
}
return false;
}
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
//获取请求token如果token不存在直接返回401
String token = getRequestToken((HttpServletRequest) request);
if(StringUtils.isBlank(token)){
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
String json = new Gson().toJson(R.error(401, "invalid token"));
httpResponse.getWriter().print(json);
return false;
}
return executeLogin(request, response);
}
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) {
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setContentType("application/json;charset=utf-8");
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
try {
//处理登录失败的异常
Throwable throwable = e.getCause() == null ? e : e.getCause();
R r = R.error(401, throwable.getMessage());
String json = new Gson().toJson(r);
httpResponse.getWriter().print(json);
} catch (IOException e1) {
}
return false;
}
/**
* 获取请求的token
*/
private String getRequestToken(HttpServletRequest httpRequest){
//从header中获取token
String token = httpRequest.getHeader("token");
//如果header中不存在token则从参数中获取token
if(StringUtils.isBlank(token)){
token = httpRequest.getParameter("token");
}
return token;
}
}

View File

@@ -0,0 +1,29 @@
package com.zmzm.financial.config;
import org.apache.shiro.authc.AuthenticationToken;
/**
* token
*
* @author Mark sunlightcs@gmail.com
*/
public class OAuth2Token implements AuthenticationToken {
private String token;
public OAuth2Token(String token){
this.token = token;
}
@Override
public String getPrincipal() {
return token;
}
@Override
public Object getCredentials() {
return token;
}
}

View File

@@ -0,0 +1,51 @@
package com.zmzm.financial.config;
import jakarta.servlet.Filter;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@Configuration
public class ShiroConfig {
@Bean
public Realm realm() {
CustomRealm customRealm = new CustomRealm();
customRealm.setAuthenticationTokenClass(OAuth2Token.class);
return customRealm;
}
@Bean
public DefaultWebSecurityManager securityManager(Realm realm) {
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
securityManager.setRealm(realm);
securityManager.setRememberMeManager(null);
return securityManager;
}
@Bean
public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
shiroFilter.setSecurityManager(securityManager);
//oauth过滤
Map<String, Filter> filters = new HashMap<>();
filters.put("oauth2", new OAuth2Filter());
shiroFilter.setFilters(filters);
Map<String, String> filterMap = new LinkedHashMap<>();
filterMap.put("/auth/login", "anon");
filterMap.put("/auth/register", "anon");
filterMap.put("/**", "oauth2");
shiroFilter.setFilterChainDefinitionMap(filterMap);
return shiroFilter;
}
}

View File

@@ -0,0 +1,48 @@
package com.zmzm.financial.util;
import com.baomidou.mybatisplus.generator.*;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.nio.file.Paths;
import java.sql.Types;
public class CodeGenerator {
public static void main(String[] args) {
FastAutoGenerator.create(
"jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/finance?rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai",
"nuttyreading",
"Wu751019!")
.globalConfig(builder -> {
builder.outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java"); // 指定输出目录
})
.dataSourceConfig(builder ->
builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
int typeCode = metaInfo.getJdbcType().TYPE_CODE;
if (typeCode == Types.SMALLINT) {
// 自定义类型转换
return DbColumnType.INTEGER;
}
return typeRegistry.getColumnType(metaInfo);
})
)
.packageConfig(builder ->
builder.parent("com.zmzm.financial") // 设置父包名
.moduleName("common") // 设置父包模块名
.entity("entity")
.mapper("dao")
.service("service")
.serviceImpl("service.impl")
)
.strategyConfig(builder ->
builder.addInclude("user_token") // 设置需要生成的表名
.addTablePrefix("t_", "c_") // 设置过滤表前缀
.entityBuilder()
.enableLombok()
.controllerBuilder()
.enableRestStyle()
)
.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板默认的是Velocity引擎模板
.execute();
}
}

View File

@@ -0,0 +1,24 @@
package com.zmzm.financial.util;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import jakarta.servlet.http.HttpServletRequest;
public class HttpContextUtils {
public static HttpServletRequest getHttpServletRequest() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}
public static String getDomain(){
HttpServletRequest request = getHttpServletRequest();
StringBuffer url = request.getRequestURL();
return url.delete(url.length() - request.getRequestURI().length(), url.length()).toString();
}
public static String getOrigin(){
HttpServletRequest request = getHttpServletRequest();
return request.getHeader("Origin");
}
}

View File

@@ -0,0 +1,256 @@
package com.zmzm.financial.util;
import org.apache.shiro.codec.Hex;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;
/**
* @author hh@163.com:
* @version 创建时间2018-3-20 下午2:40:13
* @introduction
*/
public class MD5Utils {
/**
* 普通MD5加密 01
* <p>
*
* @Title : getStrMD5
* </p>
* <p>
* @Description : TODO
* </p>
* <p>
* @Author : HuaZai
* </p>
* <p>
* @Date : 2017年12月26日 下午2:49:44
* </p>
*/
public static String getStrMD5(String inStr) {
// 获取MD5实例
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
System.out.println(e.toString());
return "";
}
// 将加密字符串转换为字符数组
char[] charArray = inStr.toCharArray();
byte[] byteArray = new byte[charArray.length];
// 开始加密
for (int i = 0; i < charArray.length; i++)
byteArray[i] = (byte) charArray[i];
byte[] digest = md5.digest(byteArray);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < digest.length; i++) {
int var = digest[i] & 0xff;
if (var < 16)
sb.append("0");
sb.append(Integer.toHexString(var));
}
return sb.toString();
}
/**
* 普通MD5加密 02
* <p>
*
* @Title : getStrrMD5
* </p>
* <p>
* @Description : TODO
* </p>
* <p>
* @Author : HuaZai
* </p>
* <p>
* @Date : 2017年12月27日 上午11:18:39
* </p>
*/
public static String getStrrMD5(String password) {
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
try {
byte strTemp[] = password.getBytes("UTF-8");
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(strTemp);
byte md[] = mdTemp.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 >>> 4 & 15];
str[k++] = hexDigits[byte0 & 15];
}
return new String(str);
} catch (Exception e) {
return null;
}
}
/**
* MD5双重解密
* <p>
*
* @Title : getconvertMD5
* </p>
* <p>
* @Description : TODO
* </p>
* <p>
* @Author : HuaZai
* </p>
* <p>
* @Date : 2017年12月26日 下午3:34:17
* </p>
*/
public static String getconvertMD5(String inStr) {
char[] charArray = inStr.toCharArray();
for (int i = 0; i < charArray.length; i++) {
charArray[i] = (char) (charArray[i] ^ 't');
}
String str = String.valueOf(charArray);
return str;
}
/**
* 使用Apache的Hex类实现Hex(16进制字符串和)和字节数组的互转
* <p>
*
* @Title : md5Hex
* </p>
* <p>
* @Description : TODO
* </p>
* <p>
* @Author : HuaZai
* </p>
* <p>
* @Date : 2017年12月27日 上午11:28:25
* </p>
*/
@SuppressWarnings("unused")
private static String md5Hex(String str) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(str.getBytes());
return new String(new Hex().encode(digest));
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.toString());
return "";
}
}
/**
* 加盐MD5加密
* <p>
*
* @Title : getSaltMD5
* </p>
* <p>
* @Description : TODO
* </p>
* <p>
* @Author : HuaZai
* </p>
* <p>
* @Date : 2017年12月27日 上午11:21:00
* </p>
*/
public static String getSaltMD5(String password) {
// 生成一个16位的随机数
Random random = new Random();
StringBuilder sBuilder = new StringBuilder(16);
sBuilder.append(random.nextInt(99999999)).append(random.nextInt(99999999));
int len = sBuilder.length();
if (len < 16) {
for (int i = 0; i < 16 - len; i++) {
sBuilder.append("0");
}
}
// 生成最终的加密盐
String Salt = sBuilder.toString();
password = md5Hex(password + Salt);
char[] cs = new char[48];
for (int i = 0; i < 48; i += 3) {
cs[i] = password.charAt(i / 3 * 2);
char c = Salt.charAt(i / 3);
cs[i + 1] = c;
cs[i + 2] = password.charAt(i / 3 * 2 + 1);
}
return String.valueOf(cs);
}
/**
* 验证加盐后是否和原文一致
* <p>
*
* @Title : verifyMD5
* </p>
* <p>
* @Description : TODO
* </p>
* <p>
* @Author : HuaZai
* </p>
* <p>
* @Date : 2017年12月27日 下午2:22:22
* </p>
*/
public static boolean getSaltverifyMD5(String password, String md5str) {
char[] cs1 = new char[32];
char[] cs2 = new char[16];
for (int i = 0; i < 48; i += 3) {
cs1[i / 3 * 2] = md5str.charAt(i);
cs1[i / 3 * 2 + 1] = md5str.charAt(i + 2);
cs2[i / 3] = md5str.charAt(i + 1);
}
String Salt = new String(cs2);
return md5Hex(password + Salt).equals(String.valueOf(cs1));
}
public static void main(String[] args) {
MD5Utils md = new MD5Utils();
String strMD5 = new String("696c23c1e04f330c55a635f571ee949f");
System.out.println("原始:" + strMD5);
System.out.println("东东的:" + md.getStrrMD5(strMD5));
System.out.println("MD5后" + md.getStrMD5(strMD5));
System.out.println("加密的:" + md.getconvertMD5(strMD5));
System.out.println("解密的:" + md.getconvertMD5(md.getconvertMD5(strMD5)));
System.out.println("\t\t=======================================");
// 原文
String plaintext = "huazai";
// plaintext = "123456";
System.out.println("原始:" + plaintext);
System.out.println("普通MD5后" + MD5Utils.getStrMD5(plaintext));
// 获取加盐后的MD5值
String ciphertext = MD5Utils.getSaltMD5(plaintext);
System.out.println("加盐后MD5" + ciphertext);
System.out.println("是否是同一字符串:" + MD5Utils.getSaltverifyMD5(plaintext, ciphertext));
/**
* 其中某次DingSai字符串的MD5值
*/
String[] tempSalt = { "810e1ee9ee5e28188658f431451a29c2d81048de6a108e8a",
"66db82d9da2e35c95416471a147d12e46925d38e1185c043",
"61a718e4c15d914504a41d95230087a51816632183732b5a" };
for (String temp : tempSalt) {
System.out.println("是否是同一字符串:" + MD5Utils.getSaltverifyMD5(plaintext, temp));
}
}
}

View File

@@ -0,0 +1,60 @@
package com.zmzm.financial.util;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;
/**
* 返回数据
*/
@Data
public class R extends HashMap<String, Object> {
private static final long serialVersionUID = 1L;
public R() {
put("code", 0);
put("msg", "success");
}
public static R error(int code, String msg) {
R r = new R();
r.put("code", code);
r.put("msg", msg);
return r;
}
public static R code(int code){
R r = new R();
r.put("code",code);
return r;
}
public static R code(int code,String msg){
R r = new R();
r.put("code",code);
r.put("msg",msg);
return r;
}
public static R ok(String msg) {
R r = new R();
r.put("msg", msg);
return r;
}
public static R ok(Map<String, Object> map) {
R r = new R();
r.putAll(map);
return r;
}
public static R ok() {
return new R();
}
public R put(String key, Object value) {
super.put(key, value);
return this;
}
}

View File

@@ -0,0 +1,45 @@
package com.zmzm.financial.util;
import com.zmzm.financial.common.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
/**
* Shiro工具类
*
* @author Mark sunlightcs@gmail.com
*/
public class ShiroUtils {
public static Session getSession() {
return SecurityUtils.getSubject().getSession();
}
public static Subject getSubject() {
return SecurityUtils.getSubject();
}
public static User getUserEntity() {
return (User)SecurityUtils.getSubject().getPrincipal();
}
public static Integer getUserId() {
return getUserEntity().getId();
}
public static void setSessionAttribute(Object key, Object value) {
getSession().setAttribute(key, value);
}
public static Object getSessionAttribute(Object key) {
return getSession().getAttribute(key);
}
public static boolean isLogin() {
return SecurityUtils.getSubject().getPrincipal() != null;
}
}

View File

@@ -0,0 +1,43 @@
package com.zmzm.financial.util;
import java.security.MessageDigest;
import java.util.UUID;
/**
* 生成token
*
* @author Mark sunlightcs@gmail.com
*/
public class TokenGenerator {
public static String generateValue() {
return generateValue(UUID.randomUUID().toString());
}
private static final char[] hexCode = "0123456789abcdef".toCharArray();
public static String toHexString(byte[] data) {
if(data == null) {
return null;
}
StringBuilder r = new StringBuilder(data.length*2);
for ( byte b : data) {
r.append(hexCode[(b >> 4) & 0xF]);
r.append(hexCode[(b & 0xF)]);
}
return r.toString();
}
public static String generateValue(String param) {
try {
MessageDigest algorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(param.getBytes());
byte[] messageDigest = algorithm.digest();
return toHexString(messageDigest);
} catch (Exception e) {
throw new RuntimeException("生成Token失败", e);
}
}
}

View File

@@ -0,0 +1,64 @@
server:
port: 9000
servlet:
context-path: /financial
spring:
servlet:
multipart:
max-file-size: 1000MB
max-request-size: 1000MB
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
validation-query: SELECT 1 FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
stat-view-servlet:
enabled: true
url-pattern: /druid/*
filter:
stat:
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: false
wall:
config:
multi-statement-allow: true
dynamic:
druid:
initial-size: 10
max-active: 100
min-idle: 10
max-wait: 60000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
primary: master #设置默认的数据源或者数据源组,默认值即为master
datasource:
master: #主数据库
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/finance?rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
username: nuttyreading
password: Wu751019!
wumen: #吴门医述数据库
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://rm-2zev4157t67trxuu3yo.mysql.rds.aliyuncs.com:3306/e_book_test?rewriteBatchedStatements=true
username: nuttyreading
password: Wu751019!
yljk: #一路健康数据库
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://goldorchid.mysql.rds.aliyuncs.com:3309/everhealth?rewriteBatchedStatements=true
username: yljkmaster
password: Wu751019!@
#mybatis
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
#原生配置
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
call-setters-on-nulls: true
jdbc-type-for-null: 'null'
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

View File

@@ -0,0 +1,13 @@
package com.zmzm.financial;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class FinancialApplicationTests {
@Test
void contextLoads() {
}
}