| | |
| | | import com.ycl.platform.base.BaseSelect; |
| | | import com.ycl.platform.domain.entity.Region; |
| | | import com.ycl.platform.domain.entity.YwUnit; |
| | | import com.ycl.platform.domain.vo.RegionCascaderVO; |
| | | import com.ycl.platform.mapper.RegionMapper; |
| | | import com.ycl.platform.service.RegionService; |
| | | import com.ycl.system.Result; |
| | |
| | | import com.ycl.platform.domain.form.RegionForm; |
| | | import com.ycl.platform.domain.vo.RegionVO; |
| | | import com.ycl.platform.domain.query.RegionQuery; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import com.ycl.utils.DateUtils; |
| | |
| | | public Result add(RegionForm form) { |
| | | Region entity = RegionForm.getEntityByForm(form, null); |
| | | entity.setRegionLevel(RegionLevelEnum.STREET); |
| | | Date now = new Date(); |
| | | entity.setCreateTime(now); |
| | | entity.setUpdateTime(now); |
| | | if(baseMapper.insert(entity) > 0) { |
| | | return Result.ok("添加成功"); |
| | | } |
| | |
| | | public Result update(RegionForm form) { |
| | | |
| | | Region entity = baseMapper.selectById(form.getId()); |
| | | |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | Date now = new Date(); |
| | | entity.setUpdateTime(now); |
| | | if (baseMapper.updateById(entity) > 0) { |
| | | return Result.ok("修改成功"); |
| | | } |
| | |
| | | }).collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | } |
| | | |
| | | @Override |
| | | public Result cascader() { |
| | | List<Region> regionList = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .ne(Region::getRegionLevel, RegionLevelEnum.CITY) |
| | | .list(); |
| | | List<RegionCascaderVO> vos = regionList.stream().map(entity -> { |
| | | RegionCascaderVO vo = new RegionCascaderVO(); |
| | | vo.setValue(entity.getId()); |
| | | vo.setLabel(entity.getSimpleName()); |
| | | vo.setRegionLevel(entity.getRegionLevel()); |
| | | vo.setParentId(entity.getParentId()); |
| | | return vo; |
| | | }).collect(Collectors.toList()); |
| | | List<RegionCascaderVO> removeList = new ArrayList<>(12); |
| | | for (RegionCascaderVO region : vos) { |
| | | if (region.getRegionLevel() == RegionLevelEnum.COUNTY) { |
| | | List<RegionCascaderVO> childList = new ArrayList<>(12); |
| | | for (RegionCascaderVO region1 : vos) { |
| | | if (region1.getParentId() == region.getValue()) { |
| | | childList.add(region1); |
| | | removeList.add(region1); |
| | | } |
| | | } |
| | | region.setChildren(childList); |
| | | } |
| | | } |
| | | vos.removeAll(removeList); |
| | | return Result.ok().data(vos); |
| | | } |
| | | } |