admin
2024-07-27 65aaf1c05bd06cefa82ebc40cc3e01cf4ac233c0
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
package com.taoke.autopay.service.impl;
 
import com.taoke.autopay.dao.WxUserSettingsMapper;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
import com.taoke.autopay.entity.WxUserSettings;
import com.taoke.autopay.service.SystemConfigService;
import com.taoke.autopay.service.WxUserSettingService;
import com.taoke.autopay.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * @author hxh
 * @title: WxUserSettingServiceImpl
 * @description: TODO
 * @date 2024/6/28 19:10
 */
@Service
public class WxUserSettingServiceImpl implements WxUserSettingService {
 
    @Resource
    private WxUserSettingsMapper wxUserSettingsMapper;
 
    @Resource
    private SystemConfigService systemConfigService;
 
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void add(WxUserSettings settings) {
        WxUserSettings old =   wxUserSettingsMapper.selectByPrimaryKeyForUpdate(settings.getId());
        if(old==null) {
            if (settings.getCreateTime() == null) {
                settings.setCreateTime(new Date());
            }
            wxUserSettingsMapper.insertSelective(settings);
        }else{
            settings.setUpdateTime(new Date());
            wxUserSettingsMapper.updateByPrimaryKeySelective(settings);
        }
    }
 
    /**
     * @author hxh 
     * @description 获取用户设置,如果没有设置就采用默认设置
     * @date 18:32 2024/7/9
     * @param: uid
     * @return com.taoke.autopay.entity.WxUserSettings
     **/
    @Override
    public WxUserSettings getUserSettings(Long uid) {
        WxUserSettings settings = selectByUid(uid);
        if(settings!=null){
            return settings;
        }
        settings = new WxUserSettings();
        settings.setId(uid);
        String value = systemConfigService.getValueCache(SystemConfigKeyEnum.DY_ORDER_MAX_PAY_COUNT_DEFAULT);
        if (!StringUtil.isNullOrEmpty(value)) {
            settings.setDyOrderCountPerDay(Integer.parseInt(value));
        }
        value = systemConfigService.getValueCache(SystemConfigKeyEnum.KS_ORDER_MAX_PAY_COUNT_DEFAULT);
        if (!StringUtil.isNullOrEmpty(value)) {
            settings.setKsOrderCountPerDay(Integer.parseInt(value));
        }
        value = systemConfigService.getValueCache(SystemConfigKeyEnum.ORDER_MAX_SUBMIT_COUNT_DEFAULT);
        if (!StringUtil.isNullOrEmpty(value)) {
            settings.setTotalOrderCountPerDay(Integer.parseInt(value));
        }
       return settings;
    }
 
    @Override
    public WxUserSettings selectByUid(Long uid) {
        return wxUserSettingsMapper.selectByPrimaryKey(uid);
    }
 
    @Override
    public void updateSelective(WxUserSettings settings) {
        if (settings == null) {
            return;
        }
        if (settings.getUpdateTime() == null) {
            settings.setUpdateTime(new Date());
        }
        wxUserSettingsMapper.updateByPrimaryKeySelective(settings);
    }
 
    @Override
    public List<WxUserSettings> listByUids(List<Long> uidList) {
        if (uidList == null || uidList.size() == 0) {
            return new ArrayList<>();
        }
        List<WxUserSettings> list=new ArrayList<>();
        for(Long uid:uidList){
            list.add(getUserSettings(uid));
        }
        return list;
    }
}