Administrator
2023-12-25 b7ea296dcc09cf12a11aa1b649401f77b5520215
2023-12-25 朱宝民 农户对象查询一个、删除一个、修改一个
7个文件已修改
1个文件已添加
238 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeClientMapper.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeClient.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeClientMapper.xml 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java 123 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientSv.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/DtoClient.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/DtoClientToSeClient.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/SeClientToVoClient.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoSe/SeClientMapper.java
@@ -64,4 +64,18 @@
     * @return
     */
    List<VoClient> getClients(Map<?, ?> params);
    /**
     * 根据农户ID逻辑删除农户
     * @param id 农户ID
     * @return 逻辑删除记录数
     */
    Integer deleteClientById(@Param("id") Long id);
    /**
     * 根据主键获取村ID
     * @param id 农户ID
     * @return 村主键
     */
    Long getVillageIdById(@Param("id") Long id);
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoSe/SeClient.java
@@ -9,9 +9,7 @@
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.baomidou.mybatisplus.annotation.*;
import com.dy.common.po.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
@@ -168,12 +166,14 @@
    @Schema(description = "是否禁用", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @Max(message = "是否禁用只能0或1", value = 1)
    @Min(message = "是否禁用只能0或1",value = 0)
    @TableField(updateStrategy = FieldStrategy.NEVER)
    private Byte disabled;
    /**
     * 逻辑删除标识;0-未删除,1-删除
     */
    @Schema(description = "删除标识,form表单中不存在,只在查询显示中有效", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
    @TableField(updateStrategy = FieldStrategy.NEVER)
    private Byte deleted;
}
pipIrr-platform/pipIrr-global/src/main/resources/mapper/SeClientMapper.xml
@@ -260,9 +260,10 @@
      address = #{address,jdbcType=VARCHAR},
      remarks = #{remarks,jdbcType=VARCHAR},
      `operator` = #{operator,jdbcType=BIGINT},
      operateDt = #{operatedt,jdbcType=TIMESTAMP},
      disabled = #{disabled,jdbcType=TINYINT},
      deleted = #{deleted,jdbcType=TINYINT}
      operateDt = #{operatedt,jdbcType=TIMESTAMP}
<!--    ,-->
<!--      disabled = #{disabled,jdbcType=TINYINT},-->
<!--      deleted = #{deleted,jdbcType=TINYINT}-->
    where id = #{id,jdbcType=BIGINT}
  </update>
@@ -347,4 +348,19 @@
  <select id="getClientIdByNum" resultType="java.lang.Long">
    SELECT id FROM se_client WHERE clientNum = ${clientNum}
  </select>
  <!--根据农户ID逻辑删除农户-->
  <update id="deleteClientById" parameterType="java.lang.Long">
    update se_client set deleted = 1
    <where>
      <if test = "id != null and id > 0">
        AND id = ${id}
      </if>
    </where>
  </update>
  <!--根据主键获取村ID-->
  <select id="getVillageIdById" parameterType="java.lang.Long" resultType="java.lang.Long">
    SELECT villageId FROM se_client WHERE id = ${id}
  </select>
</mapper>
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
@@ -61,6 +61,28 @@
        }
    }
    @Operation(summary = "获得一个农户", description = "返回一个农户数据")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回一页农户数据(BaseResponse.content:QueryResultVo[{}])",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = BaClient.class))}
            )
    })
    @GetMapping(path = "/getone/{id}")
    @SsoAop()
    public BaseResponse<VoClient> getOneClient(@PathVariable("id") Long id){
        try {
            VoClient res = clientSv.getOneClient(id);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询农户异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
    @Operation(summary = "添加农户记录", description = "添加农户记录")
    @ApiResponses(value = {
            @ApiResponse(
@@ -153,4 +175,105 @@
        return clientNum;
    }
    /**
     * 修改农户对象
     * @param po 农户对象
     * @param bindingResult
     * @return
     */
    @Operation(summary = "修改农户记录", description = "修改农户记录")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "操作结果:true:成功,false:失败(BaseResponse.content)",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = Boolean.class))}
            )
    })
    @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public BaseResponse<Boolean> update(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid DtoClient po, @Parameter(hidden = true) BindingResult bindingResult){
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        // 接收村编号(主键)
        Long villageId = po.getVillageid();
        /**
         * 获取5级行政区划信息
         */
        Map map_districts = Optional.ofNullable(clientSv.getDistrictsByVillageId(villageId)).orElse(new HashMap());
        if(map_districts.size() <= 0) {
            return BaseResponseUtils.buildFail("区划信息有误");
        }
        String provinceNum = map_districts.get("provinceNum").toString();
        String cityNum = map_districts.get("cityNum").toString();
        Long countryId = Long.parseLong(map_districts.get("countryId").toString());
        String countyNum = map_districts.get("countyNum").toString();
        String countryName = map_districts.get("countryName").toString();
        Long townId = Long.parseLong(map_districts.get("townId").toString());
        String townNum = map_districts.get("townNum").toString();
        String townName = map_districts.get("townName").toString();
        String villageNum = map_districts.get("villageNum").toString();
        String villageName = map_districts.get("villageName").toString();
        // 生成8位行政区划编码,生成农户编号用
        String district8 = countyNum + townNum + villageNum;
        // 生成农户编号
        String clientNum = generateClientNum(district8);
        // 生成12位5级行政区划编码串及名称串
        Long districtNum = Long.parseLong(provinceNum + cityNum + district8);
        String districtTitle = countryName + townName + villageName;
        SeClient seClient = DtoClientToSeClient.INSTANCT.po2vo(po);
        seClient.setCountyid(countryId);
        seClient.setTownid(townId);
        seClient.setClientnum(clientNum);
        seClient.setDistrictnum(districtNum);
        seClient.setDistricttitle(districtTitle);
        Date operateTime = new Date();
        seClient.setOperatedt(operateTime);
        //
        //seClient.setDisabled((byte)0);
        //seClient.setDeleted((byte)0);
        Integer rec = Optional.ofNullable(clientSv.updateByPrimaryKey(seClient)).orElse(0);
        if(rec == 0) {
            return BaseResponseUtils.buildFail("添加农户失败");
        }
        return BaseResponseUtils.buildSuccess(true) ;
    }
    /**
     * 根据农户ID逻辑删除农户
     * @param id
     * @return
     */
    @Operation(summary = "删除一个农户", description = "删除一个农户数据")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回一页农户数据(BaseResponse.content:QueryResultVo[{}])",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = BaClient.class))}
            )
    })
    @GetMapping(path = "/delone/{id}")
    @SsoAop()
    public BaseResponse<Boolean> deleteClientById(@PathVariable("id") Long id){
        try {
            Integer res = Optional.ofNullable(clientSv.deleteClientById(id)).orElse(0);
            if(res == 0) {
                return BaseResponseUtils.buildFail("农户删除失败");
            }
            return BaseResponseUtils.buildSuccess(true);
        } catch (Exception e) {
            log.error("查询农户异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientSv.java
@@ -48,6 +48,16 @@
    }
    /**
     * 根据主键获取农户对象
     * @param id 农户主键
     * @return 农户对象
     */
    public VoClient getOneClient(Long id) {
        SeClient seClient = seClientMapper.selectByPrimaryKey(id);
        VoClient voClient = SeClientToVoClient.INSTANCT.po2vo(seClient);
        return voClient;
    }
    /**
     * 增开农户
     * @param po
     * @return
@@ -73,4 +83,30 @@
    public Map getDistrictsByVillageId(Long villageId) {
        return baDistrictMapper.getDistrictsByVillageId(villageId);
    }
    /**
     * 根据农户ID逻辑删除农户
     */
    public Integer deleteClientById(Long id) {
        return seClientMapper.deleteClientById(id);
    }
    /**
     * 修改农户对象
     * @param po 农户对象
     * @return 修改记录条数
     */
    public Integer updateByPrimaryKey(SeClient po) {
        return seClientMapper.updateByPrimaryKey(po);
    }
    /**
     * 根据主键获取村ID
     * @param id
     * @return
     */
    public Long getVillageIdById(Long id) {
        return seClientMapper.getVillageIdById(id);
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/DtoClient.java
@@ -22,6 +22,12 @@
    public static final long serialVersionUID = 1L;
    /**
     * ID
     */
    @Schema(description = "农户ID", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long id;
    /**
     * 村ID
     */
    @Schema(description = "所在村ID", requiredMode = Schema.RequiredMode.REQUIRED)
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/DtoClientToSeClient.java
@@ -26,5 +26,8 @@
    @Mapping(target = "address", source = "address")
    @Mapping(target = "remarks", source = "remarks")
    @Mapping(target = "operator", source = "operator")
    @Mapping(target = "disabled", ignore=true)
    @Mapping(target = "deleted", ignore=true)
    SeClient po2vo(DtoClient po);
}
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/SeClientToVoClient.java
New file
@@ -0,0 +1,28 @@
package com.dy.pipIrrSell.client;
import com.dy.pipIrrGlobal.pojoSe.SeClient;
import com.dy.pipIrrGlobal.voSe.VoClient;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
/**
 * @author ZhuBaoMin
 * @date 2023-12-25 15:54
 * @LastEditTime 2023-12-25 15:54
 * @Description
 */
@Mapper
public interface SeClientToVoClient {
    SeClientToVoClient INSTANCT = Mappers.getMapper(SeClientToVoClient.class);
    @Mapping(target = "name", source = "name")
    @Mapping(target = "clientNum", source = "clientnum")
    @Mapping(target = "phone", source = "phone")
    @Mapping(target = "idCard", source = "idcard")
    //@Mapping(target = "cardCount", source = "cardCount")
    @Mapping(target = "address", source = "address")
    @Mapping(target = "operateDt", source = "operatedt")
    VoClient po2vo(SeClient po);
}