Commit 89832dd7 authored by 贷前—徐菲's avatar 贷前—徐菲

修改用户信息,review

parent a8bdc354
...@@ -93,5 +93,5 @@ public interface Constants { ...@@ -93,5 +93,5 @@ public interface Constants {
String REPAY_SMS = "用户您好,您在信用钱包的本期账单已还款成功,保持良好的信用可升级为VIP用户,享更多特权,感谢您对信用钱包的支持"; String REPAY_SMS = "用户您好,您在信用钱包的本期账单已还款成功,保持良好的信用可升级为VIP用户,享更多特权,感谢您对信用钱包的支持";
} }
String aesKey = "ScnmRBhuQpo9kBdn"; String AES_KEY = "ScnmRBhuQpo9kBdn";
} }
...@@ -8,6 +8,7 @@ import cn.quantgroup.xyqb.controller.IBaseController; ...@@ -8,6 +8,7 @@ import cn.quantgroup.xyqb.controller.IBaseController;
import cn.quantgroup.xyqb.entity.*; import cn.quantgroup.xyqb.entity.*;
import cn.quantgroup.xyqb.entity.enumerate.*; import cn.quantgroup.xyqb.entity.enumerate.*;
import cn.quantgroup.xyqb.model.*; import cn.quantgroup.xyqb.model.*;
import cn.quantgroup.xyqb.repository.IUserDetailRepository;
import cn.quantgroup.xyqb.service.api.IUserApiService; import cn.quantgroup.xyqb.service.api.IUserApiService;
import cn.quantgroup.xyqb.service.auth.IIdCardService; import cn.quantgroup.xyqb.service.auth.IIdCardService;
import cn.quantgroup.xyqb.service.http.IHttpService; import cn.quantgroup.xyqb.service.http.IHttpService;
...@@ -38,6 +39,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -38,6 +39,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.ParseException; import java.text.ParseException;
...@@ -957,23 +959,89 @@ public class InnerController implements IBaseController { ...@@ -957,23 +959,89 @@ public class InnerController implements IBaseController {
} }
@RequestMapping("/forbiddenUserWeChat") @RequestMapping("/forbiddenUserWeChat")
public JsonResult forbiddenUserWeChat(@RequestParam Long userId, @RequestParam String reason,@RequestParam String content, public JsonResult forbiddenUserWeChat(@RequestParam Long userId, @RequestParam String reason, @RequestParam String content) {
HttpServletRequest request) { if (StringUtils.isBlank(reason) || null == userId || userId <= 0) {
LOGGER.info("请求的ip:IPUtil.getRemoteIP(request):{}", IPUtil.getRemoteIP(request));
if (null!=content){
content=content.replace(" ","+");
}
LOGGER.info(content);
String str= AESUtil.decryptAfterBase64Decode(content, Constants.aesKey);
if (null==str ||!str.equals(userId.toString())){
return JsonResult.buildErrorStateResult("参数有误", null); return JsonResult.buildErrorStateResult("参数有误", null);
} }
if (null == userId || userId <= 0 || StringUtils.isEmpty(reason)) { //密文
if (null != content) {
content = content.replaceAll(" ", "+");
}
String str = AESUtil.decryptAfterBase64Decode(content, Constants.AES_KEY);
if (null == str || !str.equals(userId.toString())) {
return JsonResult.buildErrorStateResult("解密有误", null);
}
int affectedRows=wechatService.forbiddenUserWeChat(userId);
LOGGER.info("用户微信禁用,userId:{},禁用的原因reason:{},受影响的行数affectedRows:{}",userId,reason,affectedRows);
return JsonResult.buildSuccessResult("用户禁用微信成功", affectedRows);
}
@RequestMapping("/updateIdCard")
public JsonResult updateIdCard(@RequestParam String name, @RequestParam String idNo, @RequestParam String phoneNo,
@RequestParam String reason, @RequestParam String content) {
//密文
if (null != content) {
content = content.replaceAll(" ", "+");
}
String str = AESUtil.decryptAfterBase64Decode(content, Constants.AES_KEY);
if (null == str || !str.equals(phoneNo)) {
return JsonResult.buildErrorStateResult("解密有误", null);
}
if (StringUtils.isBlank(name) || StringUtils.isBlank(idNo) || StringUtils.isBlank(phoneNo) || StringUtils.isBlank(reason)) {
return JsonResult.buildErrorStateResult("参数有误", null); return JsonResult.buildErrorStateResult("参数有误", null);
} }
wechatService.forbiddenUserWeChat(userId); if (!ValidationUtil.validatePhoneNo(phoneNo)) {
return JsonResult.buildSuccessResult("用户禁用微信成功", null); LOGGER.info("手机号有误, phoneNo:{}", phoneNo);
return JsonResult.buildErrorStateResult("用户手机号错误", null);
}
if (!ValidationUtil.validateChinese(name)) {
LOGGER.info("名字有误, name:{}", name);
return JsonResult.buildErrorStateResult("用户姓名错误", null);
}
int affectedRows=userDetailService.updateIdCard(name, idNo, phoneNo);
LOGGER.info("更新用户的信息,name;{},idNo:{},phoneNo:{},操作的理由reason:{},受影响的行数affectedRows:{}", name, idNo, phoneNo, reason,affectedRows);
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
builder.put("phoneNo", phoneNo);
builder.put("name", name);
builder.put("idNo", idNo);
builder.put("reason", reason);
builder.put("content", content);
LOGGER.info("去清除函谷关的缓存");
Map<String, String> param = builder.build();
httpService.get(hanguguanUrl.concat("/innerapi/updateIdCard"), param);
return JsonResult.buildSuccessResult("修改用户身份证号成功", affectedRows);
} }
@RequestMapping("/forbiddenUserOrNot")
public JsonResult forbiddenUserOrNot(@RequestParam String phoneNo, @RequestParam Boolean enable,
@RequestParam String reason, @RequestParam String content) {
if (StringUtils.isBlank(phoneNo) || StringUtils.isBlank(reason)) {
return JsonResult.buildErrorStateResult("参数有误", null);
}
//密文
if (null != content) {
content = content.replaceAll(" ", "+");
}
String str = AESUtil.decryptAfterBase64Decode(content, Constants.AES_KEY);
if (null == str || !str.equals(phoneNo)) {
return JsonResult.buildErrorStateResult("解密有误", null);
}
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
LOGGER.info("用户手机号错误, phoneNo:{}", phoneNo);
return JsonResult.buildErrorStateResult("用户手机号错误", null);
}
int affectedRows=userService.forbiddenUser(enable, phoneNo);
LOGGER.info("禁用或者重启用户的理由,reason:{},手机号phoneNo:{},受影响的行数affectedRows:{}", reason, phoneNo,affectedRows);
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
builder.put("phoneNo", phoneNo);
builder.put("enable", String.valueOf(enable));
builder.put("reason", reason);
builder.put("content", content);
LOGGER.info("去清除函谷关的缓存");
Map<String, String> param = builder.build();
httpService.get(hanguguanUrl.concat("/innerapi/forbiddenUserOrNot"), param);
return JsonResult.buildSuccessResult("用户禁用或重启成功成功", affectedRows);
}
} }
\ No newline at end of file
...@@ -39,4 +39,9 @@ public interface IUserDetailRepository extends JpaRepository<UserDetail, Long>,J ...@@ -39,4 +39,9 @@ public interface IUserDetailRepository extends JpaRepository<UserDetail, Long>,J
@Modifying @Modifying
@Query(value = "select * from user_detail where gender!=1 and gender!=2 and id_no is not null", nativeQuery = true) @Query(value = "select * from user_detail where gender!=1 and gender!=2 and id_no is not null", nativeQuery = true)
List<UserDetail> selectUserDetailsBy(); List<UserDetail> selectUserDetailsBy();
@Transactional
@Modifying
@Query(value = "update user_detail set name=?1,id_no=?2,gender=?3 where phone_no=?4", nativeQuery = true)
int updateIdNoByPhoneNo(String name, String idNo, String gender, String phoneNo);
} }
...@@ -3,7 +3,9 @@ package cn.quantgroup.xyqb.repository; ...@@ -3,7 +3,9 @@ package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
...@@ -23,4 +25,9 @@ public interface IUserRepository extends JpaRepository<User, Long>, JpaSpecifica ...@@ -23,4 +25,9 @@ public interface IUserRepository extends JpaRepository<User, Long>, JpaSpecifica
@Query(value ="select * from user where created_at>=?1 and created_at<?2 ", nativeQuery = true) @Query(value ="select * from user where created_at>=?1 and created_at<?2 ", nativeQuery = true)
List<User> findRegisterUserByTime(String beginTime,String endTime); List<User> findRegisterUserByTime(String beginTime,String endTime);
@Transactional
@Modifying
@Query(value = "update user set enable=?1 where phone_no=?2", nativeQuery = true)
int forbiddenUser(Boolean enable, String phoneNo);
} }
...@@ -18,5 +18,5 @@ public interface IWeChatUserRepository extends JpaRepository<WechatUserInfo, Lon ...@@ -18,5 +18,5 @@ public interface IWeChatUserRepository extends JpaRepository<WechatUserInfo, Lon
@Transactional @Transactional
@Modifying @Modifying
void removeByUserId(Long userId); int removeByUserId(Long userId);
} }
...@@ -36,4 +36,14 @@ public interface IUserDetailService { ...@@ -36,4 +36,14 @@ public interface IUserDetailService {
*/ */
void fixedIdNoAndGender(); void fixedIdNoAndGender();
/**
* 更新用户的身份证号
*
* @param name name
* @param idNo idNo
* @param phoneNo phoneNo
* @return 受影响的行数
*/
int updateIdCard(String name, String idNo, String phoneNo);
} }
...@@ -70,4 +70,11 @@ public interface IUserService { ...@@ -70,4 +70,11 @@ public interface IUserService {
List<User> findRegisterUserByTime(String beginTime,String endTime); List<User> findRegisterUserByTime(String beginTime,String endTime);
/**
* 禁用用户
*
* @param phoneNo 电话号码
*/
int forbiddenUser(Boolean enable,String phoneNo);
} }
package cn.quantgroup.xyqb.service.user.impl; package cn.quantgroup.xyqb.service.user.impl;
import cn.quantgroup.xyqb.controller.ExceptionHandlingController;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail; import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.model.Gender; import cn.quantgroup.xyqb.model.Gender;
import cn.quantgroup.xyqb.model.UserQueryInfo;
import cn.quantgroup.xyqb.repository.IUserDetailRepository; import cn.quantgroup.xyqb.repository.IUserDetailRepository;
import cn.quantgroup.xyqb.repository.IUserRepository; import cn.quantgroup.xyqb.repository.IUserRepository;
import cn.quantgroup.xyqb.service.auth.IIdCardService; import cn.quantgroup.xyqb.service.auth.IIdCardService;
...@@ -20,7 +18,6 @@ import javax.persistence.criteria.CriteriaBuilder; ...@@ -20,7 +18,6 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.transaction.Transactional;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -29,7 +26,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -29,7 +26,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -205,4 +201,22 @@ public class UserDetailServiceImpl implements IUserDetailService { ...@@ -205,4 +201,22 @@ public class UserDetailServiceImpl implements IUserDetailService {
LOGGER.info("修复用户老数据身份证号完成"); LOGGER.info("修复用户老数据身份证号完成");
} }
} }
@Override
public int updateIdCard(String name, String idNo, String phoneNo) {
String lastChar = "";
if (idNo.length() == 18) {
lastChar = idNo.substring(16, 17).toLowerCase();
} else if (idNo.length() == 15) {
lastChar = idNo.substring(13, 14).toLowerCase();
}
// 判断男女
if (Integer.parseInt(lastChar) % 2 == 0) {
//女
return userDetailRepository.updateIdNoByPhoneNo(name, idNo, "1", phoneNo);
} else {
//男
return userDetailRepository.updateIdNoByPhoneNo(name, idNo, "2", phoneNo);
}
}
} }
...@@ -396,4 +396,11 @@ public class UserServiceImpl implements IUserService { ...@@ -396,4 +396,11 @@ public class UserServiceImpl implements IUserService {
count++; count++;
} }
} }
@Override
@CacheEvict(value = "usercache", key = "'xyqbuser' + #phoneNo", cacheManager = "cacheManager")
public int forbiddenUser(Boolean enable, String phoneNo) {
return userRepository.forbiddenUser(enable, phoneNo);
}
} }
...@@ -19,5 +19,5 @@ public interface IWechatService { ...@@ -19,5 +19,5 @@ public interface IWechatService {
WechatUserInfo queryOpenIdByUserId(Long userId); WechatUserInfo queryOpenIdByUserId(Long userId);
void forbiddenUserWeChat(Long userId); int forbiddenUserWeChat(Long userId);
} }
...@@ -141,7 +141,7 @@ public class WechatServiceImpl implements IWechatService { ...@@ -141,7 +141,7 @@ public class WechatServiceImpl implements IWechatService {
@Override @Override
public void forbiddenUserWeChat(Long userId) { public int forbiddenUserWeChat(Long userId) {
weChatUserRepository.removeByUserId(userId); return weChatUserRepository.removeByUserId(userId);
} }
} }
...@@ -26,45 +26,7 @@ public class AESUtil { ...@@ -26,45 +26,7 @@ public class AESUtil {
/** /**
* 编码格式 * 编码格式
*/ */
private static final String data_encoding = "utf-8"; private static final String DATA_ENCODING = "utf-8";
/**
* 数据加密
* @param data 待加密的数据
* @param key 加密使用的KEY
* @return 加密之后的数据
*/
public static String encryptAndBase64Encode(String data, String key) {
try {
return encryptAndBase64Encode(data.getBytes(data_encoding), key);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 对字节数组加密
* @param data
* @param key
* @return
*/
public static String encryptAndBase64Encode(byte[] data, String key) {
try {
if (key == null || "".equals(key.trim().length())) {
return null;
}
byte[] raw = key.getBytes(data_encoding);
SecretKeySpec skeySpec = new SecretKeySpec(raw, KEY_ALGORITHM);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(data);
return new Base64().encodeToString(encrypted);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/** /**
* 数据解密,返回字符串 * 数据解密,返回字符串
...@@ -76,7 +38,7 @@ public class AESUtil { ...@@ -76,7 +38,7 @@ public class AESUtil {
try { try {
byte[] bytes = decryptAfterBase64DecodeToByte(data, key); byte[] bytes = decryptAfterBase64DecodeToByte(data, key);
if (bytes != null && bytes.length > 0){ if (bytes != null && bytes.length > 0){
return new String(bytes, data_encoding); return new String(bytes, DATA_ENCODING);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -95,7 +57,7 @@ public class AESUtil { ...@@ -95,7 +57,7 @@ public class AESUtil {
if (key == null || "".equals(key.trim().length())) { if (key == null || "".equals(key.trim().length())) {
return null; return null;
} }
byte[] raw = key.getBytes(data_encoding); byte[] raw = key.getBytes(DATA_ENCODING);
SecretKeySpec skeySpec = new SecretKeySpec(raw, KEY_ALGORITHM); SecretKeySpec skeySpec = new SecretKeySpec(raw, KEY_ALGORITHM);
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, skeySpec); cipher.init(Cipher.DECRYPT_MODE, skeySpec);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment