Commit 6e929ee3 authored by zhangqingle's avatar zhangqingle

修改文件上传

parent af4547d6
......@@ -240,7 +240,7 @@ public class BLessonPersonServiceImpl implements BLessonPersonService {
bLessonPerson.setIsAppoint("0");
result = bLessonPersonRepository.updateByPrimaryKeySelective(bLessonPerson);
}
if (bLesson != null && "0".equals(bLesson.getLessonType()) && (IsFinishEnum.LEARNING.getCode().equals(bLessonPerson.getIsFinish()) || IsFinishEnum.FINISHED.getCode().equals(bLessonPerson.getIsFinish()))){
if (bLesson != null && LessonTypeEnum.LESSON.getCode().equals(bLesson.getLessonType()) && (IsFinishEnum.LEARNING.getCode().equals(bLessonPerson.getIsFinish()) || IsFinishEnum.FINISHED.getCode().equals(bLessonPerson.getIsFinish()))){
//已开始执行更新
UserUtil.setCurrentMergeOperation(bLessonPerson);
bLessonPerson.setIsAppoint("0");
......
......@@ -26,8 +26,8 @@ public class MTMicroappApiRequestClient {
public static Long zxAccountId = (long)1;
// @Value("${appId.noticeAppId}")
private Long appId = (long)123321123;
@Value("${appId.noticeAppId}")
private Long appId;
@Autowired
private MicroappFeignClient microappFeignClient;
......
......@@ -33,6 +33,8 @@ import java.util.List;
@Slf4j
public class MvcConfig extends WebMvcConfigurerAdapter {
static String MESS = "网络异常";
@Value("${spring.profiles.active}")
private String env;//当前激活的配置文件
......@@ -91,8 +93,8 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
log.error(message);
if (e instanceof ServiceException) {//业务失败的异常,如“账号或密码错误”
ServiceException se = (ServiceException) e;
result.setCode(ResultCode.FAIL).setMessage(e.getMessage()).setData(Result.builder(se.getCode(),message,null));
}else {
result.setCode(ResultCode.FAIL).setMessage(e.getMessage()).setData(Result.builder(se.getCode(), message, null));
} else {
result.setCode(ResultCode.ERROR).setMessage(message);
}
} else {
......@@ -102,6 +104,9 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
result.setCode(ResultCode.ERROR).setMessage(e.getMessage());
}
}
if ("prod".equalsIgnoreCase(serverType)){
result.setMessage(MvcConfig.MESS);
}
log.error(message);
ResponseUtil.responseResult(response, result);
return new ModelAndView();
......
......@@ -79,6 +79,38 @@ public class OfficeToPdf {
opc.transformToPdf(path+"abc.pptx", path+"1.pdf");
}
static OpenOfficeConnection connection = null;
public static OpenOfficeConnection getConnection(Global global){
//关闭状态
if(null == connection || ! connection.isConnected()) {
connection = new SocketOpenOfficeConnection(
global.getLibreofficeIp(), global.getLibreofficePort());
try {
LogUtil.fileChangeLog("****************connect + begin***********" + DateFormatUtils.format(new Date(), "HH:mm:ss"));
connection.connect();
LogUtil.fileChangeLog("****************connect + end***********" + DateFormatUtils.format(new Date(), "HH:mm:ss"));
} catch (ConnectException e) {
LogUtil.fileChangeLog("----------------------ConnectException------------------" + e);
e.printStackTrace();
}
}
return connection;
}
static DocumentConverter converter = null;
public static DocumentConverter getConverter(){
if(null == converter){
converter = new OpenOfficeDocumentConverter(
connection);
}
return converter;
}
/**
* 转换pdf
* @param sourceFile
......@@ -87,10 +119,14 @@ public class OfficeToPdf {
*
* synchronized
*/
public synchronized int transformToPdf(String sourceFile, String destFile){
public int transformToPdf(String sourceFile, String destFile){
OfficeToPdf.getConnection(global);
// convert
LogUtil.fileChangeLog("----------创建OpenOfficeDocumentConverter------------");
OfficeToPdf.getConverter();
synchronized (converter) {
LogUtil.fileChangeLog("****************transform + begin***********" + DateFormatUtils.format(new Date(), "HH:mm:ss"));
OpenOfficeConnection connection = null;
try {
File inputFile = new File(sourceFile);
if (!inputFile.exists()) {
return -1;// 找不到源文件, 则返回-1
......@@ -103,46 +139,17 @@ public class OfficeToPdf {
}
LogUtil.fileChangeLog("----------新建SocketOpenOfficeConnection连接------------");
// connect to an OpenOffice.org instance running on port 8100
connection = new SocketOpenOfficeConnection(
global.getLibreofficeIp(), global.getLibreofficePort());
LogUtil.fileChangeLog("****************connect + begin***********" + DateFormatUtils.format(new Date(), "HH:mm:ss"));
connection.connect();
LogUtil.fileChangeLog("****************connect + end***********" + DateFormatUtils.format(new Date(), "HH:mm:ss"));
// convert
LogUtil.fileChangeLog("----------创建OpenOfficeDocumentConverter------------");
DocumentConverter converter = new OpenOfficeDocumentConverter(
connection);
DocumentFormatRegistry factory = new BasicDocumentFormatRegistry();
LogUtil.fileChangeLog("----------设置输入输出------------");
DocumentFormat inputDocumentFormat = factory
.getFormatByFileExtension(FileUtil.getFilePostfix(sourceFile));
DocumentFormat outputDocumentFormat = factory
.getFormatByFileExtension(FileUtil.getFilePostfix(destFile));
LogUtil.fileChangeLog("开始转换--> "+ sourceFile);
converter.convert(inputFile,inputDocumentFormat,outputFile,outputDocumentFormat);
LogUtil.fileChangeLog("转换完毕--> "+ destFile);
LogUtil.fileChangeLog("开始转换--> " + sourceFile);
converter.convert(inputFile, inputDocumentFormat, outputFile, outputDocumentFormat);
LogUtil.fileChangeLog("转换完毕--> " + destFile);
LogUtil.fileChangeLog("****************transform + end***********" + DateFormatUtils.format(new Date(), "HH:mm:ss"));
// close the connection
} catch (ConnectException e) {
LogUtil.fileChangeLog("----------------------ConnectException------------------"+e);
e.printStackTrace();
} catch (IOException e) {
LogUtil.fileChangeLog("----------------------IOException------------------"+e);
e.printStackTrace();
return 0;
}finally {
if(connection!=null) {
LogUtil.fileChangeLog("----------------------finally1-断开连接------------------");
connection.disconnect();
}else{
LogUtil.fileChangeLog("----------------------finally2-无连接抛异常------------------");
// throw new ServiceException(ResultServiceEnums.CHANGE_FILE_ERROR);
throw new ServiceException(ResultServiceEnums.CHANGE_HAVE_MEDIA);
}
}
return 1;
}
......
......@@ -126,3 +126,7 @@ notice:
urlTrain: http://192.168.9.39:8001/#/trainDetail?
urlExam: http://192.168.9.39:8001/#/onlineExamination?
defaultUrl: http://zx-zgiot-002.oss-cn-qingdao.aliyuncs.com/image/2d60950fefa14041b4d9715a70a7d389.png
appId:
globalAppId: 1
noticeAppId: 9
\ No newline at end of file
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