添加支付宝支付修改公司资料等
parent
20b2a4fff0
commit
4e083e754b
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.annotation;
|
||||
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Log {
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean enable() default true;
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.baiye.constant;
|
||||
|
||||
/**
|
||||
* 支付相关 常量定义
|
||||
*
|
||||
* @author Enzo
|
||||
* @date : 2021/6/16
|
||||
*/
|
||||
public class PayConstants {
|
||||
|
||||
private PayConstants() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 付款信息 反馈中文字段补充前缀
|
||||
*/
|
||||
public static final String PAY_TITLE = "投流回跟系统支付订单:";
|
||||
|
||||
/**
|
||||
* 返回的信息字段内容对应 key
|
||||
*/
|
||||
public static final String OUT_TRADE_NO = "out_trade_no";
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.util;
|
||||
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 获取 HttpServletRequest
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
public class RequestHolder {
|
||||
|
||||
public static HttpServletRequest getHttpServletRequest() {
|
||||
return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* 异常工具 2019-01-06
|
||||
* @author Zheng Jie
|
||||
*/
|
||||
public class ThrowableUtil {
|
||||
|
||||
/**
|
||||
* 获取堆栈信息
|
||||
*/
|
||||
public static String getStackTrace(Throwable throwable){
|
||||
StringWriter sw = new StringWriter();
|
||||
try (PrintWriter pw = new PrintWriter(sw)) {
|
||||
throwable.printStackTrace(pw);
|
||||
return sw.toString();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2019-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.model.enums;
|
||||
|
||||
/**
|
||||
* @author: liaojinlong
|
||||
* @date: 2020/6/11 19:47
|
||||
* @apiNote: 日志类型
|
||||
*/
|
||||
|
||||
public enum LogActionType {
|
||||
/**
|
||||
* 增删改查
|
||||
*/
|
||||
ADD("新增"),
|
||||
SELECT("查询"),
|
||||
UPDATE("更新"),
|
||||
DELETE("删除");
|
||||
private String value;
|
||||
|
||||
LogActionType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
package com.baiye.aspect;
|
||||
|
||||
import com.baiye.modules.system.domain.Log;
|
||||
import com.baiye.modules.system.service.LogService;
|
||||
import com.baiye.util.RequestHolder;
|
||||
import com.baiye.util.SecurityUtils;
|
||||
import com.baiye.util.StringUtils;
|
||||
import com.baiye.util.ThrowableUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/3/20
|
||||
*/
|
||||
@Component
|
||||
@Aspect
|
||||
@Slf4j
|
||||
public class LogAspect {
|
||||
|
||||
private final LogService logService;
|
||||
|
||||
ThreadLocal<Long> currentTime = new ThreadLocal<>();
|
||||
|
||||
public LogAspect(LogService logService) {
|
||||
this.logService = logService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置切入点
|
||||
*/
|
||||
@Pointcut("@annotation(com.baiye.annotation.Log)")
|
||||
public void logPointcut() {
|
||||
// 该方法无方法体,主要为了让同类中其他方法使用此切入点
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置环绕通知,使用在方法logPointcut()上注册的切入点
|
||||
*
|
||||
* @param joinPoint join point for advice
|
||||
*/
|
||||
@Around("logPointcut()")
|
||||
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
Object result;
|
||||
currentTime.set(System.currentTimeMillis());
|
||||
result = joinPoint.proceed();
|
||||
Log log = new Log("INFO",System.currentTimeMillis() - currentTime.get());
|
||||
currentTime.remove();
|
||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置异常通知
|
||||
*
|
||||
* @param joinPoint join point for advice
|
||||
* @param e exception
|
||||
*/
|
||||
@AfterThrowing(pointcut = "logPointcut()", throwing = "e")
|
||||
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
|
||||
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime.get());
|
||||
currentTime.remove();
|
||||
log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes());
|
||||
HttpServletRequest request = RequestHolder.getHttpServletRequest();
|
||||
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log);
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
try {
|
||||
return SecurityUtils.getCurrentUsername();
|
||||
}catch (Exception e){
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.baiye.config.properties;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "alipay")
|
||||
public class AliPayProperties {
|
||||
|
||||
@ApiModelProperty("协议")
|
||||
private String protocol;
|
||||
@ApiModelProperty("请求地址")
|
||||
private String gatewayHost;
|
||||
@ApiModelProperty("签名类型")
|
||||
private String signType;
|
||||
@ApiModelProperty("appId")
|
||||
private String appId;
|
||||
@ApiModelProperty("应用私钥")
|
||||
private String merchantPrivateKey;
|
||||
@ApiModelProperty("支付宝公钥")
|
||||
private String aliPayPublicKey;
|
||||
@ApiModelProperty("回调地址")
|
||||
private String notifyUrl;
|
||||
@ApiModelProperty("AES密钥")
|
||||
private String encryptKey;
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.domain;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Table(name = "sys_log")
|
||||
@NoArgsConstructor
|
||||
public class Log implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "log_id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
/** 操作用户 */
|
||||
private String username;
|
||||
|
||||
/** 描述 */
|
||||
private String description;
|
||||
|
||||
/** 方法名 */
|
||||
private String method;
|
||||
|
||||
/** 参数 */
|
||||
private String params;
|
||||
|
||||
/** 日志类型 */
|
||||
private String logType;
|
||||
|
||||
/** 请求ip */
|
||||
private String requestIp;
|
||||
|
||||
/** 地址 */
|
||||
private String address;
|
||||
|
||||
/** 浏览器 */
|
||||
private String browser;
|
||||
|
||||
/** 请求耗时 */
|
||||
private Long time;
|
||||
|
||||
/** 异常详细 */
|
||||
private byte[] exceptionDetail;
|
||||
|
||||
/** 创建日期 */
|
||||
@CreationTimestamp
|
||||
private Timestamp createTime;
|
||||
|
||||
public Log(String logType, Long time) {
|
||||
this.logType = logType;
|
||||
this.time = time;
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.baiye.modules.system.domain;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date 2021-10-28
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "tb_pay_order")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class PayOrder implements Serializable {
|
||||
private static final long serialVersionUID = 2056458673691527927L;
|
||||
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@ApiModelProperty(value = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "pay_type")
|
||||
@ApiModelProperty(value = "支付类型")
|
||||
private Integer payType;
|
||||
|
||||
@Column(name = "order_number")
|
||||
@ApiModelProperty(value = "订单编号")
|
||||
private String orderNumber;
|
||||
|
||||
@Column(name = "status")
|
||||
@ApiModelProperty(value = "支付状态")
|
||||
private Integer status;
|
||||
|
||||
@Column(name = "purchaser")
|
||||
@ApiModelProperty(value = "购买人")
|
||||
private String purchaser;
|
||||
|
||||
@CreatedDate
|
||||
@Column(name = "order_time")
|
||||
@ApiModelProperty(value = "下单时间")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
|
||||
private Date orderTime;
|
||||
|
||||
@Column(name = "pay_time")
|
||||
@ApiModelProperty(value = "支付时间")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
|
||||
private Date payTime;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
@Column(name = "create_time")
|
||||
@CreationTimestamp
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
@Column(name = "update_time")
|
||||
@LastModifiedDate
|
||||
private Date updateTime;
|
||||
|
||||
@Column(name = "amount")
|
||||
@ApiModelProperty(value = "金额")
|
||||
private Double amount;
|
||||
|
||||
@Column(name = "user_id")
|
||||
@ApiModelProperty(value = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Column(name = "company_id")
|
||||
@ApiModelProperty(value = "公司id")
|
||||
private Long companyId;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.repository;
|
||||
|
||||
import com.baiye.modules.system.domain.Log;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Repository
|
||||
public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecificationExecutor<Log> {
|
||||
|
||||
/**
|
||||
* 根据日志类型删除信息
|
||||
* @param logType 日志类型
|
||||
*/
|
||||
@Modifying
|
||||
@Query(value = "delete from sys_log where log_type = ?1", nativeQuery = true)
|
||||
void deleteByLogType(String logType);
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.repository;
|
||||
|
||||
import com.baiye.modules.system.domain.PayOrder;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date 2022-3-18
|
||||
*/
|
||||
public interface PayOrderRepository extends JpaRepository<PayOrder, Long>, JpaSpecificationExecutor<PayOrder> {
|
||||
|
||||
/**
|
||||
* 订单编号查询
|
||||
* @param orderNo
|
||||
* @return
|
||||
*/
|
||||
PayOrder findByOrderNumber(String orderNo);
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.baiye.modules.system.rest;
|
||||
|
||||
|
||||
import com.baiye.http.CommonResponse;
|
||||
import com.baiye.modules.system.service.AliPayService;
|
||||
import com.baiye.modules.system.service.dto.AliPayPcDTO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
*/
|
||||
@Api(tags = "支付宝支付")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping(value = "/pay/aliPay")
|
||||
@AllArgsConstructor
|
||||
public class AliPayController {
|
||||
|
||||
private final AliPayService aliPayService;
|
||||
|
||||
@ApiOperation(value = "电脑支付")
|
||||
@PostMapping(value = "/pcPay")
|
||||
public CommonResponse<String> pcPay(@Validated @RequestBody AliPayPcDTO aliPayPcDTO) {
|
||||
return CommonResponse.createBySuccess(aliPayService.aliPayPc(aliPayPcDTO));
|
||||
}
|
||||
|
||||
/**
|
||||
* pc 回调接收参数
|
||||
*
|
||||
* @param request request
|
||||
* @return 返回结果
|
||||
*/
|
||||
@RequestMapping(value = "/pay-notify")
|
||||
public ResponseEntity<String> frontRcvResponse(HttpServletRequest request) {
|
||||
return new ResponseEntity<>(aliPayService.pcNotifyResponse(request),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.baiye.modules.system.rest;
|
||||
|
||||
import com.baiye.annotation.Log;
|
||||
import com.baiye.modules.system.service.PayOrderService;
|
||||
import com.baiye.modules.system.service.dto.AliPayQueryCriteria;
|
||||
import com.baiye.modules.system.service.dto.PayOrderDto;
|
||||
import com.baiye.modules.system.service.dto.UpdateOrderDto;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/3/20
|
||||
*/
|
||||
@Api(tags = "订单相关")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping(value = "/pay/payOrder")
|
||||
@AllArgsConstructor
|
||||
public class PayOrderController {
|
||||
|
||||
private final PayOrderService payOrderService;
|
||||
|
||||
@ApiOperation("查询订单数据")
|
||||
@GetMapping(value = "/list")
|
||||
public ResponseEntity<Object> list(AliPayQueryCriteria criteria, Pageable pageable) {
|
||||
return new ResponseEntity<>(payOrderService.queryAll(criteria, pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("新增订单")
|
||||
@PostMapping("/create")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody PayOrderDto resources){
|
||||
payOrderService.create(resources);
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("修改用户使用金额")
|
||||
@ApiOperation("修改金额")
|
||||
@PostMapping(value = "/amendmentAmount")
|
||||
public ResponseEntity<Object> updateAmounts(@RequestBody List<UpdateOrderDto> updateOrderDtoList) {
|
||||
payOrderService.updateAmount(updateOrderDtoList);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.baiye.modules.system.service;
|
||||
|
||||
import com.baiye.modules.system.service.dto.AliPayPcDTO;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2021/6/16
|
||||
*/
|
||||
public interface AliPayService {
|
||||
|
||||
|
||||
/**
|
||||
* pc端创建支付宝订单
|
||||
* @param aliPayPcDTO
|
||||
* @return
|
||||
*/
|
||||
String aliPayPc(AliPayPcDTO aliPayPcDTO);
|
||||
|
||||
/**
|
||||
* 支付宝订单回调
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
String pcNotifyResponse(HttpServletRequest request);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.service;
|
||||
|
||||
import com.baiye.modules.system.domain.Log;
|
||||
import com.baiye.modules.system.service.dto.LogQueryCriteria;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
public interface LogService {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param criteria 查询条件
|
||||
* @param pageable 分页参数
|
||||
* @return /
|
||||
*/
|
||||
Object queryAll(LogQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询全部数据
|
||||
* @param criteria 查询条件
|
||||
* @return /
|
||||
*/
|
||||
List<Log> queryAll(LogQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 查询用户日志
|
||||
* @param criteria 查询条件
|
||||
* @param pageable 分页参数
|
||||
* @return -
|
||||
*/
|
||||
Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 保存日志数据
|
||||
* @param username 用户
|
||||
* @param browser 浏览器
|
||||
* @param ip 请求IP
|
||||
* @param joinPoint /
|
||||
* @param log 日志实体
|
||||
*/
|
||||
@Async
|
||||
void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log);
|
||||
|
||||
/**
|
||||
* 查询异常详情
|
||||
* @param id 日志ID
|
||||
* @return Object
|
||||
*/
|
||||
Object findByErrDetail(Long id);
|
||||
|
||||
/**
|
||||
* 导出日志
|
||||
* @param logs 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<Log> logs, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除所有错误日志
|
||||
*/
|
||||
void delAllByError();
|
||||
|
||||
/**
|
||||
* 删除所有INFO日志
|
||||
*/
|
||||
void delAllByInfo();
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.baiye.modules.system.service;
|
||||
|
||||
import com.baiye.modules.system.service.dto.AliPayQueryCriteria;
|
||||
import com.baiye.modules.system.service.dto.PayOrderDto;
|
||||
import com.baiye.modules.system.service.dto.UpdateOrderDto;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/3/20
|
||||
*/
|
||||
public interface PayOrderService {
|
||||
/**
|
||||
* 查询订单数据
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> queryAll(AliPayQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 修改金额
|
||||
* @param updateOrderDtoList
|
||||
* @return
|
||||
*/
|
||||
Boolean updateAmount(List<UpdateOrderDto> updateOrderDtoList);
|
||||
|
||||
/**
|
||||
* 手动创建订单
|
||||
* @param resources
|
||||
*/
|
||||
void create(PayOrderDto resources);
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.baiye.modules.system.service.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.DecimalMin;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/3/16
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class AliPayPcDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6500373305956248683L;
|
||||
|
||||
@NotNull(message = "金额不能为空")
|
||||
@DecimalMin(value = "0.01",message = "最小金额0.01")
|
||||
@ApiModelProperty("充值金额")
|
||||
private Double amount;
|
||||
|
||||
@ApiModelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.service.dto;
|
||||
|
||||
import com.baiye.annotation.DataPermission;
|
||||
import com.baiye.annotation.Query;
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-03-25
|
||||
*/
|
||||
@Data
|
||||
@DataPermission(fieldName = "id")
|
||||
public class AliPayQueryCriteria {
|
||||
|
||||
@Query
|
||||
private Integer status;
|
||||
|
||||
|
||||
private Boolean sortBy;
|
||||
|
||||
private String sortByStr;
|
||||
|
||||
@Query(type = Query.Type.INNER_LIKE)
|
||||
private String orderNumber;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Double> amount;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> createTime;
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Data
|
||||
public class LogErrorDTO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String username;
|
||||
|
||||
private String description;
|
||||
|
||||
private String method;
|
||||
|
||||
private String params;
|
||||
|
||||
private String browser;
|
||||
|
||||
private String requestIp;
|
||||
|
||||
private String address;
|
||||
|
||||
private Timestamp createTime;
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.service.dto;
|
||||
|
||||
import com.baiye.annotation.Query;
|
||||
import lombok.Data;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 日志查询类
|
||||
* @author Zheng Jie
|
||||
* @date 2019-6-4 09:23:07
|
||||
*/
|
||||
@Data
|
||||
public class LogQueryCriteria {
|
||||
|
||||
@Query(blurry = "username,description,address,requestIp,method,params")
|
||||
private String blurry;
|
||||
|
||||
@Query
|
||||
private String logType;
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> createTime;
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Data
|
||||
public class LogSmallDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4552967950319128982L;
|
||||
|
||||
private String description;
|
||||
|
||||
private String requestIp;
|
||||
|
||||
private Long time;
|
||||
|
||||
private String address;
|
||||
|
||||
private String browser;
|
||||
|
||||
private Timestamp createTime;
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.service.dto;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.baiye.model.base.BaseDTO;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-03-29
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class PayOrderDto extends BaseDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2035716596706011470L;
|
||||
|
||||
@ApiModelProperty(value = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "支付类型")
|
||||
private Integer payType;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty(value = "订单编号")
|
||||
private String orderNumber;
|
||||
|
||||
@ApiModelProperty(value = "支付状态")
|
||||
private Integer status;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty(value = "购买人")
|
||||
private String purchaser;
|
||||
|
||||
@ApiModelProperty(value = "下单时间")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
|
||||
private Date orderTime;
|
||||
|
||||
@ApiModelProperty(value = "支付时间")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
|
||||
private Date payTime;
|
||||
|
||||
@NotNull
|
||||
@ApiModelProperty(value = "金额")
|
||||
private Double amount;
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.baiye.modules.system.service.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-03-29
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class UpdateOrderDto implements Serializable {
|
||||
|
||||
|
||||
private static final long serialVersionUID = -9110566536531791573L;
|
||||
|
||||
@ApiModelProperty(value = "公司id")
|
||||
private Long companyId;
|
||||
|
||||
@ApiModelProperty(value = "用户id")
|
||||
private Long userId;
|
||||
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package com.baiye.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.text.StrPool;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.alipay.easysdk.kernel.util.ResponseChecker;
|
||||
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
|
||||
import com.baiye.config.properties.AliPayProperties;
|
||||
import com.baiye.constant.DefaultNumberConstants;
|
||||
import com.baiye.constant.PayConstants;
|
||||
import com.baiye.exception.BadRequestException;
|
||||
import com.baiye.model.enums.ResponseCode;
|
||||
import com.baiye.modules.system.domain.PayOrder;
|
||||
import com.baiye.modules.system.repository.PayOrderRepository;
|
||||
import com.baiye.modules.system.service.AliPayService;
|
||||
import com.baiye.modules.system.service.CompanyService;
|
||||
import com.baiye.modules.system.service.dto.AliPayPcDTO;
|
||||
import com.baiye.modules.system.service.dto.CompanyDto;
|
||||
import com.baiye.util.SecurityUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AliPayServiceImpl implements AliPayService {
|
||||
|
||||
private final PayOrderRepository payOrderRepository;
|
||||
|
||||
private final CompanyService companyService;
|
||||
|
||||
private final AliPayProperties aliPay;
|
||||
|
||||
@Value("${snowflake.workerId}")
|
||||
private int workerId;
|
||||
|
||||
@Value("${snowflake.datacenterId}")
|
||||
private int datacenterId;
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String pcNotifyResponse(HttpServletRequest request) {
|
||||
log.info("================ the pay notify enter date as {} ================", DateUtil.date());
|
||||
//获取支付宝GET过来反馈信息
|
||||
Map<String, String> params = new HashMap<>(DefaultNumberConstants.SIXTEEN_NUMBER);
|
||||
// 处理乱码问题
|
||||
checkParam(request, params);
|
||||
Boolean flag;
|
||||
try {
|
||||
flag = Factory.Payment.Common().verifyNotify(params);
|
||||
//商户订单号
|
||||
String orderNo = new String(request.getParameter(PayConstants.OUT_TRADE_NO).
|
||||
getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
|
||||
//前台回调验证签名 v1 or v2
|
||||
if (flag != null && flag) {
|
||||
log.info("========== order verify signature success the orderNumber as {} ==========", orderNo);
|
||||
PayOrder order = payOrderRepository.findByOrderNumber(orderNo);
|
||||
if (order != null &&
|
||||
order.getStatus() == DefaultNumberConstants.ZERO_NUMBER) {
|
||||
log.info("========== the order notify success date as {} ==========", DateUtil.date());
|
||||
Long companyId = order.getCompanyId();
|
||||
order.setPayTime(DateUtil.date());
|
||||
order.setStatus(DefaultNumberConstants.ONE_NUMBER);
|
||||
CompanyDto companyById = companyService.findCompanyById(companyId);
|
||||
if (ObjectUtil.isNotNull(companyById)) {
|
||||
// 设置充值金额
|
||||
Double balance = companyById.getUserBalance() != null ?
|
||||
companyById.getUserBalance() : DefaultNumberConstants.ZERO_NUMBER;
|
||||
companyService.updateUserBalanceByCompanyId
|
||||
(NumberUtil.add(balance, order.getAmount()), companyId);
|
||||
}
|
||||
payOrderRepository.save(order);
|
||||
return ResponseCode.SUCCESS.getDesc();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("the pc response error time {}", LocalTime.now());
|
||||
throw new BadRequestException(ResponseCode.CALLBACK_FAILED.getDesc());
|
||||
}
|
||||
return ResponseCode.FAILURE.getDesc();
|
||||
}
|
||||
|
||||
|
||||
private void checkParam(HttpServletRequest request, Map<String, String> params) {
|
||||
Map<String, String[]> requestParams = request.getParameterMap();
|
||||
if (CollectionUtils.isNotEmpty(requestParams.keySet())) {
|
||||
for (Map.Entry<String, String[]> stringEntry : requestParams.entrySet()) {
|
||||
String[] values = stringEntry.getValue();
|
||||
String valueStr = CharSequenceUtil.EMPTY;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
valueStr = (i == values.length - 1) ? valueStr + values[i]
|
||||
: valueStr + values[i] + StrPool.COMMA;
|
||||
}
|
||||
//乱码解决,这段代码在出现乱码时使用
|
||||
valueStr = new String(valueStr.getBytes
|
||||
(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
|
||||
params.put(stringEntry.getKey(), valueStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String aliPayPc(AliPayPcDTO aliPayPcDTO) {
|
||||
// 查询记录
|
||||
try {
|
||||
// 雪花算法id
|
||||
String orderNo = String.valueOf
|
||||
(IdUtil.getSnowflake(workerId, datacenterId).nextId());
|
||||
// 生成返回对象
|
||||
AlipayTradePagePayResponse response = Factory.Payment.Page()
|
||||
.pay(PayConstants.PAY_TITLE + orderNo,
|
||||
orderNo, aliPayPcDTO.getAmount().toString(),
|
||||
aliPay.getNotifyUrl());
|
||||
if (ResponseChecker.success(response)) {
|
||||
boolean result = savePayOrder(aliPayPcDTO, orderNo);
|
||||
log.info("============= the save order result {} =============", result);
|
||||
return response.getBody();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("the order failed purchaser {} time {}", aliPayPcDTO.getRemark(), LocalTime.now());
|
||||
throw new BadRequestException(ResponseCode.ALI_PAY_ERROR.getDesc());
|
||||
}
|
||||
throw new BadRequestException(ResponseCode.ALI_PAY_ERROR.getDesc());
|
||||
}
|
||||
|
||||
private boolean savePayOrder(AliPayPcDTO aliPayPcDTO, String orderNo) {
|
||||
PayOrder order = new PayOrder();
|
||||
order.setPurchaser(SecurityUtils.getCurrentUsername());
|
||||
order.setOrderNumber(orderNo);
|
||||
order.setAmount(aliPayPcDTO.getAmount());
|
||||
order.setUserId(SecurityUtils.getCurrentUserId());
|
||||
order.setCompanyId(SecurityUtils.getCompanyId());
|
||||
order.setPayType(DefaultNumberConstants.ONE_NUMBER);
|
||||
order.setStatus(DefaultNumberConstants.ZERO_NUMBER);
|
||||
return payOrderRepository.save(order).getId() != null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baiye.modules.system.domain.Log;
|
||||
import com.baiye.modules.system.repository.LogRepository;
|
||||
import com.baiye.modules.system.service.LogService;
|
||||
import com.baiye.modules.system.service.dto.LogQueryCriteria;
|
||||
import com.baiye.modules.system.service.mapstruct.LogErrorMapper;
|
||||
import com.baiye.modules.system.service.mapstruct.LogSmallMapper;
|
||||
import com.baiye.util.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LogServiceImpl implements LogService {
|
||||
private static final Logger log = LoggerFactory.getLogger(LogServiceImpl.class);
|
||||
private final LogRepository logRepository;
|
||||
private final LogErrorMapper logErrorMapper;
|
||||
private final LogSmallMapper logSmallMapper;
|
||||
|
||||
@Override
|
||||
public Object queryAll(LogQueryCriteria criteria, Pageable pageable) {
|
||||
Page<Log> page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)), pageable);
|
||||
String status = "ERROR";
|
||||
if (status.equals(criteria.getLogType())) {
|
||||
return PageUtil.toPage(page.map(logErrorMapper::toDto));
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Log> queryAll(LogQueryCriteria criteria) {
|
||||
return logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object queryAllByUser(LogQueryCriteria criteria, Pageable pageable) {
|
||||
Page<Log> page = logRepository.findAll(((root, criteriaQuery, cb) -> QueryHelp.getPredicate(root, criteria, cb)), pageable);
|
||||
return PageUtil.toPage(page.map(logSmallMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(String username, String browser, String ip, ProceedingJoinPoint joinPoint, Log log) {
|
||||
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
com.baiye.annotation.Log aopLog = method.getAnnotation(com.baiye.annotation.Log.class);
|
||||
|
||||
// 方法路径
|
||||
String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
|
||||
|
||||
StringBuilder params = new StringBuilder("{");
|
||||
//参数值
|
||||
List<Object> argValues = new ArrayList<>(Arrays.asList(joinPoint.getArgs()));
|
||||
//参数名称
|
||||
for (Object argValue : argValues) {
|
||||
params.append(argValue).append(" ");
|
||||
}
|
||||
// 描述
|
||||
if (log != null) {
|
||||
log.setDescription(aopLog.value());
|
||||
}
|
||||
assert log != null;
|
||||
log.setRequestIp(ip);
|
||||
|
||||
String loginPath = "login";
|
||||
if (loginPath.equals(signature.getName())) {
|
||||
try {
|
||||
username = new JSONObject(argValues.get(0)).get("username").toString();
|
||||
} catch (Exception e) {
|
||||
LogServiceImpl.log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
log.setAddress(StringUtils.getCityInfo(log.getRequestIp()));
|
||||
log.setMethod(methodName);
|
||||
log.setUsername(username);
|
||||
log.setParams(params.toString() + " }");
|
||||
log.setBrowser(browser);
|
||||
logRepository.save(log);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object findByErrDetail(Long id) {
|
||||
Log log = logRepository.findById(id).orElseGet(Log::new);
|
||||
ValidationUtil.isNull(log.getId(), "Log", "id", id);
|
||||
byte[] details = log.getExceptionDetail();
|
||||
return Dict.create().set("exception", new String(ObjectUtil.isNotNull(details) ? details : "".getBytes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(List<Log> logs, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Log log : logs) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("用户名", log.getUsername());
|
||||
map.put("IP", log.getRequestIp());
|
||||
map.put("IP来源", log.getAddress());
|
||||
map.put("描述", log.getDescription());
|
||||
map.put("浏览器", log.getBrowser());
|
||||
map.put("请求耗时/毫秒", log.getTime());
|
||||
map.put("异常详情", new String(ObjectUtil.isNotNull(log.getExceptionDetail()) ? log.getExceptionDetail() : "".getBytes()));
|
||||
map.put("创建日期", log.getCreateTime());
|
||||
list.add(map);
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delAllByError() {
|
||||
logRepository.deleteByLogType("ERROR");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delAllByInfo() {
|
||||
logRepository.deleteByLogType("INFO");
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package com.baiye.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baiye.constant.DefaultNumberConstants;
|
||||
import com.baiye.exception.BadRequestException;
|
||||
import com.baiye.model.dto.RoleSmallDto;
|
||||
import com.baiye.model.dto.UserDto;
|
||||
import com.baiye.model.enums.ResponseCode;
|
||||
import com.baiye.modules.system.domain.PayOrder;
|
||||
import com.baiye.modules.system.repository.PayOrderRepository;
|
||||
import com.baiye.modules.system.service.CompanyService;
|
||||
import com.baiye.modules.system.service.PayOrderService;
|
||||
import com.baiye.modules.system.service.UserService;
|
||||
import com.baiye.modules.system.service.dto.AliPayQueryCriteria;
|
||||
import com.baiye.modules.system.service.dto.CompanyDto;
|
||||
import com.baiye.modules.system.service.dto.PayOrderDto;
|
||||
import com.baiye.modules.system.service.dto.UpdateOrderDto;
|
||||
import com.baiye.modules.system.service.mapstruct.PayOrderMapper;
|
||||
import com.baiye.util.PageUtil;
|
||||
import com.baiye.util.QueryHelp;
|
||||
import com.baiye.util.SecurityUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Enzo
|
||||
* @date : 2022/3/20
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PayOrderServiceImpl implements PayOrderService {
|
||||
|
||||
private final UserService userService;
|
||||
private final CompanyService companyService;
|
||||
private final PayOrderMapper payOrderMapper;
|
||||
private final PayOrderRepository payOrderRepository;
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAll(AliPayQueryCriteria criteria, Pageable pageable) {
|
||||
Sort sort = Sort.by(Sort.Direction.DESC, "id");
|
||||
if (criteria.getSortBy() != null) {
|
||||
sort = Sort.by(Boolean.TRUE.equals(criteria.getSortBy()) ? Sort.Direction.ASC
|
||||
: Sort.Direction.DESC, criteria.getSortByStr());
|
||||
}
|
||||
PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort);
|
||||
Page<PayOrder> pageAll = payOrderRepository.findAll(
|
||||
(root, criteriaQuery, criteriaBuilder) ->
|
||||
QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageRequest);
|
||||
return PageUtil.toPage(pageAll.map(payOrderMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean updateAmount(List<UpdateOrderDto> updateOrderDtoList) {
|
||||
checkPer();
|
||||
if (CollUtil.isNotEmpty(updateOrderDtoList)) {
|
||||
// 公司分组
|
||||
Map<Long, List<UpdateOrderDto>> longListMap = updateOrderDtoList.stream().collect(
|
||||
Collectors.groupingBy(UpdateOrderDto::getCompanyId));
|
||||
for (Map.Entry<Long, List<UpdateOrderDto>> longListEntry : longListMap.entrySet()) {
|
||||
Long companyId = longListEntry.getKey();
|
||||
List<UpdateOrderDto> orderDtoList = longListEntry.getValue();
|
||||
CompanyDto companyById =
|
||||
companyService.findCompanyById(companyId);
|
||||
List<UpdateOrderDto> dtoList = longListMap.get(companyId);
|
||||
Double userBalance = companyById.getUserBalance();
|
||||
Double minusAmount = NumberUtil.mul
|
||||
(dtoList.size(), DefaultNumberConstants.THIRTY);
|
||||
double subAmount = NumberUtil.sub(userBalance, minusAmount);
|
||||
// 判断余额
|
||||
if (userBalance == null || subAmount <= DefaultNumberConstants.ZERO_NUMBER) {
|
||||
throw new BadRequestException(ResponseCode.INSUFFICIENT_ACCOUNT_BALANCE.getDesc());
|
||||
}
|
||||
// 异步插入数据
|
||||
CompletableFuture.runAsync(() ->
|
||||
userService.updateUserExpirationTime(orderDtoList));
|
||||
// 修改公司余额
|
||||
companyService.updateUserBalanceByCompanyId(subAmount, companyId);
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(PayOrderDto resources) {
|
||||
checkPer();
|
||||
PayOrder payOrder = new PayOrder();
|
||||
BeanUtil.copyProperties(resources, payOrder);
|
||||
payOrderRepository.save(payOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测是否拥有权限
|
||||
*/
|
||||
private void checkPer() {
|
||||
UserDto userDto = JSONUtil.toBean(SecurityUtils.getUser(), UserDto.class);
|
||||
boolean flag = Boolean.TRUE;
|
||||
for (RoleSmallDto role : userDto.getRoles()) {
|
||||
if (role.getId() == DefaultNumberConstants.ONE_NUMBER
|
||||
|| role.getId() == DefaultNumberConstants.EIGHT_NUMBER) {
|
||||
flag = Boolean.FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
throw new BadRequestException
|
||||
(ResponseCode.NON_SUPER_ADMINISTRATORS_CANNOT_MODIFY_DATA.getDesc());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.service.mapstruct;
|
||||
|
||||
import com.baiye.model.base.BaseMapper;
|
||||
import com.baiye.modules.system.domain.Log;
|
||||
import com.baiye.modules.system.service.dto.LogErrorDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LogErrorMapper extends BaseMapper<LogErrorDTO, Log> {
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.service.mapstruct;
|
||||
|
||||
import com.baiye.model.base.BaseMapper;
|
||||
import com.baiye.modules.system.domain.Log;
|
||||
import com.baiye.modules.system.service.dto.LogSmallDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-5-22
|
||||
*/
|
||||
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface LogSmallMapper extends BaseMapper<LogSmallDTO, Log> {
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.baiye.modules.system.service.mapstruct;
|
||||
|
||||
import com.baiye.model.base.BaseMapper;
|
||||
import com.baiye.modules.system.domain.Dept;
|
||||
import com.baiye.modules.system.domain.PayOrder;
|
||||
import com.baiye.modules.system.service.dto.DeptDto;
|
||||
import com.baiye.modules.system.service.dto.PayOrderDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2019-03-25
|
||||
*/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface PayOrderMapper extends BaseMapper<PayOrderDto, PayOrder> {
|
||||
|
||||
}
|
Loading…
Reference in New Issue