From d4fabb188a2426c3e0a0d13074c81c7b9f54ca97 Mon Sep 17 00:00:00 2001 From: Administrator <zhubaomin> Date: 星期六, 20 一月 2024 11:00:04 +0800 Subject: [PATCH] 2024-01-20 朱宝民 用户实体类id改为userId --- pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java | 247 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 233 insertions(+), 14 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java index a274591..8a41586 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/district/DistrictCtrl.java @@ -1,13 +1,18 @@ package com.dy.pipIrrBase.district; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import com.dy.common.aop.SsoAop; +import com.dy.common.mybatis.envm.Deleted; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.QueryResultVo; import com.dy.common.webUtil.ResultCodeMsg; +import com.dy.pipIrrGlobal.pojoBa.BaClient; import com.dy.pipIrrGlobal.pojoBa.BaDistrict; import com.dy.pipIrrGlobal.util.DistrictLevel; import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -18,14 +23,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; +import java.util.*; @Slf4j @Tag(name = "琛屾斂鍖哄垝绠$悊", description = "琛屾斂鍖哄垝澧炲垹鏀规煡绛夋搷浣�") @@ -56,10 +56,48 @@ }) @GetMapping(path = "allLevel") public BaseResponse<List<DistrictLevel>> allDistrictLevels(){ - List<DistrictLevel> list = Arrays.asList(DistrictLevel.City, DistrictLevel.County, DistrictLevel.Town, DistrictLevel.Village, DistrictLevel.Group) ; + //List<DistrictLevel> list = Arrays.asList(DistrictLevel.City, DistrictLevel.County, DistrictLevel.Town, DistrictLevel.Village) ; + return BaseResponseUtils.buildSuccess(DistrictLevel.LevelList); + } + + /** + * 瀹㈡埛绔姹傚緱鍒版墍鏈夎鏀垮尯鏁版嵁 + * @return 鎵�鏈夎鏀垮尯鏁版嵁 + */ + @Operation(summary = "鑾峰緱鎵�鏈夎鏀垮尯", description = "杩斿洖鎵�鏈夎鏀垮尯鏁版嵁") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖鎵�鏈夎鏀垮尯鏁版嵁锛圔aseResponse.content:[{}]锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = BaDistrict.class))} + ) + }) + @GetMapping(path = "all") + @SsoAop() + public BaseResponse<List<BaDistrict>> all(){ + List<BaDistrict> list = this.sv.selectAllByLevel(DistrictLevel.City.code) ; return BaseResponseUtils.buildSuccess(list); } + /** + * 寰楀埌涓�涓鏀垮尯鏁版嵁 + * @return 涓�涓鏀垮尯鏁版嵁 + */ + @Operation(summary = "涓�涓鏀垮尯", description = "寰楀埌涓�涓鏀垮尯鏁版嵁") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖涓�涓鏀垮尯鏁版嵁锛圔aseResponse.content:{}锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = BaDistrict.class))} + ) + }) + @GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE) + @SsoAop() + public BaseResponse<BaDistrict> one(Long id){ + return BaseResponseUtils.buildSuccess(this.sv.selectById(id)); + } /** * 淇濆瓨琛屾斂鍖� @@ -70,29 +108,210 @@ @ApiResponses(value = { @ApiResponse( responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, - description = "淇濆瓨琛屾斂鍖鸿繑鍥烇細true锛氭垚鍔燂紝false锛氬け璐ワ紙鏁版嵁鍩虹被鐨刢ontent锛�", + description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�", content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = Boolean.class))} ) }) - @PostMapping(path = "save", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - @SsoAop("-1")//@SsoAop(power = "-1") - public BaseResponse<Boolean> save(@Parameter(description = "form琛ㄥ崟鏁版嵁", required = true) @Valid DistrictVo vo, @Parameter(hidden = true) BindingResult bindingResult){ + @PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE) + @SsoAop() + public BaseResponse<Boolean> save(@RequestBody @Valid DistrictVo vo, BindingResult bindingResult){ if(bindingResult != null && bindingResult.hasErrors()){ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } BaDistrict po = DistrictVoMapper.INSTANCT.convert(vo); int count; try { + BaDistrict supperPo = this.sv.selectById(po.supperId) ; + if(supperPo == null){ + return BaseResponseUtils.buildFail("鍑洪敊锛屾湭寰楀埌涓婄骇琛屾斂鍖�") ; + }else{ + po.level = DistrictLevel.get((byte)(supperPo.level.code + 1)) ; + } + po.deleted = Deleted.NO ; count = this.sv.save(po); } catch (Exception e) { log.error("淇濆瓨琛屾斂鍖哄紓甯�", e); return BaseResponseUtils.buildException(e.getMessage()) ; } if(count <= 0){ - return BaseResponseUtils.buildSuccess(true) ; + return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ; }else{ return BaseResponseUtils.buildSuccess(true) ; } } + + /** + * 缂栬緫淇敼琛屾斂鍖� + * @param vo 淇濆瓨琛屾斂鍖篺orm琛ㄥ崟瀵硅薄 + * @return 鏄惁鎴愬姛 + */ + @Operation(summary = "缂栬緫淇敼琛屾斂鍖�", description = "鎻愪氦琛屾斂鍖烘暟鎹紙form琛ㄥ崟锛夛紝杩涜淇敼") + @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 = "update", consumes = MediaType.APPLICATION_JSON_VALUE) + @SsoAop() + public BaseResponse<Boolean> update(@RequestBody @Valid DistrictVo vo, BindingResult bindingResult){ + if(bindingResult != null && bindingResult.hasErrors()){ + return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); + } + BaDistrict po = DistrictVoMapper.INSTANCT.convert(vo); + int count; + try { + count = this.sv.update(po); + } catch (Exception e) { + log.error("淇濆瓨琛屾斂鍖哄紓甯�", e); + return BaseResponseUtils.buildException(e.getMessage()) ; + } + if(count <= 0){ + return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ; + }else{ + return BaseResponseUtils.buildSuccess(true) ; + } + } + + + /** + * 鍒犻櫎琛屾斂鍖� + * @param id 琛屾斂鍖篒D + * @return 鏄惁鎴愬姛 + */ + @Operation(summary = "鍒犻櫎琛屾斂鍖�", description = "鎻愪氦琛屾斂鍖篒D锛岃繘琛岄�昏緫鍒犻櫎") + @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))} + ) + }) + @GetMapping(path = "delete", consumes = MediaType.TEXT_PLAIN_VALUE) + @SsoAop() + public BaseResponse<Boolean> delete(Long id){ + if(id == null){ + return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖") ; + } + int count; + try { + count = this.sv.delete(id); + } catch (Exception e) { + log.error("淇濆瓨琛屾斂鍖哄紓甯�", e); + return BaseResponseUtils.buildException(e.getMessage()) ; + } + if(count <= 0){ + return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�") ; + }else{ + return BaseResponseUtils.buildSuccess(true) ; + } + } + + /** + * 鏍规嵁绾у埆鑾峰彇琛屾斂鍖哄垝鍒楄〃 + * @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 = "/level/{id}") + @SsoAop() + public BaseResponse<QueryResultVo<List<Map<String, Object>>>> getDistrictgsByLevel(@PathVariable("id") Integer id){ + if(id == null || id <= 0){ + return BaseResponseUtils.buildFail("id涓嶈兘涓虹┖") ; + } + + List<Map<String, Object>> map_Districts = Optional.ofNullable(sv.getDistrictgsByLevel(id)).orElse(new ArrayList<>()); + if(map_Districts == null || map_Districts.size() == 0) { + return BaseResponseUtils.buildFail("鎮ㄨ緭鍏ョ殑灞傜骇鏈夎") ; + } + return BaseResponseUtils.buildSuccess(map_Districts); + } + + /** + * 鏍规嵁鐖禝D鑾峰彇琛屾斂鍖哄垝鍒楄〃 + * @param supperId + * @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 = "/supperid/{supperId}") + @SsoAop() + public BaseResponse<QueryResultVo<List<Map<String, Object>>>> getDistrictsBySupperId(@PathVariable("supperId") Long supperId){ + if(supperId == null || supperId <= 0){ + return BaseResponseUtils.buildFail("鐖禝D涓嶈兘涓虹┖") ; + } + + List<Map<String, Object>> map_Districts = Optional.ofNullable(sv.getDistrictsBySupperId(supperId)).orElse(new ArrayList<>()); + if(map_Districts == null || map_Districts.size() == 0) { + return BaseResponseUtils.buildFail("鎮ㄨ緭鍏ョ殑鐖剁骇ID鏈夎") ; + } + return BaseResponseUtils.buildSuccess(map_Districts); + } + + /** + * 鑾峰彇涓夌骇琛屾斂鍖哄垝 + * @return 鍘块晣鏉戜笁绾ц鏀垮尯鍒� + */ + @GetMapping(path = "/three") + @SsoAop() + public BaseResponse<QueryResultVo<List<Map<String, Object>>>> getThreeDistrict() { + JSONArray array_counties = new JSONArray(); + JSONArray array_towns = new JSONArray(); + JSONArray array_villages = new JSONArray(); + + List<Map<String, Object>> list_counties = Optional.ofNullable(sv.getDistrictgsByLevel(2)).orElse(new ArrayList<>()); + if(list_counties.size() > 0) { + array_counties = JSONArray.parseArray(JSON.toJSONString(list_counties)); + // 閬嶅巻姣忎竴涓幙锛屽皢鍘夸笅鐨勯晣鏉戝姞鍒板幙鐨勫瓙闆� + for(int i = 0; i < array_counties.size(); i++) { + JSONObject job_county = array_counties.getJSONObject(i); + Long countyId = job_county.getLong("id"); + List<Map<String, Object>> list_towns = Optional.ofNullable(sv.getDistrictsBySupperId(countyId)).orElse(new ArrayList<>()); + if(list_towns.size() > 0) { + array_towns = JSONArray.parseArray(JSON.toJSONString(list_towns)); + // 閬嶅巻姣忎竴涓晣锛屽皢闀囦笅鏉戝垪琛ㄥ姞鍒伴晣鐨勫瓙闆� + for(int j = 0; j < array_towns.size(); j++) { + JSONObject job_town = array_towns.getJSONObject(j); + Long townId = job_town.getLong("id"); + List<Map<String, Object>> list_villages = Optional.ofNullable(sv.getDistrictsBySupperId(townId)).orElse(new ArrayList<>()); + if(list_villages.size() > 0) { + array_villages = JSONArray.parseArray(JSON.toJSONString(list_villages)); + job_town.put("children", array_villages); + } + } + //System.out.println("----" + array_towns); + } + // 闀囨潙缁勮瀹屾瘯锛屽皢闀囨潙鍔犲埌鍘夸笅 + job_county.put("children", array_towns); + } + // 鍘跨粍瑁呭畬姣� + //String a = array_counties.toJSONString(); + //System.out.println(a); + return BaseResponseUtils.buildSuccess(array_counties); + }else { + return BaseResponseUtils.buildFail("鍘跨骇琛屾斂鍖哄垝涓嶅瓨鍦�"); + } + + + //return BaseResponseUtils.buildSuccess(); + } } -- Gitblit v1.8.0