feat():增删改查
parent
879d4949a9
commit
f5246e2f24
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.cloud.pay.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.cloud.pay.domain.OrderPayCustomer;
|
||||
import com.muyu.cloud.pay.domain.OrderPayInfo;
|
||||
|
@ -11,7 +12,9 @@ import com.muyu.cloud.pay.mapper.OrderPayCustomerMapper;
|
|||
import com.muyu.cloud.pay.service.OrderPayCustomerService;
|
||||
import com.muyu.cloud.pay.service.OrderPayService;
|
||||
import com.muyu.common.core.enums.SysPayType;
|
||||
import com.muyu.common.core.enums.SystemYesNo;
|
||||
import com.muyu.common.core.exception.ServiceException;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.nacos.service.NacosServerService;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -19,7 +22,9 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
@ -45,6 +50,7 @@ public class OrderPayCustomerServiceImpl
|
|||
|
||||
/**
|
||||
* 查询客户集合
|
||||
*
|
||||
* @param customerListReq
|
||||
* @return
|
||||
*/
|
||||
|
@ -75,37 +81,102 @@ public class OrderPayCustomerServiceImpl
|
|||
|
||||
/**
|
||||
* 获取所有的客户
|
||||
*
|
||||
* @return客户集合
|
||||
*/
|
||||
@Override
|
||||
public List<String> getCustomerAllList () {
|
||||
public List<String> getCustomerAllList() {
|
||||
List<String> nacosServerAllList = nacosServerService.nacosServerAllList();
|
||||
LambdaQueryWrapper<OrderPayCustomer> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.select(OrderPayCustomer::getAppCode);
|
||||
List<OrderPayCustomer> orderPayCustomerList = this.list(queryWrapper);
|
||||
Set<String> customerSet
|
||||
= orderPayCustomerList.stream().map(OrderPayCustomer::getAppCode).collect(Collectors.toSet());
|
||||
Set<String> customerSet = orderPayCustomerList.stream()
|
||||
.map(OrderPayCustomer::getAppCode)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
return nacosServerAllList.stream()
|
||||
.filter(nacosServer -> !customerSet.contains(nacosServer))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeById(Serializable id) {
|
||||
OrderPayCustomer orderPayCustomer = this.getById(id);
|
||||
if (orderPayCustomer==null){
|
||||
throw new ServiceException("客户不存在");
|
||||
}
|
||||
LambdaQueryWrapper<OrderPayInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(OrderPayInfo::getAppCode,orderPayCustomer.getAppCode());
|
||||
queryWrapper.gt(OrderPayInfo::getCreateTime, DateUtils.addDays(new Date(),-7));
|
||||
long count = orderPayService.count();
|
||||
if (count>0){
|
||||
throw new RuntimeException(
|
||||
StringUtils.format("客户:[{}],近七天还在使用,不可删除",orderPayCustomer.getAppName())
|
||||
);
|
||||
}
|
||||
return super.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的客户1111111111
|
||||
* 禁用客户
|
||||
*
|
||||
* @param orderCustomerId 客户ID
|
||||
*/
|
||||
@Override
|
||||
public void disable(Long orderCustomerId) {
|
||||
this.settingStatus(orderCustomerId, SystemYesNo.NO.getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用客户
|
||||
*
|
||||
* @param orderCustomerId 客户Id
|
||||
*/
|
||||
@Override
|
||||
public void enable(Long orderCustomerId) {
|
||||
this.settingStatus(orderCustomerId, SystemYesNo.YES.getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过客户ID设置客户状态
|
||||
* @param orderCustomerId id
|
||||
* @param status 状态 SysIsYesNo
|
||||
*/
|
||||
public void settingStatus(Long orderCustomerId, String status) {
|
||||
LambdaQueryWrapper<OrderPayCustomer> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(OrderPayCustomer::getId, orderCustomerId);
|
||||
boolean isExists = this.exists(queryWrapper);
|
||||
if (!isExists) {
|
||||
throw new ServiceException("操作客户不存在");
|
||||
}
|
||||
|
||||
if (!SystemYesNo.isCode(status)){
|
||||
throw new ServiceException("设置状态值违法");
|
||||
}
|
||||
LambdaUpdateWrapper<OrderPayCustomer> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(OrderPayCustomer::getId,orderCustomerId);
|
||||
updateWrapper.set(OrderPayCustomer::getStatus,status);
|
||||
this.update(updateWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的客户
|
||||
*
|
||||
* @return客户集合
|
||||
*/
|
||||
@Override
|
||||
public boolean save(OrderPayCustomer orderPayCustomer) {
|
||||
String appCode = orderPayCustomer.getAppCode();
|
||||
List<String> nacosServerAllList = nacosServerService.nacosServerAllList();
|
||||
log.info("进行服务合法性判断:[{}->{}]",appCode,nacosServerAllList);
|
||||
if (!nacosServerAllList.contains(appCode)){
|
||||
log.info("进行服务合法性判断:[{}->{}]", appCode, nacosServerAllList);
|
||||
if (!nacosServerAllList.contains(appCode)) {
|
||||
throw new ServiceException("客户编码违法");
|
||||
}
|
||||
LambdaQueryWrapper<OrderPayCustomer> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(OrderPayCustomer::getAppCode,appCode);
|
||||
queryWrapper.eq(OrderPayCustomer::getAppCode, appCode);
|
||||
long isAppCodeOnly = this.count(queryWrapper);
|
||||
log.info("进行服务code唯一性校验:[{}--{}]",appCode,isAppCodeOnly);
|
||||
if (isAppCodeOnly>0){
|
||||
log.info("进行服务code唯一性校验:[{}--{}]", appCode, isAppCodeOnly);
|
||||
if (isAppCodeOnly > 0) {
|
||||
throw new ServiceException("客户编码重复");
|
||||
}
|
||||
return super.save(orderPayCustomer);
|
||||
|
|
Loading…
Reference in New Issue