Explorar o código

添加土地供应相关方法

gushoubang hai 2 meses
pai
achega
92f4b6f744

+ 61 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/TdgyController.java

@@ -0,0 +1,61 @@
+package com.siwei.apply.controller;
+
+import com.siwei.apply.domain.Tdgy;
+import com.siwei.apply.service.TdgyService;
+import com.siwei.common.core.domain.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 土地供应 控制器
+ */
+@RestController
+@RequestMapping("/tdgy")
+public class TdgyController {
+    @Autowired
+    private TdgyService tdgyService;
+
+    /**
+     * 添加供地信息
+     */
+    @PostMapping()
+    public R<Map> add(@RequestBody Tdgy tdgy) {
+        try {
+            String id = tdgyService.add(tdgy);
+            Map<String, String> map = new HashMap<>();
+            map.put("id", id);
+            return R.ok(map);
+        } catch (Exception e) {
+            return R.fail(e.getMessage());
+        }
+    }
+
+    /**
+     * 根据 ID 获取供地信息
+     */
+    @GetMapping("/{id}")
+    public R<Tdgy> get(@PathVariable("id") String id) {
+        try {
+            Tdgy tdgy = tdgyService.get(id);
+            return R.ok(tdgy);
+        } catch (Exception e) {
+            return R.fail(e.getMessage());
+        }
+    }
+
+    /**
+     * 更新供地信息(按非空字段更新)
+     */
+    @PutMapping("")
+    public R<Void> update(@RequestBody Tdgy tdgy) {
+        try {
+            tdgyService.update(tdgy);
+            return R.ok();
+        } catch (Exception e) {
+            return R.fail(e.getMessage());
+        }
+    }
+}

+ 9 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/domain/Tdgy.java

@@ -1,9 +1,11 @@
 package com.siwei.apply.domain;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
 
 import java.util.Date;
 import java.util.Map;
+import java.util.UUID;
 
 /*
  * 土地供应对象 t_tdgy
@@ -24,6 +26,13 @@ public class Tdgy {
     private Map<String, Object> attachment;     // 附件
     private Boolean hasOnchain;    // 是否上链
     private String creatorId;      // 创建人ID
+
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createdAt;        // 创建时间
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date updatedAt;        // 更新时间
+
+    public void generateId() {
+        this.id = UUID.randomUUID().toString();
+    }
 }

+ 32 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/TdgyService.java

@@ -0,0 +1,32 @@
+package com.siwei.apply.service;
+
+import com.siwei.apply.domain.Tdgy;
+
+/**
+ * 土地供应 服务接口
+ */
+public interface TdgyService {
+    /**
+     * 添加一条供地记录
+     *
+     * @param tdgy Tdgy 对象
+     * @return 插入是否成功
+     */
+    String add(Tdgy tdgy);
+
+    /**
+     * 根据 ID 获取供地信息
+     *
+     * @param id 主键
+     * @return Tdgy 对象
+     */
+    Tdgy get(String id);
+
+    /**
+     * 更新供地信息
+     *
+     * @param tdgy Tdgy 对象
+     * @return 更新是否成功
+     */
+    void update(Tdgy tdgy);
+}

+ 36 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/TdgyImpl.java

@@ -0,0 +1,36 @@
+package com.siwei.apply.service.impl;
+
+import com.siwei.apply.domain.Tdgy;
+import com.siwei.apply.mapper.TdgyMapper;
+import com.siwei.apply.service.TdgyService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import static com.siwei.apply.common.Common.UserId;
+
+/**
+ * 土地供应 服务实现类
+ */
+@Service
+public class TdgyImpl implements TdgyService {
+    @Autowired
+    private TdgyMapper tdgyMapper;
+
+    @Override
+    public String add(Tdgy tdgy) {
+        tdgy.generateId();
+        tdgy.setCreatorId(UserId);
+        tdgyMapper.add(tdgy);
+        return tdgy.getId();
+    }
+
+    @Override
+    public Tdgy get(String id) {
+        return tdgyMapper.get(id);
+    }
+
+    @Override
+    public void update(Tdgy tdgy) {
+        tdgyMapper.update(tdgy);
+    }
+}