| | |
| | | package com.zy.asrs.wms.system.license.controller; |
| | | |
| | | import com.zy.asrs.wms.system.license.LicenseCheckListener; |
| | | import com.zy.asrs.wms.system.license.entity.license.*; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import com.zy.asrs.wms.system.license.timer.LicenseTimer; |
| | | import de.schlichtherle.license.LicenseContent; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * |
| | | * 用于生成证书文件,不能放在给客户部署的代码里 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/api/license") |
| | | public class LicenseCreatorController { |
| | | |
| | | @Value("${license.licensePath}") |
| | | private String licensePath; |
| | | @Autowired |
| | | private LicenseCheckListener licenseCheckListener; |
| | | @Autowired |
| | | private LicenseTimer licenseTimer; |
| | | |
| | | /** |
| | | * 获取服务器硬件信息 |
| | | * @param osName 操作系统类型,如果为空则自动判断 |
| | | */ |
| | | @RequestMapping(value = "/getServerInfos",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}) |
| | | public LicenseCheck getServerInfos(@RequestParam(value = "osName",required = false) String osName) { |
| | | //操作系统类型 |
| | | if(Cools.isEmpty(osName)){ |
| | | osName = System.getProperty("os.name"); |
| | | } |
| | | osName = osName.toLowerCase(); |
| | | |
| | | AbstractServerInfos abstractServerInfos = null; |
| | | |
| | | //根据不同操作系统类型选择不同的数据获取方法 |
| | | if (osName.startsWith("windows")) { |
| | | abstractServerInfos = new WindowsServerInfos(); |
| | | } else if (osName.startsWith("linux")) { |
| | | abstractServerInfos = new LinuxServerInfos(); |
| | | }else{//其他服务器类型 |
| | | abstractServerInfos = new WindowsServerInfos(); |
| | | } |
| | | |
| | | return abstractServerInfos.getServerInfos(); |
| | | } |
| | | |
| | | /** |
| | | * 获取许可证有效期天数 |
| | | */ |
| | | @RequestMapping(value = "/getLicenseDays") |
| | | public R getLicenseDays() { |
| | | return R.ok().add(licenseTimer.getLicenseDays()); |
| | | } |
| | | |
| | | @RequestMapping(value = "/updateLicense") |
| | | public R updateLicense(@RequestParam("file") MultipartFile[] files){ |
| | | MultipartFile file = files[0]; |
| | | |
| | | String licensePathFileName = this.getClass().getClassLoader().getResource(licensePath).getPath(); |
| | | File licensePathFile = new File(licensePathFileName); |
| | | //服务器端保存的文件对象 |
| | | File serverFile = new File(licensePathFile.getPath()); |
| | | if (serverFile.exists()) { |
| | | try { |
| | | serverFile.delete();//存在文件,删除 |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | try { |
| | | //创建文件 |
| | | serverFile.createNewFile(); |
| | | //将上传的文件写入到服务器端文件内 |
| | | file.transferTo(serverFile); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | //重新加载许可证 |
| | | boolean loadedLicense = licenseCheckListener.loadLicense(); |
| | | if (loadedLicense) { |
| | | return R.ok(); |
| | | } |
| | | return R.error("许可证更新失败"); |
| | | } |
| | | |
| | | package com.zy.asrs.wms.system.license.controller;
|
| | |
|
| | | import com.zy.asrs.wms.system.license.LicenseCheckListener;
|
| | | import com.zy.asrs.wms.system.license.entity.license.*;
|
| | | import com.zy.asrs.framework.common.Cools;
|
| | | import com.zy.asrs.framework.common.R;
|
| | | import com.zy.asrs.wms.system.license.timer.LicenseTimer;
|
| | | import de.schlichtherle.license.LicenseContent;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.http.MediaType;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestParam;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | |
|
| | | import java.io.File;
|
| | | import java.io.IOException;
|
| | | import java.util.Date;
|
| | |
|
| | | /**
|
| | | *
|
| | | * 用于生成证书文件,不能放在给客户部署的代码里
|
| | | */
|
| | | @RestController
|
| | | @RequestMapping("/api/license")
|
| | | public class LicenseCreatorController {
|
| | |
|
| | | @Value("${license.licensePath}")
|
| | | private String licensePath;
|
| | | @Autowired
|
| | | private LicenseCheckListener licenseCheckListener;
|
| | | @Autowired
|
| | | private LicenseTimer licenseTimer;
|
| | |
|
| | | /**
|
| | | * 获取服务器硬件信息
|
| | | * @param osName 操作系统类型,如果为空则自动判断
|
| | | */
|
| | | @RequestMapping(value = "/getServerInfos",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
|
| | | public LicenseCheck getServerInfos(@RequestParam(value = "osName",required = false) String osName) {
|
| | | //操作系统类型
|
| | | if(Cools.isEmpty(osName)){
|
| | | osName = System.getProperty("os.name");
|
| | | }
|
| | | osName = osName.toLowerCase();
|
| | |
|
| | | AbstractServerInfos abstractServerInfos = null;
|
| | |
|
| | | //根据不同操作系统类型选择不同的数据获取方法
|
| | | if (osName.startsWith("windows")) {
|
| | | abstractServerInfos = new WindowsServerInfos();
|
| | | } else if (osName.startsWith("linux")) {
|
| | | abstractServerInfos = new LinuxServerInfos();
|
| | | }else{//其他服务器类型
|
| | | abstractServerInfos = new WindowsServerInfos();
|
| | | }
|
| | |
|
| | | return abstractServerInfos.getServerInfos();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取许可证有效期天数
|
| | | */
|
| | | @RequestMapping(value = "/getLicenseDays")
|
| | | public R getLicenseDays() {
|
| | | return R.ok().add(licenseTimer.getLicenseDays());
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "/updateLicense")
|
| | | public R updateLicense(@RequestParam("file") MultipartFile[] files){
|
| | | MultipartFile file = files[0];
|
| | |
|
| | | String licensePathFileName = this.getClass().getClassLoader().getResource(licensePath).getPath();
|
| | | File licensePathFile = new File(licensePathFileName);
|
| | | //服务器端保存的文件对象
|
| | | File serverFile = new File(licensePathFile.getPath());
|
| | | if (serverFile.exists()) {
|
| | | try {
|
| | | serverFile.delete();//存在文件,删除
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | try {
|
| | | //创建文件
|
| | | serverFile.createNewFile();
|
| | | //将上传的文件写入到服务器端文件内
|
| | | file.transferTo(serverFile);
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | //重新加载许可证
|
| | | boolean loadedLicense = licenseCheckListener.loadLicense();
|
| | | if (loadedLicense) {
|
| | | return R.ok();
|
| | | }
|
| | | return R.error("许可证更新失败");
|
| | | }
|
| | |
|
| | | } |