Ver código fonte

添加检验任务下载

ZhangLeo 3 meses atrás
pai
commit
1a543441b6

+ 212 - 1
api/work.uts

@@ -1,5 +1,5 @@
 // #ifdef APP-ANDROID
-import { selectTableData, insertTableData, updateTableData, selectJoinTableData, selectRecordData, selectRecordInfo, selectLatestInfoData, deleteTableData } from '@/utils/sqlite'
+import { selectTableData, insertTableData, updateTableData, selectJoinTableData, selectRecordData, selectRecordInfo, selectLatestInfoData, deleteTableData, selectTaskInfo, selectLatestTaskData, selectTaskId } from '@/utils/sqlite'
 // #endif
 
 export type Download = {
@@ -299,6 +299,217 @@ export async function addLog(data ?: UTSJSONObject | null) : Promise<UTSJSONObje
 	console.log(result);
 	return result;
 	// #endif
+	// #ifdef H5
+	return offlineData({ success: true, data: [] } as UTSJSONObject);
+	// #endif
+}
+
+
+export async function saveTaskInfo(data ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
+	// #ifdef APP-ANDROID
+	// 表名
+	const tableName = 'app_task_info';
+
+	// 构造插入的数据字符串,注意数据库字段名和类型
+	const values = `'${data?.getString('gxpk') ?? ''}','${data?.getString('pk_serial') ?? ''}','${data?.getString('cardno') ?? ''}','${data?.getString('productcode') ?? ''}','${data?.getString('model') ?? ''}','${data?.getString('workorder') ?? ''}','${data?.getString('invname') ?? ''}','${data?.getString('graphid') ?? ''}','${data?.getString('processno') ?? ''}','${data?.getString('gxno') ?? ''}', '${data?.getString('ver') ?? ''}','${data?.getString('lastupdatetime') ?? ''}','${data?.getString('updateuser') ?? ''}', 0`;
+
+	// 构造字段名字符串
+	const fields = 'gxpk,pk_serial,cardno,productcode,model,workorder,invname,graphid,processno,gxno,ver,lastupdatetime,updateuser,uploadflag';
+
+	try {
+		// 调用sqlite的插入方法
+		const result = await insertTableData(tableName, values, fields);
+		console.log('保存app_task_info成功:', result);
+		addLog({module:tableName,dataid:0,content:'保存检验任务信息成功',status:1,params:values})
+		return result;
+	} catch (error) {
+		console.error('保存app_task_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 saveTaskPhoto类型的数据
+ * @returns Promise<UTSJSONObject> 保存结果
+ */
+export async function saveTaskPhoto(values : string) : Promise<UTSJSONObject> {
+	// #ifdef APP-ANDROID
+	// 表名
+	const tableName = 'app_task_photo';
+
+	// 构造字段名字符串
+	const fields = 'pdid,pk,photographpoint,photographdescription,photourl,exampleurl,photoname,fk_qcRecord,fk_prodcode,prodno,fk_creator,fks_operator,operator,processStep,fk_processTask,cs,ts';
+
+	try {
+		// 调用sqlite的插入方法
+		const result = await insertTableData(tableName, values, fields);
+		console.log('保存app_task_photo成功:', result);
+		addLog({module:tableName,dataid:0,content:'保存任务图像记录',status:1,params:values})
+		return result;
+	} catch (error) {
+		console.error('保存app_task_photo失败:', 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 getTaskInfoList(initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
+
+	// #ifdef APP-ANDROID
+	const result = await selectTaskInfo();
+	console.log(result);
+	return result;
+	// #endif
+
+	// #ifdef H5
+	return offlineData(initData)
+	// #endif
+}
+
+
+export async function saveTaskKeyProcess(data ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
+	// #ifdef APP-ANDROID
+	// 表名
+	const tableName = 'app_task_keyprocess';
+
+	// 构造插入的数据字符串,注意数据库字段名和类型
+	const values = `'${data?.getNumber('pdid') ?? 0}','${data?.getString('pk') ?? ''}','${data?.getString('testapparatus') ?? ''}','${data?.getString('tableid') ?? ''}','${data?.getString('testrequirelower') ?? ''}','${data?.getString('testrequireupper') ?? ''}','${data?.getString('parametername') ?? ''}','${data?.getString('parameterorder') ?? ''}','${data?.getString('measureunit') ?? ''}','${data?.getString('parameterinstruction') ?? ''}', '${data?.getString('parameterid') ?? ''}','${data?.getString('fk_creator') ?? ''}','${data?.getString('fk_prodcode') ?? ''}','${data?.getString('prodno') ?? ''}','${data?.getString('processstep') ?? ''}','${data?.getString('fk_processtask') ?? ''}','${data?.getString('measuredvaluemin') ?? ''}','${data?.getString('measuredvaluemax') ?? ''}','${data?.getString('fks_operator') ?? ''}','${data?.getString('cs') ?? ''}','${data?.getString('ts') ?? ''}'`;
+
+	// 构造字段名字符串
+	const fields = 'pdid,pk,testapparatus,tableid,testrequirelower,testrequireupper,parametername,parameterorder,measureunit,parameterinstruction,parameterid,fk_creator,fk_prodcode,prodno,processstep,fk_processtask,measuredvaluemin,measuredvaluemax,fks_operator,cs,ts';
+
+	try {
+		// 调用sqlite的插入方法
+		const result = await insertTableData(tableName, values, fields);
+		console.log('保存app_task_info成功:', result);
+		addLog({module:tableName,dataid:0,content:'保存检验任务信息成功',status:1,params:values})
+		return result;
+	} catch (error) {
+		console.error('保存app_task_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
+}
+
+
+export async function saveTaskRecord(data ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
+	// #ifdef APP-ANDROID
+	// 表名
+	const tableName = 'app_task_record';
+
+	// 构造插入的数据字符串,注意数据库字段名和类型
+	const values = `'${data?.getNumber('pdid') ?? 0}','${data?.getString('pk') ?? ''}','${data?.getString('fk_invcode') ?? ''}','${data?.getString('no') ?? ''}','${data?.getString('invcode') ?? ''}','${data?.getString('invname') ?? ''}','${data?.getString('processStep') ?? ''}','${data?.getString('fk_processTask') ?? ''}','${data?.getString('checkTarget') ?? ''}',${data?.getNumber('checknum') ?? 0}, ${data?.getNumber('oknum') ?? 0},${data?.getNumber('ngnum') ?? 0},'${data?.getString('status') ?? ''}','${data?.getString('result') ?? ''}','${data?.getString('checkTime') ?? ''}','${data?.getString('fk_creator') ?? ''}','${data?.getString('cs') ?? ''}','${data?.getString('ts') ?? ''}'`;
+
+	// 构造字段名字符串
+	const fields = 'pdid,pk,fk_invcode,no,invcode,invname,processStep,fk_processTask,checkTarget,checknum,oknum,ngnum,status,result,checkTime,fk_creator,cs,ts';
+
+	try {
+		// 调用sqlite的插入方法
+		const result = await insertTableData(tableName, values, fields);
+		console.log('保存app_task_record成功:', result);
+		addLog({module:tableName,dataid:0,content:'保存检验任务记录信息成功',status:1,params:values})
+		return result;
+	} catch (error) {
+		console.error('保存app_task_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 saveTaskRecordItem(data ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
+	// #ifdef APP-ANDROID
+	// 表名
+	const tableName = 'app_task_record_item';
+
+	// 构造插入的数据字符串,注意数据库字段名和类型
+	const values = `'${data?.getNumber('psxid') ?? 0}','${data?.getString('pk') ?? ''}','${data?.getString('fk_qcRecord') ?? ''}','${data?.getString('fk_prodcode') ?? ''}','${data?.getString('prodno') ?? ''}','${data?.getString('name') ?? ''}','${data?.getString('no') ?? ''}','${data?.getString('nature') ?? ''}','${data?.getString('unit') ?? ''}',${data?.getNumber('maxNum') ?? 0}, ${data?.getNumber('maxNum') ?? 0},'${data?.getString('status') ?? ''}','${data?.getString('memo') ?? ''}','${data?.getString('measuredvalue') ?? ''}','${data?.getString('result') ?? ''}','${data?.getString('cs') ?? ''}','${data?.getString('ts') ?? ''}'`;
+
+	// 构造字段名字符串
+	const fields = 'psxid,pk,fk_qcRecord,fk_prodcode,prodno,prodno,no,nature,unit,maxNum,minNum,status,memo,measuredvalue,result,cs,ts';
+
+	try {
+		// 调用sqlite的插入方法
+		const result = await insertTableData(tableName, values, fields);
+		console.log('保存app_task_record_item成功:', result);
+		addLog({module:tableName,dataid:0,content:'保存检验任务项目信息成功',status:1,params:values})
+		return result;
+	} catch (error) {
+		console.error('保存app_task_record_item失败:', 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 getLatestTask(productNo:string, initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
+	// #ifdef APP-ANDROID
+	const result = await selectLatestTaskData(productNo);
+	console.log(result);
+	return result;
+	// #endif
+
+	// #ifdef H5
+	return offlineData({ success: true, data: [] } as UTSJSONObject)
+	// #endif
+}
+
+export async function removeTaskAndRecord(value:string) : Promise<UTSJSONObject> {
+	// #ifdef APP-ANDROID
+	
+	try {
+		// 调用sqlite的删除方法
+		const taskId = await selectTaskId('app_task_info', 'pdid', 'gxpk', value);
+		const result = await deleteTableData('app_task_info', 'pdid', taskId);
+		addLog({module:'app_task_info',dataid:1,content:'删除数据成功',status:1,params:value,updatetime: "strftime('%Y-%m-%d %H:%M:%S', 'now')"})
+		
+		const result2 = await deleteTableData('app_task_photo', 'pdid', taskId);
+		addLog({module:'app_task_photo',dataid:1,content:'删除数据成功',status:1,params:value})
+
+		const recordId = await selectTaskId('app_task_record', 'sxid', 'pdid', taskId);
+		const result3 = await deleteTableData('app_task_record_item', 'psxid', recordId);
+		addLog({module:'app_task_record_item',dataid:1,content:'删除数据成功',status:1,params:value})
+		
+		const result4 = await deleteTableData('app_task_record', 'sxid', recordId);
+		addLog({module:'app_task_record',dataid:1,content:'删除数据成功',status:1,params:value})
+		return {};
+	} 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

+ 8 - 6
config.uts

@@ -17,6 +17,7 @@ export type GlobalConfig= {
   host: string;
   tokenURL: string;
   downloadURL: string;
+  downloadTaskURL: string;
   uploadURL: string;
   getImgURL: string;
 }
@@ -45,12 +46,13 @@ export const globalConfig  = {
       }
     ]
   },
-  // host: "http://192.168.43.62:4523/m1/7190626-6915798-default",
-  host: "http://10.122.15.8",
+  host: "http://192.168.5.149:4523/m1/7190626-6915798-default",
+  // host: "http://10.122.15.8",
   tokenURL: '/paas/RestService/d800.paas.app.LoginImpl/caLogin?username=',
   downloadURL: '/qm/RestService/d800.qm.QmImpl/loadQmImagetask?prodcode=',
-  getImgURL: 'http://10.122.15.8/qm/Rest/download?fileid=',
-  // getImgURL: 'http://192.168.43.62:8080/qm/Rest/download?fileid=',
-  uploadURL: 'http://10.122.15.8/qm/Rest/upload'
-  // uploadURL: 'http://192.168.43.62:8080/qm/Rest/upload'
+  downloadTaskURL: '/qm/RestService/d800.qm.QmImpl/loadQmLkCheckinfo?gxpk=',
+  // getImgURL: 'http://10.122.15.8/qm/Rest/download?fileid=',
+  getImgURL: 'http://192.168.5.149:8080/qm/Rest/download?fileid=',
+  // uploadURL: 'http://10.122.15.8/qm/Rest/upload'
+  uploadURL: 'http://192.168.5.149:8080/qm/Rest/upload'
 } as GlobalConfig;

+ 2 - 2
pages/work/download/DownloadDetail.uvue

@@ -131,7 +131,7 @@
 		// 模拟数据加载,建议替换为后端接口请求
         // #ifdef APP-ANDROID
 		    //获取下载产品数据
-         	getList('app_product', 'pdid', downloadId,null, null, null).then((res:UTSJSONObject) => {
+         	getList('app_task_info', 'pdid', downloadId,null, null, null).then((res:UTSJSONObject) => {
          	 		console.log(res)
          				let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
          				if(dataList!=null && dataList.length>0){							
@@ -167,7 +167,7 @@
         // #endif
 	})
 
-	const goBack = () => {
+	const goBack = () => {5
 		uni.navigateBack()
 	}
 

+ 38 - 48
pages/work/download/DownloadList.uvue

@@ -47,15 +47,7 @@
 			</view>
 			<view class="info-row">
 			  <text class="label">最近更新时间:</text>
-			  <text class="value">{{ item.updatetime == "" ? item.createtime : item.updatetime }}</text>
-			</view>
-			<view class="info-row">
-			  <text class="label">进度:</text>
-			  <text class="process-value" :class="{
-			    'bg-green': item.statusRecordCount === item.totalRecord,
-			    'bg-yellow': item.statusRecordCount < item.totalRecord,
-			    'bg-black': item.statusRecordCount === 0
-			  }"> {{ item.statusRecordCount }} / {{ item.totalRecord }} </text>
+			  <text class="value">{{ item.lastupdatetime }}</text>
 			</view>
 		</view>  
 		
@@ -74,11 +66,11 @@
 
 <script setup>
   import { ref, reactive } from 'vue'
-  import { getRecordInfoList } from '@/api/work';
-  import { downloadDataFromAPI, uploadDataToAPI } from '@/utils/dataProcessor';
+  import { getTaskInfoList } from '@/api/work';
+  import { downloadDataFromAPI, uploadDataToAPI } from '@/utils/qcDataProcessor.uts';
 
   // 产品号输入框数据
-  const productNo = ref('');
+  const productNo = ref('PI02297172');
   
   const backPressOptions = reactive({
     from: 'backbutton'
@@ -95,35 +87,33 @@
     return true
   })
 
-  type Download = {
+  type Task = {
     pdid : number,
-	productno : string,
+	gxpk : string,
 	cardno : string,
+    productcode : string,
+    model : string,
     workorder : string,
     invname : string,
     graphid : string,
     processno : string,
+    gxno : string,
     ver : string,
-    updatetime : string,
-    createtime : string,
-    status : number,
-    totalRecord : number,
-    statusRecordCount : number,
-	uploadflag: number
+    lastupdatetime : string
   }
 
-  var initDownloads = [] as Download[]
-  var downloads = ref<Download[]>([]);
+  var initDownloads = [] as Task[]
+  var downloads = ref<Task[]>([]);
   const map = ref(new Map<number, string>([[1, '未执行'], [2, '执行中'], [3, '执行完'], [4, '有错误']]))
 
   // #ifdef APP-ANDROID
-  getRecordInfoList(null).then((res : UTSJSONObject) => {
+  getTaskInfoList(null).then((res : UTSJSONObject) => {
     console.log(res)
     let dataList = res?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>()
     if (dataList != null && dataList.length > 0) {
       dataList.forEach(item => {
         if (item != null) {
-          let download = JSON.parse<Download>(item.toJSONString());
+          let download = JSON.parse<Task>(item.toJSONString());
           if (download != null) {
             initDownloads.push(download)
           }
@@ -199,35 +189,35 @@
 	
     await downloadDataFromAPI(productNo.value, () => {
       // 回调函数中执行刷新,确保数据都保存好,进度条跑完
-      uni.reLaunch({ url: '/pages/work/record/InfoList' })
+      uni.reLaunch({ url: '/pages/work/download/DownloadList' })
     }).then((res) => {
       // 移除这里的刷新逻辑,避免过早刷新
     })
   }
   
-  const upload = async (e : Download) => {
-	if(e.statusRecordCount != e.totalRecord) {
-		uni.showToast({
-		  title: '当前任务还未完成!',
-		  icon: 'error'
-		});
-		return
-	}
-	if(e.uploadflag > 0) {
-		uni.showToast({
-		  title: '当前任务已上传!',
-		  icon: 'error'
-		});
-		return
-	}
-    console.log("开始上传...")
-    uploadDataToAPI(productNo.value, () => {
-	  // 回调函数中执行刷新,确保数据都保存好,进度条跑完
-	  uni.reLaunch({ url: '/pages/work/record/InfoList' })
-	}).then((res) => {
-	  // 移除这里的刷新逻辑,避免过早刷新
-	  // 处理断点续传
-	})
+  const upload = async (e : Task) => {
+	// if(e.statusRecordCount != e.totalRecord) {
+	// 	uni.showToast({
+	// 	  title: '当前任务还未完成!',
+	// 	  icon: 'error'
+	// 	});
+	// 	return
+	// }
+	// if(e.uploadflag > 0) {
+	// 	uni.showToast({
+	// 	  title: '当前任务已上传!',
+	// 	  icon: 'error'
+	// 	});
+	// 	return
+	// }
+ //    console.log("开始上传...")
+ //    uploadDataToAPI(productNo.value, () => {
+	//   // 回调函数中执行刷新,确保数据都保存好,进度条跑完
+	//   uni.reLaunch({ url: '/pages/work/record/InfoList' })
+	// }).then((res) => {
+	//   // 移除这里的刷新逻辑,避免过早刷新
+	//   // 处理断点续传
+	// })
 
   }
   

BIN
static/db/QT800.db


+ 113 - 4
utils/sqlite.uts

@@ -524,10 +524,7 @@ export function selectLatestInfoData (
     } as selectSqlOptions
   
     const info = sqlite.selectSql(selectSqlOptions) as selectSqlOptionsResult
-	console.log("===========================================>");
-    console.log(info)
 	let data = info?.data;
-	console.log(data);
     const ret = {
   	  errMsg: info?.errMsg ?? '',
   	  data: (info?.data != null && info.data.length > 0) ? info.data[0] : null
@@ -581,4 +578,116 @@ export function selectLatestInfoData (
  			resolve(ret);
  		})
  	}
- }
+ }
+ 
+ 
+ export function selectTaskInfo() : Promise<UTSJSONObject> {
+ 
+ 	var sql = `SELECT
+ 					m.*
+ 				FROM
+ 					app_task_info m
+ 				ORDER BY
+ 					m.pdid DESC`;
+ 
+ 
+ 	const sqlite = createSQLiteContext(dbName);
+ 
+ 	return new Promise<UTSJSONObject>((resolve, reject) => {
+ 		const selectSqlOptions = {
+ 			sql: sql,
+ 			success: (e : selectSqlOptionsResult) => {
+ 				console.log(e)
+ 
+ 			},
+ 			fail: (e : selectSqlOptionsResult) => {
+ 				console.error(e)
+ 			}
+ 		} as selectSqlOptions
+ 
+ 		const info = sqlite.selectSql(selectSqlOptions) as selectSqlOptionsResult
+ 
+ 		console.log(info)
+ 		const ret = {
+ 			errMsg: info?.errMsg ?? '',
+ 			data: info?.data ?? ['']
+ 		} as UTSJSONObject
+ 		resolve(ret)
+ 	});
+ 
+ }
+ 
+ export function selectTaskId(table : string, field : string, paramField : string,  value : string) : Promise<string> {
+ 
+ 	var sql = `SELECT
+ 					m.${field} as id
+ 				FROM
+ 					${table} m
+				where ${paramField} = '${value}'	
+ 				`;
+ 
+    console.log(sql);
+ 	const sqlite = createSQLiteContext(dbName);
+ 
+ 	return new Promise<string>((resolve, reject) => {
+ 		const selectSqlOptions = {
+ 			sql: sql,
+ 			success: (e : selectSqlOptionsResult) => {
+ 				console.log(e)
+ 
+ 			},
+ 			fail: (e : selectSqlOptionsResult) => {
+ 				console.error(e)
+ 			}
+ 		} as selectSqlOptions
+ 
+ 		const info = sqlite.selectSql(selectSqlOptions) as selectSqlOptionsResult
+		let resultArr = info?.['data'] as UTSJSONObject[] ?? Array<UTSJSONObject>();
+		let returnValue = '';
+		if (resultArr!=null && resultArr.length > 0) {
+			const firstRecord = resultArr[0];
+			if (firstRecord != null) {
+				returnValue = firstRecord?.['id'] as string;
+			}
+		}
+ 		resolve(returnValue)
+ 	});
+ 
+ }
+ 
+
+ export function selectLatestTaskData (
+   productNo?: string,
+ ):Promise<UTSJSONObject>
+ {
+   var sql = `SELECT
+ 					m.*
+ 				FROM
+ 					app_task_info m
+				where gxpk = '${productNo}'
+ 				ORDER BY
+ 					m.pdid DESC
+				LIMIT 1`;
+   const sqlite = createSQLiteContext(dbName);
+   
+   return new Promise<UTSJSONObject>((resolve, reject) => {
+     const selectSqlOptions ={		
+   	  sql: sql,
+   	  success: (e: selectSqlOptionsResult) => {
+   	    console.log(e)
+   		
+   	  },
+   	  fail: (e: selectSqlOptionsResult) => {
+   	    console.error(e)
+   	  }		
+     } as selectSqlOptions
+   
+     const info = sqlite.selectSql(selectSqlOptions) as selectSqlOptionsResult
+     const ret = {
+   	  errMsg: info?.errMsg ?? '',
+   	  data: (info?.data != null && info.data.length > 0) ? info.data[0] : null
+     } as UTSJSONObject
+     resolve(ret)
+   });	
+   
+  }