Authored by TANLING

降级接口

... ... @@ -2,6 +2,7 @@ package com.yohoufo.dal.order;
import com.yohobuy.ufo.model.order.resp.FastDeliveryGetShelfDetailResp;
import com.yohoufo.dal.order.model.SellerEarnestStatistics;
import com.yohoufo.dal.order.model.SellerGoodSkup;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.dal.order.model.SellerOrderInfo;
import org.apache.ibatis.annotations.Param;
... ... @@ -18,11 +19,13 @@ public interface SellerOrderGoodsMapper {
SellerOrderGoods selectByPrimaryKey(Integer id);
List<SellerOrderGoods> selectByUidAndStatus(@Param("uid") Integer uid, @Param("status") Integer status);
// List<SellerOrderGoods> selectByUidAndStatus(@Param("uid") Integer uid, @Param("status") Integer status);
List<SellerOrderGoods> selectByUidAndAttributesDesc(@Param("uid") Integer uid, @Param("status") Integer status, @Param("list") List<Integer> attributes);
List<SellerGoodSkup> selectOnsaleByUid(@Param("uid") Integer uid, @Param("status") Integer status, @Param("list") List<Integer> attributes);
List<SellerEarnestStatistics> selectEarnestMoneyByUid(@Param("list") List<Integer> uid);
List<SellerGoodSkup> selectSaleOutProcessiongByUid(@Param("uid") Integer uid);
// List<SellerEarnestStatistics> selectEarnestMoneyByUid(@Param("list") List<Integer> uid);
List<SellerOrderGoods> selectByBatchNo(@Param("condition")SellerOrderGoods record, @Param("statusList") Collection<Integer> statusList);
... ... @@ -30,15 +33,15 @@ public interface SellerOrderGoodsMapper {
List<SellerOrderGoods> selectBySkupsNStatus(@Param("list") List<Integer> skup, @Param("statusList") Collection<Integer> statusList);
List<SellerOrderInfo> selectByStatusAndOrderCode(@Param("uid") int uid,
@Param("orderCode") Long orderCode,
@Param("statusList") Collection<Integer> statusList,
@Param("offset")Integer offset,
@Param("limit")Integer limit);
// List<SellerOrderInfo> selectByStatusAndOrderCode(@Param("uid") int uid,
// @Param("orderCode") Long orderCode,
// @Param("statusList") Collection<Integer> statusList,
// @Param("offset")Integer offset,
// @Param("limit")Integer limit);
int selectCntByStatusAndOrderCode(@Param("uid") int uid,
@Param("orderCode") Long orderCode,
@Param("statusList") Collection<Integer> statusList);
// int selectCntByStatusAndOrderCode(@Param("uid") int uid,
// @Param("orderCode") Long orderCode,
// @Param("statusList") Collection<Integer> statusList);
int updateByPrimaryKeySelective(SellerOrderGoods record);
... ... @@ -62,10 +65,10 @@ public interface SellerOrderGoodsMapper {
FastDeliveryGetShelfDetailResp selectMultiInfoBySkup(@Param("uid")int uid,
@Param("skup") Integer skup);
List<SellerOrderGoods> selectByUidStatusList(@Param("uid")int uid,
@Param("statusList") List<Integer> statusList,
@Param("offset")Integer offset,
@Param("limit")Integer limit);
// List<SellerOrderGoods> selectByUidStatusList(@Param("uid")int uid,
// @Param("statusList") List<Integer> statusList,
// @Param("offset")Integer offset,
// @Param("limit")Integer limit);
/**
* GBB is group by batch no
* @param uid
... ... @@ -96,7 +99,7 @@ public interface SellerOrderGoodsMapper {
int insertBatch(@Param("records") Collection<SellerOrderGoods> records);
SellerOrderGoods selectByUidStatusGBBN(SellerOrderGoods record);
// SellerOrderGoods selectByUidStatusGBBN(SellerOrderGoods record);
List<SellerOrderGoods> selectGPByBNStatusPrice(SellerOrderGoods condition);
... ...
package com.yohoufo.dal.order.model;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class SellerGoodSkup {
private Integer uid;
private Integer skup;
private BigDecimal earnestMoney;
}
... ...
... ... @@ -38,20 +38,20 @@
</sql>
<select id="selectEarnestMoneyByUid" resultType="com.yohoufo.dal.order.model.SellerEarnestStatistics">
select
sum(case when sog.attributes in (1,5,6) then (<![CDATA[ case when sog.goods_price*0.04>200 then 200 when sog.goods_price*0.04<28 then 28 else sog.goods_price*0.04 end ]]>)
when sog.attributes=4 then (<![CDATA[ case when sog.goods_price*0.08>400 then 400 when sog.goods_price*0.08<40 then 40 else sog.goods_price*0.08 end ]]> )
end) earnestTotal, sog.uid, sw.amount leftMoney
from seller_order_goods sog, seller_wallet sw
where sog.uid=sw.uid and sog.status=1
<if test="list != null">
and sog.uid in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</if> GROUP BY sog.uid
</select>
<!--<select id="selectEarnestMoneyByUid" resultType="com.yohoufo.dal.order.model.SellerEarnestStatistics">-->
<!--select-->
<!--sum(case when sog.attributes in (1,5,6) then (<![CDATA[ case when sog.goods_price*0.04>200 then 200 when sog.goods_price*0.04<28 then 28 else sog.goods_price*0.04 end ]]>)-->
<!--when sog.attributes=4 then (<![CDATA[ case when sog.goods_price*0.08>400 then 400 when sog.goods_price*0.08<40 then 40 else sog.goods_price*0.08 end ]]> )-->
<!--end) earnestTotal, sog.uid, sw.amount leftMoney-->
<!--from seller_order_goods sog, seller_wallet sw-->
<!--where sog.uid=sw.uid and sog.status=1-->
<!--<if test="list != null">-->
<!--and sog.uid in-->
<!--<foreach item="item" index="index" collection="list" open="(" separator="," close=")">-->
<!--#{item}-->
<!--</foreach>-->
<!--</if> GROUP BY sog.uid-->
<!--</select>-->
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
... ... @@ -63,18 +63,34 @@
<select id="selectByUidAndStatus" resultMap="BaseResultMap">
<!--<select id="selectByUidAndStatus" resultMap="BaseResultMap">-->
<!--select-->
<!--<include refid="Base_Column_List" />-->
<!--from seller_order_goods-->
<!--where uid = #{uid,jdbcType=INTEGER}-->
<!--and status= #{status,jdbcType=INTEGER}-->
<!--</select>-->
<select id="selectSaleOutProcessiongByUid" resultType="com.yohoufo.dal.order.model.SellerGoodSkup">
select
<include refid="Base_Column_List" />
from seller_order_goods
where uid = #{uid,jdbcType=INTEGER}
and status= #{status,jdbcType=INTEGER}
sog.uid, sog.id skup,so.earnest_money earnestMoney
from seller_order_goods sog, seller_order so, buyer_order_goods bog, buyer_order bo
where
sog.id = so.skup
and so.skup = bog.skup
and bog.order_code = bo.order_code
and so.payment=11
and sog.uid = #{uid,jdbcType=INTEGER}
and sog.status = 2
and bo.status IN (0, 1, 2, 3, 32,31)
order by sog.id desc
</select>
<select id="selectByUidAndAttributesDesc" resultMap="BaseResultMap">
<select id="selectOnsaleByUid" resultType="com.yohoufo.dal.order.model.SellerGoodSkup">
select
sog.uid, sog.id
sog.uid, sog.id skup ,so.earnest_money earnestMoney
from seller_order_goods sog, seller_order so
where
sog.id = so.skup
... ... @@ -85,7 +101,7 @@
<foreach collection="list" item="item" open="(" close=")" separator=",">
#{item,jdbcType=INTEGER}
</foreach>
order by id desc
order by sog.id desc
</select>
... ... @@ -102,29 +118,29 @@
</if>
</select>
<select id="selectCntByStatusAndOrderCode" resultType="java.lang.Integer">
select
count(1)
from ufo_order.seller_order a, ufo_order.seller_order_goods b
where a.skup=b.id
<include refid="join_where_status_orderCode"></include>
</select>
<select id="selectByStatusAndOrderCode" resultType="com.yohoufo.dal.order.model.SellerOrderInfo">
select
a.order_code orderCode, b.status status, b.image_url imageUrl,
b.product_name productName, b.product_id productId, a.skup skup,
b.color_id colorId, b.color_name colorName, b.size_id sizeId, b.size_name sizeName,
b.goods_price goodsPrice, b.attributes attributes,
a.uid ,a.create_time createTime
from ufo_order.seller_order a, ufo_order.seller_order_goods b
where a.skup=b.id
<include refid="join_where_status_orderCode"></include>
order by a.create_time desc
limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}
</select>
<!--<select id="selectCntByStatusAndOrderCode" resultType="java.lang.Integer">-->
<!--select-->
<!--count(1)-->
<!--from ufo_order.seller_order a, ufo_order.seller_order_goods b-->
<!--where a.skup=b.id-->
<!--<include refid="join_where_status_orderCode"></include>-->
<!--</select>-->
<!--<select id="selectByStatusAndOrderCode" resultType="com.yohoufo.dal.order.model.SellerOrderInfo">-->
<!--select-->
<!--a.order_code orderCode, b.status status, b.image_url imageUrl,-->
<!--b.product_name productName, b.product_id productId, a.skup skup,-->
<!--b.color_id colorId, b.color_name colorName, b.size_id sizeId, b.size_name sizeName,-->
<!--b.goods_price goodsPrice, b.attributes attributes,-->
<!--a.uid ,a.create_time createTime-->
<!--from ufo_order.seller_order a, ufo_order.seller_order_goods b-->
<!--where a.skup=b.id-->
<!--<include refid="join_where_status_orderCode"></include>-->
<!--order by a.create_time desc-->
<!--limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}-->
<!--</select>-->
<sql id="join_where_status_orderCode">
<if test="orderCode !=null">
... ... @@ -246,12 +262,12 @@
limit 1
</select>
<select id="selectByUidStatusList" resultMap="BaseResultMap">
select <include refid="Base_Column_List" /> from seller_order_goods
where <include refid="sql_where_4_select_UidStatusList"/>
order by id desc
limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}
</select>
<!--<select id="selectByUidStatusList" resultMap="BaseResultMap">-->
<!--select <include refid="Base_Column_List" /> from seller_order_goods-->
<!--where <include refid="sql_where_4_select_UidStatusList"/>-->
<!--order by id desc-->
<!--limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}-->
<!--</select>-->
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerOrderGoods" useGeneratedKeys="true">
... ... @@ -519,15 +535,15 @@
limit #{offset, jdbcType=INTEGER}, #{limit, jdbcType=INTEGER}
</select>
<select id="selectByUidStatusGBBN" parameterType="com.yohoufo.dal.order.model.SellerOrderGoods" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />,count(*) num,GROUP_CONCAT(id) skup_list from seller_order_goods
where uid = #{uid,jdbcType=INTEGER} and is_del = 1
and batch_no = #{batchNo,jdbcType=BIGINT}
and goods_price = #{goodsPrice,jdbcType=DECIMAL}
and status = #{status,jdbcType=TINYINT}
group by batch_no , goods_price ,`status`
limit 1
</select>
<!--<select id="selectByUidStatusGBBN" parameterType="com.yohoufo.dal.order.model.SellerOrderGoods" resultMap="BaseResultMap">-->
<!--select <include refid="Base_Column_List" />,count(*) num,GROUP_CONCAT(id) skup_list from seller_order_goods-->
<!--where uid = #{uid,jdbcType=INTEGER} and is_del = 1-->
<!--and batch_no = #{batchNo,jdbcType=BIGINT}-->
<!--and goods_price = #{goodsPrice,jdbcType=DECIMAL}-->
<!--and status = #{status,jdbcType=TINYINT}-->
<!--group by batch_no , goods_price ,`status`-->
<!--limit 1-->
<!--</select>-->
<select id="selectGPByBNStatusPrice" parameterType="com.yohoufo.dal.order.model.SellerOrderGoods" resultMap="BaseResultMap">
... ...
... ... @@ -49,10 +49,7 @@ import java.math.BigDecimal;
import java.text.CollationElementIterator;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
... ... @@ -431,6 +428,51 @@ public class StoreSellerServiceImpl implements IStoredSellerService {
public void orderPayBySkups(List<Integer> skups){
if (CollectionUtils.isEmpty(skups)){
return;
}
scriptLogger.info("start orderPayBySkups {}", skups);
// 过滤出 支付方式是11的
List<SellerOrder> sellerOrders = sellerOrderMapper.selectBySkups(skups);
List<SellerOrder> walletSellerOrders = sellerOrders.stream().filter(x->Objects.nonNull(x.getPayment()) && x.getPayment()==11).collect(Collectors.toList());
if (CollectionUtils.isEmpty(walletSellerOrders)){
scriptLogger.info("no need orderPay....can sell goods not wallet");
}
int now = DateUtil.getCurrentTimeSecond();
for (SellerOrder sellerOrder : walletSellerOrders) {
scriptLogger.info("[{}] startorderPay [{}]", sellerOrder.getUid(), sellerOrder.getOrderCode());
OrdersPay ordersPaydb = ordersPayMapper.selectOrdersPay(sellerOrder.getOrderCode(), sellerOrder.getUid());
if (ordersPaydb != null) {
scriptLogger.info("[{}] no need orderPay [{}]", sellerOrder.getUid(), sellerOrder.getOrderCode());
continue;
}
OrdersPay ordersPay = new OrdersPay();
ordersPay.setPayOrderCode(String.valueOf(sellerOrder.getOrderCode()));
ordersPay.setAmount(sellerOrder.getEarnestMoney());
ordersPay.setOrderCode(sellerOrder.getOrderCode());
ordersPay.setUid(sellerOrder.getUid());
ordersPay.setPayment(11);
ordersPay.setCreateTime(now);
ordersPay.setSerialNo(String.valueOf(sellerOrder.getOrderCode()));
ordersPayMapper.insertSelective(ordersPay);
scriptLogger.info("[{}] do orderPay [{}]", sellerOrder.getUid(), sellerOrder.getOrderCode());
scriptLogger.info("==================================================");
}
}
public void compensate(List<Integer> uids){
... ... @@ -501,44 +543,56 @@ public class StoreSellerServiceImpl implements IStoredSellerService {
Map<Integer, SellerWallet> sellerWalletMap = sellerWalletList.stream().collect(Collectors.toMap(SellerWallet::getUid, Function.identity(), (key1, key2) -> key2));
// 2.需要执行商品下架的uid & skup
Map<Integer, List<Integer>> saleoutProcessingSkups = Maps.newHashMap();
// key=uid, value=需要下架的skup
Map<Integer, List<Integer>> downSelfSkupMap = Maps.newHashMap();
// key=uid, value=上架中的商品的价格,需占用
// key=uid, value=上架中的商品的价格+过程中的订单保证金,需占用
Map<Integer, Double> onshelfEarnest = Maps.newHashMap();
Map<Integer, List<Integer>> onselfSkupMap = Maps.newHashMap();
scriptLogger.info("========================== process degrade calculate ==========================");
for (Integer uid : filterUids){
scriptLogger.info("\n");
// 上架中 & 钱包 & 保证金 的skup
List<Integer> skupsOfuid = getOnshelfSkupOfUid(uid);
scriptLogger.info("[{}] process degrade, all skup {} ", uid, skupsOfuid);
Map<Integer, BigDecimal> onsaleSkupMap = getOnshelfSkupOfUid(uid);
// 上架中 and 已出售但是流程还没有走完的
Map<Integer, BigDecimal> saleoutProcessingSkupMap = getSaleOutProcessingSkup(uid);
if (CollectionUtils.isEmpty(skupsOfuid)){
scriptLogger.info("[{}] process degrade, onsale skups {}, saleoutprocessing skups {} ", uid, onsaleSkupMap.keySet(), saleoutProcessingSkupMap.keySet());
if (CollectionUtils.isEmpty(onsaleSkupMap.keySet()) && CollectionUtils.isEmpty(saleoutProcessingSkupMap.keySet())){
continue;
}
// 这些skup的实际保证金 key=skup, value=保证金
List<SellerOrderMeta> sellerOrderMetaList = sellerOrderMetaMapper.selectByUidSkupAndMetaKey(uid, skupsOfuid, Lists.newArrayList("fee"));
Map<Integer, SellerOrderMeta> skupEarnestMap = sellerOrderMetaList.stream().collect(Collectors.toMap(SellerOrderMeta::getSkup, Function.identity(), (key1, key2) -> key2));
double walletLeftMoney = sellerWalletMap.get(uid).getAmount().doubleValue();
double saleoutProcessingMoney = getSumEarnestSaleOutProcessiongSkups(saleoutProcessingSkupMap);
double leftMoney = sellerWalletMap.get(uid).getAmount().doubleValue();
// 实际真正可用金额
double availableLeftMoney = YHMath.sub(walletLeftMoney, saleoutProcessingMoney);
// 保持上架的skup & money
Pair<List<Integer>, Double> onshelfSkup = getOnselfSkupsAndEarnest(skupsOfuid, skupEarnestMap, leftMoney , uid);
scriptLogger.info("[{}] process degrade, leftMoney {}", uid, leftMoney);
Pair<List<Integer>, Double> onshelfSkup = getOnselfSkupsAndEarnest(onsaleSkupMap, availableLeftMoney);
scriptLogger.info("[{}] process degrade, walletLeftMoney {}, saleoutProcessingMoney {}, availableLeftMoney {}", uid, walletLeftMoney, saleoutProcessingMoney, availableLeftMoney);
scriptLogger.info("[{}] process degrade, onshelfSkup {}", uid, onshelfSkup.getLeft());
scriptLogger.info("[{}] process degrade, earnestMoneyTotal {} ", uid, onshelfSkup.getRight());
skupsOfuid.removeAll(onshelfSkup.getKey());
onselfSkupMap.put(uid, Lists.newArrayList(onshelfSkup.getKey()));
onsaleSkupMap.keySet().removeAll(onshelfSkup.getKey());
// 应该下架的skup
downSelfSkupMap.put(uid, skupsOfuid);
downSelfSkupMap.put(uid, Lists.newArrayList(onsaleSkupMap.keySet()));
onshelfEarnest.put(uid, onshelfSkup.getValue());
saleoutProcessingSkups.put(uid, Lists.newArrayList(saleoutProcessingSkupMap.keySet()));
onshelfEarnest.put(uid, YHMath.add(saleoutProcessingMoney, onshelfSkup.getValue()));
}
... ... @@ -573,7 +627,7 @@ public class StoreSellerServiceImpl implements IStoredSellerService {
// 3.2 下架商品
if (CollectionUtils.isNotEmpty(downSelfSkupMap.get(uid))){
boolean updateStatusFlag = productProxyService.sellerBatchUpdateStatus(downSelfSkupMap.get(uid), ProductProxyService.PrdShelvelStatus.off);
productProxyService.sellerBatchUpdateStatus(downSelfSkupMap.get(uid), ProductProxyService.PrdShelvelStatus.off);
sellerOrderGoodsMapper.updateStatusfBySkups(downSelfSkupMap.get(uid), SkupStatus.YOHO_CANCEL_SELL.getCode());
... ... @@ -585,20 +639,51 @@ public class StoreSellerServiceImpl implements IStoredSellerService {
scriptLogger.info("[{}] down shelf skup {} success", uid, downSelfSkupMap.get(uid));
}
// 给下架的商品和过程中的商品补充支付信息
orderPayBySkups(onselfSkupMap.get(uid));
scriptLogger.info("[{}] orerpay onsale skup {} success", uid, onselfSkupMap.get(uid));
orderPayBySkups(saleoutProcessingSkups.get(uid));
scriptLogger.info("[{}] orerpay processing skup {} success", uid, saleoutProcessingSkups.get(uid));
}
scriptLogger.info("========================== degrade end ==========================");
}
private List<Integer> getOnshelfSkupOfUid(Integer uid){
private double getSumEarnestSaleOutProcessiongSkups(Map<Integer, BigDecimal> saleoutProcessingSkupMap) {
double sum = 0.00d;
for (BigDecimal earnestMoney : saleoutProcessingSkupMap.values()) {
sum = YHMath.add(sum, earnestMoney.doubleValue());
}
return sum;
}
private Map<Integer, BigDecimal> getOnshelfSkupOfUid(Integer uid){
// 查询上架中 & 收取保证金的 skup
List<SellerOrderGoods> sellerOrderGoods = sellerOrderGoodsMapper.selectByUidAndAttributesDesc(uid,
List<SellerGoodSkup> sellerOrderGoods = sellerOrderGoodsMapper.selectOnsaleByUid(uid,
SkupStatus.CAN_SELL.getCode(), Lists.newArrayList(OrderAttributes.COMMON_IN_STOCK.getCode(),
OrderAttributes.FLAW.getCode(),OrderAttributes.SECOND_HAND.getCode(), OrderAttributes.ADVANCE_SALE.getCode()));
return sellerOrderGoods.stream().map(SellerOrderGoods::getId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(sellerOrderGoods)){
return Maps.newHashMap();
}
return sellerOrderGoods.stream().collect(Collectors.toMap(SellerGoodSkup::getSkup, SellerGoodSkup::getEarnestMoney));
}
private Map<Integer, BigDecimal> getSaleOutProcessingSkup(Integer uid){
List<SellerGoodSkup> sellerOrderGoods = sellerOrderGoodsMapper.selectSaleOutProcessiongByUid(uid);
if (CollectionUtils.isEmpty(sellerOrderGoods)){
return Maps.newHashMap();
}
return sellerOrderGoods.stream().collect(Collectors.toMap(SellerGoodSkup::getSkup, SellerGoodSkup::getEarnestMoney));
}
... ... @@ -631,7 +716,7 @@ public class StoreSellerServiceImpl implements IStoredSellerService {
}
public Pair<List<Integer>, Double> getOnselfSkupsAndEarnest(List<Integer> skups, Map<Integer, SellerOrderMeta> sellerOrderMetaMap, double leftMoney, int uid){
public Pair<List<Integer>, Double> getOnselfSkupsAndEarnest(Map<Integer, BigDecimal> onsaleSkupMap, double leftMoney){
double earnestTotal = 0.00;
... ... @@ -639,14 +724,11 @@ public class StoreSellerServiceImpl implements IStoredSellerService {
List<Integer> onshelfSkups = Lists.newArrayList();
double onShelfSkupsEarnest = 0.00;
Map<Integer, Double> skupEarnest = Maps.newHashMap();
for (Integer skup : skups){
for (Integer skup : onsaleSkupMap.keySet()){
// 保证金
SellerOrderMeta sellerOrderMeta = sellerOrderMetaMap.get(skup);
JSONObject earnestJson = JSONObject.parseObject(sellerOrderMeta.getMetaValue()).getJSONObject("earnestMoney");
double earnestMoney = earnestJson.getDouble("earnestMoney");
double earnestMoney = onsaleSkupMap.get(skup).doubleValue();
earnestTotal=YHMath.add(earnestTotal, earnestMoney);
... ...