Authored by michaelcao

update 添加用户信息

... ... @@ -27,6 +27,8 @@ public class YearMemberBillBO extends BaseModel {
private String year;
private String email;
//是否有账单
private boolean hasBill;
//称号
... ... @@ -129,6 +131,11 @@ public class YearMemberBillBO extends BaseModel {
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
... ...
... ... @@ -5,8 +5,11 @@ package com.yoho.activity.common.helper;
import javax.annotation.Resource;
import com.yoho.activity.common.ApiResponse;
import com.yoho.core.rest.client.hystrix.AsyncFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.yoho.core.rest.client.ServiceCaller;
... ... @@ -14,6 +17,9 @@ import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.order.request.OrdersStatusStatisticsRequest;
import com.yoho.service.model.order.response.CountBO;
import java.util.HashMap;
import java.util.Map;
/**
* @author ping.huang
* 2016年12月29日
... ... @@ -25,6 +31,12 @@ public class UserServiceHelper {
@Resource
ServiceCaller serviceCaller;
@Resource
ClientSecretHelper clientSecretHelper;
@Value("${gateway.url}")
private String gatewayUrl;
/**
* 根据uid,查询订单数
... ... @@ -45,4 +57,28 @@ public class UserServiceHelper {
log.info("getOrderCountByUid success with response={}. uid is {}", result, uid);
return result;
}
public ApiResponse getProfileByUid(int uid) throws ServiceException {
log.info("start with getProfileByUid. uid is {}", uid);
if (uid == 0) {
log.warn("getProfileByUid error with uid={}", uid);
return null;
}
Map<String, String> map = new HashMap<String, String>();
map.put("method", "app.passport.profile");
map.put("uid", String.valueOf(uid));
String param = clientSecretHelper.createClientSecret(map);
// 调用gateway的获取用户信息
AsyncFuture<ApiResponse> response = serviceCaller.get("user.getProfileByUid", gatewayUrl + "?" + param, null, ApiResponse.class, null);
ApiResponse apiResponse = response.get();
if(apiResponse.getCode() != 200){
log.warn("call app.passport.profile error e={}", apiResponse.getMessage());
return new ApiResponse();
}
log.info("getProfileByUid success with response={}. uid is {}", apiResponse, uid);
return apiResponse;
}
}
... ...
... ... @@ -21,6 +21,8 @@ public class AppYearMemberBill {
private String year;
private String email;
public Integer getUid() {
return uid;
}
... ... @@ -100,4 +102,12 @@ public class AppYearMemberBill {
public void setYear(String year) {
this.year = year == null ? null : year.trim();
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
\ No newline at end of file
... ...
... ... @@ -12,9 +12,10 @@
<result column="nickname" property="nickname" jdbcType="VARCHAR" />
<result column="phone" property="phone" jdbcType="VARCHAR" />
<result column="year" property="year" jdbcType="VARCHAR" />
<result column="email" property="email" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
uid, order_num, buy_num, order_amount, kilo, score, beat, nickname, phone, year
uid, order_num, buy_num, order_amount, kilo, score, beat, nickname, phone, year,email
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
... ... @@ -30,11 +31,11 @@
insert into app_year_member_bill (uid, order_num, buy_num,
order_amount, kilo, score,
beat, nickname, phone,
year)
year,email)
values (#{uid,jdbcType=INTEGER}, #{orderNum,jdbcType=INTEGER}, #{buyNum,jdbcType=INTEGER},
#{orderAmount,jdbcType=INTEGER}, #{kilo,jdbcType=INTEGER}, #{score,jdbcType=INTEGER},
#{beat,jdbcType=INTEGER}, #{nickname,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
#{year,jdbcType=VARCHAR})
#{year,jdbcType=VARCHAR},#{email,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.yoho.activity.dal.model.AppYearMemberBill" >
insert into app_year_member_bill
... ... @@ -69,6 +70,9 @@
<if test="year != null" >
year,
</if>
<if test="email != null" >
email,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="uid != null" >
... ... @@ -101,6 +105,9 @@
<if test="year != null" >
#{year,jdbcType=VARCHAR},
</if>
<if test="email != null" >
#{email,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.activity.dal.model.AppYearMemberBill" >
... ... @@ -133,6 +140,9 @@
<if test="year != null" >
year = #{year,jdbcType=VARCHAR},
</if>
<if test="email != null" >
email = #{email,jdbcType=VARCHAR},
</if>
</set>
where uid = #{uid,jdbcType=INTEGER}
</update>
... ... @@ -146,7 +156,8 @@
beat = #{beat,jdbcType=INTEGER},
nickname = #{nickname,jdbcType=VARCHAR},
phone = #{phone,jdbcType=VARCHAR},
year = #{year,jdbcType=VARCHAR}
year = #{year,jdbcType=VARCHAR},
email = #{email,jdbcType=VARCHAR}
where uid = #{uid,jdbcType=INTEGER}
</update>
<select id="selectByUidAndYear" resultMap="BaseResultMap">
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.activity.service.impl;
import com.yoho.activity.common.ApiResponse;
import com.yoho.activity.common.bo.YearMemberBillBO;
import com.yoho.activity.common.helper.UserServiceHelper;
import com.yoho.activity.common.redis.CacheKeyHelper;
import com.yoho.activity.dal.AppYearMemberBillMapper;
import com.yoho.activity.dal.model.AppYearMemberBill;
... ... @@ -15,6 +16,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;
... ... @@ -35,6 +37,10 @@ public class YearMemberBillServiceImpl implements IYearMemberBillService {
@Resource(name = "yhRedisTemplate")
private YHRedisTemplate<String, String> yhRedisTemplate;
@Resource
UserServiceHelper uerServiceHelper;
public static final String YEAR_MEMBER_BILL_KEY = "yh:activity:year_member_bill:";
@Override
... ... @@ -58,10 +64,18 @@ public class YearMemberBillServiceImpl implements IYearMemberBillService {
result.setHasBill(false);
//分值为85-89之间随机
int score = getRandomNum(85,89);
result.setUid(uid);
result.setYear(year);
result.setScore(score);
result.setBeat(getBeatByScore(score));
setProfile(uid,result);
}else{
BeanUtils.copyProperties(appYearMemberBill,result);
String mobile = appYearMemberBill.getPhone();
if(StringUtils.isNotEmpty(mobile) && mobile.length() > 7){
mobile = mobile.substring(0,3) + "****" + mobile.substring(7, mobile.length());
}
result.setPhone(mobile);
result.setHasBill(true);
}
//根据分值设置展示形象
... ... @@ -99,6 +113,29 @@ public class YearMemberBillServiceImpl implements IYearMemberBillService {
return beat;
}
private void setProfile(int uid, YearMemberBillBO result){
log.info("setProfile in with uid = {}",uid);
ApiResponse profileRsp = new ApiResponse();
try{
profileRsp = uerServiceHelper.getProfileByUid(uid);
}catch (Exception e){
log.warn("setProfile error with e = {}",e.getMessage());
return;
}
Map profileMap = (Map) profileRsp.getData();
if(null == profileMap){
log.info("setProfile error profileMap is null");
return;
}
result.setEmail(String.valueOf(profileMap.get("verify_mobile")));
result.setNickname(String.valueOf(profileMap.get("nickname")));
String mobile = String.valueOf(profileMap.get("mobile"));
if(StringUtils.isNotEmpty(mobile) && mobile.length() > 7){
mobile = mobile.substring(0,3) + "****" + mobile.substring(7, mobile.length());
}
result.setPhone(mobile);
}
private int getRandomNum(int min,int max){
Random random = new Random();
int s = random.nextInt(max)%(max-min+1) + min;
... ...