|
@@ -0,0 +1,300 @@
|
|
|
|
|
+package com.jeesite.modules.mes.web;
|
|
|
|
|
+
|
|
|
|
|
+import com.jeesite.common.collect.ListUtils;
|
|
|
|
|
+import com.jeesite.common.config.Global;
|
|
|
|
|
+import com.jeesite.common.entity.Page;
|
|
|
|
|
+import com.jeesite.common.lang.ObjectUtils;
|
|
|
|
|
+import com.jeesite.common.lang.StringUtils;
|
|
|
|
|
+import com.jeesite.common.mybatis.mapper.query.QueryType;
|
|
|
|
|
+import com.jeesite.common.web.BaseController;
|
|
|
|
|
+import com.jeesite.modules.file.entity.FileUpload;
|
|
|
|
|
+import com.jeesite.modules.file.service.FileUploadService;
|
|
|
|
|
+import com.jeesite.modules.mes.entity.MesClientUpgrade;
|
|
|
|
|
+import com.jeesite.modules.mes.entity.MesLine;
|
|
|
|
|
+import com.jeesite.modules.mes.entity.MesLineProcess;
|
|
|
|
|
+import com.jeesite.modules.mes.resp.CommonResp;
|
|
|
|
|
+import com.jeesite.modules.mes.service.MesClientUpgradeService;
|
|
|
|
|
+import com.jeesite.modules.mes.service.MesLineService;
|
|
|
|
|
+import com.jeesite.modules.mes.service.MesLineProcessService;
|
|
|
|
|
+import com.jeesite.modules.mes.util.ClientVersionUtils;
|
|
|
|
|
+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.validation.annotation.Validated;
|
|
|
|
|
+import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+@Controller
|
|
|
|
|
+@RequestMapping(value = "${adminPath}/mes/mesClientUpgrade")
|
|
|
|
|
+public class MesClientUpgradeController extends BaseController {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MesClientUpgradeService mesClientUpgradeService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MesLineProcessService mesLineProcessService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private MesLineService mesLineService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FileUploadService fileUploadService;
|
|
|
|
|
+
|
|
|
|
|
+ @ModelAttribute
|
|
|
|
|
+ public MesClientUpgrade get(String id, boolean isNewRecord) {
|
|
|
|
|
+ return mesClientUpgradeService.get(id, isNewRecord);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @RequiresPermissions("mes:mesLineProcess:view")
|
|
|
|
|
+ @RequestMapping(value = {"list", ""})
|
|
|
|
|
+ public String list(MesClientUpgrade mesClientUpgrade, Model model, HttpServletRequest request) {
|
|
|
|
|
+ boolean lineProcessJar = "1".equals(request.getParameter("lineProcessJar"));
|
|
|
|
|
+ String lineProcessId = request.getParameter("lineProcessId");
|
|
|
|
|
+ fillLineProcessJarLineSn(mesClientUpgrade, lineProcessId);
|
|
|
|
|
+ model.addAttribute("mesClientUpgrade", mesClientUpgrade);
|
|
|
|
|
+ model.addAttribute("lineProcessJar", lineProcessJar);
|
|
|
|
|
+ model.addAttribute("lineProcessId", lineProcessId);
|
|
|
|
|
+ return "modules/mes/mesClientUpgradeList";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @RequiresPermissions("mes:mesLineProcess:view")
|
|
|
|
|
+ @RequestMapping(value = "listData")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public Page<MesClientUpgrade> listData(MesClientUpgrade mesClientUpgrade,
|
|
|
|
|
+ HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
+ if ("1".equals(request.getParameter("lineProcessJar"))) {
|
|
|
|
|
+ List<String> oprnos = fillLineProcessJarLineSn(mesClientUpgrade, request.getParameter("lineProcessId"));
|
|
|
|
|
+ if (StringUtils.isNotBlank(mesClientUpgrade.getLineSn())) {
|
|
|
|
|
+ mesClientUpgrade.getSqlMap().getWhere().and("a.line_sn", QueryType.EQ, mesClientUpgrade.getLineSn());
|
|
|
|
|
+ mesClientUpgrade.setLineSn(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!oprnos.isEmpty()) {
|
|
|
|
|
+ mesClientUpgrade.getSqlMap().getWhere().and("a.oprno", QueryType.IN, oprnos.toArray(new String[0]));
|
|
|
|
|
+ mesClientUpgrade.setOprno(null);
|
|
|
|
|
+ } else if (StringUtils.isNotBlank(mesClientUpgrade.getOprno())) {
|
|
|
|
|
+ mesClientUpgrade.getSqlMap().getWhere().and("a.oprno", QueryType.EQ, mesClientUpgrade.getOprno());
|
|
|
|
|
+ mesClientUpgrade.setOprno(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ mesClientUpgrade.setPage(new Page<>(request, response));
|
|
|
|
|
+ return mesClientUpgradeService.findPage(mesClientUpgrade);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<String> fillLineProcessJarLineSn(MesClientUpgrade mesClientUpgrade, String lineProcessId) {
|
|
|
|
|
+ List<String> oprnos = new ArrayList<>();
|
|
|
|
|
+ if (StringUtils.isBlank(lineProcessId)) {
|
|
|
|
|
+ return oprnos;
|
|
|
|
|
+ }
|
|
|
|
|
+ MesLineProcess lineProcess = mesLineProcessService.get(new MesLineProcess(lineProcessId));
|
|
|
|
|
+ if (lineProcess == null) {
|
|
|
|
|
+ return oprnos;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(mesClientUpgrade.getLineSn())) {
|
|
|
|
|
+ String lineSn = lineProcess.getLineSn();
|
|
|
|
|
+ if (StringUtils.isBlank(lineSn) && StringUtils.isNotBlank(lineProcess.getLineId())) {
|
|
|
|
|
+ MesLine line = mesLineService.get(new MesLine(lineProcess.getLineId()));
|
|
|
|
|
+ if (line != null) {
|
|
|
|
|
+ lineSn = line.getSn();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ mesClientUpgrade.setLineSn(lineSn);
|
|
|
|
|
+ }
|
|
|
|
|
+ for (MesLineProcess child : findChildLineProcesses(lineProcessId)) {
|
|
|
|
|
+ if (StringUtils.isNotBlank(child.getOprno())) {
|
|
|
|
|
+ oprnos.add(child.getOprno());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (oprnos.isEmpty() && StringUtils.isNotBlank(lineProcess.getOprno())) {
|
|
|
|
|
+ oprnos.add(lineProcess.getOprno());
|
|
|
|
|
+ }
|
|
|
|
|
+ return oprnos;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<MesLineProcess> findChildLineProcesses(String lineProcessId) {
|
|
|
|
|
+ if (StringUtils.isBlank(lineProcessId)) {
|
|
|
|
|
+ return ListUtils.newArrayList();
|
|
|
|
|
+ }
|
|
|
|
|
+ MesLineProcess childQuery = new MesLineProcess();
|
|
|
|
|
+ childQuery.setPid(lineProcessId);
|
|
|
|
|
+ return mesLineProcessService.findList(childQuery);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @RequiresPermissions("mes:mesLineProcess:view")
|
|
|
|
|
+ @RequestMapping(value = "form")
|
|
|
|
|
+ public String form(MesClientUpgrade mesClientUpgrade, Model model, HttpServletRequest request) {
|
|
|
|
|
+ String lineProcessId = request.getParameter("lineProcessId");
|
|
|
|
|
+ boolean lineProcessJar = StringUtils.isNotBlank(lineProcessId);
|
|
|
|
|
+ if (lineProcessJar) {
|
|
|
|
|
+ fillLineProcessJarLineSn(mesClientUpgrade, lineProcessId);
|
|
|
|
|
+ model.addAttribute("childLineProcessList", findChildLineProcesses(lineProcessId));
|
|
|
|
|
+ }
|
|
|
|
|
+ model.addAttribute("mesClientUpgrade", mesClientUpgrade);
|
|
|
|
|
+ model.addAttribute("lineProcessJar", lineProcessJar);
|
|
|
|
|
+ model.addAttribute("lineProcessId", lineProcessId);
|
|
|
|
|
+ return "modules/mes/mesClientUpgradeForm";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @RequiresPermissions("mes:mesLineProcess:edit")
|
|
|
|
|
+ @PostMapping(value = "save")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public String save(@Validated MesClientUpgrade mesClientUpgrade) {
|
|
|
|
|
+ mesClientUpgradeService.save(mesClientUpgrade);
|
|
|
|
|
+ return renderResult(Global.TRUE, text("保存客户端升级版本成功!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @RequiresPermissions("mes:mesLineProcess:edit")
|
|
|
|
|
+ @RequestMapping(value = "delete")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public String delete(MesClientUpgrade mesClientUpgrade) {
|
|
|
|
|
+ mesClientUpgradeService.delete(mesClientUpgrade);
|
|
|
|
|
+ return renderResult(Global.TRUE, text("删除客户端升级版本成功!"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @RequestMapping(value = "checkUpdate")
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ public CommonResp<ClientUpdateInfo> checkUpdate(HttpServletRequest request) {
|
|
|
|
|
+ CommonResp<ClientUpdateInfo> resp = new CommonResp<>();
|
|
|
|
|
+ String lineSn = trimToNull(request.getParameter("lineSn"));
|
|
|
|
|
+ String oprno = trimToNull(request.getParameter("oprno"));
|
|
|
|
|
+ MesClientUpgrade latest = mesClientUpgradeService.findLatestVersion(lineSn, oprno);
|
|
|
|
|
+ if (ObjectUtils.isEmpty(latest)) {
|
|
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
|
|
+ resp.setMessage("no version record");
|
|
|
|
|
+ return resp;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ FileUpload fu = new FileUpload();
|
|
|
|
|
+ fu.setBizKey(latest.getId());
|
|
|
|
|
+ fu.setBizType("mesClientUpgrade_file");
|
|
|
|
|
+ List<FileUpload> files = fileUploadService.findList(fu);
|
|
|
|
|
+ if (ListUtils.isEmpty(files)) {
|
|
|
|
|
+ resp.setResult(Global.FALSE);
|
|
|
|
|
+ resp.setMessage("no downloadable file");
|
|
|
|
|
+ return resp;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String currentVersion = trimToNull(request.getParameter("currentVersion"));
|
|
|
|
|
+ FileUpload file = files.get(0);
|
|
|
|
|
+ ClientUpdateInfo updateInfo = new ClientUpdateInfo();
|
|
|
|
|
+ updateInfo.setCurrentVersion(currentVersion);
|
|
|
|
|
+ updateInfo.setLatestVersion(latest.getVersion());
|
|
|
|
|
+ updateInfo.setLineSn(latest.getLineSn());
|
|
|
|
|
+ updateInfo.setOprno(latest.getOprno());
|
|
|
|
|
+ updateInfo.setHasUpdate(ClientVersionUtils.isNewer(latest.getVersion(), currentVersion));
|
|
|
|
|
+ updateInfo.setContent(latest.getContent());
|
|
|
|
|
+ updateInfo.setDownloadUrl(buildFileUrl(request, file.getFileUrl()));
|
|
|
|
|
+ String originalName = file.getFileName();
|
|
|
|
|
+ if (StringUtils.isBlank(originalName)) {
|
|
|
|
|
+ originalName = extractFileName(file.getFileUrl());
|
|
|
|
|
+ }
|
|
|
|
|
+ updateInfo.setFileName(originalName);
|
|
|
|
|
+ resp.setData(updateInfo);
|
|
|
|
|
+ resp.setResult(Global.TRUE);
|
|
|
|
|
+ return resp;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String buildFileUrl(HttpServletRequest request, String fileUrl) {
|
|
|
|
|
+ String host = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
|
|
|
|
|
+ return host + request.getContextPath() + fileUrl;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String trimToNull(String value) {
|
|
|
|
|
+ if (value == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ value = value.trim();
|
|
|
|
|
+ return value.length() == 0 ? null : value;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String extractFileName(String fileUrl) {
|
|
|
|
|
+ if (fileUrl == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ int index = fileUrl.lastIndexOf('/');
|
|
|
|
|
+ return index >= 0 ? fileUrl.substring(index + 1) : fileUrl;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static class ClientUpdateInfo {
|
|
|
|
|
+ private String currentVersion;
|
|
|
|
|
+ private String latestVersion;
|
|
|
|
|
+ private String lineSn;
|
|
|
|
|
+ private String oprno;
|
|
|
|
|
+ private boolean hasUpdate;
|
|
|
|
|
+ private String content;
|
|
|
|
|
+ private String downloadUrl;
|
|
|
|
|
+ private String fileName;
|
|
|
|
|
+
|
|
|
|
|
+ public String getCurrentVersion() {
|
|
|
|
|
+ return currentVersion;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setCurrentVersion(String currentVersion) {
|
|
|
|
|
+ this.currentVersion = currentVersion;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String getLatestVersion() {
|
|
|
|
|
+ return latestVersion;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setLatestVersion(String latestVersion) {
|
|
|
|
|
+ this.latestVersion = latestVersion;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String getLineSn() {
|
|
|
|
|
+ return lineSn;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setLineSn(String lineSn) {
|
|
|
|
|
+ this.lineSn = lineSn;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String getOprno() {
|
|
|
|
|
+ return oprno;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setOprno(String oprno) {
|
|
|
|
|
+ this.oprno = oprno;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public boolean isHasUpdate() {
|
|
|
|
|
+ return hasUpdate;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setHasUpdate(boolean hasUpdate) {
|
|
|
|
|
+ this.hasUpdate = hasUpdate;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String getContent() {
|
|
|
|
|
+ return content;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setContent(String content) {
|
|
|
|
|
+ this.content = content;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String getDownloadUrl() {
|
|
|
|
|
+ return downloadUrl;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setDownloadUrl(String downloadUrl) {
|
|
|
|
|
+ this.downloadUrl = downloadUrl;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String getFileName() {
|
|
|
|
|
+ return fileName;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setFileName(String fileName) {
|
|
|
|
|
+ this.fileName = fileName;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|