diff --git a/.drone-datacenter.yml b/.drone-datacenter.yml index 0b1b7502a..611e5c90a 100644 --- a/.drone-datacenter.yml +++ b/.drone-datacenter.yml @@ -7,74 +7,74 @@ name: ludu-system-drone # 定义流水线名称 steps: # 定义流水线执行步骤,这些步骤将顺序执行 - - name: package # 流水线名称 - - image: maven:3-jdk-8 # 定义创建容器的Docker镜像 - - volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置 - - - name: maven-cache - - path: /root/.m2 # 将maven下载依赖的目录挂载出来,防止重复下载 - - - name: maven-build - - path: /app/build # 将应用打包好的Jar和执行脚本挂载出来 - - commands: # 定义在Docker容器中执行的shell命令 - - - mvn package -Dmaven.test.skip=true # 应用打包命令 - - 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/Dockerfile /app/build/ludu-module-datacenter - - cp ./ludu-module-datacenter/ludu-module-datacenter-biz/run.sh /app/build/ludu-module-datacenter - - - name: copy-to-object # 构建基础模块和复制票务停车场到轮渡服务器 - - image: appleboy/drone-ssh # SSH工具镜像 - - settings: - - host: 101.43.112.107 # 远程连接地址 - - username: root # 远程连接账号 - - password: - - from_secret: ssh_password # 从Secret中读取SSH密码 - - port: 22 # 远程连接端口 - - command_timeout: 15m # 远程执行命令超时时间 - - script: - - - scp -r /ludu/maven/build/ludu-module-datacenter root@120.46.37.243:/ludu/maven/build - - echo "datacenter done" - - - name: build-old-service - - image: appleboy/drone-ssh # SSH工具镜像 - - settings: - - host: 120.46.37.243 # 远程连接地址 - - username: root # 远程连接账号 - - password: - - from_secret: ssh_password2 # 从Secret中读取SSH密码 - - port: 22 # 远程连接端口 - - command_timeout: 5m # 远程执行命令超时时间 - - script: - - - cd /ludu/maven/build/ludu-module-datacenter/ - - chmod +x ./run.sh # 更改为可执行脚本 - - ./run.sh || echo "ludu-module-datacenter build failed" # 运行脚本打包应用镜像并运行 +# - name: package # 流水线名称 +# +# image: maven:3-jdk-8 # 定义创建容器的Docker镜像 +# +# volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置 +# +# - name: maven-cache +# +# path: /root/.m2 # 将maven下载依赖的目录挂载出来,防止重复下载 +# +# - name: maven-build +# +# path: /app/build # 将应用打包好的Jar和执行脚本挂载出来 +# +# commands: # 定义在Docker容器中执行的shell命令 +# +# - mvn package -Dmaven.test.skip=true # 应用打包命令 +# - 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/Dockerfile /app/build/ludu-module-datacenter +# - cp ./ludu-module-datacenter/ludu-module-datacenter-biz/run.sh /app/build/ludu-module-datacenter +# +# - name: copy-to-object # 构建基础模块和复制票务停车场到轮渡服务器 +# +# image: appleboy/drone-ssh # SSH工具镜像 +# +# settings: +# +# host: 101.43.112.107 # 远程连接地址 +# +# username: root # 远程连接账号 +# +# password: +# +# from_secret: ssh_password # 从Secret中读取SSH密码 +# +# port: 22 # 远程连接端口 +# +# command_timeout: 15m # 远程执行命令超时时间 +# +# script: +# +# - scp -r /ludu/maven/build/ludu-module-datacenter root@120.46.37.243:/ludu/maven/build +# - echo "datacenter done" +# +# - name: build-old-service +# +# image: appleboy/drone-ssh # SSH工具镜像 +# +# settings: +# +# host: 120.46.37.243 # 远程连接地址 +# +# username: root # 远程连接账号 +# +# password: +# +# from_secret: ssh_password2 # 从Secret中读取SSH密码 +# +# port: 22 # 远程连接端口 +# +# command_timeout: 5m # 远程执行命令超时时间 +# +# script: +# +# - cd /ludu/maven/build/ludu-module-datacenter/ +# - chmod +x ./run.sh # 更改为可执行脚本 +# - ./run.sh || echo "ludu-module-datacenter build failed" # 运行脚本打包应用镜像并运行 - name: build-new-service @@ -105,7 +105,7 @@ steps: # 定义流水线执行步骤,这些步骤将顺序执行 echo "Killing process $pid" kill -9 $pid 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: # 定义流水线挂载目录,用于共享数据 diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/BookCarController.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/BookCarController.java index 5335f3298..34bb25a8d 100644 --- a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/BookCarController.java +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/BookCarController.java @@ -38,6 +38,20 @@ public class BookCarController { @Resource private BookCarService bookCarService; + @PostMapping("/sendBookingCar") + @Operation(summary = "预约车下发") + @PreAuthorize("@ss.hasPermission('parking:book-car:create')") + public CommonResult sendBookingCar(@RequestBody BookCarReqDataVO bookCarReqDataVO){ + return success(bookCarService.sendBookingCar(bookCarReqDataVO)); + } + @PostMapping("/queryBookingCar") + @Operation(summary = "预约车查询") + @PreAuthorize("@ss.hasPermission('parking:book-car:query')") + public CommonResult queryBookingCar(@RequestBody BookCarQueryDataVO bookCarQueryDataVO){ + return success(bookCarService.queryBookingCar(bookCarQueryDataVO)); + } + + @PostMapping("/create") @Operation(summary = "创建预约车") @PreAuthorize("@ss.hasPermission('parking:book-car:create')") diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarQueryDataVO.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarQueryDataVO.java new file mode 100644 index 000000000..794f6a6c8 --- /dev/null +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarQueryDataVO.java @@ -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; +} diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarQueryVO.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarQueryVO.java new file mode 100644 index 000000000..25e6915ad --- /dev/null +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarQueryVO.java @@ -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 plateList; + @Schema(description = "开始时间") + private String start; + @Schema(description = "结束时间") + private String end; +} diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarReqDataVO.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarReqDataVO.java new file mode 100644 index 000000000..343831435 --- /dev/null +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarReqDataVO.java @@ -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 datas; +} diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/bookcar/BookCarService.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/bookcar/BookCarService.java index 2e0afb5d2..ae89afc17 100644 --- a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/bookcar/BookCarService.java +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/bookcar/BookCarService.java @@ -52,4 +52,17 @@ public interface BookCarService { */ PageResult getBookCarPage(BookCarPageReqVO pageReqVO); + /** + * 预约车下发和记录 + * @param bookCarReqDataVO + * @return java.lang.String + */ + String sendBookingCar(BookCarReqDataVO bookCarReqDataVO); + + /** + * 预约车查询和记录 + * @param bookCarQueryDataVO + * @return java.lang.Object + */ + String queryBookingCar(BookCarQueryDataVO bookCarQueryDataVO); } \ No newline at end of file diff --git a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/bookcar/BookCarServiceImpl.java b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/bookcar/BookCarServiceImpl.java index a2f345084..3c8028448 100644 --- a/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/bookcar/BookCarServiceImpl.java +++ b/ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/service/bookcar/BookCarServiceImpl.java @@ -1,11 +1,19 @@ 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 javax.annotation.Resource; + import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; import java.util.*; + import cn.iocoder.yudao.module.parking.controller.admin.bookcar.vo.*; import cn.iocoder.yudao.module.parking.dal.dataobject.bookcar.BookCarDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -28,6 +36,8 @@ public class BookCarServiceImpl implements BookCarService { @Resource private BookCarMapper bookCarMapper; + @Resource + private BlueCarRequestUtil blueCarRequestUtil; @Override public Long createBookCar(BookCarSaveReqVO createReqVO) { @@ -71,4 +81,29 @@ public class BookCarServiceImpl implements BookCarService { return bookCarMapper.selectPage(pageReqVO); } + @Override + public String sendBookingCar(BookCarReqDataVO bookCarReqDataVO) { + CommonResult result = blueCarRequestUtil.doBlueCarPost(bookCarReqDataVO, "out/synBookingCa"); + if (result.getCode() == 0) { + List 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 result = blueCarRequestUtil.doBlueCarPost(bookCarQueryDataVO, "out/queryBookingCar"); + if (result.getCode() == 0){ + Object object = JSON.parse(result.getData()); + // TODO 保存操作,暂时没想好 + return "success"; + } + return "error"; + } + } \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/checkticket/CheckTicketToday.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/checkticket/CheckTicketToday.java index f829ef142..cc21a87b6 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/checkticket/CheckTicketToday.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/checkticket/CheckTicketToday.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.infra.dal.dataobject.checkticket; import lombok.Data; import org.springframework.data.mongodb.core.mapping.Document; -@Document("checkticket") +@Document("check_ticket_today") //@Document("checktickettest") @Data public class CheckTicketToday { diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/checkticket/CheckTicketTodayRepository.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/checkticket/CheckTicketTodayRepository.java index 387af83b2..4b78d339d 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/checkticket/CheckTicketTodayRepository.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/checkticket/CheckTicketTodayRepository.java @@ -1,12 +1,30 @@ 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 org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.data.mongodb.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface CheckTicketTodayRepository extends MongoRepository { - + /** + * 根据dataId数组查找 + * @param dataIdList + * @return java.util.List + */ + @Query(value = "{ 'dataId': { $in: ?0 } }", fields = "{ 'dataId': 1, '_id': 0 }") + List findByDataIdIn(List dataIdList); + /** + * 找到所有不在时间段内的日期字段 + * @param startDate + * @param endDate + * @return java.util.List + */ + @Query("{ 'checkticketdate': { $not: { $gte: ?0, $lt: ?1 } } }") + List findNotInTimeRange(String startDate, String endDate); } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/saledata/SaleDataTodayRepository.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/saledata/SaleDataTodayRepository.java index e9515a7a8..c6620a348 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/saledata/SaleDataTodayRepository.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mongodb/saledata/SaleDataTodayRepository.java @@ -1,6 +1,8 @@ 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.SaleDataToday; import org.springframework.data.mongodb.repository.Aggregation; @@ -61,5 +63,19 @@ public interface SaleDataTodayRepository extends MongoRepository findAllByTransactiontypenoTime(String starTime, String endTime); - + /** + * 更具dataId查找售票记录 + * @param dataIdList + * @return java.util.List + */ + @Query(value = "{ 'dataId': { $in: ?0 } }", fields = "{ 'dataId': 1, '_id': 0 }") + List findByDataIdIn(List dataIdList); + /** + * 找到所有不在时间段内的日期字段 + * @param startDate + * @param endDate + * @return java.util.List + */ + @Query("{ 'sddate': { $not: { $gte: ?0, $lt: ?1 } } }") + List findNotInTimeRange(String startDate, String endDate); } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java index 4dfea2874..a89643322 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/job/ticketing/TicketDataMigration.java @@ -303,6 +303,45 @@ public class TicketDataMigration { 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 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 lastYearCheckTicketList = checkTicketService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(lastYearThirtyDaysAgo.getTime()), TickingDateUtils.format(lastYearToday.getTime())); + XxlJobHelper.log("删除去年检票日期为{}", lastYearCheckTicketList.toString()); + // 售票数据今年多余删除 + List thisYearSaleDataList = saleDataService.deleteNotInTimeZonesByMongoDB(TickingDateUtils.format(thirtyDaysAgo.getTime()), TickingDateUtils.format(today.getTime())); + XxlJobHelper.log("删除今年售票日期为{}", thisYearSaleDataList.toString()); + // 售票数据去年多余删除 + List 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) @@ -358,9 +397,9 @@ public class TicketDataMigration { mapList = ticketingSamplingRespVO.getDataMapList(); List resultNum = null; 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)) { - resultNum = saleDataService.insertByMongoDB(BeanUtils.toBean(mapList, SaleData.class)); + resultNum = saleDataService.insertTodayByMongoDB(BeanUtils.toBean(mapList, SaleDataToday.class)); } if (resultNum == null) { result.add("数据批量插入异常!"); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketService.java index 31d33386d..306523d88 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketService.java @@ -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 javax.validation.Valid; +import java.util.Calendar; import java.util.List; import java.util.Map; @@ -39,4 +40,11 @@ public interface CheckTicketService { */ List insertByMongoDB(List checkTicketList); List insertTodayByMongoDB(List checkTicketList); + /** + * 删除不在指定日期内的数据(mongodb) + * @param startDate 如:"20240729" + * @param endDate 如:"20240829" + * @return java.util.List 删除的日期 + */ + List deleteNotInTimeZonesByMongoDB(String startDate,String endDate); } \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketServiceImpl.java index 25717b942..7576a91af 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/checkticket/CheckTicketServiceImpl.java @@ -71,7 +71,7 @@ public class CheckTicketServiceImpl implements CheckTicketService { try { // 批量插入 checkTicketRepository.insert(insertCheckTicketList); - } catch (MongoException e){ + } catch (MongoException e) { return null; } resultNum.add(insertCheckTicketList.size()); @@ -85,13 +85,16 @@ public class CheckTicketServiceImpl implements CheckTicketService { // 把检票数据的dataId提取出来成数组 List dataIdList = checkTicketList.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList()); // 获取重复的dataId - List duplicatesDataId = this.checkDuplicatesByMongoDB(dataIdList); + // 查询数据库中存在的 dataId + List existingTickets = checkTicketTodayRepository.findByDataIdIn(dataIdList); + // 把CheckTicket对象列表改为dataId字符串列表 + List duplicatesDataId = existingTickets.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList()); // 对checkTicketList过滤掉重复的dataId对应的数据,得到需要插入的不重复数据 List insertCheckTicketList = checkTicketList.stream().filter(ticket -> !duplicatesDataId.contains(ticket.getDataId())).collect(Collectors.toList()); try { // 批量插入 checkTicketTodayRepository.insert(insertCheckTicketList); - } catch (MongoException e){ + } catch (MongoException e) { return null; } resultNum.add(insertCheckTicketList.size()); @@ -99,4 +102,18 @@ public class CheckTicketServiceImpl implements CheckTicketService { return resultNum; } + @Override + public List deleteNotInTimeZonesByMongoDB(String startDate, String endDate) { + + // 执行查询并获取要删除的数据 + List entitiesToDelete = checkTicketTodayRepository.findNotInTimeRange(startDate, endDate); + // 执行删除操作 + checkTicketTodayRepository.deleteAll(entitiesToDelete); + // 获取要删除的日期列表 + List deletedDates = entitiesToDelete.stream() + .map(CheckTicketToday::getCheckticketdate) + .collect(Collectors.toList()); + return deletedDates; + } + } \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataService.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataService.java index 9890d22a0..49c014ba1 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataService.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataService.java @@ -42,4 +42,11 @@ public interface SaleDataService { */ List insertByMongoDB(List saleDataList); List insertTodayByMongoDB(List saleDataList); + /** + * 删除不在指定日期内的数据(mongodb) + * @param startDate 如:"20240729" + * @param endDate 如:"20240829" + * @return java.util.List 删除的日期 + */ + List deleteNotInTimeZonesByMongoDB(String startDate,String endDate); } \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataServiceImpl.java index 6e0c0dfaf..7eadfa01c 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/saledata/SaleDataServiceImpl.java @@ -1,6 +1,7 @@ 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.CheckTicketToday; 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.SaleDataToday; @@ -62,7 +63,7 @@ public class SaleDataServiceImpl implements SaleDataService { try { // 批量插入 saleDataRepository.insert(insertSaleDataList); - } catch (MongoException e){ + } catch (MongoException e) { return null; } resultNum.add(insertSaleDataList.size()); @@ -76,19 +77,34 @@ public class SaleDataServiceImpl implements SaleDataService { // 把检票数据的dataId提取出来成数组 List dataIdList = saleDataList.stream().map(SaleDataToday::getDataId).collect(Collectors.toList()); // 获取重复的dataId - List duplicatesDataId = this.checkDuplicatesByMongoDB(dataIdList); + // 查询数据库中存在的 dataId + List existingTickets = saleDataTodayRepository.findByDataIdIn(dataIdList); + // 把CheckTicket对象列表改为dataId字符串列表 + List duplicatesDataId = existingTickets.stream().map(SaleDataToday::getDataId).collect(Collectors.toList()); // 对checkTicketList过滤掉重复的dataId对应的数据,得到需要插入的不重复数据 List insertSaleDataList = saleDataList.stream().filter(saleData -> !duplicatesDataId.contains(saleData.getDataId())).collect(Collectors.toList()); try { // 批量插入 saleDataTodayRepository.insert(insertSaleDataList); - } catch (MongoException e){ + } catch (MongoException e) { return null; } resultNum.add(insertSaleDataList.size()); resultNum.add(duplicatesDataId.size()); return resultNum; } + @Override + public List deleteNotInTimeZonesByMongoDB(String startDate, String endDate) { + // 执行查询并获取要删除的数据 + List entitiesToDelete = saleDataTodayRepository.findNotInTimeRange(startDate, endDate); + // 执行删除操作 + saleDataTodayRepository.deleteAll(entitiesToDelete); + // 获取要删除的日期列表 + List deletedDates = entitiesToDelete.stream() + .map(SaleDataToday::getSddate) + .collect(Collectors.toList()); + return deletedDates; + } } \ No newline at end of file