opt:粉料开单接口优化

This commit is contained in:
zhangzhiqiang
2022-12-01 18:39:29 +08:00
parent 9b0d70ae33
commit 1201b9db6f
3 changed files with 120 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ public class PowderProductionQueryController {
@Log("粉料投产记录查询")
@ApiOperation("粉料投产记录查询")
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
return new ResponseEntity<>(powderProductionQueryService.queryAll(whereJson, page), HttpStatus.OK);
// return new ResponseEntity<>(powderProductionQueryService.queryAll(whereJson, page), HttpStatus.OK);
return new ResponseEntity<>(powderProductionQueryService.queryAll2(whereJson, page), HttpStatus.OK);
}
}

View File

@@ -13,4 +13,12 @@ public interface PowderProductionQueryService {
* @return Map<String, Object>
*/
Map<String, Object> queryAll(Map whereJson, Pageable page);
/**
* 优化查询
* @param whereJson
* @param page
* @return
*/
Map<String, Object> queryAll2(Map whereJson, Pageable page);
}

View File

@@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@Service
@RequiredArgsConstructor
@@ -128,4 +129,113 @@ public class PowderProductionQueryServiceImpl implements PowderProductionQuerySe
json.put("content",resultArr);
return json;
}
@Override
public Map<String, Object> queryAll2(Map whereJson, Pageable page) {
String pcsn = MapUtil.getStr(whereJson, "pcsn");
String material_code = MapUtil.getStr(whereJson, "material_code");
WQLObject formMstTab = WQLObject.getWQLObject("PDM_BI_Formula");
HashMap<String, String> map = new HashMap<>();
map.put("flag", "1");
map.put("begin_time", MapUtil.getStr(whereJson, "begin_time"));
map.put("end_time", MapUtil.getStr(whereJson, "end_time"));
if (ObjectUtil.isNotEmpty(pcsn)) map.put("pcsn", "%"+pcsn+"%");
if (ObjectUtil.isNotEmpty(material_code)) map.put("material_code", "%"+material_code+"%");
String classIds = classstandardService.getAllChildIdStr(MaterOptTypeEnum.YL_AND_FL_AND_RF.getClass_idStr());
JSONObject json = WQL.getWO("QP_POWDERPRODUCTION").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "work.create_time desc");
JSONArray contentArr = json.getJSONArray("content");
JSONArray resultArr = new JSONArray();
Set<String> cTHW = classstandardService.getAllChildIdSet(MaterOptTypeEnum.THW.getClass_idStr());
Set<String> cGF = classstandardService.getAllChildIdSet(MaterOptTypeEnum.GF.getClass_idStr());
Set<String> cTF = classstandardService.getAllChildIdSet(MaterOptTypeEnum.TF.getClass_idStr());
Set<String> cWF = classstandardService.getAllChildIdSet(MaterOptTypeEnum.WF.getClass_idStr());
Set<String> cOTHER = classstandardService.getAllChildIdSet(MaterOptTypeEnum.OTHER.getClass_idStr());
Set<String> cTJJ = classstandardService.getAllChildIdSet(MaterOptTypeEnum.TJJ.getClass_idStr());
Set<String> cHG = classstandardService.getAllChildIdSet(MaterOptTypeEnum.HG.getClass_idStr());
Set<String> cRF = classstandardService.getAllChildIdSet(MaterOptTypeEnum.RF.getClass_idStr());
for (int i = 0; i < contentArr.size(); i++) {
JSONObject jsonObject = contentArr.getJSONObject(i);
String workorder_id = jsonObject.getString("workorder_id");
JSONArray formMstArr = formMstTab.query("workorder_id = '" + workorder_id + "' and is_delete = '0'").getResultJSONArray(0);
String formula_id = "('";
if (ObjectUtil.isNotEmpty(formMstArr)) {
for (int n = 0; n < formMstArr.size(); n++) {
JSONObject jsonObject2 = formMstArr.getJSONObject(n);
String param = jsonObject2.getString("formula_id");
if (n==0){
formula_id = formula_id + param+"'";
}else {
formula_id = formula_id+",'"+param+"'";
}
}
formula_id = formula_id+")";
} else {
formula_id = "";
}
JSONObject resultJson = new JSONObject();
// 根据物料类型分组汇总重量
JSONArray dtlArr = WQL.getWO("QP_POWDERPRODUCTION").addParam("formula_id", formula_id).addParam("flag", "2").addParam("classIds", classIds).process().getResultJSONArray(0);
resultJson.put("create_time",jsonObject.getString("create_time"));
resultJson.put("workorder_code",jsonObject.getString("workorder_code"));
resultJson.put("material_code",jsonObject.getString("material_code"));
resultJson.put("pcsn",jsonObject.getString("pcsn"));
// 遍历明细判断是那种物料类型
String total = "0";
for (int j = 0; j < dtlArr.size(); j++) {
JSONObject jsonObject1 = dtlArr.getJSONObject(j);
String class_id = jsonObject1.getString("class_id");
boolean is_THW = cTHW.contains(class_id);
boolean is_GF = cGF.contains(class_id);
boolean is_TF = cTF.contains(class_id);
boolean is_WF = cWF.contains(class_id);
boolean is_OTHER = cOTHER.contains(class_id);
boolean is_TJJ = cTJJ.contains(class_id);
boolean is_HG = cHG.contains(class_id);
boolean is_RF = cRF.contains(class_id);
if (is_THW) resultJson.put("yl_thw", jsonObject1.get("formula_qty"));
if (is_GF) resultJson.put("yl_gf", jsonObject1.get("formula_qty"));
if (is_TF) resultJson.put("yl_tf", jsonObject1.get("formula_qty"));
if (is_WF) resultJson.put("yl_wf", jsonObject1.get("formula_qty"));
if (is_OTHER) resultJson.put("yl_other", jsonObject1.get("formula_qty"));
if (is_TJJ) resultJson.put("yl_yzj", jsonObject1.get("formula_qty"));
if (is_HG) resultJson.put("fl_cxj", jsonObject1.get("formula_qty"));
if (is_RF) resultJson.put("cp_rf", jsonObject1.get("formula_qty"));
// 合计
total = String.valueOf(NumberUtil.add(total, jsonObject1.getString("formula_qty")));
}
resultJson.put("total",total);
// 成品入库日期
JSONObject jsonLine = WQLObject.getWQLObject("PDM_BI_ProcedureOffline").query("material_id ='" + jsonObject.getString("material_id") + "' and pcsn ='" + jsonObject.getString("pcsn") + "' and status ='1'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonLine)) resultJson.put("in_dateTime", jsonLine.getString("create_time"));
// 成品产出量
JSONArray jsonArr = WQLObject.getWQLObject("PDM_BI_ProcedureOffline").query("material_id ='" + jsonObject.getString("material_id") + "' and pcsn ='" + jsonObject.getString("pcsn") + "' and status ='1'").getResultJSONArray(0);
String qty = "0";
if (ObjectUtil.isNotEmpty(jsonArr)) {
for (int k = 0; k < jsonArr.size(); k++) {
JSONObject jsonObject1 = jsonArr.getJSONObject(k);
qty = String.valueOf(NumberUtil.add(qty,jsonObject1.getString("qty")));
}
}
resultJson.put("out_weight", NumberUtil.round(qty, 3));
// 产出率
JSONObject jsonFor = WQL.getWO("QP_POWDERPRODUCTION").addParam("flag", "3").addParam("workorder_id", workorder_id).process().uniqueResult(0);
String confirm_qty = jsonFor.getString("confirm_qty");
if (ObjectUtil.isNotEmpty(confirm_qty)) {
BigDecimal yield = NumberUtil.div(qty, confirm_qty);
resultJson.put("yield", NumberUtil.round(yield, 3));
}
resultArr.add(resultJson);
}
json.put("content",resultArr);
return json;
}
}