|
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
import cn.hutool.core.lang.Snowflake; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.ccsens.tall.bean.dto.WpsDto; |
|
|
|
import com.ccsens.tall.bean.po.*; |
|
|
|
import com.ccsens.tall.bean.vo.UserVo; |
|
|
@ -26,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.http.Part; |
|
|
|
import java.io.File; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
@ -59,7 +61,7 @@ public class WpsService implements IWpsService { |
|
|
|
@Resource |
|
|
|
private Snowflake snowflake; |
|
|
|
|
|
|
|
private String fileUrl = "http://wwo.wps.cn/office/{}/{}?_w_fname={}&_w_userid={}&_w_appid="+WebConstant.Wps.APPID+"&_w_signature={}"; |
|
|
|
private String fileUrl = "http://wwo.wps.cn/office/{}/{}?_w_appid="+WebConstant.Wps.APPID+"&_w_signature={}"; |
|
|
|
|
|
|
|
@Override |
|
|
|
public void notify(String token, WpsDto.NotifyBody body) throws Exception { |
|
|
@ -67,7 +69,7 @@ public class WpsService implements IWpsService { |
|
|
|
WpsNotify wpsNotify = new WpsNotify(); |
|
|
|
wpsNotify.setId(snowflake.nextId()); |
|
|
|
wpsNotify.setCmd(body.getCmd()); |
|
|
|
wpsNotify.setBody(body.getBody()); |
|
|
|
wpsNotify.setBody(body.getBody().toJSONString()); |
|
|
|
wpsNotifyMapper.insertSelective(wpsNotify); |
|
|
|
} |
|
|
|
|
|
|
@ -88,13 +90,14 @@ public class WpsService implements IWpsService { |
|
|
|
// 删除原来的文件版本记录
|
|
|
|
WpsFileVersionExample wpsFileVersionExample = new WpsFileVersionExample(); |
|
|
|
wpsFileVersionExample.createCriteria().andFileIdEqualTo(fileId) |
|
|
|
.andVersionEqualTo(wpsFile.getCurrentVersion()) |
|
|
|
.andVersionEqualTo(file.getCurrentVersion()) |
|
|
|
.andRecStatusEqualTo(WebConstant.REC_STATUS.Normal.value); |
|
|
|
WpsFileVersion updateVersion = new WpsFileVersion(); |
|
|
|
updateVersion.setRecStatus(WebConstant.REC_STATUS.Deleted.value); |
|
|
|
wpsFileVersionMapper.updateByExampleSelective(updateVersion, wpsFileVersionExample); |
|
|
|
// 保存版本信息
|
|
|
|
WpsFileVersion version = saveVersion(wpsFile); |
|
|
|
WpsFile newWpsFile = wpsFileDao.selectByPrimaryKey(fileId); |
|
|
|
WpsFileVersion version = saveVersion(newWpsFile); |
|
|
|
// 保存操作记录
|
|
|
|
WpsFileUser fileUser = initFileUser(userId, version.getId()); |
|
|
|
fileUser.setOperation(WebConstant.Wps.USER_OPERATION_RENAME); |
|
|
@ -112,7 +115,8 @@ public class WpsService implements IWpsService { |
|
|
|
public WpsVo.FileBase fileVersion(String token, Long fileId, Integer version) throws Exception { |
|
|
|
Long userId = getUserId(token); |
|
|
|
// 查找指定版本version
|
|
|
|
WpsVo.FileBase base = wpsFileDao.getVersion(fileId, version); |
|
|
|
Map<String, Object> map = wpsFileDao.getVersion(fileId, version); |
|
|
|
WpsVo.FileBase base = JSONObject.parseObject(JSONObject.toJSONString(map), WpsVo.FileBase.class); |
|
|
|
// 保存用户打开文件旧版本记录
|
|
|
|
WpsFileUser wpsFileUser = initFileUser(userId, base.getFileVersionId()); |
|
|
|
wpsFileUser.setOperation(WebConstant.Wps.USER_OPERATION_OLD); |
|
|
@ -128,13 +132,13 @@ public class WpsService implements IWpsService { |
|
|
|
String fileType = WebConstant.Wps.getFileType(ext); |
|
|
|
Map<String, String> paramMap= new HashMap<>(); |
|
|
|
paramMap.put("_w_appid", WebConstant.Wps.APPID); |
|
|
|
paramMap.put("_w_fname", fileName); |
|
|
|
paramMap.put("_w_userid", String.valueOf(wpsFile.getCreator())); |
|
|
|
// paramMap.put("_w_fname", fileName);
|
|
|
|
// paramMap.put("_w_userid", String.valueOf(wpsFile.getCreator()));
|
|
|
|
String newSignature = WpsSignature.getSignature(paramMap, WebConstant.Wps.APPKEY); |
|
|
|
String url = StrUtil.format(fileUrl, fileType, wpsFile.getId(), fileName, newSignature); |
|
|
|
String url = StrUtil.format(fileUrl, fileType, wpsFile.getId(), newSignature); |
|
|
|
WpsVo.FileNew fileNew = new WpsVo.FileNew(); |
|
|
|
fileNew.setRedirect_url(url); |
|
|
|
fileNew.setUser_id(fileNew.getUser_id()); |
|
|
|
fileNew.setUser_id(String.valueOf(wpsFile.getCreator())); |
|
|
|
return fileNew; |
|
|
|
} |
|
|
|
|
|
|
@ -217,10 +221,7 @@ public class WpsService implements IWpsService { |
|
|
|
WpsFile wpsFile = saveWpsFile(token, fileId, file,WebConstant.Wps.USER_OPERATION_SAVE); |
|
|
|
|
|
|
|
// 返回参数
|
|
|
|
WpsVo.FileBase fileBase = new WpsVo.FileBase(); |
|
|
|
BeanUtils.copyProperties(wpsFile, fileBase); |
|
|
|
fileBase.setCreate_time(wpsFile.getCreatedAt().getTime()/1000); |
|
|
|
fileBase.setModify_time(wpsFile.getUpdatedAt().getTime()/1000); |
|
|
|
WpsVo.FileBase fileBase = new WpsVo.FileBase(wpsFile); |
|
|
|
|
|
|
|
return new WpsVo.FileSave(fileBase); |
|
|
|
} |
|
|
@ -282,10 +283,18 @@ public class WpsService implements IWpsService { |
|
|
|
} |
|
|
|
wpsFile.setCurrentVersion(wpsFile.getCurrentVersion() + 1); |
|
|
|
} |
|
|
|
wpsFile.setCreatedAt(new Date()); |
|
|
|
wpsFile.setUpdatedAt(new Date()); |
|
|
|
wpsFile.setName(name); |
|
|
|
wpsFile.setSize(file.getSize()); |
|
|
|
wpsFile.setDownloadUrl(PropUtil.domain + filePath); |
|
|
|
wpsFile.setDownloadUrl(PropUtil.domain + "file/download/" + name + "?path=" + filePath); |
|
|
|
wpsFile.setModifier(userId); |
|
|
|
|
|
|
|
if (StrUtil.isEmpty(fileId)) { |
|
|
|
wpsFileDao.insertSelective(wpsFile); |
|
|
|
} else { |
|
|
|
wpsFileDao.updateByPrimaryKeySelective(wpsFile); |
|
|
|
} |
|
|
|
return wpsFile; |
|
|
|
} |
|
|
|
|
|
|
|