瀏覽代碼

优化同步数据时间

调味吧台
liup 5 月之前
父節點
當前提交
716810fbdd
共有 5 個文件被更改,包括 667 次插入130 次删除
  1. +174
    -127
      app/src/main/java/com/bonait/bnframework/HttpModel/APIService.java
  2. +366
    -0
      app/src/main/java/com/bonait/bnframework/common/db/ListAddUtil.java
  3. +100
    -1
      app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java
  4. +2
    -1
      app/src/main/java/com/bonait/bnframework/common/db/file/DBHelper.java
  5. +25
    -1
      app/src/main/java/com/bonait/bnframework/modules/home/fragment/GongnengFragment.java

+ 174
- 127
app/src/main/java/com/bonait/bnframework/HttpModel/APIService.java 查看文件

@@ -1,18 +1,22 @@
package com.bonait.bnframework.HttpModel;

import com.alibaba.fastjson.TypeReference;
import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.HBL.API.APIHelper;
import com.bonait.bnframework.HBL.API.APIResultT;
import com.bonait.bnframework.HBL.API.Utils;
import com.bonait.bnframework.MainApplication;
import com.bonait.bnframework.business.ConfigData;
import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.QueryDB;
import com.bonait.bnframework.common.db.file.DBHelper;
import com.bonait.bnframework.common.db.mode.BPA_GOODPROPERTY;
import com.bonait.bnframework.common.db.mode.BPA_GOODS;
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPENAME;
import com.bonait.bnframework.common.db.mode.BPA_GOODSTYPE;
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL;
import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS;

import java.util.ArrayList;
import java.util.List;
@@ -28,161 +32,200 @@ public class APIService {
return deviceGoodInfo;
}
public static MaterialData GetMaterialModels(){ return materialModels; }
private static long lastTime = System.currentTimeMillis();

public static void MainInit(){
Utils.disableSSLCertChecking();
CleanData();
GetMaterialInfo();
GetGoodsInfo();
// GetGoodsInfo();
}

private static void GetGoodsInfo(){
String autoKey = ConfigName.getInstance().DeviceAutoKey;
String url = "https://cfv.black-pa.com/kitchbase/api/goods/Getdevicegoods?deviceId="+autoKey;
long curTime = System.currentTimeMillis();
LogUtils.d(" GetGoodsInfo1 usetime="+(curTime-lastTime));
lastTime = curTime;
APIHelper.PostT(url,null,null,new TypeReference<APIResultT<List<DeviceGoodInfo>>>(){}).OnSource(s->{
long curTime2 = System.currentTimeMillis();
LogUtils.d(" GetGoodsInfo11 usetime="+(curTime2-lastTime));
lastTime = curTime2;
deviceGoodInfo=s.Content;
UpdateLocalGoodsInfo();
});
curTime = System.currentTimeMillis();
LogUtils.d(" GetGoodsInfo2 usetime="+(curTime-lastTime));
lastTime = curTime;
}

private static void GetMaterialInfo(){
String url = "https://cfv.black-pa.com/saasbase/api/ExternalPlatform/Material/GetMaterialPageList";
String key ="2c39bc05-25c2-46c4-b5c6-dba349058492";
long curTime = System.currentTimeMillis();
LogUtils.d(" GetMaterialInfo1 usetime="+(curTime-lastTime));
lastTime = curTime;
APIHelper.PostT(url,new MaterialRequestPar(1,100),key,new TypeReference<APIResultT<MaterialData>>(){}).OnSource(s->{
long curTime2 = System.currentTimeMillis();
LogUtils.d(" GetMaterialInfo11 usetime="+(curTime2-lastTime));
lastTime = curTime2;
materialModels=s.Content;
UpdateLocalMaterial();
});
curTime = System.currentTimeMillis();
LogUtils.d(" GetMaterialInfo2 usetime="+(curTime-lastTime));
lastTime = curTime;
}

