瀏覽代碼

任务提交 增加停泊点配置入库

qinguocai 1 年之前
父節點
當前提交
fa999df118

+ 62 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/BerthingPointConfig.java

@@ -0,0 +1,62 @@
+package com.ruoyi.system.domain;
+
+import java.util.Date;
+import java.io.Serializable;
+import lombok.Data;
+
+/**
+ * 停泊点策略配置(BerthingPointConfig)实体类
+ *
+ * @author makejava
+ * @since 2024-04-15 17:01:27
+ */
+@Data
+public class BerthingPointConfig implements Serializable {
+    private static final long serialVersionUID = 944719013643220557L;
+/**
+     * 停泊点策略ID
+     */
+    private Long stopId;
+/**
+     * 站码
+     */
+    private String id;
+/**
+     * 站点ID
+     */
+    private Long siteId;
+/**
+     * 策略编号
+     */
+    private Long planid;
+/**
+     * 断面ID
+     */
+    private Long berthingId;
+/**
+     * 停泊点位json list字符串 例子:[{“x”:54.3,"y":44.2}]
+     */
+    private String positions;
+/**
+     * 创建时间
+     */
+    private Date createTime;
+/**
+     * 状态 0:无效 1.有效 
+     */
+    private Integer status;
+/**
+     * 是否删除
+     */
+    private Integer isDel;
+/**
+     * 起测水位
+     */
+    private Double wlevel;
+/**
+     * 修正系数数组json 例子:[1,1]
+     */
+    private String factors;
+
+}
+

+ 51 - 0
ruoyi-system/src/main/java/com/ruoyi/system/dto/BerthingPointConfigDTO.java

@@ -0,0 +1,51 @@
+package com.ruoyi.system.dto;
+
+import lombok.Data;
+
+import javax.validation.constraints.*;
+import java.io.Serializable;
+import java.util.ArrayList;
+
+/**
+ * 停泊点策略配置(BerthingPointConfig)实体类
+ *
+ * @author makejava
+ * @since 2024-04-15 17:01:27
+ */
+@Data
+public class BerthingPointConfigDTO implements Serializable {
+/**
+     * 停泊点策略ID
+     */
+    private Long stopId;
+/**
+     * 站点ID
+     */
+    @NotNull(message = "站点ID不能为空")
+    private Long siteId;
+/**
+     * 策略编号
+     */
+    @DecimalMax(value = "20", message = "策略编号1-20之间")
+    @DecimalMin(value = "1", message = "策略编号1-20之间")
+    @NotNull(message = "策略编号不能为空")
+    private Long planid;
+
+/**
+     * 停泊点位json list字符串 例子:[{“x”:54.3,"y":44.2}]
+     */
+    @NotEmpty(message = "停泊点位不能为空")
+    private ArrayList<PrintExcelDTO> positions;
+/**
+     * 起测水位
+     */
+    @NotNull(message = "起测水位不能为空")
+    private Double wlevel;
+/**
+     * 修正系数数组json 例子:[1,1]
+     */
+    @NotEmpty(message = "修正系数不能为空")
+    private  ArrayList<Integer> factors;
+
+}
+

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

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

+ 8 - 2
ruoyi-system/src/main/java/com/ruoyi/system/mapper/BerthingPointMapper.java

@@ -3,9 +3,7 @@ package com.ruoyi.system.mapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.system.domain.BerthingPoint;
 import com.ruoyi.system.paramet.BerthingPointQuery;
-import com.ruoyi.system.paramet.SiteInfoQuery;
 import org.apache.ibatis.annotations.Param;
-import org.springframework.data.domain.Pageable;
 import java.util.List;
 
 /**
@@ -25,6 +23,14 @@ public interface BerthingPointMapper {
     BerthingPoint queryById(Long berthingId);
 
 
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param siteId 主键
+     * @return 实例对象
+     */
+    BerthingPoint queryBySiteId(Long siteId);
+
     /**
      * 设置状态
      *

+ 0 - 1
ruoyi-system/src/main/java/com/ruoyi/system/paramet/BerthingPointQuery.java

@@ -17,7 +17,6 @@ public class BerthingPointQuery implements Serializable {
     /**
      * 站点ID
      */
