code review:售后详情接口

This commit is contained in:
YunaiV 2023-08-30 20:18:40 +08:00
parent 059202a588
commit 60d4aa97fb
11 changed files with 54 additions and 40 deletions

View File

@ -8,7 +8,6 @@ import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderItemBas
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List; import java.util.List;
@Schema(description = "管理后台 - 售后订单的详情 Response VO") @Schema(description = "管理后台 - 售后订单的详情 Response VO")
@ -16,7 +15,6 @@ import java.util.List;
public class TradeAfterSaleDetailRespVO extends TradeAfterSaleBaseVO { public class TradeAfterSaleDetailRespVO extends TradeAfterSaleBaseVO {
@Schema(description = "售后编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @Schema(description = "售后编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@NotNull(message = "售后编号不能为空")
private Long id; private Long id;
/** /**

View File

@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.trade.controller.admin.delivery;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.pickup.*; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.pickup.*;
import cn.iocoder.yudao.module.trade.convert.delivery.DeliveryPickUpStoreConvert; import cn.iocoder.yudao.module.trade.convert.delivery.DeliveryPickUpStoreConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO;
@ -68,11 +66,9 @@ public class DeliveryPickUpStoreController {
@GetMapping("/list-all-simple") @GetMapping("/list-all-simple")
@Operation(summary = "获得自提门店精简信息列表") @Operation(summary = "获得自提门店精简信息列表")
public CommonResult<List<DeliveryPickUpStoreSimpleRespVO>> getSimpleDeliveryPickUpStoreList() { public CommonResult<List<DeliveryPickUpStoreSimpleRespVO>> getSimpleDeliveryPickUpStoreList() {
List<DeliveryPickUpStoreDO> list = deliveryPickUpStoreService.getDeliveryPickUpStoreListByStatus(CommonStatusEnum.ENABLE.getStatus()); List<DeliveryPickUpStoreDO> list = deliveryPickUpStoreService.getDeliveryPickUpStoreListByStatus(
return success(CollectionUtils.convertList(DeliveryPickUpStoreConvert.INSTANCE.convertList1(list), item -> { CommonStatusEnum.ENABLE.getStatus());
item.setAreaName(AreaUtils.format(item.getAreaId())); return success(DeliveryPickUpStoreConvert.INSTANCE.convertList1(list));
return item;
}));
} }
@GetMapping("/list") @GetMapping("/list")

View File

@ -69,14 +69,7 @@ public interface TradeAfterSaleConvert {
PageResult<AppTradeAfterSaleRespVO> convertPage02(PageResult<TradeAfterSaleDO> page); PageResult<AppTradeAfterSaleRespVO> convertPage02(PageResult<TradeAfterSaleDO> page);
List<TradeAfterSaleLogRespDTO> convertList(List<TradeAfterSaleLogDO> list); List<TradeAfterSaleLogRespDTO> convertList(List<TradeAfterSaleLogDO> list);
List<TradeAfterSaleLogRespVO> convertList1(List<TradeAfterSaleLogRespDTO> list);
TradeOrderBaseVO convert(TradeOrderDO order);
@Mapping(target = "id", source = "afterSale.id")
TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, List<TradeOrderItemDO> orderItems, List<TradeAfterSaleLogRespVO> logs);
default TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, TradeOrderDO order, List<TradeOrderItemDO> orderItems, default TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, TradeOrderDO order, List<TradeOrderItemDO> orderItems,
MemberUserRespDTO user, List<TradeAfterSaleLogRespDTO> logs) { MemberUserRespDTO user, List<TradeAfterSaleLogRespDTO> logs) {
TradeAfterSaleDetailRespVO respVO = convert(afterSale, orderItems, convertList1(logs)); TradeAfterSaleDetailRespVO respVO = convert(afterSale, orderItems, convertList1(logs));
@ -86,4 +79,9 @@ public interface TradeAfterSaleConvert {
respVO.setOrder(convert(order)); respVO.setOrder(convert(order));
return respVO; return respVO;
} }
List<TradeAfterSaleLogRespVO> convertList1(List<TradeAfterSaleLogRespDTO> list);
@Mapping(target = "id", source = "afterSale.id")
TradeAfterSaleDetailRespVO convert(TradeAfterSaleDO afterSale, List<TradeOrderItemDO> orderItems, List<TradeAfterSaleLogRespVO> logs);
TradeOrderBaseVO convert(TradeOrderDO order);
} }

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.pickup.Deliver
import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.pickup.DeliveryPickUpStoreUpdateReqVO; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.pickup.DeliveryPickUpStoreUpdateReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryPickUpStoreDO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named; import org.mapstruct.Named;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -28,10 +29,13 @@ public interface DeliveryPickUpStoreConvert {
PageResult<DeliveryPickUpStoreRespVO> convertPage(PageResult<DeliveryPickUpStoreDO> page); PageResult<DeliveryPickUpStoreRespVO> convertPage(PageResult<DeliveryPickUpStoreDO> page);
@Named("convertAreaIdToName") List<DeliveryPickUpStoreSimpleRespVO> convertList1(List<DeliveryPickUpStoreDO> list);
default String convertAreaIdToName(Integer areaId) { @Mapping(source = "areaId", target = "areaName", qualifiedByName = "convertAreaIdToAreaName")
DeliveryPickUpStoreSimpleRespVO convert02(DeliveryPickUpStoreDO bean);
@Named("convertAreaIdToAreaName")
default String convertAreaIdToAreaName(Integer areaId) {
return AreaUtils.format(areaId); return AreaUtils.format(areaId);
} }
List<DeliveryPickUpStoreSimpleRespVO> convertList1(List<DeliveryPickUpStoreDO> list);
} }

View File

@ -27,6 +27,11 @@ import java.time.LocalDateTime;
@AllArgsConstructor @AllArgsConstructor
public class TradeOrderDO extends BaseDO { public class TradeOrderDO extends BaseDO {
/**
* 发货物流公司编号 - 无需发货
*/
public static final Long LOGISTICS_ID_NULL = 0L;
// ========== 订单基本信息 ========== // ========== 订单基本信息 ==========
/** /**
* 订单编号主键自增 * 订单编号主键自增

View File

@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
// TODO @puhui999这个是不是应该搞成 vo
/** /**
* 贸易售后日志详情 DTO * 贸易售后日志详情 DTO
* *

View File

@ -26,7 +26,7 @@ public interface AfterSaleLogService {
/** /**
* 获取售后日志 * 获取售后日志
* *
* @param afterSaleId 售后 id * @param afterSaleId 售后编号
* @return 售后日志 * @return 售后日志
*/ */
List<TradeAfterSaleLogRespDTO> getLog(Long afterSaleId); List<TradeAfterSaleLogRespDTO> getLog(Long afterSaleId);

View File

@ -91,6 +91,7 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
@Override @Override
public TradeAfterSaleDO getAfterSale(Long id) { public TradeAfterSaleDO getAfterSale(Long id) {
TradeAfterSaleDO afterSale = tradeAfterSaleMapper.selectById(id); TradeAfterSaleDO afterSale = tradeAfterSaleMapper.selectById(id);
// TODO @puhui999读不到不要这里报错哈交给前端报错一般是读取信息不到message 提示然后 close tab
if (afterSale == null) { if (afterSale == null) {
throw exception(AFTER_SALE_NOT_FOUND); throw exception(AFTER_SALE_NOT_FOUND);
} }
@ -457,4 +458,5 @@ public class TradeAfterSaleServiceImpl implements TradeAfterSaleService, AfterSa
List<TradeAfterSaleLogDO> saleLogDOs = tradeAfterSaleLogMapper.selectList(TradeAfterSaleLogDO::getAfterSaleId, afterSaleId); List<TradeAfterSaleLogDO> saleLogDOs = tradeAfterSaleLogMapper.selectList(TradeAfterSaleLogDO::getAfterSaleId, afterSaleId);
return TradeAfterSaleConvert.INSTANCE.convertList(saleLogDOs); return TradeAfterSaleConvert.INSTANCE.convertList(saleLogDOs);
} }
} }

View File

@ -47,6 +47,14 @@ public interface DeliveryExpressService {
*/ */
DeliveryExpressDO getDeliveryExpress(Long id); DeliveryExpressDO getDeliveryExpress(Long id);
/**
* 校验快递公司是否合法
*
* @param id 编号
* @return 快递公司
*/
DeliveryExpressDO validateDeliveryExpress(Long id);
/** /**
* 获得快递公司分页 * 获得快递公司分页
* *
@ -70,4 +78,5 @@ public interface DeliveryExpressService {
* @return 快递公司列表 * @return 快递公司列表
*/ */
List<DeliveryExpressDO> getDeliveryExpressListByStatus(Integer status); List<DeliveryExpressDO> getDeliveryExpressListByStatus(Integer status);
} }

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.trade.service.delivery; package cn.iocoder.yudao.module.trade.service.delivery;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.express.DeliveryExpressCreateReqVO; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.express.DeliveryExpressCreateReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.express.DeliveryExpressExportReqVO; import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.express.DeliveryExpressExportReqVO;
@ -12,12 +13,10 @@ import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_CODE_DUPLICATE; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_NOT_EXISTS;
/** /**
* 快递公司 Service 实现类 * 快递公司 Service 实现类
@ -85,6 +84,18 @@ public class DeliveryExpressServiceImpl implements DeliveryExpressService {
return deliveryExpressMapper.selectById(id); return deliveryExpressMapper.selectById(id);
} }
@Override
public DeliveryExpressDO validateDeliveryExpress(Long id) {
DeliveryExpressDO deliveryExpress = deliveryExpressMapper.selectById(id);
if (deliveryExpress == null) {
throw exception(EXPRESS_NOT_EXISTS);
}
if (deliveryExpress.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) {
throw exception(EXPRESS_STATUS_NOT_ENABLE);
}
return deliveryExpress;
}
@Override @Override
public PageResult<DeliveryExpressDO> getDeliveryExpressPage(DeliveryExpressPageReqVO pageReqVO) { public PageResult<DeliveryExpressDO> getDeliveryExpressPage(DeliveryExpressPageReqVO pageReqVO) {
return deliveryExpressMapper.selectPage(pageReqVO); return deliveryExpressMapper.selectPage(pageReqVO);

View File

@ -7,7 +7,6 @@ import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.core.KeyValue;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.framework.common.enums.TerminalEnum;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
@ -43,7 +42,6 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettle
import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO;
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper;
@ -416,32 +414,24 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void deliveryOrder(TradeOrderDeliveryReqVO deliveryReqVO) { public void deliveryOrder(TradeOrderDeliveryReqVO deliveryReqVO) {
// TODO @puhui999只有选择快递的才可以发货
// 1.1 校验并获得交易订单可发货 // 1.1 校验并获得交易订单可发货
TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId()); TradeOrderDO order = validateOrderDeliverable(deliveryReqVO.getId());
// 校验 deliveryType 是否为快递是快递才可以发货 // 1.2 校验 deliveryType 是否为快递是快递才可以发货
if (ObjectUtil.notEqual(order.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getMode())) { if (ObjectUtil.notEqual(order.getDeliveryType(), DeliveryTypeEnum.EXPRESS.getMode())) {
throw exception(ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS); throw exception(ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS);
} }
// TODO @puhui999下面不修改 deliveryType直接校验 deliveryType 是否为快递是快递才可以发货先做严格的方式哈
// 判断发货类型 // 2. 更新订单为已发货
TradeOrderDO updateOrderObj = new TradeOrderDO(); TradeOrderDO updateOrderObj = new TradeOrderDO();
// 2.1 快递发货 // 2.1 快递发货
if (ObjectUtil.notEqual(deliveryReqVO.getLogisticsId(), 0L)) { if (ObjectUtil.notEqual(deliveryReqVO.getLogisticsId(), TradeOrderDO.LOGISTICS_ID_NULL)) {
// 校验快递公司 deliveryExpressService.validateDeliveryExpress(deliveryReqVO.getLogisticsId());
DeliveryExpressDO deliveryExpress = deliveryExpressService.getDeliveryExpress(deliveryReqVO.getLogisticsId());
if (deliveryExpress == null) {
throw exception(EXPRESS_NOT_EXISTS);
}
if (deliveryExpress.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) {
throw exception(EXPRESS_STATUS_NOT_ENABLE);
}
updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo()); updateOrderObj.setLogisticsId(deliveryReqVO.getLogisticsId()).setLogisticsNo(deliveryReqVO.getLogisticsNo());
} else { } else {
// 2.2 无需发货 // 2.2 无需发货
updateOrderObj.setLogisticsId(0L).setLogisticsNo(""); updateOrderObj.setLogisticsId(0L).setLogisticsNo("");
} }
// 更新 TradeOrderDO 状态为已发货等待收货 // 执行更新
updateOrderObj.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now()); updateOrderObj.setStatus(TradeOrderStatusEnum.DELIVERED.getStatus()).setDeliveryTime(LocalDateTime.now());
int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), updateOrderObj); int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), updateOrderObj);
if (updateCount == 0) { if (updateCount == 0) {