Commit 6e929ee3 authored by zhangqingle's avatar zhangqingle

修改文件上传

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