@Query(value = "select " + | @Query(value = "select " + | ||||
" DATE_FORMAT(insert_time, '%Y-%m-%d') as accountDate,agent_id as agentId , COUNT(1) as numberTotal ,SUM(receipt_Amt) as moneyTotal ,SUM(CASE WHEN `status` = 1 THEN receipt_Amt ELSE 0 END) as collectMoney ,0 as refundMoney " + | " DATE_FORMAT(insert_time, '%Y-%m-%d') as accountDate,agent_id as agentId , COUNT(1) as numberTotal ,SUM(receipt_Amt) as moneyTotal ,SUM(CASE WHEN `status` = 1 THEN receipt_Amt ELSE 0 END) as collectMoney ,0 as refundMoney " + | ||||
" from fss_paccount_pay where Date(insert_time) = DATE_SUB(CURDATE(),INTERVAL 1 DAY) GROUP BY DATE_FORMAT(insert_time, '%Y-%m-%d'),agent_id ",nativeQuery = true ) | |||||
List<Map<String,Object>> findCountTotal(); | |||||
" from fss_paccount_pay where insert_time = ?1 GROUP BY DATE_FORMAT(insert_time, '%Y-%m-%d'),agent_id ",nativeQuery = true ) | |||||
List<Map<String,Object>> findCountTotal(String yesterday); | |||||
} | } |
JpaRepository<AflPaccountRefundCount, String> , | JpaRepository<AflPaccountRefundCount, String> , | ||||
JpaSpecificationExecutor<AflPaccountRefundCount> { | JpaSpecificationExecutor<AflPaccountRefundCount> { | ||||
@Query(value = " SELECT COUNT(1) FROM AFL_PACCOUNT_REFUND_COUNT GROUP BY ACCOUNT_DATE having ACCOUNT_DATE = DATE_SUB(CURDATE(),INTERVAL 1 DAY) ",nativeQuery = true) | |||||
Integer findByToDay(); | |||||
@Query(value = " SELECT COUNT(1) FROM AFL_PACCOUNT_REFUND_COUNT GROUP BY ACCOUNT_DATE having ACCOUNT_DATE = ?1 ",nativeQuery = true) | |||||
Integer findByToDay(String yesterday); | |||||
@Query(" from AflPaccountRefundCount where agentId = ?1 and accountDate=?2") | @Query(" from AflPaccountRefundCount where agentId = ?1 and accountDate=?2") |
import org.springframework.util.CollectionUtils; | import org.springframework.util.CollectionUtils; | ||||
import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
import java.time.LocalDate; | |||||
import java.time.LocalDateTime; | import java.time.LocalDateTime; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
@Override | @Override | ||||
public void count() throws ServiceHandleException { | public void count() throws ServiceHandleException { | ||||
Integer i= aflPaccountRefundCountRepo.findByToDay(); | |||||
// 获取当前日期前一天的日期 | |||||
LocalDate localDate = LocalDate.now().minusDays(1);//1代表提前多少天 | |||||
String yesterday = localDate.toString(); | |||||
Integer i= aflPaccountRefundCountRepo.findByToDay(yesterday); | |||||
if (i!=null&&i>0){ | if (i!=null&&i>0){ | ||||
throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("当前n+1天记录已存在"); | throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("当前n+1天记录已存在"); | ||||
} | } | ||||
List<Map<String, Object>> countTotal = paccountPayRepo.findCountTotal(); | |||||
List<Map<String, Object>> countTotal = paccountPayRepo.findCountTotal(yesterday+" 00:00:00"); | |||||
List<AflPaccountRefundCount> list = new ArrayList<AflPaccountRefundCount>(); | List<AflPaccountRefundCount> list = new ArrayList<AflPaccountRefundCount>(); | ||||
for (Map<String, Object> stringObjectMap : countTotal) { | for (Map<String, Object> stringObjectMap : countTotal) { | ||||
AflPaccountRefundCount aflPaccountRefundCount = new AflPaccountRefundCount(); | AflPaccountRefundCount aflPaccountRefundCount = new AflPaccountRefundCount(); |