admin
2021-06-11 bc9d4bf3fddcb3107f8509159a250f7a5a5f8ae5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.yeshi.fanli.service.manger.goods.jd;
 
import com.ks.lib.common.exception.ParamsException;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.SystemPIDInfo;
import com.yeshi.fanli.service.manger.PIDManager;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.jd.JDApiUtil;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
 
/**
 * 京东转链管理
 */
@Component
public class JDConvertLinkManager {
 
    @Resource
    private PIDManager pidManager;
 
    /**
     * 转链短链接
     *
     * @param shortLink
     * @param uid
     * @param system
     * @param pidType
     * @return
     * @throws ParamsException
     */
    public String convertShortUrl(String shortLink, Long uid, SystemEnum system, SystemPIDInfo.PidType pidType) throws ParamsException {
        if (StringUtil.isNullOrEmpty(shortLink)) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "短链为空");
        }
 
        if (system == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "system为空");
        }
 
        if (pidType == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "推广位类型为空");
        }
 
        return JDApiUtil.convertLinkWithSubUnionId(shortLink, null, null, pidManager.getPidCache(system, Constant.SOURCE_TYPE_JD, pidType), uid + "");
    }
 
 
    /**
     * 转链常规链接
     *
     * @param materialId
     * @param couponUrl
     * @param uid
     * @param system
     * @param pidType
     * @return
     * @throws ParamsException
     */
    public String convertGoodsUrl(String materialId, String couponUrl, Long uid, SystemEnum system, SystemPIDInfo.PidType pidType) throws ParamsException {
        if (StringUtil.isNullOrEmpty(materialId)) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "materialId为空");
        }
 
        if (system == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "system为空");
        }
 
        if (pidType == null) {
            throw new ParamsException(ParamsException.CODE_PARAMS_NOT_ENOUGH, "推广位类型为空");
        }
 
        return JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, null, pidManager.getPidCache(system, Constant.SOURCE_TYPE_JD, pidType), uid + "");
    }
 
 
}