Selaa lähdekoodia

井的增删改查的操作

hbjzws 2 vuotta sitten
vanhempi
commit
0a63e46024

+ 20 - 2
src/main/java/com/hb/proj/model/Well.java

@@ -6,10 +6,28 @@ import java.util.Date;
 
 @Data
 public class Well {
+    /**
+     *井号
+     */
     private String wellId;
-
+    /**
+     *井名
+     */
     private String wellName;
-
+    /**
+     *井别
+     */
     private String wellSort;
+    /**
+     *创建时间
+     */
     private Date createTime;
+    /**
+     *修改时间
+     */
+    private Date modifyTime;
+    /**
+     *删除标志
+     */
+    private Boolean delIf;
 }

+ 51 - 0
src/main/java/com/hb/proj/well/controller/WellController.java

@@ -1,14 +1,20 @@
 package com.hb.proj.well.controller;
 
+
 import cn.hutool.core.util.IdUtil;
 import com.hb.proj.model.Well;
+import com.hb.proj.utils.RespVO;
+import com.hb.proj.utils.RespVOBuilder;
 import com.hb.proj.well.service.WellService;
+import com.hb.xframework.dao.util.PageModel;
+import jakarta.validation.constraints.NotBlank;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.Date;
+import java.util.Map;
 
 /**
  * 井相关接口
@@ -33,4 +39,49 @@ public class WellController {
         well.setCreateTime(new Date());
         wellService.insert(well);
     }
+    /**
+     * 井修改
+     * @apiNote 修改井信息
+     * @return 无
+     */
+    @RequestMapping("/update")
+    public void update(){
+        Well well = wellService.get("c15404d0d40e442ca35544d1f36a40bf");
+        well.setModifyTime(new Date());
+        well.setWellName("修改井名");
+        wellService.update(well);
+    }
+    /**
+     * 井删除
+     * @apiNote 删除井信息
+     * @return 无
+     */
+    @RequestMapping("/delete")
+    public void delete(){
+        Well well = wellService.get("c15404d0d40e442ca35544d1f36a40bf");
+        well.setModifyTime(new Date());
+        well.setDelIf(true);
+        wellService.update(well);
+    }
+    /**
+     * 获得单个井数据.
+     *  @apiNote <p>通过指定的井编号获取数据<br>
+     * @param id
+     * @return
+     */
+    @RequestMapping("/get")
+    RespVO<Well> getUser(@NotBlank(message = "井编号【wellId】不能为空") String id) {
+        return RespVOBuilder.ok(wellService.get(id));
+    }
+    /**
+     * 查询分页井数据.
+     *  @apiNote <p>通过条件获取数据<br>
+     * @return
+     */
+    @RequestMapping("/queryPaged")
+    RespVO<PageModel<Map<String,Object>>> queryPaged() {
+        PageModel<Map<String,Object>> page= wellService.queryPagedMap();
+
+        return RespVOBuilder.ok(page);
+    }
 }

+ 25 - 1
src/main/java/com/hb/proj/well/service/WellService.java

@@ -1,17 +1,41 @@
 package com.hb.proj.well.service;
 
 
+import com.hb.proj.auth.service.User;
 import com.hb.proj.model.Well;
 import com.hb.xframework.dao.core.SpringJdbcDAO;
+import com.hb.xframework.dao.util.PageModel;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Map;
+
 @Service
 public class WellService {
     @Autowired
     private SpringJdbcDAO springDAO;
     private String tabName="tzl_well";
     public void insert(Well well) {
-          springDAO.insert(well, tabName);
+        springDAO.insert(well, tabName);
+    }
+    public boolean update(Well well) {
+        return springDAO.update(well, "tzl_well", "well_id")>0;
+    }
+    public void delete(Well well) {
+         springDAO.update(well, "tzl_well", "well_id");
+    }
+    public Well get(String id){
+        String sql="""
+				
+				select * from tzl_well
+				where well_id=?
+				
+				""";
+        return springDAO.queryForPojo(sql,Well.class,id);
     }
+
+    public PageModel<Map<String,Object>> queryPagedMap(){
+        return springDAO.queryForPagedData("select * from tzl_well", 1, 10);
+    }
+
 }