Browse Source

修改 sql 查询 当天及 当月的数据

heyueyang
hyy 11 months ago
parent
commit
fea110b8e1

+ 5
- 4
src/main/java/com/qtzl/alterSales/dao/repo/jpa/second/AflSmsRecordRepo.java View File

@@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.time.LocalDateTime;
import java.util.List;

public interface AflSmsRecordRepo extends JpaRepository<AflSmsRecord, String>, JpaSpecificationExecutor<AflSmsRecord> {
@@ -21,9 +22,9 @@ public interface AflSmsRecordRepo extends JpaRepository<AflSmsRecord, String>, J
@Query("from AflSmsRecord where mobile = ?1 and businessId=?2 and businessType='3' ")
public List<AflSmsRecord> findByMobileandBusinessIdThree(String mobile, String businessId);

@Query("from AflSmsRecord where status = '0' and vehicleId=?1 and sendTime = TRUNC(SYSDATE) ")
public List<AflSmsRecord> findByCountDay(String vehicleId);
@Query("from AflSmsRecord where status = '0' and vehicleId=?1 and sendTime BETWEEN ?2 AND ?3")
public List<AflSmsRecord> findByCountDay(String vehicleId, LocalDateTime startDate, LocalDateTime endDate);

@Query("from AflSmsRecord where status = '0' and vehicleId = ?1 and MONTH(sendTime) = MONTH(CURRENT_DATE()) AND YEAR(sendTime) = YEAR(CURRENT_DATE())")
public List<AflSmsRecord> findByCountMonth(String vehicleId);
@Query("from AflSmsRecord where status = '0' and vehicleId=?1 and sendTime BETWEEN ?2 AND ?3")
public List<AflSmsRecord> findByCountMonth(String vehicleId, LocalDateTime startDate, LocalDateTime endDate);
}

+ 18
- 2
src/main/java/com/qtzl/alterSales/manager/service/AflSmsSendImpl.java View File

@@ -20,9 +20,11 @@ import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -137,13 +139,27 @@ public class AflSmsSendImpl implements AflSmsSendManager {
}
if (byAgentId.getIsEnabled() == 1&&isWithinTimeRange(byAgentId.getSendTimeStart(), byAgentId.getSendTimeEnd())) {
if (byAgentId.getType() == 1) {
List<AflSmsRecord> byCountDay = aflSmsRecordRepo.findByCountDay(paccountPay.getVehicleId());
// 获取当天开始时间
LocalDateTime startOfDay = LocalDate.now().atStartOfDay();
System.out.println("当天开始时间:" + startOfDay);

// 获取当天结束时间
LocalDateTime endOfDay = LocalDate.now().atTime(LocalTime.MAX);
System.out.println("当天结束时间:" + endOfDay);
List<AflSmsRecord> byCountDay = aflSmsRecordRepo.findByCountDay(paccountPay.getVehicleId(),startOfDay,endOfDay);
if (byCountDay.size() >= byAgentId.getMaxCountPerDay()) {
return false;
}
}
if (byAgentId.getType() == 2) {
List<AflSmsRecord> byCountMonth = aflSmsRecordRepo.findByCountMonth(paccountPay.getVehicleId());
// 获取当月的第一天
LocalDateTime firstDayOfMonth = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).atStartOfDay();
System.out.println("当月的第一天:" + firstDayOfMonth);

// 获取当月的最后一天
LocalDateTime lastDayOfMonth = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()).atTime(LocalTime.MAX);
System.out.println("当月的最后一天:" + lastDayOfMonth);
List<AflSmsRecord> byCountMonth = aflSmsRecordRepo.findByCountMonth(paccountPay.getVehicleId(),firstDayOfMonth,lastDayOfMonth);
if (byCountMonth.size() >= byAgentId.getMaxCountPerMonth()) {
return false;
}

Loading…
Cancel
Save