Просмотр исходного кода

任务提交 完成断面全部接口

qinguocai 1 год назад
Родитель
Сommit
892657664b

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

@@ -2,6 +2,8 @@ package com.ruoyi.system.domain;
 
 import java.util.Date;
 import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 
 /**
@@ -36,6 +38,7 @@ public class BerthingPoint implements Serializable {
 /**
      * 创建时间
      */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
     private Date createTime;
 /**
      * 状态 0:无效 1.有效 

+ 11 - 30
ruoyi-system/src/main/java/com/ruoyi/system/dto/BerthingPointDTO.java

@@ -3,8 +3,10 @@ package com.ruoyi.system.dto;
 import lombok.Data;
 
 import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.Date;
 
 /**
@@ -15,44 +17,23 @@ import java.util.Date;
  */
 @Data
 public class BerthingPointDTO implements Serializable {
-    private static final long serialVersionUID = 245797945527062595L;
-/**
-     * 断面ID
-     */
-    private Long berthingId;
-/**
-     * 站码
-     */
-    @NotBlank(message = "站码不能为空")
-    private String id;
-/**
+
+    /**
      * 站点ID
      */
+    @NotNull(message = "站点ID不能为空")
     private Long siteId;
-/**
+    /**
      * 断面名称
      */
+    @NotBlank(message = "断面名称不能为空")
     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;
+    @NotEmpty(message = "断面点位不能为空")
+    private ArrayList<PrintExcelDTO> positions;
+
 
 }
 

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

