master
陈思豪 2024-08-08 19:44:59 +08:00
parent 7ae3a99737
commit 849bdc5725
6 changed files with 291 additions and 65 deletions

View File

@ -4,9 +4,13 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.domain.req.OrderCustomerAddReq;
import com.muyu.domain.req.OrderCustomerUpdReq;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.util.function.Supplier;
@SuperBuilder
@Data
@AllArgsConstructor
@ -42,5 +46,24 @@ public class OrderPayCustomer extends BaseEntity {
*/
private String status;
public static OrderPayCustomer addBuild(OrderCustomerAddReq req){
return OrderPayCustomer.builder()
.appName(req.getAppName())
.appCode(req.getAppCode())
.appDesc(req.getAppDesc())
.status(req.getStatus())
.remark(req.getRemark())
.build();
}
public static OrderPayCustomer updBuild(OrderCustomerUpdReq req, Supplier<Long> idSupplier){
return OrderPayCustomer.builder()
.id(idSupplier.get())
.appName(req.getAppName())
.appDesc(req.getAppDesc())
.status(req.getStatus())
.remark(req.getRemark())
.build();
}
}

View File

@ -0,0 +1,58 @@
package com.muyu.domain.req;
import com.muyu.common.core.validation.custom.IsSystemYesNo;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Tag(name = "支付服务客户添加请求对象", description = "根据入参进行客户服务的添加")
public class OrderCustomerAddReq {
/**
* /
*/
@NotEmpty(message = "服务客户名称不可为空")
@Schema(title = "服务/客户名称", type = "String", defaultValue = "会员服务",
description = "客户名称一般为微服务的中文名称,方便使用者进行区分", requiredProperties = {"appName"})
private String appName;
/**
* /
*/
@NotBlank(message = "服务客户编码不可为空")
@Schema(title = "服务/客户编码", type = "String", defaultValue = "muyu-vip",
description = "客户编码,从[/customer/all]接口当中进行获取", requiredProperties = {"appName"})
private String appCode;
/**
* /
*/
@Schema(title = "服务/客户描述", type = "String")
private String appDesc;
/**
*
*/
@NotBlank(message = "客户使用状态不可为空")
@IsSystemYesNo
@Schema(title = "服务/客户开通状态", type = "String", defaultValue = "Y",
description = "状态为Y和N如果为Y则客户可以使用支付接口若为N则客户不可以使用支付类接口")
private String status;
/**
*
*/
@Schema(title = "服务/客户备注", type = "String")
private String remark;
}

View File

@ -0,0 +1,46 @@
package com.muyu.domain.req;
import com.muyu.common.core.validation.custom.IsSystemYesNo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrderCustomerUpdReq {
/**
* /
*/
@NotEmpty(message = "服务客户名称不可为空")
@Schema(title = "服务/客户名称", type = "String", defaultValue = "会员服务",
description = "客户名称为微服务的中文名称", requiredProperties = {"appName"})
private String appName;
/**
* /
*/
@Schema(title = "服务/客户描述", type = "String")
private String appDesc;
/**
*
*/
@NotBlank(message = "客户使用状态不可为空")
@IsSystemYesNo
@Schema(title = "服务/客户开通状态", type = "String", defaultValue = "Y",
description = "状态为Y和N如果为Y则客户可以使用支付接口若为N则客户不可以使用支付类接口")
private String status;
/**
*
*/
@Schema(title = "服务/客户备注", type = "String")
private String remark;
}

View File

