This commit is contained in:
sxu 2025-02-17 16:54:03 +08:00
parent f352b91391
commit a0673be746
5 changed files with 50 additions and 35 deletions

View File

@ -4,6 +4,8 @@ import java.util.Set;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import com.bonus.common.core.annotation.Excel; import com.bonus.common.core.annotation.Excel;
@ -25,6 +27,7 @@ public class SysRole extends BaseEntity
/** 角色ID */ /** 角色ID */
@Excel(name = "角色序号", cellType = ColumnType.NUMERIC) @Excel(name = "角色序号", cellType = ColumnType.NUMERIC)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long roleId; private Long roleId;
/** 角色名称 */ /** 角色名称 */

View File

@ -46,9 +46,16 @@ public class SysUser extends BaseEntity {
/** /**
* 公司ID * 公司ID
*/ */
@Excel(name = "公司编号", type = Type.IMPORT) //@Excel(name = "公司编号", type = Type.IMPORT)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long companyId; private Long companyId;
/**
* 区域id源自送变电公司下面的管辖区域可以用来划分数据范围
*/
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long areaId;
/** /**
* 用户账号 * 用户账号
*/ */
@ -144,6 +151,7 @@ public class SysUser extends BaseEntity {
/** /**
* 角色ID * 角色ID
*/ */
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long roleId; private Long roleId;
/** /**
@ -166,6 +174,7 @@ public class SysUser extends BaseEntity {
@ApiModelProperty("客户端人员id") @ApiModelProperty("客户端人员id")
@JsonFormat(shape = JsonFormat.Shape.STRING) @JsonFormat(shape = JsonFormat.Shape.STRING)
private Long custId; private Long custId;
@ApiModelProperty("客户端人员编号") @ApiModelProperty("客户端人员编号")
private String custNum; private String custNum;
@ -211,6 +220,14 @@ public class SysUser extends BaseEntity {
this.companyId = companyId; this.companyId = companyId;
} }
public Long getAreaId() {
return areaId;
}
public void setAreaId(Long areaId) {
this.areaId = areaId;
}
@Xss(message = "用户昵称不能包含脚本字符") @Xss(message = "用户昵称不能包含脚本字符")
@Size(min = 0, max = 200, message = "用户昵称长度不能超过200个字符") @Size(min = 0, max = 200, message = "用户昵称长度不能超过200个字符")
public String getNickName() { public String getNickName() {

View File

@ -150,13 +150,7 @@ public class TokenController {
LoginUser login = strategy.login(form.getUsername(), form.getPassword()); LoginUser login = strategy.login(form.getUsername(), form.getPassword());
logService.saveLogin(form.getUsername(), "登录", "登录成功", null, "成功"); logService.saveLogin(form.getUsername(), "登录", "登录成功", null, "成功");
if (LoginType.CUST_PHONE_PASSWORD.equals(form.getLoginType()) || LoginType.CUST_PHONE_OPT.equals(form.getLoginType())) { if (LoginType.PHONE_PASSWORD.equals(form.getLoginType()) || LoginType.PHONE_OTP.equals(form.getLoginType())) {
Map<String, Object> map = tokenService.createCustToken(login);
login.setToken((String) map.get("access_token"));
login.setExpireIn((Long) map.get("expires_in"));
login.setLogin((boolean) map.get("isLogin"));
return R.ok(login);
} else if (LoginType.PHONE_PASSWORD.equals(form.getLoginType()) || LoginType.PHONE_OTP.equals(form.getLoginType())) {
Map<String, Object> map = tokenService.createToken(login); Map<String, Object> map = tokenService.createToken(login);
login.setToken((String) map.get("access_token")); login.setToken((String) map.get("access_token"));
login.setExpireIn((Long) map.get("expires_in")); login.setExpireIn((Long) map.get("expires_in"));

View File

@ -100,32 +100,32 @@ public class TokenService {
/** /**
* 创建客户令牌 * 创建客户令牌
*/ */
public Map<String, Object> createCustToken(LoginUser loginUser) { // public Map<String, Object> createCustToken(LoginUser loginUser) {
// 检查并删除已有的token // // 检查并删除已有的token
delExistingToken(loginUser.getCustId()); // delExistingToken(loginUser.getCustId());
String token = IdUtils.fastUUID(); // String token = IdUtils.fastUUID();
Long custId = loginUser.getCustId(); // Long custId = loginUser.getCustId();
String phoneNumber = Sm4Utils.decrypt(loginUser.getSysUser().getPhonenumber()); // String phoneNumber = Sm4Utils.decrypt(loginUser.getSysUser().getPhonenumber());
loginUser.setToken(token); // loginUser.setToken(token);
loginUser.setCustId(custId); // loginUser.setCustId(custId);
loginUser.setIpaddr(IpUtils.getIpAddr()); // loginUser.setIpaddr(IpUtils.getIpAddr());
loginUser.getSysUser().setPhonenumber(phoneNumber); // loginUser.getSysUser().setPhonenumber(phoneNumber);
refreshToken(loginUser); // refreshToken(loginUser);
// Jwt存储信息 // // Jwt存储信息
Map<String, Object> claimsMap = new HashMap<String, Object>(16); // Map<String, Object> claimsMap = new HashMap<String, Object>(16);
claimsMap.put(SecurityConstants.USER_KEY, token); // claimsMap.put(SecurityConstants.USER_KEY, token);
claimsMap.put(SecurityConstants.DETAILS_USER_ID, custId); // claimsMap.put(SecurityConstants.DETAILS_USER_ID, custId);
claimsMap.put(SecurityConstants.DETAILS_USERNAME, phoneNumber); // claimsMap.put(SecurityConstants.DETAILS_USERNAME, phoneNumber);
String accessToken = JwtUtils.createToken(claimsMap); // String accessToken = JwtUtils.createToken(claimsMap);
Map<String, Object> rspMap = new HashMap<String, Object>(16); // Map<String, Object> rspMap = new HashMap<String, Object>(16);
rspMap.put("access_token", accessToken); // rspMap.put("access_token", accessToken);
rspMap.put("expires_in", EXPIRETIME); // rspMap.put("expires_in", EXPIRETIME);
rspMap.put("isLogin", isLogin(String.valueOf(custId))); // rspMap.put("isLogin", isLogin(String.valueOf(custId)));
long tokenTime = getTokenTime(); // long tokenTime = getTokenTime();
//对token进行存储 // //对token进行存储
redisService.setCacheObject(LOGIN_USER_KEY + custId, token, tokenTime, TimeUnit.MINUTES); // redisService.setCacheObject(LOGIN_USER_KEY + custId, token, tokenTime, TimeUnit.MINUTES);
return rspMap; // return rspMap;
} // }
public boolean isLogin(String userId) { public boolean isLogin(String userId) {
String existingTokenKey = redisService.getCacheObject(LOGIN_USER_KEY + userId); String existingTokenKey = redisService.getCacheObject(LOGIN_USER_KEY + userId);

View File

@ -8,6 +8,7 @@
<id property="userId" column="user_id"/> <id property="userId" column="user_id"/>
<result property="deptId" column="dept_id"/> <result property="deptId" column="dept_id"/>
<result property="companyId" column="company_id"/> <result property="companyId" column="company_id"/>
<result property="areaId" column="area_id"/>
<result property="userName" column="user_name"/> <result property="userName" column="user_name"/>
<result property="nickName" column="nick_name"/> <result property="nickName" column="nick_name"/>
<result property="email" column="email"/> <result property="email" column="email"/>
@ -32,7 +33,6 @@
<result property="custNum" column="cust_num"/> <result property="custNum" column="cust_num"/>
<association property="dept" javaType="SysDept" resultMap="deptResult"/> <association property="dept" javaType="SysDept" resultMap="deptResult"/>
<collection property="roles" javaType="java.util.List" resultMap="RoleResult"/> <collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>
</resultMap> </resultMap>
<resultMap id="deptResult" type="SysDept"> <resultMap id="deptResult" type="SysDept">
@ -63,6 +63,7 @@
ELSE ELSE
SUBSTRING_INDEX(SUBSTRING_INDEX(d.ancestors, ',', 2), ',', -1) SUBSTRING_INDEX(SUBSTRING_INDEX(d.ancestors, ',', 2), ',', -1)
END as company_id, END as company_id,
u.area_id,
u.user_name, u.user_name,
u.nick_name, u.nick_name,
u.email, u.email,