Browse Source

成品入仓优化

unknown 1 week ago
parent
commit
01d2b3c36e

+ 12 - 6
application/api/controller/FinishedProductWarehousing.php

@@ -453,8 +453,9 @@ public function getList()
         }
         }
 
 
         $this->validateMaterialReceived($data['jjcp_gdbh'], $data['jjcp_yjno']);
         $this->validateMaterialReceived($data['jjcp_gdbh'], $data['jjcp_yjno']);
-
+     
         $data['UniqId'] = $this->generateFinishStockUniqId();
         $data['UniqId'] = $this->generateFinishStockUniqId();
+      
         $mongodb = Db::connect(config('database.mongodb'));
         $mongodb = Db::connect(config('database.mongodb'));
         $this->saveFinishStock($data, $mongodb);
         $this->saveFinishStock($data, $mongodb);
 
 
@@ -467,7 +468,7 @@ public function getList()
                 $this->error('成品入仓已保存,但' . $e->getMessage(), ['UniqId' => $data['UniqId']]);
                 $this->error('成品入仓已保存,但' . $e->getMessage(), ['UniqId' => $data['UniqId']]);
             }
             }
         }
         }
-
+        
         if ($this->isEndBoard($data['jjcp_smb'])) {
         if ($this->isEndBoard($data['jjcp_smb'])) {
             $this->handleEndBoardSuperLoss($data['jjcp_gdbh'], $data['jjcp_yjno']);
             $this->handleEndBoardSuperLoss($data['jjcp_gdbh'], $data['jjcp_yjno']);
         }
         }
@@ -1509,13 +1510,17 @@ public function getList()
     }
     }
 
 
     /**
     /**
-     * 判断是否为末版
+     * 判断是否为末版(仅判断首字符是否为「末」)
      * @param string $smb
      * @param string $smb
      * @return bool
      * @return bool
      */
      */
     protected function isEndBoard($smb)
     protected function isEndBoard($smb)
     {
     {
-        return strpos((string)$smb, '末') !== false;
+        $smb = preg_replace('/^[\s\x{3000}]+|[\s\x{3000}]+$/u', '', (string)$smb);
+        if ($smb === '') {
+            return false;
+        }
+        return mb_substr($smb, 0, 1, 'UTF-8') === '末';
     }
     }
 
 
     /**
     /**
@@ -1545,8 +1550,9 @@ public function getList()
             return false;
             return false;
         }
         }
 
 
-        // 与 syncFinishStockMiddle 一致:测试库 database.db8;正式库可改为 database.db3
-        $middleDb = Db::connect(config('database.db8'));
+        // db3:正式中间库,仅查询 U8_06工单资料是否存在该工单
+        // 实际写入走 syncFinishStockMiddle 中的 database.db8(本地 MySQL 测试库)
+        $middleDb = Db::connect(config('database.db3'));
         $exists = $middleDb->name('U8_06工单资料')->where('工单编号', $gdbh)->count();
         $exists = $middleDb->name('U8_06工单资料')->where('工单编号', $gdbh)->count();
         return $exists > 0;
         return $exists > 0;
     }
     }

+ 5 - 3
application/api/controller/Synchronization.php

@@ -2109,6 +2109,7 @@ class Synchronization extends Api
         }
         }
 
 
         $record = db('成品入仓')->where('UniqId', $uniqId)->find();
         $record = db('成品入仓')->where('UniqId', $uniqId)->find();
+     
         if (empty($record)) {
         if (empty($record)) {
             throw new \Exception('同步失败:未找到成品入仓记录 UniqId=' . $uniqId);
             throw new \Exception('同步失败:未找到成品入仓记录 UniqId=' . $uniqId);
         }
         }
@@ -2117,12 +2118,14 @@ class Synchronization extends Api
             $record['Sys_id'] = $usernameOverride;
             $record['Sys_id'] = $usernameOverride;
         }
         }
 
 
-        // 测试库:database.db8(MySQL);正式库可改为 database.db3(SQL Server)
+        // 写入目标:本地测试库 database.db8(MySQL)
+        // 是否同步的判定在 shouldSyncFinishStockMiddle:用正式库 database.db3 查 U8_06工单资料是否存在
         $targetDb = Db::connect(config('database.db8'));
         $targetDb = Db::connect(config('database.db8'));
         $targetTable = 'U8_成品入仓';
         $targetTable = 'U8_成品入仓';
 
 
         $syncTime = date('Y-m-d H:i:s');
         $syncTime = date('Y-m-d H:i:s');
-        $isEndBoard = (strpos((string)$record['jjcp_smb'], '末') !== false) ? '末板' : '';
+        $smb = preg_replace('/^[\s\x{3000}]+|[\s\x{3000}]+$/u', '', (string)$record['jjcp_smb']);
+        $isEndBoard = ($smb !== '' && mb_substr($smb, 0, 1, 'UTF-8') === '末') ? '末板' : '';
         $id = 0;
         $id = 0;
         $errorMsg = '';
         $errorMsg = '';
         $iQty = $iQtyOverride !== null ? $iQtyOverride : $record['jjcp_sl'];
         $iQty = $iQtyOverride !== null ? $iQtyOverride : $record['jjcp_sl'];
@@ -2154,7 +2157,6 @@ class Synchronization extends Api
                 '成品名称'    => $record['成品名称'],                   // 成品名称
                 '成品名称'    => $record['成品名称'],                   // 成品名称
                 'UniqId'      => $record['UniqId'],                    // 唯一ID
                 'UniqId'      => $record['UniqId'],                    // 唯一ID
             ];
             ];
-
             // 中文字段名不能走 ThinkPHP 命名绑定(PDO 会截断 :data__MES插入类型),改用位置绑定
             // 中文字段名不能走 ThinkPHP 命名绑定(PDO 会截断 :data__MES插入类型),改用位置绑定
             $this->insertFinishStockMiddle($targetDb, $targetTable, $data);
             $this->insertFinishStockMiddle($targetDb, $targetTable, $data);