重构用户实体类

This commit is contained in:
liuchengqian 2023-02-03 17:02:02 +08:00
parent 54faad2d67
commit e85d818b67
8 changed files with 43 additions and 62 deletions

View File

@ -31,7 +31,7 @@ public class PushController {
@PostMapping("/bindUserPushInfo") @PostMapping("/bindUserPushInfo")
public String bindUserPushInfo(@RequestBody SysUserPushAccountQo sysUserPushAccountQo) { public String bindUserPushInfo(@RequestBody SysUserPushAccountQo sysUserPushAccountQo) {
Integer id = sysUserPushAccountQo.getId(); Long id = sysUserPushAccountQo.getId();
String regID = sysUserPushAccountQo.getRegID(); String regID = sysUserPushAccountQo.getRegID();
String userAccount = sysUserPushAccountQo.getUserAccount(); String userAccount = sysUserPushAccountQo.getUserAccount();
if (null == id) { if (null == id) {

View File

@ -88,7 +88,7 @@ public class SysUserController {
List<String> failureIdList = new ArrayList<>();//操作失败的ID集合 List<String> failureIdList = new ArrayList<>();//操作失败的ID集合
for (String userId : userIdList) { for (String userId : userIdList) {
try { try {
Optional<SysUserEntity> targetEntityOptional = sysUserDao.findById(Integer.parseInt(userId)); Optional<SysUserEntity> targetEntityOptional = sysUserDao.findById(Long.parseLong(userId));
if (targetEntityOptional.isPresent()) { if (targetEntityOptional.isPresent()) {
SysUserEntity targetEntity = targetEntityOptional.get(); SysUserEntity targetEntity = targetEntityOptional.get();
if (!TextUtils.isEmpty(overTime)) { if (!TextUtils.isEmpty(overTime)) {
@ -125,18 +125,16 @@ public class SysUserController {
@RequestMapping(value = "/updateviplevel", method = RequestMethod.POST) @RequestMapping(value = "/updateviplevel", method = RequestMethod.POST)
public String updateVipLevel(@RequestBody SysUserVipLevelQo sysUserVipLevelQo) { public String updateVipLevel(@RequestBody SysUserVipLevelQo sysUserVipLevelQo) {
String ids = sysUserVipLevelQo.getIds(); String ids = sysUserVipLevelQo.getIds();
List<Integer> idList = new ArrayList<>(); List<Long> idList = new ArrayList<>();
if (ids.contains(",")) { if (ids.contains(",")) {
String[] splits = ids.split(","); String[] splits = ids.split(",");
if (splits != null && splits.length > 0) { for (String split : splits) {
for (String split : splits) { idList.add(Long.parseLong(split));
idList.add(Integer.parseInt(split));
}
} }
} else { } else {
idList.add(Integer.parseInt(ids)); idList.add(Long.parseLong(ids));
} }
for (Integer id : idList) { for (Long id : idList) {
sysUserDao.updateVipLevel(id, sysUserVipLevelQo.getVipLevel()); sysUserDao.updateVipLevel(id, sysUserVipLevelQo.getVipLevel());
} }
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
@ -149,18 +147,16 @@ public class SysUserController {
@RequestMapping(value = "/updatereceivesms", method = RequestMethod.POST) @RequestMapping(value = "/updatereceivesms", method = RequestMethod.POST)
public String updateReceiveSms(@RequestBody SysUserReceiveSmsQo sysUserReceiveSmsQo) { public String updateReceiveSms(@RequestBody SysUserReceiveSmsQo sysUserReceiveSmsQo) {
String ids = sysUserReceiveSmsQo.getIds(); String ids = sysUserReceiveSmsQo.getIds();
List<Integer> idList = new ArrayList<>(); List<Long> idList = new ArrayList<>();
if (ids.contains(",")) { if (ids.contains(",")) {
String[] splits = ids.split(","); String[] splits = ids.split(",");
if (splits != null && splits.length > 0) { for (String split : splits) {
for (String split : splits) { idList.add(Long.parseLong(split));
idList.add(Integer.parseInt(split));
}
} }
} else { } else {
idList.add(Integer.parseInt(ids)); idList.add(Long.parseLong(ids));
} }
for (Integer id : idList) { for (Long id : idList) {
sysUserDao.updateReceiveSms(id, sysUserReceiveSmsQo.getReceiveSms()); sysUserDao.updateReceiveSms(id, sysUserReceiveSmsQo.getReceiveSms());
} }
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
@ -169,7 +165,7 @@ public class SysUserController {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@RequestMapping(value = "/updateremark", method = RequestMethod.POST) @RequestMapping(value = "/updateremark", method = RequestMethod.POST)
public String updateRemark(@RequestBody SysUserRemarkQo sysUserRemarkQo) { public String updateRemark(@RequestBody SysUserRemarkQo sysUserRemarkQo) {
Integer id = sysUserRemarkQo.getId(); Long id = sysUserRemarkQo.getId();
Optional<SysUserEntity> optionalById = sysUserDao.findById(id); Optional<SysUserEntity> optionalById = sysUserDao.findById(id);
if (optionalById.isEmpty()) { if (optionalById.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "修改失败,用户找不到", locale); return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "修改失败,用户找不到", locale);
@ -231,7 +227,7 @@ public class SysUserController {
* 软删除指定id的普通用户 * 软删除指定id的普通用户
*/ */
@RequestMapping(value = "/general/delete", method = RequestMethod.DELETE) @RequestMapping(value = "/general/delete", method = RequestMethod.DELETE)
public String deleteCustomUser(@RequestParam(value = "userId", required = false) int id) { public String deleteCustomUser(@RequestParam(value = "userId", required = false) Long id) {
// 验证数据合法性 // 验证数据合法性
int res = sysUserService.softDeleteGeneralUser(id); int res = sysUserService.softDeleteGeneralUser(id);
if (res == 1) { if (res == 1) {
@ -291,7 +287,7 @@ public class SysUserController {
*/ */
@PostMapping("/operateActiveFlag") @PostMapping("/operateActiveFlag")
public String operateActiveFlag(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) { public String operateActiveFlag(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
Integer userId = (Integer) map.get("userId"); Long userId = (Long) map.get("userId");
String keepType = (String) map.get("keepType"); String keepType = (String) map.get("keepType");
// 验证token // 验证token
String tokenUserName = TokenUtil.getTokenUserName(token); String tokenUserName = TokenUtil.getTokenUserName(token);

View File

@ -10,51 +10,37 @@ import java.util.List;
/** /**
* SysRoleDao * SysRoleDao
*
* @author tajochen * @author tajochen
*/ */
public interface SysRoleDao extends JpaRepository<SysRoleEntity,Integer> { public interface SysRoleDao extends JpaRepository<SysRoleEntity, Integer> {
/** /**
* 查询用户角色列表根据用户id * 查询用户角色列表根据用户id
*
* @param id * @param id
* @return * @return
*/ */
@Query(value = "SELECT sys_role.id,sys_role.role_name,sys_role.role_name_zh,sys_role.role_desc " + @Query(value = "SELECT sys_role.id,sys_role.role_name,sys_role.role_name_zh,sys_role.role_desc FROM sys_role,rel_user_role WHERE sys_role.id = rel_user_role.role_id AND rel_user_role.user_id = :id ", nativeQuery = true)
"FROM sys_role,rel_user_role " + List<SysRoleEntity> selectByUserId(@Param("id") Long id);
"WHERE sys_role.id = rel_user_role.role_id " +
"AND rel_user_role.user_id = :id ", nativeQuery = true)
List<SysRoleEntity> selectByUserId(@Param("id") Integer id);
/** /**
* 查询用户角色列表根据用户名 * 查询用户角色列表根据用户名
*
* @param userName * @param userName
* @return * @return
*/ */
@Query(value = "SELECT sys_role.id,sys_role.role_name,sys_role.role_name_zh,sys_role.role_desc " + @Query(value = "SELECT sys_role.id,sys_role.role_name,sys_role.role_name_zh,sys_role.role_desc FROM sys_role.ID = rel_user_role.role_id WHERE rel_user_role.user_id = sys_user.id AND rel_user_role.user_id = sys_user.id AND sys_user.user_name = :userName ", nativeQuery = true)
"FROM sys_role.ID = rel_user_role.role_id " +
"WHERE rel_user_role.user_id = sys_user.id " +
"AND rel_user_role.user_id = sys_user.id " +
"AND sys_user.user_name = :userName ", nativeQuery = true)
List<SysRoleEntity> selectByUserName(@Param("userName") String userName); List<SysRoleEntity> selectByUserName(@Param("userName") String userName);
// /**
// * 根据用户名修改用户角色
// */
// @Modifying
// @Query(value = "UPDATE sys_user SET last_entry_time = now(), last_entry_ip = :ipAddress " +
// "WHERE user_name = :userName ;", nativeQuery = true)
// int updateUserRoleByUserName(@Param("userName") String userName);
/** /**
* 添加用户角色根据用户名和角色名 * 添加用户角色根据用户名和角色名
*
* @param userName * @param userName
* @param roleName * @param roleName
* @return * @return
*/ */
@Modifying @Modifying
@Query(value = "INSERT INTO rel_user_role (id,role_id, user_id) " + @Query(value = "INSERT INTO rel_user_role (id,role_id, user_id) SELECT nextval('rel_user_role_seq'),sys_role.ID,sys_user.ID FROM sys_role,sys_user WHERE sys_role.role_name = :roleName AND sys_user.user_name = :userName ", nativeQuery = true)
"SELECT nextval('rel_user_role_seq'),sys_role.ID,sys_user.ID FROM sys_role,sys_user " +
"WHERE sys_role.role_name = :roleName AND sys_user.user_name = :userName ", nativeQuery = true)
int insertRelUserRole(@Param("userName") String userName, @Param("roleName") String roleName); int insertRelUserRole(@Param("userName") String userName, @Param("roleName") String roleName);
} }

View File

@ -15,19 +15,19 @@ import java.util.List;
* *
* @author tajochen * @author tajochen
*/ */
public interface SysUserDao extends JpaRepository<SysUserEntity, Integer>, JpaSpecificationExecutor<SysUserEntity> { public interface SysUserDao extends JpaRepository<SysUserEntity, Long>, JpaSpecificationExecutor<SysUserEntity> {
@Modifying(clearAutomatically = true) @Modifying(clearAutomatically = true)
@Query(value = "UPDATE sys_user SET vip_level = ?2 WHERE id = ?1", nativeQuery = true) @Query(value = "UPDATE sys_user SET vip_level = ?2 WHERE id = ?1", nativeQuery = true)
void updateVipLevel(Integer id, Integer vipLevel); void updateVipLevel(Long id, Integer vipLevel);
@Modifying(clearAutomatically = true) @Modifying(clearAutomatically = true)
@Query(value = "UPDATE sys_user SET receive_sms = ?2 WHERE id = ?1", nativeQuery = true) @Query(value = "UPDATE sys_user SET receive_sms = ?2 WHERE id = ?1", nativeQuery = true)
void updateReceiveSms(Integer id, Integer receiveSms); void updateReceiveSms(Long id, Integer receiveSms);
@Modifying(clearAutomatically = true) @Modifying(clearAutomatically = true)
@Query(value = "UPDATE sys_user SET remark = ?2 WHERE id = ?1", nativeQuery = true) @Query(value = "UPDATE sys_user SET remark = ?2 WHERE id = ?1", nativeQuery = true)
void updateRemark(Integer id, String remark); void updateRemark(Long id, String remark);
/** /**
* 检查系统用户名是否存在 * 检查系统用户名是否存在
@ -58,7 +58,7 @@ public interface SysUserDao extends JpaRepository<SysUserEntity, Integer>, JpaSp
*/ */
@Modifying @Modifying
@Query(value = "UPDATE sys_user SET delete_flag = 1 " + "WHERE id = :id ;", nativeQuery = true) @Query(value = "UPDATE sys_user SET delete_flag = 1 " + "WHERE id = :id ;", nativeQuery = true)
int softDeleteGeneralUserById(@Param("id") Integer id); int softDeleteGeneralUserById(@Param("id") Long id);
/** /**
* 删除系统用户危险操作 * 删除系统用户危险操作
@ -84,14 +84,14 @@ public interface SysUserDao extends JpaRepository<SysUserEntity, Integer>, JpaSp
*/ */
@Query(value = "update sys_user set active_flag = 0 where id = ?", nativeQuery = true) @Query(value = "update sys_user set active_flag = 0 where id = ?", nativeQuery = true)
@Modifying(clearAutomatically = true) @Modifying(clearAutomatically = true)
void updateEnable(Integer userId); void updateEnable(Long userId);
/** /**
* 禁用 * 禁用
*/ */
@Query(value = "update sys_user set active_flag = 1 where id = ?", nativeQuery = true) @Query(value = "update sys_user set active_flag = 1 where id = ?", nativeQuery = true)
@Modifying(clearAutomatically = true) @Modifying(clearAutomatically = true)
void updateDisable(Integer userId); void updateDisable(Long userId);
/** /**
* 用户修改密码 * 用户修改密码

View File

@ -2,7 +2,7 @@ package com.xkrs.model.qo;
public class SysUserPushAccountQo { public class SysUserPushAccountQo {
private Integer id; private Long id;
private String regID; private String regID;
@ -11,11 +11,11 @@ public class SysUserPushAccountQo {
public SysUserPushAccountQo() { public SysUserPushAccountQo() {
} }
public Integer getId() { public Long getId() {
return id; return id;
} }
public void setId(Integer id) { public void setId(Long id) {
this.id = id; this.id = id;
} }

View File

@ -7,7 +7,7 @@ import javax.validation.constraints.NotNull;
public class SysUserRemarkQo { public class SysUserRemarkQo {
@NotNull(message = "{SysUser.id.blank}", groups = {SysUserQoUpdate.class}) @NotNull(message = "{SysUser.id.blank}", groups = {SysUserQoUpdate.class})
private Integer id; private Long id;
@NotNull(message = "{SysUser.remark.blank}", groups = {SysUserQoUpdate.class}) @NotNull(message = "{SysUser.remark.blank}", groups = {SysUserQoUpdate.class})
private String remark; private String remark;
@ -15,11 +15,11 @@ public class SysUserRemarkQo {
public SysUserRemarkQo() { public SysUserRemarkQo() {
} }
public Integer getId() { public Long getId() {
return id; return id;
} }
public void setId(Integer id) { public void setId(Long id) {
this.id = id; this.id = id;
} }

View File

@ -76,7 +76,7 @@ public interface SysUserService {
* @param id * @param id
* @return * @return
*/ */
int softDeleteGeneralUser(Integer id); int softDeleteGeneralUser(Long id);
/** /**
* 查询用户的信息 * 查询用户的信息
@ -90,14 +90,14 @@ public interface SysUserService {
* *
* @param userId * @param userId
*/ */
void updateEnable(Integer userId); void updateEnable(Long userId);
/** /**
* 禁用 * 禁用
* *
* @param userId * @param userId
*/ */
void updateDisable(Integer userId); void updateDisable(Long userId);
/** /**
* 用户修改密码 * 用户修改密码

View File

@ -253,10 +253,9 @@ public class SysUserServiceImpl implements SysUserService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public int softDeleteGeneralUser(Integer id) { public int softDeleteGeneralUser(Long id) {
String adminRole = "role_administor"; String adminRole = "role_administor";
String sysRole = "role_system_manager"; String sysRole = "role_system_manager";
List<SysRoleEntity> list = sysRoleDao.selectByUserId(id); List<SysRoleEntity> list = sysRoleDao.selectByUserId(id);
if (list.size() > 0) { if (list.size() > 0) {
SysRoleEntity sysRoleEntity = list.get(1); SysRoleEntity sysRoleEntity = list.get(1);
@ -285,7 +284,7 @@ public class SysUserServiceImpl implements SysUserService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void updateEnable(Integer userId) { public void updateEnable(Long userId) {
sysUserDao.updateEnable(userId); sysUserDao.updateEnable(userId);
} }
@ -296,7 +295,7 @@ public class SysUserServiceImpl implements SysUserService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void updateDisable(Integer userId) { public void updateDisable(Long userId) {
sysUserDao.updateDisable(userId); sysUserDao.updateDisable(userId);
} }