Merge pull request 'xinwei' (#56) from xinwei into master
All checks were successful
continuous-integration/drone Build is passing

Reviewed-on: #56
This commit is contained in:
root 2024-08-29 11:09:14 +08:00
commit 05b7ca3f1d
15 changed files with 308 additions and 80 deletions

View File

@ -7,74 +7,74 @@ name: ludu-system-drone # 定义流水线名称
steps: # 定义流水线执行步骤,这些步骤将顺序执行 steps: # 定义流水线执行步骤,这些步骤将顺序执行
- name: package # 流水线名称 # - name: package # 流水线名称
#
image: maven:3-jdk-8 # 定义创建容器的Docker镜像 # image: maven:3-jdk-8 # 定义创建容器的Docker镜像
#
volumes: # 将容器内目录挂载到宿主机仓库需要开启Trusted设置 # volumes: # 将容器内目录挂载到宿主机仓库需要开启Trusted设置
#
- name: maven-cache # - name: maven-cache
#
path: /root/.m2 # 将maven下载依赖的目录挂载出来防止重复下载 # path: /root/.m2 # 将maven下载依赖的目录挂载出来防止重复下载
#
- name: maven-build # - name: maven-build
#
path: /app/build # 将应用打包好的Jar和执行脚本挂载出来 # path: /app/build # 将应用打包好的Jar和执行脚本挂载出来
#
commands: # 定义在Docker容器中执行的shell命令 # commands: # 定义在Docker容器中执行的shell命令
#
- mvn package -Dmaven.test.skip=true # 应用打包命令 # - mvn package -Dmaven.test.skip=true # 应用打包命令
- mkdir -p /app/build/ludu-module-datacenter/target # - mkdir -p /app/build/ludu-module-datacenter/target
- cp ./ludu-module-datacenter/ludu-module-datacenter-biz/target/ludu-module-datacenter-biz.jar /app/build/ludu-module-datacenter/target # - cp ./ludu-module-datacenter/ludu-module-datacenter-biz/target/ludu-module-datacenter-biz.jar /app/build/ludu-module-datacenter/target
- cp ./ludu-module-datacenter/ludu-module-datacenter-biz/Dockerfile /app/build/ludu-module-datacenter # - cp ./ludu-module-datacenter/ludu-module-datacenter-biz/Dockerfile /app/build/ludu-module-datacenter
- cp ./ludu-module-datacenter/ludu-module-datacenter-biz/run.sh /app/build/ludu-module-datacenter # - cp ./ludu-module-datacenter/ludu-module-datacenter-biz/run.sh /app/build/ludu-module-datacenter
#
- name: copy-to-object # 构建基础模块和复制票务停车场到轮渡服务器 # - name: copy-to-object # 构建基础模块和复制票务停车场到轮渡服务器
#
image: appleboy/drone-ssh # SSH工具镜像 # image: appleboy/drone-ssh # SSH工具镜像
#
settings: # settings:
#
host: 101.43.112.107 # 远程连接地址 # host: 101.43.112.107 # 远程连接地址
#
username: root # 远程连接账号 # username: root # 远程连接账号
#
password: # password:
#
from_secret: ssh_password # 从Secret中读取SSH密码 # from_secret: ssh_password # 从Secret中读取SSH密码
#
port: 22 # 远程连接端口 # port: 22 # 远程连接端口
#
command_timeout: 15m # 远程执行命令超时时间 # command_timeout: 15m # 远程执行命令超时时间
#
script: # script:
#
- scp -r /ludu/maven/build/ludu-module-datacenter root@120.46.37.243:/ludu/maven/build # - scp -r /ludu/maven/build/ludu-module-datacenter root@120.46.37.243:/ludu/maven/build
- echo "datacenter done" # - echo "datacenter done"
#
- name: build-old-service # - name: build-old-service
#
image: appleboy/drone-ssh # SSH工具镜像 # image: appleboy/drone-ssh # SSH工具镜像
#
settings: # settings:
#
host: 120.46.37.243 # 远程连接地址 # host: 120.46.37.243 # 远程连接地址
#
username: root # 远程连接账号 # username: root # 远程连接账号
#
password: # password:
#
from_secret: ssh_password2 # 从Secret中读取SSH密码 # from_secret: ssh_password2 # 从Secret中读取SSH密码
#
port: 22 # 远程连接端口 # port: 22 # 远程连接端口
#
command_timeout: 5m # 远程执行命令超时时间 # command_timeout: 5m # 远程执行命令超时时间
#
script: # script:
#
- cd /ludu/maven/build/ludu-module-datacenter/ # - cd /ludu/maven/build/ludu-module-datacenter/
- chmod +x ./run.sh # 更改为可执行脚本 # - chmod +x ./run.sh # 更改为可执行脚本
- ./run.sh || echo "ludu-module-datacenter build failed" # 运行脚本打包应用镜像并运行 # - ./run.sh || echo "ludu-module-datacenter build failed" # 运行脚本打包应用镜像并运行
- name: build-new-service - name: build-new-service
@ -105,7 +105,7 @@ steps: # 定义流水线执行步骤,这些步骤将顺序执行
echo "Killing process $pid" echo "Killing process $pid"
kill -9 $pid kill -9 $pid
fi fi
nohup java -Xms256m -Xmx256m -jar ludu-module-datacenter/ludu-module-datacenter-biz/target/ludu-module-datacenter-biz.jar --spring.profiles.active=dev > api.log & nohup java -jar ludu-module-datacenter/ludu-module-datacenter-biz/target/ludu-module-datacenter-biz.jar --spring.profiles.active=dev > api.log &
volumes: # 定义流水线挂载目录,用于共享数据 volumes: # 定义流水线挂载目录,用于共享数据

View File

@ -38,6 +38,20 @@ public class BookCarController {
@Resource @Resource
private BookCarService bookCarService; private BookCarService bookCarService;
@PostMapping("/sendBookingCar")
@Operation(summary = "预约车下发")
@PreAuthorize("@ss.hasPermission('parking:book-car:create')")
public CommonResult<String> sendBookingCar(@RequestBody BookCarReqDataVO bookCarReqDataVO){
return success(bookCarService.sendBookingCar(bookCarReqDataVO));
}
@PostMapping("/queryBookingCar")
@Operation(summary = "预约车查询")
@PreAuthorize("@ss.hasPermission('parking:book-car:query')")
public CommonResult<String> queryBookingCar(@RequestBody BookCarQueryDataVO bookCarQueryDataVO){
return success(bookCarService.queryBookingCar(bookCarQueryDataVO));
}
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建预约车") @Operation(summary = "创建预约车")
@PreAuthorize("@ss.hasPermission('parking:book-car:create')") @PreAuthorize("@ss.hasPermission('parking:book-car:create')")

View File

@ -0,0 +1,13 @@
package cn.iocoder.yudao.module.parking.controller.admin.bookcar.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 预约车查询 Request VO")
@Data
public class BookCarQueryDataVO {
@Schema(description = "场库编号")
private String parkNumber;
@Schema(description = "车牌列表")
private BookCarRespVO datas;
}

View File

@ -0,0 +1,17 @@
package cn.iocoder.yudao.module.parking.controller.admin.bookcar.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 预约车查询 Request VO")
@Data
public class BookCarQueryVO {
@Schema(description = "车牌列表")
private List<String> plateList;
@Schema(description = "开始时间")
private String start;
@Schema(description = "结束时间")
private String end;
}

View File

@ -0,0 +1,15 @@
package cn.iocoder.yudao.module.parking.controller.admin.bookcar.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 预约车下发 Request VO")
@Data
public class BookCarReqDataVO {
@Schema(description = "场库编号")
private String parkNumber;
@Schema(description = "预约数据")
private List<BookCarSaveReqVO> datas;
}

View File

@ -52,4 +52,17 @@ public interface BookCarService {
*/ */
PageResult<BookCarDO> getBookCarPage(BookCarPageReqVO pageReqVO); PageResult<BookCarDO> getBookCarPage(BookCarPageReqVO pageReqVO);
/**
* 预约车下发和记录
* @param bookCarReqDataVO
* @return java.lang.String
*/
String sendBookingCar(BookCarReqDataVO bookCarReqDataVO);
/**
* 预约车查询和记录
* @param bookCarQueryDataVO
* @return java.lang.Object
*/
String queryBookingCar(BookCarQueryDataVO bookCarQueryDataVO);
} }

View File

@ -1,11 +1,19 @@
package cn.iocoder.yudao.module.parking.service.bookcar; package cn.iocoder.yudao.module.parking.service.bookcar;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.parking.util.BlueCarRequestUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
import cn.iocoder.yudao.module.parking.controller.admin.bookcar.vo.*; import cn.iocoder.yudao.module.parking.controller.admin.bookcar.vo.*;
import cn.iocoder.yudao.module.parking.dal.dataobject.bookcar.BookCarDO; import cn.iocoder.yudao.module.parking.dal.dataobject.bookcar.BookCarDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -28,6 +36,8 @@ public class BookCarServiceImpl implements BookCarService {
@Resource @Resource
private BookCarMapper bookCarMapper; private BookCarMapper bookCarMapper;
@Resource
private BlueCarRequestUtil blueCarRequestUtil;
@Override @Override
public Long createBookCar(BookCarSaveReqVO createReqVO) { public Long createBookCar(BookCarSaveReqVO createReqVO) {
@ -71,4 +81,29 @@ public class BookCarServiceImpl implements BookCarService {
return bookCarMapper.selectPage(pageReqVO); return bookCarMapper.selectPage(pageReqVO);
} }
@Override
public String sendBookingCar(BookCarReqDataVO bookCarReqDataVO) {
CommonResult<String> result = blueCarRequestUtil.doBlueCarPost(bookCarReqDataVO, "out/synBookingCa");
if (result.getCode() == 0) {
List<BookCarSaveReqVO> datas = bookCarReqDataVO.getDatas();
for (BookCarSaveReqVO data : datas) {
data.setParkNumber(bookCarReqDataVO.getParkNumber());
}
bookCarMapper.insertBatch(BeanUtils.toBean(datas, BookCarDO.class));
return "success";
}
return "error";
}
@Override
public String queryBookingCar(BookCarQueryDataVO bookCarQueryDataVO) {
CommonResult<String> result = blueCarRequestUtil.doBlueCarPost(bookCarQueryDataVO, "out/queryBookingCar");
if (result.getCode() == 0){
Object object = JSON.parse(result.getData());
// TODO 保存操作暂时没想好
return "success";
}
return "error";
}
} }

View File

@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.infra.dal.dataobject.checkticket;
import lombok.Data; import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
@Document("checkticket") @Document("check_ticket_today")
//@Document("checktickettest") //@Document("checktickettest")
@Data @Data
public class CheckTicketToday { public class CheckTicketToday {

View File

@ -1,12 +1,30 @@
package cn.iocoder.yudao.module.infra.dal.mongodb.checkticket; package cn.iocoder.yudao.module.infra.dal.mongodb.checkticket;
import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket;
import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday; import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Repository @Repository
public interface CheckTicketTodayRepository extends MongoRepository<CheckTicketToday,String> { public interface CheckTicketTodayRepository extends MongoRepository<CheckTicketToday,String> {
/**
* 根据dataId数组查找
* @param dataIdList
* @return java.util.List<cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket>
*/
@Query(value = "{ 'dataId': { $in: ?0 } }", fields = "{ 'dataId': 1, '_id': 0 }")
List<CheckTicketToday> findByDataIdIn(List<String> dataIdList);
/**
* 找到所有不在时间段内的日期字段
* @param startDate
* @param endDate
* @return java.util.List<cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday>
*/
@Query("{ 'checkticketdate': { $not: { $gte: ?0, $lt: ?1 } } }")
List<CheckTicketToday> findNotInTimeRange(String startDate, String endDate);
} }

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.infra.dal.mongodb.saledata; package cn.iocoder.yudao.module.infra.dal.mongodb.saledata;
import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket;
import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday;
import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleData; import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleData;
import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday; import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday;
import org.springframework.data.mongodb.repository.Aggregation; import org.springframework.data.mongodb.repository.Aggregation;
@ -61,5 +63,19 @@ public interface SaleDataTodayRepository extends MongoRepository<SaleDataToday,S
// //
// @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }") // @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }")
// List<SaleData> findAllByTransactiontypenoTime(String starTime, String endTime); // List<SaleData> findAllByTransactiontypenoTime(String starTime, String endTime);
/**
* 更具dataId查找售票记录
* @param dataIdList
* @return java.util.List<cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket>
*/
@Query(value = "{ 'dataId': { $in: ?0 } }", fields = "{ 'dataId': 1, '_id': 0 }")
List<SaleDataToday> findByDataIdIn(List<String> dataIdList);
/**
* 找到所有不在时间段内的日期字段
* @param startDate
* @param endDate
* @return java.util.List<cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday>
*/
@Query("{ 'sddate': { $not: { $gte: ?0, $lt: ?1 } } }")
List<SaleDataToday> findNotInTimeRange(String startDate, String endDate);
} }

View File

@ -303,6 +303,45 @@ public class TicketDataMigration {
XxlJobHelper.log("抽数结束!!!"); XxlJobHelper.log("抽数结束!!!");
} }
/**
* 删除今年和去年往前推31天外的数据和抽取去年明天的数据
*/
@XxlJob("deleteTwoYearOneMonthAgoAndUpdateLastYearTomorrow")
public void deleteTwoYearOneMonthAgoAndUpdateLastYearTomorrow(){
XxlJobHelper.log("删除多余数据开始...");
// 检票数据今年多余删除
Calendar today = Calendar.getInstance();
Calendar thirtyDaysAgo = (Calendar) today.clone(); // 克隆当前日期
thirtyDaysAgo.add(Calendar.DAY_OF_MONTH, -31);
List<String> thisYearCheckTicketList = checkTicketService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(thirtyDaysAgo.getTime()), TickingDateUtils.format(today.getTime()));
XxlJobHelper.log("删除今年检票日期为{}", thisYearCheckTicketList.toString());
// 检票数据去年多余删除
Calendar lastYearToday = (Calendar) today.clone();
lastYearToday.add(Calendar.YEAR, -1);
Calendar lastYearThirtyDaysAgo = (Calendar) lastYearToday.clone();
lastYearThirtyDaysAgo.add(Calendar.DAY_OF_MONTH, -31);
List<String> lastYearCheckTicketList = checkTicketService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(lastYearThirtyDaysAgo.getTime()), TickingDateUtils.format(lastYearToday.getTime()));
XxlJobHelper.log("删除去年检票日期为{}", lastYearCheckTicketList.toString());
// 售票数据今年多余删除
List<String> thisYearSaleDataList = saleDataService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(thirtyDaysAgo.getTime()), TickingDateUtils.format(today.getTime()));
XxlJobHelper.log("删除今年售票日期为{}", thisYearSaleDataList.toString());
// 售票数据去年多余删除
List<String> lastYearSaleDataList = checkTicketService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(lastYearThirtyDaysAgo.getTime()), TickingDateUtils.format(lastYearToday.getTime()));
XxlJobHelper.log("删除去年检票日期为{}", lastYearSaleDataList.toString());
// 抽取去年明天的检票和售票数据
Calendar lastYearTomorrow = (Calendar) lastYearToday.clone();
lastYearTomorrow.add(Calendar.DAY_OF_MONTH, 1);
try {
this.getTicketDataByTimeZonesToMongo(lastYearTomorrow, lastYearTomorrow, "checkTicket");
} catch (Exception e) {
XxlJobHelper.log("抽取去年明天的检票数据失败,日期为{}", TickingDateUtils.format(lastYearTomorrow.getTime()));
}
try {
this.getTicketDataByTimeZonesToMongo(lastYearTomorrow, lastYearTomorrow, "saleData");
} catch (Exception e) {
XxlJobHelper.log("抽取去年明天的售票数据失败,日期为{}", TickingDateUtils.format(lastYearTomorrow.getTime()));
}
}
/** /**
* 用于更新指定日期的检票或售票数据(mongodb) * 用于更新指定日期的检票或售票数据(mongodb)
@ -358,9 +397,9 @@ public class TicketDataMigration {
mapList = ticketingSamplingRespVO.getDataMapList(); mapList = ticketingSamplingRespVO.getDataMapList();
List<Integer> resultNum = null; List<Integer> resultNum = null;
if ("checkTicket".equals(method)) { if ("checkTicket".equals(method)) {
resultNum = checkTicketService.insertByMongoDB(BeanUtils.toBean(mapList, CheckTicket.class)); resultNum = checkTicketService.insertTodayByMongoDB(BeanUtils.toBean(mapList, CheckTicketToday.class));
} else if ("saleData".equals(method)) { } else if ("saleData".equals(method)) {
resultNum = saleDataService.insertByMongoDB(BeanUtils.toBean(mapList, SaleData.class)); resultNum = saleDataService.insertTodayByMongoDB(BeanUtils.toBean(mapList, SaleDataToday.class));
} }
if (resultNum == null) { if (resultNum == null) {
result.add("数据批量插入异常!"); result.add("数据批量插入异常!");

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday; import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -39,4 +40,11 @@ public interface CheckTicketService {
*/ */
List<Integer> insertByMongoDB(List<CheckTicket> checkTicketList); List<Integer> insertByMongoDB(List<CheckTicket> checkTicketList);
List<Integer> insertTodayByMongoDB(List<CheckTicketToday> checkTicketList); List<Integer> insertTodayByMongoDB(List<CheckTicketToday> checkTicketList);
/**
* 删除不在指定日期内的数据(mongodb)
* @param startDate "20240729"
* @param endDate "20240829"
* @return java.util.List<java.lang.String> 删除的日期
*/
List<String> deleteNotInTimeZonesByMongoDB(String startDate,String endDate);
} }

