获取废品最新价格类目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;
}
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) {
if (ObjectUtil.isNotEmpty(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.Param;
import java.util.List;
/**
* <p>
* Mapper
@ -24,6 +26,6 @@ public interface ProductMapper extends BaseMapper<Product> {
* @param productCode
* @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
* @param productId
* @param enterpriseId
* @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
* @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;
@Override
public PriceProduct getLatestPriceProduct(String productId) {
return recycleOrderProductMapper.getLatestPriceProductByProductId(productId);
public PriceProduct getLatestPriceProduct(String productId, String enterpriseId) {
return recycleOrderProductMapper.getLatestPriceProductByProductId(productId, enterpriseId);
}
@Override

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

@ -57,18 +57,18 @@ public class RecycleStationServiceImpl extends ServiceImpl<RecycleStationMapper,
// 根据废品类目过滤站点
String productCode = recycleStationQuery.getProductCode();
if (StrUtil.isNotEmpty(productCode)) {
String priceId = productMapper.getLatestPriceByProductCode(productCode);
if (ObjectUtil.isEmpty(priceId)) {
List<String> stationList = productMapper.getStationsByProductCode(productCode);
if (ObjectUtil.isEmpty(stationList)) {
return new Page<>();
} else {
List<RecycleStationPrice> stationPriceList = new LambdaQueryChainWrapper<>(recycleStationPriceMapper)
.eq(RecycleStationPrice::getPriceId, priceId).select(RecycleStationPrice::getRecycleStationId).list();
List<String> stationIds = new ArrayList<>();
for (RecycleStationPrice recycleStationPrice : stationPriceList) {
String recycleStationId = recycleStationPrice.getRecycleStationId();
stationIds.add(recycleStationId);
}
wrapperX.inIfPresent(RecycleStation::getId, stationIds);
// List<RecycleStationPrice> stationPriceList = new LambdaQueryChainWrapper<>(recycleStationPriceMapper)
// .eq(RecycleStationPrice::getPriceId, priceId).select(RecycleStationPrice::getRecycleStationId).list();
// List<String> stationIds = new ArrayList<>();
// for (RecycleStationPrice recycleStationPrice : stationPriceList) {
// String recycleStationId = recycleStationPrice.getRecycleStationId();
// stationIds.add(recycleStationId);
// }
wrapperX.inIfPresent(RecycleStation::getId, stationList);
}
}
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">
<mapper namespace="cc.yunxi.mapper.ProductMapper">
<!-- 根据类目code查询最新一条的有效的价目 -->
<select id="getLatestPriceByProductCode" resultType="String">
<!-- 根据类目code查询关联有效的价目站点列表 (前100条) todo 待优化 -->
<select id="getStationsByProductCode" resultType="String">
SELECT
c.id
-- c.id,
d.recycle_id
FROM
nx_product a
INNER JOIN nx_price_product b ON a.id = b.product_id
INNER JOIN nx_price c ON b.price_id = c.id
AND c.`status` = 1
INNER JOIN nx_price_recycle d ON c.id = d.price_id
WHERE
a.`code` = #{productCode}
ORDER BY
c.f_creator_time DESC
LIMIT 1;
LIMIT 100;
</select>
</mapper>

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

Loading…
Cancel
Save