-    @NotNull(message = "站点ID不能为空")
     private Long siteId;
 
     /**

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

@@ -3,11 +3,13 @@ package com.ruoyi.system.service;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.system.domain.BerthingPoint;
+import com.ruoyi.system.dto.BerthingPointConfigDTO;
 import com.ruoyi.system.dto.BerthingPointDTO;
 import com.ruoyi.system.dto.PrintExcelDTO;
 import com.ruoyi.system.paramet.BerthingPointQuery;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.ArrayList;
 
 
@@ -22,5 +24,8 @@ public interface BerthingService {
     Page<BerthingPoint> queryBerthing(BerthingPointQuery berthingPointQuery);
 
 
+    boolean  downFile(Long siteId, HttpServletResponse response);
 
+
+    boolean addStopPrint(BerthingPointConfigDTO berthingPointConfigDTO);
 }

+ 94 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/BerthingServiceImpl.java

@@ -2,14 +2,20 @@ package com.ruoyi.system.service.impl;
 
 import cn.hutool.json.JSONUtil;
 import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.ExcelWriter;
 import com.alibaba.excel.context.AnalysisContext;
 import com.alibaba.excel.read.listener.ReadListener;
+import com.alibaba.excel.write.metadata.WriteSheet;
+import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.system.domain.BerthingPoint;
+import com.ruoyi.system.domain.BerthingPointConfig;
 import com.ruoyi.system.domain.SiteInfo;
+import com.ruoyi.system.dto.BerthingPointConfigDTO;
 import com.ruoyi.system.dto.BerthingPointDTO;
 import com.ruoyi.system.dto.PrintExcelDTO;
+import com.ruoyi.system.mapper.BerthingPointConfigMapper;
 import com.ruoyi.system.mapper.BerthingPointMapper;
 import com.ruoyi.system.mapper.SiteInfoMapper;
 import com.ruoyi.system.paramet.BerthingPointQuery;
@@ -19,14 +25,16 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import javax.validation.constraints.NotNull;
+import javax.servlet.http.HttpServletResponse;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Date;
+import java.util.List;
 
 
 /**
- * classname: 站点信息
+ * classname: 断面信息
  * description  服务实现类
  */
 @Service
@@ -40,6 +48,9 @@ public class BerthingServiceImpl implements BerthingService {
     @Resource
     private BerthingPointMapper berthingPointMapper;
 
+    @Resource
+    private BerthingPointConfigMapper berthingPointConfigMapper;
+
 
     @Override
     public ArrayList<PrintExcelDTO> uploadFile(MultipartFile file) {
@@ -113,6 +124,87 @@ public class BerthingServiceImpl implements BerthingService {
         }
     }
 
+    @Override
+    public boolean downFile(Long siteId, HttpServletResponse response) {
+        if (siteId == null) {
+            throw new BaseException("站点ID不能为空");
+        }
+        BerthingPoint berthingPoint = berthingPointMapper.queryBySiteId(siteId);
+        if (berthingPoint == null) {
+            throw new BaseException("没有断面数据");
+        }
+        List<PrintExcelDTO> positions = JSONUtil.toList(berthingPoint.getPositions(), PrintExcelDTO.class);
+        try {
+            response.setContentType("application/octet-stream; charset=utf-8");
+            // 文件名中文名需要转义
+            String today = new SimpleDateFormat("yyyyMMdd").format(new Date());
+            String fileName = "downFile_".concat(today);
+            // 设置导出头信息,文件名放在里面
+            response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
+            // 设置自适应列宽,注册一个handler: LongestMatchColumnWidthStyleStrategy
+            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
+            // 创建sheet并设置好标题
+            WriteSheet detailSheet = EasyExcel.writerSheet(0, "断面数据").head(PrintExcelDTO.class).build();
+            // 向sheet中写入数据
+            excelWriter.write(positions, detailSheet);
+            // 数据下载,完成后会自动关闭流
+            excelWriter.finish();
+            return true;
+        } catch (Exception e){
+            log.error("下载文件错误", e);
+            throw new BaseException("下载文件错误");
+        }
+    }
+
+
+    @Override
+    public boolean addStopPrint(BerthingPointConfigDTO berthingPointConfigDTO) {
+        SiteInfo siteInfo = siteInfoMapper.queryById(berthingPointConfigDTO.getSiteId());
+        if (siteInfo == null) {
+            throw new BaseException("站点不存在");
+        }
+        if (berthingPointConfigDTO.getStopId() == null) {
+            berthingPointConfigDTO.setStopId(0L);
+        }
+        if(berthingPointConfigDTO.getPositions().size() != berthingPointConfigDTO.getFactors().size()){
+            throw new BaseException("修正系数与停泊点位长度不匹配");
+        }
+        boolean res = false;
+        BerthingPointConfig berthingPointConfig = berthingPointConfigMapper.queryById(berthingPointConfigDTO.getStopId());
+        try {
+            ArrayList<PrintExcelDTO> positions = berthingPointConfigDTO.getPositions();
+            if (berthingPointConfig == null) {
+                //新增
+                berthingPointConfig = new BerthingPointConfig();
+                berthingPointConfig.setStopId(0L);
+                berthingPointConfig.setSiteId(siteInfo.getSiteId());
+                berthingPointConfig.setBerthingId(0L);
+                berthingPointConfig.setPositions(JSONUtil.toJsonStr(positions));
+                berthingPointConfig.setPlanid(berthingPointConfigDTO.getPlanid());
+                berthingPointConfig.setWlevel(berthingPointConfigDTO.getWlevel());
+                berthingPointConfig.setFactors(JSONUtil.toJsonStr(berthingPointConfigDTO.getFactors()));
+                berthingPointConfig.setCreateTime(new Date());
+                berthingPointConfig.setIsDel(0);
+                berthingPointConfig.setStatus(1);
+                berthingPointConfig.setId(siteInfo.getId());
+                res =  berthingPointConfigMapper.insert(berthingPointConfig) > 0;
+            } else {
+                //更新
+                berthingPointConfig.setPositions(JSONUtil.toJsonStr(positions));
+                berthingPointConfig.setPlanid(berthingPointConfigDTO.getPlanid());
+                berthingPointConfig.setWlevel(berthingPointConfigDTO.getWlevel());
+                berthingPointConfig.setFactors(JSONUtil.toJsonStr(berthingPointConfigDTO.getFactors()));
+                res =  berthingPointConfigMapper.update(berthingPointConfig) > 0;
+            }
+        } catch (Exception e){
+            log.error("新增或修改停泊点错误", e);
+            throw new BaseException("新增或修改停泊点错误");
+        }
+        //TODO 下发配置
+        return res;
+}
+
+
 
 
 }

