feat: 增加上传其他文件

dev
huangfeng 1 year ago
parent 70ab460c90
commit 2f816869fb

@ -27,8 +27,8 @@ public class MntnUploadController extends BaseController {
@GetMapping("listAll")
@ApiOperation("查询全部列表")
public ResponseReult<List<MntnUploads>> listAll() {
List<MntnUploads> result = service.listAll();
public ResponseReult<List<MntnUploads>> listAll(Integer type) {
List<MntnUploads> result = service.listAll(type);
return ResponseReult.success(result);
}
@ -54,4 +54,17 @@ public class MntnUploadController extends BaseController {
result.setCode(0);
return result;
}
@PostMapping("uploadFile")
@ApiOperation("上传文件")
public ResponseReult uploadFile(@RequestParam("file") MultipartFile file,
@RequestParam(value = "termId", required = false) Integer termId) throws Exception {
if (termId == null) {
termId = 0;
}
service.uploadLog(termId, file);
ResponseReult result = new ResponseReult();
result.setCode(0);
return result;
}
}

@ -21,6 +21,15 @@ public class MntnUploads {
*/
private Integer termId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column mntn_uploads.type
*
* @mbg.generated
*/
private Integer type;
/**
*
* This field was generated by MyBatis Generator.
@ -105,6 +114,30 @@ public class MntnUploads {
this.termId = termId;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column mntn_uploads.type
*
* @return the value of mntn_uploads.type
*
* @mbg.generated
*/
public Integer getType() {
return type;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column mntn_uploads.type
*
* @param type the value for mntn_uploads.type
*
* @mbg.generated
*/
public void setType(Integer type) {
this.type = type;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column mntn_uploads.file_name

@ -315,6 +315,66 @@ public class MntnUploadsExample {
return (Criteria) this;
}
public Criteria andTypeIsNull() {
addCriterion("`type` is null");
return (Criteria) this;
}
public Criteria andTypeIsNotNull() {
addCriterion("`type` is not null");
return (Criteria) this;
}
public Criteria andTypeEqualTo(Integer value) {
addCriterion("`type` =", value, "type");
return (Criteria) this;
}
public Criteria andTypeNotEqualTo(Integer value) {
addCriterion("`type` <>", value, "type");
return (Criteria) this;
}
public Criteria andTypeGreaterThan(Integer value) {
addCriterion("`type` >", value, "type");
return (Criteria) this;
}
public Criteria andTypeGreaterThanOrEqualTo(Integer value) {
addCriterion("`type` >=", value, "type");
return (Criteria) this;
}
public Criteria andTypeLessThan(Integer value) {
addCriterion("`type` <", value, "type");
return (Criteria) this;
}
public Criteria andTypeLessThanOrEqualTo(Integer value) {
addCriterion("`type` <=", value, "type");
return (Criteria) this;
}
public Criteria andTypeIn(List<Integer> values) {
addCriterion("`type` in", values, "type");
return (Criteria) this;
}
public Criteria andTypeNotIn(List<Integer> values) {
addCriterion("`type` not in", values, "type");
return (Criteria) this;
}
public Criteria andTypeBetween(Integer value1, Integer value2) {
addCriterion("`type` between", value1, value2, "type");
return (Criteria) this;
}
public Criteria andTypeNotBetween(Integer value1, Integer value2) {
addCriterion("`type` not between", value1, value2, "type");
return (Criteria) this;
}
public Criteria andFileNameIsNull() {
addCriterion("file_name is null");
return (Criteria) this;

@ -8,6 +8,7 @@
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="term_id" jdbcType="INTEGER" property="termId" />
<result column="type" jdbcType="INTEGER" property="type" />
<result column="file_name" jdbcType="VARCHAR" property="fileName" />
<result column="path" jdbcType="VARCHAR" property="path" />
<result column="file_size" jdbcType="INTEGER" property="fileSize" />
@ -84,7 +85,7 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, term_id, file_name, `path`, file_size, create_time
id, term_id, `type`, file_name, `path`, file_size, create_time
</sql>
<select id="selectByExample" parameterType="com.shxy.xymanager_common.entity.MntnUploadsExample" resultMap="BaseResultMap">
<!--
@ -140,10 +141,12 @@
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into mntn_uploads (term_id, file_name, `path`,
file_size, create_time)
values (#{termId,jdbcType=INTEGER}, #{fileName,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR},
#{fileSize,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP})
insert into mntn_uploads (term_id, `type`, file_name,
`path`, file_size, create_time
)
values (#{termId,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, #{fileName,jdbcType=VARCHAR},
#{path,jdbcType=VARCHAR}, #{fileSize,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}
)
</insert>
<insert id="insertSelective" parameterType="com.shxy.xymanager_common.entity.MntnUploads">
<!--
@ -158,6 +161,9 @@
<if test="termId != null">
term_id,
</if>
<if test="type != null">
`type`,
</if>
<if test="fileName != null">
file_name,
</if>
@ -175,6 +181,9 @@
<if test="termId != null">
#{termId,jdbcType=INTEGER},
</if>
<if test="type != null">
#{type,jdbcType=INTEGER},
</if>
<if test="fileName != null">
#{fileName,jdbcType=VARCHAR},
</if>
@ -212,6 +221,9 @@
<if test="row.termId != null">
term_id = #{row.termId,jdbcType=INTEGER},
</if>
<if test="row.type != null">
`type` = #{row.type,jdbcType=INTEGER},
</if>
<if test="row.fileName != null">
file_name = #{row.fileName,jdbcType=VARCHAR},
</if>
@ -237,6 +249,7 @@
update mntn_uploads
set id = #{row.id,jdbcType=INTEGER},
term_id = #{row.termId,jdbcType=INTEGER},
`type` = #{row.type,jdbcType=INTEGER},
file_name = #{row.fileName,jdbcType=VARCHAR},
`path` = #{row.path,jdbcType=VARCHAR},
file_size = #{row.fileSize,jdbcType=INTEGER},
@ -255,6 +268,9 @@
<if test="termId != null">
term_id = #{termId,jdbcType=INTEGER},
</if>
<if test="type != null">
`type` = #{type,jdbcType=INTEGER},
</if>
<if test="fileName != null">
file_name = #{fileName,jdbcType=VARCHAR},
</if>
@ -277,6 +293,7 @@
-->
update mntn_uploads
set term_id = #{termId,jdbcType=INTEGER},
`type` = #{type,jdbcType=INTEGER},
file_name = #{fileName,jdbcType=VARCHAR},
`path` = #{path,jdbcType=VARCHAR},
file_size = #{fileSize,jdbcType=INTEGER},

@ -35,9 +35,12 @@ public class MntnUploadServiceImpl implements MntnUploadService {
NewCacheService cacheService;
@Override
public List<MntnUploads> listAll() {
public List<MntnUploads> listAll(Integer type) {
MntnUploadsExample example = new MntnUploadsExample();
MntnUploadsExample.Criteria criteria = example.createCriteria();
if (type != null) {
criteria.andTypeEqualTo(type);
}
example.setOrderByClause("id desc");
List<MntnUploads> list = mapper.selectByExample(example);
for (MntnUploads item : list) {
@ -76,6 +79,29 @@ public class MntnUploadServiceImpl implements MntnUploadService {
MntnUploads item = new MntnUploads();
item.setTermId(termId);
item.setFileName(fileName);
item.setType(0);
item.setPath(path);
item.setFileSize((int) file.getSize());
item.setCreateTime(new Date());
File dest = new File(termlog + path);
file.transferTo(dest);
mapper.insert(item);
}
@Override
public void uploadFile(Integer termId, MultipartFile file) throws Exception {
String fileName = file.getOriginalFilename();
String ext = StringUtils.getFilenameExtension(fileName);
String path = DateUtil.format(new Date(), "yyyyMMdd") + "_file_"
+ UUID.randomUUID().toString().replace("-", "").substring(0, 10);
if (StringUtils.hasLength(ext)) {
path = path + "." + ext;
}
MntnUploads item = new MntnUploads();
item.setTermId(termId);
item.setFileName(fileName);
item.setType(1);
item.setPath(path);
item.setFileSize((int) file.getSize());
item.setCreateTime(new Date());

@ -8,9 +8,11 @@ import java.util.List;
public interface MntnUploadService {
List<MntnUploads> listAll();
List<MntnUploads> listAll(Integer type);
void delete(Integer id) throws Exception;
void uploadLog(Integer termId, MultipartFile file) throws Exception;
void uploadFile(Integer termId, MultipartFile file) throws Exception;
}

Loading…
Cancel
Save