张江玮
1 year ago
6 changed files with 127 additions and 27 deletions
@ -0,0 +1,80 @@ |
|||||
|
package org.nl.wms.sch.manage; |
||||
|
|
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
import com.alibaba.fastjson.JSONArray; |
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import lombok.SneakyThrows; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.nl.modules.wql.WQL; |
||||
|
import org.nl.modules.wql.core.bean.WQLObject; |
||||
|
import org.nl.wms.ext.acs.service.WmsToAcsService; |
||||
|
import org.nl.wms.sch.task.util.TaskUtils; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* @author zhangjiangwei |
||||
|
* @date 2023/07/04 09:56 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
@RequiredArgsConstructor |
||||
|
@Component("autoUpdateWorkOrder") |
||||
|
public class AutoUpdateWorkOrder { |
||||
|
|
||||
|
private final WmsToAcsService wmsToAcsService; |
||||
|
|
||||
|
@SneakyThrows |
||||
|
public void run() { |
||||
|
JSONArray workOrders = WQL.getWO("MANAGE_QUERY").addParam("flag", "4").process().getResultJSONArray(0); |
||||
|
|
||||
|
if (ObjectUtil.isNotEmpty(workOrders)) { |
||||
|
List<Object> list = workOrders.stream().map(o -> { |
||||
|
JSONObject workOrder = (JSONObject) o; |
||||
|
JSONObject newData = new JSONObject(); |
||||
|
newData.put("workorder_id", workOrder.getString("workorder_id")); |
||||
|
newData.put("region_code", workOrder.getString("region_code")); |
||||
|
newData.put("device_code", workOrder.getString("device_code")); |
||||
|
return (Object) newData; |
||||
|
}).collect(Collectors.toList()); |
||||
|
JSONObject result = wmsToAcsService.getDeviceStatus(new JSONArray(list)); |
||||
|
WQLObject workOrderTable = WQLObject.getWQLObject("pdm_bd_workorder"); |
||||
|
|
||||
|
if ("200".equals(result.getString("status"))) { |
||||
|
JSONArray data = result.getJSONArray("data"); |
||||
|
|
||||
|
if (ObjectUtil.isNotEmpty(data)) { |
||||
|
JSONArray yzData = new JSONArray(data.stream().filter(o -> Region.YZ.value().equals(((JSONObject) o).getString("region_code"))).collect(Collectors.toList())); |
||||
|
JSONObject yzWorkOrderUpdate = new JSONObject(); |
||||
|
TaskUtils.addAutoUpdateColum(yzWorkOrderUpdate); |
||||
|
for (int i = 0; i < yzData.size(); i++) { |
||||
|
JSONObject newData = yzData.getJSONObject(i); |
||||
|
yzWorkOrderUpdate.put("real_qty", newData.getString("reql_qty")); |
||||
|
yzWorkOrderUpdate.put("qualified_qty", newData.getString("qualified")); |
||||
|
yzWorkOrderUpdate.put("unqualified_qty", newData.getString("unqualified")); |
||||
|
workOrderTable.update(yzWorkOrderUpdate, "workorder_id = " + newData.getString("workorder_id")); |
||||
|
} |
||||
|
|
||||
|
JSONArray fjData = new JSONArray(data.stream().filter(o -> Region.FJ.value().equals(((JSONObject) o).getString("region_code"))).collect(Collectors.toList())); |
||||
|
JSONObject fjWorkOrderUpdate = new JSONObject(); |
||||
|
TaskUtils.addAutoUpdateColum(fjWorkOrderUpdate); |
||||
|
for (int i = 0; i < fjData.size(); i++) { |
||||
|
JSONObject newData = fjData.getJSONObject(i); |
||||
|
yzWorkOrderUpdate.put("real_qty", newData.getString("reql_qty")); |
||||
|
workOrderTable.update(yzWorkOrderUpdate, "workorder_id = " + newData.getString("workorder_id")); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
JSONArray yield = WQL.getWO("MANAGE_QUERY").addParam("flag", "5").process().getResultJSONArray(0); |
||||
|
WQLObject materialTable = WQLObject.getWQLObject("md_me_materialbase"); |
||||
|
for (int i = 0; i < yield.size(); i++) { |
||||
|
JSONObject deviceYield = yield.getJSONObject(i); |
||||
|
deviceYield.put("surplus_aux_qty", Math.max(deviceYield.getIntValue("aux_qty") - deviceYield.getIntValue("current_aux_qty"), 0)); |
||||
|
materialTable.update(deviceYield); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue