From b209a002fb8d1c136cadd0a57145725b70c6b710 Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Thu, 29 Aug 2024 09:05:41 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E9=A2=84=E7=BA=A6=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/bookcar/BookCarController.java | 14 ++++++++ .../admin/bookcar/vo/BookCarQueryDataVO.java | 13 +++++++ .../admin/bookcar/vo/BookCarQueryVO.java | 17 +++++++++ .../admin/bookcar/vo/BookCarReqDataVO.java | 15 ++++++++ .../service/bookcar/BookCarService.java | 13 +++++++ .../service/bookcar/BookCarServiceImpl.java | 35 +++++++++++++++++++ 6 files changed, 107 insertions(+) create mode 100644 ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarQueryDataVO.java create mode 100644 ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarQueryVO.java create mode 100644 ludu-module-parking/ludu-module-parking-biz/src/main/java/cn/iocoder/yudao/module/parking/controller/admin/bookcar/vo/BookCarReqDataVO.java 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 From 2dba47b01b58d2ab691c7a6e4d0c65f9bb837c8f Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Thu, 29 Aug 2024 09:07:54 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=B0=E7=A5=A8=E5=8A=A1=E9=9B=86?= =?UTF-8?q?=E5=90=88=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dal/dataobject/checkticket/CheckTicketToday.java | 2 +- .../checkticket/CheckTicketTodayRepository.java | 12 +++++++++++- .../mongodb/saledata/SaleDataTodayRepository.java | 9 ++++++++- .../service/checkticket/CheckTicketServiceImpl.java | 5 ++++- .../infra/service/saledata/SaleDataServiceImpl.java | 9 ++++++--- 5 files changed, 30 insertions(+), 7 deletions(-) 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..62b8d6d70 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,22 @@ 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); } 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..a46d82954 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,7 @@ 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.saledata.SaleData; import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday; import org.springframework.data.mongodb.repository.Aggregation; @@ -61,5 +62,11 @@ 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); } 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..bea649292 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 @@ -85,7 +85,10 @@ 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(CheckTicket::getDataId).collect(Collectors.toList()); // 对checkTicketList过滤掉重复的dataId对应的数据,得到需要插入的不重复数据 List insertCheckTicketList = checkTicketList.stream().filter(ticket -> !duplicatesDataId.contains(ticket.getDataId())).collect(Collectors.toList()); try { 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..45e81208b 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 @@ -62,7 +62,7 @@ public class SaleDataServiceImpl implements SaleDataService { try { // 批量插入 saleDataRepository.insert(insertSaleDataList); - } catch (MongoException e){ + } catch (MongoException e) { return null; } resultNum.add(insertSaleDataList.size()); @@ -76,13 +76,16 @@ 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 = saleDataRepository.findByDataIdIn(dataIdList); + // 把CheckTicket对象列表改为dataId字符串列表 + List duplicatesDataId = existingTickets.stream().map(CheckTicket::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()); From 3d7b4a00a27a6880037a5c1cbf4bef6177b839d7 Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Thu, 29 Aug 2024 10:59:30 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=96=B0=E7=A5=A8=E5=8A=A1=E9=9B=86?= =?UTF-8?q?=E5=90=88=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CheckTicketTodayRepository.java | 10 ++++++++- .../saledata/SaleDataTodayRepository.java | 11 +++++++++- .../checkticket/CheckTicketService.java | 8 +++++++ .../checkticket/CheckTicketServiceImpl.java | 22 +++++++++++++++---- .../service/saledata/SaleDataService.java | 7 ++++++ .../service/saledata/SaleDataServiceImpl.java | 17 ++++++++++++-- 6 files changed, 67 insertions(+), 8 deletions(-) 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 62b8d6d70..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 @@ -18,5 +18,13 @@ public interface CheckTicketTodayRepository extends MongoRepository */ @Query(value = "{ 'dataId': { $in: ?0 } }", fields = "{ 'dataId': 1, '_id': 0 }") - List findByDataIdIn(List dataIdList); + 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 a46d82954..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 @@ -2,6 +2,7 @@ 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; @@ -68,5 +69,13 @@ public interface SaleDataTodayRepository extends MongoRepository */ @Query(value = "{ 'dataId': { $in: ?0 } }", fields = "{ 'dataId': 1, '_id': 0 }") - List findByDataIdIn(List dataIdList); + 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/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 bea649292..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()); @@ -86,15 +86,15 @@ public class CheckTicketServiceImpl implements CheckTicketService { List dataIdList = checkTicketList.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList()); // 获取重复的dataId // 查询数据库中存在的 dataId - List existingTickets = checkTicketTodayRepository.findByDataIdIn(dataIdList); + List existingTickets = checkTicketTodayRepository.findByDataIdIn(dataIdList); // 把CheckTicket对象列表改为dataId字符串列表 - List duplicatesDataId = existingTickets.stream().map(CheckTicket::getDataId).collect(Collectors.toList()); + 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()); @@ -102,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 45e81208b..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; @@ -77,9 +78,9 @@ public class SaleDataServiceImpl implements SaleDataService { List dataIdList = saleDataList.stream().map(SaleDataToday::getDataId).collect(Collectors.toList()); // 获取重复的dataId // 查询数据库中存在的 dataId - List existingTickets = saleDataRepository.findByDataIdIn(dataIdList); + List existingTickets = saleDataTodayRepository.findByDataIdIn(dataIdList); // 把CheckTicket对象列表改为dataId字符串列表 - List duplicatesDataId = existingTickets.stream().map(CheckTicket::getDataId).collect(Collectors.toList()); + 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 { @@ -92,6 +93,18 @@ public class SaleDataServiceImpl implements SaleDataService { 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 From ab9fee09bfe37b145ed80f733fcca8fdb648b60c Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Thu, 29 Aug 2024 10:59:56 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=8A=BD=E6=95=B0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=A4=9A=E4=BD=99=E6=95=B0=E6=8D=AE=E5=92=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8E=BB=E5=B9=B4=E6=98=8E=E5=A4=A9=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../job/ticketing/TicketDataMigration.java | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) 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("数据批量插入异常!"); From 8fbb8cff99f4abab08a5d1093694f4cecc852ab3 Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Thu, 29 Aug 2024 11:08:30 +0800 Subject: [PATCH 5/5] =?UTF-8?q?datacenter=E6=9E=84=E5=BB=BA=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E6=8E=89120=E9=82=A3=E5=8F=B0=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone-datacenter.yml | 138 +++++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 69 deletions(-) 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: # 定义流水线挂载目录,用于共享数据