|
@@ -1,5 +1,7 @@
|
|
package com.xy.service.impl;
|
|
package com.xy.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.xy.collections.list.JArrayList;
|
|
import com.xy.collections.list.JArrayList;
|
|
@@ -15,16 +17,20 @@ import com.xy.mapper.SysSystemMapper;
|
|
import com.xy.redis.RedisCache;
|
|
import com.xy.redis.RedisCache;
|
|
import com.xy.service.SysMenuService;
|
|
import com.xy.service.SysMenuService;
|
|
import com.xy.service.SysRoleMenuService;
|
|
import com.xy.service.SysRoleMenuService;
|
|
|
|
+import com.xy.third.baidu.TransApi;
|
|
import com.xy.utils.Emptys;
|
|
import com.xy.utils.Emptys;
|
|
import com.xy.utils.MybatisPlusQuery;
|
|
import com.xy.utils.MybatisPlusQuery;
|
|
import com.xy.utils.R;
|
|
import com.xy.utils.R;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -40,6 +46,7 @@ import static com.xy.utils.Beans.tree;
|
|
* @author lijin
|
|
* @author lijin
|
|
* @since 2022-12-09
|
|
* @since 2022-12-09
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Api(tags = "菜单管理")
|
|
@Api(tags = "菜单管理")
|
|
@Service
|
|
@Service
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
@@ -53,6 +60,35 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|
|
|
|
|
private SysSystemMapper sysSystemMapper;
|
|
private SysSystemMapper sysSystemMapper;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 菜单全量翻译
|
|
|
|
+ */
|
|
|
|
+ @Async
|
|
|
|
+ public void translateAllMenu() {
|
|
|
|
+ List<SysMenu> sysMenus = this.list();
|
|
|
|
+ List<SysMenu> updateMenus = new ArrayList<>();
|
|
|
|
+ for (SysMenu sysMenu : sysMenus) {
|
|
|
|
+ String name = sysMenu.getName();
|
|
|
|
+ String enName = sysMenu.getEnName();
|
|
|
|
+ if (StrUtil.isEmpty(enName)) {
|
|
|
|
+ //百度api翻译
|
|
|
|
+ String translatedValue = TransApi.translate(name, "zh", "en");
|
|
|
|
+ sysMenu.setEnName(translatedValue);
|
|
|
|
+ updateMenus.add(sysMenu);
|
|
|
|
+ // 增加1.2秒的延迟
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(1800);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
|
+ log.error("线程中断异常", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (CollUtil.isNotEmpty(updateMenus)) {
|
|
|
|
+ updateBatchById(updateMenus);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@PostMapping("workMenu")
|
|
@PostMapping("workMenu")
|
|
@ApiOperation("用户菜单树")
|
|
@ApiOperation("用户菜单树")
|
|
public R<List<SysMenuDto.Vo>> workMenu(@RequestBody @Validated SysMenuDto.WorkMenu workMenu) {
|
|
public R<List<SysMenuDto.Vo>> workMenu(@RequestBody @Validated SysMenuDto.WorkMenu workMenu) {
|
|
@@ -70,7 +106,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|
|
|
|
|
@PostMapping("workMenuList")
|
|
@PostMapping("workMenuList")
|
|
@ApiOperation("用户菜单集合")
|
|
@ApiOperation("用户菜单集合")
|
|
- public R<List<SysMenuDto.MenuVo>> workMenuList(@RequestBody @Validated SysMenuDto.WorkMenuList workMenu) {
|
|
|
|
|
|
+ public R<List<SysMenuDto.MenuVo>> workMenuList(@RequestHeader(value = "lang", required = false) String lang, @RequestBody @Validated SysMenuDto.WorkMenuList workMenu) {
|
|
List<SysMenuDto.MenuVo> menuVos = new ArrayList<>();
|
|
List<SysMenuDto.MenuVo> menuVos = new ArrayList<>();
|
|
List<Long> sysIds = workMenu.getSysId();
|
|
List<Long> sysIds = workMenu.getSysId();
|
|
List<SysSystem> sysSystems = sysSystemMapper.selectList(new LambdaQueryWrapper<SysSystem>().in(SysSystem::getId, sysIds));
|
|
List<SysSystem> sysSystems = sysSystemMapper.selectList(new LambdaQueryWrapper<SysSystem>().in(SysSystem::getId, sysIds));
|
|
@@ -81,6 +117,16 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|
? RedisCache.getMenu(sysId, workMenu.getClientType())
|
|
? RedisCache.getMenu(sysId, workMenu.getClientType())
|
|
: RedisCache.getMenu(sysId);
|
|
: RedisCache.getMenu(sysId);
|
|
menus.forEach(sysMenuJoinSysRoleMenu -> list.add(copy(SysMenuDto.Vo.class, sysMenuJoinSysRoleMenu)));
|
|
menus.forEach(sysMenuJoinSysRoleMenu -> list.add(copy(SysMenuDto.Vo.class, sysMenuJoinSysRoleMenu)));
|
|
|
|
+ if ("en".equals(lang)) {
|
|
|
|
+ //英文菜单
|
|
|
|
+ list.forEach(sm -> {
|
|
|
|
+ String enName = sm.getEnName();
|
|
|
|
+ if (StrUtil.isNotEmpty(enName)) {
|
|
|
|
+ sm.setName(enName);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ }
|
|
SysSystem sysSystem = sysSystemJMap.get(sysId);
|
|
SysSystem sysSystem = sysSystemJMap.get(sysId);
|
|
if (sysSystem == null) {
|
|
if (sysSystem == null) {
|
|
continue;
|
|
continue;
|
|
@@ -91,6 +137,10 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|
.setName(sysSystem.getName())
|
|
.setName(sysSystem.getName())
|
|
.setIcon(sysSystem.getIcon())
|
|
.setIcon(sysSystem.getIcon())
|
|
.setMenu(list);
|
|
.setMenu(list);
|
|
|
|
+ if ("en".equals(lang) && "xy_merc_mini".equals(sysSystem.getCode())) {
|
|
|
|
+ //商管端
|
|
|
|
+ menuVo.setName("Business Management Platform");
|
|
|
|
+ }
|
|
menuVos.add(menuVo);
|
|
menuVos.add(menuVo);
|
|
}
|
|
}
|
|
return R.ok(menuVos);
|
|
return R.ok(menuVos);
|