private static void CleanData(){
List<BPA_MATERIAL> materials = QueryDB.GetMaterialALL();
materials.forEach(data->{QueryDB.DeleteMaterial(data);});

List<BPA_GOODS> goods = QueryDB.GetGoodsALL();//获取所有商品
goods.forEach(data->{QueryDB.DeleteGoods(data);});

List<BPA_GOODSRECIPE> goodSrecipes= QueryDB.GetGoodsSrecipeALL();
goodSrecipes.forEach(data->{QueryDB.DeleteGoodsSrecipe(data);});
long curTime = System.currentTimeMillis();
LogUtils.d(" CleanData1 usetime="+(curTime-lastTime));
lastTime = curTime;

List<BPA_GOODSTYPE> goodTypes = QueryDB.GetGoodsTypeALL();//获取所有商品分类
goodTypes.forEach(data->{QueryDB.DeleteGoodsType(data);});
DBHelper.getInstance(MainApplication.getContext()).DeleteCreateTables(BPA_MATERIAL.class,"id");
DBHelper.getInstance(MainApplication.getContext()).DeleteCreateTables(BPA_GOODS.class,null);
DBHelper.getInstance(MainApplication.getContext()).DeleteCreateTables(BPA_GOODSRECIPE.class,null);
DBHelper.getInstance(MainApplication.getContext()).DeleteCreateTables(BPA_GOODSTYPE.class,null);
DBHelper.getInstance(MainApplication.getContext()).DeleteCreateTables(BPA_GOODPROPERTY.class,null);
DBHelper.getInstance(MainApplication.getContext()).DeleteCreateTables(BPA_GOODSRECIPENAME.class,null);

List<BPA_GOODPROPERTY> goodProperties = QueryDB.GetGoodsSubPropertyALL();//获取所有规格
goodProperties.forEach(data->{ QueryDB.DeleteGoodsProperty(data);});
// List<BPA_MATERIAL> materials = QueryDB.GetMaterialALL();
// materials.forEach(data->{QueryDB.DeleteMaterial(data);});

List<BPA_GOODSRECIPENAME> goodReciepeNames = QueryDB.GetGoodsSrecipeNameALL();//获取所有配方信息
goodReciepeNames.forEach(data->{QueryDB.DeleteGoodsRecipeName(data);});
// List<BPA_GOODS> goods = QueryDB.GetGoodsALL();//获取所有商品
// goods.forEach(data->{QueryDB.DeleteGoods(data);});
//
// List<BPA_GOODSRECIPE> goodSrecipes= QueryDB.GetGoodsSrecipeALL();
// goodSrecipes.forEach(data->{QueryDB.DeleteGoodsSrecipe(data);});
//
// List<BPA_GOODSTYPE> goodTypes = QueryDB.GetGoodsTypeALL();//获取所有商品分类
// goodTypes.forEach(data->{QueryDB.DeleteGoodsType(data);});
//
// List<BPA_GOODPROPERTY> goodProperties = QueryDB.GetGoodsSubPropertyALL();//获取所有规格
// goodProperties.forEach(data->{ QueryDB.DeleteGoodsProperty(data);});
//
// List<BPA_GOODSRECIPENAME> goodReciepeNames = QueryDB.GetGoodsSrecipeNameALL();//获取所有配方信息
// goodReciepeNames.forEach(data->{QueryDB.DeleteGoodsRecipeName(data);});
curTime = System.currentTimeMillis();
LogUtils.d(" CleanData2 usetime="+(curTime-lastTime));
lastTime = curTime;
}

private static void UpdateLocalMaterial(){
long curTime = System.currentTimeMillis();
LogUtils.d(" UpdateLocalMaterial1 usetime="+(curTime-lastTime));
lastTime = curTime;
List<BPA_MATERIAL> datas = new ArrayList<>();
materialModels.data.forEach(item->{
if(item.name!=null){
BPA_MATERIAL bpa_material =new BPA_MATERIAL();
bpa_material.name = item.name;
bpa_material.id = item.id;
QueryDB.AddMaterial(bpa_material);
datas.add(bpa_material);
}
});
QueryDB.AddMaterialList(datas);

LogUtils.d(" UpdateLocalMaterial2 usetime="+(curTime-lastTime));
lastTime = curTime;
GetGoodsInfo();
}

private static void UpdateLocalGoodsInfo(){
List<BPA_GOODS> goods = QueryDB.GetGoodsALL();//获取所有商品
List<BPA_GOODSTYPE> goodTypes = QueryDB.GetGoodsTypeALL();//获取所有商品分类
List<BPA_GOODPROPERTY> goodProperties = QueryDB.GetGoodsPropertyALL();//获取所有规格
List<BPA_GOODSRECIPENAME> goodReciepeNames = QueryDB.GetGoodsSrecipeNameALL();//获取所有配方信息
deviceGoodInfo.forEach(item->{
long curTime = System.currentTimeMillis();
LogUtils.d(" UpdateLocalGoodsInfo1 usetime="+(curTime-lastTime));
lastTime = curTime;
// List<BPA_GOODS> goods = QueryDB.GetGoodsALL();//获取所有商品
// List<BPA_GOODSTYPE> goodTypes = QueryDB.GetGoodsTypeALL();//获取所有商品分类
// List<BPA_GOODPROPERTY> goodProperties = QueryDB.GetGoodsPropertyALL();//获取所有规格
// List<BPA_GOODSRECIPENAME> goodReciepeNames = QueryDB.GetGoodsSrecipeNameALL();//获取所有配方信息
GoodTypeSynchronous();
GoodPropSynchronous();//同步云端商品属性
GoodInfoSynchronous();//同步云端商品信息
GoodRecipeSynchronous();

GoodTypeSynchronous(item);//同步云端商品分类信息

GoodPropSynchronous(item.goodsTypeId,item.goodsAttributeList);//同步云端商品属性

GoodInfoSynchronous(item,goods);//同步云端商品信息

GoodRecipeSynchronous(item,goodReciepeNames);
});
curTime = System.currentTimeMillis();
LogUtils.d(" UpdateLocalGoodsInfo3 usetime="+(curTime-lastTime));
lastTime = curTime;
}

