Commit 14d803bd authored by tianchao's avatar tianchao

init

parents
Pipeline #898 failed with stages
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
# Gradle
.gradle
build
bin
# Cache of project
.gradletasknamecache
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
target/
.idea/
*.iml
hs_err_pid*
.project
.settings/
.classpath
.factorypath
.DS_Store
tmp/
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
*.tmp.*
*-local.*
**模块介绍**
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>xstartup-cloud</groupId>
<artifactId>xstartup-cloud-parent-core</artifactId>
<version>1.16.10-xstartup-cloud</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>gf</groupId>
<artifactId>cnpc-common</artifactId>
<version>1.0.0-gf</version>
<properties>
<maven.build.timestamp.format>yyyy.MMdd.HHmmss</maven.build.timestamp.format>
</properties>
<dependencies>
<dependency>
<groupId>xstartup</groupId>
<artifactId>xstartup-toolkit-office</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.2-android</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration combine.self="override">
<archive>
<manifestEntries>
<Component-Group-Name>${project.groupId}</Component-Group-Name>
<Component-Artifactid>${project.artifactId}</Component-Artifactid>
<Component-Version>${project.version}</Component-Version>
<Component-Build-Time>${maven.build.timestamp}</Component-Build-Time>
<Component-Description>${project.description}</Component-Description>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>central</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>xstartup-hz</id>
<url>http://dev.sunboxauto.com/HZ/_packaging/xstartup-hz/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</project>
package cnpc.core.common.cache;
import xstartup.base.XContext;
import xstartup.cache.XCacheLife;
import xstartup.cache.XCacheObject;
import xstartup.cache.XSingleCache;
import xstartup.core.base.annotation.XCacheKeyPrefix;
import java.util.function.Supplier;
@XCacheKeyPrefix("CONFIG_CACHE")
public class ConfigCache implements XCacheObject, XCacheLife {
/*
* 配置名称
* */
private String configName;
/*
* 配置值
* */
private String configValue;
public String getConfigName() {
return configName;
}
public void setConfigName(String configName) {
this.configName = configName;
}
public String getConfigValue() {
return configValue;
}
public void setConfigValue(String configValue) {
this.configValue = configValue;
}
@Override
public Integer getDuration() {
//30秒
return 30;
}
@Override
public String getCacheKey() {
return configName;
}
/**
* 获取缓存的token
*/
public static ConfigCache get(XContext context, String configName, boolean deleteOriginal, Supplier<String> valueProvider) {
ConfigCacheRefreshTool tool = ConfigCacheRefreshTool.get(ConfigCacheRefreshTool.class);
tool.setValueProvider(valueProvider);
ConfigCache cache = tool.find(context, configName, ConfigCache.class);
if( deleteOriginal){
try{
tool.delete(context, cache);
}catch(Exception e){
context.getLogger().error("delete cache exception.", e);
}
cache = tool.find(context, configName, ConfigCache.class);
}
return cache;
}
static class ConfigCacheRefreshTool extends XSingleCache<ConfigCache> {
private Supplier<String> valueProvider;
public Supplier<String> getValueProvider() {
return valueProvider;
}
public void setValueProvider(Supplier<String> valueProvider) {
this.valueProvider = valueProvider;
}
@Override
protected ConfigCache restore(XContext context, String cacheKey) {
//生成缓存对象
if(valueProvider != null){
ConfigCache cache = new ConfigCache();
cache.configName = cacheKey;
cache.configValue = valueProvider.get();
return cache;
}
return null;
}
}
}
package cnpc.core.common.constant;
/**
* 常量
*
* @author lixueyan
*/
public interface Constant {
int FLAG_TRUE = 1;
int FLAG_FALSE = 0;
/**
* 成功
*/
int SUCCESS = 1;
/**
* 失败
*/
int FAIL = 0;
/**
* 表单类型-草稿
*/
int FORMTEMPLATE_DRAFT = 1;
/**
* 表单类型-已发布
*/
int FORMTEMPLATE_COMMIT = 2;
/**
* 有子集
*/
int ISHASHCHILDREN_TRUE = 1;
/**
* 无子集
*/
int ISHASHCHILDREN_FALSE = 0;
/**
* 菜单根节点标识
*/
Long MENU_ROOT = 0L;
/**
* 部门根节点标识
*/
Long DEPT_ROOT = 0L;
/**
* 升序
*/
String ASC = "asc";
/**
* 降序
*/
String DESC = "desc";
/**
* 创建时间字段名
*/
String CREATE_DATE = "create_date";
/**
* 数据权限过滤
*/
String SQL_FILTER = "sqlFilter";
/**
* 当前页码
*/
String PAGE = "page";
/**
* 每页显示记录数
*/
String LIMIT = "limit";
/**
* 排序字段
*/
String ORDER_FIELD = "orderField";
/**
* 排序方式
*/
String ORDER = "order";
/**
* token header
*/
String TOKEN_HEADER = "token";
/**
* 云存储配置KEY
*/
String CLOUD_STORAGE_CONFIG_KEY = "CLOUD_STORAGE_CONFIG_KEY";
}
package cnpc.core.common.enums;
public interface DictEnum {
Integer getValue();
String getDesc();
public static <T> T findByValue(Integer v, DictEnum[] values){
if( v == null){
return null;
}
for(DictEnum e : values){
if( e.getValue() .equals(v) ){
return (T)e;
}
}
return null;
}
public static <T> T findByDesc(String desc, DictEnum[] values){
for(DictEnum e : values){
if( e.getDesc().equals(desc) ){
return (T)e;
}
}
return null;
}
}
package cnpc.core.common.enums;
import xstartup.data.XFileType;
public enum FileTypeEnum {
IMAGE_PNG(".png",XFileType.IMAGE_PNG),
IMAGE_GIF(".gif",XFileType.IMAGE_GIF),
IMAGE_JPEG(".jpeg",XFileType.IMAGE_JPEG),
TEXT_HTML(".html",XFileType.TEXT_HTML),
TEXT_PLAIN(".txt",XFileType.TEXT_PLAIN),
TEXT_XML(".xml",XFileType.TEXT_XML),
VIDEO_MP4(".mpeg4",XFileType.VIDEO_MP4),
VIDEO_MP3(".mpeg3",XFileType.VIDEO_MP3),
APPLICATION_XLSX(".xlsx",XFileType.APPLICATION_XLSX),
APPLICATION_XLS(".xls",XFileType.APPLICATION_XLSX),
APPLICATION_DOCX(".docx",XFileType.APPLICATION_DOCX),
APPLICATION_DOC(".doc",XFileType.APPLICATION_DOCX),
APPLICATION_JSON(".json",XFileType.APPLICATION_JSON),
APPLICATION_PDF(".pdf",XFileType.APPLICATION_PDF),
APPLICATION_ZIP(".zip",XFileType.APPLICATION_ZIP),
OTHER("",XFileType.APPLICATION_OCTET_STREAM)
;
private String attachType;
private XFileType fileType;
FileTypeEnum(String attachType, XFileType fileType) {
this.attachType = attachType;
this.fileType = fileType;
}
public String getAttachType() {
return attachType;
}
public void setAttachType(String attachType) {
this.attachType = attachType;
}
public XFileType getFileType() {
return fileType;
}
public void setFileType(XFileType fileType) {
this.fileType = fileType;
}
public static FileTypeEnum findByType(String attachType){
for(FileTypeEnum e : values()){
if( e.getAttachType() .equals(attachType) ){
return e;
}
}
return OTHER;
}
}
package cnpc.core.common.module;
import xstartup.annotation.XText;
import xstartup.base.XContext;
import xstartup.base.XModule;
@XText("公共模块")
public class CnpcCoreCommonModule extends XModule {
protected CnpcCoreCommonModule() {
super(1000);
}
@Override
protected void onStarted(XContext context) {
}
}
package cnpc.core.common.mybatis;
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
import java.util.UUID;
public class MyIDGenerator extends DefaultIdentifierGenerator {
@Override
public String nextUUID(Object entity) {
return UUID.randomUUID().toString().replace("-","");
}
}
package cnpc.core.common.mybatis;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;
import java.util.function.Supplier;
public enum MybaitisGlobalConfigSuppiler implements Supplier<GlobalConfig> {
INSTANCE;
private final GlobalConfig globalConfig ;
private MybaitisGlobalConfigSuppiler(){
this.globalConfig = GlobalConfigUtils.defaults();
this.globalConfig.setIdentifierGenerator(new MyIDGenerator());
}
@Override
public GlobalConfig get() {
return globalConfig;
}
}
package cnpc.core.common.mybatis;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import xstartup.service.mybatis.XMybatis;
/**
* mybatis 配置类
*/
@Component
@EnableTransactionManagement
@MapperScan(sqlSessionTemplateRef = "sqlSessionTemplateRef.pps.core.common",
sqlSessionFactoryRef = "sqlSessionFactoryRef.pps.core.common",
basePackages = {"pps.core.common.mapper"})
public class PpsCoreCommonMybatis extends XMybatis {
@Override
public GlobalConfig getGlobalConfig() {
return MybaitisGlobalConfigSuppiler.INSTANCE.get();
}
}
package cnpc.core.common.pattern;
import java.util.Objects;
public class Builder<T> {
@FunctionalInterface
public static interface FieldsValidator<T> {
boolean valid(T instance);
}
@FunctionalInterface
public static interface FillField<T> {
void fill(T instance);
}
@FunctionalInterface
public static interface Init<T> {
void initialize(T instanse);
}
private final Class<T> clazz;
private Init<T> init;
private FieldsValidator<T> fieldsValidator;
public Builder(Class<T> clazz) {
this.clazz = clazz;
}
public Builder(Class<T> clazz, Init<T> init) {
this.clazz = clazz;
this.init = init;
}
public Builder(Class<T> clazz, Init<T> init, FieldsValidator<T> fieldsValidator) {
this.clazz = clazz;
this.init = init;
this.fieldsValidator = fieldsValidator;
}
public static <T> Builder<T> create(Class<T> clazz) {
return new Builder<>(clazz);
}
public static <T> Builder<T> create(Class<T> clazz, Init<T> init) {
return new Builder<>(clazz, init);
}
public static <T> Builder<T> create(Class<T> clazz, Init<T> init, FieldsValidator<T> fieldsValidator) {
return new Builder<>(clazz, init, fieldsValidator);
}
public Builder<T> addValid(FieldsValidator<T> valid){
this.fieldsValidator = valid;
return this;
}
public T build(FillField<T> fillField) {
T instance = null;
try {
instance = this.clazz.newInstance();
if (Objects.nonNull(init)){
init.initialize(instance);
}
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e.getMessage());
}
fillField.fill(instance);
if (Objects.isNull(fieldsValidator)){
return instance;
}
boolean validRet = this.fieldsValidator.valid(instance);
if (validRet){
return instance;
}
throw new RuntimeException(String.format("instance fields valid error, Class is %s", instance.getClass().getName()));
}
}
package cnpc.core.common.pattern;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
/**
* Node of Chain Pattern
*/
public class ChainNode<T> {
private T node;
private ChainNode<T> successor;
public T getNode() {
return node;
}
public void setNode(T node) {
this.node = node;
}
public ChainNode<T> getSuccessor() {
return successor;
}
// public void setSuccessor(ChainNode<T> successor) {
// this.successor = successor;
// }
public ChainNode<T> append(T successorNode){
ChainNode<T> successorChainNode = new ChainNode<>();
successorChainNode.setNode(successorNode);
// this.setSuccessor(successorChainNode);
this.successor = successorChainNode;
return successorChainNode;
}
public ChainNode<T> getLastSuccessor(){
if( this.successor == null){
return this;
}else{
return this.successor.getLastSuccessor();
}
}
public ChainNode<T> setOrAppendLast(T node){
if( this.node == null){
this.node = node;
return this;
}
ChainNode<T> lastSuccessor = this.getLastSuccessor();
if( lastSuccessor.node == null){
lastSuccessor.node = node;
return lastSuccessor;
}
return lastSuccessor.append(node);
}
public void walkThroughLast(Consumer<T> consumer){
if( this.node != null){
consumer.accept(this.node);
}
if( this.successor != null){
this.successor.walkThroughLast(consumer);
}
}
public List<ChainNode<T>> walkThroughLast(){
return walkThroughLast(new ArrayList<>());
}
public List<ChainNode<T>> walkThroughLast(List<ChainNode<T>> list){
if( list == null){
list = new ArrayList<>();
}
list.add(this);
if( this.successor == null){
return list;
}else{
return this.successor.walkThroughLast(list);
}
}
}
package cnpc.core.common.utils;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
import java.security.SecureRandom;
import java.util.Date;
import java.util.logging.Logger;
/**
* @author lixueyan
* @date 2023/5/19 0019 10:04
*/
public class AESUtil {
private static final String KEY_ALGORITHM = "AES";
private static final String DEFAULT_CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";
/**
* 指定随机字符串(密码)生成密钥
*
* @param randomKey 加解密的密码
* @throws Exception
*/
public static byte[] getSecretKey(String randomKey) throws Exception {
KeyGenerator keyGenerator = KeyGenerator.getInstance(KEY_ALGORITHM); //秘钥生成器,指定秘钥算法
//初始化此密钥生成器,指定AES的秘钥长度为128
if (StringUtils.isBlank(randomKey)) { //不指定密码
keyGenerator.init(128);
} else { //指定密码
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
random.setSeed(randomKey.getBytes());
keyGenerator.init(128, random);
}
SecretKey secretKey = keyGenerator.generateKey(); //生成密钥
return secretKey.getEncoded();
}
/**
* 加密
*
* @param data 待加密数据
* @param key 密钥
* @return byte[] 加密数据
* @throws Exception
*/
public static byte[] encrypt(byte[] data, Key key) throws Exception {
return encrypt(data, key, DEFAULT_CIPHER_ALGORITHM);
}
/**
* 加密
*
* @param data 待加密数据
* @param key 二进制密钥
* @return byte[] 加密数据
* @throws Exception
*/
public static byte[] encrypt(byte[] data, byte[] key) throws Exception {
return encrypt(data, key, DEFAULT_CIPHER_ALGORITHM);
}
/**
* 加密
*
* @param data 待加密数据
* @param key 二进制密钥
* @param cipherAlgorithm 加密算法/工作模式/填充方式
* @return byte[] 加密数据
* @throws Exception
*/
public static byte[] encrypt(byte[] data, byte[] key, String cipherAlgorithm) throws Exception {
Key k = toKey(key);
return encrypt(data, k, cipherAlgorithm);
}
/**
* 加密
*
* @param data 待加密数据
* @param key 密钥
* @param cipherAlgorithm 加密算法/工作模式/填充方式
* @return byte[] 加密数据
* @throws Exception
*/
public static byte[] encrypt(byte[] data, Key key, String cipherAlgorithm) throws Exception {
Cipher cipher = Cipher.getInstance(cipherAlgorithm); //获取算法
cipher.init(Cipher.ENCRYPT_MODE, key); //设置加密模式,并指定秘钥
return cipher.doFinal(data); //加密数据
}
/**
* 解密
*
* @param data 待解密数据
* @param key 二进制密钥
* @return byte[] 解密数据
* @throws Exception
*/
public static byte[] decrypt(byte[] data, byte[] key) throws Exception {
return decrypt(data, key, DEFAULT_CIPHER_ALGORITHM);
}
/**
* 解密
*
* @param data 待解密数据
* @param key 密钥
* @return byte[] 解密数据
* @throws Exception
*/
public static byte[] decrypt(byte[] data, Key key) throws Exception {
return decrypt(data, key, DEFAULT_CIPHER_ALGORITHM);
}
/**
* 解密
*
* @param data 待解密数据
* @param key 二进制密钥
* @param cipherAlgorithm 加密算法/工作模式/填充方式
* @return byte[] 解密数据
* @throws Exception
*/
public static byte[] decrypt(byte[] data, byte[] key, String cipherAlgorithm) throws Exception {
Key k = toKey(key);
return decrypt(data, k, cipherAlgorithm);
}
/**
* 解密
*
* @param data 待解密数据
* @param key 密钥
* @param cipherAlgorithm 加密算法/工作模式/填充方式
* @return byte[] 解密数据
* @throws Exception
*/
public static byte[] decrypt(byte[] data, Key key, String cipherAlgorithm) throws Exception {
Cipher cipher = Cipher.getInstance(cipherAlgorithm); //获取算法
cipher.init(Cipher.DECRYPT_MODE, key); //设置解密模式,并指定秘钥
return cipher.doFinal(data); //解密数据
}
/**
* 转换密钥
*
* @param secretKey 二进制密钥
* @return 密钥
*/
public static Key toKey(byte[] secretKey) {
return new SecretKeySpec(secretKey, KEY_ALGORITHM); //生成密钥
}
public static String encrypt(String data,String secret) {
String encryptDataHex = null;
try {
byte[] secretKey = getSecretKey(secret);
Key key = toKey(secretKey);
byte[] encryptData = encrypt(data.getBytes(), key);
encryptDataHex = Hex.encodeHexString(encryptData);
}catch (Exception e){
System.out.println("加密出现错误"+e.getMessage());
}
return encryptDataHex;
}
public static String decrypt(String data,String secret) {
try {
byte[] secretKey = getSecretKey(secret);
Key key = toKey(secretKey);
byte[] decryptData = decrypt(Hex.decodeHex(data.toCharArray()), key);
return new String(decryptData);
}catch (Exception e){
System.out.println("解密出现错误"+e.getMessage());
return null;
}
}
public static void main(String[] args) throws Exception {
String password = "123456"; //加解密的密码
String data = "123456"+new Date().getTime();
System.out.println("明文 :" + data);
String encryptDataHex = encrypt(data, password);
System.out.println("加密 : " + encryptDataHex);
String decryptData = decrypt(encryptDataHex,password);
System.out.println("解密 : " + new String(decryptData));
}
}
package cnpc.core.common.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* 转换工具类
*
* @author lixueyan
*/
public class ConvertUtils {
private static Logger logger = LoggerFactory.getLogger(ConvertUtils.class);
public static <T> T sourceToTarget(Object source, Class<T> target){
if(source == null){
return null;
}
T targetObject = null;
try {
targetObject = target.newInstance();
BeanUtils.copyProperties(source, targetObject);
} catch (Exception e) {
logger.error("convert error ", e);
}
return targetObject;
}
public static <T> List<T> sourceToTarget(Collection<?> sourceList, Class<T> target){
if(sourceList == null){
return null;
}
List targetList = new ArrayList<>(sourceList.size());
try {
for(Object source : sourceList){
T targetObject = target.newInstance();
BeanUtils.copyProperties(source, targetObject);
targetList.add(targetObject);
}
}catch (Exception e){
logger.error("convert error ", e);
}
return targetList;
}
}
package cnpc.core.common.utils;
/**
* @Description 雪花算法
*
*/
public class IdWorker {
private final long twepoch = 1288834974657L;
private final long workerIdBits = 5L;
private final long datacenterIdBits = 5L;
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
private final long sequenceBits = 12L;
private final long workerIdShift = sequenceBits;
private final long datacenterIdShift = sequenceBits + workerIdBits;
private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
private long workerId;
private long datacenterId;
private long sequence = 0L;
private long lastTimestamp = -1L;
public IdWorker(long workerId, long datacenterId) {
if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
}
if (datacenterId > maxDatacenterId || datacenterId < 0) {
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
}
this.workerId = workerId;
this.datacenterId = datacenterId;
}
/**
* 获得下一个ID (该方法是线程安全的)
* @return SnowflakeId
*/
public synchronized long nextId() {
long timestamp = timeGen();
//如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
if (timestamp < lastTimestamp) {
throw new RuntimeException(
String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
}
//如果是同一时间生成的,则进行毫秒内序列
if (lastTimestamp == timestamp) {
//如果毫秒相同,则从0递增生成序列号
sequence = (sequence + 1) & sequenceMask;
//毫秒内序列溢出
if (sequence == 0) {
//阻塞到下一个毫秒,获得新的时间戳
timestamp = tilNextMillis(lastTimestamp);
}
}
//时间戳改变,毫秒内序列重置
else {
sequence = 0L;
}
//上次生成ID的时间截
lastTimestamp = timestamp;
//移位并通过或运算拼到一起组成64位的ID
return ((timestamp - twepoch) << timestampLeftShift) //
| (workerId << workerIdShift) //
| sequence;
}
protected long tilNextMillis(long lastTimestamp) {
long timestamp = timeGen();
while (timestamp <= lastTimestamp) {
timestamp = timeGen();
}
return timestamp;
}
protected long timeGen() {
return System.currentTimeMillis();
}
public static void main(String[] args) {
IdWorker idWorker = new IdWorker(0, 0);
for (int i = 0; i < 100; i++) {
long id = idWorker.nextId();
System.out.println(id);
}
}
}
package cnpc.core.common.utils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.Row;
import java.util.List;
public class ImportExcelUtils {
/**
* 判断Excel当前行是否为空
* @param row
* @return
*/
public static boolean isRowEmpty(Row row){
for (int c = row.getFirstCellNum(); c < row.getLastCellNum(); c++) {
Cell cell = row.getCell(c);
if (cell != null && cell.getCellType() != CellType.BLANK)
return false;
}
return true;
}
/**
* 数据非空校验
* 规则:titles 中 含有 * 的 会进行非空校验
* @param row
* @param titles
* @return
*/
public static String checkData(Row row, List<String> titles){
DataFormatter formatter = new DataFormatter();
for (int i = 0; i < titles.size(); i++) {
Cell cell = row.getCell(i);
if(titles.get(i).startsWith("*") && StringUtils.isBlank(formatter.formatCellValue(cell))){
String msg = String.format("第%s行 %s 不能为空",(i+1),titles.get(i).replace("*",""));
return msg;
}
}
return null;
}
}
package cnpc.core.common.utils;
import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
/**
* IP地址
*
* @author lixueyan
*/
public class IpUtils {
private static Logger logger = LoggerFactory.getLogger(IpUtils.class);
/**
* 获取IP地址
* <p>
* 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址
* 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址
*/
public static String getIpAddr(HttpServletRequest request) {
String unknown = "unknown";
String ip = null;
try {
ip = request.getHeader("x-forwarded-for");
if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (StringUtils.isEmpty(ip) || ip.length() == 0 || unknown.equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (StringUtils.isEmpty(ip) || unknown.equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
} catch (Exception e) {
logger.error("IPUtils ERROR ", e);
}
return ip;
}
private volatile static String ips;
public synchronized static String getHostIPs() {
return getHostIPs(false);
}
public static String getHostIPs(boolean refresh) {
if(!refresh && !Strings.isNullOrEmpty(ips)){
return ips;
}
List<String> list = new ArrayList<String>();
try {
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
while (en.hasMoreElements()) {
NetworkInterface nint = en.nextElement();
if (nint.isLoopback()) {
continue;
}
if (nint.isPointToPoint()) {
continue;
}
if (nint.isVirtual()) {
continue;
}
if(!nint.isUp()){
continue;
}
List<InterfaceAddress> interfaceAddresses = nint.getInterfaceAddresses();
if (interfaceAddresses == null) {
continue;
}
interfaceAddresses.forEach(item -> {
String addr = item.getAddress().getHostAddress();
if (!Strings.isNullOrEmpty(addr)) {
list.add(addr.trim());
}
});
}
} catch (java.net.SocketException e) {
// fine, let's take is as signal of not having any interfaces
}
list.sort((x, y) -> {
return x.compareTo(y);
});
ips = Joiner.on(",").join(list);
return ips;
}
}
package cnpc.core.common.utils;
import org.apache.commons.lang3.StringUtils;
/**
* @author lixueyan
* @date 2023/1/10 0010 16:45
*/
public class JsonUtil {
/**
* json字符串特殊字符处理
* @param jsonStr
* @return
*/
public static String string2Json(String jsonStr) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < jsonStr.length(); i++) {
char c = jsonStr.charAt(i);
switch (c) {
case '\"':
sb.append("\\\"");
break;
case '\\':
sb.append("\\\\");
break;
case '/':
sb.append("\\/");
break;
case '\b':
sb.append("\\b");
break;
case '\f':
sb.append("\\f");
break;
case '\n':
sb.append("\\n");
break;
case '\r':
sb.append("\\r");
break;
case '\t':
sb.append("\\t");
break;
default:
sb.append(c);
}
}
return sb.toString();
}
public static String escapeExprSpecialWord(String keyword) {
if (StringUtils.isNotBlank(keyword)) {
String[] fbsArr = {"\\", "$", "(", ")", "*", "+", "?", "'", "^", "|","\b","\t","\f","\n","\r"};
for (String key : fbsArr) {
if (keyword.contains(key)) {
keyword = keyword.replace(key, "\\" + key);
}
}
}
return keyword;
}
}
package cnpc.core.common.utils;
import java.security.MessageDigest;
/**
* @author lixueyan
* @date 2022/11/11 0011 16:11
*/
public class MD5Util {
private static byte[] md5(String s) {
MessageDigest algorithm;
try {
algorithm = MessageDigest.getInstance("MD5");
algorithm.reset();
algorithm.update(s.getBytes("UTF-8"));
byte[] messageDigest = algorithm.digest();
return messageDigest;
} catch (Exception e) {
System.out.println("MD5 Error..."+e.getMessage());
}
return null;
}
private static final String toHex(byte hash[]) {
if (hash == null) {
return null;
}
StringBuffer buf = new StringBuffer(hash.length * 2);
int i;
for (i = 0; i < hash.length; i++) {
if ((hash[i] & 0xff) < 0x10) {
buf.append("0");
}
buf.append(Long.toString(hash[i] & 0xff, 16));
}
return buf.toString();
}
public static String hash(String s) {
try {
return new String(toHex(md5(s)).getBytes("UTF-8"), "UTF-8");
} catch (Exception e) {
System.out.println("not supported charset..."+e.getMessage());
return s;
}
}
/**
* 对密码按照用户名,密码,盐进行加密
* @param username 用户名
* @param password 密码
* @param salt 盐
* @return
*/
public static String encryptPassword(String username, String password, String salt) {
return MD5Util.hash(username + password + salt);
}
/**
* 对密码按照密码,盐进行加密
* @param password 密码
* @param salt 盐
* @return
*/
public static String encryptPassword(String password, String salt) {
return MD5Util.hash(password + salt);
}
/**
* 对密码按照密码,盐进行加密
* @param password 密码
* @return
*/
public static String encryptPassword(String password) {
return MD5Util.hash(password);
}
}
package cnpc.core.common.utils;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import xstartup.base.util.XDateUtils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author lixueyan
* @date 2022/8/9 0009 15:38
*/
public class MapUtil {
private static Map<Class, List<Method>> classMethodMap = new ConcurrentHashMap<Class, List<Method>>();
private static Map<Class<?>, Map<String, Method>> getMethods = new HashMap<Class<?>, Map<String, Method>>();
public static Map<String, Object> objectToMapObject(Object bean) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Method> fields = recursiveGetMethodMap(bean);
for (String fieldName : fields.keySet()) {
Method method = fields.get(fieldName);
if (method == null) continue;
JsonIgnore jsonIgnore = method.getAnnotation(JsonIgnore.class);
if (jsonIgnore != null)
continue;
Object value = invokeMethod(bean, method);
Class<?> returnType = method.getReturnType();
if(returnType!=null && returnType==Date.class && value!=null){
map.put(fieldName, XDateUtils.getDateTimeString((Date) value));
}else{
map.put(fieldName, value);
}
}
return map;
}
public static Map<String, Object> objectToMapNotContainNull(Object bean) {
Map<String, Object> map = objectToMapObject(bean);
Map<String, Object> mapResult = new HashMap<String, Object>();
for (String key : map.keySet()) {
if (map.get(key) != null) {
mapResult.put(key, map.get(key));
}
}
return mapResult;
}
private static Map<String, Method> recursiveGetMethodMap(Object obj) {
return recursiveGetMethodMap(obj.getClass());
}
private static Object invokeMethod(Object obj, Method method, Object... args) {
if (method == null)
return null;
try {
return method.invoke(obj, args);
} catch (Exception e) {
}
return null;
}
private static Map<String, Method> recursiveGetMethodMap(Class<?> _class) {
Map<String, Method> methodMap = getMethods.get(_class);
if (methodMap == null) {
synchronized (getMethods) {
if ((methodMap = getMethods.get(_class)) == null) {
methodMap = new HashMap<String, Method>();
List<Method> methodList = getDeclaredMethods(_class);
for (Method method : methodList) {
String methodName = method.getName();
int modifiers = method.getModifiers();
if (!Modifier.isPublic(modifiers))
continue;
if (Modifier.isStatic(modifiers))
continue;
if (method.getParameterCount() != 0)
continue;
if (method.getDeclaringClass() == Object.class)
continue;
if (methodName.startsWith("get") && methodName.length() > 3) {
String propertyName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4, methodName.length());
methodMap.put(propertyName, method);
}
}
getMethods.put(_class, methodMap);
}
}
}
return methodMap;
}
private static List<Method> getDeclaredMethods(Class<?> clazz) {
if (classMethodMap.containsKey(clazz))
return classMethodMap.get(clazz);
synchronized (classMethodMap) {
if (classMethodMap.containsKey(clazz))
return classMethodMap.get(clazz);
List<Method> methodList = Arrays.asList(clazz.getMethods());
classMethodMap.put(clazz, methodList);
return methodList;
}
}
public static <T> T mapToObj(Map<String,Object> map,Class<T> clz) throws Exception{
Object obj = clz.newInstance();
Field[] declaredFields = obj.getClass().getDeclaredFields();
for(Field field:declaredFields){
int mod = field.getModifiers();
if(Modifier.isStatic(mod) || Modifier.isFinal(mod)){
continue;
}
field.setAccessible(true);
field.set(obj, objToValue(map.get(field.getName()),field.getType()));
}
return (T) obj;
}
public static <T> List<T> mapToList(List<Map<String,Object>> mapList,Class<T> clz) throws Exception{
List<T> list = new ArrayList<>();
for (Map<String, Object> map : mapList) {
list.add((T) mapToObj(map,clz));
}
return list;
}
public static Object objToValue(Object o, Class c) {
if(o==null || StringUtils.isBlank(String.valueOf(o))){
if(c == String.class){
return o;
}else {
return null;
}
}
if (c == Integer.class) {
if (o instanceof Long) {
return o;
}
return Integer.parseInt(String.valueOf(o));
} else if (c == Float.class) {
return Float.parseFloat(String.valueOf(o));
} else if (c == Double.class) {
return Double.parseDouble(String.valueOf(o));
} else if (c == BigDecimal.class) {
return new BigDecimal(String.valueOf(o));
} else if (c == Boolean.class) {
if (o != null) {
if ((Boolean.parseBoolean(String.valueOf(o))) == true)
return 1;
else
return 0;
} else {
return null;
}
} else if (c == Date.class) {
return XDateUtils.parse(String.valueOf(o));
} else {
return o;
}
}
}
package cnpc.core.common.utils;
import org.apache.commons.lang3.StringUtils;
import java.util.regex.Pattern;
/**
* @author lixueyan
* @date 2022/11/11 0011 10:31
*/
public class PatternUtil {
private static final String phonePattern = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$";
public static boolean checkPhone(String phone){
//用户手机号码校验
if(Pattern.matches(phonePattern,phone)){
return true;
}else {
return false;
}
}
/**
* 字符串脱敏模糊处理
*/
public static String desensitization(String str){
if(StringUtils.isBlank(str)){
return str;
}
//先判断手机号
String s = rePhone(str);
if(!s.contains("****")){
//在判断身份证号
s = reNo(str);
}
return s;
}
/**
* 身份证号简单校验
* @param IdCard
* @return
*/
public static boolean easyCheckIdCard(String IdCard) {
//字符串为空或者不符合简单的18位校验返回false
String regex = "^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
if (StringUtils.isBlank(IdCard) || !Pattern.matches(regex, IdCard)) {
return false;
}
return true;
}
//身份证号加*号
public static String reNo(String realNo) {
String newNo = "";
if(easyCheckIdCard(realNo)) {
if (realNo.length() == 15)
newNo = realNo.replaceAll("(\\d{4})\\d{7}(\\d{4})", "$1*******$2");
if (realNo.length() == 18)
newNo = realNo.replaceAll("(\\d{4})\\d{10}(\\d{4})", "$1**********$2");
}else{
newNo = reStr(realNo);
}
return newNo;
}
//邮箱加*号
public static String reStr(String str) {
if(StringUtils.isBlank(str)){
return str;
}
String name = str;
if(str.contains("@") && str.length()>9){
StringBuilder stringBuilder = new StringBuilder(str);
name = stringBuilder.replace(3, 7, "****").toString();
}
return name;
}
//手机号加*号
public static String rePhone(String realPhone) {
String phoneNumber = "";
if (realPhone.length() == 11 && checkPhone(realPhone))
phoneNumber = realPhone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
else
phoneNumber = realPhone;
return phoneNumber;
}
}
package cnpc.core.common.utils;
/**
* @author lixueyan
* @date 2022/12/22 0022 18:52
*/
import javax.crypto.Cipher;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;
import java.util.Base64;
public class RSAUtil {
//将Base64编码后的公钥转换成PublicKey对象
public static PublicKey string2PublicKey(String pubStr) throws Exception{
byte[] keyBytes = base642Byte(pubStr);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey publicKey = keyFactory.generatePublic(keySpec);
return publicKey;
}
//将Base64编码后的私钥转换成PrivateKey对象
public static PrivateKey string2PrivateKey(String priStr) throws Exception{
byte[] keyBytes = base642Byte(priStr);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
return privateKey;
}
//Base64编码转字节数组
public static byte[] base642Byte(String base64Key) throws IOException{
Base64.Decoder decoder = Base64.getDecoder();
return decoder.decode(base64Key);
}
/**
* 解密方法
* @param byte2Base64
* @return
*/
public static String RsaDecrypt(String byte2Base64,String privateKeyStr){
byte[] decryptedData=null;
try {
//将Base64编码后的私钥转换成PrivateKey对象
PrivateKey privateKey = RSAUtil.string2PrivateKey(privateKeyStr);
Cipher cipher = Cipher.getInstance(privateKey.getAlgorithm());
cipher.init(2, privateKey);
byte[] encryptedData = RSAUtil.base642Byte(byte2Base64);
int inputLen = encryptedData.length;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
for(int i = 0; inputLen - offSet > 0; offSet = i * 256) {
byte[] cache;
if(inputLen - offSet > 256) {
cache = cipher.doFinal(encryptedData, offSet, 256);
} else {
cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet);
}
out.write(cache, 0, cache.length);
++i;
}
decryptedData = out.toByteArray();
out.close();
}catch (Exception e){
e.printStackTrace();
}
return new String(decryptedData);
}
/**
* 分断加密
* @param byte2Base642
* @return
*/
public static String rsaEncrypt(String byte2Base642,String publicKeyStr) {
String result = "";
try {
// 将Base64编码后的公钥转换成PublicKey对象
PublicKey publicKey = RSAUtil.string2PublicKey(publicKeyStr);
// 加密
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] inputArray = byte2Base642.getBytes();
int inputLength = inputArray.length;
// 最大加密字节数,超出最大字节数需要分组加密
int MAX_ENCRYPT_BLOCK = 117;
// 标识
int offSet = 0;
byte[] resultBytes = {};
byte[] cache = {};
while (inputLength - offSet > 0) {
if (inputLength - offSet > MAX_ENCRYPT_BLOCK) {
cache = cipher.doFinal(inputArray, offSet, MAX_ENCRYPT_BLOCK);
offSet += MAX_ENCRYPT_BLOCK;
} else {
cache = cipher.doFinal(inputArray, offSet, inputLength - offSet);
offSet = inputLength;
}
resultBytes = Arrays.copyOf(resultBytes, resultBytes.length + cache.length);
System.arraycopy(cache, 0, resultBytes, resultBytes.length - cache.length, cache.length);
}
Base64.Encoder encoder = Base64.getEncoder();
result = encoder.encodeToString(resultBytes);
} catch (Exception e) {
System.out.println(e.toString());
System.out.println("rsaEncrypt error:" + e.getMessage());
}
return result;
}
public static void main(String[] args) {
//公钥
String publicKey="MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2S4SMvvQJ7uO8shBO6STUhgT3zp/WbHT0j89rDQ4Q1dGV6nsCMQJNfJ6jhdQNxNSwfoZGf4bLbXfxxvdgMqisYxwBcOgfxZkEsmAl1MXr9JmNgD6MkqvxK3WCb8NsyeUsOK7frvL7OJjo2P9LLbR5SS2iBXz4Vh+2GT0C/aZmbyF0lW+qd8LTr3VPIuz0/m5cLqmatsZs3w//2rca2kaBpJ5PhL1g5OXCII76HuKQHJYsKspcziLZwtX1c5q6PFCnHFMQl6hRL62p6DgRY9PmFAUKRP3fFJWmyhevwd+6mh4Ra+puSosd1SSfWZATsT1CBUZEtnHBIfzO0Uqq25xKQIDAQAB";
//私钥
String privateKey="11111";
String string="{\"loginName\":\"cnpc\",\"phone\":\"15000000000\"}";
System.out.println("加密内容 : "+string);
String encryptRes = RSAUtil.rsaEncrypt(string,publicKey);
System.out.println("res加密后的密文 : "+encryptRes);
String decryptRes = RSAUtil.RsaDecrypt(encryptRes,privateKey);
System.out.println("res加密密文解密后的内容 : "+decryptRes);
}
}
package cnpc.core.common.utils;
import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.Set;
public class ThreadHelper {
public static final String LINE_SEPERATOR = System.getProperty("line.separator");
public static String buildThreadsSimpleInfos(StringBuilder sb) {
if (sb == null) {
sb = new StringBuilder();
}
try{
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
ArrayList<Thread> threads = new ArrayList<>(threadSet.size());
threads.addAll(threadSet);
threads.sort((x, y) -> x.getName().compareTo(y.getName()));
//int i = 0;
for (Thread t : threads) {
//i++;
sb.append(t.getName());
sb.append("(");
sb.append(t.getId());
sb.append("),");
}
sb.append("TOTAL : ").append(threadSet.size());
}catch (Exception ex){
}
return sb.toString();
}
public static void buildThreadsInfos(StringBuilder sb){
if( sb == null){
sb = new StringBuilder();
}
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
ArrayList<Thread> threads = new ArrayList<>(threadSet.size());
threads.addAll(threadSet);
threads.sort((x,y) -> x.getName().compareTo(y.getName()));
//int i = 0;
for( Thread t : threads){
//i++;
sb.append("[");
sb.append(t.getName());
sb.append("] ID:");
sb.append(t.getId());
sb.append(LINE_SEPERATOR);
sb.append(arrayToString(t.getStackTrace(), LINE_SEPERATOR));
sb.append(LINE_SEPERATOR);
sb.append(LINE_SEPERATOR);
}
sb.append("TOTAL : ").append(threadSet.size()).append(LINE_SEPERATOR);
for (Thread item : threads) {
sb.append(item.getName()).append(LINE_SEPERATOR);
}
}
public static String arrayToString(Object[] a, String seperator) {
if (a == null)
return "null";
int iMax = a.length - 1;
if (iMax == -1)
return "[]";
if (Strings.isNullOrEmpty(seperator))
seperator = ", ";
StringBuilder b = new StringBuilder();
b.append('[');
for (int i = 0; ; i++) {
b.append(String.valueOf(a[i]));
if (i == iMax) {
return b.append(']').toString();
}
b.append(seperator);
}
}
}
package cnpc.core.common.utils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* 树节点,所有需要实现树节点的,都需要继承该类
*
* @author lixueyan
* @since 1.0.0
*/
public class TreeNode<T> implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
private String id;
/**
* 上级ID
*/
private String pid;
/**
* 子节点列表
*/
private List<T> children = new ArrayList<>();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
public List<T> getChildren() {
return children;
}
public void setChildren(List<T> children) {
this.children = children;
}
}
package cnpc.core.common.utils;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 树形结构工具类,如:菜单、部门等
*
* @author lixueyan
* @since 1.0.0
*/
public class TreeUtils {
/**
* 根据pid,构建树节点
*/
public static <T extends TreeNode> List<T> build(List<T> treeNodes, Long pid) {
//pid不能为空
//AssertUtils.isNull(pid, "pid");
List<T> treeList = new ArrayList<>();
for(T treeNode : treeNodes) {
if (pid.equals(treeNode.getPid())) {
treeList.add(findChildren(treeNodes, treeNode));
}
}
return treeList;
}
/**
* 查找子节点
*/
private static <T extends TreeNode> T findChildren(List<T> treeNodes, T rootNode) {
for(T treeNode : treeNodes) {
if(rootNode.getId().equals(treeNode.getPid())) {
rootNode.getChildren().add(findChildren(treeNodes, treeNode));
}
}
return rootNode;
}
/**
* 构建树节点
*/
public static <T extends TreeNode> List<T> build(List<T> treeNodes) {
List<T> result = new ArrayList<>();
//list转map
Map<String, T> nodeMap = new LinkedHashMap<>(treeNodes.size());
for(T treeNode : treeNodes){
nodeMap.put(treeNode.getId(), treeNode);
}
for(T node : nodeMap.values()) {
T parent = nodeMap.get(node.getPid());
if(parent != null && !(node.getId().equals(parent.getId()))){
parent.getChildren().add(node);
continue;
}
result.add(node);
}
return result;
}
}
package xstartup.base;
import xstartup.base.exception.XServiceException;
import xstartup.base.util.XUuidUtils;
/**
* @author lixueyan
* @date 2023/4/4 0004 13:36
* 为满足定时任务等 非前端请求需要用户信息的 接口,特创建此类
*/
public class XSelfServiceContext extends XContext{
XSelfServiceContext(String logTag) {
super(XUuidUtils.randomUUID(), "UNKNOWN", XStartup.getCurrent().getScope(), logTag);
}
public XApp getApp() {
if (this.app == null) {
XAppInfo appInfo = XStartup.getApplication();
this.app = new XApp(appInfo.getSystemId(), appInfo.getTenantId(), appInfo.getId());
}
return this.app;
}
public static XSelfServiceContext build(String logTag) {
XSelfServiceContext context = new XSelfServiceContext(logTag);
return context;
}
public static XSelfServiceContext build(Class<?> targetClass) {
XSelfServiceContext context = new XSelfServiceContext(targetClass.getName());
return context;
}
public void setUser(XUser user) throws XServiceException {
this.user = user;
}
public XUser getUser() {
if (this.user == null) {
this.user = XUser.createAnonymousUser("local", 1L, 1L, 1L, "xservice", "xservice");
}
return this.user;
}
public String getSessionId() {
return this.getUser().getSessionId();
}
}
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>urdp-hub</artifactId>
<groupId>gf</groupId>
<version>1.0.0-gf</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>C00-common</artifactId>
<version>1.0.0-gf</version>
<packaging>pom</packaging>
<modules>
<module>cnpc-common</module>
</modules>
<repositories>
<repository>
<id>central</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>xstartup-hz</id>
<url>http://dev.sunboxauto.com/HZ/_packaging/xstartup-hz/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</project>
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>xstartup-cloud</groupId>
<artifactId>xstartup-cloud-parent-cloud</artifactId>
<version>1.16.10-xstartup-cloud</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>gf</groupId>
<artifactId>cnpc-cloud-main</artifactId>
<version>1.0.0-gf</version>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<maven.build.timestamp.format>yyyy.MMdd.HHmmss</maven.build.timestamp.format>
</properties>
<build>
<plugins>
<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration combine.self="override">
<archive>
<manifestEntries>
<Component-Group-Name>${project.groupId}</Component-Group-Name>
<Component-Artifactid>${project.artifactId}</Component-Artifactid>
<Component-Version>${project.version}</Component-Version>
<Component-Build-Time>${maven.build.timestamp}</Component-Build-Time>
<Component-Description>${project.description}</Component-Description>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>central</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>xstartup-hz</id>
<url>http://dev.sunboxauto.com/HZ/_packaging/xstartup-hz/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</project>
package gf.cloud.main.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import xstartup.base.exception.XServiceException;
public enum MessageTypeEnum {
TEXT("text","文本消息"),
IM("image","图片消息"),
EMAIL("voice","语音消息"),
VIDEO("video","视频消息"),
FILE("file","文件消息"),
TEXT_CARD("textcard","文本卡片消息"),
NEWS("news","图文消息"),
MINIPROGRAM_NOTICE("miniprogram_notice","小程序通知消息"),
;
@EnumValue
private String key;
private String value;
MessageTypeEnum(String key, String value){
this.value = value;
this.key = key;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
public static MessageTypeEnum findByValue(String key){
for(MessageTypeEnum item : values()){
if(item.getKey().equals(key)){
return item;
}
}
throw new XServiceException(1000,"不支持的消息类型");
}
}
package gf.cloud.main.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
public enum SendStateEnum {
Unknow(0,"未知"),
SUCCESS(1,"成功"),
Failure(2,"失败"),
;
@EnumValue
private Integer value;
private String desc;
SendStateEnum(Integer value, String desc){
this.desc =desc;
this.value = value;
}
public Integer getValue() {
return value;
}
public String getDesc() {
return desc;
}
public static SendStateEnum findByValue(Integer value){
for(SendStateEnum item : values()){
if(item.getValue().equals(value)){
return item;
}
}
return null;
}
}
package gf.cloud.main.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
public enum SendTypeEnum {
Single_Targert_Single_SMS(1,"发送单条短信","sendSms"),
Single_Targert_Single_IM(2,"发送单条即时通讯","sendIm"),
Single_Targert_Single_Message(3,"发送单条消息","sendMessage"),
More_Targert_Single_SMS(4,"发送多目标单条短信","sendBatchOneSms"),
More_Targert_Single_IM(5,"发送多目标单条即时通讯","sendBatchOneIm"),
More_Targert_Single_Message(6,"发送多目标单条消息","sendBatchOneMessage"),
More_Targert_More_SMS(7,"发送多手机号多条短信","sendBatchMoreSms"),
More_Targert_More_IM(8,"发送多手机号多条即时通讯","sendBatchMoreIm"),
More_Targert_More_Message(9,"发送多手机号多条消息","sendBatchMoreMessage"),
;
@EnumValue
private Integer value;
private String desc;
private String methodName;
SendTypeEnum(Integer value, String desc, String methodName){
this.desc =desc;
this.value = value;
this.methodName = methodName;
}
public Integer getValue() {
return value;
}
public String getDesc() {
return desc;
}
public String getMethodName() {
return methodName;
}
public static SendTypeEnum findByValue(Integer value){
for(SendTypeEnum item : values()){
if(item.getValue().equals(value)){
return item;
}
}
return null;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
/**
* @author lixueyan
* @date 2023/5/30 0030 14:29
*/
public class ExecuteTaskPlanInput {
@NotNull
@XText("任务id")
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
package gf.cloud.main.service.data;
import xstartup.annotation.XText;
import java.util.Date;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/29 0029 17:49
*/
public class GetSmsReplyInput {
@XText("回复手机号")
private List<String> mobile;
@XText("回复开始时间")
private Date startDate;
@XText("回复结束时间")
private Date endDate;
public List<String> getMobile() {
return mobile;
}
public void setMobile(List<String> mobile) {
this.mobile = mobile;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
}
package gf.cloud.main.service.data;
import xstartup.annotation.XText;
import java.util.Date;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/29 0029 17:49
*/
public class GetSmsReplyOutput {
@XText("回复手机号")
private String mobile;
@XText("回复内容")
private String content;
@XText("回复时间")
private Date replyDate;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Date getReplyDate() {
return replyDate;
}
public void setReplyDate(Date replyDate) {
this.replyDate = replyDate;
}
}
package gf.cloud.main.service.data;
import xstartup.annotation.XText;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:14
*/
public class GetTypeOutput {
@XText("消息类型")
private String type;
@XText("消息类型名称")
private String typeName;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTypeName() {
return typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
}
package gf.cloud.main.service.data;
import xstartup.annotation.XText;
import java.util.Date;
public class QueryMessageTaskPlanOutput {
@XText("主键")
private Integer id;
@XText("任务id")
private Integer taskId;
@XText("计划时间")
private Date planTime;
@XText("开始时间")
private Date startTime;
@XText("结束时间")
private Date endTime;
@XText("执行状态(0:未开始,1:执行中,2:执行成功,3:执行失败)")
private Integer state;
@XText("结果信息")
private String retMsg;
public Integer getId() {
return this.id;
}
public void setId(Integer value) {
this.id = value;
}
public Integer getTaskId() {
return this.taskId;
}
public void setTaskId(Integer value) {
this.taskId = value;
}
public Date getPlanTime() {
return this.planTime;
}
public void setPlanTime(Date value) {
this.planTime = value;
}
public Date getStartTime() {
return this.startTime;
}
public void setStartTime(Date value) {
this.startTime = value;
}
public Date getEndTime() {
return this.endTime;
}
public void setEndTime(Date value) {
this.endTime = value;
}
public Integer getState() {
return this.state;
}
public void setState(Integer value) {
this.state = value;
}
public String getRetMsg() {
return this.retMsg;
}
public void setRetMsg(String value) {
this.retMsg = value;
}
}
package gf.cloud.main.service.data;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
import java.util.Date;
/**
* @author lixueyan
* @date 2023/5/30 0030 9:35
*/
public class SendBaseInput {
@XText("发送方式 , 0:立即发送,1:定时发送(指定时间 一次性发送),2:周期发送(cron 表达式 多次发送)")
private Integer sendWay = 0;
@XText("发送时间, 发送方式=1时 值为:yyyy-MM-dd HH:mm:ss; 发送方式=2时 值为 ‘0/20 * * * * ?’")
private String sendTime;
@XText("截至时间,发送方式=2时,默认当前时间+1年")
private Date endTime;
@XText("发送标记,请勿赋值")
private Boolean sendFlag = false;
@XText("发送标记,请勿赋值")
@JsonIgnore
private Integer sendId;
public Integer getSendWay() {
return sendWay;
}
public void setSendWay(Integer sendWay) {
this.sendWay = sendWay;
}
public String getSendTime() {
return sendTime;
}
public void setSendTime(String sendTime) {
this.sendTime = sendTime;
}
public Boolean getSendFlag() {
return sendFlag;
}
public void setSendFlag(Boolean sendFlag) {
this.sendFlag = sendFlag;
}
public Integer getSendId() {
return sendId;
}
public void setSendId(Integer sendId) {
this.sendId = sendId;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchMoreImInput extends SendBaseInput {
@XText("消息对象集合")
@NotNull
private List<SendImInput> messageList;
public List<SendImInput> getMessageList() {
return messageList;
}
public void setMessageList(List<SendImInput> messageList) {
this.messageList = messageList;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchMoreImOutput {
@XText("错误码:0-成功,其他-失败")
private Integer errcode;
@XText("错误描述")
private String errmsg;
@XText("无效的成员id")
private String invaliduser; // 不区分大小写,返回的列表都统一转为小写
@XText("无效的部门id")
private String invalidparty;
@XText("无效的标签ID")
private String invalidtag;
@XText("im消息id")
private String jobid;
public Integer getErrcode() {
return errcode;
}
public void setErrcode(Integer errcode) {
this.errcode = errcode;
}
public String getErrmsg() {
return errmsg;
}
public void setErrmsg(String errmsg) {
this.errmsg = errmsg;
}
public String getInvaliduser() {
return invaliduser;
}
public void setInvaliduser(String invaliduser) {
this.invaliduser = invaliduser;
}
public String getInvalidparty() {
return invalidparty;
}
public void setInvalidparty(String invalidparty) {
this.invalidparty = invalidparty;
}
public String getInvalidtag() {
return invalidtag;
}
public void setInvalidtag(String invalidtag) {
this.invalidtag = invalidtag;
}
public String getJobid() {
return jobid;
}
public void setJobid(String jobid) {
this.jobid = jobid;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchMoreMessageInput extends SendBaseInput {
@XText("消息对象集合")
@NotNull
private List<SendMessageInput> messageList;
public List<SendMessageInput> getMessageList() {
return messageList;
}
public void setMessageList(List<SendMessageInput> messageList) {
this.messageList = messageList;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchMoreMessageOutput {
@XText("消息对象集合")
@NotNull
private List<SendMessageInput> messageList;
public List<SendMessageInput> getMessageList() {
return messageList;
}
public void setMessageList(List<SendMessageInput> messageList) {
this.messageList = messageList;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchMoreSmsInput extends SendBaseInput {
@XText("消息对象集合")
@NotNull
private List<SendImInput> messageList;
public List<SendImInput> getMessageList() {
return messageList;
}
public void setMessageList(List<SendImInput> messageList) {
this.messageList = messageList;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchMoreSmsOutput {
@XText("手机号")
private String mobile;
@XText("消息 ID")
private String smsId;
@XText("客户自定义 SMSID")
private String customSmsId;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getSmsId() {
return smsId;
}
public void setSmsId(String smsId) {
this.smsId = smsId;
}
public String getCustomSmsId() {
return customSmsId;
}
public void setCustomSmsId(String customSmsId) {
this.customSmsId = customSmsId;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchOneImInput extends SendBaseInput {
@XText("手机号")
@NotNull
private List<String> mobile;
@XText("短信内容")
@NotNull
private String content;
public List<String> getMobile() {
return mobile;
}
public void setMobile(List<String> mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
package gf.cloud.main.service.data;
import xstartup.annotation.XText;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchOneImOutput {
@XText("错误码:0-成功,其他-失败")
private Integer errcode;
@XText("错误描述")
private String errmsg;
@XText("无效的成员id")
private String invaliduser; // 不区分大小写,返回的列表都统一转为小写
@XText("无效的部门id")
private String invalidparty;
@XText("无效的标签ID")
private String invalidtag;
@XText("im消息id")
private String jobid;
public Integer getErrcode() {
return errcode;
}
public void setErrcode(Integer errcode) {
this.errcode = errcode;
}
public String getErrmsg() {
return errmsg;
}
public void setErrmsg(String errmsg) {
this.errmsg = errmsg;
}
public String getInvaliduser() {
return invaliduser;
}
public void setInvaliduser(String invaliduser) {
this.invaliduser = invaliduser;
}
public String getInvalidparty() {
return invalidparty;
}
public void setInvalidparty(String invalidparty) {
this.invalidparty = invalidparty;
}
public String getInvalidtag() {
return invalidtag;
}
public void setInvalidtag(String invalidtag) {
this.invalidtag = invalidtag;
}
public String getJobid() {
return jobid;
}
public void setJobid(String jobid) {
this.jobid = jobid;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchOneMessageInput extends SendBaseInput {
@XText("手机号")
@NotNull
private List<String> mobile;
@XText("短信内容")
@NotNull
private String content;
@XText("类型")
@NotNull
private String type;
public List<String> getMobile() {
return mobile;
}
public void setMobile(List<String> mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package gf.cloud.main.service.data;
import xstartup.annotation.XText;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchOneMessageOutput {
@XText("手机号")
private String mobile;
@XText("短信内容")
private String content;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
import java.util.List;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchOneSmsInput extends SendBaseInput {
@XText("手机号")
private List<String> mobile;
@XText("短信内容")
@NotNull
private String content;
public List<String> getMobile() {
return mobile;
}
public void setMobile(List<String> mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
package gf.cloud.main.service.data;
import xstartup.annotation.XText;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendBatchOneSmsOutput {
@XText("手机号")
private String mobile;
@XText("消息 ID")
private String smsId;
@XText("客户自定义 SMSID")
private String customSmsId;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getSmsId() {
return smsId;
}
public void setSmsId(String smsId) {
this.smsId = smsId;
}
public String getCustomSmsId() {
return customSmsId;
}
public void setCustomSmsId(String customSmsId) {
this.customSmsId = customSmsId;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendImInput extends SendBaseInput {
@XText("手机号")
@NotNull
private String mobile;
@XText("短信内容")
@NotNull
private String content;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
package gf.cloud.main.service.data;
import xstartup.annotation.XText;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendImOutput {
@XText("错误码:0-成功,其他-失败")
private Integer errcode;
@XText("错误描述")
private String errmsg;
@XText("无效的成员id")
private String invaliduser; // 不区分大小写,返回的列表都统一转为小写
@XText("无效的部门id")
private String invalidparty;
@XText("无效的标签ID")
private String invalidtag;
@XText("im消息id")
private String jobid;
public Integer getErrcode() {
return errcode;
}
public void setErrcode(Integer errcode) {
this.errcode = errcode;
}
public String getErrmsg() {
return errmsg;
}
public void setErrmsg(String errmsg) {
this.errmsg = errmsg;
}
public String getInvaliduser() {
return invaliduser;
}
public void setInvaliduser(String invaliduser) {
this.invaliduser = invaliduser;
}
public String getInvalidparty() {
return invalidparty;
}
public void setInvalidparty(String invalidparty) {
this.invalidparty = invalidparty;
}
public String getInvalidtag() {
return invalidtag;
}
public void setInvalidtag(String invalidtag) {
this.invalidtag = invalidtag;
}
public String getJobid() {
return jobid;
}
public void setJobid(String jobid) {
this.jobid = jobid;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendMessageInput extends SendBaseInput {
@XText("手机号")
@NotNull
private String mobile;
@XText("短信内容")
@NotNull
private String content;
@XText("消息类型, ALL-全渠道发送,SMS|IM - 多渠道发送")
@NotNull
private String type;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package gf.cloud.main.service.data;
import xstartup.annotation.XText;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendMessageOutput {
@XText("手机号")
private String mobile;
@XText("短信内容")
private String content;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
package gf.cloud.main.service.data;
import jakarta.validation.constraints.NotNull;
import xstartup.annotation.XText;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendSmsInput extends SendBaseInput {
@XText("手机号")
@NotNull
private String mobile;
@XText("短信内容")
@NotNull
private String content;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
package gf.cloud.main.service.data;
import xstartup.annotation.XText;
/**
* @author lixueyan
* @date 2023/5/19 0019 14:17
*/
public class SendSmsOutput {
@XText("手机号")
private String mobile;
@XText("消息 ID")
private String smsId;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getSmsId() {
return smsId;
}
public void setSmsId(String smsId) {
this.smsId = smsId;
}
}
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>xstartup-cloud</groupId>
<artifactId>xstartup-cloud-parent-core</artifactId>
<version>1.16.10-xstartup-cloud</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>gf</groupId>
<artifactId>gf-core-main</artifactId>
<version>1.0.0-gf</version>
<properties>
<maven.build.timestamp.format>yyyy.MMdd.HHmmss</maven.build.timestamp.format>
</properties>
<dependencies>
<dependency>
<groupId>gf</groupId>
<artifactId>cnpc-common</artifactId>
<version>1.0.0-gf</version>
</dependency>
<dependency>
<groupId>gf</groupId>
<artifactId>cnpc-cloud-main</artifactId>
<version>1.0.0-gf</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>gf</groupId>
<artifactId>cnpc-cloud-auth</artifactId>
<version>1.16.10-xstartup-cloud</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration combine.self="override">
<archive>
<manifestEntries>
<Component-Group-Name>${project.groupId}</Component-Group-Name>
<Component-Artifactid>${project.artifactId}</Component-Artifactid>
<Component-Version>${project.version}</Component-Version>
<Component-Build-Time>${maven.build.timestamp}</Component-Build-Time>
<Component-Description>${project.description}</Component-Description>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.ini</include>
</includes>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>central</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>xstartup-hz</id>
<url>http://dev.sunboxauto.com/HZ/_packaging/xstartup-hz/maven/v1</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
</project>
package gf.core.main.constant;
/**
* @author lixueyan
* @date 2023/5/25 0025 18:08
*/
public class MessageConstants {
public static final Integer MESSAGE_FLAG_NE_ONE = -888;
public static final Integer MESSAGE_FLAG_NE_999 = -999;
}
package gf.core.main.enums;
import cnpc.core.common.enums.DictEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
public enum SendStateEnum implements DictEnum {
Doing(0,"处理中"),
SUCCESS(1,"成功"),
Party_SUCCESS(2,"部分成功"),
Failure(3,"失败"),
;
@EnumValue
private Integer value;
private String desc;
SendStateEnum(Integer value, String desc){
this.desc =desc;
this.value = value;
}
@Override
public Integer getValue() {
return value;
}
@Override
public String getDesc() {
return desc;
}
public static SendStateEnum findByValue(Integer value){
for(SendStateEnum item : values()){
if(item.getValue().equals(value)){
return item;
}
}
return null;
}
}
package gf.core.main.enums;
import cnpc.core.common.enums.DictEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
public enum SendWayEnum implements DictEnum {
Send_Now(0,"立即发送"),
Send_Time(1,"定时发送"),
Send_Cycle(2,"周期发送"),
;
@EnumValue
private Integer value;
private String desc;
SendWayEnum(Integer value, String desc){
this.desc =desc;
this.value = value;
}
@Override
public Integer getValue() {
return value;
}
@Override
public String getDesc() {
return desc;
}
public static SendWayEnum findByValue(Integer value){
for(SendWayEnum item : values()){
if(item.getValue().equals(value)){
return item;
}
}
return null;
}
}
package gf.core.main.enums;
import cnpc.core.common.enums.DictEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
public enum TaskAnalysisStateEnum implements DictEnum {
NO(0,"未解析"),
YES(1,"已解析"),
;
@EnumValue
private Integer value;
private String desc;
TaskAnalysisStateEnum(Integer value, String desc){
this.desc =desc;
this.value = value;
}
@Override
public Integer getValue() {
return value;
}
@Override
public String getDesc() {
return desc;
}
public static TaskAnalysisStateEnum findByValue(Integer value){
for(TaskAnalysisStateEnum item : values()){
if(item.getValue().equals(value)){
return item;
}
}
return null;
}
}
package gf.core.main.enums;
import cnpc.core.common.enums.DictEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
public enum TaskPlanStateEnum implements DictEnum {
Wait(0,"未开始"),
Doing(1,"进行中"),
Success(2,"成功"),
Failure(3,"失败"),
;
@EnumValue
private Integer value;
private String desc;
TaskPlanStateEnum(Integer value, String desc){
this.desc =desc;
this.value = value;
}
@Override
public Integer getValue() {
return value;
}
@Override
public String getDesc() {
return desc;
}
public static TaskPlanStateEnum findByValue(Integer value){
for(TaskPlanStateEnum item : values()){
if(item.getValue().equals(value)){
return item;
}
}
return null;
}
}
package gf.core.main.enums;
import cnpc.core.common.enums.DictEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
public enum TaskStateEnum implements DictEnum {
Delete(0,"已删除"),
Enable(1,"启用"),
Disable(2,"禁用"),
;
@EnumValue
private Integer value;
private String desc;
TaskStateEnum(Integer value, String desc){
this.desc =desc;
this.value = value;
}
@Override
public Integer getValue() {
return value;
}
@Override
public String getDesc() {
return desc;
}
public static TaskStateEnum findByValue(Integer value){
for(TaskStateEnum item : values()){
if(item.getValue().equals(value)){
return item;
}
}
return null;
}
}
package gf.core.main.error;
import xstartup.error.XError;
/**
* @author lixueyan
* @date 2023/5/18 0018 10:33
*/
public enum MessageError implements XError {
Send_Not_Exists_Error(1001001,"定时发送请求不存在"),
Send_Time_Error(1001002,"发送时间不合法"),
Send_Time_Fast_Error(1001003,"不允许秒级的定时发送请求"),
;
private int code;
private String text;
MessageError(int code, String text) {
this.code = code;
this.text = text;
}
@Override
public int getCode() {
return code;
}
@Override
public String getText() {
return text;
}
}
package gf.core.main.mapper;
import gf.core.main.entity.WeatherDataEnt;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
@Repository(value="gf.core.main.mapper.WeatherDataMapper")
public interface WeatherDataMapper extends BaseMapper<WeatherDataEnt> {
}
package gf.core.main.mapper;
import gf.core.main.entity.WeatherDataView;
import org.springframework.stereotype.Repository;
@Repository(value="gf.core.main.mapper.WeatherDataViewMapper")
public interface WeatherDataViewMapper {
WeatherDataView selectOne(WeatherDataView record);
}
package gf.core.main.module;
import xstartup.annotation.XText;
import xstartup.base.XContext;
import xstartup.base.XModule;
@XText("主模块")
public class GfCoreMainModule extends XModule {
protected GfCoreMainModule() {
super(1001);
}
@Override
protected void onStarted(XContext context) {
//配置信息 自定义实现类
System.out.println("2323423");
}
}
package gf.core.main.mybatis;
import cnpc.core.common.mybatis.MybaitisGlobalConfigSuppiler;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import xstartup.service.mybatis.XMybatis;
/**
* mybatis 配置类
*/
@Component
@EnableTransactionManagement
@MapperScan(sqlSessionTemplateRef = "sqlSessionTemplateRef.gf.core.main",
sqlSessionFactoryRef = "sqlSessionFactoryRef.gf.core.main",
basePackages = {"gf.core.main.mapper"})
public class GfCoreMainMybatis extends XMybatis {
@Override
public GlobalConfig getGlobalConfig() {
return MybaitisGlobalConfigSuppiler.INSTANCE.get();
}
}
package gf.core.main.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import gf.core.main.entity.WeatherDataEnt;
import gf.core.main.entity.WeatherDataView;
import gf.core.main.mapper.WeatherDataMapper;
import gf.core.main.mapper.WeatherDataViewMapper;
import gf.core.main.service.data.weather_data.GetWeatherDataViewInput;
import xstartup.annotation.XService;
import xstartup.base.XContext;
import xstartup.data.XSingleResult;
import xstartup.feature.api.annotation.XApiAnonymous;
import xstartup.feature.api.annotation.XApiGet;
@XService
public class OilFieldDataService {
@XApiAnonymous
@XApiGet
public XSingleResult getOilFieldData(XContext context, GetWeatherDataViewInput input){
WeatherDataMapper weatherDataMapper = context.getBean(WeatherDataMapper.class);
QueryWrapper<WeatherDataEnt> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(WeatherDataEnt::getId , input.getId());
WeatherDataEnt ent = weatherDataMapper.selectOne(queryWrapper);
return XSingleResult.success(ent);
}
@XApiAnonymous
@XApiGet
public XSingleResult getOilFieldDataView(XContext context, GetWeatherDataViewInput input){
WeatherDataViewMapper viewMapper = context.getBean(WeatherDataViewMapper.class);
WeatherDataView view = new WeatherDataView();
view.setId(input.getId());
view = viewMapper.selectOne(view);
return XSingleResult.success(view);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
package cnpc.core.auth.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import cnpc.core.auth.entity.AuthBaseThirdAuthEnt;
@Repository(value="cnpc.core.auth.mapper.AuthBaseThirdAuthMapper")
public interface AuthBaseThirdAuthMapper extends BaseMapper<AuthBaseThirdAuthEnt> {
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment