Merge pull request 'xinwei' (#54) from xinwei into master
Reviewed-on: #54
This commit is contained in:
commit
a28f47cebe
29
.drone.yml
29
.drone.yml
@ -161,7 +161,36 @@ steps: # 定义流水线执行步骤,这些步骤将顺序执行
|
||||
- cd /ludu/maven/build/ludu-job-admin/
|
||||
- chmod +x ./run.sh # 更改为可执行脚本
|
||||
- ./run.sh || echo "ludu-job-admin build failed" # 运行脚本打包应用镜像并运行
|
||||
- name: build-new-service
|
||||
|
||||
image: appleboy/drone-ssh # SSH工具镜像
|
||||
|
||||
settings:
|
||||
|
||||
host: 121.36.203.133 # 远程连接地址
|
||||
|
||||
username: root # 远程连接账号
|
||||
|
||||
password:
|
||||
|
||||
from_secret: ssh_password3 # 从Secret中读取SSH密码
|
||||
|
||||
port: 22 # 远程连接端口
|
||||
|
||||
command_timeout: 10m # 远程执行命令超时时间
|
||||
|
||||
script: |
|
||||
cd /root/ludu-cloud
|
||||
git pull origin master
|
||||
rm -f ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/framework/nacos/config/BeanInit.java
|
||||
/root/apache-maven-3.9.4/bin/mvn clean package -Dmaven.test.skip=true
|
||||
port=48092 # 指定端口号
|
||||
pid=$(lsof -t -i:$port) # 获取占用指定端口的进程号
|
||||
if [ -n "$pid" ]; then
|
||||
echo "Killing process $pid"
|
||||
kill -9 $pid
|
||||
fi
|
||||
nohup java -Xms512m -Xmx512m -jar ludu-module-datacenter/ludu-module-datacenter-biz/target/ludu-module-datacenter-biz.jar --spring.profiles.active=dev > api.log &
|
||||
volumes: # 定义流水线挂载目录,用于共享数据
|
||||
|
||||
- name: maven-build
|
||||
|
@ -0,0 +1,33 @@
|
||||
package cn.iocoder.yudao.module.infra.controller.admin.ticketing;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.date.TickingDateUtils;
|
||||
import cn.iocoder.yudao.module.infra.job.ticketing.TicketDataMigration;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description 测试抽数接口
|
||||
*/
|
||||
@Tag(name = "管理后台 - 抽数接口")
|
||||
@RestController
|
||||
@RequestMapping("/infra/ticketing")
|
||||
@Validated
|
||||
public class TicketingController {
|
||||
@Resource
|
||||
TicketDataMigration ticketDataMigration;
|
||||
|
||||
@GetMapping
|
||||
public CommonResult<String> testTicketing(@RequestParam("startDate") String startDate, @RequestParam("endDate")String endDate, @RequestParam("method") String method) throws Exception {
|
||||
Calendar startCalendar = Calendar.getInstance();
|
||||
Calendar endCalendar = Calendar.getInstance();
|
||||
startCalendar.setTime(TickingDateUtils.parse(startDate));
|
||||
endCalendar.setTime(TickingDateUtils.parse(endDate));
|
||||
return CommonResult.success(ticketDataMigration.getTicketDataByTimeZonesToMongo(startCalendar, endCalendar, method));
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@ public class SecurityConfiguration {
|
||||
.antMatchers(adminSeverContextPath + "/**").anonymous();
|
||||
// 文件读取
|
||||
registry.antMatchers(buildAdminApi("/infra/file/*/get/**")).permitAll();
|
||||
registry.antMatchers("/**/infra/ticketing/**").permitAll();
|
||||
|
||||
// TODO 芋艿:这个每个项目都需要重复配置,得捉摸有没通用的方案
|
||||
// RPC 服务的安全配置
|
||||
|
@ -28,10 +28,7 @@ import org.springframework.stereotype.Component;
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Description 票务抽数服务
|
||||
@ -64,7 +61,7 @@ public class TicketDataMigration {
|
||||
int failedCount = 0;
|
||||
int pageNumber = 1;
|
||||
XxlJobHelper.log("抽数服务:mysql销售数据开始抽数...");
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = this.getUrlResponseData(SALE_DATA_SERVICE, SALE_DATA_METHOD, TickingDateUtils.getPreviousDayFormat(), pageNumber);
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = this.getUrlResponseData(SALE_DATA_SERVICE, SALE_DATA_METHOD, TickingDateUtils.getNowDayFormat(), pageNumber);
|
||||
int totalRows = ticketingSamplingRespVO.getTotalRows();
|
||||
List<Map<String, Object>> mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 总条数小于等于每页条数 则直接按照总条数进行插入即可
|
||||
@ -79,7 +76,7 @@ public class TicketDataMigration {
|
||||
int totalPages = ticketingSamplingRespVO.getTotalPages();
|
||||
// 处理剩余页的数据
|
||||
for (; pageNumber <= totalPages; pageNumber++) {
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(SALE_DATA_SERVICE, SALE_DATA_METHOD, TickingDateUtils.getPreviousDayFormat(), pageNumber);
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(SALE_DATA_SERVICE, SALE_DATA_METHOD, TickingDateUtils.getNowDayFormat(), pageNumber);
|
||||
|
||||
mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 对最后一页进行处理,得到最后一页的实际条数
|
||||
@ -103,7 +100,7 @@ public class TicketDataMigration {
|
||||
int failedCount = 0;
|
||||
int pageNumber = 1;
|
||||
XxlJobHelper.log("抽数服务:mysql检票数据开始抽数...");
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = this.getUrlResponseData(CHECK_TICKET_SERVICE, CHECK_TICKET_METHOD, TickingDateUtils.getPreviousDayFormat(), pageNumber);
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = this.getUrlResponseData(CHECK_TICKET_SERVICE, CHECK_TICKET_METHOD, TickingDateUtils.getNowDayFormat(), pageNumber);
|
||||
int totalRows = ticketingSamplingRespVO.getTotalRows();
|
||||
List<Map<String, Object>> mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 总条数小于等于每页条数 则直接按照总条数进行插入即可
|
||||
@ -118,7 +115,7 @@ public class TicketDataMigration {
|
||||
int totalPages = ticketingSamplingRespVO.getTotalPages();
|
||||
// 处理剩余页的数据
|
||||
for (; pageNumber <= totalPages; pageNumber++) {
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(CHECK_TICKET_SERVICE, CHECK_TICKET_METHOD, TickingDateUtils.getPreviousDayFormat(), pageNumber);
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(CHECK_TICKET_SERVICE, CHECK_TICKET_METHOD, TickingDateUtils.getNowDayFormat(), pageNumber);
|
||||
mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
// 对最后一页进行处理,得到最后一页的实际条数
|
||||
if (pageNumber != totalPages) {
|
||||
@ -242,12 +239,13 @@ public class TicketDataMigration {
|
||||
}
|
||||
int currentMonth = startDate.get(Calendar.MONTH) + 1; // 加1以得到1-12的月份
|
||||
int currentDay = startDate.get(Calendar.DAY_OF_MONTH);
|
||||
XxlJobHelper.log("抽数服务:{}月{}日:检票数据抽数正常结束!总共:{}条数据,{}条数据重复,{}条数据插入成功!",currentMonth,currentDay ,totalRows, duplicatesCount, successCount);
|
||||
XxlJobHelper.log("抽数服务:{}月{}日:检票数据抽数正常结束!总共:{}条数据,{}条数据重复,{}条数据插入成功!", currentMonth, currentDay, totalRows, duplicatesCount, successCount);
|
||||
// 日期递增一天
|
||||
startDate.add(Calendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
XxlJobHelper.log("抽数结束!!!");
|
||||
}
|
||||
|
||||
@XxlJob("getSaleDataByMongoDBLastMonthToNow")
|
||||
public void getSaleDataByMongoDBLastMonthToNow() throws Exception {
|
||||
XxlJobHelper.log("抽数服务:mongodb售票数据开始抽数...");
|
||||
@ -296,12 +294,92 @@ public class TicketDataMigration {
|
||||
}
|
||||
int currentMonth = startDate.get(Calendar.MONTH) + 1; // 加1以得到1-12的月份
|
||||
int currentDay = startDate.get(Calendar.DAY_OF_MONTH);
|
||||
XxlJobHelper.log("抽数服务:{}月{}日:售票数据抽数正常结束!总共:{}条数据,{}条数据重复,{}条数据插入成功!",currentMonth,currentDay ,totalRows, duplicatesCount, successCount);
|
||||
XxlJobHelper.log("抽数服务:{}月{}日:售票数据抽数正常结束!总共:{}条数据,{}条数据重复,{}条数据插入成功!", currentMonth, currentDay, totalRows, duplicatesCount, successCount);
|
||||
// 日期递增一天
|
||||
startDate.add(Calendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
XxlJobHelper.log("抽数结束!!!");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用于更新指定日期的检票或售票数据(mongodb)
|
||||
*
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return void
|
||||
*/
|
||||
public String getTicketDataByTimeZonesToMongo(Calendar startDate, Calendar endDate, String method) throws Exception {
|
||||
String methodName;
|
||||
String respService;
|
||||
String respMethod;
|
||||
if ("checkTicket".equals(method)) {
|
||||
methodName = "检票";
|
||||
respService = CHECK_TICKET_SERVICE;
|
||||
respMethod = CHECK_TICKET_METHOD;
|
||||
} else if ("saleData".equals(method)) {
|
||||
methodName = "售票";
|
||||
respService = SALE_DATA_SERVICE;
|
||||
respMethod = SALE_DATA_METHOD;
|
||||
} else {
|
||||
XxlJobHelper.log("服务名错误");
|
||||
logger.error("服务名错误");
|
||||
return null;
|
||||
}
|
||||
StringJoiner result = new StringJoiner("\n");
|
||||
XxlJobHelper.log("抽数服务:mongodb{}数据开始抽数...", methodName);
|
||||
result.add("抽数服务:mongodb" + methodName + "数据开始抽数...");
|
||||
int successCount;
|
||||
int duplicatesCount;
|
||||
int pageNumber;
|
||||
|
||||
// 循环从开始日期到结束日期
|
||||
while (!startDate.after(endDate)) {
|
||||
successCount = 0;
|
||||
duplicatesCount = 0;
|
||||
String dateString = TickingDateUtils.format(startDate.getTime());
|
||||
pageNumber = 1;
|
||||
TicketingSamplingRespVO ticketingSamplingRespVO = this.getUrlResponseData(respService, respMethod, dateString, pageNumber);
|
||||
if (ticketingSamplingRespVO == null) {
|
||||
startDate.add(Calendar.DAY_OF_MONTH, 1);
|
||||
continue;
|
||||
}
|
||||
int totalRows = ticketingSamplingRespVO.getTotalRows();
|
||||
List<Map<String, Object>> mapList;
|
||||
|
||||
// 获得总页数
|
||||
int totalPages = ticketingSamplingRespVO.getTotalPages();
|
||||
|
||||
// 处理剩余页的数据
|
||||
for (; pageNumber <= totalPages; pageNumber++) {
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(respService, respMethod, dateString, pageNumber);
|
||||
mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
List<Integer> resultNum = null;
|
||||
if ("checkTicket".equals(method)) {
|
||||
resultNum = checkTicketService.insertByMongoDB(BeanUtils.toBean(mapList, CheckTicket.class));
|
||||
} else if ("saleData".equals(method)) {
|
||||
resultNum = saleDataService.insertByMongoDB(BeanUtils.toBean(mapList, SaleData.class));
|
||||
}
|
||||
if (resultNum == null) {
|
||||
result.add("数据批量插入异常!");
|
||||
} else {
|
||||
successCount += resultNum.get(0);
|
||||
duplicatesCount += resultNum.get(1);
|
||||
}
|
||||
}
|
||||
int currentYear = startDate.get(Calendar.YEAR);
|
||||
int currentMonth = startDate.get(Calendar.MONTH) + 1; // 加1以得到1-12的月份
|
||||
int currentDay = startDate.get(Calendar.DAY_OF_MONTH);
|
||||
result.add(String.format("抽数服务:%d年%d月%d日:" + methodName + "数据抽数正常结束!总共:%d条数据,%d条数据重复,%d条数据插入成功!", currentYear, currentMonth, currentDay, totalRows, duplicatesCount, successCount));
|
||||
XxlJobHelper.log("抽数服务:{}年{}月{}日:{}数据抽数正常结束!总共:{}条数据,{}条数据重复,{}条数据插入成功!", currentYear, currentMonth, currentDay, methodName, totalRows, duplicatesCount, successCount);
|
||||
// 日期递增一天
|
||||
startDate.add(Calendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
result.add("抽数结束!!!");
|
||||
logger.info(result.toString());
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入销售数据的方法(mysql)
|
||||
*
|
||||
@ -377,7 +455,7 @@ public class TicketDataMigration {
|
||||
XxlJobHelper.log("数据抽数失败,返回消息:" + ticketingSamplingRespVO.getRtnMsg());
|
||||
XxlJobHelper.handleFail("数据抽数失败,请重试");
|
||||
throw new RuntimeException();
|
||||
}else if (ticketingSamplingRespVO.getPageNumber() == null || ticketingSamplingRespVO.getPageSize() == null || ticketingSamplingRespVO.getTotalPages() == null || ticketingSamplingRespVO.getTotalRows() == null || ticketingSamplingRespVO.getDataMapList().isEmpty()){
|
||||
} else if (ticketingSamplingRespVO.getPageNumber() == null || ticketingSamplingRespVO.getPageSize() == null || ticketingSamplingRespVO.getTotalPages() == null || ticketingSamplingRespVO.getTotalRows() == null || ticketingSamplingRespVO.getDataMapList().isEmpty()) {
|
||||
XxlJobHelper.log("{},请求抽数成功,但返回参数值存在问题:{}", date, ticketingSamplingRespVO);
|
||||
return null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user