From e990c1fc77ff2adbb0deff5285460888fc2987eb Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Sat, 22 Jun 2024 09:39:29 +0800 Subject: [PATCH] =?UTF-8?q?wip:=20=E9=87=8D=E6=9E=84=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/MemberServiceImpl.java | 6 +-- .../order/service/impl/OrderServiceImpl.java | 10 ++--- ...uteController.java => AttrController.java} | 2 +- .../mall/product/converter/AttrConverter.java | 4 +- .../product/converter/AttrGroupConverter.java | 4 +- .../product/converter/CategoryConverter.java | 2 +- .../mall/product/converter/SkuConverter.java | 2 +- .../mall/product/converter/SpecConverter.java | 2 +- .../mall/product/converter/SpuConverter.java | 2 +- .../mall/product/service/AttrService.java | 9 +++- .../product/service/SpuAttrValueService.java | 8 +++- .../service/impl/AttrGroupServiceImpl.java | 16 ++++--- .../product/service/impl/AttrServiceImpl.java | 24 +++++++++++ .../service/impl/CategoryServiceImpl.java | 2 +- .../product/service/impl/SpecServiceImpl.java | 2 +- .../service/impl/SpuAttrValueServiceImpl.java | 12 ++++++ .../product/service/impl/SpuServiceImpl.java | 2 +- .../src/main/resources/mapper/AttrMapper.xml | 2 +- .../mall/sms/converter/CouponConverter.java | 2 +- .../sms/service/impl/CouponServiceImpl.java | 2 +- .../web/aspect/DuplicateSubmitAspect.java | 4 +- .../common/web/exception/BizException.java | 35 --------------- .../web/exception/BusinessException.java | 43 +++++++++++++++++++ .../web/exception/GlobalExceptionHandler.java | 4 +- .../resources/templates/converter.java.vm | 4 +- .../resources/templates/serviceImpl.java.vm | 2 +- .../system/converter/DeptConverter.java | 4 +- .../system/converter/DictConverter.java | 4 +- .../system/converter/DictTypeConverter.java | 2 +- .../system/converter/MenuConverter.java | 2 +- .../system/converter/RoleConverter.java | 2 +- .../system/converter/UserConverter.java | 4 +- .../service/impl/SysDeptServiceImpl.java | 4 +- .../service/impl/SysDictServiceImpl.java | 2 +- .../service/impl/SysDictTypeServiceImpl.java | 2 +- .../service/impl/SysMenuServiceImpl.java | 2 +- .../service/impl/SysRoleServiceImpl.java | 2 +- 37 files changed, 146 insertions(+), 91 deletions(-) rename mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/admin/{AttributeController.java => AttrController.java} (98%) delete mode 100644 youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BizException.java create mode 100644 youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BusinessException.java diff --git a/mall-member/member-boot/src/main/java/com/youlai/mall/member/service/impl/MemberServiceImpl.java b/mall-member/member-boot/src/main/java/com/youlai/mall/member/service/impl/MemberServiceImpl.java index 25375c58f..fdeef31e0 100644 --- a/mall-member/member-boot/src/main/java/com/youlai/mall/member/service/impl/MemberServiceImpl.java +++ b/mall-member/member-boot/src/main/java/com/youlai/mall/member/service/impl/MemberServiceImpl.java @@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.youlai.common.result.ResultCode; import com.youlai.common.security.util.SecurityUtils; -import com.youlai.common.web.exception.BizException; +import com.youlai.common.web.exception.BusinessException; import com.youlai.mall.member.convert.AddressConvert; import com.youlai.mall.member.convert.MemberConvert; import com.youlai.mall.member.dto.MemberAddressDTO; @@ -76,7 +76,7 @@ public class MemberServiceImpl extends ServiceImpl impleme ); if (entity == null) { - throw new BizException(ResultCode.USER_NOT_EXIST); + throw new BusinessException(ResultCode.USER_NOT_EXIST); } return memberConvert.entity2OpenidAuthDTO(entity); } @@ -98,7 +98,7 @@ public class MemberServiceImpl extends ServiceImpl impleme ); if (entity == null) { - throw new BizException(ResultCode.USER_NOT_EXIST); + throw new BusinessException(ResultCode.USER_NOT_EXIST); } return memberConvert.entity2MobileAuthDTO(entity); } diff --git a/mall-order/order-boot/src/main/java/com/youlai/mall/order/service/impl/OrderServiceImpl.java b/mall-order/order-boot/src/main/java/com/youlai/mall/order/service/impl/OrderServiceImpl.java index 5c5e1442f..75155405c 100644 --- a/mall-order/order-boot/src/main/java/com/youlai/mall/order/service/impl/OrderServiceImpl.java +++ b/mall-order/order-boot/src/main/java/com/youlai/mall/order/service/impl/OrderServiceImpl.java @@ -3,7 +3,6 @@ package com.youlai.mall.order.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -25,7 +24,7 @@ import com.github.binarywang.wxpay.service.WxPayService; import com.youlai.common.constant.RedisConstants; import com.youlai.common.rabbitmq.constant.RabbitMqConstants; import com.youlai.common.security.util.SecurityUtils; -import com.youlai.common.web.exception.BizException; +import com.youlai.common.web.exception.BusinessException; import com.youlai.mall.order.config.property.WxPayProperties; import com.youlai.mall.order.converter.OrderConverter; import com.youlai.mall.order.enums.ApprovalStatusEnum; @@ -57,7 +56,6 @@ import com.youlai.mall.member.api.MemberFeignClient; import com.youlai.mall.member.dto.CartItemDTO; import com.youlai.mall.member.dto.MemberAddressDTO; import io.seata.spring.annotation.GlobalTransactional; -import io.seata.spring.util.OrderUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.redisson.api.RLock; @@ -376,7 +374,7 @@ public class OrderServiceImpl extends ServiceImpl impleme refundResult = wxPayService.refund(request); } catch (WxPayException e) { log.error(e.getMessage(), e); - throw new BizException("订单(" + order.getOrderNo() + ")退款失败"); + throw new BusinessException("订单(" + order.getOrderNo() + ")退款失败"); } if (WxPayConstants.ResultCode.SUCCESS.equals(refundResult.getResultCode())) { order.setStatus(OrderStatusEnum.REFUND_PENDING.getValue()); @@ -433,7 +431,7 @@ public class OrderServiceImpl extends ServiceImpl impleme wxPayService.closeOrderV3(orderNo); } catch (WxPayException e) { log.error(e.getMessage(), e); - throw new BizException("微信关单异常"); + throw new BusinessException("微信关单异常"); } } @@ -463,7 +461,7 @@ public class OrderServiceImpl extends ServiceImpl impleme jsapiResult = wxPayService.createOrderV3(TradeTypeEnum.JSAPI, wxRequest); } catch (WxPayException e) { log.error(e.getMessage(), e); - throw new BizException("微信统一下单异常"); + throw new BusinessException("微信统一下单异常"); } return jsapiResult; } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/admin/AttributeController.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/admin/AttrController.java similarity index 98% rename from mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/admin/AttributeController.java rename to mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/admin/AttrController.java index 04148f120..94fffb3a3 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/admin/AttributeController.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/admin/AttrController.java @@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api/v1/attributes") @RequiredArgsConstructor -public class AttributeController { +public class AttrController { private final AttrGroupService attrGroupService; diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/AttrConverter.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/AttrConverter.java index f74b003b4..39b2f96ff 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/AttrConverter.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/AttrConverter.java @@ -11,8 +11,8 @@ import java.util.List; @Mapper(componentModel = "spring") public interface AttrConverter { - AttrForm toForm(Attr entity); - List toForm(List entity); + AttrForm convertToForm(Attr entity); + List convertToForm(List entity); Attr convertToEntity(AttrGroupForm.Attr attr); List convertToEntity(List attrs); diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/AttrGroupConverter.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/AttrGroupConverter.java index 3f3286de3..783e067ef 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/AttrGroupConverter.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/AttrGroupConverter.java @@ -16,8 +16,8 @@ public interface AttrGroupConverter { Page toPageVo(Page bo); - AttrGroupForm toForm(AttrGroup entity); + AttrGroupForm convertToForm(AttrGroup entity); - @InheritInverseConfiguration(name = "toForm") + @InheritInverseConfiguration(name = "convertToForm") AttrGroup toEntity(AttrGroupForm entity); } \ No newline at end of file diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/CategoryConverter.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/CategoryConverter.java index 2468abb47..6fef47192 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/CategoryConverter.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/CategoryConverter.java @@ -10,7 +10,7 @@ import org.mapstruct.Mappings; @Mapper(componentModel = "spring") public interface CategoryConverter { - CategoryForm toForm(Category entity); + CategoryForm convertToForm(Category entity); Category toEntity(CategoryForm formData); diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SkuConverter.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SkuConverter.java index 7c04a85e9..e2e0494d0 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SkuConverter.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SkuConverter.java @@ -26,5 +26,5 @@ public interface SkuConverter { Sku toEntity(SpuForm.Sku skuForm); - SpuForm.Sku toForm(SkuBO bo); + SpuForm.Sku convertToForm(SkuBO bo); } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SpecConverter.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SpecConverter.java index e734b45b1..0abe5417c 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SpecConverter.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SpecConverter.java @@ -26,7 +26,7 @@ public interface SpecConverter { Page toPageVo(Page bo); - SpecForm toForm(Spec entity); + SpecForm convertToForm(Spec entity); Spec toEntity(SpecForm formData); } \ No newline at end of file diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SpuConverter.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SpuConverter.java index 33bcf4b40..fc3649d65 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SpuConverter.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/converter/SpuConverter.java @@ -17,5 +17,5 @@ public interface SpuConverter { Spu toEntity(SpuForm form); - SpuForm toForm(Spu spu); + SpuForm convertToForm(Spu spu); } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/AttrService.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/AttrService.java index 89d85a8da..96fb7d3c5 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/AttrService.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/AttrService.java @@ -2,9 +2,7 @@ package com.youlai.mall.product.service; import com.baomidou.mybatisplus.extension.service.IService; import com.youlai.mall.product.model.entity.Attr; -import com.youlai.mall.product.model.form.AttrForm; import com.youlai.mall.product.model.vo.AttrGroupVO; -import com.youlai.mall.product.model.vo.AttrVO; import java.util.List; @@ -22,4 +20,11 @@ public interface AttrService extends IService { * @param categoryId 分类ID */ List listAttrsByCategoryId(Long categoryId); + + /** + * 根据分组ID删除属性 + * + * @param groupId 分组ID + */ + void removeByGroupId(Long groupId); } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuAttrValueService.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuAttrValueService.java index 824ee00c4..8b36714a5 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuAttrValueService.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuAttrValueService.java @@ -17,9 +17,15 @@ public interface SpuAttrValueService extends IService { /** * 保存商品属性 * - * @param spuId SPU ID + * @param spuId SPU ID * @param attrValues 属性列表 */ void saveAttributeValues(Long spuId, List attrValues); + /** + * 判断属性是否有商品引用 + * + * @param attrId 属性ID + */ + boolean isAttrReferenced(Long attrId); } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/AttrGroupServiceImpl.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/AttrGroupServiceImpl.java index 8357ce7d1..27bd0c932 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/AttrGroupServiceImpl.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/AttrGroupServiceImpl.java @@ -16,8 +16,10 @@ import com.youlai.mall.product.model.query.AttrGroupPageQuery; import com.youlai.mall.product.model.vo.AttrGroupPageVO; import com.youlai.mall.product.service.AttrGroupService; import com.youlai.mall.product.service.AttrService; +import com.youlai.mall.product.service.SpuAttrValueService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.stream.Collectors; @@ -38,6 +40,8 @@ public class AttrGroupServiceImpl extends ServiceImpl attrEntities = attrService.list(new LambdaQueryWrapper() .eq(Attr::getAttrGroupId, groupId) ); - List attrList = attrConverter.toForm(attrEntities); + List attrList = attrConverter.convertToForm(attrEntities); attrGroupForm.setAttrs(attrList); return attrGroupForm; @@ -156,9 +160,9 @@ public class AttrGroupServiceImpl extends ServiceImpl idList = Arrays.stream(ids.split(",")) .map(Long::parseLong) .toList(); @@ -167,9 +171,7 @@ public class AttrGroupServiceImpl extends ServiceImpl().eq(Attr::getAttrGroupId, groupId) - ); + attrService.removeByGroupId(groupId); } } } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/AttrServiceImpl.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/AttrServiceImpl.java index d7619159b..67c933132 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/AttrServiceImpl.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/AttrServiceImpl.java @@ -1,10 +1,13 @@ package com.youlai.mall.product.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.youlai.common.web.exception.BusinessException; import com.youlai.mall.product.mapper.AttrMapper; import com.youlai.mall.product.model.entity.Attr; import com.youlai.mall.product.model.vo.AttrGroupVO; import com.youlai.mall.product.service.AttrService; +import com.youlai.mall.product.service.SpuAttrValueService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,6 +23,8 @@ import java.util.List; @RequiredArgsConstructor public class AttrServiceImpl extends ServiceImpl implements AttrService { + private final SpuAttrValueService spuAttrValueService; + /** * 根据分类ID获取基础属性列表 * @@ -30,4 +35,23 @@ public class AttrServiceImpl extends ServiceImpl implements At return this.baseMapper.listAttrsByCategoryId(categoryId); } + /** + * 根据分组ID删除属性 + * + * @param groupId 分组ID + */ + @Override + public void removeByGroupId(Long groupId) { + List attrList = this.list(new LambdaQueryWrapper().eq(Attr::getAttrGroupId, groupId)); + + attrList.forEach(attr -> { + // 判断属性是否有商品引用 + boolean isAttrReferenced = spuAttrValueService.isAttrReferenced(attr.getId()); + if (isAttrReferenced) { + throw new BusinessException( "属性【{}】已被商品引用,无法删除"); + } + this.removeById(attr.getId()); + }); + } + } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/CategoryServiceImpl.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/CategoryServiceImpl.java index f9ff20848..ce26980e0 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/CategoryServiceImpl.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/CategoryServiceImpl.java @@ -146,7 +146,7 @@ public class CategoryServiceImpl extends ServiceImpl i @Override public CategoryForm getCategoryForm(Long id) { Category entity = this.getById(id); - return categoryConverter.toForm(entity); + return categoryConverter.convertToForm(entity); } /** diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpecServiceImpl.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpecServiceImpl.java index 3cc7abc0e..f083e81e8 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpecServiceImpl.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpecServiceImpl.java @@ -65,7 +65,7 @@ public class SpecServiceImpl extends ServiceImpl implements Sp @Override public SpecForm getSpecFormData(Long id) { Spec entity = this.getById(id); - return specConverter.toForm(entity); + return specConverter.convertToForm(entity); } /** diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuAttrValueServiceImpl.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuAttrValueServiceImpl.java index 2339b1721..b3e263bb5 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuAttrValueServiceImpl.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuAttrValueServiceImpl.java @@ -46,5 +46,17 @@ public class SpuAttrValueServiceImpl extends ServiceImpl() + .eq(SpuAttrValue::getAttrId, attrId)); + return count > 0; + } + } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuServiceImpl.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuServiceImpl.java index 158daa9d7..69005238b 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuServiceImpl.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuServiceImpl.java @@ -91,7 +91,7 @@ public class SpuServiceImpl extends ServiceImpl implements SpuSe Spu spu = this.getById(spuId); Assert.isTrue(spu != null, "商品不存在"); - SpuForm spuForm = spuConverter.toForm(spu); + SpuForm spuForm = spuConverter.convertToForm(spu); // 商品图片 List imageList = spuImageService.list(new LambdaQueryWrapper() diff --git a/mall-product/product-boot/src/main/resources/mapper/AttrMapper.xml b/mall-product/product-boot/src/main/resources/mapper/AttrMapper.xml index cf9b8e2a3..9029e174a 100644 --- a/mall-product/product-boot/src/main/resources/mapper/AttrMapper.xml +++ b/mall-product/product-boot/src/main/resources/mapper/AttrMapper.xml @@ -25,7 +25,7 @@ - diff --git a/mall-sales/sales-boot/src/main/java/com/youlai/mall/sms/converter/CouponConverter.java b/mall-sales/sales-boot/src/main/java/com/youlai/mall/sms/converter/CouponConverter.java index e45768d39..bd3f29c55 100644 --- a/mall-sales/sales-boot/src/main/java/com/youlai/mall/sms/converter/CouponConverter.java +++ b/mall-sales/sales-boot/src/main/java/com/youlai/mall/sms/converter/CouponConverter.java @@ -44,5 +44,5 @@ public interface CouponConverter { @Mappings({ @Mapping(target = "discount",expression = "java(cn.hutool.core.util.NumberUtil.mul(entity.getDiscount(),10L))"), }) - CouponForm toForm(Coupon entity); + CouponForm convertToForm(Coupon entity); } \ No newline at end of file diff --git a/mall-sales/sales-boot/src/main/java/com/youlai/mall/sms/service/impl/CouponServiceImpl.java b/mall-sales/sales-boot/src/main/java/com/youlai/mall/sms/service/impl/CouponServiceImpl.java index b524170dc..7ccb3c410 100644 --- a/mall-sales/sales-boot/src/main/java/com/youlai/mall/sms/service/impl/CouponServiceImpl.java +++ b/mall-sales/sales-boot/src/main/java/com/youlai/mall/sms/service/impl/CouponServiceImpl.java @@ -70,7 +70,7 @@ public class CouponServiceImpl extends ServiceImpl impleme public CouponForm getCouponFormData(Long couponId) { Coupon entity = this.getById(couponId); // 实体转换entity->form - CouponForm couponForm = couponConverter.toForm(entity); + CouponForm couponForm = couponConverter.convertToForm(entity); Integer applicationScope = couponForm.getApplicationScope(); diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/DuplicateSubmitAspect.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/DuplicateSubmitAspect.java index 2de16c4a7..69a304d49 100644 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/DuplicateSubmitAspect.java +++ b/youlai-common/common-web/src/main/java/com/youlai/common/web/aspect/DuplicateSubmitAspect.java @@ -4,7 +4,7 @@ import cn.hutool.core.util.StrUtil; import com.youlai.common.result.ResultCode; import com.youlai.common.security.util.SecurityUtils; import com.youlai.common.web.annotation.PreventDuplicateResubmit; -import com.youlai.common.web.exception.BizException; +import com.youlai.common.web.exception.BusinessException; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -56,7 +56,7 @@ public class DuplicateSubmitAspect { RLock lock = redissonClient.getLock(resubmitLockKey); boolean lockResult = lock.tryLock(0, expire, TimeUnit.SECONDS); // 获取锁失败,直接返回 false if (!lockResult) { - throw new BizException(ResultCode.REPEAT_SUBMIT_ERROR); // 抛出重复提交提示信息 + throw new BusinessException(ResultCode.REPEAT_SUBMIT_ERROR); // 抛出重复提交提示信息 } } return pjp.proceed(); diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BizException.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BizException.java deleted file mode 100644 index b17981fb5..000000000 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BizException.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.youlai.common.web.exception; - -import com.youlai.common.result.IResultCode; -import lombok.Getter; - -/** - * 自定义业务异常 - * - * @author Ray - * @since 2022/7/31 - */ -@Getter -public class BizException extends RuntimeException { - - public IResultCode resultCode; - - public BizException(IResultCode errorCode) { - super(errorCode.getMsg()); - this.resultCode = errorCode; - } - - public BizException(String message){ - super(message); - } - - public BizException(String message, Throwable cause){ - super(message, cause); - } - - public BizException(Throwable cause){ - super(cause); - } - - -} diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BusinessException.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BusinessException.java new file mode 100644 index 000000000..9423d3bee --- /dev/null +++ b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/BusinessException.java @@ -0,0 +1,43 @@ +package com.youlai.common.web.exception; + +import com.youlai.common.result.IResultCode; +import lombok.Getter; +import org.slf4j.helpers.MessageFormatter; + +/** + * 自定义业务异常 + * + * @author Ray + * @since 2022/7/31 + */ +@Getter +public class BusinessException extends RuntimeException { + + public IResultCode resultCode; + + public BusinessException(IResultCode errorCode) { + super(errorCode.getMsg()); + this.resultCode = errorCode; + } + + public BusinessException(String message) { + super(message); + } + + public BusinessException(String message, Throwable cause) { + super(message, cause); + } + + public BusinessException(Throwable cause) { + super(cause); + } + + + public BusinessException(String message, Object... args) { + super(formatMessage(message, args)); + } + + private static String formatMessage(String message, Object... args) { + return MessageFormatter.arrayFormat(message, args).getMessage(); + } +} diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java index c62c81bc8..3eaca6894 100644 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java +++ b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java @@ -190,8 +190,8 @@ public class GlobalExceptionHandler { @ResponseStatus(HttpStatus.BAD_REQUEST) - @ExceptionHandler(BizException.class) - public Result handleBizException(BizException e) { + @ExceptionHandler(BusinessException.class) + public Result handleBizException(BusinessException e) { log.error("biz exception:{}", e.getMessage(), e); if (e.getResultCode() != null) { return Result.failed(e.getResultCode()); diff --git a/youlai-common/common-web/src/main/resources/templates/converter.java.vm b/youlai-common/common-web/src/main/resources/templates/converter.java.vm index 93f973817..d2683686e 100644 --- a/youlai-common/common-web/src/main/resources/templates/converter.java.vm +++ b/youlai-common/common-web/src/main/resources/templates/converter.java.vm @@ -23,8 +23,8 @@ public interface ${entity}Converter{ Page<${entity}PageVO> toPageVo(Page<${entity}BO> bo); - ${entity}Form toForm(${entity} entity); + ${entity}Form convertToForm(${entity} entity); - @InheritInverseConfiguration(name = "toForm") + @InheritInverseConfiguration(name = "convertToForm") ${entity} toEntity(${entity}Form entity); } \ No newline at end of file diff --git a/youlai-common/common-web/src/main/resources/templates/serviceImpl.java.vm b/youlai-common/common-web/src/main/resources/templates/serviceImpl.java.vm index 23876147a..fb1b27250 100644 --- a/youlai-common/common-web/src/main/resources/templates/serviceImpl.java.vm +++ b/youlai-common/common-web/src/main/resources/templates/serviceImpl.java.vm @@ -68,7 +68,7 @@ public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.m @Override public ${entity}Form get${entity}FormData(Long id) { ${entity} entity = this.getById(id); - return ${firstCharLowerCaseEntity}Converter.toForm(entity); + return ${firstCharLowerCaseEntity}Converter.convertToForm(entity); } /** diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DeptConverter.java b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DeptConverter.java index ba389ff07..f150d3484 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DeptConverter.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DeptConverter.java @@ -14,9 +14,9 @@ import org.mapstruct.Mapper; @Mapper(componentModel = "spring") public interface DeptConverter { - DeptForm toForm(SysDept entity); + DeptForm convertToForm(SysDept entity); DeptVO entity2Vo(SysDept entity); - SysDept toForm(DeptForm deptForm); + SysDept convertToForm(DeptForm deptForm); } \ No newline at end of file diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DictConverter.java b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DictConverter.java index 30831bb44..cdd422e0b 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DictConverter.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DictConverter.java @@ -18,8 +18,8 @@ public interface DictConverter { Page entity2Page(Page page); - DictForm toForm(SysDict entity); + DictForm convertToForm(SysDict entity); - @InheritInverseConfiguration(name="toForm") + @InheritInverseConfiguration(name="convertToForm") SysDict toEntity(DictForm entity); } diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DictTypeConverter.java b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DictTypeConverter.java index 562d586b9..94533839a 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DictTypeConverter.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/DictTypeConverter.java @@ -17,7 +17,7 @@ public interface DictTypeConverter { Page entity2Page(Page page); - DictTypeForm toForm(SysDictType entity); + DictTypeForm convertToForm(SysDictType entity); SysDictType toEntity(DictTypeForm entity); } diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/MenuConverter.java b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/MenuConverter.java index 365371957..123d50f88 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/MenuConverter.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/MenuConverter.java @@ -18,7 +18,7 @@ public interface MenuConverter { MenuVO entity2Vo(SysMenu entity); @Mapping(target = "params", ignore = true) - MenuForm toForm(SysMenu entity); + MenuForm convertToForm(SysMenu entity); @Mapping(target = "params", ignore = true) SysMenu toEntity(MenuForm menuForm); diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/RoleConverter.java b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/RoleConverter.java index 62e183f4c..1afe65ba0 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/RoleConverter.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/RoleConverter.java @@ -33,5 +33,5 @@ public interface RoleConverter { SysRole toEntity(RoleForm roleForm); - RoleForm toForm(SysRole entity); + RoleForm convertToForm(SysRole entity); } \ No newline at end of file diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/UserConverter.java b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/UserConverter.java index 7cebde267..a40c1e323 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/converter/UserConverter.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/converter/UserConverter.java @@ -33,9 +33,9 @@ public interface UserConverter { UserForm bo2Form(UserFormBO bo); - UserForm toForm(SysUser entity); + UserForm convertToForm(SysUser entity); - @InheritInverseConfiguration(name = "toForm") + @InheritInverseConfiguration(name = "convertToForm") SysUser toEntity(UserForm entity); @Mappings({ diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDeptServiceImpl.java b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDeptServiceImpl.java index 0a17be399..cbe300b5d 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDeptServiceImpl.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDeptServiceImpl.java @@ -127,7 +127,7 @@ public class SysDeptServiceImpl extends ServiceImpl impl */ @Override public Long saveDept(DeptForm formData) { - SysDept entity = deptConverter.toForm(formData); + SysDept entity = deptConverter.convertToForm(formData); // 部门层级路径 String treePath = buildTreePath(formData.getParentId()); entity.setTreePath(treePath); @@ -198,7 +198,7 @@ public class SysDeptServiceImpl extends ServiceImpl impl SysDept::getSort )); - return deptConverter.toForm(entity); + return deptConverter.convertToForm(entity); } diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDictServiceImpl.java b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDictServiceImpl.java index 28cb83be2..55dbdb5ee 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDictServiceImpl.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDictServiceImpl.java @@ -85,7 +85,7 @@ public class SysDictServiceImpl extends ServiceImpl impl Assert.isTrue(entity != null, "字典数据项不存在"); // 实体转换 - DictForm dictForm = dictConverter.toForm(entity); + DictForm dictForm = dictConverter.convertToForm(entity); return dictForm; } diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDictTypeServiceImpl.java b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDictTypeServiceImpl.java index f62c7d410..ebaafc71c 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDictTypeServiceImpl.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysDictTypeServiceImpl.java @@ -94,7 +94,7 @@ public class SysDictTypeServiceImpl extends ServiceImpl impl public MenuForm getMenuForm(Long id) { SysMenu entity = this.getById(id); Assert.isTrue(entity != null, "菜单不存在"); - MenuForm formData = menuConverter.toForm(entity); + MenuForm formData = menuConverter.convertToForm(entity); // 路由参数字符串 {"id":"1","name":"张三"} 转换为 [{key:"id", value:"1"}, {key:"name", value:"张三"}] String params = entity.getParams(); if (StrUtil.isNotBlank(params)) { diff --git a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysRoleServiceImpl.java b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysRoleServiceImpl.java index 6c6547c3e..3cfe69283 100644 --- a/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysRoleServiceImpl.java +++ b/youlai-system/system-boot/src/main/java/com/youlai/system/service/impl/SysRoleServiceImpl.java @@ -142,7 +142,7 @@ public class SysRoleServiceImpl extends ServiceImpl impl @Override public RoleForm getRoleForm(Long roleId) { SysRole entity = this.getById(roleId); - return roleConverter.toForm(entity); + return roleConverter.convertToForm(entity); } /**