@Resource | @Resource | ||||
private AflBydDashboardService aflBydDashboardService; | private AflBydDashboardService aflBydDashboardService; | ||||
@Scheduled(cron = "0 0/30 1-4 * * ?") | |||||
// @Scheduled(cron = "0 0/30 1-4 * * ?") | |||||
public void dashboardBatchSync() { | public void dashboardBatchSync() { | ||||
// | // | ||||
final List<AflBydDashboard> dashboards = aflBydDashboardRepo.findAll(((root, query, cb) -> query.where( | final List<AflBydDashboard> dashboards = aflBydDashboardRepo.findAll(((root, query, cb) -> query.where( |
package com.qtzl.alterSales.manager.quartz; | |||||
import cn.com.taiji.common.manager.AbstractManager; | |||||
import cn.com.taiji.common.manager.net.http.ServiceHandleException; | |||||
import com.qtzl.alterSales.dao.entity.second.AflBydDashboard; | |||||
import com.qtzl.alterSales.dao.repo.jpa.second.AflBydDashboardRepo; | |||||
import com.qtzl.alterSales.manager.enums.AflBydDashboardPushStateEnum; | |||||
import com.qtzl.alterSales.manager.service.AflBydDashboardService; | |||||
import com.qtzl.alterSales.manager.service.byd.vo.BydDashBoardResponse; | |||||
import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | |||||
import org.springframework.data.domain.Sort; | |||||
import org.springframework.scheduling.annotation.Scheduled; | |||||
import org.springframework.stereotype.Component; | |||||
import org.springframework.util.CollectionUtils; | |||||
import javax.annotation.Resource; | |||||
import java.time.LocalDateTime; | |||||
import java.util.List; | |||||
/*** | |||||
* <p> | |||||
* 比亚迪看板数据批量同步. 临时处理 | |||||
* </p> | |||||
* @author hou yi | |||||
* {@code @date} 2024/3/15 9:36 | |||||
**/ | |||||
@Component | |||||
public class BydDashboardBatchSyncTempTask extends AbstractManager { | |||||
private static final Logger log = LoggerFactory.getLogger(BydDashboardBatchSyncTempTask.class); | |||||
@Resource | |||||
private AflBydDashboardRepo aflBydDashboardRepo; | |||||
@Resource | |||||
private AflBydDashboardService aflBydDashboardService; | |||||
@Scheduled(cron = "0 0/5 * * * ?") | |||||
public void dashboardBatchSync() throws ServiceHandleException { | |||||
// | |||||
final List<AflBydDashboard> dashboards = aflBydDashboardRepo.findAll(((root, query, cb) -> query.where( | |||||
cb.notEqual(root.<AflBydDashboardPushStateEnum>get("pushState"), AflBydDashboardPushStateEnum.PUSH_SUCCESS) | |||||
).getRestriction()), Sort.by(Sort.Direction.ASC, "insertTime")); | |||||
log.info("比亚迪看板数据同步-临时,本次共处理批次数:" + dashboards.size()); | |||||
if (CollectionUtils.isEmpty(dashboards)) { | |||||
log.info("比亚迪看板数据同步-临时,已全部处理完成"); | |||||
return; | |||||
} | |||||
final AflBydDashboard dashboard = dashboards.get(0); | |||||
final BydDashBoardResponse batchSync = aflBydDashboardService.batchSync(dashboard); | |||||
dashboard.setPushState(AflBydDashboardPushStateEnum.PUSH_SUCCESS); | |||||
dashboard.setPushDate(LocalDateTime.now()); | |||||
dashboard.setBydState(batchSync.getRespondData()); | |||||
dashboard.setPushMsg(null); | |||||
aflBydDashboardRepo.save(dashboard); | |||||
log.info("比亚迪看板数据同步-临时,处理完成"); | |||||
} | |||||
} |
if (!CollectionUtils.isEmpty(applyOrders)) { | if (!CollectionUtils.isEmpty(applyOrders)) { | ||||
applyOrders.forEach(vo -> vo.setSealedStatus(1)); | applyOrders.forEach(vo -> vo.setSealedStatus(1)); | ||||
etcApplyOrderRepo.saveAll(applyOrders); | etcApplyOrderRepo.saveAll(applyOrders); | ||||
return; | |||||
} | } | ||||
// 处理注册表 | // 处理注册表 |
for (BydOrderVehicleInfoVo infoVo : orderVehicleInfoVo) { | for (BydOrderVehicleInfoVo infoVo : orderVehicleInfoVo) { | ||||
// 查询首次获取验证码时间 | // 查询首次获取验证码时间 | ||||
userLoginInfos = aflOrderInfoRepo.getFirstLoginTime(infoVo.getPlateNo()); | userLoginInfos = aflOrderInfoRepo.getFirstLoginTime(infoVo.getPlateNo()); | ||||
if (CollectionUtils.isEmpty(userLoginInfos)) { | |||||
throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("处理比亚迪看板数据时, 车牌号未查到订单或登录信息..." + infoVo.getPlateNo()); | |||||
} | |||||
// if (CollectionUtils.isEmpty(userLoginInfos)) { | |||||
// throw UcServiceError.BUSINESS_VALIDATE_ERR.toHandleException("处理比亚迪看板数据时, 车牌号未查到订单或登录信息..." + infoVo.getPlateNo()); | |||||
// } | |||||
final AflBydBrandConfig brandConfig = brandConfigs.stream().filter(vo -> vo.getBrandName().equals(infoVo.getVehicleModel())).findFirst().orElse(null); | final AflBydBrandConfig brandConfig = brandConfigs.stream().filter(vo -> vo.getBrandName().equals(infoVo.getVehicleModel())).findFirst().orElse(null); | ||||
String source = null == brandConfig ? getSource(brandConfigs, infoVo.getVin()) : brandConfig.getBrandCode(); | String source = null == brandConfig ? getSource(brandConfigs, infoVo.getVin()) : brandConfig.getBrandCode(); | ||||
userLoginInfo = userLoginInfos.stream().max(Comparator.comparing(AflUserLoginInfo::getInsertTime)).orElse(null); | |||||
userLoginInfo = CollectionUtils.isEmpty(userLoginInfos) ? null : userLoginInfos.stream().max(Comparator.comparing(AflUserLoginInfo::getInsertTime)).orElse(null); | |||||
// 查询绑定支付渠道时间 | // 查询绑定支付渠道时间 | ||||
final LocalDateTime bindPayTime = getBindPayTime(infoVo.getPlateNo(), infoVo.getPlateColor()); | final LocalDateTime bindPayTime = getBindPayTime(infoVo.getPlateNo(), infoVo.getPlateColor()); | ||||
dashboardDetails.add(new AflBydDashboardDetail(dashboard.getId(), infoVo.getVin(), infoVo.getPlateNo(), infoVo.getPlateColor(), infoVo.getOrderNo(), | dashboardDetails.add(new AflBydDashboardDetail(dashboard.getId(), infoVo.getVin(), infoVo.getPlateNo(), infoVo.getPlateColor(), infoVo.getOrderNo(), | ||||
null != bindPayTime ? DateTools.getDate(bindPayTime) : infoVo.getCreateTime(), DateTools.getDate(userLoginInfo.getInsertTime()), infoVo.getSuccessActivationTime(), source)); | |||||
null != bindPayTime ? DateTools.getDate(bindPayTime) : infoVo.getCreateTime(), | |||||
null != userLoginInfo && null != userLoginInfo.getInsertTime() ? DateTools.getDate(userLoginInfo.getInsertTime()) : DateTools.addSecond(infoVo.getCreateTime(), -30), | |||||
infoVo.getSuccessActivationTime(), source)); | |||||
} | } | ||||
} | } | ||||
return getDate(localDate.atTime(23, 59, 59, 0)); | return getDate(localDate.atTime(23, 59, 59, 0)); | ||||
} | } | ||||
/** | |||||
* 获取日期前一天的结束时间 - 23:59:59 | |||||
* | |||||
* @param date | |||||
* @return | |||||
*/ | |||||
public static Date getDayEnding(Date date) { | |||||
LocalDate localDate = getLocalDate(date); | |||||
return getDate(localDate.atTime(23, 59, 59, 0)); | |||||
} | |||||
/** | /** | ||||
* 获取日期所在年末的23:59:59 | * 获取日期所在年末的23:59:59 | ||||
* | * |
import com.qtzl.alterSales.manager.service.byd.BydService; | import com.qtzl.alterSales.manager.service.byd.BydService; | ||||
import com.qtzl.alterSales.manager.service.byd.vo.BydDashBoardResponse; | import com.qtzl.alterSales.manager.service.byd.vo.BydDashBoardResponse; | ||||
import com.qtzl.alterSales.manager.service.byd.vo.BydPushDataResultRequest; | import com.qtzl.alterSales.manager.service.byd.vo.BydPushDataResultRequest; | ||||
import com.qtzl.alterSales.manager.tools.DateTools; | |||||
import com.qtzl.alterSales.manager.tools.RedisUtils; | import com.qtzl.alterSales.manager.tools.RedisUtils; | ||||
import com.qtzl.alterSales.manager.vo.BydOrderVehicleInfoVo; | import com.qtzl.alterSales.manager.vo.BydOrderVehicleInfoVo; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
import java.text.ParseException; | import java.text.ParseException; | ||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import java.time.LocalDateTime; | import java.time.LocalDateTime; | ||||
import java.util.Date; | |||||
import java.util.List; | import java.util.List; | ||||
/*** | /*** | ||||
public void bydDataIntegration() throws ParseException, ServiceHandleException { | public void bydDataIntegration() throws ParseException, ServiceHandleException { | ||||
// 指定时间跑对应版本的数据。按天出 | // 指定时间跑对应版本的数据。按天出 | ||||
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||||
bydService.dataIntegration(format.parse("2023-11-02 00:00:00"), format.parse("2024-03-01 23:59:59")); | |||||
Date parse = format.parse("2023-11-15 00:00:00"); | |||||
while (true){ | |||||
final String formatted = format.format(parse); | |||||
if (formatted.contains("2024-04-16")){ | |||||
break; | |||||
} | |||||
System.out.println("当前处理 " + formatted +" 的数据"); | |||||
bydService.dataIntegration(parse, DateTools.getDayEnding(parse)); | |||||
parse = DateTools.addDays(parse, 1); | |||||
} | |||||
} | } | ||||
} | } |