3D机房配置:所有记录/站点/设备对应的记录列表,单条记录的增删改查,批量新增记录,机房图片上传
4个文件已添加
327 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/Station3DController.java 89 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/Station3DMapper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/Station3D.java 123 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/Station3DService.java 108 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/Station3DController.java
New file
@@ -0,0 +1,89 @@
package com.whyc.controller;
import com.whyc.dto.Response;
import com.whyc.pojo.Station3D;
import com.whyc.service.Station3DService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("station3D")
@Api(tags = "3D机房配置")
public class Station3DController {
    @Autowired
    private Station3DService service;
    @PostMapping
    @ApiOperation(value = "新增")
    public Response add(@RequestBody Station3D station3D){
        service.add(station3D);
        return new Response().setII(1,"新增成功");
    }
    @PostMapping("batch")
    @ApiOperation(value = "新增批量")
    public Response addBatch(@RequestBody List<Station3D> station3DList){
        service.addBatch(station3DList);
        return new Response().setII(1,"新增成功");
    }
    @DeleteMapping
    @ApiOperation(value = "删除")
    public Response delete(@RequestParam int stationId){
        service.delete(stationId);
        return new Response().setII(1,"删除成功");
    }
    @PutMapping
    @ApiOperation(value = "更新")
    public Response update(@RequestBody Station3D station3D){
        service.update(station3D);
        return new Response().setII(1,"更新成功");
    }
    @GetMapping("byId")
    @ApiOperation(value = "查询站点-根据记录id")
    public Response<Station3D> getById(@RequestParam int id){
        Station3D station3D = service.getById(id);
        return new Response<Station3D>().set(1,station3D);
    }
    @GetMapping("byDeviceId")
    @ApiOperation(value = "查询站点-根据设备id")
    public Response<List<Station3D>> getByDeviceId(@RequestParam int deviceId){
        List<Station3D> station3DList = service.getByDeviceId(deviceId);
        return new Response<List<Station3D>>().set(1,station3DList);
    }
    @GetMapping("all")
    @ApiOperation(value = "查询所有")
    public Response<List<Station3D>> getAll(){
        List<Station3D> station3DList = service.getAll();
        return new Response<List<Station3D>>().set(1,station3DList);
    }
    @GetMapping("allStations")
    @ApiOperation(value = "查询所有站点")
    public Response<List<Station3D>> getAllStations(){
        List<Station3D> station3DList = service.getAllStations();
        return new Response<List<Station3D>>().set(1,station3DList);
    }
    @PostMapping("uploadPicture")
    @ApiOperation(value = "上传图片")
    public Response uploadPicture(@RequestBody Map<String,String> map){
        String fileData = (String)map.get("fileData");
        String pictureName = (String)map.get("pictureName");
        String stationName = (String)map.get("stationName");
        service.uploadPicture(stationName,fileData,pictureName);
        return new Response().setII(1,"上传成功");
    }
}
src/main/java/com/whyc/mapper/Station3DMapper.java
New file
@@ -0,0 +1,7 @@
package com.whyc.mapper;
import com.whyc.pojo.Station3D;
public interface Station3DMapper extends CustomMapper<Station3D>{
}
src/main/java/com/whyc/pojo/Station3D.java
New file
@@ -0,0 +1,123 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.apache.ibatis.type.Alias;
@Alias("Station3D")
@TableName( schema = "`web_site`",value = "tb_3d_station")
public class Station3D {
    @TableId
    private Integer id;
    @TableField("deviceId")
    private Integer deviceId;
    @TableField("battGroupId")
    private Integer battGroupId;
    @TableField("stationName")
    private String stationName;
    @TableField("battGroupName")
    private String battGroupName;
    @TableField("pictureName")
    private String pictureName;
    @TableField("pictureUrl")
    private String pictureUrl;
    @TableField("positionX")
    private double positionX;
    @TableField("positionY")
    private double positionY;
    @TableField("length")
    private double length;
    @TableField("width")
    private double width;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public Integer getDeviceId() {
        return deviceId;
    }
    public void setDeviceId(Integer deviceId) {
        this.deviceId = deviceId;
    }
    public Integer getBattGroupId() {
        return battGroupId;
    }
    public void setBattGroupId(Integer battGroupId) {
        this.battGroupId = battGroupId;
    }
    public String getStationName() {
        return stationName;
    }
    public void setStationName(String stationName) {
        this.stationName = stationName;
    }
    public String getBattGroupName() {
        return battGroupName;
    }
    public void setBattGroupName(String battGroupName) {
        this.battGroupName = battGroupName;
    }
    public String getPictureName() {
        return pictureName;
    }
    public void setPictureName(String pictureName) {
        this.pictureName = pictureName;
    }
    public double getPositionX() {
        return positionX;
    }
    public void setPositionX(double positionX) {
        this.positionX = positionX;
    }
    public double getPositionY() {
        return positionY;
    }
    public void setPositionY(double positionY) {
        this.positionY = positionY;
    }
    public double getLength() {
        return length;
    }
    public void setLength(double length) {
        this.length = length;
    }
    public double getWidth() {
        return width;
    }
    public void setWidth(double width) {
        this.width = width;
    }
    public String getPictureUrl() {
        return pictureUrl;
    }
    public void setPictureUrl(String pictureUrl) {
        this.pictureUrl = pictureUrl;
    }
}
src/main/java/com/whyc/service/Station3DService.java
New file
@@ -0,0 +1,108 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.mapper.Station3DMapper;
import com.whyc.pojo.Station3D;
import com.whyc.util.ActionUtil;
import org.springframework.stereotype.Service;
import sun.misc.BASE64Decoder;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@Service
public class Station3DService {
    @Resource
    private Station3DMapper mapper;
    public void add(Station3D station3D) {
        mapper.insert(station3D);
    }
    public void addBatch(List<Station3D> station3DList) {
        mapper.insertBatchSomeColumn(station3DList);
    }
    public void delete(int stationId) {
        mapper.deleteById(stationId);
    }
    public void update(Station3D station3D) {
        mapper.updateById(station3D);
    }
    public Station3D getById(int id) {
        return mapper.selectById(id);
    }
    public List<Station3D> getByDeviceId(int deviceId) {
        QueryWrapper<Station3D> wrapper = Wrappers.query();
        wrapper.eq("deviceId",deviceId);
        return mapper.selectList(wrapper);
    }
    public List<Station3D> getAll() {
        return mapper.selectList(null);
    }
    public List<Station3D> getAllStations() {
        QueryWrapper<Station3D> wrapper = Wrappers.query();
        wrapper.select("distinct deviceId,stationName,pictureName,pictureUrl");
        return mapper.selectList(wrapper);
    }
    public void uploadPicture(String stationName, String fileData, String pictureName) {
        fileData = fileData.replaceAll(" ", "+");
        fileData = fileData.split(",")[1];
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] dataBytes = new byte[0];
        String pictureUrl="";
        try {
            dataBytes = decoder.decodeBuffer(fileData);
            /*=========图片保存===========*/
            //获取到tomcat webapp绝对路径
            String realPath = ActionUtil.getApplication().getRealPath("/");
            String[] split = realPath.split("\\\\");
            String projectName = split[split.length - 1];
            String webAppPath = realPath.substring(0, realPath.lastIndexOf(projectName));
            //存储3D站点图片的文件夹
            String fileDirName = webAppPath + projectName + "_photo_3DStation";
            //图片的Url
            StringBuffer requestUrl = ActionUtil.getRequest().getRequestURL();
            String httpName = requestUrl.substring(0, requestUrl.indexOf(projectName));
            pictureUrl = httpName+projectName + "_photo_3DStation/"+pictureName+".jpg";
            File file = new File(fileDirName);
            //不存在则创建该文件夹
            if (!file.exists()) {
                file.mkdirs();
            }
            //文件全路径
            String fileName = fileDirName + "\\" + pictureName + ".jpg";
            FileOutputStream fot = new FileOutputStream(fileName);
            fot.write(dataBytes);
            fot.flush();
            fot.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        /*=========数据库表更新===========*/
        UpdateWrapper<Station3D> wrapper = Wrappers.update();
        wrapper.set("pictureUrl",pictureUrl).eq("stationName",stationName);
        mapper.update(null,wrapper);
    }
}