Try   HackMD

CRM 開發環境準備筆記

前置作業

跟 MIS 申請 Microsoft Partner Network(MPN)。申請方式如下:

  1. 打開瀏覽器並連到 mis.gss.com.tw
  2. 點選 9. 申請軟體授權(Office / Visual Studio)
  3. 軟體名稱:Visual Studio 2022
  4. 權限原因申請內容可參考我當時輸入的:
    ​​​因參與雲端產品 Vital CRM 開發,需要申請 Azure AD 帳號;配發 MPN - Visual Studio subscriptions。
    
  5. 送出表單
  6. 靜候佳音

申請成功後會收到一封信,驗證身份。之後在 https://my.visualstudio.com/downloads 使用公司帳密登入,即可取得不同軟體的授權。

開發環境需求

  • Windows 10

    需要有 D 槽存放 CRM 的資料庫檔案(容量不用很大沒關係)

    卡西的 Windows 筆電因為沒有 D 槽,在開發 CRM 時要額外調整設定,感覺帶來不少困擾。
  • Git for Windows
    版本控制用。Charley 推薦用 Fork,看個人習慣用哪種版控軟體都行。我是直接裝 Cmder,因為它裡面有包含 Git for Windows
  • Visual Studio Enterprise 2019
    Enterprise 版本的金鑰要跟 MIS 申請,不過其實裝免費的社群版本應該也可以執行啦⋯⋯安裝時請參考以下兩張照片勾選安裝項目(Python development 可不勾選)。安裝完在 Visual Studio 輸入公司帳密登入即完成驗證)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →


    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • Visual Studio Code
    我在改程式碼的時候多半還是用它,畢竟跟 Visual Studio 不太熟 😅
  • SQLite Expert Personal 5.0.0
    資料庫管理工具,版更之後有時候會需要用它執行 SQL 命令
  • Node.js
    好像沒有限定版本,我還在用舊的 10.23.3 版,但應該裝目前的 LTS 穩定版本就行。如果有切換不同 Node.js 版本的需求,可改裝 nvm-windows
  • yarn
    安裝完 Node.js 之後,執行 npm install --global yarn 即可

執行環境需求

  • 下載 memcached (我是使用 v1.6.8,不確定使用其它版本有無問題)
    下載完解壓縮到 D:\,之後以管理員權限打開 命令提示字元或 powershell:
    ​​D: ​​cd memcached ​​nssm install memcached D:\memcached\memcached.exe ​​nssm start memcached
  • 下載資料庫壓縮檔,並解壓縮到 D:\App_Data_iStore\ 資料夾底下(這是資料庫檔案)
    較新的資料庫壓縮檔可以跟 CRM 團隊索取,或是下載 2023/04/21 UAT DB
  • Clone CRM repo

把 CRM 跑起來

  1. 以管理員身份執行 \CRM\docs\環境變數\RunLocalHost.bat,然後重開機
    • DB 預設路徑為 D:\App_Data_iStore\,如有想設在別的路徑的話,編輯RunLocalHost.bat,將裡面的 D:\\App_Data_iStore\\ 改為想設為的路行
  2. 打開 CRM\Gss.Crm.Store.WebUI.slnf 檔案
  3. 在右邊找到 Gss.Crm.Store.WebUI 點擊右鍵選擇-設定為啟動專案(A)
  4. 到畫面中間上方點選「IIS Express」:
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  5. 此時應該會跳出瀏覽器視窗,網址是 http://localhost:54275
  6. 將網址改為 http://localhost:54275/1111
  7. 輸入帳號(sa)和密碼(1111)登入

修改 React 的程式碼

需要先跑以下指令,再開 Visual Studio 執行專案:

D: cd CRM/Frontend yarn install yarn starty

yarn start 期間產出的 *.bundle.js 不會讓它們進版控,而是在 local branch 做完事之後執行 yarn build,透過 yarn build 產出來的 *.bundle.js 會額外用一個 commit 專門把它們納入版控:

yarn build git add . git commit -m "chore: rebuild frontend scripts"

註:這種打包過後的檔案通常不會納進版控,而是在 CI/CD 時去自動產比較合理。但考量到 CRM 團隊未必每個人都熟悉現代前端的開發與打包流程,所以當時規劃是手動 build + commit

常見問題

版更後莫名報錯

版更時有可能需要跑 SQL 命令更新資料庫,步驟如下:

  1. 以 Visual Studio Code 或任何文字編輯器開啟 CRM\docs\DBScript\upgrade-sqlite.sql 檔案
  2. 複製該檔案所有內容
  3. 開啟 SQLite Expert Personal
  4. 畫面中間下來一點有五個頁籤 DatabaseDataDDLDesignSQL,選擇 SQL 頁籤
  5. 貼上第 2 步驟複製的文字
  6. 點選畫面中間下方的「Execute SQL」按鈕
  7. 關閉 SQLite Expert Personal

若還是不行的話,請洽詢 CRM 團隊協助

找不到 \src\Core\Gss.Crm.Store.Creator.Core\Gss.Crm.Store.Creator.Core.csproj 專案資訊

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  1. 執行 ``/CRM/Build.sln`
  2. 在方案總管中的 /main 找到 Gss.Crm.Store.WebUI,按右鍵,點選"設為啟動專案"
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

在非公司內網使用 React 版佈告欄時,可能在存檔時報錯

這個情形在公司內網不會遇到,遇到時有兩個解法:

  1. 在本地安裝 MySQL
  2. 在不納入版控的前提下,註解掉某些程式碼

在本地安裝 MySQL

  1. 下載並執行 MySQL 安裝檔:
    https://dev.mysql.com/downloads/windows/installer/
  2. 選預設設定,一直按 Next 直到出現 Accounts and Roles
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  3. 上方 Accounts and Roles 區域輸入 Root 的密碼(任意密碼,自己記得就行)
  4. 下方 MySQL User Accounts 區域點選 Add User,帳號密碼都輸入 heart,其它選項保持預設值不動
  5. 繼續下一步直到安裝結束
  6. 下載 Dump20210624.zip 後解壓縮到任意路徑(例如:桌面)
  7. 打開 MySQL Workbench(如果第 2 步那邊是預設安裝的話,應該會一併安裝 Workbench)
  8. local
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  9. 點左側 Data Import/Restore,選第 6 步解壓縮的資料夾路徑
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  10. 左下角會跳出 quartzquartz-batch,確認兩者都是勾選的狀態
  11. 點選右下角的 Start import(找不到的話,可能要調整版面,收合右側和下方視窗)
  12. 匯入完成後,切換到 Schemas 頁籤
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  13. 隨便點個地方滑鼠右鍵選 refresh
  14. 確認有沒有多出兩個 DB
  15. 重新跑 CRM 專案,此時佈告欄存檔應該不會報錯了

在不納入版控的前提下,註解掉某些程式碼

\src\Store\Gss.Crm.Quartz.Job\Impl\SchedulerEngine.cs 檔案中註解掉以下幾行程式碼:

// 第55行左右 scheduleTask = JobManager.AddJob(scheduleTask, scheduler, jobParameterMap); // 第334行左右 JobManager.DeleteJob(QuartzEngine.Scheduler, this.GroupName, jobName);