View File

@ -71,7 +71,7 @@ public class CheckTicketServiceImpl implements CheckTicketService {
try { try {
// 批量插入 // 批量插入
checkTicketRepository.insert(insertCheckTicketList); checkTicketRepository.insert(insertCheckTicketList);
} catch (MongoException e){ } catch (MongoException e) {
return null; return null;
} }
resultNum.add(insertCheckTicketList.size()); resultNum.add(insertCheckTicketList.size());
@ -85,13 +85,16 @@ public class CheckTicketServiceImpl implements CheckTicketService {
// 把检票数据的dataId提取出来成数组 // 把检票数据的dataId提取出来成数组
List<String> dataIdList = checkTicketList.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList()); List<String> dataIdList = checkTicketList.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList());
// 获取重复的dataId // 获取重复的dataId
List<String> duplicatesDataId = this.checkDuplicatesByMongoDB(dataIdList); // 查询数据库中存在的 dataId
List<CheckTicketToday> existingTickets = checkTicketTodayRepository.findByDataIdIn(dataIdList);
// 把CheckTicket对象列表改为dataId字符串列表
List<String> duplicatesDataId = existingTickets.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList());
// 对checkTicketList过滤掉重复的dataId对应的数据得到需要插入的不重复数据 // 对checkTicketList过滤掉重复的dataId对应的数据得到需要插入的不重复数据
List<CheckTicketToday> insertCheckTicketList = checkTicketList.stream().filter(ticket -> !duplicatesDataId.contains(ticket.getDataId())).collect(Collectors.toList()); List<CheckTicketToday> insertCheckTicketList = checkTicketList.stream().filter(ticket -> !duplicatesDataId.contains(ticket.getDataId())).collect(Collectors.toList());
try { try {
// 批量插入 // 批量插入
checkTicketTodayRepository.insert(insertCheckTicketList); checkTicketTodayRepository.insert(insertCheckTicketList);
} catch (MongoException e){ } catch (MongoException e) {
return null; return null;
} }
resultNum.add(insertCheckTicketList.size()); resultNum.add(insertCheckTicketList.size());
@ -99,4 +102,18 @@ public class CheckTicketServiceImpl implements CheckTicketService {
return resultNum; return resultNum;
} }
@Override
public List<String> deleteNotInTimeZonesByMongoDB(String startDate, String endDate) {
// 执行查询并获取要删除的数据
List<CheckTicketToday> entitiesToDelete = checkTicketTodayRepository.findNotInTimeRange(startDate, endDate);
// 执行删除操作
checkTicketTodayRepository.deleteAll(entitiesToDelete);
// 获取要删除的日期列表
List<String> deletedDates = entitiesToDelete.stream()
.map(CheckTicketToday::getCheckticketdate)
.collect(Collectors.toList());
return deletedDates;
}
} }

