mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-03 17:42:20 +08:00
wip: 重构临时提交
This commit is contained in:
parent
fa8ef2e61b
commit
e990c1fc77
@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.youlai.common.result.ResultCode;
|
import com.youlai.common.result.ResultCode;
|
||||||
import com.youlai.common.security.util.SecurityUtils;
|
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.AddressConvert;
|
||||||
import com.youlai.mall.member.convert.MemberConvert;
|
import com.youlai.mall.member.convert.MemberConvert;
|
||||||
import com.youlai.mall.member.dto.MemberAddressDTO;
|
import com.youlai.mall.member.dto.MemberAddressDTO;
|
||||||
@ -76,7 +76,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
throw new BizException(ResultCode.USER_NOT_EXIST);
|
throw new BusinessException(ResultCode.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
return memberConvert.entity2OpenidAuthDTO(entity);
|
return memberConvert.entity2OpenidAuthDTO(entity);
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> impleme
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
throw new BizException(ResultCode.USER_NOT_EXIST);
|
throw new BusinessException(ResultCode.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
return memberConvert.entity2MobileAuthDTO(entity);
|
return memberConvert.entity2MobileAuthDTO(entity);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package com.youlai.mall.order.service.impl;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
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.constant.RedisConstants;
|
||||||
import com.youlai.common.rabbitmq.constant.RabbitMqConstants;
|
import com.youlai.common.rabbitmq.constant.RabbitMqConstants;
|
||||||
import com.youlai.common.security.util.SecurityUtils;
|
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.config.property.WxPayProperties;
|
||||||
import com.youlai.mall.order.converter.OrderConverter;
|
import com.youlai.mall.order.converter.OrderConverter;
|
||||||
import com.youlai.mall.order.enums.ApprovalStatusEnum;
|
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.CartItemDTO;
|
||||||
import com.youlai.mall.member.dto.MemberAddressDTO;
|
import com.youlai.mall.member.dto.MemberAddressDTO;
|
||||||
import io.seata.spring.annotation.GlobalTransactional;
|
import io.seata.spring.annotation.GlobalTransactional;
|
||||||
import io.seata.spring.util.OrderUtil;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.redisson.api.RLock;
|
import org.redisson.api.RLock;
|
||||||
@ -376,7 +374,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
|
|||||||
refundResult = wxPayService.refund(request);
|
refundResult = wxPayService.refund(request);
|
||||||
} catch (WxPayException e) {
|
} catch (WxPayException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
throw new BizException("订单(" + order.getOrderNo() + ")退款失败");
|
throw new BusinessException("订单(" + order.getOrderNo() + ")退款失败");
|
||||||
}
|
}
|
||||||
if (WxPayConstants.ResultCode.SUCCESS.equals(refundResult.getResultCode())) {
|
if (WxPayConstants.ResultCode.SUCCESS.equals(refundResult.getResultCode())) {
|
||||||
order.setStatus(OrderStatusEnum.REFUND_PENDING.getValue());
|
order.setStatus(OrderStatusEnum.REFUND_PENDING.getValue());
|
||||||
@ -433,7 +431,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
|
|||||||
wxPayService.closeOrderV3(orderNo);
|
wxPayService.closeOrderV3(orderNo);
|
||||||
} catch (WxPayException e) {
|
} catch (WxPayException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
throw new BizException("微信关单异常");
|
throw new BusinessException("微信关单异常");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,7 +461,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OmsOrder> impleme
|
|||||||
jsapiResult = wxPayService.createOrderV3(TradeTypeEnum.JSAPI, wxRequest);
|
jsapiResult = wxPayService.createOrderV3(TradeTypeEnum.JSAPI, wxRequest);
|
||||||
} catch (WxPayException e) {
|
} catch (WxPayException e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
throw new BizException("微信统一下单异常");
|
throw new BusinessException("微信统一下单异常");
|
||||||
}
|
}
|
||||||
return jsapiResult;
|
return jsapiResult;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/attributes")
|
@RequestMapping("/api/v1/attributes")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class AttributeController {
|
public class AttrController {
|
||||||
|
|
||||||
private final AttrGroupService attrGroupService;
|
private final AttrGroupService attrGroupService;
|
||||||
|
|
@ -11,8 +11,8 @@ import java.util.List;
|
|||||||
@Mapper(componentModel = "spring")
|
@Mapper(componentModel = "spring")
|
||||||
public interface AttrConverter {
|
public interface AttrConverter {
|
||||||
|
|
||||||
AttrForm toForm(Attr entity);
|
AttrForm convertToForm(Attr entity);
|
||||||
List<AttrGroupForm.Attr> toForm(List<Attr> entity);
|
List<AttrGroupForm.Attr> convertToForm(List<Attr> entity);
|
||||||
|
|
||||||
Attr convertToEntity(AttrGroupForm.Attr attr);
|
Attr convertToEntity(AttrGroupForm.Attr attr);
|
||||||
List<Attr> convertToEntity(List<AttrGroupForm.Attr> attrs);
|
List<Attr> convertToEntity(List<AttrGroupForm.Attr> attrs);
|
||||||
|
@ -16,8 +16,8 @@ public interface AttrGroupConverter {
|
|||||||
|
|
||||||
Page<AttrGroupPageVO> toPageVo(Page<AttrGroupBO> bo);
|
Page<AttrGroupPageVO> toPageVo(Page<AttrGroupBO> bo);
|
||||||
|
|
||||||
AttrGroupForm toForm(AttrGroup entity);
|
AttrGroupForm convertToForm(AttrGroup entity);
|
||||||
|
|
||||||
@InheritInverseConfiguration(name = "toForm")
|
@InheritInverseConfiguration(name = "convertToForm")
|
||||||
AttrGroup toEntity(AttrGroupForm entity);
|
AttrGroup toEntity(AttrGroupForm entity);
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ import org.mapstruct.Mappings;
|
|||||||
|
|
||||||
@Mapper(componentModel = "spring")
|
@Mapper(componentModel = "spring")
|
||||||
public interface CategoryConverter {
|
public interface CategoryConverter {
|
||||||
CategoryForm toForm(Category entity);
|
CategoryForm convertToForm(Category entity);
|
||||||
|
|
||||||
Category toEntity(CategoryForm formData);
|
Category toEntity(CategoryForm formData);
|
||||||
|
|
||||||
|
@ -26,5 +26,5 @@ public interface SkuConverter {
|
|||||||
Sku toEntity(SpuForm.Sku skuForm);
|
Sku toEntity(SpuForm.Sku skuForm);
|
||||||
|
|
||||||
|
|
||||||
SpuForm.Sku toForm(SkuBO bo);
|
SpuForm.Sku convertToForm(SkuBO bo);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public interface SpecConverter {
|
|||||||
|
|
||||||
Page<SpecPageVO> toPageVo(Page<SpecBO> bo);
|
Page<SpecPageVO> toPageVo(Page<SpecBO> bo);
|
||||||
|
|
||||||
SpecForm toForm(Spec entity);
|
SpecForm convertToForm(Spec entity);
|
||||||
|
|
||||||
Spec toEntity(SpecForm formData);
|
Spec toEntity(SpecForm formData);
|
||||||
}
|
}
|
@ -17,5 +17,5 @@ public interface SpuConverter {
|
|||||||
Spu toEntity(SpuForm form);
|
Spu toEntity(SpuForm form);
|
||||||
|
|
||||||
|
|
||||||
SpuForm toForm(Spu spu);
|
SpuForm convertToForm(Spu spu);
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,7 @@ package com.youlai.mall.product.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.youlai.mall.product.model.entity.Attr;
|
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.AttrGroupVO;
|
||||||
import com.youlai.mall.product.model.vo.AttrVO;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -22,4 +20,11 @@ public interface AttrService extends IService<Attr> {
|
|||||||
* @param categoryId 分类ID
|
* @param categoryId 分类ID
|
||||||
*/
|
*/
|
||||||
List<AttrGroupVO> listAttrsByCategoryId(Long categoryId);
|
List<AttrGroupVO> listAttrsByCategoryId(Long categoryId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分组ID删除属性
|
||||||
|
*
|
||||||
|
* @param groupId 分组ID
|
||||||
|
*/
|
||||||
|
void removeByGroupId(Long groupId);
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,15 @@ public interface SpuAttrValueService extends IService<SpuAttrValue> {
|
|||||||
/**
|
/**
|
||||||
* 保存商品属性
|
* 保存商品属性
|
||||||
*
|
*
|
||||||
* @param spuId SPU ID
|
* @param spuId SPU ID
|
||||||
* @param attrValues 属性列表
|
* @param attrValues 属性列表
|
||||||
*/
|
*/
|
||||||
void saveAttributeValues(Long spuId, List<SpuForm.AttrValue> attrValues);
|
void saveAttributeValues(Long spuId, List<SpuForm.AttrValue> attrValues);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断属性是否有商品引用
|
||||||
|
*
|
||||||
|
* @param attrId 属性ID
|
||||||
|
*/
|
||||||
|
boolean isAttrReferenced(Long attrId);
|
||||||
}
|
}
|
||||||
|
@ -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.model.vo.AttrGroupPageVO;
|
||||||
import com.youlai.mall.product.service.AttrGroupService;
|
import com.youlai.mall.product.service.AttrGroupService;
|
||||||
import com.youlai.mall.product.service.AttrService;
|
import com.youlai.mall.product.service.AttrService;
|
||||||
|
import com.youlai.mall.product.service.SpuAttrValueService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -38,6 +40,8 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupMapper, AttrGroup
|
|||||||
|
|
||||||
private final AttrConverter attrConverter;
|
private final AttrConverter attrConverter;
|
||||||
|
|
||||||
|
private final SpuAttrValueService spuAttrValueService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取属性组分页列表
|
* 获取属性组分页列表
|
||||||
*
|
*
|
||||||
@ -82,13 +86,13 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupMapper, AttrGroup
|
|||||||
AttrGroup attrGroup = this.getById(groupId);
|
AttrGroup attrGroup = this.getById(groupId);
|
||||||
Assert.isTrue(attrGroup != null, "属性组不存在");
|
Assert.isTrue(attrGroup != null, "属性组不存在");
|
||||||
|
|
||||||
AttrGroupForm attrGroupForm = attrGroupConverter.toForm(attrGroup);
|
AttrGroupForm attrGroupForm = attrGroupConverter.convertToForm(attrGroup);
|
||||||
|
|
||||||
// 属性列表
|
// 属性列表
|
||||||
List<Attr> attrEntities = attrService.list(new LambdaQueryWrapper<Attr>()
|
List<Attr> attrEntities = attrService.list(new LambdaQueryWrapper<Attr>()
|
||||||
.eq(Attr::getAttrGroupId, groupId)
|
.eq(Attr::getAttrGroupId, groupId)
|
||||||
);
|
);
|
||||||
List<AttrGroupForm.Attr> attrList = attrConverter.toForm(attrEntities);
|
List<AttrGroupForm.Attr> attrList = attrConverter.convertToForm(attrEntities);
|
||||||
attrGroupForm.setAttrs(attrList);
|
attrGroupForm.setAttrs(attrList);
|
||||||
|
|
||||||
return attrGroupForm;
|
return attrGroupForm;
|
||||||
@ -156,9 +160,9 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupMapper, AttrGroup
|
|||||||
* @param ids 属性组ID,多个以英文逗号(,)分割
|
* @param ids 属性组ID,多个以英文逗号(,)分割
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional
|
||||||
public void deleteAttrGroups(String ids) {
|
public void deleteAttrGroups(String ids) {
|
||||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的属性组数据为空");
|
Assert.isTrue(StrUtil.isNotBlank(ids), "请选择需要删除的属性组");
|
||||||
// 逻辑删除
|
|
||||||
List<Long> idList = Arrays.stream(ids.split(","))
|
List<Long> idList = Arrays.stream(ids.split(","))
|
||||||
.map(Long::parseLong)
|
.map(Long::parseLong)
|
||||||
.toList();
|
.toList();
|
||||||
@ -167,9 +171,7 @@ public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupMapper, AttrGroup
|
|||||||
boolean result = this.removeById(groupId);
|
boolean result = this.removeById(groupId);
|
||||||
if (result) {
|
if (result) {
|
||||||
// 删除属性组下的属性
|
// 删除属性组下的属性
|
||||||
attrService.remove(
|
attrService.removeByGroupId(groupId);
|
||||||
new LambdaQueryWrapper<Attr>().eq(Attr::getAttrGroupId, groupId)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package com.youlai.mall.product.service.impl;
|
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.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.mapper.AttrMapper;
|
||||||
import com.youlai.mall.product.model.entity.Attr;
|
import com.youlai.mall.product.model.entity.Attr;
|
||||||
import com.youlai.mall.product.model.vo.AttrGroupVO;
|
import com.youlai.mall.product.model.vo.AttrGroupVO;
|
||||||
import com.youlai.mall.product.service.AttrService;
|
import com.youlai.mall.product.service.AttrService;
|
||||||
|
import com.youlai.mall.product.service.SpuAttrValueService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -20,6 +23,8 @@ import java.util.List;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class AttrServiceImpl extends ServiceImpl<AttrMapper, Attr> implements AttrService {
|
public class AttrServiceImpl extends ServiceImpl<AttrMapper, Attr> implements AttrService {
|
||||||
|
|
||||||
|
private final SpuAttrValueService spuAttrValueService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据分类ID获取基础属性列表
|
* 根据分类ID获取基础属性列表
|
||||||
*
|
*
|
||||||
@ -30,4 +35,23 @@ public class AttrServiceImpl extends ServiceImpl<AttrMapper, Attr> implements At
|
|||||||
return this.baseMapper.listAttrsByCategoryId(categoryId);
|
return this.baseMapper.listAttrsByCategoryId(categoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分组ID删除属性
|
||||||
|
*
|
||||||
|
* @param groupId 分组ID
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void removeByGroupId(Long groupId) {
|
||||||
|
List<Attr> attrList = this.list(new LambdaQueryWrapper<Attr>().eq(Attr::getAttrGroupId, groupId));
|
||||||
|
|
||||||
|
attrList.forEach(attr -> {
|
||||||
|
// 判断属性是否有商品引用
|
||||||
|
boolean isAttrReferenced = spuAttrValueService.isAttrReferenced(attr.getId());
|
||||||
|
if (isAttrReferenced) {
|
||||||
|
throw new BusinessException( "属性【{}】已被商品引用,无法删除");
|
||||||
|
}
|
||||||
|
this.removeById(attr.getId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> i
|
|||||||
@Override
|
@Override
|
||||||
public CategoryForm getCategoryForm(Long id) {
|
public CategoryForm getCategoryForm(Long id) {
|
||||||
Category entity = this.getById(id);
|
Category entity = this.getById(id);
|
||||||
return categoryConverter.toForm(entity);
|
return categoryConverter.convertToForm(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,7 +65,7 @@ public class SpecServiceImpl extends ServiceImpl<SpecMapper, Spec> implements Sp
|
|||||||
@Override
|
@Override
|
||||||
public SpecForm getSpecFormData(Long id) {
|
public SpecForm getSpecFormData(Long id) {
|
||||||
Spec entity = this.getById(id);
|
Spec entity = this.getById(id);
|
||||||
return specConverter.toForm(entity);
|
return specConverter.convertToForm(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,5 +46,17 @@ public class SpuAttrValueServiceImpl extends ServiceImpl<SpuAttrValueMapper, Spu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断属性是否有商品引用
|
||||||
|
*
|
||||||
|
* @param attrId 属性ID
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isAttrReferenced(Long attrId) {
|
||||||
|
long count = this.count(new LambdaQueryWrapper<SpuAttrValue>()
|
||||||
|
.eq(SpuAttrValue::getAttrId, attrId));
|
||||||
|
return count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu> implements SpuSe
|
|||||||
Spu spu = this.getById(spuId);
|
Spu spu = this.getById(spuId);
|
||||||
Assert.isTrue(spu != null, "商品不存在");
|
Assert.isTrue(spu != null, "商品不存在");
|
||||||
|
|
||||||
SpuForm spuForm = spuConverter.toForm(spu);
|
SpuForm spuForm = spuConverter.convertToForm(spu);
|
||||||
|
|
||||||
// 商品图片
|
// 商品图片
|
||||||
List<SpuForm.Image> imageList = spuImageService.list(new LambdaQueryWrapper<SpuImage>()
|
List<SpuForm.Image> imageList = spuImageService.list(new LambdaQueryWrapper<SpuImage>()
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
<resultMap id="AttributeGroupMap" type="com.youlai.mall.product.model.vo.AttrGroupVO">
|
<resultMap id="AttributeGroupMap" type="com.youlai.mall.product.model.vo.AttrGroupVO">
|
||||||
<result column="attr_group_id" property="groupId"/>
|
<result column="attr_group_id" property="groupId"/>
|
||||||
<result column="attribute_group_name" property="groupName"/>
|
<result column="attribute_group_name" property="groupName"/>
|
||||||
<collection property="attributes"
|
<collection property="attrs"
|
||||||
ofType="com.youlai.mall.product.model.vo.AttrVO"
|
ofType="com.youlai.mall.product.model.vo.AttrVO"
|
||||||
javaType="java.util.List"
|
javaType="java.util.List"
|
||||||
>
|
>
|
||||||
|
@ -44,5 +44,5 @@ public interface CouponConverter {
|
|||||||
@Mappings({
|
@Mappings({
|
||||||
@Mapping(target = "discount",expression = "java(cn.hutool.core.util.NumberUtil.mul(entity.getDiscount(),10L))"),
|
@Mapping(target = "discount",expression = "java(cn.hutool.core.util.NumberUtil.mul(entity.getDiscount(),10L))"),
|
||||||
})
|
})
|
||||||
CouponForm toForm(Coupon entity);
|
CouponForm convertToForm(Coupon entity);
|
||||||
}
|
}
|
@ -70,7 +70,7 @@ public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> impleme
|
|||||||
public CouponForm getCouponFormData(Long couponId) {
|
public CouponForm getCouponFormData(Long couponId) {
|
||||||
Coupon entity = this.getById(couponId);
|
Coupon entity = this.getById(couponId);
|
||||||
// 实体转换entity->form
|
// 实体转换entity->form
|
||||||
CouponForm couponForm = couponConverter.toForm(entity);
|
CouponForm couponForm = couponConverter.convertToForm(entity);
|
||||||
|
|
||||||
Integer applicationScope = couponForm.getApplicationScope();
|
Integer applicationScope = couponForm.getApplicationScope();
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import com.youlai.common.result.ResultCode;
|
import com.youlai.common.result.ResultCode;
|
||||||
import com.youlai.common.security.util.SecurityUtils;
|
import com.youlai.common.security.util.SecurityUtils;
|
||||||
import com.youlai.common.web.annotation.PreventDuplicateResubmit;
|
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 jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -56,7 +56,7 @@ public class DuplicateSubmitAspect {
|
|||||||
RLock lock = redissonClient.getLock(resubmitLockKey);
|
RLock lock = redissonClient.getLock(resubmitLockKey);
|
||||||
boolean lockResult = lock.tryLock(0, expire, TimeUnit.SECONDS); // 获取锁失败,直接返回 false
|
boolean lockResult = lock.tryLock(0, expire, TimeUnit.SECONDS); // 获取锁失败,直接返回 false
|
||||||
if (!lockResult) {
|
if (!lockResult) {
|
||||||
throw new BizException(ResultCode.REPEAT_SUBMIT_ERROR); // 抛出重复提交提示信息
|
throw new BusinessException(ResultCode.REPEAT_SUBMIT_ERROR); // 抛出重复提交提示信息
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pjp.proceed();
|
return pjp.proceed();
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -190,8 +190,8 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
|
|
||||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
@ExceptionHandler(BizException.class)
|
@ExceptionHandler(BusinessException.class)
|
||||||
public <T> Result<T> handleBizException(BizException e) {
|
public <T> Result<T> handleBizException(BusinessException e) {
|
||||||
log.error("biz exception:{}", e.getMessage(), e);
|
log.error("biz exception:{}", e.getMessage(), e);
|
||||||
if (e.getResultCode() != null) {
|
if (e.getResultCode() != null) {
|
||||||
return Result.failed(e.getResultCode());
|
return Result.failed(e.getResultCode());
|
||||||
|
@ -23,8 +23,8 @@ public interface ${entity}Converter{
|
|||||||
|
|
||||||
Page<${entity}PageVO> toPageVo(Page<${entity}BO> bo);
|
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);
|
${entity} toEntity(${entity}Form entity);
|
||||||
}
|
}
|
@ -68,7 +68,7 @@ public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.m
|
|||||||
@Override
|
@Override
|
||||||
public ${entity}Form get${entity}FormData(Long id) {
|
public ${entity}Form get${entity}FormData(Long id) {
|
||||||
${entity} entity = this.getById(id);
|
${entity} entity = this.getById(id);
|
||||||
return ${firstCharLowerCaseEntity}Converter.toForm(entity);
|
return ${firstCharLowerCaseEntity}Converter.convertToForm(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,9 +14,9 @@ import org.mapstruct.Mapper;
|
|||||||
@Mapper(componentModel = "spring")
|
@Mapper(componentModel = "spring")
|
||||||
public interface DeptConverter {
|
public interface DeptConverter {
|
||||||
|
|
||||||
DeptForm toForm(SysDept entity);
|
DeptForm convertToForm(SysDept entity);
|
||||||
DeptVO entity2Vo(SysDept entity);
|
DeptVO entity2Vo(SysDept entity);
|
||||||
|
|
||||||
SysDept toForm(DeptForm deptForm);
|
SysDept convertToForm(DeptForm deptForm);
|
||||||
|
|
||||||
}
|
}
|
@ -18,8 +18,8 @@ public interface DictConverter {
|
|||||||
|
|
||||||
Page<DictPageVO> entity2Page(Page<SysDict> page);
|
Page<DictPageVO> entity2Page(Page<SysDict> page);
|
||||||
|
|
||||||
DictForm toForm(SysDict entity);
|
DictForm convertToForm(SysDict entity);
|
||||||
|
|
||||||
@InheritInverseConfiguration(name="toForm")
|
@InheritInverseConfiguration(name="convertToForm")
|
||||||
SysDict toEntity(DictForm entity);
|
SysDict toEntity(DictForm entity);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public interface DictTypeConverter {
|
|||||||
|
|
||||||
Page<DictTypePageVO> entity2Page(Page<SysDictType> page);
|
Page<DictTypePageVO> entity2Page(Page<SysDictType> page);
|
||||||
|
|
||||||
DictTypeForm toForm(SysDictType entity);
|
DictTypeForm convertToForm(SysDictType entity);
|
||||||
|
|
||||||
SysDictType toEntity(DictTypeForm entity);
|
SysDictType toEntity(DictTypeForm entity);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public interface MenuConverter {
|
|||||||
MenuVO entity2Vo(SysMenu entity);
|
MenuVO entity2Vo(SysMenu entity);
|
||||||
|
|
||||||
@Mapping(target = "params", ignore = true)
|
@Mapping(target = "params", ignore = true)
|
||||||
MenuForm toForm(SysMenu entity);
|
MenuForm convertToForm(SysMenu entity);
|
||||||
|
|
||||||
@Mapping(target = "params", ignore = true)
|
@Mapping(target = "params", ignore = true)
|
||||||
SysMenu toEntity(MenuForm menuForm);
|
SysMenu toEntity(MenuForm menuForm);
|
||||||
|
@ -33,5 +33,5 @@ public interface RoleConverter {
|
|||||||
|
|
||||||
SysRole toEntity(RoleForm roleForm);
|
SysRole toEntity(RoleForm roleForm);
|
||||||
|
|
||||||
RoleForm toForm(SysRole entity);
|
RoleForm convertToForm(SysRole entity);
|
||||||
}
|
}
|
@ -33,9 +33,9 @@ public interface UserConverter {
|
|||||||
|
|
||||||
UserForm bo2Form(UserFormBO bo);
|
UserForm bo2Form(UserFormBO bo);
|
||||||
|
|
||||||
UserForm toForm(SysUser entity);
|
UserForm convertToForm(SysUser entity);
|
||||||
|
|
||||||
@InheritInverseConfiguration(name = "toForm")
|
@InheritInverseConfiguration(name = "convertToForm")
|
||||||
SysUser toEntity(UserForm entity);
|
SysUser toEntity(UserForm entity);
|
||||||
|
|
||||||
@Mappings({
|
@Mappings({
|
||||||
|
@ -127,7 +127,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long saveDept(DeptForm formData) {
|
public Long saveDept(DeptForm formData) {
|
||||||
SysDept entity = deptConverter.toForm(formData);
|
SysDept entity = deptConverter.convertToForm(formData);
|
||||||
// 部门层级路径
|
// 部门层级路径
|
||||||
String treePath = buildTreePath(formData.getParentId());
|
String treePath = buildTreePath(formData.getParentId());
|
||||||
entity.setTreePath(treePath);
|
entity.setTreePath(treePath);
|
||||||
@ -198,7 +198,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
SysDept::getSort
|
SysDept::getSort
|
||||||
));
|
));
|
||||||
|
|
||||||
return deptConverter.toForm(entity);
|
return deptConverter.convertToForm(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
|||||||
Assert.isTrue(entity != null, "字典数据项不存在");
|
Assert.isTrue(entity != null, "字典数据项不存在");
|
||||||
|
|
||||||
// 实体转换
|
// 实体转换
|
||||||
DictForm dictForm = dictConverter.toForm(entity);
|
DictForm dictForm = dictConverter.convertToForm(entity);
|
||||||
return dictForm;
|
return dictForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
|
|||||||
Assert.isTrue(entity != null, "字典类型不存在");
|
Assert.isTrue(entity != null, "字典类型不存在");
|
||||||
|
|
||||||
// 实体转换
|
// 实体转换
|
||||||
DictTypeForm dictTypeForm = dictTypeConverter.toForm(entity);
|
DictTypeForm dictTypeForm = dictTypeConverter.convertToForm(entity);
|
||||||
return dictTypeForm;
|
return dictTypeForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||||||
public MenuForm getMenuForm(Long id) {
|
public MenuForm getMenuForm(Long id) {
|
||||||
SysMenu entity = this.getById(id);
|
SysMenu entity = this.getById(id);
|
||||||
Assert.isTrue(entity != null, "菜单不存在");
|
Assert.isTrue(entity != null, "菜单不存在");
|
||||||
MenuForm formData = menuConverter.toForm(entity);
|
MenuForm formData = menuConverter.convertToForm(entity);
|
||||||
// 路由参数字符串 {"id":"1","name":"张三"} 转换为 [{key:"id", value:"1"}, {key:"name", value:"张三"}]
|
// 路由参数字符串 {"id":"1","name":"张三"} 转换为 [{key:"id", value:"1"}, {key:"name", value:"张三"}]
|
||||||
String params = entity.getParams();
|
String params = entity.getParams();
|
||||||
if (StrUtil.isNotBlank(params)) {
|
if (StrUtil.isNotBlank(params)) {
|
||||||
|
@ -142,7 +142,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||||||
@Override
|
@Override
|
||||||
public RoleForm getRoleForm(Long roleId) {
|
public RoleForm getRoleForm(Long roleId) {
|
||||||
SysRole entity = this.getById(roleId);
|
SysRole entity = this.getById(roleId);
|
||||||
return roleConverter.toForm(entity);
|
return roleConverter.convertToForm(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user