package com.panzhihua.service_community.api; import cn.hutool.core.util.ArrayUtil; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.dtos.property.CommonPage; import com.panzhihua.service_community.dao.ComAreaTownCommunityDao; import com.panzhihua.common.model.vos.community.acid.ComAreaCounty; import com.panzhihua.service_community.entity.ComAreaTownCommunity; import com.panzhihua.service_community.service.ComAreaTownCommunityService; import org.apache.commons.lang3.ArrayUtils; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * (ComAreaTownCommunity)表控制层 * projectName 成都呐喊信息技术有限公司-智慧社区项目 * description: 相关功能 * * @author zzj * @since 2022-04-10 17:37:33 */ @RestController @RequestMapping("comAreaTownCommunity") public class ComAreaTownCommunityApi { /** * 服务对象 */ @Resource private ComAreaTownCommunityService comAreaTownCommunityService; @Resource private ComAreaTownCommunityDao comAreaTownCommunityDao; /** * 分页查询所有数据 * * @param commonPage 查询实体 * @return 所有数据 */ @PostMapping("queryAll") public R selectAll(@RequestBody CommonPage commonPage) { return this.comAreaTownCommunityService.pageList(commonPage); } /** * 通过主键查询单条数据 * * @param id 主键 * @return 单条数据 */ @GetMapping("{id}") public R selectOne(@PathVariable("id") Serializable id) { return R.ok(this.comAreaTownCommunityService.getById(id)); } /** * 新增数据 * * @param comAreaTownCommunity 实体对象 * @return 新增结果 */ @PostMapping public R insert(@RequestBody ComAreaTownCommunity comAreaTownCommunity) { return R.ok(this.comAreaTownCommunityService.save(comAreaTownCommunity)); } /** * 修改数据 * * @param comAreaTownCommunity 实体对象 * @return 修改结果 */ @PostMapping("/update") public R update(@RequestBody ComAreaTownCommunity comAreaTownCommunity) { return R.ok(this.comAreaTownCommunityService.updateById(comAreaTownCommunity)); } /** * 删除数据 * * @param id 主键结合 * @return 删除结果 */ @GetMapping("del") public R delete(@RequestParam("id") Long id) { return R.ok(this.comAreaTownCommunityService.removeById(id)); } @GetMapping("/areaTownCommunity") public R test(@RequestParam("name")String name,@RequestParam("userId")Long userId){ Long[] idArray={4L,17959L,16522L,16196L,16214L,17949L,89234L}; if("panzhihua".equals(name)){ List list=comAreaTownCommunityDao.selectArea(); list.forEach(lis->{ List townList=comAreaTownCommunityDao.selectTown(lis.getValue()); townList.forEach(tow->{ List list1=new ArrayList<>(); if(ArrayUtil.contains(idArray,userId)){ list1=comAreaTownCommunityDao.selectCommunity(tow.getValue(),"学园社区"); } else { list1=comAreaTownCommunityDao.selectCommunity(tow.getValue(),""); } if("大渡口街道".equals(tow.getValue())){ ComAreaCounty comAreaCounty=list1.get(0); list1.remove(0); list1.add(2,comAreaCounty); } tow.setChildren(list1); }); lis.setChildren(townList); }); return R.ok(list); } else { List townList=comAreaTownCommunityDao.selectTown(name); if(!CollectionUtils.isEmpty(townList)){ townList.forEach(tow->{ List list1=new ArrayList<>(); if(ArrayUtil.contains(idArray,userId)){ list1=comAreaTownCommunityDao.selectCommunity(tow.getValue(),"学园社区"); } else { list1=comAreaTownCommunityDao.selectCommunity(tow.getValue(),""); } tow.setChildren(list1); }); return R.ok(townList); } else { List list1=new ArrayList<>(); if(ArrayUtil.contains(idArray,userId)){ list1=comAreaTownCommunityDao.selectCommunity(name,"学园社区"); } else { list1=comAreaTownCommunityDao.selectCommunity(name,""); } return R.ok(list1); } } } }