Showing
12 changed files
with
472 additions
and
68 deletions
1 | package com.yoho.unions.common.redis; | 1 | package com.yoho.unions.common.redis; |
2 | 2 | ||
3 | +import com.alibaba.fastjson.JSONArray; | ||
4 | +import com.google.common.collect.Lists; | ||
5 | +import com.google.common.collect.Maps; | ||
3 | import com.yoho.core.redis.YHHashOperations; | 6 | import com.yoho.core.redis.YHHashOperations; |
7 | +import com.yoho.core.redis.YHRedisTemplate; | ||
4 | import com.yoho.unions.common.utils.SerializeUtils; | 8 | import com.yoho.unions.common.utils.SerializeUtils; |
9 | +import com.yoho.unions.helper.CacheKeyHelper; | ||
5 | import org.apache.commons.collections.CollectionUtils; | 10 | import org.apache.commons.collections.CollectionUtils; |
11 | +import org.apache.commons.collections.MapUtils; | ||
6 | import org.apache.commons.lang3.StringUtils; | 12 | import org.apache.commons.lang3.StringUtils; |
7 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
8 | import org.slf4j.LoggerFactory; | 14 | import org.slf4j.LoggerFactory; |
@@ -11,15 +17,21 @@ import org.springframework.stereotype.Component; | @@ -11,15 +17,21 @@ import org.springframework.stereotype.Component; | ||
11 | 17 | ||
12 | import javax.annotation.Resource; | 18 | import javax.annotation.Resource; |
13 | import java.util.ArrayList; | 19 | import java.util.ArrayList; |
20 | +import java.util.Collection; | ||
14 | import java.util.List; | 21 | import java.util.List; |
22 | +import java.util.Map; | ||
23 | +import java.util.concurrent.TimeUnit; | ||
15 | 24 | ||
16 | @Component | 25 | @Component |
17 | public class RedisHashCache { | 26 | public class RedisHashCache { |
18 | 27 | ||
19 | private final static Logger logger = LoggerFactory.getLogger(RedisHashCache.class); | 28 | private final static Logger logger = LoggerFactory.getLogger(RedisHashCache.class); |
20 | 29 | ||
21 | - @Resource(name="yhHashOperations") | ||
22 | - YHHashOperations<String, String, String> yhHashOperations; | 30 | + @Resource(name = "yhHashOperations") |
31 | + private YHHashOperations<String, String, String> hashOperations; | ||
32 | + | ||
33 | + @Resource(name = "yhRedisTemplate") | ||
34 | + private YHRedisTemplate<String, String> yHRedisTemplate; | ||
23 | 35 | ||
24 | /** | 36 | /** |
25 | * 获取所有的values | 37 | * 获取所有的values |
@@ -35,7 +47,7 @@ public class RedisHashCache { | @@ -35,7 +47,7 @@ public class RedisHashCache { | ||
35 | return null; | 47 | return null; |
36 | } | 48 | } |
37 | 49 | ||
38 | - List<String> valueList = yhHashOperations.values(key); | 50 | + List<String> valueList = hashOperations.values(key); |
39 | logger.debug("values hashOperation value list size is {}", valueList == null ? 0 : valueList.size()); | 51 | logger.debug("values hashOperation value list size is {}", valueList == null ? 0 : valueList.size()); |
40 | if (CollectionUtils.isEmpty(valueList)) { | 52 | if (CollectionUtils.isEmpty(valueList)) { |
41 | return null; | 53 | return null; |
@@ -51,4 +63,170 @@ public class RedisHashCache { | @@ -51,4 +63,170 @@ public class RedisHashCache { | ||
51 | return null; | 63 | return null; |
52 | } | 64 | } |
53 | 65 | ||
66 | + | ||
67 | + /** | ||
68 | + * Hash存储数据 | ||
69 | + * | ||
70 | + * @param cacheKey | ||
71 | + * @param entries | ||
72 | + * @param timeout | ||
73 | + * @param unit | ||
74 | + * @param <V> | ||
75 | + */ | ||
76 | + public <V> void add(String cacheKey, Map<String, List<V>> entries, long timeout, TimeUnit unit) { | ||
77 | + | ||
78 | + if (entries == null || entries.size() == 0) { | ||
79 | + logger.warn("add params is null ."); | ||
80 | + return; | ||
81 | + } | ||
82 | + | ||
83 | + try { | ||
84 | + // 将入口参数中的 Map<String, List<V>> 装换成 Map<String, String> | ||
85 | + Map<String, String> valueStrMap = Maps.newHashMap(); | ||
86 | + for (String key : entries.keySet()) { | ||
87 | + List<V> valueObjList = entries.get(key); | ||
88 | + | ||
89 | + valueStrMap.put(key, JSONArray.toJSONString(valueObjList)); | ||
90 | + | ||
91 | + } | ||
92 | + | ||
93 | + this.hashOperations.putAll(cacheKey, valueStrMap); | ||
94 | + this.yHRedisTemplate.longExpire(cacheKey, timeout, unit); | ||
95 | + } catch (Exception e) { | ||
96 | + logger.warn("add failed!!! key is: {}", cacheKey); | ||
97 | + } | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * 根据key和hashkey获取数据 | ||
102 | + * | ||
103 | + * @param cacheKey | ||
104 | + * @param hashKey | ||
105 | + * @param clazz | ||
106 | + * @param <T> | ||
107 | + * @return | ||
108 | + */ | ||
109 | + public <T> T get(String cacheKey, String hashKey, Class<T> clazz) { | ||
110 | + try { | ||
111 | + if (StringUtils.isEmpty(cacheKey) || StringUtils.isEmpty(hashKey)) { | ||
112 | + return null; | ||
113 | + } | ||
114 | + String value = this.hashOperations.get(cacheKey, hashKey); | ||
115 | + if (StringUtils.isEmpty(value)) { | ||
116 | + return null; | ||
117 | + } | ||
118 | + return CacheKeyHelper.string2Value(value, clazz); | ||
119 | + } catch (Exception e) { | ||
120 | + logger.warn("RedisHashCache get failed!!! cacheKey is: {},hashkey {}", cacheKey, hashKey); | ||
121 | + } | ||
122 | + return null; | ||
123 | + } | ||
124 | + | ||
125 | + /** | ||
126 | + * 根据key和hashkey获取数据 | ||
127 | + * | ||
128 | + * @param cacheKey | ||
129 | + * @param clazz | ||
130 | + * @param <T> | ||
131 | + * @return | ||
132 | + */ | ||
133 | + public <T> List<T> multiGet(String cacheKey, Collection<? extends Object> hashKeyList, Class<T> clazz) { | ||
134 | + try { | ||
135 | + if (StringUtils.isEmpty(cacheKey) || CollectionUtils.isEmpty(hashKeyList)) { | ||
136 | + return null; | ||
137 | + } | ||
138 | + List<String> hkeyList = new ArrayList<>(); | ||
139 | + for (Object hobj : hashKeyList) { | ||
140 | + hkeyList.add(hobj.toString()); | ||
141 | + } | ||
142 | + List<String> valueList = this.hashOperations.multiGet(cacheKey, hkeyList); | ||
143 | + if (CollectionUtils.isEmpty(valueList)) { | ||
144 | + return null; | ||
145 | + } | ||
146 | + List<T> resultList = Lists.newArrayList(); | ||
147 | + for (String result : valueList) { | ||
148 | + if (StringUtils.isEmpty(result)) { | ||
149 | + continue; | ||
150 | + } | ||
151 | + resultList.add(CacheKeyHelper.string2Value(result, clazz)); | ||
152 | + } | ||
153 | + return resultList; | ||
154 | + } catch (Exception e) { | ||
155 | + logger.warn("RedisHashCache get failed!!! cacheKey is: {},hashkey {}", cacheKey, hashKeyList); | ||
156 | + } | ||
157 | + return null; | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * 存储hash结构数据 | ||
162 | + * | ||
163 | + * @param cacheKey | ||
164 | + * @param hashKey | ||
165 | + * @param value | ||
166 | + * @param timeout | ||
167 | + * @param unit | ||
168 | + * @param <T> | ||
169 | + */ | ||
170 | + public <T> void put(String cacheKey, String hashKey, T value, long timeout, TimeUnit unit) { | ||
171 | + try { | ||
172 | + if (StringUtils.isEmpty(cacheKey) || StringUtils.isEmpty(hashKey)) { | ||
173 | + logger.warn("RedisHashCache put failed!!! cacheKey is: {},hashkey {}", cacheKey, hashKey); | ||
174 | + return; | ||
175 | + } | ||
176 | + String v = CacheKeyHelper.value2String(value); | ||
177 | + if (StringUtils.isEmpty(v)) { | ||
178 | + logger.warn("RedisHashCache put failed!!! value {}", v); | ||
179 | + return; | ||
180 | + } | ||
181 | + this.hashOperations.put(cacheKey, hashKey, v); | ||
182 | + this.yHRedisTemplate.longExpire(cacheKey, timeout, unit); | ||
183 | + } catch (Exception e) { | ||
184 | + logger.warn("RedisHashCache get failed!!! cacheKey is: {},hashkey {}", cacheKey, hashKey); | ||
185 | + } | ||
186 | + } | ||
187 | + | ||
188 | + /** | ||
189 | + * 批量put | ||
190 | + * | ||
191 | + * @param obj key的后缀 | ||
192 | + * @param m 需要设置的值(该map的key是去除hashKey后缀的值) | ||
193 | + * @param unit 超时时间单位 | ||
194 | + */ | ||
195 | + public <T> void putAll(String cacheKey, Map<? extends String, ? extends T> map, long timeout, TimeUnit unit) { | ||
196 | + logger.debug("Enter putAll hashOperation redis value. obj is {}, m is {}", map); | ||
197 | + if (MapUtils.isEmpty(map)) { | ||
198 | + return; | ||
199 | + } | ||
200 | + try { | ||
201 | + if (StringUtils.isBlank(cacheKey)) { | ||
202 | + return; | ||
203 | + } | ||
204 | + Map<String,String> newMap = Maps.newHashMap(); | ||
205 | + for(Map.Entry<? extends String, ? extends T> o : map.entrySet()){ | ||
206 | + newMap.put(o.getKey(),CacheKeyHelper.value2String(o.getValue())); | ||
207 | + } | ||
208 | + // 批量set | ||
209 | + hashOperations.putAll(cacheKey, newMap); | ||
210 | + // 设置超时 | ||
211 | + yHRedisTemplate.longExpire(cacheKey, timeout, unit); | ||
212 | + } catch (Exception e) { | ||
213 | + logger.warn("Redis exception. hash redis putAll . obj is {}, map is {}, exception msg is {}", map, e.getMessage()); | ||
214 | + } | ||
215 | + } | ||
216 | + | ||
217 | + /** | ||
218 | + * 判断值是否存在 | ||
219 | + * @param cacheKey | ||
220 | + * @return | ||
221 | + */ | ||
222 | + public Boolean hasKey(String cacheKey) { | ||
223 | + logger.debug("Enter hasKey hashOperation redis. cacheKey is {}", cacheKey); | ||
224 | + try { | ||
225 | + return yHRedisTemplate.hasKey(cacheKey); | ||
226 | + } catch (Exception e) { | ||
227 | + logger.warn("get haskey method fail!! e {}", e); | ||
228 | + } | ||
229 | + return false; | ||
230 | + } | ||
231 | + | ||
54 | } | 232 | } |
1 | package com.yoho.unions.vo; | 1 | package com.yoho.unions.vo; |
2 | 2 | ||
3 | -import com.alibaba.fastjson.annotation.JSONField; | ||
4 | import lombok.Data; | 3 | import lombok.Data; |
4 | +import lombok.ToString; | ||
5 | 5 | ||
6 | -import java.io.Serializable; | ||
7 | 6 | ||
7 | + | ||
8 | +@Data | ||
9 | +@ToString | ||
8 | public class UnionReqVO{ | 10 | public class UnionReqVO{ |
9 | 11 | ||
10 | private String channel_id; | 12 | private String channel_id; |
@@ -23,68 +25,5 @@ public class UnionReqVO{ | @@ -23,68 +25,5 @@ public class UnionReqVO{ | ||
23 | 25 | ||
24 | private String utm_campaign; | 26 | private String utm_campaign; |
25 | 27 | ||
26 | - public String getChannel_id() { | ||
27 | - return channel_id; | ||
28 | - } | ||
29 | - | ||
30 | - public void setChannel_id(String channel_id) { | ||
31 | - this.channel_id = channel_id; | ||
32 | - } | ||
33 | - | ||
34 | - public String getTarget_url() { | ||
35 | - return target_url; | ||
36 | - } | ||
37 | - | ||
38 | - public void setTarget_url(String target_url) { | ||
39 | - this.target_url = target_url; | ||
40 | - } | ||
41 | - | ||
42 | - public String getTracking_code() { | ||
43 | - return tracking_code; | ||
44 | - } | ||
45 | - | ||
46 | - public void setTracking_code(String tracking_code) { | ||
47 | - this.tracking_code = tracking_code; | ||
48 | - } | ||
49 | - | ||
50 | - public String getU_id() { | ||
51 | - return u_id; | ||
52 | - } | ||
53 | - | ||
54 | - public void setU_id(String u_id) { | ||
55 | - this.u_id = u_id; | ||
56 | - } | ||
57 | - | ||
58 | - public String getUnion_type() { | ||
59 | - return union_type == null ? "" :union_type; | ||
60 | - } | ||
61 | - | ||
62 | - public void setUnion_type(String union_type) { | ||
63 | - this.union_type = union_type; | ||
64 | - } | ||
65 | - | ||
66 | - public String getUtm_source() { | ||
67 | - return utm_source == null ? "" :utm_source ; | ||
68 | - } | ||
69 | - | ||
70 | - public void setUtm_source(String utm_source) { | ||
71 | - this.utm_source = utm_source; | ||
72 | - } | ||
73 | - | ||
74 | - public String getUtm_medium() { | ||
75 | - return utm_medium == null ? "" :utm_medium; | ||
76 | - } | ||
77 | - | ||
78 | - public void setUtm_medium(String utm_medium) { | ||
79 | - this.utm_medium = utm_medium; | ||
80 | - } | ||
81 | - | ||
82 | - public String getUtm_campaign() { | ||
83 | - return utm_campaign == null ? "" : utm_campaign; | ||
84 | - } | ||
85 | - | ||
86 | - public void setUtm_campaign(String utm_campaign) { | ||
87 | - this.utm_campaign = utm_campaign; | ||
88 | - } | ||
89 | } | 28 | } |
90 | 29 |
1 | +package com.yoho.unions.dal; | ||
2 | + | ||
3 | + | ||
4 | +import com.yoho.unions.dal.model.MobilePanChannel; | ||
5 | +import org.apache.ibatis.annotations.Param; | ||
6 | + | ||
7 | +public interface IMobilePanChannelDAO { | ||
8 | + int deleteByPrimaryKey(Integer id); | ||
9 | + | ||
10 | + int insert(MobilePanChannel record); | ||
11 | + | ||
12 | + int insertSelective(MobilePanChannel record); | ||
13 | + | ||
14 | + MobilePanChannel selectByPrimaryKey(Integer id); | ||
15 | + | ||
16 | + MobilePanChannel selectByMobile(@Param("mobile") String mobile); | ||
17 | + | ||
18 | + int updateByPrimaryKeySelective(MobilePanChannel record); | ||
19 | + | ||
20 | + int updateByPrimaryKey(MobilePanChannel record); | ||
21 | +} |
1 | +package com.yoho.unions.dal.model; | ||
2 | + | ||
3 | + | ||
4 | +import lombok.Data; | ||
5 | +import lombok.ToString; | ||
6 | + | ||
7 | +@Data | ||
8 | +@ToString | ||
9 | +public class MobilePanChannel { | ||
10 | + private Integer id; | ||
11 | + | ||
12 | + private String mobile; | ||
13 | + | ||
14 | + private Byte channel; | ||
15 | + | ||
16 | + private Integer createTime; | ||
17 | + | ||
18 | + | ||
19 | +} |
1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||
3 | +<mapper namespace="com.yoho.unions.dal.IMobilePanChannelDAO" > | ||
4 | + <resultMap id="BaseResultMap" type="com.yoho.unions.dal.model.MobilePanChannel" > | ||
5 | + <id column="id" property="id" jdbcType="INTEGER" /> | ||
6 | + <result column="mobile" property="mobile" jdbcType="VARCHAR" /> | ||
7 | + <result column="channel" property="channel" jdbcType="TINYINT" /> | ||
8 | + <result column="create_time" property="createTime" jdbcType="INTEGER" /> | ||
9 | + </resultMap> | ||
10 | + <sql id="Base_Column_List" > | ||
11 | + id, mobile, channel, create_time | ||
12 | + </sql> | ||
13 | + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > | ||
14 | + select | ||
15 | + <include refid="Base_Column_List" /> | ||
16 | + from mobile_pan_channel | ||
17 | + where id = #{id,jdbcType=INTEGER} | ||
18 | + </select> | ||
19 | + | ||
20 | + <select id="selectByMobile" resultMap="BaseResultMap" parameterType="java.lang.String" > | ||
21 | + select | ||
22 | + <include refid="Base_Column_List" /> | ||
23 | + from mobile_pan_channel | ||
24 | + where mobile = #{mobile,jdbcType=VARCHAR} | ||
25 | + </select> | ||
26 | + | ||
27 | + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" > | ||
28 | + delete from mobile_pan_channel | ||
29 | + where id = #{id,jdbcType=INTEGER} | ||
30 | + </delete> | ||
31 | + <insert id="insert" parameterType="com.yoho.unions.dal.model.MobilePanChannel" > | ||
32 | + insert into mobile_pan_channel (id, mobile, channel, | ||
33 | + create_time) | ||
34 | + values (#{id,jdbcType=INTEGER}, #{mobile,jdbcType=VARCHAR}, #{channel,jdbcType=TINYINT}, | ||
35 | + #{createTime,jdbcType=INTEGER}) | ||
36 | + </insert> | ||
37 | + <insert id="insertSelective" parameterType="com.yoho.unions.dal.model.MobilePanChannel" > | ||
38 | + insert into mobile_pan_channel | ||
39 | + <trim prefix="(" suffix=")" suffixOverrides="," > | ||
40 | + <if test="id != null" > | ||
41 | + id, | ||
42 | + </if> | ||
43 | + <if test="mobile != null" > | ||
44 | + mobile, | ||
45 | + </if> | ||
46 | + <if test="channel != null" > | ||
47 | + channel, | ||
48 | + </if> | ||
49 | + <if test="createTime != null" > | ||
50 | + create_time, | ||
51 | + </if> | ||
52 | + </trim> | ||
53 | + <trim prefix="values (" suffix=")" suffixOverrides="," > | ||
54 | + <if test="id != null" > | ||
55 | + #{id,jdbcType=INTEGER}, | ||
56 | + </if> | ||
57 | + <if test="mobile != null" > | ||
58 | + #{mobile,jdbcType=VARCHAR}, | ||
59 | + </if> | ||
60 | + <if test="channel != null" > | ||
61 | + #{channel,jdbcType=TINYINT}, | ||
62 | + </if> | ||
63 | + <if test="createTime != null" > | ||
64 | + #{createTime,jdbcType=INTEGER}, | ||
65 | + </if> | ||
66 | + </trim> | ||
67 | + </insert> | ||
68 | + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.unions.dal.model.MobilePanChannel" > | ||
69 | + update mobile_pan_channel | ||
70 | + <set > | ||
71 | + <if test="mobile != null" > | ||
72 | + mobile = #{mobile,jdbcType=VARCHAR}, | ||
73 | + </if> | ||
74 | + <if test="channel != null" > | ||
75 | + channel = #{channel,jdbcType=TINYINT}, | ||
76 | + </if> | ||
77 | + <if test="createTime != null" > | ||
78 | + create_time = #{createTime,jdbcType=INTEGER}, | ||
79 | + </if> | ||
80 | + </set> | ||
81 | + where id = #{id,jdbcType=INTEGER} | ||
82 | + </update> | ||
83 | + <update id="updateByPrimaryKey" parameterType="com.yoho.unions.dal.model.MobilePanChannel" > | ||
84 | + update mobile_pan_channel | ||
85 | + set mobile = #{mobile,jdbcType=VARCHAR}, | ||
86 | + channel = #{channel,jdbcType=TINYINT}, | ||
87 | + create_time = #{createTime,jdbcType=INTEGER} | ||
88 | + where id = #{id,jdbcType=INTEGER} | ||
89 | + </update> | ||
90 | +</mapper> |
1 | +package com.yoho.unions.server.restapi; | ||
2 | + | ||
3 | +import com.yoho.unions.server.service.IPayChannelService; | ||
4 | +import com.yoho.unions.vo.ApiResponse; | ||
5 | +import com.yoho.unions.vo.ChannelTypeReqVO; | ||
6 | +import com.yoho.unions.vo.ChannelTypeVO; | ||
7 | +import org.apache.commons.lang.StringUtils; | ||
8 | +import org.slf4j.Logger; | ||
9 | +import org.slf4j.LoggerFactory; | ||
10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
11 | +import org.springframework.stereotype.Controller; | ||
12 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
13 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
14 | + | ||
15 | +/** | ||
16 | + * Created by yoho on 2017/3/2. | ||
17 | + */ | ||
18 | +@Controller | ||
19 | +@RequestMapping("/PayChannelRest") | ||
20 | +public class PayChannelRest { | ||
21 | + | ||
22 | + Logger logger = LoggerFactory.getLogger(PayChannelRest.class); | ||
23 | + | ||
24 | + @Autowired | ||
25 | + IPayChannelService payChannelService; | ||
26 | + | ||
27 | + @RequestMapping("/getChannelType") | ||
28 | + @ResponseBody | ||
29 | + public ApiResponse getChannelType(ChannelTypeReqVO unionReqVO) { | ||
30 | + logger.info("Enter PayChannelRest.getChannelType unionReqVO {} ", unionReqVO); | ||
31 | + ChannelTypeVO channelTypeBO = payChannelService.getChannelType(unionReqVO); | ||
32 | + if (StringUtils.isNotBlank(channelTypeBO.getChannelTypeName())){ | ||
33 | + return new ApiResponse.ApiResponseBuilder().data(channelTypeBO).build(); | ||
34 | + }else{ | ||
35 | + return new ApiResponse.ApiResponseBuilder().code(401).build(); | ||
36 | + } | ||
37 | + | ||
38 | + } | ||
39 | +} |
1 | +package com.yoho.unions.server.service; | ||
2 | + | ||
3 | +import com.yoho.unions.vo.ChannelTypeReqVO; | ||
4 | +import com.yoho.unions.vo.ChannelTypeVO; | ||
5 | +import com.yoho.unions.vo.UnionReqVO; | ||
6 | + | ||
7 | +/** | ||
8 | + * Created by yoho on 2017/3/2. | ||
9 | + */ | ||
10 | +public interface IPayChannelService { | ||
11 | + | ||
12 | + /** | ||
13 | + * 判断是否是否付费渠道 | ||
14 | + * @param unionReqVO | ||
15 | + * @return | ||
16 | + */ | ||
17 | + public ChannelTypeVO getChannelType(ChannelTypeReqVO unionReqVO); | ||
18 | +} |
1 | +package com.yoho.unions.server.service.impl; | ||
2 | + | ||
3 | +import com.yoho.unions.common.redis.RedisHashCache; | ||
4 | +import com.yoho.unions.common.redis.RedisValueCache; | ||
5 | +import com.yoho.unions.dal.IMobilePanChannelDAO; | ||
6 | +import com.yoho.unions.dal.model.MobilePanChannel; | ||
7 | +import com.yoho.unions.server.service.IPayChannelService; | ||
8 | +import com.yoho.unions.vo.ChannelTypeReqVO; | ||
9 | +import com.yoho.unions.vo.ChannelTypeVO; | ||
10 | +import org.apache.commons.lang.StringUtils; | ||
11 | +import org.slf4j.Logger; | ||
12 | +import org.slf4j.LoggerFactory; | ||
13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
14 | +import org.springframework.stereotype.Service; | ||
15 | + | ||
16 | +import java.util.concurrent.TimeUnit; | ||
17 | + | ||
18 | + | ||
19 | +/** | ||
20 | + * Created by yoho on 2017/3/2. | ||
21 | + */ | ||
22 | +@Service | ||
23 | +public class PayChannelServiceImpl implements IPayChannelService { | ||
24 | + | ||
25 | + static Logger logger = LoggerFactory.getLogger(PayChannelServiceImpl.class); | ||
26 | + | ||
27 | + @Autowired | ||
28 | + IMobilePanChannelDAO mobilePanChannelDAO; | ||
29 | + | ||
30 | + @Autowired | ||
31 | + RedisHashCache redisHashCache; | ||
32 | + | ||
33 | + @Autowired | ||
34 | + RedisValueCache redisValueCache; | ||
35 | + | ||
36 | + private static final String UNION_PAY_CHANNEL_KEY_PRE = "union:pay_channel:"; | ||
37 | + | ||
38 | + /** | ||
39 | + * 判断是否是否付费渠道 | ||
40 | + * @param unionReqVO | ||
41 | + * @return | ||
42 | + */ | ||
43 | + public ChannelTypeVO getChannelType(ChannelTypeReqVO unionReqVO){ | ||
44 | + | ||
45 | + ChannelTypeVO channelTypeBO = new ChannelTypeVO(); | ||
46 | + | ||
47 | + // (1)判断是否是 付费渠道 | ||
48 | + if (StringUtils.isNotBlank(unionReqVO.getUdid())){ | ||
49 | + String redisKey = UNION_PAY_CHANNEL_KEY_PRE + unionReqVO.getUdid(); | ||
50 | + String payChannel= redisValueCache.get(redisKey, String.class); | ||
51 | + if(StringUtils.isNotBlank(payChannel)){ | ||
52 | + channelTypeBO.setChannelTypeName("paychannel"); | ||
53 | + } | ||
54 | + } | ||
55 | + | ||
56 | + // (2)判断是否是 泛渠道 | ||
57 | + if (StringUtils.isEmpty(channelTypeBO.getChannelTypeName()) | ||
58 | + && StringUtils.isNotBlank(unionReqVO.getMobile())){ | ||
59 | + MobilePanChannel mobilePanChannel = mobilePanChannelDAO.selectByMobile(unionReqVO.getMobile()); | ||
60 | + if (mobilePanChannel != null){ | ||
61 | + channelTypeBO.setChannelTypeName("panchannel"); | ||
62 | + } | ||
63 | + } | ||
64 | + | ||
65 | + return channelTypeBO; | ||
66 | + } | ||
67 | +} |
@@ -51,5 +51,6 @@ datasources: | @@ -51,5 +51,6 @@ datasources: | ||
51 | - com.yoho.unions.dal.IChannelGroupConditionDAO | 51 | - com.yoho.unions.dal.IChannelGroupConditionDAO |
52 | - com.yoho.unions.dal.IChannelGroupBatchDAO | 52 | - com.yoho.unions.dal.IChannelGroupBatchDAO |
53 | - com.yoho.unions.dal.IChannelSmsBlackDAO | 53 | - com.yoho.unions.dal.IChannelSmsBlackDAO |
54 | + - com.yoho.unions.dal.IMobilePanChannelDAO | ||
54 | 55 | ||
55 | readOnlyInSlave: true | 56 | readOnlyInSlave: true |
@@ -52,5 +52,6 @@ datasources: | @@ -52,5 +52,6 @@ datasources: | ||
52 | - com.yoho.unions.dal.IChannelGroupConditionDAO | 52 | - com.yoho.unions.dal.IChannelGroupConditionDAO |
53 | - com.yoho.unions.dal.IChannelGroupBatchDAO | 53 | - com.yoho.unions.dal.IChannelGroupBatchDAO |
54 | - com.yoho.unions.dal.IChannelSmsBlackDAO | 54 | - com.yoho.unions.dal.IChannelSmsBlackDAO |
55 | + - com.yoho.unions.dal.IMobilePanChannelDAO | ||
55 | 56 | ||
56 | readOnlyInSlave: true | 57 | readOnlyInSlave: true |
-
Please register or login to post a comment