package com.sandu.ximon.admin.pay.wxpay;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.github.pagehelper.PageHelper;
|
import com.sandu.common.execption.BusinessException;
|
import com.sandu.common.object.BaseConditionVO;
|
import com.sandu.common.service.impl.BaseServiceImpl;
|
import com.sandu.ximon.admin.param.WxpayConfigParam;
|
import com.sandu.ximon.admin.security.SecurityUtils;
|
import com.sandu.ximon.admin.service.ClientService;
|
import com.sandu.ximon.admin.service.PoleService;
|
import com.sandu.ximon.admin.utils.SpringContextUtil;
|
import com.sandu.ximon.dao.domain.Pole;
|
import com.sandu.ximon.dao.domain.WxConfigEntity;
|
import com.sandu.ximon.dao.mapper.UsrWxPayConfigMapper;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
/**
|
* @Author liuhaonan
|
* @Date 2022/3/18 14:37
|
* @Version 1.0
|
*/
|
@Service
|
@AllArgsConstructor
|
public class UsrWxPayConfigService extends BaseServiceImpl<UsrWxPayConfigMapper, WxConfigEntity> {
|
|
private final UsrWxPayConfigMapper wxPayConfigMapper;
|
private final ClientService clientService;
|
private final PoleService poleService;
|
|
public WxConfigEntity getConfigByPoleId(Long poleId) {
|
Pole pole = poleService.getById(poleId);
|
if (pole == null) {
|
throw new BusinessException("灯杆id错误或灯杆不存在");
|
}
|
WxConfigEntity config;
|
if (pole.getClientId() == null) {
|
config = getById(0);
|
}
|
config = getOne(Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getCreateUserId, SecurityUtils.getUserId()));
|
if (config == null) {
|
throw new BusinessException("用户未配置支付配置,请配置后重试");
|
}
|
return config;
|
}
|
|
|
public static UsrWxPayConfigService getBean() {
|
return (UsrWxPayConfigService) SpringContextUtil.getBean("UsrWxPayConfigService");
|
}
|
|
|
public boolean addWxPayConfig(WxpayConfigParam configParam) {
|
WxConfigEntity config = new WxConfigEntity();
|
BeanUtil.copyProperties(configParam, config);
|
config.setAppid(configParam.getAppId());
|
config.setAppappid(configParam.getAppAppId());
|
if(SecurityUtils.getClientId()!=null){
|
config.setCreateUserId(SecurityUtils.getUserId());
|
if(clientService.findClientId()){
|
config.setClientId(clientService.getClientId());
|
}
|
}
|
return save(config);
|
}
|
|
public boolean updateWxPayConfig(Long id, WxpayConfigParam configParam) {
|
WxConfigEntity byId = getById(id);
|
if (byId == null) {
|
throw new BusinessException("配置id错误或配置不存在");
|
}
|
WxConfigEntity config = new WxConfigEntity();
|
BeanUtil.copyProperties(configParam, config);
|
config.setAppid(configParam.getAppId());
|
config.setAppappid(configParam.getAppAppId());
|
config.setConfigId(id);
|
return updateById(config);
|
}
|
|
public boolean deleteWxPayConfig(Long id) {
|
WxConfigEntity byId = getById(id);
|
if (byId == null) {
|
throw new BusinessException("配置id错误或配置不存在");
|
}
|
return removeById(id);
|
}
|
|
|
public List<WxConfigEntity> configList(BaseConditionVO baseConditionVO,String keyword) {
|
LambdaQueryWrapper<WxConfigEntity> wrapper = new LambdaQueryWrapper<>();
|
System.out.println("----------------------------" + clientService.findClientId());
|
PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
|
if (SecurityUtils.getClientId() != null) {//客户
|
if (clientService.findClientId()) {//二级客户
|
PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
|
wrapper = Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getCreateUserId, SecurityUtils.getUserId());
|
} else if (!clientService.findClientId()) {//一级客户
|
PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
|
wrapper = Wrappers.lambdaQuery(WxConfigEntity.class).eq(WxConfigEntity::getClientId, SecurityUtils.getUserId());
|
}
|
} else {//管理
|
PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize());
|
wrapper = Wrappers.lambdaQuery(WxConfigEntity.class);
|
}
|
if(!keyword.isEmpty()){
|
wrapper= wrapper.like(WxConfigEntity::getConfigId,keyword).or(
|
appid->{
|
appid.like(WxConfigEntity::getAppid,keyword);
|
}
|
).or(
|
appappid->{
|
appappid.like(WxConfigEntity::getAppappid,keyword);
|
}
|
).or(
|
mchId->{
|
mchId.like(WxConfigEntity::getMchId,keyword);
|
}
|
).or(
|
privateKey->{
|
privateKey.like(WxConfigEntity::getPrivateKey,keyword);
|
}
|
);
|
}
|
return list(wrapper);
|
}
|
|
}
|