xiaoyong931011
2021-07-15 2f2006691270d2788e32ca3eeae5a3b2faed0fc1
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
package com.xzx.gc.user.service;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.xzx.gc.entity.ConfigInfo;
import com.xzx.gc.entity.CoreSetMoney;
import com.xzx.gc.entity.PartnerConfig;
import com.xzx.gc.user.mapper.PartnerConfigMapper;
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 tk.mybatis.mapper.entity.Example;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
@Service
@Transactional
public class PartnerConfigService {
 
    @Autowired
    private PartnerConfigMapper partnerConfigMapper;
 
    @Autowired
    private ConfigService configService;
    @Autowired
    private CityPartnerService cityPartnerService;
 
    private String checkConfigValue(String type,String partnerId){
        PartnerConfig config = new PartnerConfig();
        config.setConfigCode(type);
        config.setPartnerId(Long.parseLong(partnerId));
        String num = partnerConfigMapper.selectConfigByCode(config);
        return num;
    }
    private int updateConfigValue(Long id,String code, String value, String partnerId, String groupType){
        PartnerConfig config = new PartnerConfig();
        config.setId(id);
        config.setConfigCode(code);
        config.setConfigValue(value);
        config.setConfigGroup(groupType);
        config.setPartnerId(Long.parseLong(partnerId));
        config.setUpdateTime(new Date());
        int num = partnerConfigMapper.updateByPrimaryKeySelective(config);
        return num;
    }
    private int insertConfigValue(String code, String value, String partnerId, String groupType){
        PartnerConfig config = new PartnerConfig();
        config.setConfigCode(code);
        config.setConfigValue(value);
        config.setConfigGroup(groupType);
        config.setPartnerId(Long.parseLong(partnerId));
        config.setDelFlag((byte)0);
        config.setCreateTime(new Date());
        int num = partnerConfigMapper.insertUseGeneratedKeys(config);
        return num;
    }
    public void updateMoneyPartnerSetting(CoreSetMoney money,String partnerId) {
        if (!StringUtils.isEmpty(money.getTimeInterval())) {
            String psId = checkConfigValue("INTERVAL_TIME",partnerId);
            if(null!=psId&&!"".equals(psId)){
                updateConfigValue(Long.parseLong(psId),"INTERVAL_TIME",money.getTimeInterval(),partnerId,"orderTime");
            }else{
                insertConfigValue("INTERVAL_TIME",money.getTimeInterval(),partnerId,"orderTime");
            }
        }
        if (!StringUtils.isEmpty(money.getStartTime())) {
            String psId = checkConfigValue("START_TIME",partnerId);
            if(null!=psId&&!"".equals(psId)){
                updateConfigValue(Long.parseLong(psId),"START_TIME",money.getStartTime(),partnerId,"orderTime");
            }else{
                insertConfigValue("START_TIME",money.getStartTime(),partnerId,"orderTime");
            }
        }
        if (!StringUtils.isEmpty(money.getEndTime())) {
            String psId = checkConfigValue("END_TIME",partnerId);
            if(null!=psId&&!"".equals(psId)){
                updateConfigValue(Long.parseLong(psId),"END_TIME",money.getEndTime(),partnerId,"orderTime");
            }else{
                insertConfigValue("END_TIME",money.getEndTime(),partnerId,"orderTime");
            }
        }
        if (!StringUtils.isEmpty(money.getOrderTimeout())) {
            String psId = checkConfigValue("ORDERTIMEOUT",partnerId);
            if(null!=psId&&!"".equals(psId)){
                updateConfigValue(Long.parseLong(psId),"ORDERTIMEOUT",money.getOrderTimeout(),partnerId,"");
            }else{
                insertConfigValue("ORDERTIMEOUT",money.getOrderTimeout(),partnerId,"");
            }
        }
        if (!StringUtils.isEmpty(money.getOrderTotal())) {
            String psId = checkConfigValue("ORDERTOTAL",partnerId);
            if(null!=psId&&!"".equals(psId)){
                updateConfigValue(Long.parseLong(psId),"ORDERTOTAL",money.getOrderTotal(),partnerId,"ORDER_NUM");
            }else{
                insertConfigValue("ORDERTOTAL",money.getOrderTotal(),partnerId,"ORDER_NUM");
            }
        }
 
        if (!StringUtils.isEmpty(money.getOrderViewNum())) {
           // BigDecimal ovnum = new BigDecimal(money.getOrderViewNum());
            String psId = checkConfigValue("ORDER_VIEW_TOTAL",partnerId);
            BigDecimal ovN = new BigDecimal(money.getOrderViewNum());
                if(ovN.compareTo(BigDecimal.ZERO)==0){
                    if(null!=psId&&!"".equals(psId)){
                        updateConfigValue(Long.parseLong(psId),"ORDER_VIEW_TOTAL",money.getOrderViewNum(),partnerId,"ORDER_NUM");
                    }else{
                        insertConfigValue("ORDER_VIEW_TOTAL",money.getOrderViewNum(),partnerId,"ORDER_NUM");
                    }
                }else if(ovN.compareTo(BigDecimal.ZERO)==1){
                    if (!StringUtils.isEmpty(money.getOrderTotal())) {
                        if(null!=psId&&!"".equals(psId)){
                            updateConfigValue(Long.parseLong(psId),"ORDER_VIEW_TOTAL",money.getOrderTotal(),partnerId,"ORDER_NUM");
                        }else{
                            insertConfigValue("ORDER_VIEW_TOTAL",money.getOrderTotal(),partnerId,"ORDER_NUM");
                        }
                    }
 
                }
 
 
        }
    }
 
    public List<PartnerConfig> queryPartnerConfigByPid(String s) {
        Example example = new Example(PartnerConfig.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("partnerId", s);
        return partnerConfigMapper.selectByExample(example);
    }
 
    public void updateMoney(CoreSetMoney coreSetMoney){
        List<String> partnerIds = cityPartnerService.queryPartnerByCurrent();
        if(null!=partnerIds&&partnerIds.size()>0){
            updateMoneyPartnerSetting(coreSetMoney,partnerIds.get(0));
        }else{
            configService.updateMoneySetting(coreSetMoney);
        }
    }
}