|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.utils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.Wrapper; | 
|---|
|  |  |  | import com.core.common.Arith; | 
|---|
|  |  |  | 
|---|
|  |  |  | if(Cools.isEmpty(condition) || "null".equals(condition)){ | 
|---|
|  |  |  | wrapper.andNew().eq(column,"").or().isNull(column); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | wrapper.eq(column,condition); | 
|---|
|  |  |  | wrapper.andNew().eq(column,condition); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static String getOrderNo(String orderNo, double anfme){ | 
|---|
|  |  |  | JSONArray orderArray = new JSONArray(); | 
|---|
|  |  |  | //如果订单号为jsonString | 
|---|
|  |  |  | if(orderNo.contains("{")){ | 
|---|
|  |  |  | JSONArray jsonArray = JSON.parseArray(orderNo); | 
|---|
|  |  |  | //遍历所有订单号及订单数量 | 
|---|
|  |  |  | for (Object o : jsonArray){ | 
|---|
|  |  |  | JSONObject orderJson = (JSONObject) o; | 
|---|
|  |  |  | Double orderAnfme = orderJson.getDouble("anfme"); | 
|---|
|  |  |  | //如果订单数量为0,则跳过 | 
|---|
|  |  |  | if(orderAnfme <= 0){ | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(orderAnfme > anfme){ | 
|---|
|  |  |  | //如果订单数量大于该库存数量,且订单数组为空,则直接返回该订单号,否则就将该订单添加到订单数组 | 
|---|
|  |  |  | if(orderArray.isEmpty()){ | 
|---|
|  |  |  | return orderJson.getString("orderNo"); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | orderJson.put("anfme",anfme); | 
|---|
|  |  |  | orderArray.add(orderJson); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | anfme -= orderAnfme; | 
|---|
|  |  |  | orderArray.add(orderJson); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return orderArray.toJSONString(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return orderNo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static String orderMergeUpdate(String orderNo, double anfme){ | 
|---|
|  |  |  | if(orderNo.contains("{")){ | 
|---|
|  |  |  | JSONArray jsonArray = JSON.parseArray(orderNo); | 
|---|
|  |  |  | for(int i=0; i<jsonArray.size(); i++){ | 
|---|
|  |  |  | JSONObject orderJson = (JSONObject)jsonArray.get(i); | 
|---|
|  |  |  | Double orderAnfme = orderJson.getDouble("anfme"); | 
|---|
|  |  |  | if(orderAnfme > anfme){ | 
|---|
|  |  |  | ((JSONObject) jsonArray.get(i)).put("anfme",orderAnfme - anfme); | 
|---|
|  |  |  | return jsonArray.toJSONString(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | ((JSONObject) jsonArray.get(i)).put("anfme",0); | 
|---|
|  |  |  | anfme -= orderAnfme; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return jsonArray.toJSONString(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return orderNo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|