feat: 上传新版本后对每个旧版本制作补丁包
parent
d26658c840
commit
f76d121f0c
@ -0,0 +1,98 @@
|
||||
package com.shxy.xymanager_service.impl;
|
||||
|
||||
import com.shxy.xymanager_common.entity.MntnUpgrades;
|
||||
import com.shxy.xymanager_common.entity.MntnUpgradesExample;
|
||||
import com.shxy.xymanager_common.entity.MntnUpgradesPatch;
|
||||
import com.shxy.xymanager_common.entity.MntnUpgradesPatchExample;
|
||||
import com.shxy.xymanager_dao.dao.MntnUpgradesMapper;
|
||||
import com.shxy.xymanager_dao.dao.MntnUpgradesPatchMapper;
|
||||
import com.shxy.xymanager_service.service.UpgradePatchService;
|
||||
import io.sigpipe.jbsdiff.Diff;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class UpgradePatchServiceImpl implements UpgradePatchService {
|
||||
|
||||
@Value("${maintain.apk}")
|
||||
private String apkpath;
|
||||
@Value("${maintain.patch}")
|
||||
private String patchpath;
|
||||
@Value("${maintain.uri}")
|
||||
private String uri;
|
||||
|
||||
@Resource
|
||||
MntnUpgradesMapper upgradesMapper;
|
||||
@Resource
|
||||
MntnUpgradesPatchMapper patchMapper;
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void processPatch(MntnUpgrades upg) throws Exception {
|
||||
if (StringUtils.isBlank(upg.getApp()) || StringUtils.isBlank(upg.getVersion())) {
|
||||
return;
|
||||
}
|
||||
String app = upg.getApp();
|
||||
String ver = upg.getVersion();
|
||||
|
||||
MntnUpgradesExample example = new MntnUpgradesExample();
|
||||
MntnUpgradesExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andAppEqualTo(app);
|
||||
criteria.andVersionNotEqualTo(ver);
|
||||
example.setOrderByClause("id asc");
|
||||
List<MntnUpgrades> list = upgradesMapper.selectByExample(example);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] newIn = Files.readAllBytes(Paths.get(apkpath + upg.getPath()));
|
||||
for (MntnUpgrades item : list) {
|
||||
if (StringUtils.isNotBlank(item.getVersion())) {
|
||||
String oldpath = apkpath + item.getPath();
|
||||
try {
|
||||
byte[] oldIn = Files.readAllBytes(Paths.get(oldpath));
|
||||
String filename = app + "_" + item.getVersion() + "_" + ver + ".patch";
|
||||
FileOutputStream fos = new FileOutputStream(new File(patchpath + filename));
|
||||
Diff.diff(oldIn, newIn, fos);
|
||||
log.info("生成" + filename);
|
||||
long fileSize = Files.size(Paths.get(patchpath + filename));
|
||||
MntnUpgradesPatch record = new MntnUpgradesPatch();
|
||||
record.setApp(app);
|
||||
record.setOldVer(item.getVersion());
|
||||
record.setNewVer(ver);
|
||||
record.setPath(filename);
|
||||
record.setFileSize((int) fileSize);
|
||||
patchMapper.insert(record);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MntnUpgradesPatch> list(String app, String oldver) {
|
||||
MntnUpgradesPatchExample example = new MntnUpgradesPatchExample();
|
||||
MntnUpgradesPatchExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andAppEqualTo(app);
|
||||
if (StringUtils.isNotBlank(oldver)) {
|
||||
criteria.andOldVerEqualTo(oldver);
|
||||
}
|
||||
List<MntnUpgradesPatch> list = patchMapper.selectByExample(example);
|
||||
for (MntnUpgradesPatch item : list) {
|
||||
item.setPath(uri + "patch/" + item.getPath());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.shxy.xymanager_service.service;
|
||||
|
||||
import com.shxy.xymanager_common.entity.MntnUpgrades;
|
||||
import com.shxy.xymanager_common.entity.MntnUpgradesPatch;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UpgradePatchService {
|
||||
|
||||
void processPatch(MntnUpgrades upg) throws Exception;
|
||||
|
||||
List<MntnUpgradesPatch> list(String app, String oldver);
|
||||
|
||||
}
|
Loading…
Reference in New Issue