myjf007
2024-11-04 627b61d17da1dbf02c0363c659b728627dd42890
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
package com.nova.sankuai.service.impl;
 
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nova.sankuai.domain.entity.ChannelDownloadLog;
import com.nova.sankuai.domain.entity.ChannelInfo;
import com.nova.sankuai.domain.entity.CustomerUser;
import com.nova.sankuai.infra.config.CommonException;
import com.nova.sankuai.infra.mapper.ChannelDownloadLogMapper;
import com.nova.sankuai.infra.mapper.ChannelInfoMapper;
import com.nova.sankuai.security.UserDetail;
import com.nova.sankuai.service.IChannelDownloadLogService;
import com.nova.sankuai.service.ICustomerUserService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.util.Date;
 
/**
 * @author weikangdi
 * @create 2022/1/25
 */
@AllArgsConstructor
@Service
@Slf4j
public class ChannelDownloadLogServiceImpl extends ServiceImpl<ChannelDownloadLogMapper, ChannelDownloadLog> implements IChannelDownloadLogService {
 
    private final ChannelInfoMapper channelInfoMapper;
 
    private final ICustomerUserService customerUserService;
 
    @Override
    public void addDownloadLog(String downloadUrl, UserDetail userDetail) {
        String uuid = IdUtil.randomUUID();
        CustomerUser customerUser = customerUserService.checkCustomer(userDetail.getPhone(), null);
        if (customerUser==null){
            throw new CommonException("用户不存在");
        }
        ChannelInfo channelByCode = channelInfoMapper.getChannelByCode(customerUser.getSourceChannel());
        if (channelByCode==null){
            throw new CommonException("渠道Code非法");
        }
        log.info("创建渠道下载日志:下载日志UUID=" + uuid + "AppId=" + channelByCode.getAppId() + "下载链接=" + downloadUrl + "用户ID=" + customerUser.getId());
        ChannelDownloadLog channelDownloadLog = new ChannelDownloadLog();
        channelDownloadLog.setCustomerUserId(userDetail.getId());
        channelDownloadLog.setDownloadUrl(downloadUrl);
        channelDownloadLog.setCreationDate(new Date());
        channelDownloadLog.setUuidFlag(uuid);
        channelDownloadLog.setChannelId(channelByCode.getId());
        save(channelDownloadLog);
    }
 
    @Override
    public void addAutoDownloadLog(Long userId, String downloadUrl) {
        String uuid = IdUtil.randomUUID();
        CustomerUser customerUser = customerUserService.getById(userId);
        if (customerUser==null){
            throw new CommonException("用户不存在");
        }
        ChannelInfo channelByCode = channelInfoMapper.getChannelByCode(customerUser.getSourceChannel());
        if (channelByCode==null){
            throw new CommonException("渠道Code非法");
        }
        log.info("创建渠道下载日志:下载日志UUID=" + uuid + "AppId=" + channelByCode.getAppId() + "下载链接=" + downloadUrl + "用户ID=" + customerUser.getId());
        ChannelDownloadLog channelDownloadLog = new ChannelDownloadLog();
        channelDownloadLog.setCustomerUserId(customerUser.getId());
        channelDownloadLog.setDownloadUrl(downloadUrl);
        channelDownloadLog.setCreationDate(new Date());
        channelDownloadLog.setUuidFlag(uuid);
        channelDownloadLog.setChannelId(channelByCode.getId());
        save(channelDownloadLog);
    }
}