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);
|
}
|
}
|