From f3529363cc63b4729a429f80a4827b71df0cd5dd Mon Sep 17 00:00:00 2001 From: cy <1664593601@qq.com> Date: 星期五, 10 十一月 2023 11:26:23 +0800 Subject: [PATCH] feat: 上传 --- consum-base/src/main/java/com/consum/base/controller/FinFileController.java | 99 ++++++++ consum-model-pojo/src/main/java/com/consum/model/po/FinFile_mapper.java | 323 ++++++++++++++++++++++++++ consum-base/src/main/java/com/consum/base/service/FinFileServiceImpl.java | 14 + consum-model-pojo/src/main/java/com/consum/model/po/FinFile.java | 282 +++++++++++++++++++++++ 4 files changed, 718 insertions(+), 0 deletions(-) diff --git a/consum-base/src/main/java/com/consum/base/controller/FinFileController.java b/consum-base/src/main/java/com/consum/base/controller/FinFileController.java new file mode 100644 index 0000000..9d9dae5 --- /dev/null +++ b/consum-base/src/main/java/com/consum/base/controller/FinFileController.java @@ -0,0 +1,99 @@ +package com.consum.base.controller; + +import com.consum.base.BaseController; +import com.consum.base.service.FinFileServiceImpl; +import com.consum.model.po.FinFile; +import com.walker.file.FileInfo; +import com.walker.infrastructure.utils.DateUtils; +import com.walker.infrastructure.utils.NumberGenerator; +import com.walker.web.ResponseValue; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.text.NumberFormat; + +/** + * @Description 鏂囦欢涓婁紶 + * @Author wh + * @Date 2023/8/1 10:33 + */ +@RestController +@RequestMapping("/pc/fin/file") +public class FinFileController extends BaseController { + + public static void main(String[] args) { + NumberFormat nf = NumberFormat.getPercentInstance(); + nf.setMaximumFractionDigits(2); // 灏嗗皬鏁颁繚鐣� 2 浣� + System.out.println(nf.format(0.123456));; + } + @Autowired + private FinFileServiceImpl finFileService; + + /** + * @Description + * fileContentType 缁勪欢涓璾ploadf 涓烘枃浠� 鍏朵粬涓哄浘鐗� + * groupId 1瀹㈡湇瀵硅瘽鑱婂ぉ + * owner 鎵�灞炰汉 + * @Author wh + * @Date 2023/8/1 10:45 + */ + @PostMapping("/upload") + public ResponseValue upload(@RequestBody MultipartFile multipartFile) { + FileInfo fileInfo = null; + try { + fileInfo = this.uploadFileToLocal(multipartFile, "-1", 0, "-1", "uploadf"); + } catch (Exception e) { + logger.error("涓婁紶鏂囦欢寮傚父", e); + } + if (fileInfo != null) { + FinFile finFile = new FinFile(); + finFile.setId(NumberGenerator.getLongSequenceNumberNano()); + finFile.setCreateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis())); + finFile.setUserName("-1"); + finFile.setContentType(finFile.getContentType()); + finFile.setFileName(fileInfo.getFileName()); + finFile.setFileExt(fileInfo.getFileExt()); + finFile.setFilePath(fileInfo.getUrl()); + finFile.setFileSize(fileInfo.getFileSize()); + finFile.setFileType("-1"); + this.finFileService.insert(finFile); + } + return ResponseValue.success(fileInfo); + } + + /** + * @Description 澶氭枃浠朵笂浼� + * @Author wh + * @Date 2023/8/4 15:46 + */ + @PostMapping("/uploadMore") + public ResponseValue upload(@RequestBody MultipartFile[] multipartFile) { + FileInfo[] uploadfs = new FileInfo[]{}; + try { + uploadfs = this.uploadFileToLocal(multipartFile, "-1", 0, "-1", "uploadf"); + } catch (Exception e) { + logger.error("涓婁紶鏂囦欢寮傚父", e); + } + if (uploadfs.length > 0) { + for (int i = 0; i < uploadfs.length; i++) { + FileInfo fileInfo = uploadfs[i]; + FinFile finFile = new FinFile(); + finFile.setId(NumberGenerator.getLongSequenceNumberNano()); + finFile.setCreateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis())); + finFile.setUserName("-1"); + finFile.setContentType(finFile.getContentType()); + finFile.setFileName(fileInfo.getFileName()); + finFile.setFileExt(fileInfo.getFileExt()); + finFile.setFilePath(fileInfo.getUrl()); + finFile.setFileSize(fileInfo.getFileSize()); + finFile.setFileType("-1"); + this.finFileService.insert(finFile); + } + } + return ResponseValue.success(uploadfs); + } +} diff --git a/consum-base/src/main/java/com/consum/base/service/FinFileServiceImpl.java b/consum-base/src/main/java/com/consum/base/service/FinFileServiceImpl.java new file mode 100644 index 0000000..8c13e39 --- /dev/null +++ b/consum-base/src/main/java/com/consum/base/service/FinFileServiceImpl.java @@ -0,0 +1,14 @@ +package com.consum.base.service; + +import com.walker.jdbc.service.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @Description 鏂囦欢涓婁紶 + * @Author wh + * @Date 2023/8/1 10:34 + */ +@Service +public class FinFileServiceImpl extends BaseServiceImpl { + +} diff --git a/consum-model-pojo/src/main/java/com/consum/model/po/FinFile.java b/consum-model-pojo/src/main/java/com/consum/model/po/FinFile.java new file mode 100644 index 0000000..0e5d1b2 --- /dev/null +++ b/consum-model-pojo/src/main/java/com/consum/model/po/FinFile.java @@ -0,0 +1,282 @@ + +package com.consum.model.po; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.walker.jdbc.BasePo; + +/** + * 琛ㄥ悕:FIN_FILE * + * @author genrator + */ +@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) +public class FinFile extends BasePo<FinFile> { + // 搴忓垪鍖栫増鏈彿 + private static final long serialVersionUID = 1L; + + // 涓婚敭 + private Long id = null; + @JsonIgnore + protected boolean isset_id = false; + + // 灞炴�у垪琛� + private Long createTime = null; + @JsonIgnore + protected boolean isset_createTime = false; + + private String userName = null; + @JsonIgnore + protected boolean isset_userName = false; + + private String contentType = null; + @JsonIgnore + protected boolean isset_contentType = false; + + private String fileName = null; + @JsonIgnore + protected boolean isset_fileName = false; + + private String fileExt = null; + @JsonIgnore + protected boolean isset_fileExt = false; + + private String filePath = null; + @JsonIgnore + protected boolean isset_filePath = false; + + private Long fileSize = null; + @JsonIgnore + protected boolean isset_fileSize = false; + + private String fileType = null; + @JsonIgnore + protected boolean isset_fileType = false; + + private String summary = null; + @JsonIgnore + protected boolean isset_summary = false; + + /** + * 榛樿鏋勯�犲嚱鏁� + */ + public FinFile() { + } + + /** + * 鏍规嵁涓婚敭鏋勯�犲璞� + */ + public FinFile(Long id) { + this.setId(id); + } + + /** + * 璁剧疆涓婚敭鍊� + */ + @Override + public void setPkValue(Object value) { + this.setId((Long) value); + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + this.isset_id = true; + } + + @JsonIgnore + public boolean isEmptyId() { + return this.id == null; + } + + public Long getCreateTime() { + return this.createTime; + } + + public void setCreateTime(Long createTime) { + this.createTime = createTime; + this.isset_createTime = true; + } + + @JsonIgnore + public boolean isEmptyCreateTime() { + return this.createTime == null; + } + + public String getUserName() { + return this.userName; + } + + public void setUserName(String userName) { + this.userName = userName; + this.isset_userName = true; + } + + @JsonIgnore + public boolean isEmptyUserName() { + return this.userName == null || this.userName.length() == 0; + } + + public String getContentType() { + return this.contentType; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + this.isset_contentType = true; + } + + @JsonIgnore + public boolean isEmptyContentType() { + return this.contentType == null || this.contentType.length() == 0; + } + + public String getFileName() { + return this.fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + this.isset_fileName = true; + } + + @JsonIgnore + public boolean isEmptyFileName() { + return this.fileName == null || this.fileName.length() == 0; + } + + public String getFileExt() { + return this.fileExt; + } + + public void setFileExt(String fileExt) { + this.fileExt = fileExt; + this.isset_fileExt = true; + } + + @JsonIgnore + public boolean isEmptyFileExt() { + return this.fileExt == null || this.fileExt.length() == 0; + } + + public String getFilePath() { + return this.filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + this.isset_filePath = true; + } + + @JsonIgnore + public boolean isEmptyFilePath() { + return this.filePath == null || this.filePath.length() == 0; + } + + public Long getFileSize() { + return this.fileSize; + } + + public void setFileSize(Long fileSize) { + this.fileSize = fileSize; + this.isset_fileSize = true; + } + + @JsonIgnore + public boolean isEmptyFileSize() { + return this.fileSize == null; + } + + public String getFileType() { + return this.fileType; + } + + public void setFileType(String fileType) { + this.fileType = fileType; + this.isset_fileType = true; + } + + @JsonIgnore + public boolean isEmptyFileType() { + return this.fileType == null || this.fileType.length() == 0; + } + + public String getSummary() { + return this.summary; + } + + public void setSummary(String summary) { + this.summary = summary; + this.isset_summary = true; + } + + @JsonIgnore + public boolean isEmptySummary() { + return this.summary == null || this.summary.length() == 0; + } + + /** + * 閲嶅啓 toString() 鏂规硶 + */ + @Override + public String toString() { + return new StringBuilder() + .append("id=").append(this.id) + .append("createTime=").append(this.createTime) + .append("userName=").append(this.userName) + .append("contentType=").append(this.contentType) + .append("fileName=").append(this.fileName) + .append("fileExt=").append(this.fileExt) + .append("filePath=").append(this.filePath) + .append("fileSize=").append(this.fileSize) + .append("fileType=").append(this.fileType) + .append("summary=").append(this.summary) + .toString(); + } + + /** + * 鍏嬮殕 + */ + public FinFile $clone() { + FinFile fin_file = new FinFile(); + + // 鏁版嵁搴撳悕绉� + //fin_file.setDatabaseName_(this.getDatabaseName_()); + + // 涓婚敭 + if (this.isset_id) { + fin_file.setId(this.getId()); + } + // 鏅�氬睘鎬� + if (this.isset_createTime) { + fin_file.setCreateTime(this.getCreateTime()); + } + if (this.isset_userName) { + fin_file.setUserName(this.getUserName()); + } + if (this.isset_contentType) { + fin_file.setContentType(this.getContentType()); + } + if (this.isset_fileName) { + fin_file.setFileName(this.getFileName()); + } + if (this.isset_fileExt) { + fin_file.setFileExt(this.getFileExt()); + } + if (this.isset_filePath) { + fin_file.setFilePath(this.getFilePath()); + } + if (this.isset_fileSize) { + fin_file.setFileSize(this.getFileSize()); + } + if (this.isset_fileType) { + fin_file.setFileType(this.getFileType()); + } + if (this.isset_summary) { + fin_file.setSummary(this.getSummary()); + } + return fin_file; + } +} diff --git a/consum-model-pojo/src/main/java/com/consum/model/po/FinFile_mapper.java b/consum-model-pojo/src/main/java/com/consum/model/po/FinFile_mapper.java new file mode 100644 index 0000000..543944e --- /dev/null +++ b/consum-model-pojo/src/main/java/com/consum/model/po/FinFile_mapper.java @@ -0,0 +1,323 @@ +package com.consum.model.po; + +import com.walker.jdbc.BaseMapper; +import com.walker.jdbc.ResultSetUtils; +import com.walker.jdbc.SqlAndParameters; +import com.walker.jdbc.sqlgen.DeleteBuilder; +import com.walker.jdbc.sqlgen.InsertBuilder; +import com.walker.jdbc.sqlgen.SelectBuilder; +import com.walker.jdbc.sqlgen.UpdateBuilder; +import org.springframework.jdbc.core.RowMapper; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Map; + +/** + * 琛ㄥ悕:FIN_FILE * + * @author genrator + */ +public class FinFile_mapper extends FinFile implements BaseMapper<FinFile> { + // 搴忓垪鍖栫増鏈彿 + private static final long serialVersionUID = 1L; + + public static final RowMapper<FinFile> ROW_MAPPER = new FinFileRowMapper(); + + // 涓婚敭 + public static final String Id = "id"; + // 鏅�氬睘鎬� + public static final String CreateTime = "create_time"; + public static final String UserName = "user_name"; + public static final String ContentType = "content_type"; + public static final String FileName = "file_name"; + public static final String FileExt = "file_ext"; + public static final String FilePath = "file_path"; + public static final String FileSize = "file_size"; + public static final String FileType = "file_type"; + public static final String Summary = "summary"; + + /** + * 榛樿鏋勯�犲嚱鏁� + */ + public FinFile_mapper(FinFile finFile) { + if (finFile == null) { + throw new IllegalArgumentException("po鍙傛暟涓嶅厑璁镐负绌猴紒"); + } + //涓婚敭 + if (finFile.isset_id) { + this.setId(finFile.getId()); + } + //鏅�氬睘鎬� + if (finFile.isset_createTime) { + this.setCreateTime(finFile.getCreateTime()); + } + if (finFile.isset_userName) { + this.setUserName(finFile.getUserName()); + } + if (finFile.isset_contentType) { + this.setContentType(finFile.getContentType()); + } + if (finFile.isset_fileName) { + this.setFileName(finFile.getFileName()); + } + if (finFile.isset_fileExt) { + this.setFileExt(finFile.getFileExt()); + } + if (finFile.isset_filePath) { + this.setFilePath(finFile.getFilePath()); + } + if (finFile.isset_fileSize) { + this.setFileSize(finFile.getFileSize()); + } + if (finFile.isset_fileType) { + this.setFileType(finFile.getFileType()); + } + if (finFile.isset_summary) { + this.setSummary(finFile.getSummary()); + } + // 鍘绘帀锛�2022-09-07 + // this.setDatabaseName_(fin_file.getDatabaseName_()); + } + + /** + * 鑾峰彇琛ㄥ悕 + */ + @Override + public String getTableName_() { + String tableName = "fin_file"; + /** + if (StringUtils.isNotEmpty(this.getDatabaseName_())) { + return this.getDatabaseName_() + "." + tableName; + } else { + return tableName; + } + */ + return tableName; + } + + /** + * 鑾峰彇涓婚敭鍚嶇О + */ + @Override + public String getPkName_() { + return Id; + } + + /** + * 鑾峰彇涓婚敭鍊� + */ + @Override + public Object getPkValue_() { + return this.getId(); + } + + /** + * 鑾峰彇鎻掑叆璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getInsertSql_() { + InsertBuilder ib = new InsertBuilder(this.getTableName_()); + ib.set(Id, this.getId()); + ib.set(CreateTime, this.getCreateTime(), this.isset_createTime); + ib.set(UserName, this.getUserName(), this.isset_userName); + ib.set(ContentType, this.getContentType(), this.isset_contentType); + ib.set(FileName, this.getFileName(), this.isset_fileName); + ib.set(FileExt, this.getFileExt(), this.isset_fileExt); + ib.set(FilePath, this.getFilePath(), this.isset_filePath); + ib.set(FileSize, this.getFileSize(), this.isset_fileSize); + ib.set(FileType, this.getFileType(), this.isset_fileType); + ib.set(Summary, this.getSummary(), this.isset_summary); + return ib.genMapSql(); + } + + /** + * 鑾峰彇鏇存柊璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getUpdateSql_() { + UpdateBuilder ub = new UpdateBuilder(this.getTableName_()); + ub.set(CreateTime, this.getCreateTime(), this.isset_createTime); + ub.set(UserName, this.getUserName(), this.isset_userName); + ub.set(ContentType, this.getContentType(), this.isset_contentType); + ub.set(FileName, this.getFileName(), this.isset_fileName); + ub.set(FileExt, this.getFileExt(), this.isset_fileExt); + ub.set(FilePath, this.getFilePath(), this.isset_filePath); + ub.set(FileSize, this.getFileSize(), this.isset_fileSize); + ub.set(FileType, this.getFileType(), this.isset_fileType); + ub.set(Summary, this.getSummary(), this.isset_summary); + ub.where(this.getPkName_(), this.getPkValue_()); + return ub.genMapSql(); + } + + /** + * 鑾峰彇鏇存柊璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getUpdateSql_(String where, Map<String, Object> parameters) { + UpdateBuilder ub = new UpdateBuilder(this.getTableName_()); + ub.set(CreateTime, this.getCreateTime(), this.isset_createTime); + ub.set(UserName, this.getUserName(), this.isset_userName); + ub.set(ContentType, this.getContentType(), this.isset_contentType); + ub.set(FileName, this.getFileName(), this.isset_fileName); + ub.set(FileExt, this.getFileExt(), this.isset_fileExt); + ub.set(FilePath, this.getFilePath(), this.isset_filePath); + ub.set(FileSize, this.getFileSize(), this.isset_fileSize); + ub.set(FileType, this.getFileType(), this.isset_fileType); + ub.set(Summary, this.getSummary(), this.isset_summary); + return ub.genMapSql(where, parameters); + } + + /** + * 鑾峰彇鏇存柊璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Object[]> getUpdateSql_(String where, Object[] parameters) { + UpdateBuilder ub = new UpdateBuilder(this.getTableName_()); + ub.set(CreateTime, this.getCreateTime(), this.isset_createTime); + ub.set(UserName, this.getUserName(), this.isset_userName); + ub.set(ContentType, this.getContentType(), this.isset_contentType); + ub.set(FileName, this.getFileName(), this.isset_fileName); + ub.set(FileExt, this.getFileExt(), this.isset_fileExt); + ub.set(FilePath, this.getFilePath(), this.isset_filePath); + ub.set(FileSize, this.getFileSize(), this.isset_fileSize); + ub.set(FileType, this.getFileType(), this.isset_fileType); + ub.set(Summary, this.getSummary(), this.isset_summary); + return ub.genArraySql(where, parameters); + } + + /** + * 鑾峰彇鍒犻櫎璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getDeleteSql_() { + DeleteBuilder db = new DeleteBuilder(this.getTableName_()); + db.where(this.getPkName_(), this.getPkValue_()); + return db.genMapSql(); + } + + /** + * 鑾峰彇鍒犻櫎璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getDeleteSql_(String where, Map<String, Object> parameters) { + DeleteBuilder db = new DeleteBuilder(this.getTableName_()); + return db.genMapSql(where, parameters); + } + + /** + * 鑾峰彇鍒犻櫎璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Object[]> getDeleteSql_(String where, Object[] parameters) { + DeleteBuilder db = new DeleteBuilder(this.getTableName_()); + return db.genArraySql(where, parameters); + } + + /** + * 鑾峰彇鍗曡鏌ヨ璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getSingleSql_() { + SelectBuilder sb = new SelectBuilder(this.getTableName_()); + sb.where(this.getPkName_(), this.getPkValue_()); + return sb.genMapSql(); + } + + + /** + * 鑾峰彇鏌ヨ璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Map<String, Object>> getSelectSql_(String where, Map<String, Object> parameters) { + return new SqlAndParameters<>("select id, create_time, user_name, content_type, file_name, file_ext, file_path, file_size, file_type, summary from " + this.getTableName_() + " " + where, parameters); + } + + /** + * 鑾峰彇鏌ヨ璇彞鍜屽弬鏁� + */ + @Override + public SqlAndParameters<Object[]> getSelectSql_(String where, Object[] parameters) { + return new SqlAndParameters<>("select id, create_time, user_name, content_type, file_name, file_ext, file_path, file_size, file_type, summary from " + this.getTableName_() + " " + where, parameters); + } + + /** + * 灏唕esultset鐨勪竴琛岃浆鍖栦负po + */ + @Override + public FinFile mapRow(ResultSet rs, int i) throws SQLException { + return ROW_MAPPER.mapRow(rs, i); + } + + /** + * 鍏嬮殕 + */ + public FinFile toFinFile() { + return super.$clone(); + } +} + +/** + * fin_file RowMapper + * + * @author genrator + */ +class FinFileRowMapper implements RowMapper<FinFile> { + + @Override + public FinFile mapRow(ResultSet rs, int i) throws SQLException { + ResultSetUtils resultSetUtils = new ResultSetUtils(); + FinFile fin_file = new FinFile(); + Integer columnIndex; + //涓婚敭 + columnIndex = resultSetUtils.findColumn(rs, FinFile_mapper.Id); + if (columnIndex > 0) { + fin_file.setId(rs.getLong(columnIndex)); + } + //鏅�氬睘鎬� + columnIndex = resultSetUtils.findColumn(rs, FinFile_mapper.CreateTime); + if (columnIndex > 0) { + if (rs.getBigDecimal(columnIndex) == null) { + fin_file.setCreateTime(null); + } else { + fin_file.setCreateTime(rs.getLong(columnIndex)); + } + } + columnIndex = resultSetUtils.findColumn(rs, FinFile_mapper.UserName); + if (columnIndex > 0) { + fin_file.setUserName(rs.getString(columnIndex)); + } + columnIndex = resultSetUtils.findColumn(rs, FinFile_mapper.ContentType); + if (columnIndex > 0) { + fin_file.setContentType(rs.getString(columnIndex)); + } + columnIndex = resultSetUtils.findColumn(rs, FinFile_mapper.FileName); + if (columnIndex > 0) { + fin_file.setFileName(rs.getString(columnIndex)); + } + columnIndex = resultSetUtils.findColumn(rs, FinFile_mapper.FileExt); + if (columnIndex > 0) { + fin_file.setFileExt(rs.getString(columnIndex)); + } + columnIndex = resultSetUtils.findColumn(rs, FinFile_mapper.FilePath); + if (columnIndex > 0) { + fin_file.setFilePath(rs.getString(columnIndex)); + } + columnIndex = resultSetUtils.findColumn(rs, FinFile_mapper.FileSize); + if (columnIndex > 0) { + if (rs.getBigDecimal(columnIndex) == null) { + fin_file.setFileSize(null); + } else { + fin_file.setFileSize(rs.getLong(columnIndex)); + } + } + columnIndex = resultSetUtils.findColumn(rs, FinFile_mapper.FileType); + if (columnIndex > 0) { + fin_file.setFileType(rs.getString(columnIndex)); + } + columnIndex = resultSetUtils.findColumn(rs, FinFile_mapper.Summary); + if (columnIndex > 0) { + fin_file.setSummary(rs.getString(columnIndex)); + } + return fin_file; + } +} -- Gitblit v1.9.1