Commit 49a2aec5 authored by zhouqian's avatar zhouqian

refact some code.

parent 4ea75dad
......@@ -27,6 +27,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.weibo.api.motan.config.springsupport.annotation.MotanService;
import java.util.concurrent.ThreadLocalRandom;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -42,7 +43,7 @@ import java.util.stream.Collectors;
* Created by 11 on 2017/2/27.
*/
@Slf4j
@MotanService(export = "userMotan:8002", registry = "registryConfig")
@MotanService(basicService = "baseServiceConfig")
public class MotanUserServiceImpl implements UserMotanService {
private static final ObjectMapper MAPPER = new ObjectMapper();
private final static Random random = new Random();
......@@ -127,7 +128,7 @@ public class MotanUserServiceImpl implements UserMotanService {
@Override
public UserSysResult<XUserDetail> findUserDetailByUserId(Long userId) {
if (userId == null || userId.longValue() < 1) {
if (userId == null || userId < 1) {
return returnErrorValue("参数必须是正整数");
}
UserDetail userDetail = userDetailService.findByUserId(userId);
......@@ -136,49 +137,16 @@ public class MotanUserServiceImpl implements UserMotanService {
}
private XUserDetail fromUserDetail(UserDetail userDetail) {
if (userDetail == null) {
return null;
}
XUserDetail xUserDetail = new XUserDetail();
xUserDetail.setId(userDetail.getId());
xUserDetail.setUserId(userDetail.getUserId());
xUserDetail.setPhoneNo(userDetail.getPhoneNo());
xUserDetail.setName(userDetail.getName());
xUserDetail.setIdNo(userDetail.getIdNo());
if (userDetail.getIdType() != null) {
xUserDetail.setIdType(cn.quantgroup.motan.enums.IdType.valueOf(userDetail.getIdType().name()));
}
if (userDetail.getGender() != null) {
xUserDetail.setGender(cn.quantgroup.motan.enums.Gender.valueOf(userDetail.getGender().name()));
}
xUserDetail.setEmail(userDetail.getEmail());
xUserDetail.setQq(userDetail.getQq());
xUserDetail.setId(userDetail.getId());
xUserDetail.setCreatedAt(userDetail.getCreatedAt());
xUserDetail.setUpdatedAt(userDetail.getUpdatedAt());
xUserDetail.setIsAuthenticated(userDetail.getIsAuthenticated());
return xUserDetail;
return userDetail == null ? null : userDetail.toXUserDetail();
}
private XUser fromUser(User user) {
if (user == null) {
return null;
}
XUser xUser = new XUser();
xUser.setId(user.getId());
xUser.setPassword(user.getPassword());
xUser.setRegisteredFrom(user.getRegisteredFrom());
xUser.setUuid(user.getUuid());
xUser.setEnable(user.getEnable());
xUser.setPhoneNo(user.getPhoneNo());
xUser.setUpdatedAt(user.getUpdatedAt());
xUser.setCreatedAt(user.getCreatedAt());
return xUser;
return user == null ? null : user.toXUser();
}
@Override
public UserSysResult<XUser> findUserByUserId(Long id) {
if (id == null || id.longValue() < 1) {
if (id == null || id < 1) {
return returnErrorValue("参数必须是正整数");
}
User user = userService.findById(id);
......
......@@ -236,6 +236,12 @@ public class InnerController {
return JsonResult.buildErrorStateResult(null, null);
}
Timestamp now = new Timestamp(System.currentTimeMillis());
convertContactList(userId, contacts, now);
List<Contact> result = contactService.save(contacts);
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(result));
}
private void convertContactList(Long userId, List<Contact> contacts, Timestamp now) {
for (Contact c : contacts) {
c.setId(null);
c.setUserId(userId);
......@@ -243,8 +249,6 @@ public class InnerController {
c.setCreatedAt(now);
c.setUpdateAt(now);
}
List<Contact> result = contactService.save(contacts);
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(result));
}
@RequestMapping("/address/search/user_id")
......
package cn.quantgroup.xyqb.entity;
import cn.quantgroup.motan.retbean.XUser;
import cn.quantgroup.xyqb.config.http.Timestamp2LongConverter;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
......@@ -57,4 +58,18 @@ public class User implements Serializable {
private Timestamp updatedAt;
public XUser toXUser() {
XUser xUser = new XUser();
xUser.setId(this.getId());
xUser.setPassword(this.getPassword());
xUser.setRegisteredFrom(this.getRegisteredFrom());
xUser.setUuid(this.getUuid());
xUser.setEnable(this.getEnable());
xUser.setPhoneNo(this.getPhoneNo());
xUser.setUpdatedAt(this.getUpdatedAt());
xUser.setCreatedAt(this.getCreatedAt());
return xUser;
}
}
package cn.quantgroup.xyqb.entity;
import cn.quantgroup.motan.retbean.XUserDetail;
import cn.quantgroup.xyqb.model.Gender;
import cn.quantgroup.xyqb.model.IdType;
import lombok.Getter;
......@@ -66,5 +67,27 @@ public class UserDetail implements Serializable {
@Column(name = "updated_at")
private Timestamp updatedAt;
public XUserDetail toXUserDetail() {
XUserDetail xUserDetail = new XUserDetail();
xUserDetail.setId(this.getId());
xUserDetail.setUserId(this.getUserId());
xUserDetail.setPhoneNo(this.getPhoneNo());
xUserDetail.setName(this.getName());
xUserDetail.setIdNo(this.getIdNo());
if (this.getIdType() != null) {
xUserDetail.setIdType(cn.quantgroup.motan.enums.IdType.valueOf(this.getIdType().name()));
}
if (this.getGender() != null) {
xUserDetail.setGender(cn.quantgroup.motan.enums.Gender.valueOf(this.getGender().name()));
}
xUserDetail.setEmail(this.getEmail());
xUserDetail.setQq(this.getQq());
xUserDetail.setId(this.getId());
xUserDetail.setCreatedAt(this.getCreatedAt());
xUserDetail.setUpdatedAt(this.getUpdatedAt());
xUserDetail.setIsAuthenticated(this.getIsAuthenticated());
return xUserDetail;
}
}
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