Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
dinggang 2022-11-09 09:14:07 +08:00
commit 9f9e3b7e5f
9 changed files with 371 additions and 10 deletions

View File

@ -326,8 +326,13 @@
<directory>src/main/resources</directory>
<excludes>
<!-- 排除生产环境配置 -->
<exclude>application-prod.yml</exclude>
<exclude>application-bt.yml</exclude>
<exclude>application-dev.yml</exclude>
<exclude>application-hwx.yml</exclude>
<exclude>application-my.yml</exclude>
<exclude>application-prod.yml</exclude>
<exclude>application-show.yml</exclude>
<exclude>application-test.yml</exclude>
<exclude>application-xha.yml</exclude>
<!-- 排除flyway管理的sql -->
<exclude>db/*.sql</exclude>
@ -363,7 +368,9 @@
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>. lib/yawei-pso-${yawei-pso.version}.jar lib/contingencyplan-${contingencyplan.version}.jar</Class-Path>
<Class-Path>. lib/yawei-pso-${yawei-pso.version}.jar
lib/contingencyplan-${contingencyplan.version}.jar
</Class-Path>
</manifestEntries>
</archive>
</configuration>

View File

@ -0,0 +1,91 @@
package io.renren.common.controller;
import io.renren.common.utils.Result;
import io.renren.common.utils.UpdateUtil;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Api(tags = "管理员后台")
@RestController
@RequestMapping("/admin")
public class AdminController {
private static final Logger logger = LoggerFactory.getLogger(AdminController.class);
private static final String pwd = System.getProperty("user.dir");
@Autowired
private UpdateUtil updateUtil;
@Value("${spring.profiles.active}")
private String active; // 现有生效
/**
* @param updateFile 更新包下载地址
* @param active 重启完成后的配置环境
* @return
*/
@PostMapping(value = "/update")
public Result<String> update(String updateFile, String active) {
if (StringUtils.isEmpty(active)) {
active = this.active;
}
boolean success = updateUtil.update(updateFile, active);
return new Result<String>().ok(String.valueOf(success));
}
/**
* 列出所有日志文件
*
* @return
*/
@GetMapping(value = "logFiles")
public Result<List<String>> logFiles() {
List<String> result = new ArrayList<>();
File file = new File(pwd + File.separator + "logs");
File[] tempFile = file.listFiles();
result = Arrays.asList(tempFile).stream().filter(index -> index.isFile()).map(index -> index.getName()).collect(Collectors.toList());
return new Result<List<String>>().ok(result);
}
/**
* 下载日志文件
*
* @param file
* @return
*/
@GetMapping(value = "downloadLog")
public ResponseEntity<FileSystemResource> downloadLogFile(String file) {
File file_ = new File(pwd + File.separator + "logs" + File.separator + file);
if (!file_.exists()) {
return null;
}
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition", "attachment; filename=" + file_.getName());
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
headers.add("Last-Modified", new Date().toString());
headers.add("ETag", String.valueOf(System.currentTimeMillis()));
return ResponseEntity.ok().headers(headers).contentLength(file_.length()).contentType(MediaType.parseMediaType("application/octet-stream")).body(new FileSystemResource(file_));
}
}

View File

