| package com.zy.asrs.task.handler; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.alibaba.fastjson.JSONObject; | 
| import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
| import com.zy.asrs.entity.DocType; | 
| import com.zy.asrs.entity.Order; | 
| import com.zy.asrs.service.DocTypeService; | 
| import com.zy.asrs.service.OrderService; | 
| import com.zy.asrs.task.AbstractHandler; | 
| import com.zy.asrs.task.ErpAccessTokenScheduler; | 
| import com.zy.common.utils.HttpHandler; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
|   | 
| import java.io.IOException; | 
| import java.util.HashMap; | 
| import java.util.Map; | 
|   | 
| @Slf4j | 
| @Service | 
| @Transactional | 
| public class OrderSendHandler extends AbstractHandler<String> { | 
|     private static final String erpIp = "10.100.221.19:81"; | 
|     private static final String inPath = "/ierp/kapi/app/im/PurinbillApiPlugin"; | 
|     private static final String outPath = "/ierp/kapi/app/im/SaloutbillApiPlugin"; | 
|   | 
|   | 
|   | 
|   | 
|     @Autowired | 
|     private OrderService orderService; | 
|     @Autowired | 
|     private DocTypeService docTypeService; | 
|   | 
|     public void start(Order order) { | 
|         String accessToken = ErpAccessTokenScheduler.accessToken; | 
|         if (accessToken.equals("")) { | 
|             return; | 
|         } | 
|   | 
|         HashMap<String, Object> header = new HashMap<>(); | 
|         header.put("accessToken",accessToken); | 
|         JSONObject jsonObject = new JSONObject(); | 
|         jsonObject.put("orderNo",order.getOrderNo()); | 
|         HttpHandler.Builder prepBuilder = new HttpHandler.Builder() | 
|                 .setUri(erpIp) | 
|                 .setHeaders(header) | 
|                 .setJson(jsonObject.toJSONString()); | 
|         JSONObject respJson; | 
|   | 
|   | 
|         //入库单据 | 
|         if (docTypeService.selectOne(new EntityWrapper<DocType>() | 
|                 .eq("doc_id",order.getDocType())).getPakin() == 1) { | 
|             try { | 
|                 respJson = JSON.parseObject( | 
|                         prepBuilder.setPath(inPath) | 
|                         .build() | 
|                         .doPost()); | 
|             } catch (IOException e) { | 
|                 throw new RuntimeException(e); | 
|             } | 
|         }else { | 
|             //出库单据 | 
|             try { | 
|                 respJson = JSON.parseObject( | 
|                 prepBuilder.setPath(outPath) | 
|                         .build() | 
|                         .doPost()); | 
|             } catch (IOException e) { | 
|                 throw new RuntimeException(e); | 
|             } | 
|         } | 
|         if ((boolean)respJson.get("success")) { | 
|             orderService.updateSettle(order.getId(),6L,1L); | 
|             log.info("单据:" + order.getOrderNo() + "回传成功,已更新单据状态"); | 
|         }else { | 
|   | 
|             order.setItemId(order.getItemId() + 1); | 
|             orderService.updateById(order); | 
|             log.info("单据:"+ order.getOrderNo()+" 回传失败,这是第" + order.getItemId() + "次回传"); | 
|             log.info(respJson.toJSONString()); | 
|         } | 
|     } | 
| } |