Browse Source

修改支持多语言分类

multiwx
xh-pan1 1 year ago
parent
commit
5bb5d08372
  1. 22
      cereshop-admin/src/main/java/com/shop/cereshop/admin/page/permission/MenuButton.java
  2. 31
      cereshop-admin/src/main/java/com/shop/cereshop/admin/page/permission/Permission.java
  3. 31
      cereshop-admin/src/main/java/com/shop/cereshop/admin/service/permission/impl/CereBusinessPermissionServiceImpl.java
  4. 18
      cereshop-admin/src/main/java/com/shop/cereshop/admin/service/permission/impl/CerePlatformPermissionServiceImpl.java
  5. 27
      cereshop-admin/src/main/java/com/shop/cereshop/admin/service/product/impl/CereProductClassifyServiceImpl.java
  6. 4
      cereshop-admin/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml
  7. 21
      cereshop-admin/src/main/resources/mybatis/mapper/product/CereProductClassifyDAO.xml
  8. 6
      cereshop-business/src/main/java/com/shop/cereshop/business/interceptor/AuthorizationInterceptor.java
  9. 38
      cereshop-business/src/main/java/com/shop/cereshop/business/page/permission/MenuButton.java
  10. 38
      cereshop-business/src/main/java/com/shop/cereshop/business/page/permission/Permission.java
  11. 7
      cereshop-business/src/main/java/com/shop/cereshop/business/param/permission/PermissionSaveParam.java
  12. 8
      cereshop-business/src/main/java/com/shop/cereshop/business/param/permission/PermissionUpdateParam.java
  13. 24
      cereshop-business/src/main/java/com/shop/cereshop/business/service/permission/impl/CerePlatformPermissionServiceImpl.java
  14. 39
      cereshop-business/src/main/java/com/shop/cereshop/business/service/product/impl/CereProductClassifyServiceImpl.java
  15. 20
      cereshop-business/src/main/java/com/shop/cereshop/business/utils/ContextUtil.java
  16. 21
      cereshop-business/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml
  17. 21
      cereshop-business/src/main/resources/mybatis/mapper/product/CereProductClassifyDAO.xml
  18. 36
      cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/permission/CerePlatformPermission.java
  19. 27
      cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/permission/PermissionNameAttr.java
  20. 47
      cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/product/CereProductClassify.java
  21. 48
      cereshop-commons/src/main/java/com/shop/cereshop/commons/domain/product/Classify.java

22
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<String,String> permissionNameMap;
private Map<String, String> permissionNameMap;
public void initData(){
Map<String,String> 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");
}
}

31
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<String,String> permissionNameMap;
@TableField(exist = false)
private Map<String, String> permissionNameMap;
public void initData(){
Map<String,String> 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");
}
}
}

31
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<String, Integer> 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<String, Integer> 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<String, Integer> 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<String, Integer> 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());

18
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<String,String> 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<String,String> 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);

27
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<CereProductClassify> 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<CereProductClassify> list=cereProductClassifyDAO.getAll();
list.forEach(a -> {
a.initData();
if(a.getChilds() != null) {
a.getChilds().forEach(CereProductClassify::initData);
}
});
PageInfo<CereProductClassify> 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;
}

4
cereshop-admin/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml

