jiangping
2024-07-17 2cbd23d061be5076b86771750bf17615bbecb57d
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.doumee.service.business.impl;
 
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.CustomerLogMapper;
import com.doumee.dao.business.model.*;
import com.doumee.service.business.CustomerLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.List;
import java.util.Objects;
 
/**
 * 客户留资记录信息表Service实现
 * @author 江蹄蹄
 * @date 2024/07/04 14:40
 */
@Service
public class CustomerLogServiceImpl implements CustomerLogService {
 
    @Autowired
    private CustomerLogMapper customerLogMapper;
 
    @Override
    public Long create(CustomerLog customerLog) {
        customerLogMapper.insert(customerLog);
        return customerLog.getId();
    }
 
    @Override
    public void deleteById(Long id) {
        customerLogMapper.deleteById(id);
    }
 
    @Override
    public void delete(CustomerLog customerLog) {
        UpdateWrapper<CustomerLog> deleteWrapper = new UpdateWrapper<>(customerLog);
        customerLogMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Long> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        customerLogMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(CustomerLog customerLog) {
        customerLogMapper.updateById(customerLog);
    }
 
    @Override
    public void updateByIdInBatch(List<CustomerLog> customerLogs) {
        if (CollectionUtils.isEmpty(customerLogs)) {
            return;
        }
        for (CustomerLog customerLog: customerLogs) {
            this.updateById(customerLog);
        }
    }
 
    @Override
    public CustomerLog findById(Long id) {
        return customerLogMapper.selectById(id);
    }
 
    @Override
    public CustomerLog findOne(CustomerLog customerLog) {
        QueryWrapper<CustomerLog> wrapper = new QueryWrapper<>(customerLog);
        return customerLogMapper.selectOne(wrapper);
    }
 
    @Override
    public List<CustomerLog> findList(CustomerLog customerLog) {
        QueryWrapper<CustomerLog> wrapper = new QueryWrapper<>(customerLog);
        return customerLogMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<CustomerLog> findPage(PageWrap<CustomerLog> pageWrap) {
        IPage<CustomerLog> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<CustomerLog> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.selectAll(CustomerLog.class)
                .leftJoin(Customer.class,Customer::getId,CustomerLog::getCostomerId)
                            .eq(CustomerLog::getIsdeleted, Constants.ZERO)
                .eq(Objects.nonNull(pageWrap.getModel().getType()),CustomerLog::getType, pageWrap.getModel().getType())
                .eq(Objects.nonNull(pageWrap.getModel().getMemberId()),Customer::getMemberId, pageWrap.getModel().getMemberId());
        queryWrapper.orderByDesc(CustomerLog::getCreateDate);
        PageData<CustomerLog> pageData = PageData.from(customerLogMapper.selectJoinPage(page,CustomerLog.class, queryWrapper));
        for (CustomerLog customerLog:pageData.getRecords()) {
            customerLog.setPhone(
                    customerLog.getPhone().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")
            );
        }
        return pageData;
    }
 
    @Override
    public long count(CustomerLog customerLog) {
        QueryWrapper<CustomerLog> wrapper = new QueryWrapper<>(customerLog);
        return customerLogMapper.selectCount(wrapper);
    }
}