Bladeren bron

设备点检相关逻辑

hh 2 weken geleden
bovenliggende
commit
f9d130f981

+ 2 - 0
entry/src/main/ets/common/constants/CommonConstants.ets

@@ -32,6 +32,8 @@ export default class CommonConstants {
   static mqttSubscribeTopic1: string = 'station11/data/devices';
   static readonly mqttSubscribeTopic2: string = 'station100/data/devices';
   static readonly mqttSubscribePublish: string = 'station11/cmd/devices';
+  // 默认随机ip
+  static readonly STATION_DEFAULT_IP: string = '192.168.1.' + Math.floor(Math.random() * 90 + 10)
 
   // 电烙铁允许最大、最小温度
   static readonly ironTempMin: number = 150

+ 0 - 1
entry/src/main/ets/common/util/request/ProcessRequest.ets

@@ -62,7 +62,6 @@ ProcessRequest.interceptors.response.use((response: AxiosResponse) => {
 }, (error: AxiosError) => {
   // 对响应错误做点什么
   printError(error)
-
   return Promise.reject(error);
 });
 

+ 29 - 9
entry/src/main/ets/pages/ProcessIndex.ets

@@ -39,8 +39,10 @@ import { PictureDrawingDialog } from '../view/PictureDrawingDialog';
 import { AuxiliaryOperationView } from '../view/AuxiliaryOperationView';
 import { BusinessError } from '@ohos.base';
 import window from '@ohos.window';
-import { EquipmentInspectionDialog } from '../view/EquipmentInspectionDialog';
+import { DeviceInspectionDialog } from '../view/DeviceInspectionDialog';
 import preferencesUtil from '../common/util/PerferencesUtil';
+import TimeUtil from '../common/util/TimeUtil';
+import ProcessDeviceDailyCheck from '../viewmodel/process/ProcessDeviceDailyCheck';
 
 // 声明接受参数的类型
 interface Params {
@@ -95,12 +97,15 @@ struct ProcessIndex {
   @State scanState: number = 0
   // 工单下流转卡号列表
   @State seqList: WorkOrderSeq[] = []
+  // 设备每日点检
+  @State deviceChecks: ProcessDeviceDailyCheck[] = []
 
   private scrollerList: Scroller = new Scroller()
 
   @Provide('currentDept') currentDept:string = ''
   @Provide('currentProductLine') currentProductLine:string = ''
   @Provide('currentStation') currentStation:string = ''
+  @Provide('stationIp') stationIp:string = ''
   @Provide('currentPLCode') currentPLCode:string = ''
   @Provide('currentOrgId') currentOrgId:number = 0
   @Provide('currentStationId') @Watch('refreshWorkOrder') currentStationId: string = ''
@@ -119,7 +124,7 @@ struct ProcessIndex {
       return
     }
     console.log('hhtest', '执行刷新------' +this.currentStationId)
-    let queryRes = await ProcessRequest.post('/api/v1/plan/workOrder/taskPage', {
+    let queryRes = await ProcessRequest.post('/api/v1/plan/workOrder/taskPage2', {
       stationId: this.currentStationId,
       queryComplete: 0,
     } as RequestParamModel) as WorkOrderPage;
@@ -286,12 +291,15 @@ struct ProcessIndex {
   }
 
   async aboutToAppear() {
+    // 获取工位ip
+    this.stationIp = CommonConstants.STATION_DEFAULT_IP
     try {
       const netHandle = connection.getDefaultNetSync();
       if (netHandle) {
         let connectionProperties = await connection.getConnectionProperties(netHandle)
         if (connectionProperties && connectionProperties.linkAddresses) {
           connectionProperties.linkAddresses.forEach((address: connection.LinkAddress, index: number) => {
+            this.stationIp = address.address.address
             if (address.address.address.startsWith(CommonConstants.ipPrefix)) {
               CommonConstants.mqttSubscribeTopic1 = 'station' + address.address.address.replace(CommonConstants.ipPrefix, '') + '/data/devices'
               // todo 部署时放开注释
@@ -303,12 +311,22 @@ struct ProcessIndex {
     } catch (err) {
       console.log('hhtest', err);
     }
-    if (!this.selectWorkOder || !this.selectWorkOder.workOrderCode) {
-      this.selectOrderController.open()
-    }
+    // 创建mqtt连接和usb设备连接
     this.connectMQTT()
     this.connectUsbDevice()
 
+    // 判断是否选中工单,未选择则选则工单
+    if (!this.selectWorkOder || !this.selectWorkOder.workOrderCode) {
+      this.selectOrderController.open()
+    }
+    //判断今日是否进行设备点检,否则先进行点检
+    this.deviceChecks = await ProcessRequest.post('/api/v1/process/equipDailyCheck/list', {
+      stationIp: this.stationIp,
+      createDate: TimeUtil.getCurrentDate()
+    } as RequestParamModel)
+    if (!this.deviceChecks || this.deviceChecks.length <= 0) {
+      this.deviceInspectionController.open()
+    }
     // todo 删除
     let token:string = await ProcessRequest.post('api/auth/aioLogin', {
       password: '123456',
@@ -966,8 +984,8 @@ struct ProcessIndex {
             openPictureDrawingDialog: ()=>{
               this.pictureDrawingController.open()
             },
-            openEquipmentInspectionDialog: ()=>{
-              this.EquipmentInspectionController.open()
+            openDeviceInspectionDialog: ()=>{
+              this.deviceInspectionController.open()
             },
           })
             .height('93.5%')
@@ -1259,8 +1277,10 @@ struct ProcessIndex {
     maskColor: 'rgba(0,0,0,0.8)',  // 黑色遮罩
   })
   // 设备点检弹窗
-  EquipmentInspectionController: CustomDialogController = new CustomDialogController({
-    builder: EquipmentInspectionDialog({}),
+  deviceInspectionController: CustomDialogController = new CustomDialogController({
+    builder: DeviceInspectionDialog({
+      deviceChecks: this.deviceChecks,
+    }),
     autoCancel: true, // 点击遮罩关闭
     customStyle: true,
     alignment:DialogAlignment.Center,

+ 2 - 0
entry/src/main/ets/view/AddUnqualifiedRecordDialog.ets

@@ -39,6 +39,7 @@ export struct AddUnqualifiedRecordDialog{
   @State defectRemark: string = ''
 
   @Consume('currentUserName') currentUserName: string
+  @Consume('currentStationId') currentStationId: string
   seqNo: string = ''
   selectOperationId: string = ''
   process: ProcessInfo = {}
@@ -302,6 +303,7 @@ export struct AddUnqualifiedRecordDialog{
               this.defectRecord.processesList = [this.selectOperationId]
               this.defectRecord.personResponsible = this.currentUserName
               this.defectRecord.remark = this.defectRemark
+              this.defectRecord.stationId = this.currentStationId
               await ProcessRequest.post('/api/v1/process/escalationFault/add', this.defectRecord)
               // 重新刷新不良类型记录列表
               this.refreshDefectRecords()

+ 3 - 3
entry/src/main/ets/view/AuxiliaryOperationView.ets

@@ -66,7 +66,7 @@ export struct AuxiliaryOperationView {
   // 打开图纸资料弹窗
   openPictureDrawingDialog?: () => void = () => {}
   //设备点检弹窗
-  openEquipmentInspectionDialog?: () => void = () => {}
+  openDeviceInspectionDialog?: () => void = () => {}
 
   // 获取条码关联中的统计
   getBarcodeStatistics() {
@@ -555,8 +555,8 @@ export struct AuxiliaryOperationView {
               .backgroundColor($r('app.color.20FFFFFF'))
               .borderRadius($r('app.float.fontSize_16'))
               .onClick(()=>{
-                if (this.openEquipmentInspectionDialog) {
-                  this.openEquipmentInspectionDialog()
+                if (this.openDeviceInspectionDialog) {
+                  this.openDeviceInspectionDialog()
                 }
               })
             }

+ 54 - 74
entry/src/main/ets/view/EquipmentInspectionDialog.ets

@@ -1,68 +1,40 @@
 //设备点检
 import ProcessRequest from '../common/util/request/ProcessRequest'
-import DeviceInfo from '../viewmodel/DeviceInfo'
-import RequestParamModel from '../viewmodel/RequestParamModel'
-import TimeUtil from "../common/util/TimeUtil"
-import PageInfo from '../viewmodel/PageInfo'
+import ProcessDeviceDailyCheck from '../viewmodel/process/ProcessDeviceDailyCheck'
+import DictValue from '../viewmodel/DictValue'
+import promptAction from '@ohos.promptAction'
+import HashMap from '@ohos.util.HashMap'
+
 
-//todo 需要后端接口
 @CustomDialog
-export struct EquipmentInspectionDialog {
+export struct DeviceInspectionDialog {
   private scrollerDevice: Scroller = new Scroller()
   //查找设备编码
-  @State queryDeviceNo:string = ''
+  @State queryDeviceNo: string = 'KLA-METRO01'
   //当前日期
   @State currentDate: string = ''
-  //设备列表
-  @State devicesList: DeviceInfo[] = [
-  ];
+  // 设备点检列表
+  @Link deviceChecks: ProcessDeviceDailyCheck[]
   //选中设备索引
-  @State selectDeviceIndex:number=-1
+  @State selectDeviceIndex: number=-1
+  // 设备类型(key为数据字典值,value为数据字典标签)
+  @State deviceTypes: HashMap<string, string> = new HashMap()
+  @Consume('stationIp') stationIp: string
   controller: CustomDialogController
   onConfirm: () => void = () => {}
 
-  onQueryDeviceCode = async ()=> {
-    let res = await ProcessRequest.post('/api/v1/device/page', {
-      deviceNo: this.queryDeviceNo
-    } as RequestParamModel) as PageInfo;
-    this.devicesList = res.records as DeviceInfo[] || []
-  }
-
-  //当前日期
-  updateCurrentDate() {
-    const now = new Date()
-    const year = now.getFullYear()
-    const month = (now.getMonth() + 1).toString().padStart(2, '0')
-    const day = now.getDate().toString().padStart(2, '0')
-    this.currentDate = `${year}/${month}/${day}`
-  }
+  deviceTypeDictCode: string = 'device_type'
 
-  //对比当前日期和有效期
-  private compareDates(currentDate: string, targetDate: string): number {
-    if (!targetDate) return -1; // 无效日期视为已过期
-    const normalizeDate = (dateStr: string) => {
-      let result = dateStr.split('/').join('-');
-      result = result.split('年').join('-')
-        .split('月').join('-')
-        .split('日').join('-');
-      return result;
-    };
-    try {
-      const current = new Date(normalizeDate(currentDate));
-      const target = new Date(normalizeDate(targetDate));
-      if (isNaN(current.getTime()) || isNaN(target.getTime())) {
-        return -1;
+  async aboutToAppear() {
+    let deviceDicts: DictValue[] = await ProcessRequest.get(`/api/v1/sys/dictData/queryByType/${this.deviceTypeDictCode}`)
+    if (deviceDicts) {
+      for (const dict of deviceDicts) {
+        console.log('hhtest', JSON.stringify(dict))
+        this.deviceTypes.set(dict.dictValue!, dict.dictLabel!);
       }
-      return target.getTime() - current.getTime();
-    } catch (e) {
-      return -1; // 日期解析异常视为已过期
     }
   }
 
-  aboutToAppear(): void {
-    this.updateCurrentDate();
-    this.onQueryDeviceCode();
-  }
   build() {
     Column() {
       Column() {
@@ -95,8 +67,21 @@ export struct EquipmentInspectionDialog {
               .fontSize($r('app.float.fontSize_16'))
               .fontColor($r('app.color.FFFFFF'))
               .enableKeyboardOnFocus(false)
-              .onSubmit(() => {
-                this.onQueryDeviceCode()
+              .onSubmit(async () => {
+                if (this.deviceChecks) {
+                  for (const element of this.deviceChecks) {
+                    if (element.deviceNo === this.queryDeviceNo) {
+                      promptAction.showToast({
+                        message: `设备今日已点检,无需重复点检!`,
+                        duration: 1500,
+                        bottom: 100
+                      })
+                      return
+                    }
+                  }
+                }
+                let check: ProcessDeviceDailyCheck = await ProcessRequest.get(`/api/v1/process/equipDailyCheck/getServiceLifeByDeviceNo/${this.queryDeviceNo}`)
+                this.deviceChecks.unshift(check)
               })
               .onChange((value: string) => {
                 this.queryDeviceNo = value;
@@ -116,19 +101,19 @@ export struct EquipmentInspectionDialog {
         .width('50%')
         .margin({bottom:'1%',top:'1%'})
         List({scroller: this.scrollerDevice }) {
-            ForEach(this.devicesList, (item: DeviceInfo, index) => {
+            ForEach(this.deviceChecks, (item: ProcessDeviceDailyCheck, index) => {
               ListItem() {
                 Row() {
                   Column(){
-                    Text(`${item.deviceName}`)
+                    Text(`${item.deviceName!}`)
                       .fontSize($r('app.float.fontSize_24'))
                       .fontColor($r('app.color.FFFFFF'))
-                    Text(`型号:${item.deviceType}`)
+                    Text('型号:' + (this.deviceTypes && item.deviceType && this.deviceTypes.hasKey(item.deviceType) ? this.deviceTypes.get(item.deviceType) : ''))
                       .fontSize($r('app.float.fontSize_16'))
                       .fontColor($r('app.color.FFFFFF'))
                       .fontWeight(FontWeight.Lighter)
                       .margin({top:'2%',bottom:'1%'})
-                    Text(`设备编码:${item.deviceNo}`)
+                    Text(`设备编码:${item.deviceNo!}`)
                       .fontSize($r('app.float.fontSize_16'))
                       .fontColor($r('app.color.FFFFFF'))
                       .fontWeight(FontWeight.Lighter)
@@ -144,19 +129,13 @@ export struct EquipmentInspectionDialog {
                       .fontColor($r('app.color.FFFFFF'))
                       .fontWeight(FontWeight.Lighter)
                     Row(){
-                      Image(this.compareDates(this.currentDate, item.meteringDate) > 0
-                      ?$r('app.media.device_normal') :$r('app.media.device_expire')
-                      )
+                      Image(item.meteringState! === 1 ? $r('app.media.device_normal') : $r('app.media.device_expire'))
                         .width($r('app.float.virtualSize_24'))
                         .height($r('app.float.virtualSize_24'))
                         .margin({left:'2%'})
-                      Text(`${item.meteringDate}`)
+                      Text(item.meteringDate ? `${item.meteringDate}` : '长期有效')
                         .fontSize($r('app.float.fontSize_16'))
-                        .fontColor(
-                          this.compareDates(this.currentDate, item.meteringDate) > 0
-                            ? $r('app.color.30D158')  // 有效期未过(绿色)
-                            : $r('app.color.FF453A')  // 已过期(红色)
-                        )
+                        .fontColor(item.meteringState! === 1 ? $r('app.color.30D158') : $r('app.color.FF453A'))
                         .margin({left:'2%'})
                     }
                     .width('65%')
@@ -175,19 +154,13 @@ export struct EquipmentInspectionDialog {
                       .fontColor($r('app.color.FFFFFF'))
                       .fontWeight(FontWeight.Lighter)
                     Row(){
-                      Image(this.compareDates(this.currentDate, item.updated) > 0
-                        ?$r('app.media.device_normal') :$r('app.media.device_expire')
-                      )
+                      Image(item.warrantyState! === 1 ? $r('app.media.device_normal') :$r('app.media.device_expire'))
                         .width($r('app.float.virtualSize_24'))
                         .height($r('app.float.virtualSize_24'))
                         .margin({left:'2%'})
-                      Text(`${item.updated}`)
+                      Text(item.warrantyPeriod ? `${item.warrantyPeriod}` : '长期有效')
                         .fontSize($r('app.float.fontSize_16'))
-                        .fontColor(
-                          this.compareDates(this.currentDate, item.updated) > 0
-                            ? $r('app.color.30D158')
-                            : $r('app.color.FF453A')
-                        )
+                        .fontColor(item.warrantyState! === 1 ? $r('app.color.30D158') : $r('app.color.FF453A'))
                         .margin({left:'2%'})
                     }
                     .width('65%')
@@ -206,7 +179,7 @@ export struct EquipmentInspectionDialog {
                      .height($r('app.float.virtualSize_48'))
                      .fillColor($r('app.color.FF453A'))
                      .onClick(()=>{
-                       this.devicesList.splice(index, 1);
+                       this.deviceChecks.splice(index, 1);
                      })
                   }
                   .width('10%')
@@ -258,7 +231,14 @@ export struct EquipmentInspectionDialog {
           }
           .justifyContent(FlexAlign.Center)
           .width('50%')
-          .onClick(() => {
+          .onClick(async () => {
+            if (!this.deviceChecks || this.deviceChecks.length <= 0) {
+               return
+            }
+            for (const check of this.deviceChecks) {
+              check.stationIp = this.stationIp
+            }
+            await ProcessRequest.post('/api/v1/process/equipDailyCheck/batchSave', this.deviceChecks)
             this.controller.close();
           })
         }

+ 0 - 1
entry/src/main/ets/view/LoginInfoDialog.ets

@@ -2,7 +2,6 @@ import ProcessRequest from '../common/util/request/ProcessRequest'
 import { MessageInfo, MessagePage } from '../viewmodel/MessageInfo'
 import { UserInfo, WorkstationInfo } from '../viewmodel/UserInfo'
 import RequestParamModel from '../viewmodel/RequestParamModel'
-import { SwitchingStationDialog } from './SwitchingStationViews'
 import CommonConstants from '../common/constants/CommonConstants'
 
 @CustomDialog

+ 2 - 2
entry/src/main/ets/view/SelectWorkOrderDialog.ets

@@ -21,7 +21,7 @@ export struct SelectWorkOrderDialog {
 
   //加载所有工单
   loadWorkOrders = async () => {
-    let queryRes = await ProcessRequest.post('/api/v1/plan/workOrder/taskPage', {
+    let queryRes = await ProcessRequest.post('/api/v1/plan/workOrder/taskPage2', {
       queryCode:this.scanOrderValue,
       queryComplete: 0,
       stationId:this.currentStationId
@@ -63,7 +63,7 @@ export struct SelectWorkOrderDialog {
           .fontColor($r('app.color.FFFFFF'))
           .enableKeyboardOnFocus(false)
           .onSubmit(async () => {
-            let queryRes = await ProcessRequest.post('/api/v1/plan/workOrder/taskPage', {
+            let queryRes = await ProcessRequest.post('/api/v1/plan/workOrder/taskPage2', {
               queryCode:this.scanOrderValue
             } as RequestParamModel) as WorkOrderPage;
             this.workOrderList = queryRes?.records??[]

+ 1 - 0
entry/src/main/ets/view/SwitchingProductDialog.ets

@@ -320,6 +320,7 @@ export struct SwitchingProductDialog{
             let seqNos: string[] = []
             seqNos = await preferencesUtil.get(CommonConstants.PREFERENCE_INSTANCE_NAME, this.selectWorkOder.workOrderCode!, seqNos)
             if (seqNos.includes(this.seqNo)) {
+              this.controller.close();
               return
             }
             seqNos.push(this.seqNo)

+ 0 - 13
entry/src/main/ets/viewmodel/DeviceInfo.ets

@@ -1,13 +0,0 @@
-export default class DeviceInfo {
-  // 设备名字
-  deviceName?: string
-  // 设备型号
-  deviceType?: string
-  //设备编码
-  deviceNo?: string
-  //计量有效期
-  meteringDate?:string
-  //todo 暂时使用updated作为维保有效期
-  // 维保有效期
-  updated?:string
-}

+ 1 - 2
entry/src/main/ets/viewmodel/PageInfo.ets

@@ -1,4 +1,3 @@
-import DeviceInfo from './DeviceInfo'
 import MaterialInfo from './MaterialInfo'
 import OperationItem from './OperationItem'
 import ProcessCheck from './process/ProcessCheck'
@@ -8,5 +7,5 @@ export default interface PageInfo {
   pageNo?:string,
   pageSize?:string,
   //消息记录
-  records?: MaterialInfo[] | ProcessCheck[] | OperationItem[] | UserInfo[] | DeviceInfo[]
+  records?: MaterialInfo[] | ProcessCheck[] | OperationItem[] | UserInfo[]
 }

+ 4 - 0
entry/src/main/ets/viewmodel/RequestParamModel.ets

@@ -102,4 +102,8 @@ export default class RequestParamModel {
   notDrawingDictValue?:string
   //缺陷类型(数据字典值)
   bugType?:string
+  //工位ip
+  stationIp?:string
+  //创建日期
+  createDate?:string
 }

+ 21 - 0
entry/src/main/ets/viewmodel/process/ProcessDeviceDailyCheck.ets

@@ -0,0 +1,21 @@
+// 生产过程点检
+export default class ProcessCheck {
+  // 主键id
+  id?: string;
+  // 工位ip
+  stationIp?: string;
+  // 设备编码
+  deviceNo?: string;
+  // 设备名字
+  deviceName?: string
+  // 设备型号(数据字典)
+  deviceType?: string
+  // 计量有效期
+  meteringDate?: string;
+  // 计量状态(1:有效 0:过期)
+  meteringState?: number;
+  // 维保有效期
+  warrantyPeriod?: string;
+  // 维保状态(1:有效 0:过期)
+  warrantyState?: number;
+}

+ 2 - 0
entry/src/main/ets/viewmodel/process/ProcessEscalationFault.ets

@@ -55,4 +55,6 @@ export default class ProcessEscalationFault {
   seqNoList?: string[]
   // 关联工序(目前只有当前工序)
   processesList?: string[]
+  // 工位id
+  stationId?: string
 }