| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- 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 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:mesClient: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:mesClient: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(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(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:mesClient: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:mesClient:edit")
- @PostMapping(value = "save")
- @ResponseBody
- public String save(@Validated MesClientUpgrade mesClientUpgrade) {
- mesClientUpgradeService.save(mesClientUpgrade);
- return renderResult(Global.TRUE, text("保存客户端升级版本成功!"));
- }
- @RequiresPermissions("mes:mesClient: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;
- }
- Long currentVersion = parseLong(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(currentVersion == null || latest.getVersion() != null && latest.getVersion() > currentVersion);
- updateInfo.setContent(latest.getContent());
- updateInfo.setDownloadUrl(buildFileUrl(request, file.getFileUrl()));
- updateInfo.setFileName(extractFileName(file.getFileUrl()));
- 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;
- }
- private Long parseLong(String value) {
- try {
- return ObjectUtils.isEmpty(value) ? null : Long.valueOf(value);
- } catch (NumberFormatException ex) {
- return null;
- }
- }
- public static class ClientUpdateInfo {
- private Long currentVersion;
- private Long latestVersion;
- private String lineSn;
- private String oprno;
- private boolean hasUpdate;
- private String content;
- private String downloadUrl;
- private String fileName;
- public Long getCurrentVersion() {
- return currentVersion;
- }
- public void setCurrentVersion(Long currentVersion) {
- this.currentVersion = currentVersion;
- }
- public Long getLatestVersion() {
- return latestVersion;
- }
- public void setLatestVersion(Long 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;
- }
- }
- }
|