feat():增加了删除 修改状态
parent
79256ecd5e
commit
8b4661bd77
|
@ -5,9 +5,12 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import com.muyu.pay.common.domain.req.CustomerAddReq;
|
||||
import com.muyu.pay.common.domain.req.CustomerUpdReq;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
@Data
|
||||
@SuperBuilder
|
||||
|
@ -54,6 +57,17 @@ public class OrderPayCustomer extends BaseEntity {
|
|||
.build();
|
||||
}
|
||||
|
||||
public static OrderPayCustomer updBuild(CustomerUpdReq customerUpdReq, Supplier<Long> id){
|
||||
return OrderPayCustomer.builder()
|
||||
.id(id.get())
|
||||
.appName(customerUpdReq.getAppName())
|
||||
.appDesc(customerUpdReq.getAppDesc())
|
||||
.status(customerUpdReq.getStatus())
|
||||
.remark(customerUpdReq.getRemark())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.muyu.pay.common.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 CustomerUpdReq {
|
||||
/**
|
||||
* 服务/客户名称
|
||||
*/
|
||||
@NotEmpty(message = "服务/客户名称不可为空")
|
||||
@Schema(
|
||||
title = "服务客户名称",
|
||||
description = "客户名称一般为微服务详细中文名称 方便使用者区分",
|
||||
type = "String",
|
||||
defaultValue = "会员服务",
|
||||
requiredProperties ={"appName"}
|
||||
)
|
||||
private String appName;
|
||||
|
||||
|
||||
/**
|
||||
* 客户描述
|
||||
*/
|
||||
@Schema(title = "客户描述",type = "String")
|
||||
private String appDesc;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Schema(
|
||||
title = "开通状态",description = "状态为Y和N 如果为Y客户可以使用支付接口为N不可以使用客户接口",
|
||||
type = "String",defaultValue = "Y"
|
||||
)
|
||||
@NotEmpty(message = "客户使用状态不能为空")
|
||||
@IsSystemYesNo
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(title = "客户备注",type = "String")
|
||||
private String remark;
|
||||
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package com.muyu.pay.server.controller;
|
||||
|
||||
import com.dtflys.forest.annotation.Get;
|
||||
import com.dtflys.forest.springboot.annotation.ForestScannerRegister;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.pay.common.domain.OrderPayCustomer;
|
||||
import com.muyu.pay.common.domain.req.CustomerAddReq;
|
||||
import com.muyu.pay.common.domain.req.CustomerListReq;
|
||||
import com.muyu.pay.common.domain.req.CustomerUpdReq;
|
||||
import com.muyu.pay.common.domain.resp.CustomerResp;
|
||||
import com.muyu.pay.server.service.OrderPayCustomerService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Log4j2
|
||||
@RestController
|
||||
|
@ -58,12 +61,75 @@ public class OrderPayCustomerController {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加客户
|
||||
* @param customerAddReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@Operation(summary = "添加客户信息",description = "添加支付平台客户信息,添加成功后可以使用支付信息")
|
||||
public Result<String> save(@Validated @RequestBody CustomerAddReq customerAddReq){
|
||||
orderPayCustomerService.save(OrderPayCustomer.addBuild(customerAddReq));
|
||||
return Result.success();
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改客户
|
||||
* @param customerUpdReq
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/{orderCustomerId}")
|
||||
@Operation(summary = "客户信息修改",description = "通过客户id修改客户信息")
|
||||
public Result<String> update(
|
||||
@Schema(title = "客户Id",type = "Long",defaultValue = "1")
|
||||
@PathVariable("orderCustomerId") Long orderCustomerId,
|
||||
@RequestBody @Validated CustomerUpdReq customerUpdReq){
|
||||
orderPayCustomerService.updateById( OrderPayCustomer.updBuild(customerUpdReq, ()->orderCustomerId));
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除客户信息
|
||||
* @param orderCustomerId
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/{orderCustomerId}")
|
||||
@Operation(summary = "客户信息删除",description = "通过客户id删除")
|
||||
public Result<String> delete(@PathVariable("orderCustomerId") Long orderCustomerId){
|
||||
orderPayCustomerService.removeById(orderCustomerId);
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
/**
|
||||
* 通过id获取用户信息
|
||||
* @param orderCustomerId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{orderCustomerId}")
|
||||
@Operation(summary = "通过id获取用户信息",description = "通过id获取用户信息")
|
||||
public Result<OrderPayCustomer> findById(@PathVariable("orderCustomerId") Long orderCustomerId){
|
||||
return Result.success(orderPayCustomerService.getById(orderCustomerId),"操作成功");
|
||||
}
|
||||
/**
|
||||
* 禁用
|
||||
* @param orderCustomerId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/disable/{orderCustomerId}")
|
||||
@Operation(summary = "通过id禁用客户",description = "通过id禁用客户调用支付接口")
|
||||
public Result<String> disable(@PathVariable("orderCustomerId") Long orderCustomerId){
|
||||
orderPayCustomerService.disable(orderCustomerId);
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
/**
|
||||
* 启用
|
||||
* @param orderCustomerId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/enable/{orderCustomerId}")
|
||||
@Operation(summary = "通过id启用客户",description = "通过id启用客户调用支付接口")
|
||||
public Result<String> enable(@PathVariable("orderCustomerId") Long orderCustomerId){
|
||||
orderPayCustomerService.enable(orderCustomerId);
|
||||
return Result.success(null,"操作成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,4 +14,17 @@ public interface OrderPayCustomerService extends IService<OrderPayCustomer> {
|
|||
|
||||
List<String> getCustomerAllList();
|
||||
|
||||
/**
|
||||
* 禁用客户id
|
||||
* @param orderCustomerId
|
||||
*/
|
||||
void disable(Long orderCustomerId);
|
||||
|
||||
/**
|
||||
* 启用客户id
|
||||
* @param orderCustomerId
|
||||
*/
|
||||
void enable(Long orderCustomerId);
|
||||
|
||||
void settingStatus(Long orderCustomerId,String status);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package com.muyu.pay.server.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.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 com.muyu.pay.common.domain.OrderPayCustomer;
|
||||
|
@ -18,7 +21,9 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
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;
|
||||
|
@ -81,6 +86,50 @@ public class OrderPayCustomerServiceImpl
|
|||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable(Long orderCustomerId) {
|
||||
this.settingStatus(orderCustomerId, SystemYesNo.NO.getCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable(Long orderCustomerId) {
|
||||
this.settingStatus(orderCustomerId,SystemYesNo.YES.getCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void settingStatus(Long orderCustomerId, String status) {
|
||||
LambdaQueryWrapper<OrderPayCustomer> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(OrderPayCustomer::getId,orderCustomerId);
|
||||
boolean exists = this.exists(queryWrapper);
|
||||
if (!exists){
|
||||
throw new ServiceException("操作客户不存在");
|
||||
}
|
||||
if (!SystemYesNo.isCode(status)){
|
||||
throw new ServiceException("设置状态值违法");
|
||||
}
|
||||
LambdaUpdateWrapper<OrderPayCustomer> updQueryWrapper = new LambdaUpdateWrapper<>();
|
||||
updQueryWrapper.eq(OrderPayCustomer::getId,orderCustomerId);
|
||||
updQueryWrapper.set(OrderPayCustomer::getStatus,status);
|
||||
this.update(updQueryWrapper);
|
||||
}
|
||||
|
||||
@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 = orderPayInfoService.count(queryWrapper);
|
||||
if (count>0){
|
||||
throw new ServiceException(
|
||||
StringUtils.format("客户:[{}],近七天还在使用,不可删除",orderPayCustomer.getAppName())
|
||||
);
|
||||
}
|
||||
return super.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(OrderPayCustomer orderPayCustomer) {
|
||||
|
|
Loading…
Reference in New Issue