Commit 45a4206c authored by 技术部-任文超's avatar 技术部-任文超

完成用户激活、禁用的内部免密调用接口开发

parent 72b4c6a5
......@@ -28,6 +28,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
......@@ -51,12 +52,11 @@ import java.util.stream.Collectors;
/**
* Created by Miraculous on 2016/12/19.
*/
@Slf4j
@RestController
@RequestMapping("/innerapi")
public class InnerController implements IBaseController {
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(InnerController.class);
@Autowired
private IMerchantService merchantService;
@Autowired
......@@ -131,7 +131,7 @@ public class InnerController implements IBaseController {
@LogHttpCaller
@RequestMapping("/userInfo/search/uuid")
public JsonResult findUserInfoByUuid(@RequestParam(value = "uuid") String uuid) {
LOGGER.info("需要查询的用户uuidid, uuid:" + uuid);
log.info("需要查询的用户uuidid, uuid:" + uuid);
if (StringUtils.isBlank(uuid)) {
return JsonResult.buildSuccessResult(null, null);
......@@ -151,7 +151,7 @@ public class InnerController implements IBaseController {
@LogHttpCaller
@RequestMapping("/userInfo/search/phone")
public JsonResult findUserInfoByPhone(@RequestParam(value = "phone") String phone) {
LOGGER.info("需要查询的用户phone, phone:" + phone);
log.info("需要查询的用户phone, phone:" + phone);
if (StringUtils.isBlank(phone)) {
return JsonResult.buildSuccessResult(null, null);
......@@ -171,7 +171,7 @@ public class InnerController implements IBaseController {
@LogHttpCaller
@RequestMapping("/user/getPhoneByUserIds")
public JsonResult findByIds(@RequestParam(value = "userIds") String userIdsString) {
LOGGER.info("批量查询用户的手机号列表, userIdsString:" + userIdsString);
log.info("批量查询用户的手机号列表, userIdsString:" + userIdsString);
if (StringUtils.isEmpty(userIdsString)) {
return JsonResult.buildErrorStateResult(null, null);
}
......@@ -190,7 +190,7 @@ public class InnerController implements IBaseController {
public JsonResult saveUser(
String phoneNo, Long registeredFrom, Long createdAt, Long updatedAt,
String password, String uuid) {
LOGGER.info("保存用户,phoneNo:{},registeredFrom;{},uuid:{},createdAt:{},updatedAt:{}", phoneNo, registeredFrom, uuid,createdAt,updatedAt);
log.info("保存用户,phoneNo:{},registeredFrom;{},uuid:{},createdAt:{},updatedAt:{}", phoneNo, registeredFrom, uuid,createdAt,updatedAt);
//参数验证
if (StringUtils.isBlank(phoneNo)) {
return JsonResult.buildErrorStateResult("用户手机号不能为空.", null);
......@@ -212,7 +212,7 @@ public class InnerController implements IBaseController {
if (user == null) {
user = new User();
} else if (!user.getEnable()) {
LOGGER.info("用户已经注销,phoneNo:{}", phoneNo);
log.info("用户已经注销,phoneNo:{}", phoneNo);
return JsonResult.buildErrorStateResult("用户已经注销", null);
}
if (org.apache.commons.lang.StringUtils.isEmpty(user.getUuid())) {
......@@ -241,7 +241,7 @@ public class InnerController implements IBaseController {
@RequestMapping("/user_detail/save")
public JsonResult saveUserDetail(Long userId, String phoneNo, String name, String idNo,
String email, String qq) {
LOGGER.info("保存用户详细信息,[saveUserDetail] userId:{},phoneNo:{},name:{},idNo:{},email:{},qq:{}", userId, phoneNo, name, idNo, email, qq);
log.info("保存用户详细信息,[saveUserDetail] userId:{},phoneNo:{},name:{},idNo:{},email:{},qq:{}", userId, phoneNo, name, idNo, email, qq);
//参数验证
if (userId == null || userId == 0L) {
return JsonResult.buildErrorStateResult("用户id为空.", null);
......@@ -262,7 +262,7 @@ public class InnerController implements IBaseController {
try {
info = idCardService.getIdCardInfo(idNo);
} catch (ParseException ex) {
LOGGER.error("用户身份证号错误, idNo: {}", idNo);
log.error("用户身份证号错误, idNo: {}", idNo);
}
if (Objects.isNull(info) || !info.isValid()) {
return JsonResult.buildErrorStateResult("身份证号码错误", null);
......@@ -352,12 +352,12 @@ public class InnerController implements IBaseController {
@RequestMapping("/user_full_info/search/phone")
public JsonResult findUserFullInfoByPhone(String phoneNo) {
if (StringUtils.isBlank(phoneNo)) {
LOGGER.warn("[findUserFullInfoByPhone]phoneNo为空");
log.warn("[findUserFullInfoByPhone]phoneNo为空");
return JsonResult.buildErrorStateResult(null, null);
}
Optional<UserFullInfo> userFullInfoOptional = userApiService.getUserFullInfoByPhone(phoneNo);
if (!userFullInfoOptional.isPresent()) {
LOGGER.warn("[findUserFullInfoByPhone]没有用户信息,phoneNo={}", MD5Util.build(phoneNo));
log.warn("[findUserFullInfoByPhone]没有用户信息,phoneNo={}", MD5Util.build(phoneNo));
return JsonResult.buildErrorStateResult(null, null);
}
return JsonResult.buildSuccessResult(null, userFullInfoOptional.get());
......@@ -373,12 +373,12 @@ public class InnerController implements IBaseController {
@RequestMapping("/user_full_info/search/uuid")
public JsonResult findUserFullInfoByUUuid(String uuid) {
if (StringUtils.isBlank(uuid)) {
LOGGER.warn("[findUserFullInfoByUUuid]uuid为空");
log.warn("[findUserFullInfoByUUuid]uuid为空");
return JsonResult.buildErrorStateResult(null, null);
}
Optional<UserFullInfo> userFullInfoOptional = userApiService.getUserFullInfoByUuid(uuid);
if (!userFullInfoOptional.isPresent()) {
LOGGER.warn("[findUserFullInfoByUUuid]没有用户信息,uuid={}", uuid);
log.warn("[findUserFullInfoByUUuid]没有用户信息,uuid={}", uuid);
return JsonResult.buildErrorStateResult(null, null);
}
return JsonResult.buildSuccessResult(null, userFullInfoOptional.get());
......@@ -411,18 +411,18 @@ public class InnerController implements IBaseController {
@RequestMapping("/contact/save/contacts")
public JsonResult save2Contact(Long userId, @RequestParam(value = "contacts") String contactsStr) {
if (Objects.isNull(userId) || StringUtils.isBlank(contactsStr)) {
LOGGER.warn("保存用户联系人:参数不完整:userId:{}, contacts:{}", userId, contactsStr);
log.warn("保存用户联系人:参数不完整:userId:{}, contacts:{}", userId, contactsStr);
return JsonResult.buildErrorStateResult("参数不完整", String.valueOf(userId).concat(":").concat(contactsStr));
}
LOGGER.info("保存用户联系人:userId:{}, contacts:{}", userId, contactsStr);
log.info("保存用户联系人:userId:{}, contacts:{}", userId, contactsStr);
List<Contact> contacts = JSONObject.parseObject(contactsStr, new TypeReference<List<Contact>>(){});
if (CollectionUtils.isEmpty(contacts)) {
LOGGER.info("联系人不能为空");
log.info("联系人不能为空");
return JsonResult.buildErrorStateResult("联系人不能为空", contacts);
}
for (Contact contact : contacts) {
if (!contact.valid()) {
LOGGER.info("用户手机号或姓名错误, phoneNo:{},name:{}", contact.getPhoneNo(), contact.getName());
log.info("用户手机号或姓名错误, phoneNo:{},name:{}", contact.getPhoneNo(), contact.getName());
return JsonResult.buildErrorStateResult("用户手机号或姓名错误", contact);
}
}
......@@ -444,11 +444,11 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("修改联系人修改条件不能都为空", null);
}
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
LOGGER.info("用户手机号错误, phoneNo:{}", phoneNo);
log.info("用户手机号错误, phoneNo:{}", phoneNo);
return JsonResult.buildErrorStateResult("用户手机号错误", null);
}
if (!ValidationUtil.validateChinese(name)) {
LOGGER.info("用户姓名错误, name:{}", name);
log.info("用户姓名错误, name:{}", name);
return JsonResult.buildErrorStateResult("用户姓名错误", null);
}
if (StringUtils.isEmpty(reason)) {
......@@ -459,7 +459,7 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("修改联系人不存在", null);
}
contact = contactService.saveContact(name, phoneNo, relation, contact);
LOGGER.info("修改后联系人信息:{},修改原因:{},操作ip:{}", contact, reason, IPUtil.getRemoteIP(request));
log.info("修改后联系人信息:{},修改原因:{},操作ip:{}", contact, reason, IPUtil.getRemoteIP(request));
return JsonResult.buildSuccessResult("修改联系人成功", contact);
}
......@@ -482,9 +482,9 @@ public class InnerController implements IBaseController {
public JsonResult saveAddress(
Long userId, Long provinceCode, Long cityCode, String city,
Long districtCode, String district, String address, String province) {
LOGGER.info("保存地址详情:city:{},province:{},district:{}, address:{},userId:{}", city, province, district, address, userId);
log.info("保存地址详情:city:{},province:{},district:{}, address:{},userId:{}", city, province, district, address, userId);
if (userId == null || provinceCode == null || cityCode == null || StringUtils.isBlank(address)) {
LOGGER.info("错误保存地址详情,其中参数不能为空:city:{},province:{},district:{}, address:{},userId:{}", city, province, district, address, userId);
log.info("错误保存地址详情,其中参数不能为空:city:{},province:{},district:{}, address:{},userId:{}", city, province, district, address, userId);
return JsonResult.buildErrorStateResult("参数不能为空", null);
}
Address addressObj = addressService.findByUserId(userId);
......@@ -507,7 +507,7 @@ public class InnerController implements IBaseController {
addressObj.setAddress(EmojiUtil.filterUnicode4(address));
}
addressObj = addressService.save(addressObj);
LOGGER.info("保存后地址详情:{}", addressObj);
log.info("保存后地址详情:{}", addressObj);
return JsonResult.buildSuccessResult(null, AddressRet.address2AddressRet(addressObj));
}
......@@ -566,7 +566,7 @@ public class InnerController implements IBaseController {
@RequestMapping("/user_detail/search_list")
public JsonResult searchUserDetailList(String name, String phoneNo, String idNo) {
LOGGER.info("searchUserDetailList ,param.name:{},phone:{},idNo:{},ip:{}", name, phoneNo, idNo, getIp());
log.info("searchUserDetailList ,param.name:{},phone:{},idNo:{},ip:{}", name, phoneNo, idNo, getIp());
if (StringUtils.isBlank(name) && StringUtils.isBlank(phoneNo) && StringUtils.isBlank(idNo)) {
return JsonResult.buildErrorStateResult("至少必须满足一个条件不为空", null);
}
......@@ -588,7 +588,7 @@ public class InnerController implements IBaseController {
String s = httpService.get(queryUrl.concat("/innerapi/user_detail/search_list"), param);
boolean isJson = StringUtils.isNotBlank(s) && s.trim().startsWith("{") && s.trim().endsWith("}");
if(!isJson){
LOGGER.warn("用户详情信息查询结果不完整:{}", s);
log.warn("用户详情信息查询结果不完整:{}", s);
JsonResult.buildErrorStateResult("数据不完整", s);
}
return JSON.parseObject(s, JsonResult.class);
......@@ -614,7 +614,7 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("userId不能为空", null);
}
WechatUserInfo wechatUserInfo = wechatService.queryByUserId(userId);
LOGGER.info("根据用户userId查询:微信关联:userId:{},WechatUserInfo:{}", userId, wechatUserInfo);
log.info("根据用户userId查询:微信关联:userId:{},WechatUserInfo:{}", userId, wechatUserInfo);
if (wechatUserInfo == null) {
return JsonResult.buildErrorStateResult(null, null);
}
......@@ -835,25 +835,55 @@ public class InnerController implements IBaseController {
return JsonResult.buildSuccessResult(null, null == wechatUserInfo ? null : wechatUserInfo.getOpenId());
}
/**
* 激活/启用 用户
* @param userId
* @return
*/
@LogHttpCaller
@RequestMapping("/user/active")
public JsonResult activeUser(Long userId) {
boolean flushed = flushUserStatus(userId, true);
return JsonResult.buildSuccessResult("用户已激活.", flushed);
}
/**
* 注销/禁用 用户
* @param userId
* @return
*/
@LogHttpCaller
@RequestMapping("/user/disable")
public JsonResult disableUser(Long userId) {
public JsonResult forbiddenUser(Long userId) {
boolean flushed = flushUserStatus(userId, false);
return JsonResult.buildSuccessResult("用户已禁用.", flushed);
}
/**
* 刷新用户激活状态
* @param userId - 用户主键
* @param enable - 用户激活状态
* @return
*/
private boolean flushUserStatus(Long userId, boolean enable) {
if (null == userId || 0L == userId) {
return JsonResult.buildErrorStateResult("userId不能为空", null);
log.info("刷新用户激活状态失败:userId:{},enable:{}", userId, enable);
return false;
}
User user = userService.findById(userId);
if (null == user) {
return JsonResult.buildErrorStateResult("未查询到该用户,用户id:" + userId, null);
log.info("刷新用户激活状态失败:userId:{},enable:{},user:{}", userId, enable, user);
return false;
}
user.setEnable(false);
user.setEnable(enable);
user.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
LOGGER.info("注销用户的信息,userId={}", userId);
log.info("刷新用户激活状态失败:userId:{},enable:{},user:{}", userId, enable, user);
user = userService.saveUser(user);
if (!user.getEnable()) {
sessionService.deleteByUserId(userId);
sessionService.deleteUserCatch(user);
}
return JsonResult.buildSuccessResult("用户已禁用.", user.getEnable() == false);
return Objects.equals(enable, user.getEnable());
}
/**
......@@ -873,7 +903,7 @@ public class InnerController implements IBaseController {
}
sessionService.deleteByUserId(user.getId());
sessionService.deleteUserCatch(user);
LOGGER.info("删除用户缓存信息,phoneNo:{},userId:{},", user.getPhoneNo(), user.getId());
log.info("删除用户缓存信息,phoneNo:{},userId:{},", user.getPhoneNo(), user.getId());
return JsonResult.buildSuccessResult("用户缓存信息已经删除", null);
}
......@@ -959,19 +989,19 @@ public class InnerController implements IBaseController {
@LogHttpCaller
@RequestMapping("/user/password/reset/{key}/{phone}")
public JsonResult resetPassword(@PathVariable("key") String key, @PathVariable("phone") String phone) {
LOGGER.info("密码重置请求,phone:[{}]", phone);
log.info("密码重置请求,phone:[{}]", phone);
if (StringUtils.isBlank(key)) {
return JsonResult.buildErrorStateResult("用户密码重置失败.", null);
}
if (!"ecf75c1f-2ccb-4661-8e4b-2874c0f45a2b".equalsIgnoreCase(key)) {
LOGGER.error("密码重置失败,key错误!@!,phone:[{}]", phone);
log.error("密码重置失败,key错误!@!,phone:[{}]", phone);
return JsonResult.buildErrorStateResult("用户密码重置失败.", null);
}
try {
userService.resetPassword(phone, "123456"); //默认重置的密码是123456
return JsonResult.buildSuccessResult("用户密码已重置.", "null");
} catch (Exception e) {
LOGGER.error("密码重置失败,phone[{}],err:[{}]", phone, e);
log.error("密码重置失败,phone[{}],err:[{}]", phone, e);
}
return JsonResult.buildErrorStateResult("用户密码重置失败.", null);
}
......@@ -995,7 +1025,7 @@ public class InnerController implements IBaseController {
String district,
String address,
String contacts, @RequestParam(defaultValue = "0", required = false) Long btRegisterChannelId) {
LOGGER.info("[/innerapi/user/save_multi]保存用户、联系人、地址信息:registeredFrom:[{}], phoneNo[{}],name[{}],idNo[{}],provinceCode[{}],cityCode[{}],districtCode[{}]," +
log.info("[/innerapi/user/save_multi]保存用户、联系人、地址信息:registeredFrom:[{}], phoneNo[{}],name[{}],idNo[{}],provinceCode[{}],cityCode[{}],districtCode[{}]," +
"address[{}],contacts[{}]", registeredFrom, phoneNo, name, idNo, provinceCode, cityCode, districtCode, address, contacts);
if (!NumberUtils.isDigits(registeredFrom)) {
......@@ -1058,7 +1088,7 @@ public class InnerController implements IBaseController {
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
return JsonResult.buildErrorStateResult("手机号不正确", null);
}
LOGGER.info("[/innerapi/user/register]channelId={},ip={}", channelId, getIp());
log.info("[/innerapi/user/register]channelId={},ip={}", channelId, getIp());
User user = userService.findByPhoneInDb(phoneNo);
if (user == null) {
user = userRegisterService.register(phoneNo, StringUtils.defaultString(password, ""), channelId);
......@@ -1095,7 +1125,7 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("解密有误", null);
}
int affectedRows = wechatService.forbiddenUserWeChat(userId);
LOGGER.info("用户微信禁用,userId:{},禁用的原因reason:{},受影响的行数affectedRows:{}", userId, reason, affectedRows);
log.info("用户微信禁用,userId:{},禁用的原因reason:{},受影响的行数affectedRows:{}", userId, reason, affectedRows);
return JsonResult.buildSuccessResult("用户禁用微信成功", affectedRows);
}
......@@ -1118,11 +1148,11 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("参数有误", null);
}
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
LOGGER.info("手机号有误, phoneNo:{}", phoneNo);
log.info("手机号有误, phoneNo:{}", phoneNo);
return JsonResult.buildErrorStateResult("用户手机号错误", null);
}
int affectedRows = userDetailService.updateIdCard(name, idNo, phoneNo);
LOGGER.info("更新用户的信息,name;{},idNo:{},phoneNo:{},操作的理由reason:{},受影响的行数affectedRows:{}", name, idNo, phoneNo, reason, affectedRows);
log.info("更新用户的信息,name;{},idNo:{},phoneNo:{},操作的理由reason:{},受影响的行数affectedRows:{}", name, idNo, phoneNo, reason, affectedRows);
return JsonResult.buildSuccessResult("修改用户身份证号或姓名成功", affectedRows);
}
......@@ -1139,16 +1169,16 @@ public class InnerController implements IBaseController {
}
String str = AESUtil.decryptAfterBase64Decode(content, Constants.AES_KEY);
if (null == str || !str.equals(phoneNo)) {
LOGGER.info("[forbiddenUserOrNot][禁用或激活用户]:解密有误, phoneNo:{},aes:{}", phoneNo, AESUtil.encryptAndBase64Encode(phoneNo, Constants.AES_KEY));
log.info("[forbiddenUserOrNot][禁用或激活用户]:解密有误, phoneNo:{},aes:{}", phoneNo, AESUtil.encryptAndBase64Encode(phoneNo, Constants.AES_KEY));
return JsonResult.buildErrorStateResult("解密有误", null);
}
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
LOGGER.info("[forbiddenUserOrNot][禁用或激活用户]:用户手机号错误, phoneNo:{}", phoneNo);
log.info("[forbiddenUserOrNot][禁用或激活用户]:用户手机号错误, phoneNo:{}", phoneNo);
return JsonResult.buildErrorStateResult("用户手机号错误", null);
}
int affectedRows = userService.forbiddenUser(enable, phoneNo);
LOGGER.info("[forbiddenUserOrNot][禁用或激活用户]:理由:reason:{},手机号phoneNo:{},受影响的行数affectedRows:{}", reason, phoneNo, affectedRows);
log.info("[forbiddenUserOrNot][禁用或激活用户]:理由:reason:{},手机号phoneNo:{},受影响的行数affectedRows:{}", reason, phoneNo, affectedRows);
return JsonResult.buildSuccessResult("用户禁用或重启成功成功", affectedRows);
}
......@@ -1193,7 +1223,7 @@ public class InnerController implements IBaseController {
@RequestParam(required = false,defaultValue = "xyqb") String key,
@RequestParam(required = false)Long btRegisterChannelId,
@RequestParam(required = false) String dimension) {
LOGGER.info("/innerapi/verifyPhoneAndCode -> phoneNo:{},verificationCode:{},channelId:{},appChannel:{},createdFrom:{},btRegisterChannelId:{},key:{},dimension:{}",phoneNo,verificationCode,channelId,appChannel,createdFrom,btRegisterChannelId,key,dimension);
log.info("/innerapi/verifyPhoneAndCode -> phoneNo:{},verificationCode:{},channelId:{},appChannel:{},createdFrom:{},btRegisterChannelId:{},key:{},dimension:{}",phoneNo,verificationCode,channelId,appChannel,createdFrom,btRegisterChannelId,key,dimension);
// 验证接入方
Merchant merchant = merchantService.findMerchantByName(key);
if (merchant == null) {
......@@ -1201,7 +1231,7 @@ public class InnerController implements IBaseController {
}
// 验证手机号
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
LOGGER.info("验证手机号和验证码是否匹配,手机号错误, phoneNo:{}", phoneNo);
log.info("验证手机号和验证码是否匹配,手机号错误, phoneNo:{}", phoneNo);
return JsonResult.buildErrorStateResult("手机号错误", "");
}
// 验证短信验证码
......@@ -1210,13 +1240,13 @@ public class InnerController implements IBaseController {
if(smsService.needResendCode(phoneNo)){
return JsonResult.buildErrorStateResult("验证码失效,请重新获取", "");
}
LOGGER.info("验证码校验失败,phoneNo:{} , verificationCode:{}", phoneNo, verificationCode);
log.info("验证码校验失败,phoneNo:{} , verificationCode:{}", phoneNo, verificationCode);
return JsonResult.buildErrorStateResult("短信验证码错误", "");
}
User user = userService.findByPhoneWithCache(phoneNo);
// 检查用户有效性
if (user != null && !user.getEnable()) {
LOGGER.error("用户不存在,或者已经注销,phoneNo:{}",phoneNo);
log.error("用户不存在,或者已经注销,phoneNo:{}",phoneNo);
return JsonResult.buildErrorStateResult("登录失败", null);
}
// 用户不存在时自动注册
......@@ -1250,10 +1280,10 @@ public class InnerController implements IBaseController {
try {
bufPhoneNo = new String(byPhoneNo, "UTF-8");
} catch (UnsupportedEncodingException e) {
LOGGER.error("不支持的编码: ", e);
log.error("不支持的编码: ", e);
}
if (!ValidationUtil.validatePhoneNo(bufPhoneNo)) {
LOGGER.info("手机号错误, phoneNo:{}", bufPhoneNo);
log.info("手机号错误, phoneNo:{}", bufPhoneNo);
throw new UserNotExistException("手机号错误");
}
byte[] byPassword = Base64.decodeBase64(password);
......@@ -1261,7 +1291,7 @@ public class InnerController implements IBaseController {
try {
bufPassword = new String(byPassword, "UTF-8");
} catch (UnsupportedEncodingException e) {
LOGGER.error("不支持的编码: ", e);
log.error("不支持的编码: ", e);
}
User user = userService.findByPhoneWithCache(bufPhoneNo);
if (Objects.isNull(user) || Objects.equals(Boolean.FALSE, user.getEnable())) {
......
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