# Script to seed the MF919 Default Parameters template and populate it with # reusable values derived from default_params.properties. # # Run with: mix run priv/repo/seeds/mf919_default_template.exs # # Prerequisites: # 1. mf919_parameter_categories.exs # 2. mf919_parameter_definitions.exs Mix.Task.run("app.start") require Logger alias DaProductApp.Repo alias DaProductApp.ParameterManagement.{ParameterDefinition, ParameterTemplate, ParameterTemplateValue} # --------------------------------------------------------------------------- # 1. Create (or reuse) the MF919 Default Parameters template # --------------------------------------------------------------------------- template = Repo.get_by(ParameterTemplate, vendor: "MoreFun", model: "MF919", name: "MF919 Default Parameters") || ( {:ok, t} = Repo.insert(%ParameterTemplate{ name: "MF919 Default Parameters", description: "Reusable base parameter template for MoreFun MF919 devices, " <> "populated from default_params.properties", vendor: "MoreFun", model: "MF919", is_default: true, is_active: true }) t ) Logger.info("Using template ID: #{template.id} – #{template.name}") # --------------------------------------------------------------------------- # 2. Template values sourced from default_params.properties # Merchant-specific overlay keys (MERCHANT_ID, TERMINAL_ID, BATCH_NO) are # intentionally excluded – those are applied per-terminal via overrides. # --------------------------------------------------------------------------- template_values = [ # Base {"BASE_MERCHANT_NAME", "Demo Merchant"}, {"BASE_TRACE_NO", "000001"}, {"BASE_MAX_REFUND_AMOUNT", "1000000"}, {"BASE_CURRENCY_CODE", "784"}, {"BASE_MAX_TRANS_COUNT", "500"}, # PINPAD {"PINPAD_MASTER_KEY_INDEX", "0"}, {"PINPAD_ALGORITHM_TYPE", "0"}, {"PINPAD_TIMEOUT", "60"}, {"EXTERNAL_PINPAD_YSDK", "true"}, {"EXTERNAL_PINPAD", "false"}, {"EXTERNAL_PINPAD_CONNECT_MODE", "0"}, # Printing {"PRINT_COUNT", "2"}, {"PRINT_EXTERNAL", "false"}, {"PRINT_EXTERNAL_CONNECT_MODE", "1"}, {"PRINT_EXTERNAL_SERIAL_BAUDRATE", "115200"}, {"PRINT_REMARKS", "Thank you, Visit Again"}, # Transactions {"TRANS_SALE", "true"}, {"TRANS_VOID", "true"}, {"TRANS_REFUND", "true"}, {"TRANS_BALANCE", "true"}, {"TRANS_PREAUTH", "true"}, {"TRANS_MOBILE_PAY", "true"}, {"TRANS_INSTALLMENT", "true"}, # Communication {"COMM_USE_SSL", "false"}, {"COMM_TIMEOUT", "60"}, {"COMM_TPDU", "6000782000"}, {"COMM_SERVER_ADDRESS", "40.120.104.51"}, {"COMM_PORT", "80"}, {"COMM_NII", "782"}, # Signature / Scanner {"ELECSIGN_IS_SUPPORT", "false"}, {"SCAN_PRIORITY_SCANNER", "1"}, {"SCAN_EXTERN_CONNECT_MODE", "0"}, {"SCAN_EXTERN_USB_WAIT_TIME", "300"}, {"SCAN_EXTERN_SERIAL_BAUDRATE", "115200"}, # Security / Operational {"PASSWORD_ADMIN", "123456"}, {"PASSWORD_SYSTEM_ADMIN", "000000"}, {"PASSWORD_SECURITY", "888888"}, {"TOMS_FLY_PARAMETERS", "false"}, {"TOMS_FLY_RECEIPT", "false"}, {"NFC_RECEIPT", "false"}, {"OTHER_TIP_INPUT", "false"}, {"OTHER_THRID_BILL_SHOW", "false"}, {"OTHER_VOID_CARD", "false"}, {"OTHER_VOID_PIN", "false"} ] # --------------------------------------------------------------------------- # 3. Insert template values # --------------------------------------------------------------------------- Enum.each(template_values, fn {key, value} -> case Repo.get_by(ParameterDefinition, key: key) do nil -> Logger.warning("Parameter definition not found for key: #{key} – skipping") param_def -> case Repo.get_by(ParameterTemplateValue, template_id: template.id, parameter_definition_id: param_def.id ) do nil -> changeset = ParameterTemplateValue.changeset(%ParameterTemplateValue{}, %{ template_id: template.id, parameter_definition_id: param_def.id, value: value, is_overridden: false }) case Repo.insert(changeset) do {:ok, tv} -> Logger.info("Created template value: #{key} = #{value} (ID: #{tv.id})") {:error, reason} -> Logger.error("Failed to create template value #{key}: #{inspect(reason)}") end existing -> Logger.info("Template value already exists: #{key} = #{existing.value} (ID: #{existing.id})") end end end) Logger.info("MF919 default template seeding completed!")