重构用户实体类

This commit is contained in:
liuchengqian 2023-02-03 16:44:58 +08:00
parent bde50770ca
commit 54faad2d67
9 changed files with 66 additions and 89 deletions

View File

@ -332,7 +332,7 @@ public class SysUserController {
@PostMapping("/adminUpdatePassword")
public String adminUpdatePassword(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
// 要修改的用户的id
Integer userId = (Integer) map.get("userId");
Long userId = (Long) map.get("userId");
String newPassword = (String) map.get("newPassword");
String confirmPassword = (String) map.get("confirmPassword");
// 验证token
@ -416,7 +416,7 @@ public class SysUserController {
*/
@PostMapping("/updateExpireDate")
public String updateExpireDate(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
Integer userId = (Integer) map.get("userId");
Long userId = (Long) map.get("userId");
Integer timeNum = (Integer) map.get("timeNum");
String keepType = (String) map.get("keepType");
if ("1".equals(keepType)) {
@ -435,7 +435,7 @@ public class SysUserController {
*/
@PostMapping("/updateOverTime")
public String updateOverTime(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
Integer userId = (Integer) map.get("userId");
Long userId = (Long) map.get("userId");
String overTime = (String) map.get("overTime");
return sysUserService.updateOverTime(userId, overTime);
}

View File

@ -20,7 +20,7 @@ public interface RelRoleAuthorityDao extends JpaRepository<RelRoleAuthorityEntit
* @return
*/
@Query(value = "select authority_id from rel_role_authority where user_id = ?", nativeQuery = true)
List<Integer> selectAuthorityByUserId(@Param("userId") Integer userId);
List<Integer> selectAuthorityByUserId(@Param("userId") Long userId);
@Query(value = "SELECT * FROM rel_role_authority WHERE authority_id = ?1", nativeQuery = true)
List<RelRoleAuthorityEntity> selectByAuthorityId(Integer authorityId);

View File

@ -98,40 +98,40 @@ public interface SysUserDao extends JpaRepository<SysUserEntity, Integer>, JpaSp
*/
@Query(value = "update sys_user set password = ?2 where id = ?1", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updatePassword(Integer userId, String newPassword);
void updatePassword(Long userId, String newPassword);
/**
* 根据id查询用户的信息
*/
@Query(value = "select * from sys_user where id = ?", nativeQuery = true)
SysUserEntity selectByUserId(Integer userId);
SysUserEntity selectByUserId(Long userId);
/**
* 根据id修改账户的到期时间
*/
@Query(value = "update sys_user set over_time = ?2 where id = ?1", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updateOverTime(Integer userId, String overTime);
void updateOverTime(Long userId, String overTime);
/**
* 将账户的期限修改为永久有效
*/
@Query(value = "update sys_user set over_time = '永久' and day_num = 1 where id = ?", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updateDayNum(Integer userId);
void updateDayNum(Long userId);
/**
* 记录用户登录次数
*/
@Query(value = "update sys_user set login_num = ?2 where id = ?1", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updateLoginNum(Integer userId, Integer loginNum);
void updateLoginNum(Long userId, Integer loginNum);
/**
* 修改登陆时间
*/
@Query(value = "update sys_user set login_last_time = ?2 where id = ?1", nativeQuery = true)
@Modifying(clearAutomatically = true)
void updateLoginLastTime(Integer userId, String loginLastTime);
void updateLoginLastTime(Long userId, String loginLastTime);
}

View File

@ -5,6 +5,7 @@ import java.io.Serializable;
/**
* RelRoleAuthority 表实体类
*
* @author tajochen
*/
@Entity
@ -25,7 +26,10 @@ public class RelRoleAuthorityEntity implements Serializable {
@Column(nullable = false)
private Integer authorityId;
private Integer userId;
private Long userId;
public RelRoleAuthorityEntity() {
}
public Integer getId() {
return id;
@ -51,21 +55,16 @@ public class RelRoleAuthorityEntity implements Serializable {
this.authorityId = authorityId;
}
public Integer getUserId() {
public Long getUserId() {
return userId;
}
public void setUserId(Integer userId) {
public void setUserId(Long userId) {
this.userId = userId;
}
@Override
public String toString() {
return "RelRoleAuthorityEntity{" +
"id=" + id +
", roleId=" + roleId +
", authorityId=" + authorityId +
", userId=" + userId +
'}';
return "RelRoleAuthorityEntity{" + "id=" + id + ", roleId=" + roleId + ", authorityId=" + authorityId + ", userId=" + userId + '}';
}
}

View File

@ -2,14 +2,7 @@ package com.xkrs.model.entity;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* SysUser 表实体类
*
* @author tajochen
*/
@Entity
@Table(name = "sys_user")
public class SysUserEntity implements Serializable {
@ -20,60 +13,49 @@ public class SysUserEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sys_user_seq_gen")
@SequenceGenerator(name = "sys_user_seq_gen", sequenceName = "sys_user_id_seq", allocationSize = 1)
private Integer id;
private Long id;
/**
* 用户名
*/
@Column(length = 16, nullable = false, unique = true, columnDefinition = "varchar(16)")
@Column(nullable = false, unique = true)
private String userName;
/**
* 用户真实姓名
*/
@Column(length = 32, columnDefinition = "varchar(32)")
private String reallyName;
/**
* 密码
*/
@Column(length = 64, nullable = false, columnDefinition = "varchar(64)")
@Column(nullable = false)
private String password;
@Column(length = 32, nullable = false, columnDefinition = "varchar(32)")
@Column(nullable = false)
private String salt;
@Column(length = 16, unique = true, columnDefinition = "varchar(16)")
@Column(unique = true)
private String telephone;
@Column(length = 32, columnDefinition = "varchar(32)")
private String countyCode;
@Column(columnDefinition = "varchar(192)")
private String signature;
@Column(nullable = false)
private Integer activeFlag;
@Column(nullable = false, columnDefinition = "smallint")
@Column(nullable = false)
private Integer statusCode;
@Column(nullable = false)
private String addTime;
private LocalDateTime lastEntryTime;
@Column(nullable = false)
private Integer deleteFlag;
@Column(columnDefinition = "varchar(64)")
private String lastEntryIp;
/**
* 账号的使用天数
*/
private Integer dayNum;
/**
* 账号到期的时间
*/
@ -82,10 +64,8 @@ public class SysUserEntity implements Serializable {
/**
* 账号类别
*/
@Column(length = 64, columnDefinition = "varchar(64)")
private String accountType;
@Column(length = 64, columnDefinition = "varchar(64)")
private String countyName;
/**
@ -134,14 +114,20 @@ public class SysUserEntity implements Serializable {
*/
private String pushRegID;
/**
* VIP时间范围列表Json
*/
@Column(columnDefinition = "varchar(10240)")
private String vipTimeRangeJson;
public SysUserEntity() {
}
public Integer getId() {
public Long getId() {
return id;
}
public void setId(Integer id) {
public void setId(Long id) {
this.id = id;
}
@ -225,14 +211,6 @@ public class SysUserEntity implements Serializable {
this.addTime = addTime;
}
public LocalDateTime getLastEntryTime() {
return lastEntryTime;
}
public void setLastEntryTime(LocalDateTime lastEntryTime) {
this.lastEntryTime = lastEntryTime;
}
public Integer getDeleteFlag() {
return deleteFlag;
}
@ -249,14 +227,6 @@ public class SysUserEntity implements Serializable {
this.lastEntryIp = lastEntryIp;
}
public Integer getDayNum() {
return dayNum;
}
public void setDayNum(Integer dayNum) {
this.dayNum = dayNum;
}
public String getOverTime() {
return overTime;
}
@ -353,8 +323,16 @@ public class SysUserEntity implements Serializable {
this.pushRegID = pushRegID;
}
public String getVipTimeRangeJson() {
return vipTimeRangeJson;
}
public void setVipTimeRangeJson(String vipTimeRangeJson) {
this.vipTimeRangeJson = vipTimeRangeJson;
}
@Override
public String toString() {
return "SysUserEntity{" + "id=" + id + ", userName='" + userName + '\'' + ", reallyName='" + reallyName + '\'' + ", password='" + password + '\'' + ", salt='" + salt + '\'' + ", telephone='" + telephone + '\'' + ", countyCode='" + countyCode + '\'' + ", signature='" + signature + '\'' + ", activeFlag=" + activeFlag + ", statusCode=" + statusCode + ", addTime='" + addTime + '\'' + ", lastEntryTime=" + lastEntryTime + ", deleteFlag=" + deleteFlag + ", lastEntryIp='" + lastEntryIp + '\'' + ", dayNum=" + dayNum + ", overTime='" + overTime + '\'' + ", accountType='" + accountType + '\'' + ", countyName='" + countyName + '\'' + ", loginNum=" + loginNum + ", loginLastTime='" + loginLastTime + '\'' + ", userAgent='" + userAgent + '\'' + ", vipLevel=" + vipLevel + ", receiveSms=" + receiveSms + ", remark='" + remark + '\'' + ", agentOrgId=" + agentOrgId + ", pushUserAccount='" + pushUserAccount + '\'' + ", pushRegID='" + pushRegID + '\'' + '}';
return "SysUserEntity{" + "id=" + id + ", userName='" + userName + '\'' + ", reallyName='" + reallyName + '\'' + ", password='" + password + '\'' + ", salt='" + salt + '\'' + ", telephone='" + telephone + '\'' + ", countyCode='" + countyCode + '\'' + ", signature='" + signature + '\'' + ", activeFlag=" + activeFlag + ", statusCode=" + statusCode + ", addTime='" + addTime + '\'' + ", deleteFlag=" + deleteFlag + ", lastEntryIp='" + lastEntryIp + '\'' + ", overTime='" + overTime + '\'' + ", accountType='" + accountType + '\'' + ", countyName='" + countyName + '\'' + ", loginNum=" + loginNum + ", loginLastTime='" + loginLastTime + '\'' + ", userAgent='" + userAgent + '\'' + ", vipLevel=" + vipLevel + ", receiveSms=" + receiveSms + ", remark='" + remark + '\'' + ", agentOrgId=" + agentOrgId + ", pushUserAccount='" + pushUserAccount + '\'' + ", pushRegID='" + pushRegID + '\'' + ", vipTimeRangeJson='" + vipTimeRangeJson + '\'' + '}';
}
}

View File

@ -6,12 +6,14 @@ import java.util.List;
/**
* 系统权限服务接口
*
* @author tajochen
*/
public interface SysAuthorityService {
/**
* 获取权限实体列表根据用户名
*
* @param userName
* @return
*/
@ -19,5 +21,5 @@ public interface SysAuthorityService {
List<SysAuthorityEntity> findAllByIdIn(List<Integer> id);
List<Integer> selectAuthorityByUserId(Integer userId);
List<Integer> selectAuthorityByUserId(Long userId);
}

View File

@ -118,7 +118,7 @@ public interface SysUserService {
* @param confirmPassword
* @return
*/
String adminUpdatePassword(Integer userId, String newPassword, String confirmPassword);
String adminUpdatePassword(Long userId, String newPassword, String confirmPassword);
/**
* 获取系统用户实体根据用户名
@ -135,7 +135,7 @@ public interface SysUserService {
* @param dayNum
* @return
*/
String updateExpireDateDay(Integer userId, Integer dayNum);
String updateExpireDateDay(Long userId, Integer dayNum);
/**
* 按月份修改账号到期时间
@ -144,7 +144,7 @@ public interface SysUserService {
* @param dayNum
* @return
*/
String updateExpireDateMonth(Integer userId, Integer dayNum);
String updateExpireDateMonth(Long userId, Integer dayNum);
/**
* 按年份修改账号到期时间
@ -153,7 +153,7 @@ public interface SysUserService {
* @param dayNum
* @return
*/
String updateExpireDateYear(Integer userId, Integer dayNum);
String updateExpireDateYear(Long userId, Integer dayNum);
/**
* 设置账号时间永久有效
@ -161,7 +161,7 @@ public interface SysUserService {
* @param userId
* @return
*/
String updatePermanent(Integer userId);
String updatePermanent(Long userId);
/**
* 修改账号到期时间
@ -170,7 +170,7 @@ public interface SysUserService {
* @param overTime
* @return
*/
String updateOverTime(Integer userId, String overTime);
String updateOverTime(Long userId, String overTime);
/**
* 记录用户登录次数
@ -178,7 +178,7 @@ public interface SysUserService {
* @param userId
* @param loginNum
*/
void updateLoginNum(Integer userId, Integer loginNum);
void updateLoginNum(Long userId, Integer loginNum);
/**
* 记录用户登录时间
@ -186,6 +186,6 @@ public interface SysUserService {
* @param userId
* @param loginLastTime
*/
void updateLoginLastTime(Integer userId, String loginLastTime);
void updateLoginLastTime(Long userId, String loginLastTime);
}

View File

@ -4,8 +4,6 @@ import com.xkrs.dao.RelRoleAuthorityDao;
import com.xkrs.dao.SysAuthorityDao;
import com.xkrs.model.entity.SysAuthorityEntity;
import com.xkrs.service.SysAuthorityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -13,6 +11,7 @@ import java.util.List;
/**
* 系统权限服务实现
*
* @author tajochen
*/
@Service
@ -35,7 +34,7 @@ public class SysAuthorityServiceImpl implements SysAuthorityService {
}
@Override
public List<Integer> selectAuthorityByUserId(Integer userId) {
public List<Integer> selectAuthorityByUserId(Long userId) {
return relRoleAuthorityDao.selectAuthorityByUserId(userId);
}
}

View File

@ -185,7 +185,6 @@ public class SysUserServiceImpl implements SysUserService {
sysUserEntity.setStatusCode(0);
sysUserEntity.setAddTime(dateTimeToString(LocalDateTime.now()));
sysUserEntity.setDeleteFlag(0);
sysUserEntity.setDayNum(7);
sysUserEntity.setLoginNum(0);
sysUserEntity.setCountyCode(countyCode);
sysUserEntity.setCountyName(countyName);
@ -196,7 +195,7 @@ public class SysUserServiceImpl implements SysUserService {
sysUserDao.save(sysUserEntity);
RelUserRoleEntity relUserRoleEntity = new RelUserRoleEntity();
relUserRoleEntity.setUserId(sysUserEntity.getId().longValue());
relUserRoleEntity.setUserId(sysUserEntity.getId());
relUserRoleEntity.setRoleId(2);
RelRoleAuthorityEntity relRoleAuthorityEntity = new RelRoleAuthorityEntity();
@ -335,7 +334,7 @@ public class SysUserServiceImpl implements SysUserService {
*/
@Transactional(rollbackFor = Exception.class)
@Override
public String adminUpdatePassword(Integer userId, String newPassword, String confirmPassword) {
public String adminUpdatePassword(Long userId, String newPassword, String confirmPassword) {
if (!newPassword.equals(confirmPassword)) {
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "两次密码输入不一致", locale);
}
@ -359,7 +358,7 @@ public class SysUserServiceImpl implements SysUserService {
*/
@Transactional(rollbackFor = Exception.class)
@Override
public String updateExpireDateDay(Integer userId, Integer dayNum) {
public String updateExpireDateDay(Long userId, Integer dayNum) {
long l = dayNum.longValue();
LocalDateTime now = LocalDateTime.now();
SysUserEntity sysUserEntity = sysUserDao.selectByUserId(userId);
@ -386,7 +385,7 @@ public class SysUserServiceImpl implements SysUserService {
*/
@Transactional(rollbackFor = Exception.class)
@Override
public String updateExpireDateMonth(Integer userId, Integer dayNum) {
public String updateExpireDateMonth(Long userId, Integer dayNum) {
long l = dayNum.longValue();
LocalDateTime now = LocalDateTime.now();
SysUserEntity sysUserEntity = sysUserDao.selectByUserId(userId);
@ -413,7 +412,7 @@ public class SysUserServiceImpl implements SysUserService {
*/
@Transactional(rollbackFor = Exception.class)
@Override
public String updateExpireDateYear(Integer userId, Integer dayNum) {
public String updateExpireDateYear(Long userId, Integer dayNum) {
long l = dayNum.longValue();
LocalDateTime now = LocalDateTime.now();
SysUserEntity sysUserEntity = sysUserDao.selectByUserId(userId);
@ -439,7 +438,7 @@ public class SysUserServiceImpl implements SysUserService {
*/
@Transactional(rollbackFor = Exception.class)
@Override
public String updatePermanent(Integer userId) {
public String updatePermanent(Long userId) {
sysUserDao.updateDayNum(userId);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
}
@ -453,7 +452,7 @@ public class SysUserServiceImpl implements SysUserService {
*/
@Transactional(rollbackFor = Exception.class)
@Override
public String updateOverTime(Integer userId, String overTime) {
public String updateOverTime(Long userId, String overTime) {
sysUserDao.updateOverTime(userId, overTime);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
}
@ -466,7 +465,7 @@ public class SysUserServiceImpl implements SysUserService {
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void updateLoginNum(Integer userId, Integer loginNum) {
public void updateLoginNum(Long userId, Integer loginNum) {
sysUserDao.updateLoginNum(userId, loginNum);
}
@ -478,7 +477,7 @@ public class SysUserServiceImpl implements SysUserService {
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void updateLoginLastTime(Integer userId, String loginLastTime) {
public void updateLoginLastTime(Long userId, String loginLastTime) {
sysUserDao.updateLoginLastTime(userId, loginLastTime);
}