admin
2024-06-30 b6fdf185c7e8fb1f06da0e609e39aecaef6b66f5
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
package com.taoke.autopay.service.impl;
 
import com.taoke.autopay.dao.WxUserInfoMapper;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
import com.taoke.autopay.entity.WxUserInfo;
import com.taoke.autopay.entity.WxUserSettings;
import com.taoke.autopay.service.SystemConfigService;
import com.taoke.autopay.service.WxUserService;
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.Date;
import java.util.List;
 
/**
 * @author hxh
 * @title: WxUserServiceImpl
 * @description: 微信用户服务实现
 * @date 2024/6/28 18:54
 */
@Service
public class WxUserServiceImpl implements WxUserService {
 
    @Resource
    private WxUserInfoMapper wxUserInfoMapper;
 
    @Resource
    private WxUserSettingService wxUserSettingService;
 
    @Resource
    private SystemConfigService systemConfigService;
 
 
    @Transactional(rollbackFor = Exception.class)
    @Override
    public WxUserInfo login(String openid) {
        // 查询用户是否存在
        WxUserInfoMapper.DaoQuery query = new WxUserInfoMapper.DaoQuery();
        query.openId = openid;
        query.count = 1;
        query.start = 0;
        List<WxUserInfo> list = wxUserInfoMapper.list(query);
        if (list.size() == 0) {
            // 没有数据,需要注册
            WxUserInfo user = new WxUserInfo();
            user.setOpenId(openid);
            user.setLoginTime(new Date());
            user.setCreateTime(new Date());
            wxUserInfoMapper.insertSelective(user);
 
            WxUserSettings settings = new WxUserSettings();
            settings.setId(user.getId());
            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));
            }
            wxUserSettingService.add(settings);
            return user;
        } else {
            WxUserInfo update = new WxUserInfo();
            update.setId(list.get(0).getId());
            update.setLoginTime(new Date());
            update.setUpdateTime(new Date());
            wxUserInfoMapper.updateByPrimaryKeySelective(update);
            return list.get(0);
        }
    }
 
    @Override
    public WxUserInfo selectById(Long id) {
        return wxUserInfoMapper.selectByPrimaryKey(id);
    }
 
    @Override
    public List<WxUserInfo> list(WxUserInfoMapper.DaoQuery query, int page, int pageSize) {
        query.start = (page - 1) * pageSize;
        query.count = pageSize;
        return wxUserInfoMapper.list(query);
    }
 
    @Override
    public long count(WxUserInfoMapper.DaoQuery query) {
        return wxUserInfoMapper.count(query);
    }
}