fix: 修正md5和下载path

dev
huangfeng 1 year ago
parent ae927b3cc1
commit dfda2f208a

@ -91,7 +91,8 @@ swagger2:
# urlPatterns: /system/*,/monitor/*,/tool/* # urlPatterns: /system/*,/monitor/*,/tool/*
#运维配置 #运维配置
maintain: maintain:
apk: /home/xymp/apk apk: /home/xymp/apk/
uri: http://61.169.135.146:40085/apk/
cma: cma:
server: 127.0.0.1 server: 127.0.0.1

@ -0,0 +1,40 @@
package com.shxy.xymanager_common.util;
import java.security.MessageDigest;
import java.util.Base64;
public class DigestUtils {
public static byte[] hash(byte[] message, String alg) throws Exception {
MessageDigest md = MessageDigest.getInstance(alg);
md.update(message);
return md.digest();
}
public static String md5(byte[] message, boolean b64Encoded) throws Exception {
byte[] data = hash(message, "MD5");
return b64Encoded ? new String(Base64.getEncoder().encode(data)) : HexUtils.byte2Hex(data);
}
public static String sha1(byte[] message, boolean b64Encoded) throws Exception {
byte[] data = hash(message, "SHA1");
return b64Encoded ? new String(Base64.getEncoder().encode(data)) : HexUtils.byte2Hex(data);
}
public static String sha256(byte[] message, boolean b64Encoded) throws Exception {
byte[] data = hash(message, "SHA256");
return b64Encoded ? new String(Base64.getEncoder().encode(data)) : HexUtils.byte2Hex(data);
}
public static String md5(byte[] message) throws Exception {
return md5(message, false);
}
public static String md5(String message) throws Exception {
return md5(message.getBytes(), false);
}
public static String sha1(byte[] message) throws Exception {
return sha1(message, false);
}
}

@ -0,0 +1,35 @@
package com.shxy.xymanager_common.util;
public class HexUtils {
private static final String HEX = "0123456789ABCDEF";
public static String byte2Hex(byte[] bytes) {
String result = "";
if (null != bytes) {
for (int i = 0; i < bytes.length; ++i) {
result = result + "0123456789ABCDEF".charAt(bytes[i] >> 4 & 15);
result = result + "0123456789ABCDEF".charAt(bytes[i] & 15);
}
}
return result;
}
public static byte[] hex2Byte(String text) throws Exception {
String hexText = text;
if (text.length() % 2 == 1) {
hexText = "0" + text;
}
hexText = hexText.toLowerCase();
int len = hexText.length() / 2;
byte[] result = new byte[len];
for (int i = 0; i < len; ++i) {
String s = hexText.substring(2 * i, 2 * i + 2);
result[i] = (byte) (Integer.parseInt(s, 16) & 255);
}
return result;
}
}

@ -5,9 +5,11 @@ import com.shxy.xymanager_common.entity.MntnUpgrades;
import com.shxy.xymanager_common.entity.MntnUpgradesExample; import com.shxy.xymanager_common.entity.MntnUpgradesExample;
import com.shxy.xymanager_common.exception.ApiException; import com.shxy.xymanager_common.exception.ApiException;
import com.shxy.xymanager_common.util.DateUtil; import com.shxy.xymanager_common.util.DateUtil;
import com.shxy.xymanager_common.util.DigestUtils;
import com.shxy.xymanager_dao.dao.MntnUpgradesMapper; import com.shxy.xymanager_dao.dao.MntnUpgradesMapper;
import com.shxy.xymanager_service.service.UpgradeService; import com.shxy.xymanager_service.service.UpgradeService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -16,6 +18,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.nio.file.Files;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -28,6 +31,8 @@ public class UpgradeServiceImpl implements UpgradeService {
@Value("${maintain.apk}") @Value("${maintain.apk}")
private String apkpath; private String apkpath;
@Value("${maintain.uri}")
private String uri;
@Resource @Resource
MntnUpgradesMapper mapper; MntnUpgradesMapper mapper;
@ -42,7 +47,7 @@ public class UpgradeServiceImpl implements UpgradeService {
example.setOrderByClause("id desc"); example.setOrderByClause("id desc");
List<MntnUpgrades> list = mapper.selectByExample(example); List<MntnUpgrades> list = mapper.selectByExample(example);
for (MntnUpgrades item : list) { for (MntnUpgrades item : list) {
item.setPath(uri + item.getPath());
} }
return list; return list;
} }
@ -62,8 +67,10 @@ public class UpgradeServiceImpl implements UpgradeService {
item.setCreateTime(new Date()); item.setCreateTime(new Date());
item.setUpdateTime(new Date()); item.setUpdateTime(new Date());
File dest = new File(apkpath + "/" + path); File dest = new File(apkpath + path);
file.transferTo(dest); file.transferTo(dest);
String md5 = DigestUtils.md5(file.getBytes());
item.setMd5(md5);
mapper.insert(item); mapper.insert(item);
return true; return true;
} }
@ -81,6 +88,8 @@ public class UpgradeServiceImpl implements UpgradeService {
@Override @Override
public void delete(Integer id) throws Exception { public void delete(Integer id) throws Exception {
MntnUpgrades record = mapper.selectByPrimaryKey(id);
mapper.deleteByPrimaryKey(id); mapper.deleteByPrimaryKey(id);
new File(apkpath + record.getPath()).delete();
} }
} }

Loading…
Cancel
Save