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