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

commit commit

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