parent
66fe188546
commit
d2d73cc7ef
@ -0,0 +1,89 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>cc.cjyx.sc</groupId>
|
||||||
|
<artifactId>zbgym</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>zbgym</name>
|
||||||
|
<description>总部感应门项目</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<spring-boot.version>2.6.13</spring-boot.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>1.2.72</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.snowheart</groupId>
|
||||||
|
<artifactId>spring-boot-dingtalk-robot-starter</artifactId>
|
||||||
|
<version>1.0.2.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-dependencies</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,14 @@
|
|||||||
|
package cc.cjyx.sc;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
|
||||||
|
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package cc.cjyx.sc.common;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
public class SerialNumber {
|
||||||
|
private static final SimpleDateFormat YEAR_MONTH_FORMAT = new SimpleDateFormat("yyyyMM");
|
||||||
|
private static int currentSerial = 0;
|
||||||
|
private static String currentYearMonth;
|
||||||
|
|
||||||
|
public static synchronized String generateSerialNumber() {
|
||||||
|
String currentYearMonth = YEAR_MONTH_FORMAT.format(new java.util.Date());
|
||||||
|
if (!currentYearMonth.equals(SerialNumber.currentYearMonth)) {
|
||||||
|
// 当年月变化时,重置流水号
|
||||||
|
SerialNumber.currentYearMonth = currentYearMonth;
|
||||||
|
currentSerial = 1;
|
||||||
|
} else {
|
||||||
|
// 年月未变,递增流水号
|
||||||
|
currentSerial++;
|
||||||
|
}
|
||||||
|
return currentYearMonth + String.format("%04d", currentSerial);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,104 @@
|
|||||||
|
package cc.cjyx.sc.utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
// 数据解析
|
||||||
|
@Slf4j
|
||||||
|
public class DataParserUtil {
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* byte 转 bit位
|
||||||
|
* @description: 字节转比特
|
||||||
|
* 1Byte=8bits
|
||||||
|
*/
|
||||||
|
public static String formatBinary(byte b) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for(int i = 7; i >=0; i--) {
|
||||||
|
sb.append((byte) ((b >> i) & 0x1));
|
||||||
|
}
|
||||||
|
// 小端模式(低字节在前、高字节在后)
|
||||||
|
return sb.reverse().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字节数组转16进制字符串
|
||||||
|
*
|
||||||
|
* @param b 字节数组
|
||||||
|
* @return 16进制字符串
|
||||||
|
*/
|
||||||
|
public static String byteArray2HexString(byte[] b)
|
||||||
|
{
|
||||||
|
StringBuilder sbf = new StringBuilder();
|
||||||
|
for (byte value : b)
|
||||||
|
{
|
||||||
|
String hex = Integer.toHexString(value & 0xFF);
|
||||||
|
if (hex.length() == 1)
|
||||||
|
{
|
||||||
|
hex = '0' + hex;
|
||||||
|
}
|
||||||
|
sbf.append(hex.toUpperCase()).append(" ");
|
||||||
|
}
|
||||||
|
return sbf.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 16进制字符串转字节数组
|
||||||
|
*
|
||||||
|
* @param hex 16进制字符串
|
||||||
|
* @return 字节数组
|
||||||
|
*/
|
||||||
|
public static byte[] hexString2byteArray(String hex)
|
||||||
|
{
|
||||||
|
hex = hex.replace(" ", "");
|
||||||
|
if (!isHexString(hex))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
char[] arr = hex.toCharArray();
|
||||||
|
byte[] b = new byte[hex.length() / 2];
|
||||||
|
for (int i = 0, j = 0, l = hex.length(); i < l; i++, j++)
|
||||||
|
{
|
||||||
|
String swap = "" + arr[i++] + arr[i];
|
||||||
|
int byteint = Integer.parseInt(swap, 16) & 0xFF;
|
||||||
|
b[j] = new Integer(byteint).byteValue();
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验是否是16进制字符串
|
||||||
|
*
|
||||||
|
* @param hex
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static boolean isHexString(String hex)
|
||||||
|
{
|
||||||
|
if (hex == null || hex.length() % 2 != 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < hex.length(); i++)
|
||||||
|
{
|
||||||
|
char c = hex.charAt(i);
|
||||||
|
if (!isHexChar(c))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验是否是16进制字符
|
||||||
|
*
|
||||||
|
* @param c
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
private static boolean isHexChar(char c)
|
||||||
|
{
|
||||||
|
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
server:
|
||||||
|
port: 8881
|
||||||
|
|
||||||
|
mobiles:
|
||||||
|
'15067827668,13375872885,13587753850'
|
||||||
|
|
||||||
|
# 钉钉通知
|
||||||
|
dingtalk:
|
||||||
|
robot:
|
||||||
|
webhook: https://oapi.dingtalk.com/robot/send?access_token=3e5c999e5a1163d7d9251c4f5781ccd1d10430c8987be3f3d377e6fea16a4293
|
@ -0,0 +1,6 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<h1>hello word!!!</h1>
|
||||||
|
<p>this is a html page</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,51 @@
|
|||||||
|
package cc.cjyx.sc.demo;
|
||||||
|
|
||||||
|
import cn.snowheart.dingtalk.robot.starter.client.DingTalkRobotClient;
|
||||||
|
import cn.snowheart.dingtalk.robot.starter.entity.DingTalkResponse;
|
||||||
|
import cn.snowheart.dingtalk.robot.starter.entity.TextMessage;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@Slf4j
|
||||||
|
class ModbusDemoApplicationTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("dingTalkRobotClient")
|
||||||
|
private DingTalkRobotClient client;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSendTextMessage() throws InterruptedException {
|
||||||
|
// DingTalkResponse response = null;
|
||||||
|
|
||||||
|
// response = client.sendTextMessage(new TextMessage("报警通知:构建 TextMessage对象发布!"));
|
||||||
|
// Assertions.assertEquals(response.getErrcode().longValue(), 0L);
|
||||||
|
// log.info(response.toString());
|
||||||
|
// Thread.sleep(3000);
|
||||||
|
|
||||||
|
// response = client.sendTextMessage("报警通知:构建普通字符串发布!");
|
||||||
|
// Assertions.assertEquals(response.getErrcode().longValue(), 0L);
|
||||||
|
// log.info(response.toString());
|
||||||
|
// Thread.sleep(3000);
|
||||||
|
|
||||||
|
DingTalkResponse response = client.sendTextMessage("报警通知:通知指定人!", new String[]{"15137603460"});
|
||||||
|
Assertions.assertEquals(response.getErrcode().longValue(), 0L);
|
||||||
|
log.info(response.toString());
|
||||||
|
Thread.sleep(3000);
|
||||||
|
|
||||||
|
// response = client.sendTextMessage("报警通知:通知群内所有人!", true);
|
||||||
|
// Assertions.assertEquals(response.getErrcode().longValue(), 0L);
|
||||||
|
// log.info(response.toString());
|
||||||
|
// Thread.sleep(3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue