Преглед на файлове

任务提交 完成断面EXCEL上传返回坐标点

qinguocai преди 1 година
родител
ревизия
b9b43d08e1

+ 12 - 1
ruoyi-system/pom.xml

@@ -23,13 +23,24 @@
             <artifactId>ruoyi-common</artifactId>
         </dependency>
 
-
         <!--mybatis plus-->
         <dependency>
             <groupId>com.baomidou</groupId>
             <artifactId>mybatis-plus-boot-starter</artifactId>
         </dependency>
 
+        <!--easyexcel-->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel-core</artifactId>
+            <version>3.3.2</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+        </dependency>
 
 
         <dependency>

+ 54 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/BerthingPoint.java

@@ -0,0 +1,54 @@
+package com.ruoyi.system.domain;
+
+import java.util.Date;
+import java.io.Serializable;
+import lombok.Data;
+
+/**
+ * 停泊点配置(BerthingPoint)实体类
+ *
+ * @author makejava
+ * @since 2024-04-10 15:29:55
+ */
+@Data
+public class BerthingPoint implements Serializable {
+    private static final long serialVersionUID = 245797945527062595L;
+/**
+     * 断面ID
+     */
+    private Long berthingId;
+/**
+     * 站码
+     */
+    private String id;
+/**
+     * 站点ID
+     */
+    private Long siteId;
+/**
+     * 断面名称
+     */
+    private String berthingName;
+/**
+     * 断面点位json list字符串 例子:[{“x”:54.3,"y":44.2}]
+     */
+    private String positions;
+/**
+     * 创建时间
+     */
+    private Date createTime;
+/**
+     * 状态 0:无效 1.有效 
+     */
+    private Integer status;
+/**
+     * 是否删除
+     */
+    private Integer isDel;
+/**
+     * 修正系数数组json 例子:[1,1]
+     */
+    private String factors;
+
+}
+

+ 58 - 0
ruoyi-system/src/main/java/com/ruoyi/system/dto/BerthingPointDTO.java

@@ -0,0 +1,58 @@
+package com.ruoyi.system.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 停泊点配置(BerthingPoint)实体类
+ *
+ * @author makejava
+ * @since 2024-04-10 15:29:55
+ */
+@Data
+public class BerthingPointDTO implements Serializable {
+    private static final long serialVersionUID = 245797945527062595L;
+/**
+     * 断面ID
+     */
+    private Long berthingId;
+/**
+     * 站码
+     */
+    @NotBlank(message = "站码不能为空")
+    private String id;
+/**
+     * 站点ID
+     */
+    private Long siteId;
+/**
+     * 断面名称
+     */
+    private String berthingName;
+/**
+     * 断面点位json list字符串 例子:[{“x”:54.3,"y":44.2}]
+     */
+    private String positions;
+/**
+     * 创建时间
+     */
+    private Date createTime;
+/**
+     * 状态 0:无效 1.有效 
+     */
+    private Integer status;
+/**
+     * 是否删除
+     */
+    private Integer isDel;
+/**
+     * 修正系数数组json 例子:[1,1]
+     */
+    private String factors;
+
+}
+

+ 15 - 0
ruoyi-system/src/main/java/com/ruoyi/system/dto/PrintExcelDTO.java

@@ -0,0 +1,15 @@
+package com.ruoyi.system.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+@Data
+public class PrintExcelDTO {
+    //状态
+    @ExcelProperty(value = "起点",index = 0)
+    private Double x;
+
+    @ExcelProperty(value = "高程",index = 1)
+    private Double y;
+
+}

+ 83 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/BerthingPointMapper.java

@@ -0,0 +1,83 @@
+package com.ruoyi.system.mapper;
+
+import com.ruoyi.system.domain.BerthingPoint;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.data.domain.Pageable;
+import java.util.List;
+
+/**
+ * 停泊点配置(BerthingPoint)表数据库访问层
+ *
+ * @author makejava
+ * @since 2024-04-10 15:29:55
+ */
+public interface BerthingPointMapper {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param berthingId 主键
+     * @return 实例对象
+     */
+    BerthingPoint queryById(Long berthingId);
+
+    /**
+     * 查询指定行数据
+     *
+     * @param berthingPoint 查询条件
+     * @param pageable         分页对象
+     * @return 对象列表
+     */
+    List<BerthingPoint> queryAllByLimit(BerthingPoint berthingPoint, @Param("pageable") Pageable pageable);
+
+    /**
+     * 统计总行数
+     *
+     * @param berthingPoint 查询条件
+     * @return 总行数
+     */
+    long count(BerthingPoint berthingPoint);
+
+    /**
+     * 新增数据
+     *
+     * @param berthingPoint 实例对象
+     * @return 影响行数
+     */
+    int insert(BerthingPoint berthingPoint);
+
+    /**
+     * 批量新增数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<BerthingPoint> 实例对象列表
+     * @return 影响行数
+     */
+    int insertBatch(@Param("entities") List<BerthingPoint> entities);
+
+    /**
+     * 批量新增或按主键更新数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<BerthingPoint> 实例对象列表
+     * @return 影响行数
+     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
+     */
+    int insertOrUpdateBatch(@Param("entities") List<BerthingPoint> entities);
+
+    /**
+     * 修改数据
+     *
+     * @param berthingPoint 实例对象
+     * @return 影响行数
+     */
+    int update(BerthingPoint berthingPoint);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param berthingId 主键
+     * @return 影响行数
+     */
+    int deleteById(Long berthingId);
+
+}
+

