mdf:粉料计划接口优化
This commit is contained in:
@@ -119,3 +119,22 @@
|
||||
ENDSELECT
|
||||
ENDQUERY
|
||||
ENDIF
|
||||
|
||||
IF 输入.flag = "5"
|
||||
QUERY
|
||||
SELECT
|
||||
ITEM_ID AS ext_id,
|
||||
sum(QTY_ZT) AS notqty
|
||||
FROM
|
||||
PURCHASE_CONTRACT_VIEW
|
||||
where
|
||||
STATUSFLAG = '3'
|
||||
AND DEL_FLAG = '0'
|
||||
OPTION 输入.ext_id <> ""
|
||||
ITEM_ID in 输入.ext_id
|
||||
ENDOPTION
|
||||
GROUP BY ITEM_ID
|
||||
ENDSELECT
|
||||
ENDQUERY
|
||||
ENDIF
|
||||
|
||||
|
||||
@@ -25,7 +25,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -98,7 +100,6 @@ public class StatisticalReportServiceImpl implements StatisticalReportService {
|
||||
String org_id = MapUtil.getStr(whereJson, "org_id");
|
||||
Date date1 = DateUtil.parse(begin_time);
|
||||
Date date2 = DateUtil.parse(end_time);
|
||||
long betweenDay = DateUtil.between(date1, date2, DateUnit.DAY);
|
||||
JSONArray rows = new JSONArray();
|
||||
JSONArray mater_rows = WQL.getWO("statistical_report_query_01").addParam("flag", "3").process().getResultJSONArray(0);
|
||||
JSONObject jo1 = new JSONObject();
|
||||
@@ -136,16 +137,33 @@ public class StatisticalReportServiceImpl implements StatisticalReportService {
|
||||
JSONObject form_qty = dtlJa.getJSONObject(i);
|
||||
dtlJa_map.put(form_qty.getString("material_id"),form_qty.getDouble("qty"));
|
||||
}
|
||||
//库存物料数量
|
||||
JSONArray materQryArray = WQL.getWO("statistical_report_query_01").addParam("flag", "4").process().getResultJSONArray(0);
|
||||
Map<String, List<Object>> materialMap = materQryArray.stream().collect(Collectors.groupingBy(a -> ((JSONObject)a).getString("material_id")));
|
||||
//排产需求
|
||||
JSONArray needMaterArray = WQL.getWO("statistical_report_query_01").addParam("flag", "6").addParam("begin_time", begin_time).addParam("end_time", end_time).addParam("org_id", org_id).process().getResultJSONArray(0);
|
||||
Map<String, List<Object>> needMaterMap = needMaterArray.stream().collect(Collectors.groupingBy(a -> ((JSONObject)a).getString("material_id")));
|
||||
|
||||
//3、待检入库量:sum(此物料未确认的到货单的单据数-入库数)
|
||||
JSONArray noinJoArray = WQL.getWO("statistical_report_query_01").addParam("flag", "77").process().getResultJSONArray(0);
|
||||
Map<String, List<Object>> noinJoMap = noinJoArray.stream().collect(Collectors.groupingBy(a -> ((JSONObject)a).getString("material_id")));
|
||||
|
||||
//查询物料计划日期内的需求量
|
||||
JSONArray DataPlanQtyArray = WQL.getWO("statistical_report_query_01").addParam("flag", "10")
|
||||
.addParam("begin_time", begin_time.substring(0, 10) + "%")
|
||||
.addParam("end_time", end_time.substring(0, 10) + "%").process().getResultJSONArray(0);
|
||||
Map<String, List<Object>> datePlanMap = DataPlanQtyArray.stream().collect(Collectors.groupingBy(a -> ((JSONObject)a).getString("material_id")));
|
||||
|
||||
for (int i = 0; i < mater_rows.size(); i++) {
|
||||
JSONObject mater = mater_rows.getJSONObject(i);
|
||||
String material_id = mater.getString("material_id");
|
||||
//1、库存现存量:现有库存
|
||||
JSONObject mater_ivt = WQL.getWO("statistical_report_query_01").addParam("flag", "4").addParam("material_id", material_id).process().uniqueResult(0);
|
||||
|
||||
double now_ivt = 0;
|
||||
double need_qty = 0;
|
||||
if (ObjectUtil.isNotEmpty(mater_ivt)) {
|
||||
now_ivt = mater_ivt.getDoubleValue("qty");
|
||||
List<Object> materInfo = materialMap.get(material_id);
|
||||
if (ObjectUtil.isNotEmpty(materInfo)) {
|
||||
now_ivt = ((JSONObject) materInfo.get(0)).getDoubleValue("qty");
|
||||
}
|
||||
if (dtlJa_map.containsKey(material_id)) {
|
||||
need_qty = dtlJa_map.get(material_id);
|
||||
@@ -157,19 +175,20 @@ public class StatisticalReportServiceImpl implements StatisticalReportService {
|
||||
//已开单重量
|
||||
jo22.put(material_id, String.format("%.2f", need_qty));
|
||||
//2、排产需求量(未开工的工令重量+排产未生成工令日计划重量)根据bom计算需要多少原料库存重量:
|
||||
JSONObject nedd_mater = WQL.getWO("statistical_report_query_01").addParam("flag", "6").addParam("material_id", material_id).addParam("begin_time", begin_time).addParam("end_time", end_time).addParam("org_id", org_id).process().uniqueResult(0);
|
||||
// JSONObject nedd_mater = WQL.getWO("statistical_report_query_01").addParam("flag", "6").addParam("material_id", material_id).addParam("begin_time", begin_time).addParam("end_time", end_time).addParam("org_id", org_id).process().uniqueResult(0);
|
||||
double bom_qty = 0;
|
||||
if (ObjectUtil.isNotEmpty(nedd_mater)) {
|
||||
bom_qty = nedd_mater.getDoubleValue("qty");
|
||||
List<Object> needMaterInfo = needMaterMap.get(material_id);
|
||||
if (ObjectUtil.isNotEmpty(needMaterInfo)) {
|
||||
bom_qty = ((JSONObject) needMaterInfo.get(0)).getDoubleValue("qty");
|
||||
}
|
||||
jo2.put(material_id, String.format("%.2f", bom_qty));
|
||||
|
||||
//3、待检入库量:sum(此物料未确认的到货单的单据数-入库数)
|
||||
JSONObject noin_jo = WQL.getWO("statistical_report_query_01").addParam("flag", "77").addParam("material_id", material_id).process().uniqueResult(0);
|
||||
//待检+未入库数量
|
||||
double noin_qty = 0;
|
||||
if (ObjectUtil.isNotEmpty(noin_jo)) {
|
||||
noin_qty = noin_jo.getDoubleValue("noin_qty");
|
||||
List<Object> noinJoInfo = noinJoMap.get(material_id);
|
||||
if (ObjectUtil.isNotEmpty(noinJoInfo)) {
|
||||
bom_qty = ((JSONObject) noinJoInfo.get(0)).getDoubleValue("noin_qty");
|
||||
}
|
||||
jo4.put(material_id, String.format("%.2f", noin_qty));
|
||||
|
||||
@@ -187,7 +206,6 @@ public class StatisticalReportServiceImpl implements StatisticalReportService {
|
||||
map.put("flag", "4");
|
||||
map.put("ext_id", jsonMater.getString("ext_id"));
|
||||
JSONObject num_jo = WQL.getWO("QL_ERP").addParamMap(map).setDbname("dataSource1").process().uniqueResult(0);
|
||||
|
||||
//合同在途
|
||||
double notqty = 0;
|
||||
if (ObjectUtil.isNotEmpty(num_jo)) {
|
||||
@@ -217,24 +235,41 @@ public class StatisticalReportServiceImpl implements StatisticalReportService {
|
||||
if (canuse_num<0){
|
||||
jo5.put(material_id, DateUtil.offsetDay(date1, -1).toString().substring(0, 10));
|
||||
}else {
|
||||
for (int j = 1; j <= betweenDay; j++) {
|
||||
DateTime newDate = DateUtil.offsetDay(date1, j);
|
||||
//查询该物料当天的需求量
|
||||
JSONObject today_qty = WQL.getWO("statistical_report_query_01").addParam("flag", "8").addParam("material_id", material_id).addParam("begin_time", newDate.toString().substring(0, 10) + "%").process().uniqueResult(0);
|
||||
double need_weight = 0;
|
||||
if (ObjectUtil.isNotEmpty(today_qty)) {
|
||||
need_weight = today_qty.getDoubleValue("qty");
|
||||
}
|
||||
if (canuse_num < need_weight) {
|
||||
jo5.put(material_id, DateUtil.offsetDay(newDate, -1).toString().substring(0, 10));
|
||||
break;
|
||||
} else {
|
||||
canuse_num -= need_weight;
|
||||
}
|
||||
if (j == betweenDay) {
|
||||
jo5.put(material_id, end_time.substring(0, 10));
|
||||
List<Object> materDataPlanQty = datePlanMap.get(material_id);
|
||||
double needWeight;
|
||||
jo5.put(material_id, end_time.substring(0, 10));
|
||||
if (ObjectUtil.isNotEmpty(materDataPlanQty)){
|
||||
for (Object todayQty : materDataPlanQty) {
|
||||
JSONObject jsonQty = (JSONObject) todayQty;
|
||||
needWeight = jsonQty.getDoubleValue("qty");
|
||||
Date currentDate = ((JSONObject) todayQty).getDate("currentdate");
|
||||
if (canuse_num < needWeight) {
|
||||
jo5.put(material_id, DateUtil.offsetDay(currentDate, -1).toString().substring(0, 10));
|
||||
break;
|
||||
} else {
|
||||
canuse_num -= needWeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for (int j = 1; j <= betweenDay; j++) {
|
||||
// DateTime newDate = DateUtil.offsetDay(date1, j);
|
||||
// //查询该物料当天的需求量
|
||||
// JSONObject today_qty = WQL.getWO("statistical_report_query_01").addParam("flag", "8").addParam("material_id", material_id).addParam("begin_time", newDate.toString().substring(0, 10) + "%").process().uniqueResult(0);
|
||||
// double need_weight = 0;
|
||||
// if (ObjectUtil.isNotEmpty(today_qty)) {
|
||||
// need_weight = today_qty.getDoubleValue("qty");
|
||||
// }
|
||||
// if (canuse_num < need_weight) {
|
||||
// jo5.put(material_id, DateUtil.offsetDay(newDate, -1).toString().substring(0, 10));
|
||||
// break;
|
||||
// } else {
|
||||
// canuse_num -= need_weight;
|
||||
// }
|
||||
// if (j == betweenDay) {
|
||||
// jo5.put(material_id, end_time.substring(0, 10));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
JSONObject jo = new JSONObject();
|
||||
|
||||
@@ -385,7 +385,7 @@
|
||||
IF 输入.flag = "4"
|
||||
QUERY
|
||||
SELECT
|
||||
SUM( canuse_qty ) AS qty
|
||||
material_id,SUM( canuse_qty ) AS qty
|
||||
FROM
|
||||
st_ivt_structivt
|
||||
WHERE
|
||||
@@ -703,4 +703,103 @@
|
||||
ENDQUERY
|
||||
ENDIF
|
||||
|
||||
IF 输入.flag = "10"
|
||||
QUERY
|
||||
SELECT
|
||||
dtl.material_id,
|
||||
b.currentDate,
|
||||
ROUND((b.qty * dtl.standard_rate * 0.01),3) as qty
|
||||
FROM (
|
||||
SELECT
|
||||
material_id,SUM( qty ) AS qty,currentDate
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
material_id,
|
||||
workorder_qty AS qty,
|
||||
wo.planstart_time as currentDate
|
||||
FROM
|
||||
pdm_bi_workorder wo
|
||||
WHERE wo.`status` < 50 AND is_delete = '0'
|
||||
OPTION 输入.begin_time <> ""
|
||||
wo.planstart_time >= 输入.begin_time
|
||||
ENDOPTION
|
||||
OPTION 输入.end_time <> ""
|
||||
wo.planstart_time <= 输入.end_time
|
||||
ENDOPTION
|
||||
UNION ALL
|
||||
SELECT
|
||||
material_id,
|
||||
product_weight AS qty,
|
||||
planstart_date as currentDate
|
||||
FROM
|
||||
MPS_BD_ProductDailyPlan
|
||||
WHERE `status` = '01'
|
||||
OPTION 输入.begin_time <> ""
|
||||
planstart_date >= 输入.begin_time
|
||||
ENDOPTION
|
||||
OPTION 输入.end_time <> ""
|
||||
planstart_date <= 输入.end_time
|
||||
ENDOPTION
|
||||
) a GROUP BY a.material_id,currentDate
|
||||
) b
|
||||
LEFT JOIN md_pd_productbom mst ON mst.material_id = b.material_id
|
||||
LEFT JOIN md_pd_productbomdtl dtl ON mst.bom_id = dtl.bom_id
|
||||
WHERE
|
||||
1=1 order by currentDate
|
||||
ENDSELECT
|
||||
ENDQUERY
|
||||
ENDIF
|
||||
|
||||
IF 输入.flag = "11"
|
||||
QUERY
|
||||
SELECT DISTINCT
|
||||
mb.material_id,
|
||||
mb.material_name,
|
||||
mb.material_code,
|
||||
class.parent_class_id,
|
||||
(case when class.class_id = '1503644362192588800' then 1
|
||||
when class.class_id = '1503644361664106496' then 2
|
||||
when class.class_id = '1503644362788179968' then 4
|
||||
when class.class_id = '1503644362234531840' then 5
|
||||
else 3 end) AS order_no
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
wo.material_id
|
||||
FROM
|
||||
pdm_bi_workorder wo
|
||||
WHERE
|
||||
wo.is_delete = '0'
|
||||
AND wo.`status` IN ( '10', '20', '30' )
|
||||
OPTION 输入.begin_time <> ""
|
||||
wo.planstart_time >= 输入.begin_time
|
||||
ENDOPTION
|
||||
OPTION 输入.end_time <> ""
|
||||
wo.planstart_time <= 输入.end_time
|
||||
ENDOPTION
|
||||
UNION
|
||||
SELECT
|
||||
plan.material_id
|
||||
FROM
|
||||
mps_bd_productdailyplan plan
|
||||
WHERE
|
||||
plan.`status` = '01'
|
||||
OPTION 输入.begin_time <> ""
|
||||
plan.planstart_date >= 输入.begin_time
|
||||
ENDOPTION
|
||||
OPTION 输入.end_time <> ""
|
||||
plan.planstart_date <= 输入.end_time
|
||||
ENDOPTION
|
||||
) a
|
||||
LEFT JOIN md_pd_productbom bom ON bom.material_id = a.material_id
|
||||
LEFT JOIN md_pd_productbomdtl dtl ON dtl.bom_id = dtl.bom_id
|
||||
LEFT JOIN md_me_materialbase mb ON mb.material_id = dtl.material_id
|
||||
LEFT JOIN md_pb_classstandard class ON class.class_id = mb.material_type_id
|
||||
ORDER BY order_no,material_code
|
||||
ENDSELECT
|
||||
ENDQUERY
|
||||
ENDIF
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user