关于生成POS端sqlLiteDB文件 实现全量同步
来源:互联网 发布:中国医药化工网数据库 编辑:程序博客网 时间:2024/05/22 11:34
// 零售商商品列表 List<RetailerSkuCmmdtyEntity> cmmdtyList = null; // 商品规格表 List<CmmdtyPropertyEntity> properties = null; // 获取商品 cmmdtyList = retailerSkuCmmdtyBusiness.queryCmmdtysByMerCustNo(merchantCustNo); // 获取商品规格 properties = cmmdtyPropertyBusiness.queryCmmdtyPropertiesByMerCustNo(merchantCustNo); Map<String, Object> param = new HashMap<String, Object>();param.put("cmmdtyList", cmmdtyList);param.put("properties ", properties );createPosCmmdtyDbFile(merchantCustNo, storeCode, param);
private String createPosCmmdtyDbFile(String merchantCustNo, String storeCode, Map<String, Object> param) { String uploadPath = StringUtils.EMPTY; int status = FAIL; SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String filePath = System.getProperty("user.dir") + File.separator + "pos"; String date = df.format(new Date()); createDir(filePath); String dbFileName = "product_" + storeCode + "_" + date + ".db"; LOGGER.debug("Start零售商:{},店铺:{},DB文件本地存储路径:{}", merchantCustNo, storeCode, filePath + File.separator + dbFileName); Connection conn = SqliteConnectionUtils.getConnection("jdbc:sqlite:" + File.separator + filePath + File.separator + dbFileName); try { Statement stat = conn.createStatement(); // 建表 status = createTables(stat); if (status == SUCCESS) { // 添加商品信息 status = insertProductInfo(conn, param); } if (status == SUCCESS) { // 添加商品属性信息 status = insertPropertyInfo(conn, param); } if (status == SUCCESS) { // 添加商品属性值信息 status = insertPropertyValueInfo(conn, param); } // 生成DB文件成功则上传DB文件 if (status == SUCCESS) { OssFileUploadUtil oss = new OssFileUploadUtil(); uploadPath = oss.uploadOssFile(filePath, dbFileName); } } catch (SQLException e) { LOGGER.error("PosCmmdtyBusiness.createPosCmmdty error,", e); } finally { LOGGER.debug("End零售商:{},店铺:{},DB文件OSS存储路径:{}", merchantCustNo, storeCode, uploadPath); SqliteConnectionUtils.closeConnection(conn); deleteFile(filePath + File.separator + dbFileName); } return uploadPath; }
sqlLite 工具类
public class SqliteConnectionUtils { private static final Logger LOGGER = LoggerFactory.getLogger(SqliteConnectionUtils.class); private SqliteConnectionUtils() { } static { try { Class.forName("org.sqlite.JDBC"); } catch (ClassNotFoundException e) { LOGGER.error("SqliteConnectionUtil error,", e); } } /** * 功能描述: 获取SQLite数据库连接<br> * 〈功能详细描述〉 获取SQLite数据库连接 * * @param connName 连接名称 * @return Connection * @see [相关类/方法](可选) * @since [产品/模块版本](可选) */ public static Connection getConnection(String connName) { Connection conn = null; try { conn = DriverManager.getConnection(connName); } catch (SQLException e) { LOGGER.error("SqliteConnectionUtils.getConnection error,", e); } return conn; } /** * 功能描述: 关闭SQLite数据库连接<br> * 〈功能详细描述〉 关闭SQLite数据库连接 * * @param Connection 数据库连接 * @see [相关类/方法](可选) * @since [产品/模块版本](可选) */ public static void closeConnection(Connection conn) { if (null != conn) { try { conn.close(); } catch (SQLException e) { LOGGER.error("SqliteConnectionUtils.closeConnection error,", e); } } }}
private boolean createDir(String filePath) { File dir = new File(filePath); // 判断目录是否存在 if (dir.exists()) { return false; } // 创建目标目录 if (dir.mkdirs()) { return true; } else { return false; } }
private int createTables(Statement stat) { try { stat.executeUpdate("drop table if exists Brand;"); stat.executeUpdate("drop table if exists Category;"); stat.executeUpdate("drop table if exists Product;"); stat.executeUpdate("drop table if exists Product_Category_Relation;"); stat.executeUpdate("drop table if exists Product_Property;"); stat.executeUpdate("drop table if exists Product_Property_Value;"); stat.executeUpdate("drop table if exists Sku_Property_Relation;"); // 建表语句执行 stat.executeUpdate("create table Brand (brandCode text not null,brandName text,brandImage text,primary key (brandCode));"); stat.executeUpdate("create table Category(categoryCode text not null,categoryName text,categoryEng text,manageInventory text, primary key (categoryCode));"); stat.executeUpdate("create table Product(productCode text not null," + "skuProductCode text," + "spuProductCode text," + "productName text," + "productType text," + "barcode text," + "brandName text," + "brandCode text," + "unit text," + "productSource text," + "deliveryTime text," + "imageSeq text," + "imageIndex text," + "imageUrl text," + "imageSource text," + "retrailPrice text," + "managerPrice text," + "emplPrice text," + "retailPriceLowest text," + "inventory text," + "salesCount text," + "primary key (productCode));"); stat.executeUpdate("create table Product_Category_Relation(id bigint not null,productCode text,categoryCode text,primary key (id));"); stat.executeUpdate("create table Product_Property(propertyId text not null,propertyCode text,spuProductCode text,propertyName text,showLevel text,primary key (propertyId));"); stat.executeUpdate("create table Product_Property_Value(valueId text not null,valueName text not null,showLevel text,propertyId text,primary key (valueId));"); stat.executeUpdate("create table Sku_Property_Relation(id bigint not null,skuProductCode text,propertyId text,valueId text,primary key (id));"); } catch (SQLException e) { LOGGER.error("PosCmmdtyBusiness.createTables error,", e); return FAIL; } return SUCCESS; }
创建数据
@SuppressWarnings("unchecked") private int insertProductInfo(Connection conn, Map<String, Object> param) { // 零售商商品列表获取 List<RetailerSkuCmmdtyEntity> cmmdtyList = (List<RetailerSkuCmmdtyEntity>) param.get("cmmdtyList"); // 有商品数据 if (CollectionUtils.isEmpty(cmmdtyList)) { return SUCCESS; } // 商品价格获取 List<StoreCmmdtyPriceEntity> priceList = (List<StoreCmmdtyPriceEntity>) param.get("priceList"); // 商库存格获取 List<InventoryEntity> inventoryList = (List<InventoryEntity>) param.get("inventoryList"); PreparedStatement prep = null; try { String insertSql = "insert into Product (productCode,skuProductCode,spuProductCode," + "productName,barcode,brandName,brandCode,unit,productSource,deliveryTime,imageSeq," + "imageIndex,imageUrl,imageSource,retrailPrice,managerPrice," + "emplPrice,retailPriceLowest,inventory,salesCount) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; prep = conn.prepareStatement(insertSql); // 商品信息 for (RetailerSkuCmmdtyEntity cmmdtyEntity : cmmdtyList) { String cmmdtyCode = cmmdtyEntity.getCmmdtyCode(); // 商品价格获取 StoreCmmdtyPriceEntity priceEntity = getPriceByCmmdtyCode(cmmdtyCode, priceList); // 商品库存获取 InventoryEntity inventory = getInventoryByCmmdtyCode(cmmdtyCode, inventoryList); LOGGER.debug("插入Product数据,商品数据:{},价格数据:{},库存:{}", cmmdtyEntity, priceEntity, inventory); prep.setString(1, cmmdtyEntity.getCmmdtyCode()); prep.setString(2, cmmdtyEntity.getCommonSku()); prep.setString(3, cmmdtyEntity.getCommonSpu()); prep.setString(4, cmmdtyEntity.getCmmdtyDisplayName()); prep.setString(5, cmmdtyEntity.getBarCode()); prep.setString(6, cmmdtyEntity.getBrandName()); prep.setString(7, cmmdtyEntity.getBrandId().toString()); prep.setString(8, cmmdtyEntity.getMeasureUnit()); prep.setString(9, cmmdtyEntity.getSource()); prep.setString(10, ""); prep.setString(11, cmmdtyEntity.getImageCount() == null ? "" : cmmdtyEntity.getImageCount().toString()); prep.setString(12, ""); // 苏宁平台商品 String coverImgUrl; if ("0".equals(cmmdtyEntity.getSource())) { coverImgUrl = uimgServer + CommonUtils.getImageUrlFolder(CommonUtils.MAIN_SITE) + "0000000000-" + cmmdtyEntity.getSnCmmdtyCode() + "_1_200x200.jpg"; prep.setString(13, coverImgUrl); } else { coverImgUrl = uimgServer + CommonUtils.getImageUrlFolder(CommonUtils.SELF_SITE) + cmmdtyEntity.getCmmdtyCode() + "_1_200x200.jpg"; prep.setString(13, coverImgUrl); } prep.setString(14, ""); prep.setString(15, priceEntity.getRetailPrice() == null ? "" : priceEntity.getRetailPrice().toString()); prep.setString(16, priceEntity.getStoreMgrPrice() == null ? "" : priceEntity.getStoreMgrPrice() .toString()); prep.setString(17, priceEntity.getEmplPrice() == null ? "" : priceEntity.getEmplPrice().toString()); prep.setString(18, priceEntity.getRetailPriceLowest() == null ? "" : priceEntity.getRetailPriceLowest() .toString()); prep.setString(19, inventory.getQuantity() == null ? "" : inventory.getQuantity().toString()); prep.setString(20, ""); prep.addBatch(); } prep.executeBatch(); } catch (SQLException e) { LOGGER.error("PosCmmdtyBusiness.insertProductInfo error,", e); return FAIL; } finally { if (prep != null) { try { prep.close(); } catch (SQLException e) { LOGGER.error("PosCmmdtyBusiness.insertProductInfo error,", e); } } } return SUCCESS; }
阅读全文
0 0
- 关于生成POS端sqlLiteDB文件 实现全量同步
- 全量同步索引
- 中间表同步方案(全量,增量)
- 完成量实现线程同步
- Android下载apk全量更新实现
- Bugly实现app全量更新
- C# MVC 实现生成二维码条形码给予Pos核销
- jdbc操作 数据库同步,全量,加入线程,批处理
- Mysql全量数据同步Oracle步骤详解
- 增量and全量数据同步项目总结
- solr配置dataimport步骤 增量 全量同步配置
- Solr之Mysql数据库全量、增量同步-yellowcong
- 如何制作关于pos.txt序列的文件
- 大数据量同步方案之全量同步改为增量同步解决方案
- php生成百度换量 XML文件
- 【全量备份MySQL脚本】(生成5个备份)
- POS接入技术全接触
- 同步转异步+RPC的一个POS行业应用-关键技术实现
- SDL2.0 多线程使用信号量
- Java 中的一种更轻松的函数式编程途径
- 工具网站
- 错误处理技术
- ReactNative fetch 网络请求
- 关于生成POS端sqlLiteDB文件 实现全量同步
- cvs
- WebSocket 和socket、HTTP的区别和联系
- Java 根据Properties读写Properties配置文件
- 汇编-将数据区的字符串逆序输出
- Nginx 反向代理,负载均衡,动静分离配置
- 操作集合的工具类Collections
- 非结构化数据是什么
- 【模块】二维三点定位算法