IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> 浅入Android -> 正文阅读

[大数据]浅入Android

?

1. dcloud_uniplugins 注册

{
"type": "module",
"name": "PDUtils",
"class": "com.PanDianUtils"
}

2.新增数据

public static Boolean savaSheetGoodsInfo(Context context,SheetGoods options){
   boolean result=false;
    DatabaseUtil databaseUtil = new DatabaseUtil(context, null);SQLiteDatabase db = null;
    try{
        db = databaseUtil.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.clear();
        values.put("sheetId",options.getSheetId());
        values.put("goodid",options.getGoodsId());
        values.put("colorid",options.getColorId());
        values.put("longid",options.getLongId());
        values.put("sizeid",options.getSizeId());
        values.put("sizedesc",options.getSizedesc());
        values.put("colordesc",options.getColordesc());
        values.put("longdesc",options.getLongdesc());
        values.put("goodsno",options.getGoodsno());
        values.put("filedname",options.getFieldName());
        values.put("goodsname",options.getGoodsName());
        values.put("colorcode",options.getColorCode());
        values.put("quantity", options.getQuantity());
        values.put("scanTime", System.currentTimeMillis());
        db.insert("scang", null, values);
         result =true;
     }catch (Exception ex){

     }finally {
        //关闭数据库
        if (db!=null){
            db.close();
        }
     }
        return result;
}

3.单表查询

public static GoodsInfo getGoodsInfo (Context context,String sheetId,String goodsId,String colorID,String LongId,String sizeId){
    GoodsInfo goodsInfo =new GoodsInfo();
    DatabaseUtil databaseUtil = new DatabaseUtil(context, null);
    SQLiteDatabase db = databaseUtil.getWritableDatabase();
    String boxId="";
    int count = 0;
    try {
            Cursor cursor = db.rawQuery("select sum(quantity) as sumquantity ,goodsno,goodsname,colordesc,longdesc,sizedesc"             +" from scang " +
            " where sheetId=?" +
            " and goodid=?"+
            " and colorid=?"+
            " and longid=?"+
            " and sizeid=?", new String[]{sheetId,goodsId,colorID,LongId,sizeId});
            while (cursor.moveToNext()) {
                goodsInfo.setYisaoshu (cursor.getInt(cursor.getColumnIndexOrThrow("sumquantity")));
                goodsInfo.setGoodsName(cursor.getString(cursor.getColumnIndexOrThrow("goodsname")));
                goodsInfo.setGoodsNo(cursor.getString(cursor.getColumnIndexOrThrow("goodsno")));
                goodsInfo.setBarcode("");
                goodsInfo.setColordesc(cursor.getString(cursor.getColumnIndexOrThrow("colordesc")));
                goodsInfo.setLongdesc(cursor.getString(cursor.getColumnIndexOrThrow("longdesc")));
                goodsInfo.setSizedesc(cursor.getString(cursor.getColumnIndexOrThrow("sizedesc")));
                goodsInfo.setChayishu(0);
          }

    } catch (Exception ex) {

    } finally {
        //关闭数据库
        if (db != null) {
            db.close();
        }
    }
    return goodsInfo;
}

4.单表删除

public static Boolean deleteUniCode(Context context,String unicode,String sheetId){
    boolean result = false;
    DatabaseUtil databaseUtil = new DatabaseUtil(context, null);
    SQLiteDatabase db = null;
    try{
        db = databaseUtil.getReadableDatabase();
        db.execSQL(" delete from uniquecode where unicode=? and sheetId=?", new String[]{unicode,sheetId});
        result = true;
    }catch (Exception ex){


    }finally {
        //关闭数据库
        if (db!=null){
        db.close();
    }
}
    return result;
}

5.左连接 + 子查询

public static Map<String, Integer> getBottom(Context context,String sheetId){
    Map<String,Integer> map = new HashMap<>();
    DatabaseUtil databaseUtil = new DatabaseUtil(context, null);
    SQLiteDatabase db = null;


    try {
        db = databaseUtil.getReadableDatabase();
        Cursor cursor = db.rawQuery(" select ifnull(a.quantity,0) as quantity,ifnull(b.kuanShu,0) as kuanShu from \n" +
        " ( " +
        " SELECT sum(quantity) as quantity ,sheetId,longDesc, colorDesc,sizeDesc,goodsNo,goodid,colorId,longId,sizeId \n" +
        " from scang where scang.sheetId = ? \n" +
        " group by scang.sheetId\n" +
        " ) a \n" +
        " left join \n" +
        " ( " +
        " select count(distinct goodsId) as kuanShu,sheetId,longDesc, colorDesc,sizeDesc,goodsNo,goodid ,colorId,longId,sizeId \n"     +
        " from scang \n" +
        " where scang.sheetId = ? \n" +
        " group by scang.sheetId,scang.goodid\n" +
        " ) b on a.sheetId= b.sheetId"
        , new String[]{sheetId,sheetId});
    while (cursor.moveToNext()){
         map.put("zongsaomiaoshu",cursor.getInt(cursor.getColumnIndexOrThrow("quantity")));
        map.put("kuanShu",cursor.getInt(cursor.getColumnIndexOrThrow("kuanShu")));
        return map;
    }
    }catch (Exception e){


    }finally {


    }
    return map;
}

6.查询结果(1)如果 货品在scangoods不存在也会直接赋值?quantity ; 查询结果(2)则是 0

