Authored by chenchao

fix delete and digit number judge

... ... @@ -89,12 +89,14 @@ public class BigDecimalHelper {
}
public static boolean isDigitalNumber(String numStr){
Pattern pattern = Pattern.compile("\\d+.[0-9]+[1-9]+");
Pattern pattern = Pattern.compile("\\d+\\.([0-9]+)([1-9]+)");
Matcher matcher = pattern.matcher(numStr);
return matcher.matches();
}
public static void main(String[] args) {
System.out.println(isDigitalNumber("12.0000001"));
System.out.println(isDigitalNumber("11111"));
System.out.println(isDigitalNumber("1111.00"));
System.out.println(isDigitalNumber("1111.001"));
}
}
... ...
... ... @@ -58,4 +58,8 @@ public interface SellerOrderGoodsMapper {
int insertBatch(@Param("records") Collection<SellerOrderGoods> records);
SellerOrderGoods selectByUidStatusGBBN(SellerOrderGoods record);
List<SellerOrderGoods> selectGPByBNStatusPrice(SellerOrderGoods condition);
int batchDelete(@Param("skups") Collection<Integer> skups);
}
\ No newline at end of file
... ...
... ... @@ -25,6 +25,8 @@ public interface SellerOrderMapper {
int updateByPrimaryKeySelective(SellerOrder record);
int batchDelete(@Param("skups") Collection<Integer> skups);
int updateByPrimaryKey(SellerOrder record);
int updateByOrderCode(SellerOrder record);
... ...
... ... @@ -349,4 +349,22 @@
group by batch_no , goods_price ,`status`
limit 1
</select>
<select id="selectGPByBNStatusPrice" parameterType="com.yohoufo.dal.order.model.SellerOrderGoods" resultMap="BaseResultMap">
select <include refid="Base_Column_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}
</select>
<update id="batchDelete">
update seller_order_goods set is_del = 0
where id in
<foreach collection="skups" item="id" open="(" close=")" separator=",">
#{id,jdbcType=INTEGER}
</foreach>
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -266,4 +266,12 @@
#{status,jdbcType=INTEGER}
</foreach>
</select>
<update id="batchDelete">
update seller_order set is_del = 0
where skup in
<foreach collection="skups" item="skup" open="(" close=")" separator=",">
#{skup,jdbcType=INTEGER}
</foreach>
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -60,6 +60,7 @@ import com.yohoufo.order.service.proxy.ProductProxyService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.utils.PaymentHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -365,15 +366,11 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
CacheKeyBuilder.sellerOrderDetailKey(sellerOrderGoods)
));
}
result = true;
}else {
//1.2 商品下架失败后
result = false;
}
return result;
}
... ... @@ -394,7 +391,11 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
}
/**
* 删除
* @param req
* @return
*/
public boolean delete(SellerOrderCancelReq req){
log.info("seller self delete order,req {}", req);
int uid = req.getUid();
... ... @@ -423,23 +424,28 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
log.warn("not exist skup in delete action, req {}", req);
return false;
}
boolean isDelFlag = sellerOrderGoods.getIsDel() != null && DelStatus.IS_DEL.getCode() == sellerOrderGoods.getIsDel();
if (isDelFlag){
SellerOrderGoods sogc = new SellerOrderGoods();
sogc.setUid(uid);
sogc.setGoodsPrice(sellerOrderGoods.getGoodsPrice());
sogc.setBatchNo(sellerOrderGoods.getBatchNo());
sogc.setStatus(sellerOrderGoods.getStatus());
List<SellerOrderGoods> sogList = sellerOrderGoodsMapper.selectGPByBNStatusPrice(sogc);
Set<Integer> skups = sogList.parallelStream()
.filter(csog -> csog.getIsDel() == null || DelStatus.NOT_DEL.getCode() ==csog.getIsDel())
.map(SellerOrderGoods::getId).collect(Collectors.toSet());
if (CollectionUtils.isEmpty(skups)){
log.warn("in seller delete not exist skups, req {}", req);
return false;
}
//判断状态后更新
checkSellCanDelStatus(sellerOrder.getStatus());
SellerOrder target = new SellerOrder();
target.setId(sellerOrder.getId());
target.setIsDel(DelStatus.IS_DEL.getCode());
target.setUpdateTime(DateUtil.getCurrentTimeSecond());
sellerOrderMapper.updateByPrimaryKeySelective(target);
SellerOrderGoods tsog = new SellerOrderGoods();
tsog.setId(sellerOrder.getSkup());
tsog.setIsDel(DelStatus.IS_DEL.getCode());
sellerOrderGoodsMapper.updateByPrimaryKeySelective(tsog);
List<SellerOrder> soList = sellerOrderMapper.selectBySkups(skups);
for(SellerOrder so : soList){
checkSellCanDelStatus(so.getStatus());
}
sellerOrderMapper.batchDelete(skups);
sellerOrderGoodsMapper.batchDelete(skups);
}
... ... @@ -552,21 +558,19 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
*/
public BatchChangePriceResp batchChangePrice(BatchChangePriceReq req) throws GatewayException {
ChangePricePrepareDTO cppDto = changePricePrepareProcessor.checkAndAcquire(req);
BigDecimal diffEarnestMoney = cppDto.getDiffEarnestMoney();
if (diffEarnestMoney.compareTo(BigDecimal.ZERO) == 0){
throw new UfoServiceException(401, "前后价格没有变化");
}
BigDecimal preSalePrice = cppDto.getPreSalePrice(),
salePrice = cppDto.getSalePrice();
int uid = req.getUid();
Map<Integer, SkupDto> skupMap = cppDto.getSkupMap();
SellerOrderComputeResult computeResult = cppDto.getComputeResult();
//1 划账
BigDecimal diffEarnestMoney = cppDto.getDiffEarnestMoney();
BigDecimal totalDiffMoney = diffEarnestMoney.multiply(new BigDecimal(skupMap.size()));
SellerWalletDetail.Type swdType = SellerWalletDetail.Type.ADD_PRICE;
MerchantOrderAttachInfo moai = MerchantOrderAttachInfo.builder().uid(req.getUid())
.afterProductPrice(cppDto.getSalePrice())
.afterProductPrice(salePrice)
.beforeEarnestMoney(cppDto.getPreEarnestMoney().toPlainString())
.beforeProductPrice(cppDto.getPreSalePrice())
.beforeProductPrice(preSalePrice)
.afterEarnestMoney(computeResult.getEarnestMoney().getEarnestMoney().toPlainString())
.earnestMoney(totalDiffMoney).productCount(skupMap.size())
.seriNo(String.valueOf(req.getBatchNo()))
... ... @@ -578,7 +582,6 @@ public class SellerOrderService implements IOrderListService, IOrderDetailServi
if(Objects.nonNull(sellerWallet)) {
//1.1 划账成功后
//TODO 2 商品变价(同步价格到商品)
BigDecimal salePrice = cppDto.getSalePrice();
Set<Integer> skupSet = skupMap.keySet();
productProxyService.batchUpdatePrice(skupSet, salePrice);
... ...
... ... @@ -57,6 +57,9 @@ public class ChangePricePrepareProcessor {
@Autowired
private SellerOrderComputeHandler computeHandler;
@Autowired
private PriceComputePrepareProcessor priceComputePrepareProcessor;
public ChangePricePrepareDTO checkAndAcquire(BatchChangePriceReq req) throws GatewayException {
int uid = req.getUid();
if (uid <= 0){
... ... @@ -80,20 +83,7 @@ public class ChangePricePrepareProcessor {
//check batch no
Long batchNo = checkNAcquireBatchNo(req.getBatchNo(), req);
BigDecimal salePrice;
try{
salePrice = new BigDecimal(req.getPrice());
}catch (Exception ex){
logger.warn("ChangePrice checkAndAcquire salePrice illegal , req {}", req);
throw new UfoServiceException(400, "售价格式错误");
}
if (salePrice.compareTo(BigDecimal.ZERO) <= 0){
throw new UfoServiceException(401, "价格只能为正整数");
}
if(BigDecimalHelper.isDigitalNumber(req.getPrice())){
throw new UfoServiceException(401, "价格只能为正整数");
}
BigDecimal salePrice = priceComputePrepareProcessor.checkAndAcquireSalePrice(req.getPrice());
//检查是否有买家下单,返回的是可售 待买家付款的skup
Map<Integer, SkupDto> skupOfSalingMap = checkExistWaitingBuyerPay(batchNo, req);
... ... @@ -103,6 +93,11 @@ public class ChangePricePrepareProcessor {
SkupDto sampleSkupDto = skupMap.values().iterator().next();
int sampleSkup = sampleSkupDto.getSkup();
SellerOrderGoods sampleSog = sampleSkupDto.getSellerOrderGoods();
BigDecimal preSalePrice = sampleSog.getGoodsPrice();
if (preSalePrice.compareTo(salePrice) == 0){
throw new UfoServiceException(401, "前后价格没有变化");
}
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(sampleSkup);
BigDecimal sourceEM = sellerOrder.getEarnestMoney();
int storageId = sampleSog.getStorageId();
... ... @@ -139,7 +134,7 @@ public class ChangePricePrepareProcessor {
.skupMap(skupMap)
.computeResult(computeResult)
.preEarnestMoney(sourceEM)
.preSalePrice(sampleSog.getGoodsPrice())
.preSalePrice(preSalePrice)
.tips(tips)
.build();
}
... ...
... ... @@ -34,32 +34,15 @@ public class PriceComputePrepareProcessor {
}
}
public PriceComputeNode checkBasePrice(SellerOrderComputeReq req) throws GatewayException {
int uid = req.getUid();
if(uid <= 0){
log.warn("in computePublishPrd uid illegal , req {}", req);
throw new GatewayException(400, "用户ID错误");
}
//
Integer storageId = req.getStorageId();
if (storageId <=0 ){
log.warn("in computePublishPrd storageId illegal , req {}", req);
throw new GatewayException(400, "storageId 错误");
}
int num;
if ((num = req.getNum())<=0){
log.warn("in computePublishPrd num illegal , req {}", req);
throw new GatewayException(400, "非法数量值");
}
public BigDecimal checkAndAcquireSalePrice(String price){
/*商品鉴定费 ¥10.00
商品包装费 ¥10.00
平台服务费(5%,优惠期间0%) ¥0.00
*/
String price = req.getPrice();
if (StringUtils.isBlank(price)){
log.warn("in computePublishPrd price illegal , req {}", req);
throw new GatewayException(400, "没有价格");
log.warn("in checkAndAcquireSalePrice price illegal , price {}", price);
throw new UfoServiceException(400, "没有价格");
}
/*
if(!price.endsWith("9")){
... ... @@ -71,8 +54,8 @@ public class PriceComputePrepareProcessor {
try{
prdPrice = new BigDecimal(price);
}catch (Exception e){
log.warn("in computePublishPrd price convert BigDecimal fail, {}", req);
throw new GatewayException(400, "非法数字");
log.warn("in checkAndAcquireSalePrice price convert BigDecimal fail, price {}", price);
throw new UfoServiceException(400, "非法数字");
}
if (prdPrice.compareTo(BigDecimal.ZERO) <= 0){
throw new UfoServiceException(401, "价格只能为正整数");
... ... @@ -81,6 +64,28 @@ public class PriceComputePrepareProcessor {
if(BigDecimalHelper.isDigitalNumber(price)){
throw new UfoServiceException(401, "价格只能为正整数");
}
return prdPrice;
}
public PriceComputeNode checkBasePrice(SellerOrderComputeReq req) {
int uid = req.getUid();
if(uid <= 0){
log.warn("in computePublishPrd uid illegal , req {}", req);
throw new UfoServiceException(400, "用户ID错误");
}
//
Integer storageId = req.getStorageId();
if (storageId <=0 ){
log.warn("in computePublishPrd storageId illegal , req {}", req);
throw new UfoServiceException(400, "storageId 错误");
}
int num;
if ((num = req.getNum())<=0){
log.warn("in computePublishPrd num illegal , req {}", req);
throw new UfoServiceException(400, "非法数量值");
}
BigDecimal prdPrice = checkAndAcquireSalePrice(req.getPrice());
return new PriceComputeNode(uid, storageId, num, prdPrice);
}
... ...
... ... @@ -49,6 +49,9 @@ public class SellerOrderPrepareProcessor {
@Autowired
private SellerWalletMapper sellerWalletMapper;
@Autowired
private PriceComputePrepareProcessor priceComputePrepareProcessor;
public SellerOrderContext buildPublishPrdCtx(SellerOrderSubmitReq req) throws GatewayException {
SellerOrderContext ctx = buildSellerOrderContext(req);
int uid = ctx.getUid();
... ... @@ -91,31 +94,8 @@ public class SellerOrderPrepareProcessor {
log.warn("storageId illegal , uid {}", uid);
throw new GatewayException(400, "storageId 错误");
}
String price = req.getPrice();
if (StringUtils.isBlank(price)){
log.warn("in buildSellerOrderContext price illegal , req {}", req);
throw new GatewayException(400, "没有价格");
}
/*
if(!price.endsWith("9")){
log.warn("in buildSellerOrderContext price illegal , req {}", req);
throw new GatewayException(400, "价格须为以9结尾的正整数");
}*/
BigDecimal salePrice;
try{
salePrice = new BigDecimal(req.getPrice());
}catch (Exception ex){
log.warn("storageId illegal , uid {}", uid);
throw new GatewayException(400, "售价格式错误");
}
if (salePrice.compareTo(BigDecimal.ZERO) <= 0){
throw new UfoServiceException(401, "价格只能为正整数");
}
if(BigDecimalHelper.isDigitalNumber(price)){
throw new UfoServiceException(401, "价格只能为正整数");
}
BigDecimal salePrice = priceComputePrepareProcessor.checkAndAcquireSalePrice(req.getPrice());
int addressId = AddressUtil.getDecryptStr(req.getAddressId());
if (addressId < 0){
... ...
... ... @@ -3,7 +3,6 @@ package com.yohoufo.order.service.proxy;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.exception.GatewayException;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.product.model.ProductInfo;
... ... @@ -29,23 +28,35 @@ import java.util.Set;
public class ProductProxyService {
final Logger logger = LoggerFactory.getLogger(getClass());
@Data
public static class PrdPrice{
private BigDecimal maxPrice;
private BigDecimal minPrice;
private BigDecimal suggestMaxPrice;
private BigDecimal suggestMinPrice;
private BigDecimal leastPrice;
}
@Autowired
private UfoServiceCaller ufoServiceCaller;
private final static String syncSkup = "ufo.product.createSkup";
private final static String SYNC_SKUP_STATUS = "ufo.product.sellerUpdateStatus";
public final static String syncSkup = "ufo.product.createSkup";
public final static String SYNC_SKUP_STATUS = "ufo.product.sellerUpdateStatus";
/**
* 减库存
*/
private final static String SUBTRACT_STORAGE = "ufo.product.saleSkup";
public final static String SUBTRACT_STORAGE = "ufo.product.saleSkup";
/**
* 归还库存
*/
private final static String RETURN_STORAGE = "ufo.product.cancelSaleSkup";
public final static String RETURN_STORAGE = "ufo.product.cancelSaleSkup";
static String batchCreateSkup = "ufo.product.batchCreateSkup";
static String sellerBatchUpdateStatus = "ufo.product.sellerBatchUpdateStatus";
public static String STORAGE_DATA = "ufo.product.storage.data";
public boolean subtractStorage(Integer productId, Integer skup){
... ... @@ -58,20 +69,10 @@ public class ProductProxyService {
public boolean returnStorage(Integer skup){
ApiResponse resp = ufoServiceCaller.call(RETURN_STORAGE, ApiResponse.class, skup, 1);
return (resp == null || resp.getData()==null) ? false : (boolean)resp.getData();
}
@Data
public static class PrdPrice{
private BigDecimal maxPrice;
private BigDecimal minPrice;
private BigDecimal suggestMaxPrice;
private BigDecimal suggestMinPrice;
private BigDecimal leastPrice;
}
public PrdPrice getPrdPriceRange(int storageId){
StorageDataResp storage = getStorageData(storageId);
... ... @@ -105,9 +106,15 @@ public class ProductProxyService {
}
public StorageDataResp getStorageData(int storageId){
StorageDataResp prdResp = ufoServiceCaller.call("ufo.product.storage.data", storageId);
logger.info("in getStorageData storageId {} prdResp {}", storageId, prdResp);
StorageDataResp prdResp = null;
try {
prdResp = ufoServiceCaller.call(STORAGE_DATA, storageId);
logger.info("in getStorageData storageId {} prdResp {}", storageId, prdResp);
}catch (Exception ex){
logger.warn("in getStorageData call {} fail, storageId {}", STORAGE_DATA, storageId);
}
return prdResp;
}
... ... @@ -190,8 +197,7 @@ public class ProductProxyService {
return (null == resp || null == resp.getData())? false : (boolean)resp.getData();
}
static String batchCreateSkup = "ufo.product.batchCreateSkup";
static String sellerBatchUpdateStatus = "ufo.product.sellerBatchUpdateStatus";
public boolean batchCreateSkup(List<SellerOrderGoods> sogList){
List<StoragePriceBo> skupBoList = new ArrayList<>(sogList.size());
... ...