|
@@ -0,0 +1,161 @@
|
|
|
|
|
+package com.jeesite.modules.mes.web;
|
|
|
|
|
+
|
|
|
|
|
+import java.text.ParseException;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.Calendar;
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+
|
|
|
|
|
+import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
|
+import org.springframework.ui.Model;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
+
|
|
|
|
|
+import com.jeesite.common.entity.Page;
|
|
|
|
|
+import com.jeesite.common.lang.StringUtils;
|
|
|
|
|
+import com.jeesite.common.web.BaseController;
|
|
|
|
|
+import com.jeesite.modules.mes.entity.MesLine;
|
|
|
|
|
+import com.jeesite.modules.mes.entity.MesLineCapacity;
|
|
|
|
|
+import com.jeesite.modules.mes.req.MesSearchDateReq;
|
|
|
|
|
+import com.jeesite.modules.mes.service.MesLineCapacityService;
|
|
|
|
|
+import com.jeesite.modules.mes.service.MesLineService;
|
|
|
|
|
+import com.jeesite.modules.mes.util.CommonUitl;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 产线产能管理Controller
|
|
|
|
|
+ * @author mes
|
|
|
|
|
+ * @version 2026-10-30
|
|
|
|
|
+ */
|
|
|
|
|
+@Controller
|
|
|
|
|
+@RequestMapping(value = "${adminPath}/mes/mesLineCapacity")
|
|
|
|
|
+public class MesLineCapacityController extends BaseController {
|
|
|
|
|
+
|
|
|
|
|
+ private static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
|
|
|
|
+ private static final String MINUTE_PATTERN = "yyyy-MM-dd HH:mm";
|
|
|
|
|
+ private static final String DATE_PATTERN = "yyyy-MM-dd";
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MesLineCapacityService mesLineCapacityService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MesLineService mesLineService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询列表(默认统计最近 7 天,与生产记录管理等页面的默认查询区间一致)
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesLineCapacity:view")
|
|
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
|
|
+ public String list(MesLineCapacity mesLineCapacity, Model model) {
|
|
|
|
|
+ if (StringUtils.isBlank(mesLineCapacity.getStartDate()) && StringUtils.isBlank(mesLineCapacity.getEndDate())) {
|
|
|
|
|
+ Date[] defaultRange = getDefaultDateRange();
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(MINUTE_PATTERN);
|
|
|
|
|
+ mesLineCapacity.setStartDate(sdf.format(defaultRange[0]));
|
|
|
|
|
+ mesLineCapacity.setEndDate(sdf.format(defaultRange[1]));
|
|
|
|
|
+ }
|
|
|
|
|
+ model.addAttribute("mesLineCapacity", mesLineCapacity);
|
|
|
|
|
+ model.addAttribute("lineList", mesLineService.findList(new MesLine()));
|
|
|
|
|
+ return "modules/mes/mesLineCapacityList";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询列表数据
|
|
|
|
|
+ */
|
|
|
|
|
+ @RequiresPermissions("mes:mesLineCapacity:view")
|
|
|
|
|
+ @RequestMapping(value = "listData")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public Page<Map<String, Object>> listData(MesLineCapacity mesLineCapacity, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ Page<Map<String, Object>> page = new Page<>(request, response);
|
|
|
|
|
+
|
|
|
|
|
+ Date startTime = parseDate(mesLineCapacity.getStartDate(), false);
|
|
|
|
|
+ Date endTime = parseDate(mesLineCapacity.getEndDate(), true);
|
|
|
|
|
+ if (startTime == null && endTime == null) {
|
|
|
|
|
+ Date[] defaultRange = getDefaultDateRange();
|
|
|
|
|
+ startTime = defaultRange[0];
|
|
|
|
|
+ endTime = defaultRange[1];
|
|
|
|
|
+ } else if (startTime == null) {
|
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
|
+ calendar.setTime(endTime);
|
|
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
|
|
+ startTime = calendar.getTime();
|
|
|
|
|
+ } else if (endTime == null) {
|
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
|
+ calendar.setTime(startTime);
|
|
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
|
+ endTime = calendar.getTime();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!endTime.after(startTime)) {
|
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
|
+ calendar.setTime(startTime);
|
|
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
|
+ endTime = calendar.getTime();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int pageNo = page.getPageNo() < 1 ? 1 : page.getPageNo();
|
|
|
|
|
+ int pageSize = page.getPageSize() < 1 ? 20 : page.getPageSize();
|
|
|
|
|
+ int offset = (pageNo - 1) * pageSize;
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> list = mesLineCapacityService.findCapacityList(
|
|
|
|
|
+ StringUtils.trimToEmpty(mesLineCapacity.getLineId()),
|
|
|
|
|
+ StringUtils.trimToEmpty(mesLineCapacity.getLineSn()),
|
|
|
|
|
+ StringUtils.trimToEmpty(mesLineCapacity.getOprno()),
|
|
|
|
|
+ StringUtils.trimToEmpty(mesLineCapacity.getTitle()),
|
|
|
|
|
+ startTime, endTime, offset, pageSize);
|
|
|
|
|
+ long count = mesLineCapacityService.findCapacityCount(
|
|
|
|
|
+ StringUtils.trimToEmpty(mesLineCapacity.getLineId()),
|
|
|
|
|
+ StringUtils.trimToEmpty(mesLineCapacity.getLineSn()),
|
|
|
|
|
+ StringUtils.trimToEmpty(mesLineCapacity.getOprno()),
|
|
|
|
|
+ StringUtils.trimToEmpty(mesLineCapacity.getTitle()));
|
|
|
|
|
+
|
|
|
|
|
+ page.setCount((int) count);
|
|
|
|
|
+ page.setList(list);
|
|
|
|
|
+ return page;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 默认统计区间:最近 N 天(N 由配置 mes.search.days 控制,默认 7)
|
|
|
|
|
+ * 与生产记录管理、探伤记录等页面的默认查询区间保持一致
|
|
|
|
|
+ */
|
|
|
|
|
+ private Date[] getDefaultDateRange() {
|
|
|
|
|
+ MesSearchDateReq dateMap = CommonUitl.getSearchDate();
|
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
|
+ calendar.setTime(dateMap.getEndtDate());
|
|
|
|
|
+ calendar.set(Calendar.SECOND, 59);
|
|
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
|
+ return new Date[] { dateMap.getStartDate(), calendar.getTime() };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解析查询时间,支持 yyyy-MM-dd HH:mm:ss、yyyy-MM-dd HH:mm、yyyy-MM-dd
|
|
|
|
|
+ */
|
|
|
|
|
+ private Date parseDate(String value, boolean isEnd) {
|
|
|
|
|
+ if (StringUtils.isBlank(value)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ String text = value.trim();
|
|
|
|
|
+ String[] patterns = new String[] {DATETIME_PATTERN, MINUTE_PATTERN, DATE_PATTERN};
|
|
|
|
|
+ for (String pattern : patterns) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
|
|
|
|
+ sdf.setLenient(false);
|
|
|
|
|
+ Date date = sdf.parse(text);
|
|
|
|
|
+ if (isEnd && DATE_PATTERN.equals(pattern)) {
|
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
|
+ calendar.setTime(date);
|
|
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
|
+ return calendar.getTime();
|
|
|
|
|
+ }
|
|
|
|
|
+ return date;
|
|
|
|
|
+ } catch (ParseException e) {
|
|
|
|
|
+ // 尝试下一种格式
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|