获取废品最新价格类目bug: 需根据商户id隔离

door
LI-CCONG\李聪聪 7 months ago
parent 6343cc23d3
commit 38be4be902

@ -38,6 +38,20 @@ public class LambdaQueryWrapperX<T> extends LambdaQueryWrapper<T> {
return this; return this;
} }
public LambdaQueryWrapperX<T> existsIfPresent(String existsSql, Collection<?> values) {
if (ObjectUtil.isAllNotEmpty(values) && !ArrayUtil.isEmpty(values)) {
return (LambdaQueryWrapperX<T>) super.exists(existsSql, values);
}
return this;
}
public LambdaQueryWrapperX<T> existsIfPresent(String existsSql, Object... values) {
if (ObjectUtil.isAllNotEmpty(values) && !ArrayUtil.isEmpty(values)) {
return (LambdaQueryWrapperX<T>) super.exists(existsSql, values);
}
return this;
}
public LambdaQueryWrapperX<T> eqIfPresent(SFunction<T, ?> column, Object val) { public LambdaQueryWrapperX<T> eqIfPresent(SFunction<T, ?> column, Object val) {
if (ObjectUtil.isNotEmpty(val)) { if (ObjectUtil.isNotEmpty(val)) {
return (LambdaQueryWrapperX<T>) super.eq(column, val); return (LambdaQueryWrapperX<T>) super.eq(column, val);

@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* <p> * <p>
* Mapper * Mapper
@ -24,6 +26,6 @@ public interface ProductMapper extends BaseMapper<Product> {
* @param productCode * @param productCode
* @return Price * @return Price
*/ */
String getLatestPriceByProductCode(@Param("productCode") String productCode); List<String> getStationsByProductCode(@Param("productCode") String productCode);
} }

@ -20,8 +20,10 @@ public interface RecycleOrderProductMapper extends BaseMapper<RecycleOrderProduc
/** /**
* id * id
* @param productId * @param productId
* @param enterpriseId
* @return Price * @return Price
*/ */
PriceProduct getLatestPriceProductByProductId(@Param("productId") String productId); PriceProduct getLatestPriceProductByProductId(@Param("productId") String productId,
@Param("enterpriseId") String enterpriseId);
} }

@ -24,7 +24,7 @@ public interface IRecycleOrderProductService extends IService<RecycleOrderProduc
* @param productId * @param productId
* @return PriceProduct * @return PriceProduct
*/ */
PriceProduct getLatestPriceProduct(String productId); PriceProduct getLatestPriceProduct(String productId, String enterpriseId);
/** /**
* *

@ -29,8 +29,8 @@ public class RecycleOrderProductServiceImpl extends ServiceImpl<RecycleOrderProd
private RecycleOrderProductMapper recycleOrderProductMapper; private RecycleOrderProductMapper recycleOrderProductMapper;
@Override @Override
public PriceProduct getLatestPriceProduct(String productId) { public PriceProduct getLatestPriceProduct(String productId, String enterpriseId) {
return recycleOrderProductMapper.getLatestPriceProductByProductId(productId); return recycleOrderProductMapper.getLatestPriceProductByProductId(productId, enterpriseId);
} }
@Override @Override

@ -259,6 +259,7 @@ public class RecycleOrderServiceImpl extends ServiceImpl<RecycleOrderMapper, Rec
} }
// 创建订单 // 创建订单
String orderNo = CommonUtil.getIdNumber(BusinessCodeEnum.ORDER.getCode()); String orderNo = CommonUtil.getIdNumber(BusinessCodeEnum.ORDER.getCode());
String enterpriseId = recycler.getCompanyId();
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
RecycleOrder recycleOrder = new RecycleOrder(); RecycleOrder recycleOrder = new RecycleOrder();
recycleOrder.setRecycleStationId(recycler.getStationId()); recycleOrder.setRecycleStationId(recycler.getStationId());
@ -270,7 +271,7 @@ public class RecycleOrderServiceImpl extends ServiceImpl<RecycleOrderMapper, Rec
recycleOrder.setOrderStatus(OrderStatusEnum.FINISHED); // 直接完成 recycleOrder.setOrderStatus(OrderStatusEnum.FINISHED); // 直接完成
recycleOrder.setCreatorTime(now); recycleOrder.setCreatorTime(now);
recycleOrder.setCompleteTime(now); // 完成时间 recycleOrder.setCompleteTime(now); // 完成时间
this.saveRecycleOrder(recycleOrder, recycler.getCompanyId()); this.saveRecycleOrder(recycleOrder, enterpriseId);
// 创建订单明细 // 创建订单明细
String orderId = recycleOrder.getId(); String orderId = recycleOrder.getId();
@ -280,7 +281,7 @@ public class RecycleOrderServiceImpl extends ServiceImpl<RecycleOrderMapper, Rec
rp.setRecycleOrderId(orderId); rp.setRecycleOrderId(orderId);
rp.setCreatorTime(now); rp.setCreatorTime(now);
rp.setUpdateTime(now); rp.setUpdateTime(now);
PriceProduct latestPriceProduct = this.recycleOrderProductService.getLatestPriceProduct(rp.getProductId()); PriceProduct latestPriceProduct = this.recycleOrderProductService.getLatestPriceProduct(rp.getProductId(), enterpriseId);
log.info("latest price product: {}", latestPriceProduct); log.info("latest price product: {}", latestPriceProduct);
if (ObjectUtil.isEmpty(latestPriceProduct)) { if (ObjectUtil.isEmpty(latestPriceProduct)) {
throw new BusinessLogicException("产品价格信息未公布,请联系商户!"); throw new BusinessLogicException("产品价格信息未公布,请联系商户!");
@ -403,9 +404,10 @@ public class RecycleOrderServiceImpl extends ServiceImpl<RecycleOrderMapper, Rec
// 更新订单明细信息 // 更新订单明细信息
List<RecycleOrderDetailUpdateVO> recycleOrderProductVOList = orderFinishVO.getOrderDetails(); List<RecycleOrderDetailUpdateVO> recycleOrderProductVOList = orderFinishVO.getOrderDetails();
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
String enterpriseId = recycleOrder.getCompanyId();
recycleOrderProductVOList.forEach(rp -> { recycleOrderProductVOList.forEach(rp -> {
rp.setUpdateTime(now); rp.setUpdateTime(now);
PriceProduct latestPriceProduct = this.recycleOrderProductService.getLatestPriceProduct(rp.getProductId()); PriceProduct latestPriceProduct = this.recycleOrderProductService.getLatestPriceProduct(rp.getProductId(), enterpriseId);
log.info("latest price product: {}", latestPriceProduct); log.info("latest price product: {}", latestPriceProduct);
if (ObjectUtil.isEmpty(latestPriceProduct)) { if (ObjectUtil.isEmpty(latestPriceProduct)) {
throw new BusinessLogicException("产品价格信息未公布,请联系商户!"); throw new BusinessLogicException("产品价格信息未公布,请联系商户!");
@ -462,11 +464,12 @@ public class RecycleOrderServiceImpl extends ServiceImpl<RecycleOrderMapper, Rec
List<RecycleOrderDetailSaveVO> recycleOrderProductVOList = tmOrderFinishVO.getOrderDetails(); List<RecycleOrderDetailSaveVO> recycleOrderProductVOList = tmOrderFinishVO.getOrderDetails();
List<RecycleOrderProduct> recycleOrderProducts = BeanUtils.copyList(recycleOrderProductVOList, RecycleOrderProduct.class); List<RecycleOrderProduct> recycleOrderProducts = BeanUtils.copyList(recycleOrderProductVOList, RecycleOrderProduct.class);
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
String enterpriseId = recycleOrder.getCompanyId();
recycleOrderProducts.forEach(rp -> { recycleOrderProducts.forEach(rp -> {
rp.setRecycleOrderId(orderId); rp.setRecycleOrderId(orderId);
rp.setCreatorTime(now); rp.setCreatorTime(now);
rp.setUpdateTime(now); rp.setUpdateTime(now);
PriceProduct latestPriceProduct = this.recycleOrderProductService.getLatestPriceProduct(rp.getProductId()); PriceProduct latestPriceProduct = this.recycleOrderProductService.getLatestPriceProduct(rp.getProductId(), enterpriseId);
log.info("latest price product: {}", latestPriceProduct); log.info("latest price product: {}", latestPriceProduct);
if (ObjectUtil.isEmpty(latestPriceProduct)) { if (ObjectUtil.isEmpty(latestPriceProduct)) {
throw new BusinessLogicException("产品价格信息未公布,请联系商户!"); throw new BusinessLogicException("产品价格信息未公布,请联系商户!");

@ -57,18 +57,18 @@ public class RecycleStationServiceImpl extends ServiceImpl<RecycleStationMapper,
// 根据废品类目过滤站点 // 根据废品类目过滤站点
String productCode = recycleStationQuery.getProductCode(); String productCode = recycleStationQuery.getProductCode();
if (StrUtil.isNotEmpty(productCode)) { if (StrUtil.isNotEmpty(productCode)) {
String priceId = productMapper.getLatestPriceByProductCode(productCode); List<String> stationList = productMapper.getStationsByProductCode(productCode);
if (ObjectUtil.isEmpty(priceId)) { if (ObjectUtil.isEmpty(stationList)) {
return new Page<>(); return new Page<>();
} else { } else {
List<RecycleStationPrice> stationPriceList = new LambdaQueryChainWrapper<>(recycleStationPriceMapper) // List<RecycleStationPrice> stationPriceList = new LambdaQueryChainWrapper<>(recycleStationPriceMapper)
.eq(RecycleStationPrice::getPriceId, priceId).select(RecycleStationPrice::getRecycleStationId).list(); // .eq(RecycleStationPrice::getPriceId, priceId).select(RecycleStationPrice::getRecycleStationId).list();
List<String> stationIds = new ArrayList<>(); // List<String> stationIds = new ArrayList<>();
for (RecycleStationPrice recycleStationPrice : stationPriceList) { // for (RecycleStationPrice recycleStationPrice : stationPriceList) {
String recycleStationId = recycleStationPrice.getRecycleStationId(); // String recycleStationId = recycleStationPrice.getRecycleStationId();
stationIds.add(recycleStationId); // stationIds.add(recycleStationId);
} // }
wrapperX.inIfPresent(RecycleStation::getId, stationIds); wrapperX.inIfPresent(RecycleStation::getId, stationList);
} }
} }
wrapperX.eqIfPresent(RecycleStation::getStationName, recycleStationQuery.getStationName()); wrapperX.eqIfPresent(RecycleStation::getStationName, recycleStationQuery.getStationName());

@ -2,20 +2,22 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cc.yunxi.mapper.ProductMapper"> <mapper namespace="cc.yunxi.mapper.ProductMapper">
<!-- 根据类目code查询最新一条的有效的价目 --> <!-- 根据类目code查询关联有效的价目站点列表 (前100条) todo 待优化 -->
<select id="getLatestPriceByProductCode" resultType="String"> <select id="getStationsByProductCode" resultType="String">
SELECT SELECT
c.id -- c.id,
d.recycle_id
FROM FROM
nx_product a nx_product a
INNER JOIN nx_price_product b ON a.id = b.product_id INNER JOIN nx_price_product b ON a.id = b.product_id
INNER JOIN nx_price c ON b.price_id = c.id INNER JOIN nx_price c ON b.price_id = c.id
AND c.`status` = 1 AND c.`status` = 1
INNER JOIN nx_price_recycle d ON c.id = d.price_id
WHERE WHERE
a.`code` = #{productCode} a.`code` = #{productCode}
ORDER BY ORDER BY
c.f_creator_time DESC c.f_creator_time DESC
LIMIT 1; LIMIT 100;
</select> </select>
</mapper> </mapper>

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cc.yunxi.mapper.RecycleOrderProductMapper"> <mapper namespace="cc.yunxi.mapper.RecycleOrderProductMapper">
<!-- 根据类目Id查询最新一条的有效的价目 --> <!-- 根据类目Id查询商户下的最新一条的有效的价目 -->
<select id="getLatestPriceProductByProductId" resultType="PriceProduct"> <select id="getLatestPriceProductByProductId" resultType="PriceProduct">
SELECT SELECT
b.id, b.id,
@ -17,6 +17,7 @@
AND c.`status` = 1 AND c.`status` = 1
WHERE WHERE
b.`product_id` = #{productId} b.`product_id` = #{productId}
AND c.buiness_id = #{enterpriseId}
ORDER BY ORDER BY
c.f_creator_time DESC c.f_creator_time DESC
LIMIT 1; LIMIT 1;

Loading…
Cancel
Save