Commit 39dddc0d by 毛勇泽

文件读写

parent 5651166a
......@@ -39,3 +39,4 @@ export {pzlx_dict,szlx_dict,new_zmlx_dict} from './src/main/ets/utils/dict';
export {SearchData} from './src/main/ets/bean/dto/SearchData';
export {HWFromData} from './src/main/ets/bean/dto/SearchData';
export {WzPositionInfo} from './src/main/ets/bean/dto/WzPositionInfo';
export {uuid,dateUtils,isEmpty,isPerCent,formatLocation} from './src/main/ets/utils/util';
......@@ -7,4 +7,5 @@ export class WzPositionInfo{
YL?:number
ZS?:number
total?:number
kfdm?:string
}
\ No newline at end of file
......@@ -105,6 +105,27 @@ export class BgglDao extends BaseTable<Bggl> {
}
}
/**
* 包裹导出
*/
async exportAllSql(bgzt?:string): Promise<newBgglDto[]> {
try {
let val_sql = NativeSql.exportAllSql(bgzt);
Logger.info('包裹导出>>sql', val_sql)
let db = await this.futureDb;
let rs = await db.querySql(val_sql);
let items = []
if (rs.goToFirstRow()) {
do {
items.push(this.toWzcrkRefWz(rs))
} while (rs.goToNextRow())
}
Logger.info(this, '包裹导出>>' + JSON.stringify(items))
return items;
} catch (e) {
throw new Error('[查询异常]|' + e)
}
}
/**
* 查询包裹数据
*/
async getBgglPageSql(params?: any): Promise<newBgglDto[]> {
......@@ -149,6 +170,18 @@ export class BgglDao extends BaseTable<Bggl> {
throw new Error('[插入异常]|' + e)
}
}
/*未领取导出 导出完执行*/
async exportAwaitSql(bgzt?:string) {
try {
let val_sql = NativeSql.exportAwaitSql(bgzt)
Logger.info('未领取导出 导出完执行>>sql', val_sql)
let db = await this.futureDb;
let rs = await db.executeSql(val_sql);
return rs;
} catch (e) {
throw new Error('[插入异常]|' + e)
}
}
/**
* // 检测包裹是否重复添加
*/
......
......@@ -162,6 +162,26 @@ export class HwInfoDao extends BaseTable<HwInfo> {
console.log("查询报错==》"+JSON.stringify(err))
}
}
async getKfdm(params?: any): Promise<WzPositionInfo[]> {
try {
Logger.info(this,"查询参数",JSON.stringify(params))
let val_sql = NativeSql.getKfdm(params) ;
console.log('查询SQL语句=' + val_sql)
let db = await this.futureDb;
let rs = await db.querySql(val_sql);
console.log('查询SQL语句开始2')
let items = []
if (rs.goToFirstRow()) {
do {
items.push(this.toKfmInfo(rs))
} while (rs.goToNextRow())
}
console.log('查询SQL结果=' + JSON.stringify(items))
return items;
}catch (err){
console.log("查询报错==》"+JSON.stringify(err))
}
}
/*删除sql*/
async deleHwRecordSql(guid?: string) {
try {
......@@ -266,4 +286,13 @@ export class HwInfoDao extends BaseTable<HwInfo> {
};
return info;
}
/**
* 转换
*/
toKfmInfo(cursor: relationalStore.ResultSet): WzPositionInfo {
let info: WzPositionInfo = {
kfdm: cursor.getString(cursor.getColumnIndex('kfdm'))
};
return info;
}
}
\ No newline at end of file
......@@ -75,5 +75,11 @@ export class XtpzInfoDao extends BaseTable<XtpzInfo> {
throw new Error('[插入异常]|' + e)
}
}
/**
* 查询系统配置
*/
async systemSql(): Promise<XtpzInfo[]> {
let wp = this.getPredicates();
return this.query(wp, this.getTableColumns());
}
}
\ No newline at end of file
......@@ -764,6 +764,36 @@ WHERE
`update tab_bzgl_knzy_app_hwb set hwsl = hwsl + ${params.hwsl} where pmdmcode = ${params.pmdmcode} and gldwguid = '${params.gldwguid}' and kfguid = '${params.kfguid}' and zmlx = '${params.zmlx}' and hwh = 'LS-1-1-1'`
return sql
}
/**/
static getKfdm (params?:any):string {
const sql = `select * from (select hw.*,qy.kfdm kfdm from tab_bzgl_knzy_app_hwb hw left join tab_bzgl_knzy_app_hjb hj on hj.guid = hw.hjguid left join tab_bzgl_knzy_app_qyb qy on qy.guid = hj.qyguid)
where hwh = '${params.hwh}' and hjguid = '${params.hjguid}'`
return sql
}
/*未领取*/
static setDpfSql(params?:any):string {
const sql =
`update TAB_BZGL_KNZY_APP_BGGL set BGZT = '未领取',hwh = '${params.hwh}',kfdm = '${params.kfdm}' where guid in ('${params.guid}')`
return sql
}
/*包裹导出*/
static exportAllSql(bgzt?:string):string {
// sfdc:0未导出 1已导出
var sql =
`select bg.*,kf.kfmc from TAB_BZGL_KNZY_APP_BGGL bg left join TAB_BZGL_KNZY_APP_DWKF kf on kf.kfdm = bg.kfdm where bg.BGZT = '${bgzt}' and sfdc = 0 `
var sql2 =
`select bg.*,kf.kfmc from TAB_BZGL_KNZY_APP_BGGL bg left join TAB_BZGL_KNZY_APP_DWKF kf on kf.kfdm = bg.kfdm where sfdc = 0 `
var sqlHz = ' order by bg.JSSJ desc'
if (bgzt == '全部') {
return sql2 + sqlHz
} else {
return sql + sqlHz
}
}
// 未领取导出 导出完执行
static exportAwaitSql(bgzt?:string):string{
return `update TAB_BZGL_KNZY_APP_BGGL set sfdc = 1 where sfdc = 0 and BGZT = '${bgzt}'`
}
}
import fs from '@ohos.file.fs';
import common from '@ohos.app.ability.common';
import { Logger } from '@ohos/common/src/main/ets/utils/Logger';
import buffer from '@ohos.buffer';
let context = getContext(this) as common.UIAbilityContext;
let filesDir = context.filesDir;
export class FileWR{
writeFile(path:string,data?:any,isStr:boolean=false){
console.log("打开文件路径"+filesDir+path)
// try{
// let srcFile = fs.openSync('/data/storage/el2/base/haps/entry/files/2024年01月29日' + '/test.txt', fs.OpenMode.READ_WRITE|fs.OpenMode.CREATE);
// fs.writeSync(srcFile.fd,"hhhhhhhhhh")
// this.readFile()
// console.info("srcFile==》"+JSON.stringify(srcFile))
// }catch (err){
// console.error(err)
// }
console.log("写入数据==》",data)
let file = fs.openSync(filesDir+path, fs.OpenMode.READ_WRITE|fs.OpenMode.CREATE);
console.info("JSONFile==》"+JSON.stringify(file))
fs.write(file.fd, data).then((writeLen) => {
console.info("write data to file succeed and size is:" + writeLen);
fs.closeSync(file);
}).catch((err) => {
console.error("write data to file failed with error message: " + err.message + ", error code: " + err.code);
});
}
/*创建文件目录*/
createFileMkdir(path?:string){
let filePath=filesDir+path
console.log("创建文件目录路径"+filePath)
if(fs.access(filePath)){
console.log("文件已存在")
return
}
fs.mkdir(filePath).then(() => {
console.info("mkdir succeed");
}).catch((err) => {
console.error("mkdir failed with error message: " + err.message + ", error code: " + err.code);
});
}
readFile(path?:string):string{
let filePath = '/data/storage/el2/base/haps/entry/files/systemFile/serialNumber.txt';
console.log("读取文件路径://==",filesDir+path)
let file = fs.openSync(filesDir+path, fs.OpenMode.READ_WRITE);
// 从文件读取一段内容
let arrayBuffer = new ArrayBuffer(1024*1024);
let readLen = fs.readSync(file.fd, arrayBuffer);
let buf = buffer.from(arrayBuffer, 0, readLen);
console.info("文件读取file: " + buf.toString());
fs.closeSync(file);
return buf.toString();
}
}
export default new FileWR()
\ No newline at end of file
......@@ -109,6 +109,16 @@ class BgglModel {
let res = await SQLiteContext.with(BgglDao).testRepetitionBgSql(ddh);
return res;
}
// 包裹导出
async exportAllSql(bgzt?:string): Promise<newBgglDto[]> {
let res = await SQLiteContext.with(BgglDao).exportAllSql(bgzt);
return res;
}
/*未领取导出 导出完执行*/
async exportAwaitSql(bgzt?:string) {
let res = await SQLiteContext.with(BgglDao).exportAwaitSql(bgzt)
return res
}
// 清空表
async clear() {
await SQLiteContext.with(BgglDao).clearTable()
......
......@@ -48,6 +48,11 @@ class HwModel {
let res = await SQLiteContext.with(HwInfoDao).getHXpageSql(searchData)
return res;
}
// 查询hw,hjguid
async getKfdm(params?: any): Promise<WzPositionInfo[]> {
let res = await SQLiteContext.with(HwInfoDao).getKfdm(params)
return res;
}
// 删除sql
async deleHwRecordSql(guid?: string) {
let res = await SQLiteContext.with(HwInfoDao).deleHwRecordSql(guid)
......
......@@ -13,7 +13,10 @@ class XtpzInfoModel {
let res = await SQLiteContext.with(XtpzInfoDao).updateSystemSql(params)
return res;
}
async systemSql() {
let res = await SQLiteContext.with(XtpzInfoDao).systemSql()
return res;
}
// 清空表
async clear() {
......
......@@ -6,7 +6,10 @@ import promptAction from '@ohos.promptAction'
import kfModel from '../../model/KfModel'
import router from '@ohos.router'
import { Logger } from '@ohos/common/src/main/ets/utils/Logger'
import IdentifyService from '../../identify/IdentifySerivce'
import { analysisQrCode } from '../../identify/analysis/analysis_QR_code'
import emitter from '@ohos.events.emitter';
import Prompt from '@system.prompt';
@Entry
@Component
export struct ArrivePack {
......@@ -14,6 +17,7 @@ export struct ArrivePack {
@State hwList: any[] = []
@State kfguid: string = ''
@State hwh: string = ''
@State hjguid:string=''
checkedList: string[]
@Builder automatic() {
......@@ -116,14 +120,22 @@ export struct ArrivePack {
build() {
Column() {
TitleBar({ title: "上架包裹" })
TitleBar({ title: "包裹上架" })
if (this.isAuto) {
this.automatic()
} else {
this.movement()
}
}.height('100%')
}.onKeyEvent((e: globalThis.KeyEvent) => {
console.error('keycode====》:' + e.keyCode)
if ((e.keyCode == 2096 || e.keyCode == 2093)) {
if (e.type == 1&&this.isAuto) {
IdentifyService.openScan()
}
}
console.error('keycode====》:' + e.keyCode)
}).height('100%')
.width('100%')
.linearGradient({
direction: GradientDirection.Right, // 渐变方向
......@@ -131,4 +143,96 @@ export struct ArrivePack {
colors: [[0x36a3c0, 0.0], [0x97c6a6, 1], [0xc7d799, 0.0]] // 数组末尾元素占比小于1时满足重复着色效果
}).padding({ bottom: 20 })
}
scanCodeListen() {
var innerEvent = { eventId: 2 }
emitter.on(innerEvent, (eventData) => {
if (innerEvent.eventId == 2) {
let result = eventData.data.scancode
console.log("扫码校验", "收到扫码信息:" + result)
this.showQRDetail(result)
}
})
}
async showQRDetail(hwQrCode: string) {
Logger.info("扫码二维码===》" + hwQrCode)
this.handleanalysisQrCode(hwQrCode)
}
async handleanalysisQrCode(value) {
try {
console.log(value, 'value')
const res = await analysisQrCode(value)
if (res.data && res.data.length > 0) {
console.log(res.data, 'res.data')
res.data.forEach((item) => {
const {
hwh,
hjguid,
ddh,
bgzt
} = item
if (hwh && hjguid) {
this.hwh = hwh
this.hjguid = hjguid
this.handleSetDpf()
}
if (!this.hwh) {
Prompt.showToast({
message: '请扫描货位'
})
return
}
})
} else {
Prompt.showToast({
message: '请检查基础数据是否完善'
})
}
} catch (e) {
Prompt.showToast({
message: '解析失败'
})
}
}
async handleSetDpf() {
try {
const testParams = {
hwh: this.hwh,
hjguid: this.hjguid
}
const res = await hwModel.getKfdm(testParams)
console.log(JSON.stringify(res[0]))
const params = {
guid: this.checkedList.join(','),
kfdm: res[0].kfdm,
hwh: this.hwh
}
await bgglModel.setDpf({kfdm:params.kfdm,guid:params.guid,hwh:params.hwh})
// uni.$emit('updateHitTheShelfValue', {
// data: 1,
// msg: '上架成功'
// })
Prompt.showToast({
message: '上架成功'
})
setTimeout(() => {
router.back()
}, 1500)
} catch (e) {
Prompt.showToast({
message: '上架失败'
})
}
}
onPageShow() {
console.error("========onPageShow=========")
this.scanCodeListen()
IdentifyService.openScanPort()
}
onPageHide() {
IdentifyService.closeScan()
/*取消扫码订阅*/
emitter.off(2);
}
}
\ No newline at end of file
......@@ -3,11 +3,11 @@ import { TitleBar } from '../../view/title/TitleBar'
import router from '@ohos.router'
import bgglModel from '../../model/BgglModel'
import { Bggl } from '@ohos/common/src/main/ets/entity/Bggl'
import { Logger } from '@ohos/common/src/main/ets/utils/Logger'
import { Logger,dateUtils } from '@ohos/common'
import { PackList } from './PackList'
import { newBgglDto } from '@ohos/common/src/main/ets/bean/dto/BgglDto'
import promptAction from '@ohos.promptAction'
import FileWR from '../../io/FileWR'
interface Type {
type: "wait" | "unclaimed" | "received" | "all"
}
......@@ -41,8 +41,10 @@ export struct Pack {
@State ddh: string = ''
@State bgzt: string = ''
@State checkedList: string[] = []
optionsData:string[]=['待上架', '未领取', '已领取', '全部']
onPageShow() {
// Logger.info(this,"文件路径==》"+JSON.stringify(filesDir))
let params = router.getParams() as Type;
this.type = params.type
......@@ -85,7 +87,7 @@ export struct Pack {
build() {
Column() {
Flex({ direction: FlexDirection.Column }) {
TitleBar({ title: "包裹信息查询" })
TitleBar({ title: "包裹查询" })
Row() {
Flex({ justifyContent: FlexAlign.SpaceAround, alignItems: ItemAlign.Center }) {
......@@ -128,7 +130,9 @@ export struct Pack {
this.ddh = value
this.getPackList()
})
Button("导出").CommonButtonStyle()
Button("导出").CommonButtonStyle().onClick(()=>{
this.handleWpfExport()
})
Button("打印面单").CommonButtonStyle()
}
......@@ -144,7 +148,9 @@ export struct Pack {
this.ddh = value
this.getPackList()
})
Button("导出").CommonButtonStyle()
Button("导出").CommonButtonStyle().onClick(()=>{
this.handleYpfExport()
})
}
}
}.padding({ top: 20 })
......@@ -182,4 +188,198 @@ export struct Pack {
colors: [[0x36a3c0, 0.0], [0x97c6a6, 1.0], [0xc7d799, 2.0]]
})
}
/***
* @description: 未派发导出
*/
handleWpfExport() {
var that = this
that.handleWpfAllExport()
}
/***
* @description: 未派发导出
* @param {*}
* @return {*}
* @author: 王弘钢
*/
async handleWpfAllExport() {
// 第一步:读取数据
// 第二步:写文件
// 第三步:提示地址展示
// 第四步:查看文件
try {
const params = {
bgzt: this.optionsData[1]
}
const res = await bgglModel. exportAllSql(params.bgzt)
if (res && res.length > 0) {
const date = dateUtils.formatDateTime(new Date(), 'before')
const time = dateUtils.formatDateTime(new Date(), 'after')
FileWR.createFileMkdir("/"+date);
// const path = 'file://storage/emulated/0/Download/仓库终端导出数据/包裹数据/' + date + '/包裹数据-未派发' + time +
// '.json'
FileWR.writeFile("/"+date+ '/包裹数据-未派发' + time + '.json',JSON.stringify(res));
await bgglModel.exportAwaitSql(params.bgzt)
// this.init(this.current)
this.getPackList()
// const path = 'file://storage/emulated/0/Download/bzck/已领取数据.json'
// if (this.sysConfig.transmission_mode == 'network') {
// // const dwData = await database.selectInformationType(
// // "GY_M_PMV3",
// // sqlCommon.getDw())
// // console.log('单位数据:', dwData)
// // if (dwData.length == 0) {
// // promptAction.showToast({
// // message: '请检查单位基础信息'
// // })
// // return
// // }
// // await transferApi.enwrapUp({
// // pzzbJson: res,
// // // crklx: '11111CRKLX6',
// // // bestrow: true,
// // gznd: '2023',
// // dwguid: dwData[0].DWDM
// // })
// // uni.showModal({
// // title: '提示',
// // content: '未派发包裹数据导出成功,并已同步至业务系统',
// // confirmText: '已知晓',
// // showCancel: false,
// // success: function(RES) {
// // if (RES.confirm) {
// // console.log('用户点击确定');
// // // uni.navigateTo({
// // // url: '/pages/sub_systemMaintenance/burnerDescription/burnerDescription'
// // // })
// // } else if (RES.cancel) {
// // console.log('用户点击取消');
// // }
// // }
// // });
// } else {
// const cipherText = JSON.stringify(res)
// console.log('cipherText', cipherText)
// // await io.storage(path, cipherText, false)
// // await io.storage(path, res)
// // setTimeout(() => {
// // uni.showModal({
// // title: '提示',
// // content: '导出路径:' + path + '请将数据包同步到被装系统.刻录须知,是否前往查看',
// // confirmText: '前往查看',
// // cancelText: '已知晓',
// // success: function(RES) {
// // if (RES.confirm) {
// // console.log('用户点击确定');
// // uni.navigateTo({
// // url: '/pages/sub_systemMaintenance/burnerDescription/burnerDescription'
// // })
// // } else if (RES.cancel) {
// // console.log('用户点击取消');
// // }
// // }
// // });
// // }, 1500)
// }
// await bgglModel.exportAwaitSql()
// // this.init(this.current)
// this.getPackList()
} else {
promptAction.showToast({
message: '暂无数据,无法导出'
})
}
} catch (e) {
promptAction.showToast({
message: '导出失败'
})
}
}
async handleYpfExport() {
// 第一步:读取数据
// 第二步:写文件
// 第三步:提示地址展示
// 第四步:查看文件
try {
const params = {
bgzt: this.optionsData[2]
}
const res = await bgglModel.exportAllSql(params.bgzt)
if (res && res.length > 0) {
const date = dateUtils.formatDateTime(new Date(), 'before')
const time = dateUtils.formatDateTime(new Date(), 'after')
const path = 'file://storage/emulated/0/Download/仓库终端导出数据/包裹数据/' + date + '/包裹数据-已领取' + time +
'.json'
FileWR.createFileMkdir("/"+date);
// const path = 'file://storage/emulated/0/Download/仓库终端导出数据/包裹数据/' + date + '/包裹数据-未派发' + time +
// '.json'
FileWR.writeFile("/"+date+ '/包裹数据-已领取' + time + '.json',JSON.stringify(res));
await bgglModel.exportAwaitSql(params.bgzt)
// this.init(this.current)
this.getPackList()
// const path = 'file://storage/emulated/0/Download/bzck/已领取数据.json'
// if (this.sysConfig.transmission_mode == 'network') {
// const dwData = await database.selectInformationType("GY_M_PMV3", sqlCommon.getDw())
// console.log('单位数据:', dwData)
// if (dwData.length == 0) {
// uni.showToast({
// title: '请检查单位基础信息',
// icon: 'none'
// })
// return
// }
// await transferApi.enwrapUp({
// pzzbJson: res,
// // crklx: '11111CRKLX6',
// // bestrow: true,
// gznd: '2023',
// dwguid: dwData[0].DWDM
// })
// uni.showModal({
// title: '提示',
// content: '已领取包裹数据导出成功,并已同步至业务系统',
// confirmText: '已知晓',
// showCancel: false,
// success: function(RES) {
// if (RES.confirm) {
// console.log('用户点击确定');
// } else if (RES.cancel) {
// console.log('用户点击取消');
// }
// }
// });
// } else {
// // const cipherText = encryptByAES(JSON.stringify(res), this.$appSecretKey);
// // console.log('cipherText', cipherText)
// // await io.storage(path, cipherText, false)
// // // await io.storage(path, res)
// // // setTimeout(() => {
// // // uni.showModal({
// // // title: '提示',
// // // content: '导出路径:' + path + ',刻录须知,是否前往查看',
// // // confirmText: '前往查看',
// // // cancelText: '已知晓',
// // // success: function(RES) {
// // // if (RES.confirm) {
// // // console.log('用户点击确定');
// // // uni.navigateTo({
// // // url: '/pages/sub_systemMaintenance/burnerDescription/burnerDescription'
// // // })
// // // } else if (RES.cancel) {
// // // console.log('用户点击取消');
// // // }
// // // }
// // // });
// // // }, 1500)
// }
} else {
promptAction.showToast({
message: '暂无数据,无法导出'
})
}
} catch (e) {
promptAction.showToast({
message: '导出失败'
})
}
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ import { TitleBar } from '../../view/title/TitleBar'
import promptAction from '@ohos.promptAction'
import { GeneralDialog } from '../../view/GeneralDialog/GeneralDialog'
import xtpzInfoModel from '../../model/XtpzInfoModel'
import FileWR from '../../io/FileWR'
@Extend(Button) function CommonButtonStyle() {
.borderWidth(2)
......@@ -29,13 +30,15 @@ interface FormData {
scan_read_mode: string,
scanning_mode: string,
broadcastKey: string,
power: string
power: string,
sbbm:string
}
@Entry
@Component
export struct General {
xlhPath: string='/systemFile/serialNumber.txt'
@State systemTitle: Array<string> = ['直连配置','扫描配置','系统配置'];
@State clickItem: UniListItem = {
title: '',
......@@ -57,7 +60,8 @@ export struct General {
scan_read_mode: "",
scanning_mode: "",
broadcastKey: "",
power: ""
power: "",
sbbm:""
}
onPageShow() {
......@@ -72,21 +76,53 @@ export struct General {
*/
async init() {
try {
// const sysRes = await selectInformationType("GY_M_PMV3", sqlCommon.systemSql)
// const data = this.convertionToggleCase(sysRes)
// console.log('data', data)
// this.formData = {
// sbbm: '',
// ...data
// }
// this.handleGetSbbm()
// const sysRes = await xtpzInfoModel.systemSql()
// // const data = this.convertionToggleCase(sysRes)
// // console.log('data', data)
// // this.formData = {
// // sbbm: '',
// // ...data
// // }
FileWR.createFileMkdir('/systemFile')
this.handleGetSbbm()
} catch (e) {
//TODO handle the exception
promptAction.showToast({
message: '初始配置失败'
})
}
}
async handleGetSbbm() {
this.handleTestIo()
}
async handleTestIo(value?:string) {
try {
const data = await FileWR.readFile(this.xlhPath)
if (value == 'noHave' && data =='') {
promptAction.showToast({
message: '请联系管理员'
})
return
}
this.formData.sbbm = data.slice(1, 16) || ''
console.log('formData.sbbm', this.formData.sbbm)
} catch (e) {
console.log("文件未找到报错::"+JSON.stringify(e))
var that = this
if (value == 'noHave') {
return
}
//TODO handle the exception
if (e.code == 13900002 || e.message == '路径不存在') {
let randomNum1 = Math.floor(Math.random() * Math.pow(10, 5)).toString()
let randomNum2 = new Date().getTime().toString().substring(0, 10);
that.formData.sbbm = randomNum1 + randomNum2
const xlh = that.formData.sbbm
console.log('formData.sbbm', that.formData.sbbm)
await FileWR.writeFile(this.xlhPath, xlh, false)
await that.handleTestIo('noHave')
}
}
}
/***
* @description: 保存
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论