Merge branch 'dev' of http://192.168.124.50/wangliwen/share-platform into dev
* 'dev' of http://192.168.124.50/wangliwen/share-platform: ... 导出能力挂接内资源 下载运行日志文件 列出日志文件与提供下载日志文件接口 TODO 列出日志文件 屮 启动脚本 500 屮 。。。 下载更新包失败的处理 调整更新接口 # Conflicts: # renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java
This commit is contained in:
commit
6f04dc91bc
|
@ -1,26 +1,41 @@
|
|||
package io.renren.common.controller;
|
||||
|
||||
|
||||
import io.renren.common.annotation.LogOperation;
|
||||
import io.renren.common.utils.Result;
|
||||
import io.renren.common.utils.UpdateUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
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 更新包下载地址
|
||||
|
@ -28,10 +43,49 @@ public class AdminController {
|
|||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/update")
|
||||
@ApiOperation("进行后台程序更新")
|
||||
@LogOperation("进行后台程序更新")
|
||||
public Result<String> update(String updateFile, String active) {
|
||||
return new Result<String>().ok("");
|
||||
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_));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -505,9 +505,6 @@ public class CensusController {
|
|||
SysDeptDTO sysDeptDTO = sysDeptService.get(user.getDeptId());
|
||||
params.put("region", sysDeptDTO.getDistrict()); // 管理员只出本部门区域
|
||||
}
|
||||
// else if (user.getSuperAdmin() == SuperAdminEnum.YES.value()) { // 超级管理员
|
||||
//
|
||||
// }
|
||||
ArrayList<Map> resultList = (ArrayList<Map>) resourceDao.selectCensusResourceTable(params);
|
||||
List<List<Object>> date = resultList.stream().map(index -> {
|
||||
List<Object> data = new ArrayList<>();
|
||||
|
|
|
@ -14,6 +14,7 @@ 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;
|
||||
|
@ -56,7 +57,7 @@ public class UpdateUtil {
|
|||
if (!folder.isDirectory()) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
Request request = new Request.Builder().url(updateFile).build();
|
||||
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)) {
|
||||
|
@ -74,7 +75,7 @@ public class UpdateUtil {
|
|||
return file.getAbsolutePath();
|
||||
}
|
||||
} else {
|
||||
logger.error("下载更新包失败:{}", updateFile);
|
||||
logger.error("下载更新包失败:{},错误码:{}", updateFile, response.code());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("下载更新包失败:" + updateFile, e);
|
||||
|
@ -87,8 +88,9 @@ public class UpdateUtil {
|
|||
* @param active 启动程序的配置文件
|
||||
*/
|
||||
private void execUpdate(String updateFilePath, String active) {
|
||||
String cmd = String.format("cd %s && sh update.sh %s %s", pwd, pwd, updateFilePath, "renren-admin", active);
|
||||
logger.info("执行指令:{}", cmd);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ import io.renren.modules.resource.dataResource.DataResourceFactory;
|
|||
import io.renren.modules.resource.dto.GetDataResourceListDto;
|
||||
import io.renren.modules.resource.dto.ResourceDTO;
|
||||
import io.renren.modules.resource.excel.ResourceExcelImportListener;
|
||||
import io.renren.modules.resource.excel.census.config.CustomCellWriteHeightConfig;
|
||||
import io.renren.modules.resource.excel.census.config.CustomCellWriteWeightConfig;
|
||||
import io.renren.modules.resource.service.ResourceService;
|
||||
import io.renren.modules.resource.videoPreview.AbstractVideoPreviewService;
|
||||
import io.renren.modules.resource.videoPreview.VideoPreviewFactory;
|
||||
|
@ -46,8 +48,10 @@ import springfox.documentation.annotations.ApiIgnore;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -114,8 +118,12 @@ public class ResourceController {
|
|||
@Autowired
|
||||
private SysDeptService sysDeptService;
|
||||
|
||||
@Autowired
|
||||
private SysUserDao sysUserDao;
|
||||
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Resource(name = "${hisense.gateway.name}")
|
||||
private ApiGateway apiGateway;
|
||||
|
||||
|
@ -153,6 +161,82 @@ public class ResourceController {
|
|||
return new Result<PageData<ResourceDTO>>().ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("/export")
|
||||
@ApiOperation("导出资源")
|
||||
@LogOperation("导出资源")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "startDate", value = "开始时间", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "endDate", value = "结束时间", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "type", value = "资源类型", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "deptId", value = "所属部门", paramType = "query", dataType = "long"),
|
||||
@ApiImplicitParam(name = "approveStatus", value = "审核状态,可选值(通过、审核中)", paramType = "query", dataType = "String"),
|
||||
})
|
||||
public void exportSelectCensusResourceTable(@RequestParam Map<String, Object> params, HttpServletResponse response) throws IOException {
|
||||
// UserDetail user = SecurityUser.getUser();
|
||||
// if (user.getDeptId() != null) {
|
||||
// SysDeptDTO sysDeptDTO = sysDeptService.get(user.getDeptId());
|
||||
// params.put("region", sysDeptDTO.getDistrict()); // 管理员只出本部门区域
|
||||
// }
|
||||
List<ResourceDTO> result = resourceService.list(params);
|
||||
List<List<Object>> date = result.stream().map(index -> {
|
||||
List<Object> data = new ArrayList<>();
|
||||
data.add(index.getName());
|
||||
data.add(index.getDescription());
|
||||
Optional<SysDeptDTO> sysDeptDTOOptional = Optional.ofNullable(sysDeptService.get(index.getDeptId() == null ? 0l : index.getDeptId()));
|
||||
if (sysDeptDTOOptional.isPresent()) {
|
||||
data.add(sysDeptDTOOptional.get().getName());
|
||||
} else {
|
||||
data.add("--");
|
||||
}
|
||||
Optional<String> yyly = index.getInfoList().stream().filter(index_ -> index_.getAttrType().equals("应用领域") && index_.getDelFlag().intValue() == 0).map(index_ -> index_.getAttrValue()).findFirst();
|
||||
if (yyly.isPresent()) {
|
||||
data.add(yyly.get());
|
||||
} else {
|
||||
data.add("--");
|
||||
}
|
||||
data.add(index.getCreateDate() == null ? "--" : index.getCreateDate().toString());
|
||||
|
||||
SysUserDTO userDTO = sysUserService.get(index.getCreator() == null ? 0l : index.getCreator());
|
||||
if (userDTO != null) {
|
||||
data.add(userDTO.getUsername());
|
||||
} else {
|
||||
data.add("--");
|
||||
}
|
||||
return data;
|
||||
}).collect(Collectors.toList());
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
String fileName = URLEncoder.encode("资源导出_" + System.currentTimeMillis(), "UTF-8").replaceAll("\\+", "%20");
|
||||
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
||||
EasyExcel.write(response.getOutputStream()).head(exportSelectCensusResourceTableHead())
|
||||
.registerWriteHandler(new CustomCellWriteWeightConfig())
|
||||
.registerWriteHandler(new CustomCellWriteHeightConfig())
|
||||
.sheet("上架情况").doWrite(date);
|
||||
}
|
||||
|
||||
private List<List<String>> exportSelectCensusResourceTableHead() {
|
||||
List<List<String>> list = new ArrayList<>();
|
||||
List<String> head0 = new ArrayList<>();
|
||||
head0.add("名称");
|
||||
List<String> head1 = new ArrayList<>();
|
||||
head1.add("描述");
|
||||
List<String> head2 = new ArrayList<>();
|
||||
head2.add("归属部门");
|
||||
List<String> head3 = new ArrayList<>();
|
||||
head3.add("应用领域");
|
||||
List<String> head4 = new ArrayList<>();
|
||||
head4.add("上架时间");
|
||||
List<String> head5 = new ArrayList<>();
|
||||
head4.add("上架账号");
|
||||
list.add(head0);
|
||||
list.add(head1);
|
||||
list.add(head2);
|
||||
list.add(head3);
|
||||
list.add(head4);
|
||||
list.add(head5);
|
||||
return list;
|
||||
}
|
||||
|
||||
@PostMapping("/pageWithAttrs")
|
||||
@ApiOperation("分页查询资源信息2")
|
||||
@LogOperation("分页查询资源信息2")
|
||||
|
@ -451,8 +535,8 @@ public class ResourceController {
|
|||
@ApiOperation("资源列表转发")
|
||||
@LogOperation("资源列表转发")
|
||||
public Result yaweiApproveStatus(@ApiParam("页数") Integer page,
|
||||
@ApiParam("页大小") Integer size,
|
||||
@ApiParam("资源模糊搜索") String title) {
|
||||
@ApiParam("页大小") Integer size,
|
||||
@ApiParam("资源模糊搜索") String title) {
|
||||
|
||||
if (page == null) page = 1;
|
||||
if (size == null) size = 10;
|
||||
|
|
|
@ -19,7 +19,7 @@ fi
|
|||
#开始方法
|
||||
start() {
|
||||
cd $JAR_ROOT
|
||||
nohup java -Dfile.encoding=utf-8 -server -Xms256m -Xmx2g -XX:+HeapDumpOnOutOfMemoryError -Duser.timezone=GMT+08 -XX:HeapDumpPath=./ -jar --spring.profiles.active=$PROFILES_ACTIVE $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."
|
||||
}
|
||||
|
||||
|
|
|
@ -98,12 +98,12 @@ if [ -f "${APP_DIR}/tmp/${APP_NAME}/${APP_NAME}.jar" ]; then
|
|||
\cp -rf ${APP_DIR}/tmp/${APP_NAME}/${APP_NAME}.jar ${APP_DIR}/
|
||||
echo "${APP_NAME} 项目更新完成"
|
||||
else
|
||||
echo "${APP_NAME} 项目程序不存在"
|
||||
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}
|
||||
sh ${APP_DIR}/renren-admin.sh start ${PROFILES_ACTIVE}
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue