jiangping
2024-07-18 64a6a81753abfc712b1ab384de0f7afb87f4fb23
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package com.doumee.service.business.impl;
 
import com.doumee.biz.zbom.ZbomCRMService;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
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;
    @Autowired
    private ZbomCRMService zbomCRMService;
 
    @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 reSubmit(CustomerLog customerLog){
        CustomerLog log = customerLogMapper.selectById(customerLog.getId());
        if(log ==null || Constants.equalsInteger(log.getIsdeleted(),Constants.ONE)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(Constants.equalsInteger(log.getCrmStatus(),Constants.ONE)){
            //如果已经提交成功过
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该留资数据已提交,无需重新提交!");
        }
        zbomCRMService.dealCustomerLogData(log);
    }
    @Override
    public void reSubmitAll(CustomerLog log){
        List<CustomerLog> logList = customerLogMapper.selectList(new QueryWrapper<CustomerLog>()
                .lambda()
                .eq(CustomerLog::getIsdeleted,Constants.ZERO)
                .eq(log.getCrmStatus()!=null,CustomerLog::getCrmStatus,log.getCrmStatus())
                .ne(CustomerLog::getCrmStatus,Constants.ONE));
        if(logList ==null || logList.size() ==0){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,不存在待处理数据");
        }
        if(Constants.equalsInteger(log.getCrmStatus(),Constants.ONE)){
            //如果已经提交成功过
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该留资数据已提交,无需重新提交!");
        }
        for(CustomerLog model :logList){
            zbomCRMService.dealCustomerLogData(model);
        }
    }
 
    @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);
    }
}