Commit 1a1cd083 authored by 周健威's avatar 周健威

修改代码

parent 4e388281
package com.upyuns.platform.rs.website.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 数据临时缓存库
*
* @author zjw
* @email jiaoruizhen@126.com
* @date 2024-08-14 14:52:35
*/
@Data
@Table(name = "data_tempcache")
public class DataTempcache implements Serializable {
private static final long serialVersionUID = 1L;
public static final int HASGTDATA_NOT = 0;
public static final int HASGTDATA_FIN = 1;
public static final int HASGTDATA_UPD = 2;
public static final int UPTYPE_UPLOAD = 1;
public static final int UPTYPE_GTDATA = 2;
public static final int UPTYPE_URL = 3;
/**
*
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty("")
private Integer id;
/**
* 数据名称
*/
@Column(name = "name")
@ApiModelProperty(value = "数据名称")
private String name;
/**
* 数据类型 1--图片;2--栅格文件;3--图库
*/
@Column(name = "type")
@ApiModelProperty(value = "数据类型 1--图片;2--栅格文件;3--图库")
private Integer type;
/**
* 数据来源 1--门户;2--生产线;3--AI系统
*/
@Column(name = "source")
@ApiModelProperty(value = "数据来源 1--门户;2--生产线;3--AI系统")
private Integer source;
/**
* 功能模块 0--默认;
*/
@Column(name = "source_module")
@ApiModelProperty(value = "功能模块 0--默认;")
private String sourceModule;
/**
* 文件名称
*/
@Column(name = "filename")
@ApiModelProperty(value = "文件名称")
private String filename;
/**
* 文件类型
*/
@Column(name = "filetype")
@ApiModelProperty(value = "文件类型")
private String filetype;
/**
* 文件地址
*/
@Column(name = "fileurl")
@ApiModelProperty(value = "文件地址")
private String fileurl;
/**
* 文件大小
*/
@Column(name = "filesize")
@ApiModelProperty(value = "文件大小")
private String filesize;
/**
* 是否删除 1--已删除;0--未删除
*/
@Column(name = "is_del")
@ApiModelProperty(value = "是否删除 1--已删除;0--未删除")
private Integer isDel;
/**
* 属性信息
*/
@Column(name = "detail_json")
@ApiModelProperty(value = "属性信息")
private String detailJson;
/**
* gtdata路径
*/
@Column(name = "gtdata_path")
@ApiModelProperty(value = "gtdata路径")
private String gtdataPath;
/**
* 是否已经存储gtdata 0--未处理;1--已处理;2--已更新
*/
@Column(name = "has_gtdata")
@ApiModelProperty(value = "是否已经存储gtdata 0--未处理;1--已处理;2--已更新")
private Integer hasGtdata;
/**
* 创建时间
*/
@Column(name = "crt_time")
@ApiModelProperty(value = "创建时间", hidden = true )
private Long crtTime;
/**
* 更新时间
*/
@Column(name = "upd_time")
@ApiModelProperty(value = "更新时间", hidden = true )
private Long updTime;
/**
* 创建人
*/
@Column(name = "crt_user")
@ApiModelProperty(value = "创建人")
private String crtUser;
/**
* 更新人
*/
@Column(name = "upd_user")
@ApiModelProperty(value = "更新人")
private String updUser;
/**
* 定制用户
*/
@Column(name = "user_id")
@ApiModelProperty(value = "定制用户")
private Integer userId;
/**
* 1--已提交;
*/
@Column(name = "status")
@ApiModelProperty(value = "1--已提交;")
private Integer status;
@Column(name = "remark")
@ApiModelProperty(value = "备注描述")
private String remark;
@Column(name = "uptype")
@ApiModelProperty(value = "上传类型 1--文件上传;2--gtdata路径;3--url")
private Integer uptype;
@Column(name = "upurl")
@ApiModelProperty(value = "上传文件url地址")
private String upurl;
}
package com.upyuns.platform.rs.website.biz;
import org.springframework.stereotype.Service;
import com.upyuns.platform.rs.website.entity.DataTempcache;
import com.upyuns.platform.rs.website.mapper.DataTempcacheMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
/**
* 数据临时缓存库
*
* @author zjw
* @email jiaoruizhen@126.com
* @date 2024-08-14 14:52:35
*/
@Service
public class DataTempcacheBiz extends BaseBiz<DataTempcacheMapper,DataTempcache> {
}
\ No newline at end of file
package com.upyuns.platform.rs.website.controller.web;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.github.wxiaoqi.security.common.util.process.SystemConfig;
import com.upyuns.platform.rs.gtdata.GtDataRestClient;
import com.upyuns.platform.rs.gtdata.GtFileInfo;
import com.upyuns.platform.rs.website.biz.DataTempcacheBiz;
import com.upyuns.platform.rs.website.entity.DataTempcache;
import com.upyuns.platform.rs.website.entity.FileData;
import com.upyuns.platform.rs.website.entity.GainData;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_TRUE;
@RestController
@RequestMapping("gainData/web")
public class DataTempcacheController extends BaseController<DataTempcacheBiz,DataTempcache> {
@Autowired
GtDataRestClient gtDataRestClient;
@Value("${universal.tempcachePath}")
private String tempcachePath ;
@Value("${universal.baseUploadPath}")
private String baseUploadPath ;
@Value("${universal.url}")
private String xx_url ;
@ApiModelProperty("添加修改文件")
@RequestMapping(value = "/saveDataTempcache",method = RequestMethod.POST)
public ObjectRestResponse<FileData> saveDataTempcache(@RequestBody DataTempcache dataTempcache) {
if(null != dataTempcache.getUptype()) {
if(DataTempcache.UPTYPE_GTDATA == dataTempcache.getUptype()) {
// //gtdtat 获取数据
Map<String, Object> responseMap = gtDataRestClient.list(dataTempcache.getGtdataPath());
if(null != responseMap && null != responseMap.get("HttpStatusCode") && null != responseMap.get("files") && 200 == (Integer) responseMap.get("HttpStatusCode")) {
List<GtFileInfo> gtFileInfos = Convert.toList(GtFileInfo.class, responseMap.get("files"));
GtFileInfo gtFileInfo = gtFileInfos.get(0);
String filename = gtFileInfo.getFilename();
String filesize = gtFileInfo.getSize();
String filetype = filename.substring(filename.lastIndexOf("."));
long fileSize = Long.valueOf(filesize);
// double fileSizeInKB = (double) fileSize / 1024; // 转换为 KB
double fileSizeInMB = (double) fileSize / (1024 * 1024); // 转换为 MB
double roundedFileSizeInMB = Math.round(fileSizeInMB * 100.0) / 100.0; // 保留两位小数
String fileSizeString = String.format("%.2f MB", roundedFileSizeInMB);
dataTempcache.setHasGtdata(SYS_TRUE);
dataTempcache.setFilename(filename);
dataTempcache.setFiletype(filetype);
dataTempcache.setFilesize(fileSizeString);
}else {
return ObjectRestResponse.createFailedResult(ResultCode.FAILED_CODE, "分布式路径不对");
}
}else if(DataTempcache.UPTYPE_URL == dataTempcache.getUptype()) {
//提前插入
if(null == dataTempcache.getId()) {
baseBiz.insertSelective(dataTempcache);
}
//创建目录
if(!FileUtil.exist(baseUploadPath+tempcachePath+"/"+dataTempcache.getId())) {
FileUtil.mkdir(baseUploadPath+tempcachePath+"/"+dataTempcache.getId());
}
String fileName = StrUtil.subAfter(dataTempcache.getUpurl(), "/", true);
//然后获取这个文件名的后缀
String suffix = StrUtil.subAfter(fileName, ".", true);
if(StrUtil.isBlank(dataTempcache.getFilename())) {
dataTempcache.setFilename(fileName);
}
if(StrUtil.isBlank(dataTempcache.getFiletype())) {
dataTempcache.setFiletype("." + suffix);
}
//下载文件
Long size = HttpUtil.downloadFile(dataTempcache.getUpurl(), FileUtil.file(baseUploadPath+tempcachePath+"/"+dataTempcache.getFilename()));
double fileSizeInMB = (double) size / (1024 * 1024); // 转换为 MB
double roundedFileSizeInMB = Math.round(fileSizeInMB * 100.0) / 100.0; // 保留两位小数
String fileSizeString = String.format("%.2f MB", roundedFileSizeInMB);
dataTempcache.setFilesize(fileSizeString);
dataTempcache.setFileurl(xx_url+ SystemConfig.XXMP_URL + tempcachePath + "/" + dataTempcache.getFilename());
}
}
if (dataTempcache.getId()!=null){
baseBiz.updateSelectiveById(dataTempcache);
}else {
dataTempcache.setIsDel(0);
baseBiz.insertSelective(dataTempcache);
}
return ObjectRestResponse.succ();
}
public static void main(String[] args) {
String url = "http://example.com/path/to/file.jpg";
// 假设URL的最后一个部分是文件名,我们可以先获取这个部分
String fileName = StrUtil.subAfter(url, "/", true);
System.out.println("URL路径的文件后缀是:" + fileName);
// 然后获取这个文件名的后缀
String suffix = StrUtil.subAfter(fileName, ".", true);
System.out.println("URL路径的文件后缀是:" + suffix);
}
}
\ No newline at end of file
package com.upyuns.platform.rs.website.mapper;
import com.upyuns.platform.rs.website.entity.DataTempcache;
import tk.mybatis.mapper.common.Mapper;
/**
* 数据临时缓存库
*
* @author zjw
* @email jiaoruizhen@126.com
* @date 2024-08-14 14:52:35
*/
public interface DataTempcacheMapper extends Mapper<DataTempcache> {
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.upyuns.platform.rs.website.mapper.DataTempcacheMapper">
</mapper>
\ 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