|
@@ -21,14 +21,18 @@ import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import vip.xiaonuo.common.exception.CommonException;
|
|
@@ -51,6 +55,7 @@ import vip.xiaonuo.dev.modular.file.util.DevFileMinIoUtil;
|
|
|
import vip.xiaonuo.dev.modular.file.util.DevFileTencentUtil;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
@@ -63,6 +68,7 @@ import java.util.Map;
|
|
|
* @author xuyuxiang
|
|
|
* @date 2022/2/23 18:43
|
|
|
**/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class DevFileServiceImpl extends ServiceImpl<DevFileMapper, DevFile> implements DevFileService {
|
|
|
|
|
@@ -91,6 +97,52 @@ public class DevFileServiceImpl extends ServiceImpl<DevFileMapper, DevFile> impl
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> uploadImgMap(String engine, MultipartFile file) {
|
|
|
+ Map<String,Object> map = Maps.newHashMap();
|
|
|
+ String bucketName;
|
|
|
+ if(StringUtils.equals(devConfigApi.getValueByKey("SNOWY_ENVIRONMENT_CONFIG"),"linux")){
|
|
|
+ //linux环境
|
|
|
+ bucketName = devConfigApi.getValueByKey("SNOWY_FILE_LOCAL_FOLDER_FOR_UNIX")+"/hnzy/";
|
|
|
+ }else{
|
|
|
+ //windows环境
|
|
|
+ bucketName = devConfigApi.getValueByKey("SNOWY_FILE_LOCAL_FOLDER_FOR_WINDOWS")+"/hnzy";
|
|
|
+ }
|
|
|
+ File localFile = new File(bucketName);
|
|
|
+ if(!localFile.exists()) {
|
|
|
+ localFile.mkdir();
|
|
|
+ }
|
|
|
+ String localPath = bucketName +"/" + file.getOriginalFilename();
|
|
|
+ File imgFile = new File(localPath);
|
|
|
+ try {
|
|
|
+ // 保存文件到本地
|
|
|
+ file.transferTo(imgFile);
|
|
|
+
|
|
|
+ log.info("文件上传成功!文件保存路径:" + localPath);
|
|
|
+ String result = HttpRequest.post(devConfigApi.getValueByKey("SNOWY_FILE_PATH")).
|
|
|
+ form("groupName", "hnzy").
|
|
|
+ form("imageFile", imgFile).execute().body();
|
|
|
+ JSONObject json = (JSONObject) JSONObject.parse(result);
|
|
|
+ log.info("result:"+result);
|
|
|
+ if(StringUtils.equals(json.getString("success"),"true")){
|
|
|
+ map.put("imageFile",json.get("imageFile"));
|
|
|
+ }
|
|
|
+ if (imgFile.exists()) { // 检查文件是否存在
|
|
|
+ if (imgFile.delete()) { // 删除文件
|
|
|
+ log.info("文件删除成功!");
|
|
|
+ } else {
|
|
|
+ log.info("文件删除失败!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info("文件不存在!");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.info("文件上传失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Page<DevFile> page(DevFilePageParam devFilePageParam) {
|
|
|
QueryWrapper<DevFile> queryWrapper = new QueryWrapper<DevFile>().checkSqlInjection();
|