PsychologicalApplication.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package com.rf.psychological;
  2. import com.querydsl.jpa.impl.JPAQueryFactory;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.beans.factory.annotation.Value;
  8. import org.springframework.boot.SpringApplication;
  9. import org.springframework.boot.autoconfigure.SpringBootApplication;
  10. import org.springframework.boot.web.client.RestTemplateBuilder;
  11. import org.springframework.context.annotation.Bean;
  12. import org.springframework.core.env.Environment;
  13. import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
  14. import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  15. import org.springframework.scheduling.annotation.EnableScheduling;
  16. import org.springframework.transaction.annotation.EnableTransactionManagement;
  17. import org.springframework.web.client.RestTemplate;
  18. import javax.persistence.EntityManager;
  19. /**
  20. * @author zzf
  21. */
  22. //@EnableCaching
  23. @EnableJpaRepositories(basePackages = {"com.rf.psychological"})
  24. @SpringBootApplication(scanBasePackages = {"com.rf.psychological"})
  25. @EnableJpaAuditing
  26. @EnableTransactionManagement
  27. @EnableScheduling
  28. @Slf4j
  29. //@EnableSwagger2
  30. public class PsychologicalApplication {
  31. static Logger logger = LoggerFactory.getLogger(PsychologicalApplication.class);
  32. @Autowired
  33. static Environment environment;
  34. @Value("${spring.profiles.active}")
  35. static String profile;
  36. @Autowired
  37. private RestTemplateBuilder builder;
  38. @Bean
  39. public RestTemplate restTemplate(){
  40. return builder.build();
  41. }
  42. public static void main(String[] args) throws Exception {
  43. //检查环境
  44. //System.out.println("profile--"+profile);
  45. //System.out.println("env--"+environment.getActiveProfiles()[0]);
  46. /*if (PsychologicalApplication.checkDog()){
  47. }else {
  48. return;
  49. }*/
  50. SpringApplication.run(PsychologicalApplication.class, args);
  51. /*if (CPUSerial.getDiskdriveAndCsproductUUID().equals(Constant.DEFAULT_PZ_UUID)){
  52. }else {
  53. System.out.println("无权限启动");
  54. }*/
  55. }
  56. private static boolean checkDog() {
  57. System.out.println(System.getProperty("java.library.path"));
  58. int ret;
  59. SoftKey ytsoftkey = new SoftKey();
  60. String DevicePath;
  61. DevicePath = ytsoftkey.FindPort(0);
  62. if(ytsoftkey.get_LastError()!=0)
  63. {
  64. System.out.println("未找到加密锁,请插入加密锁后,再进行操作。");
  65. logger.error("未找到加密锁,请插入加密锁后,再进行操作。");
  66. return false;
  67. }
  68. if (ytsoftkey.CheckKeyByFindort_2() == 0)
  69. {
  70. System.out.println("使用普通算法一来检查:找到指定的加密锁");
  71. logger.info("使用普通算法一来检查:找到指定的加密锁");
  72. }
  73. else
  74. {
  75. logger.error("使用普通算法一来检查:未能找到指定的加密锁");
  76. System.out.println("使用普通算法一来检查:未能找到指定的加密锁");
  77. return false;
  78. }
  79. ret = ytsoftkey.CheckKeyByEncstring();
  80. if (ret == 1)
  81. {
  82. logger.error("你生成加密代码时没有设置该函数");
  83. System.out.println( "你生成加密代码时没有设置该函数");
  84. return false;
  85. }
  86. if (ret == 0)
  87. {
  88. logger.info("使用增强算法一来检查:找到指定的加密锁");
  89. System.out.println("使用增强算法一来检查:找到指定的加密锁");
  90. }
  91. else
  92. {
  93. logger.error("使用增强算法一来检查:未能找到指定的加密锁");
  94. System.out.println("使用增强算法一来检查:未能找到指定的加密锁");
  95. return false;
  96. }
  97. ret = ytsoftkey.CheckKeyByEncstring_New();
  98. if (ret == 0)
  99. {
  100. logger.info("使用增强算法二来检查:找到指定的加密锁");
  101. System.out.println("使用增强算法二来检查:找到指定的加密锁");
  102. }
  103. else
  104. {
  105. if (ret < 0)
  106. {
  107. log.error("使用增强算法二来检查:未能找到指定的加密锁");
  108. System.out.println("使用增强算法二来检查:未能找到指定的加密锁");
  109. return false;
  110. }
  111. else
  112. {
  113. if (ret == 2)
  114. {
  115. log.error("当前锁不支持这个功能。");
  116. System.out.println("当前锁不支持这个功能。");
  117. return false;
  118. }
  119. }
  120. }
  121. ret = ytsoftkey.CheckKeyByReadEprom();
  122. if (ret == 1)
  123. {
  124. logger.error("你生成加密代码时没有设置该函数");
  125. System.out.println("你生成加密代码时没有设置该函数");
  126. return false;
  127. }
  128. if (ret == 0)
  129. {
  130. logger.info("使用读写储存器来检查:找到指定的加密锁");
  131. System.out.println("使用读写储存器来检查:找到指定的加密锁");
  132. }
  133. else
  134. {
  135. logger.error("使用读写储存器来检查:未能找到指定的加密锁");
  136. System.out.println("使用读写储存器来检查:未能找到指定的加密锁");
  137. return false;
  138. }
  139. return true;
  140. }
  141. /**
  142. * 让Spring管理JPAQueryFactory
  143. *
  144. * @param entityManager
  145. * @return
  146. */
  147. @Bean
  148. public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) {
  149. return new JPAQueryFactory(entityManager);
  150. }
  151. }