diff --git a/cereshop-admin/src/main/java/com/shop/cereshop/admin/page/permission/MenuButton.java b/cereshop-admin/src/main/java/com/shop/cereshop/admin/page/permission/MenuButton.java index 0a2cbc3..76b0772 100644 --- a/cereshop-admin/src/main/java/com/shop/cereshop/admin/page/permission/MenuButton.java +++ b/cereshop-admin/src/main/java/com/shop/cereshop/admin/page/permission/MenuButton.java @@ -13,6 +13,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -88,15 +89,24 @@ public class MenuButton { */ @ApiModelProperty(value = "名称Map") @TableField(exist = false) - private Map permissionNameMap; + private Map permissionNameMap; public void initData(){ - Map permissionNameMap = null; - if(StringUtils.isNotEmpty(getPermissionNameJson())){ - permissionNameMap = new Gson().fromJson(getPermissionNameJson(), Map.class); + if(permissionNameMap == null){ + permissionNameMap = new HashMap<>(); } - if(CollectionUtils.isEmpty(permissionNameMap)){ - permissionNameMap.put("zh-CN", getPermissionName()); + if (CollectionUtils.isEmpty(permissionNameMap)) { + if(StringUtils.isNotEmpty(permissionNameJson)){ + permissionNameMap = new Gson().fromJson(permissionNameJson, Map.class); + } + if(CollectionUtils.isEmpty(permissionNameMap)){ + permissionNameMap.put("zh", permissionName); + } + } + if(permissionNameMap.containsKey("zh")){ + permissionName = permissionNameMap.get("zh"); + }else if(permissionNameMap.containsKey("en")){ + permissionName = permissionNameMap.get("en"); } } diff --git a/cereshop-admin/src/main/java/com/shop/cereshop/admin/page/permission/Permission.java b/cereshop-admin/src/main/java/com/shop/cereshop/admin/page/permission/Permission.java index 69826ef..ce90f59 100644 --- a/cereshop-admin/src/main/java/com/shop/cereshop/admin/page/permission/Permission.java +++ b/cereshop-admin/src/main/java/com/shop/cereshop/admin/page/permission/Permission.java @@ -5,15 +5,23 @@ */ package com.shop.cereshop.admin.page.permission; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.google.common.reflect.TypeToken; import com.google.gson.Gson; +import com.shop.cereshop.commons.domain.permission.PermissionNameAttr; import com.shop.cereshop.commons.utils.StringUtils; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; /** * 权限返回数据实体类 @@ -98,15 +106,26 @@ public class Permission { * 名称Map */ @ApiModelProperty(value = "名称Map") - private Map permissionNameMap; + @TableField(exist = false) + private Map permissionNameMap; public void initData(){ - Map permissionNameMap = null; - if(StringUtils.isNotEmpty(getPermissionNameJson())){ - permissionNameMap = new Gson().fromJson(getPermissionNameJson(), Map.class); + if(permissionNameMap == null){ + permissionNameMap = new HashMap<>(); } - if(CollectionUtils.isEmpty(permissionNameMap)){ - permissionNameMap.put("zh-CN", getPermissionName()); + if (CollectionUtils.isEmpty(permissionNameMap)) { + if(StringUtils.isNotEmpty(permissionNameJson)){ + permissionNameMap = new Gson().fromJson(permissionNameJson, Map.class); + } + if(CollectionUtils.isEmpty(permissionNameMap)){ + permissionNameMap.put("zh", permissionName); + } + } + if(permissionNameMap.containsKey("zh")){ + permissionName = permissionNameMap.get("zh"); + }else if(permissionNameMap.containsKey("en")){ + permissionName = permissionNameMap.get("en"); } } + } diff --git a/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/permission/impl/CereBusinessPermissionServiceImpl.java b/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/permission/impl/CereBusinessPermissionServiceImpl.java index 5e77ac4..e5667f0 100644 --- a/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/permission/impl/CereBusinessPermissionServiceImpl.java +++ b/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/permission/impl/CereBusinessPermissionServiceImpl.java @@ -8,6 +8,7 @@ package com.shop.cereshop.admin.service.permission.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.google.gson.Gson; import com.shop.cereshop.admin.dao.business.CereBusinessUserDAO; import com.shop.cereshop.admin.dao.business.CerePlatformBusinessUserDAO; import com.shop.cereshop.admin.dao.permission.CereBusinessPermissionDAO; @@ -86,6 +87,8 @@ public class CereBusinessPermissionServiceImpl implements CereBusinessPermission permission.setIcon(param.getIcon()); permission.setResourceType(param.getResourceType()); permission.setSort(param.getSort()); + permission.initData(); + permission.setPermissionNameJson(new Gson().toJson(param.getPermissionNameMap())); if (EmptyUtils.isEmpty(permission.getPermissionPid())) { //如果没有父节点id,新增根节点 permission.setPermissionPid(LongEnum.getByName("根节点")); @@ -113,6 +116,8 @@ public class CereBusinessPermissionServiceImpl implements CereBusinessPermission permission.setSort(param.getSort()); permission.setPermissionId(param.getPermissionId()); permission.setUpdateTime(time); + permission.initData(); + permission.setPermissionNameJson(new Gson().toJson(param.getPermissionNameMap())); cereBusinessPermissionDAO.updateByPrimaryKeySelective(permission); //新增日志 cerePlatformLogService.addLog(user, "权限管理", "平台端操作", "修改权限", String.valueOf(permission.getPermissionId()), time); @@ -129,7 +134,9 @@ public class CereBusinessPermissionServiceImpl implements CereBusinessPermission @Override public CerePlatformPermission getById(Long permissionId) throws CoBusinessException { - return cereBusinessPermissionDAO.getById(permissionId); + CerePlatformPermission cerePlatformPermission = cereBusinessPermissionDAO.getById(permissionId); + cerePlatformPermission.initData(); + return cerePlatformPermission; } @Override @@ -142,6 +149,10 @@ public class CereBusinessPermissionServiceImpl implements CereBusinessPermission if (!EmptyUtils.isEmpty(list)) { Map map = new HashMap<>(); list.forEach((permission -> { + permission.initData(); + for (Permission child : childs) { + child.initData(); + } setMenuChildsIndex(permission, childs, map, null); })); } @@ -160,6 +171,10 @@ public class CereBusinessPermissionServiceImpl implements CereBusinessPermission if (!EmptyUtils.isEmpty(list)) { Map map = new HashMap<>(); list.forEach((permission -> { + permission.initData(); + for (Permission child : childs) { + child.initData(); + } setMenuChildsIndex(permission, childs, map, null); })); } @@ -180,6 +195,13 @@ public class CereBusinessPermissionServiceImpl implements CereBusinessPermission if (!EmptyUtils.isEmpty(list)) { Map map = new HashMap<>(); list.forEach((permission -> { + permission.initData(); + for (MenuButton child : childs) { + child.initData(); + } + for (MenuButton button : buttons) { + button.initData(); + } Meta meta = new Meta(); meta.setTitle(permission.getPermissionName()); meta.setIcon(permission.getIcon()); @@ -201,6 +223,13 @@ public class CereBusinessPermissionServiceImpl implements CereBusinessPermission if (!EmptyUtils.isEmpty(list)) { Map map = new HashMap<>(); list.forEach((permission -> { + permission.initData(); + for (MenuButton child : childs) { + child.initData(); + } + for (MenuButton button : buttons) { + button.initData(); + } Meta meta = new Meta(); meta.setTitle(permission.getPermissionName()); meta.setIcon(permission.getIcon()); diff --git a/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/permission/impl/CerePlatformPermissionServiceImpl.java b/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/permission/impl/CerePlatformPermissionServiceImpl.java index edb713b..acc8141 100644 --- a/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/permission/impl/CerePlatformPermissionServiceImpl.java +++ b/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/permission/impl/CerePlatformPermissionServiceImpl.java @@ -67,13 +67,8 @@ public class CerePlatformPermissionServiceImpl implements CerePlatformPermission permission.setIcon(param.getIcon()); permission.setResourceType(param.getResourceType()); permission.setSort(param.getSort()); - Map permissionNameMap = param.getPermissionNameMap(); - if(permissionNameMap == null || permissionNameMap.isEmpty()){ - permissionNameMap.put("zh-CN", param.getPermissionName()); - } - if(permissionNameMap != null && !permissionNameMap.isEmpty()){ - permission.setPermissionNameJson(new Gson().toJson(permissionNameMap)); - } + permission.initData(); + permission.setPermissionNameJson(new Gson().toJson(param.getPermissionNameMap())); if(EmptyUtils.isEmpty(permission.getPermissionPid())){ //如果没有父节点id,新增根节点 permission.setPermissionPid(LongEnum.getByName("根节点")); @@ -101,13 +96,8 @@ public class CerePlatformPermissionServiceImpl implements CerePlatformPermission permission.setSort(param.getSort()); permission.setPermissionId(param.getPermissionId()); permission.setUpdateTime(time); - Map permissionNameMap = param.getPermissionNameMap(); - if(permissionNameMap == null || permissionNameMap.isEmpty()){ - permissionNameMap.put("zh-CN", param.getPermissionName()); - } - if(permissionNameMap != null && !permissionNameMap.isEmpty()){ - permission.setPermissionNameJson(new Gson().toJson(permissionNameMap)); - } + permission.initData(); + permission.setPermissionNameJson(new Gson().toJson(param.getPermissionNameMap())); cerePlatformPermissionDAO.updateByPrimaryKeySelective(permission); //新增日志 cerePlatformLogService.addLog(user,"权限管理","平台端操作","修改权限",String.valueOf(permission.getPermissionId()),time); diff --git a/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/product/impl/CereProductClassifyServiceImpl.java b/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/product/impl/CereProductClassifyServiceImpl.java index a7c4ffb..2f2445e 100644 --- a/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/product/impl/CereProductClassifyServiceImpl.java +++ b/cereshop-admin/src/main/java/com/shop/cereshop/admin/service/product/impl/CereProductClassifyServiceImpl.java @@ -8,6 +8,7 @@ package com.shop.cereshop.admin.service.product.impl; import com.alibaba.fastjson.JSON; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.google.gson.Gson; import com.shop.cereshop.admin.dao.product.CereProductClassifyDAO; import com.shop.cereshop.admin.param.product.ClassifyDeleteParam; import com.shop.cereshop.admin.param.product.ClassifyGetAllParam; @@ -80,6 +81,10 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic cereProductClassify.setLink(classify.getLink()); cereProductClassify.setProject(ProjectUtil.DEFAULT_PROJECT); cereProductClassify.setClassifyHierarchy("-"+classify.getClassifyName()); + cereProductClassify.setClassifyNameJson(classify.getClassifyNameJson()); + cereProductClassify.setClassifyNameMap(classify.getClassifyNameMap()); + cereProductClassify.initData(); + cereProductClassify.setClassifyNameJson(new Gson().toJson(cereProductClassify.getClassifyNameMap())); if(!EmptyUtils.isLongEmpty(classify.getClassifyId())){ //更新一级类别 cereProductClassify.setUpdateTime(time); @@ -115,6 +120,10 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic productClassify.setClassifyImage(child.getClassifyImage()); productClassify.setProject(ProjectUtil.DEFAULT_PROJECT); productClassify.setClassifyHierarchy(parent.getClassifyHierarchy()+"-"+child.getClassifyName()); + productClassify.setClassifyNameJson(child.getClassifyNameJson()); + productClassify.setClassifyNameMap(child.getClassifyNameMap()); + productClassify.initData(); + productClassify.setClassifyNameJson(new Gson().toJson(productClassify.getClassifyNameMap())); if(!EmptyUtils.isLongEmpty(child.getClassifyId())){ //更新子级类别 productClassify.setUpdateTime(time); @@ -143,10 +152,10 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic List updates=new ArrayList<>(); if(!EmptyUtils.isEmpty(param.getClassifies())){ + System.out.println(JSON.toJSON(param.getClassifies())); for (CereProductClassify classify:param.getClassifies()) { addOneClassify(classify,time,updates); } - System.out.println("11111"); System.out.println(JSON.toJSON(param.getClassifies())); if(!EmptyUtils.isEmpty(updates)){ //批量更新分类层级结构 @@ -171,7 +180,11 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic if(!EmptyUtils.isEmpty(classifies)){ //查询所有三级分类 classifies.forEach(a -> { - a.setChilds( cereProductClassifyDAO.findByPid(a.getClassifyId())); + a.setChilds(cereProductClassifyDAO.findByPid(a.getClassifyId())); + }); + classifies.forEach(a -> { + a.initData(); + a.getChilds().forEach(CereProductClassify::initData); }); classify.setChilds(classifies); } @@ -183,6 +196,12 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic public Page getAll(ClassifyGetAllParam param) throws CoBusinessException { PageHelper.startPage(param.getPage(),param.getPageSize()); List list=cereProductClassifyDAO.getAll(); + list.forEach(a -> { + a.initData(); + if(a.getChilds() != null) { + a.getChilds().forEach(CereProductClassify::initData); + } + }); PageInfo pageInfo=new PageInfo<>(list); Page page=new Page(pageInfo.getList(),pageInfo.getTotal()); return page; @@ -247,6 +266,10 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic setChildsIndex(classify,childs,map); })); } + list.forEach(a -> { + a.initData(); + a.getChilds().forEach(Classify::initData); + }); return list; } diff --git a/cereshop-admin/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml b/cereshop-admin/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml index 5ce71f3..688ac46 100644 --- a/cereshop-admin/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml +++ b/cereshop-admin/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml @@ -173,7 +173,9 @@ select @@ -47,6 +48,9 @@ classify_name, + + classify_name_json, + classify_image, @@ -82,6 +86,9 @@ #{classifyName,jdbcType=VARCHAR}, + + #{classifyNameJson,jdbcType=VARCHAR}, + #{classifyImage,jdbcType=VARCHAR}, @@ -120,6 +127,9 @@ classify_name = #{classifyName,jdbcType=VARCHAR}, + + classify_name_json = #{classifyNameJson,jdbcType=VARCHAR}, + classify_image = #{classifyImage,jdbcType=VARCHAR}, @@ -148,6 +158,7 @@ classify_level = #{classifyLevel,jdbcType=TINYINT}, classify_level_hierarchy = #{classifyLevelHierarchy,jdbcType=VARCHAR}, classify_name = #{classifyName,jdbcType=VARCHAR}, + classify_name_json = #{classifyNameJson,jdbcType=VARCHAR}, classify_image = #{classifyImage,jdbcType=VARCHAR}, sort = #{sort,jdbcType=INTEGER}, link = #{link,jdbcType=BIGINT}, @@ -158,12 +169,12 @@ @@ -198,12 +209,12 @@ diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/interceptor/AuthorizationInterceptor.java b/cereshop-business/src/main/java/com/shop/cereshop/business/interceptor/AuthorizationInterceptor.java index 3761ba5..4613c76 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/interceptor/AuthorizationInterceptor.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/interceptor/AuthorizationInterceptor.java @@ -136,6 +136,12 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter { String project = request.getHeader("project"); ContextUtil.setProject(project); + + String language = request.getHeader("language"); + if(StringUtils.isEmpty(language)){ + language = "zh"; + } + ContextUtil.setLanguage(language); return true; } diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/page/permission/MenuButton.java b/cereshop-business/src/main/java/com/shop/cereshop/business/page/permission/MenuButton.java index c776612..1103029 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/page/permission/MenuButton.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/page/permission/MenuButton.java @@ -5,11 +5,17 @@ */ package com.shop.cereshop.business.page.permission; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.google.gson.Gson; +import com.shop.cereshop.commons.utils.StringUtils; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 权限数据 @@ -71,4 +77,36 @@ public class MenuButton { */ @ApiModelProperty(value = "按钮数据") private List buttons; + + /** + * 名称Json + */ + @ApiModelProperty(value = "名称Json") + private String permissionNameJson; + + /** + * 名称Map + */ + @ApiModelProperty(value = "名称Map") + @TableField(exist = false) + private Map permissionNameMap; + + public void initData(){ + if(permissionNameMap == null){ + permissionNameMap = new HashMap<>(); + } + if (CollectionUtils.isEmpty(permissionNameMap)) { + if(StringUtils.isNotEmpty(permissionNameJson)){ + permissionNameMap = new Gson().fromJson(permissionNameJson, Map.class); + } + if(CollectionUtils.isEmpty(permissionNameMap)){ + permissionNameMap.put("zh", permissionName); + } + } + if(permissionNameMap.containsKey("zh")){ + permissionName = permissionNameMap.get("zh"); + }else if(permissionNameMap.containsKey("en")){ + permissionName = permissionNameMap.get("en"); + } + } } diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/page/permission/Permission.java b/cereshop-business/src/main/java/com/shop/cereshop/business/page/permission/Permission.java index 93bd1a4..07ae016 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/page/permission/Permission.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/page/permission/Permission.java @@ -5,11 +5,17 @@ */ package com.shop.cereshop.business.page.permission; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.google.gson.Gson; +import com.shop.cereshop.commons.utils.StringUtils; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 权限返回数据实体类 @@ -89,4 +95,36 @@ public class Permission { */ @ApiModelProperty(value = "按钮权限数据") private List buttonPermissions; + + /** + * 名称Json + */ + @ApiModelProperty(value = "名称Json") + private String permissionNameJson; + + /** + * 名称Map + */ + @ApiModelProperty(value = "名称Map") + @TableField(exist = false) + private Map permissionNameMap; + + public void initData(){ + if(permissionNameMap == null){ + permissionNameMap = new HashMap<>(); + } + if (CollectionUtils.isEmpty(permissionNameMap)) { + if(StringUtils.isNotEmpty(permissionNameJson)){ + permissionNameMap = new Gson().fromJson(permissionNameJson, Map.class); + } + if(CollectionUtils.isEmpty(permissionNameMap)){ + permissionNameMap.put("zh", permissionName); + } + } + if(permissionNameMap.containsKey("zh")){ + permissionName = permissionNameMap.get("zh"); + }else if(permissionNameMap.containsKey("en")){ + permissionName = permissionNameMap.get("en"); + } + } } diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/param/permission/PermissionSaveParam.java b/cereshop-business/src/main/java/com/shop/cereshop/business/param/permission/PermissionSaveParam.java index e758495..74245cb 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/param/permission/PermissionSaveParam.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/param/permission/PermissionSaveParam.java @@ -10,6 +10,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotBlank; +import java.util.Map; /** * 添加权限请求 @@ -79,4 +80,10 @@ public class PermissionSaveParam { */ @ApiModelProperty(value = "权限所属项目") private Integer project; + + /** + * 名称Map + */ + @ApiModelProperty(value = "名称Map") + private Map permissionNameMap; } diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/param/permission/PermissionUpdateParam.java b/cereshop-business/src/main/java/com/shop/cereshop/business/param/permission/PermissionUpdateParam.java index 2f89609..8e8d97c 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/param/permission/PermissionUpdateParam.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/param/permission/PermissionUpdateParam.java @@ -9,6 +9,8 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.Map; + /** * 更新权限请求 */ @@ -75,4 +77,10 @@ public class PermissionUpdateParam { */ @ApiModelProperty(value = "权限所属项目") private Integer project; + + /** + * 名称Map + */ + @ApiModelProperty(value = "名称Map") + private Map permissionNameMap; } diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/service/permission/impl/CerePlatformPermissionServiceImpl.java b/cereshop-business/src/main/java/com/shop/cereshop/business/service/permission/impl/CerePlatformPermissionServiceImpl.java index 814ceae..9598661 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/service/permission/impl/CerePlatformPermissionServiceImpl.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/service/permission/impl/CerePlatformPermissionServiceImpl.java @@ -7,6 +7,7 @@ package com.shop.cereshop.business.service.permission.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.google.gson.Gson; import com.shop.cereshop.business.dao.permission.CerePlatformPermissionDAO; import com.shop.cereshop.business.page.permission.MenuButton; import com.shop.cereshop.business.page.permission.Meta; @@ -63,6 +64,8 @@ public class CerePlatformPermissionServiceImpl implements CerePlatformPermission permission.setIcon(param.getIcon()); permission.setResourceType(param.getResourceType()); permission.setSort(param.getSort()); + permission.initData(); + permission.setPermissionNameJson(new Gson().toJson(param.getPermissionNameMap())); if(EmptyUtils.isEmpty(permission.getPermissionPid())){ //如果没有父节点id,新增根节点 permission.setPermissionPid(LongEnum.getByName("根节点")); @@ -88,6 +91,8 @@ public class CerePlatformPermissionServiceImpl implements CerePlatformPermission permission.setIcon(param.getIcon()); permission.setResourceType(param.getResourceType()); permission.setSort(param.getSort()); + permission.initData(); + permission.setPermissionNameJson(new Gson().toJson(param.getPermissionNameMap())); permission.setPermissionId(param.getPermissionId()); permission.setUpdateTime(time); cerePlatformPermissionDAO.updateByPrimaryKeySelective(permission); @@ -122,6 +127,10 @@ public class CerePlatformPermissionServiceImpl implements CerePlatformPermission if(!EmptyUtils.isEmpty(list)){ Map map=new HashMap<>(); list.forEach((permission -> { + permission.initData(); + for (Permission child : childs) { + child.initData(); + } setMenuChildsIndex(permission,childs,map,null); })); } @@ -140,6 +149,10 @@ public class CerePlatformPermissionServiceImpl implements CerePlatformPermission if(!EmptyUtils.isEmpty(list)){ Map map=new HashMap<>(); list.forEach((permission -> { + permission.initData(); + for (Permission child : childs) { + child.initData(); + } setMenuChildsIndex(permission,childs,map,null); })); } @@ -166,6 +179,13 @@ public class CerePlatformPermissionServiceImpl implements CerePlatformPermission if(!EmptyUtils.isEmpty(list)){ Map map=new HashMap<>(); list.forEach((permission -> { + permission.initData(); + for (MenuButton child : childs) { + child.initData(); + } + for (MenuButton button : buttons) { + button.initData(); + } Meta meta=new Meta(); meta.setTitle(permission.getPermissionName()); meta.setIcon(permission.getIcon()); @@ -181,7 +201,9 @@ public class CerePlatformPermissionServiceImpl implements CerePlatformPermission @Override public CerePlatformPermission findBySort(Integer sort, Long id,Long businessId) { - return cerePlatformPermissionDAO.findBySort(sort,id,businessId); + CerePlatformPermission cerePlatformPermission = cerePlatformPermissionDAO.findBySort(sort,id,businessId); + cerePlatformPermission.initData(); + return cerePlatformPermission; } @Override diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/service/product/impl/CereProductClassifyServiceImpl.java b/cereshop-business/src/main/java/com/shop/cereshop/business/service/product/impl/CereProductClassifyServiceImpl.java index ce11561..41595fb 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/service/product/impl/CereProductClassifyServiceImpl.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/service/product/impl/CereProductClassifyServiceImpl.java @@ -7,6 +7,7 @@ package com.shop.cereshop.business.service.product.impl; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.google.gson.Gson; import com.shop.cereshop.business.dao.product.CereProductClassifyDAO; import com.shop.cereshop.business.param.product.ClassifyDeleteParam; import com.shop.cereshop.business.param.product.ClassifyGetAllParam; @@ -48,12 +49,18 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic @Override public List getClassifySelect(ProductGetClassifyParam param) throws CoBusinessException { - return cereProductClassifyDAO.getClassifySelect(ContextUtil.getProject(), param.getClassifyPid()); + List classifyList = cereProductClassifyDAO.getClassifySelect(ContextUtil.getProject(), param.getClassifyPid()); + for (CereProductClassify classify : classifyList) { + classify.initData(ContextUtil.getLanguage()); + } + return classifyList; } @Override public CereProductClassify findByHierarchy(String hierarchy) throws CoBusinessException { - return cereProductClassifyDAO.findByHierarchy(ContextUtil.getProject(), hierarchy); + CereProductClassify classify = cereProductClassifyDAO.findByHierarchy(ContextUtil.getProject(), hierarchy); +// classify.initData(); + return classify; } @Override @@ -65,6 +72,10 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic if(!EmptyUtils.isEmpty(list)){ Map map=new HashMap<>(); list.forEach((classify -> { + classify.initData(ContextUtil.getLanguage()); + for (Classify child : childs) { + child.initData(ContextUtil.getLanguage()); + } setChildsIndex(classify,childs,map); })); } @@ -73,7 +84,11 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic @Override public List selectAll() throws CoBusinessException { - return cereProductClassifyDAO.selectAll(ContextUtil.getProject()); + List classifyList = cereProductClassifyDAO.selectAll(ContextUtil.getProject()); + for (CereProductClassify classify : classifyList) { + classify.initData(ContextUtil.getLanguage()); + } + return classifyList; } private Classify setChildsIndex(Classify parent, List all, Map map) throws ArrayIndexOutOfBoundsException{ @@ -151,6 +166,10 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic cereProductClassify.setLink(classify.getLink()); cereProductClassify.setProject(ContextUtil.getProject()); cereProductClassify.setClassifyHierarchy("-"+classify.getClassifyName()); + cereProductClassify.setClassifyNameJson(classify.getClassifyNameJson()); + cereProductClassify.setClassifyNameMap(classify.getClassifyNameMap()); + cereProductClassify.initData(); + cereProductClassify.setClassifyNameJson(new Gson().toJson(cereProductClassify.getClassifyNameMap())); if(!EmptyUtils.isLongEmpty(classify.getClassifyId())){ //更新一级类别 cereProductClassify.setUpdateTime(time); @@ -186,6 +205,10 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic productClassify.setClassifyImage(child.getClassifyImage()); productClassify.setProject(ContextUtil.getProject()); productClassify.setClassifyHierarchy(parent.getClassifyHierarchy()+"-"+child.getClassifyName()); + productClassify.setClassifyNameJson(child.getClassifyNameJson()); + productClassify.setClassifyNameMap(child.getClassifyNameMap()); + productClassify.initData(); + productClassify.setClassifyNameJson(new Gson().toJson(productClassify.getClassifyNameMap())); if(!EmptyUtils.isLongEmpty(child.getClassifyId())){ //更新子级类别 productClassify.setUpdateTime(time); @@ -234,12 +257,19 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic //查询一级类别数据 CereProductClassify classify=cereProductClassifyDAO.selectByPrimaryKey(classifyId); if(classify!=null){ + classify.initData(); //查询所有二级分类 List classifies=cereProductClassifyDAO.findByPid(classify.getClassifyId()); if(!EmptyUtils.isEmpty(classifies)){ //查询所有三级分类 classifies.forEach(a -> { a.setChilds( cereProductClassifyDAO.findByPid(a.getClassifyId())); + a.initData(); + if(a.getChilds() != null){ + for (CereProductClassify child : a.getChilds()) { + child.initData(); + } + } }); classify.setChilds(classifies); } @@ -251,6 +281,9 @@ public class CereProductClassifyServiceImpl implements CereProductClassifyServic public Page getAll(ClassifyGetAllParam param) throws CoBusinessException { PageHelper.startPage(param.getPage(),param.getPageSize()); List list=cereProductClassifyDAO.getAll(ContextUtil.getProject()); + for (CereProductClassify classify : list) { + classify.initData(ContextUtil.getLanguage()); + } PageInfo pageInfo=new PageInfo<>(list); Page page=new Page(pageInfo.getList(),pageInfo.getTotal()); return page; diff --git a/cereshop-business/src/main/java/com/shop/cereshop/business/utils/ContextUtil.java b/cereshop-business/src/main/java/com/shop/cereshop/business/utils/ContextUtil.java index c3f8495..a0185dd 100644 --- a/cereshop-business/src/main/java/com/shop/cereshop/business/utils/ContextUtil.java +++ b/cereshop-business/src/main/java/com/shop/cereshop/business/utils/ContextUtil.java @@ -55,4 +55,24 @@ public class ContextUtil { return project; } } + + + static ThreadLocal languageTL = new ThreadLocal<>(); + + public static void setLanguage(String language){ + languageTL.set(language); + } + + public static void clearLanguage(){ + languageTL.set(null); + } + + public static String getLanguage(){ + String language = languageTL.get(); + if(StringUtils.isEmpty(language)) { + return "zh"; + }else { + return language; + } + } } diff --git a/cereshop-business/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml b/cereshop-business/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml index 7f97e90..5d32040 100644 --- a/cereshop-business/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml +++ b/cereshop-business/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml @@ -5,6 +5,7 @@ + @@ -16,7 +17,7 @@ - permission_id, permission_pid, permission_name, permission_uri, permission, icon, + permission_id, permission_pid, permission_name, permission_name_json, permission_uri, permission, icon, `describe`, resource_type, sort, project, create_time, update_time - SELECT permission_id,permission_pid,permission_name,permission_uri,permission,icon,`describe`,resource_type,sort FROM cere_platform_permission where permission_id=#{permissionId} + SELECT permission_id,permission_pid,permission_name, permission_name_json, permission_uri,permission,icon,`describe`,resource_type,sort FROM cere_platform_permission where permission_id=#{permissionId} select @@ -47,6 +48,9 @@ classify_name, + + classify_name_json, + classify_image, @@ -82,6 +86,9 @@ #{classifyName,jdbcType=VARCHAR}, + + #{classifyNameJson,jdbcType=VARCHAR}, + #{classifyImage,jdbcType=VARCHAR}, @@ -120,6 +127,9 @@ classify_name = #{classifyName,jdbcType=VARCHAR}, + + classify_name_json = #{classifyNameJson,jdbcType=VARCHAR}, + classify_image = #{classifyImage,jdbcType=VARCHAR}, @@ -148,6 +158,7 @@ classify_level = #{classifyLevel,jdbcType=TINYINT}, classify_level_hierarchy = #{classifyLevelHierarchy,jdbcType=VARCHAR}, classify_name = #{classifyName,jdbcType=VARCHAR}, + classify_name_json = #{classifyNameJson,jdbcType=VARCHAR}, classify_image = #{classifyImage,jdbcType=VARCHAR}, sort = #{sort,jdbcType=INTEGER}, link = #{link,jdbcType=BIGINT}, @@ -158,7 +169,7 @@ @@ -220,7 +231,7 @@ diff --git a/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/permission/CerePlatformPermission.java b/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/permission/CerePlatformPermission.java index cac04a1..507ceb4 100644 --- a/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/permission/CerePlatformPermission.java +++ b/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/permission/CerePlatformPermission.java @@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import com.shop.cereshop.commons.utils.StringUtils; import io.swagger.annotations.ApiModel; @@ -16,7 +17,13 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; /** * cere_platform_permission 权限实体类 @@ -106,23 +113,36 @@ public class CerePlatformPermission implements Serializable { @ApiModelProperty(value = "名称Json") private String permissionNameJson; + + private static final long serialVersionUID = 1L; + /** * 名称Map */ @ApiModelProperty(value = "名称Map") @TableField(exist = false) - private Map permissionNameMap; - - private static final long serialVersionUID = 1L; + private Map permissionNameMap; public void initData(){ - Map permissionNameMap = null; - if(StringUtils.isNotEmpty(getPermissionNameJson())){ - permissionNameMap = new Gson().fromJson(getPermissionNameJson(), Map.class); + if(permissionNameMap == null){ + permissionNameMap = new HashMap<>(); } - if(CollectionUtils.isEmpty(permissionNameMap)){ - permissionNameMap.put("zh-CN", getPermissionName()); + if (CollectionUtils.isEmpty(permissionNameMap)) { + if(StringUtils.isNotEmpty(permissionNameJson)){ + permissionNameMap = new Gson().fromJson(permissionNameJson, Map.class); + } + if(CollectionUtils.isEmpty(permissionNameMap)){ + permissionNameMap.put("zh", permissionName); + } } + + if(permissionNameMap.containsKey("zh")){ + permissionName = permissionNameMap.get("zh"); + }else if(permissionNameMap.containsKey("en")){ + permissionName = permissionNameMap.get("en"); + } + } + } diff --git a/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/permission/PermissionNameAttr.java b/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/permission/PermissionNameAttr.java new file mode 100644 index 0000000..a5956a9 --- /dev/null +++ b/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/permission/PermissionNameAttr.java @@ -0,0 +1,27 @@ +package com.shop.cereshop.commons.domain.permission; + +public class PermissionNameAttr { + private String type; + private String name; + + public PermissionNameAttr(String type, String name) { + this.type = type; + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/product/CereProductClassify.java b/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/product/CereProductClassify.java index 6ae3a08..a7890b7 100644 --- a/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/product/CereProductClassify.java +++ b/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/product/CereProductClassify.java @@ -8,12 +8,17 @@ package com.shop.cereshop.commons.domain.product; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.google.gson.Gson; +import com.shop.cereshop.commons.utils.StringUtils; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * cere_product_classify 平台商品分类实体类 @@ -66,6 +71,12 @@ public class CereProductClassify implements Serializable { private String classifyName; /** + * 分类名称Json + */ + @ApiModelProperty(value = "分类名称Json") + private String classifyNameJson; + + /** * 分类图片地址 */ @ApiModelProperty(value = "分类图片地址") @@ -104,4 +115,40 @@ public class CereProductClassify implements Serializable { private static final long serialVersionUID = 1L; + + /** + * 名称Map + */ + @ApiModelProperty(value = "名称Map") + @TableField(exist = false) + private Map classifyNameMap; + + public void initData(){ + initData("zh"); + } + public void initData(String language){ + if(classifyNameMap == null){ + classifyNameMap = new HashMap<>(); + } + if (CollectionUtils.isEmpty(classifyNameMap)) { + if(StringUtils.isNotEmpty(classifyNameJson)){ + classifyNameMap = new Gson().fromJson(classifyNameJson, Map.class); + } + if(CollectionUtils.isEmpty(classifyNameMap)){ + classifyNameMap.put("zh", classifyName); + } + } + + if(StringUtils.equals(language, "zh")){ + classifyName = classifyNameMap.get("zh"); + }else if(StringUtils.equals(language, "en")){ + classifyName = classifyNameMap.get("en"); + }else if(classifyNameMap.containsKey("zh")){ + classifyName = classifyNameMap.get("zh"); + }else if(classifyNameMap.containsKey("en")){ + classifyName = classifyNameMap.get("en"); + } + + } + } diff --git a/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/product/Classify.java b/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/product/Classify.java index 2bc3086..b24771f 100644 --- a/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/product/Classify.java +++ b/cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/product/Classify.java @@ -5,11 +5,17 @@ */ package com.shop.cereshop.commons.domain.product; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.google.gson.Gson; +import com.shop.cereshop.commons.utils.StringUtils; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 分类层级结构 @@ -53,4 +59,46 @@ public class Classify { */ @ApiModelProperty(value = "子节点") private List childs; + + + /** + * 分类名称Json + */ + @ApiModelProperty(value = "分类名称Json") + private String classifyNameJson; + + /** + * 名称Map + */ + @ApiModelProperty(value = "名称Map") + @TableField(exist = false) + private Map classifyNameMap; + + public void initData(){ + initData("zh"); + } + public void initData(String language){ + if(classifyNameMap == null){ + classifyNameMap = new HashMap<>(); + } + if (CollectionUtils.isEmpty(classifyNameMap)) { + if(StringUtils.isNotEmpty(classifyNameJson)){ + classifyNameMap = new Gson().fromJson(classifyNameJson, Map.class); + } + if(CollectionUtils.isEmpty(classifyNameMap)){ + classifyNameMap.put("zh", categoryName); + } + } + + if(StringUtils.equals(language, "zh")){ + categoryName = classifyNameMap.get("zh"); + }else if(StringUtils.equals(language, "en")){ + categoryName = classifyNameMap.get("en"); + }else if(classifyNameMap.containsKey("zh")){ + categoryName = classifyNameMap.get("zh"); + }else if(classifyNameMap.containsKey("en")){ + categoryName = classifyNameMap.get("en"); + } + + } }