Authored by mali

召回试算接口

package com.yohoufo.dal.order;
import com.yohoufo.dal.order.model.DepositOrder;
public interface DepositOrderMapper {
int insert(DepositOrder record);
DepositOrder selectByPrimaryKey(Integer id);
int updateByPrimaryKey(DepositOrder record);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.order.model;
import lombok.Builder;
import lombok.ToString;
import java.math.BigDecimal;
@ToString
@Builder
public class DepositOrder {
private Integer id;
private Integer uid;
private Long orderCode;
private String depositCode;
private BigDecimal amount;
private Integer payment;
private Integer clientType;
private Integer eventType;
private Integer status;
private Integer createTime;
private Integer updateTime;
}
\ No newline at end of file
... ...
... ... @@ -28,4 +28,6 @@ public interface StorageDepositMapper {
int queryUserDopositBackCount(Integer uid);
List<StorageDeposit> queryUserDopositBack(@Param("uid") Integer uid, @Param("start") Integer start, @Param("count") Integer count);
StorageDeposit selectByDepositCode(@Param("uid") int uid, @Param("depositCode")String depositCode);
}
\ 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.DepositOrderMapper" >
<resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.DepositOrder" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="uid" property="uid" jdbcType="INTEGER" />
<result column="order_code" property="orderCode" jdbcType="BIGINT" />
<result column="deposit_code" property="depositCode" jdbcType="VARCHAR" />
<result column="amount" property="amount" jdbcType="DECIMAL" />
<result column="payment" property="payment" jdbcType="INTEGER" />
<result column="client_type" property="clientType" jdbcType="INTEGER" />
<result column="event_type" property="eventType" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, uid, order_code, deposit_code, amount, payment, client_type, event_type, status,
create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from deposit_order
where id = #{id,jdbcType=INTEGER}
</select>
<insert id="insert" parameterType="com.yohoufo.dal.order.model.DepositOrder" >
insert into deposit_order (id, uid, order_code,
deposit_code, amount, payment,
client_type, event_type, status,
create_time, update_time)
values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{orderCode,jdbcType=BIGINT},
#{depositCode,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL}, #{payment,jdbcType=INTEGER},
#{clientType,jdbcType=INTEGER}, #{eventType,jdbcType=INTEGER}, #{status,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
</insert>
<update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.DepositOrder" >
update deposit_order
set uid = #{uid,jdbcType=INTEGER},
order_code = #{orderCode,jdbcType=BIGINT},
deposit_code = #{depositCode,jdbcType=VARCHAR},
amount = #{amount,jdbcType=DECIMAL},
payment = #{payment,jdbcType=INTEGER},
client_type = #{clientType,jdbcType=INTEGER},
event_type = #{eventType,jdbcType=INTEGER},
status = #{status,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -272,12 +272,17 @@
group by product_id
</select>
<select id="queryUserDopositBackCount" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select count(*) from storage_deposit
select count(1) from storage_deposit
where owner_uid = #{uid} and status in(2,3,4) and out_type in(0,1) and del_status=0
</select>
<select id="queryUserDopositBack" resultMap="BaseResultMap">
select * from storage_deposit
select <include refid="Base_Column_List" /> from storage_deposit
where owner_uid = #{uid} and status in(2,3,4) and out_type in(0,1) and del_status=0
limit #{start}, #{count}
</select>
<select id="selectByDepositCode" resultMap="BaseResultMap">
select <include refid="Base_Column_List" /> from storage_deposit
where owner_uid = #{uid} and status = 1 and del_status= 0 AND deposit_code = #{depositCode,jdbcType=VARCHAR} limit 1
</select>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.order.controller;
import com.yohobuy.ufo.model.order.bo.SoldPrdComputeBo;
import com.yohobuy.ufo.model.order.req.DepositOrderComputeReq;
import com.yohobuy.ufo.model.order.req.SellerOrderComputeReq;
import com.yohobuy.ufo.model.order.resp.DepositOrderComputeResp;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.order.service.deposit.DepositOrderService;
import com.yohoufo.order.utils.LoggerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by li.ma on 2019/7/9.
*/
@Controller
public class DepositOrderController {
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
@Autowired
private DepositOrderService depositOrderService;
/**
* 根据库存货号,计算召回的费用
* @param uid
* @param deposit_code 库存货号
* @param price
* @return
* @throws GatewayException
*/
@RequestMapping(params = "method=ufo.deposit.computeRecall")
@ResponseBody
public ApiResponse computePublishPrd(@RequestParam(name = "uid", required = true)int uid,
@RequestParam(name = "deposit_code", required = true)String depositCode) throws GatewayException {
DepositOrderComputeReq req = DepositOrderComputeReq.builder().uid(uid).depositCode(depositCode).build();
LOG.info("in ufo.deposit.computeRecall, req {}", req);
DepositOrderComputeResp resp = depositOrderService.computePublishPrd(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(resp).message("算费成功").build();
}
}
... ...
package com.yohoufo.order.service.deposit;
import com.google.common.collect.Lists;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.req.DepositOrderComputeReq;
import com.yohobuy.ufo.model.order.resp.DepositOrderComputeResp;
import com.yohobuy.ufo.model.order.vo.AddressInfo;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.DepositOrderMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.BuyerOrderGoods;
import com.yohoufo.dal.order.model.DepositOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.dal.order.model.StorageDeposit;
import com.yohoufo.dal.product.StorageDepositMapper;
import com.yohoufo.order.convert.GoodsInfoConvertor;
import com.yohoufo.order.service.IBuyerOrderMetaService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.helpers.MessageFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by li.ma on 2019/7/9.
*/
@Service
public class DepositOrderService {
@Autowired
private DepositOrderMapper depositOrderMapper;
@Autowired
private StorageDepositMapper storageDepositMapper;
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
private IBuyerOrderMetaService buyerOrderMetaService;
public int insert(DepositOrder record) {
return depositOrderMapper.insert(record);
}
/**
* 根据库存货号,计算需要召回的费用
* @param req
* @return
*/
public DepositOrderComputeResp computePublishPrd(DepositOrderComputeReq req) {
StorageDeposit storageDeposit = storageDepositMapper.selectByDepositCode(req.getUid(), req.getDepositCode());
// TODO 不存在的时候有异常
// TODO 一期都是要违约金的 storageDeposit.getDepositEndTime();
Integer depositEndTime = storageDeposit.getDepositEndTime();
int depositRemainDay = 45;
if (null != depositEndTime) {
depositRemainDay = (depositEndTime - DateUtil.getCurrentTimeSecond()) / 24 * 60 * 60;
}
Long skup = storageDeposit.getSkup();
Long orderCode = storageDeposit.getOrderCode();
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup.intValue());
GoodsInfo goodsInfo = null;
if (null != sellerOrderGoods) {
goodsInfo = GoodsInfoConvertor.SellerOrderGoods2GoodsInfo(sellerOrderGoods);
}
List<BuyerOrderGoods> buyerOrderGoodses = buyerOrderGoodsMapper.selectBySkups(Lists.newArrayList(skup.intValue()));
DepositOrderComputeResp.PriceInfo priceInfo = null;
if (CollectionUtils.isNotEmpty(buyerOrderGoodses)) {
priceInfo = DepositOrderComputeResp.PriceInfo.builder().goodPrice(buyerOrderGoodses.get(0).getGoodsAmount().toPlainString()).build();
}
AddressInfo addressInfo = buyerOrderMetaService.getAddressInfo(req.getUid(), orderCode);
return DepositOrderComputeResp.builder().depositRemainDay(getReplacedContent(DepositOrderComputeResp.DEPOSITREMAINDAY_TIP, depositRemainDay))
.userAddress(addressInfo).priceInfo(priceInfo).goodsInfo(goodsInfo).build();
}
private String getReplacedContent(String content ,Object... params) {
return MessageFormatter.arrayFormat(content, params).getMessage();
}
}
... ...