Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
Tankaikai
2024-12-30 18:30:45 +08:00
12 changed files with 169 additions and 67 deletions

View File

@@ -46,18 +46,22 @@ public class AppApiMethodAspect {
// 执行被拦截的方法 // 执行被拦截的方法
Object result = pjp.proceed(); Object result = pjp.proceed();
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
String method = request.getMethod();
String requestUrl = request.getRequestURL().toString();
String requestIp = IPUtils.getIpAddr(request);
long useTime = end - start;
ThreadUtil.execAsync(() -> { ThreadUtil.execAsync(() -> {
//请求的参数 //请求的参数
String resultJson = new Gson().toJson(result); String resultJson = new Gson().toJson(result);
try { try {
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
if (StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)) { if (StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)) {
log.info("\n>>>>>> {} {}" + log.info("\n>>>>>> {} {}" +
"\n>>>>>> IP: {} " + "\n>>>>>> IP: {} " +
"\n>>>>>> execute time:{}ms " + "\n>>>>>> execute time:{}ms " +
"\n>>>>>> Request: {}" + "\n>>>>>> Request: {}" +
"\n>>>>>> Response: {}", "\n>>>>>> Response: {}",
request.getMethod(), request.getRequestURL(), IPUtils.getIpAddr(request), end - start, method, requestUrl, requestIp, useTime,
params, params,
resultJson resultJson
); );

View File

@@ -23,6 +23,7 @@ import com.sqx.modules.pay.service.PayDetailsService;
import com.sqx.modules.sys.entity.SysUserEntity; import com.sqx.modules.sys.entity.SysUserEntity;
import com.sqx.modules.sys.service.SysUserService; import com.sqx.modules.sys.service.SysUserService;
import com.sqx.modules.utils.EasyPoi.ExcelUtils; import com.sqx.modules.utils.EasyPoi.ExcelUtils;
import com.sqx.modules.utils.TimeCompleteUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
@@ -270,7 +271,7 @@ public class UserController {
@ApiOperation("短剧分析") @ApiOperation("短剧分析")
public Result courseMessage(Long page, Long limit, String date, int type, Long sysUserId) { public Result courseMessage(Long page, Long limit, String date, int type, Long sysUserId) {
Page<Map<String, Object>> iPage = new Page<>(page, limit); Page<Map<String, Object>> iPage = new Page<>(page, limit);
IPage<Map<String, Object>> mapIPage = userService.queryCourseOrder(iPage, type, date, sysUserId); IPage<Map<String, Object>> mapIPage = userService.queryCourseOrder(iPage, type, TimeCompleteUtils.completeStartTime(date), sysUserId);
return Result.success().put("data", new PageUtils(mapIPage)); return Result.success().put("data", new PageUtils(mapIPage));
} }
@@ -280,6 +281,7 @@ public class UserController {
@GetMapping("/userMessage") @GetMapping("/userMessage")
@ApiOperation("用户分析") @ApiOperation("用户分析")
public Result userMessage(String date, int type, Long sysUserId) { public Result userMessage(String date, int type, Long sysUserId) {
date = TimeCompleteUtils.completeStartTime(date);
String qdCode = null; String qdCode = null;
if (sysUserId != null) { if (sysUserId != null) {
qdCode = sysUserService.getById(sysUserId).getQdCode(); qdCode = sysUserService.getById(sysUserId).getQdCode();

View File

@@ -4,11 +4,16 @@ import com.sqx.common.annotation.SysLog;
import com.sqx.common.utils.PageUtils; import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result; import com.sqx.common.utils.Result;
import com.sqx.common.validator.ValidatorUtils; import com.sqx.common.validator.ValidatorUtils;
import com.sqx.modules.job.dto.RunJobDTO;
import com.sqx.modules.job.entity.ScheduleJobEntity; import com.sqx.modules.job.entity.ScheduleJobEntity;
import com.sqx.modules.job.service.ScheduleJobService; import com.sqx.modules.job.service.ScheduleJobService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@@ -21,7 +26,14 @@ public class ScheduleJobController {
@Autowired @Autowired
private ScheduleJobService scheduleJobService; private ScheduleJobService scheduleJobService;
/** private final ApplicationContext applicationContext;
public ScheduleJobController(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
/**
* 定时任务列表 * 定时任务列表
*/ */
@RequestMapping("/list") @RequestMapping("/list")
@@ -81,6 +93,14 @@ public class ScheduleJobController {
/** /**
* 立即执行任务 * 立即执行任务
*/ */
@SysLog("立即执行任务")
@RequestMapping("/run")
public Result run(@RequestBody Long[] jobIds) throws Exception {
return Result.success().put("data", scheduleJobService.run(jobIds));
}
// @SysLog("立即执行任务") // @SysLog("立即执行任务")
// @RequestMapping("/run") // @RequestMapping("/run")
// public Result run(@RequestBody Long[] jobIds){ // public Result run(@RequestBody Long[] jobIds){
@@ -88,7 +108,7 @@ public class ScheduleJobController {
// //
// return Result.success(); // return Result.success();
// } // }
//
// /** // /**
// * 暂停定时任务 // * 暂停定时任务
// */ // */

View File

@@ -0,0 +1,14 @@
package com.sqx.modules.job.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
@Data
public class RunJobDTO {
@NotNull
private Integer jobId;
private List<?> args;
}

View File

@@ -2,6 +2,7 @@ package com.sqx.modules.job.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.sqx.common.utils.PageUtils; import com.sqx.common.utils.PageUtils;
import com.sqx.modules.job.dto.RunJobDTO;
import com.sqx.modules.job.entity.ScheduleJobEntity; import com.sqx.modules.job.entity.ScheduleJobEntity;
import java.util.Map; import java.util.Map;
@@ -34,6 +35,8 @@ public interface ScheduleJobService extends IService<ScheduleJobEntity> {
*/ */
int updateBatch(Long[] jobIds, int status); int updateBatch(Long[] jobIds, int status);
Object run(Long[] jobIds) throws Exception;
// /** // /**
// * 立即执行 // * 立即执行
// */ // */

View File

@@ -1,5 +1,6 @@
package com.sqx.modules.job.service.impl; package com.sqx.modules.job.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -7,21 +8,27 @@ import com.sqx.common.utils.Constant;
import com.sqx.common.utils.PageUtils; import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Query; import com.sqx.common.utils.Query;
import com.sqx.modules.job.dao.ScheduleJobDao; import com.sqx.modules.job.dao.ScheduleJobDao;
import com.sqx.modules.job.dto.RunJobDTO;
import com.sqx.modules.job.entity.ScheduleJobEntity; import com.sqx.modules.job.entity.ScheduleJobEntity;
import com.sqx.modules.job.service.ScheduleJobService; import com.sqx.modules.job.service.ScheduleJobService;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays; import java.lang.reflect.Method;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.Map;
@Service("scheduleJobService") @Service("scheduleJobService")
public class ScheduleJobServiceImpl extends ServiceImpl<ScheduleJobDao, ScheduleJobEntity> implements ScheduleJobService { public class ScheduleJobServiceImpl extends ServiceImpl<ScheduleJobDao, ScheduleJobEntity> implements ScheduleJobService {
/** private final ApplicationContext applicationContext;
public ScheduleJobServiceImpl(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
/**
* 项目启动时,初始化定时器 * 项目启动时,初始化定时器
*/ */
@@ -69,7 +76,47 @@ public class ScheduleJobServiceImpl extends ServiceImpl<ScheduleJobDao, Schedule
return baseMapper.updateBatch(map); return baseMapper.updateBatch(map);
} }
// @Override
@Override
public Object run(Long[] jobIds) throws Exception {
ArrayList<Object> result = new ArrayList<>();
for(Long jobId : jobIds){
ScheduleJobEntity jobEntity = baseMapper.selectById(jobId);
if (jobEntity == null) {
throw new RuntimeException("任务不存在");
}
// 从Spring容器获取类的实例
Object classInstance = applicationContext.getBean(StrUtil.lowerFirst(jobEntity.getBeanName()));
if (!"com.sqx.modules.job.task".equals(classInstance.getClass().getPackage().getName())) {
throw new RuntimeException("非法调用");
}
// if (jobDTO.getArgs() != null && !jobDTO.getArgs().isEmpty()) {
// Class<?>[] argTypes = new Class<?>[jobDTO.getArgs().size()];
// for (int i = 0; i < jobDTO.getArgs().size(); i++) {
// argTypes[i] = jobDTO.getArgs().get(i).getClass();
// }
// // 获取指定的Method对象
// Method method = classInstance.getClass().getDeclaredMethod(jobDTO.getMethodName(), argTypes);
//
// // 调用方法并返回结果
// return method.invoke(classInstance, jobDTO.getArgs().toArray());
// }
// 获取指定的Method对象
Method method = classInstance.getClass().getDeclaredMethod("run", String.class);
// 调用方法并返回结果
Object invoke = method.invoke(classInstance, jobEntity.getParams());
if (invoke != null) {
result.add(invoke);
}
}
return result;
}
// @Override
// @Transactional(rollbackFor = Exception.class) // @Transactional(rollbackFor = Exception.class)
// public void run(Long[] jobIds) { // public void run(Long[] jobIds) {
// for(Long jobId : jobIds){ // for(Long jobId : jobIds){

View File

@@ -67,4 +67,9 @@ public class CashOutTask{
} }
logger.info("提现结束"); logger.info("提现结束");
} }
public void test(String name, String age) {
logger.info("name: {}, age: {}", name, age);
}
} }

View File

@@ -38,6 +38,7 @@ import com.sqx.modules.pay.controller.app.AliPayController;
import com.sqx.modules.pay.service.DyService; import com.sqx.modules.pay.service.DyService;
import com.sqx.modules.pay.service.WxService; import com.sqx.modules.pay.service.WxService;
import com.sqx.modules.utils.AliPayOrderUtil; import com.sqx.modules.utils.AliPayOrderUtil;
import com.sqx.modules.utils.TimeCompleteUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -657,8 +658,9 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersDao, Orders> implements
Integer flag, String time, String userName, Integer ordersType, String startTime, String endTime, Integer flag, String time, String userName, Integer ordersType, String startTime, String endTime,
Long sysUserId, String qdCode, String sysUserName) { Long sysUserId, String qdCode, String sysUserName) {
Page<Orders> pages = new Page<>(page, limit); Page<Orders> pages = new Page<>(page, limit);
return Result.success().put("data", new PageUtils(baseMapper.selectOrdersByOrdersNo(pages, ordersNo, status, userId, courseId, return Result.success().put("data", new PageUtils(baseMapper.selectOrdersByOrdersNo(pages, ordersNo, status, userId, courseId,
flag, time, userName, ordersType, startTime, endTime, sysUserId, qdCode, sysUserName))); flag, time, userName, ordersType, TimeCompleteUtils.completeStartTime(startTime), TimeCompleteUtils.completeEndTime(endTime), sysUserId, qdCode, sysUserName)));
} }
@Override @Override

View File

@@ -6,6 +6,7 @@ import com.sqx.common.utils.PageUtils;
import com.sqx.modules.pay.dao.PayDetailsDao; import com.sqx.modules.pay.dao.PayDetailsDao;
import com.sqx.modules.pay.entity.PayDetails; import com.sqx.modules.pay.entity.PayDetails;
import com.sqx.modules.pay.service.PayDetailsService; import com.sqx.modules.pay.service.PayDetailsService;
import com.sqx.modules.utils.TimeCompleteUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -30,15 +31,15 @@ public class PayDetailsServiceImpl extends ServiceImpl<PayDetailsDao, PayDetails
if (state != null && state == -1) { if (state != null && state == -1) {
state = null; state = null;
} }
return new PageUtils(payDetailsDao.selectPayDetails(pages, startTime, endTime, userId, state,userName,orderId)); return new PageUtils(payDetailsDao.selectPayDetails(pages, TimeCompleteUtils.completeStartTime(startTime), TimeCompleteUtils.completeEndTime(endTime), userId, state,userName,orderId));
} }
@Override @Override
public Double selectSumPay(String createTime, String endTime, Long userId) { public Double selectSumPay(String createTime, String endTime, Long userId) {
if (userId == null || userId == -1) { if (userId == null || userId == -1) {
return payDetailsDao.selectSumPay(createTime, endTime, null); return payDetailsDao.selectSumPay(TimeCompleteUtils.completeStartTime(createTime), TimeCompleteUtils.completeEndTime(endTime), null);
} }
return payDetailsDao.selectSumPay(createTime, endTime, userId); return payDetailsDao.selectSumPay(TimeCompleteUtils.completeStartTime(createTime), TimeCompleteUtils.completeEndTime(endTime), userId);
} }
@Override @Override

View File

@@ -0,0 +1,27 @@
package com.sqx.modules.utils;
/**
* @author GYJoker
*/
public class TimeCompleteUtils {
public static String completeStartTime(String startTime) {
if (startTime == null || startTime.isEmpty()) {
return null;
}
if (startTime.contains(" ")) {
return startTime;
}
return startTime + " 00:00:00";
}
public static String completeEndTime(String endTime) {
if (endTime == null || endTime.isEmpty()) {
return null;
}
if (endTime.contains(" ")) {
return endTime;
}
return endTime + " 23:59:59";
}
}

View File

@@ -127,13 +127,13 @@
and o.sys_user_id=#{sysUserId} and o.sys_user_id=#{sysUserId}
</if> </if>
<if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''"> <if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
and date_format(o.create_time,'%Y-%m-%d') BETWEEN #{startTime} and #{endTime} and o.create_time BETWEEN #{startTime} and #{endTime}
</if> </if>
<if test="startTime!=null and startTime!='' and (endTime==null or endTime=='')"> <if test="startTime!=null and startTime!='' and (endTime==null or endTime=='')">
and date_format(o.create_time,'%Y-%m-%d') &gt;= #{startTime} and o.create_time &gt;= #{startTime}
</if> </if>
<if test="endTime!=null and endTime!='' and (startTime==null or startTime=='')"> <if test="endTime!=null and endTime!='' and (startTime==null or startTime=='')">
and date_format(o.create_time,'%Y-%m-%d') &lt;= #{endTime} and o.create_time &lt;= #{endTime}
</if> </if>
order by o.create_time desc order by o.create_time desc
</select> </select>

View File

@@ -23,28 +23,6 @@
update pay_details set `state`=#{state},pay_time=#{time},trade_no=#{tradeNo} where id=#{id} update pay_details set `state`=#{state},pay_time=#{time},trade_no=#{tradeNo} where id=#{id}
</update> </update>
<select id=" selectPayDetails" resultType="Map">
select s.id,s.classify,s.order_id as orderId,s.money,s.user_id as userId,
s.state,s.create_time as createTime,s.pay_time as payTime,u.user_name as userName,u.phone
from pay_details s
left join tb_user u on u.user_id=s.user_id
where 1=1
<if test="startTime!=null and startTime!=''and endTime!=null and endTime!='' ">
and str_to_date(s.create_time, '%Y-%m-%d') between str_to_date(#{startTime}, '%Y-%m-%d') AND str_to_date(#{endTime}, '%Y-%m-%d')
</if>
<if test="userId!=null">
and u.user_id=#{userId}
</if>
<if test="state!=null and state!=-1">
and s.state=#{state}
</if>
<if test="state==null or state==-1">
and s.state!=-1
</if>
group by s.id
order by s.create_time desc
</select>
<select id="selectPayDetails" resultType="Map"> <select id="selectPayDetails" resultType="Map">
select s.id,s.classify,s.order_id as orderId,s.money,s.user_id as userId,s.pay_diamond as payDiamond,s.diamond, select s.id,s.classify,s.order_id as orderId,s.money,s.user_id as userId,s.pay_diamond as payDiamond,s.diamond,
s.state,s.create_time as createTime,s.pay_time as payTime,u.user_name as userName,u.phone s.state,s.create_time as createTime,s.pay_time as payTime,u.user_name as userName,u.phone
@@ -52,8 +30,7 @@
left join tb_user u on u.user_id=s.user_id left join tb_user u on u.user_id=s.user_id
where 1=1 where 1=1
<if test="startTime!=null and startTime!=''and endTime!=null and endTime!='' "> <if test="startTime!=null and startTime!=''and endTime!=null and endTime!='' ">
and str_to_date(s.create_time, '%Y-%m-%d') between str_to_date(#{startTime}, '%Y-%m-%d') AND and s.create_time between #{startTime} AND #{endTime}
str_to_date(#{endTime}, '%Y-%m-%d')
</if> </if>
<if test="userName!=null and userName!=''"> <if test="userName!=null and userName!=''">
and u.user_name like concat("%",#{userName},"%") and u.user_name like concat("%",#{userName},"%")
@@ -77,7 +54,7 @@
<select id="selectSumPay" resultType="Double"> <select id="selectSumPay" resultType="Double">
select sum(money) from pay_details select sum(money) from pay_details
where str_to_date(create_time, '%Y-%m-%d') BETWEEN str_to_date(#{createTime}, '%Y-%m-%d') AND str_to_date(#{endTime}, '%Y-%m-%d') where create_time BETWEEN #{createTime} AND #{endTime}
<if test="userId!=null"> <if test="userId!=null">
and user_id=#{userId} and user_id=#{userId}
</if> </if>