@@ -2680,6 +2680,8 @@ public class QueryDB { | |||
return isSucess; | |||
} | |||
/** | |||
* 获取数据 | |||
* | |||
@@ -8,6 +8,7 @@ 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_GOODS; | |||
import com.bonait.bnframework.common.db.mode.BPA_GOODS_PROCESS_DETAIL; | |||
import com.bonait.bnframework.common.helper.Tools; | |||
import java.util.ArrayList; | |||
@@ -105,6 +106,38 @@ public class GoodsDBUtil { | |||
return QueryDB.Delete(BPA_GOODS.class, data.id); | |||
} | |||
public static boolean deleteByGoodsIds( List<String> list) { | |||
if(list.isEmpty()){ | |||
return true; | |||
} | |||
QueryDB.lock.lock(); | |||
SQLiteDatabase db = DBHelper.getInstance(ConfigName.getInstance().dishesCon).getWritableDatabase(); | |||
try { | |||
db.beginTransaction(); | |||
boolean isSuccess =true; | |||
for(int i = 0; i < list.size(); i++){ | |||
if (list.get(i).isEmpty()) | |||
return false; | |||
long delete = db.delete(BPA_GOODS.class.getSimpleName(), "id = ?", | |||
new String[]{list.get(i)}); | |||
if(delete<=0){ | |||
isSuccess = false; | |||
} | |||
} | |||
db.setTransactionSuccessful(); | |||
LogUtils.d("removeList 批量删除工序"); | |||
return isSuccess; | |||
} catch (Exception e) { | |||
LogUtils.d("goodsSubAttributeGroupId 批量删除异常"); | |||
} finally { | |||
db.endTransaction(); | |||
db.close(); | |||
QueryDB.lock.unlock(); | |||
} | |||
return false; | |||
} | |||
/** | |||
* 根据属性id删除商品数据 | |||
* | |||
@@ -224,6 +224,38 @@ public class GoodsProcessDetailDBUtil { | |||
return result; | |||
} | |||
public static boolean deleteByGoodsIds( List<String> list) { | |||
if(list.isEmpty()){ | |||
return true; | |||
} | |||
QueryDB.lock.lock(); | |||
SQLiteDatabase db = DBHelper.getInstance(ConfigName.getInstance().dishesCon).getWritableDatabase(); | |||
try { | |||
db.beginTransaction(); | |||
boolean isSuccess =true; | |||
for(int i = 0; i < list.size(); i++){ | |||
if (list.get(i).isEmpty()) | |||
return false; | |||
long delete = db.delete(BPA_GOODS_PROCESS_DETAIL.class.getSimpleName(), "goodsSubAttributeGroupId = ?", | |||
new String[]{list.get(i)}); | |||
if(delete<=0){ | |||
isSuccess = false; | |||
} | |||
} | |||
db.setTransactionSuccessful(); | |||
LogUtils.d("removeList 批量删除工序"); | |||
return isSuccess; | |||
} catch (Exception e) { | |||
LogUtils.d("goodsSubAttributeGroupId 批量删除异常"); | |||
} finally { | |||
db.endTransaction(); | |||
db.close(); | |||
QueryDB.lock.unlock(); | |||
} | |||
return false; | |||
} | |||
/** | |||
* 根据商品id删除配料信息 | |||
* | |||
@@ -145,6 +145,39 @@ public class SubAttributeGroupDBUtil { | |||
return result; | |||
} | |||
public static boolean deleteByGoodsIds( List<String> list) { | |||
if(list.isEmpty()){ | |||
return true; | |||
} | |||
QueryDB.lock.lock(); | |||
SQLiteDatabase db = DBHelper.getInstance(ConfigName.getInstance().dishesCon).getWritableDatabase(); | |||
try { | |||
db.beginTransaction(); | |||
boolean isSuccess =true; | |||
for(int i = 0; i < list.size(); i++){ | |||
if (list.get(i).isEmpty()) | |||
return false; | |||
long delete = db.delete(BPA_GOODS_SUBATTRIBUTE_GROUP.class.getSimpleName(), "goodsId = ?", | |||
new String[]{list.get(i)}); | |||
if(delete<=0){ | |||
isSuccess = false; | |||
} | |||
} | |||
db.setTransactionSuccessful(); | |||
LogUtils.d("removeList 批量删除工序"); | |||
return isSuccess; | |||
} catch (Exception e) { | |||
LogUtils.d("GoodsProcessDetailDBUtil 批量新增异常"); | |||
} finally { | |||
db.endTransaction(); | |||
db.close(); | |||
QueryDB.lock.unlock(); | |||
} | |||
return false; | |||
} | |||
/** | |||
* 删除子属性组合数据 | |||
* | |||
@@ -197,18 +197,25 @@ public class LocalGoodsFragment extends BaseFragment { | |||
} | |||
List<BPA_GOODS> res = goodsList.stream().filter(p->p.status==1).collect(Collectors.toList()); | |||
if(res!=null) { | |||
List<String> goodIds=new ArrayList<>(); | |||
res.forEach(bean->{ | |||
GoodsProcessDetailDBUtil.deleteByGoodsId(bean.id); | |||
SubAttributeGroupDBUtil.deleteByGoodsId(bean.id); | |||
if(GoodsDBUtil.delete(bean)){ | |||
NewToastUtil.getInstance().showToast("删除["+bean.name+"]成功!","Delete ["+bean.name+"] Success!"); | |||
goodsList.remove(bean); | |||
goodsAdapter.notifyDataSetChanged(); | |||
RecordManager.getInstance().addLogRecord("角色操作日志","删除["+bean.name+"]菜品成功!"); | |||
}else { | |||
NewToastUtil.getInstance().showToast("删除["+bean.name+"]失败!","Delete ["+bean.name+"] Fail!"); | |||
try{ | |||
goodIds.add(bean.id); | |||
goodsList.remove(bean); | |||
goodsAdapter.notifyDataSetChanged(); | |||
}catch (Exception e){ | |||
String error = e.getMessage(); | |||
} | |||
}); | |||
try{ | |||
GoodsProcessDetailDBUtil.deleteByGoodsIds(goodIds); | |||
SubAttributeGroupDBUtil. deleteByGoodsIds(goodIds); | |||
GoodsDBUtil. deleteByGoodsIds(goodIds); | |||
RecordManager.getInstance().addLogRecord("角色操作日志","删除所有菜品成功!"); | |||
}catch (Exception e){ | |||
RecordManager.getInstance().addLogRecord("角色操作日志","批量删除菜品失败!"); | |||
} | |||
} | |||
updateData(); | |||
RecordManager.getInstance().addLogRecord("角色操作日志","删除所有商品信息"); | |||