增加环境搭建文档

pull/4/MERGE
YunaiV 2021-02-21 19:28:48 +08:00
parent 4e926d8d1a
commit 30e2d08784
11 changed files with 261 additions and 249 deletions

View File

@ -26,7 +26,10 @@
> 一起交流Get 知识。
* 我们迫切希望更多的参与进来,可以加入「交流群」,一起骚聊。
* [《Onemall 电商开源项目 —— 应用分层》](http://www.iocoder.cn/Onemall/Application-layer/?vip&onemall)
* [《Onemall 电商开源项目 —— 应用分层》](http://www.iocoder.cn/Onemall/Application-layer/?onemall)
* [《Onemall 电商开源项目 —— 搭建调试环境》](http://www.iocoder.cn/Onemall/build-debugger-environment/?onemall)
* 前端项目地址:<https://github.com/YunaiV/onemall-web>
# 演示
@ -95,7 +98,7 @@
## 搭建环境
[搭建调试环境](https://gitee.com/zhijiantianya/onemall/blob/master/docs/setup/quick-start.md)
[搭建调试环境](http://www.iocoder.cn/Onemall/build-debugger-environment/)
## 架构图

View File

@ -28,7 +28,6 @@ public interface GlobalErrorCodeConstants {
ErrorCode UNKNOWN = new ErrorCode(999, "未知错误");
static boolean isMatch(Integer code) {
return code != null
&& code >= SUCCESS.getCode() && code <= UNKNOWN.getCode();

View File

@ -15,7 +15,7 @@ import java.util.concurrent.ConcurrentMap;
*
* String.format 使 {} 使 {@link #doFormat(int, String, Object...)}
*
* {@link #messages} 使
* {@link #MESSAGES} 使
*
* 1. cn.iocoder.oceans.user.api.constants.ErrorCodeEnum + ServiceExceptionConfiguration
* 2. .properties
@ -29,29 +29,29 @@ public class ServiceExceptionUtil {
/**
*
*/
private static ConcurrentMap<Integer, String> messages = new ConcurrentHashMap<>();
private static final ConcurrentMap<Integer, String> MESSAGES = new ConcurrentHashMap<>();
public static void putAll(Map<Integer, String> messages) {
ServiceExceptionUtil.messages.putAll(messages);
ServiceExceptionUtil.MESSAGES.putAll(messages);
}
public static void put(Integer code, String message) {
ServiceExceptionUtil.messages.put(code, message);
ServiceExceptionUtil.MESSAGES.put(code, message);
}
public static void delete(Integer code, String message) {
ServiceExceptionUtil.messages.remove(code, message);
ServiceExceptionUtil.MESSAGES.remove(code, message);
}
// ========== 和 ServiceException 的集成 ==========
public static ServiceException exception(ErrorCode errorCode) {
String messagePattern = messages.getOrDefault(errorCode.getCode(), errorCode.getMessage());
String messagePattern = MESSAGES.getOrDefault(errorCode.getCode(), errorCode.getMessage());
return exception0(errorCode.getCode(), messagePattern);
}
public static ServiceException exception(ErrorCode errorCode, Object... params) {
String messagePattern = messages.getOrDefault(errorCode.getCode(), errorCode.getMessage());
String messagePattern = MESSAGES.getOrDefault(errorCode.getCode(), errorCode.getMessage());
return exception0(errorCode.getCode(), messagePattern, params);
}
@ -62,7 +62,7 @@ public class ServiceExceptionUtil {
* @return
*/
public static ServiceException exception(Integer code) {
return exception0(code, messages.get(code));
return exception0(code, MESSAGES.get(code));
}
/**
@ -73,7 +73,7 @@ public class ServiceExceptionUtil {
* @return
*/
public static ServiceException exception(Integer code, Object... params) {
return exception0(code, messages.get(code), params);
return exception0(code, MESSAGES.get(code), params);
}
public static ServiceException exception0(Integer code, String messagePattern, Object... params) {

View File

@ -37,7 +37,7 @@ public class RedisKeyDefine {
*
* 使 {@link java.util.concurrent.locks.Lock}
*/
private final Class valueType;
private final Class<?> valueType;
/**
*
*
@ -45,7 +45,7 @@ public class RedisKeyDefine {
*/
private final Duration timeout;
public RedisKeyDefine(String keyTemplate, KeyTypeEnum keyType, Class valueType, Duration timeout) {
public RedisKeyDefine(String keyTemplate, KeyTypeEnum keyType, Class<?> valueType, Duration timeout) {
this.keyTemplate = keyTemplate;
this.keyType = keyType;
this.valueType = valueType;
@ -60,7 +60,7 @@ public class RedisKeyDefine {
return keyType;
}
public Class getValueType() {
public Class<?> getValueType() {
return valueType;
}

View File

@ -11,13 +11,10 @@ import javax.validation.constraints.NotEmpty;
public class DataDictSimpleVO {
@ApiModelProperty(value = "大类枚举值", required = true, example = "gender")
@NotEmpty(message = "大类枚举值不能为空")
private String enumValue;
@ApiModelProperty(value = "小类数值", required = true, example = "1")
@NotEmpty(message = "小类数值不能为空")
private String value;
@ApiModelProperty(value = "展示名", required = true, example = "男")
@NotEmpty(message = "展示名不能为空")
private String displayName;
}

View File

@ -15,6 +15,7 @@ public class UserUpdateStatusReqVO {
@ApiModelProperty(value = "用户编号", required = true)
@NotNull(message = "用户编号不能为空")
private Integer userId;
@ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 CommonStatusEnum 枚举")
@NotNull(message = "状态不能为空")
@InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")

View File

@ -6,13 +6,18 @@ import cn.iocoder.mall.managementweb.controller.pay.vo.transaction.PayTransactio
import cn.iocoder.mall.managementweb.controller.pay.vo.transaction.PayTransactionRespVO;
import cn.iocoder.mall.managementweb.convert.pay.transaction.PayTransactionConvert;
import cn.iocoder.mall.payservice.rpc.transaction.dto.PayTransactionRespDTO;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Stream;
@Service
public class PayTransactionService {
@Autowired
@Resource
private PayTransactionClient payTransactionClient;
public PageResult<PayTransactionRespVO> pagePayTransaction(PayTransactionPageReqVO pageReqVO) {

View File

@ -7,7 +7,7 @@ import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignAdminRol
import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionAssignRoleResourceDTO;
import cn.iocoder.mall.systemservice.rpc.permission.dto.PermissionCheckDTO;
import cn.iocoder.mall.systemservice.service.permission.PermissionService;
import cn.iocoder.mall.systemservice.service.permission.ResourceService;
import cn.iocoder.mall.systemservice.service.permission.ResourceServiceImpl;
import cn.iocoder.mall.systemservice.service.permission.RoleService;
import cn.iocoder.mall.systemservice.service.permission.bo.ResourceBO;
import org.springframework.beans.factory.annotation.Autowired;
@ -31,7 +31,7 @@ public class PermissionManager {
@Autowired
private RoleService roleService;
@Autowired
private ResourceService resourceService;
private ResourceServiceImpl resourceService;
/**
*

View File

@ -4,7 +4,7 @@ import cn.iocoder.mall.systemservice.convert.permission.ResourceConvert;
import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO;
import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceUpdateDTO;
import cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO;
import cn.iocoder.mall.systemservice.service.permission.ResourceService;
import cn.iocoder.mall.systemservice.service.permission.ResourceServiceImpl;
import cn.iocoder.mall.systemservice.service.permission.RoleService;
import cn.iocoder.mall.systemservice.service.permission.bo.ResourceBO;
import org.springframework.beans.factory.annotation.Autowired;
@ -20,7 +20,7 @@ import java.util.List;
public class ResourceManager {
@Autowired
private ResourceService resourceService;
private ResourceServiceImpl resourceService;
@Autowired
private RoleService roleService;

View File

@ -1,230 +1,7 @@
package cn.iocoder.mall.systemservice.service.permission;
import cn.iocoder.common.framework.util.CollectionUtils;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
import cn.iocoder.mall.systemservice.convert.permission.ResourceConvert;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.ResourceDO;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.RoleResourceDO;
import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.ResourceMapper;
import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleResourceMapper;
import cn.iocoder.mall.systemservice.enums.SystemErrorCodeConstants;
import cn.iocoder.mall.systemservice.enums.permission.ResourceIdEnum;
import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum;
import cn.iocoder.mall.systemservice.service.permission.bo.ResourceBO;
import cn.iocoder.mall.systemservice.service.permission.bo.ResourceCreateBO;
import cn.iocoder.mall.systemservice.service.permission.bo.ResourceUpdateBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeConstants.*;
/**
* Service
*/
@Service
@Validated
public class ResourceService {
@Autowired
private ResourceMapper resourceMapper;
@Autowired
private RoleResourceMapper roleResourceMapper;
/**
*
*
* @param createBO BO
* @return
*/
public ResourceBO createResource(@Valid ResourceCreateBO createBO) {
// 校验父资源存在
checkParentResource(createBO.getPid(), null);
// 校验资源(自己)
checkResource(createBO.getPid(), createBO.getName(), null);
// 插入数据库
ResourceDO resourceDO = ResourceConvert.INSTANCE.convert(createBO);
initResourceProperty(resourceDO);
resourceMapper.insert(resourceDO);
// 返回
return ResourceConvert.INSTANCE.convert(resourceDO);
}
/**
*
*
* @param updateBO BO
*/
public void updateResource(@Valid ResourceUpdateBO updateBO) {
// 校验更新的资源是否存在
if (resourceMapper.selectById(updateBO.getId()) == null) {
throw ServiceExceptionUtil.exception(RESOURCE_NOT_EXISTS);
}
// 校验父资源存在
checkParentResource(updateBO.getPid(), updateBO.getId());
// 校验资源(自己)
checkResource(updateBO.getPid(), updateBO.getName(), updateBO.getId());
// 更新到数据库
ResourceDO updateObject = ResourceConvert.INSTANCE.convert(updateBO);
initResourceProperty(updateObject);
resourceMapper.updateById(updateObject);
}
/**
*
*
* @param resourceId
*/
public void deleteResource(Integer resourceId) {
// 校验更新的资源是否存在
if (resourceMapper.selectById(resourceId) == null) {
throw ServiceExceptionUtil.exception(SystemErrorCodeConstants.RESOURCE_NOT_EXISTS);
}
// 校验是否还有子资源
if (resourceMapper.selectCountByPid(resourceId) > 0) {
throw ServiceExceptionUtil.exception(SystemErrorCodeConstants.RESOURCE_EXISTS_CHILDREN);
}
// 校验删除的资源是否存在
if (resourceMapper.selectById(resourceId) == null) {
throw ServiceExceptionUtil.exception(RESOURCE_NOT_EXISTS);
}
// 标记删除
resourceMapper.deleteById(resourceId);
// 删除授予给角色的权限
roleResourceMapper.deleteByResourceId(resourceId);
}
/**
*
*
* @param resourceId
* @return
*/
public ResourceBO getResource(Integer resourceId) {
ResourceDO resourceDO = resourceMapper.selectById(resourceId);
return ResourceConvert.INSTANCE.convert(resourceDO);
}
/**
*
*
* @param resourceIds
* @return
*/
public List<ResourceBO> listResources(List<Integer> resourceIds) {
List<ResourceDO> resourceDOs = resourceMapper.selectBatchIds(resourceIds);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
/**
*
*
* @return
*/
public List<ResourceBO> listResources() {
List<ResourceDO> resourceDOs = resourceMapper.selectList(null);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
/**
*
*
* @param type
* @return
*/
public List<ResourceBO> listResourcesByType(Integer type) {
List<ResourceDO> resourceDOs = resourceMapper.selectListByType(type);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
/**
*
*
* @param roleIds
* @param type
* @return
*/
public List<ResourceBO> listRoleResourcesByType(Collection<Integer> roleIds, Integer type) {
List<RoleResourceDO> roleResourceDOs = roleResourceMapper.selectListByRoleIds(roleIds);
if (CollectionUtils.isEmpty(roleResourceDOs)) {
return Collections.emptyList();
}
List<ResourceDO> resourceDOs = resourceMapper.selectListByIdsAndType(
CollectionUtils.convertSet(roleResourceDOs, RoleResourceDO::getResourceId), type);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
/**
*
*
* 1.
* 2.
* 3. {@link ResourceTypeEnum#MENU}
*
* @param pid
* @param childId
*/
private void checkParentResource(Integer pid, Integer childId) {
if (pid == null || ResourceIdEnum.ROOT.getId().equals(pid)) {
return;
}
// 不能设置自己为父资源
if (pid.equals(childId)) {
throw ServiceExceptionUtil.exception(RESOURCE_PARENT_ERROR);
}
ResourceDO resource = resourceMapper.selectById(pid);
// 父资源不存在
if (resource == null) {
throw ServiceExceptionUtil.exception(RESOURCE_PARENT_NOT_EXISTS);
}
// 父资源必须是菜单类型
if (!ResourceTypeEnum.MENU.getType().equals(resource.getType())) {
throw ServiceExceptionUtil.exception(RESOURCE_PARENT_NOT_MENU);
}
}
/**
*
*
* 1.
*
* @param name
* @param pid
* @param id
*/
private void checkResource(Integer pid, String name, Integer id) {
ResourceDO resource = resourceMapper.selectByPidAndName(pid, name);
if (resource == null) {
return;
}
// 如果 id 为空,说明不用比较是否为相同 id 的资源
if (id == null) {
throw ServiceExceptionUtil.exception(RESOURCE_NAME_DUPLICATE);
}
if (!resource.getId().equals(id)) {
throw ServiceExceptionUtil.exception(RESOURCE_NAME_DUPLICATE);
}
}
/**
*
*
* icon
*
* @param resource
*/
private void initResourceProperty(ResourceDO resource) {
// 资源为按钮类型时,无需 route、icon、view 属性,进行置空
if (ResourceTypeEnum.BUTTON.getType().equals(resource.getType())) {
resource.setRoute(null);
resource.setIcon(null);
resource.setView(null);
}
}
* Service
*/
public interface ResourceService {
}

View File

@ -0,0 +1,230 @@
package cn.iocoder.mall.systemservice.service.permission;
import cn.iocoder.common.framework.util.CollectionUtils;
import cn.iocoder.common.framework.exception.util.ServiceExceptionUtil;
import cn.iocoder.mall.systemservice.convert.permission.ResourceConvert;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.ResourceDO;
import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.RoleResourceDO;
import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.ResourceMapper;
import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleResourceMapper;
import cn.iocoder.mall.systemservice.enums.SystemErrorCodeConstants;
import cn.iocoder.mall.systemservice.enums.permission.ResourceIdEnum;
import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum;
import cn.iocoder.mall.systemservice.service.permission.bo.ResourceBO;
import cn.iocoder.mall.systemservice.service.permission.bo.ResourceCreateBO;
import cn.iocoder.mall.systemservice.service.permission.bo.ResourceUpdateBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeConstants.*;
/**
* Service
*/
@Service
@Validated
public class ResourceServiceImpl implements ResourceService {
@Autowired
private ResourceMapper resourceMapper;
@Autowired
private RoleResourceMapper roleResourceMapper;
/**
*
*
* @param createBO BO
* @return
*/
public ResourceBO createResource(@Valid ResourceCreateBO createBO) {
// 校验父资源存在
checkParentResource(createBO.getPid(), null);
// 校验资源(自己)
checkResource(createBO.getPid(), createBO.getName(), null);
// 插入数据库
ResourceDO resourceDO = ResourceConvert.INSTANCE.convert(createBO);
initResourceProperty(resourceDO);
resourceMapper.insert(resourceDO);
// 返回
return ResourceConvert.INSTANCE.convert(resourceDO);
}
/**
*
*
* @param updateBO BO
*/
public void updateResource(@Valid ResourceUpdateBO updateBO) {
// 校验更新的资源是否存在
if (resourceMapper.selectById(updateBO.getId()) == null) {
throw ServiceExceptionUtil.exception(RESOURCE_NOT_EXISTS);
}
// 校验父资源存在
checkParentResource(updateBO.getPid(), updateBO.getId());
// 校验资源(自己)
checkResource(updateBO.getPid(), updateBO.getName(), updateBO.getId());
// 更新到数据库
ResourceDO updateObject = ResourceConvert.INSTANCE.convert(updateBO);
initResourceProperty(updateObject);
resourceMapper.updateById(updateObject);
}
/**
*
*
* @param resourceId
*/
public void deleteResource(Integer resourceId) {
// 校验更新的资源是否存在
if (resourceMapper.selectById(resourceId) == null) {
throw ServiceExceptionUtil.exception(SystemErrorCodeConstants.RESOURCE_NOT_EXISTS);
}
// 校验是否还有子资源
if (resourceMapper.selectCountByPid(resourceId) > 0) {
throw ServiceExceptionUtil.exception(SystemErrorCodeConstants.RESOURCE_EXISTS_CHILDREN);
}
// 校验删除的资源是否存在
if (resourceMapper.selectById(resourceId) == null) {
throw ServiceExceptionUtil.exception(RESOURCE_NOT_EXISTS);
}
// 标记删除
resourceMapper.deleteById(resourceId);
// 删除授予给角色的权限
roleResourceMapper.deleteByResourceId(resourceId);
}
/**
*
*
* @param resourceId
* @return
*/
public ResourceBO getResource(Integer resourceId) {
ResourceDO resourceDO = resourceMapper.selectById(resourceId);
return ResourceConvert.INSTANCE.convert(resourceDO);
}
/**
*
*
* @param resourceIds
* @return
*/
public List<ResourceBO> listResources(List<Integer> resourceIds) {
List<ResourceDO> resourceDOs = resourceMapper.selectBatchIds(resourceIds);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
/**
*
*
* @return
*/
public List<ResourceBO> listResources() {
List<ResourceDO> resourceDOs = resourceMapper.selectList(null);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
/**
*
*
* @param type
* @return
*/
public List<ResourceBO> listResourcesByType(Integer type) {
List<ResourceDO> resourceDOs = resourceMapper.selectListByType(type);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
/**
*
*
* @param roleIds
* @param type
* @return
*/
public List<ResourceBO> listRoleResourcesByType(Collection<Integer> roleIds, Integer type) {
List<RoleResourceDO> roleResourceDOs = roleResourceMapper.selectListByRoleIds(roleIds);
if (CollectionUtils.isEmpty(roleResourceDOs)) {
return Collections.emptyList();
}
List<ResourceDO> resourceDOs = resourceMapper.selectListByIdsAndType(
CollectionUtils.convertSet(roleResourceDOs, RoleResourceDO::getResourceId), type);
return ResourceConvert.INSTANCE.convertList(resourceDOs);
}
/**
*
*
* 1.
* 2.
* 3. {@link ResourceTypeEnum#MENU}
*
* @param pid
* @param childId
*/
private void checkParentResource(Integer pid, Integer childId) {
if (pid == null || ResourceIdEnum.ROOT.getId().equals(pid)) {
return;
}
// 不能设置自己为父资源
if (pid.equals(childId)) {
throw ServiceExceptionUtil.exception(RESOURCE_PARENT_ERROR);
}
ResourceDO resource = resourceMapper.selectById(pid);
// 父资源不存在
if (resource == null) {
throw ServiceExceptionUtil.exception(RESOURCE_PARENT_NOT_EXISTS);
}
// 父资源必须是菜单类型
if (!ResourceTypeEnum.MENU.getType().equals(resource.getType())) {
throw ServiceExceptionUtil.exception(RESOURCE_PARENT_NOT_MENU);
}
}
/**
*
*
* 1.
*
* @param name
* @param pid
* @param id
*/
private void checkResource(Integer pid, String name, Integer id) {
ResourceDO resource = resourceMapper.selectByPidAndName(pid, name);
if (resource == null) {
return;
}
// 如果 id 为空,说明不用比较是否为相同 id 的资源
if (id == null) {
throw ServiceExceptionUtil.exception(RESOURCE_NAME_DUPLICATE);
}
if (!resource.getId().equals(id)) {
throw ServiceExceptionUtil.exception(RESOURCE_NAME_DUPLICATE);
}
}
/**
*
*
* icon
*
* @param resource
*/
private void initResourceProperty(ResourceDO resource) {
// 资源为按钮类型时,无需 route、icon、view 属性,进行置空
if (ResourceTypeEnum.BUTTON.getType().equals(resource.getType())) {
resource.setRoute(null);
resource.setIcon(null);
resource.setView(null);
}
}
}