|  |  |  | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.responses.ApiResponses; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.tags.Tag; | 
|---|
|  |  |  | import jakarta.validation.Valid; | 
|---|
|  |  |  | import jakarta.validation.constraints.NotNull; | 
|---|
|  |  |  | import lombok.RequiredArgsConstructor; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.http.MediaType; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.validation.BindingResult; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Tag(name = "农户管理", description = "农户操作") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(path="client") | 
|---|
|  |  |  | @RequestMapping(path = "client") | 
|---|
|  |  |  | @RequiredArgsConstructor | 
|---|
|  |  |  | public class ClientCtrl { | 
|---|
|  |  |  | private final ClientSv clientSv; | 
|---|
|  |  |  | //private final RedisUtils redisUtils; | 
|---|
|  |  |  | @Value("${project.projectNo}") | 
|---|
|  |  |  | private Integer projectNo; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取农户列表 | 
|---|
|  |  |  | 
|---|
|  |  |  | String villageName = map_districts.get("villageName").toString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成8位行政区划编码,生成农户编号用 | 
|---|
|  |  |  | String district8 = countyNum + townNum + villageNum; | 
|---|
|  |  |  | String district8 = String.format("%02d", Integer.parseInt(countyNum))  + String.format("%03d", Integer.parseInt(townNum)) + String.format("%03d", Integer.parseInt(villageNum)); | 
|---|
|  |  |  | // 生成农户编号 | 
|---|
|  |  |  | String clientNum = generateClientNum(district8); | 
|---|
|  |  |  | if(clientNum == null) { | 
|---|
|  |  |  | return BaseResponseUtils.buildErrorMsg("农户编号超限"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 生成12位5级行政区划编码串及名称串 | 
|---|
|  |  |  | Long districtNum = Long.parseLong(provinceNum + cityNum + district8); | 
|---|
|  |  |  | String districtTitle = countryName + townName + villageName; | 
|---|
|  |  |  | 
|---|
|  |  |  | Integer number = Integer.parseInt(clientNum.substring(8)); | 
|---|
|  |  |  | number = number + 1; | 
|---|
|  |  |  | if(number > 9999) { | 
|---|
|  |  |  | return "农户编号超限"; | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | clientNum = clientNum.substring(0, 8) + String.format("%04d", number); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | 
|---|
|  |  |  | String villageName = map_districts.get("villageName").toString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成8位行政区划编码,生成农户编号用 | 
|---|
|  |  |  | String district8 = countyNum + townNum + villageNum; | 
|---|
|  |  |  | //String district8 = countyNum + townNum + villageNum; | 
|---|
|  |  |  | String district8 = String.format("%02d", Integer.parseInt(countyNum))  + String.format("%03d", Integer.parseInt(townNum)) + String.format("%03d", Integer.parseInt(villageNum)); | 
|---|
|  |  |  | // 生成农户编号 | 
|---|
|  |  |  | String clientNum = generateClientNum(district8); | 
|---|
|  |  |  | // 生成12位5级行政区划编码串及名称串 | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(map_WaterTypes); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据村ID获取12位行政区划 | 
|---|
|  |  |  | * @param villageId | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "根据村ID获取12位行政区划", description = "根据村ID获取12位行政区划") | 
|---|
|  |  |  | @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))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "district") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> getDistrictNum(@RequestParam("villageId") @NotNull(message = "村编号不能为空") Long villageId){ | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取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(); | 
|---|
|  |  |  | String countyNum = map_districts.get("countyNum").toString(); | 
|---|
|  |  |  | String townNum = map_districts.get("townNum").toString(); | 
|---|
|  |  |  | String villageNum = map_districts.get("villageNum").toString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生成12位5级行政区划编码串及名称串 | 
|---|
|  |  |  | Long districtNum = Long.parseLong(provinceNum + cityNum + countyNum + townNum + villageNum); | 
|---|
|  |  |  | //获取项目编码 | 
|---|
|  |  |  | //        String projectNo = clientSv.getItemValue("projectNo"); | 
|---|
|  |  |  | //        //转为int | 
|---|
|  |  |  | //        Integer projectNo1 = Integer.valueOf(projectNo); | 
|---|
|  |  |  | //        //转为16进制 | 
|---|
|  |  |  | ////        String projectNo2 = Integer.toHexString(projectNo1); | 
|---|
|  |  |  | ////        log.info(projectNo2); | 
|---|
|  |  |  | String projectNo3 = String.format("%02x", projectNo); | 
|---|
|  |  |  | log.info(projectNo3); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map map = new HashMap(); | 
|---|
|  |  |  | map.put("districtNum", districtNum); | 
|---|
|  |  |  | map.put("projectNo",projectNo3); | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(map); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|