+ 19 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/BerthingService.java

@@ -0,0 +1,19 @@
+package com.ruoyi.system.service;
+
+
+import com.ruoyi.system.dto.PrintExcelDTO;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.ArrayList;
+
+
+public interface BerthingService {
+
+    ArrayList<PrintExcelDTO> uploadFile(MultipartFile file);
+
+
+
+
+
+
+}

+ 53 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BerthingServiceImpl.java

@@ -0,0 +1,53 @@
+package com.ruoyi.system.service.impl;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.read.listener.ReadListener;
+import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.system.dto.PrintExcelDTO;
+import com.ruoyi.system.service.BerthingService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+import java.util.ArrayList;
+import java.util.Comparator;
+
+
+/**
+ * classname: 站点信息
+ * description  服务实现类
+ */
+@Service
+@Slf4j
+public class BerthingServiceImpl implements BerthingService {
+
+    @Override
+    public ArrayList<PrintExcelDTO> uploadFile(MultipartFile file) {
+        ArrayList<PrintExcelDTO> excelDateList = new ArrayList<>();
+        try {
+            if (file.isEmpty()) {
+                log.error("文件为空");
+                throw new BaseException("文件为空");
+            }
+            EasyExcel.read(file.getInputStream(), PrintExcelDTO.class, new ReadListener<PrintExcelDTO>() {
+                @Override
+                public void invoke(PrintExcelDTO printExcelDto, AnalysisContext analysisContext) {
+                    excelDateList.add(printExcelDto);
+                }
+                @Override
+                public void doAfterAllAnalysed(AnalysisContext context) {}
+            }).sheet().doRead();
+            //排序
+            excelDateList.sort(Comparator.comparingDouble(PrintExcelDTO::getX));
+            return excelDateList;
+        } catch (BaseException e){
+            throw new BaseException(e.getMessage());
+        } catch (Exception e){
+            log.error("上传断面excel错误", e);
+            throw new BaseException("上传断面excel错误");
+        }
+    }
+
+
+
+}

+ 166 - 0
ruoyi-system/src/main/resources/mapper/BerthingPointMapper.xml

