Author: Moxi
Study notes of Moxi: note moguit. cn
Hello, I'm Mo Xi
As we all know, the bank's system is relatively stable, and the development of new functions will also give a long cycle of iteration. For example, a CURD small function will be scheduled for two weeks of development, and then add testing. Maybe a small demand will not be launched until a month later.
Internet companies, on the other hand, have to complete the iteration of requirements every two weeks. From the requirements put forward by business students to requirements review, design review, technical review, test review and launch, it should be completed within two weeks (if it is not completed, it may be delayed to the launch node in two weeks)
Therefore, it's relatively easy to be a programmer in a bank. Let's take a look at how Xiao Hui, a small partner in the group, fish in the bank~
I move bricks in the bank, so I need to use the cloud desktop to work. There are relatively few things to work in the bank, so I often fish. Fishing is fishing, but I am still monitored. Why?
The hibernation time of the installation settings issued by the bank is 5 minutes. Due to the permission problem, we cannot adjust the hibernation time. When the hibernation time is greater than 5 minutes, the computer will enter the hibernation state and the online time will not be counted.
Some time ago, I was monitored to be online for only 85%. Ranking in the bottom 30%, was regarded as a negative teaching material. So I thought of a way to prevent the computer from going to sleep by simulating clicking the mouse. If some partners also work with cloud desktop and want to fish happily, you can refer to the code provided by me.
thinking
- Determine whether it is within the time range
- Adopt java. java provided by java Robot class under AWT package, simulate clicking (refer to the specific api by yourself)
The Robot class is used to generate native system input events for test automation, self running demo programs, and other applications that need to control the mouse and keyboard. The main purpose of Robot is to facilitate automatic testing on the Java platform. When using Robot class in Java, you need to import Java AWT package
Specific code
First of all, I need to define the working time. My working time is from 8:30 a.m. to 20:00 p.m
Then it is executed every 60 seconds. In order to make the performance more scientific and reasonable, we change to double-click the mouse (programmer's specialty, CV foreplay)
import java.awt.*; import java.awt.event.KeyEvent; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /** * Prevent computer hibernation * Imitate mouse click */ public class WaitFor { public static void main(String[] args) throws AWTException { Robot robot = new Robot(); // Time range working hours String exeTimeStr = "083000-200000"; while (isExeTime(exeTimeStr)){ // It is reasonable to simulate double clicking the mouse robot.mousePress(KeyEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK); //Frequency 60s once robot.delay(60000); } }
To avoid errors, in a verification method
/** * Determine whether it is within the time range * @param exeTimeStr * @return */ private static boolean isExeTime(String exeTimeStr){ String currentTime = getCurrentTime("HHmmss"); int currentTimeInt = Integer.parseInt(currentTime); String[] timeArr = exeTimeStr.split("-"); if (timeArr.length!=2){ throw new RuntimeException("exeTimeStr Time input error" + exeTimeStr); } int startTimeInt = Integer.parseInt(timeArr[0]); int endTimeInt = Integer.parseInt(timeArr[1]); return startTimeInt <= currentTimeInt && endTimeInt >= currentTimeInt; } /** * Format current time * @param formatStr * @return */ private static String getCurrentTime(String formatStr) { DateFormat sdf = new SimpleDateFormat(formatStr); Date date = Calendar.getInstance().getTime(); return sdf.format(date); } }
actual combat
Generally, the execution is performed on the local physical machine. The principle of cloud desktop is that you actually operate the physical machine and indirectly operate the cloud desktop,
Therefore, we need to install JDK on the physical machine. Generally, we are not allowed to install other IDE software on the physical machine of the bank. In fact, even the installation is very troublesome.
Therefore, my idea is to directly execute Java programs in the form of scripts, which reminds me of the most primitive method we have just begun to learn Java.
- On the physical machine, install the JDK configuration environment variable (omitted)
- Write java file = javac compile java file class file

Execute java class name to execute main

- Script cmd
In this way, every time we cmd enter, so we knock in the black box. It's a little troublesome. So we need to write a bat file. Write the command in
Then give this document a name: fishing bat
cd %~dp0 javac WaitFor.java java WaitFor
After that, you can directly double-click to run

Well, that's all for this issue
I'm Mo Xi. I'll see you next time~
The blogger works in the commercialization department and has been maintaining the learning note warehouse. "There are 4.5K stars on Gitee, and the warehouse address is https://Gitee.com/moxi159753/LearningNote s 」
At the same time, if you want to have rich project experience, you can refer to the open source micro service Blog project I maintain: Mushroom blog "Gitee official recommendation project", ranking first in blog search. There are 4.1K star s in Gitee, warehouse address: https://gitee.com/moxi159753/mogu_blog_v2 」.