JNBusiness/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/RbTask.java

98 lines
3.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.ruoyi.quartz.task;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.redis.RedisLock;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.quartz.domain.c_rb_product_price;
import com.ruoyi.quartz.domain.c_rb_productbase_price;
import com.ruoyi.quartz.service.SapTjService;
import com.ruoyi.quartz.util.JDBCBatchInsert;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;
/**
* 定时任务调度-同步红本数据库
*
* @author ruoyi
*/
@Component("rbTask")
public class RbTask
{
@Autowired
private RedisCache redisCache;
@Autowired
private RedisLock redisLock;
@Autowired
private Scheduler scheduler;
@Resource
private SapTjService sapTjService;
public static RbTask testUtils;
@PostConstruct
public void init() {
testUtils = this;
}
/**
* 同步红本数据库
*/
public void tongb() throws Exception {
String jobId = scheduler.getSchedulerInstanceId();
String rbVersionUid = testUtils.sapTjService.selRbVersionUid();//红本调价记录uid
Boolean lock= redisLock.getLock(getJobKey(jobId), -1, rbVersionUid);
if(lock){
//判断是否已执行调价 6.3 redbook rb_productVersion 是否有新增uid and sta='1'、sdmdm1 调价日期今日的数据是否存在)
String locVersionUid = testUtils.sapTjService.selLocVersionUid();//本地红本调价记录uid
String RbProductPriceCount = testUtils.sapTjService.selRbProductPriceVersionUid(rbVersionUid);//RbProductPrice表是否有更新
String RbProductBasePriceCount = testUtils.sapTjService.selRbProductBasePriceVersionUid(rbVersionUid);//RbProductBasePrice表是否有更新
try{
if(!rbVersionUid.equals(locVersionUid) && Integer.valueOf(RbProductPriceCount)>0 && Integer.valueOf(RbProductBasePriceCount)>0) {//有新增调价版本并且有调价记录
System.out.println("=======================开始同步!======================");
testUtils.sapTjService.deleteLocProductPrice();//删除本地c_rb_product_price表数据
List<c_rb_product_price> productPriceList = testUtils.sapTjService.getProductPriceList(rbVersionUid);
JDBCBatchInsert.insertRbProductPrice(productPriceList);//批量插入
testUtils.sapTjService.deleteLocProductBasePrice();//删除本地c_rb_productbase_price表数据
List<c_rb_productbase_price> productBasePriceList = testUtils.sapTjService.getProductBasePriceList(rbVersionUid);
JDBCBatchInsert.insertRbProductBasePrice(productBasePriceList);//批量插入
testUtils.sapTjService.updateLocRbVersion(rbVersionUid);//更新本地c_rb_version表
redisCache.deleteObject(getJobKey(jobId));
}
}catch (Exception e) {
throw new Exception(e.getMessage(), e);
}
}
}
/**
* 定时任务缓存键名
*
* @param jobId 任务编号
* @return 缓存键key
*/
private String getJobKey(String jobId)
{
return CacheConstants.SYS_JOB_KEY + jobId;
}
}