zoujiajian il y a 3 ans
Parent
commit
1abafb602f

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/I18nDynamicValueMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.I18nDynamicValue;
+
+/*
+ *项目名: netflix
+ *文件名: I18nDynamicValueMapper
+ *创建者: JavaZou
+ *创建时间:2022/12/12 12:09
+ */
+public interface I18nDynamicValueMapper extends BaseMapper<I18nDynamicValue> {
+}

+ 27 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/I18nDynamicValue.java

@@ -0,0 +1,27 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+
+/*
+ *项目名: netflix
+ *文件名: I18nDynamicValue
+ *创建者: JavaZou
+ *创建时间:2022/12/12 12:08
+ */
+@Getter
+@Setter
+public class I18nDynamicValue extends BaseEntity{
+	private String module;
+
+	@NotEmpty
+	private String key;
+
+	@NotEmpty
+	private String zhValue;
+
+	@NotEmpty
+	private String enValue;
+}

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/model/entity/UserPageLanguage.java

@@ -24,7 +24,7 @@ public class UserPageLanguage extends BaseEntity {
 	public enum Language {
 		zh_CN("中文"),
 
-		en_US("英");
+		en_US("英");
 
 		String desc;
 

+ 1 - 1
netflix-service/src/main/java/com/cyksj/common/I18nMessageUtil.java

@@ -15,7 +15,7 @@ import org.springframework.stereotype.Component;
 public class I18nMessageUtil {
 	private static MessageSource messageSource;
 
-	private static String DEFAULT_KEY = "default_msg";
+	public static String DEFAULT_KEY = "default_msg";
 
 	public I18nMessageUtil(MessageSource messageSource) {
 		this.messageSource = messageSource;

+ 45 - 0
netflix-service/src/main/java/com/cyksj/common/I18nValueEnum.java

@@ -0,0 +1,45 @@
+package com.cyksj.common;
+
+import com.cyksj.model.entity.UserPageLanguage;
+import lombok.Getter;
+
+import java.util.Locale;
+
+/*
+ *项目名: netflix
+ *文件名: I18nValueEnum
+ *创建者: JavaZou
+ *创建时间:2022/12/12 13:57
+ */
+@Getter
+public enum I18nValueEnum {
+
+
+	PARKING_SPACE_NOT_EXIST("该车位不存在", "The parking space does not exist"),
+
+	PARKING_SPACE_IS_OCCUPIED("该车位已有人", "The parking space is occupied"),
+
+
+	SYS_ERROR("系统错误", "Please refresh and try again"),
+
+	PARAMS_ERROR("参数错误", "Parameter error"),
+	;
+
+	private String zh_CN_value;
+
+	private String en_US_value;
+
+	public I18nValueEnum(String zh_CN_value, String en_US_value) {
+		this.zh_CN_value = zh_CN_value;
+		this.en_US_value = en_US_value;
+	}
+
+	public static String getI18nValue(I18nValueEnum i18nValueEnum) {
+		Locale locale = Locale.getDefault();
+		UserPageLanguage.Language language = UserPageLanguage.Language.valueOf(locale.getLanguage());
+		if (language == UserPageLanguage.Language.en_US) {
+			return i18nValueEnum.getEn_US_value();
+		}
+		return i18nValueEnum.getZh_CN_value();
+	}
+}

+ 16 - 0
netflix-service/src/main/java/com/cyksj/service/i18n/DynamicValueService.java

@@ -0,0 +1,16 @@
+package com.cyksj.service.i18n;
+
+/*
+ *项目名: netflix
+ *文件名: DynamicValueService
+ *创建者: JavaZou
+ *创建时间:2022/12/12 12:11
+ */
+public interface DynamicValueService{
+	/**
+	 * 获取管理端配置的动态国际化语言
+	 * @param key 后台国际化动态语言key
+	 * @return
+	 */
+	String getDynamicValueByKey(String key);
+}

+ 42 - 0
netflix-service/src/main/java/com/cyksj/service/i18n/impl/DynamicValueServiceImpl.java

@@ -0,0 +1,42 @@
+package com.cyksj.service.i18n.impl;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.common.I18nMessageUtil;
+import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.mapper.I18nDynamicValueMapper;
+import com.cyksj.model.entity.I18nDynamicValue;
+import com.cyksj.model.entity.UserPageLanguage;
+import com.cyksj.service.i18n.DynamicValueService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.Locale;
+
+/*
+ *项目名: netflix
+ *文件名: DynamicValueServiceImpl
+ *创建者: JavaZou
+ *创建时间:2022/12/12 12:11
+ */
+@Service
+@RequiredArgsConstructor
+@Slf4j
+public class DynamicValueServiceImpl implements DynamicValueService {
+	private final I18nDynamicValueMapper i18nDynamicValueMapper;
+
+	@Override
+	public String getDynamicValueByKey(String key) {
+		I18nDynamicValue value = i18nDynamicValueMapper.selectOne(Wrappers.lambdaQuery(I18nDynamicValue.class)
+				.eq(I18nDynamicValue::getKey, key).last("limit 1").select(I18nDynamicValue::getZhValue, I18nDynamicValue::getEnValue));
+		if (value == null) {
+			throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg(I18nMessageUtil.DEFAULT_KEY));
+		}
+		Locale locale = Locale.getDefault();
+		UserPageLanguage.Language language = UserPageLanguage.Language.valueOf(locale.getLanguage());
+		if (language == UserPageLanguage.Language.en_US) {
+			return value.getEnValue();
+		}
+		return value.getZhValue();
+	}
+}

+ 5 - 4
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.cyksj.common.AliPayCommon;
 import com.cyksj.common.EnvCommonService;
+import com.cyksj.common.I18nMessageUtil;
 import com.cyksj.common.constant.TemplateEnum;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.snowflake.Sequence;
@@ -160,7 +161,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		GoodsDon goodsDon = goodsDonMapper.selectById(sku.getGoodsId());
 		Boolean isNew = false;
 		if (goodsDon == null || !goodsDon.getStatus()) {
-			throw new BusinessRuntimeException("商品已下架");
+			throw new BusinessRuntimeException(I18nValue);
 		}
 		String payOpenId = user.getOpenId();
 
@@ -172,7 +173,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 			if (payRequest.getRelationId() != null && payRequest.getRelationId() > 0) {
 				relation = groupsRelationMapper.selectById(payRequest.getRelationId());
 				if (relation == null) {
-					throw new BusinessRuntimeException(GROUP_INDEX_NOT_FIND.getCode(), GROUP_INDEX_NOT_FIND.getMsg());
+					throw new BusinessRuntimeException(GROUP_INDEX_NOT_FIND.getCode(), I18nMessageUtil.getI18nMsg("parking_space_not_exist"));
 				}
 				if (relation.getUserId() != null && relation.getUserId() > 0L) {
 					throw new BusinessRuntimeException(GROUP_INDEX_ALREADY_BE_USER.getCode(), GROUP_INDEX_ALREADY_BE_USER.getMsg());
@@ -236,7 +237,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		orderDon.setOrderNo(donNo);
 		orderDon.setOpenId(payOpenId);
 		if (sku.getPrice() != null && payRequest.getDonMoney().compareTo(sku.getPrice()) < 0) {
-			throw BusinessRuntimeException.getInstance("车位所付金额错误");
+			throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("sys_error"));
 		}
 		orderDon.setMoney(payRequest.getDonMoney());
 		orderDon.setRealMoney(payRequest.getDonMoney());
@@ -278,7 +279,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		if (relationId != 0) {
 			Long gtSkuId = groupsRelationMapper.getGroupTripsSkuIdByRelationId(relationId);
 			if (!gtSkuId.equals(orderDon.getSkuId())) {
-				throw BusinessRuntimeException.getInstance("车位与车队规格不一致");
+				throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("sys_error"));
 			}
 		}
 		this.saveOrUpdate(orderDon);

+ 56 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/language/DynamicValueController.java

@@ -0,0 +1,56 @@
+package com.cyksj.web.controller.manage.language;
+
+import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.dto.Result;
+import com.cyksj.enums.GatewayResponse;
+import com.cyksj.mapper.I18nDynamicValueMapper;
+import com.cyksj.model.entity.I18nDynamicValue;
+import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.SearchResult;
+import com.ejlchina.searcher.util.MapUtils;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+
+/*
+ *项目名: netflix
+ *文件名: DynamicValueController
+ *创建者: JavaZou
+ *创建时间:2022/12/12 12:21
+ */
+@RestController
+@RequestMapping("/manage/language/dynamic")
+@RequiredArgsConstructor
+public class DynamicValueController {
+	private final I18nDynamicValueMapper i18nDynamicValueMapper;
+
+	private final BeanSearcher beanSearcher;
+
+	@PostMapping("/post")
+	public Result<String> saveDynamicValue(@RequestBody I18nDynamicValue value) {
+		i18nDynamicValueMapper.insert(value);
+		return GatewayResponse.SUCCESS.newBuilder().toResult("新增成功");
+	}
+
+	@DeleteMapping("/delete/{id}")
+	public Result<String> deleteById(@PathVariable Long id) {
+		i18nDynamicValueMapper.deleteById(id);
+		return GatewayResponse.SUCCESS.newBuilder().toResult("删除成功");
+	}
+
+	@PutMapping("/put")
+	public Result<String> updateDynamicValue(@RequestBody I18nDynamicValue value) {
+		if (value.getId() == null || value.getId() < 1) {
+			throw BusinessRuntimeException.getInstance("id为空");
+		}
+		i18nDynamicValueMapper.updateById(value);
+		return GatewayResponse.SUCCESS.newBuilder().toResult("修改成功");
+	}
+
+	@GetMapping("/get")
+	public Result<SearchResult<I18nDynamicValue>> get(HttpServletRequest request) {
+		SearchResult<I18nDynamicValue> search = beanSearcher.search(I18nDynamicValue.class, MapUtils.flatBuilder(request.getParameterMap()).build());
+		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
+	}
+}

+ 12 - 1
netflix-web/src/main/java/com/cyksj/web/controller/user/UserController.java

@@ -10,6 +10,7 @@ import com.cyksj.model.entity.User;
 import com.cyksj.model.entity.UserPageLanguage;
 import com.cyksj.model.request.ExchangeCodeTicket;
 import com.cyksj.service.exchange.ExchangeCodeService;
+import com.cyksj.service.i18n.DynamicValueService;
 import com.cyksj.service.user.UserService;
 import com.cyksj.web.util.StpUserUtil;
 import lombok.RequiredArgsConstructor;
@@ -33,6 +34,7 @@ public class UserController {
 
     private final UserPageLanguageMapper userPageLanguageMapper;
 
+    private final DynamicValueService dynamicValueService;
 
     @GetMapping(value = "/wx/whoami")
     public Result<UserWhoami> whoami(){
@@ -53,7 +55,7 @@ public class UserController {
     }
 
     /**
-     * 查询页面语言
+     * 查询自身页面语言
      */
     @GetMapping("/get/self/language")
     public Result<UserPageLanguage> getSelfLanguage() {
@@ -63,6 +65,15 @@ public class UserController {
     }
 
 
+    /**
+     * 获取对应key国际化语言 动态后台配置
+     */
+    @GetMapping("/get/dynamic/value")
+    public Result<String> getDynamicValue(String key) {
+        return GatewayResponse.SUCCESS.newBuilder().toResult(dynamicValueService.getDynamicValueByKey(key));
+    }
+
+
     /**
      * 更换页面语言
      */

+ 5 - 1
netflix-web/src/main/resources/i18n/yhlx.properties

@@ -2,4 +2,8 @@ default_msg=国际化信息返回异常
 ex_code_error=兑换码错误
 ex_code_success=兑换成功
 ex_code_used=该兑换码已使用
-login=登录
+login=登录
+params_error=参数错误
+parking_space_is_occupied=该车位已有人
+parking_space_not_exist=该车位不存在
+sys_error=请刷新重试

+ 5 - 1
netflix-web/src/main/resources/i18n/yhlx_en_US.properties

@@ -2,4 +2,8 @@ default_msg=Internationalization information returned exception
 ex_code_error=redemption code is wrong
 ex_code_success=Successful exchange
 ex_code_used=this redemption code has already been used
-login=login
+login=login
+params_error=Parameter error
+parking_space_is_occupied=The parking space is occupied
+parking_space_not_exist=Parking space does not exist
+sys_error=Please refresh and try again

+ 5 - 1
netflix-web/src/main/resources/i18n/yhlx_zh_CN.properties

@@ -2,4 +2,8 @@ default_msg=国际化信息返回异常
 ex_code_error=兑换码错误
 ex_code_success=兑换成功
 ex_code_used=该兑换码已使用
-login=登录
+login=登录
+params_error=参数错误
+parking_space_is_occupied=该车位已有人
+parking_space_not_exist=该车位不存在
+sys_error=请刷新重试