From 079d7aaca34dffa3bdcdc291c861b51ee707a67e Mon Sep 17 00:00:00 2001 From: wuzeyu <1223318623@qq.com> Date: 星期三, 15 五月 2024 09:29:53 +0800 Subject: [PATCH] 田间灌溉项目管理 添加项目接口 逻辑删除项目接口 --- pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/result/IrrigateResultCode.java | 7 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrProjectMapper.java | 27 +++ pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoIr/IrProject.java | 111 +++++++++++++ pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrProjectMapper.xml | 118 ++++++++++++++ pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectCtrl.java | 99 ++++++++++++ pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectSv.java | 70 ++++++++ 6 files changed, 429 insertions(+), 3 deletions(-) diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrProjectMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrProjectMapper.java new file mode 100644 index 0000000..6f69940 --- /dev/null +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrProjectMapper.java @@ -0,0 +1,27 @@ +package com.dy.pipIrrGlobal.daoIr; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.dy.pipIrrGlobal.pojoIr.IrProject; +import com.dy.pipIrrGlobal.pojoPr.PrController; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author :WuZeYu + * @Date :2024/5/14 15:04 + * @LastEditTime :2024/5/14 15:04 + * @Description + */ +@Mapper +public interface IrProjectMapper extends BaseMapper<IrProject> { + + int insertSelective(IrProject record); + + int deleteLogicById(Long id); + + /** + * 鏍规嵁涓嬬骇Id鑾峰彇涓婁竴绾у湴鍧�Id + * @param vaId 涓嬩竴绾d + * @return + */ + Long getSupperByVillageId(long vaId); +} diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoIr/IrProject.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoIr/IrProject.java new file mode 100644 index 0000000..b6e9ae6 --- /dev/null +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoIr/IrProject.java @@ -0,0 +1,111 @@ +package com.dy.pipIrrGlobal.pojoIr; + +import com.alibaba.fastjson2.annotation.JSONField; +import com.alibaba.fastjson2.writer.ObjectWriterImplToString; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.dy.common.po.BaseEntity; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.*; +import org.hibernate.validator.constraints.Length; + +import java.util.Date; + +/** + * @author :WuZeYu + * @Date :2024/5/14 13:53 + * @LastEditTime :2024/5/14 13:53 + * @Description + */ + +/** + * 椤圭洰琛� + */ + +@TableName(value="ir_project", autoResultMap = true) +@Data +@Builder +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "椤圭洰瀹炰綋") +public class IrProject implements BaseEntity { + public static final long serialVersionUID = 202405141427001L; + + /** + * 涓婚敭 + */ + @JSONField(serializeUsing= ObjectWriterImplToString.class) + @TableId(type = IdType.INPUT) + @Schema(description = "瀹炰綋id", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Long id; + + /** + * 椤圭洰鍚嶇О + */ + @Schema(description = "椤圭洰鍚嶇О", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "椤圭洰鍚嶇О涓嶈兘涓虹┖") + @Length(message = "椤圭洰鍚嶇О涓嶅ぇ浜巤max}瀛�",max = 50) + private String projectName; + + /** + * 鐪両D + */ + @Schema(description = "鐪両D", requiredMode = Schema.RequiredMode.REQUIRED) + private Long provinceId; + /** + * 甯侷D + */ + @Schema(description = "甯侷D", requiredMode = Schema.RequiredMode.REQUIRED) + private Long cityId; + /** + * 鍘縄D + */ + @Schema(description = "鍘縄D", requiredMode = Schema.RequiredMode.REQUIRED) + private Long countyId; + /** + * 闀嘔D + */ + @Schema(description = "闀嘔D", requiredMode = Schema.RequiredMode.REQUIRED) + private Long townId; + /** + * 鏉慖D + */ + @Schema(description = "鏉慖D", requiredMode = Schema.RequiredMode.REQUIRED) + private Long villageId; + + + + /** + * 椤圭洰鐘舵��;1-鍚姩锛�2-鍋滄 + */ + @Schema(description = "椤圭洰鐘舵��", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Byte projectState; + + /** + * 鎿嶄綔浜篒D + */ + @Schema(description = "鎿嶄綔浜篒D", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Long operator; + + /** + * 鎿嶄綔鏃堕棿 + */ + @Schema(description = "鎿嶄綔鏃堕棿", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Date operateDt; + + /** + * 澶囨敞 + */ + @Schema(description = "澶囨敞", requiredMode = Schema.RequiredMode.REQUIRED) + private String remarks; + + /** + * 閫昏緫鍒犻櫎鏍囪瘑;0-鏈垹闄わ紝1-鍒犻櫎 + */ + @Schema(description = "鍒犻櫎鏍囪瘑", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Byte deleted; +} \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrProjectMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrProjectMapper.xml new file mode 100644 index 0000000..81848e5 --- /dev/null +++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrProjectMapper.xml @@ -0,0 +1,118 @@ +<?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.dy.pipIrrGlobal.daoIr.IrProjectMapper"> + <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoIr.IrProject"> + <!--@mbg.generated--> + <!--@Table ir_project--> + <id column="id" jdbcType="BIGINT" property="id" /> + <result column="project_name" jdbcType="VARCHAR" property="projectName" /> + <result column="province_id" jdbcType="BIGINT" property="provinceId" /> + <result column="city_id" jdbcType="BIGINT" property="cityId" /> + <result column="county_id" jdbcType="BIGINT" property="countyId" /> + <result column="town_id" jdbcType="BIGINT" property="townId" /> + <result column="village_id" jdbcType="BIGINT" property="villageId" /> + <result column="project_state" jdbcType="TINYINT" property="projectState" /> + <result column="remarks" jdbcType="VARCHAR" property="remarks" /> + <result column="operator" jdbcType="BIGINT" property="operator" /> + <result column="operate_time" jdbcType="TIMESTAMP" property="operateDt" /> + <result column="deleted" jdbcType="TINYINT" property="deleted" /> + </resultMap> + + <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoIr.IrProject"> + <!--@mbg.generated--> + insert into ir_project + <trim prefix="(" suffix=")" suffixOverrides=","> + <if test="id != null"> + id, + </if> + <if test="projectName != null"> + project_name, + </if> + <if test="provinceId != null"> + province_id, + </if> + <if test="cityId != null"> + city_id, + </if> + <if test="countyId != null"> + county_id, + </if> + <if test="townId != null"> + town_id, + </if> + <if test="villageId != null"> + village_id, + </if> + <if test="projectState != null"> + project_state, + </if> + <if test="remarks != null"> + remarks, + </if> + <if test="operator != null"> + `operator`, + </if> + <if test="operateDt != null"> + operate_time, + </if> + <if test="deleted != null"> + deleted, + </if> + </trim> + <trim prefix="values (" suffix=")" suffixOverrides=","> + <if test="id != null"> + #{id,jdbcType=BIGINT}, + </if> + <if test="projectName != null"> + #{projectName,jdbcType=VARCHAR}, + </if> + <if test="provinceId != null"> + #{provinceId,jdbcType=BIGINT}, + </if> + <if test="cityId != null"> + #{cityId,jdbcType=BIGINT}, + </if> + <if test="countyId != null"> + #{countyId,jdbcType=BIGINT}, + </if> + <if test="townId != null"> + #{townId,jdbcType=BIGINT}, + </if> + <if test="villageId != null"> + #{villageId,jdbcType=BIGINT}, + </if> + <if test="projectState != null"> + #{projectState,jdbcType=TINYINT}, + </if> + <if test="remarks != null"> + #{remarks,jdbcType=VARCHAR}, + </if> + <if test="operator != null"> + #{operator,jdbcType=BIGINT}, + </if> + <if test="operateDt != null"> + #{operateDt,jdbcType=TIMESTAMP}, + </if> + <if test="deleted != null"> + #{deleted,jdbcType=TINYINT}, + </if> + </trim> + </insert> + + <!--鏍规嵁涓嬬骇鑾峰彇涓婁竴绾у湴鍧�--> + <select id="getSupperByVillageId" parameterType="_long" resultType="java.lang.Long"> + select dis_tow.* + from ba_district dis_vil + inner join + ba_district dis_tow + on dis_vil.supperId = dis_tow.id + where dis_vil.id = #{vaId,jdbcType=BIGINT} + </select> + + <delete id="deleteLogicById" parameterType="java.lang.Long"> + <!--@mbg.generated--> + update ir_project + set deleted = 1 + where id = #{id,jdbcType=BIGINT} + </delete> +</mapper> \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectCtrl.java new file mode 100644 index 0000000..409ed4e --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectCtrl.java @@ -0,0 +1,99 @@ +package com.dy.pipIrrIrrigate.project; + +import com.dy.common.aop.SsoAop; +import com.dy.common.webUtil.BaseResponse; +import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.ResultCodeMsg; +import com.dy.pipIrrGlobal.pojoIr.IrProject; +import com.dy.pipIrrIrrigate.result.IrrigateResultCode; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.annotations.Param; +import org.springframework.http.MediaType; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +/** + * @author :WuZeYu + * @Date :2024/5/14 13:53 + * @LastEditTime :2024/5/14 13:53 + * @Description + */ +@Slf4j +@Tag(name = "椤圭洰绠$悊", description = "椤圭洰鎿嶄綔") +@RestController +@RequestMapping(path = "project") +@RequiredArgsConstructor +public class ProjectCtrl { + private final ProjectSv projectSv; + + /** + * 娣诲姞椤圭洰 + * + * @param po 椤圭洰瀹炰綋瀵硅薄 + * @param bindingResult + * @return 娣诲姞鏄惁鎴愬姛 + */ + @Operation(summary = "娣诲姞椤圭洰璁板綍", description = "娣诲姞椤圭洰璁板綍") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = Boolean.class))} + ) + }) + @PostMapping(path = "add", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> add(@RequestBody @Valid IrProject po, BindingResult bindingResult) { + if (bindingResult != null && bindingResult.hasErrors()) { + return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + try { + Integer rec = Optional.ofNullable(projectSv.addProject(po)).orElse(0); + if (rec == 0) { + return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_PROJECT_FAIL.getMessage()); + } + } catch (Exception e) { + log.error("娣诲姞椤圭洰寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + return BaseResponseUtils.buildSuccess(true); + } + + @PostMapping(path = "delete", consumes = MediaType.APPLICATION_JSON_VALUE) + @Transactional(rollbackFor = Exception.class) + @SsoAop() + public BaseResponse<Boolean> delete(@RequestBody Map map) { + if (map == null || map.size() <= 0) { + BaseResponseUtils.buildFail(IrrigateResultCode.PLEASE_INPUT_PROJECT_ID.getMessage()); + } + Long projectId = Long.parseLong(map.get("projectId").toString()); + try { + Integer rows = projectSv.deleteProject(projectId); + if (rows == 0) { + return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage()); + } + } catch (Exception e) { + log.error("鍒犻櫎椤圭洰寮傚父", e); + return BaseResponseUtils.buildException(e.getMessage()); + } + return BaseResponseUtils.buildSuccess(true); + } +} diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectSv.java new file mode 100644 index 0000000..3a5ce63 --- /dev/null +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectSv.java @@ -0,0 +1,70 @@ +package com.dy.pipIrrIrrigate.project; + + +import com.dy.pipIrrGlobal.daoIr.IrProjectMapper; +import com.dy.pipIrrGlobal.pojoIr.IrProject; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; + +/** + * @author :WuZeYu + * @Date :2024/5/14 13:56 + * @LastEditTime :2024/5/14 13:56 + * @Description + */ +@Slf4j +@Service +public class ProjectSv { + @Autowired + private IrProjectMapper irProjectMapper; + + /** + * 娣诲姞椤圭洰 + * + * @param po + * @return + */ + public Integer addProject(IrProject po) { + po.setOperateDt(new Date()); + po.setDeleted((byte) 0); + if (po.getVillageId() != null) { + po.setTownId(irProjectMapper.getSupperByVillageId(po.getVillageId())); + po.setCountyId(irProjectMapper.getSupperByVillageId(po.getTownId())); + po.setCityId(irProjectMapper.getSupperByVillageId(po.getCountyId())); + po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId())); + } + if (po.getTownId() != null) { + po.setCountyId(irProjectMapper.getSupperByVillageId(po.getTownId())); + po.setCityId(irProjectMapper.getSupperByVillageId(po.getCountyId())); + po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId())); + } + if (po.getCountyId() != null) { + po.setCityId(irProjectMapper.getSupperByVillageId(po.getCountyId())); + po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId())); + } + if (po.getCityId() != null) { + po.setProvinceId(irProjectMapper.getSupperByVillageId(po.getCityId())); + } + int rows = irProjectMapper.insertSelective(po); + if (rows == 0) { + return 0; + } + return 1; + } + + /** + * 鍒犻櫎椤圭洰 + * + * @param id + */ + public Integer deleteProject(Long id) { + int rows = irProjectMapper.deleteLogicById(id); + if (rows == 0) { + return 0; + } + return 1; + } +} diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/result/IrrigateResultCode.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/result/IrrigateResultCode.java index 8c3ec6c..f165eaf 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/result/IrrigateResultCode.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/result/IrrigateResultCode.java @@ -14,10 +14,11 @@ @AllArgsConstructor public enum IrrigateResultCode { /** - * 鐢伴棿鐏屾簤椤圭洰 + * 椤圭洰 */ - DIVIDE_FAIL(10001, "鍒嗘按鎴挎坊鍔犲け璐�"), - DELETE_DIVIDE_FAIL(10001, "鍒嗘按鎴垮垹闄ゅけ璐�"), + ADD_PROJECT_FAIL(10001, "椤圭洰娣诲姞澶辫触"), + PLEASE_INPUT_PROJECT_ID(10002, "璇疯緭鍏ラ」鐩甀D"), + DELETE_PROJECT_FAIL(10003, "椤圭洰鍒犻櫎澶辫触"), NO_DIVIDES(10001, "鏃犵鍚堟潯浠剁殑鍒嗘按鎴胯褰�"); -- Gitblit v1.8.0