规格编辑时 名称重复问题
订单管理模块
This commit is contained in:
@@ -18,6 +18,10 @@ package me.zhengjie.modules.order.cashierCart.repository;
|
||||
import me.zhengjie.modules.order.cashierCart.domain.TbCashierCart;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
@@ -25,4 +29,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
* @date 2024-03-02
|
||||
**/
|
||||
public interface TbCashierCartRepository extends JpaRepository<TbCashierCart, Integer>, JpaSpecificationExecutor<TbCashierCart> {
|
||||
|
||||
@Query("SELECT cart FROM TbCashierCart cart WHERE cart.orderId = :orderId")
|
||||
List<TbCashierCart> searchCartByOrderId(@Param("orderId")Integer orderId);
|
||||
}
|
||||
@@ -57,6 +57,13 @@ public class TbOrderInfoController {
|
||||
return new ResponseEntity<>(tbOrderInfoService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@Log("查询/orderInfo")
|
||||
@ApiOperation("查询/orderInfo")
|
||||
public Object queryTbOrderInfo(@PathVariable("id") Integer id){
|
||||
return tbOrderInfoService.findById(id);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增/orderInfo")
|
||||
@ApiOperation("新增/orderInfo")
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
package me.zhengjie.modules.order.orderInfo.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.modules.order.cashierCart.domain.TbCashierCart;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
@@ -150,4 +153,6 @@ public class TbOrderInfoDto implements Serializable {
|
||||
private Integer source;
|
||||
|
||||
private String remark;
|
||||
|
||||
private List<TbCashierCart> cartList;
|
||||
}
|
||||
@@ -15,21 +15,23 @@
|
||||
*/
|
||||
package me.zhengjie.modules.order.orderInfo.service.impl;
|
||||
|
||||
import me.zhengjie.modules.order.cashierCart.domain.TbCashierCart;
|
||||
import me.zhengjie.modules.order.cashierCart.repository.TbCashierCartRepository;
|
||||
import me.zhengjie.modules.order.orderInfo.domain.TbOrderInfo;
|
||||
import me.zhengjie.utils.ValidationUtil;
|
||||
import me.zhengjie.utils.FileUtil;
|
||||
import me.zhengjie.modules.order.orderInfo.service.vo.TbOrderInfoVo;
|
||||
import me.zhengjie.utils.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.zhengjie.modules.order.orderInfo.repository.TbOrderInfoRepository;
|
||||
import me.zhengjie.modules.order.orderInfo.service.TbOrderInfoService;
|
||||
import me.zhengjie.modules.order.orderInfo.service.dto.TbOrderInfoDto;
|
||||
import me.zhengjie.modules.order.orderInfo.service.dto.TbOrderInfoQueryCriteria;
|
||||
import me.zhengjie.modules.order.orderInfo.service.mapstruct.TbOrderInfoMapper;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import me.zhengjie.utils.PageUtil;
|
||||
import me.zhengjie.utils.QueryHelp;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.IOException;
|
||||
@@ -49,11 +51,19 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
||||
|
||||
private final TbOrderInfoRepository tbOrderInfoRepository;
|
||||
private final TbOrderInfoMapper tbOrderInfoMapper;
|
||||
|
||||
private final TbCashierCartRepository tbCashierCartRepository;
|
||||
@Override
|
||||
public Map<String,Object> queryAll(TbOrderInfoQueryCriteria criteria, Pageable pageable){
|
||||
Page<TbOrderInfo> page = tbOrderInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(tbOrderInfoMapper::toDto));
|
||||
List<TbOrderInfoVo> orderInfoVoList = new ArrayList<>();
|
||||
for (TbOrderInfo tbOrderInfo : page.getContent()) {
|
||||
TbOrderInfoVo orderInfoVo=new TbOrderInfoVo();
|
||||
List<TbCashierCart> tbCashierCarts = tbCashierCartRepository.searchCartByOrderId(tbOrderInfo.getId());
|
||||
orderInfoVo.setCartList(tbCashierCarts);
|
||||
BeanUtils.copyProperties(tbOrderInfo, orderInfoVo);
|
||||
orderInfoVoList.add(orderInfoVo);
|
||||
}
|
||||
return PageUtil.toPage(orderInfoVoList, page.getTotalElements());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,7 +76,10 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
||||
public TbOrderInfoDto findById(Integer id) {
|
||||
TbOrderInfo tbOrderInfo = tbOrderInfoRepository.findById(id).orElseGet(TbOrderInfo::new);
|
||||
ValidationUtil.isNull(tbOrderInfo.getId(),"TbOrderInfo","id",id);
|
||||
return tbOrderInfoMapper.toDto(tbOrderInfo);
|
||||
TbOrderInfoDto dto = tbOrderInfoMapper.toDto(tbOrderInfo);
|
||||
List<TbCashierCart> tbCashierCarts = tbCashierCartRepository.searchCartByOrderId(tbOrderInfo.getId());
|
||||
dto.setCartList(tbCashierCarts);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.modules.order.orderInfo.service.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import me.zhengjie.modules.order.cashierCart.domain.TbCashierCart;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class TbOrderInfoVo {
|
||||
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String orderNo;
|
||||
|
||||
private BigDecimal settlementAmount;
|
||||
|
||||
private BigDecimal packFee;
|
||||
|
||||
private BigDecimal originAmount;
|
||||
|
||||
private BigDecimal productAmount;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
private BigDecimal payAmount;
|
||||
|
||||
private BigDecimal freightAmount;
|
||||
|
||||
private BigDecimal discountAmount;
|
||||
|
||||
private String tableId;
|
||||
|
||||
private BigDecimal smallChange;
|
||||
|
||||
private String sendType;
|
||||
|
||||
private String orderType;
|
||||
|
||||
private String productType;
|
||||
|
||||
private String status;
|
||||
|
||||
private String billingId;
|
||||
|
||||
private String merchantId;
|
||||
|
||||
private String shopId;
|
||||
|
||||
private Integer isVip;
|
||||
|
||||
private String memberId;
|
||||
|
||||
private String userId;
|
||||
|
||||
private Integer productScore;
|
||||
|
||||
private Integer deductScore;
|
||||
|
||||
private String userCouponId;
|
||||
|
||||
private BigDecimal userCouponAmount;
|
||||
|
||||
private String masterId;
|
||||
|
||||
private Integer refundAble;
|
||||
|
||||
private Long paidTime;
|
||||
|
||||
private Integer isEffect;
|
||||
|
||||
private Integer isGroup;
|
||||
|
||||
private Long updatedAt;
|
||||
|
||||
private Long systemTime;
|
||||
|
||||
private Long createdAt;
|
||||
|
||||
private Integer isAccepted;
|
||||
|
||||
private String payType;
|
||||
|
||||
private BigDecimal orderAmount;
|
||||
|
||||
private BigDecimal discountRatio;
|
||||
|
||||
private String payOrderNo;
|
||||
|
||||
private String tradeDay;
|
||||
|
||||
private Integer source;
|
||||
|
||||
private String remark;
|
||||
|
||||
private List<TbCashierCart> cartList;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public class TbProductSpecServiceImpl implements TbProductSpecService {
|
||||
specList.add(specVo);
|
||||
}
|
||||
|
||||
return PageUtil.toPage(specList, specList.size());
|
||||
return PageUtil.toPage(specList, page.getTotalElements());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,11 +101,11 @@ public class TbProductSpecServiceImpl implements TbProductSpecService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(TbProductSpec resources) {
|
||||
TbProductSpec tbProductSpec = tbProductSpecRepository.findById(resources.getId()).orElseGet(TbProductSpec::new);
|
||||
TbProductSpec allByName = tbProductSpecRepository.findAllByName(resources.getShopId(), resources.getName());
|
||||
if (allByName != null){
|
||||
throw new BadRequestException("规格名称重复");
|
||||
}
|
||||
ValidationUtil.isNull( tbProductSpec.getId(),"TbProductSpec","id",resources.getId());
|
||||
// TbProductSpec allByName = tbProductSpecRepository.findAllByName(resources.getShopId(), resources.getName());
|
||||
// if (allByName != null){
|
||||
// throw new BadRequestException("规格名称重复");
|
||||
// }
|
||||
ValidationUtil.isNull(tbProductSpec.getId(),"TbProductSpec","id",resources.getId());
|
||||
tbProductSpec.copy(resources);
|
||||
tbProductSpecRepository.save(tbProductSpec);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user