package com.bonait.bnframework.common.db;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.bonait.bnframework.common.constant.ConfigName;
import com.bonait.bnframework.common.db.file.DBHelper;
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL;
import com.bonait.bnframework.common.db.file.DBHelper;
import com.bonait.bnframework.common.db.mode.BPA_ALERTLOG;
import com.bonait.bnframework.common.db.mode.BPA_CRAFT;
import com.bonait.bnframework.common.db.mode.BPA_CRAFTPROCESS;
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_LOG;
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL;
import com.bonait.bnframework.common.db.mode.BPA_MENU;
import com.bonait.bnframework.common.db.mode.BPA_MENUANDUSER;
import com.bonait.bnframework.common.db.mode.BPA_ORDER;
import com.bonait.bnframework.common.db.mode.BPA_ORDERLOG;
import com.bonait.bnframework.common.db.mode.BPA_ORDERLOGDESC;
import com.bonait.bnframework.common.db.mode.BPA_PROCESS;
import com.bonait.bnframework.common.db.mode.BPA_PROCESSModel;
import com.bonait.bnframework.common.db.mode.BPA_SILOS;
import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL;
import com.bonait.bnframework.common.db.mode.BPA_SUBORDER;
import com.bonait.bnframework.common.db.mode.BPA_SUGAR;
import com.bonait.bnframework.common.db.mode.BPA_SYSTEMSET;
import com.bonait.bnframework.common.db.mode.BPA_USER;
import com.bonait.bnframework.common.db.mode.ModeBase;
import com.bonait.bnframework.common.db.res.ResAlertLog;
import com.bonait.bnframework.common.db.res.ResGoodsRecipe;
import com.bonait.bnframework.common.db.res.ResLog;
import com.bonait.bnframework.common.db.res.ResSilosMode;
import com.bonait.bnframework.common.db.res.ResSubOrder;
import com.bonait.bnframework.common.helper.Tools;
import com.bonait.bnframework.common.utils.PreferenceUtils;

import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 数据库数据访问类库
 * add fengyoufu 20230413
 */
public class QueryDB {

    //region 成员变量
    /**
     * 数据库链接
     */
    private static DBHelper helper = DBHelper.getInstance(ConfigName.getInstance().dishesCon);

    /**
     * 时间倒序
     */
    public static String Desc_Time_Down = "createTime desc";
    /**
     * 时间正序
     */
    public static String Desc_Time_Up = "createTime";
    /**
     * 排序、优先顺序
     */
    public static String Desc_Sort_Up = "Sort";

    /**
     * 加锁
     */
    public static Lock lock = new ReentrantLock();    //注意这个地方
    //endregion

    //region BPA_MATERIAL 物料表

    /**
     * 新增物料数据
     * add fengyoufu 20230413
     *
     * @param data 物料数据
     * @return 是否成功
     */
    public static boolean AddMaterial(BPA_MATERIAL data) {

        return Add(BPA_MATERIAL.class, data);
    }

    /**
     * 修改物料数据
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateMaterial(BPA_MATERIAL data) {
        Update(BPA_MATERIAL.class, data);
    }

    /**
     * 删除物料数据
     * add fengyoufu 20230413
     *
     * @param data 物料数据
     * @return 是否成功
     */
    public static boolean DeleteMaterial(BPA_MATERIAL data) {
        return Delete(BPA_MATERIAL.class, data.id);
    }

//    public static boolean DeleteMaterial(String id){
//        boolean result = false;
//        SQLiteDatabase db = helper.getWritableDatabase();
//        try {
//            db.beginTransaction();
//            StringBuilder sql = new StringBuilder();
//            sql.append("delete from ").append(BPA_MATERIAL.class.getSimpleName()).append(" where id=?");
//            db.execSQL(sql.toString(), new String[]{id});
//            db.setTransactionSuccessful();
//            result = true;
//        }catch (SQLException e) {
//            e.printStackTrace();
//            result = false;
//        }finally {
//            db.endTransaction();
//        }
//
//        try {
//            db.beginTransaction();
//            StringBuilder sql = new StringBuilder();
//            sql.append("delete from ").append(BPA_SILOSANDMATERIAL.class.getSimpleName()).append(" where materialID=?");
//            db.execSQL(sql.toString(), new String[]{id});
//            db.setTransactionSuccessful();
//        }catch (SQLException e) {
//            e.printStackTrace();
//
//        }finally {
//            db.endTransaction();//结束第二个事务，回滚或提交操作
//        }
//        db.close();
//        return result;
//    }