+ 188 - 0
ruoyi-system/src/main/resources/mapper/BerthingPointConfigMapper.xml

@@ -0,0 +1,188 @@
+<?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.BerthingPointConfigMapper">
+
+    <resultMap type="com.ruoyi.system.domain.BerthingPointConfig" id="BerthingPointConfigMap">
+        <result property="stopId" column="stop_id" jdbcType="INTEGER"/>
+        <result property="id" column="id" jdbcType="VARCHAR"/>
+        <result property="siteId" column="site_id" jdbcType="INTEGER"/>
+        <result property="planid" column="planid" jdbcType="INTEGER"/>
+        <result property="berthingId" column="berthing_id" jdbcType="INTEGER"/>
+        <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="wlevel" column="wlevel" jdbcType="NUMERIC"/>
+        <result property="factors" column="factors" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <!--查询单个-->
+    <select id="queryById" resultMap="BerthingPointConfigMap">
+        select
+stop_id, id, site_id, planid, berthing_id, positions, create_time, status, is_del, wlevel, factors
+        from berthing_point_config
+        where stop_id = #{stopId}
+    </select>
+
+    <!--查询指定行数据-->
+    <select id="queryAllByLimit" resultMap="BerthingPointConfigMap">
+        select
+stop_id, id, site_id, planid, berthing_id, positions, create_time, status, is_del, wlevel, factors
+        from berthing_point_config
+        <where>
+            <if test="stopId != null">
+                and stop_id = #{stopId}
+            </if>
+            <if test="id != null and id != ''">
+                and id = #{id}
+            </if>
+            <if test="siteId != null">
+                and site_id = #{siteId}
+            </if>
+            <if test="planid != null">
+                and planid = #{planid}
+            </if>
+            <if test="berthingId != null">
+                and berthing_id = #{berthingId}
+            </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="wlevel != null">
+                and wlevel = #{wlevel}
+            </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_config
+        <where>
+            <if test="stopId != null">
+                and stop_id = #{stopId}
+            </if>
+            <if test="id != null and id != ''">
+                and id = #{id}
+            </if>
+            <if test="siteId != null">
+                and site_id = #{siteId}
+            </if>
+            <if test="planid != null">
+                and planid = #{planid}
+            </if>
+            <if test="berthingId != null">
+                and berthing_id = #{berthingId}
+            </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="wlevel != null">
+                and wlevel = #{wlevel}
+            </if>
+            <if test="factors != null and factors != ''">
+                and factors = #{factors}
+            </if>
+        </where>
+    </select>
+
+    <!--新增所有列-->
+    <insert id="insert" keyProperty="stopId" useGeneratedKeys="true">
+        insert into berthing_point_config(id, site_id, planid, berthing_id, positions, create_time, status, is_del, wlevel, factors)
+        values (#{id}, #{siteId}, #{planid}, #{berthingId}, #{positions}, #{createTime}, #{status}, #{isDel}, #{wlevel}, #{factors})
+    </insert>
+
+    <insert id="insertBatch" keyProperty="stopId" useGeneratedKeys="true">
+        insert into berthing_point_config(id, site_id, planid, berthing_id, positions, create_time, status, is_del, wlevel, factors)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+        (#{entity.id}, #{entity.siteId}, #{entity.planid}, #{entity.berthingId}, #{entity.positions}, #{entity.createTime}, #{entity.status}, #{entity.isDel}, #{entity.wlevel}, #{entity.factors})
+        </foreach>
+    </insert>
+
+    <insert id="insertOrUpdateBatch" keyProperty="stopId" useGeneratedKeys="true">
+        insert into berthing_point_config(id, site_id, planid, berthing_id, positions, create_time, status, is_del, wlevel, factors)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{entity.id}, #{entity.siteId}, #{entity.planid}, #{entity.berthingId}, #{entity.positions}, #{entity.createTime}, #{entity.status}, #{entity.isDel}, #{entity.wlevel}, #{entity.factors})
+        </foreach>
+        on duplicate key update
+id = values(id),
+site_id = values(site_id),
+planid = values(planid),
+berthing_id = values(berthing_id),
+positions = values(positions),
+create_time = values(create_time),
+status = values(status),
+is_del = values(is_del),
+wlevel = values(wlevel),
+factors = values(factors)
+    </insert>
+
+    <!--通过主键修改数据-->
+    <update id="update">
+        update berthing_point_config
+        <set>
+            <if test="id != null and id != ''">
+                id = #{id},
+            </if>
+            <if test="siteId != null">
+                site_id = #{siteId},
+            </if>
+            <if test="planid != null">
+                planid = #{planid},
+            </if>
+            <if test="berthingId != null">
+                berthing_id = #{berthingId},
+            </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="wlevel != null">
+                wlevel = #{wlevel},
+            </if>
+            <if test="factors != null and factors != ''">
+                factors = #{factors},
+            </if>
+        </set>
+        where stop_id = #{stopId}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete from berthing_point_config where stop_id = #{stopId}
+    </delete>
+
+</mapper>
+

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

@@ -22,6 +22,14 @@
         where berthing_id = #{berthingId}
     </select>
 
+    <!--查询单个-->
+    <select id="queryBySiteId" resultMap="BerthingPointMap">
+        select
+            berthing_id, id, site_id, berthing_name, positions, create_time, status, is_del, factors
+        from berthing_point
+        where site_id = #{siteId}
+    </select>
+
 
     <!--设置表状态-->
     <update id="setBerthingStatus">

+ 19 - 4
waterAffairs-admin/src/main/java/com/ruoyi/web/controller/tool/BerthingController.java

@@ -1,10 +1,10 @@
 package com.ruoyi.web.controller.tool;
 
-
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.annotation.Anonymous;
 import com.ruoyi.common.utils.R;
 import com.ruoyi.system.domain.BerthingPoint;
+import com.ruoyi.system.dto.BerthingPointConfigDTO;
 import com.ruoyi.system.dto.BerthingPointDTO;
 import com.ruoyi.system.dto.PrintExcelDTO;
 import com.ruoyi.system.paramet.BerthingPointQuery;
@@ -12,14 +12,15 @@ import com.ruoyi.system.service.BerthingService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.util.ArrayList;
 
-
 /**
  * @author ifei
  */
@@ -27,6 +28,7 @@ import java.util.ArrayList;
 @RequestMapping("/berthing")
 @Api(tags = "断面接口")
 @Anonymous
+@Slf4j
 public class BerthingController {
 
 
@@ -47,11 +49,24 @@ public class BerthingController {
     }
 
     @PostMapping(value = "/queryBerthing")
-    @ApiOperation("删除断面")
+    @ApiOperation("查询断面")
     public R<Page<BerthingPoint>> queryBerthing(@Valid @RequestBody BerthingPointQuery berthingPointQuery) {
         return R.ok(berthingService.queryBerthing(berthingPointQuery));
     }
 
+    @GetMapping(value = "/downFile")
+    @ApiOperation(value = "导出断面")
+    public R<Boolean> downFile(Long siteId, HttpServletResponse response) {
+        return R.ok(berthingService.downFile(siteId, response));
+
+    }
+
+    @PostMapping(value = "/addStopPrint")
+    @ApiOperation("增加或修改停泊点")
+    public R<Boolean> addStopPrint(@Valid @RequestBody BerthingPointConfigDTO berthingPointConfigDTO) {
+        return R.ok(berthingService.addStopPrint(berthingPointConfigDTO));
+    }
+
 
 
-}
+    }