| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 | 
							- // #ifdef APP-ANDROID
 
- import { selectTableData, insertTableData, updateTableData, selectJoinTableData, selectRecordData, selectRecordInfo, selectLatestInfoData, deleteTableData } from '@/utils/sqlite'
 
- // #endif
 
- export type Download = {
 
- 	pdid : number,
 
- 	workorder : string,
 
- 	invname : string,
 
- 	productno : string,
 
- 	graphid : string,
 
- 	cardno : string,
 
- 	processno : string,
 
- 	ver : string,
 
- 	updatetime : string,
 
- 	progress : string,
 
- 	status : number
 
- }
 
- export type Record = {
 
- 	sxid : number,
 
- 	senum : number,
 
- 	photoitem : string,
 
- 	productno : string,
 
- 	part : string,
 
- 	descb : string,
 
- 	date : string,
 
- 	partno : string,
 
- 	num : number,
 
- 	status : number,
 
- 	urlspl : string[],
 
- 	imgname : string[],
 
- 	urlpdt : string[]
 
- }
 
- export type TaskProcess = {
 
- 	id : number
 
- 	name : string
 
- 	num : number
 
- 	step : number
 
- 	status : number
 
- }
 
- export type JoinRecord = {
 
- 	sxid : number,
 
- 	senum : number,
 
- 	photoitem : string,
 
- 	productno : string,
 
- 	part : string,
 
- 	descb : string,
 
- 	date : string,
 
- 	partno : string,
 
- 	num : number,
 
- 	status : number,
 
- 	urlspl : string
 
- 	imgname : string,
 
- 	urlpdt : string,
 
- 	pid : number,
 
- 	workorder : string,
 
- 	invname : string
 
- }
 
- export type RecordCalculate = {
 
- 	photoitem : string,
 
- 	pid : number,
 
- 	step : number,
 
- 	total : number,
 
- 	status : number
 
- }
 
- //检验任务
 
- export type TaskInfo = {
 
- 	gxid : string, 
 
- 	itemTitle: string,
 
- 	photoitemStep : number,
 
- 	photoitemTotal: number,
 
- 	photoitemStatus: string,
 
- 	recordStep : number,
 
- 	recordTotal : number,
 
- 	recordStatus : string,
 
- 	keypointStep : number,
 
- 	keypointTotal : number
 
- 	keypointStatus : string
 
- }
 
- export function offlineData(data : UTSJSONObject) : Promise<UTSJSONObject> {
 
- 	return new Promise((resolve, reject) => {
 
- 		let result = JSON.parseObject(JSON.stringify(data)) as UTSJSONObject
 
- 		resolve(result)
 
- 	});
 
- }
 
- export const statusDict = { '1': '未执行', '2': '执行中', '3': '已执行', '4': '执行错误', '5': '已取消' }
 
- export const recordStatusDict = { '1': '未拍照', '2': '拍照中', '3': '拍照完成', '4': '检验不清晰', '5': '拍照取消' }
 
- export const taskType = { '1': '检测任务', '2': '关键工序任务' }
 
- export const funcType = {'1': '新增', '2': '更新', '3': '删除'}
 
- //export const moduleType = {'1': '声像记录', '2':'检验任务', '3':'关键工序','4': '系统管理','5':'其它'}
 
- export async function getList(tableName : string, condition ?: string | null, value ?: string | null, condition2 ?: string | null, value2 ?: string | null, initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
 
- 	// #ifdef APP-ANDROID
 
- 	const result = await selectTableData(tableName, condition, value, condition2, value2);
 
- 	console.log(result);
 
- 	return result;
 
- 	// #endif
 
- 	// #ifdef H5
 
- 	return offlineData(initData)
 
- 	// #endif
 
- }
 
- export async function getJoinList(dbTable : string, joinTable : string, labels : string, joinCondition : string, lname ?: string, lvalue ?: string, others ?: string) : Promise<UTSJSONObject> {
 
- 	// #ifdef APP-ANDROID
 
- 	const result = await selectJoinTableData(dbTable, joinTable, labels, joinCondition, lname, lvalue, others);
 
- 	console.log(result);
 
- 	return result;
 
- 	// #endif
 
- }
 