@@ -0,0 +1,166 @@
+<?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="com.ruoyi.system.mapper.BerthingPointMapper">
+
+    <resultMap type="com.ruoyi.system.domain.BerthingPoint" id="BerthingPointMap">
+        <result property="berthingId" column="berthing_id" jdbcType="INTEGER"/>
+        <result property="id" column="id" jdbcType="VARCHAR"/>
+        <result property="siteId" column="site_id" jdbcType="INTEGER"/>
+        <result property="berthingName" column="berthing_name" jdbcType="VARCHAR"/>
+        <result property="positions" column="positions" jdbcType="VARCHAR"/>
+        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
+        <result property="status" column="status" jdbcType="INTEGER"/>
+        <result property="isDel" column="is_del" jdbcType="INTEGER"/>
+        <result property="factors" column="factors" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <!--查询单个-->
+    <select id="queryById" resultMap="BerthingPointMap">
+        select
+berthing_id, id, site_id, berthing_name, positions, create_time, status, is_del, factors
+        from berthing_point
+        where berthing_id = #{berthingId}
+    </select>
+
+    <!--查询指定行数据-->
+    <select id="queryAllByLimit" resultMap="BerthingPointMap">
+        select
+berthing_id, id, site_id, berthing_name, positions, create_time, status, is_del, factors
+        from berthing_point
+        <where>
+            <if test="berthingId != null">
+                and berthing_id = #{berthingId}
+            </if>
+            <if test="id != null and id != ''">
+                and id = #{id}
+            </if>
+            <if test="siteId != null">
+                and site_id = #{siteId}
+            </if>
+            <if test="berthingName != null and berthingName != ''">
+                and berthing_name = #{berthingName}
+            </if>
+            <if test="positions != null and positions != ''">
+                and positions = #{positions}
+            </if>
+            <if test="createTime != null">
+                and create_time = #{createTime}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+            <if test="isDel != null">
+                and is_del = #{isDel}
+            </if>
+            <if test="factors != null and factors != ''">
+                and factors = #{factors}
+            </if>
+        </where>
+        limit #{pageable.offset}, #{pageable.pageSize}
+    </select>
+
+    <!--统计总行数-->
+    <select id="count" resultType="java.lang.Long">
+        select count(1)
+        from berthing_point
+        <where>
+            <if test="berthingId != null">
+                and berthing_id = #{berthingId}
+            </if>
+            <if test="id != null and id != ''">
+                and id = #{id}
+            </if>
+            <if test="siteId != null">
+                and site_id = #{siteId}
+            </if>
+            <if test="berthingName != null and berthingName != ''">
+                and berthing_name = #{berthingName}
+            </if>
+            <if test="positions != null and positions != ''">
+                and positions = #{positions}
+            </if>
+            <if test="createTime != null">
+                and create_time = #{createTime}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+            <if test="isDel != null">
+                and is_del = #{isDel}
+            </if>
+            <if test="factors != null and factors != ''">
+                and factors = #{factors}
+            </if>
+        </where>
+    </select>
+
+    <!--新增所有列-->
+    <insert id="insert" keyProperty="berthingId" useGeneratedKeys="true">
+        insert into berthing_point(id, site_id, berthing_name, positions, create_time, status, is_del, factors)
+        values (#{id}, #{siteId}, #{berthingName}, #{positions}, #{createTime}, #{status}, #{isDel}, #{factors})
+    </insert>
+
+    <insert id="insertBatch" keyProperty="berthingId" useGeneratedKeys="true">
+        insert into berthing_point(id, site_id, berthing_name, positions, create_time, status, is_del, factors)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+        (#{entity.id}, #{entity.siteId}, #{entity.berthingName}, #{entity.positions}, #{entity.createTime}, #{entity.status}, #{entity.isDel}, #{entity.factors})
+        </foreach>
+    </insert>
+
+    <insert id="insertOrUpdateBatch" keyProperty="berthingId" useGeneratedKeys="true">
+        insert into berthing_point(id, site_id, berthing_name, positions, create_time, status, is_del, factors)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{entity.id}, #{entity.siteId}, #{entity.berthingName}, #{entity.positions}, #{entity.createTime}, #{entity.status}, #{entity.isDel}, #{entity.factors})
+        </foreach>
+        on duplicate key update
+id = values(id),
+site_id = values(site_id),
+berthing_name = values(berthing_name),
+positions = values(positions),
+create_time = values(create_time),
+status = values(status),
+is_del = values(is_del),
+factors = values(factors)
+    </insert>
+
+    <!--通过主键修改数据-->
+    <update id="update">
+        update berthing_point
+        <set>
+            <if test="id != null and id != ''">
+                id = #{id},
+            </if>
+            <if test="siteId != null">
+                site_id = #{siteId},
+            </if>
+            <if test="berthingName != null and berthingName != ''">
+                berthing_name = #{berthingName},
+            </if>
+            <if test="positions != null and positions != ''">
+                positions = #{positions},
+            </if>
+            <if test="createTime != null">
+                create_time = #{createTime},
+            </if>
+            <if test="status != null">
+                status = #{status},
+            </if>
+            <if test="isDel != null">
+                is_del = #{isDel},
+            </if>
+            <if test="factors != null and factors != ''">
+                factors = #{factors},
+            </if>
+        </set>
+        where berthing_id = #{berthingId}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete from berthing_point where berthing_id = #{berthingId}
+    </delete>
+
+</mapper>
+

+ 39 - 0
waterAffairs-admin/src/main/java/com/ruoyi/web/controller/tool/BerthingController.java

@@ -0,0 +1,39 @@
+package com.ruoyi.web.controller.tool;
+
+
+import com.ruoyi.common.annotation.Anonymous;
+import com.ruoyi.common.utils.R;
+import com.ruoyi.system.dto.PrintExcelDTO;
+import com.ruoyi.system.service.BerthingService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+
+
+/**
+ * @author ifei
+ */
+@RestController
+@RequestMapping("/berthing")
+@Api(tags = "断面接口")
+@Anonymous
+public class BerthingController {
+
+
+    @Resource
+    private BerthingService berthingService;
+
+
+    @PostMapping(value = "/uploadFile")
+    @ApiOperation("上传断面Excel")
+    public R<ArrayList<PrintExcelDTO>> uploadFile(@ApiParam(required = true, value = "The file to be uploaded", name = "file") @RequestPart("file") MultipartFile file)  {
+        return R.ok(berthingService.uploadFile(file));
+    }
+
+
+}