| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.zy.asrs.entity.DocType; |
| | | import com.zy.asrs.entity.OrderDetlPakin; |
| | | import com.zy.asrs.entity.OrderPakin; |
| | | import com.zy.asrs.mapper.OrderDetlPakinMapper; |
| | | import com.zy.asrs.mapper.OrderPakinMapper; |
| | | import com.zy.asrs.service.ApiLogService; |
| | | import com.zy.asrs.service.DocTypeService; |
| | | import com.zy.asrs.service.OrderDetlPakinService; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Created by vincent on 2020/7/7 |
| | |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | public void reportInStockOrders(List<OrderDetlPakin> orderDetlPakinList) { |
| | | // 按订单分组 |
| | | Map<String, List<OrderDetlPakin>> listMap = orderDetlPakinList.stream().collect(Collectors.groupingBy(OrderDetlPakin::getOrderNo)); |
| | | |
| | | // 构造请求体 |
| | | JSONArray param = new JSONArray(); |
| | | for (Map.Entry<String, List<OrderDetlPakin>> entry : listMap.entrySet()) { |
| | | JSONObject object = new JSONObject(); |
| | | object.put("orderNo", entry.getKey()); |
| | | List<OrderDetlPakin> orderDetlPakins = entry.getValue(); |
| | | JSONArray detl = new JSONArray(); |
| | | for (OrderDetlPakin orderDetlPakin : orderDetlPakins) { |
| | | JSONObject detlObject = new JSONObject(); |
| | | detlObject.put("sku", orderDetlPakin.getSku()); |
| | | detlObject.put("standby1", orderDetlPakin.getStandby1()); |
| | | detlObject.put("matnr", orderDetlPakin.getMatnr()); |
| | | detlObject.put("batch", orderDetlPakin.getBatch()); |
| | | detlObject.put("anfme", orderDetlPakin.getQty() - orderDetlPakin.getUnits()); |
| | | detl.add(detlObject); |
| | | } |
| | | object.put("matList", detl); |
| | | param.add(object); |
| | | } |
| | | |
| | | String response = ""; |
| | | boolean success = false; |
| | | String errorMsg = null; |
| | | String requestJson = param.toJSONString(); |
| | | String url = loadingConfigTimer.getErpReportURL() + loadingConfigTimer.getErpInReportPath(); |
| | | String nameSpaces = "入库单上报"; |
| | | try { |
| | | |
| | | response = new HttpHandler.Builder() |
| | | .setUri(loadingConfigTimer.getErpReportURL()) |
| | | .setPath(loadingConfigTimer.getErpInReportPath()) |
| | | .setJson(requestJson) |
| | | .build() |
| | | .doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | if (jsonObject.getString("code") != null && jsonObject.getString("code").equals("200")) { |
| | | // 批量更新units 上报数量 |
| | | List<OrderDetlPakin> collect = orderDetlPakinList.stream().peek(orderDetlPakin -> orderDetlPakin.setUnits(orderDetlPakin.getQty())).collect(Collectors.toList()); |
| | | orderDetlPakinService.updateBatchById(collect); |
| | | success = true; |
| | | } else { |
| | | errorMsg = response; |
| | | log.error(nameSpaces + "调用外部接口失败,url:{},request:{},response:{}", url, requestJson, response); |
| | | } |
| | | } catch (Exception e) { |
| | | errorMsg = e.getMessage(); |
| | | log.error(nameSpaces + "调用外部接口异常,url:{},request:{},response:{}", url, requestJson, response, e); |
| | | } finally { |
| | | try { |
| | | apiLogService.save( |
| | | nameSpaces, |
| | | url, |
| | | null, |
| | | "127.0.0.1", |
| | | requestJson, |
| | | response, |
| | | success, |
| | | errorMsg |
| | | ); |
| | | } catch (Exception e) { |
| | | log.error(nameSpaces + "保存接口日志失败", e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Resource |
| | | private OrderDetlPakinMapper orderDetlPakinMapper; |
| | | |
| | | public void completeOrderReport() { |
| | | List<OrderPakin> orderPakins = orderPakinService.selectList(new EntityWrapper<OrderPakin>().where("settle = 4")); |
| | | |
| | | // 使用 removeIf 简化代码 |
| | | orderPakins.removeIf(orderPakin -> orderDetlPakinMapper.selectReportComplete(orderPakin.getId()) == 0); |
| | | |
| | | // 对剩余数据进行settle设置 |
| | | orderPakins.forEach(orderPakin -> orderPakin.setSettle(6L)); |
| | | |
| | | // 批量更新 |
| | | if (!orderPakins.isEmpty()) { |
| | | orderPakinService.updateBatchById(orderPakins); |
| | | } |
| | | } |
| | | } |