@@ -6,7 +6,7 @@ import lombok.Data;
 @Data
 public class PrintExcelDTO {
     //状态
-    @ExcelProperty(value = "起点",index = 0)
+    @ExcelProperty(value = "起点",index = 0)
     private Double x;
 
     @ExcelProperty(value = "高程",index = 1)

+ 15 - 3
ruoyi-system/src/main/java/com/ruoyi/system/mapper/BerthingPointMapper.java

@@ -1,6 +1,9 @@
 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;
@@ -21,14 +24,23 @@ public interface BerthingPointMapper {
      */
     BerthingPoint queryById(Long berthingId);
 
+
+    /**
+     * 设置状态
+     *
+     * @param site 状态
+     * @return 实例对象
+     */
+    int setBerthingStatus(Long site);
+
     /**
      * 查询指定行数据
      *
-     * @param berthingPoint 查询条件
-     * @param pageable         分页对象
+     * @param berthingPointQuery 查询条件
+     * @param page        分页对象
      * @return 对象列表
      */
-    List<BerthingPoint> queryAllByLimit(BerthingPoint berthingPoint, @Param("pageable") Pageable pageable);
+    Page<BerthingPoint> queryAllByLimit(@Param("berthingPointQuery") BerthingPointQuery berthingPointQuery , Page page);
 
     /**
      * 统计总行数

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

@@ -0,0 +1,34 @@
+package com.ruoyi.system.paramet;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+/**
+ * 停泊点配置(BerthingPoint)实体类
+ *
+ * @author makejava
+ * @since 2024-04-10 15:29:55
+ */
+@Data
+public class BerthingPointQuery implements Serializable {
+
+    /**
+     * 站点ID
+     */
+    @NotNull(message = "站点ID不能为空")
+    private Long siteId;
+
+    /**
+     * 分页
+     */
+    private Long page;
+
+    /**
+     * 分页长度
+     */
+    private Long size;
+
+}
+

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

@@ -1,7 +1,11 @@
 package com.ruoyi.system.service;
 
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.system.domain.BerthingPoint;
+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 java.util.ArrayList;
@@ -12,8 +16,11 @@ public interface BerthingService {
     ArrayList<PrintExcelDTO> uploadFile(MultipartFile file);
 
 
+    boolean insertBerthing(BerthingPointDTO berthingPointDTO);
 
 
+    Page<BerthingPoint> queryBerthing(BerthingPointQuery berthingPointQuery);
+
 
 
 }

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

@@ -1,16 +1,28 @@
 package com.ruoyi.system.service.impl;
 
+import cn.hutool.json.JSONUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.context.AnalysisContext;
 import com.alibaba.excel.read.listener.ReadListener;
+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.SiteInfo;
+import com.ruoyi.system.dto.BerthingPointDTO;
 import com.ruoyi.system.dto.PrintExcelDTO;
+import com.ruoyi.system.mapper.BerthingPointMapper;
+import com.ruoyi.system.mapper.SiteInfoMapper;
+import com.ruoyi.system.paramet.BerthingPointQuery;
 import com.ruoyi.system.service.BerthingService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import javax.validation.constraints.NotNull;
 import java.util.ArrayList;
 import java.util.Comparator;
+import java.util.Date;
 
 
 /**
@@ -21,6 +33,14 @@ import java.util.Comparator;
 @Slf4j
 public class BerthingServiceImpl implements BerthingService {
 
+
+    @Resource
+    private SiteInfoMapper siteInfoMapper;
+
+    @Resource
+    private BerthingPointMapper berthingPointMapper;
+
+
     @Override
     public ArrayList<PrintExcelDTO> uploadFile(MultipartFile file) {
         ArrayList<PrintExcelDTO> excelDateList = new ArrayList<>();
@@ -48,6 +68,51 @@ public class BerthingServiceImpl implements BerthingService {
         }
     }
 
+    @Override
+    public boolean insertBerthing(BerthingPointDTO berthingPointDTO){
+        SiteInfo siteInfo = siteInfoMapper.queryById(berthingPointDTO.getSiteId());
+        if (siteInfo == null) {
+            throw new BaseException("站点不存在");
+        }
+        try {
+            ArrayList<PrintExcelDTO> positions = berthingPointDTO.getPositions();
+            positions.sort(Comparator.comparingDouble(PrintExcelDTO::getX));
+            //设置他断面状态为无效
+            berthingPointMapper.setBerthingStatus(siteInfo.getSiteId());
+            BerthingPoint berthingPoint = new BerthingPoint();
+            berthingPoint.setBerthingName(berthingPointDTO.getBerthingName());
+            berthingPoint.setPositions(JSONUtil.toJsonStr(positions));
+            berthingPoint.setSiteId(siteInfo.getSiteId());
+            berthingPoint.setBerthingId(0L);
+            berthingPoint.setCreateTime(new Date());
+            berthingPoint.setIsDel(0);
+            berthingPoint.setId(siteInfo.getId());
+            berthingPoint.setStatus(1);
+            return berthingPointMapper.insert(berthingPoint) > 0;
+            //TODO 配置下发
+        } catch (Exception e){
+            log.error("新增断面错误", e);
+            throw new BaseException("新增断面错误");
+        }
+    }
+
+
+    @Override
+    public  Page<BerthingPoint> queryBerthing(BerthingPointQuery berthingPointQuery) {
+        try {
+            if (berthingPointQuery.getPage() == null || berthingPointQuery.getSize() == null) {
+                berthingPointQuery.setPage(1L);
+                berthingPointQuery.setSize(10L);
+            }
+            Page<SiteInfo> page = new Page<>(berthingPointQuery.getPage(), berthingPointQuery.getSize());
+            return berthingPointMapper.queryAllByLimit(berthingPointQuery, page);
+
+        } catch (Exception e) {
+            log.error("查询站点错误", e);
+            throw new BaseException("查询站点错误");
+        }
+    }
+
 
 
 }

+ 15 - 29
ruoyi-system/src/main/resources/mapper/BerthingPointMapper.xml

@@ -17,46 +17,32 @@
     <!--查询单个-->
     <select id="queryById" resultMap="BerthingPointMap">
         select
-berthing_id, id, site_id, berthing_name, positions, create_time, status, is_del, factors
+            berthing_id, id, site_id, berthing_name, positions, create_time, status, is_del, factors
         from berthing_point
         where berthing_id = #{berthingId}
     </select>
 
+
+    <!--设置表状态-->
+    <update id="setBerthingStatus">
+        update berthing_point
+        <set>
+            status = 0
+        </set>
+            where site_id = #{siteId}
+    </update>
+
     <!--查询指定行数据-->
     <select id="queryAllByLimit" resultMap="BerthingPointMap">
         select
-berthing_id, id, site_id, berthing_name, positions, create_time, status, is_del, factors
+            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 test="berthingPointQuery.siteId != null">
+                and site_id= #{berthingPointQuery.siteId}
             </if>
         </where>
-        limit #{pageable.offset}, #{pageable.pageSize}
+        ORDER BY create_time DESC
     </select>
 
     <!--统计总行数-->

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

@@ -1,9 +1,13 @@
 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.BerthingPointDTO;
 import com.ruoyi.system.dto.PrintExcelDTO;
+import com.ruoyi.system.paramet.BerthingPointQuery;
 import com.ruoyi.system.service.BerthingService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -12,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import javax.validation.Valid;
 import java.util.ArrayList;
 
 
@@ -35,5 +40,18 @@ public class BerthingController {
         return R.ok(berthingService.uploadFile(file));
     }
 
+    @PostMapping(value = "/insertBerthing")
+    @ApiOperation("新增断面")
+    public R<Boolean> insertBerthing(@Valid  @RequestBody BerthingPointDTO berthingPointDTO) {
+        return R.ok(berthingService.insertBerthing(berthingPointDTO));
+    }
+
+    @PostMapping(value = "/queryBerthing")
+    @ApiOperation("删除断面")
+    public R<Page<BerthingPoint>> queryBerthing(@Valid @RequestBody BerthingPointQuery berthingPointQuery) {
+        return R.ok(berthingService.queryBerthing(berthingPointQuery));
+    }
+
+
 
 }