    /**
     * 获取所有物料信息
     *
     * @return
     */
    public static ArrayList<BPA_MATERIAL> GetMaterialALL() {
        String orderby = Desc_Time_Up;//出料顺序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_MATERIAL> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_MATERIAL.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_MATERIAL) k);
        }
        return data;
    }

    /**
     * 根据物料id获取物料
     *
     * @param
     * @return
     */
    public static BPA_MATERIAL GetMaterialbyid(String id) {
        String orderby = Desc_Time_Up;//时间
        String where = "isDelete=? and id=?";
        String[] args = new String[]{"0", id};
        BPA_MATERIAL data = new BPA_MATERIAL();
        ArrayList<Object> obj = Get(BPA_MATERIAL.class, where, args, orderby);

        return obj.size() > 0 ? (BPA_MATERIAL) obj.get(0) : null;
    }
    /**
     * 根据物料名称获取物料
     *
     * @param name
     * @return
     */
    public static BPA_MATERIAL GetMaterialName(String name) {
        String orderby = Desc_Time_Up;//出料顺序
        String where = "isDelete=? and name=?";
        String[] args = new String[]{"0", name};
        ArrayList<BPA_MATERIAL> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_MATERIAL.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_MATERIAL) k);
        }
        return data.size() > 0?data.get(0):null;
    }

    /**
     * 判断物料数据是否存在
     *
     * @param name
     * @return
     */
    public static boolean GetMaterialIs(String name) {
        boolean isSucess = false;
        String orderby = Desc_Time_Up;//出料顺序
        String where = "isDelete=? and name=?";
        String[] args = new String[]{"0", name};
        ArrayList<BPA_MATERIAL> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_MATERIAL.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_MATERIAL) k);
        }
        return data.size() > 0;
    }

    /**
     * 物料ID查询物料信息
     *
     * @param id
     * @return
     */
    public static BPA_MATERIAL GetMaterialID(String id) {
        try {
            BPA_MATERIAL bpa_material = null;
            boolean isSucess = false;
            String orderby = Desc_Time_Up;//出料顺序
            String where = "isDelete=? and id=?";
            String[] args = new String[]{"0", id};
            ArrayList<BPA_MATERIAL> data = new ArrayList<>();
            ArrayList<Object> obj = Get(BPA_MATERIAL.class, where, args, orderby);
            for (Object k : obj) {
                bpa_material = (BPA_MATERIAL) k;
            }
            return bpa_material;
        } catch (Exception e) {
            Log.d("物料ID查询物料信息", "物料ID查询物料信息异常: " + e.getMessage());
            return null;
        }

    }

    /**
     * 修改物料名称
     * @param id
     * @param name
     */
    public static void UpdateMaterialName(String id, String name) {
        BPA_MATERIAL material = GetMaterialID(id);
        if (material != null) {
            material.name = name;
            Update(BPA_MATERIAL.class, material);
        }
    }

    /**
     * 修改物料类型
     * @param id
     * @param type
     */
    public static void UpdateMaterialType(String id, int type) {
        BPA_MATERIAL material = GetMaterialID(id);
        if (material != null) {
            material.type = type;
            Update(BPA_MATERIAL.class, material);
        }
    }
    //endregion

    //region BPA_SILOS 料仓管理表

    /**
     * 新增料仓管理
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddSilos(BPA_SILOS data) {
        return Add(BPA_SILOS.class, data);
    }

    /**
     * 修改料仓管理
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateSilos(BPA_SILOS data) {
        Update(BPA_SILOS.class, data);
    }

    /**
     * 删除料仓管理
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteSilos(BPA_SILOS data) {
        return Delete(BPA_SILOS.class, data.id);
    }

    /**
     * 获取所有料仓管理
     *
     * @return
     */
    public static ArrayList<BPA_SILOS> GetSilosALL() {
        String orderby = Desc_Sort_Up + ',' + Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_SILOS> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_SILOS.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_SILOS) k);
        }
        return data;
    }

    /**
     * 获取料仓数据
     *
     * @return
     */
    public static ArrayList<ResSilosMode> GetSilos() {
        ArrayList<ResSilosMode> data = new ArrayList<>();
        //1.获取料仓数据
        ArrayList<BPA_SILOS> silos = GetSilosALL();
        //2.获取物料
        ArrayList<BPA_MATERIAL> materials = GetMaterialALL();
        //3.获取返回数据
        for (BPA_SILOS k : silos) {
            ResSilosMode par = new ResSilosMode();
            par.id = k.id;
            par.createTime = k.createTime;
            par.updateTime = k.updateTime;
            par.deleteTime = k.deleteTime;
            par.deviceID = k.deviceID;
            par.userID = k.userID;
            par.isDelete = k.isDelete;
            par.exp = k.exp;

            par.num = k.num;
            par.name = k.name;
            par.warningValue = k.warningValue;
            par.thrsoleValue = k.thrsoleValue;
            par.silosmargin = k.silosmargin;
            par.siloszl = k.siloszl;

            par.plcValue = k.plcValue;
            par.bValue = k.bValue;
            par.jValue = k.jValue;
            par.status = k.status;
            par.Sort = k.Sort;

            ArrayList<String> gx = GetMaterialList(k.id);
            if (!gx.isEmpty() && gx.size() > 0) {
                String wlid = gx.get(0);
                if (!wlid.isEmpty()) {
                    BPA_MATERIAL wl = null;
                    for (BPA_MATERIAL m : materials) {
                        if (m.id.equals(wlid)) {
                            wl = m;
                            break;
                        }
                    }
                    if (wl != null) {
                        par.materialID = wl.id;
                        par.materialimgUrl = wl.imgUrl;
                        par.materialname = wl.name;
                    }
                }
            }

            par.dvalue = 0;
            data.add(par);
        }
        return data;
    }

    /**
     * 根据ID查询料仓管理
     *
     * @return
     */
    public static BPA_SILOS GetSilosID(String id) {
        BPA_SILOS data = null;
        String orderby = Desc_Sort_Up + ',' + Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and id=?";
        String[] args = new String[]{"0", id};
        ArrayList<Object> obj = Get(BPA_SILOS.class, where, args, orderby);
        for (Object k : obj) {
            data = (BPA_SILOS) k;
        }
        return data;
    }

    /**
     * 修改校准值
     *
     * @param id
     * @param data
     */
    public static void UpdateJYZ(String id, int data) {
        BPA_SILOS silos = GetSilosID(id);
        if (silos != null) {
            silos.jValue = data;
            Update(BPA_SILOS.class, silos);
        }
    }

    /**
     * 修改余料
     *
     * @param id
     * @param data
     */
    public static void UpdateYL(String id, int data) {
        BPA_SILOS silos = GetSilosID(id);
        if (silos != null) {
            silos.silosmargin = data;
            Update(BPA_SILOS.class, silos);
        }
    }

    /**
     * 修改报警值
     *
     * @param id
     * @param data
     */
    public static void UpdateSilosBJZ(String id, int data) {
        BPA_SILOS silos = GetSilosID(id);
        if (silos != null) {
            silos.warningValue = data;
            Update(BPA_SILOS.class, silos);
        }
    }

    /**
     * 修改总量
     *
     * @param id
     * @param data
     */
    public static void UpdateSilosZL(String id, int data) {
        BPA_SILOS silos = GetSilosID(id);
        if (silos != null) {
            silos.siloszl = data;
            Update(BPA_SILOS.class, silos);
        }
    }
    //endregion

    //region BPA_SILOSANDMATERIAL 料仓物料关联表

    /**
     * 新增料仓物料关联
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddSilosAndMaterial(BPA_SILOSANDMATERIAL data) {
        return Add(BPA_SILOSANDMATERIAL.class, data);
    }

    /**
     * 修改料仓物料关联
     * yddate 20230413
     *
     * @param data
     */
    public static boolean UpdateSilosAndMaterial(BPA_SILOSANDMATERIAL data) {
        return Update(BPA_SILOSANDMATERIAL.class, data, "silosID");
    }

    /**
     * 删除料仓物料关联
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteSilosAndMaterial(BPA_SILOSANDMATERIAL data) {
        return Delete(BPA_SILOSANDMATERIAL.class, data.id);
    }

    /**
     * 删除料仓物料关联:根据料仓id 删除料仓与物料关联
     * add fengyoufu 20230413
     *
     * @return 是否成功
     */
    public static boolean DeleteSilosAndMaterial(String id) {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and silosID=?";
        String[] args = new String[]{"0", id};
        ArrayList<String> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_SILOSANDMATERIAL.class, where, args, orderby);
        for (Object k : obj) {
            Delete(BPA_SILOSANDMATERIAL.class, ((BPA_SILOSANDMATERIAL) k).id);
        }
        return true;
    }

    /**
     * 获取所有料仓物料关联
     *
     * @return
     */
    public static ArrayList<BPA_SILOSANDMATERIAL> GetSilosAndMaterialALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_SILOSANDMATERIAL> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_SILOSANDMATERIAL.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_SILOSANDMATERIAL) k);
        }
        return data;
    }

    /**
     * 根据料仓id查询物料id
     *
     * @param id
     * @return
     */
    public static ArrayList<String> GetMaterialList(String id) {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and silosID=?";
        String[] args = new String[]{"0", id};
        ArrayList<String> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_SILOSANDMATERIAL.class, where, args, orderby);
        for (Object k : obj) {
            data.add(((BPA_SILOSANDMATERIAL) k).materialID);
        }
        return data;
    }

    /**
     * 根据物料id查询料仓ID
     *
     * @param id
     * @return
     */
    public static ArrayList<String> GetSilosLIst(String id) {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and materialID=?";
        String[] args = new String[]{"0", id};
        ArrayList<String> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_SILOSANDMATERIAL.class, where, args, orderby);
        for (Object k : obj) {
            data.add(((BPA_SILOSANDMATERIAL) k).silosID);
        }
        return data;
    }

    /**
     * 根据物料id查询料仓
     *
     * @param id
     * @return
     */
    public static List<BPA_SILOS> GetSolisByMaterialID(String id) {
        List<String> solisids = GetSilosLIst(id);
        List<BPA_SILOS> data = new ArrayList<>();
        if (solisids.size() == 0) {
            return data;
        }

        for (String s : solisids) {
            BPA_SILOS silos = GetSilosID(s);
            if (silos != null) {
                data.add(silos);
            }
        }
        return data;
    }

    /**
     * 根据料仓id查询物料
     *
     * @param id
     * @return
     */
    public static List<BPA_MATERIAL> GetMaterialBySilosID(String id) {
        List<BPA_MATERIAL> data = new ArrayList<>();
        List<String> res = GetMaterialList(id);//根据料仓ID获取物料ID
        if (res.size() == 0) {
            return data;
        }
        if (res.get(0).equals("")) {
            return data;
        }
        //根据物料id查询物料
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and id=?";

        for (String s : res) {
            String[] args = new String[]{"0", s};
            List<Object> obj = Get(BPA_MATERIAL.class, where, args, orderby);
            for (Object o : obj) {
                data.add((BPA_MATERIAL) o);
            }

        }
        return data;

    }

    /**
     * 根据物料名称查询料仓
     * @return
     */
    public static List<BPA_SILOS> GetSolisByMaterialName(String name) {
        List<BPA_SILOS> data = new ArrayList<>();
        BPA_MATERIAL material= GetMaterialName(name);
        if(material==null)
        {
            return data;
        }
        List<String> solisids = GetSilosLIst(material.id);
        if (solisids.size() == 0) {
            return data;
        }
        for (String s : solisids) {
            BPA_SILOS silos = GetSilosID(s);
            if (silos != null) {
                data.add(silos);
            }
        }
        return data;
    }
    //endregion

    //region BPA_GOODS 商品表

    /**
     * 新增商品表
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddGoods(BPA_GOODS data) {
        return Add(BPA_GOODS.class, data);
    }

    /**
     * 修改商品
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateGoods(BPA_GOODS data) {
        Update(BPA_GOODS.class, data);
    }

    /**
     * 删除商品
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteGoods(BPA_GOODS data) {
        return Delete(BPA_GOODS.class, data.id);
    }
    public static boolean DeleteGoodsid(String data) {
        return Delete(BPA_GOODS.class, data);
    }
    /**
     * 修改是否收藏
     *
     * @param id
     * @param data
     */
    public static void UpdateGoodsSC(String id, int data) {
        BPA_GOODS goods = GetGoodsId(id);
        if (goods != null) {
            goods.issc = data;
            Update(BPA_GOODS.class, goods);
        }
    }
    /**
     * 获取所有商品
     *
     * @return
     */
    public static ArrayList<BPA_GOODS> GetGoodsALL() {
        String orderby = Desc_Sort_Up + ',' + Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_GOODS> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_GOODS.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_GOODS) k);
        }
        return data;
    }

    /**
     * 模糊查询商品
     * @param name
     * @return
     */
    public static ArrayList<BPA_GOODS> GetGoodsLike(String name) {
        String orderby = Desc_Sort_Up + ',' + Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and name like ?";
        String[] args = new String[]{"0","%" + name + "%"};
        ArrayList<BPA_GOODS> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_GOODS.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_GOODS) k);
        }
        return data;
    }

    /**
     * 获取所有启用的商品
     *
     * @return
     */
    public static ArrayList<BPA_GOODS> GetGoodsStateALL() {
        String orderby = Desc_Sort_Up + ',' + Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and status=?";
        String[] args = new String[]{"0", "1"};
        ArrayList<BPA_GOODS> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_GOODS.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_GOODS) k);
        }
        return data;
    }

    /**
     * 根据id查询商品
     *
     * @return
     */
    public static BPA_GOODS GetGoodsId(String id) {
        String orderby = Desc_Time_Up;//出料顺序
        String where = "isDelete=? and id=?";
        String[] args = new String[]{"0", id};
        ArrayList<BPA_GOODS> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_GOODS.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_GOODS) k);
        }
        if (data.size() > 0) {
            return data.get(0);
        } else {
            return null;
        }
    }

    /**
     * 判断商品数据是否存在
     *
     * @param name
     * @return
     */
    public static boolean GetGoodsIs(String name) {
        boolean isSucess = false;
        String orderby = Desc_Time_Up;//出料顺序
        String where = "isDelete=? and name=?";
        String[] args = new String[]{"0", name};
        ArrayList<BPA_GOODS> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_GOODS.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_GOODS) k);
        }
        return data.size() > 0;
    }

    /**
     * 判断商品数据是否存在
     *
     * @param name
     * @return
     */
    public static boolean GetGoodsIs(String name,String id) {
        boolean isSucess = false;
        String orderby = Desc_Time_Up;//出料顺序
        String where = "isDelete=? and name=? and id!=?";
        String[] args = new String[]{"0", name,id};
        ArrayList<BPA_GOODS> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_GOODS.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_GOODS) k);
        }
        return data.size() > 0;
    }

    /**
     * 判断商品数据是否存在
     *
     * @param id
     * @return
     */
    public static boolean GetGoodsIDIs(String id) {
        boolean isSucess = false;
        String orderby = Desc_Time_Up;//出料顺序
        String where = "isDelete=? and id=?";
        String[] args = new String[]{"0", id};
        ArrayList<BPA_GOODS> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_GOODS.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_GOODS) k);
        }
        return data.size() > 0;
    }

    /**
     * 根据排序查询商品
     *
     * @param sort
     * @return
     */
    public static BPA_GOODS GetGoodsSortIs(int sort) {
        boolean isSucess = false;
        String orderby = Desc_Time_Up;//出料顺序
        String where = "isDelete=? and sort=?";
        String[] args = new String[]{"0", sort + ""};
        BPA_GOODS data = null;
        ArrayList<Object> obj = Get(BPA_GOODS.class, where, args, orderby);
        for (Object k : obj) {
            data = (BPA_GOODS) k;
        }
        return data;
    }

    /**
     * 商品数据排序
     *
     * @param data 数据
     * @param type 0 下移动 1 上移动
     * @return
     */
    public static void GetGoodsSort(BPA_GOODS data, int type) {
        if (type == 0) {
            BPA_GOODS q_data = data;
            BPA_GOODS h_data = GetGoodsSortIs(data.sort + 1);
            if (h_data != null) {
                h_data.sort = h_data.sort - 1;
                UpdateGoods(h_data);
            }
            q_data.sort = q_data.sort + 1;
            UpdateGoods(q_data);

        } else {
            BPA_GOODS q_data = GetGoodsSortIs(data.sort - 1);
            BPA_GOODS h_data = data;
            if (q_data != null) {
                q_data.sort = q_data.sort + 1;
                UpdateGoods(q_data);
            }
            h_data.sort = h_data.sort - 1;
            UpdateGoods(h_data);
        }
    }
    //endregion

    //region BPA_GOODSRECIPE 商品配方明细表

    /**
     * 新增商品配方明细
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddGoodsSrecipe(BPA_GOODSRECIPE data) {
        return Add(BPA_GOODSRECIPE.class, data);
    }

    /**
     * 修改商品配方明细
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateGoodsSrecipe(BPA_GOODSRECIPE data) {
        Update(BPA_GOODSRECIPE.class, data);
    }

    /**
     * 删除商品配方明细
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteGoodsSrecipe(BPA_GOODSRECIPE data) {
        return Delete(BPA_GOODSRECIPE.class, data.id);
    }

    /**
     * 获取所有商品配方明细
     *
     * @return
     */
    public static ArrayList<BPA_GOODSRECIPE> GetGoodsSrecipeALL() {
        String orderby = Desc_Sort_Up + ',' + Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_GOODSRECIPE> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_GOODSRECIPE.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_GOODSRECIPE) k);
        }
        return data;
    }
    /**
     * 根据商品id查询配方信息
     *
     * @param id
     * @return
     */
    public static ArrayList<BPA_GOODSRECIPE> GetGoodsSrecipeID(String id) {
        String orderby = Desc_Sort_Up + ',' + Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and goodsID=?";
        String[] args = new String[]{"0", id};
        ArrayList<BPA_GOODSRECIPE> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_GOODSRECIPE.class, where, args, orderby);
        for (Object item : obj) {
            BPA_GOODSRECIPE k = (BPA_GOODSRECIPE) item;
            data.add(k);
        }
        return data;
    }
    /**
     * 根据商品id查询配方信息
     *
     * @param id
     * @return
     */
    public static ArrayList<ResGoodsRecipe> GetGoodsSrecipeList(String id) {
        String orderby = Desc_Sort_Up + ',' + Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and goodsID=?";
        String[] args = new String[]{"0", id};
        ArrayList<ResGoodsRecipe> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_GOODSRECIPE.class, where, args, orderby);
        for (Object item : obj) {
            BPA_GOODSRECIPE k = (BPA_GOODSRECIPE) item;
            String name = "";
            BPA_MATERIAL res = GetMaterialID(k.materialID);
            if (res != null) {
                name = GetMaterialID(k.materialID).name;
            }
//            if (k.materialType ==1){
//            }else if (k.materialType ==2){
//                BPA_SUGAR res = GetsugarId(k.materialID);
//                if (res!= null) {  name = GetsugarId(k.materialID).sugarName;}
//            }

            if (name != "") {
                ResGoodsRecipe par = new ResGoodsRecipe();
                par.id = k.id;
                par.materialType = k.materialType;
                par.createTime = k.createTime;
                par.updateTime = k.updateTime;
                par.deleteTime = k.deleteTime;
                par.deviceID = k.deviceID;
                par.userID = k.userID;
                par.isDelete = k.isDelete;
                par.exp = k.exp;
                par.materialName = name;

                par.goodsID = k.goodsID;
                par.materialID = k.materialID;
                par.value = k.value;
                par.sort = k.sort;
                data.add(par);
            }
        }
        return data;
    }

    /**
     * 根据商品id删除配料信息
     *
     * @param id
     * @return
     */
    public static Boolean DeleteGoodsSrecipeList(String id) {
        if (id.isEmpty())
            return false;
        SQLiteDatabase db = helper.getWritableDatabase();
        long delete = db.delete(BPA_GOODSRECIPE.class.getSimpleName(), "goodsID=?",
                new String[]{id});

        db.close();
        return delete > 0;
    }
    //endregion

    //region BPA_ORDER 订单表

    /**
     * 新增订单
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddOrder(BPA_ORDER data) {
        return Add(BPA_ORDER.class, data);
    }

    /**
     * 修改订单
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateOrder(BPA_ORDER data) {
        Update(BPA_ORDER.class, data);
    }

    /**
     * 删除订单
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteOrder(BPA_ORDER data) {
        return Delete(BPA_ORDER.class, data.id);
    }

    /**
     * 获取所有订单
     *
     * @return
     */
    public static ArrayList<BPA_ORDER> GetOrderALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_ORDER> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_ORDER.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_ORDER) k);
        }
        return data;
    }

    /**
     * 判断订单是否存在在
     *
     * @param id
     * @return
     */
    public static boolean GetOrderIs(String id) {
        boolean isSucess = false;
        String orderby = Desc_Time_Up;//出料顺序
        String where = "isDelete=? and id=?";
        String[] args = new String[]{"0", id};
        ArrayList<BPA_ORDER> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_ORDER.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_ORDER) k);
        }
        return data.size() > 0;
    }
    //endregion

    //region BPA_SUBORDER 订单子表

    /**
     * 新增订单子表
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddSubOrder(BPA_SUBORDER data) {
        return Add(BPA_SUBORDER.class, data);
    }

    /**
     * 修改订单子表
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateSubOrder(BPA_SUBORDER data) {
        Update(BPA_SUBORDER.class, data);
    }

    /**
     * 删除订单子表
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteSubOrder(BPA_SUBORDER data) {
        return Delete(BPA_SUBORDER.class, data.id);
    }

    /**
     * 获取所有订单子表
     *
     * @return
     */
    public static ArrayList<BPA_SUBORDER> GetSubOrderALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_SUBORDER> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_SUBORDER.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_SUBORDER) k);
        }
        return data;
    }

    /**
     * 根据主订单id查询子订单列表
     *
     * @param id
     * @return
     */
    public static ArrayList<BPA_SUBORDER> GetSubOrderList(String id) {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and orderID=?";
        String[] args = new String[]{"0", id};
        ArrayList<BPA_SUBORDER> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_SUBORDER.class, where, args, orderby);
        for (Object k : obj) {
            data.add(((BPA_SUBORDER) k));
        }
        return data;
    }

    /**
     * 根据条件查询子订单
     *
     * @param sta
     * @param stp
     * @param lx
     * @param text
     * @return
     */
    public static ArrayList<ResSubOrder> GetSubOrders(String sta, String stp, int lx, String text) {
        String orderby = Desc_Time_Down;//先按排序 创建时间倒序
        String where = "isDelete=? and createTime>=? and createTime<=?";
        String[] args = new String[]{"0", sta, stp};
        if (lx >= 0) {
            where = "isDelete=? and createTime>=? and createTime<=? and status=?";
            args = new String[]{"0", sta, stp, String.valueOf(lx)};
        }

        ArrayList<BPA_GOODS> goods = GetGoodsALL();
        ArrayList<ResSubOrder> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_SUBORDER.class, where, args, orderby);
        for (Object k : obj) {
            ResSubOrder sub = new ResSubOrder();
            BPA_SUBORDER o = (BPA_SUBORDER) k;

            sub.orderID = o.orderID;
            sub.goodsID = o.goodsID;
            sub.number = o.number;
            sub.status = o.status;


            sub.id = o.id;
            sub.createTime = o.createTime;
            sub.updateTime = o.updateTime;
            sub.deleteTime = o.deleteTime;
            sub.deviceID = o.deviceID;
            sub.userID = o.userID;
            sub.isDelete = o.isDelete;
            sub.exp = o.exp;

            BPA_GOODS good = null;
            for (BPA_GOODS i : goods) {
                if (i.id.equals(o.goodsID)) {
                    good = i;
                    break;
                }
            }
            if (good != null) {
                sub.goodsName = good.name;
                switch (o.status) {
                    case 0:
                        sub.statusText = "未开始";
                        break;
                    case 1:
                        sub.statusText = "制作中";
                        break;
                    case 2:
                        sub.statusText = "已制作";
                        break;
                    case 3:
                        sub.statusText = "已超时";
                        break;
                }
            }

            boolean IsText = false;
            if (!text.isEmpty()) {
                if (sub.goodsName.contains(text)) {
                    IsText = true;
                } else {
                    IsText = false;
                }
            } else {
                IsText = true;
            }

            if (IsText) {
                data.add(sub);
            }
        }
        return data;
    }
    //endregion

    //region BPA_ALERTLOG 预警日志表

    /**
     * 新增预警日志
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddAlertlog(BPA_ALERTLOG data) {
        return Add(BPA_ALERTLOG.class, data);
    }

    /**
     * 修改预警日志
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateAlertlog(BPA_ALERTLOG data) {
        Update(BPA_ALERTLOG.class, data);
    }

    /**
     * 删除预警日志
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteAlertlog(BPA_ALERTLOG data) {
        return Delete(BPA_ALERTLOG.class, data.id);
    }

    /**
     * 获取所有预警日志
     *
     * @return
     */
    public static ArrayList<BPA_ALERTLOG> GetAlertlogALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_ALERTLOG> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_ALERTLOG.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_ALERTLOG) k);
        }
        return data;
    }

    /**
     * @return
     */
    public static ArrayList<ResAlertLog> GetAlertlogs(String sta, String stp, int lx, String text) {
        String orderby = Desc_Time_Down;//先按排序 创建时间倒序
        String where = "isDelete=? and createTime>=? and createTime<=?";
        String[] args = new String[]{"0", sta, stp};
        if (lx != 0) {
            where = "isDelete=? and createTime>=? and createTime<=? and type=?";
            args = new String[]{"0", sta, stp, String.valueOf(lx)};
            if (!text.isEmpty()) {
                where = "isDelete=? and createTime>=? and createTime<=? and text like ? and type=?";
                args = new String[]{"0", sta, stp, "%" + text + "%", String.valueOf(lx)};
            }
        } else {
            if (!text.isEmpty()) {
                where = "isDelete=? and createTime>=? and createTime<=? and text like ?";
                args = new String[]{"0", sta, stp, "%" + text + "%"};
            }
        }
        ArrayList<BPA_USER> Users = GetUserALL();
        ArrayList<ResAlertLog> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_ALERTLOG.class, where, args, orderby);
        for (Object k : obj) {
            BPA_ALERTLOG o = (BPA_ALERTLOG) k;
            ResAlertLog log = new ResAlertLog();
            log.type = o.type;
            log.text = o.text;
            log.id = o.id;
            log.createTime = o.createTime;
            log.updateTime = o.updateTime;
            log.deleteTime = o.deleteTime;
            log.deviceID = o.deviceID;
            log.userID = o.userID;
            log.isDelete = o.isDelete;
            log.exp = o.exp;


            data.add(log);
        }
        return data;
    }

    /**
     * 获取所有今日预警日志
     *
     * @return
     */
    public static ArrayList<BPA_ALERTLOG> GetAlertlogTodan() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and createTime>?";
        String[] args = new String[]{"0", new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + " 00:00:00"};
        ArrayList<BPA_ALERTLOG> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_ALERTLOG.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_ALERTLOG) k);
        }
        return data;
    }
    //endregion

    //region BPA_LOG 日志表

    /**
     * 新增日志
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean Addlog(BPA_LOG data) {
        return Add(BPA_LOG.class, data);
    }

    /**
     * 修改日志
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void Updatelog(BPA_LOG data) {
        Update(BPA_LOG.class, data);
    }

    /**
     * 删除日志
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean Deletelog(BPA_LOG data) {
        return Delete(BPA_LOG.class, data.id);
    }

    /**
     * 获取日志
     *
     * @return
     */
    public static ArrayList<BPA_LOG> GetlogALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_LOG> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_LOG.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_LOG) k);

        }
        return data;
    }

    /**
     * @return
     */
    public static ArrayList<ResLog> Getlogs(String sta, String stp, int lx, String text) {
        String orderby = Desc_Time_Down;//先按排序 创建时间倒序
        String where = "isDelete=? and createTime>=? and createTime<=?";
        String[] args = new String[]{"0", sta, stp};
        if (lx != 0) {
            where = "isDelete=? and createTime>=? and createTime<=? and type=?";
            args = new String[]{"0", sta, stp, String.valueOf(lx)};
            if (!text.isEmpty()) {
                where = "isDelete=? and createTime>=? and createTime<=? and text like ? and type=?";
                args = new String[]{"0", sta, stp, "%" + text + "%", String.valueOf(lx)};
            }
        } else {
            if (!text.isEmpty()) {
                where = "isDelete=? and createTime>=? and createTime<=? and text like ?";
                args = new String[]{"0", sta, stp, "%" + text + "%"};
            }
        }
        ArrayList<BPA_USER> Users = GetUserALL();
        ArrayList<ResLog> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_LOG.class, where, args, orderby);
        for (Object k : obj) {
            BPA_LOG o = (BPA_LOG) k;
            ResLog log = new ResLog();
            log.type = o.type;
            log.text = o.text;
            log.id = o.id;
            log.createTime = o.createTime;
            log.updateTime = o.updateTime;
            log.deleteTime = o.deleteTime;
            log.deviceID = o.deviceID;
            log.userID = o.userID;
            log.isDelete = o.isDelete;
            log.exp = o.exp;

            BPA_USER user = null;
            for (BPA_USER i : Users) {
                if (i.id.equals(log.userID)) {
                    user = i;
                    break;
                }
            }
            if (user != null) {
                log.Name = user.name;
            }
            data.add(log);
        }
        return data;
    }

    /**
     * 获取所有今日日志
     *
     * @return
     */
    public static ArrayList<BPA_LOG> GetlogTodan() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and createTime>?";
        String[] args = new String[]{"0", new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + " 00:00:00"};
        ArrayList<BPA_LOG> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_LOG.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_LOG) k);
        }
        return data;
    }
    //endregion

    //region BPA_ORDERLOG 订单制作记录表

    /**
     * 新增订单制作记录
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddOrderlog(BPA_ORDERLOG data) {
        return Add(BPA_ORDERLOG.class, data);
    }

    /**
     * 修改订单制作记录
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateOrderlog(BPA_ORDERLOG data) {
        Update(BPA_ORDERLOG.class, data);
    }

    /**
     * 删除订单制作记录
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteOrderlog(BPA_ORDERLOG data) {
        return Delete(BPA_ORDERLOG.class, data.id);
    }

    /**
     * 获取所有订单制作记录
     *
     * @return
     */
    public static ArrayList<BPA_ORDERLOG> GetOrderlogALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_ORDERLOG> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_ORDERLOG.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_ORDERLOG) k);
        }
        return data;
    }

    /**
     * 根据子订单id查询子订单制作记录
     *
     * @param id
     * @return
     */
    public static ArrayList<BPA_ORDERLOG> GetOrderlogList(String id) {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and suborderID=?";
        String[] args = new String[]{"0", id};
        ArrayList<BPA_ORDERLOG> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_ORDERLOG.class, where, args, orderby);
        for (Object k : obj) {
            data.add(((BPA_ORDERLOG) k));
        }
        return data;
    }
    //endregion

    //region BPA_ORDERLOGDESC 订单制作记录描述表

    /**
     * 新增订单制作记录描述
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddOrderlogdesc(BPA_ORDERLOGDESC data) {
        return Add(BPA_ORDERLOGDESC.class, data);
    }

    /**
     * 修改订单制作记录描述
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateOrderlogdesc(BPA_ORDERLOGDESC data) {
        Update(BPA_ORDERLOGDESC.class, data);
    }

    /**
     * 删除订单制作记录描述
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteOrderlogdesc(BPA_ORDERLOGDESC data) {
        return Delete(BPA_ORDERLOGDESC.class, data.id);
    }

    /**
     * 获取订单制作记录描述
     *
     * @return
     */
    public static ArrayList<BPA_ORDERLOGDESC> GetOrderlogdescALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_ORDERLOGDESC> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_ORDERLOGDESC.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_ORDERLOGDESC) k);
        }
        return data;
    }

    /**
     * 根据子订单id查询子订单订单制作记录描述
     *
     * @param id
     * @return
     */
    public static ArrayList<BPA_ORDERLOGDESC> GetOrderlogdescList(String id) {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and suborderID=?";
        String[] args = new String[]{"0", id};
        ArrayList<BPA_ORDERLOGDESC> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_ORDERLOGDESC.class, where, args, orderby);
        for (Object k : obj) {
            data.add(((BPA_ORDERLOGDESC) k));
        }
        return data;
    }
    //endregion

    //region BPA_SYSTEMSET 系统设置表

    /**
     * 新增系统设置
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddSystemset(BPA_SYSTEMSET data) {
        return Add(BPA_SYSTEMSET.class, data);
    }

    /**
     * 修改系统设置
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateSystemset(BPA_SYSTEMSET data) {
        Update(BPA_SYSTEMSET.class, data);
    }

    /**
     * 删除系统设置
     * add fengyoufu 20230413
     *
     * @return 是否成功
     */
    public static boolean DeleteSystemset(String id) {
        return Delete(BPA_SYSTEMSET.class, id);
    }

    /**
     * 获取系统设置
     *
     * @return
     */
    public static ArrayList<BPA_SYSTEMSET> GetSystemsetALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_SYSTEMSET> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_SYSTEMSET.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_SYSTEMSET) k);
        }
        return data;
    }
    //endregion

    //region BPA_USER 账户表

    /**
     * 新增账户
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddUser(BPA_USER data) {
        return Add(BPA_USER.class, data);
    }

    /**
     * 修改账户
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateUser(BPA_USER data) {
        Update(BPA_USER.class, data);
    }

    /**
     * 删除账户
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteUser(BPA_USER data) {
        return Delete(BPA_USER.class, data.id);
    }

    /**
     * 获取账户
     *
     * @return
     */
    public static ArrayList<BPA_USER> GetUserALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_USER> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_USER.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_USER) k);
        }
        return data;
    }

    /**
     * 用户登录
     *
     * @param Name
     * @param Pass
     * @return
     */
    public static BPA_USER UserLogin(String Name, String Pass) {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and (account=? or name=?) and pass=?";
        String[] args = new String[]{"0", Name, Name, Pass};
        ArrayList<BPA_USER> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_USER.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_USER) k);
        }
        if (data.size() <= 0)
            return null;
        else
            return data.get(0);
    }
    //endregion

    //region BPA_MENU 菜单表

    /**
     * 新增菜单
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddMenu(BPA_MENU data) {
        return Add(BPA_MENU.class, data);
    }

    /**
     * 修改菜单
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateMenu(BPA_MENU data) {
        Update(BPA_MENU.class, data);
    }

    /**
     * 删除菜单
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteMenu(BPA_MENU data) {
        return Delete(BPA_MENU.class, data.id);
    }

    /**
     * 获取菜单
     *
     * @return
     */
    public static ArrayList<BPA_MENU> GetMenuALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_MENU> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_MENU.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_MENU) k);
        }
        return data;
    }
    //endregion

    //region BPA_MENUANDUSER 菜单用户关联表

    /**
     * 新增菜单用户关联表
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddMenuAndUser(BPA_MENUANDUSER data) {
        return Add(BPA_MENUANDUSER.class, data);
    }

    /**
     * 修改菜单用户关联表
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateMenuAndUser(BPA_MENUANDUSER data) {
        Update(BPA_MENUANDUSER.class, data);
    }

    /**
     * 删除菜单用户关联表
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteMenuAndUser(BPA_MENUANDUSER data) {
        return Delete(BPA_MENUANDUSER.class, data.id);
    }

    /**
     * 获取菜单用户关联表
     *
     * @return
     */
    public static ArrayList<BPA_MENUANDUSER> GetMenuAndUserALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_MENUANDUSER> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_MENUANDUSER.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_MENUANDUSER) k);
        }
        return data;
    }
    //endregion

    //region BPA_SUGAR 果糖辅料表

    /**
     * 新增果糖
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddSugar(BPA_SUGAR data) {
        return Add(BPA_SUGAR.class, data);
    }

    /**
     * 修改果糖表
     *
     * @param data
     */
    public static void UpdateSugar(BPA_SUGAR data) {
        Update(BPA_SUGAR.class, data);
    }

    /**
     * 删除果糖表
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean DeleteSugar(BPA_SUGAR data) {
        return Delete(BPA_SUGAR.class, data.id);
    }

    /**
     * 获取果糖表
     *
     * @return
     */
    public static ArrayList<BPA_SUGAR> GetSugarALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_SUGAR> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_SUGAR.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_SUGAR) k);
        }
        return data;
    }

    public static BPA_SUGAR GetsugarId(String id) {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and id=?";
        String[] args = new String[]{"0", id};
        BPA_SUGAR data = new BPA_SUGAR();
        ArrayList<Object> obj = Get(BPA_SUGAR.class, where, args, orderby);
        for (Object k : obj) {
            data = (BPA_SUGAR) k;
        }
        return data;
    }
    //endregion

    //region BPA_CRAFT 工艺基础信息表

    /**
     * 新增工艺基础信息表
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddCraft(BPA_CRAFT data) {
        return Add(BPA_CRAFT.class, data);
    }

    /**
     * 修改工艺基础信息表
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateCraft(BPA_CRAFT data) {
        Update(BPA_CRAFT.class, data);
    }

    /**
     * 删除工艺基础信息表
     * add fengyoufu 20230413
     *
     * @return 是否成功
     */
    public static boolean DeleteCraft(String id) {
        return Delete(BPA_CRAFT.class, id);
    }

    /**
     * 获取工艺基础信息表
     *
     * @return
     */
    public static ArrayList<BPA_CRAFT> GetCraftALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_CRAFT> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_CRAFT.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_CRAFT) k);
        }
        return data;
    }
    //endregion

    //region BPA_CRAFTPROCESS 工艺流程表

    /**
     * 新增工艺流程表
     * add fengyoufu 20230413
     *
     * @param data
     * @return 是否成功
     */
    public static boolean AddCraftProcess(BPA_CRAFTPROCESS data) {
        return Add(BPA_CRAFTPROCESS.class, data);
    }

    /**
     * 修改工艺流程表
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateCraftProcess(BPA_CRAFTPROCESS data) {
        Update(BPA_CRAFTPROCESS.class, data);
    }

    /**
     * 删除工艺流程表
     * add fengyoufu 20230413
     *
     * @return 是否成功
     */
    public static boolean DeleteCraftProcess(String id) {
        return Delete(BPA_CRAFTPROCESS.class, id);
    }

    /**
     * 获取工艺流程表
     *
     * @return
     */
    public static ArrayList<BPA_CRAFTPROCESS> GetCraftProcessALL() {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_CRAFTPROCESS> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_CRAFTPROCESS.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_CRAFTPROCESS) k);
        }
        return data;
    }

    /**
     * 根据工艺id获取工艺流程表
     *
     * @return
     */
    public static ArrayList<BPA_CRAFTPROCESS> GetCraftProcessId(String id) {
        String orderby = Desc_Time_Up;//先按排序 创建时间倒序
        String where = "isDelete=? and gyid=?";
        String[] args = new String[]{"0", id};
        ArrayList<BPA_CRAFTPROCESS> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_CRAFTPROCESS.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_CRAFTPROCESS) k);
        }
        return data;
    }
    //endregion

    //region BPA_PROCESS 工序表
    /**
     * 新增工序数据
     * add fengyoufu 20230413
     *
     * @param data 工序数据
     * @return 是否成功
     */
    public static boolean AddProcess(BPA_PROCESS data) {

        return Add(BPA_PROCESS.class, data);
    }

    /**
     * 修改工序数据
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateProcess(BPA_PROCESS data) {
        Update(BPA_PROCESS.class, data);
    }

    /**
     * 删除工序数据
     * add fengyoufu 20230413
     *
     * @param data 工序数据
     * @return 是否成功
     */
    public static boolean DeleteProcess(BPA_PROCESS data) {
        return Delete(BPA_PROCESS.class, data.id);
    }

    /**
     * 获取所有工序信息
     *
     * @return
     */
    public static ArrayList<BPA_PROCESS> GetProcessALL() {
        String orderby = Desc_Sort_Up + ',' +Desc_Time_Up;//出料顺序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_PROCESS> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_PROCESS.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_PROCESS) k);
        }
        return data;
    }

    /**
     * 物料ID查询工序信息
     *
     * @param id
     * @return
     */
    public static BPA_PROCESS GetProcessID(String id) {
        try {
            BPA_PROCESS bpa_material = null;
            boolean isSucess = false;
            String orderby = Desc_Time_Up;//出料顺序
            String where = "isDelete=? and id=?";
            String[] args = new String[]{"0", id};
            ArrayList<BPA_PROCESS> data = new ArrayList<>();
            ArrayList<Object> obj = Get(BPA_PROCESS.class, where, args, orderby);
            for (Object k : obj) {
                bpa_material = (BPA_PROCESS) k;
            }
            return bpa_material;
        } catch (Exception e) {
            Log.d("物料ID查询工序信息", "物料ID查询工序信息异常: " + e.getMessage());
            return null;
        }

    }
    /**
     * 修改工序名称
     * @param id
     * @param name
     */
    public static void UpdateProcessName(String id, String name) {
        BPA_PROCESS material = GetProcessID(id);
        if (material != null) {
            material.name = name;
            Update(BPA_PROCESS.class, material);
        }
    }
    //endregion

    //region BPA_PROCESSModel 工序模型表
    /**
     * 新增工序模型表
     * add fengyoufu 20230413
     *
     * @param data 工序数据
     * @return 是否成功
     */
    public static boolean AddProcessModel(BPA_PROCESSModel data) {

        return Add(BPA_PROCESSModel.class, data);
    }

    /**
     * 修改工序模型表
     * add fengyoufu 20230413
     *
     * @param data
     */
    public static void UpdateProcessModel(BPA_PROCESSModel data) {
        Update(BPA_PROCESSModel.class, data);
    }

    /**
     * 删除工序模型表
     * add fengyoufu 20230413
     *
     * @param data 工序数据
     * @return 是否成功
     */
    public static boolean DeleteProcessModel(BPA_PROCESSModel data) {
        return Delete(BPA_PROCESSModel.class, data.id);
    }

    /**
     * 获取所有工序模型表
     *
     * @return
     */
    public static ArrayList<BPA_PROCESSModel> GetProcessModelALL() {
        String orderby = Desc_Sort_Up + ',' +Desc_Time_Up;//出料顺序
        String where = "isDelete=?";
        String[] args = new String[]{"0"};
        ArrayList<BPA_PROCESSModel> data = new ArrayList<>();
        ArrayList<Object> obj = Get(BPA_PROCESSModel.class, where, args, orderby);
        for (Object k : obj) {
            data.add((BPA_PROCESSModel) k);
        }
        return data;
    }
    /**
     * 工序ID查询工序模型表
     *
     * @param id
     * @return
     */
    public static ArrayList<BPA_PROCESSModel> GetProcessModelProcessID(String id) {
        ArrayList<BPA_PROCESSModel> data = new ArrayList<>();
        try {
            boolean isSucess = false;
            String orderby = Desc_Sort_Up + ','+Desc_Time_Up;//出料顺序
            String where = "isDelete=? and processid=?";
            String[] args = new String[]{"0", id};
            ArrayList<Object> obj = Get(BPA_PROCESSModel.class, where, args, orderby);
            for (Object k : obj) {
                data.add((BPA_PROCESSModel) k);
            }
            return data;
        } catch (Exception e) {
            Log.d("物料ID查询工序信息", "物料ID查询工序信息异常: " + e.getMessage());
            return data;
        }

    }
    /**
     * ID查询工序模型表
     *
     * @param id
     * @return
     */
    public static BPA_PROCESSModel GetProcessModelID(String id) {
        try {
            BPA_PROCESSModel bpa_material = null;
            boolean isSucess = false;
            String orderby = Desc_Time_Up;//出料顺序
            String where = "isDelete=? and id=?";
            String[] args = new String[]{"0", id};
            ArrayList<BPA_PROCESSModel> data = new ArrayList<>();
            ArrayList<Object> obj = Get(BPA_PROCESSModel.class, where, args, orderby);
            for (Object k : obj) {
                bpa_material = (BPA_PROCESSModel) k;
            }
            return bpa_material;
        } catch (Exception e) {
            Log.d("物料ID查询工序信息", "物料ID查询工序信息异常: " + e.getMessage());
            return null;
        }

    }
    /**
     * 修改工序模型表名称
     * @param id
     * @param name
     */
    public static void UpdateProcessModelName(String id, String name) {
        BPA_PROCESSModel material = GetProcessModelID(id);
        if (material != null) {
            material.name = name;
            Update(BPA_PROCESSModel.class, material);
        }
    }
    //endregion

    //region 私有

    /**
     * 新增
     *
     * @param c
     * @param data
     * @return
     */
    private static boolean Add(Class c, Object data) {
        lock.lock();
        boolean isSucess = false;
        SQLiteDatabase db = helper.getWritableDatabase();
        try {
            ContentValues cv = new ContentValues();
            Map<String, Object> map = Tools.getObjValue(data);
            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());
                }
