中扬CRM客户关系管理系统
Junjie
2023-09-07 8cbd2425dc7e21e9dfb56f3f68f13ec82142655b
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
package com.zy.crm.manager.service.impl;
 
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.core.common.Cools;
import com.zy.crm.manager.entity.Order;
import com.zy.crm.manager.mapper.OrderMapper;
import com.zy.crm.manager.service.OrderService;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 
@Service("orderService")
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
 
    @Override
    public Order selectByUuid(Long hostId, String uuid) {
        return this.baseMapper.selectByUuid(hostId, uuid);
    }
 
    @Override
    public Page<Order> getPage(Page<Order> page, Long hostId, String deptId, Long userId, String condition) {
        return page.setRecords(baseMapper.listByPage(page, hostId, deptId, userId, condition));
    }
 
    @Override
    public String getUuid(Long hostId) {
        String uuid = null;
        int times = 0;
        while (Cools.isEmpty(uuid)) {
            if (times > 100) { break; }
            String nextUuid = getNextUuid(hostId);
            if (selectByUuid(hostId, nextUuid) == null) {
                uuid = nextUuid;
            }
            times ++;
        }
        return uuid;
    }
 
    private String getNextUuid(Long hostId) {
        Order order = this.baseMapper.selectOrderByNewestUuid(hostId);
        if (order == null) {
            return "0001";
        }
        return zerofill(String.valueOf(Integer.parseInt(order.getUuid()) + 1), 4);
    }
 
    public static String zerofill(String msg, Integer count){
        if (msg.length() == count){
            return msg;
        } else if (msg.length() > count){
            return msg.substring(0, 16);
        } else {
            StringBuilder msgBuilder = new StringBuilder(msg);
            for (int i = 0; i<count-msg.length(); i++){
                msgBuilder.insert(0,"0");
            }
            return msgBuilder.toString();
        }
    }
 
    @Override
    public Double selectMoneyByYearAndStatus(String year, Integer status) {
        Double data = this.baseMapper.selectMoneyByYearAndStatus(year, status);
        if (data == null) {
            return 0D;
        }
        return data;
    }
 
    @Override
    public Double selectMoneyByUserAndYearAndStatus(Long userId, String year, Integer status) {
        Double data = this.baseMapper.selectMoneyByUserAndYearAndStatus(userId, year, status);
        if (data == null) {
            return 0D;
        }
        return data;
    }
 
    @Override
    public List<Order> selectTopMoney() {
        return this.baseMapper.selectTopMoney();
    }
 
    @Override
    public List<Double> selectCurrentYearMonthSuccess() {
        ArrayList<Double> list = new ArrayList<Double>(){{
            add(0D);add(0D);add(0D);add(0D);
            add(0D);add(0D);add(0D);add(0D);
            add(0D);add(0D);add(0D);add(0D);
        }};
        for (HashMap<String, Object> map : this.baseMapper.selectCurrentYearMonthSuccess()) {
            list.set(Integer.parseInt(map.get("mon").toString()) - 1, Double.parseDouble(map.get("money").toString()));
        }
        return list;
    }
}