@ -0,0 +1,96 @@
package io.renren.common.utils;
import cn.hutool.core.util.RuntimeUtil;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@Component
public class UpdateUtil {
private static final Logger logger = LoggerFactory.getLogger(UpdateUtil.class);
private static final Integer CPUNUM = Runtime.getRuntime().availableProcessors();
private static final ExecutorService executor = Executors.newFixedThreadPool(CPUNUM);
private static final String pwd = System.getProperty("user.dir");
private static final OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(1, TimeUnit.MINUTES).readTimeout(2, TimeUnit.MINUTES).connectionPool(new ConnectionPool(CPUNUM * 2, 2, TimeUnit.MINUTES)).retryOnConnectionFailure(false).build(); // 下载更新包的工具
/**
* 执行更新
*
* @param updateFile
* @param active
* @return
*/
public Boolean update(String updateFile, String active) {
String updateFilePath = downloadUpdateFile(updateFile);
if (StringUtils.isEmpty(updateFile)) {
return false;
}
execUpdate(updateFilePath, active);
return true;
}
/**
* 下载更新包
*
* @param updateFile
* @return 下载的更新包磁盘路径
*/
private String downloadUpdateFile(String updateFile) {
File folder = new File(pwd + File.separator + "/update"); // 更新包下载保存文件夹
File file = new File(folder, updateFile.substring(updateFile.lastIndexOf("/") + 1)); // 保存文件路径与名称
if (!folder.isDirectory()) {
folder.mkdirs();
}
Request request = new Request.Builder().url(updateFile).addHeader("Connection", "close").get().build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
try (InputStream is = response.body().byteStream(); FileOutputStream fos = new FileOutputStream(file)) {
long total = response.body().contentLength();
byte[] buf = new byte[4096];
int len;
long sum = 0;
while ((len = is.read(buf)) != -1) {
fos.write(buf, 0, len);
sum += len;
int progress = (int) (sum * 1.0f / total * 100);
logger.info("更新包下载进度 {}% ", progress);
}
fos.flush();
return file.getAbsolutePath();
}
} else {
logger.error("下载更新包失败:{},错误码:{}", updateFile, response.code());
}
} catch (IOException e) {
logger.error("下载更新包失败:" + updateFile, e);
}
return null;
}
/**
* @param updateFilePath 下载到本地的更新文件
* @param active 启动程序的配置文件
*/
private void execUpdate(String updateFilePath, String active) {
String[] cmd = {"/bin/sh", "-c", String.format("cd %s && sh update.sh %s %s %s %s", pwd, pwd, updateFilePath, "renren-admin", active)};
// String cmd = String.format("cd %s && sh update.sh %s %s", pwd, pwd, updateFilePath, "renren-admin", active);
logger.info("执行指令:{}", Arrays.asList(cmd).toString());
logger.info(RuntimeUtil.execForStr(cmd));
}
}

View File

@ -440,6 +440,46 @@ public class ResourceController {
}
}
@GetMapping("ZywMessage/yaweiApproveStatus")
@ApiOperation("资源列表转发")
@LogOperation("资源列表转发")
public Result yaweiApproveStatus(@ApiParam("页数") Integer page,
@ApiParam("页大小") Integer size,
@ApiParam("资源模糊搜索") String title) {
if (page == null) page = 1;
if (size == null) size = 10;
String url = "http://15.72.158.81/zyjk/ZywMessage.asmx";
String parame = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <soap:Body>\n" +
" <ZySPPort xmlns=\"http://tempuri.org/\">\n" +
" <userguid>e8d2fb43-f512-4918-ab47-1141b925af10</userguid>\n" +
" <pagenum>1</pagenum>\n" +
" <pagesize>10</pagesize>\n" +
" <title></title>\n" +
" </ZySPPort>\n" +
" </soap:Body>\n" +
"</soap:Envelope>";
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("SOAPAction", "http://tempuri.org/ZWCJ_mainPort");
requestHeaders.setContentType(new MediaType("text", "xml", Charset.forName("utf-8")));
HttpEntity<String> requestEntity = new HttpEntity<>(parame, requestHeaders);
try {
String body = restTemplate.postForEntity(url, requestEntity, String.class).getBody();
String startTag = "<ZWCJ_mainPortResult>";
String endTag = "</ZWCJ_mainPortResult>";
String json = body.substring(body.indexOf(startTag) + startTag.length(), body.indexOf(endTag));
HashMap result = JSON.parseObject(json, HashMap.class);
return new Result().ok(result);
} catch (Exception e) {
e.printStackTrace();
return new Result().ok(new ArrayList(0));
}
}
@GetMapping("qdyjjWeather")
@ApiOperation("青岛应急局-查询青岛市地区天气信息")
@LogOperation("青岛应急局-查询青岛市地区天气信息")