//            else if (value instanceof Date)
//            {
//                cv.put(key,  (Date) value);
//            }
            }
            long insert = db.insert(c.getSimpleName(), null, cv);
            db.close();
            isSucess= insert > 0;
        } catch (Exception e) {
            db.close();
            isSucess= false;
        }finally {
            lock.unlock();
        }
        return isSucess;
    }

    /**
     * 修改
     *
     * @param c
     * @param data
     * @return
     */
    private static boolean Update(Class c, Object data) {
        lock.lock();
        boolean isSucess = false;
        SQLiteDatabase db = helper.getWritableDatabase();
        try {
            ContentValues cv = new ContentValues();
            Map<String, Object> map = Tools.getObjValue(data);
            String id = map.get("id").toString();
            if (id.isEmpty())
                return false;
            for (String key : map.keySet()) {
                if (!key.equals("id")) {
                    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());
                    }
                }
//            else if (value instanceof Date)
//            {
//                cv.put(key,  (Date) value);
//            }
            }
            db.update(c.getSimpleName(), cv, "id = ?", new String[]{id});
            db.close();
            isSucess= true;
        } catch (Exception e) {
            db.close();
            isSucess= false;
        }finally {
            lock.unlock();
        }
        return isSucess;
    }

    /**
     * 修改
     *
     * @param c
     * @param data
     * @param where
     * @return
     */
    private static boolean Update(Class c, Object data, String where) {
        lock.lock();
        SQLiteDatabase db = helper.getWritableDatabase();
        try {
            ContentValues cv = new ContentValues();
            Map<String, Object> map = Tools.getObjValue(data);
            String id = map.get(where).toString();
            if (id.isEmpty())
                return false;
            for (String key : map.keySet()) {
                if (!key.equals(where)) {
                    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());
                    }
                }
//            else if (value instanceof Date)
//            {
//                cv.put(key,  (Date) value);
//            }
            }
            int i = db.update(c.getSimpleName(), cv, where + " = ?", new String[]{id});
            db.close();
        } catch (Exception e) {
            Log.d("修改异常", "修改异常: " + e.getMessage());
            db.close();
        } finally {
            lock.unlock();
        }
        return true;
    }

    /**
     * 删除
     *
     * @param c
     * @param id
     * @return
     */
    private static boolean Delete(Class c, String id) {
        lock.lock();
        SQLiteDatabase db = helper.getWritableDatabase();
        boolean isSucess = false;
        try {
            if (id.isEmpty())
                return false;
            long delete = db.delete(c.getSimpleName(), "id = ?",
                    new String[]{id});
            db.close();
            isSucess = delete > 0;
        } catch (Exception e) {
            Log.d("删除异常", "删除异常: " + e.getMessage());
            db.close();
        } finally {
            lock.unlock();
        }
        return isSucess;
    }

    /**
     * 获取数据
     *
     * @param c
     * @param whereClause "id = ? and id=?"  "sys_pre>? and dia_pre<?"  "createTime>?"
     * @param Args        new String[] { id,id }
     * @param orderby     "date("+COLUMN_DATE+") desc"   "TYPE desc";  desc 倒序
     * @return
     */
    private static ArrayList<Object> Get(Class c, String whereClause, String[] Args, String orderby) {
        lock.lock();
        ArrayList<Object> rlts = new ArrayList<Object>();
        SQLiteDatabase db = helper.getReadableDatabase();
        try {
            //String orderby = "TYPE desc";
            List<String> col = new ArrayList<>();
            for (Field field : c.getFields()) {
                col.add(field.getName());
            }
            String[] columns = (String[]) col.toArray(new String[col.size()]);
            Cursor cursor = db.query(c.getSimpleName(), columns, whereClause, Args, null,
                    null, orderby, null);
            Object data = new Object();
            while (cursor.moveToNext()) {
                switch (c.getSimpleName()) {
                    case "BPA_MATERIAL":
                        data = new BPA_MATERIAL();
                        //私有
                        ((BPA_MATERIAL) data).imgUrl = cursor.getString((int) cursor.getColumnIndex("imgUrl"));
                        ((BPA_MATERIAL) data).name = cursor.getString((int) cursor.getColumnIndex("name"));
                        ((BPA_MATERIAL) data).type = cursor.getInt((int) cursor.getColumnIndex("type"));
                        break;
                    case "BPA_SILOS":
                        data = new BPA_SILOS();
                        //私有
                        ((BPA_SILOS) data).num = cursor.getInt((int) cursor.getColumnIndex("num"));
                        ((BPA_SILOS) data).name = cursor.getString((int) cursor.getColumnIndex("name"));
                        ((BPA_SILOS) data).warningValue = cursor.getInt((int) cursor.getColumnIndex("warningValue"));
                        ((BPA_SILOS) data).thrsoleValue = cursor.getInt((int) cursor.getColumnIndex("thrsoleValue"));
                        ((BPA_SILOS) data).plcValue = cursor.getString((int) cursor.getColumnIndex("plcValue"));
                        ((BPA_SILOS) data).bValue = cursor.getInt((int) cursor.getColumnIndex("bValue"));
                        ((BPA_SILOS) data).jValue = cursor.getInt((int) cursor.getColumnIndex("jValue"));
                        ((BPA_SILOS) data).status = cursor.getInt((int) cursor.getColumnIndex("status"));
                        ((BPA_SILOS) data).Sort = cursor.getInt((int) cursor.getColumnIndex("Sort"));
                        ((BPA_SILOS) data).silosmargin = cursor.getInt((int) cursor.getColumnIndex("silosmargin"));
                        ((BPA_SILOS) data).siloszl = cursor.getInt((int) cursor.getColumnIndex("siloszl"));
                        break;
                    case "BPA_SILOSANDMATERIAL":
                        data = new BPA_SILOSANDMATERIAL();
                        //私有
                        ((BPA_SILOSANDMATERIAL) data).silosID = cursor.getString((int) cursor.getColumnIndex("silosID"));
                        ((BPA_SILOSANDMATERIAL) data).materialID = cursor.getString((int) cursor.getColumnIndex("materialID"));
                        break;
                    case "BPA_GOODS":
                        data = new BPA_GOODS();
                        //私有
                        ((BPA_GOODS) data).name = cursor.getString((int) cursor.getColumnIndex("name"));
                        ((BPA_GOODS) data).sort = cursor.getInt((int) cursor.getColumnIndex("sort"));
                        ((BPA_GOODS) data).status = cursor.getInt((int) cursor.getColumnIndex("status"));
                        ((BPA_GOODS) data).url = cursor.getString((int) cursor.getColumnIndex("url"));
                        ((BPA_GOODS) data).gyid = cursor.getString((int) cursor.getColumnIndex("gyid"));

                        ((BPA_GOODS) data).maketime = cursor.getInt((int) cursor.getColumnIndex("maketime"));
                        ((BPA_GOODS) data).issc = cursor.getInt((int) cursor.getColumnIndex("issc"));

                        break;
                    case "BPA_GOODSRECIPE":
                        data = new BPA_GOODSRECIPE();
                        //私有
                        ((BPA_GOODSRECIPE) data).goodsID = cursor.getString((int) cursor.getColumnIndex("goodsID"));
                        ((BPA_GOODSRECIPE) data).materialID = cursor.getString((int) cursor.getColumnIndex("materialID"));
                        ((BPA_GOODSRECIPE) data).value = cursor.getInt((int) cursor.getColumnIndex("value"));
                        ((BPA_GOODSRECIPE) data).sort = cursor.getInt((int) cursor.getColumnIndex("sort"));
                        ((BPA_GOODSRECIPE) data).materialType = cursor.getInt((int) cursor.getColumnIndex("materialType"));
                        ((BPA_GOODSRECIPE) data).processname = cursor.getString((int) cursor.getColumnIndex("processname"));
                        ((BPA_GOODSRECIPE) data).processvalue = cursor.getString((int) cursor.getColumnIndex("processvalue"));
                        ((BPA_GOODSRECIPE) data).processms = cursor.getString((int) cursor.getColumnIndex("processms"));
                        break;
                    case "BPA_ORDER":
                        data = new BPA_ORDER();
                        //私有
                        ((BPA_ORDER) data).thirdPartyID = cursor.getString((int) cursor.getColumnIndex("thirdPartyID"));
                        ((BPA_ORDER) data).status = cursor.getInt((int) cursor.getColumnIndex("status"));
                        ((BPA_ORDER) data).sortId = cursor.getString((int) cursor.getColumnIndex("sortId"));
                        break;
                    case "BPA_SUBORDER":
                        data = new BPA_SUBORDER();
                        //私有
                        ((BPA_SUBORDER) data).orderID = cursor.getString((int) cursor.getColumnIndex("orderID"));
                        ((BPA_SUBORDER) data).goodsID = cursor.getString((int) cursor.getColumnIndex("goodsID"));
                        ((BPA_SUBORDER) data).number = cursor.getInt((int) cursor.getColumnIndex("number"));
                        ((BPA_SUBORDER) data).status = cursor.getInt((int) cursor.getColumnIndex("status"));
                        ((BPA_SUBORDER) data).goodImg = cursor.getString((int) cursor.getColumnIndex("goodImg"));
                        ((BPA_SUBORDER) data).originalMoney = cursor.getDouble((int) cursor.getColumnIndex("originalMoney"));
                        ((BPA_SUBORDER) data).realMoney = cursor.getDouble((int) cursor.getColumnIndex("realMoney"));
                        break;
                    case "BPA_ALERTLOG":
                        data = new BPA_ALERTLOG();
                        //私有
                        ((BPA_ALERTLOG) data).type = cursor.getInt((int) cursor.getColumnIndex("type"));
                        ((BPA_ALERTLOG) data).text = cursor.getString((int) cursor.getColumnIndex("text"));
                        break;
                    case "BPA_LOG":
                        data = new BPA_LOG();
                        //私有
                        ((BPA_LOG) data).type = cursor.getInt((int) cursor.getColumnIndex("type"));
                        ((BPA_LOG) data).text = cursor.getString((int) cursor.getColumnIndex("text"));
                        break;
                    case "BPA_ORDERLOG":
                        data = new BPA_ORDERLOG();
                        //私有
                        ((BPA_ORDERLOG) data).suborderID = cursor.getString((int) cursor.getColumnIndex("suborderID"));
                        ((BPA_ORDERLOG) data).prewStatus = cursor.getInt((int) cursor.getColumnIndex("prewStatus"));
                        ((BPA_ORDERLOG) data).currentStatus = cursor.getInt((int) cursor.getColumnIndex("currentStatus"));
                        break;
                    case "BPA_ORDERLOGDESC":
                        data = new BPA_ORDERLOGDESC();
                        //私有
                        ((BPA_ORDERLOGDESC) data).suborderID = cursor.getString((int) cursor.getColumnIndex("suborderID"));
                        ((BPA_ORDERLOGDESC) data).text = cursor.getString((int) cursor.getColumnIndex("text"));
                        break;
                    case "BPA_SYSTEMSET":
                        data = new BPA_SYSTEMSET();
                        //私有
                        ((BPA_SYSTEMSET) data).type = cursor.getInt((int) cursor.getColumnIndex("type"));
                        ((BPA_SYSTEMSET) data).value = cursor.getString((int) cursor.getColumnIndex("value"));
                        break;
                    case "BPA_USER":
                        data = new BPA_USER();
                        //私有
                        ((BPA_USER) data).name = cursor.getString((int) cursor.getColumnIndex("name"));
                        ((BPA_USER) data).account = cursor.getString((int) cursor.getColumnIndex("account"));
                        ((BPA_USER) data).pass = cursor.getString((int) cursor.getColumnIndex("pass"));
                        break;
                    case "BPA_MENU":
                        data = new BPA_MENU();
                        //私有
                        ((BPA_MENU) data).name = cursor.getString((int) cursor.getColumnIndex("name"));
                        break;
                    case "BPA_MENUANDUSER":
                        data = new BPA_MENUANDUSER();
                        //私有
                        ((BPA_MENUANDUSER) data).menuID = cursor.getString((int) cursor.getColumnIndex("menuID"));
                        break;
                    case "BPA_SUGAR":
                        data = new BPA_SUGAR();
                        //私有
                        ((BPA_SUGAR) data).sugarName = cursor.getString((int) cursor.getColumnIndex("sugarName"));
                        ((BPA_SUGAR) data).plcvar = cursor.getString((int) cursor.getColumnIndex("plcvar"));
                        break;
                    case "BPA_CRAFT":
                        data = new BPA_CRAFT();
                        //私有
                        ((BPA_CRAFT) data).status = cursor.getInt((int) cursor.getColumnIndex("status"));
                        ((BPA_CRAFT) data).name = cursor.getString((int) cursor.getColumnIndex("name"));
                        break;
                    case "BPA_CRAFTPROCESS":
                        data = new BPA_CRAFTPROCESS();
                        //私有
                        ((BPA_CRAFTPROCESS) data).gyid = cursor.getString((int) cursor.getColumnIndex("gyid"));
                        ((BPA_CRAFTPROCESS) data).pfid = cursor.getString((int) cursor.getColumnIndex("pfid"));
                        ((BPA_CRAFTPROCESS) data).sort = cursor.getInt((int) cursor.getColumnIndex("sort"));
                        ((BPA_CRAFTPROCESS) data).value = cursor.getInt((int) cursor.getColumnIndex("value"));
                        break;
                    case "BPA_PROCESS":
                        data = new BPA_PROCESS();
                        //私有
                        ((BPA_PROCESS) data).name = cursor.getString((int) cursor.getColumnIndex("name"));
                        ((BPA_PROCESS) data).sort = cursor.getInt((int) cursor.getColumnIndex("sort"));
                        break;
                    case "BPA_PROCESSModel":
                        data = new BPA_PROCESSModel();
                        //私有
                        ((BPA_PROCESSModel) data).processid = cursor.getString((int) cursor.getColumnIndex("processid"));
                        ((BPA_PROCESSModel) data).name = cursor.getString((int) cursor.getColumnIndex("name"));
                        ((BPA_PROCESSModel) data).datatype = cursor.getInt((int) cursor.getColumnIndex("datatype"));
                        ((BPA_PROCESSModel) data).data = cursor.getString((int) cursor.getColumnIndex("data"));
                        ((BPA_PROCESSModel) data).sort = cursor.getInt((int) cursor.getColumnIndex("sort"));
                        break;
                }
                ((ModeBase) data).id = cursor.getString((int) cursor.getColumnIndex("id"));
                ((ModeBase) data).createTime = cursor.getString((int) cursor.getColumnIndex("createTime"));
                ((ModeBase) data).updateTime = cursor.getString((int) cursor.getColumnIndex("updateTime"));
                ((ModeBase) data).deleteTime = cursor.getString((int) cursor.getColumnIndex("deleteTime"));
                ((ModeBase) data).deviceID = cursor.getString((int) cursor.getColumnIndex("deviceID"));
                ((ModeBase) data).userID = cursor.getString((int) cursor.getColumnIndex("userID"));
                ((ModeBase) data).isDelete = cursor.getInt((int) cursor.getColumnIndex("isDelete"));
                ((ModeBase) data).exp = cursor.getString((int) cursor.getColumnIndex("exp"));
                rlts.add(data);
            }
            cursor.close();
            db.close();
        } catch (Exception e) {
            Log.d("查询异常", "查询异常: " + e.getMessage());
            db.close();
        } finally {
            lock.unlock();
        }
        return rlts;
    }
    //endregion
}