- export async function updateData(tableName : string, data : string, lname ?: string, lvalue ?: string) : Promise<UTSJSONObject> {
 
- 	// #ifdef APP-ANDROID
 
- 	const result = await updateTableData(tableName, data, lname, lvalue);
 
- 	console.log(result);
 
- 	addLog({module:tableName,dataid:lvalue,content:'更新数据',status:result?.['errMsg']==='ok'?1:0,params:data})
 
- 	return result;
 
- 	// #endif
 
- }
 
- export async function getRecordCalculate(tableName : string, value ?: string | null, initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
 
- 	// #ifdef APP-ANDROID
 
- 	const result = await selectRecordData(tableName, value);
 
- 	console.log(result);
 
- 	return result;
 
- 	// #endif
 
- 	// #ifdef H5
 
- 	return offlineData(initData)
 
- 	// #endif
 
- }
 
- export async function getRecordInfoList(initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
 
- 	// #ifdef APP-ANDROID
 
- 	const result = await selectRecordInfo();
 
- 	console.log(result);
 
- 	return result;
 
- 	// #endif
 
- 	// #ifdef H5
 
- 	return offlineData(initData)
 
- 	// #endif
 
- }
 
- /**
 
-  * 保存媒体信息数据到数据库
 
-  * @param data MediaInfoData类型的数据
 
-  * @returns Promise<UTSJSONObject> 保存结果
 
-  */
 
- export async function saveMediaInfo(data ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
 
- 	// #ifdef APP-ANDROID
 
- 	// 表名
 
- 	const tableName = 'app_media_info';
 
- 	// 构造插入的数据字符串,注意数据库字段名和类型
 
- 	const values = `'${data?.getString('workorder') ?? ''}','${data?.getString('invname') ?? ''}','${data?.getString('productcode') ?? ''}','${data?.getString('cardno') ?? ''}','${data?.getString('model') ?? ''}','${data?.getString('graphid') ?? ''}','${data?.getString('ver') ?? ''}','${data?.getString('phase') ?? ''}','${data?.getString('processno') ?? ''}','${data?.getString('progress') ?? ''}',${data?.getNumber('status') ?? 1},'${data?.getString('createtime') ?? ''}',${data?.getNumber('createuser') ?? 0},'${data?.getString('updatetime') ?? ''}',${data?.getNumber('updateuser') ?? 0}, 0`;
 
- 	// 构造字段名字符串
 
- 	const fields = 'workorder,invname,productno,cardno,model,graphid,ver,phase,processno,progress,status,createtime,createuser,updatetime,updateuser,uploadflag';
 
- 	try {
 
- 		// 调用sqlite的插入方法
 
- 		const result = await insertTableData(tableName, values, fields);
 
- 		console.log('保存app_media_info成功:', result);
 
- 		addLog({module:tableName,dataid:0,content:'保存媒体信息',status:1,params:values})
 
- 		return result;
 
- 	} catch (error) {
 
- 		console.error('保存app_media_info失败:', error);
 
- 		addLog({module:tableName,dataid:0,content:'保存媒体信息失败',status:0,params:values})	
 
- 		return { errMsg: '保存失败', data: [] as any[] } as UTSJSONObject;
 
- 	}
 
- 	// #endif
 
- 	// #ifdef H5
 
- 	return offlineData({ success: true, data: [] } as UTSJSONObject);
 
- 	// #endif
 
- }
 
- /**
 
-  * 保存媒体信息数据到数据库
 
-  * @param data saveMediaRecord类型的数据
 
-  * @returns Promise<UTSJSONObject> 保存结果
 
-  */
 
- export async function saveMediaRecord(values : string) : Promise<UTSJSONObject> {
 
- 	// #ifdef APP-ANDROID
 
- 	// 表名
 
- 	const tableName = 'app_media_record';
 
- 	// 构造字段名字符串
 
- 	const fields = 'senum,photoitem,productno,part,partno,pk,exampleid,descb,num,status,date,urlspl,imgname,urlpdt,createtime,createuser,updatetime,updateuser,pid';
 
- 	try {
 
- 		// 调用sqlite的插入方法
 
- 		const result = await insertTableData(tableName, values, fields);
 
- 		console.log('保存app_media_record成功:', result);
 
- 		addLog({module:tableName,dataid:0,content:'保存媒体记录',status:1,params:values})
 
- 		return result;
 
- 	} catch (error) {
 
- 		console.error('保存app_media_record失败:', error);
 
- 		addLog({module:tableName,dataid:0,content:'保存媒体记录失败',status:0,params:values})		
 
- 		return { errMsg: '保存失败', data: [] as any[] } as UTSJSONObject;
 
- 	}
 
- 	// #endif
 
- 	// #ifdef H5
 
- 	return offlineData({ success: true, data: [] } as UTSJSONObject);
 
- 	// #endif
 
- }
 
