Commit 059709dc by 张新旗

代码永远在路上

parent 875859f8
......@@ -47,6 +47,8 @@ public class MachineApiServiceImpl {
private GoodsMapper goodsMapper;
@Autowired
private JiGuangPushServiceImpl jiGuangPushService;
@Autowired
private GoodsCategoryMapper goodsCategoryMapper;
public String shopGoodsUpdate(JSONObject jsonObject) {
String shopID = jsonObject.getString("shopId");
......@@ -103,15 +105,29 @@ public class MachineApiServiceImpl {
Goods goods = goodsMapper.selectGoodsById(detail.getGoodsId());
detail.setGoods(goods);
}
order.setOrderDetails(orderDetails);
createOrder(order);
}catch (Exception e){
log.error("",e);
}
}
public ResultVo createOrder(Order order){
String orderInfo = null;
JSONObject orderJson =null;
try{
ObjectMapper objectMapper = new ObjectMapper();
String orderInfo = objectMapper.writeValueAsString(order);
JSONObject orderJson = JSONObject.parseObject(orderInfo);
orderInfo = objectMapper.writeValueAsString(order);
log.info("创建订单数据为:【{}】",orderInfo);
orderJson = JSONObject.parseObject(orderInfo);
orderJson.put("goodsNum",orderJson.getLong("goodsNum"));
orderJson.put("machineId",orderJson.getLong("machineId"));
orderJson.put("shopId",orderJson.getLong("shopId"));
orderJson.put("state",orderJson.getLong("state"));
List<JSONObject> goodsList =new ArrayList<>();
orderJson.put("goodsList",goodsList);
List<OrderDetail> orderDetails = order.getOrderDetails();
for (OrderDetail detail : orderDetails) {
JSONObject jsonObject = new JSONObject();
goodsList.add(jsonObject);
......@@ -122,33 +138,20 @@ public class MachineApiServiceImpl {
jsonObject.put("specRuleDetail",detail.getSpecRuleDetail());
jsonObject.put("specRuleIds",detail.getSpecRuleIds());
jsonObject.put("skuId",Long.parseLong(detail.getSkuId()));
jsonObject.put("goodsCategory",detail.getGoods().getCategoryName());
}
ResultVo resultVo =sendRequest(orderJson.toJSONString(),"/v1/order");
String code = resultVo.getCode();
if("2001".equals(code)){
throw new ServiceException("库存不足");
}else if("3001".equals(code)){
throw new ServiceException("机器繁忙");
}
}catch (Exception e){
log.error("",e);
if("0".equals(detail.getGoodsCategory())){
jsonObject.put("goodsCategory","今日特惠");
}else{
GoodsCategory goodsCategory = goodsCategoryMapper.selectGoodsCategoryById(detail.getGoodsCategory());
jsonObject.put("goodsCategory",goodsCategory.getName());
}
}
public ResultVo createOrder(Order order){
String orderInfo = null;
try{
ObjectMapper objectMapper = new ObjectMapper();
orderInfo = objectMapper.writeValueAsString(order);
}catch (Exception e){
log.error("初始化订单发生异常",e);
throw new ServiceException("初始订单数据异常,请重试");
}
ResultVo resultVo =sendRequest(orderInfo,"/v1/order");
ResultVo resultVo =sendRequest(orderJson.toJSONString(),"/v1/order");
String code = resultVo.getCode();
if("2001".equals(code)){
......
......@@ -46,7 +46,13 @@ public class OrderRefundServiceImpl implements IOrderRefundService
@Override
public OrderRefund selectOrderRefundById(String id)
{
return orderRefundMapper.selectOrderRefundById(id);
OrderRefund orderRefund = orderRefundMapper.selectOrderRefundById(id);
Order order = orderService.selectOrderById(orderRefund.getOrderId());
OrderSnapshot orderSnapshot = orderSnapshotMapper.selectOrderSnapshotByOrderId(order.getId());
List<OrderDetail> orderDetails = JSONObject.parseArray(orderSnapshot.getSnapshot(), OrderDetail.class);
order.setOrderDetails(orderDetails);
orderRefund.setOrder(order);
return orderRefund;
}
/**
......
......@@ -63,13 +63,10 @@ public class OrderServiceImpl implements IOrderService
{
Order order = orderMapper.selectOrderById(id);
order.setShop(shopMapper.selectShopById(order.getShopId()));
OrderDetail orderDetail = new OrderDetail();
orderDetail.setOrderId(order.getId());
List<OrderDetail> orderDetails = orderDetailMapper.selectOrderDetailList(orderDetail);
for (OrderDetail detail : orderDetails) {
detail.setGoods(goodsMapper.selectGoodsById(detail.getGoodsId()));
}
order.setOrderDetails(orderDetails);
OrderSnapshot orderSnapshot = orderSnapshotService.selectOrderSnapshotByOrderId(order.getId());
String snapshot = orderSnapshot.getSnapshot();
List<OrderDetail> orderDetails1 = JSONObject.parseArray(snapshot, OrderDetail.class);
order.setOrderDetails(orderDetails1);
return order;
}
......@@ -111,6 +108,7 @@ public class OrderServiceImpl implements IOrderService
order.setCreatedAt(new Date());
order.setOrderNum(getOrderNum(order.getShopId()));
order.setOrderNo(getOrderNo(order.getSource()));
order.setUpdatedAt(new Date());
String machineId = null;
if(StringUtils.isEmpty(order.getMachineId())){
Machine machine =new Machine();
......@@ -224,12 +222,14 @@ public class OrderServiceImpl implements IOrderService
}
@Override
@Transactional
public int cancel(String orderId) {
Order order = orderMapper.selectOrderById(orderId);
if("1".equals(order.getState())){
order.setState("7");
order.setUpdatedAt(new Date());
orderMapper.updateOrder(order);
machineApiService.updateOrder(order);
}else{
throw new ServiceException("该订单不允许取消");
}
......
......@@ -20,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
</select>
<select id="selectOrderSnapshotByOrderId" parameterType="String" resultMap="OrderSnapshotResult">
<select id="selectOrderSnapshotByOrderId" resultMap="OrderSnapshotResult">
<include refid="selectOrderSnapshotVo"/>
where order_id = #{orderId}
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment