zds
4 weeks ago
16 changed files with 200 additions and 775 deletions
@ -1,570 +0,0 @@ |
|||||
package org.nl.wms.sch.manage; |
|
||||
|
|
||||
|
|
||||
import cn.hutool.core.date.DateUtil; |
|
||||
import cn.hutool.core.util.NumberUtil; |
|
||||
import cn.hutool.core.util.ObjectUtil; |
|
||||
import com.alibaba.fastjson.JSONArray; |
|
||||
import com.alibaba.fastjson.JSONObject; |
|
||||
import lombok.RequiredArgsConstructor; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.nl.modules.wql.WQL; |
|
||||
import org.nl.modules.wql.core.bean.WQLObject; |
|
||||
import org.nl.modules.wql.util.SpringContextHolder; |
|
||||
import org.nl.system.service.param.impl.SysParamServiceImpl; |
|
||||
import org.nl.wms.ext.mes.service.LmsToMesService; |
|
||||
import org.springframework.stereotype.Component; |
|
||||
|
|
||||
import java.util.ArrayList; |
|
||||
import java.util.Arrays; |
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
import java.util.stream.Collectors; |
|
||||
|
|
||||
@Slf4j |
|
||||
@Component |
|
||||
@RequiredArgsConstructor |
|
||||
public class AutoQueryProudDayDataTest { |
|
||||
|
|
||||
private final LmsToMesService lmsToMesService; |
|
||||
|
|
||||
public void run() { |
|
||||
JSONObject param = new JSONObject(); |
|
||||
|
|
||||
JSONArray UserList = new JSONArray(); |
|
||||
|
|
||||
String userList = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("USER_LIST_FEISHU").getValue(); |
|
||||
|
|
||||
String[] split = userList.split(","); |
|
||||
if (split.length > 0) { |
|
||||
for (String s : split) { |
|
||||
JSONObject jo = new JSONObject(); |
|
||||
jo.put("User", s); |
|
||||
UserList.add(jo); |
|
||||
} |
|
||||
} else { |
|
||||
JSONObject jo = new JSONObject(); |
|
||||
jo.put("User", ""); |
|
||||
UserList.add(jo); |
|
||||
} |
|
||||
param.put("UserList", UserList); |
|
||||
|
|
||||
param.put("Code", "ctp_AAVwgNuQOtO0"); |
|
||||
param.put("card", data()); |
|
||||
|
|
||||
// 调用接口
|
|
||||
lmsToMesService.proudDayData(param); |
|
||||
|
|
||||
} |
|
||||
|
|
||||
public JSONObject data() { |
|
||||
WQLObject storTab = WQLObject.getWQLObject("st_ivt_bsrealstorattr"); // 仓库表
|
|
||||
|
|
||||
// 查询共多少个仓库
|
|
||||
String in_stor_code = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("STOR_CODE_FEISHU").getValue(); |
|
||||
JSONArray storArr = storTab.query("is_used = '1' and stor_code in" + in_stor_code).getResultJSONArray(0); |
|
||||
|
|
||||
// 客户
|
|
||||
String custB = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("CUST_B").getValue(); |
|
||||
String custC = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("CUST_C").getValue(); |
|
||||
|
|
||||
JSONObject result = new JSONObject(); // 全部数据
|
|
||||
result.put("Title", DateUtil.today() + "成品数据(单位:T)"); |
|
||||
|
|
||||
/* |
|
||||
* 查询各仓库库存 |
|
||||
*/ |
|
||||
JSONArray Arrayobject1 = new JSONArray(); // 各仓库库存集合
|
|
||||
|
|
||||
// 库存总量集合
|
|
||||
List<JSONObject> allIvtList = WQL.getWO("TEST0001").addParam("flag", "1").process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 超期库存集合
|
|
||||
List<JSONObject> sidIvtList = WQL.getWO("TEST0001").addParam("flag", "2").process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 临期库存集合
|
|
||||
List<JSONObject> faceIvtList = WQL.getWO("TEST0001").addParam("flag", "3").process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 正常库龄
|
|
||||
List<JSONObject> regIvtList = WQL.getWO("TEST0001").addParam("flag", "4").process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
for (int i = 0; i < storArr.size(); i++) { |
|
||||
JSONObject item = storArr.getJSONObject(i); |
|
||||
|
|
||||
JSONObject json = new JSONObject(); |
|
||||
json.put("local", item.getString("stor_name")); // 存储地点
|
|
||||
|
|
||||
// 库存总量
|
|
||||
List<JSONObject> collect = allIvtList.stream() |
|
||||
.filter(row -> row.getString("stor_id").equals(item.getString("stor_id"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
json.put("TotalInventory", collect.isEmpty() ? "0" : NumberUtil.round(collect.get(0).getString("num"), 2) + ""); |
|
||||
|
|
||||
// 超期库存
|
|
||||
List<JSONObject> collect2 = sidIvtList.stream() |
|
||||
.filter(row -> row.getString("stor_id").equals(item.getString("stor_id"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
json.put("OverdueInventory", collect2.isEmpty() ? "0" : NumberUtil.round(collect2.get(0).getString("num"), 2) + ""); |
|
||||
|
|
||||
// 临期库存
|
|
||||
List<JSONObject> collect3 = faceIvtList.stream() |
|
||||
.filter(row -> row.getString("stor_id").equals(item.getString("stor_id"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
json.put("InterimInventory", collect3.isEmpty() ? "0" : NumberUtil.round(collect3.get(0).getString("num"), 2) + ""); |
|
||||
|
|
||||
// 正常库存
|
|
||||
List<JSONObject> collect4 = regIvtList.stream() |
|
||||
.filter(row -> row.getString("stor_id").equals(item.getString("stor_id"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
json.put("NormalStockAge", collect4.isEmpty() ? "0" : NumberUtil.round(collect4.get(0).getString("num"), 2) + ""); |
|
||||
|
|
||||
Arrayobject1.add(json); |
|
||||
} |
|
||||
|
|
||||
// 计算全部
|
|
||||
JSONObject allIvt = new JSONObject(); |
|
||||
allIvt.put("local", "全部"); |
|
||||
allIvt.put("TotalInventory", NumberUtil.round(allIvtList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
allIvt.put("OverdueInventory", NumberUtil.round(sidIvtList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
allIvt.put("InterimInventory", NumberUtil.round(faceIvtList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
allIvt.put("NormalStockAge", NumberUtil.round(regIvtList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
// Arrayobject1.add(allIvt);
|
|
||||
|
|
||||
result.put("Arrayobject1", Arrayobject1); |
|
||||
|
|
||||
/* |
|
||||
* 各客户库存 : |
|
||||
* 1.表头 |
|
||||
* { |
|
||||
* B库存:10000708 蕉城时代,10000698 江苏时代,10000779 四川时代,10000561 宁德时代 |
|
||||
* C库存:10000426 比亚迪,2010 海亮股份 |
|
||||
* Other库存: 除B、C客户的其他客户 |
|
||||
* } |
|
||||
* 2.数据 |
|
||||
*/ |
|
||||
// 1.表头:
|
|
||||
JSONArray Customernventory = new JSONArray(); |
|
||||
|
|
||||
JSONObject custHand = new JSONObject(); |
|
||||
custHand.put("Customer1", "B库存"); |
|
||||
custHand.put("Customer2", "C库存"); |
|
||||
custHand.put("Customer3", "Other库存"); |
|
||||
Customernventory.add(custHand); |
|
||||
result.put("Customernventory", Customernventory); |
|
||||
|
|
||||
// 2.数据
|
|
||||
JSONArray Arrayobject2 = new JSONArray(); |
|
||||
|
|
||||
String[] splitB = custB.split(","); |
|
||||
ArrayList<String> bList = new ArrayList<>(Arrays.asList(splitB)); |
|
||||
String collectB1 = String.join("','", bList); |
|
||||
|
|
||||
String[] splitC = custC.split(","); |
|
||||
ArrayList<String> cList = new ArrayList<>(Arrays.asList(splitC)); |
|
||||
String collectC1 = String.join("','", cList); |
|
||||
|
|
||||
|
|
||||
String in_cust = custB + "," + custC; |
|
||||
String[] splitAll = in_cust.split(","); |
|
||||
ArrayList<String> aAndBList = new ArrayList<>(Arrays.asList(splitAll)); |
|
||||
String collectAll = String.join("','", aAndBList); |
|
||||
|
|
||||
// B库存集合
|
|
||||
List<JSONObject> custIvtBList = WQL.getWO("TEST0001").addParam("flag", "5") |
|
||||
.addParam("customer_name", "('" + collectB1 + "')") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// C库存集合
|
|
||||
List<JSONObject> custIvtCList = WQL.getWO("TEST0001").addParam("flag", "5") |
|
||||
.addParam("customer_name", "('" + collectC1 + "')") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 其他库存集合
|
|
||||
List<JSONObject> custIvtOtherList = WQL.getWO("TEST0001").addParam("flag", "6") |
|
||||
.addParam("customer_name", "('" + collectAll + "')") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
for (int i = 0; i < storArr.size(); i++) { |
|
||||
JSONObject item = storArr.getJSONObject(i); |
|
||||
|
|
||||
JSONObject json = new JSONObject(); |
|
||||
json.put("Local", item.getString("stor_name")); |
|
||||
|
|
||||
// B库存
|
|
||||
List<JSONObject> collectB = custIvtBList.stream() |
|
||||
.filter(row -> row.getString("stor_id").equals(item.getString("stor_id"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
json.put("Customernventory1", collectB.isEmpty() ? "0" : NumberUtil.round(collectB.get(0).getString("num"), 2) + ""); |
|
||||
|
|
||||
// C库存
|
|
||||
List<JSONObject> collectC = custIvtCList.stream() |
|
||||
.filter(row -> row.getString("stor_id").equals(item.getString("stor_id"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
json.put("Customernventory2", collectC.isEmpty() ? "0" : NumberUtil.round(collectC.get(0).getString("num"), 2) + ""); |
|
||||
|
|
||||
// 其他库存
|
|
||||
List<JSONObject> collectOthen = custIvtOtherList.stream() |
|
||||
.filter(row -> row.getString("stor_id").equals(item.getString("stor_id"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
json.put("Customernventory3", collectOthen.isEmpty() ? "0" : NumberUtil.round(collectOthen.get(0).getString("num"), 2) + ""); |
|
||||
|
|
||||
Arrayobject2.add(json); |
|
||||
} |
|
||||
|
|
||||
// 计算全部
|
|
||||
JSONObject allCustIvt = new JSONObject(); |
|
||||
allCustIvt.put("Local", "全部"); |
|
||||
allCustIvt.put("Customernventory1", NumberUtil.round(custIvtBList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
allCustIvt.put("Customernventory2", NumberUtil.round(custIvtCList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
allCustIvt.put("Customernventory3", NumberUtil.round(custIvtOtherList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
// Arrayobject2.add(allCustIvt);
|
|
||||
|
|
||||
result.put("Arrayobject2", Arrayobject2); |
|
||||
|
|
||||
/* |
|
||||
* 库存变化 |
|
||||
* 1.表头 |
|
||||
* { |
|
||||
* B库存:10000708 蕉城时代,10000698 江苏时代,10000779 四川时代,10000561 宁德时代 |
|
||||
* C库存:10000426 比亚迪,2010 海亮股份 |
|
||||
* 汇总: 所有客户 |
|
||||
* } |
|
||||
* 2.数据 |
|
||||
*/ |
|
||||
// 1.表头
|
|
||||
JSONArray Arrayobject3 = new JSONArray(); |
|
||||
|
|
||||
JSONObject changeIvt = new JSONObject(); |
|
||||
changeIvt.put("Customer1", "B客户"); |
|
||||
changeIvt.put("Customer2", "C客户"); |
|
||||
changeIvt.put("Customer3", "汇总"); |
|
||||
Arrayobject3.add(changeIvt); |
|
||||
result.put("Arrayobject3", Arrayobject3); |
|
||||
|
|
||||
// 2.数据
|
|
||||
JSONArray Arrayobject4 = new JSONArray(); |
|
||||
|
|
||||
// 所有昨日入库量客户分组集合
|
|
||||
List<JSONObject> yesterdayInList = WQL.getWO("TEST0001").addParam("flag", "7") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 所有昨日出库量客户分组集合
|
|
||||
List<JSONObject> yesterdayOutList = WQL.getWO("TEST0001").addParam("flag", "8") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 所有当月入库量客户分组集合
|
|
||||
List<JSONObject> monthInList = WQL.getWO("TEST0001").addParam("flag", "9") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 所有当月出库量客户分组集合
|
|
||||
List<JSONObject> monthOutList = WQL.getWO("TEST0001").addParam("flag", "10") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// ---- 昨日入库量 ----
|
|
||||
JSONObject yesterdayIn = new JSONObject(); |
|
||||
yesterdayIn.put("Title", "昨日入库量"); |
|
||||
|
|
||||
// B客户
|
|
||||
List<JSONObject> custBList = yesterdayInList.stream() |
|
||||
.filter(row -> custB.contains(row.getString("customer_name"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
yesterdayIn.put("Customerqty1", NumberUtil.round(custBList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
|
|
||||
// C客户
|
|
||||
List<JSONObject> custCList = yesterdayInList.stream() |
|
||||
.filter(row -> custC.contains(row.getString("customer_name"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
yesterdayIn.put("Customerqty2", NumberUtil.round(custCList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
|
|
||||
// 汇总
|
|
||||
yesterdayIn.put("Customerqty3", NumberUtil.round(yesterdayInList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
Arrayobject4.add(yesterdayIn); |
|
||||
|
|
||||
// ---- 昨日出库量 ----
|
|
||||
JSONObject yesterdayOut = new JSONObject(); |
|
||||
yesterdayOut.put("Title", "昨日出库量"); |
|
||||
|
|
||||
// B客户
|
|
||||
List<JSONObject> custBList2 = yesterdayOutList.stream() |
|
||||
.filter(row -> custB.contains(row.getString("customer_name"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
yesterdayOut.put("Customerqty1", NumberUtil.round(custBList2.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
|
|
||||
// C客户
|
|
||||
List<JSONObject> custCList2 = yesterdayOutList.stream() |
|
||||
.filter(row -> custC.contains(row.getString("customer_name"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
yesterdayOut.put("Customerqty2", NumberUtil.round(custCList2.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
|
|
||||
// 汇总
|
|
||||
yesterdayOut.put("Customerqty3", NumberUtil.round(yesterdayOutList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
// Arrayobject4.add(yesterdayOut);
|
|
||||
|
|
||||
// ---- 当月入库量 ----
|
|
||||
JSONObject monthdayIn = new JSONObject(); |
|
||||
monthdayIn.put("Title", "当月入库量"); |
|
||||
|
|
||||
// B客户
|
|
||||
List<JSONObject> custBList3 = monthInList.stream() |
|
||||
.filter(row -> custB.contains(row.getString("customer_name"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
monthdayIn.put("Customerqty1", NumberUtil.round(custBList3.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
|
|
||||
// C客户
|
|
||||
List<JSONObject> custCList3 = monthInList.stream() |
|
||||
.filter(row -> custC.contains(row.getString("customer_name"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
monthdayIn.put("Customerqty2", NumberUtil.round(custCList3.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
|
|
||||
// 汇总
|
|
||||
monthdayIn.put("Customerqty3", NumberUtil.round(monthInList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
Arrayobject4.add(monthdayIn); |
|
||||
|
|
||||
// ---- 当月出库量 ----
|
|
||||
JSONObject monthdayOut = new JSONObject(); |
|
||||
monthdayOut.put("Title", "当月出库量"); |
|
||||
|
|
||||
// B客户
|
|
||||
List<JSONObject> custBList4 = monthOutList.stream() |
|
||||
.filter(row -> custB.contains(row.getString("customer_name"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
monthdayOut.put("Customerqty1", NumberUtil.round(custBList4.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
|
|
||||
// C客户
|
|
||||
List<JSONObject> custCList4 = monthOutList.stream() |
|
||||
.filter(row -> custC.contains(row.getString("customer_name"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
monthdayOut.put("Customerqty2", NumberUtil.round(custCList4.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
|
|
||||
// 汇总
|
|
||||
monthdayOut.put("Customerqty3", NumberUtil.round(monthOutList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""); |
|
||||
// Arrayobject4.add(monthdayOut);
|
|
||||
|
|
||||
result.put("Arrayobject4", Arrayobject4); |
|
||||
|
|
||||
/* |
|
||||
* 各区域库存变化 |
|
||||
* 数据 |
|
||||
* { |
|
||||
* B库存:10000708 蕉城时代,10000698 江苏时代,10000779 四川时代,10000561 宁德时代 |
|
||||
* C库存:10000426 比亚迪,2010 海亮股份 |
|
||||
* } |
|
||||
* { |
|
||||
* region_code: A1,A2,A3,A4 |
|
||||
* } |
|
||||
*/ |
|
||||
JSONArray Arrayobject5 = new JSONArray(); |
|
||||
|
|
||||
// 所有昨日入库量区域分组集合
|
|
||||
List<JSONObject> yesterdayInRegList = WQL.getWO("TEST0001").addParam("flag", "11") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 所有昨日出库量区域分组集合
|
|
||||
List<JSONObject> yesterdayOutRegList = WQL.getWO("TEST0001").addParam("flag", "12") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 所有昨日入库量区域、客户分组集合
|
|
||||
List<JSONObject> yesterdayCustInRegList = WQL.getWO("TEST0001").addParam("flag", "13") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 所有昨日出库量区域、客户分组集合
|
|
||||
List<JSONObject> yesterdayCustOutRegList = WQL.getWO("TEST0001").addParam("flag", "14") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 所有当月入库量区域分组集合
|
|
||||
List<JSONObject> monthInRegList = WQL.getWO("TEST0001").addParam("flag", "15") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 所有当月出库量区域分组集合
|
|
||||
List<JSONObject> monthOutRegList = WQL.getWO("TEST0001").addParam("flag", "16") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 所有当月入库量区域、客户分组集合
|
|
||||
List<JSONObject> monthCustInRegList = WQL.getWO("TEST0001").addParam("flag", "17") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// 所有当月出库量区域、客户分组集合
|
|
||||
List<JSONObject> monthCustOutRegList = WQL.getWO("TEST0001").addParam("flag", "18") |
|
||||
.process().getResultJSONArray(0).toJavaList(JSONObject.class); |
|
||||
|
|
||||
// ---- 当月入库量 ----
|
|
||||
JSONObject monthRegIn = monthReg(monthInRegList, "当月入库量"); |
|
||||
Arrayobject5.add(monthRegIn); |
|
||||
|
|
||||
// ---- 当月出库量 ----
|
|
||||
JSONObject monthRegOut = monthReg(monthOutRegList, "当月出库量"); |
|
||||
Arrayobject5.add(monthRegOut); |
|
||||
|
|
||||
// ---- 昨日入库量 ----
|
|
||||
JSONObject yesterdayInReg = monthReg(yesterdayInRegList, "昨日入库量"); |
|
||||
Arrayobject5.add(yesterdayInReg); |
|
||||
|
|
||||
// ---- 昨日出库量 ----
|
|
||||
JSONObject yesterdayOutReg = monthReg(yesterdayOutRegList, "昨日出库量"); |
|
||||
Arrayobject5.add(yesterdayOutReg); |
|
||||
|
|
||||
// ---- B昨日出库量 ----
|
|
||||
JSONObject yesterdayCustOutRegB = monthRegCust(yesterdayCustOutRegList, "B昨日出库量", custB); |
|
||||
Arrayobject5.add(yesterdayCustOutRegB); |
|
||||
|
|
||||
// ---- B昨日入库量 ----
|
|
||||
JSONObject yesterdayCustInRegB = monthRegCust(yesterdayCustInRegList, "B昨日入库量", custB); |
|
||||
Arrayobject5.add(yesterdayCustInRegB); |
|
||||
|
|
||||
// ---- B当月入库量 ----
|
|
||||
JSONObject monthCustInRegB = monthRegCust(monthCustInRegList, "B当月入库量", custB); |
|
||||
Arrayobject5.add(monthCustInRegB); |
|
||||
|
|
||||
// ---- B当月出库量 ----
|
|
||||
JSONObject monthCustOutRegB = monthRegCust(monthCustOutRegList, "B当月出库量", custB); |
|
||||
Arrayobject5.add(monthCustOutRegB); |
|
||||
|
|
||||
// ---- C昨日出库量 ----
|
|
||||
JSONObject yesterdayCustOutRegC = monthRegCust(yesterdayCustOutRegList, "C昨日出库量", custC); |
|
||||
Arrayobject5.add(yesterdayCustOutRegC); |
|
||||
|
|
||||
// ---- C昨日入库量 ----
|
|
||||
JSONObject yesterdayCustInRegC = monthRegCust(yesterdayCustInRegList, "C昨日入库量", custC); |
|
||||
Arrayobject5.add(yesterdayCustInRegC); |
|
||||
|
|
||||
// ---- C当月入库量 ----
|
|
||||
JSONObject monthCustInRegC = monthRegCust(monthCustInRegList, "C当月入库量", custC); |
|
||||
Arrayobject5.add(monthCustInRegC); |
|
||||
|
|
||||
// ---- C当月出库量 ----
|
|
||||
JSONObject monthCustOutRegC = monthRegCust(monthCustOutRegList, "C当月出库量", custC); |
|
||||
Arrayobject5.add(monthCustOutRegC); |
|
||||
|
|
||||
result.put("Arrayobject5", Arrayobject5); |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 当月区域公共方法 |
|
||||
* |
|
||||
* @param param 、 |
|
||||
* @param title 、 |
|
||||
* @return JSONObject |
|
||||
*/ |
|
||||
private JSONObject monthReg(List<JSONObject> param, String title) { |
|
||||
|
|
||||
JSONObject result = new JSONObject(); |
|
||||
result.put("Title", title); |
|
||||
|
|
||||
Map<String, List<JSONObject>> paramMap = param.stream() |
|
||||
.collect(Collectors.groupingBy(row -> row.getString("region_code"))); |
|
||||
|
|
||||
if (paramMap.isEmpty()) { |
|
||||
result.put("Areaqty1", "0"); |
|
||||
result.put("Areaqty2", "0"); |
|
||||
result.put("Areaqty3", "0"); |
|
||||
result.put("Areaqty4", "0"); |
|
||||
} |
|
||||
|
|
||||
for (String region_code : paramMap.keySet()) { |
|
||||
List<JSONObject> list = paramMap.get(region_code); |
|
||||
|
|
||||
String num = NumberUtil.round(list.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""; |
|
||||
|
|
||||
switch (region_code) { |
|
||||
case "A1": |
|
||||
result.put("Areaqty1", num); |
|
||||
break; |
|
||||
case "A2": |
|
||||
result.put("Areaqty2", num); |
|
||||
break; |
|
||||
case "A3": |
|
||||
result.put("Areaqty3", num); |
|
||||
break; |
|
||||
case "A4": |
|
||||
result.put("Areaqty4", num); |
|
||||
break; |
|
||||
default: |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
if (ObjectUtil.isEmpty(result.getString("Areaqty1"))) { |
|
||||
result.put("Areaqty1", "0"); |
|
||||
} |
|
||||
if (ObjectUtil.isEmpty(result.getString("Areaqty2"))) { |
|
||||
result.put("Areaqty2", "0"); |
|
||||
} |
|
||||
if (ObjectUtil.isEmpty(result.getString("Areaqty3"))) { |
|
||||
result.put("Areaqty3", "0"); |
|
||||
} |
|
||||
if (ObjectUtil.isEmpty(result.getString("Areaqty4"))) { |
|
||||
result.put("Areaqty4", "0"); |
|
||||
} |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 当月区域、客户公共方法 |
|
||||
* |
|
||||
* @param param 、 |
|
||||
* @param title 、 |
|
||||
* @param customer 客户 、 |
|
||||
* @return JSONObject |
|
||||
*/ |
|
||||
private JSONObject monthRegCust(List<JSONObject> param, String title, String customer) { |
|
||||
|
|
||||
JSONObject result = new JSONObject(); |
|
||||
result.put("Title", title); |
|
||||
|
|
||||
Map<String, List<JSONObject>> paramMap = param.stream() |
|
||||
.collect(Collectors.groupingBy(row -> row.getString("region_code"))); |
|
||||
|
|
||||
if (paramMap.isEmpty()) { |
|
||||
result.put("Areaqty1", "0"); |
|
||||
result.put("Areaqty2", "0"); |
|
||||
result.put("Areaqty3", "0"); |
|
||||
result.put("Areaqty4", "0"); |
|
||||
} |
|
||||
|
|
||||
for (String region_code : paramMap.keySet()) { |
|
||||
List<JSONObject> list = paramMap.get(region_code); |
|
||||
|
|
||||
List<JSONObject> custList = list.stream() |
|
||||
.filter(row -> customer.contains(row.getString("customer_name"))) |
|
||||
.collect(Collectors.toList()); |
|
||||
|
|
||||
String num = NumberUtil.round(custList.stream().map(row -> row.getDoubleValue("num")).reduce(Double::sum).orElse(0.0).toString(), 2) + ""; |
|
||||
|
|
||||
|
|
||||
switch (region_code) { |
|
||||
case "A1": |
|
||||
result.put("Areaqty1", num); |
|
||||
break; |
|
||||
case "A2": |
|
||||
result.put("Areaqty2", num); |
|
||||
break; |
|
||||
case "A3": |
|
||||
result.put("Areaqty3", num); |
|
||||
break; |
|
||||
case "A4": |
|
||||
result.put("Areaqty4", num); |
|
||||
break; |
|
||||
default: |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
if (ObjectUtil.isEmpty(result.getString("Areaqty1"))) { |
|
||||
result.put("Areaqty1", "0"); |
|
||||
} |
|
||||
if (ObjectUtil.isEmpty(result.getString("Areaqty2"))) { |
|
||||
result.put("Areaqty2", "0"); |
|
||||
} |
|
||||
if (ObjectUtil.isEmpty(result.getString("Areaqty3"))) { |
|
||||
result.put("Areaqty3", "0"); |
|
||||
} |
|
||||
if (ObjectUtil.isEmpty(result.getString("Areaqty4"))) { |
|
||||
result.put("Areaqty4", "0"); |
|
||||
} |
|
||||
|
|
||||
return result; |
|
||||
} |
|
||||
} |
|
Loading…
Reference in new issue