|
@@ -391,38 +391,12 @@ public class MesProductPlanService extends CrudService<MesProductPlanDao, MesPro
|
|
|
if(plans == null || plans.size() < 2){
|
|
if(plans == null || plans.size() < 2){
|
|
|
return plans == null ? new ArrayList<>() : plans;
|
|
return plans == null ? new ArrayList<>() : plans;
|
|
|
}
|
|
}
|
|
|
- List<String> ids = new ArrayList<>();
|
|
|
|
|
- for(MesProductPlan plan : plans){
|
|
|
|
|
- if(StringUtils.isNotBlank(plan.getId())){
|
|
|
|
|
- ids.add(plan.getId());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- Map<String, Integer> producedMap = new HashMap<>();
|
|
|
|
|
- Map<String, Long> finishMap = new HashMap<>();
|
|
|
|
|
- if(!ids.isEmpty()){
|
|
|
|
|
- List<Map<String, Object>> rows = dao.countProducedByPlanIds(ids);
|
|
|
|
|
- if(rows != null){
|
|
|
|
|
- for(Map<String, Object> row : rows){
|
|
|
|
|
- Object pid = row.get("plan_id") != null ? row.get("plan_id") : row.get("planId");
|
|
|
|
|
- if(pid == null){
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- String key = String.valueOf(pid);
|
|
|
|
|
- Object cnt = row.get("produced") != null ? row.get("produced") : row.get("PRODUCED");
|
|
|
|
|
- if(cnt != null){
|
|
|
|
|
- producedMap.put(key, Integer.parseInt(String.valueOf(cnt)));
|
|
|
|
|
- }
|
|
|
|
|
- Object fin = row.get("finish_date") != null ? row.get("finish_date") : row.get("FINISH_DATE");
|
|
|
|
|
- if(fin instanceof java.util.Date){
|
|
|
|
|
- finishMap.put(key, ((java.util.Date) fin).getTime());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Map<String, PlanStat> statMap = statByPlans(plans);
|
|
|
List<MesProductPlan> todo = new ArrayList<>();
|
|
List<MesProductPlan> todo = new ArrayList<>();
|
|
|
List<MesProductPlan> done = new ArrayList<>();
|
|
List<MesProductPlan> done = new ArrayList<>();
|
|
|
for(MesProductPlan plan : plans){
|
|
for(MesProductPlan plan : plans){
|
|
|
- if(isPlanFinished(plan, producedMap.get(plan.getId()))){
|
|
|
|
|
|
|
+ PlanStat stat = statMap.get(plan.getId());
|
|
|
|
|
+ if(isPlanFinished(plan, stat == null ? null : stat.offline)){
|
|
|
done.add(plan);
|
|
done.add(plan);
|
|
|
}else{
|
|
}else{
|
|
|
todo.add(plan);
|
|
todo.add(plan);
|
|
@@ -430,9 +404,11 @@ public class MesProductPlanService extends CrudService<MesProductPlanDao, MesPro
|
|
|
}
|
|
}
|
|
|
// 已完成区:最后完成的排前面,最早完成的沉到最底
|
|
// 已完成区:最后完成的排前面,最早完成的沉到最底
|
|
|
done.sort((a, b) -> {
|
|
done.sort((a, b) -> {
|
|
|
- Long ta = finishMap.get(a.getId());
|
|
|
|
|
- Long tb = finishMap.get(b.getId());
|
|
|
|
|
- return Long.compare(tb == null ? 0L : tb, ta == null ? 0L : ta);
|
|
|
|
|
|
|
+ PlanStat sa = statMap.get(a.getId());
|
|
|
|
|
+ PlanStat sb = statMap.get(b.getId());
|
|
|
|
|
+ long ta = sa == null || sa.finish == null ? 0L : sa.finish;
|
|
|
|
|
+ long tb = sb == null || sb.finish == null ? 0L : sb.finish;
|
|
|
|
|
+ return Long.compare(tb, ta);
|
|
|
});
|
|
});
|
|
|
List<MesProductPlan> result = new ArrayList<>(plans.size());
|
|
List<MesProductPlan> result = new ArrayList<>(plans.size());
|
|
|
result.addAll(todo);
|
|
result.addAll(todo);
|
|
@@ -441,13 +417,13 @@ public class MesProductPlanService extends CrudService<MesProductPlanDao, MesPro
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 计划是否已完工:计划量大于 0 且已生产数不少于计划量。
|
|
|
|
|
|
|
+ * 计划是否已完工:计划量大于 0 且已下线数不少于计划量(以走完最后一道工位为准,不看投料数)。
|
|
|
*/
|
|
*/
|
|
|
- private boolean isPlanFinished(MesProductPlan plan, Integer produced){
|
|
|
|
|
|
|
+ private boolean isPlanFinished(MesProductPlan plan, Integer offline){
|
|
|
if(plan == null || plan.getNums() == null || plan.getNums() <= 0){
|
|
if(plan == null || plan.getNums() == null || plan.getNums() <= 0){
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- return produced != null && produced >= plan.getNums();
|
|
|
|
|
|
|
+ return offline != null && offline >= plan.getNums();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -778,13 +754,17 @@ public class MesProductPlanService extends CrudService<MesProductPlanDao, MesPro
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 批量统计多个计划已绑定的工件数,口径与 countProduced 一致。
|
|
|
|
|
|
|
+ * 批量统计多个计划的生产情况,口径与 countProduced 一致。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 每行包含:已绑定工件数(produced)、已下线工件数(offline,下线合格/返修中,不含报废)、
|
|
|
|
|
+ * 已包装入库工件数(stored,mes_product_storage_record 中 bind=1 的记录)、
|
|
|
|
|
+ * 最后一件工件的生成时间(finish,仅用于已完成区排序)。
|
|
|
*
|
|
*
|
|
|
* @param plans 计划列表
|
|
* @param plans 计划列表
|
|
|
- * @return 计划id -> 已生产数;没有工件的计划不在返回值里
|
|
|
|
|
|
|
+ * @return 计划id -> 统计对象;没有工件的计划不在返回值里
|
|
|
*/
|
|
*/
|
|
|
- private Map<String, Integer> countProducedByPlans(List<MesProductPlan> plans){
|
|
|
|
|
- Map<String, Integer> result = new HashMap<>();
|
|
|
|
|
|
|
+ private Map<String, PlanStat> statByPlans(List<MesProductPlan> plans){
|
|
|
|
|
+ Map<String, PlanStat> result = new HashMap<>();
|
|
|
if(plans == null || plans.isEmpty()){
|
|
if(plans == null || plans.isEmpty()){
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -803,15 +783,40 @@ public class MesProductPlanService extends CrudService<MesProductPlanDao, MesPro
|
|
|
}
|
|
}
|
|
|
for(Map<String, Object> row : rows){
|
|
for(Map<String, Object> row : rows){
|
|
|
Object pid = row.get("plan_id") != null ? row.get("plan_id") : row.get("planId");
|
|
Object pid = row.get("plan_id") != null ? row.get("plan_id") : row.get("planId");
|
|
|
- Object cnt = row.get("produced") != null ? row.get("produced") : row.get("PRODUCED");
|
|
|
|
|
- if(pid == null || cnt == null){
|
|
|
|
|
|
|
+ if(pid == null){
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- result.put(String.valueOf(pid), Integer.parseInt(String.valueOf(cnt)));
|
|
|
|
|
|
|
+ PlanStat stat = new PlanStat();
|
|
|
|
|
+ stat.produced = toInt(row.get("produced") != null ? row.get("produced") : row.get("PRODUCED"));
|
|
|
|
|
+ stat.offline = toInt(row.get("offline_nums") != null ? row.get("offline_nums") : row.get("OFFLINE_NUMS"));
|
|
|
|
|
+ stat.stored = toInt(row.get("stored_nums") != null ? row.get("stored_nums") : row.get("STORED_NUMS"));
|
|
|
|
|
+ Object fin = row.get("finish_date") != null ? row.get("finish_date") : row.get("FINISH_DATE");
|
|
|
|
|
+ if(fin instanceof java.util.Date){
|
|
|
|
|
+ stat.finish = ((java.util.Date) fin).getTime();
|
|
|
|
|
+ }
|
|
|
|
|
+ result.put(String.valueOf(pid), stat);
|
|
|
}
|
|
}
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private int toInt(Object value){
|
|
|
|
|
+ return value == null ? 0 : Integer.parseInt(String.valueOf(value));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 单个计划的生产统计,供排产页展示。
|
|
|
|
|
+ */
|
|
|
|
|
+ private static class PlanStat {
|
|
|
|
|
+ /** OP035 系列工位扫过码的工件数(首道工序实际投产件数) */
|
|
|
|
|
+ private int produced;
|
|
|
|
|
+ /** 已下线工件数(下线合格或返修中,不含报废) */
|
|
|
|
|
+ private int offline;
|
|
|
|
|
+ /** 已包装入库工件数 */
|
|
|
|
|
+ private int stored;
|
|
|
|
|
+ /** 最后一件工件的生成时间(毫秒),无工件时为空 */
|
|
|
|
|
+ private Long finish;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 计划是否维护了完整的时间段。
|
|
* 计划是否维护了完整的时间段。
|
|
|
*/
|
|
*/
|
|
@@ -881,11 +886,11 @@ public class MesProductPlanService extends CrudService<MesProductPlanDao, MesPro
|
|
|
*/
|
|
*/
|
|
|
public Map<String, Object> findScheduleData(){
|
|
public Map<String, Object> findScheduleData(){
|
|
|
List<MesProductPlan> plans = getScheduledQueuePlans();
|
|
List<MesProductPlan> plans = getScheduledQueuePlans();
|
|
|
- Map<String, Integer> producedMap = countProducedByPlans(plans);
|
|
|
|
|
|
|
+ Map<String, PlanStat> statMap = statByPlans(plans);
|
|
|
List<Map<String, Object>> rows = new ArrayList<>();
|
|
List<Map<String, Object>> rows = new ArrayList<>();
|
|
|
for(int i = 0; i < plans.size(); i++){
|
|
for(int i = 0; i < plans.size(); i++){
|
|
|
MesProductPlan plan = plans.get(i);
|
|
MesProductPlan plan = plans.get(i);
|
|
|
- rows.add(toSchedulePlan(plan, i + 1, producedMap.get(plan.getId())));
|
|
|
|
|
|
|
+ rows.add(toSchedulePlan(plan, i + 1, statMap.get(plan.getId())));
|
|
|
}
|
|
}
|
|
|
Map<String, Object> data = new LinkedHashMap<>();
|
|
Map<String, Object> data = new LinkedHashMap<>();
|
|
|
data.put("scheduled", rows);
|
|
data.put("scheduled", rows);
|
|
@@ -920,9 +925,9 @@ public class MesProductPlanService extends CrudService<MesProductPlanDao, MesPro
|
|
|
List<MesProductPlan> plans = findList(query);
|
|
List<MesProductPlan> plans = findList(query);
|
|
|
List<Map<String, Object>> rows = new ArrayList<>();
|
|
List<Map<String, Object>> rows = new ArrayList<>();
|
|
|
if(plans != null){
|
|
if(plans != null){
|
|
|
- Map<String, Integer> producedMap = countProducedByPlans(plans);
|
|
|
|
|
|
|
+ Map<String, PlanStat> statMap = statByPlans(plans);
|
|
|
for(MesProductPlan plan : plans){
|
|
for(MesProductPlan plan : plans){
|
|
|
- rows.add(toSchedulePlan(plan, 0, producedMap.get(plan.getId())));
|
|
|
|
|
|
|
+ rows.add(toSchedulePlan(plan, 0, statMap.get(plan.getId())));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return rows;
|
|
return rows;
|
|
@@ -987,9 +992,11 @@ public class MesProductPlanService extends CrudService<MesProductPlanDao, MesPro
|
|
|
return changed;
|
|
return changed;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Map<String, Object> toSchedulePlan(MesProductPlan plan, int seq, Integer produced){
|
|
|
|
|
|
|
+ private Map<String, Object> toSchedulePlan(MesProductPlan plan, int seq, PlanStat stat){
|
|
|
int planNums = plan.getNums() == null ? 0 : plan.getNums();
|
|
int planNums = plan.getNums() == null ? 0 : plan.getNums();
|
|
|
- int doneNums = produced == null ? 0 : produced;
|
|
|
|
|
|
|
+ int doneNums = stat == null ? 0 : stat.produced;
|
|
|
|
|
+ int offlineNums = stat == null ? 0 : stat.offline;
|
|
|
|
|
+ int storedNums = stat == null ? 0 : stat.stored;
|
|
|
Map<String, Object> row = new LinkedHashMap<>();
|
|
Map<String, Object> row = new LinkedHashMap<>();
|
|
|
row.put("id", plan.getId());
|
|
row.put("id", plan.getId());
|
|
|
row.put("orderSn", plan.getOrderSn());
|
|
row.put("orderSn", plan.getOrderSn());
|
|
@@ -999,6 +1006,10 @@ public class MesProductPlanService extends CrudService<MesProductPlanDao, MesPro
|
|
|
row.put("nums", plan.getNums());
|
|
row.put("nums", plan.getNums());
|
|
|
row.put("produced", doneNums);
|
|
row.put("produced", doneNums);
|
|
|
row.put("percent", planNums <= 0 ? 0 : Math.min(100, doneNums * 100 / planNums));
|
|
row.put("percent", planNums <= 0 ? 0 : Math.min(100, doneNums * 100 / planNums));
|
|
|
|
|
+ // 生产完成率:已下线件数 / 计划数量(下线合格或返修中,不含报废)
|
|
|
|
|
+ row.put("offline", offlineNums);
|
|
|
|
|
+ row.put("stored", storedNums);
|
|
|
|
|
+ row.put("rate", planNums <= 0 ? 0 : offlineNums * 100 / planNums);
|
|
|
row.put("priority", plan.getPriority());
|
|
row.put("priority", plan.getPriority());
|
|
|
row.put("seq", seq);
|
|
row.put("seq", seq);
|
|
|
row.put("createDate", plan.getCreateDate() == null ? ""
|
|
row.put("createDate", plan.getCreateDate() == null ? ""
|