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);
|
}
|
}
|