|
|
@@ -1153,6 +1153,8 @@ public class HeiHuOrderServiceImpl implements HeiHuOrderService {
|
|
|
body_A.put("orderNo",orderNumber);
|
|
|
String jsonString2 = UtilHttp.doPost("https://liteweb.blacklake.cn/api/dytin/external/saleOrder/queryList2", header, null, body_A);//todo:查询销售订单,获取客户、订单号、款号、产品描述、颜色、数量、销售单价、销售金额、币别
|
|
|
JSONArray array = JSONObject.parseObject(jsonString2).getJSONArray("data");//主表数据
|
|
|
+
|
|
|
+ boolean isSample = false;//销售订单若为样品订单则不发起钉钉流程
|
|
|
for(int i=0;i<array.size();i++){
|
|
|
JSONObject data = array.getJSONObject(i);
|
|
|
customerName = data.getString("customerCode");//客户
|
|
|
@@ -1172,125 +1174,133 @@ public class HeiHuOrderServiceImpl implements HeiHuOrderService {
|
|
|
JsonNode valueNode = field.get("value");
|
|
|
if(valueNode != null){
|
|
|
estimatedPrice = valueNode.asDouble();//辅料预估单价
|
|
|
- break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(fieldIdNode != null && fieldIdNode.asInt() == 47771){
|
|
|
+ JsonNode valueNode = field.get("value");
|
|
|
+ if("样品订单".equals(valueNode.asText())){
|
|
|
+ isSample = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- JSONArray products_A = JSONObject.parseObject(jsonString2).getJSONArray("data").getJSONObject(0).getJSONArray("saleManageOrderDetailRowApiVOList");//销售订单明细数据
|
|
|
-
|
|
|
- if(products_A != null) {
|
|
|
- for (int i = 0; i < products_A.size(); i++) {
|
|
|
- JSONObject detail = products_A.getJSONObject(i);
|
|
|
- HashMap row = new HashMap();
|
|
|
- row.put("textField_mm2t71jm",orderCode);//todo:采购订单单号
|
|
|
- row.put("textField_ml6g7k5e", customerName);//todo:客户
|
|
|
- row.put("textField_ml6g7k5f", orderNumber);//todo:订单号
|
|
|
-
|
|
|
- styleNumber = detail.getString("productCode");//款号
|
|
|
- row.put("textField_ml7c3yhq", styleNumber);//todo:款号
|
|
|
-
|
|
|
- productDescription = detail.getString("productName");//产品描述
|
|
|
- row.put("textField_ml7c3yhr", productDescription);//todo:产品描述
|
|
|
-
|
|
|
- JSONArray array1 = detail.getJSONArray("customFieldValues");
|
|
|
- color = array1.stream()
|
|
|
- .map(obj -> (JSONObject) obj)
|
|
|
- .filter(item -> item.getIntValue("fieldId") == 82259)
|
|
|
- .map(item -> item.getString("value"))
|
|
|
- .findFirst()
|
|
|
- .orElse(null);
|
|
|
- ArrayList colorList = new ArrayList();
|
|
|
- colorList.add(color);
|
|
|
- String color_AAA = null;
|
|
|
- try {
|
|
|
- color_AAA = getProductColor(colorList);
|
|
|
- } catch (JacksonException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- row.put("textField_ml7c3yhs", color_AAA);//todo:颜色
|
|
|
-
|
|
|
- number = detail.getDoubleValue("qty");//数量
|
|
|
- row.put("numberField_ml7c3yht", number);//todo:数量
|
|
|
-
|
|
|
- unitPrice = detail.getDoubleValue("unitPrice");//销售单价
|
|
|
- row.put("numberField_ml7c3yhu", unitPrice);//todo:销售单价
|
|
|
-
|
|
|
- salesAmount = number * unitPrice;//销售金额
|
|
|
- row.put("numberField_ml7c3yhv", salesAmount);//todo:销售金额
|
|
|
- String customFieldValues = detail.getString("customFieldValues");
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- JsonNode jsonarray = null;
|
|
|
- try {
|
|
|
- jsonarray = mapper.readTree(customFieldValues);
|
|
|
- } catch (JsonProcessingException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- for (JsonNode node : jsonarray) {
|
|
|
- if (node.get("fieldId").asInt() == 47919) {
|
|
|
- currency = node.get("value").asText();
|
|
|
- } else if (node.get("fieldId").asInt() == 165251) {
|
|
|
- USDrate = node.get("value").asDouble();
|
|
|
-
|
|
|
- } else if (node.get("fieldId").asInt() == 161783) {
|
|
|
- flygcb = node.get("value").asDouble();
|
|
|
+ if (!isSample){
|
|
|
+ JSONArray products_A = JSONObject.parseObject(jsonString2).getJSONArray("data").getJSONObject(0).getJSONArray("saleManageOrderDetailRowApiVOList");//销售订单明细数据
|
|
|
+
|
|
|
+ if(products_A != null) {
|
|
|
+ for (int i = 0; i < products_A.size(); i++) {
|
|
|
+ JSONObject detail = products_A.getJSONObject(i);
|
|
|
+ HashMap row = new HashMap();
|
|
|
+ row.put("textField_mm2t71jm",orderCode);//todo:采购订单单号
|
|
|
+ row.put("textField_ml6g7k5e", customerName);//todo:客户
|
|
|
+ row.put("textField_ml6g7k5f", orderNumber);//todo:订单号
|
|
|
+
|
|
|
+ styleNumber = detail.getString("productCode");//款号
|
|
|
+ row.put("textField_ml7c3yhq", styleNumber);//todo:款号
|
|
|
+
|
|
|
+ productDescription = detail.getString("productName");//产品描述
|
|
|
+ row.put("textField_ml7c3yhr", productDescription);//todo:产品描述
|
|
|
+
|
|
|
+ JSONArray array1 = detail.getJSONArray("customFieldValues");
|
|
|
+ color = array1.stream()
|
|
|
+ .map(obj -> (JSONObject) obj)
|
|
|
+ .filter(item -> item.getIntValue("fieldId") == 82259)
|
|
|
+ .map(item -> item.getString("value"))
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+ ArrayList colorList = new ArrayList();
|
|
|
+ colorList.add(color);
|
|
|
+ String color_AAA = null;
|
|
|
+ try {
|
|
|
+ color_AAA = getProductColor(colorList);
|
|
|
+ } catch (JacksonException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
- }
|
|
|
- row.put("textField_ml7c3yhw", currency);//todo:币别
|
|
|
- row.put("numberField_ml86221y", USDrate);//todo:美金汇率
|
|
|
- row.put("numberField_ml86221z", flygcb);//todo:辅料预估成本
|
|
|
- if(currency.equals("USD")){
|
|
|
- saletotalAmount = salesAmount * USDrate;
|
|
|
- }else {
|
|
|
- saletotalAmount = salesAmount;
|
|
|
- }
|
|
|
- row.put("numberField_ml862220",saletotalAmount);
|
|
|
- //下面是采购订单的明细数据
|
|
|
- row.put("textField_ml7c3yhx",shortName);//todo:生产工厂
|
|
|
- for(int j=0;j<products.size();j++){
|
|
|
- if(styleNumber.equals(products.getJSONObject(j).getString("productCode"))){
|
|
|
- //找到对应的采购一行数据
|
|
|
- row.put("numberField_ml7c3yhy",products.getJSONObject(j).getDouble("purchasePrice"));//todo:采购单价
|
|
|
- row.put("numberField_ml7c3yhz",products.getJSONObject(j).getDouble("purchaseNum"));//todo:采购数量
|
|
|
- row.put("numberField_ml7c3yi0",products.getJSONObject(j).getDouble("purchasePrice") * products.getJSONObject(j).getDouble("purchaseNum"));//todo:采购金额
|
|
|
+ row.put("textField_ml7c3yhs", color_AAA);//todo:颜色
|
|
|
+
|
|
|
+ number = detail.getDoubleValue("qty");//数量
|
|
|
+ row.put("numberField_ml7c3yht", number);//todo:数量
|
|
|
+
|
|
|
+ unitPrice = detail.getDoubleValue("unitPrice");//销售单价
|
|
|
+ row.put("numberField_ml7c3yhu", unitPrice);//todo:销售单价
|
|
|
+
|
|
|
+ salesAmount = number * unitPrice;//销售金额
|
|
|
+ row.put("numberField_ml7c3yhv", salesAmount);//todo:销售金额
|
|
|
+ String customFieldValues = detail.getString("customFieldValues");
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ JsonNode jsonarray = null;
|
|
|
+ try {
|
|
|
+ jsonarray = mapper.readTree(customFieldValues);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ for (JsonNode node : jsonarray) {
|
|
|
+ if (node.get("fieldId").asInt() == 47919) {
|
|
|
+ currency = node.get("value").asText();
|
|
|
+ } else if (node.get("fieldId").asInt() == 165251) {
|
|
|
+ USDrate = node.get("value").asDouble();
|
|
|
+
|
|
|
+ } else if (node.get("fieldId").asInt() == 161783) {
|
|
|
+ flygcb = node.get("value").asDouble();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ row.put("textField_ml7c3yhw", currency);//todo:币别
|
|
|
+ row.put("numberField_ml86221y", USDrate);//todo:美金汇率
|
|
|
+ row.put("numberField_ml86221z", flygcb);//todo:辅料预估成本
|
|
|
+ if(currency.equals("USD")){
|
|
|
+ saletotalAmount = salesAmount * USDrate;
|
|
|
+ }else {
|
|
|
+ saletotalAmount = salesAmount;
|
|
|
+ }
|
|
|
+ row.put("numberField_ml862220",saletotalAmount);
|
|
|
+ //下面是采购订单的明细数据
|
|
|
+ row.put("textField_ml7c3yhx",shortName);//todo:生产工厂
|
|
|
+ for(int j=0;j<products.size();j++){
|
|
|
+ if(styleNumber.equals(products.getJSONObject(j).getString("productCode"))){
|
|
|
+ //找到对应的采购一行数据
|
|
|
+ row.put("numberField_ml7c3yhy",products.getJSONObject(j).getDouble("purchasePrice"));//todo:采购单价
|
|
|
+ row.put("numberField_ml7c3yhz",products.getJSONObject(j).getDouble("purchaseNum"));//todo:采购数量
|
|
|
+ row.put("numberField_ml7c3yi0",products.getJSONObject(j).getDouble("purchasePrice") * products.getJSONObject(j).getDouble("purchaseNum"));//todo:采购金额
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // ========== 修改点4:将当前行转换为Map<String,String>并暂存 ==========
|
|
|
- Map<String, String> rowMap = new HashMap<>();
|
|
|
- for (Object key : row.keySet()) {
|
|
|
- Object value = row.get(key);
|
|
|
- rowMap.put(key.toString(), value != null ? value.toString() : "");
|
|
|
- }
|
|
|
- currentOrderRows.add(rowMap);
|
|
|
+ // ========== 修改点4:将当前行转换为Map<String,String>并暂存 ==========
|
|
|
+ Map<String, String> rowMap = new HashMap<>();
|
|
|
+ for (Object key : row.keySet()) {
|
|
|
+ Object value = row.get(key);
|
|
|
+ rowMap.put(key.toString(), value != null ? value.toString() : "");
|
|
|
+ }
|
|
|
+ currentOrderRows.add(rowMap);
|
|
|
|
|
|
- // ========== 修改点5:累加当前订单的汇总数据用于计算毛利率 ==========
|
|
|
- orderTotalSalesAmount += saletotalAmount;
|
|
|
- orderTotalPurchaseAmount += (Double)row.get("numberField_ml7c3yi0");
|
|
|
- orderTotalFlygcb += flygcb;
|
|
|
+ // ========== 修改点5:累加当前订单的汇总数据用于计算毛利率 ==========
|
|
|
+ orderTotalSalesAmount += saletotalAmount;
|
|
|
+ orderTotalPurchaseAmount += (Double)row.get("numberField_ml7c3yi0");
|
|
|
+ orderTotalFlygcb += flygcb;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // ========== 修改点6:计算当前订单的毛利率 ==========
|
|
|
- double mlv = 0.0;
|
|
|
- if (orderTotalSalesAmount > 0) {
|
|
|
- mlv = (orderTotalSalesAmount - orderTotalPurchaseAmount - orderTotalFlygcb) / orderTotalSalesAmount;
|
|
|
- }
|
|
|
|
|
|
- System.out.println("订单 " + orderCode + " 毛利率: " + String.format("%.2f%%", mlv * 100));
|
|
|
+ // ========== 修改点6:计算当前订单的毛利率 ==========
|
|
|
+ double mlv = 0.0;
|
|
|
+ if (orderTotalSalesAmount > 0) {
|
|
|
+ mlv = (orderTotalSalesAmount - orderTotalPurchaseAmount - orderTotalFlygcb) / orderTotalSalesAmount;
|
|
|
+ }
|
|
|
|
|
|
- // ========== 修改点7:根据毛利率决定添加到哪个列表 ==========
|
|
|
- if (mlv >= 0.15) {
|
|
|
- // 高毛利率订单
|
|
|
- tabledataHigh.addAll(currentOrderRows);
|
|
|
- System.out.println("订单 " + orderCode + " 归类到高毛利率审批(>=15%)");
|
|
|
- } else {
|
|
|
- // 低毛利率订单
|
|
|
- tabledataLow.addAll(currentOrderRows);
|
|
|
- System.out.println("订单 " + orderCode + " 归类到低毛利率审批(<15%)");
|
|
|
+ System.out.println("订单 " + orderCode + " 毛利率: " + String.format("%.2f%%", mlv * 100));
|
|
|
+
|
|
|
+ // ========== 修改点7:根据毛利率决定添加到哪个列表 ==========
|
|
|
+ if (mlv >= 0.15) {
|
|
|
+ // 高毛利率订单
|
|
|
+ tabledataHigh.addAll(currentOrderRows);
|
|
|
+ System.out.println("订单 " + orderCode + " 归类到高毛利率审批(>=15%)");
|
|
|
+ } else {
|
|
|
+ // 低毛利率订单
|
|
|
+ tabledataLow.addAll(currentOrderRows);
|
|
|
+ System.out.println("订单 " + orderCode + " 归类到低毛利率审批(<15%)");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
List<Map<String, Object>> oldList = new ArrayList<>();
|
|
|
if (type.equals(targetValueUpdate)){
|
|
|
oldIds.forEach(h->{
|
|
|
@@ -1426,7 +1436,7 @@ public class HeiHuOrderServiceImpl implements HeiHuOrderService {
|
|
|
body.put("status", status);
|
|
|
|
|
|
String doPost = UtilHttp.doPost("https://liteweb.blacklake.cn/api/dytin/external/purchaseOrder/queryList2", header, null, body);//查询采购订单
|
|
|
- log.info("header:",header.toString());
|
|
|
+ log.info("header:{}",header.toString());
|
|
|
System.out.println("header:" + header.toString());
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
Map<String, Object> response = mapper.readValue(doPost, Map.class);
|
|
|
@@ -1440,7 +1450,6 @@ public class HeiHuOrderServiceImpl implements HeiHuOrderService {
|
|
|
List<Map<String, Object>> mapList = (List<Map<String, Object>>) response.get("data");
|
|
|
if (ObjectUtil.isNotNull(mapList) && mapList.size() > 0){
|
|
|
dataList.addAll(mapList);
|
|
|
-
|
|
|
hasMoreData = mapList.size() >= pageSize;
|
|
|
} else {
|
|
|
hasMoreData = false;
|