@ -173,7 +173,9 @@
</select>
<select id="findAllByResourceType" parameterType="java.lang.Object" resultType="com.shop.cereshop.admin.page.permission.Permission">
SELECT permission_id,permission_pid,permission_name, permission_name_json, permission_uri,permission,icon,`describe`,resource_type,sort FROM cere_platform_permission
SELECT permission_id,
permission_pid,
permission_name, permission_name_json, permission_uri,permission,icon,`describe`,resource_type,sort FROM cere_platform_permission
where project=1 and resource_type=#{resourceType}
<if test="permissionName!=null and permissionName!=''">
and permission_name like concat('%',#{permissionName},'%')

21
cereshop-admin/src/main/resources/mybatis/mapper/product/CereProductClassifyDAO.xml

@ -8,6 +8,7 @@
<result column="classify_level" jdbcType="TINYINT" property="classifyLevel" />
<result column="classify_level_hierarchy" jdbcType="VARCHAR" property="classifyLevelHierarchy" />
<result column="classify_name" jdbcType="VARCHAR" property="classifyName" />
<result column="classify_name_json" jdbcType="VARCHAR" property="classifyNameJson" />
<result column="classify_image" jdbcType="VARCHAR" property="classifyImage" />
<result column="sort" jdbcType="INTEGER" property="sort" />
<result column="link" jdbcType="BIGINT" property="link" />
@ -17,7 +18,7 @@
</resultMap>
<sql id="Base_Column_List">
classify_id, classify_pid, classify_hierarchy, classify_level, classify_level_hierarchy,
classify_name, classify_image, sort, link, project, create_time, update_time
classify_name, classify_name_json, classify_image, sort, link, project, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
@ -47,6 +48,9 @@
<if test="classifyName != null and classifyName!=''">
classify_name,
</if>
<if test="classifyNameJson != null and classifyNameJson!=''">
classify_name_json,
</if>
<if test="classifyImage != null and classifyImage!=''">
classify_image,
</if>
@ -82,6 +86,9 @@
<if test="classifyName != null and classifyName!=''">
#{classifyName,jdbcType=VARCHAR},
</if>
<if test="classifyNameJson != null and classifyNameJson!=''">
#{classifyNameJson,jdbcType=VARCHAR},
</if>
<if test="classifyImage != null and classifyImage!=''">
#{classifyImage,jdbcType=VARCHAR},
</if>
@ -120,6 +127,9 @@
<if test="classifyName != null and classifyName!=''">
classify_name = #{classifyName,jdbcType=VARCHAR},
</if>
<if test="classifyNameJson != null and classifyNameJson!=''">
classify_name_json = #{classifyNameJson,jdbcType=VARCHAR},
</if>
<if test="classifyImage != null and classifyImage!=''">
classify_image = #{classifyImage,jdbcType=VARCHAR},
</if>
@ -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 @@
</update>
<select id="getById" parameterType="java.lang.Object" resultType="com.shop.cereshop.commons.domain.product.CereProductClassify">
SELECT classify_id,classify_name,classify_level_hierarchy,classify_image,link,project,classify_level FROM cere_product_classify
SELECT classify_id,classify_name,classify_name_json,classify_level_hierarchy,classify_image,link,project,classify_level FROM cere_product_classify
where classify_id=#{classifyId}
</select>
<select id="getAll" resultType="com.shop.cereshop.commons.domain.product.CereProductClassify">
SELECT classify_id,classify_name FROM cere_product_classify
SELECT classify_id,classify_name,classify_name_json FROM cere_product_classify
where classify_level=1 AND project = '0' ORDER BY update_time DESC,create_time DESC
</select>
@ -198,12 +209,12 @@
</update>
<select id="findAll" resultType="com.shop.cereshop.commons.domain.product.Classify">
SELECT classify_id id,classify_pid parentId,classify_name categoryName,classify_level depth,classify_image classifyImage
SELECT classify_id id,classify_pid parentId,classify_name categoryName, classify_name_json, classify_level depth,classify_image classifyImage
FROM cere_product_classify where classify_level=1 AND project = '0'
</select>
<select id="findChilds" resultType="com.shop.cereshop.commons.domain.product.Classify">
SELECT classify_id id,classify_pid parentId,classify_name categoryName,classify_level depth,classify_image classifyImage
SELECT classify_id id,classify_pid parentId,classify_name categoryName,classify_name_json,classify_level depth,classify_image classifyImage
FROM cere_product_classify where classify_level<![CDATA[!= ]]>1 AND project = '0'
</select>

6
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;
}

38
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<MenuButton> buttons;
/**
* 名称Json
*/
@ApiModelProperty(value = "名称Json")
private String permissionNameJson;
/**
* 名称Map
*/
@ApiModelProperty(value = "名称Map")
@TableField(exist = false)
private Map<String, String> 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");
}
}
}

38
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<Permission> buttonPermissions;
/**
* 名称Json
*/
@ApiModelProperty(value = "名称Json")
private String permissionNameJson;
/**
* 名称Map
*/
@ApiModelProperty(value = "名称Map")
@TableField(exist = false)
private Map<String, String> 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");
}
}
}

7
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<String,String> permissionNameMap;
}

8
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<String,String> permissionNameMap;
}

24
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<String,Integer> 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<String,Integer> 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<String,Integer> 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

39
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<CereProductClassify> getClassifySelect(ProductGetClassifyParam param) throws CoBusinessException {
return cereProductClassifyDAO.getClassifySelect(ContextUtil.getProject(), param.getClassifyPid());
List<CereProductClassify> 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<String,Integer> 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<CereProductClassify> selectAll() throws CoBusinessException {
return cereProductClassifyDAO.selectAll(ContextUtil.getProject());
List<CereProductClassify> classifyList = cereProductClassifyDAO.selectAll(ContextUtil.getProject());
for (CereProductClassify classify : classifyList) {
classify.initData(ContextUtil.getLanguage());
}
return classifyList;
}
private Classify setChildsIndex(Classify parent, List<Classify> all, Map<String,Integer> 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<CereProductClassify> 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<CereProductClassify> list=cereProductClassifyDAO.getAll(ContextUtil.getProject());
for (CereProductClassify classify : list) {
classify.initData(ContextUtil.getLanguage());
}
PageInfo<CereProductClassify> pageInfo=new PageInfo<>(list);
Page page=new Page(pageInfo.getList(),pageInfo.getTotal());
return page;

20
cereshop-business/src/main/java/com/shop/cereshop/business/utils/ContextUtil.java

@ -55,4 +55,24 @@ public class ContextUtil {
return project;
}
}
static ThreadLocal<String> 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;
}
}
}

