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
75
76
77
78
79
package com.nova.sankuai.service.impl;
 
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nova.sankuai.domain.dto.ChannelVisitDto;
import com.nova.sankuai.domain.dto.H5LoanMarketViewLogDto;
import com.nova.sankuai.domain.entity.ChannelInfo;
import com.nova.sankuai.domain.entity.H5LoanMarketViewLog;
import com.nova.sankuai.domain.vo.channel.H5LoanMarketViewVo;
import com.nova.sankuai.infra.config.CommonException;
import com.nova.sankuai.infra.mapper.ChannelInfoMapper;
import com.nova.sankuai.infra.mapper.H5LoanMarketViewLogMapper;
import com.nova.sankuai.infra.utils.PageRequest;
import com.nova.sankuai.infra.utils.PageUtil;
import com.nova.sankuai.service.IH5LoanMarketViewLogService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * @author weikangdi
 * @create 2021/12/30
 */
@Service
@AllArgsConstructor
@Slf4j
public class H5LoanMarketViewLogImpl extends ServiceImpl<H5LoanMarketViewLogMapper, H5LoanMarketViewLog> implements IH5LoanMarketViewLogService {
 
    private final H5LoanMarketViewLogMapper h5LoanMarketViewLogMapper;
 
    private final ChannelInfoMapper channelInfoMapper;
 
    private final PageUtil pageUtil;
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addH5LoanMarketViewLog(H5LoanMarketViewLogDto viewLogDto) {
        List<H5LoanMarketViewLog> toSaveLogs = new ArrayList();
        String uuid = IdUtil.randomUUID();
        ChannelInfo channelInfo = channelInfoMapper.getChannelByAppId(viewLogDto.getAppId());
        if (channelInfo == null) {
            log.error("添加H5渠道贷超记录失败,渠道AppId非法, 原始信息:" + viewLogDto.toString());
            throw new CommonException("渠道Id非法");
        }
        Date date = new Date();
        H5LoanMarketViewLog loanMarketViewLog = new H5LoanMarketViewLog();
        loanMarketViewLog.setChannelId(channelInfo.getId());
        loanMarketViewLog.setCreation_date(date);
        loanMarketViewLog.setVisitType(viewLogDto.getType());
        loanMarketViewLog.setUuidFlag(uuid);
        loanMarketViewLog.setLoanMarketId(viewLogDto.getLoanMarketId());
        toSaveLogs.add(loanMarketViewLog);
        if (H5LoanMarketViewLog.TYPE_UV == viewLogDto.getType()) {
            H5LoanMarketViewLog loanMarketViewLogPV = new H5LoanMarketViewLog();
            loanMarketViewLogPV.setChannelId(channelInfo.getId());
            loanMarketViewLogPV.setCreation_date(date);
            loanMarketViewLogPV.setVisitType(H5LoanMarketViewLog.TYPE_PV);
            loanMarketViewLogPV.setUuidFlag(uuid);
            loanMarketViewLogPV.setLoanMarketId(viewLogDto.getLoanMarketId());
            toSaveLogs.add(loanMarketViewLogPV);
        }
        if (toSaveLogs.size() > 0) {
            saveBatch(toSaveLogs);
        }
    }
 
    @Override
    public IPage<H5LoanMarketViewVo> getH5LoanMarketViewLogs(PageRequest pageRequest, ChannelVisitDto visitDto) {
        visitDto = visitDto.initDate();
        IPage<H5LoanMarketViewVo> result = h5LoanMarketViewLogMapper.getH5LoanMarketViewLogs(pageUtil.getPage(pageRequest), visitDto);
        return result;
    }
}