diff --git a/openhis-server/core-common/src/main/java/com/core/common/utils/MessageUtils.java b/openhis-server/core-common/src/main/java/com/core/common/utils/MessageUtils.java index 4cf48caf..1be2b0b0 100644 --- a/openhis-server/core-common/src/main/java/com/core/common/utils/MessageUtils.java +++ b/openhis-server/core-common/src/main/java/com/core/common/utils/MessageUtils.java @@ -4,6 +4,9 @@ import org.springframework.context.MessageSource; import org.springframework.context.i18n.LocaleContextHolder; import com.core.common.utils.spring.SpringUtils; +import org.springframework.lang.Nullable; + +import java.util.Locale; /** * 获取i18n资源文件 @@ -22,4 +25,10 @@ public class MessageUtils { MessageSource messageSource = SpringUtils.getBean(MessageSource.class); return messageSource.getMessage(code, args, LocaleContextHolder.getLocale()); } + + public static String createMessage(String id, @Nullable Object[] params) { + MessageSource messageSource = (MessageSource) SpringContextUtils.getApplicationContext().getBean(MessageSource.class); + String messageConvert = messageSource.getMessage(id, params, Locale.getDefault()); + return messageConvert; + } } diff --git a/openhis-server/core-common/src/main/java/com/core/common/utils/SpringContextUtils.java b/openhis-server/core-common/src/main/java/com/core/common/utils/SpringContextUtils.java new file mode 100644 index 00000000..acfa683e --- /dev/null +++ b/openhis-server/core-common/src/main/java/com/core/common/utils/SpringContextUtils.java @@ -0,0 +1,38 @@ +package com.core.common.utils; + + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@Component +public class SpringContextUtils implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + public SpringContextUtils() { + } + + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + SpringContextUtils.applicationContext = applicationContext; + } + + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + public static HttpServletRequest getHttpServletRequest() { + return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); + } + + public static HttpServletResponse getHttpServletResponse() { + return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse(); + } + +} diff --git a/openhis-server/openhis-application/src/main/java/com/openhis/web/InventoryManage/controller/PurchaseInventoryController.java b/openhis-server/openhis-application/src/main/java/com/openhis/web/InventoryManage/controller/PurchaseInventoryController.java index ac99d23e..e25580ca 100644 --- a/openhis-server/openhis-application/src/main/java/com/openhis/web/InventoryManage/controller/PurchaseInventoryController.java +++ b/openhis-server/openhis-application/src/main/java/com/openhis/web/InventoryManage/controller/PurchaseInventoryController.java @@ -5,6 +5,8 @@ package com.openhis.web.InventoryManage.controller; import javax.servlet.http.HttpServletRequest; +import com.core.common.utils.MessageUtils; +import com.openhis.common.constant.PromptMsgConstant; import com.openhis.web.InventoryManage.dto.SupplySaveRequestDto; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -38,6 +40,12 @@ public class PurchaseInventoryController { private final IChargeItemService chargeItemService; + @GetMapping(value = "/test") + public R test(){ + //return R.ok(null, MessageUtils.createMessage(PromptMsgConstant.Common.M00002,new Object[] {"12345"})) ; + return R.fail(MessageUtils.createMessage(PromptMsgConstant.Common.M00002,new Object[] {"12345"})) ; + } + /** * 入库单据分页列表 * diff --git a/openhis-server/openhis-application/src/main/resources/application.yml b/openhis-server/openhis-application/src/main/resources/application.yml index 3e0f5b9e..4144e50a 100644 --- a/openhis-server/openhis-application/src/main/resources/application.yml +++ b/openhis-server/openhis-application/src/main/resources/application.yml @@ -87,6 +87,10 @@ spring: max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms + # 文言 + messages: + basename: i18n/general_message/messages + encoding: utf-8 # token配置 token: diff --git a/openhis-server/openhis-application/src/main/resources/i18n/messages.properties b/openhis-server/openhis-application/src/main/resources/i18n/messages.properties index dbd997bd..ecbbd07e 100644 --- a/openhis-server/openhis-application/src/main/resources/i18n/messages.properties +++ b/openhis-server/openhis-application/src/main/resources/i18n/messages.properties @@ -31,3 +31,7 @@ no.update.permission=您没有修改数据的权限,请联系管理员添加 no.delete.permission=您没有删除数据的权限,请联系管理员添加权限 [{0}] no.export.permission=您没有导出数据的权限,请联系管理员添加权限 [{0}] no.view.permission=您没有查看数据的权限,请联系管理员添加权限 [{0}] + + + +apl.common.M00002={0}保存成功 \ No newline at end of file diff --git a/openhis-server/openhis-common/src/main/java/com/openhis/common/constant/PromptMsgConstant.java b/openhis-server/openhis-common/src/main/java/com/openhis/common/constant/PromptMsgConstant.java new file mode 100644 index 00000000..8fc65117 --- /dev/null +++ b/openhis-server/openhis-common/src/main/java/com/openhis/common/constant/PromptMsgConstant.java @@ -0,0 +1,48 @@ +package com.openhis.common.constant; + +/** + * APL消息ID常量类 + */ +public interface PromptMsgConstant { + + /** + * 共用 + */ + interface Common { + /** + * {0}添加成功 + */ + String M00001 = "apl.common.M00001"; + /** + * {0}保存成功 + */ + String M00002 = "apl.common.M00002"; + /** + * {0}已经存在 + */ + String M00003 = "apl.common.M00003"; + /** + * {0}操作成功 + */ + String M00004 = "apl.common.M00004"; + /** + * {0}删除成功 + */ + String M00005 = "apl.common.M00005"; + /** + * 操作失败,该数据已被他人删除,请刷新后重试 + */ + String M00006 = "apl.common.M00006"; + /** + * 操作失败,该数据已被他人更改,请刷新后重试 + */ + String M00007 = "apl.common.M00007"; + /** + * 请勿重复提交 + */ + String M00008 = "apl.common.M00008"; + + } + + +}