Commit 6481d28a authored by 廖旭伟's avatar 廖旭伟

保存页面截图接口修改为文件路径存储

parent d8182ee8
package com.mortals.xhx.module.page.service.impl;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.common.utils.ImageBase64;
import com.mortals.xhx.module.page.model.PageInfoQuery;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
......@@ -21,6 +24,10 @@ import java.util.Date;
@Service("pageInfoService")
public class PageInfoServiceImpl extends AbstractCRUDServiceImpl<PageInfoDao, PageInfoEntity, Long> implements PageInfoService {
@Value("${upload.path}")
@Getter
private String filePath;
@Override
protected void saveBefore(PageInfoEntity entity, Context context) throws AppException {
this.validData(entity, context);
......@@ -47,6 +54,7 @@ public class PageInfoServiceImpl extends AbstractCRUDServiceImpl<PageInfoDao, Pa
query.setDeviceNum(entity.getDeviceNum());
PageInfoEntity pageInfoEntity = this.selectOne(query);
if(pageInfoEntity==null){
doSaveImageBase64(entity,"");
entity.setCreateTime(new Date());
int iRet = this.dao.insert(entity);
if (iRet == 0) {
......@@ -56,6 +64,7 @@ public class PageInfoServiceImpl extends AbstractCRUDServiceImpl<PageInfoDao, Pa
return entity;
}
}else {
doSaveImageBase64(entity,pageInfoEntity.getScreenUrl());
PageInfoEntity updateEntity = new PageInfoEntity();
updateEntity.setId(pageInfoEntity.getId());
updateEntity.setScreenUrl(pageInfoEntity.getScreenUrl());
......@@ -69,6 +78,25 @@ public class PageInfoServiceImpl extends AbstractCRUDServiceImpl<PageInfoDao, Pa
return entity;
}
}
}
private void doSaveImageBase64(PageInfoEntity entity,String oldName){
String base64 = String.valueOf(entity.getScreenUrl());
if(StringUtils.isEmpty(base64)){
throw new AppException("图片不能为空");
}
String imageName = new Date().getTime() + ".png";
String imagePath = "/file/uploadfile/"+imageName;
if(StringUtils.isNotEmpty(oldName)){
imagePath = oldName;
}
String filePath = this.filePath.endsWith("/") ? this.filePath : this.filePath + "/" + imagePath;
try{
ImageBase64.convertImg(base64.trim(),filePath);
entity.setScreenUrl(imagePath);
}catch (Exception e){
log.error("base64图片转换异常",e.fillInStackTrace());
entity.setScreenUrl("");
}
}
}
\ 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