@ -4,6 +4,8 @@ import com.dtflys.forest.springboot.annotation.ForestScannerRegister;
import com.muyu.common.core.domain.Result;
import com.muyu.domain.OrderPayCustomer;
import com.muyu.domain.req.CustomerListReq;
import com.muyu.domain.req.OrderCustomerAddReq;
import com.muyu.domain.req.OrderCustomerUpdReq;
import com.muyu.domain.resp.CustomerResp;
import com.muyu.pay.service.OrderPayCustomerService;
import io.swagger.v3.oas.annotations.Operation;
@ -17,25 +19,25 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
@Log4j2
@RestController
@RequestMapping("/customer")
@Log4j2
@Tag(name = "客户控制层",description = "进行客户管理,查看等相关操作")
@Tag(name = "客户控制层", description = "进行客户管理、查看等相关操作")
public class OrderPayCustomerController {
public OrderPayCustomerController (){
log.info("扫描路径{}", ForestScannerRegister.getBasePackages());
public OrderPayCustomerController () {
log.info("forest扫描路径:{}", ForestScannerRegister.getBasePackages());
}
@Autowired
private OrderPayCustomerService orderPayCustomerService;
/**
*
*/
@RequestMapping(path = "/list",method = RequestMethod.POST)
@Operation(summary = "查看客户" , description = "根据客户的名称,编码,是否开启等可以镜像客户的筛选")
public Result<List<CustomerResp>> selectList(@Validated @RequestBody CustomerListReq customerListReq){
@RequestMapping(path = "/list", method = RequestMethod.POST)
@Operation(summary = "查看客户", description = "根据客户的名称、编码、是否开启等可以进行客户的筛选")
public Result<List<CustomerResp>> selectList(
@Validated @RequestBody CustomerListReq customerListReq) {
return Result.success(
orderPayCustomerService.selectList(customerListReq)
);
@ -43,9 +45,61 @@ public class OrderPayCustomerController {
@GetMapping("/all")
@Operation(summary = "获取未接入的客户",description = "调用nacosAPI获取所有的微服务名称")
@Schema(description = "获取未接入的客户",defaultValue = "客户1客户2",type = "List")
@Operation(summary = "获取未接入的客户", description = "调用nacosAPI获取所有的微服务名称,作为支付中台的客户")
@Schema(description = "获取未接入的客户", defaultValue = "[\"客户1\",\"客户2\"]", type = "List")
public Result<List<String>> getCustomerAllList(){
return Result.success(orderPayCustomerService.getCustomerAllList());
return Result.success(
orderPayCustomerService.getCustomerAllList()
);
}
@PostMapping
@Operation(summary = "客户信息添加",description = "添加支付平台客户信息,添加成功之后才可以使用支付类的产品")
public Result<String> save(@Validated @RequestBody OrderCustomerAddReq orderCustomerAddReq) {
orderPayCustomerService.save(OrderPayCustomer.addBuild(orderCustomerAddReq));
return Result.success(null, "操作成功");
}
@PutMapping("/{orderCustomerId}")
@Operation(summary = "客户信息修改", description = "通过ID修改客户信息")
public Result<String> update(
@Schema(title = "客户ID", type = "Long", defaultValue = "1", description = "修改客户信息需要依据的唯一条件")
@PathVariable("orderCustomerId") Long orderCustomerId,
@RequestBody @Validated OrderCustomerUpdReq orderCustomerUpdReq){
orderPayCustomerService.updateById(OrderPayCustomer.updBuild(orderCustomerUpdReq, () -> orderCustomerId));
return Result.success(null, "操作成功");
}
@DeleteMapping("/{orderCustomerId}")
@Operation(summary = "客户信息删除", description = "通过ID删除客户信息")
public Result<String> delete(@PathVariable("orderCustomerId") Long orderCustomerId){
orderPayCustomerService.removeById(orderCustomerId);
return Result.success(null, "操作成功");
}
@GetMapping("/{orderCustomerId}")
@Operation(summary = "通过ID获取客户信息", description = "通过ID获取客户信息")
public Result<OrderPayCustomer> findById(@PathVariable("orderCustomerId") Long orderCustomerId){
return Result.success(orderPayCustomerService.getById(orderCustomerId), "操作成功");
}
@GetMapping("/disable/{orderCustomerId}")
@Operation(summary = "通过ID禁用客户", description = "通过ID禁用客户")
public Result<String> disable(@PathVariable("orderCustomerId") Long orderCustomerId){
this.orderPayCustomerService.disable(orderCustomerId);
return Result.success(null, "操作成功");
}
@GetMapping("/enable/{orderCustomerId}")
@Operation(summary = "通过ID启用客户", description = "通过ID启用客户")
public Result<String> enable(@PathVariable("orderCustomerId") Long orderCustomerId){
this.orderPayCustomerService.enable(orderCustomerId);
return Result.success(null, "操作成功");
}
}

View File

@ -1,5 +1,6 @@
package com.muyu.pay.service;
import cn.hutool.log.Log;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.domain.OrderPayCustomer;
import com.muyu.domain.req.CustomerListReq;
@ -15,4 +16,11 @@ public interface OrderPayCustomerService extends IService<OrderPayCustomer> {
public List<CustomerResp> selectList(CustomerListReq customerListReq);
List<String> getCustomerAllList();
void disable (Long orderCustomerId);
void enable(Long orderCustomerId);
void settingStatus(Long orderCustomerId, String status);
}

View File

@ -1,32 +1,37 @@
package com.muyu.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.common.core.utils.StringUtils;
import com.muyu.common.nacos.service.NacosServerService;
import com.dtflys.forest.Forest;
import com.muyu.domain.OrderPayCustomer;
import com.muyu.domain.OrderPayInfo;
import com.muyu.domain.req.CustomerListReq;
import com.muyu.domain.resp.CustomerOrderPaySimpleResp;
import com.muyu.domain.resp.CustomerResp;
import com.muyu.pay.controller.OrderPayCustomerController;
import com.muyu.pay.mapper.OrderPayCustomerMapper;
import com.muyu.pay.service.OrderPayCustomerService;
import com.muyu.pay.service.OrderPayService;
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 lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
@Log4j2
@Service
public class OrderPayCustomerServiceImpl extends ServiceImpl<OrderPayCustomerMapper ,OrderPayCustomer>
implements OrderPayCustomerService {
public class OrderPayCustomerServiceImpl
extends ServiceImpl<OrderPayCustomerMapper, OrderPayCustomer>
implements OrderPayCustomerService {
@Autowired
private OrderPayService orderPayService;
@ -34,17 +39,18 @@ public class OrderPayCustomerServiceImpl extends ServiceImpl<OrderPayCustomerMap
@Autowired
private NacosServerService nacosServerService;
@Override
public List<CustomerResp> selectList(CustomerListReq customerListReq) {
public List<CustomerResp> selectList (CustomerListReq customerListReq) {
LambdaQueryWrapper<OrderPayCustomer> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(
StringUtils.isNotEmpty(customerListReq.getAppCode()),
OrderPayCustomer::getAppCode, customerListReq.getAppCode()
);
queryWrapper.like(
StringUtils.isNotEmpty(customerListReq.getAppName()),
OrderPayCustomer::getAppName, customerListReq.getAppName()
);
queryWrapper.like(
StringUtils.isNotEmpty(customerListReq.getAppCode()),
OrderPayCustomer::getAppCode, customerListReq.getAppCode()
);
queryWrapper.eq(
StringUtils.isNotEmpty(customerListReq.getStatus()),
OrderPayCustomer::getStatus, customerListReq.getStatus()
@ -62,8 +68,9 @@ public class OrderPayCustomerServiceImpl extends ServiceImpl<OrderPayCustomerMap
.toList();
}
@Override
public List<String> getCustomerAllList() {
public List<String> getCustomerAllList () {
List<String> nacosServerAllList = nacosServerService.nacosServiceAllList();
LambdaQueryWrapper<OrderPayCustomer> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.select(OrderPayCustomer::getAppCode);
@ -74,41 +81,71 @@ public class OrderPayCustomerServiceImpl extends ServiceImpl<OrderPayCustomerMap
.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(queryWrapper);
if (count > 0) {
throw new ServiceException(
StringUtils.format("客户:[{}], 七天还用, 不能删除", orderPayCustomer.getAppName())
);
}
return super.removeById(id);
}
@Override
public void disable (Long orderCustomerId) {
this.settingStatus(orderCustomerId, SystemYesNo.NO.getCode());
}
@Override
public void enable (Long orderCustomerId) {
this.settingStatus(orderCustomerId, SystemYesNo.YES.getCode());
}
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);
}
@Override
public boolean save (OrderPayCustomer orderPayCustomer) {
String appCode = orderPayCustomer.getAppCode();
List<String> nacosServerAllList = nacosServerService.nacosServiceAllList();
log.info("进行服务合法性判断:[{}->{}]", appCode, nacosServerAllList);
if (!nacosServerAllList.contains(appCode)){
throw new ServiceException("客户编码违法");
}
LambdaQueryWrapper<OrderPayCustomer> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(OrderPayCustomer::getAppCode, appCode);
long isAppCodeOnly = this.count(queryWrapper);
log.info("进行服务code唯一性校验[{}-{}]", appCode, isAppCodeOnly);
if (isAppCodeOnly > 0){
throw new ServiceException("客户编码重复");
}
return super.save(orderPayCustomer);
}
}