1.     Cursor cursor = db.rawQuery("select a.sheetId, a.goodsname, a.goodsno,a.goodid, ifnull(b.quantity,0) as quantity from\n" +
"(\n" +
"SELECT sheetId, goodsname, goodsno,goodid, quantity\n" +
"from sheetg\n" +
"where sheetg.sheetId =?\n" +
"GROUP BY sheetg.goodid\n" +
")a\n" +
"LEFT JOIN\n" +
"(\n" +
"SELECT sum(quantity) as quantity ,goodid,sheetId\n" +
"from scang\n" +
"where scang.sheetId =?\n" +
")b on a.sheetId = b.sheetId "
, new String[]{sheetId,sheetId});
2.     Cursor cursor = db.rawQuery("select a.sheetId, a.goodsname, a.goodsno,a.goodid, ifnull(b.quantity,0) as quantity from\n" +
"(\n" +
"SELECT sheetId, goodsname, goodsno,goodid, quantity\n" +
"from sheetg\n" +
"where sheetg.sheetId =?\n" +
"GROUP BY sheetg.goodid\n" +
")a\n" +
"LEFT JOIN\n" +
"(\n" +
"SELECT sum(quantity) as quantity ,goodid,sheetId\n" +
"from scang\n" +
"where scang.sheetId =?\n" +
")b on a.sheetId = b.sheetId and a.goodid=b.goodid"
, new String[]{sheetId,sheetId});

7.绝对值取值 (quantity不管是正数还是负数,都会取正数)

Math.abs(quantity)

8.嵌套使用

public static List<SheetGoods> checkChouCode(Context context, String sheetId, String barcode){
    List<SheetGoods> list = new ArrayList<>();
    DatabaseUtil databaseUtil = new DatabaseUtil(context, null);
    SQLiteDatabase db = null;


    try {
        db = databaseUtil.getReadableDatabase();
        Cursor cursor = db.rawQuery("select * from barcode WHERE barcode=?",new String[]{barcode});
        while (cursor.moveToNext()){
        String goodsid = cursor.getString(cursor.getColumnIndexOrThrow("goodsid"));
        Cursor cursor1 = db.rawQuery("select * from sheetg WHERE goodsid=? and sheetId=?",new String[]{ goodsid,sheetId});
        while (cursor1.moveToNext()) {
            SheetGood sheetGoods = new SheetGood();
            sheetGoods.setGoodsno(cursor1.getString(cursor1.getColumnIndexOrThrow("goodsno")));
            sheetGoods.setQuantity(cursor1.getInt(cursor1.getColumnIndexOrThrow("quantity")));
            sheetGoods.setColordesc(cursor1.getString(cursor1.getColumnIndexOrThrow("colordesc")));
            sheetGoods.setSizedesc(cursor1.getString(cursor1.getColumnIndexOrThrow("sizedesc")));
            sheetGoods.setLongdesc(cursor1.getString(cursor1.getColumnIndexOrThrow("longdesc")));
            list.add(sheetGoods);
        }
    }
    }catch (Exception exception){
        String sheet=exception.getMessage();
    }finally {
        if (db!=null){
            db.close();
        }
    }
    return list;
}

9.更新表

public static void updateSheetBoxQuantity(Context context,String sheetId,Long boxId) {
    DatabaseUtil databaseUtil = new DatabaseUtil(context, null);
    SQLiteDatabase db = null;


    try {
        db = databaseUtil.getReadableDatabase();


        db.execSQL("update sheetb set jianNum=" +
            "(select sum(quantity) from sheetd where sheetId=? and boxId=?)" +
            "where sheetId=? and boxId=?"
            , new String[]{sheetId, String.valueOf(boxId), sheetId, String.valueOf(boxId)});
    } catch (Exception ex) {
        String EX = ex.getMessage();
    } finally {
        //关闭数据库
        if (db != null) {
            db.close();
        }
    }
}

10.判断某个字段是否未空?

 if (!"".equals(zancun.getSheetCode())){}

11. 自定义方法,直接用来在uni-app中调用

@JSMethod(uiThread = true) //表示 JScript 方法。 此类属于名称绑定类别
public void getSku(JSONObject options, JSCallback jsCallback){
    myCallback = jsCallback;
    int OriQuantity=PanDian.getOriQuantityByGoods(mWXSDKInstance.getContext()
    ,options.getString("sheetId")
    ,options.getString("goodsId")
    ,options.getString("colorId")
    ,options.getString("longId")
    ,options.getString("sizeId")) ;
    Map<String, Object> map = new HashMap<>();
    map.put("code", "200");
    map.put("msg", "查询成功");
    map.put("data",OriQuantity);
    myCallback.invoke(map);
}

12.uni-app 调用 android 方法

????????requireNativePlugin:内置原生插件,uni-app已默认集成,支持直接在内置基座运行。

const PDUtils = uni.requireNativePlugin('PDUtils');   // PanDianUtils 为原生插件名称
PanDianUtils.clear({
    "sheetId": this.panDianInfo.id
}, result => {
    if (result.code == 200) {
        this.cont = "撤销录入成功";
        this.$forceUpdate();
        this.$refs.messageBox.open()
    }
})
// dcloud_uniplugins 注册
{
"type": "module",
"name": "PanDianUtils",
"class": "com.PDUtils"
}

*?注意

  • 使用前一定要注册
  • SQLite 语句的大小写不敏感,但是使用Cursor(游标)获取数据时很敏感,一定要在创建的表中存在一样的字段
  • execSQL(sql语句"",参数)里面的?代表占位符,有几个占位符就需要几个参数,参数对应的位置要保持一致
  • 每一个方法都需要加@JSMethod(uiThread = true),否则即使参数没有问题,也没法成功请求方法
  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2022-03-12 17:36:19  更:2022-03-12 17:38:03 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 8:56:32-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码