/**
* 同步云端商品分类到本地
* @param item
*/
private static void GoodTypeSynchronous(DeviceGoodInfo item){
BPA_GOODSTYPE bpa_goodstype = new BPA_GOODSTYPE();
bpa_goodstype.name = item.goodsTypeName;
bpa_goodstype.id = item.goodsTypeId;
bpa_goodstype.userID="超级管理员";
QueryDB.AddGoodsType(bpa_goodstype);
private static void GoodTypeSynchronous(){
List<BPA_GOODSTYPE> datas = new ArrayList<>();
for(DeviceGoodInfo item : deviceGoodInfo){
BPA_GOODSTYPE bpa_goodstype = new BPA_GOODSTYPE();
bpa_goodstype.name = item.goodsTypeName;
bpa_goodstype.id = item.goodsTypeId;
bpa_goodstype.userID="超级管理员";
datas.add(bpa_goodstype);
}
QueryDB.AddGoodsTypeList(datas);
}

/**
* 同步云端商品属性到本地
* @param goodsAttributeList
*/
private static void GoodPropSynchronous(String goodsTypeId, List<GoodsAttributeList> goodsAttributeList){
if(goodsAttributeList==null){
return;
}
for(int n=0;n<goodsAttributeList.size();n++){
//属性添加
BPA_GOODPROPERTY bpa_goodproperty = new BPA_GOODPROPERTY();
bpa_goodproperty.name = goodsAttributeList.get(n).goodsAttributeName;
bpa_goodproperty.parentid ="0";
bpa_goodproperty.sort =n+1;
bpa_goodproperty.id = goodsAttributeList.get(n).goodsAttributeId;
bpa_goodproperty.userID="超级管理员";
bpa_goodproperty.GoodsTypeId=goodsTypeId;
QueryDB.AddGoodsProperty(bpa_goodproperty);

//子属性添加
if(goodsAttributeList.get(n).goodsAttributeValueList!=null){
for(int i=0;i<goodsAttributeList.get(n).goodsAttributeValueList.size();i++){
BPA_GOODPROPERTY bpa_goodpropertySub = new BPA_GOODPROPERTY();
bpa_goodpropertySub.name = goodsAttributeList.get(n).goodsAttributeValueList.get(i).attributeValue;
bpa_goodpropertySub.parentid = goodsAttributeList.get(n).goodsAttributeId;
bpa_goodpropertySub.id = goodsAttributeList.get(n).goodsAttributeValueList.get(i).goodsAttributeValueId;
bpa_goodpropertySub.sort = i+1;
private static void GoodPropSynchronous(){
List<BPA_GOODPROPERTY> datas = new ArrayList<>();
for(DeviceGoodInfo item : deviceGoodInfo){
if(item.goodsAttributeList!=null){
for(int n=0;n<item.goodsAttributeList.size();n++){
//属性添加
BPA_GOODPROPERTY bpa_goodproperty = new BPA_GOODPROPERTY();
bpa_goodproperty.name = item.goodsAttributeList.get(n).goodsAttributeName;
bpa_goodproperty.parentid ="0";
bpa_goodproperty.sort =n+1;
bpa_goodproperty.id = item.goodsAttributeList.get(n).goodsAttributeId;
bpa_goodproperty.userID="超级管理员";
QueryDB.AddGoodsProperty(bpa_goodpropertySub);
bpa_goodproperty.GoodsTypeId=item.goodsTypeId;
datas.add(bpa_goodproperty);

//子属性添加
if(item.goodsAttributeList.get(n).goodsAttributeValueList!=null){
for(int i=0;i<item.goodsAttributeList.get(n).goodsAttributeValueList.size();i++){
BPA_GOODPROPERTY bpa_goodpropertySub = new BPA_GOODPROPERTY();
bpa_goodpropertySub.name = item.goodsAttributeList.get(n).goodsAttributeValueList.get(i).attributeValue;
bpa_goodpropertySub.parentid = item.goodsAttributeList.get(n).goodsAttributeId;
bpa_goodpropertySub.id = item.goodsAttributeList.get(n).goodsAttributeValueList.get(i).goodsAttributeValueId;
bpa_goodpropertySub.sort = i+1;
bpa_goodpropertySub.userID="超级管理员";
datas.add(bpa_goodpropertySub);
}
}
}
}

}
QueryDB.AddGoodsPropertyList(datas);
}

/**
* 同步云端商品信息到本地
* @param item
* @param goods
*/
private static void GoodInfoSynchronous(DeviceGoodInfo item,List<BPA_GOODS> goods){
if(item.goodsInfoList!=null){
for(int i=0;i<item.goodsInfoList.size();i++){
BPA_GOODS bpa_goods =new BPA_GOODS();
bpa_goods.id = item.goodsInfoList.get(i).goodsId;
bpa_goods.name = item.goodsInfoList.get(i).goodsName;
bpa_goods.materialids = getMaterialids(item.goodsInfoList.get(i));
bpa_goods.goodtype=item.goodsTypeId;
bpa_goods.status=1;
bpa_goods.issc=1;
bpa_goods.maketime=180;
bpa_goods.url=item.goodsInfoList.get(i).imgUrl==null?"":item.goodsInfoList.get(i).imgUrl;
bpa_goods.sort= i+1;
bpa_goods.foreignKeyRe="";
QueryDB.AddGoods(bpa_goods);
private static void GoodInfoSynchronous(){
List<BPA_GOODS> datas = new ArrayList<>();
for(DeviceGoodInfo item : deviceGoodInfo){
if(item.goodsInfoList!=null){
for(int i=0;i<item.goodsInfoList.size();i++){
BPA_GOODS bpa_goods =new BPA_GOODS();
bpa_goods.id = item.goodsInfoList.get(i).goodsId;
bpa_goods.name = item.goodsInfoList.get(i).goodsName;
bpa_goods.materialids = getMaterialids(item.goodsInfoList.get(i));
bpa_goods.goodtype=item.goodsTypeId;
bpa_goods.status=1;
bpa_goods.issc=1;
bpa_goods.maketime = 180;
bpa_goods.url=item.goodsInfoList.get(i).imgUrl==null?"":item.goodsInfoList.get(i).imgUrl;
bpa_goods.sort= i+1;
bpa_goods.foreignKeyRe="";
datas.add(bpa_goods);
}
}
// item.goodsInfoList.forEach(goodinfo->{
// BPA_GOODS bpa_goods =new BPA_GOODS();
// bpa_goods.id = goodinfo.goodsId;
// bpa_goods.name = goodinfo.goodsName;
// bpa_goods.materialids = getMaterialids(goodinfo);
// bpa_goods.goodtype=item.goodsTypeId;
// bpa_goods.status=1;
// bpa_goods.issc=1;
// bpa_goods.maketime=180;
// bpa_goods.url="";
// bpa_goods.foreignKeyRe="";
// QueryDB.AddGoods(bpa_goods);
// });
}
QueryDB.AddGoodsList(datas);

}

/**
@@ -206,49 +249,53 @@ public class APIService {

/**
* 同步云端配方详细信息到本地
* @param item
* @param goodReciepeNames
*/
private static void GoodRecipeSynchronous(DeviceGoodInfo item,List<BPA_GOODSRECIPENAME> goodReciepeNames) {
if(item.goodsInfoList!=null){
List<BPA_GOODPROPERTY> goodProps = QueryDB.GetGoodsSubPropertyALL();
List<BPA_MATERIAL> bpaMaterials = QueryDB.GetMaterialALL();
item.goodsInfoList.forEach(goodinfo->{
ConcurrentHashMap<String,List<GoodsTechnologyActionList>> recipes = new ConcurrentHashMap<>();
goodinfo.goodsTechnologyActionList.forEach(material->{
if(!recipes.containsKey(material.goodsAttributeId))recipes.put(material.goodsAttributeId,new ArrayList<>());
recipes.get(material.goodsAttributeId).add(material);
});
private static void GoodRecipeSynchronous() {
List<BPA_GOODSRECIPENAME> datas1 = new ArrayList<>();
List<BPA_GOODSRECIPE> datas2 = new ArrayList<>();
for(DeviceGoodInfo item : deviceGoodInfo){
if(item.goodsInfoList!=null){
List<BPA_GOODPROPERTY> goodProps = QueryDB.GetGoodsSubPropertyALL();
List<BPA_MATERIAL> bpaMaterials = QueryDB.GetMaterialALL();
item.goodsInfoList.forEach(goodinfo->{
ConcurrentHashMap<String,List<GoodsTechnologyActionList>> recipes = new ConcurrentHashMap<>();
goodinfo.goodsTechnologyActionList.forEach(material->{
if(!recipes.containsKey(material.goodsAttributeId))recipes.put(material.goodsAttributeId,new ArrayList<>());
recipes.get(material.goodsAttributeId).add(material);
});

recipes.forEach((key,value)->{
//添加配方
BPA_GOODSRECIPENAME bpa_goodsrecipename = new BPA_GOODSRECIPENAME();
bpa_goodsrecipename.name =GetRecipeName(goodinfo.goodsName, value.get(0).goodsAttributeId,goodProps);
bpa_goodsrecipename.goodsID= goodinfo.goodsId;
bpa_goodsrecipename.design=key;
QueryDB.AddGoodsRecipeName(bpa_goodsrecipename);
recipes.forEach((key,value)->{
//添加配方
BPA_GOODSRECIPENAME bpa_goodsrecipename = new BPA_GOODSRECIPENAME();
bpa_goodsrecipename.name =GetRecipeName(goodinfo.goodsName, value.get(0).goodsAttributeId,goodProps);
bpa_goodsrecipename.goodsID= goodinfo.goodsId;
bpa_goodsrecipename.design=key;
datas1.add(bpa_goodsrecipename);

//遍历工艺步骤
value.forEach(material->{
material.GetFuncModel().OnSource(action->{
FuncModel func= action.Content.stream().filter(p->p.actionName.equals("主料名称")).findFirst().get();
BPA_MATERIAL bpaMaterial= bpaMaterials.stream().filter(p->p.name.equals(func.actionValue)).findFirst().get();
FuncModel weight= action.Content.stream().filter(p->p.actionName.equals("主料重量")).findFirst().get();
FuncModel sort= action.Content.stream().filter(p->p.actionName.equals("执行步骤")).findFirst().get();
if(bpaMaterial!=null){
BPA_GOODSRECIPE bpa_goodsrecipe = new BPA_GOODSRECIPE();
bpa_goodsrecipe.goodsID = goodinfo.goodsId;
bpa_goodsrecipe.materialID = bpaMaterial.id;
bpa_goodsrecipe.value =weight.actionValue;
bpa_goodsrecipe.sort = Integer.parseInt(sort.actionValue);
bpa_goodsrecipe.recipeID=bpa_goodsrecipename.id;
QueryDB.AddGoodsSrecipe(bpa_goodsrecipe);
}
//遍历工艺步骤
value.forEach(material->{
material.GetFuncModel().OnSource(action->{
FuncModel func= action.Content.stream().filter(p->p.actionName.equals("主料名称")).findFirst().get();
BPA_MATERIAL bpaMaterial= bpaMaterials.stream().filter(p->p.name.equals(func.actionValue)).findFirst().get();
FuncModel weight= action.Content.stream().filter(p->p.actionName.equals("主料重量")).findFirst().get();
FuncModel sort= action.Content.stream().filter(p->p.actionName.equals("执行步骤")).findFirst().get();
if(bpaMaterial!=null){
BPA_GOODSRECIPE bpa_goodsrecipe = new BPA_GOODSRECIPE();
bpa_goodsrecipe.goodsID = goodinfo.goodsId;
bpa_goodsrecipe.materialID = bpaMaterial.id;
bpa_goodsrecipe.value =weight.actionValue;
bpa_goodsrecipe.sort = Integer.parseInt(sort.actionValue);
bpa_goodsrecipe.recipeID=bpa_goodsrecipename.id;
datas2.add(bpa_goodsrecipe);
}
});
});
});
});
});
}
}
QueryDB.AddGoodsRecipeNameList(datas1);
QueryDB.AddGoodsSrecipeList(datas2);
}

/**


+ 366
- 0
app/src/main/java/com/bonait/bnframework/common/db/ListAddUtil.java 查看文件

@@ -0,0 +1,366 @@
package com.bonait.bnframework.common.db;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;

import com.bonait.bnframework.common.db.mode.BPA_GOODPROPERTY;
import com.bonait.bnframework.common.db.mode.BPA_GOODS;
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE;
import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPENAME;
import com.bonait.bnframework.common.db.mode.BPA_GOODSTYPE;
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL;
import com.bonait.bnframework.common.helper.Tools;

import java.util.List;
import java.util.Map;

/**
* @author: liup
* @description:
* @date: 2024/5/24 16:20.
*/
public class ListAddUtil {
/**
* 批量新增
* @param c
* @param list
* @return
*/
public static boolean AddGOODSTYPEList(Class c, List<BPA_GOODSTYPE> list) {
if(list.isEmpty()){
return false;
}
QueryDB.lock.lock();
boolean isSucess = false;
SQLiteDatabase db = QueryDB.helper.getWritableDatabase();
try {
long insert=-1;
db.beginTransaction();
for(int i = 0; i < list.size(); i++){
ContentValues cv = new ContentValues();

Map<String, Object> map = Tools.getObjValue(list.get(i));
if (map.get("id").toString().isEmpty())
return false;
for (String key : map.keySet()) {
Object value = map.get(key);
if (value instanceof String) {
cv.put(key, (String) value);
} else if (value instanceof Integer) {
cv.put(key, ((Integer) value).intValue());
} else if (value instanceof Double) {
cv.put(key, ((Double) value).doubleValue());
} else if (value instanceof Float) {
cv.put(key, ((Float) value).floatValue());
} else if (value instanceof Long) {
cv.put(key, ((Long) value).longValue());
} else if (value instanceof Boolean) {
cv.put(key, ((Boolean) value).booleanValue());
}
}
insert = db.insertOrThrow(c.getSimpleName(), null, cv);
if (insert == -1) {
throw new Exception("Failed to insert data at index " + i);
}
}

db.setTransactionSuccessful();

isSucess = insert > 0;
} catch (Exception e) {
// db.close();
isSucess = false;
} finally {
db.endTransaction();
db.close();
QueryDB.lock.unlock();
}
return isSucess;
}

/**
* 批量新增
* @param c
* @param list
* @return
*/
public static boolean AddMATERIALList(Class c, List<BPA_MATERIAL> list) {
if(list.isEmpty()){
return false;
}
QueryDB.lock.lock();
boolean isSucess = false;
SQLiteDatabase db = QueryDB.helper.getWritableDatabase();
try {
long insert=-1;
db.beginTransaction();
for(int i = 0; i < list.size(); i++){
ContentValues cv = new ContentValues();

Map<String, Object> map = Tools.getObjValue(list.get(i));
if (map.get("id").toString().isEmpty())
return false;
for (String key : map.keySet()) {
Object value = map.get(key);
if (value instanceof String) {
cv.put(key, (String) value);
} else if (value instanceof Integer) {
cv.put(key, ((Integer) value).intValue());
} else if (value instanceof Double) {
cv.put(key, ((Double) value).doubleValue());
} else if (value instanceof Float) {
cv.put(key, ((Float) value).floatValue());
} else if (value instanceof Long) {
cv.put(key, ((Long) value).longValue());
} else if (value instanceof Boolean) {
cv.put(key, ((Boolean) value).booleanValue());
}
}
insert = db.insertOrThrow(c.getSimpleName(), null, cv);
if (insert == -1) {
throw new Exception("Failed to insert data at index " + i);
}
}

db.setTransactionSuccessful();

isSucess = insert > 0;
} catch (Exception e) {
// db.close();
isSucess = false;
} finally {
db.endTransaction();
db.close();
QueryDB.lock.unlock();
}
return isSucess;
}
/**
* 批量新增
* @param c
* @param list
* @return
*/
public static boolean AddGoodsPropertyList(Class c, List<BPA_GOODPROPERTY> list) {
if(list.isEmpty()){
return false;
}
QueryDB.lock.lock();
boolean isSucess = false;
SQLiteDatabase db = QueryDB.helper.getWritableDatabase();
try {
long insert=-1;
db.beginTransaction();
for(int i = 0; i < list.size(); i++){
ContentValues cv = new ContentValues();

Map<String, Object> map = Tools.getObjValue(list.get(i));
if (map.get("id").toString().isEmpty())
return false;
for (String key : map.keySet()) {
Object value = map.get(key);
if (value instanceof String) {
cv.put(key, (String) value);
} else if (value instanceof Integer) {
cv.put(key, ((Integer) value).intValue());
} else if (value instanceof Double) {
cv.put(key, ((Double) value).doubleValue());
} else if (value instanceof Float) {
cv.put(key, ((Float) value).floatValue());
} else if (value instanceof Long) {
cv.put(key, ((Long) value).longValue());
} else if (value instanceof Boolean) {
cv.put(key, ((Boolean) value).booleanValue());
}
}
insert = db.insertOrThrow(c.getSimpleName(), null, cv);
if (insert == -1) {
throw new Exception("Failed to insert data at index " + i);
}
}

db.setTransactionSuccessful();

isSucess = insert > 0;
} catch (Exception e) {
// db.close();
isSucess = false;
} finally {
db.endTransaction();
db.close();
QueryDB.lock.unlock();
}
return isSucess;
}
/**
* 批量新增
* @param c
* @param list
* @return
*/
public static boolean AddGoodsList(Class c, List<BPA_GOODS> list) {
if(list.isEmpty()){
return false;
}
QueryDB.lock.lock();
boolean isSucess = false;
SQLiteDatabase db = QueryDB.helper.getWritableDatabase();
try {
long insert=-1;
db.beginTransaction();
for(int i = 0; i < list.size(); i++){
ContentValues cv = new ContentValues();

Map<String, Object> map = Tools.getObjValue(list.get(i));
if (map.get("id").toString().isEmpty())
return false;
for (String key : map.keySet()) {
Object value = map.get(key);
if (value instanceof String) {
cv.put(key, (String) value);
} else if (value instanceof Integer) {
cv.put(key, ((Integer) value).intValue());
} else if (value instanceof Double) {
cv.put(key, ((Double) value).doubleValue());
} else if (value instanceof Float) {
cv.put(key, ((Float) value).floatValue());
} else if (value instanceof Long) {
cv.put(key, ((Long) value).longValue());
} else if (value instanceof Boolean) {
cv.put(key, ((Boolean) value).booleanValue());
}
}
insert = db.insertOrThrow(c.getSimpleName(), null, cv);
if (insert == -1) {
throw new Exception("Failed to insert data at index " + i);
}
}

db.setTransactionSuccessful();

isSucess = insert > 0;
} catch (Exception e) {
// db.close();
isSucess = false;
} finally {
db.endTransaction();
db.close();
QueryDB.lock.unlock();
}
return isSucess;
}
/**
* 批量新增
* @param c
* @param list
* @return
*/
public static boolean AddGoodsRecipeNameList(Class c, List<BPA_GOODSRECIPENAME> list) {
if(list.isEmpty()){
return false;
}
QueryDB.lock.lock();
boolean isSucess = false;
SQLiteDatabase db = QueryDB.helper.getWritableDatabase();
try {
long insert=-1;
db.beginTransaction();
for(int i = 0; i < list.size(); i++){
ContentValues cv = new ContentValues();

Map<String, Object> map = Tools.getObjValue(list.get(i));
if (map.get("id").toString().isEmpty())
return false;
for (String key : map.keySet()) {
Object value = map.get(key);
if (value instanceof String) {
cv.put(key, (String) value);
} else if (value instanceof Integer) {
cv.put(key, ((Integer) value).intValue());
} else if (value instanceof Double) {
cv.put(key, ((Double) value).doubleValue());
} else if (value instanceof Float) {
cv.put(key, ((Float) value).floatValue());
} else if (value instanceof Long) {
cv.put(key, ((Long) value).longValue());
} else if (value instanceof Boolean) {
cv.put(key, ((Boolean) value).booleanValue());
}
}
insert = db.insertOrThrow(c.getSimpleName(), null, cv);
if (insert == -1) {
throw new Exception("Failed to insert data at index " + i);
}
}

db.setTransactionSuccessful();

isSucess = insert > 0;
} catch (Exception e) {
// db.close();
isSucess = false;
} finally {
db.endTransaction();
db.close();
QueryDB.lock.unlock();
}
return isSucess;
}
/**
* 批量新增
* @param c
* @param list
* @return
*/
public static boolean AddGoodsSrecipeList(Class c, List<BPA_GOODSRECIPE> list) {
if(list.isEmpty()){
return false;
}
QueryDB.lock.lock();
boolean isSucess = false;
SQLiteDatabase db = QueryDB.helper.getWritableDatabase();
try {
long insert=-1;
db.beginTransaction();
for(int i = 0; i < list.size(); i++){
ContentValues cv = new ContentValues();

Map<String, Object> map = Tools.getObjValue(list.get(i));
if (map.get("id").toString().isEmpty())
return false;
for (String key : map.keySet()) {
Object value = map.get(key);
if (value instanceof String) {
cv.put(key, (String) value);
} else if (value instanceof Integer) {
cv.put(key, ((Integer) value).intValue());
} else if (value instanceof Double) {
cv.put(key, ((Double) value).doubleValue());
} else if (value instanceof Float) {
cv.put(key, ((Float) value).floatValue());
} else if (value instanceof Long) {
cv.put(key, ((Long) value).longValue());
} else if (value instanceof Boolean) {
cv.put(key, ((Boolean) value).booleanValue());
}
}
insert = db.insertOrThrow(c.getSimpleName(), null, cv);
if (insert == -1) {
throw new Exception("Failed to insert data at index " + i);
}
}

db.setTransactionSuccessful();

isSucess = insert > 0;
} catch (Exception e) {
// db.close();
isSucess = false;
} finally {
db.endTransaction();
db.close();
QueryDB.lock.unlock();
}
return isSucess;
}
}

+ 100
- 1
app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java 查看文件

@@ -47,6 +47,7 @@ import com.bonait.bnframework.common.utils.PreferenceUtils;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -73,7 +74,7 @@ public class QueryDB {
/**
* 数据库链接
*/
private static DBHelper helper = DBHelper.getInstance(ConfigName.getInstance().dishesCon);
public static DBHelper helper = DBHelper.getInstance(ConfigName.getInstance().dishesCon);

/**
* 时间倒序
@@ -108,6 +109,11 @@ public class QueryDB {
return Add(BPA_MATERIAL.class, data);
}

public static boolean AddMaterialList(List<BPA_MATERIAL> data) {

return ListAddUtil.AddMATERIALList(BPA_MATERIAL.class, data);
}

/**
* 修改物料数据
* add fengyoufu 20230413
@@ -723,6 +729,13 @@ public class QueryDB {
return Add(BPA_GOODS.class, data);
}

/**
* 新增商品表
*/
public static boolean AddGoodsList(List<BPA_GOODS> data) {
return ListAddUtil.AddGoodsList(BPA_GOODS.class, data);
}

/**
* 修改商品
* add fengyoufu 20230413
@@ -1011,6 +1024,17 @@ public class QueryDB {
return Add(BPA_GOODSTYPE.class, data);
}

/**
* 新增
* add fengyoufu 20230413
*
* @param data
* @return 是否成功
*/
public static boolean AddGoodsTypeList(List<BPA_GOODSTYPE> data) {
return ListAddUtil.AddGOODSTYPEList(BPA_GOODSTYPE.class, data);
}

/**
* 修改
* add fengyoufu 20230413
@@ -1082,6 +1106,15 @@ public class QueryDB {
return Add(BPA_GOODPROPERTY.class, data);
}

/**
* 批量新增
* @param data
* @return
*/
public static boolean AddGoodsPropertyList(List<BPA_GOODPROPERTY> data) {
return ListAddUtil.AddGoodsPropertyList(BPA_GOODPROPERTY.class, data);
}

/**
* 修改
* add fengyoufu 20230413
@@ -1243,6 +1276,10 @@ public class QueryDB {
return Add(BPA_GOODSRECIPENAME.class, data);
}

public static boolean AddGoodsRecipeNameList(List<BPA_GOODSRECIPENAME> data) {
return ListAddUtil.AddGoodsRecipeNameList(BPA_GOODSRECIPENAME.class, data);
}

/**
* 修改
* add fengyoufu 20230413
@@ -1413,6 +1450,10 @@ public class QueryDB {
return Add(BPA_GOODSRECIPE.class, data);
}

public static boolean AddGoodsSrecipeList(List<BPA_GOODSRECIPE> data) {
return ListAddUtil.AddGoodsSrecipeList(BPA_GOODSRECIPE.class, data);
}

/**
* 修改商品配方明细
* add fengyoufu 20230413
@@ -3267,6 +3308,64 @@ public class QueryDB {
return isSucess;
}

/**
* 批量新增
* @param c
* @param list
* @return
*/
private static boolean AddList(Class c, List<Object> list) {
if(list.isEmpty()){
return false;
}
lock.lock();
boolean isSucess = false;
SQLiteDatabase db = helper.getWritableDatabase();
try {
long insert=-1;
db.beginTransaction();
for(int i = 0; i < list.size(); i++){
ContentValues cv = new ContentValues();

Map<String, Object> map = Tools.getObjValue(list.get(i));
if (map.get("id").toString().isEmpty())
return false;
for (String key : map.keySet()) {
Object value = map.get(key);
if (value instanceof String) {
cv.put(key, (String) value);
} else if (value instanceof Integer) {
cv.put(key, ((Integer) value).intValue());
} else if (value instanceof Double) {
cv.put(key, ((Double) value).doubleValue());
} else if (value instanceof Float) {
cv.put(key, ((Float) value).floatValue());
} else if (value instanceof Long) {
cv.put(key, ((Long) value).longValue());
} else if (value instanceof Boolean) {
cv.put(key, ((Boolean) value).booleanValue());
}
}
insert = db.insertOrThrow(c.getSimpleName(), null, cv);
if (insert == -1) {
throw new Exception("Failed to insert data at index " + i);
}
}

db.setTransactionSuccessful();

isSucess = insert > 0;
} catch (Exception e) {
// db.close();
isSucess = false;
} finally {
db.endTransaction();
db.close();
lock.unlock();
}
return isSucess;
}

/**
* 修改
*


+ 2
- 1
app/src/main/java/com/bonait/bnframework/common/db/file/DBHelper.java 查看文件

@@ -140,7 +140,7 @@ public class DBHelper extends SQLiteOpenHelper {
* 创建数据库表
* @param c
*/
private void CreateTablesAll(Class c,String premarykey)
public void CreateTablesAll(Class c,String premarykey)
{
if (premarykey == null){

@@ -243,6 +243,7 @@ public class DBHelper extends SQLiteOpenHelper {
}
db.setTransactionSuccessful();
db.endTransaction();
db.close();
}
/**


+ 25
- 1
app/src/main/java/com/bonait/bnframework/modules/home/fragment/GongnengFragment.java 查看文件

@@ -12,8 +12,10 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;

import com.apkfuns.logutils.LogUtils;
import com.bonait.bnframework.HBL.Dialog.AlertDialogButton;
import com.bonait.bnframework.HBL.Dialog.DialogManager;
import com.bonait.bnframework.HBL.Dialog.WaitDialog;
import com.bonait.bnframework.HBL.Thread.ThreadManager;
import com.bonait.bnframework.HttpModel.APIService;
import com.bonait.bnframework.R;
@@ -33,6 +35,8 @@ import com.orhanobut.logger.Logger;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
@@ -73,11 +77,11 @@ public class GongnengFragment extends BaseFragment {
btn_Sync.setOnClickListener(v->{
DialogManager.showWarn(context,"同步云端商品会参数本地所有配方数据,\r\n请问是否继续?", AlertDialogButton.YesNo,(s)->{
if(s){
WaitDialog.getInstance().Show("同步数据","请耐心等待,不要关闭应用",getContext(),getActivity());
ThreadManager.get().execute(new Runnable() {
@Override
public void run() {
APIService.MainInit();
ToastUtils.info("同步成功");
EventBus.getDefault().post(new SynchronousCloudDataEvent());
}
});
@@ -117,6 +121,26 @@ public class GongnengFragment extends BaseFragment {
Logger.d("第一页销毁");
}

@Override
public void onResume() {
super.onResume();
LogUtils.d("gongnengfragment onResume");
EventBus.getDefault().register(this);
}

@Override
public void onPause() {
super.onPause();
LogUtils.d("gongnengfragment onPause");
EventBus.getDefault().unregister(this);
}

@Subscribe(threadMode = ThreadMode.MAIN)
public void onSynchronousCloudDataEvent(SynchronousCloudDataEvent event) {
WaitDialog.getInstance().Dismiss();
ToastUtils.info("同步完成");
}

/**
* 当在activity设置viewPager + BottomNavigation + fragment时,
* 为防止viewPager左滑动切换界面,与fragment左滑返回上一界面冲突引起闪退问题,


Loading…
取消
儲存