work.uts 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. // #ifdef APP-ANDROID
  2. import { selectTableData, insertTableData, updateTableData, selectJoinTableData, selectRecordData, selectRecordInfo, selectLatestInfoData, deleteTableData } from '@/utils/sqlite'
  3. // #endif
  4. export type Download = {
  5. pdid : number,
  6. workorder : string,
  7. invname : string,
  8. productno : string,
  9. graphid : string,
  10. cardno : string,
  11. processno : string,
  12. ver : string,
  13. updatetime : string,
  14. progress : string,
  15. status : number
  16. }
  17. export type Record = {
  18. sxid : number,
  19. senum : number,
  20. photoitem : string,
  21. productno : string,
  22. part : string,
  23. descb : string,
  24. date : string,
  25. partno : string,
  26. num : number,
  27. status : number,
  28. urlspl : string[],
  29. imgname : string[],
  30. urlpdt : string[]
  31. }
  32. export type TaskProcess = {
  33. id : number
  34. name : string
  35. num : number
  36. step : number
  37. status : number
  38. }
  39. export type JoinRecord = {
  40. sxid : number,
  41. senum : number,
  42. photoitem : string,
  43. productno : string,
  44. part : string,
  45. descb : string,
  46. date : string,
  47. partno : string,
  48. num : number,
  49. status : number,
  50. urlspl : string
  51. imgname : string,
  52. urlpdt : string,
  53. pid : number,
  54. workorder : string,
  55. invname : string
  56. }
  57. export type RecordCalculate = {
  58. photoitem : string,
  59. pid : number,
  60. step : number,
  61. total : number,
  62. status : number
  63. }
  64. //检验任务
  65. export type TaskInfo = {
  66. gxid : string,
  67. itemTitle: string,
  68. photoitemStep : number,
  69. photoitemTotal: number,
  70. photoitemStatus: string,
  71. recordStep : number,
  72. recordTotal : number,
  73. recordStatus : string,
  74. keypointStep : number,
  75. keypointTotal : number
  76. keypointStatus : string
  77. }
  78. export function offlineData(data : UTSJSONObject) : Promise<UTSJSONObject> {
  79. return new Promise((resolve, reject) => {
  80. let result = JSON.parseObject(JSON.stringify(data)) as UTSJSONObject
  81. resolve(result)
  82. });
  83. }
  84. export const statusDict = { '1': '未执行', '2': '执行中', '3': '已执行', '4': '执行错误', '5': '已取消' }
  85. export const recordStatusDict = { '1': '未拍照', '2': '拍照中', '3': '拍照完成', '4': '检验不清晰', '5': '拍照取消' }
  86. export const taskType = { '1': '检测任务', '2': '关键工序任务' }
  87. export const funcType = {'1': '新增', '2': '更新', '3': '删除'}
  88. //export const moduleType = {'1': '声像记录', '2':'检验任务', '3':'关键工序','4': '系统管理','5':'其它'}
  89. export async function getList(tableName : string, condition ?: string | null, value ?: string | null, condition2 ?: string | null, value2 ?: string | null, initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
  90. // #ifdef APP-ANDROID
  91. const result = await selectTableData(tableName, condition, value, condition2, value2);
  92. console.log(result);
  93. return result;
  94. // #endif
  95. // #ifdef H5
  96. return offlineData(initData)
  97. // #endif
  98. }
  99. export async function getJoinList(dbTable : string, joinTable : string, labels : string, joinCondition : string, lname ?: string, lvalue ?: string, others ?: string) : Promise<UTSJSONObject> {
  100. // #ifdef APP-ANDROID
  101. const result = await selectJoinTableData(dbTable, joinTable, labels, joinCondition, lname, lvalue, others);
  102. console.log(result);
  103. return result;
  104. // #endif
  105. }
  106. export async function updateData(tableName : string, data : string, lname ?: string, lvalue ?: string) : Promise<UTSJSONObject> {
  107. // #ifdef APP-ANDROID
  108. const result = await updateTableData(tableName, data, lname, lvalue);
  109. console.log(result);
  110. addLog({module:tableName,dataid:lvalue,content:'更新数据',status:result?.['errMsg']==='ok'?1:0,params:data})
  111. return result;
  112. // #endif
  113. }
  114. export async function getRecordCalculate(tableName : string, value ?: string | null, initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
  115. // #ifdef APP-ANDROID
  116. const result = await selectRecordData(tableName, value);
  117. console.log(result);
  118. return result;
  119. // #endif
  120. // #ifdef H5
  121. return offlineData(initData)
  122. // #endif
  123. }
  124. export async function getRecordInfoList(initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
  125. // #ifdef APP-ANDROID
  126. const result = await selectRecordInfo();
  127. console.log(result);
  128. return result;
  129. // #endif
  130. // #ifdef H5
  131. return offlineData(initData)
  132. // #endif
  133. }
  134. /**
  135. * 保存媒体信息数据到数据库
  136. * @param data MediaInfoData类型的数据
  137. * @returns Promise<UTSJSONObject> 保存结果
  138. */
  139. export async function saveMediaInfo(data ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
  140. // #ifdef APP-ANDROID
  141. // 表名
  142. const tableName = 'app_media_info';
  143. // 构造插入的数据字符串,注意数据库字段名和类型
  144. 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`;
  145. // 构造字段名字符串
  146. const fields = 'workorder,invname,productno,cardno,model,graphid,ver,phase,processno,progress,status,createtime,createuser,updatetime,updateuser,uploadflag';
  147. try {
  148. // 调用sqlite的插入方法
  149. const result = await insertTableData(tableName, values, fields);
  150. console.log('保存app_media_info成功:', result);
  151. addLog({module:tableName,dataid:0,content:'保存媒体信息',status:1,params:values})
  152. return result;
  153. } catch (error) {
  154. console.error('保存app_media_info失败:', error);
  155. addLog({module:tableName,dataid:0,content:'保存媒体信息失败',status:0,params:values})
  156. return { errMsg: '保存失败', data: [] as any[] } as UTSJSONObject;
  157. }
  158. // #endif
  159. // #ifdef H5
  160. return offlineData({ success: true, data: [] } as UTSJSONObject);
  161. // #endif
  162. }
  163. /**
  164. * 保存媒体信息数据到数据库
  165. * @param data saveMediaRecord类型的数据
  166. * @returns Promise<UTSJSONObject> 保存结果
  167. */
  168. export async function saveMediaRecord(values : string) : Promise<UTSJSONObject> {
  169. // #ifdef APP-ANDROID
  170. // 表名
  171. const tableName = 'app_media_record';
  172. // 构造字段名字符串
  173. const fields = 'senum,photoitem,productno,part,partno,pk,exampleid,descb,num,status,date,urlspl,imgname,urlpdt,createtime,createuser,updatetime,updateuser,pid';
  174. try {
  175. // 调用sqlite的插入方法
  176. const result = await insertTableData(tableName, values, fields);
  177. console.log('保存app_media_record成功:', result);
  178. addLog({module:tableName,dataid:0,content:'保存媒体记录',status:1,params:values})
  179. return result;
  180. } catch (error) {
  181. console.error('保存app_media_record失败:', error);
  182. addLog({module:tableName,dataid:0,content:'保存媒体记录失败',status:0,params:values})
  183. return { errMsg: '保存失败', data: [] as any[] } as UTSJSONObject;
  184. }
  185. // #endif
  186. // #ifdef H5
  187. return offlineData({ success: true, data: [] } as UTSJSONObject);
  188. // #endif
  189. }
  190. export async function getLatestRecord(productNo:string , initData ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
  191. // #ifdef APP-ANDROID
  192. const result = await selectLatestInfoData(productNo);
  193. console.log(result);
  194. return result;
  195. // #endif
  196. // #ifdef H5
  197. return offlineData({ success: true, data: [] } as UTSJSONObject)
  198. // #endif
  199. }
  200. export async function removeTableData(tableName:string, field: string, value: string) : Promise<UTSJSONObject> {
  201. // #ifdef APP-ANDROID
  202. try {
  203. // 调用sqlite的删除方法
  204. const result = await deleteTableData(tableName, field, value);
  205. console.log('删除数据成功:', result);
  206. addLog({module:tableName,dataid:1,content:'删除数据成功',status:1,params:value})
  207. return result;
  208. } catch (error) {
  209. console.error('删除数据失败:', error);
  210. addLog({module:tableName,dataid:1,content:'删除数据失败',status:0,params:value})
  211. return { errMsg: '删除失败', data: [] as any[] } as UTSJSONObject;
  212. }
  213. // #endif
  214. // #ifdef H5
  215. return offlineData({ success: true, data: [] } as UTSJSONObject);
  216. // #endif
  217. }
  218. export async function removeInfoAndRecord(value:string) : Promise<UTSJSONObject> {
  219. // #ifdef APP-ANDROID
  220. try {
  221. // 调用sqlite的删除方法
  222. const result = await deleteTableData('app_media_record', 'pid', value);
  223. addLog({module:'app_media_record',dataid:1,content:'删除数据成功',status:1,params:value,updatetime: "strftime('%Y-%m-%d %H:%M:%S', 'now')"})
  224. const result2 = await deleteTableData('app_media_info', 'pdid', value);
  225. addLog({module:'app_media_info',dataid:1,content:'删除数据成功',status:1,params:value})
  226. return result;
  227. } catch (error) {
  228. console.error('删除数据失败:', error);
  229. addLog({module:'app_media_record',dataid:1,content:'删除数据失败',status:0,params:value})
  230. return { errMsg: '删除失败', data: [] as any[] } as UTSJSONObject;
  231. }
  232. // #endif
  233. // #ifdef H5
  234. return offlineData({ success: true, data: [] } as UTSJSONObject);
  235. // #endif
  236. }
  237. export async function addLog(data ?: UTSJSONObject | null) : Promise<UTSJSONObject> {
  238. const tableName = 'app_log';
  239. // #ifdef APP-ANDROID
  240. const params = data?.getString('params')?.replace(/['"]/g, '')
  241. const dataid = data?.getNumber('dataid') ?? 0
  242. let fields = 'module,dataid,content,status,params';
  243. let values = `'${data?.getString('module') ?? ''}',${data?.getNumber('dataid') ?? 0},'${data?.getString('content') ?? ''}',${data?.getNumber('status') ?? 0},'${params}'`;
  244. if(dataid === 0){
  245. fields = fields + ",createuser,createtime"
  246. values = values + `,'${data?.getString('createuser') ?? 0}',strftime('%Y-%m-%d %H:%M:%S', 'now')`
  247. }else{
  248. fields = fields + ",updateuser,updatetime"
  249. values = values + `,'${data?.getString('updateuser') ?? 0}',strftime('%Y-%m-%d %H:%M:%S', 'now')`
  250. }
  251. const result = await insertTableData(tableName, values, fields);
  252. console.log(result);
  253. return result;
  254. // #endif
  255. // #ifdef H5
  256. return offlineData({ success: true, data: [] } as UTSJSONObject);
  257. // #endif
  258. }