parent
221e416007
commit
1eb0f41908
8 changed files with 222 additions and 0 deletions
@ -0,0 +1,32 @@ |
||||
package org.springblade.upload.controller; |
||||
|
||||
import io.swagger.annotations.Api; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.upload.service.IProBusLineImgService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
@Api(tags = "管理后台 - 图片上传") |
||||
@RestController |
||||
@RequestMapping("/pro-bus-line-img") |
||||
@Validated |
||||
@Slf4j |
||||
public class PosBusLineController { |
||||
|
||||
@Autowired |
||||
private IProBusLineImgService proBusLineImgService; |
||||
|
||||
@PostMapping("/upload") |
||||
public R upload(@RequestParam("file") MultipartFile file, @RequestParam("imgType") Integer imgType,@RequestParam("busLineId") Long busLineId) { |
||||
return proBusLineImgService.upload(file, imgType,busLineId); |
||||
} |
||||
|
||||
@GetMapping("/query-list") |
||||
public R queryList(@RequestParam("id")Long id) { |
||||
return proBusLineImgService.queryList(id); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,44 @@ |
||||
package org.springblade.upload.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType; |
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
import org.springblade.core.mp.base.BaseEntity; |
||||
|
||||
/** |
||||
* 图片信息表 |
||||
* |
||||
* @author Chill |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
@TableName("poc_bus_line_img") |
||||
public class PocBusLineImg extends BaseEntity { |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
@JsonSerialize( |
||||
using = ToStringSerializer.class |
||||
) |
||||
@ApiModelProperty("主键id") |
||||
@TableId( |
||||
value = "id", |
||||
type = IdType.ASSIGN_ID |
||||
) |
||||
private Long id; |
||||
|
||||
private Long busLineId; |
||||
|
||||
//图片名称
|
||||
private String imgName; |
||||
// 图片地址
|
||||
private String imgUrl; |
||||
//图片类型
|
||||
private Integer imgType; |
||||
|
||||
} |
||||
@ -0,0 +1,15 @@ |
||||
package org.springblade.upload.mapper; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
import org.springblade.upload.entity.PocBusLineImg; |
||||
|
||||
/** |
||||
* 文件操作 Mapper |
||||
* |
||||
*/ |
||||
@Mapper |
||||
public interface ProBusLineImgMapper extends BaseMapper<PocBusLineImg> { |
||||
|
||||
} |
||||
@ -0,0 +1,13 @@ |
||||
<?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="org.springblade.upload.mapper.ProBusLineImgMapper"> |
||||
|
||||
<!-- 通用查询映射结果 --> |
||||
<resultMap id="PocBusLineImgResultMap" type="org.springblade.upload.entity.PocBusLineImg"> |
||||
<result column="id" property="id"/> |
||||
<result column="bus_line_id" property="busLineId"/> |
||||
<result column="img_name" property="imgName"/> |
||||
<result column="img_url" property="imgUrl"/> |
||||
<result column="img_type" property="imgType"/> |
||||
</resultMap> |
||||
</mapper> |
||||
@ -0,0 +1,19 @@ |
||||
package org.springblade.upload.service; |
||||
|
||||
|
||||
import org.springblade.core.tool.api.R; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
/** |
||||
* 文件 Service 接口 |
||||
* |
||||
*/ |
||||
public interface IProBusLineImgService { |
||||
/** |
||||
*文件上传接口 |
||||
* @return |
||||
*/ |
||||
R upload(MultipartFile file, Integer imgType,Long busLineId); |
||||
|
||||
R queryList(Long id); |
||||
} |
||||
@ -0,0 +1,66 @@ |
||||
package org.springblade.upload.service.impl; |
||||
|
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springblade.core.tool.api.R; |
||||
import org.springblade.upload.entity.PocBusLineImg; |
||||
import org.springblade.upload.mapper.ProBusLineImgMapper; |
||||
import org.springblade.upload.service.IProBusLineImgService; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.util.Date; |
||||
import java.util.UUID; |
||||
|
||||
|
||||
/** |
||||
*图片上传实现类 |
||||
*/ |
||||
@Service |
||||
@Slf4j |
||||
public class ProBusLineImgImpl implements IProBusLineImgService { |
||||
|
||||
@Resource |
||||
ProBusLineImgMapper pocBusLineImgMapper; |
||||
|
||||
@Override |
||||
public R upload(MultipartFile file, Integer imgType,Long busLineId) { |
||||
String fileName = file.getOriginalFilename(); |
||||
String suffixName = fileName.substring(fileName.lastIndexOf(".")); |
||||
String newFileName = UUID.randomUUID().toString() + suffixName; |
||||
String filePath = "uploads/"; |
||||
String absolutePath = new File("").getAbsolutePath() + "/" + filePath; |
||||
File directory = new File(absolutePath); |
||||
if (!directory.exists()) { |
||||
directory.mkdirs(); |
||||
} |
||||
File dest = new File(absolutePath + newFileName); |
||||
try { |
||||
file.transferTo(dest); |
||||
PocBusLineImg pocBusLineImg = new PocBusLineImg(); |
||||
pocBusLineImg.setImgName(fileName); |
||||
pocBusLineImg.setImgUrl(newFileName); |
||||
pocBusLineImg.setImgType(imgType); |
||||
pocBusLineImg.setBusLineId(busLineId); |
||||
// TODO: 设置创建人
|
||||
pocBusLineImg.setCreateTime(new Date()); |
||||
// TODO: 设置修改人
|
||||
pocBusLineImg.setUpdateTime(new Date()); |
||||
pocBusLineImg.setIsDeleted(0); |
||||
pocBusLineImgMapper.insert(pocBusLineImg); |
||||
return R.data(pocBusLineImg); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return R.fail("上传失败"); |
||||
} |
||||
|
||||
@Override |
||||
public R queryList(Long id) { |
||||
PocBusLineImg pocBusLineImg = pocBusLineImgMapper.selectById(id); |
||||
return R.data(pocBusLineImg); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,21 @@ |
||||
package org.springblade.upload.vo; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @Author: Chents |
||||
* @Create: 2023-05-08 |
||||
*/ |
||||
@Data |
||||
public class StationHintVo { |
||||
|
||||
private Long id; |
||||
private String name;//接口中站名
|
||||
private String tips;//提示
|
||||
private String red;//情怀,励志
|
||||
private String green;//活动
|
||||
private String yellow; |
||||
private List<imgVo> imgList; |
||||
} |
||||
@ -0,0 +1,12 @@ |
||||
package org.springblade.upload.vo; |
||||
|
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* @Author: Chents |
||||
* @Create: 2023-05-08 |
||||
*/ |
||||
@Data |
||||
public class imgVo { |
||||
private String imgUrl; |
||||
} |
||||
Loading…
Reference in new issue