'定时同步红本物料价格'
This commit is contained in:
parent
c0c70ea555
commit
e9b8260d94
|
@ -0,0 +1,40 @@
|
|||
package com.ruoyi.quartz.domain;
|
||||
|
||||
public class c_rb_product_price {
|
||||
private String material_xingh;
|
||||
private String material_guig;
|
||||
private String material_diany;
|
||||
private String material_rb_price;
|
||||
|
||||
public String getMaterial_xingh() {
|
||||
return material_xingh;
|
||||
}
|
||||
|
||||
public void setMaterial_xingh(String material_xingh) {
|
||||
this.material_xingh = material_xingh;
|
||||
}
|
||||
|
||||
public String getMaterial_guig() {
|
||||
return material_guig;
|
||||
}
|
||||
|
||||
public void setMaterial_guig(String material_guig) {
|
||||
this.material_guig = material_guig;
|
||||
}
|
||||
|
||||
public String getMaterial_diany() {
|
||||
return material_diany;
|
||||
}
|
||||
|
||||
public void setMaterial_diany(String material_diany) {
|
||||
this.material_diany = material_diany;
|
||||
}
|
||||
|
||||
public String getMaterial_rb_price() {
|
||||
return material_rb_price;
|
||||
}
|
||||
|
||||
public void setMaterial_rb_price(String material_rb_price) {
|
||||
this.material_rb_price = material_rb_price;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.ruoyi.quartz.domain;
|
||||
|
||||
public class c_rb_productbase_price {
|
||||
private String material_xingh;
|
||||
private String material_guig;
|
||||
private String material_diany;
|
||||
private String material_cb_price;
|
||||
|
||||
public String getMaterial_xingh() {
|
||||
return material_xingh;
|
||||
}
|
||||
|
||||
public void setMaterial_xingh(String material_xingh) {
|
||||
this.material_xingh = material_xingh;
|
||||
}
|
||||
|
||||
public String getMaterial_guig() {
|
||||
return material_guig;
|
||||
}
|
||||
|
||||
public void setMaterial_guig(String material_guig) {
|
||||
this.material_guig = material_guig;
|
||||
}
|
||||
|
||||
public String getMaterial_diany() {
|
||||
return material_diany;
|
||||
}
|
||||
|
||||
public void setMaterial_diany(String material_diany) {
|
||||
this.material_diany = material_diany;
|
||||
}
|
||||
|
||||
public String getMaterial_cb_price() {
|
||||
return material_cb_price;
|
||||
}
|
||||
|
||||
public void setMaterial_cb_price(String material_cb_price) {
|
||||
this.material_cb_price = material_cb_price;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.ruoyi.quartz.mapper;
|
||||
|
||||
import com.ruoyi.quartz.domain.c_rb_product_price;
|
||||
import com.ruoyi.quartz.domain.c_rb_productbase_price;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by xuxueli on 16/9/30.
|
||||
*/
|
||||
public interface SapTjMapper {
|
||||
/**
|
||||
* 获取红本调价版本
|
||||
* @return
|
||||
*/
|
||||
String selRbVersionUid();
|
||||
|
||||
/**
|
||||
* 获取本地红本调价版本
|
||||
* @return
|
||||
*/
|
||||
String selLocVersionUid();
|
||||
|
||||
/**
|
||||
* 获取红本价格
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
List<c_rb_product_price> getProductPriceList(String rbVersionUid);
|
||||
|
||||
/**
|
||||
* 获取红本成本价格
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
List<c_rb_productbase_price> getProductBasePriceList(String rbVersionUid);
|
||||
|
||||
/**
|
||||
* 删除本地红本价格表
|
||||
*/
|
||||
void deleteLocProductPrice();
|
||||
|
||||
/**
|
||||
* 删除本地红本成本价格表
|
||||
*/
|
||||
void deleteLocProductBasePrice();
|
||||
|
||||
/**
|
||||
* RbProductPrice表是否有更新
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
String selRbProductPriceVersionUid(String rbVersionUid);
|
||||
|
||||
/**
|
||||
* RbProductBasePrice表是否有更新
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
String selRbProductBasePriceVersionUid(String rbVersionUid);
|
||||
|
||||
/**
|
||||
* 更新本地c_rb_version表
|
||||
* @param rbVersionUid
|
||||
*/
|
||||
void updateLocRbVersion(String rbVersionUid);
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.ruoyi.quartz.service;
|
||||
|
||||
import com.ruoyi.quartz.domain.c_rb_product_price;
|
||||
import com.ruoyi.quartz.domain.c_rb_productbase_price;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SAP库存数据批量插入中间表
|
||||
*/
|
||||
|
||||
public interface SapTjService {
|
||||
|
||||
/**
|
||||
* 获取红本调价版本
|
||||
* @return
|
||||
*/
|
||||
public String selRbVersionUid();
|
||||
|
||||
/**
|
||||
* 获取本地红本调价版本
|
||||
* @return
|
||||
*/
|
||||
public String selLocVersionUid();
|
||||
|
||||
/**
|
||||
* 获取红本价格
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
List<c_rb_product_price> getProductPriceList(String rbVersionUid);
|
||||
|
||||
/**
|
||||
* 获取红本成本价格
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
List<c_rb_productbase_price> getProductBasePriceList(String rbVersionUid);
|
||||
|
||||
/**
|
||||
* 删除本地红本价格表
|
||||
*/
|
||||
void deleteLocProductPrice();
|
||||
|
||||
/**
|
||||
* 删除本地红本成本价格表
|
||||
*/
|
||||
void deleteLocProductBasePrice();
|
||||
|
||||
/**
|
||||
* RbProductPrice表是否有更新
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
String selRbProductPriceVersionUid(String rbVersionUid);
|
||||
|
||||
/**
|
||||
* RbProductBasePrice表是否有更新
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
String selRbProductBasePriceVersionUid(String rbVersionUid);
|
||||
|
||||
/**
|
||||
* 更新本地c_rb_version表
|
||||
* @param rbVersionUid
|
||||
*/
|
||||
void updateLocRbVersion(String rbVersionUid);
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package com.ruoyi.quartz.service.impl;
|
||||
import com.ruoyi.common.annotation.DataSource;
|
||||
import com.ruoyi.common.enums.DataSourceType;
|
||||
import com.ruoyi.quartz.domain.c_rb_product_price;
|
||||
import com.ruoyi.quartz.domain.c_rb_productbase_price;
|
||||
import com.ruoyi.quartz.mapper.SapTjMapper;
|
||||
import com.ruoyi.quartz.service.SapTjService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* core job action for xxl-job
|
||||
* @author xuxueli 2016-5-28 15:30:33
|
||||
*/
|
||||
@Service
|
||||
public class SapTjServiceImpl implements SapTjService {
|
||||
|
||||
@Resource
|
||||
private SapTjMapper sapTjMapper;
|
||||
|
||||
/**
|
||||
* 获取红本调价版本
|
||||
* @return
|
||||
*/
|
||||
@DataSource(DataSourceType.REDBOOK)
|
||||
@Override
|
||||
public String selRbVersionUid() {
|
||||
return sapTjMapper.selRbVersionUid();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地红本调价版本
|
||||
* @return
|
||||
*/
|
||||
@DataSource(DataSourceType.QUOT)
|
||||
@Override
|
||||
public String selLocVersionUid() {return sapTjMapper.selLocVersionUid(); }
|
||||
|
||||
|
||||
/**
|
||||
* 获取红本价格
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
@DataSource(DataSourceType.REDBOOK)
|
||||
@Override
|
||||
public List<c_rb_product_price> getProductPriceList(String rbVersionUid) {return sapTjMapper.getProductPriceList(rbVersionUid); }
|
||||
|
||||
/**
|
||||
* 获取红本成本价格
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
@DataSource(DataSourceType.REDBOOK)
|
||||
@Override
|
||||
public List<c_rb_productbase_price> getProductBasePriceList(String rbVersionUid) {return sapTjMapper.getProductBasePriceList(rbVersionUid); }
|
||||
|
||||
/**
|
||||
* 删除本地红本价格表
|
||||
*/
|
||||
@DataSource(DataSourceType.QUOT)
|
||||
@Override
|
||||
public void deleteLocProductPrice() {sapTjMapper.deleteLocProductPrice(); }
|
||||
|
||||
/**
|
||||
* 删除本地红本成本价格表
|
||||
*/
|
||||
@DataSource(DataSourceType.QUOT)
|
||||
@Override
|
||||
public void deleteLocProductBasePrice() {sapTjMapper.deleteLocProductBasePrice(); }
|
||||
|
||||
/**
|
||||
* RbProductPrice表是否有更新
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
@DataSource(DataSourceType.REDBOOK)
|
||||
@Override
|
||||
public String selRbProductPriceVersionUid(String rbVersionUid) {
|
||||
return sapTjMapper.selRbProductPriceVersionUid(rbVersionUid);
|
||||
}
|
||||
|
||||
/**
|
||||
* RbProductBasePrice表是否有更新
|
||||
* @param rbVersionUid
|
||||
* @return
|
||||
*/
|
||||
@DataSource(DataSourceType.REDBOOK)
|
||||
@Override
|
||||
public String selRbProductBasePriceVersionUid(String rbVersionUid) {
|
||||
return sapTjMapper.selRbProductBasePriceVersionUid(rbVersionUid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新本地c_rb_version表
|
||||
* @param rbVersionUid
|
||||
*/
|
||||
@DataSource(DataSourceType.QUOT)
|
||||
@Override
|
||||
public void updateLocRbVersion(String rbVersionUid) {
|
||||
sapTjMapper.updateLocRbVersion(rbVersionUid);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.ruoyi.quartz.task;
|
||||
|
||||
import com.ruoyi.common.annotation.DataSource;
|
||||
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.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
|
||||
{
|
||||
@Resource
|
||||
private SapTjService sapTjService;
|
||||
|
||||
public static RbTask testUtils;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
testUtils = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步红本数据库
|
||||
*/
|
||||
public void tongb() throws Exception {
|
||||
//判断是否已执行调价 (6.3 redbook rb_productVersion 是否有新增uid and sta='1'、sdmdm1 调价日期今日的数据是否存在)
|
||||
String rbVersionUid = testUtils.sapTjService.selRbVersionUid();//红本调价记录uid
|
||||
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表
|
||||
}
|
||||
}catch (Exception e) {
|
||||
throw new Exception(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
package com.ruoyi.quartz.util;
|
||||
|
||||
import com.ruoyi.quartz.domain.c_rb_product_price;
|
||||
import com.ruoyi.quartz.domain.c_rb_productbase_price;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@Component
|
||||
public class JDBCBatchInsert {
|
||||
|
||||
private static String databaseURL;
|
||||
public static String getDatabaseURL() {
|
||||
return databaseURL;
|
||||
}
|
||||
|
||||
@Value(value = "${spring.datasource.druid.quot.url}")
|
||||
public void setDatabaseUR(String databaseURL) {
|
||||
JDBCBatchInsert.databaseURL = databaseURL;
|
||||
}
|
||||
|
||||
private static String username;
|
||||
public static String getUsername() {return username;}
|
||||
|
||||
@Value(value = "${spring.datasource.druid.quot.username}")
|
||||
public void setUsername(String username) {
|
||||
JDBCBatchInsert.username = username;
|
||||
}
|
||||
|
||||
private static String password;
|
||||
public static String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
@Value(value = "${spring.datasource.druid.quot.password}")
|
||||
public void setPassword(String password) {
|
||||
JDBCBatchInsert.password = password;
|
||||
}
|
||||
|
||||
public static void insertRbProductPrice(List<c_rb_product_price> list) throws IOException {
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try {
|
||||
connection = DriverManager.getConnection(databaseURL, username, password);
|
||||
// 关闭自动提交事务,改为手动提交
|
||||
connection.setAutoCommit(false);
|
||||
System.out.println("===== 开始插入数据 =====");
|
||||
long startTime = System.currentTimeMillis();
|
||||
String sqlInsert = "INSERT INTO c_rb_product_price ( material_xingh, material_guig, material_diany, material_rb_price) VALUES ( ?, ?, ?, ?)";
|
||||
preparedStatement = connection.prepareStatement(sqlInsert);
|
||||
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
preparedStatement.setString(1, list.get(i).getMaterial_xingh());
|
||||
preparedStatement.setString(2, list.get(i).getMaterial_guig());
|
||||
preparedStatement.setString(3, list.get(i).getMaterial_diany());
|
||||
preparedStatement.setString(4, list.get(i).getMaterial_rb_price());
|
||||
// 添加到批处理中
|
||||
preparedStatement.addBatch();
|
||||
|
||||
if (i % 10000 == 0) {
|
||||
// 每1000条数据提交一次
|
||||
preparedStatement.executeBatch();
|
||||
connection.commit();
|
||||
System.out.println("成功插入第 "+ i+" 条数据");
|
||||
}
|
||||
|
||||
}
|
||||
// 处理剩余的数据
|
||||
preparedStatement.executeBatch();
|
||||
connection.commit();
|
||||
long spendTime = System.currentTimeMillis()-startTime;
|
||||
System.out.println("成功插入"+ list.size()+" 条数据,耗时:"+spendTime+"毫秒");
|
||||
} catch (SQLException e) {
|
||||
System.out.println("Error: " + e.getMessage());
|
||||
} finally {
|
||||
if (preparedStatement != null) {
|
||||
try {
|
||||
preparedStatement.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void insertRbProductBasePrice(List<c_rb_productbase_price> list) throws IOException {
|
||||
Connection connection = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try {
|
||||
connection = DriverManager.getConnection(databaseURL, username, password);
|
||||
// 关闭自动提交事务,改为手动提交
|
||||
connection.setAutoCommit(false);
|
||||
System.out.println("===== 开始插入数据 =====");
|
||||
long startTime = System.currentTimeMillis();
|
||||
String sqlInsert = "INSERT INTO c_rb_productbase_price ( material_xingh, material_guig, material_diany, material_cb_price) VALUES ( ?, ?, ?, ?)";
|
||||
preparedStatement = connection.prepareStatement(sqlInsert);
|
||||
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
preparedStatement.setString(1, list.get(i).getMaterial_xingh());
|
||||
preparedStatement.setString(2, list.get(i).getMaterial_guig());
|
||||
preparedStatement.setString(3, list.get(i).getMaterial_diany());
|
||||
preparedStatement.setString(4, list.get(i).getMaterial_cb_price());
|
||||
// 添加到批处理中
|
||||
preparedStatement.addBatch();
|
||||
|
||||
if (i % 10000 == 0) {
|
||||
// 每1000条数据提交一次
|
||||
preparedStatement.executeBatch();
|
||||
connection.commit();
|
||||
System.out.println("成功插入第 "+ i+" 条数据");
|
||||
}
|
||||
|
||||
}
|
||||
// 处理剩余的数据
|
||||
preparedStatement.executeBatch();
|
||||
connection.commit();
|
||||
long spendTime = System.currentTimeMillis()-startTime;
|
||||
System.out.println("成功插入"+ list.size()+" 条数据,耗时:"+spendTime+"毫秒");
|
||||
} catch (SQLException e) {
|
||||
System.out.println("Error: " + e.getMessage());
|
||||
} finally {
|
||||
if (preparedStatement != null) {
|
||||
try {
|
||||
preparedStatement.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.quartz.mapper.SapTjMapper">
|
||||
|
||||
<select id="selRbVersionUid" resultType="java.lang.String" >
|
||||
select top 1 uid_0 from rb_productVersion where date_0=(select MAX(date_0) from [dbo].[rb_productVersion] where sta_0=0 or sta_0=1) and (sta_0=0 or sta_0=1) order by uid_0 desc
|
||||
</select>
|
||||
|
||||
<select id="selLocVersionUid" resultType="java.lang.String" >
|
||||
select top 1 version_uid from c_rb_version
|
||||
</select>
|
||||
|
||||
<select id="selRbProductPriceVersionUid" resultType="java.lang.String" >
|
||||
select count(1) from rb_product_price where version_uid_0 = #{rbVersionUid}
|
||||
</select>
|
||||
|
||||
<select id="selRbProductBasePriceVersionUid" resultType="java.lang.String" >
|
||||
select count(1) from rb_productbase_price where version_uid_0 = #{rbVersionUid}
|
||||
</select>
|
||||
|
||||
<select id="getProductPriceList" resultType="c_rb_product_price" >
|
||||
select distinct 型号 material_xingh,规格 material_guig,电压等级 material_diany,红本价格 material_rb_price from rb_product_price where version_uid_0 = #{rbVersionUid}
|
||||
</select>
|
||||
|
||||
<select id="getProductBasePriceList" resultType="c_rb_productbase_price" >
|
||||
select distinct 型号 material_xingh,规格 material_guig,电压等级 material_diany,成本价格 material_cb_price from rb_productbase_price where version_uid_0 = #{rbVersionUid}
|
||||
</select>
|
||||
|
||||
<delete id="deleteLocProductPrice">
|
||||
delete from c_rb_product_price
|
||||
</delete>
|
||||
|
||||
<delete id="deleteLocProductBasePrice">
|
||||
delete from c_rb_productbase_price
|
||||
</delete>
|
||||
|
||||
<update id="updateLocRbVersion">
|
||||
update c_rb_version set version_uid = #{rbVersionUid}
|
||||
</update>
|
||||
</mapper>
|
Loading…
Reference in New Issue