Authored by caoyan

寄存转现货

... ... @@ -89,4 +89,10 @@ public interface StorageDepositMapper {
);
int removeStorageLockFlag(int id);
int selectUserValidDepositCnt(@Param("uid")Integer uid, @Param("storageId")Integer storageId);
List<StorageDeposit> selectUserValidDepositList(@Param("uid") Integer uid, @Param("storageId") Integer storageId,
@Param("start") Integer start, @Param("count") Integer count);
}
\ No newline at end of file
... ...
... ... @@ -219,6 +219,19 @@
</if>
limit #{start}, #{count}
</select>
<select id="selectUserValidDepositCnt" resultType="java.lang.Integer">
select count(1) from storage_deposit
where owner_uid = #{uid} and status=1 and storage_id =#{storageId} and del_status=0 and deposit_type=0
and deposit_end_time &gt; unix_timestamp(now())
</select>
<select id="selectUserValidDepositList" resultMap="BaseResultMap">
select <include refid="Base_Column_List" /> from storage_deposit
where owner_uid = #{uid} and status=1 and storage_id =#{storageId} and del_status=0 and deposit_type=0
and deposit_end_time &gt; unix_timestamp()
limit #{start}, #{count}
</select>
<update id="updateDelStatusByCode">
update storage_deposit
... ... @@ -244,4 +257,5 @@
where id = #{id,jdbcType=INTEGER}
AND lock_flag = 1
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -250,4 +250,38 @@ public class DepositController {
LOG.info("end insertFakeDeposit uid is {}, appraiseOrderCode is {} result: {}", uid, appraiseOrderCode, count);
return count;
}
@RequestMapping(params = "method=ufo.deposit.list")
@Cachable(expire = 30, pageArgs = {2,3})
public ApiResponse save(@RequestParam("uid") Integer uid, @RequestParam("storageId") Integer storageId,
@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
@RequestParam(value = "limit", required = false, defaultValue = "10") Integer limit) {
LOG.info("ufo.deposit.list in. uid is {}", uid);
if(null == uid || 0 == uid.intValue()) {
return new ApiResponse.ApiResponseBuilder().code(400).message("uid不能为空").build();
}
if(null == storageId || 0 == storageId) {
return new ApiResponse.ApiResponseBuilder().code(400).message("storageId不能为空").build();
}
UserDopositReq builder = UserDopositReq.builder().uid(uid).storageId(storageId).page(page-1).limit(limit).build();
JSONObject result = depositService.queryListByUidAndStorageId(builder);
return new ApiResponse.ApiResponseBuilder().code(200).data(result).message("查询成功").build();
}
@RequestMapping(params = "method=ufo.deposit.count")
@Cachable(expire = 180)
public ApiResponse getUserDepositCount(@RequestParam("uid") Integer uid, @RequestParam("storageId") Integer storageId) {
LOG.info("ufo.deposit.count in. uid is {}", uid);
if(null == uid || 0 == uid.intValue()) {
return new ApiResponse.ApiResponseBuilder().code(400).message("uid不能为空").build();
}
if(null == storageId || 0 == storageId) {
return new ApiResponse.ApiResponseBuilder().code(400).message("storageId不能为空").build();
}
UserDopositReq builder = UserDopositReq.builder().uid(uid).storageId(storageId).build();
int result = depositService.queryCntByUidAndStorageId(builder);
return new ApiResponse.ApiResponseBuilder().code(200).data(result).message("查询成功").build();
}
}
... ...
package com.yohoufo.order.service;
import java.util.List;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohobuy.ufo.model.order.bo.DepositDetailBo;
import com.yohobuy.ufo.model.order.bo.DepositProductBo;
import com.yohobuy.ufo.model.order.constants.StorageDepositStatusEnum;
import com.yohobuy.ufo.model.order.req.UserDopositReq;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.model.StorageDeposit;
import java.util.Collection;
import java.util.List;
public interface DepositService {
PageResp<List<DepositProductBo>> queryUserDoposit(Integer uid, Integer page, Integer limit);
... ... @@ -105,4 +103,27 @@ public interface DepositService {
* @return
*/
int insertFakeDeposit(Integer uid, long appraiseOrderCode, Long parentAppraiseOrderCode);
/**
* 查询用户所属的寄存商品
* @param req
* @return
*/
JSONObject queryListByUidAndStorageId(UserDopositReq req);
/**
* 查询用户所属的寄存商品数量
* @param req
* @return
*/
int queryCntByUidAndStorageId(UserDopositReq req);
/**
* 更新寄存的状态为待拣货状态
* @param uid
* @param depositCode
* @return
*/
int updateDepositWaitToPick(Integer uid, String depositCode);
}
... ...
package com.yohoufo.order.service.impl;
import com.google.common.base.Throwables;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
import com.yohobuy.ufo.model.order.bo.DepositDetailBo;
import com.yohobuy.ufo.model.order.bo.DepositProductBo;
import com.yohobuy.ufo.model.order.constants.*;
import com.yohobuy.ufo.model.order.constants.DepositOrderStatusEnum;
import com.yohobuy.ufo.model.order.constants.DepositOutTypeEnum;
import com.yohobuy.ufo.model.order.constants.DepositSourceEnum;
import com.yohobuy.ufo.model.order.constants.DepositTypeEnum;
import com.yohobuy.ufo.model.order.constants.DepotType;
import com.yohobuy.ufo.model.order.constants.StorageDepositStatusEnum;
import com.yohobuy.ufo.model.order.req.UserDopositReq;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.cache.ControllerCacheAop;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.*;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.dal.order.AppraiseOrderMapper;
import com.yohoufo.dal.order.AppraiseOrderStorageMapper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.StorageDepositMapper;
import com.yohoufo.dal.order.model.AppraiseOrder;
import com.yohoufo.dal.order.model.AppraiseOrderStorage;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.dal.order.model.StorageDeposit;
import com.yohoufo.dal.order.model.StorageDepositCount;
import com.yohoufo.order.controller.DepositController;
import com.yohoufo.order.model.response.AppraiseAddressResp;
import com.yohoufo.order.service.DepositService;
... ... @@ -25,16 +54,6 @@ import com.yohoufo.order.service.proxy.InBoxFacade;
import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.seller.SkupService;
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.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
... ... @@ -80,6 +99,8 @@ public class DepositServiceImpl implements DepositService {
@Autowired
private AppraiseOrderStorageMapper appraiseOrderStorageMapper;
@Autowired
private AppraiseOrderMapper appraiseOrderMapper;
@Override
public PageResp<List<DepositProductBo>> queryUserDoposit(Integer uid, Integer page, Integer limit) {
... ... @@ -748,4 +769,82 @@ public class DepositServiceImpl implements DepositService {
return insert;
}
@Override
public JSONObject queryListByUidAndStorageId(UserDopositReq req) {
JSONObject result = new JSONObject();
int total = storageDepositMapper.selectUserValidDepositCnt(req.getUid(), req.getStorageId());
if(total == 0) {
return result;
}
List<StorageDeposit> list = storageDepositMapper.selectUserValidDepositList(req.getUid(), req.getStorageId(), req.getPage(), req.getLimit());
Map<Integer, SellerOrderGoods> goodsMap = depositHelpService.getProductBySkuMap(Lists.newArrayList(req.getStorageId()));
SellerOrderGoods goods = goodsMap.get(req.getStorageId());
List<Long> orderCodeList = list.stream().map(StorageDeposit::getOrderCode).collect(Collectors.toList());
result.put("imageUrl", goods.getImageUrl());
result.put("productName", goods.getProductName());
result.put("sizeName", goods.getSizeName());
result.put("count", list.size());
result.put("list", convertDepositResp(list, orderCodeList));
return result;
}
@Override
public int queryCntByUidAndStorageId(UserDopositReq req) {
return storageDepositMapper.selectUserValidDepositCnt(req.getUid(), req.getStorageId());
}
@Override
public int updateDepositWaitToPick(Integer uid, String depositCode) {
int num = 0;
StorageDeposit deposit = storageDepositMapper.selectByDepositCode(uid, depositCode, Lists.newArrayList(StorageDepositStatusEnum.HAS_IN.getCode()));
if(null == deposit) {
return num;
}
LOGGER.info("updateDepositWaitToPick, uid is {}, depositCode is {}, old depositInfo is {}", uid, depositCode, deposit);
return storageDepositMapper.updateStorageStatus(deposit.getId(), StorageDepositStatusEnum.WAITING_OUT.getCode(), 0, DepositOutTypeEnum.OUTTYPE_DEPOSIT_CHANGE_TO_IN_STOCK.getCode(), uid);
}
private List<DepositDetailBo> convertDepositResp(List<StorageDeposit> list, List<Long> orderCodeList){
Map<Long, BigDecimal> orderCodePriceMap = Maps.newHashMap();
List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectByOrderCodes(orderCodeList, null);
if(CollectionUtils.isNotEmpty(buyerOrderList)) {
orderCodePriceMap.putAll(buyerOrderList.stream().collect(Collectors.toMap(BuyerOrder::getOrderCode, BuyerOrder::getAmount)));
orderCodeList.removeAll(buyerOrderList.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList()));
}
if(CollectionUtils.isNotEmpty(orderCodeList)) {
List<AppraiseOrder> appraiseOrderList = appraiseOrderMapper.selectByOrderCodeList(orderCodeList);
if(CollectionUtils.isNotEmpty(appraiseOrderList)) {
orderCodePriceMap.putAll(appraiseOrderList.stream().collect(Collectors.toMap(AppraiseOrder::getOrderCode, AppraiseOrder::getAmount)));
}
}
List<DepositDetailBo> resultList = Lists.newArrayList();
for(StorageDeposit item : list) {
DepositDetailBo resp = new DepositDetailBo();
resp.setDepositCode(item.getDepositCode());
resp.setOrderStatusStr(getOrderStatusStr(item.getOrderStatus()));
resp.setRemainDays(String.valueOf((item.getDepositEndTime() - DateUtil.getCurrentTimeSecond()) / 60*60*24));
resp.setPrice(null == orderCodePriceMap.get(item.getOrderCode()) ? "" : String.valueOf(orderCodePriceMap.get(item.getOrderCode()).intValue()));
resultList.add(resp);
}
return resultList;
}
private String getOrderStatusStr(Integer orderStatus) {
if(orderStatus.intValue() == 0) {
return "待上架";
}else if(orderStatus.intValue() == 1) {
return "出售中";
}else {
return StringUtils.EMPTY;
}
}
}
... ...