Files
17168ERP/data/search_keyword.md

210 lines
8.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 新增 followers 欄位 search_keywords
- 參考程式 : D:\dev\ez\17168erp\git_17888\web\admin\follower\follower_code.aspx
```
string joinedString = string.Join("|", new string[] {
phone_decrypted, // 解密後的 phone 電話號碼
cellphone_decrypted, // 解密後的 cellphone 手機號碼
id_code_decrypted, // 解密後的 id_code 身份證號
passport_decrypted // 解密後的 passport 護照號碼
});
// 將連接字串轉換為 HEX
string hexString = "";
try {
byte[] bytes = Encoding.UTF8.GetBytes(joinedString);
hexString = BitConverter.ToString(bytes).Replace("-", "").ToLower();
} catch {
hexString = "";
}
```
- 原本table: followers 有4個欄位 phone, cellphone, id_code, passport
- 是加密儲存, 但因部份用戶認為方便比加密重要, 所以折衷加上欄位: search_keywords, 如上方式"編碼", 而非加密。
- 為保持原程式安全性, 本功能應為: 輔助, 選用, 不使用此機制, 就保持安全性優先。使用了, 就放棄加密。
- 為保彈性, 在web.config加一個參數: use search keywords, 為true/false, 目前設true, 並讀入為static class property。
- 相關機制運作, 都只有在該值為true時作用。
## 應作用機制:
針對以下程式, 若web.config use search keywords為true:
```
D:\dev\ez\17168erp\git_17888\web\App_Code\api\FollowerController.cs
D:\dev\ez\17168erp\git_17888\web\admin\follower\index.aspx
D:\dev\ez\17168erp\git_17888\web\admin\follower\index.aspx.cs
D:\dev\ez\17168erp\git_17888\web\admin\follower\reg.aspx
D:\dev\ez\17168erp\git_17888\web\admin\follower\reg.aspx.cs
D:\dev\ez\17168erp\git_17888\web\App_Code\Model\Partial\follower.cs
D:\dev\ez\17168erp\git_17888\web\App_Code\api\FollowerController.cs
D:\dev\ez\17168erp\git_17888\web\App_Code\appapi\appFollowerController.cs
```
- 搜尋時, 加上一個: 電話/證號 搜尋欄位, 將輸入的字串轉為HEX做 search_keywords like '%...%' 搜尋
- 儲存時, 除了原來欄位加密照原方式運行, 另外將4個欄位解密/組合/轉為HEX字串, 存入search_keywords
# 現有程式檢查
## 1. 資料庫檢查
- **followers 資料表**
- ✅ 已有加密欄位: `phone`, `cellphone`, `id_code`, `passport`
- ⚠️ **需新增**: `search_keywords` VARCHAR(MAX) 欄位 (用於存放 HEX 編碼字串)
## 2. 加密解密機制檢查
- **MyWeb.encrypt 類別** (App_Code/encrypt.cs)
- ✅ 已有加密方法: `EncryptAutoKey()`
- ✅ 已有解密方法: `DecryptAutoKey()`
- ✅ 已有 `followerHash()` 方法 (可參考其 HEX 轉換邏輯)
## 3. 現有程式搜尋功能
### 3.1 API 控制器 - FollowerController.cs
- **路徑**: D:\dev\ez\17168erp\git_17888\web\App_Code\api\FollowerController.cs
- **現況**:
- `GetList()` 方法有搜尋功能
- 使用 `Contains()` 搜尋 `f_number`, `u_name`, `address` 等欄位
- ⚠️ **無加密欄位搜尋**: phone, cellphone, id_code, passport 欄位無法直接搜尋
### 3.2 API 控制器 - appFollowerController.cs
- **路徑**: D:\dev\ez\17168erp\git_17888\web\App_Code\appapi\appFollowerController.cs
- **現況**: 與 FollowerController.cs 類似
- ⚠️ 同樣無加密欄位搜尋功能
### 3.3 前端頁面 - index.aspx
- **路徑**: D:\dev\ez\17168erp\git_17888\web\admin\follower\index.aspx
- **現況**:
- 搜尋欄位: 信眾編號、信眾姓名、地址、生日、國籍
- ⚠️ **缺少**: 電話/證號 搜尋欄位
### 3.4 後端頁面 - index.aspx.cs
- **路徑**: D:\dev\ez\17168erp\git_17888\web\admin\follower\index.aspx.cs
- **現況**:
- `searchData()` 方法處理搜尋條件
- ⚠️ 無加密欄位搜尋邏輯
## 4. 儲存功能檢查
### 4.1 註冊頁面 - reg.aspx.cs
- **路徑**: D:\dev\ez\17168erp\git_17888\web\admin\follower\reg.aspx.cs
- **現況**:
- ✅ `add_Click()` 新增方法: 有使用 `EncryptAutoKey()` 加密
- ✅ `edit_Click()` 修改方法: 有使用 `EncryptAutoKey()` 加密
- ⚠️ **缺少**: 儲存時需要生成 search_keywords
### 4.2 Model Partial 類別 - follower.cs
- **路徑**: D:\dev\ez\17168erp\git_17888\web\App_Code\Model\Partial\follower.cs
- **現況**:
- ✅ 有各種輔助方法
- ⚠️ **建議新增**: 生成 search_keywords 的輔助方法
## 5. Web.config 檢查
- **路徑**: D:\dev\ez\17168erp\git_17888\web\web.config
- **現況**:
- ⚠️ **需新增**: `<add key="UseSearchKeywords" value="true" />` 參數
# 程式工作規劃
## 階段一:資料庫與配置 (優先)
1. **資料庫結構調整**
- [ ] 在 `followers` 資料表新增 `search_keywords` VARCHAR(MAX) 欄位
- [ ] 執行 SQL Script 更新結構
- [ ] 備份現有資料
2. **Web.config 配置**
- [ ] 新增 `UseSearchKeywords` 參數 (預設值: true)
- [ ] 建立靜態類別讀取此設定值
## 階段二:核心功能實作
3. **encrypt.cs 擴充** (D:\dev\ez\17168erp\git_17888\web\App_Code\encrypt.cs)
- [ ] 新增 `GenerateSearchKeywords()` 方法
```csharp
// 輸入: phone, cellphone, id_code, passport (加密字串)
// 輸出: HEX 編碼的搜尋關鍵字
public string GenerateSearchKeywords(string phone, string cellphone,
string id_code, string passport)
```
- [ ] 參考現有 follower_code.aspx 的轉換邏輯
4. **follower.cs Partial 擴充** (D:\dev\ez\17168erp\git_17888\web\App_Code\Model\Partial\follower.cs)
- [ ] 新增屬性 `public string search_keywords { get; set; }`
- [ ] 新增靜態方法 `UpdateSearchKeywords()`
## 階段三:儲存功能調整
5. **reg.aspx.cs 修改** (D:\dev\ez\17168erp\git_17888\web\admin\follower\reg.aspx.cs)
- [ ] 修改 `add_Click()` 方法
- 新增資料後,如果 UseSearchKeywords = true
- 將 phone, cellphone, id_code, passport 解密
- 調用 GenerateSearchKeywords() 生成 HEX
- 更新 search_keywords 欄位
- [ ] 修改 `edit_Click()` 方法
- 同上述邏輯更新 search_keywords
6. **API 控制器調整**
- [ ] FollowerController.cs: 調整 POST/PUT 方法
- [ ] appFollowerController.cs: 同步調整
## 階段四:搜尋功能實作
7. **前端頁面 - index.aspx**
- [ ] 在搜尋區塊新增「電話/證號」搜尋欄位
- [ ] 修改 Vue.js data 區塊,新增 `search.phone_idcode` 欄位
- [ ] 修改 `btn_search()` 方法傳送新參數
8. **後端頁面 - index.aspx.cs**
- [ ] 修改 `searchData()` 方法
- [ ] 新增電話/證號搜尋邏輯
```csharp
if (!isStrNull(s_phone_idcode.Value) && UseSearchKeywords)
{
string hexSearch = ConvertToHex(s_phone_idcode.Value.Trim());
qry = qry.Where(o => o.search_keywords.Contains(hexSearch));
}
```
9. **API 控制器搜尋功能**
- [ ] FollowerController.cs - `GetList()` 方法
- 新增 phone_idcode 參數處理
- 如果 UseSearchKeywords = true使用 HEX 搜尋
- 如果 UseSearchKeywords = false返回錯誤或略過
- [ ] appFollowerController.cs - 同步修改
## 階段五:資料遷移與測試
10. **現有資料更新**
- [ ] 撰寫 SQL Script 或後台工具
- [ ] 批次更新現有 followers 的 search_keywords 欄位
- [ ] 驗證資料完整性
11. **測試計畫**
- [ ] 單元測試: HEX 轉換正確性
- [ ] 整合測試: 新增/修改資料後 search_keywords 正確生成
- [ ] 功能測試: 搜尋功能正常運作
## 階段六:文件與部署
12. **文件撰寫**
- [ ] 更新 API 文件
- [ ] 撰寫使用者手冊
- [ ] 記錄資料庫變更
13. **部署準備**
- [ ] 準備 SQL 更新腳本
- [ ] 準備回滾計畫
- [ ] 通知相關人員
# 程式問題
## 技術實作問題
### 8. 欄位為 NULL 的處理
- **6題**: phone, cellphone, id_code, passport 可能為 NULL
- **風險**: 轉 HEX 時可能發生錯誤
- **建議**:
- 在 GenerateSearchKeywords() 方法中妥善處理 NULL 值
- 使用 `string.Join("|", new string[] { ... }.Where(s => !string.IsNullOrEmpty(s)))`
## 建議的緩解措施優先順序
實作優先順序建議
### 高優先級 (必須處理)
1. **NULL 值處理**: 確保程式不會因為 NULL 值崩潰
2. **現有資料遷移**: 確保資料完整性
3. **錯誤處理**: 完善的例外處理機制