Compare commits
16 Commits
fe20745099
...
ab9fee09bf
Author | SHA1 | Date | |
---|---|---|---|
ab9fee09bf | |||
3d7b4a00a2 | |||
2dba47b01b | |||
b209a002fb | |||
1dc70860a6 | |||
3be191f8e9 | |||
a28f47cebe | |||
e795b348e8 | |||
3abac95293 | |||
7dd0b85d36 | |||
6606826273 | |||
51138d8a45 | |||
501997db97 | |||
e24bc2c5ee | |||
f2b8f017e2 | |||
4c3c582ebd |
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.datacenter.controller.app.saledata;
|
||||
|
||||
import cn.iocoder.yudao.module.datacenter.service.saledata.SaleDataService;
|
||||
import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -26,6 +27,8 @@ import java.util.regex.Pattern;
|
||||
public class SaleDataApi {
|
||||
@Resource
|
||||
private SaleDataService saleDataService;
|
||||
// @Resource
|
||||
// private WebSocketSenderApi webSocketSenderApi;
|
||||
|
||||
@GetMapping()
|
||||
@Operation(summary = "获得输入日期的当天总售票数")
|
||||
@ -138,4 +141,10 @@ public class SaleDataApi {
|
||||
return saleDataService.findyearJun(saleDataService.findEventsLastYear());
|
||||
}
|
||||
|
||||
// @GetMapping("/test")
|
||||
// public void testMethod(){
|
||||
//
|
||||
// webSocketSenderApi.sendObject("1","1","666");
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -5,5 +5,5 @@ import lombok.Data;
|
||||
@Data
|
||||
public class SaleDataItemTypeVo {
|
||||
// private String itemtype;
|
||||
private String itemtypename;
|
||||
private String itemname;
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.datacenter.dal.dataobject.checkticket;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document("check_ticket_today")
|
||||
//@Document("checktickettest")
|
||||
@Data
|
||||
public class CheckTicketToday {
|
||||
private String id;
|
||||
private String dataId;
|
||||
private String checkstation;
|
||||
private String checkstationname;
|
||||
private String ticket;
|
||||
private String checkticketdate;
|
||||
private String checktickettime;
|
||||
private Integer personcount;
|
||||
private String sdshipping;
|
||||
private String salepropetyvaluename;
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package cn.iocoder.yudao.module.datacenter.dal.dataobject.saledata;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Document("sale_data_today")
|
||||
@Data
|
||||
public class SaleDataToday {
|
||||
private String id;
|
||||
private String dataId;
|
||||
private String sdno;
|
||||
private String transactiontypeno;
|
||||
private String sddate;
|
||||
private String sdtime;
|
||||
private BigDecimal amount;
|
||||
private Integer quantity;
|
||||
private String certificatetype;
|
||||
private String certificateno;
|
||||
private String itemtype;
|
||||
private String itemtypename;
|
||||
private String item;
|
||||
private String itemname;
|
||||
private String productbatchno;
|
||||
private String salepropetyvaluename;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.datacenter.dal.mongodb.checkticket;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.datacenter.dal.dataobject.checkticket.CheckTicket;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
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<CheckTicket,String> {
|
||||
@Query("{'name': {'$regex': '?0', '$options': 'i'}}")
|
||||
Page<CheckTicket> findByName(String q, PageRequest pageable);
|
||||
|
||||
@Query("{'checkticketdate':{'$gte': ?0, '$lt': ?1}}")
|
||||
List<CheckTicket> countByCheckticketdateBetween(String starTime, String endTime);
|
||||
|
||||
@Query("{'checktickettime':{'$gte': ?0, '$lt': ?1},'checkticketdate':{'$dt': ?2}}")
|
||||
List<CheckTicket> findByTimestampBetweenAndCheckticketdate(String startTime, String endTime,String day);
|
||||
|
||||
List<CheckTicket> findByCheckticketdateAndChecktickettimeBetween(String day,String startTime, String endTime);
|
||||
|
||||
@Query("{'checkticketdate':{'$gte': ?0, '$lt': ?1} , 'checktickettime':{'$gte': ?2, '$lt': ?3}}")
|
||||
List<CheckTicket> findByCheckticketdateBetweenAndChecktickettimeBetween(String startTime, String endTime,String beingTime, String resultTime);
|
||||
}
|
@ -58,7 +58,7 @@ public interface SaleDataRepository extends MongoRepository<SaleData,String> {
|
||||
@Query(value = "{}", fields = "{ 'itemtypename': 1 }")
|
||||
List<SaleDataItemTypeVo> findAllByItemtypename();
|
||||
|
||||
@Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'itemtypename': 1 }")
|
||||
@Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'itemname': 1 }")
|
||||
List<SaleDataItemTypeVo> findAllByItemtypenameTime(String starTime, String endTime);
|
||||
|
||||
@Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }")
|
||||
|
@ -0,0 +1,68 @@
|
||||
package cn.iocoder.yudao.module.datacenter.dal.mongodb.saledata;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.AgeVo;
|
||||
import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.AggregationVO;
|
||||
import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.SaleDataItemTypeVo;
|
||||
import cn.iocoder.yudao.module.datacenter.dal.dataobject.saledata.SaleData;
|
||||
import cn.iocoder.yudao.module.datacenter.dal.dataobject.saledata.SaleDataToday;
|
||||
import org.springframework.data.mongodb.repository.Aggregation;
|
||||
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 SaleDataTodayRepository extends MongoRepository<SaleDataToday,String> {
|
||||
/*@Query("{'name': {'$regex': '?0', '$options': 'i'}}")
|
||||
Page<SaleData> findByName(String q, PageRequest pageable);*/
|
||||
int countBySddate(String day);
|
||||
|
||||
@Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'sddate': 1 }")
|
||||
List<String> countBySddateToTime(String starTime, String endTime);
|
||||
|
||||
|
||||
// @Query("{ 'sddate' : { $gte: ?0, $lte: ?1 } }")
|
||||
@Query(value = "{ 'sddate': { $gte: ?0, $lte: ?1 } }", fields = "{ 'certificateno': 1, 'amount': 1}")
|
||||
List<SaleData>findBySddateBetween(String begin,String end);
|
||||
|
||||
@Aggregation(pipeline = {
|
||||
"{$project: {certLength: {$strLenCP: '$certificateno'}, secondLastChar: {$substrCP: ['$certificateno', {$subtract: [{$strLenCP: '$certificateno'}, 2]}, 1]}}}",
|
||||
"{$group: {_id: null, maleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 1]}, then: 1, else: 0}}}, femaleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 0]}, then: 1, else: 0}}}, totalCount: {$sum: 1}}}",
|
||||
"{$project: {_id: 0, maleCount: 1, femaleCount: 1, maleRatio: {$divide: ['$maleCount', '$totalCount']}}}"
|
||||
})
|
||||
AggregationVO findAllByCertificateno();
|
||||
|
||||
@Aggregation(pipeline = {
|
||||
"{$match: {sddate: { $gte: ?0, $lte: ?1 }}}",
|
||||
"{$project: {certLength: {$strLenCP: '$certificateno'}, secondLastChar: {$substrCP: ['$certificateno', {$subtract: [{$strLenCP: '$certificateno'}, 2]}, 1]}}}",
|
||||
"{$group: {_id: null, maleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 1]}, then: 1, else: 0}}}, femaleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 0]}, then: 1, else: 0}}}, totalCount: {$sum: 1}}}",
|
||||
"{$project: {_id: 0, maleCount: 1, femaleCount: 1, maleRatio: {$divide: ['$maleCount', '$totalCount']}}}"
|
||||
})
|
||||
AggregationVO findAllByCertificatenoSDTime(String starTime, String endTime);
|
||||
|
||||
@Aggregation(pipeline = {
|
||||
"{$match: {sddate: { $gte: ?0, $lte: ?1 }}}",
|
||||
"{$match: {certificateno: {$regex: '^.{18}$'}}}",
|
||||
"{$project: {birthYear: {$toInt: {$substr: ['$certificateno', 6, 4]}}, currentYear: {$year: '$$NOW'}}}",
|
||||
"{$addFields: {age: {$subtract: ['$currentYear', '$birthYear']}}}",
|
||||
"{$group: {_id: null, one: {$sum: {$cond: [{$lte: ['$age', 20]}, 1, 0]}}, " +
|
||||
"two: {$sum: {$cond: [{$and: [{$gt: ['$age', 20]}, {$lte: ['$age', 30]}]}, 1, 0]}}, " +
|
||||
"three: {$sum: {$cond: [{$and: [{$gt: ['$age', 30]}, {$lte: ['$age', 40]}]}, 1, 0]}}, " +
|
||||
"four: {$sum: {$cond: [{$and: [{$gt: ['$age', 40]}, {$lte: ['$age', 50]}]}, 1, 0]}}, " +
|
||||
"five: {$sum: {$cond: [{$and: [{$gt: ['$age', 50]}, {$lte: ['$age', 60]}]}, 1, 0]}}, " +
|
||||
"six: {$sum: {$cond: [{$gt: ['$age', 60]}, 1, 0]}}}}"
|
||||
})
|
||||
AgeVo findByAge(String starTime, String endTime);
|
||||
|
||||
@Query(value = "{}", fields = "{ 'itemtypename': 1 }")
|
||||
List<SaleDataItemTypeVo> findAllByItemtypename();
|
||||
|
||||
@Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'itemname': 1 }")
|
||||
List<SaleDataItemTypeVo> findAllByItemtypenameTime(String starTime, String endTime);
|
||||
|
||||
@Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }")
|
||||
List<SaleData> findAllByTransactiontypenoTime(String starTime, String endTime);
|
||||
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
package cn.iocoder.yudao.module.datacenter.service.checkticket;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
|
||||
import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.AggregationVO;
|
||||
import cn.iocoder.yudao.module.datacenter.dal.dataobject.checkticket.CheckTicket;
|
||||
import cn.iocoder.yudao.module.datacenter.dal.mongodb.checkticket.CheckTicketRepository;
|
||||
import cn.iocoder.yudao.module.datacenter.dal.mongodb.checkticket.CheckTicketTodayRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@ -17,7 +15,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* 检票 Service 实现类
|
||||
@ -29,7 +26,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
|
||||
public class CheckTicketServiceImpl implements CheckTicketService {
|
||||
|
||||
@Resource
|
||||
private CheckTicketRepository checkTicketRepository;
|
||||
private CheckTicketTodayRepository checkTicketRepository;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -8,7 +8,7 @@ import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.AgeVo;
|
||||
import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.AggregationVO;
|
||||
import cn.iocoder.yudao.module.datacenter.controller.app.saledata.vo.SaleDataItemTypeVo;
|
||||
import cn.iocoder.yudao.module.datacenter.dal.dataobject.saledata.SaleData;
|
||||
import cn.iocoder.yudao.module.datacenter.dal.mongodb.saledata.SaleDataRepository;
|
||||
import cn.iocoder.yudao.module.datacenter.dal.mongodb.saledata.SaleDataTodayRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -16,8 +16,6 @@ import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -32,7 +30,7 @@ import java.util.stream.Collectors;
|
||||
public class SaleDataServiceImpl implements SaleDataService {
|
||||
|
||||
@Autowired
|
||||
private SaleDataRepository saleDataRepository;
|
||||
private SaleDataTodayRepository saleDataRepository;
|
||||
|
||||
public String publicMethod(String endTime){
|
||||
// 创建 DateTimeFormatter 实例以解析指定日期的格式
|
||||
@ -256,7 +254,7 @@ public class SaleDataServiceImpl implements SaleDataService {
|
||||
public List<Map<String, String>> findByDoItemType(String starTime, String endTime) {
|
||||
List<SaleDataItemTypeVo> list = saleDataRepository.findAllByItemtypenameTime(starTime, this.publicMethod(endTime));
|
||||
Map<String, Long> countMap = list.stream()
|
||||
.collect(Collectors.groupingBy(SaleDataItemTypeVo::getItemtypename, Collectors.counting()));
|
||||
.collect(Collectors.groupingBy(SaleDataItemTypeVo::getItemname, Collectors.counting()));
|
||||
List<Map<String, String>> mapArrayList = new ArrayList<>();
|
||||
for (String s : countMap.keySet()) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
@ -38,6 +38,20 @@ public class BookCarController {
|
||||
@Resource
|
||||
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")
|
||||
@Operation(summary = "创建预约车")
|
||||
@PreAuthorize("@ss.hasPermission('parking:book-car:create')")
|
||||
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -52,4 +52,17 @@ public interface BookCarService {
|
||||
*/
|
||||
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);
|
||||
}
|
@ -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<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";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.dataobject.checkticket;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document("check_ticket_today")
|
||||
//@Document("checktickettest")
|
||||
@Data
|
||||
public class CheckTicketToday {
|
||||
private String id;
|
||||
private String dataId;
|
||||
private String checkstation;
|
||||
private String checkstationname;
|
||||
private String ticket;
|
||||
private String checkticketdate;
|
||||
private String checktickettime;
|
||||
private Integer personcount;
|
||||
private String sdshipping;
|
||||
private String salepropetyvaluename;
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package cn.iocoder.yudao.module.infra.dal.dataobject.saledata;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Document("sale_data_today")
|
||||
@Data
|
||||
public class SaleDataToday {
|
||||
private String id;
|
||||
private String dataId;
|
||||
private String sdno;
|
||||
private String transactiontypeno;
|
||||
private String sddate;
|
||||
private String sdtime;
|
||||
private BigDecimal amount;
|
||||
private Integer quantity;
|
||||
private String certificatetype;
|
||||
private String certificateno;
|
||||
private String itemtype;
|
||||
private String itemtypename;
|
||||
private String item;
|
||||
private String itemname;
|
||||
private String productbatchno;
|
||||
private String salepropetyvaluename;
|
||||
}
|
@ -0,0 +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<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);
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
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;
|
||||
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 SaleDataTodayRepository extends MongoRepository<SaleDataToday,String> {
|
||||
// /*@Query("{'name': {'$regex': '?0', '$options': 'i'}}")
|
||||
// Page<SaleData> findByName(String q, PageRequest pageable);*/
|
||||
// int countBySddate(String day);
|
||||
//
|
||||
// @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'sddate': 1 }")
|
||||
// List<String> countBySddateToTime(String starTime, String endTime);
|
||||
//
|
||||
//
|
||||
//// @Query("{ 'sddate' : { $gte: ?0, $lte: ?1 } }")
|
||||
// @Query(value = "{ 'sddate': { $gte: ?0, $lte: ?1 } }", fields = "{ 'certificateno': 1, 'amount': 1}")
|
||||
// List<SaleData>findBySddateBetween(String begin, String end);
|
||||
//
|
||||
// @Aggregation(pipeline = {
|
||||
// "{$project: {certLength: {$strLenCP: '$certificateno'}, secondLastChar: {$substrCP: ['$certificateno', {$subtract: [{$strLenCP: '$certificateno'}, 2]}, 1]}}}",
|
||||
// "{$group: {_id: null, maleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 1]}, then: 1, else: 0}}}, femaleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 0]}, then: 1, else: 0}}}, totalCount: {$sum: 1}}}",
|
||||
// "{$project: {_id: 0, maleCount: 1, femaleCount: 1, maleRatio: {$divide: ['$maleCount', '$totalCount']}}}"
|
||||
// })
|
||||
// AggregationVO findAllByCertificateno();
|
||||
//
|
||||
// @Aggregation(pipeline = {
|
||||
// "{$match: {sddate: { $gte: ?0, $lte: ?1 }}}",
|
||||
// "{$project: {certLength: {$strLenCP: '$certificateno'}, secondLastChar: {$substrCP: ['$certificateno', {$subtract: [{$strLenCP: '$certificateno'}, 2]}, 1]}}}",
|
||||
// "{$group: {_id: null, maleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 1]}, then: 1, else: 0}}}, femaleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 0]}, then: 1, else: 0}}}, totalCount: {$sum: 1}}}",
|
||||
// "{$project: {_id: 0, maleCount: 1, femaleCount: 1, maleRatio: {$divide: ['$maleCount', '$totalCount']}}}"
|
||||
// })
|
||||
// AggregationVO findAllByCertificatenoSDTime(String starTime, String endTime);
|
||||
//
|
||||
// @Aggregation(pipeline = {
|
||||
// "{$match: {sddate: { $gte: ?0, $lte: ?1 }}}",
|
||||
// "{$match: {certificateno: {$regex: '^.{18}$'}}}",
|
||||
// "{$project: {birthYear: {$toInt: {$substr: ['$certificateno', 6, 4]}}, currentYear: {$year: '$$NOW'}}}",
|
||||
// "{$addFields: {age: {$subtract: ['$currentYear', '$birthYear']}}}",
|
||||
// "{$group: {_id: null, one: {$sum: {$cond: [{$lte: ['$age', 20]}, 1, 0]}}, " +
|
||||
// "two: {$sum: {$cond: [{$and: [{$gt: ['$age', 20]}, {$lte: ['$age', 30]}]}, 1, 0]}}, " +
|
||||
// "three: {$sum: {$cond: [{$and: [{$gt: ['$age', 30]}, {$lte: ['$age', 40]}]}, 1, 0]}}, " +
|
||||
// "four: {$sum: {$cond: [{$and: [{$gt: ['$age', 40]}, {$lte: ['$age', 50]}]}, 1, 0]}}, " +
|
||||
// "five: {$sum: {$cond: [{$and: [{$gt: ['$age', 50]}, {$lte: ['$age', 60]}]}, 1, 0]}}, " +
|
||||
// "six: {$sum: {$cond: [{$gt: ['$age', 60]}, 1, 0]}}}}"
|
||||
// })
|
||||
// AgeVo findByAge(String starTime, String endTime);
|
||||
//
|
||||
// @Query(value = "{}", fields = "{ 'itemtypename': 1 }")
|
||||
// List<SaleDataItemTypeVo> findAllByItemtypename();
|
||||
//
|
||||
// @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'itemname': 1 }")
|
||||
// List<SaleDataItemTypeVo> findAllByItemtypenameTime(String starTime, String endTime);
|
||||
//
|
||||
// @Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }")
|
||||
// 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);
|
||||
}
|
@ -7,8 +7,10 @@ import cn.iocoder.yudao.framework.common.util.date.TickingDateUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket;
|
||||
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.saledata.SaleData;
|
||||
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.mongodb.checkticket.CheckTicketRepository;
|
||||
import cn.iocoder.yudao.module.infra.dal.mongodb.saledata.SaleDataRepository;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.checkticket.CheckTicketMapper;
|
||||
@ -148,7 +150,7 @@ public class TicketDataMigration {
|
||||
for (; pageNumber <= totalPages; pageNumber++) {
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(SALE_DATA_SERVICE, SALE_DATA_METHOD, TickingDateUtils.getNowDayFormat(), pageNumber);
|
||||
mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
List<Integer> resultNum = saleDataService.insertByMongoDB(BeanUtils.toBean(mapList, SaleData.class));
|
||||
List<Integer> resultNum = saleDataService.insertTodayByMongoDB(BeanUtils.toBean(mapList, SaleDataToday.class));
|
||||
if (resultNum == null) {
|
||||
XxlJobHelper.log("数据批量插入异常!", pageNumber);
|
||||
} else {
|
||||
@ -179,7 +181,7 @@ public class TicketDataMigration {
|
||||
for (; pageNumber <= totalPages; pageNumber++) {
|
||||
ticketingSamplingRespVO = this.getUrlResponseData(CHECK_TICKET_SERVICE, CHECK_TICKET_METHOD, date, pageNumber);
|
||||
mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
List<Integer> resultNum = checkTicketService.insertByMongoDB(BeanUtils.toBean(mapList, CheckTicket.class));
|
||||
List<Integer> resultNum = checkTicketService.insertTodayByMongoDB(BeanUtils.toBean(mapList, CheckTicketToday.class));
|
||||
if (resultNum == null) {
|
||||
XxlJobHelper.log("数据批量插入异常!", pageNumber);
|
||||
} else {
|
||||
@ -301,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<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)
|
||||
@ -356,9 +397,9 @@ public class TicketDataMigration {
|
||||
mapList = ticketingSamplingRespVO.getDataMapList();
|
||||
List<Integer> 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("数据批量插入异常!");
|
||||
|
@ -4,8 +4,10 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.infra.controller.checkticket.vo.CheckTicketSaveReqVO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket;
|
||||
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;
|
||||
|
||||
@ -37,4 +39,12 @@ public interface CheckTicketService {
|
||||
* @return java.util.List<java.lang.Integer> 插入数据和重复数据
|
||||
*/
|
||||
List<Integer> insertByMongoDB(List<CheckTicket> 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);
|
||||
}
|
@ -5,7 +5,9 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.checkticket.CheckTicket;
|
||||
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.mongodb.checkticket.CheckTicketRepository;
|
||||
import cn.iocoder.yudao.module.infra.dal.mongodb.checkticket.CheckTicketTodayRepository;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.checkticket.CheckTicketMapper;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.dynamic.datasource.annotation.Slave;
|
||||
@ -38,6 +40,8 @@ public class CheckTicketServiceImpl implements CheckTicketService {
|
||||
private CheckTicketMapper checkTicketMapper;
|
||||
@Resource
|
||||
private CheckTicketRepository checkTicketRepository;
|
||||
@Resource
|
||||
private CheckTicketTodayRepository checkTicketTodayRepository;
|
||||
|
||||
@Override
|
||||
public Long createCheckTicket(CheckTicketDO checkTicketDO) {
|
||||
@ -67,7 +71,7 @@ public class CheckTicketServiceImpl implements CheckTicketService {
|
||||
try {
|
||||
// 批量插入
|
||||
checkTicketRepository.insert(insertCheckTicketList);
|
||||
} catch (MongoException e){
|
||||
} catch (MongoException e) {
|
||||
return null;
|
||||
}
|
||||
resultNum.add(insertCheckTicketList.size());
|
||||
@ -75,4 +79,41 @@ public class CheckTicketServiceImpl implements CheckTicketService {
|
||||
return resultNum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> insertTodayByMongoDB(List<CheckTicketToday> checkTicketList) {
|
||||
List<Integer> resultNum = new ArrayList<>(2);
|
||||
// 把检票数据的dataId提取出来成数组
|
||||
List<String> dataIdList = checkTicketList.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList());
|
||||
// 获取重复的dataId
|
||||
// 查询数据库中存在的 dataId
|
||||
List<CheckTicketToday> existingTickets = checkTicketTodayRepository.findByDataIdIn(dataIdList);
|
||||
// 把CheckTicket对象列表改为dataId字符串列表
|
||||
List<String> duplicatesDataId = existingTickets.stream().map(CheckTicketToday::getDataId).collect(Collectors.toList());
|
||||
// 对checkTicketList过滤掉重复的dataId对应的数据,得到需要插入的不重复数据
|
||||
List<CheckTicketToday> insertCheckTicketList = checkTicketList.stream().filter(ticket -> !duplicatesDataId.contains(ticket.getDataId())).collect(Collectors.toList());
|
||||
try {
|
||||
// 批量插入
|
||||
checkTicketTodayRepository.insert(insertCheckTicketList);
|
||||
} catch (MongoException e) {
|
||||
return null;
|
||||
}
|
||||
resultNum.add(insertCheckTicketList.size());
|
||||
resultNum.add(duplicatesDataId.size());
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.infra.controller.saledata.vo.SaleDataSaveReqVO;
|
||||
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.SaleDataDO;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.saledata.SaleDataToday;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.math.BigDecimal;
|
||||
@ -40,4 +41,12 @@ public interface SaleDataService {
|
||||
* @return java.util.List<java.lang.Integer>
|
||||
*/
|
||||
List<Integer> insertByMongoDB(List<SaleData> 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);
|
||||
}
|
@ -1,35 +1,21 @@
|
||||
package cn.iocoder.yudao.module.infra.service.saledata;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.ticket.IdCardUtil;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.infra.controller.saledata.vo.SaleDataSaveReqVO;
|
||||
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;
|
||||
import cn.iocoder.yudao.module.infra.dal.mongodb.saledata.SaleDataRepository;
|
||||
import cn.iocoder.yudao.module.infra.dal.mongodb.saledata.SaleDataTodayRepository;
|
||||
import cn.iocoder.yudao.module.infra.dal.mysql.saledata.SaleDataMapper;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.dynamic.datasource.annotation.Slave;
|
||||
import com.mongodb.DuplicateKeyException;
|
||||
import com.mongodb.MongoException;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.ExampleMatcher;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.exact;
|
||||
|
||||
|
||||
/**
|
||||
* 售票 Service 实现类
|
||||
@ -41,6 +27,10 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc
|
||||
public class SaleDataServiceImpl implements SaleDataService {
|
||||
@Resource
|
||||
private SaleDataRepository saleDataRepository;
|
||||
|
||||
@Resource
|
||||
private SaleDataTodayRepository saleDataTodayRepository;
|
||||
|
||||
@Resource
|
||||
private SaleDataMapper saleDataMapper;
|
||||
|
||||
@ -73,7 +63,7 @@ public class SaleDataServiceImpl implements SaleDataService {
|
||||
try {
|
||||
// 批量插入
|
||||
saleDataRepository.insert(insertSaleDataList);
|
||||
} catch (MongoException e){
|
||||
} catch (MongoException e) {
|
||||
return null;
|
||||
}
|
||||
resultNum.add(insertSaleDataList.size());
|
||||
@ -81,5 +71,40 @@ public class SaleDataServiceImpl implements SaleDataService {
|
||||
return resultNum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> insertTodayByMongoDB(List<SaleDataToday> saleDataList) {
|
||||
List<Integer> resultNum = new ArrayList<>(2);
|
||||
// 把检票数据的dataId提取出来成数组
|
||||
List<String> dataIdList = saleDataList.stream().map(SaleDataToday::getDataId).collect(Collectors.toList());
|
||||
// 获取重复的dataId
|
||||
// 查询数据库中存在的 dataId
|
||||
List<SaleDataToday> existingTickets = saleDataTodayRepository.findByDataIdIn(dataIdList);
|
||||
// 把CheckTicket对象列表改为dataId字符串列表
|
||||
List<String> duplicatesDataId = existingTickets.stream().map(SaleDataToday::getDataId).collect(Collectors.toList());
|
||||
// 对checkTicketList过滤掉重复的dataId对应的数据,得到需要插入的不重复数据
|
||||
List<SaleDataToday> insertSaleDataList = saleDataList.stream().filter(saleData -> !duplicatesDataId.contains(saleData.getDataId())).collect(Collectors.toList());
|
||||
try {
|
||||
// 批量插入
|
||||
saleDataTodayRepository.insert(insertSaleDataList);
|
||||
} catch (MongoException e) {
|
||||
return null;
|
||||
}
|
||||
resultNum.add(insertSaleDataList.size());
|
||||
resultNum.add(duplicatesDataId.size());
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user