View File

@ -42,4 +42,11 @@ public interface SaleDataService {
*/ */
List<Integer> insertByMongoDB(List<SaleData> saleDataList); List<Integer> insertByMongoDB(List<SaleData> saleDataList);
List<Integer> insertTodayByMongoDB(List<SaleDataToday> saleDataList); List<Integer> insertTodayByMongoDB(List<SaleDataToday> saleDataList);
/**
* 删除不在指定日期内的数据(mongodb)
* @param startDate "20240729"
* @param endDate "20240829"
* @return java.util.List<java.lang.String> 删除的日期
*/
List<String> deleteNotInTimeZonesByMongoDB(String startDate,String endDate);
} }

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.infra.service.saledata; package cn.iocoder.yudao.module.infra.service.saledata;
import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket; import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket;
import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicketToday;
import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleData; import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleData;
import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataDO; import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataDO;
import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday; import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday;
@ -62,7 +63,7 @@ public class SaleDataServiceImpl implements SaleDataService {
try { try {
// 批量插入 // 批量插入
saleDataRepository.insert(insertSaleDataList); saleDataRepository.insert(insertSaleDataList);
} catch (MongoException e){ } catch (MongoException e) {
return null; return null;
} }
resultNum.add(insertSaleDataList.size()); resultNum.add(insertSaleDataList.size());
@ -76,19 +77,34 @@ public class SaleDataServiceImpl implements SaleDataService {
// 把检票数据的dataId提取出来成数组 // 把检票数据的dataId提取出来成数组
List<String> dataIdList = saleDataList.stream().map(SaleDataToday::getDataId).collect(Collectors.toList()); List<String> dataIdList = saleDataList.stream().map(SaleDataToday::getDataId).collect(Collectors.toList());
// 获取重复的dataId // 获取重复的dataId
List<String> duplicatesDataId = this.checkDuplicatesByMongoDB(dataIdList); // 查询数据库中存在的 dataId
List<SaleDataToday> existingTickets = saleDataTodayRepository.findByDataIdIn(dataIdList);
// 把CheckTicket对象列表改为dataId字符串列表
List<String> duplicatesDataId = existingTickets.stream().map(SaleDataToday::getDataId).collect(Collectors.toList());
// 对checkTicketList过滤掉重复的dataId对应的数据得到需要插入的不重复数据 // 对checkTicketList过滤掉重复的dataId对应的数据得到需要插入的不重复数据
List<SaleDataToday> insertSaleDataList = saleDataList.stream().filter(saleData -> !duplicatesDataId.contains(saleData.getDataId())).collect(Collectors.toList()); List<SaleDataToday> insertSaleDataList = saleDataList.stream().filter(saleData -> !duplicatesDataId.contains(saleData.getDataId())).collect(Collectors.toList());
try { try {
// 批量插入 // 批量插入
saleDataTodayRepository.insert(insertSaleDataList); saleDataTodayRepository.insert(insertSaleDataList);
} catch (MongoException e){ } catch (MongoException e) {
return null; return null;
} }
resultNum.add(insertSaleDataList.size()); resultNum.add(insertSaleDataList.size());
resultNum.add(duplicatesDataId.size()); resultNum.add(duplicatesDataId.size());
return resultNum; return resultNum;
} }
@Override
public List<String> deleteNotInTimeZonesByMongoDB(String startDate, String endDate) {
// 执行查询并获取要删除的数据
List<SaleDataToday> entitiesToDelete = saleDataTodayRepository.findNotInTimeRange(startDate, endDate);
// 执行删除操作
saleDataTodayRepository.deleteAll(entitiesToDelete);
// 获取要删除的日期列表
List<String> deletedDates = entitiesToDelete.stream()
.map(SaleDataToday::getSddate)
.collect(Collectors.toList());
return deletedDates;
}
} }