| | |
| | | <groupId>com.fasterxml.jackson.module</groupId> |
| | | <artifactId>jackson-module-kotlin</artifactId> |
| | | </dependency> |
| | | <!--çælicense--> |
| | | <dependency> |
| | | <groupId>de.schlichtherle.truelicense</groupId> |
| | | <artifactId>truelicense-core</artifactId> |
| | | <version>1.33</version> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config; |
| | | |
| | | import org.jeecg.config.license.LicenseCheckInterceptor; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
| | | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @Description: Licenseæ¦æªå¨é
ç½® |
| | | * @DateTime: 17:55 2024/11/2 |
| | | */ |
| | | @Configuration |
| | | public class LicenseConfig implements WebMvcConfigurer { |
| | | |
| | | @Resource |
| | | private LicenseCheckInterceptor licenseCheckInterceptor; |
| | | |
| | | @Override |
| | | public void addInterceptors(InterceptorRegistry registry) { |
| | | |
| | | //æ·»å è¦æ¦æªçurl |
| | | registry.addInterceptor(licenseCheckInterceptor) |
| | | // æ¦æªçè·¯å¾ |
| | | .addPathPatterns("/**") |
| | | // æ¾è¡çè·¯å¾ |
| | | .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**", "/doc.html")//swagger |
| | | .excludePathPatterns("/base/license/**");//çælicenseåè·åæå¡å¨ç¡¬ä»¶ä¿¡æ¯ |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license; |
| | | |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.jeecg.config.license.entity.LicenseCheckModel; |
| | | |
| | | import java.net.InetAddress; |
| | | import java.net.NetworkInterface; |
| | | import java.net.SocketException; |
| | | import java.util.ArrayList; |
| | | import java.util.Enumeration; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName AbstractServerInfos |
| | | * @date 2024/11/2 16:00 |
| | | */ |
| | | |
| | | public abstract class AbstractServerInfos { |
| | | |
| | | private static Logger logger = LogManager.getLogger(AbstractServerInfos.class); |
| | | |
| | | /** |
| | | * ç»è£
éè¦é¢å¤æ ¡éªçLicenseåæ° |
| | | * |
| | | * @return entity.vo.LicenseCheckModel |
| | | */ |
| | | public LicenseCheckModel getServerInfos() { |
| | | LicenseCheckModel result = new LicenseCheckModel(); |
| | | |
| | | try { |
| | | result.setIpAddress(this.getIpAddress()); |
| | | result.setMacAddress(this.getMacAddress()); |
| | | result.setCpuSerial(this.getCPUSerial()); |
| | | result.setMainBoardSerial(this.getMainBoardSerial()); |
| | | } catch (Exception e) { |
| | | logger.error("è·åæå¡å¨ç¡¬ä»¶ä¿¡æ¯å¤±è´¥", e); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * è·åIPå°å |
| | | * |
| | | * @return java.util.List<java.lang.String> |
| | | */ |
| | | protected abstract List<String> getIpAddress() throws Exception; |
| | | |
| | | /** |
| | | * è·åMacå°å |
| | | * |
| | | * @return java.util.List<java.lang.String> |
| | | */ |
| | | protected abstract List<String> getMacAddress() throws Exception; |
| | | |
| | | /** |
| | | * è·åCPUåºåå· |
| | | * |
| | | * @return java.lang.String |
| | | */ |
| | | protected abstract String getCPUSerial() throws Exception; |
| | | |
| | | /** |
| | | * è·å主æ¿åºåå· |
| | | * |
| | | * @return java.lang.String |
| | | */ |
| | | protected abstract String getMainBoardSerial() throws Exception; |
| | | |
| | | /** |
| | | * è·åå½åæå¡å¨ææç¬¦åæ¡ä»¶çInetAddress |
| | | * |
| | | * @return java.util.List<java.net.InetAddress> |
| | | */ |
| | | protected List<InetAddress> getLocalAllInetAddress() throws Exception { |
| | | List<InetAddress> result = new ArrayList<>(4); |
| | | |
| | | // éåææçç½ç»æ¥å£ |
| | | for (Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements(); ) { |
| | | NetworkInterface iface = (NetworkInterface) networkInterfaces.nextElement(); |
| | | // 卿æçæ¥å£ä¸åéåIP |
| | | for (Enumeration inetAddresses = iface.getInetAddresses(); inetAddresses.hasMoreElements(); ) { |
| | | InetAddress inetAddr = (InetAddress) inetAddresses.nextElement(); |
| | | |
| | | //æé¤LoopbackAddressãSiteLocalAddressãLinkLocalAddressãMulticastAddressç±»åçIPå°å |
| | | if (!inetAddr.isLoopbackAddress() /*&& !inetAddr.isSiteLocalAddress()*/ |
| | | && !inetAddr.isLinkLocalAddress() && !inetAddr.isMulticastAddress()) { |
| | | result.add(inetAddr); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * è·åæä¸ªç½ç»æ¥å£çMacå°å |
| | | * |
| | | * @return void |
| | | */ |
| | | protected String getMacByInetAddress(InetAddress inetAddr) { |
| | | try { |
| | | byte[] mac = NetworkInterface.getByInetAddress(inetAddr).getHardwareAddress(); |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | |
| | | for (int i = 0; i < mac.length; i++) { |
| | | if (i != 0) { |
| | | stringBuffer.append("-"); |
| | | } |
| | | |
| | | //å°åå
è¿å¶byte转å为å符串 |
| | | String temp = Integer.toHexString(mac[i] & 0xff); |
| | | if (temp.length() == 1) { |
| | | stringBuffer.append("0" + temp); |
| | | } else { |
| | | stringBuffer.append(temp); |
| | | } |
| | | } |
| | | |
| | | return stringBuffer.toString().toUpperCase(); |
| | | } catch (SocketException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license; |
| | | |
| | | import de.schlichtherle.license.AbstractKeyStoreParam; |
| | | |
| | | import java.io.*; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName CustomKeyStoreParam |
| | | * @date 2024/11/2 16:00 |
| | | */ |
| | | |
| | | public class CustomKeyStoreParam extends AbstractKeyStoreParam { |
| | | |
| | | /** |
| | | * å
¬é¥/ç§é¥å¨ç£çä¸çåå¨è·¯å¾ |
| | | */ |
| | | private String storePath; |
| | | private String alias; |
| | | private String storePwd; |
| | | private String keyPwd; |
| | | |
| | | public CustomKeyStoreParam(Class clazz, String resource, String alias, String storePwd, String keyPwd) { |
| | | super(clazz, resource); |
| | | this.storePath = resource; |
| | | this.alias = alias; |
| | | this.storePwd = storePwd; |
| | | this.keyPwd = keyPwd; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String getAlias() { |
| | | return alias; |
| | | } |
| | | |
| | | @Override |
| | | public String getStorePwd() { |
| | | return storePwd; |
| | | } |
| | | |
| | | @Override |
| | | public String getKeyPwd() { |
| | | return keyPwd; |
| | | } |
| | | |
| | | /** |
| | | * å¤åde.schlichtherle.license.AbstractKeyStoreParamçgetStream()æ¹æ³<br/> |
| | | * ç¨äºå°å
¬ç§é¥å卿件忾å°å
¶ä»ç£çä½ç½®è䏿¯é¡¹ç®ä¸ |
| | | * |
| | | * @param |
| | | * @return java.io.InputStream |
| | | */ |
| | | @Override |
| | | public InputStream getStream() throws IOException { |
| | | final InputStream in = new FileInputStream(new File(storePath)); |
| | | if (null == in) { |
| | | throw new FileNotFoundException(storePath); |
| | | } |
| | | |
| | | return in; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.lang.Nullable; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.servlet.HandlerInterceptor; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @Description: ä½¿ç¨æ¦æªå¨æ¦æªè¯·æ±ï¼éªè¯è¯ä¹¦çå¯ç¨æ§ |
| | | * @DateTime: 2024/11/2 16:00 |
| | | */ |
| | | @Component |
| | | public class LicenseCheckInterceptor implements HandlerInterceptor { |
| | | |
| | | private static Logger log = LoggerFactory.getLogger(LicenseCheckListener.class); |
| | | |
| | | /** |
| | | * è¿å
¥controllerå±ä¹åæ¦æªè¯·æ± |
| | | * @param request |
| | | * @param response |
| | | * @param handler |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
| | | log.info("è¿å
¥æ¦æªå¨ï¼éªè¯è¯ä¹¦å¯ä½¿ç¨æ§"); |
| | | LicenseVerify licenseVerify = new LicenseVerify(); |
| | | |
| | | //æ ¡éªè¯ä¹¦æ¯å¦ææ |
| | | boolean verifyResult = licenseVerify.verify(); |
| | | |
| | | if(verifyResult){ |
| | | log.info("éªè¯æåï¼è¯ä¹¦å¯ç¨"); |
| | | return true; |
| | | }else{ |
| | | log.info("éªè¯å¤±è´¥ï¼è¯ä¹¦æ æ"); |
| | | response.setContentType("application/json;charset=utf-8"); |
| | | Map<String,String> result = new HashMap<>(1); |
| | | result.put("result","æ¨çè¯ä¹¦æ æï¼è¯·æ ¸æ¥æå¡å¨æ¯å¦å徿ææéæ°ç³è¯·è¯ä¹¦ï¼"); |
| | | |
| | | response.getWriter().write(JSON.toJSONString(result)); |
| | | |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¤ç请æ±å®æåè§å¾æ¸²æä¹åçå¤çæä½ |
| | | * @param request |
| | | * @param response |
| | | * @param handler |
| | | * @param modelAndView |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception { |
| | | // log.info("å¤ç请æ±å®æåè§å¾æ¸²æä¹åçå¤çæä½"); |
| | | } |
| | | |
| | | /** |
| | | * è§å¾æ¸²æä¹åçæä½ |
| | | * @param request |
| | | * @param response |
| | | * @param handler |
| | | * @param ex |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception { |
| | | // log.info("è§å¾æ¸²æä¹åçæä½"); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.config.license.entity.LicenseVerifyParam; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.context.ApplicationListener; |
| | | import org.springframework.context.event.ContextRefreshedEvent; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName LicenseCheckListener |
| | | * @date 2024/11/2 16:00 |
| | | */ |
| | | |
| | | @Component |
| | | public class LicenseCheckListener implements ApplicationListener<ContextRefreshedEvent> { |
| | | |
| | | private static Logger logger = LoggerFactory.getLogger(LicenseCheckListener.class); |
| | | |
| | | /** |
| | | * è¯ä¹¦subject |
| | | */ |
| | | @Value("${license.subject}") |
| | | private String subject; |
| | | |
| | | /** |
| | | * å
¬é¥å«ç§° |
| | | */ |
| | | @Value("${license.publicAlias}") |
| | | private String publicAlias; |
| | | |
| | | /** |
| | | * 访é®å
¬é¥åºçå¯ç |
| | | */ |
| | | @Value("${license.storePass}") |
| | | private String storePass; |
| | | |
| | | /** |
| | | * è¯ä¹¦çæè·¯å¾ |
| | | */ |
| | | @Value("${license.licensePath}") |
| | | private String licensePath; |
| | | |
| | | /** |
| | | * å¯é¥åºåå¨è·¯å¾ |
| | | */ |
| | | @Value("${license.publicKeysStorePath}") |
| | | private String publicKeysStorePath; |
| | | |
| | | @Override |
| | | public void onApplicationEvent(ContextRefreshedEvent event) { |
| | | //root application context 没æparent |
| | | ApplicationContext context = event.getApplicationContext().getParent(); |
| | | if (context == null) { |
| | | if (StringUtils.isNotBlank(licensePath)) { |
| | | logger.info("++++++++ å¼å§å®è£
è¯ä¹¦ ++++++++"); |
| | | |
| | | LicenseVerifyParam param = new LicenseVerifyParam(); |
| | | param.setSubject(subject); |
| | | param.setPublicAlias(publicAlias); |
| | | param.setStorePass(storePass); |
| | | param.setLicensePath(licensePath); |
| | | param.setPublicKeysStorePath(publicKeysStorePath); |
| | | |
| | | LicenseVerify licenseVerify = new LicenseVerify(); |
| | | //å®è£
è¯ä¹¦ |
| | | licenseVerify.install(param); |
| | | |
| | | logger.info("++++++++ è¯ä¹¦å®è£
ç»æ ++++++++"); |
| | | } |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license; |
| | | |
| | | import de.schlichtherle.license.LicenseManager; |
| | | import de.schlichtherle.license.LicenseParam; |
| | | import org.jeecg.config.license.entity.CustomLicenseManager; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName LicenseManagerHolder |
| | | * @date 2024/11/2 16:00 |
| | | */ |
| | | |
| | | public class LicenseManagerHolder { |
| | | |
| | | private static volatile LicenseManager LICENSE_MANAGER; |
| | | |
| | | public static LicenseManager getInstance(LicenseParam param){ |
| | | if(LICENSE_MANAGER == null){ |
| | | synchronized (LicenseManagerHolder.class){ |
| | | if(LICENSE_MANAGER == null){ |
| | | LICENSE_MANAGER = new CustomLicenseManager(param); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return LICENSE_MANAGER; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license; |
| | | |
| | | import de.schlichtherle.license.*; |
| | | import org.jeecg.config.license.entity.LicenseVerifyParam; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import java.io.File; |
| | | import java.text.DateFormat; |
| | | import java.text.MessageFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.prefs.Preferences; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName LicenseVerify |
| | | * @Description å®è£
ææè¯ä¹¦ |
| | | * @date 2024/11/2 16:00 |
| | | */ |
| | | |
| | | public class LicenseVerify { |
| | | |
| | | private static final Logger logger = LoggerFactory.getLogger(LicenseVerify.class); |
| | | |
| | | /** |
| | | * å®è£
Licenseè¯ä¹¦ |
| | | */ |
| | | public synchronized LicenseContent install(LicenseVerifyParam param){ |
| | | LicenseContent result = null; |
| | | DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | //1. å®è£
è¯ä¹¦ |
| | | try{ |
| | | LicenseManager licenseManager = LicenseManagerHolder.getInstance(initLicenseParam(param)); |
| | | licenseManager.uninstall(); |
| | | |
| | | result = licenseManager.install(new File(param.getLicensePath())); |
| | | logger.info(MessageFormat.format("è¯ä¹¦å®è£
æåï¼è¯ä¹¦æææï¼{0} - {1}",format.format(result.getNotBefore()),format.format(result.getNotAfter()))); |
| | | }catch (Exception e){ |
| | | logger.error("è¯ä¹¦å®è£
失败ï¼",e); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªLicenseè¯ä¹¦ |
| | | * @return boolean |
| | | */ |
| | | public boolean verify(){ |
| | | LicenseManager licenseManager = LicenseManagerHolder.getInstance(null); |
| | | DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | //2. æ ¡éªè¯ä¹¦ |
| | | try { |
| | | LicenseContent licenseContent = licenseManager.verify(); |
| | | |
| | | logger.info(MessageFormat.format("è¯ä¹¦æ ¡éªéè¿ï¼è¯ä¹¦æææï¼{0} - {1}",format.format(licenseContent.getNotBefore()),format.format(licenseContent.getNotAfter()))); |
| | | return true; |
| | | }catch (Exception e){ |
| | | logger.error("è¯ä¹¦æ ¡éªå¤±è´¥ï¼",e); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åå§åè¯ä¹¦çæåæ° |
| | | * @param param Licenseæ ¡éªç±»éè¦çåæ° |
| | | * @return de.schlichtherle.license.LicenseParam |
| | | */ |
| | | private LicenseParam initLicenseParam(LicenseVerifyParam param){ |
| | | Preferences preferences = Preferences.userNodeForPackage(LicenseVerify.class); |
| | | |
| | | CipherParam cipherParam = new DefaultCipherParam(param.getStorePass()); |
| | | |
| | | KeyStoreParam publicStoreParam = new CustomKeyStoreParam(LicenseVerify.class |
| | | ,param.getPublicKeysStorePath() |
| | | ,param.getPublicAlias() |
| | | ,param.getStorePass() |
| | | ,null); |
| | | |
| | | return new DefaultLicenseParam(param.getSubject() |
| | | ,preferences |
| | | ,publicStoreParam |
| | | ,cipherParam); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.InputStreamReader; |
| | | import java.net.InetAddress; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName LinuxServerInfos |
| | | * @date 2024/11/2 16:00 |
| | | */ |
| | | |
| | | public class LinuxServerInfos extends AbstractServerInfos{ |
| | | |
| | | @Override |
| | | protected List<String> getIpAddress() throws Exception { |
| | | List<String> result = null; |
| | | |
| | | //è·åææç½ç»æ¥å£ |
| | | List<InetAddress> inetAddresses = getLocalAllInetAddress(); |
| | | |
| | | if(inetAddresses != null && inetAddresses.size() > 0){ |
| | | result = inetAddresses.stream().map(InetAddress::getHostAddress).distinct().map(String::toLowerCase).collect(Collectors.toList()); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | protected List<String> getMacAddress() throws Exception { |
| | | List<String> result = null; |
| | | |
| | | //1. è·åææç½ç»æ¥å£ |
| | | List<InetAddress> inetAddresses = getLocalAllInetAddress(); |
| | | |
| | | if(inetAddresses != null && inetAddresses.size() > 0){ |
| | | //2. è·åææç½ç»æ¥å£çMacå°å |
| | | result = inetAddresses.stream().map(this::getMacByInetAddress).distinct().collect(Collectors.toList()); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | protected String getCPUSerial() throws Exception { |
| | | //åºåå· |
| | | String serialNumber = ""; |
| | | |
| | | //使ç¨dmidecodeå½ä»¤è·åCPUåºåå· |
| | | String[] shell = {"/bin/bash","-c","dmidecode -t processor | grep 'ID' | awk -F ':' '{print $2}' | head -n 1"}; |
| | | Process process = Runtime.getRuntime().exec(shell); |
| | | process.getOutputStream().close(); |
| | | |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
| | | |
| | | String line = reader.readLine().trim(); |
| | | if(StringUtils.isNotBlank(line)){ |
| | | serialNumber = line; |
| | | } |
| | | |
| | | reader.close(); |
| | | return serialNumber; |
| | | } |
| | | |
| | | @Override |
| | | protected String getMainBoardSerial() throws Exception { |
| | | //åºåå· |
| | | String serialNumber = ""; |
| | | |
| | | //使ç¨dmidecodeå½ä»¤è·å主æ¿åºåå· |
| | | String[] shell = {"/bin/bash","-c","dmidecode | grep 'Serial Number' | awk -F ':' '{print $2}' | head -n 1"}; |
| | | Process process = Runtime.getRuntime().exec(shell); |
| | | process.getOutputStream().close(); |
| | | |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
| | | |
| | | String line = reader.readLine().trim(); |
| | | if(StringUtils.isNotBlank(line)){ |
| | | serialNumber = line; |
| | | } |
| | | |
| | | reader.close(); |
| | | return serialNumber; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license; |
| | | |
| | | import java.net.InetAddress; |
| | | import java.util.List; |
| | | import java.util.Scanner; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName WindowsServerInfos |
| | | * @date 2024/11/2 16:00 |
| | | */ |
| | | |
| | | public class WindowsServerInfos extends AbstractServerInfos{ |
| | | |
| | | @Override |
| | | protected List<String> getIpAddress() throws Exception { |
| | | List<String> result = null; |
| | | |
| | | //è·åææç½ç»æ¥å£ |
| | | List<InetAddress> inetAddresses = getLocalAllInetAddress(); |
| | | |
| | | if(inetAddresses != null && inetAddresses.size() > 0){ |
| | | result = inetAddresses.stream().map(InetAddress::getHostAddress).distinct().map(String::toLowerCase).collect(Collectors.toList()); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | protected List<String> getMacAddress() throws Exception { |
| | | List<String> result = null; |
| | | |
| | | //1. è·åææç½ç»æ¥å£ |
| | | List<InetAddress> inetAddresses = getLocalAllInetAddress(); |
| | | |
| | | if(inetAddresses != null && inetAddresses.size() > 0){ |
| | | //2. è·åææç½ç»æ¥å£çMacå°å |
| | | result = inetAddresses.stream().map(this::getMacByInetAddress).distinct().collect(Collectors.toList()); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | protected String getCPUSerial() throws Exception { |
| | | //åºåå· |
| | | String serialNumber = ""; |
| | | |
| | | //使ç¨WMICè·åCPUåºåå· |
| | | Process process = Runtime.getRuntime().exec("wmic cpu get processorid"); |
| | | process.getOutputStream().close(); |
| | | Scanner scanner = new Scanner(process.getInputStream()); |
| | | |
| | | if(scanner.hasNext()){ |
| | | scanner.next(); |
| | | } |
| | | |
| | | if(scanner.hasNext()){ |
| | | serialNumber = scanner.next().trim(); |
| | | } |
| | | |
| | | scanner.close(); |
| | | return serialNumber; |
| | | } |
| | | |
| | | @Override |
| | | protected String getMainBoardSerial() throws Exception { |
| | | //åºåå· |
| | | String serialNumber = ""; |
| | | |
| | | //使ç¨WMICè·å主æ¿åºåå· |
| | | Process process = Runtime.getRuntime().exec("wmic baseboard get serialnumber"); |
| | | process.getOutputStream().close(); |
| | | Scanner scanner = new Scanner(process.getInputStream()); |
| | | |
| | | if(scanner.hasNext()){ |
| | | scanner.next(); |
| | | } |
| | | |
| | | if(scanner.hasNext()){ |
| | | serialNumber = scanner.next().trim(); |
| | | } |
| | | |
| | | scanner.close(); |
| | | return serialNumber; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license.entity; |
| | | |
| | | import de.schlichtherle.license.*; |
| | | import de.schlichtherle.xml.GenericCertificate; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.jeecg.config.license.AbstractServerInfos; |
| | | import org.jeecg.config.license.LinuxServerInfos; |
| | | import org.jeecg.config.license.WindowsServerInfos; |
| | | |
| | | import java.beans.XMLDecoder; |
| | | import java.io.BufferedInputStream; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName CustomLicenseManager |
| | | * @date 2024/11/2 16:00 |
| | | */ |
| | | |
| | | public class CustomLicenseManager extends LicenseManager { |
| | | |
| | | private static Logger logger = LogManager.getLogger(CustomLicenseManager.class); |
| | | |
| | | //XMLç¼ç |
| | | private static final String XML_CHARSET = "UTF-8"; |
| | | //é»è®¤BUFSIZE |
| | | private static final int DEFAULT_BUFSIZE = 8 * 1024; |
| | | |
| | | public CustomLicenseManager() { |
| | | |
| | | } |
| | | |
| | | public CustomLicenseManager(LicenseParam param) { |
| | | super(param); |
| | | } |
| | | |
| | | /** |
| | | * å¤åcreateæ¹æ³ |
| | | * |
| | | * @param |
| | | * @return byte[] |
| | | */ |
| | | @Override |
| | | protected synchronized byte[] create( |
| | | LicenseContent content, |
| | | LicenseNotary notary) |
| | | throws Exception { |
| | | initialize(content); |
| | | this.validateCreate(content); |
| | | final GenericCertificate certificate = notary.sign(content); |
| | | return getPrivacyGuard().cert2key(certificate); |
| | | } |
| | | |
| | | /** |
| | | * å¤åinstallæ¹æ³ï¼å
¶ä¸validateæ¹æ³è°ç¨æ¬ç±»ä¸çvalidateæ¹æ³ï¼æ ¡éªIPå°åãMacå°åçå
¶ä»ä¿¡æ¯ |
| | | * |
| | | * @param |
| | | * @return de.schlichtherle.license.LicenseContent |
| | | */ |
| | | @Override |
| | | protected synchronized LicenseContent install( |
| | | final byte[] key, |
| | | final LicenseNotary notary) |
| | | throws Exception { |
| | | final GenericCertificate certificate = getPrivacyGuard().key2cert(key); |
| | | |
| | | notary.verify(certificate); |
| | | final LicenseContent content = (LicenseContent) this.load(certificate.getEncoded()); |
| | | this.validate(content); |
| | | setLicenseKey(key); |
| | | setCertificate(certificate); |
| | | |
| | | return content; |
| | | } |
| | | |
| | | /** |
| | | * å¤åverifyæ¹æ³ï¼è°ç¨æ¬ç±»ä¸çvalidateæ¹æ³ï¼æ ¡éªIPå°åãMacå°åçå
¶ä»ä¿¡æ¯ |
| | | * |
| | | * @param |
| | | * @return de.schlichtherle.license.LicenseContent |
| | | */ |
| | | @Override |
| | | protected synchronized LicenseContent verify(final LicenseNotary notary) |
| | | throws Exception { |
| | | GenericCertificate certificate = getCertificate(); |
| | | |
| | | // Load license key from preferences, |
| | | final byte[] key = getLicenseKey(); |
| | | if (null == key) { |
| | | throw new NoLicenseInstalledException(getLicenseParam().getSubject()); |
| | | } |
| | | |
| | | certificate = getPrivacyGuard().key2cert(key); |
| | | notary.verify(certificate); |
| | | final LicenseContent content = (LicenseContent) this.load(certificate.getEncoded()); |
| | | this.validate(content); |
| | | setCertificate(certificate); |
| | | |
| | | return content; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªçæè¯ä¹¦çåæ°ä¿¡æ¯ |
| | | * |
| | | * @param content è¯ä¹¦æ£æ |
| | | */ |
| | | protected synchronized void validateCreate(final LicenseContent content) |
| | | throws LicenseContentException { |
| | | final LicenseParam param = getLicenseParam(); |
| | | |
| | | final Date now = new Date(); |
| | | final Date notBefore = content.getNotBefore(); |
| | | final Date notAfter = content.getNotAfter(); |
| | | if (null != notAfter && now.after(notAfter)) { |
| | | throw new LicenseContentException("è¯ä¹¦å¤±ææ¶é´ä¸è½æ©äºå½åæ¶é´"); |
| | | } |
| | | if (null != notBefore && null != notAfter && notAfter.before(notBefore)) { |
| | | throw new LicenseContentException("è¯ä¹¦çææ¶é´ä¸è½æäºè¯ä¹¦å¤±ææ¶é´"); |
| | | } |
| | | final String consumerType = content.getConsumerType(); |
| | | if (null == consumerType) { |
| | | throw new LicenseContentException("ç¨æ·ç±»åä¸è½ä¸ºç©º"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * å¤åvalidateæ¹æ³ï¼å¢å IPå°åãMacå°åçå
¶ä»ä¿¡æ¯æ ¡éª |
| | | * |
| | | * @param content LicenseContent |
| | | */ |
| | | @Override |
| | | protected synchronized void validate(final LicenseContent content) |
| | | throws LicenseContentException { |
| | | //1. é¦å
è°ç¨ç¶ç±»çvalidateæ¹æ³ |
| | | super.validate(content); |
| | | |
| | | //2. ç¶åæ ¡éªèªå®ä¹çLicenseåæ° |
| | | //Licenseä¸å¯è¢«å
许çåæ°ä¿¡æ¯ |
| | | LicenseCheckModel expectedCheckModel = (LicenseCheckModel) content.getExtra(); |
| | | //å½åæå¡å¨çå®çåæ°ä¿¡æ¯ |
| | | LicenseCheckModel serverCheckModel = getServerInfos(); |
| | | |
| | | if (expectedCheckModel != null && serverCheckModel != null) { |
| | | //æ ¡éªIPå°å |
| | | if (!checkIpAddress(expectedCheckModel.getIpAddress(), serverCheckModel.getIpAddress())) { |
| | | throw new LicenseContentException("å½åæå¡å¨çIPæ²¡å¨ææèå´å
"); |
| | | } |
| | | |
| | | //æ ¡éªMacå°å |
| | | if (!checkIpAddress(expectedCheckModel.getMacAddress(), serverCheckModel.getMacAddress())) { |
| | | throw new LicenseContentException("å½åæå¡å¨çMacå°åæ²¡å¨ææèå´å
"); |
| | | } |
| | | |
| | | //æ ¡éªä¸»æ¿åºåå· |
| | | if (!checkSerial(expectedCheckModel.getMainBoardSerial(), serverCheckModel.getMainBoardSerial())) { |
| | | throw new LicenseContentException("å½åæå¡å¨ç主æ¿åºåå·æ²¡å¨ææèå´å
"); |
| | | } |
| | | |
| | | //æ ¡éªCPUåºåå· |
| | | if (!checkSerial(expectedCheckModel.getCpuSerial(), serverCheckModel.getCpuSerial())) { |
| | | throw new LicenseContentException("å½åæå¡å¨çCPUåºåå·æ²¡å¨ææèå´å
"); |
| | | } |
| | | } else { |
| | | throw new LicenseContentException("ä¸è½è·åæå¡å¨ç¡¬ä»¶ä¿¡æ¯"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * éåXMLDecoderè§£æXML |
| | | * |
| | | * @param encoded XMLç±»åå符串 |
| | | * @return java.lang.Object |
| | | */ |
| | | private Object load(String encoded) { |
| | | BufferedInputStream inputStream = null; |
| | | XMLDecoder decoder = null; |
| | | try { |
| | | inputStream = new BufferedInputStream(new ByteArrayInputStream(encoded.getBytes(XML_CHARSET))); |
| | | |
| | | decoder = new XMLDecoder(new BufferedInputStream(inputStream, DEFAULT_BUFSIZE), null, null); |
| | | |
| | | return decoder.readObject(); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | if (decoder != null) { |
| | | decoder.close(); |
| | | } |
| | | if (inputStream != null) { |
| | | inputStream.close(); |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("XMLDecoderè§£æXML失败", e); |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * è·åå½åæå¡å¨éè¦é¢å¤æ ¡éªçLicenseåæ° |
| | | * |
| | | * @return demo.LicenseCheckModel |
| | | */ |
| | | private LicenseCheckModel getServerInfos() { |
| | | //æä½ç³»ç»ç±»å |
| | | String osName = System.getProperty("os.name").toLowerCase(); |
| | | AbstractServerInfos abstractServerInfos = null; |
| | | |
| | | //æ ¹æ®ä¸åæä½ç³»ç»ç±»åéæ©ä¸åçæ°æ®è·åæ¹æ³ |
| | | if (osName.startsWith("windows")) { |
| | | abstractServerInfos = new WindowsServerInfos(); |
| | | } else if (osName.startsWith("linux")) { |
| | | abstractServerInfos = new LinuxServerInfos(); |
| | | } else {//å
¶ä»æå¡å¨ç±»å |
| | | abstractServerInfos = new LinuxServerInfos(); |
| | | } |
| | | |
| | | return abstractServerInfos.getServerInfos(); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªå½åæå¡å¨çIP/Macå°åæ¯å¦å¨å¯è¢«å
许çIPèå´å
<br/> |
| | | * 妿åå¨IPå¨å¯è¢«å
许çIP/Macå°åèå´å
ï¼åè¿åtrue |
| | | * |
| | | * @return boolean |
| | | */ |
| | | private boolean checkIpAddress(List<String> expectedList, List<String> serverList) { |
| | | if (expectedList != null && expectedList.size() > 0) { |
| | | if (serverList != null && serverList.size() > 0) { |
| | | for (String expected : expectedList) { |
| | | if (serverList.contains(expected.trim())) { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } else { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªå½åæå¡å¨ç¡¬ä»¶ï¼ä¸»æ¿ãCPUçï¼åºåå·æ¯å¦å¨å¯å
许èå´å
|
| | | * |
| | | * @return boolean |
| | | */ |
| | | private boolean checkSerial(String expectedSerial, String serverSerial) { |
| | | if (StringUtils.isNotBlank(expectedSerial)) { |
| | | if (StringUtils.isNotBlank(serverSerial)) { |
| | | if (expectedSerial.equals(serverSerial)) { |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } else { |
| | | return true; |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license.entity; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName LicenseCheckModel |
| | | * @date 2024/11/2 16:00 |
| | | */ |
| | | @ApiModel("设å¤ä¿¡æ¯å®ä½ç±»") |
| | | public class LicenseCheckModel implements Serializable { |
| | | |
| | | private static final long serialVersionUID = -2314678441082223148L; |
| | | |
| | | @ApiModelProperty("å¯è¢«å
许çIPå°å") |
| | | private List<String> ipAddress; |
| | | |
| | | @ApiModelProperty("å¯è¢«å
许çMACå°å") |
| | | private List<String> macAddress; |
| | | |
| | | @ApiModelProperty("å¯è¢«å
许çCPUåºåå·") |
| | | private String cpuSerial; |
| | | |
| | | @ApiModelProperty("å¯è¢«å
许ç主æ¿åºåå·") |
| | | private String mainBoardSerial; |
| | | |
| | | public List<String> getIpAddress() { |
| | | return ipAddress; |
| | | } |
| | | |
| | | public void setIpAddress(List<String> ipAddress) { |
| | | this.ipAddress = ipAddress; |
| | | } |
| | | |
| | | public List<String> getMacAddress() { |
| | | return macAddress; |
| | | } |
| | | |
| | | public void setMacAddress(List<String> macAddress) { |
| | | this.macAddress = macAddress; |
| | | } |
| | | |
| | | public String getCpuSerial() { |
| | | return cpuSerial; |
| | | } |
| | | |
| | | public void setCpuSerial(String cpuSerial) { |
| | | this.cpuSerial = cpuSerial; |
| | | } |
| | | |
| | | public String getMainBoardSerial() { |
| | | return mainBoardSerial; |
| | | } |
| | | |
| | | public void setMainBoardSerial(String mainBoardSerial) { |
| | | this.mainBoardSerial = mainBoardSerial; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license.entity; |
| | | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName LicenseVerifyParam |
| | | * @date 2024/11/2 16:00 |
| | | */ |
| | | |
| | | public class LicenseVerifyParam { |
| | | |
| | | @ApiModelProperty("è¯ä¹¦subject") |
| | | private String subject; |
| | | |
| | | @ApiModelProperty("å
¬é¥å«ç§°") |
| | | private String publicAlias; |
| | | |
| | | @ApiModelProperty("访é®å
¬é¥åºçå¯ç ") |
| | | private String storePass; |
| | | |
| | | @ApiModelProperty("è¯ä¹¦çæè·¯å¾") |
| | | private String licensePath; |
| | | |
| | | @ApiModelProperty("å¯é¥åºåå¨è·¯å¾") |
| | | private String publicKeysStorePath; |
| | | |
| | | public String getSubject() { |
| | | return subject; |
| | | } |
| | | |
| | | public void setSubject(String subject) { |
| | | this.subject = subject; |
| | | } |
| | | |
| | | public String getPublicAlias() { |
| | | return publicAlias; |
| | | } |
| | | |
| | | public void setPublicAlias(String publicAlias) { |
| | | this.publicAlias = publicAlias; |
| | | } |
| | | |
| | | public String getStorePass() { |
| | | return storePass; |
| | | } |
| | | |
| | | public void setStorePass(String storePass) { |
| | | this.storePass = storePass; |
| | | } |
| | | |
| | | public String getLicensePath() { |
| | | return licensePath; |
| | | } |
| | | |
| | | public void setLicensePath(String licensePath) { |
| | | this.licensePath = licensePath; |
| | | } |
| | | |
| | | public String getPublicKeysStorePath() { |
| | | return publicKeysStorePath; |
| | | } |
| | | |
| | | public void setPublicKeysStorePath(String publicKeysStorePath) { |
| | | this.publicKeysStorePath = publicKeysStorePath; |
| | | } |
| | | } |
| | |
| | | filterChainDefinitionMap.put("/sys/getLoginQrcode/**", "anon"); //ç»å½äºç»´ç |
| | | filterChainDefinitionMap.put("/sys/getQrcodeToken/**", "anon"); //ç嬿«ç |
| | | filterChainDefinitionMap.put("/sys/checkAuth", "anon"); //æææ¥å£æé¤ |
| | | filterChainDefinitionMap.put("/base/license/**", "anon"); //çælicenseåè·åæå¡å¨ç¡¬ä»¶ä¿¡æ¯ |
| | | |
| | | |
| | | filterChainDefinitionMap.put("/", "anon"); |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.mdc.dto; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author Lius |
| | | * @date 2024/11/1 15:00 |
| | | */ |
| | | @Data |
| | | public class CurrentElectricDto { |
| | | /** |
| | | * ééæ¶é´ |
| | | */ |
| | | private Date collectTime; |
| | | /** |
| | | * 设å¤ç¼å· |
| | | */ |
| | | private String equipmentID; |
| | | /** |
| | | * daoè§£ææ°æ®ä½¿ç¨ |
| | | */ |
| | | private String currentValue; |
| | | |
| | | |
| | | } |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.system.vo.DictModel; |
| | | import org.jeecg.modules.mdc.dto.CurrentElectricHistoryDto; |
| | | import org.jeecg.modules.mdc.dto.CurrentElectricDto; |
| | | import org.jeecg.modules.mdc.dto.EquipmentMachiningHistoryDto; |
| | | import org.jeecg.modules.mdc.dto.MachineXYZHistoryDto; |
| | | import org.jeecg.modules.mdc.entity.Equipment; |
| | |
| | | private IEquipmentElectricStatisticalService equipmentElectricStatisticalService; |
| | | |
| | | @Resource |
| | | private ICurrentXYZHistoryService currentXYZHistoryService; |
| | | private IEquipmentWorkLineService equipmentWorkLineService; |
| | | |
| | | @Resource |
| | | private IMachineXYZHistoryService machineXYZHistoryService; |
| | | |
| | | @Resource |
| | | private IEquipmentMachiningHistoryService equipmentMachiningHistoryService; |
| | | private IEquipmentXYZService equipmentXYZService; |
| | | |
| | | @Override |
| | | public void execute(JobExecutionContext context) throws JobExecutionException { |
| | |
| | | List<DictModel> dictList = sysDictService.queryEnableDictItemsByCode(CommonConstant.AXIS_TYPE); |
| | | if (dictList != null && !dictList.isEmpty()) { |
| | | for (Equipment equipment : equipmentList) { |
| | | if (equipment.getDrivetype().equals("SIEMENSOpcUa")) { |
| | | String saveTableName = equipment.getSavetablename(); |
| | | Date lastDate = equipmentElectricStatisticalService.getMaxDate(equipment.getEquipmentid()); |
| | | if (lastDate == null) { |
| | | Date minCollectTime = currentXYZHistoryService.getMinDate(equipment.getEquipmentid()); |
| | | Date minCollectTime = equipmentWorkLineService.getMinDate(saveTableName); |
| | | if (minCollectTime == null) { |
| | | continue; |
| | | } |
| | | initDate = DateUtils.removeTime(minCollectTime); |
| | | } else { |
| | | initDate = DateUtils.plusTime(lastDate, 1); |
| | | } |
| | | for (DictModel dictModel : dictList) { |
| | | electricStatistical = new EquipmentElectricStatistical(); |
| | | Integer axisType = Integer.parseInt(dictModel.getValue()); |
| | | CurrentElectricHistoryDto currentElectricHistoryDto = currentXYZHistoryService.getMaxElectric(equipment.getEquipmentid(), axisType, initDate, DateUtils.plusTime(initDate, 1)); |
| | | if (currentElectricHistoryDto == null || currentElectricHistoryDto.getEquipmentID() == null || currentElectricHistoryDto.getCollectTime() == null) { |
| | | initDate = DateUtils.plusTime(initDate, 1); |
| | | CurrentElectricDto currentElectricDto = equipmentWorkLineService.getMaxElectric(saveTableName, axisType, initDate, DateUtils.plusTime(initDate, 1)); |
| | | if (currentElectricDto == null) { |
| | | continue; |
| | | } |
| | | electricStatistical.setAxistype(axisType); |
| | | electricStatistical.setEquipmentid(equipment.getEquipmentid()); |
| | | electricStatistical.setEquipmentname(equipment.getEquipmentname()); |
| | | electricStatistical.setElectrictime(currentElectricHistoryDto.getCollectTime()); |
| | | electricStatistical.setElectricvalue(currentElectricHistoryDto.getCurrentValue()); |
| | | electricStatistical.setElectrictime(currentElectricDto.getCollectTime()); |
| | | electricStatistical.setElectricvalue(currentElectricDto.getCurrentValue()); |
| | | electricStatistical.setCreatedate(initDate); |
| | | EquipmentMachiningHistoryDto machiningHistoryDto = equipmentMachiningHistoryService.getNearTimeSpindleLoad(equipment.getEquipmentid(), initDate, DateUtils.plusTime(initDate, 1), currentElectricHistoryDto.getCollectTime()); |
| | | EquipmentMachiningHistoryDto machiningHistoryDto = equipmentWorkLineService.getNearTimeSpindleLoad(saveTableName, initDate, DateUtils.plusTime(initDate, 1), currentElectricDto.getCollectTime()); |
| | | if (machiningHistoryDto != null) { |
| | | electricStatistical.setSpindlespeed(machiningHistoryDto.getSpindleSpeed()); |
| | | electricStatistical.setSpindleload(machiningHistoryDto.getSpindleLoad()); |
| | | electricStatistical.setSpindletime(machiningHistoryDto.getCollectTime()); |
| | | } |
| | | MachineXYZHistoryDto machineXYZHistoryDto = machineXYZHistoryService.getNearAxisType(equipment.getEquipmentid(), initDate, DateUtils.plusTime(initDate, 1), currentElectricHistoryDto.getCollectTime()); |
| | | MachineXYZHistoryDto machineXYZHistoryDto = equipmentXYZService.getNearAxisType(equipment.getEquipmentid(), initDate, DateUtils.plusTime(initDate, 1), currentElectricDto.getCollectTime()); |
| | | if (machineXYZHistoryDto != null) { |
| | | electricStatistical.setAxistime(machineXYZHistoryDto.getCollectTime()); |
| | | if (axisType == 1) { |
| | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(!resultList.isEmpty()) { |
| | | equipmentElectricStatisticalService.saveBatch(resultList); |
| | | } |
| | |
| | | import org.jeecg.modules.mdc.dto.MachineXYZHistoryDto; |
| | | import org.jeecg.modules.mdc.entity.Equipment; |
| | | import org.jeecg.modules.mdc.entity.EquipmentSpindleStatistical; |
| | | import org.jeecg.modules.mdc.service.IEquipmentMachiningHistoryService; |
| | | import org.jeecg.modules.mdc.service.IEquipmentService; |
| | | import org.jeecg.modules.mdc.service.IEquipmentSpindleStatisticalService; |
| | | import org.jeecg.modules.mdc.service.IMachineXYZHistoryService; |
| | | import org.jeecg.modules.mdc.service.*; |
| | | import org.jeecg.modules.mdc.util.DateUtils; |
| | | import org.jeecg.modules.mdc.util.ThrowableUtil; |
| | | import org.jeecg.modules.quartz.entity.QuartzJob; |
| | |
| | | @Resource |
| | | private IMachineXYZHistoryService machineXYZHistoryService; |
| | | |
| | | @Resource |
| | | private IEquipmentWorkLineService equipmentWorkLineService; |
| | | |
| | | @Resource |
| | | private IEquipmentXYZService equipmentXYZService; |
| | | |
| | | @Override |
| | | public void execute(JobExecutionContext context) throws JobExecutionException { |
| | | SysQuartzLog quartzLog = new SysQuartzLog(); |
| | |
| | | EquipmentSpindleStatistical spindleStatistical; |
| | | List<EquipmentSpindleStatistical> resultList = new ArrayList<>(); |
| | | for (Equipment equipment : equipmentList) { |
| | | if (!equipment.getDrivetype().equals("CurrentState")) { |
| | | String saveTableName = equipment.getSavetablename(); |
| | | Date lastDate = equipmentSpindleStatisticalService.getMaxDate(equipment.getEquipmentid()); |
| | | if (lastDate == null) { |
| | | Date minCollectTime = equipmentMachiningHistoryService.getMinDate(equipment.getEquipmentid()); |
| | | Date minCollectTime = equipmentWorkLineService.getMinDate(saveTableName); |
| | | if (minCollectTime == null) { |
| | | continue; |
| | | } |
| | | initDate = DateUtils.removeTime(minCollectTime); |
| | | } else { |
| | | initDate = DateUtils.plusTime(lastDate, 1); |
| | | } |
| | | |
| | | spindleStatistical = new EquipmentSpindleStatistical(); |
| | | EquipmentMachiningHistoryDto machiningHistoryDto = equipmentMachiningHistoryService.getMaxSpindleLoad(equipment.getEquipmentid(), initDate, DateUtils.plusTime(initDate, 1)); |
| | | EquipmentMachiningHistoryDto machiningHistoryDto = equipmentWorkLineService.getMaxSpindleLoad(saveTableName, initDate, DateUtils.plusTime(initDate, 1)); |
| | | if(machiningHistoryDto == null || machiningHistoryDto.getEquipmentID() == null || machiningHistoryDto.getCollectTime() == null) { |
| | | continue; |
| | | } |
| | |
| | | spindleStatistical.setEquipmentname(equipment.getEquipmentname()); |
| | | spindleStatistical.setSpindleload(machiningHistoryDto.getSpindleLoad()); |
| | | spindleStatistical.setSpindletime(machiningHistoryDto.getCollectTime()); |
| | | MachineXYZHistoryDto machineXYZHistoryDto = machineXYZHistoryService.getNearAxisType(equipment.getEquipmentid(), initDate, DateUtils.plusTime(initDate, 1), machiningHistoryDto.getCollectTime()); |
| | | MachineXYZHistoryDto machineXYZHistoryDto = equipmentXYZService.getNearAxisType(equipment.getEquipmentid(), initDate, DateUtils.plusTime(initDate, 1), machiningHistoryDto.getCollectTime()); |
| | | if(machineXYZHistoryDto != null) { |
| | | spindleStatistical.setAxistime(machineXYZHistoryDto.getCollectTime()); |
| | | spindleStatistical.setAxisx(machineXYZHistoryDto.getXMachine()); |
| | |
| | | } |
| | | resultList.add(spindleStatistical); |
| | | } |
| | | } |
| | | if (!resultList.isEmpty()) { |
| | | equipmentSpindleStatisticalService.saveBatch(resultList); |
| | | } |
| | |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.apache.ibatis.annotations.Select; |
| | | import org.jeecg.modules.mdc.dto.CurrentElectricDto; |
| | | import org.jeecg.modules.mdc.dto.EquipmentMachingDto; |
| | | import org.jeecg.modules.mdc.dto.EquipmentMachiningHistoryDto; |
| | | import org.jeecg.modules.mdc.dto.MdcEquipmentDto; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | |
| | | |
| | | @InterceptorIgnore(tenantLine = "1") |
| | | Map<String, Object> getDataList(@Param("tableName") String saveTableName); |
| | | |
| | | @InterceptorIgnore(tenantLine = "1") |
| | | Date getMinDate(@Param("tableName") String saveTableName); |
| | | |
| | | @InterceptorIgnore(tenantLine = "1") |
| | | CurrentElectricDto getMaxElectric(@Param("tableName") String saveTableName, @Param("axisType") Integer axisType, @Param("startDate") Date startDate, @Param("endDate") Date endDate); |
| | | |
| | | @InterceptorIgnore(tenantLine = "1") |
| | | EquipmentMachiningHistoryDto getNearTimeSpindleLoad(@Param("tableName") String tableName, @Param("startDate")Date startDate, @Param("endDate")Date endDate, @Param("nearDate")Date nearDate); |
| | | |
| | | @InterceptorIgnore(tenantLine = "1") |
| | | EquipmentMachiningHistoryDto getMaxSpindleLoad(@Param("tableName") String tableName, @Param("startDate")Date startDate, @Param("endDate")Date endDate); |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.jeecg.modules.mdc.dto.MachineXYZHistoryDto; |
| | | import org.jeecg.modules.mdc.entity.EquipmentXYZ; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author: LiuS |
| | |
| | | public interface EquipmentXYZMapper extends BaseMapper<EquipmentXYZ> { |
| | | |
| | | EquipmentXYZ findByEquipmentId(@Param("equipmentId") String equipmentId); |
| | | |
| | | MachineXYZHistoryDto getNearAxisType(@Param("equipmentId") String equipmentId, @Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("nearDate") Date nearDate); |
| | | } |
| | |
| | | <select id="getDataList" resultType="java.util.Map"> |
| | | select top 1 [${tableName}].* from [${tableName}] order by CollectTime desc |
| | | </select> |
| | | |
| | | <select id="getMinDate" resultType="java.util.Date"> |
| | | SELECT TOP 1 CollectTime from [${tableName}] ORDER BY CollectTime ASC |
| | | </select> |
| | | |
| | | <select id="getMaxElectric" resultType="org.jeecg.modules.mdc.dto.CurrentElectricDto"> |
| | | SELECT TOP 1 |
| | | <if test="axisType != null and axisType != '' and axisType == 1"> |
| | | ABS( actualCurrentX ) currentValue, |
| | | EquipmentID, |
| | | CollectTime |
| | | </if> |
| | | <if test="axisType != null and axisType != '' and axisType == 2"> |
| | | ABS( actualCurrentY ) currentValue, |
| | | EquipmentID, |
| | | CollectTime |
| | | </if> |
| | | <if test="axisType != null and axisType != '' and axisType == 3"> |
| | | ABS( actualCurrentZ ) currentValue, |
| | | EquipmentID, |
| | | CollectTime |
| | | </if> |
| | | <if test="axisType != null and axisType != '' and axisType == 4"> |
| | | ABS( actualCurrentA ) currentValue, |
| | | EquipmentID, |
| | | CollectTime |
| | | </if> |
| | | <if test="axisType != null and axisType != '' and axisType == 5"> |
| | | ABS( actualCurrentB ) currentValue, |
| | | EquipmentID, |
| | | CollectTime |
| | | </if> |
| | | FROM |
| | | [${tableName}] |
| | | WHERE |
| | | <if test="axisType != null and axisType != '' and axisType == 1"> |
| | | ABS( actualCurrentX ) = ( SELECT MAX ( ABS( actualCurrentX ) ) currentValue FROM [${tableName}] WHERE CollectTime BETWEEN #{startDate} AND #{endDate} ) |
| | | </if> |
| | | <if test="axisType != null and axisType != '' and axisType == 2"> |
| | | ABS( actualCurrentY ) = ( SELECT MAX ( ABS( actualCurrentY ) ) currentValue FROM [${tableName}] WHERE CollectTime BETWEEN #{startDate} AND #{endDate} ) |
| | | </if> |
| | | <if test="axisType != null and axisType != '' and axisType == 3"> |
| | | ABS( actualCurrentZ ) = ( SELECT MAX ( ABS( actualCurrentZ ) ) currentValue FROM [${tableName}] WHERE CollectTime BETWEEN #{startDate} AND #{endDate} ) |
| | | </if> |
| | | <if test="axisType != null and axisType != '' and axisType == 4"> |
| | | ABS( actualCurrentA ) = ( SELECT MAX ( ABS( actualCurrentA ) ) currentValue FROM [${tableName}] WHERE CollectTime BETWEEN #{startDate} AND #{endDate} ) |
| | | </if> |
| | | <if test="axisType != null and axisType != '' and axisType == 5"> |
| | | ABS( actualCurrentB ) = ( SELECT MAX ( ABS( actualCurrentB ) ) currentValue FROM [${tableName}] WHERE CollectTime BETWEEN #{startDate} AND #{endDate} ) |
| | | </if> |
| | | </select> |
| | | |
| | | <select id="getNearTimeSpindleLoad" resultType="org.jeecg.modules.mdc.dto.EquipmentMachiningHistoryDto"> |
| | | SELECT TOP 1 |
| | | CollectTime collectTime, |
| | | spindleload, |
| | | spindlespeed |
| | | FROM |
| | | [${tableName}] |
| | | WHERE |
| | | CollectTime BETWEEN #{startDate} AND #{endDate} |
| | | ORDER BY |
| | | ABS( DATEDIFF( SECOND, CollectTime, #{nearDate} ) ) |
| | | </select> |
| | | |
| | | <select id="getMaxSpindleLoad" resultType="org.jeecg.modules.mdc.dto.EquipmentMachiningHistoryDto"> |
| | | SELECT TOP 1 |
| | | CollectTime collectTime, |
| | | EquipmentID equipmentID, |
| | | spindleload spindleLoad, |
| | | spindlespeed spindleSpeed |
| | | FROM |
| | | [${tableName}] |
| | | WHERE |
| | | ABS( spindleload ) = ( SELECT MAX ( ABS( spindleload ) ) spindleload FROM [${tableName}] WHERE CollectTime BETWEEN #{startDate} AND #{endDate} ) |
| | | </select> |
| | | </mapper> |
| | |
| | | ORDER BY |
| | | CollectTime DESC |
| | | </select> |
| | | |
| | | <select id="getNearAxisType" resultType="org.jeecg.modules.mdc.dto.MachineXYZHistoryDto"> |
| | | SELECT TOP 1 |
| | | CollectTime collectTime, |
| | | EquipmentID equipmentID, |
| | | Xmachine xMachine, |
| | | Ymachine yMachine, |
| | | Zmachine zMachine, |
| | | Amachine aMachine, |
| | | Bmachine bMachine |
| | | FROM |
| | | EquipmentXYZ |
| | | WHERE |
| | | EquipmentID = #{equipmentId} |
| | | AND CollectTime BETWEEN #{startDate} AND #{endDate} |
| | | ORDER BY |
| | | ABS( DATEDIFF( SECOND, CollectTime, #{nearDate} ) ) |
| | | </select> |
| | | </mapper> |
| | |
| | | package org.jeecg.modules.mdc.service; |
| | | |
| | | import org.jeecg.modules.mdc.dto.CurrentElectricDto; |
| | | import org.jeecg.modules.mdc.dto.EquipmentMachingDto; |
| | | import org.jeecg.modules.mdc.dto.EquipmentMachiningHistoryDto; |
| | | import org.jeecg.modules.mdc.dto.MdcEquipmentDto; |
| | | |
| | | import java.util.Date; |
| | |
| | | |
| | | /** |
| | | * æ¥æ¾æ³å
°å
设å¤è¿è¡çç¨åºå· |
| | | * |
| | | * @param drivetype |
| | | * @param equipmentid |
| | | * @param startTime |
| | |
| | | |
| | | /** |
| | | * æ¥è¯¢æ³æå
设å¤å 工工件å¼å§æ¶é´ |
| | | * |
| | | * @param saveTableName |
| | | * @param productCount |
| | | * @return |
| | |
| | | |
| | | /** |
| | | * æ¥è¯¢æ³æå
设å¤å å·¥å·¥ä»¶ç»ææ¶é´ |
| | | * |
| | | * @param saveTableName |
| | | * @param productCount |
| | | * @return |
| | |
| | | |
| | | /** |
| | | * è·å设å¤è¿è¡æ°æ® |
| | | * |
| | | * @param saveTableName |
| | | * @return |
| | | */ |
| | | Map<String, Object> getDataList(String saveTableName); |
| | | |
| | | /** |
| | | * æ¥è¯¢åè¡¨ç¬¬ä¸æ¡æ°æ®æ¶é´ |
| | | * |
| | | * @param saveTableName |
| | | * @return |
| | | */ |
| | | Date getMinDate(String saveTableName); |
| | | |
| | | /** |
| | | * æ¥è¯¢è½´æå¤§çµæµ |
| | | * |
| | | * @param saveTableName |
| | | * @param axisType |
| | | * @param startDate |
| | | * @param endDate |
| | | * @return |
| | | */ |
| | | CurrentElectricDto getMaxElectric(String saveTableName, Integer axisType, Date startDate, Date endDate); |
| | | |
| | | /** |
| | | * æ¥è¯¢æ¶é´ç¹æè¿ç䏿¡æ°æ® |
| | | * |
| | | * @param tableName |
| | | * @param startDate |
| | | * @param endDate |
| | | * @param nearDate |
| | | * @return |
| | | */ |
| | | EquipmentMachiningHistoryDto getNearTimeSpindleLoad(String tableName, Date startDate, Date endDate, Date nearDate); |
| | | |
| | | /** |
| | | * æ¥è¯¢æå¤§ä¸»è½´è´è½½ |
| | | * |
| | | * @param tableName |
| | | * @param startDate |
| | | * @param endDate |
| | | * @return |
| | | */ |
| | | EquipmentMachiningHistoryDto getMaxSpindleLoad(String tableName, Date startDate, Date endDate); |
| | | } |
| | |
| | | package org.jeecg.modules.mdc.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import org.jeecg.modules.mdc.dto.MachineXYZHistoryDto; |
| | | import org.jeecg.modules.mdc.entity.EquipmentXYZ; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author: LiuS |
| | |
| | | EquipmentXYZ getByEquipmentId(String equipmentId); |
| | | |
| | | EquipmentXYZ findByEquipmentId(String equipmentId); |
| | | |
| | | MachineXYZHistoryDto getNearAxisType(String equipmentId, Date startDate, Date endDate, Date nearDate); |
| | | } |
| | |
| | | package org.jeecg.modules.mdc.service.impl; |
| | | |
| | | import org.jeecg.modules.mdc.dto.CurrentElectricDto; |
| | | import org.jeecg.modules.mdc.dto.EquipmentMachingDto; |
| | | import org.jeecg.modules.mdc.dto.EquipmentMachiningHistoryDto; |
| | | import org.jeecg.modules.mdc.dto.MdcEquipmentDto; |
| | | import org.jeecg.modules.mdc.mapper.EquipmentWorklineMapper; |
| | | import org.jeecg.modules.mdc.service.IEquipmentWorkLineService; |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Date getMinDate(String saveTableName) { |
| | | try { |
| | | return equipmentWorkLineMapper.getMinDate(saveTableName); |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public CurrentElectricDto getMaxElectric(String saveTableName, Integer axisType, Date startDate, Date endDate) { |
| | | return equipmentWorkLineMapper.getMaxElectric(saveTableName, axisType, startDate, endDate); |
| | | } |
| | | |
| | | @Override |
| | | public EquipmentMachiningHistoryDto getNearTimeSpindleLoad(String tableName, Date startDate, Date endDate, Date nearDate) { |
| | | return equipmentWorkLineMapper.getNearTimeSpindleLoad(tableName, startDate, endDate, nearDate); |
| | | } |
| | | |
| | | @Override |
| | | public EquipmentMachiningHistoryDto getMaxSpindleLoad(String tableName, Date startDate, Date endDate) { |
| | | return equipmentWorkLineMapper.getMaxSpindleLoad(tableName, startDate, endDate); |
| | | } |
| | | |
| | | private List<EquipmentMachingDto> convertData(List<Map<String, Object>> list) { |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); |
| | | List<EquipmentMachingDto> dto = new ArrayList<>(); |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.jeecg.modules.mdc.dto.MachineXYZHistoryDto; |
| | | import org.jeecg.modules.mdc.entity.EquipmentXYZ; |
| | | import org.jeecg.modules.mdc.mapper.EquipmentXYZMapper; |
| | | import org.jeecg.modules.mdc.service.IEquipmentXYZService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author: LiuS |
| | |
| | | public EquipmentXYZ findByEquipmentId(String equipmentId) { |
| | | return this.baseMapper.findByEquipmentId(equipmentId); |
| | | } |
| | | |
| | | @Override |
| | | public MachineXYZHistoryDto getNearAxisType(String equipmentId, Date startDate, Date endDate, Date nearDate) { |
| | | return this.baseMapper.getNearAxisType(equipmentId, startDate, endDate, nearDate); |
| | | } |
| | | } |
| | |
| | | } |
| | | queryWrapper.orderByAsc(MdcEquipment::getEquipmentName); |
| | | List<MdcEquipment> equipmentList = mdcEquipmentService.list(queryWrapper); |
| | | |
| | | vo.setStartTime(DateUtils.format(DateUtils.toDate(vo.getStartTime(), DateUtils.STRDATE), DateUtils.STR_DATE)); |
| | | vo.setEndTime(DateUtils.format(DateUtils.toDate(vo.getEndTime(), DateUtils.STRDATE), DateUtils.STR_DATE)); |
| | | //æ¥è¯¢oeeæ°æ® |
| | | List<MdcOeeInfo> oeeList = this.baseMapper.oeeList(vo); |
| | | //æ°æ®å¤ç |
| | |
| | | BigDecimal oeeRate = BigDecimal.ZERO; |
| | | if (!mdcOeeInfoList.isEmpty()) { |
| | | BigDecimal count = mdcOeeInfoList.stream().map(MdcOeeInfo::getOeeRate).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | oeeRate = count.divide(new BigDecimal(mdcOeeInfoList.size()), 2, RoundingMode.HALF_UP); |
| | | oeeRate = count.divide(new BigDecimal(mdcOeeInfoList.size()), 4, RoundingMode.HALF_UP); |
| | | mdcOeeResultDto.setOeeRate(oeeRate); |
| | | } |
| | | long rate = oeeRate.multiply(new BigDecimal("100")).longValue(); |
| | |
| | | .eq(MdcProductDayschedule::getEquipmentId, equipment.getEquipmentid())); |
| | | if (productDayScheduleList != null && !productDayScheduleList.isEmpty()) { |
| | | MdcProductDayschedule mdcProductDayschedule; |
| | | MdcOeeInfo mdcOeeInfo = new MdcOeeInfo(); |
| | | for (MdcShiftSub mdcShiftSub : mdcShiftSubList) { |
| | | MdcOeeInfo mdcOeeInfo = new MdcOeeInfo(); |
| | | String id = mdcShiftSub.getId(); |
| | | if (productDayScheduleList.stream().anyMatch(productDayschedule -> productDayschedule.getOrderId().substring(8, 10).equals(id))) { |
| | | mdcOeeInfo.setEquipmentId(equipment.getEquipmentid()); |
| | |
| | | continue; |
| | | } |
| | | mdcOeeInfo.setScheduleNum(mdcComponentInfo.getScheduleNum()); |
| | | |
| | | BigDecimal oeeRate = mdcOeeInfo.getProcessLong().multiply(new BigDecimal(mdcOeeInfo.getPlanNum())).multiply(new BigDecimal(mdcOeeInfo.getQualityNum())) |
| | | .divide(mdcEquipmentStatisticalShiftInfo.getTotalLong(), 2, RoundingMode.HALF_UP) |
| | | .divide(new BigDecimal(mdcOeeInfo.getScheduleNum()), 2, RoundingMode.HALF_UP) |
| | | .divide(new BigDecimal(mdcOeeInfo.getCompleteNum()), 2, RoundingMode.HALF_UP); |
| | | BigDecimal oeeRate = BigDecimal.ZERO; |
| | | if (!mdcOeeInfo.getCompleteNum().equals(0)) { |
| | | oeeRate = mdcOeeInfo.getProcessLong().multiply(new BigDecimal(mdcOeeInfo.getPlanNum())).multiply(new BigDecimal(mdcOeeInfo.getQualityNum())) |
| | | .divide(mdcEquipmentStatisticalShiftInfo.getTotalLong(), 4, RoundingMode.HALF_UP) |
| | | .divide(new BigDecimal(mdcOeeInfo.getScheduleNum()), 4, RoundingMode.HALF_UP) |
| | | .divide(new BigDecimal(mdcOeeInfo.getCompleteNum()), 4, RoundingMode.HALF_UP); |
| | | } |
| | | mdcOeeInfo.setOeeRate(oeeRate); |
| | | result.add(mdcOeeInfo); |
| | | } |
| | |
| | | this.saveBatch(result); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | equipmentRateDto.setEquipmentName(mdcEfficiencyDto.getEquipmentName()); |
| | | equipmentRateDto.setOpenRate(mdcEfficiencyDto.getOpenRate().multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); |
| | | equipmentRateDto.setUtilizationRate(mdcEfficiencyDto.getUtilizationRate().multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); |
| | | if (!equipmentRateDto.getOpenRate().equals(BigDecimal.ZERO) || !equipmentRateDto.getUtilizationRate().equals(BigDecimal.ZERO)) { |
| | | if (!(equipmentRateDto.getOpenRate().compareTo(BigDecimal.ZERO) == 0) && !(equipmentRateDto.getUtilizationRate().compareTo(BigDecimal.ZERO) == 0)) { |
| | | result.add(equipmentRateDto); |
| | | } |
| | | } |
| | |
| | | meu.setDate(new StringBuilder(mdcEfficiencyDto.getTheDate().substring(4, 8)).insert(2, "-").toString()); |
| | | BigDecimal equipmentCount = mdcLargeScreenMapper.findEquipmentCount(yesterday); |
| | | meu.setUtilizationRate(mdcEfficiencyDto.getProcessLong().divide(equipmentCount.multiply(new BigDecimal("86400")), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); |
| | | if (!meu.getUtilizationRate().equals(BigDecimal.ZERO)) { |
| | | if (!(meu.getUtilizationRate().compareTo(BigDecimal.ZERO) == 0)) { |
| | | result.add(meu); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license; |
| | | |
| | | import de.schlichtherle.license.*; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.jeecg.config.license.entity.CustomLicenseManager; |
| | | |
| | | import javax.security.auth.x500.X500Principal; |
| | | import java.io.File; |
| | | import java.text.MessageFormat; |
| | | import java.util.prefs.Preferences; |
| | | |
| | | /** |
| | | * @Author: ljh |
| | | * @ClassName LicenseCreator |
| | | * @Description TODO |
| | | * @date 2022/12/9 11:14 |
| | | * @Version 1.0 |
| | | */ |
| | | |
| | | public class LicenseCreator { |
| | | |
| | | private static Logger logger = LogManager.getLogger(LicenseCreator.class); |
| | | private final static X500Principal DEFAULT_HOLDER_AND_ISSUER = new X500Principal("CN=localhost, OU=localhost, O=localhost, L=SH, ST=SH, C=CN"); |
| | | private LicenseCreatorParam param; |
| | | |
| | | public LicenseCreator(LicenseCreatorParam param) { |
| | | this.param = param; |
| | | } |
| | | |
| | | /** |
| | | * çæLicenseè¯ä¹¦ |
| | | * |
| | | * @return boolean |
| | | */ |
| | | public boolean generateLicense() { |
| | | try { |
| | | LicenseManager licenseManager = new CustomLicenseManager(initLicenseParam()); |
| | | LicenseContent licenseContent = initLicenseContent(); |
| | | |
| | | licenseManager.store(licenseContent, new File(param.getLicensePath())); |
| | | |
| | | return true; |
| | | } catch (Exception e) { |
| | | logger.error(MessageFormat.format("è¯ä¹¦çæå¤±è´¥ï¼{0}", param), e); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åå§åè¯ä¹¦çæåæ° |
| | | * |
| | | * @return de.schlichtherle.license.LicenseParam |
| | | */ |
| | | private LicenseParam initLicenseParam() { |
| | | Preferences preferences = Preferences.userNodeForPackage(LicenseCreator.class); |
| | | |
| | | //设置对è¯ä¹¦å
容å å¯çç§é¥ |
| | | CipherParam cipherParam = new DefaultCipherParam(param.getStorePass()); |
| | | |
| | | KeyStoreParam privateStoreParam = new CustomKeyStoreParam(LicenseCreator.class |
| | | , param.getPrivateKeysStorePath() |
| | | , param.getPrivateAlias() |
| | | , param.getStorePass() |
| | | , param.getKeyPass()); |
| | | |
| | | LicenseParam licenseParam = new DefaultLicenseParam(param.getSubject() |
| | | , preferences |
| | | , privateStoreParam |
| | | , cipherParam); |
| | | |
| | | return licenseParam; |
| | | } |
| | | |
| | | /** |
| | | * 设置è¯ä¹¦çææ£æä¿¡æ¯ |
| | | * |
| | | * @return de.schlichtherle.license.LicenseContent |
| | | */ |
| | | private LicenseContent initLicenseContent() { |
| | | LicenseContent licenseContent = new LicenseContent(); |
| | | licenseContent.setHolder(DEFAULT_HOLDER_AND_ISSUER); |
| | | licenseContent.setIssuer(DEFAULT_HOLDER_AND_ISSUER); |
| | | |
| | | licenseContent.setSubject(param.getSubject()); |
| | | licenseContent.setIssued(param.getIssuedTime()); |
| | | licenseContent.setNotBefore(param.getIssuedTime()); |
| | | licenseContent.setNotAfter(param.getExpiryTime()); |
| | | licenseContent.setConsumerType(param.getConsumerType()); |
| | | licenseContent.setConsumerAmount(param.getConsumerAmount()); |
| | | licenseContent.setInfo(param.getDescription()); |
| | | |
| | | //æ©å±æ ¡éªæå¡å¨ç¡¬ä»¶ä¿¡æ¯ |
| | | licenseContent.setExtra(param.getLicenseCheckModel()); |
| | | |
| | | return licenseContent; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.config.license; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import org.jeecg.config.license.entity.LicenseCheckModel; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName LicenseCreatorParam |
| | | * @date 2024/11/2 17:02 |
| | | */ |
| | | @ApiModel("çæè¯ä¹¦å®ä½ç±»") |
| | | public class LicenseCreatorParam implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 2832129012982731724L; |
| | | |
| | | @ApiModelProperty("è¯ä¹¦subject") |
| | | private String subject; |
| | | |
| | | @ApiModelProperty("å¯é¥å«ç§°") |
| | | private String privateAlias; |
| | | |
| | | @ApiModelProperty("å¯é¥å¯ç ") |
| | | private String keyPass; |
| | | |
| | | @ApiModelProperty("访é®ç§é¥åºçå¯ç ") |
| | | private String storePass; |
| | | |
| | | @ApiModelProperty("è¯ä¹¦çæè·¯å¾") |
| | | private String licensePath; |
| | | |
| | | @ApiModelProperty("å¯é¥åºåå¨è·¯å¾") |
| | | private String privateKeysStorePath; |
| | | |
| | | |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | @ApiModelProperty("è¯ä¹¦çææ¶é´") |
| | | private Date issuedTime = new Date(); |
| | | |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | @ApiModelProperty("è¯ä¹¦å¤±ææ¶é´") |
| | | private Date expiryTime; |
| | | |
| | | @ApiModelProperty("ç¨æ·ç±»å") |
| | | private String consumerType = "user"; |
| | | |
| | | @ApiModelProperty("ç¨æ·æ°é") |
| | | private Integer consumerAmount = 1; |
| | | |
| | | @ApiModelProperty("æè¿°ä¿¡æ¯") |
| | | private String description = ""; |
| | | |
| | | @ApiModelProperty("é¢å¤çæå¡å¨ç¡¬ä»¶æ ¡éªä¿¡æ¯") |
| | | private LicenseCheckModel licenseCheckModel; |
| | | |
| | | public String getSubject() { |
| | | return subject; |
| | | } |
| | | |
| | | public void setSubject(String subject) { |
| | | this.subject = subject; |
| | | } |
| | | |
| | | public String getPrivateAlias() { |
| | | return privateAlias; |
| | | } |
| | | |
| | | public void setPrivateAlias(String privateAlias) { |
| | | this.privateAlias = privateAlias; |
| | | } |
| | | |
| | | public String getKeyPass() { |
| | | return keyPass; |
| | | } |
| | | |
| | | public void setKeyPass(String keyPass) { |
| | | this.keyPass = keyPass; |
| | | } |
| | | |
| | | public String getStorePass() { |
| | | return storePass; |
| | | } |
| | | |
| | | public void setStorePass(String storePass) { |
| | | this.storePass = storePass; |
| | | } |
| | | |
| | | public String getLicensePath() { |
| | | return licensePath; |
| | | } |
| | | |
| | | public void setLicensePath(String licensePath) { |
| | | this.licensePath = licensePath; |
| | | } |
| | | |
| | | public String getPrivateKeysStorePath() { |
| | | return privateKeysStorePath; |
| | | } |
| | | |
| | | public void setPrivateKeysStorePath(String privateKeysStorePath) { |
| | | this.privateKeysStorePath = privateKeysStorePath; |
| | | } |
| | | |
| | | public Date getIssuedTime() { |
| | | return issuedTime; |
| | | } |
| | | |
| | | public void setIssuedTime(Date issuedTime) { |
| | | this.issuedTime = issuedTime; |
| | | } |
| | | |
| | | public Date getExpiryTime() { |
| | | return expiryTime; |
| | | } |
| | | |
| | | public void setExpiryTime(Date expiryTime) { |
| | | this.expiryTime = expiryTime; |
| | | } |
| | | |
| | | public String getConsumerType() { |
| | | return consumerType; |
| | | } |
| | | |
| | | public void setConsumerType(String consumerType) { |
| | | this.consumerType = consumerType; |
| | | } |
| | | |
| | | public Integer getConsumerAmount() { |
| | | return consumerAmount; |
| | | } |
| | | |
| | | public void setConsumerAmount(Integer consumerAmount) { |
| | | this.consumerAmount = consumerAmount; |
| | | } |
| | | |
| | | public String getDescription() { |
| | | return description; |
| | | } |
| | | |
| | | public void setDescription(String description) { |
| | | this.description = description; |
| | | } |
| | | |
| | | public LicenseCheckModel getLicenseCheckModel() { |
| | | return licenseCheckModel; |
| | | } |
| | | |
| | | public void setLicenseCheckModel(LicenseCheckModel licenseCheckModel) { |
| | | this.licenseCheckModel = licenseCheckModel; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.base.controller; |
| | | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | import org.jeecg.config.license.*; |
| | | import org.jeecg.config.license.entity.LicenseCheckModel; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @ClassName LicenseController |
| | | * @date 2024/11/2 17:35 |
| | | */ |
| | | @Slf4j |
| | | @Api(tags = "licenseè¯ä¹¦") |
| | | @RestController |
| | | @RequestMapping("/base/license") |
| | | public class LicenseController { |
| | | |
| | | /** |
| | | * è¯ä¹¦çæè·¯å¾ |
| | | */ |
| | | @Value("${license.licensePath}") |
| | | private String licensePath; |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @Description: è·åæå¡å¨ç¡¬ä»¶ä¿¡æ¯ |
| | | * @DateTime: 17:35 2024/11/2 |
| | | * @Params: osName ç³»ç»ç±»å windowsælinux |
| | | * @Return |
| | | */ |
| | | @AutoLog(value = "è·åæå¡å¨ç¡¬ä»¶ä¿¡æ¯") |
| | | @ApiOperation("è·åæå¡å¨ç¡¬ä»¶ä¿¡æ¯") |
| | | @GetMapping("/getServerInfos/{osName}") |
| | | public LicenseCheckModel getServerInfos(@PathVariable String osName) { |
| | | //æä½ç³»ç»ç±»å |
| | | if (StringUtils.isBlank(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 LinuxServerInfos(); |
| | | } |
| | | |
| | | return abstractServerInfos.getServerInfos(); |
| | | } |
| | | |
| | | /** |
| | | * @Author: lius |
| | | * @Description: çæè¯ä¹¦ |
| | | * @DateTime: 17:35 2024/11/2 |
| | | */ |
| | | @AutoLog(value = "çæè¯ä¹¦") |
| | | @ApiOperation("çæè¯ä¹¦") |
| | | @PostMapping("/generateLicense") |
| | | public Map<String, Object> generateLicense(@RequestBody LicenseCreatorParam param) { |
| | | Map<String, Object> resultMap = new HashMap<>(2); |
| | | |
| | | if (StringUtils.isBlank(param.getLicensePath())) { |
| | | param.setLicensePath(licensePath); |
| | | } |
| | | |
| | | LicenseCreator licenseCreator = new LicenseCreator(param); |
| | | boolean result = licenseCreator.generateLicense(); |
| | | |
| | | if (result) { |
| | | resultMap.put("result", "ok"); |
| | | resultMap.put("msg", param); |
| | | } else { |
| | | resultMap.put("result", "error"); |
| | | resultMap.put("msg", "è¯ä¹¦æä»¶çæå¤±è´¥ï¼"); |
| | | } |
| | | |
| | | return resultMap; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 |
| | | datasource: |
| | | master: |
| | | url: jdbc:sqlserver://192.168.124.118:1433;databasename=LXZN_TEST_YITUO |
| | | url: jdbc:sqlserver://localhost:1433;databasename=LXZN_MDC_YITUO |
| | | # url: jdbc:sqlserver://192.168.124.118:1433;databasename=LXZN_TEST_YITUO |
| | | username: sa |
| | | password: 123 |
| | | driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver |
| | | mesSoAdb: |
| | | url: jdbc:sqlserver://192.168.124.118:1433;databasename=SOADB |
| | | username: sa |
| | | password: 123 |
| | | driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver |
| | | # mesSoAdb: |
| | | # url: jdbc:sqlserver://192.168.124.118:1433;databasename=SOADB |
| | | # username: sa |
| | | # password: 123 |
| | | # driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver |
| | | #redis é
ç½® |
| | | redis: |
| | | database: 0 |
| | |
| | | namespace: http://service.server.webservice.example.com |
| | | statusMethod: equipmentStatus |
| | | rateMethod: equipmentRate |
| | | license: |
| | | subject: license_lyyt |
| | | publicAlias: publicCert |
| | | storePass: lxzn1688 |
| | | licensePath: F:/license/license.lic |
| | | publicKeysStorePath: F:/license/publicCerts.keystore |
| | | uploadPath: F:/LicenseDemo/ |