提交 ffb51fc5 authored 作者: Whispa's avatar Whispa

commit commit

上级 125e987c
...@@ -86,9 +86,7 @@ public class ImageSearchController extends Controller { ...@@ -86,9 +86,7 @@ public class ImageSearchController extends Controller {
if( labelRepository.existsByItemItemId(itemId) ) if( labelRepository.existsByItemItemId(itemId) )
return new Result<>(stationItem.getLabelList()); return new Result<>(stationItem.getLabelList());
String itemImg = stationItem.getItemImg(); String img = stationItem.catchSingleImage();
String[] strings = itemImg != null ? itemImg.split(";") : new String[]{};
String img = strings.length > 0 ? strings[0] : itemImg;
if( img != null) { if( img != null) {
System.out.println("Searching"); System.out.println("Searching");
List<ItemLabel> itemLabels = getItemLabels(img); List<ItemLabel> itemLabels = getItemLabels(img);
......
...@@ -61,7 +61,7 @@ public class OrderController extends Controller { ...@@ -61,7 +61,7 @@ public class OrderController extends Controller {
record.setTemplate(item.getExpress()); record.setTemplate(item.getExpress());
record.setItemTitle(item.getItemName()); record.setItemTitle(item.getItemName());
record.setItemPrice(BigDecimal.valueOf(price)); record.setItemPrice(BigDecimal.valueOf(price));
record.setItemImg(item.getItemImg()); record.setItemImg(item.catchSingleImage());
return record; return record;
} }
...@@ -163,111 +163,106 @@ public class OrderController extends Controller { ...@@ -163,111 +163,106 @@ public class OrderController extends Controller {
@RequestParam(value = "itemSku",required = false) String itemSku, @RequestParam(value = "itemSku",required = false) String itemSku,
@RequestParam(value = "itemPrice",required = false) Double itemPrice, @RequestParam(value = "itemPrice",required = false) Double itemPrice,
@RequestParam(value = "web", required = false) String web) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException { @RequestParam(value = "web", required = false) String web) throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
try{ TbCfUserInfo user = this.user.user();
TbCfUserInfo user = this.user.user(); String userId = user.getUserId();
String userId = user.getUserId();
int v_code = ResultCodeEnum.VALIDATE_ERROR.getCode(); int v_code = ResultCodeEnum.VALIDATE_ERROR.getCode();
if (tbCfOrder == null) if (tbCfOrder == null)
return new Result<>(v_code, "Empty body"); return new Result<>(v_code, "Empty body");
boolean noCartBody = tbCfOrder.getIds() == null || tbCfOrder.getIds().length <= 0; boolean noCartBody = tbCfOrder.getIds() == null || tbCfOrder.getIds().length <= 0;
boolean noPayNow = itemId == null || itemId.isEmpty() || itemNum == null || itemNum <= 0 || itemPrice == null || itemPrice <= 0; boolean noPayNow = itemId == null || itemId.isEmpty() || itemNum == null || itemNum <= 0 || itemPrice == null || itemPrice <= 0;
if (noCartBody && noPayNow) if (noCartBody && noPayNow)
return new Result<>(v_code, "Empty body"); return new Result<>(v_code, "Empty body");
List<TbCfCartRecordR> allByUserId = new ArrayList<>(); List<TbCfCartRecordR> allByUserId = new ArrayList<>();
if (!noPayNow) { if (!noPayNow) {
Optional<TbCfStationItem> byId = itemRepository.findById(itemId); Optional<TbCfStationItem> byId = itemRepository.findById(itemId);
if (!byId.isPresent()) if (!byId.isPresent())
return new Result<>(ResultCodeEnum.SERVICE_ERROR.getCode(), "Missing information !"); return new Result<>(ResultCodeEnum.SERVICE_ERROR.getCode(), "Missing information !");
TbCfStationItem stationItem = byId.get(); TbCfStationItem stationItem = byId.get();
allByUserId.add(getCart(stationItem, itemSku,itemNum,itemPrice)); allByUserId.add(getCart(stationItem, itemSku,itemNum,itemPrice));
} else { } else {
System.out.println(Arrays.toString(tbCfOrder.getIds())); System.out.println(Arrays.toString(tbCfOrder.getIds()));
allByUserId = cartRepository.findAllByCartRecordIdIn(tbCfOrder.getIds()); allByUserId = cartRepository.findAllByCartRecordIdIn(tbCfOrder.getIds());
} }
String addressId = tbCfOrder.getDeliveryAddressId(); String addressId = tbCfOrder.getDeliveryAddressId();
if (addressId == null || addressId.isEmpty()) return new Result<>(v_code, "Address id is required"); if (addressId == null || addressId.isEmpty()) return new Result<>(v_code, "Address id is required");
if (allByUserId.isEmpty()) { if (allByUserId.isEmpty()) {
return new Result<>(v_code, "There are no items in the shopping cart"); return new Result<>(v_code, "There are no items in the shopping cart");
} }
TbCfOrder order = new TbCfOrder(); TbCfOrder order = new TbCfOrder();
order.setUserName(user.display()); order.setUserName(user.display());
Optional<TbCfExpressTemplate> templateOptional = templateRepository.findFirstByIsDefault(1); Optional<TbCfExpressTemplate> templateOptional = templateRepository.findFirstByIsDefault(1);
templateOptional.ifPresent(order::setDefaultTemplate); templateOptional.ifPresent(order::setDefaultTemplate);
order.setOrderId(IdUtil.createIdbyUUID()); order.setOrderId(IdUtil.createIdbyUUID());
order.setCouponId(toitableId); order.setCouponId(toitableId);
TbCfToicoupon tbCfToicoupon = null; TbCfToicoupon tbCfToicoupon = null;
if (toitableId != null && !toitableId.isEmpty()) { if (toitableId != null && !toitableId.isEmpty()) {
Optional<TbCfToicoupon> couponOptional = toicouponRepository.findById(toitableId); Optional<TbCfToicoupon> couponOptional = toicouponRepository.findById(toitableId);
if( couponOptional.isPresent() ){ if( couponOptional.isPresent() ){
tbCfToicoupon = couponOptional.get(); tbCfToicoupon = couponOptional.get();
TbCfCoupon coupon = tbCfToicoupon.getCoupon(); TbCfCoupon coupon = tbCfToicoupon.getCoupon();
order.setCoupon(coupon); order.setCoupon(coupon);
} }
} }
order.setUserId(userId); order.setUserId(userId);
if ("web".equals(web)) { if ("web".equals(web)) {
order.setOrderSource(3); order.setOrderSource(3);
} else { } else {
order.setOrderSource(1); order.setOrderSource(1);
} }
order.getItemOrderListFromCartList(allByUserId); order.getItemOrderListFromCartList(allByUserId);
TbCfOrder save = repository.save(order); TbCfOrder save = repository.save(order);
if( tbCfToicoupon != null ){ if( tbCfToicoupon != null ){
tbCfToicoupon.setEnableFlag(0); tbCfToicoupon.setEnableFlag(0);
toicouponRepository.save(tbCfToicoupon); toicouponRepository.save(tbCfToicoupon);
} }
//order.getItemOrderList().forEach(itemOrderRepository::save); //order.getItemOrderList().forEach(itemOrderRepository::save);
List<String> collect = allByUserId.stream().map(TbCfCartRecordR::getCartRecordId).collect(Collectors.toList()); List<String> collect = allByUserId.stream().map(TbCfCartRecordR::getCartRecordId).collect(Collectors.toList());
String[] strings = collect.toArray(new String[]{}); String[] strings = collect.toArray(new String[]{});
cartRepository.deleteAllByCartRecordIdIn(strings); cartRepository.deleteAllByCartRecordIdIn(strings);
// implementation of coupon use // implementation of coupon use
if( user.hasFcm() ){ if( user.hasFcm() ){
sendNotification(user.getFcm(),"Order alert !!","Order of $"+order.getRealityPay()+" has been created , proceed with payment"); sendNotification(user.getFcm(),"Order alert !!","Order of $"+order.getRealityPay()+" has been created , proceed with payment");
} }
return new Result<>(save); return new Result<>(save);
}catch (Exception e){
System.out.println(e.getMessage());
return new Result<>(ResultCodeEnum.VALIDATE_ERROR.getCode(),e.getMessage());
}
} }
@GetMapping @GetMapping
......
...@@ -287,6 +287,12 @@ public class TbCfStationItem { ...@@ -287,6 +287,12 @@ public class TbCfStationItem {
return itemImg; return itemImg;
} }
public String catchSingleImage(){
String itemImg = getItemImg();
String[] strings = itemImg != null ? itemImg.split(";") : new String[]{};
return strings.length > 0 ? strings[0] : itemImg;
}
/** /**
* 设置:搜索关键字 * 设置:搜索关键字
*/ */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论