{"record":{"id":"4d390d68ea03cd7a","repo":"jeecgboot/JeecgBoot","slug":"templatecode","errorCode":null,"errorMessage":"消息模板不存在，模板编码：${templateCode}","messagePattern":"消息模板不存在，模板编码：(.+?)","errorType":"exception","errorClass":"JeecgBootException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java","lineNumber":514,"sourceCode":"\t\t\t// 同步发送第三方APP消息\n\t\t\twechatEnterpriseService.sendMessage(message, true);\n\t\t\tdingtalkService.sendMessage(message, true);\n\t\t} catch (Exception e) {\n\t\t\tlog.error(\"同步发送第三方APP消息失败！\", e);\n\t\t}\n\t}\n\n\t@Override\n\tpublic void sendTemplateAnnouncement(TemplateMessageDTO message) {\n\t\tString templateCode = message.getTemplateCode();\n\t\tString title = message.getTitle();\n\t\tMap<String,String> tmplateParam = message.getTemplateParam();\n\t\tString fromUser = message.getFromUser();\n\t\tString toUser = message.getToUser();\n\n\t\tList<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);\n\t\tif(sysSmsTemplates==null||sysSmsTemplates.size()==0){\n\t\t\tthrow new JeecgBootException(\"消息模板不存在，模板编码：\"+templateCode);\n\t\t}\n\t\tSysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);\n\t\t//模板标题\n\t\ttitle = title==null?sysSmsTemplate.getTemplateName():title;\n\t\t//模板内容\n\t\tString content = sysSmsTemplate.getTemplateContent();\n\t\tif(tmplateParam!=null) {\n\t\t\tfor (Map.Entry<String, String> entry : tmplateParam.entrySet()) {\n\t\t\t\tString str = \"${\" + entry.getKey() + \"}\";\n\t\t\t\tif(oConvertUtils.isNotEmpty(title)){\n\t\t\t\t\ttitle = title.replace(str, entry.getValue());\n\t\t\t\t}\n\t\t\t\tcontent = content.replace(str, entry.getValue());\n\t\t\t}\n\t\t}\n\t\tString mobileOpenUrl = null;\n\t\tif(tmplateParam!=null && oConvertUtils.isNotEmpty(tmplateParam.get(CommonConstant.MSG_HREF_URL))){\n\t\t\tmobileOpenUrl = tmplateParam.get(CommonConstant.MSG_HREF_URL);","sourceCodeStart":496,"sourceCodeEnd":532,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java#L496-L532","documentation":"In SysBaseApiImpl.sendTemplateAnnouncement, the message template is looked up from sys_sms_template by templateCode. If the query returns null or an empty list, there is no template to render, so a JeecgBootException is thrown before any title/content substitution. Sending is therefore impossible until a template exists.","triggerScenarios":"Calling sysBaseApi.sendTemplateAnnouncement(...) with a templateCode for which no sys_sms_template row exists — deleted, never created, typo, or a code from a different environment.","commonSituations":"Template created in dev but missing in prod; case/whitespace mismatch in the code; template was deleted but code references remain; code copied from documentation that doesn't exist in this deployment.","solutions":["Verify the code exists: SELECT * FROM sys_sms_template WHERE template_code = ?.","Create the missing template via the message-template management UI.","Check for trailing spaces and case sensitivity in the supplied templateCode."],"exampleFix":"// before\nsysBaseApi.sendTemplateAnnouncement(msg); // templateCode 'welcome' missing\n// after: guard the call against a missing template\nList<SysMessageTemplate> t = sysMessageTemplateService.selectByCode(msg.getTemplateCode());\nif (t == null || t.isEmpty()) {\n    log.warn(\"模板缺失: {}\", msg.getTemplateCode());\n    return; // or fall back to a plain-text announcement\n}\nsysBaseApi.sendTemplateAnnouncement(msg);","handlingStrategy":"validation","validationCode":"// Verify the template exists before sending.\nList<SysMessageTemplate> rows = sysMessageTemplateService.selectByCode(templateCode);\nif (rows == null || rows.isEmpty()) {\n    log.warn(\"消息模板缺失: {}\", templateCode);\n    return; // or fall back to plain text\n}","typeGuard":"public boolean templateExists(String code) {\n    List<SysMessageTemplate> r = sysMessageTemplateService.selectByCode(code);\n    return r != null && !r.isEmpty();\n}","tryCatchPattern":"try {\n    sysBaseApi.sendTemplateAnnouncement(msg);\n} catch (JeecgBootException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"消息模板不存在\")) {\n        return Result.error(\"消息模板未配置: \" + msg.getTemplateCode());\n    }\n    throw e;\n}","preventionTips":["Seed required templates via a Flyway/migration script so every environment has them.","Centralize template codes as constants shared between sender and config.","Audit for deleted templates that are still referenced by code."],"tags":["message","template","announcement"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}