Pārlūkot izejas kodu

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

heyueyang
hyy pirms 11 mēnešiem
vecāks
revīzija
fea110b8e1

+ 5
- 4
src/main/java/com/qtzl/alterSales/dao/repo/jpa/second/AflSmsRecordRepo.java Parādīt failu

import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;


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


public interface AflSmsRecordRepo extends JpaRepository<AflSmsRecord, String>, JpaSpecificationExecutor<AflSmsRecord> { public interface AflSmsRecordRepo extends JpaRepository<AflSmsRecord, String>, JpaSpecificationExecutor<AflSmsRecord> {
@Query("from AflSmsRecord where mobile = ?1 and businessId=?2 and businessType='3' ") @Query("from AflSmsRecord where mobile = ?1 and businessId=?2 and businessType='3' ")
public List<AflSmsRecord> findByMobileandBusinessIdThree(String mobile, String businessId); 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 Parādīt failu



import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
} }
if (byAgentId.getIsEnabled() == 1&&isWithinTimeRange(byAgentId.getSendTimeStart(), byAgentId.getSendTimeEnd())) { if (byAgentId.getIsEnabled() == 1&&isWithinTimeRange(byAgentId.getSendTimeStart(), byAgentId.getSendTimeEnd())) {
if (byAgentId.getType() == 1) { 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()) { if (byCountDay.size() >= byAgentId.getMaxCountPerDay()) {
return false; return false;
} }
} }
if (byAgentId.getType() == 2) { 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()) { if (byCountMonth.size() >= byAgentId.getMaxCountPerMonth()) {
return false; return false;
} }

Notiek ielāde…
Atcelt
Saglabāt