zhanghe 5 месяцев назад
Родитель
Сommit
d250328871

+ 24 - 1
src/main/java/com/jeesite/modules/mes/web/MesPlanController.java

@@ -1,6 +1,8 @@
 package com.jeesite.modules.mes.web;
 
 import java.util.List;
+import java.util.HashMap;
+import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -155,6 +157,27 @@ public class MesPlanController extends BaseController {
 		}
 		return renderResult(Global.TRUE, text("保存班次生产计划成功!"));
 	}
+
+	/**
+	 * 获取最新生产计划数量
+	 */
+	@RequestMapping(value = "latestPlanNums")
+	@ResponseBody
+	public Map<String, Object> latestPlanNums() {
+		Map<String, Object> result = new HashMap<>();
+		Map<String, Object> data = new HashMap<>();
+		MesPlan query = new MesPlan();
+		query.setStatus(MesPlan.STATUS_NORMAL);
+		List<MesPlan> list = mesPlanService.findList(query);
+		MesPlan latestPlan = ObjectUtils.isEmpty(list) ? null : list.get(0);
+		Integer nums = latestPlan == null || latestPlan.getNums() == null ? 0 : latestPlan.getNums();
+		data.put("nums", nums);
+		data.put("planId", latestPlan == null ? "" : latestPlan.getId());
+		data.put("day", latestPlan == null ? "" : latestPlan.getDay());
+		result.put("result", "true");
+		result.put("data", data);
+		return result;
+	}
 	
 	/**
 	 * 停用数据
@@ -203,4 +226,4 @@ public class MesPlanController extends BaseController {
 		return renderResult(Global.TRUE, text("删除班次生产计划成功!"));
 	}
 	
-}
+}

+ 57 - 8
src/main/resources/views/modules/mes/mesScreen3.html

@@ -1550,6 +1550,53 @@
 		});
 	}
 
+	function calcRatePercent(actual, plan) {
+		actual = Number(actual) || 0;
+		plan = Number(plan) || 0;
+		if (plan <= 0) {
+			return 0;
+		}
+		return Math.round(actual * 100 / plan);
+	}
+
+	function syncAchieveRateWithPlan() {
+		mockData.cards = mockData.cards || {};
+		mockData.achieveRate = mockData.achieveRate || { labels: [], actual: [] };
+		var planNums = Number(mockData.cards.planProduction) || 0;
+		var actualProduction = Number(mockData.cards.actualProduction) || 0;
+		var labels = mockData.achieveRate.labels || [];
+		var actualSeries = mockData.achieveRate.actual || [];
+		var targetSeries = [];
+		for (var i = 0; i < labels.length; i++) {
+			targetSeries.push(planNums);
+		}
+		var maxVal = Math.max.apply(null, targetSeries.concat(actualSeries).concat([10]));
+		mockData.achieveRate.target = targetSeries;
+		mockData.achieveRate.max = maxVal <= 0 ? 10 : Math.ceil(maxVal * 1.1);
+		mockData.achieveRate.min = 0;
+		mockData.todayRate = calcRatePercent(actualProduction, planNums);
+		mockData.monthRate = calcRatePercent(actualProduction, planNums);
+		renderTextData();
+		drawAllCharts();
+	}
+
+	function updateLatestPlanProductionByApi() {
+		$.ajax({
+			url: '${ctx}/mes/mesPlan/latestPlanNums',
+			type: 'POST',
+			dataType: 'json',
+			success: function(resp) {
+				if (!resp || resp.result !== 'true' || !resp.data) {
+					return;
+				}
+				var planNums = Number(resp.data.nums) || 0;
+				mockData.cards = mockData.cards || {};
+				mockData.cards.planProduction = planNums;
+				syncAchieveRateWithPlan();
+			}
+		});
+	}
+
 	function isOpr240Family(oprno) {
 		var op = (oprno || '').replace(/\s/g, '').toUpperCase();
 		if (op.length < 5 || op.indexOf('OP240') !== 0) return false;
@@ -1594,6 +1641,13 @@
 		var maxPages = 200;
 		var pageNo = 1;
 		var totalOk = 0;
+
+		function applyActualProductionCount(n) {
+			mockData.cards = mockData.cards || {};
+			mockData.cards.actualProduction = n;
+			syncAchieveRateWithPlan();
+		}
+
 		function fetchPage() {
 			$.ajax({
 				url: '${ctx}/mes/mesProductRecord/listData',
@@ -1620,17 +1674,11 @@
 						pageNo++;
 						fetchPage();
 					} else {
-						mockData.cards = mockData.cards || {};
-						mockData.cards.actualProduction = totalOk;
-						var target = document.getElementById('actualProduction');
-						if (target) target.textContent = totalOk;
+						applyActualProductionCount(totalOk);
 					}
 				},
 				error: function() {
-					mockData.cards = mockData.cards || {};
-					mockData.cards.actualProduction = totalOk;
-					var target = document.getElementById('actualProduction');
-					if (target) target.textContent = totalOk;
+					applyActualProductionCount(totalOk);
 				}
 			});
 		}
@@ -1733,6 +1781,7 @@
 		renderTextData();
 		updateProductionPeopleByApi();
 		updateDeviceCountByApi();
+		updateLatestPlanProductionByApi();
 		updateActualProductionByApi();
 		updateProductTrend7DaysByApi();
 		updateDeviceAlarmAlertsByApi();

+ 58 - 3
src/main/resources/views/modules/mes/mesScreen4.html

@@ -843,6 +843,43 @@
 		if (el) el.innerHTML = html;
 	}
 
+	function applyLatestPlanNumsToTable(planNums) {
+		var list = mockData.opTable || [];
+		for (var i = 0; i < list.length; i++) {
+			list[i].plan = planNums;
+		}
+		renderTable();
+	}
+
+	function calcRatePercent(actual, plan) {
+		actual = Number(actual) || 0;
+		plan = Number(plan) || 0;
+		if (plan <= 0) {
+			return 0;
+		}
+		return Math.round(actual * 100 / plan);
+	}
+
+	function syncAchieveRateWithPlan() {
+		mockData.cards = mockData.cards || {};
+		mockData.achieveRate = mockData.achieveRate || { labels: [], actual: [] };
+		var planNums = Number(mockData.cards.planProduction) || 0;
+		var actualProduction = Number(mockData.cards.actualProduction) || 0;
+		var labels = mockData.achieveRate.labels || [];
+		var actualSeries = mockData.achieveRate.actual || [];
+		var targetSeries = [];
+		for (var i = 0; i < labels.length; i++) {
+			targetSeries.push(planNums);
+		}
+		var maxVal = Math.max.apply(null, targetSeries.concat(actualSeries).concat([10]));
+		mockData.achieveRate.target = targetSeries;
+		mockData.achieveRate.max = maxVal <= 0 ? 10 : Math.ceil(maxVal * 1.1);
+		mockData.achieveRate.min = 0;
+		mockData.rate = calcRatePercent(actualProduction, planNums);
+		renderCards();
+		drawAllCharts();
+	}
+
 	function updateLineProcessTableByApi() {
 		$.ajax({
 			url: '${ctx}/mes/mesLineProcess/listData',
@@ -863,7 +900,7 @@
 					out.push({
 						code: p.oprno || '',
 						name: p.title || '',
-						plan: 0,
+						plan: (mockData.cards && mockData.cards.planProduction) || 0,
 						hour: 0,
 						real: 0,
 						shift: 0
@@ -876,6 +913,24 @@
 			}
 		});
 	}
+
+	function updateLatestPlanProductionByApi() {
+		$.ajax({
+			url: '${ctx}/mes/mesPlan/latestPlanNums',
+			type: 'POST',
+			dataType: 'json',
+			success: function(resp) {
+				if (!resp || resp.result !== 'true' || !resp.data) {
+					return;
+				}
+				var planNums = Number(resp.data.nums) || 0;
+				mockData.cards = mockData.cards || {};
+				mockData.cards.planProduction = planNums;
+				applyLatestPlanNumsToTable(planNums);
+				syncAchieveRateWithPlan();
+			}
+		});
+	}
 	function renderCards() {
 		var c = mockData.cards || {};
 		var m = {
@@ -1006,8 +1061,7 @@
 	function applyActualProductionCount(n) {
 		mockData.cards = mockData.cards || {};
 		mockData.cards.actualProduction = n;
-		var target = document.getElementById('actualProduction');
-		if (target) target.textContent = n;
+		syncAchieveRateWithPlan();
 	}
 
 	function getCalendarDayUpdateDateRange() {
@@ -1104,6 +1158,7 @@
 		renderAlerts();
 		renderTable();
 		renderCards();
+		updateLatestPlanProductionByApi();
 		updateLineProcessTableByApi();
 		updateProductionPeopleByApi();
 		updateDeviceCountByApi();

+ 58 - 3
src/main/resources/views/modules/mes/mesScreen5.html

@@ -929,6 +929,43 @@
 		}
 	}
 
+	function applyLatestPlanNumsToTable(planNums) {
+		var list = mockData.opTable || [];
+		for (var i = 0; i < list.length; i++) {
+			list[i].plan = planNums;
+		}
+		renderTable();
+	}
+
+	function calcRatePercent(actual, plan) {
+		actual = Number(actual) || 0;
+		plan = Number(plan) || 0;
+		if (plan <= 0) {
+			return 0;
+		}
+		return Math.round(actual * 100 / plan);
+	}
+
+	function syncAchieveRateWithPlan() {
+		mockData.cards = mockData.cards || {};
+		mockData.achieveRate = mockData.achieveRate || { labels: [], actual: [] };
+		var planNums = Number(mockData.cards.planProduction) || 0;
+		var actualProduction = Number(mockData.cards.actualProduction) || 0;
+		var labels = mockData.achieveRate.labels || [];
+		var actualSeries = mockData.achieveRate.actual || [];
+		var targetSeries = [];
+		for (var i = 0; i < labels.length; i++) {
+			targetSeries.push(planNums);
+		}
+		var maxVal = Math.max.apply(null, targetSeries.concat(actualSeries).concat([10]));
+		mockData.achieveRate.target = targetSeries;
+		mockData.achieveRate.max = maxVal <= 0 ? 10 : Math.ceil(maxVal * 1.1);
+		mockData.achieveRate.min = 0;
+		mockData.rate = calcRatePercent(actualProduction, planNums);
+		renderCards();
+		drawAllCharts();
+	}
+
 	function updateLineProcessTableByApi() {
 		$.ajax({
 			url: '${ctx}/mes/mesLineProcess/listData',
@@ -949,7 +986,7 @@
 					out.push({
 						code: p.oprno || '',
 						name: p.title || '',
-						plan: 0,
+						plan: (mockData.cards && mockData.cards.planProduction) || 0,
 						hour: 0,
 						real: 0,
 						shift: 0
@@ -964,6 +1001,24 @@
 			}
 		});
 	}
+
+	function updateLatestPlanProductionByApi() {
+		$.ajax({
+			url: '${ctx}/mes/mesPlan/latestPlanNums',
+			type: 'POST',
+			dataType: 'json',
+			success: function(resp) {
+				if (!resp || resp.result !== 'true' || !resp.data) {
+					return;
+				}
+				var planNums = Number(resp.data.nums) || 0;
+				mockData.cards = mockData.cards || {};
+				mockData.cards.planProduction = planNums;
+				applyLatestPlanNumsToTable(planNums);
+				syncAchieveRateWithPlan();
+			}
+		});
+	}
 	function renderCards() {
 		var c = mockData.cards || {};
 		var m = {
@@ -1094,8 +1149,7 @@
 	function applyActualProductionCount(n) {
 		mockData.cards = mockData.cards || {};
 		mockData.cards.actualProduction = n;
-		var target = document.getElementById('actualProduction');
-		if (target) target.textContent = n;
+		syncAchieveRateWithPlan();
 	}
 
 	function getCalendarDayUpdateDateRange() {
@@ -1194,6 +1248,7 @@
 		renderTable();
 		startOpTablePageRotate();
 		renderCards();
+		updateLatestPlanProductionByApi();
 		updateLineProcessTableByApi();
 		updateProductionPeopleByApi();
 		updateDeviceCountByApi();

+ 58 - 3
src/main/resources/views/modules/mes/mesScreen6.html

@@ -929,6 +929,43 @@
 		}
 	}
 
+	function applyLatestPlanNumsToTable(planNums) {
+		var list = mockData.opTable || [];
+		for (var i = 0; i < list.length; i++) {
+			list[i].plan = planNums;
+		}
+		renderTable();
+	}
+
+	function calcRatePercent(actual, plan) {
+		actual = Number(actual) || 0;
+		plan = Number(plan) || 0;
+		if (plan <= 0) {
+			return 0;
+		}
+		return Math.round(actual * 100 / plan);
+	}
+
+	function syncAchieveRateWithPlan() {
+		mockData.cards = mockData.cards || {};
+		mockData.achieveRate = mockData.achieveRate || { labels: [], actual: [] };
+		var planNums = Number(mockData.cards.planProduction) || 0;
+		var actualProduction = Number(mockData.cards.actualProduction) || 0;
+		var labels = mockData.achieveRate.labels || [];
+		var actualSeries = mockData.achieveRate.actual || [];
+		var targetSeries = [];
+		for (var i = 0; i < labels.length; i++) {
+			targetSeries.push(planNums);
+		}
+		var maxVal = Math.max.apply(null, targetSeries.concat(actualSeries).concat([10]));
+		mockData.achieveRate.target = targetSeries;
+		mockData.achieveRate.max = maxVal <= 0 ? 10 : Math.ceil(maxVal * 1.1);
+		mockData.achieveRate.min = 0;
+		mockData.rate = calcRatePercent(actualProduction, planNums);
+		renderCards();
+		drawAllCharts();
+	}
+
 	function updateLineProcessTableByApi() {
 		$.ajax({
 			url: '${ctx}/mes/mesLineProcess/listData',
@@ -949,7 +986,7 @@
 					out.push({
 						code: p.oprno || '',
 						name: p.title || '',
-						plan: 0,
+						plan: (mockData.cards && mockData.cards.planProduction) || 0,
 						hour: 0,
 						real: 0,
 						shift: 0
@@ -964,6 +1001,24 @@
 			}
 		});
 	}
+
+	function updateLatestPlanProductionByApi() {
+		$.ajax({
+			url: '${ctx}/mes/mesPlan/latestPlanNums',
+			type: 'POST',
+			dataType: 'json',
+			success: function(resp) {
+				if (!resp || resp.result !== 'true' || !resp.data) {
+					return;
+				}
+				var planNums = Number(resp.data.nums) || 0;
+				mockData.cards = mockData.cards || {};
+				mockData.cards.planProduction = planNums;
+				applyLatestPlanNumsToTable(planNums);
+				syncAchieveRateWithPlan();
+			}
+		});
+	}
 	function renderCards() {
 		var c = mockData.cards || {};
 		var m = {
@@ -1094,8 +1149,7 @@
 	function applyActualProductionCount(n) {
 		mockData.cards = mockData.cards || {};
 		mockData.cards.actualProduction = n;
-		var target = document.getElementById('actualProduction');
-		if (target) target.textContent = n;
+		syncAchieveRateWithPlan();
 	}
 
 	function getCalendarDayUpdateDateRange() {
@@ -1194,6 +1248,7 @@
 		renderTable();
 		startOpTablePageRotate();
 		renderCards();
+		updateLatestPlanProductionByApi();
 		updateLineProcessTableByApi();
 		updateProductionPeopleByApi();
 		updateDeviceCountByApi();