数据同步-sqlserver
This commit is contained in:
parent
100f197bee
commit
558a0ef033
@ -54,6 +54,9 @@ public class SyncConfig implements Serializable {
|
||||
@ApiModelProperty(value = "数据库密码")
|
||||
private String sql_pwd;
|
||||
|
||||
@ApiModelProperty(value = "数据端口")
|
||||
private String sql_port;
|
||||
|
||||
@ApiModelProperty(value = "数据库")
|
||||
private String sql_db;
|
||||
|
||||
|
||||
@ -300,6 +300,11 @@
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!--打票机 使用的库 结束-->
|
||||
<dependency>
|
||||
<groupId>com.microsoft.sqlserver</groupId>
|
||||
<artifactId>mssql-jdbc</artifactId>
|
||||
<version>9.4.1.jre8</version> <!-- 或者使用合适的版本 -->
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
package com.suisung.mall.shop.sync.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.suisung.mall.common.modules.sync.SyncConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SyncConfigServiceMapper extends BaseMapper<SyncConfig> {
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package com.suisung.mall.shop.sync.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.suisung.mall.common.modules.sync.SyncConfig;
|
||||
|
||||
public interface SyncConfigService extends IService<SyncConfig> {
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.suisung.mall.shop.sync.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.suisung.mall.common.modules.sync.SyncConfig;
|
||||
import com.suisung.mall.shop.sync.mapper.SyncConfigServiceMapper;
|
||||
import com.suisung.mall.shop.sync.service.SyncConfigService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SyncConfigServiceImpl extends ServiceImpl<SyncConfigServiceMapper, SyncConfig> implements SyncConfigService {
|
||||
}
|
||||
@ -34,6 +34,7 @@ import com.suisung.mall.common.modules.pay.PayUserResource;
|
||||
import com.suisung.mall.common.modules.product.*;
|
||||
import com.suisung.mall.common.modules.store.ShopStoreBase;
|
||||
import com.suisung.mall.common.modules.sync.SyncApp;
|
||||
import com.suisung.mall.common.modules.sync.SyncConfig;
|
||||
import com.suisung.mall.common.pojo.req.SyncThirdMemberReq;
|
||||
import com.suisung.mall.common.pojo.res.ThirdApiRes;
|
||||
import com.suisung.mall.common.utils.DateTimeUtils;
|
||||
@ -46,11 +47,14 @@ import com.suisung.mall.shop.product.service.ShopProductBaseService;
|
||||
import com.suisung.mall.shop.product.service.impl.ShopProductBaseServiceImpl;
|
||||
import com.suisung.mall.shop.store.service.ShopStoreBaseService;
|
||||
import com.suisung.mall.shop.sync.service.SyncAppService;
|
||||
import com.suisung.mall.shop.sync.service.SyncConfigService;
|
||||
import com.suisung.mall.shop.sync.service.SyncThirdDataService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.util.Pair;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -76,6 +80,8 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
|
||||
private ShopStoreBaseService shopStoreBaseService;
|
||||
@Autowired
|
||||
private SyncAppService syncAppService;
|
||||
@Autowired
|
||||
private SyncConfigService syncConfigService;
|
||||
|
||||
/**
|
||||
* 批量保存商品的分类
|
||||
@ -505,7 +511,7 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
|
||||
if (!Arrays.asList(1, 2, 3, 4).contains(syncType)) {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
//获取appid、appKey
|
||||
//获取appKey、appSecret
|
||||
SyncApp syncAppO = syncAppService.getOne(new LambdaQueryWrapper<SyncApp>()
|
||||
.select(SyncApp::getApp_key, SyncApp::getApp_secret)
|
||||
.eq(SyncApp::getStore_id, storeId));
|
||||
@ -518,48 +524,85 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
|
||||
//合作商配置
|
||||
SyncConfig syncConfig = syncConfigService.getOne(new LambdaQueryWrapper<SyncConfig>().eq(SyncConfig::getApp_key, syncAppO.getApp_key()));
|
||||
if (null == syncConfig) {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
|
||||
//jdbcTemplate
|
||||
JdbcTemplate jdbcTemplate = getJDBCTemplate(syncConfig);
|
||||
if (null == jdbcTemplate) {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
|
||||
switch (syncType) {
|
||||
case 1:
|
||||
return syncProductBrand();
|
||||
return syncProductBrand(jdbcTemplate);
|
||||
case 2:
|
||||
return syncProductClazz();
|
||||
return syncProductClazz(jdbcTemplate);
|
||||
case 3:
|
||||
return syncProduct();
|
||||
return syncProduct(jdbcTemplate);
|
||||
case 4:
|
||||
return syncVip();
|
||||
return syncVip(jdbcTemplate);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//创建Template
|
||||
private JdbcTemplate getJDBCTemplate(SyncConfig syncConfig) {
|
||||
|
||||
switch (syncConfig.getSys_version()) {
|
||||
case "hbposev9" :
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
String url = String.format("jdbc:sqlserver://%s:%s;databaseName=%s",
|
||||
syncConfig.getSever_ip(), syncConfig.getSql_port(), syncConfig.getSql_db());
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername(syncConfig.getSql_acc());
|
||||
dataSource.setPassword(syncConfig.getSql_pwd());
|
||||
// 创建 JdbcTemplate
|
||||
return new JdbcTemplate(dataSource);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步商品品牌
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public CommonResult syncProductBrand() {
|
||||
public CommonResult syncProductBrand(JdbcTemplate syncAppO) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步商品分类
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public CommonResult syncProductClazz() {
|
||||
public CommonResult syncProductClazz(JdbcTemplate syncAppO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步商品
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public CommonResult syncProduct() {
|
||||
public CommonResult syncProduct(JdbcTemplate syncAppO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步会员
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public CommonResult syncVip() {
|
||||
public CommonResult syncVip(JdbcTemplate syncAppO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user