xiaoyong931011
2021-08-04 ea868a98b776b9e89db429a195704a1412ca8905
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
package com.xzx.gc.user.service;
 
import cn.hutool.core.collection.CollUtil;
import com.xzx.gc.entity.ConfigInfo;
import com.xzx.gc.entity.CoreSetMoney;
import com.xzx.gc.user.mapper.AccountMapper;
import com.xzx.gc.user.mapper.ConfigMapper;
import com.xzx.gc.user.mapper.OtherUserMapper;
import com.xzx.gc.util.DoubleUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
 
@Service
@Transactional
public class ConfigService {
    @Autowired
    private ConfigMapper configMapper;
 
    @Autowired
    private OtherUserMapper otherUserMapper;
 
    @Autowired
    private AccountMapper accountMapper;
 
 
    public ConfigInfo findByCode(String typeCode) {
        ConfigInfo configInfo=new ConfigInfo();
        configInfo.setConfigTypeCode(typeCode);
        List<ConfigInfo> list = configMapper.select(configInfo);
        if(CollUtil.isNotEmpty(list)){
            return list.get(0);
        }
        return  null;
    }
 
    public List<ConfigInfo> findByGroup(String group) {
        ConfigInfo configInfo=new ConfigInfo();
        configInfo.setConfigGroup(group);
        List<ConfigInfo> select = configMapper.select(configInfo);
        return select;
    }
 
 
    public void updateMoneySetting(CoreSetMoney money) {
        if (!StringUtils.isEmpty(money.getAgentPrice())) {
            configMapper.updateAgentPrice(money);
        }
        if (!StringUtils.isEmpty(money.getTimeInterval())) {
            configMapper.updateTimeInterval(money);
        }
        if (!StringUtils.isEmpty(money.getStartTime())) {
            configMapper.updateStratTime(money);
        }
        if (!StringUtils.isEmpty(money.getEndTime())) {
            configMapper.updateEndTime(money);
        }
        if (!StringUtils.isEmpty(money.getOverdrawPrice())) {
            Map<String, Object> m = configMapper.queryOverdrawPrice();
            //String limitPrice = m.get("configValue").toString();
            if(null!=m){
                List<String> orderIds = otherUserMapper.queryRKOrderIds(m.get("configValue").toString(), "1");
                if (null != orderIds && orderIds.size() > 0) {
                    if (money.getOverdrawPrice().equals(m.get("configValue").toString())) {
                        // 需要更新所有account表的透支额度,但是不更新已经修改过的用户额度
                        if(null!=money.getWarehousingPrice()){
                            money.setWarehousingPrice(DoubleUtil.roundTwo(money.getWarehousingPrice()));
                        }
                        if(null!=money.getOverdrawPrice()){
                            money.setOverdrawPrice(DoubleUtil.roundTwo(money.getOverdrawPrice()));
 
                        }
                        configMapper.updateOverdrawPrice(money);
                        accountMapper.updateAccountOverdrawPrice(money.getOverdrawPrice(), m.get("configValue").toString(), orderIds, null);
                    } else {
                        money.setWarehousingPrice(DoubleUtil.roundTwo(money.getWarehousingPrice()));
                        money.setOverdrawPrice(DoubleUtil.roundTwo(money.getOverdrawPrice()));
                        configMapper.updateOverdrawPrice(money);
                        accountMapper.updateAccountOverdrawPrice(money.getOverdrawPrice(), m.get("configValue").toString(), orderIds, "1");
 
                    }
                }
            }
 
 
 
        }
        if (!StringUtils.isEmpty(money.getWarehousingPrice())) {
            Map<String, Object> m = configMapper.queryWarehousingPrice();
            List<String> orderIds = otherUserMapper.queryRKOrderIds(m.get("configValue").toString(), null);
            if (null != orderIds && orderIds.size() > 0) {
                if (money.getOverdrawPrice().equals(m.get("configValue").toString())) {
                    money.setWarehousingPrice(DoubleUtil.roundTwo(money.getWarehousingPrice()));
                    money.setOverdrawPrice(DoubleUtil.roundTwo(money.getOverdrawPrice()));
                    configMapper.updateWarehousingPrice(money);
                    accountMapper.updateAccountWarehousingPrice(money.getWarehousingPrice(), m.get("configValue").toString(), orderIds, null);
 
                } else {
                    money.setWarehousingPrice(DoubleUtil.roundTwo(money.getWarehousingPrice()));
                    money.setOverdrawPrice(DoubleUtil.roundTwo(money.getOverdrawPrice()));
                    configMapper.updateWarehousingPrice(money);
                    accountMapper.updateAccountWarehousingPrice(money.getWarehousingPrice(), m.get("configValue").toString(), orderIds, "1");
 
                }
            }
 
 
        }
        if (!StringUtils.isEmpty(money.getRechargePrice())) {
            configMapper.updateRechargePrice(money);
        }
 
        if (!StringUtils.isEmpty(money.getOrderTimeout())) {
            configMapper.updateOrderTimeout(money);
        }
        if (!StringUtils.isEmpty(money.getOrderTotal())) {
            configMapper.updateOrderTotal(money);
        }
        if (!StringUtils.isEmpty(money.getOrderViewNum())) {
            BigDecimal ovN = new BigDecimal(money.getOrderViewNum());
            if(ovN.compareTo(BigDecimal.ZERO)==0){
                configMapper.updateOrderViewNum(money);
 
            }else if(ovN.compareTo(BigDecimal.ZERO)==1){
                if(null!=money.getOrderTotal()&&!"".equals(money.getOrderTotal())){
                    money.setOrderViewNum(money.getOrderTotal());
                    configMapper.updateOrderViewNum(money);
                }
 
 
 
            }
        }
    }
 
 
}