Commit 2ba62d68 by levphon

微信小程序C端账号体系

1 parent b16d7f2b
...@@ -34,11 +34,6 @@ public class User extends BaseEntity { ...@@ -34,11 +34,6 @@ public class User extends BaseEntity {
private Long linkerId; private Long linkerId;
/** /**
* 用户账户/手机号
*/
private String account;
/**
* 状态:0白名单,临时封禁(blacklist>0,值为封禁天数),永久封禁(del_flag=-1) * 状态:0白名单,临时封禁(blacklist>0,值为封禁天数),永久封禁(del_flag=-1)
*/ */
private Integer blacklist; private Integer blacklist;
......
...@@ -7,7 +7,7 @@ import javax.persistence.Column; ...@@ -7,7 +7,7 @@ import javax.persistence.Column;
import javax.persistence.Table; import javax.persistence.Table;
@Data @Data
@Table(name = "t_user_auth_rel") @Table(name = "t_cust_user_auth_rel")
public class UserAuthRel extends BaseEntity { public class UserAuthRel extends BaseEntity {
/** /**
......
...@@ -7,16 +7,10 @@ import javax.persistence.Column; ...@@ -7,16 +7,10 @@ import javax.persistence.Column;
import javax.persistence.Table; import javax.persistence.Table;
@Data @Data
@Table(name = "t_user_local_account") @Table(name = "t_cust_user_local_account")
public class UserLocalAccount extends BaseEntity { public class UserLocalAccount extends BaseEntity {
/** /**
* 用户id 为了方便,这里冗余用户id
*/
@Column(name = "user_id")
private Long userId;
/**
* 认证id * 认证id
*/ */
@Column(name = "auth_id") @Column(name = "auth_id")
......
...@@ -7,7 +7,7 @@ import javax.persistence.Column; ...@@ -7,7 +7,7 @@ import javax.persistence.Column;
import javax.persistence.Table; import javax.persistence.Table;
@Data @Data
@Table(name = "t_user_local_auth") @Table(name = "t_cust_user_local_auth")
public class UserLocalAuth extends BaseEntity { public class UserLocalAuth extends BaseEntity {
/** /**
...@@ -19,7 +19,7 @@ public class UserLocalAuth extends BaseEntity { ...@@ -19,7 +19,7 @@ public class UserLocalAuth extends BaseEntity {
/** /**
* 密码 * 密码
*/ */
@Column(name = "account") @Column(name = "password")
private String password; private String password;
} }
\ No newline at end of file \ No newline at end of file
...@@ -7,7 +7,7 @@ import javax.persistence.Column; ...@@ -7,7 +7,7 @@ import javax.persistence.Column;
import javax.persistence.Table; import javax.persistence.Table;
@Data @Data
@Table(name = "t_user_qq_account") @Table(name = "t_cust_user_qq_account")
public class UserQQAccount extends BaseEntity { public class UserQQAccount extends BaseEntity {
/** /**
......
...@@ -7,7 +7,7 @@ import javax.persistence.Column; ...@@ -7,7 +7,7 @@ import javax.persistence.Column;
import javax.persistence.Table; import javax.persistence.Table;
@Data @Data
@Table(name = "t_user_third_auth") @Table(name = "t_cust_user_third_auth")
public class UserThirdAuth extends BaseEntity { public class UserThirdAuth extends BaseEntity {
/** /**
......
...@@ -7,7 +7,7 @@ import javax.persistence.Column; ...@@ -7,7 +7,7 @@ import javax.persistence.Column;
import javax.persistence.Table; import javax.persistence.Table;
@Data @Data
@Table(name = "t_user_wechat_account") @Table(name = "t_cust_user_wechat_account")
public class UserWechatAccount extends BaseEntity { public class UserWechatAccount extends BaseEntity {
/** /**
......
package cn.com.glsx.app.modules.entity;
import com.glsx.plat.mybatis.base.BaseEntity;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Table;
import java.util.Date;
@Data
@Table(name = "t_vehicle_shared")
public class VehicleShared extends BaseEntity {
/**
* 授权人id,对应t_cust_user表id
*/
@Column(name = "accorder_id")
private Long accorderId;
/**
* 获权人id,对应t_cust_user表id
*/
@Column(name = "receiver_id")
private Long receiverId;
/**
* 授权数据id
*/
@Column(name = "content_id")
private Long contentId;
/**
* 内容类型:0车辆
*/
@Column(name = "content_type")
private Integer contentType;
/**
* 权限类型 r=只读 wr=读写
*/
@Column(name = "permit_type")
private String permitType;
/**
* 生效时间
*/
@Column(name = "effective_date")
private Date effectiveDate;
/**
* 失效时间
*/
@Column(name = "expiration_date")
private Date expirationDate;
/**
* 状态:0默认,1有效,2失效
*/
private Integer status;
}
\ No newline at end of file \ No newline at end of file
...@@ -8,6 +8,8 @@ import org.apache.ibatis.annotations.Param; ...@@ -8,6 +8,8 @@ import org.apache.ibatis.annotations.Param;
@Mapper @Mapper
public interface UserLocalAuthMapper extends CommonBaseMapper<UserLocalAuth> { public interface UserLocalAuthMapper extends CommonBaseMapper<UserLocalAuth> {
UserLocalAuth selectByAccount(@Param("account") String account);
UserLocalAuth selectByAuthId(@Param("authId") Long authId); UserLocalAuth selectByAuthId(@Param("authId") Long authId);
UserLocalAuth selectByUserId(@Param("userId") Long userId); UserLocalAuth selectByUserId(@Param("userId") Long userId);
......
...@@ -10,8 +10,6 @@ public interface UserMapper extends CommonBaseMapper<User> { ...@@ -10,8 +10,6 @@ public interface UserMapper extends CommonBaseMapper<User> {
User selectById(@Param("id") Long id); User selectById(@Param("id") Long id);
User selectByAccount(@Param("account") String account);
int saveOrUpdate(User user); int saveOrUpdate(User user);
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.app.modules.mapper;
import cn.com.glsx.app.modules.entity.VehicleShared;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface VehicleSharedMapper extends CommonBaseMapper<VehicleShared> {
}
\ No newline at end of file \ No newline at end of file
...@@ -24,7 +24,6 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -24,7 +24,6 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.Optional;
@Slf4j @Slf4j
@Service @Service
...@@ -57,7 +56,6 @@ public class LoginService { ...@@ -57,7 +56,6 @@ public class LoginService {
@Autowired @Autowired
private BCryptPasswordEncoder bCryptPasswordEncoder; private BCryptPasswordEncoder bCryptPasswordEncoder;
@Transactional(rollbackFor = Exception.class)
public AppUser localAuth(LoginByAccountBO loginBO) { public AppUser localAuth(LoginByAccountBO loginBO) {
//内部登录转成appUser返回前端 //内部登录转成appUser返回前端
if (loginBO.getLoginType() == 1) { if (loginBO.getLoginType() == 1) {
...@@ -70,8 +68,10 @@ public class LoginService { ...@@ -70,8 +68,10 @@ public class LoginService {
User user = register(simpleUser); User user = register(simpleUser);
//返给前端的用户信息
AppUser appUser = UserConverter.INSTANCE.su2au(simpleUser); AppUser appUser = UserConverter.INSTANCE.su2au(simpleUser);
appUser.setUserType(MiniUserType.NORMAL.getType()); appUser.setUserType(MiniUserType.NORMAL.getType());
return appUser;
} else if (loginBO.getLoginType() == 2) { } else if (loginBO.getLoginType() == 2) {
//验证码校验 //验证码校验
//smsService.verifyCode(loginBO.getAccount(), loginBO.getCode()); //smsService.verifyCode(loginBO.getAccount(), loginBO.getCode());
...@@ -84,36 +84,21 @@ public class LoginService { ...@@ -84,36 +84,21 @@ public class LoginService {
* *
* @param simpleUser * @param simpleUser
*/ */
@Transactional(rollbackFor = Exception.class)
public User register(SimpleUser simpleUser) { public User register(SimpleUser simpleUser) {
User user = Optional.ofNullable(userMapper.selectByAccount(simpleUser.getAccount())).orElse(new User()); UserLocalAuth localAuth = userLocalAuthMapper.selectByAccount(simpleUser.getAccount());
user.setLinkerId(simpleUser.getId());
user.setAccount(simpleUser.getAccount());
user.setBlacklist(simpleUser.getBlacklist());
userMapper.saveOrUpdate(user);
UserLocalAuth localAuth = userLocalAuthMapper.selectByUserId(user.getId());
if (localAuth == null) { if (localAuth == null) {
localAuth = new UserLocalAuth(); localAuth = new UserLocalAuth();
localAuth.setAccount(user.getAccount()); localAuth.setAccount(simpleUser.getAccount());
String encryptedPasswd = bCryptPasswordEncoder.encode(user.getAccount()); String encryptedPasswd = bCryptPasswordEncoder.encode(simpleUser.getAccount());
localAuth.setPassword(encryptedPasswd); localAuth.setPassword(encryptedPasswd);
userLocalAuthMapper.insertUseGeneratedKeys(localAuth); userLocalAuthMapper.insert(localAuth);
}
UserAuthRel userAuthRel = userAuthRelMapper.selectByAuthTypeAndAuthId(AuthType.LOCAL.getType(), localAuth.getId());
if (userAuthRel == null) {
userAuthRel = new UserAuthRel();
userAuthRel.setUserId(user.getId());
userAuthRel.setAuthId(localAuth.getId());
userAuthRel.setAuthType(AuthType.LOCAL.getType());
userAuthRelMapper.insertUseGeneratedKeys(userAuthRel);
} }
//生成本地账号 //生成本地账号
UserLocalAccount localAccount = userLocalAccountMapper.selectByAuthId(user.getId()); UserLocalAccount localAccount = userLocalAccountMapper.selectByAuthId(localAuth.getId());
if (localAccount == null) { if (localAccount == null) {
localAccount = new UserLocalAccount(); localAccount = new UserLocalAccount();
//localAccount.setUserId(user.getId());
localAccount.setAuthId(localAuth.getId()); localAccount.setAuthId(localAuth.getId());
localAccount.setUsername(simpleUser.getUsername()); localAccount.setUsername(simpleUser.getUsername());
//生成平台unionId //生成平台unionId
...@@ -128,6 +113,29 @@ public class LoginService { ...@@ -128,6 +113,29 @@ public class LoginService {
userLocalAccountMapper.updateByPrimaryKeySelective(localAccount); userLocalAccountMapper.updateByPrimaryKeySelective(localAccount);
} }
} }
//自定义用户主体
User user = null;
UserAuthRel userAuthRel = userAuthRelMapper.selectByAuthTypeAndAuthId(AuthType.LOCAL.getType(), localAuth.getId());
if (userAuthRel == null) {
user = new User();
user.setLinkerId(simpleUser.getId());
user.setBlacklist(simpleUser.getBlacklist());
userMapper.saveOrUpdate(user);
userAuthRel = new UserAuthRel();
userAuthRel.setUserId(user.getId());
userAuthRel.setAuthId(localAuth.getId());
userAuthRel.setAuthType(AuthType.LOCAL.getType());
userAuthRelMapper.insertUseGeneratedKeys(userAuthRel);
return user;
} else {
user = userMapper.selectById(userAuthRel.getUserId());
if (user == null) {
// TODO: 2022/6/30 抛出异常
}
}
return user; return user;
} }
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<select id="selectByAuthTypeAndAuthId" resultMap="BaseResultMap"> <select id="selectByAuthTypeAndAuthId" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from t_user_auth_rel from t_cust_user_auth_rel
where auth_type = #{authType} where auth_type = #{authType}
and auth_id = #{authId} and auth_id = #{authId}
and del_flag = 0 and del_flag = 0
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<select id="selectByAuthTypeAndUserId" resultMap="BaseResultMap"> <select id="selectByAuthTypeAndUserId" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from t_user_auth_rel from t_cust_user_auth_rel
where auth_type = #{authType} where auth_type = #{authType}
and user_id = #{userId} and user_id = #{userId}
and del_flag = 0 and del_flag = 0
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
<id column="id" jdbcType="INTEGER" property="id"/> <id column="id" jdbcType="INTEGER" property="id"/>
<result column="user_id" jdbcType="INTEGER" property="userId"/>
<result column="auth_id" jdbcType="INTEGER" property="authId"/> <result column="auth_id" jdbcType="INTEGER" property="authId"/>
<result column="union_id" jdbcType="VARCHAR" property="unionId"/> <result column="union_id" jdbcType="VARCHAR" property="unionId"/>
<result column="username" jdbcType="VARCHAR" property="username"/> <result column="username" jdbcType="VARCHAR" property="username"/>
...@@ -21,7 +20,7 @@ ...@@ -21,7 +20,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
id, user_id, auth_id, union_id, username, avatar, del_flag, created_date, created_by, id, auth_id, union_id, username, avatar, del_flag, created_date, created_by,
updated_date, updated_by updated_date, updated_by
</sql> </sql>
...@@ -42,9 +41,9 @@ ...@@ -42,9 +41,9 @@
tcu.blacklist tcu.blacklist
from t_cust_user_local_account tcula from t_cust_user_local_account tcula
inner join t_cust_user_auth_rel tcuar on tcula.id = tcuar.auth_id inner join t_cust_user_auth_rel tcuar on tcula.id = tcuar.auth_id
left join t_cust_user tcu on tcu.id = tcula.user_id left join t_cust_user tcu on tcu.id = tcuar.user_id
where tcula.del_flag = 0 where tcula.del_flag = 0
and tcuar.auth_type = 'local' and tcuar.auth_type = 'local'
and tcula.user_id = #{userId} limit 1 and tcuar.user_id = #{userId} limit 1
</select> </select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -31,6 +31,14 @@ ...@@ -31,6 +31,14 @@
and tcuar.auth_id = #{authId} limit 1 and tcuar.auth_id = #{authId} limit 1
</select> </select>
<select id="selectByAccount" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_cust_user_local_auth
where account = #{account}
and del_flag = 0
</select>
<select id="selectByUserId" resultMap="BaseResultMap"> <select id="selectByUserId" resultMap="BaseResultMap">
select tcula.* select tcula.*
from t_cust_user_local_auth tcula from t_cust_user_local_auth tcula
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
<result column="expire_in" jdbcType="INTEGER" property="expireIn"/> <result column="expire_in" jdbcType="INTEGER" property="expireIn"/>
<result column="try_times" jdbcType="INTEGER" property="tryTimes"/> <result column="try_times" jdbcType="INTEGER" property="tryTimes"/>
<result column="linker_id" jdbcType="INTEGER" property="linkerId"/> <result column="linker_id" jdbcType="INTEGER" property="linkerId"/>
<result column="account" jdbcType="VARCHAR" property="account"/>
<result column="blacklist" jdbcType="TINYINT" property="blacklist"/> <result column="blacklist" jdbcType="TINYINT" property="blacklist"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/> <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/> <result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
...@@ -22,7 +21,7 @@ ...@@ -22,7 +21,7 @@
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
--> -->
id, token, expire_in, try_times, linker_id, account, blacklist, del_flag, created_date, created_by, updated_date, id, token, expire_in, try_times, linker_id, blacklist, del_flag, created_date, created_by, updated_date,
updated_by updated_by
</sql> </sql>
...@@ -34,17 +33,9 @@ ...@@ -34,17 +33,9 @@
and del_flag = 0 and del_flag = 0
</select> </select>
<select id="selectByAccount" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_cust_user
where account = #{account}
and del_flag = 0
</select>
<insert id="saveOrUpdate" useGeneratedKeys="true" keyProperty="id" parameterType="cn.com.glsx.app.modules.entity.User"> <insert id="saveOrUpdate" useGeneratedKeys="true" keyProperty="id" parameterType="cn.com.glsx.app.modules.entity.User">
INSERT INTO t_cust_user (id, linker_id, account, blacklist, del_flag, created_date) INSERT INTO t_cust_user (id, linker_id, blacklist, del_flag, created_date)
VALUES (#{id}, #{linkerId}, #{account}, #{blacklist}, 0, sysdate()) ON DUPLICATE KEY VALUES (#{id}, #{linkerId}, #{blacklist}, 0, sysdate()) ON DUPLICATE KEY
UPDATE updated_date = sysdate() UPDATE updated_date = sysdate()
</insert> </insert>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<select id="selectByAuthId" resultMap="BaseResultMap"> <select id="selectByAuthId" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from t_user_qq_account from t_cust_user_qq_account
where auth_id = #{authId} where auth_id = #{authId}
and del_flag = 0 and del_flag = 0
</select> </select>
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<select id="selectByOpenid" resultMap="BaseResultMap"> <select id="selectByOpenid" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from t_user_third_auth from t_cust_user_third_auth
where openid = #{openid} where openid = #{openid}
and del_flag = 0 and del_flag = 0
</select> </select>
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<select id="selectByAuthId" resultMap="BaseResultMap"> <select id="selectByAuthId" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List"/> <include refid="Base_Column_List"/>
from t_user_wechat_account from t_cust_user_wechat_account
where auth_id = #{authId} where auth_id = #{authId}
and del_flag = 0 and del_flag = 0
</select> </select>
......
<?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="cn.com.glsx.app.modules.mapper.VehicleSharedMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.app.modules.entity.VehicleShared">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="accorder_id" jdbcType="INTEGER" property="accorderId" />
<result column="receiver_id" jdbcType="INTEGER" property="receiverId" />
<result column="content_id" jdbcType="INTEGER" property="contentId" />
<result column="content_type" jdbcType="TINYINT" property="contentType" />
<result column="permit_type" jdbcType="VARCHAR" property="permitType" />
<result column="effective_date" jdbcType="TIMESTAMP" property="effectiveDate" />
<result column="expiration_date" jdbcType="TIMESTAMP" property="expirationDate" />
<result column="status" jdbcType="TINYINT" property="status" />
<result column="del_flag" jdbcType="TINYINT" property="delFlag" />
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate" />
<result column="created_by" jdbcType="INTEGER" property="createdBy" />
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate" />
<result column="updated_by" jdbcType="INTEGER" property="updatedBy" />
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, accorder_id, receiver_id, content_id, content_type, permit_type, effective_date,
expiration_date, `status`, del_flag, created_date, created_by, updated_date, updated_by
</sql>
</mapper>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!