Commit 059709dc by 张新旗

代码永远在路上

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