Authored by chenchao

add dao

package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.SellerChangePriceRecord;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
public interface SellerChangePriceRecordMapper {
int insert(SellerChangePriceRecord record);
int insertSelective(SellerChangePriceRecord record);
SellerChangePriceRecord selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(SellerChangePriceRecord record);
List<SellerChangePriceRecord> selectByPreOrderCode(Long preOrderCode);
List<SellerChangePriceRecord> selectByPreOrderCodeNStatus(@Param("preOrderCode") Long preOrderCode,
@Param("statusList") Collection<Short> statusList);
SellerChangePriceRecord selectByOrderCode(Long orderCode);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order.model;
public class SellerChangePriceRecord {
private Integer id;
private Integer preSkup;
private Long preOrderCode;
private Integer skup;
private Long orderCode;
private Short status;
private String remark;
private Integer createTime;
private Integer updateTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getPreSkup() {
return preSkup;
}
public void setPreSkup(Integer preSkup) {
this.preSkup = preSkup;
}
public Long getPreOrderCode() {
return preOrderCode;
}
public void setPreOrderCode(Long preOrderCode) {
this.preOrderCode = preOrderCode;
}
public Integer getSkup() {
return skup;
}
public void setSkup(Integer skup) {
this.skup = skup;
}
public Long getOrderCode() {
return orderCode;
}
public void setOrderCode(Long orderCode) {
this.orderCode = orderCode;
}
public Short getStatus() {
return status;
}
public void setStatus(Short status) {
this.status = status;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim();
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yohoufo.dal.order.SellerChangePriceRecordMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.SellerChangePriceRecord">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="pre_skup" jdbcType="INTEGER" property="preSkup" />
<result column="pre_order_code" jdbcType="BIGINT" property="preOrderCode" />
<result column="skup" jdbcType="INTEGER" property="skup" />
<result column="order_code" jdbcType="BIGINT" property="orderCode" />
<result column="status" jdbcType="SMALLINT" property="status" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
id, pre_skup, pre_order_code, skup, order_code, status, remark, create_time, update_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_change_price_record
where id = #{id,jdbcType=INTEGER}
</select>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerChangePriceRecord" useGeneratedKeys="true">
insert into seller_change_price_record (pre_skup, pre_order_code, skup,
order_code, status, remark,
create_time, update_time)
values (#{preSkup,jdbcType=INTEGER}, #{preOrderCode,jdbcType=BIGINT}, #{skup,jdbcType=INTEGER},
#{orderCode,jdbcType=BIGINT}, #{status,jdbcType=SMALLINT}, #{remark,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerChangePriceRecord" useGeneratedKeys="true">
insert into seller_change_price_record
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="preSkup != null">
pre_skup,
</if>
<if test="preOrderCode != null">
pre_order_code,
</if>
<if test="skup != null">
skup,
</if>
<if test="orderCode != null">
order_code,
</if>
<if test="status != null">
status,
</if>
<if test="remark != null">
remark,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="preSkup != null">
#{preSkup,jdbcType=INTEGER},
</if>
<if test="preOrderCode != null">
#{preOrderCode,jdbcType=BIGINT},
</if>
<if test="skup != null">
#{skup,jdbcType=INTEGER},
</if>
<if test="orderCode != null">
#{orderCode,jdbcType=BIGINT},
</if>
<if test="status != null">
#{status,jdbcType=SMALLINT},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=INTEGER},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.SellerChangePriceRecord">
update seller_change_price_record
<set>
<if test="status != null">
status = #{status,jdbcType=SMALLINT},
</if>
<if test="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=INTEGER},
</if>
</set>
where order_code = #{orderCode,jdbcType=BIGINT}
</update>
<select id="selectByPreOrderCode" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_change_price_record
where pre_order_code = #{preOrderCode,jdbcType=BIGINT}
</select>
<select id="selectByOrderCode" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_change_price_record
where order_code = #{orderCode,jdbcType=BIGINT}
</select>
<select id="selectByPreOrderCodeNStatus" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_change_price_record
where pre_order_code = #{preOrderCode,jdbcType=BIGINT}
<if test="status != null">
and status in
<foreach collection="statusList" item="status" open="(" close=")" separator=",">
#{status,jdbcType=SMALLINT}
</foreach>
</if>
</select>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.order.service.impl.processor;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yohobuy.ufo.model.order.bo.PrdPrice;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SkupStatus;
... ... @@ -25,6 +26,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
... ... @@ -105,8 +107,13 @@ public class NESChangePricePrepareProcessor extends AbsChangePricePrepareProcess
BigDecimal targetEM = computeResult.getEarnestMoney().getEarnestMoney();
BigDecimal diffEarnestMoney = calDiffOfEM(sourceEM,targetEM);
//build one skup Map
Map<Integer, SkupDto> skupMap = Maps.newHashMapWithExpectedSize(1);
SkupDto skupDto = SkupDto.builder().sellerOrder(sellerOrder).sellerOrderGoods(psog).build();
skupMap.put(skup, skupDto);
return ChangePricePrepareDTO.builder()
.baseSellerOrderGoods(psog)
.skupMap(skupMap)
.prdPrice(prdPrice)
.salePrice(salePrice)
.diffEarnestMoney(diffEarnestMoney)
... ...
package com.yohoufo.order.service.seller.changePrice;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.constants.ChangePriceStatus;
import com.yohobuy.ufo.model.order.req.NESChangePriceReq;
import com.yohoufo.dal.order.SellerChangePriceRecordMapper;
import com.yohoufo.dal.order.model.SellerChangePriceRecord;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.convert.SellerOrderConvertor;
import com.yohoufo.order.model.dto.ChangePricePrepareDTO;
import com.yohoufo.order.model.response.OrderSubmitResp;
import com.yohoufo.order.service.impl.processor.NESChangePricePrepareProcessor;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 非入驻的卖家 变价服务类
* 涉及场景
* TODO case1: 变价计算
* TODO case2:变价待支付订单生成
* TODO case2.1 : 首次 ->
* TODO case2.2: 非首次 ->
* TODO case3:预支付 ->
* TODO case4:支付回调 ->
* TODO case5:主动取消 ->
* TODO case6:超时取消 ->
* TODO case7:订单列表 详情 可售商品 变价入口控制
* 功能点
* TODO F1:记录变价历史
* TODO F2: 失败时 对应变价记录 状态更新 备注原因
* TODO F3: 成功后 变价记录状态 订单状态 商品上架
* TODO F4:并发控制 :是否被并发下单 购买,
* Created by chao.chen on 2019/3/21.
*/
@Service
public class NotEntrySellerChangePriceService {
private final Logger logger = LoggerUtils.getSellerOrderLogger();
@Autowired
private SellerChangePriceRecordMapper sellerChangePriceRecordMapper;
@Autowired
private NESChangePricePrepareProcessor nesChangePricePrepareProcessor;
public boolean isChangePriceOrder(int skup){
return false;
}
public boolean isChangePriceOrder(long orderCode){
//todo
return false;
}
/**
* compute Change Price4 NES(Not Entry Seller)
* @param req
* @return
*/
public SoldPrdComputeBo computeChangePrice(NESChangePriceReq req){
logger.info("in computeChangePrice4NES, req {}", req);
logger.info("in NotEntrySellerChangePriceService.computeChangePrice, req {}", req);
ChangePricePrepareDTO cppDto = nesChangePricePrepareProcessor.checkAndAcquire(req);
SoldPrdComputeBo computeBo = SellerOrderConvertor.computeResult2SoldPrdComputeBo(cppDto.getComputeResult());
return computeBo;
... ... @@ -41,14 +80,36 @@ public class NotEntrySellerChangePriceService {
* @return
*/
public OrderSubmitResp changePrice(NESChangePriceReq req){
logger.info("in NotEntrySellerChangePriceService.changePrice, req {}", req);
ChangePricePrepareDTO cppDto = nesChangePricePrepareProcessor.checkAndAcquire(req);
//TODO
/*1. 屏蔽待变价skup
* 1.1 何时恢复
*
* 生成待支付订单,将订单号返回给客户端
/*
step 1. 检查变价记录 seller_change_price_record
1.1 存在时 -> step 3
1.2 不存在时 -> step 2
step 2. 屏蔽待变价skup
2.1 何时恢复
step 3. 取消已有的待支付订单 (修改订单 商品状态 ,变价记录是否记录失败原因)
step 4. 生成待支付订单 待上架的商品,将订单号返回给客户端
step 5. 记录变价记录(新的订单号,新skup)
*/
SellerOrderGoods psog = cppDto.getBaseSellerOrderGoods();
int skup = psog.getId();
SellerOrder sellerOrder = cppDto.getSkupMap().get(skup).getSellerOrder();
Long preOrderCode = sellerOrder.getOrderCode();
List<Short> scprs = Lists.newArrayListWithCapacity(2);
scprs.add(ChangePriceStatus.WAITING_DEAL.getCode());
scprs.add(ChangePriceStatus.SUCCESS.getCode());
List<SellerChangePriceRecord> scprList = sellerChangePriceRecordMapper.selectByPreOrderCodeNStatus(preOrderCode, scprs);
if (CollectionUtils.isEmpty(scprList)){
//首次 或 全部失败
}
//存在成功处理,有且只有一条才对(不完全正确,多终端操作同一个待变价商品)
//没有一条成功处理,但是存在等待处理
return null;
}
... ... @@ -62,4 +123,7 @@ public class NotEntrySellerChangePriceService {
}
}
... ...
... ... @@ -89,6 +89,7 @@ datasources:
- com.yohoufo.dal.order.SellerLevelFuncMapper
- com.yohoufo.dal.order.OrderOverTimeMapper
- com.yohoufo.dal.order.BuyerOrderViewMapper
- com.yohoufo.dal.order.SellerChangePriceRecordMapper
ufo_promotion:
servers:
... ...
... ... @@ -88,6 +88,7 @@ datasources:
- com.yohoufo.dal.order.SellerLevelFuncMapper
- com.yohoufo.dal.order.OrderOverTimeMapper
- com.yohoufo.dal.order.BuyerOrderViewMapper
- com.yohoufo.dal.order.SellerChangePriceRecordMapper
ufo_promotion:
servers:
... ...