Commit 9c216eae by 毛勇泽

射频扫码解析

parent 66eef2b5
......@@ -56,9 +56,9 @@ export class WzdmDao extends BaseTable<Wzdm> {
async selectWZDM(lsm?:string):Promise<Wzdm[]>{
let wp = this.getPredicates();
if (lsm) {
wp.equalTo('LSM', lsm);
wp.equalTo('lsm', lsm);
}
wp.orderByAsc('LSM');
wp.orderByAsc('lsm');
return this.query(wp, this.getTableColumns())
}
}
\ No newline at end of file
export class TimeUtil{
getDateString(time:string):string{
let outputDate: string = "";
const outputFormat: string = "yyyy-MM-dd";
const possibleFormats: string[] = [
"yyyy-MM-dd",
"yyyyMMdd",
"yyyy/MM/dd",
"yyyyMMddHHmmss",
"yyyy-MM-dd HH:mm:ss",
// 添加其他可能的日期格式
];
let date: Date | null = null;
const outputFormatter: Intl.DateTimeFormat = new Intl.DateTimeFormat('en-US', { year: 'numeric', month: '2-digit', day: '2-digit' });
for (const format of possibleFormats) {
const inputFormatter: Intl.DateTimeFormat = new Intl.DateTimeFormat('en-US', { timeZone: 'UTC', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false });
try {
const parsedDate: Date = new Date(inputFormatter.formatToParts ? inputFormatter.formatToParts(new Date(time)).map((part: Intl.DateTimeFormatPart) => part.value).join('') : time);
date = isNaN(parsedDate.getTime()) ? null : parsedDate;
break;
} catch (e) {
// 解析失败,尝试下一个日期格式
continue;
}
}
if (date !== null) {
outputDate = outputFormatter.format(date);
} else {
outputDate = this.getDate();
console.log("无法解析日期");
}
return outputDate;
}
getDate(): string {
const today: Date = new Date();
const year: number = today.getFullYear();
const month: number = today.getMonth() + 1; // 月份从0开始
const day: number = today.getDate();
const pad = (num: number): string => (num < 10 ? '0' : '') + num;
return `${year}-${pad(month)}-${pad(day)}`;
}
getDateInt(date: string): number {
let time: number = 0;
let timeInt: number = 0;
if (date === "") {
return 0;
}
// 输入日期,转换为毫秒数,用 Date 方法()
/**
* 使用 new Date(dateString) 将日期字符串转化为 Date 对象
* 通过 Date.getTime() 方法,将其转化为毫秒数
*/
try {
const parsedDate: Date = new Date(date);
time = parsedDate.getTime() / 1000;
timeInt = Math.floor(time);
} catch (e) {
console.error(e);
}
return timeInt;
}
}
export default new TimeUtil()
\ No newline at end of file
......@@ -37,10 +37,15 @@ function isPlainObject(obj) {
return Object.prototype.toString.call(obj) === '[object Object]'
}
function replaceAll(string, search, replace) {
return string.split(search).join(replace);
function replaceAll(inputString: string, search: string, replace: string): string {
return inputString.split(search).join(replace);
}
async function analysisQrCode(bqData, isData = false) {
function removeSpecialCharacters(inputString: string): string {
// 使用正则表达式替换特殊字符为空字符串
const regex = /[^\w\d\s]/g;
return inputString.replace(regex, "");
}
async function analysisQrCode(bqData:string, isData:boolean = false) {
//15所二维码信息
//bqData = "\u001E07\u001DA002868625394\u001DA00107陆女军官春秋常服\u001DA006165/88\u001DA0031000A05133A010000001000000010000001\u001DA90900000000000000000000000000000001\u001E\u0004";
//bqData = "07A002868736774A00105女棉鞋A00622A90150件/箱A005北京生产厂家A902件A0511A0102021-01-10A3836个月A012760301106A0610.001A909e17d3e0a5f3e45548e92888e0640059bc";
......@@ -48,12 +53,15 @@ async function analysisQrCode(bqData, isData = false) {
// TODO 标签解析
// 07A00120轻便作战靴A002889000004A006290A010202303A005军委机关
var str = bqData
str = replaceAll(str, "", "")
str = replaceAll(str, "", "")
str = replaceAll(str, "", "")
str = replaceAll(str, "{", "")
str = replaceAll(str, "}", "")
str = replaceAll(str, "\n", "");
console.log("str=======>"+str)
// 移除特定字符
// str = replaceAll(str, "", "");
// str = replaceAll(str, "", "");
// str = replaceAll(str, "", "");
// str = replaceAll(str, "{", "");
// str = replaceAll(str, "}", "");
// str = replaceAll(str, "\n", "");
// str=removeSpecialCharacters(str)
var hx_map = {} //号型数量/查询条件
var res1 = "";
var pmdm = "";
......@@ -246,6 +254,7 @@ async function analysisQrCode(bqData, isData = false) {
// let sql = `SELECT HXMC,PMDMTEN from TAB_XTWH_JCSJ_BZHX where WZPM='${hx_map.wzdm}'`
// const allList = await selectInformationType("GY_M_PMV3", allsql)
// const allList1 = await createOrFindSQL("GY_M_PMV3", allsql1)\
bzhxModal.queryLsm(str)
console.log('sql', sql)
let wzdmList = await bzhxModal.queryHXlist(sql)
for (let j = 0; j < wzdmList.length; j++) {
......
import TimeUtil from '../../TimeUtil'
import TimeUtil from '../TimeUtil'
export default class ProductEpc196 {
// 标头信息
......
......@@ -27,6 +27,7 @@ class BzhxModel {
}
async queryLsm(lsm?: string):Promise<Wzdm[]> {
let res = await SQLiteContext.with(WzdmDao).selectWZDM(lsm);
Logger.info("查询LSM结果"+JSON.stringify(res))
return res;
}
async queryHXlist(sql?: string):Promise<Wzhxdm[]> {
......
......@@ -6,4 +6,7 @@ class DsRfidModel {
data.guid=uuid()
await SQLiteContext.with(DsRfidDao).insert(data)
}
}
\ No newline at end of file
}
const dsRfidModel = new DsRfidModel()
export default dsRfidModel
\ No newline at end of file
......@@ -23,7 +23,6 @@ struct GoodsSelectHwPage{
TitleBar({ title: "货位"})
Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center }) {
Column() {
Select([{ value: "LS-1-1-2" }, { value: "LS-1-1-3" }, { value: "LS-1-1-4" }])
.value('请选择')
.borderWidth(1)
......@@ -37,7 +36,7 @@ struct GoodsSelectHwPage{
.onSelect((index: number, value?: string) => {
})
}.width('70%').margin({ right: 10 })
}.visibility(this.model?Visibility.Visible:Visibility.Hidden).width('70%').margin({ right: 10 })
Button(this.model ? "切换自动选" : "切换手动选")
.borderRadius(6)
......@@ -49,8 +48,6 @@ struct GoodsSelectHwPage{
this.model = ! this.model
})
}.padding({left: 20, right: 20})
Column() {
if (this.model) {
......
import { TitleBar } from '../../view/title/TitleBar'
import { BasicTable } from '../../view/BasicTable/BasicTable'
import {analysisQrCode} from '../../identify/analysis/analysis_QR_code'
import wzcrkModel from '../../model/WzcrkModel';
import dsRfidModel from '../../model/DsRfidModel';
import Prompt from '@system.prompt';
import ProductEpc from '../../identify/analysis/label/ProductEpc';
import {
DsRfid,Logger
} from '@ohos/common';
import IdentifyService from '../../identify/IdentifySerivce'
import emitter from '@ohos.events.emitter';
import router from '@ohos.router';
@Extend(Button) function CommonButtonStyle() {
.borderWidth(2)
.borderColor('#0fa983')
......@@ -23,6 +26,7 @@ struct UHFScanPage{
@State selectedFontColor: string = '#fff'
@State currentIndex: number = 0
@State hjRfidList:DsRfid[]=[]
@State rfidList:DsRfid[]=[]
private controller: TabsController = new TabsController()
private searchcontroller: SearchController = new SearchController()
@State doneEpcsList: string[] = []
......@@ -112,6 +116,7 @@ struct UHFScanPage{
.onChange((isOn: boolean) => {
if(isOn){
IdentifyService.openRFIDInv()
this.handleanalysisQrCode("050400000000000016033C62BF2A111F0000A10040E220419000");
}else {
IdentifyService.stopRfidInv()
}
......@@ -123,7 +128,7 @@ struct UHFScanPage{
}.width("100%").height("10%").margin({top:10,left:10})
this.ListHeadView()
List(){
ForEach(this.doneEpcsList,(item,index)=>{
ForEach(this.rfidList,(item,index)=>{
this.wzListView(item)
})
}.height("70%")
......@@ -131,6 +136,9 @@ struct UHFScanPage{
Row() {
Flex({ justifyContent: FlexAlign.SpaceEvenly, alignItems: ItemAlign.Center}) {
Button("选择货位").CommonButtonStyle().width("45%")
.onClick(()=>{
router.pushUrl({url:"pages/metailmange/GoodsSelectHwPage"})
})
Button("扫货位码").CommonButtonStyle().width("45%")
}
}.margin({left:10,right:10}).height(80)
......@@ -148,23 +156,83 @@ struct UHFScanPage{
let result = eventData.data.epc
console.log("射频扫码","收到EPC:" + result)
if(result!=undefined&&!this.doneEpcsList.includes(result)&&result.substring(0, 2)=='05'){
this.showList(result)
IdentifyService.stopRfidInv();
// this.showList(result)
}
}
})
}
showList(epc?:string){
this.doneEpcsList.push(epc)
try {
// this.handleanalysisQrCode("050400000000000016033C62BF2A111F0000A10040E220419000");
const [filterData] = this.hjRfidList.filter(fItem => fItem.epc == epc)
if (!filterData) {
this.handleanalysisQrCode("050400000000000016033C62BF2A111F0000A10040E220419000");
}
}catch (err){
Logger.info("解析失败1"+epc+JSON.stringify(err))
console.error("Stack Trace1:", err.stack);
}
}
/*
* RFDID解析*/
async handleanalysisQrCode(rfid:string){
const res = await analysisQrCode(rfid, true)
async handleanalysisQrCode(epcstr:string){
console.log("解析的EPC:"+epcstr)
let pro = new ProductEpc()
pro.strEpc=epcstr
pro.getInfoFormEpc();
console.log("proEpc"+pro.strEpc)
console.log("LSM"+pro.getiWzLsm())
try {
const res = await analysisQrCode(pro.getiWzLsm().toString(), true)
}catch (err){
Logger.info("解析失败"+epcstr+JSON.stringify(err))
console.error("Stack Trace:", err.stack);
}
const res = await analysisQrCode(pro.getiWzLsm().toString(), true)
console.log('RFDID解析返回数据', res)
if (res.data && res.data.length == 0) {
console.log('RFDID解析返回数据', res)
return
}
if (res.data && res.data.length > 0) {
Logger
res.data.forEach((item) => {
let params: DsRfid = {
guid: "",
wzcrkguid: "1",
pmdmcode: "",
pmmc: "",
pmdm: "",
hxmc: "",
xh: pro.getiXangNo().toString(),
sl: pro.getStrNum(),
hwh: "",
epc: epcstr,
subepc: epcstr,
...item
}
console.log('params', params)
dsRfidModel.set(params)
const newParams: DsRfid = {
guid: params.guid,
wzcrkguid: params.wzcrkguid,
pmdmcode: params.pmdmcode,
pmmc: params.pmmc,
pmdm: params.pmdm,
hxmc: params.hxmc,
xh: params.xh,
sl: params.sl,
hwh: "",
epc: params.epc,
subepc: params.subepc,
}
this.hjRfidList.push(newParams)
this.rfidList.push(newParams)
// this.handleGetRfidList()
})
}
}
onPageShow() {
console.error("========onPageShow=========")
......
......@@ -28,6 +28,20 @@ export struct WzInPage {
@State checkedList: Array<string> = []
private controller: TabsController = new TabsController()
private searchcontroller: SearchController = new SearchController()
@State defaultSelectValue:Array<SelectOption>=[{ value: "未完成" }, { value: "已完成" }]
@State selectValue:Array<SelectOption>=[{ value: "未完成" }, { value: "已完成" }, { value: "完成已绑定" }]
@State page:number=1
@State rows:number=10
@State sjlx:string="0"
@State wczt:string=""
@State pzh:string=""
params = {
pzh:this.pzh,
page: this.page,
rows: this.rows,
sjlx: this.currentIndex===0?"导入":"临时收物",
wczt: "未完成"
}
itemClick() {
router.pushUrl({ url: 'pages/order_detail/PzInOutDetailPage' })
......@@ -130,7 +144,18 @@ export struct WzInPage {
})
.fontColor("#0fa983")
.fontSize("14vp")
Button("单据匹配")
.visibility(this.currentIndex === 1 ? Visibility.Visible : Visibility.None)
.bottomBtnSty()
.onClick(() => {
router.pushUrl({
url: "pages/metailmange/AddTemporaryInPage",
})
})
.fontColor("#0fa983")
.fontSize("14vp")
Button("导出数据包")
.visibility(this.currentIndex === 0 ? Visibility.Visible : Visibility.None)
.bottomBtnSty()
.onClick(() => {
}).fontColor("#0fa983").fontSize("14vp")
......@@ -186,11 +211,12 @@ export struct WzInPage {
.textFont({ size: 14, weight: 400 })
.width('60%')
.onSubmit((value: string) => {
this.pzh=value
})
.onChange((value: string) => {
})
.borderRadius(5)
Select([{ value: "未完成" }, { value: "已完成" }])
Select(this.currentIndex===1?this.selectValue:this.defaultSelectValue)
.value('请选择状态')
.borderWidth(1)
.borderRadius(6)
......@@ -238,9 +264,9 @@ export struct WzInPage {
// 底部按钮
Row() {
this.bottomButtons();
}.backgroundColor("#97c6a6").width("100%").height(80)
}.width("100%")
}
}.linearGradient({
}.width("100%").linearGradient({
direction: GradientDirection.Right, // 渐变方向
repeating: true, // 渐变颜色是否重复
colors: [[0x36a3c0, 0.0], [0x97c6a6, 1], [0xc7d799, 0.0]] // 数组末尾元素占比小于1时满足重复着色效果
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论