Authored by zhengwen.ge

增加排重逻辑

package com.yoho.unions.dal;
import org.apache.ibatis.annotations.Param;
import com.yoho.unions.dal.model.UnionLogs;
... ... @@ -16,4 +18,8 @@ public interface IUnionLogsDAO {
int updateByPrimaryKeySelective(UnionLogs record);
int updateByPrimaryKey(UnionLogs record);
UnionLogs selectIOS(@Param("appId") String appId,@Param("idfa") String idfa,@Param("clientType")String clientType);
UnionLogs selectAndroid(@Param("appId")String appId,@Param("imei") String imei,@Param("clientType")String clientType);
}
... ...
... ... @@ -59,4 +59,20 @@
client_type=#{clientType}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectIOS" resultMap="BaseResultMap" parameterType="com.yoho.unions.dal.model.UnionLogs">
select
<include refid="Base_Column_List" />
from union_logs
where app_id = #{appId,jdbcType=VARCHAR} and
idfa = #{idfa,jdbcType=VARCHAR} and
client_type=#{clientType}
</select>
<select id="selectAndroid" resultMap="BaseResultMap" parameterType="com.yoho.unions.dal.model.UnionLogs">
select
<include refid="Base_Column_List" />
from union_logs
where app_id = #{appId,jdbcType=VARCHAR} and
imei = #{imei,jdbcType=VARCHAR} and
client_type=#{clientType}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -72,12 +72,25 @@ public class GDTServiceImpl implements MainUnionService {
@Override
public UnionResponseBO activeUnion(ActivateUnionRequestBO request) {
log.info("activateUnion with param is{}", request);
UnionResponseBO response = check(request);
if (!response.getIsSuccess()) {
return response;
}
UnionLogs logs = new UnionLogs();
//去重,排除重复激活
if(ClientTypeEnum.IPHONE.getName().equalsIgnoreCase(request.getClient_type())){
logs = unionLogsDAO.selectIOS(String.valueOf(request.getAppid()), request.getIdfa(), request.getClient_type());
if(null !=logs &&logs.getIsActivate()==1){
return response;
}
}else{
logs = unionLogsDAO.selectAndroid(String.valueOf(request.getAppid()), request.getImei(), request.getClient_type());
if(null !=logs && logs.getIsActivate()==1){
return response;
}
}
log.info("activateUnion with param is{}", request);
// 对url进行加密,拼接
String url = urlEode(request);
... ... @@ -109,7 +122,14 @@ public class GDTServiceImpl implements MainUnionService {
unionLogs.setIsActivate((byte) 1);
unionLogs.setCreateTime(DateUtil.getCurrentTimeSecond());
unionLogs.setUpdateTime(DateUtil.getCurrentTimeSecond());
log.debug("add to unionLogs db with param is {}", unionLogs);
if(logs!= null&&logs.getIsActivate() ==0){
unionLogs.setId(logs.getId());
unionLogsDAO.updateByPrimaryKey(unionLogs);
}else{
unionLogsDAO.insert(unionLogs);
}
response = new UnionResponseBO(true, msg);
}
// 广点通返回错误
... ... @@ -118,6 +138,14 @@ public class GDTServiceImpl implements MainUnionService {
unionLogs.setCreateTime(DateUtil.getCurrentTimeSecond());
unionLogs.setUpdateTime(DateUtil.getCurrentTimeSecond());
response = new UnionResponseBO(false, msg);
if(logs!= null&&logs.getIsActivate() ==0){
logs.setUpdateTime(DateUtil.getCurrentTimeSecond());
logs.setIsActivate((byte)0);
unionLogs.setId(logs.getId());
unionLogsDAO.updateByPrimaryKey(unionLogs);
}else{
unionLogsDAO.insert(unionLogs);
}
}
} else {
// 激活失败
... ... @@ -125,8 +153,16 @@ public class GDTServiceImpl implements MainUnionService {
unionLogs.setCreateTime(DateUtil.getCurrentTimeSecond());
unionLogs.setUpdateTime(DateUtil.getCurrentTimeSecond());
response = new UnionResponseBO(false, "激活失败");
if(logs!=null&&logs.getIsActivate() ==0){
logs.setUpdateTime(DateUtil.getCurrentTimeSecond());
logs.setIsActivate((byte)1);
unionLogs.setId(logs.getId());
unionLogsDAO.updateByPrimaryKey(unionLogs);
}else{
unionLogsDAO.insert(unionLogs);
}
}
unionLogsDAO.insert(unionLogs);
return response;
}
... ...