Authored by DengXinFei

Merge branch 'test6.7'

... ... @@ -2,6 +2,7 @@ package com.yoho.message.dal;
import com.yoho.message.dal.model.MiniappMsgForm;
import org.apache.ibatis.annotations.Param;
public interface IMiniappMsgFormDAO {
int deleteByPrimaryKey(Integer id);
... ... @@ -12,11 +13,7 @@ public interface IMiniappMsgFormDAO {
MiniappMsgForm selectByPrimaryKey(Integer id);
MiniappMsgForm selectByOrderCode(String orderCode);
MiniappMsgForm selectLastedAvailabByOrderCode(String orderCode);
MiniappMsgForm selectLastedAvailabByUid(String uid);
MiniappMsgForm selectLastedAvailabByUid(@Param("uid") String uid, @Param("miniappType") String miniappType);
int updateByPrimaryKeySelective(MiniappMsgForm record);
... ...
... ... @@ -21,12 +21,13 @@
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectLastedAvailabByUid" resultMap="BaseResultMap" parameterType="java.lang.String" >
<select id="selectLastedAvailabByUid" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from miniapp_msg_form
where uid = #{uid,jdbcType=VARCHAR}
and available_times > 0
and miniapp_type = #{miniappType,jdbcType=VARCHAR}
and create_time > unix_timestamp(now()) - 7*24*60*60
order by create_time
limit 1
... ...
... ... @@ -43,41 +43,43 @@ public class MiniAppAccessTokenServiceImpl implements IMiniAppAccessTokenService
*/
public AccessToken getTokenCache(String miniappType){
// 1 代表新与力的 小程序
// 0 有货的小程序
if (!"1".equals(miniappType)){
miniappType = "0";
}
String redisValue = pushRedisService.getValue(KeyBuilder.getMiniAppAccesTokenKey(miniappType));
if (StringUtils.isNotBlank(redisValue)) {
logger.info("getTokenCache redisValue is {}", redisValue);
return toAccessToken(redisValue);
} else {
return getAccessTokenFromUrl(miniappType);
AccessToken accessToken = getAccessToken(redisValue);
if (accessToken != null){
return accessToken;
}
return getAccessTokenFromUrl(miniappType);
}
private static AccessToken toAccessToken(String tokenValue) {
if (StringUtils.isNotBlank(tokenValue)) {
String[] data = tokenValue.split(",");
AccessToken accessToken = new AccessToken();
accessToken.setToken(data[0]);
accessToken.setExpiresIn(Integer.valueOf(data[1]));
return accessToken;
public AccessToken getAccessToken(String redisValue){
if (StringUtils.isEmpty(redisValue)){
return null;
}
return null;
try{
logger.info("getTokenCache redisValue is {}", redisValue);
return JSONObject.parseObject(redisValue, AccessToken.class);
}catch (Exception e){
return null;
}
}
public AccessToken getAccessTokenFromUrl(String miniappType) {
String url = MINI_ACCESSTOKEN_GET+"&miniappType="+miniappType;
JSONObject res = HttpClientUtil.doGet(url, "UTF-8");
logger.info("getAccessTokenFromUrl is {}, result is {}", url, JSONObject.toJSONString(res));
if (null != res && res.getIntValue("code") == 200) {
AccessToken accessToken = new AccessToken(res.getString("data"), 1800);
pushRedisService.setValue(KeyBuilder.getMiniAppAccesTokenKey(miniappType),
accessToken.getToken() + "," + 1800, 1800, TimeUnit.SECONDS);
JSONObject.toJSONString(accessToken), 1800, TimeUnit.SECONDS);
return accessToken;
}
return null;
... ...
... ... @@ -39,9 +39,6 @@ public class MiniServiceAppImpl implements IMiniAppService {
private IMiniappMsgFormDAO miniappMsgFormDAO;
@Autowired
private SendWechatRequest sendWechatRequest;
@Autowired
private IMiniAppAccessTokenService miniAppAccessTokenService;
public String getMsgSendUrl(){
... ... @@ -73,7 +70,7 @@ public class MiniServiceAppImpl implements IMiniAppService {
}
// 查询时间(可用次数>1 && 时间在7天之内的消息)
MiniappMsgForm miniappMsgForm = miniappMsgFormDAO.selectLastedAvailabByUid(reqBO.getUid());
MiniappMsgForm miniappMsgForm = miniappMsgFormDAO.selectLastedAvailabByUid(reqBO.getUid(), reqBO.getMiniappType());
if (miniappMsgForm == null
|| StringUtils.isBlank(miniappMsgForm.getFormId())
|| StringUtils.isBlank(miniappMsgForm.getOpenId())){
... ... @@ -97,7 +94,7 @@ public class MiniServiceAppImpl implements IMiniAppService {
miniappMsgForm.setAvailableTimes(0);
miniappMsgFormDAO.updateByPrimaryKey(miniappMsgForm);
MiniappMsgForm miniappMsgFormNew = miniappMsgFormDAO.selectLastedAvailabByUid(reqBO.getUid());
MiniappMsgForm miniappMsgFormNew = miniappMsgFormDAO.selectLastedAvailabByUid(reqBO.getUid(), reqBO.getMiniappType());
if (miniappMsgForm == null
|| StringUtils.isBlank(miniappMsgForm.getFormId())
... ...