cy
2023-11-10 f3529363cc63b4729a429f80a4827b71df0cd5dd
feat: 上传
4个文件已添加
718 ■■■■■ 已修改文件
consum-base/src/main/java/com/consum/base/controller/FinFileController.java 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
consum-base/src/main/java/com/consum/base/service/FinFileServiceImpl.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
consum-model-pojo/src/main/java/com/consum/model/po/FinFile.java 282 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
consum-model-pojo/src/main/java/com/consum/model/po/FinFile_mapper.java 323 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
consum-base/src/main/java/com/consum/base/controller/FinFileController.java
New file
@@ -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 组件中uploadf 为文件 其他为图片
     * 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);
    }
}
consum-base/src/main/java/com/consum/base/service/FinFileServiceImpl.java
New file
@@ -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 {
}
consum-model-pojo/src/main/java/com/consum/model/po/FinFile.java
New file
@@ -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;
    }
}
consum-model-pojo/src/main/java/com/consum/model/po/FinFile_mapper.java
New file
@@ -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);
    }
    /**
     * 将resultset的一行转化为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;
    }
}