Ver Fonte

添加Controller

gushoubang há 1 mês atrás
pai
commit
932d65b943

+ 76 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/LandOneCodeController.java

@@ -0,0 +1,76 @@
+package com.siwei.apply.controller;
+
+import com.siwei.apply.domain.LandOneCode;
+import com.siwei.apply.service.LandOneCodeService;
+import com.siwei.common.core.domain.R;
+import com.siwei.common.core.web.controller.BaseController;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 土地统一编码 控制器
+ * 提供基础的增删改查接口
+ */
+@RestController
+@RequestMapping("/landOneCode")
+@RequiredArgsConstructor
+public class LandOneCodeController extends BaseController {
+
+    private final LandOneCodeService service;
+
+    /**
+     * 新增
+     */
+    @PostMapping()
+    public R<Map<String, String>> add(@RequestBody LandOneCode body) {
+        try {
+            String id = service.add(body);
+            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<LandOneCode> getById(@PathVariable String id) {
+        try {
+            return R.ok(service.getById(id));
+        } catch (Exception e) {
+            return R.fail(e.getMessage());
+        }
+    }
+
+    /**
+     * 更新(按ID)
+     */
+    @PutMapping()
+    public R<Void> update(@RequestBody LandOneCode body) {
+        try {
+            service.update(body);
+            return R.ok();
+        } catch (Exception e) {
+            return R.fail(e.getMessage());
+        }
+    }
+
+    /**
+     * 删除(按ID)
+     */
+    @DeleteMapping("/{id}")
+    public R<Void> delete(@PathVariable String id) {
+        try {
+            service.deleteById(id);
+            return R.ok();
+        } catch (Exception e) {
+            return R.fail(e.getMessage());
+        }
+    }
+}

+ 10 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/mapper/LandOneCodeMapper.java

@@ -2,6 +2,7 @@ package com.siwei.apply.mapper;
 
 import com.siwei.apply.domain.LandOneCode;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * t_land_one_code 表的 MyBatis 映射接口(新增 add 方法)
@@ -11,6 +12,15 @@ public interface LandOneCodeMapper {
     // 添加一条土地统一编码记录
     void add(LandOneCode entity);
 
+    // 根据主键ID查询
+    LandOneCode getById(@Param("id") String id);
+
+    // 根据主键ID更新(仅更新非空字段)
+    void updateById(LandOneCode entity);
+
+    // 根据主键ID删除
+    void deleteById(@Param("id") String id);
+
     // 根据环节ID(project_workflow_id)修改三类编码
     void updateCodeByProjectWorkflowId(LandOneCode entity);
 }

+ 21 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/LandOneCodeService.java

@@ -0,0 +1,21 @@
+package com.siwei.apply.service;
+
+import com.siwei.apply.domain.LandOneCode;
+
+/**
+ * 土地统一编码 服务接口
+ */
+public interface LandOneCodeService {
+    /** 新增 */
+    String add(LandOneCode entity);
+
+    /** 根据ID查询 */
+    LandOneCode getById(String id);
+
+    /** 更新(按ID) */
+    void update(LandOneCode entity);
+
+    /** 删除(按ID) */
+    void deleteById(String id);
+}
+

+ 40 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/LandOneCodeServiceImpl.java

@@ -0,0 +1,40 @@
+package com.siwei.apply.service.impl;
+
+import com.siwei.apply.domain.LandOneCode;
+import com.siwei.apply.mapper.LandOneCodeMapper;
+import com.siwei.apply.service.LandOneCodeService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@RequiredArgsConstructor
+public class LandOneCodeServiceImpl implements LandOneCodeService {
+
+    private final LandOneCodeMapper mapper;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public String add(LandOneCode entity) {
+        entity.generateId();
+        mapper.add(entity);
+        return entity.getId();
+    }
+
+    @Override
+    public LandOneCode getById(String id) {
+        return mapper.getById(id);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void update(LandOneCode entity) {
+        mapper.updateById(entity);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteById(String id) {
+        mapper.deleteById(id);
+    }
+}

+ 24 - 0
siwei-modules/siwei-apply/src/main/resources/mapper/LandOneCodeMapper.xml

@@ -25,6 +25,30 @@
         )
     </insert>
 
+    <select id="getById" parameterType="string" resultMap="LandOneCodeResultMap">
+        SELECT id, land_code, project_id, project_workflow_id,
+               resource_immobile_code, resource_business_code, resource_project_code
+        FROM t_land_one_code
+        WHERE id = #{id}
+    </select>
+
+    <update id="updateById" parameterType="com.siwei.apply.domain.LandOneCode">
+        UPDATE t_land_one_code
+        <set>
+            <if test="landCode != null">land_code = #{landCode},</if>
+            <if test="projectId != null">project_id = #{projectId},</if>
+            <if test="projectWorkflowId != null">project_workflow_id = #{projectWorkflowId},</if>
+            <if test="resourceImmobileCode != null">resource_immobile_code = #{resourceImmobileCode},</if>
+            <if test="resourceBusinessCode != null">resource_business_code = #{resourceBusinessCode},</if>
+            <if test="resourceProjectCode != null">resource_project_code = #{resourceProjectCode},</if>
+        </set>
+        WHERE id = #{id}
+    </update>
+
+    <delete id="deleteById" parameterType="string">
+        DELETE FROM t_land_one_code WHERE id = #{id}
+    </delete>
+
     <update id="updateCodeByProjectWorkflowId" parameterType="com.siwei.apply.domain.LandOneCode">
         UPDATE t_land_one_code
         SET resource_immobile_code = #{resourceImmobileCode},