21
cereshop-business/src/main/resources/mybatis/mapper/permission/CerePlatformPermissionDAO.xml

@ -5,6 +5,7 @@
<id column="permission_id" jdbcType="BIGINT" property="permissionId" />
<result column="permission_pid" jdbcType="BIGINT" property="permissionPid" />
<result column="permission_name" jdbcType="VARCHAR" property="permissionName" />
<result column="permission_name_json" jdbcType="VARCHAR" property="permissionNameJson" />
<result column="permission_uri" jdbcType="VARCHAR" property="permissionUri" />
<result column="permission" jdbcType="VARCHAR" property="permission" />
<result column="icon" jdbcType="VARCHAR" property="icon" />
@ -16,7 +17,7 @@
<result column="update_time" jdbcType="VARCHAR" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
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
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
@ -38,6 +39,9 @@
<if test="permissionName != null and permissionName!=''">
permission_name,
</if>
<if test="permissionNameJson != null and permissionNameJson!=''">
permission_name_json,
</if>
<if test="permissionUri != null and permissionUri!=''">
permission_uri,
</if>
@ -73,6 +77,9 @@
<if test="permissionName != null and permissionName!=''">
#{permissionName,jdbcType=VARCHAR},
</if>
<if test="permissionNameJson != null and permissionNameJson!=''">
#{permissionNameJson,jdbcType=VARCHAR},
</if>
<if test="permissionUri != null and permissionUri!=''">
#{permissionUri,jdbcType=VARCHAR},
</if>
@ -111,6 +118,9 @@
<if test="permissionName != null and permissionName!=''">
permission_name = #{permissionName,jdbcType=VARCHAR},
</if>
<if test="permissionNameJson != null and permissionNameJson!=''">
permission_name_json = #{permissionNameJson,jdbcType=VARCHAR},
</if>
<if test="permissionUri != null and permissionUri!=''">
permission_uri = #{permissionUri,jdbcType=VARCHAR},
</if>
@ -145,6 +155,7 @@
update cere_platform_permission
set permission_pid = #{permissionPid,jdbcType=BIGINT},
permission_name = #{permissionName,jdbcType=VARCHAR},
permission_name_json = #{permissionNameJson,jdbcType=VARCHAR},
permission_uri = #{permissionUri,jdbcType=VARCHAR},
permission = #{permission,jdbcType=VARCHAR},
icon = #{icon,jdbcType=VARCHAR},
@ -158,11 +169,11 @@
</update>
<select id="getById" parameterType="java.lang.Object" resultType="com.shop.cereshop.commons.domain.permission.CerePlatformPermission">
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>
<select id="findAllByResourceType" parameterType="java.lang.Object" resultType="com.shop.cereshop.business.page.permission.Permission">
SELECT permission_id,permission_pid,permission_name,permission_uri,permission,icon,`describe`,resource_type,sort,create_time FROM cere_platform_permission
SELECT permission_id,permission_pid,permission_name, permission_name_json, permission_uri,permission,icon,`describe`,resource_type,sort,create_time FROM cere_platform_permission
where project=#{businessId} and resource_type=#{resourceType}
<if test="permissionName!=null and permissionName!=''">
and permission_name like concat('%',#{permissionName},'%')
@ -171,7 +182,7 @@
</select>
<select id="findChilds" parameterType="java.lang.Object" resultType="com.shop.cereshop.business.page.permission.Permission">
SELECT permission_id,permission_pid,permission_name,permission_uri,permission,icon,`describe`,resource_type,sort FROM cere_platform_permission
SELECT permission_id,permission_pid,permission_name, permission_name_json, permission_uri,permission,icon,`describe`,resource_type,sort FROM cere_platform_permission
where project=#{businessId} and resource_type in ('menu','button')
<if test="permissionName!=null and permissionName!=''">
and permission_name like concat('%',#{permissionName},'%')
@ -184,7 +195,7 @@
</select>
<select id="findAllCatalogByUserIdAndResourceType" parameterType="java.lang.Object" resultType="com.shop.cereshop.business.page.permission.MenuButton">
SELECT a.permission_id,a.permission_pid,a.permission_name,a.permission path,a.icon,a.resource_type FROM cere_platform_permission a
SELECT a.permission_id,a.permission_pid,a.permission_name,a.permission_name_json,a.permission path,a.icon,a.resource_type FROM cere_platform_permission a
LEFT JOIN cere_platform_role_permission b ON a.permission_id=b.permission_id
LEFT JOIN cere_business_user_role c ON b.role_id=c.role_id
where project=#{businessId} and resource_type=#{resourceType} and c.business_user_id=#{businessUserId}

21
cereshop-business/src/main/resources/mybatis/mapper/product/CereProductClassifyDAO.xml

@ -8,6 +8,7 @@
<result column="classify_level" jdbcType="TINYINT" property="classifyLevel" />
<result column="classify_level_hierarchy" jdbcType="VARCHAR" property="classifyLevelHierarchy" />
<result column="classify_name" jdbcType="VARCHAR" property="classifyName" />
<result column="classify_name_json" jdbcType="VARCHAR" property="classifyNameJson" />
<result column="classify_image" jdbcType="VARCHAR" property="classifyImage" />
<result column="sort" jdbcType="INTEGER" property="sort" />
<result column="link" jdbcType="BIGINT" property="link" />
@ -17,7 +18,7 @@
</resultMap>
<sql id="Base_Column_List">
classify_id, classify_pid, classify_hierarchy, classify_level, classify_level_hierarchy,
classify_name, classify_image, sort, link,project, create_time, update_time
classify_name, classify_name_json, classify_image, sort, link,project, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
@ -47,6 +48,9 @@
<if test="classifyName != null and classifyName!=''">
classify_name,
</if>
<if test="classifyNameJson != null and classifyNameJson!=''">
classify_name_json,
</if>
<if test="classifyImage != null and classifyImage!=''">
classify_image,
</if>
@ -82,6 +86,9 @@
<if test="classifyName != null and classifyName!=''">
#{classifyName,jdbcType=VARCHAR},
</if>
<if test="classifyNameJson != null and classifyNameJson!=''">
#{classifyNameJson,jdbcType=VARCHAR},
</if>
<if test="classifyImage != null and classifyImage!=''">
#{classifyImage,jdbcType=VARCHAR},
</if>
@ -120,6 +127,9 @@
<if test="classifyName != null and classifyName!=''">
classify_name = #{classifyName,jdbcType=VARCHAR},
</if>
<if test="classifyNameJson != null and classifyNameJson!=''">
classify_name_json = #{classifyNameJson,jdbcType=VARCHAR},
</if>
<if test="classifyImage != null and classifyImage!=''">
classify_image = #{classifyImage,jdbcType=VARCHAR},
</if>
@ -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 @@
</update>
<select id="getClassifySelect" parameterType="java.lang.Object" resultType="com.shop.cereshop.commons.domain.product.CereProductClassify">
SELECT classify_id,classify_pid,classify_name from cere_product_classify where classify_pid=#{classifyPid} AND project=#{project} ORDER BY sort
SELECT classify_id,classify_pid,classify_name,classify_name_json from cere_product_classify where classify_pid=#{classifyPid} AND project=#{project} ORDER BY sort
</select>
<select id="findByHierarchy" parameterType="java.lang.Object" resultType="com.shop.cereshop.commons.domain.product.CereProductClassify">
@ -170,12 +181,12 @@
</select>
<select id="findAll" resultType="com.shop.cereshop.commons.domain.product.Classify">
SELECT classify_id id,classify_pid parentId,classify_name categoryName,classify_level depth
SELECT classify_id id,classify_pid parentId,classify_name categoryName,classify_name_json, classify_level depth
FROM cere_product_classify where classify_level=1 AND project=#{project}
</select>
<select id="findChilds" resultType="com.shop.cereshop.commons.domain.product.Classify">
SELECT classify_id id,classify_pid parentId,classify_name categoryName,classify_level depth
SELECT classify_id id,classify_pid parentId,classify_name categoryName,classify_name_json, classify_level depth
FROM cere_product_classify where classify_level<![CDATA[!= ]]>1 AND project=#{project}
</select>
@ -220,7 +231,7 @@
</select>
<select id="getAll" resultType="com.shop.cereshop.commons.domain.product.CereProductClassify">
SELECT classify_id,classify_name FROM cere_product_classify
SELECT classify_id,classify_name, classify_name_json FROM cere_product_classify
where classify_level=1 AND project = #{project} ORDER BY update_time DESC,create_time DESC
</select>
</mapper>

36
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<String,String> permissionNameMap;
private static final long serialVersionUID = 1L;
private Map<String, String> permissionNameMap;
public void initData(){
Map<String,String> 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");
}
}
}

27
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;
}
}

47
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<String, String> 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");
}
}
}

48
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<Classify> childs;
/**
* 分类名称Json
*/
@ApiModelProperty(value = "分类名称Json")
private String classifyNameJson;
/**
* 名称Map
*/
@ApiModelProperty(value = "名称Map")
@TableField(exist = false)
private Map<String, String> 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");
}
}
}
Loading…
Cancel
Save