|
@@ -8,9 +8,7 @@ import org.springframework.amqp.core.Message;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* @author yq
|
|
@@ -33,32 +31,10 @@ public class DishTransMqListener {
|
|
|
//消息内容
|
|
|
String s = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
log.info("dish_trade_produce获取到的消息"+s);
|
|
|
- Dish dish = checkDate(s);
|
|
|
+ Dish dish = JSONObject.parseObject(s, Dish.class);;
|
|
|
dishService.saveOrUpdate(dish);
|
|
|
} catch (Exception e) {
|
|
|
log.info("dish_trade_produce"+"异常信息:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- public Dish checkDate(String message){
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(message);
|
|
|
- Dish dish = JSONObject.parseObject(message, Dish.class);
|
|
|
- JSONObject details = jsonObject.getJSONObject("details");
|
|
|
- Optional.ofNullable(details)
|
|
|
- .ifPresent(de -> {
|
|
|
- Optional.ofNullable(de.get("pid")).ifPresent(pId -> dish.setPId(Integer.parseInt(pId.toString())));
|
|
|
- Optional.ofNullable(de.get("name")).ifPresent(pName -> dish.setPName(pName.toString()));
|
|
|
- Optional.ofNullable(de.get("price")).ifPresent(pPrice -> dish.setPPrice(new BigDecimal(pPrice.toString())));
|
|
|
- Optional.ofNullable(de.get("amt")).ifPresent(pAmt -> dish.setPAmt(new BigDecimal(pAmt.toString())));
|
|
|
- });
|
|
|
- JSONObject payments = jsonObject.getJSONObject("payments");
|
|
|
- Optional.ofNullable(payments)
|
|
|
- .ifPresent(de -> {
|
|
|
- Optional.ofNullable(de.get("type")).ifPresent(type -> dish.setPaymentType(Integer.parseInt(type.toString())));
|
|
|
- Optional.ofNullable(de.get("amt")).ifPresent(amt -> dish.setPaymentAmt(new BigDecimal(amt.toString())));
|
|
|
- Optional.ofNullable(de.get("balance")).ifPresent(balance -> dish.setPaymentBalance(new BigDecimal(balance.toString())));
|
|
|
- });
|
|
|
- return dish;
|
|
|
- }
|
|
|
}
|