- export async function getLatestRecord(productNo:string , initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
 
- 	// #ifdef APP-ANDROID
 
- 	const result = await selectLatestInfoData(productNo);
 
- 	console.log(result);
 
- 	return result;
 
- 	// #endif
 
- 	// #ifdef H5
 
- 	return offlineData({ success: true, data: [] } as UTSJSONObject)
 
- 	// #endif
 
- }
 
- export async function removeTableData(tableName:string, field: string, value: string) : Promise<UTSJSONObject> {
 
- 	// #ifdef APP-ANDROID
 
- 	try {
 
- 		// 调用sqlite的删除方法
 
- 		const result = await deleteTableData(tableName, field, value);
 
- 		console.log('删除数据成功:', result);
 
- 		addLog({module:tableName,dataid:1,content:'删除数据成功',status:1,params:value})		
 
- 		return result;
 
- 	} catch (error) {
 
- 		console.error('删除数据失败:', error);
 
- 		addLog({module:tableName,dataid:1,content:'删除数据失败',status:0,params:value})
 
- 		return { errMsg: '删除失败', data: [] as any[] } as UTSJSONObject;
 
- 	}
 
- 	// #endif
 
- 	// #ifdef H5
 
- 	return offlineData({ success: true, data: [] } as UTSJSONObject);
 
- 	// #endif
 
- }
 
- export async function removeInfoAndRecord(value:string) : Promise<UTSJSONObject> {
 
- 	// #ifdef APP-ANDROID
 
- 	
 
- 	try {
 
- 		// 调用sqlite的删除方法
 
- 		const result = await deleteTableData('app_media_record', 'pid', value);
 
- 		addLog({module:'app_media_record',dataid:1,content:'删除数据成功',status:1,params:value,updatetime: "strftime('%Y-%m-%d %H:%M:%S', 'now')"})
 
- 		
 
- 		const result2 = await deleteTableData('app_media_info', 'pdid', value);
 
- 		addLog({module:'app_media_info',dataid:1,content:'删除数据成功',status:1,params:value})
 
- 		return result;
 
- 	} catch (error) {
 
- 		console.error('删除数据失败:', error);
 
- 		addLog({module:'app_media_record',dataid:1,content:'删除数据失败',status:0,params:value})
 
- 		return { errMsg: '删除失败', data: [] as any[] } as UTSJSONObject;
 
- 	}
 
- 	// #endif
 
- 	
 
- 	// #ifdef H5
 
- 	return offlineData({ success: true, data: [] } as UTSJSONObject);
 
- 	// #endif
 
- }
 
- export async function addLog(data ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
 
- 	const tableName = 'app_log';
 
- 	// #ifdef APP-ANDROID
 
- 	const params = data?.getString('params')?.replace(/['"]/g, '')
 
- 	const dataid = data?.getNumber('dataid') ?? 0
 
- 	let fields = 'module,dataid,content,status,params';	
 
- 	let values = `'${data?.getString('module') ?? ''}',${data?.getNumber('dataid') ?? 0},'${data?.getString('content') ?? ''}',${data?.getNumber('status') ?? 0},'${params}'`;
 
- 	if(dataid === 0){
 
- 		fields = fields + ",createuser,createtime"
 
- 		values = values + `,'${data?.getString('createuser') ?? 0}',strftime('%Y-%m-%d %H:%M:%S', 'now')`
 
- 	}else{
 
- 		fields = fields + ",updateuser,updatetime"
 
- 		values = values + `,'${data?.getString('updateuser') ?? 0}',strftime('%Y-%m-%d %H:%M:%S', 'now')`
 
- 	}
 
- 	
 
- 	const result = await insertTableData(tableName, values, fields);
 
- 	console.log(result);
 
- 	return result;
 
- 	// #endif
 
- 	// #ifdef H5
 
- 	return offlineData({ success: true, data: [] } as UTSJSONObject);
 
- 	// #endif
 
- }
 
 
  |