| | |
| | | import com.ycl.platform.mapper.PlatformMapper; |
| | | import com.ycl.platform.service.PlatformService; |
| | | import com.ycl.system.Result; |
| | | import com.ycl.system.entity.SysDictData; |
| | | import com.ycl.system.page.PageUtil; |
| | | import com.ycl.system.service.ISysDictTypeService; |
| | | import com.ycl.system.service.impl.SysDictDataServiceImpl; |
| | | import com.ycl.system.service.impl.SysDictTypeServiceImpl; |
| | | import org.ehcache.core.util.CollectionUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, Platform> implements PlatformService { |
| | | |
| | | private final PlatformMapper platformMapper; |
| | | private final SysDictDataServiceImpl dictDataService; |
| | | private final ISysDictTypeService dictTypeService; |
| | | |
| | | /** |
| | | * 添加 |
| | |
| | | Date now = new Date(); |
| | | entity.setCreateTime(now); |
| | | entity.setUpdateTime(now); |
| | | String area = form.getAreaList().stream().collect(Collectors.joining(",")); |
| | | entity.setArea(area); |
| | | baseMapper.insert(entity); |
| | | if (! CollectionUtils.isEmpty(form.getDeployList())) { |
| | | List<Platform> childList = form.getDeployList().stream().map(deploy -> { |
| | | Platform child = new Platform(); |
| | | BeanUtils.copyProperties(deploy, child); |
| | | child.setPlatformName(entity.getPlatformName()); |
| | | child.setParentId(entity.getId()); |
| | | child.setCreateTime(now); |
| | | child.setUpdateTime(now); |
| | | return child; |
| | | }).collect(Collectors.toList()); |
| | | this.saveBatch(childList); |
| | | } |
| | | // if (! CollectionUtils.isEmpty(form.getDeployList())) { |
| | | // List<Platform> childList = form.getDeployList().stream().map(deploy -> { |
| | | // Platform child = new Platform(); |
| | | // BeanUtils.copyProperties(deploy, child); |
| | | // child.setPlatformName(entity.getPlatformName()); |
| | | // child.setParentId(entity.getId()); |
| | | // child.setCreateTime(now); |
| | | // child.setUpdateTime(now); |
| | | // return child; |
| | | // }).collect(Collectors.toList()); |
| | | // this.saveBatch(childList); |
| | | // } |
| | | return Result.ok("添加成功"); |
| | | } |
| | | |
| | |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | String area = form.getAreaList().stream().collect(Collectors.joining(",")); |
| | | entity.setArea(area); |
| | | baseMapper.updateById(entity); |
| | | return Result.ok("修改成功"); |
| | | } |
| | |
| | | @Override |
| | | public Result page(PlatformQuery query) { |
| | | List<PlatformVO> list = baseMapper.getPage(query); |
| | | List<PlatformVO> parentList = list.stream().filter(item -> item.getParentId() == 0).collect(Collectors.toList()); |
| | | List<PlatformVO> resultList = new ArrayList<>(4); |
| | | for (PlatformVO parent : parentList) { |
| | | List<PlatformVO> childList = list.stream().filter(item -> item.getParentId().equals(parent.getId())).collect(Collectors.toList()); |
| | | |
| | | parent.setChildNum(childList.size()); |
| | | resultList.add(parent); |
| | | resultList.addAll(childList); |
| | | // List<PlatformVO> parentList = list.stream().filter(item -> item.getParentId() == 0).collect(Collectors.toList()); |
| | | List<SysDictData> areaCodeList = dictTypeService.selectDictDataByType("area_code"); |
| | | Map<String, String> dictMap = areaCodeList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel)); |
| | | for (PlatformVO platform : list) { |
| | | String[] areaList = platform.getArea().split(","); |
| | | List<String> areas = new ArrayList<>(); |
| | | for (String s : areaList) { |
| | | String label = dictMap.get(s); |
| | | if (StringUtils.hasText(label)) { |
| | | areas.add(label); |
| | | } |
| | | } |
| | | platform.setAreaList(areaList); |
| | | platform.setArea(areas.stream().collect(Collectors.joining("、"))); |
| | | // List<PlatformVO> childList = list.stream().filter(item -> item.getParentId().equals(parent.getId())).collect(Collectors.toList()); |
| | | // |
| | | // parent.setChildNum(childList.size()); |
| | | // resultList.add(parent); |
| | | // resultList.addAll(childList); |
| | | } |
| | | // 前端不用展示分页 |
| | | return Result.ok().data(resultList).total(0); |
| | | return Result.ok().data(list).total(0); |
| | | } |
| | | |
| | | /** |