View File

@ -59,14 +59,14 @@ spring:
database: 0
host: 127.0.0.1
port: 6379
password: # 密码(默认为空)
password: # 密码(默认为空)
timeout: 6000ms # 连接超时时长(毫秒)
jedis:
pool:
max-active: 1000 # 连接池最大连接数(使用负值表示没有限制)
max-active: 1000 # 连接池最大连接数(使用负值表示没有限制)
max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)
max-idle: 10 # 连接池中的最大空闲连接
min-idle: 5 # 连接池中的最小空闲连接
max-idle: 10 # 连接池中的最大空闲连接
min-idle: 5 # 连接池中的最小空闲连接
activiti:
check-process-definitions: false
resources:
@ -81,7 +81,7 @@ spring:
parser:
# 允许出现特殊字符和转义符
allow_unquoted_control_chars: true
#允许出现单引号
# 允许出现单引号
allow_single_quotes: true
fdfs:

View File

@ -54,8 +54,13 @@
<include>domain/**</include>
</includes>
<excludes>
<exclude>application-prod.yml</exclude>
<exclude>application-bt.yml</exclude>
<exclude>application-dev.yml</exclude>
<exclude>application-hwx.yml</exclude>
<exclude>application-my.yml</exclude>
<exclude>application-prod.yml</exclude>
<exclude>application-show.yml</exclude>
<exclude>application-test.yml</exclude>
<exclude>application-xha.yml</exclude>
</excludes>
<filtered>true</filtered>

View File

@ -0,0 +1,7 @@
#!/bin/sh
Xmx $1
VERTICLE_HOME $2
JAR_FILE $3
ACTIVE $4
java -jar -Dfile.encoding=utf-8 -server -Xshareclasses -Xtune:virtualized -Xms512M -Xmx${Xmx} -XX:ReservedCodeCacheSize=240m -XX:InitialCodeCacheSize=240m -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -XX:ConcGCThreads=1 -XX:ParallelGCThreads=2 -XX:ZCollectionInterval=120 -XX:ZAllocationSpikeTolerance=5 -Duser.timezone=GMT+08 ${VERTICLE_HOME}/renren-admin/${JAR_FILE} --spring.profiles.active=${ACTIVE}

View File

@ -1,8 +1,9 @@
#! /bin/bash
#chkconfig: 2345 85 15
#description:auto_run
#processname:zf
#processname:ucs
#JAR根位置
PROFILES_ACTIVE=$2
JAR_ROOT=$(pwd)
#JAR位置
JAR_PATH="$JAR_ROOT"/renren-admin.jar
@ -10,10 +11,15 @@ JAR_PATH="$JAR_ROOT"/renren-admin.jar
#LOG位置
LOG_PATH=/dev/null
# 参数校验
if [ -z "$PROFILES_ACTIVE" ]; then
PROFILES_ACTIVE = "prod"
fi
#开始方法
start() {
cd $JAR_ROOT
nohup java -Dfile.encoding=utf-8 -server -Xms256m -Xmx2g -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./ -jar $JAR_PATH >$LOG_PATH 2>&1 &
nohup java -Dfile.encoding=utf-8 -server -Xms256m -Xmx2g -XX:+HeapDumpOnOutOfMemoryError -Duser.timezone=GMT+08 -XX:HeapDumpPath=./ -jar $JAR_PATH --spring.profiles.active=$PROFILES_ACTIVE >$LOG_PATH 2>&1 &
echo "$JAR_PATH start success."
}

View File

@ -0,0 +1,109 @@
#!/bin/sh
# $1 参数$1是当前目录即`pwd`,一般来说是/ava_app/platform/app
# $2 参数$2是更新包的文件一般为/ava_app/platform/app/upload/update/xxxwebapps.tar.gz
# $3 APP的名称。yhd
# $4: 生效的配置文件 prod、 dev
# 这里全部使用绝对路径,不要使用相对路径!!因为调用了其他脚本,可能发生路径问题。
# 变量声明
APP_DIR=$1
UPDATE_PACKAGE=$2
APP_NAME=$3
PROFILES_ACTIVE=$4
# 更新日志写在项目根目录中
LOG_FILE="${APP_DIR}/update.log"
# 删除系统生成的临时文件
#rm -rf /tmp/tomcat-*
#rm -rf /tmp/ehcache/*
# 将更新过程中出现的输出打印到日志文件中
rm -f $LOG_FILE
exec 1>$LOG_FILE 2>&1
# 参数校验
if [ -z "$APP_DIR" ] || [ -z "$UPDATE_PACKAGE" ] || [ -z "$APP_NAME" ]; then
echo "必要参数缺失"
exit 1
fi
# 参数校验
if [ -z "$PROFILES_ACTIVE" ]; then
PROFILES_ACTIVE = "prod"
fi
if [ "$APP_DIR" = "/" ]; then
echo "APP_DIR 不能为 /"
exit 1
fi
if [ ! -f "$UPDATE_PACKAGE" ]; then
echo "平台更新包不存在"
exit 1
fi
# 停止程序,如果停止之后还有进程,那么直接杀死
sleep 5
sh ${APP_DIR}/renren-admin.sh stop
# 创建临时文件夹,用于解压更新包
rm -rf ${APP_DIR}/tmp
mkdir -p ${APP_DIR}/tmp
# 将更新包移动到tmp目录重命名为app.tar.gz然后解压
mv $UPDATE_PACKAGE ${APP_DIR}/tmp/app.tar.gz
tar -zxvf ${APP_DIR}/tmp/app.tar.gz -C ${APP_DIR}/tmp
chmod -R 766 ${APP_DIR}/tmp
# 更新指定的项目。
# 1. 如果备份是今天以前的则移除之前的备份,重新备份
# 2. 更新项目
# 如果项目的jar存在那么更新
if [ -f "${APP_DIR}/tmp/${APP_NAME}/${APP_NAME}.jar" ]; then
echo "正在更新 ${APP_NAME} 项目"
# 备份项目
b=0
if [ -d ${APP_DIR}/snapshot ]; then
b=`stat -c %Y ${APP_DIR}/snapshot`
else
mkdir -p ${APP_DIR}/snapshot/
fi
e=`date +%s`
p=$(($e-$b))
if [ $p -gt 86400 ]; then
echo "正在备份 ${APP_NAME} 项目"
# 删除文件夹,再重新创建,这样上面才可以检测时间
rm -rf ${APP_DIR}/snapshot
mkdir -p ${APP_DIR}/snapshot
# 备份lib、jar
\cp -rf ${APP_DIR}/lib ${APP_DIR}/snapshot
\cp -rf ${APP_DIR}/config ${APP_DIR}/snapshot
\cp -rf ${APP_DIR}/${APP_NAME}.jar ${APP_DIR}/snapshot
echo "${APP_NAME} 项目备份完成"
fi
# 更新项目
echo "正在进行增量更新"
rm -rf ${APP_DIR}/lib/*.jar
echo "已删除lib依赖"
\cp -rf ${APP_DIR}/tmp/${APP_NAME}/lib ${APP_DIR}/
\cp -rf ${APP_DIR}/tmp/${APP_NAME}/config ${APP_DIR}/
\cp -rf ${APP_DIR}/tmp/${APP_NAME}/${APP_NAME}.jar ${APP_DIR}/
echo "${APP_NAME} 项目更新完成"
else
echo "${APP_NAME} 项目程序不存在 ${APP_DIR}/tmp/${APP_NAME}/${APP_NAME}.jar"
fi
# 移除更新包以及更新的项目
rm -rf ${APP_DIR}/tmp/*
# 重启平台
sh ${APP_DIR}/renren-admin.sh start ${PROFILES_ACTIVE}
exit 0