Commit 24a01bee authored by lee_mingzhu's avatar lee_mingzhu

删除切面逻辑,只打印获取到的用户请求IP

parent 69409ec4
package cn.quantgroup.xyqb.controller.external.user.center;
import cn.quantgroup.xyqb.entity.*;
import cn.quantgroup.xyqb.model.AddressRet;
import cn.quantgroup.xyqb.model.ContactRet;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.user.*;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -11,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -45,6 +51,9 @@ public class UserCenterController {
@RequestMapping("/index")
public JsonResult userCenterIndex(String phoneNo) {
Long userId = queryUserId(phoneNo);
if(null == userId || userId == 0L) {
return JsonResult.buildErrorStateResult(null, null);
}
UserAttached userAttached = userCenterService.searchUserAttachedByUserId(userId);
Map<String, String> result = new HashMap<>();
if(userAttached != null) {
......@@ -66,15 +75,14 @@ public class UserCenterController {
*/
@RequestMapping("/save/avatar")
public JsonResult SaveUserAvatarAddr(String phoneNo, String avatarUrl) {
/*if(null == phoneNo || userId == 0) {
LOGGER.error("用户修改头像、昵称,用户id未获取到:{}", userId);
return JsonResult.buildErrorStateResult("参数不完整,请校验参数.", null);
}*/
if(StringUtils.isEmpty(avatarUrl) || StringUtils.isEmpty(phoneNo)) {
LOGGER.error("参数不合法:avatarUrl:{}, phoneNo:{}", avatarUrl, phoneNo);
return JsonResult.buildErrorStateResult("参数不合法", null);
}
Long userId = queryUserId(phoneNo);
if(null == userId || userId == 0L) {
return JsonResult.buildErrorStateResult(null, null);
}
UserAttached userAttached = userCenterService.searchUserAttachedByUserId(userId);
//查询到数据,直接更新头像和更新时间
if(null != userAttached) {
......@@ -103,6 +111,9 @@ public class UserCenterController {
return JsonResult.buildErrorStateResult("参数不合法", null);
}
Long userId = queryUserId(phoneNo);
if(null == userId || userId == 0L) {
return JsonResult.buildErrorStateResult(null, null);
}
UserAttached userAttached = userCenterService.searchUserAttachedByUserId(userId);
if(null != userAttached) {
LOGGER.info("获取用户昵称:{}", userAttached.getNick());
......@@ -124,6 +135,9 @@ public class UserCenterController {
return JsonResult.buildErrorStateResult("参数不合法", null);
}
Long userId = queryUserId(phoneNo);
if(null == userId || userId == 0L) {
return JsonResult.buildErrorStateResult(null, null);
}
UserAttached userAttached = userCenterService.searchUserAttachedByUserId(userId);
if(null == userAttached) {
userAttached = createUserAttached(userId, "", nick);
......@@ -147,6 +161,9 @@ public class UserCenterController {
return JsonResult.buildErrorStateResult("参数不合法", null);
}
Long userId = queryUserId(phoneNo);
if(null == userId || userId == 0L) {
return JsonResult.buildErrorStateResult(null, null);
}
UserDetail userDetail = userDetailService.findByUserId(userId);
if(null != userDetail) {
return JsonResult.buildSuccessResult(null, userDetail);
......@@ -166,6 +183,9 @@ public class UserCenterController {
return JsonResult.buildErrorStateResult("参数不合法", null);
}
Long userId = queryUserId(phoneNo);
if(null == userId || userId == 0L) {
return JsonResult.buildErrorStateResult(null, null);
}
UserExtInfo userExtInfo = userExtInfoService.findByUserId(userId);
List<Contact> contacts = contactService.findByUserId(userId);
Map<String, Object> result = new HashMap<>();
......@@ -185,6 +205,137 @@ public class UserCenterController {
return JsonResult.buildSuccessResult(null, result);
}
/**
* 保存用户联系人,
* @param phoneNo 用户手机号
* @param contactJson 要保存的联系人json串
* @return
*/
@RequestMapping("/save/contacts")
public JsonResult saveUserContact(String phoneNo, String contactJson) {
if(StringUtils.isEmpty(phoneNo)) {
LOGGER.error("保存联系人,参数错误. phoneNo:{}", phoneNo);
return JsonResult.buildErrorStateResult("参数有误.", null);
}
Long userId = queryUserId(phoneNo);
if(null == userId || userId == 0L) {
LOGGER.error("保存联系人,未获取到用户id. userId:{}", userId);
return JsonResult.buildErrorStateResult(null, null);
}
if(StringUtils.isEmpty(contactJson)) {
LOGGER.error("保存联系人,联系人参数为空.contactJson:{}", contactJson);
return JsonResult.buildErrorStateResult(null, null);
}
List<Contact> userContact = contactService.findByUserId(userId);
if(userContact != null && userContact.size() >= 2) {
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(userContact));
}
List<Contact> contacts = JSONObject.parseObject(contactJson, new TypeReference<List<Contact>>() {});
if (CollectionUtils.isEmpty(contacts)) {
return JsonResult.buildErrorStateResult(null, null);
}
Timestamp now = new Timestamp(System.currentTimeMillis());
for (Contact c : contacts) {
c.setId(null);
c.setUserId(userId);
c.setCreatedAt(now);
c.setUpdateAt(now);
}
List<Contact> result = contactService.save(contacts);
return JsonResult.buildSuccessResult(null, result);
}
/**
* 保存用户住址信息
* @param province
* @param provinceCode
* @param city
* @param cityCode
* @param address
* @return
*/
@RequestMapping("/address/save")
public JsonResult saveUserAddress(String phoneNo, String province, Long provinceCode, String city, Long cityCode, String address) {
LOGGER.info("保存用户地址信息, phoneNo:{}, province:{}, provinceCode:{}, city:{}, cityCode:{}", phoneNo, province, provinceCode, city, cityCode);
if (StringUtils.isEmpty(phoneNo) || provinceCode == null || cityCode == null) {
return JsonResult.buildErrorStateResult(null, null);
}
Long userId = queryUserId(phoneNo);
if(null == userId || userId == 0L) {
LOGGER.error("保存联系人,未获取到用户id. userId:{}", userId);
return JsonResult.buildErrorStateResult(null, null);
}
//查询用户是否有保存地址信息
Address addressInfo = addressService.findByUserId(userId);
if(null == address) {
Timestamp now = new Timestamp(System.currentTimeMillis());
addressInfo = new Address();
addressInfo.setCreatedAt(now);
addressInfo.setUpdateAt(now);
}
addressInfo.setUserId(userId);
addressInfo.setProvince(province);
addressInfo.setProvinceCode(provinceCode);
addressInfo.setCity(city);
addressInfo.setCityCode(cityCode);
addressInfo.setAddress(address);
//更新时间
addressInfo.setUpdateAt(new Timestamp(System.currentTimeMillis()));
addressService.saveAddress(addressInfo);
return JsonResult.buildSuccessResult(null, address);
}
/**
* 查询用户住址信息
* @param phoneNo
* @return
*/
@RequestMapping("/searchAddress/phoneNo")
public JsonResult searchUserAddress(String phoneNo) {
if(StringUtils.isEmpty(phoneNo)) {
return JsonResult.buildErrorStateResult(null, null);
}
Long userId = queryUserId(phoneNo);
if(null == userId || userId == 0L) {
LOGGER.error("保存联系人,未获取到用户id. userId:{}", userId);
return JsonResult.buildErrorStateResult(null, null);
}
Address address = addressService.findByUserId(userId);
if (address == null) {
return JsonResult.buildErrorStateResult(null, null);
}
return JsonResult.buildSuccessResult(null, address);
}
/**
* 查询用户联系人
* @param phoneNo
* @return
*/
@RequestMapping("/searchContacts/phoneNo")
public JsonResult searchUserContacts(String phoneNo) {
if(StringUtils.isEmpty(phoneNo)) {
return JsonResult.buildErrorStateResult(null, null);
}
Long userId = queryUserId(phoneNo);
if(null == userId || userId == 0L) {
LOGGER.error("保存联系人,未获取到用户id. userId:{}", userId);
return JsonResult.buildErrorStateResult(null, null);
}
List<Contact> contacts = contactService.findByUserId(userId);
if(null == contacts || contacts.size() == 0) {
return JsonResult.buildErrorStateResult(null, Collections.emptyList());
}
return JsonResult.buildSuccessResult(null, contacts);
}
/**
* 创建用户附加信息实体
* @param userId
* @param avatar
* @param nick
* @return
*/
private UserAttached createUserAttached(Long userId, String avatar, String nick) {
UserAttached userAttached = new UserAttached();
Timestamp now = new Timestamp(System.currentTimeMillis());
......@@ -204,6 +355,6 @@ public class UserCenterController {
*/
private Long queryUserId(String phoneNo) {
User user = userService.findByPhoneInDb(phoneNo);
return user.getId();
return null == user ? null : user.getId();
}
}
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