Commit eda1c5ab by 杨伟程

几个天从path的地方

parent 8ee6f7cb
package com.makeit.utils.data.convert;
import com.makeit.enums.id.TreeConst;
import com.makeit.utils.old.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
......@@ -85,4 +84,21 @@ public class TreeUtil {
}
}
public static String path(String path, List<String> idList) {
// if(StringUtils.isBlank(path)){
// return path;
// }
LinkedHashSet<String> list = new LinkedHashSet<>();
if (StringUtils.isNotBlank(path)) {
list = new LinkedHashSet<>(Arrays.asList(path.split(",")));
}
list.addAll(idList);
return StreamUtil.join(new ArrayList<>(list), Function.identity());
}
}
......@@ -33,7 +33,6 @@ public class PlatUserVO implements Serializable {
private String orgPath;
public PlatUserVO() {
}
......@@ -49,27 +48,25 @@ public class PlatUserVO implements Serializable {
}
private boolean initFlag = false;
public void init(){
if(initFlag){
public void init() {
if (initFlag) {
return;
}
if(StringUtils.isBlank(orgPath)){
if (StringUtils.isBlank(orgPath)) {
return;
}
List<BiConsumer<PlatUserVO,String>> list = Arrays.asList(
List<BiConsumer<PlatUserVO, String>> list = Arrays.asList(
PlatUserVO::setCityOrgId,
PlatUserVO::setDistrictOrgId,
PlatUserVO::setStreetOrgId
);
String[] split = orgPath.split(",");
for (int i = 1; i < split.length; i++) {
BiConsumer<PlatUserVO, String> e = list.get(i-1);
e.accept(this,split[i]);
BiConsumer<PlatUserVO, String> e = list.get(i - 1);
e.accept(this, split[i]);
}
this.initFlag = true;
}
......
package com.makeit.dto.platform.space;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class PlatSpaceSplitDTO {
@ApiModelProperty(value = "空间id")
private String spaceId;
@ApiModelProperty(value = "小区/社区/街道空间id")
private String streetSpaceId;
@ApiModelProperty(value = "楼栋空间id")
private String buildingSpaceId;
@ApiModelProperty(value = "单元空间id")
private String unitSpaceId;
@ApiModelProperty(value = "楼层id")
private String floorSpaceId;
@ApiModelProperty(value = "房间id")
private String roomId;
@ApiModelProperty(value = "床位id")
private String bedId;
@ApiModelProperty(value = "空间-房间-床位路径")
private String spacePath;
}
......@@ -14,6 +14,7 @@ import com.makeit.dto.platform.elder.PlatElderCheckOutDTO;
import com.makeit.dto.platform.elder.PlatElderImportDTO;
import com.makeit.dto.platform.elder.PlatElderQueryDTO;
import com.makeit.dto.platform.elder.add.*;
import com.makeit.dto.platform.space.PlatSpaceSplitDTO;
import com.makeit.dto.platform.space.TreeDTOVO;
import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.device.PlatDevice;
......@@ -29,7 +30,6 @@ import com.makeit.enums.CommonEnum;
import com.makeit.enums.FileSuffixEnum;
import com.makeit.enums.id.TreeConst;
import com.makeit.exception.BusinessException;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.mapper.platform.elder.PlatElderMapper;
import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.elder.*;
......@@ -457,6 +457,20 @@ public class PlatElderServiceImpl extends ServiceImpl<PlatElderMapper, PlatElder
if (errorVoList.isEmpty()) {
List<PlatElder> platElderList = BeanDtoVoUtils.listVo(list, PlatElder.class);
platElderList.forEach(e -> {
List<String> spaceIdList = new ArrayList<>(Arrays.asList(e.getStreetSpaceId(), e.getBuildingSpaceId(), e.getUnitSpaceId(), e.getFloorSpaceId()));
List<String> newSpaceIdList = new ArrayList<>(spaceIdList);
Collections.reverse(newSpaceIdList);
e.setSpaceId(newSpaceIdList.stream().filter(StringUtils::isNotBlank).findFirst().orElse(null));
spaceIdList.add(e.getRoomId());
spaceIdList.add(e.getBedId());
e.setSpacePath(spaceIdList.stream().filter(StringUtils::isNotBlank).collect(Collectors.joining(",")));
});
PlatUserVO platUserVO = PlatUserUtil.getUserVO();
platElderList.forEach(e -> {
......@@ -492,6 +506,25 @@ public class PlatElderServiceImpl extends ServiceImpl<PlatElderMapper, PlatElder
}
private void fillSpace(PlatElder platElder) {
if (StringUtils.isBlank(platElder.getBedId())) {
return;
}
PlatSpaceSplitDTO platSpaceSplitDTO = platSpaceService.getSpaceSplitVO(platElder.getBedId());
platElder.setSpaceId(platSpaceSplitDTO.getSpaceId());
platElder.setStreetSpaceId(platSpaceSplitDTO.getStreetSpaceId());
platElder.setBuildingSpaceId(platSpaceSplitDTO.getBuildingSpaceId());
platElder.setUnitSpaceId(platSpaceSplitDTO.getUnitSpaceId());
platElder.setFloorSpaceId(platSpaceSplitDTO.getFloorSpaceId());
platElder.setRoomId(platSpaceSplitDTO.getRoomId());
//platElder.setBedId();
platElder.setSpacePath(platSpaceSplitDTO.getSpacePath());
}
@Override
@Transactional
public void add(PlatElderAddDTO dto) {
......@@ -500,6 +533,8 @@ public class PlatElderServiceImpl extends ServiceImpl<PlatElderMapper, PlatElder
PlatElder platElder = BeanDtoVoUtils.convert(dto, PlatElder.class);
fillSpace(platElder);
PlatUserVO userVO = PlatUserUtil.getUserVO();
platElder.setOrgId(userVO.getOrgId());
......@@ -523,6 +558,8 @@ public class PlatElderServiceImpl extends ServiceImpl<PlatElderMapper, PlatElder
PlatElder platElder = BeanDtoVoUtils.convert(dto, PlatElder.class);
fillSpace(platElder);
PlatUserVO userVO = PlatUserUtil.getUserVO();
platElder.setOrgId(userVO.getOrgId());
......@@ -602,6 +639,8 @@ public class PlatElderServiceImpl extends ServiceImpl<PlatElderMapper, PlatElder
PlatElder platElder = BeanDtoVoUtils.convert(dto, PlatElder.class);
fillSpace(platElder);
updateById(platElder);
addOrEditExt(dto);
......
......@@ -5,6 +5,7 @@ import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.vo.ExcelImportVo;
import com.makeit.dto.platform.space.PlatSpaceAddDTO;
import com.makeit.dto.platform.space.PlatSpaceQueryDTO;
import com.makeit.dto.platform.space.PlatSpaceSplitDTO;
import com.makeit.dto.platform.space.PlatSpaceVO;
import com.makeit.entity.platform.space.PlatSpace;
import com.makeit.vo.platform.space.PlatSpaceAndRoomVO;
......@@ -61,6 +62,8 @@ public interface PlatSpaceService extends IService<PlatSpace> {
*/
List<PlatSpaceVO> treeByBed(PlatSpaceQueryDTO dto);
PlatSpaceSplitDTO getSpaceSplitVO(String bedId);
List<PlatSpace> listChild(List<String> spaceIds);
List<PlatSpaceAddDTO> oneLevelList(BaseIdDTO dto);
......
......@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.vo.ExcelErrorVo;
import com.makeit.common.vo.ExcelImportVo;
import com.makeit.dto.platform.auth.PlatOrgSplitDTO;
import com.makeit.dto.platform.space.*;
import com.makeit.entity.platform.auth.PlatOrg;
import com.makeit.entity.platform.space.PlatBed;
......@@ -21,7 +22,9 @@ import com.makeit.service.platform.space.PlatBedService;
import com.makeit.service.platform.space.PlatRoomService;
import com.makeit.service.platform.space.PlatSpaceService;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.convert.TreeUtil;
import com.makeit.utils.data.excel.ExcelUtil;
import com.makeit.utils.old.StringUtils;
import com.makeit.utils.user.TokenUtil;
import com.makeit.utils.user.plat.PlatUserUtil;
import com.makeit.utils.user.plat.PlatUserVO;
......@@ -32,10 +35,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
/**
......@@ -53,18 +54,18 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
@Autowired
private PlatOrgService platOrgService;
private void check(PlatSpaceAddDTO dto){
private void check(PlatSpaceAddDTO dto) {
LambdaQueryWrapper<PlatSpace> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PlatSpace::getName,dto.getName());
queryWrapper.ne(StringUtil.isNotEmpty(dto.getId()), PlatSpace::getId,dto.getId());
queryWrapper.eq(PlatSpace::getName, dto.getName());
queryWrapper.ne(StringUtil.isNotEmpty(dto.getId()), PlatSpace::getId, dto.getId());
if(StringUtil.isEmpty(dto.getParentId())){
if (StringUtil.isEmpty(dto.getParentId())) {
queryWrapper.isNull(PlatSpace::getParentId);
}else{
queryWrapper.eq(PlatSpace::getParentId,dto.getParentId());
} else {
queryWrapper.eq(PlatSpace::getParentId, dto.getParentId());
}
if(this.count(queryWrapper) > 0){
if (this.count(queryWrapper) > 0) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_NAME_DUPLICATE);
}
}
......@@ -75,17 +76,17 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
public void add(PlatSpaceAddDTO dto) {
check(dto);
PlatSpace space = BeanDtoVoUtils.convert(dto, PlatSpace.class);
if(StringUtil.isEmpty(dto.getParentId())){
if (StringUtil.isEmpty(dto.getParentId())) {
PlatUserVO userVO = PlatUserUtil.getUserVOCanNull();
if(StringUtil.isEmpty(userVO.getOrgId())){
if (StringUtil.isEmpty(userVO.getOrgId())) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_USER_NOT_ADD);
}
space.setOrgId(userVO.getOrgId());
PlatOrg org = platOrgService.getById(space.getOrgId());
if(org!=null){
if (org != null) {
space.setAttribute(org.getType());
}
}else {
} else {
//上级空间
PlatSpace parentSpace = getById(dto.getParentId());
space.setOrgId(parentSpace.getOrgId());
......@@ -111,7 +112,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
//上级空间
PlatSpace parentSpace = this.getById(dto.getParentId());
if(parentSpace.getParentPath().contains(dto.getId())){
if (parentSpace.getParentPath().contains(dto.getId())) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_NOT_DEL);
}
......@@ -123,14 +124,14 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
public void del(String id) {
LambdaQueryWrapper<PlatSpace> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PlatSpace::getParentId,id);
if(count(queryWrapper) > 0){
queryWrapper.eq(PlatSpace::getParentId, id);
if (count(queryWrapper) > 0) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_NOT_DEL);
}
LambdaQueryWrapper<PlatRoom> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(PlatRoom::getSpaceId,id);
if(platRoomService.count(queryWrapper1) > 0){
queryWrapper1.eq(PlatRoom::getSpaceId, id);
if (platRoomService.count(queryWrapper1) > 0) {
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_NOT_DEL);
}
......@@ -141,26 +142,26 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
public List<PlatSpaceVO> tree(PlatSpaceQueryDTO dto) {
//查询用户权限组织id
List<PlatOrg> orgs = platOrgService.belongToScopeList(new PlatOrg());
if(orgs.isEmpty()){
if (orgs.isEmpty()) {
return new ArrayList<>();
}
List<String> orgIds = orgs.stream().map(PlatOrg::getId).collect(Collectors.toList());
LambdaQueryWrapper<PlatSpace> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(StringUtil.isNotEmpty(dto.getName()),PlatSpace::getName,dto.getName());
queryWrapper.like(StringUtil.isNotEmpty(dto.getName()), PlatSpace::getName, dto.getName());
queryWrapper.in(PlatSpace::getOrgId, orgIds);
List<PlatSpace> list = this.list(queryWrapper);
//父级
List<PlatSpace> listParent = list.stream().filter(item->StringUtil.isEmpty(item.getParentId())).collect(Collectors.toList());
List<PlatSpace> listParent = list.stream().filter(item -> StringUtil.isEmpty(item.getParentId())).collect(Collectors.toList());
//子集
List<PlatSpace> listChild = list.stream().filter(item->item.getParentId() != null).collect(Collectors.toList());
Map<String,List<PlatSpace>> map = listChild.stream().collect(Collectors.groupingBy(PlatSpace::getParentId));
List<PlatSpace> listChild = list.stream().filter(item -> item.getParentId() != null).collect(Collectors.toList());
Map<String, List<PlatSpace>> map = listChild.stream().collect(Collectors.groupingBy(PlatSpace::getParentId));
List<PlatSpaceVO> data = new ArrayList<>();
for(PlatSpace space:listParent){
for (PlatSpace space : listParent) {
PlatSpaceVO vo = convertToVO(space);
vo = child(vo,map);
vo = child(vo, map);
data.add(vo);
}
return data;
......@@ -169,7 +170,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
@Override
public PlatSpaceAddDTO view(String id) {
PlatSpace space = getById(id);
PlatSpaceAddDTO data = BeanDtoVoUtils.convert(space,PlatSpaceAddDTO.class);
PlatSpaceAddDTO data = BeanDtoVoUtils.convert(space, PlatSpaceAddDTO.class);
return data;
}
......@@ -190,10 +191,10 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
LambdaQueryWrapper<PlatBed> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(PlatBed::getStatus, CommonEnum.YES.getValue());
List<PlatBed> listBeds = platBedService.list(queryWrapper1);
Map<String,List<PlatBed>> mapBed = listBeds.stream().collect(Collectors.groupingBy(PlatBed::getRoomId));
Map<String, List<PlatBed>> mapBed = listBeds.stream().collect(Collectors.groupingBy(PlatBed::getRoomId));
List<PlatSpaceVO> listRoomVo = new ArrayList<>();
listRoom.forEach(item->{
listRoom.forEach(item -> {
PlatSpaceVO vo = new PlatSpaceVO();
vo.setId(item.getId());
vo.setName(item.getName());
......@@ -201,7 +202,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
listRoomVo.add(vo);
});
listBeds.forEach(item->{
listBeds.forEach(item -> {
PlatSpaceVO vo = new PlatSpaceVO();
vo.setId(item.getId());
vo.setName(item.getName());
......@@ -210,25 +211,25 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
});
LambdaQueryWrapper<PlatSpace> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(StringUtil.isNotEmpty(dto.getName()),PlatSpace::getName,dto.getName());
queryWrapper.eq(StringUtil.isNotEmpty(userVO.getOrgId()),PlatSpace::getOrgId,userVO.getOrgId());
queryWrapper.like(StringUtil.isNotEmpty(dto.getName()), PlatSpace::getName, dto.getName());
queryWrapper.eq(StringUtil.isNotEmpty(userVO.getOrgId()), PlatSpace::getOrgId, userVO.getOrgId());
List<PlatSpace> list = this.list(queryWrapper);
List<PlatSpaceVO> listSpaceVo = BeanDtoVoUtils.listVo(list,PlatSpaceVO.class);
List<PlatSpaceVO> listSpaceVo = BeanDtoVoUtils.listVo(list, PlatSpaceVO.class);
listSpaceVo.addAll(listRoomVo);
//父级
List<PlatSpaceVO> listParent = listSpaceVo.stream().filter(item->StringUtil.isEmpty(item.getParentId())).
List<PlatSpaceVO> listParent = listSpaceVo.stream().filter(item -> StringUtil.isEmpty(item.getParentId())).
collect(Collectors.toList());
//子集
List<PlatSpaceVO> listChild = listSpaceVo.stream().filter(item->item.getParentId() != null).collect(Collectors.toList());
Map<String,List<PlatSpaceVO>> map = listChild.stream().collect(Collectors.groupingBy(PlatSpaceVO::getParentId));
List<PlatSpaceVO> listChild = listSpaceVo.stream().filter(item -> item.getParentId() != null).collect(Collectors.toList());
Map<String, List<PlatSpaceVO>> map = listChild.stream().collect(Collectors.groupingBy(PlatSpaceVO::getParentId));
List<PlatSpaceVO> data = new ArrayList<>();
for(PlatSpaceVO space:listParent){
for (PlatSpaceVO space : listParent) {
space = childVo(space,map);
space = childVo(space, map);
data.add(space);
}
return data;
......@@ -236,6 +237,39 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
}
@Override
public PlatSpaceSplitDTO getSpaceSplitVO(String bedId) {
PlatBed platBed = platBedService.getById(bedId);
PlatRoom platRoom = platRoomService.getById(platBed.getRoomId());
PlatSpace platSpace = getById(platRoom.getSpaceId());
PlatSpaceSplitDTO platSpaceSplitDTO = new PlatSpaceSplitDTO();
platSpaceSplitDTO.setSpaceId(platSpace.getId());
List<BiConsumer<PlatSpaceSplitDTO, String>> list = Arrays.asList(
PlatSpaceSplitDTO::setStreetSpaceId,
PlatSpaceSplitDTO::setBuildingSpaceId,
PlatSpaceSplitDTO::setUnitSpaceId,
PlatSpaceSplitDTO::setFloorSpaceId
);
String[] split = TreeUtil.path(platSpace.getParentPath(), Arrays.asList(platSpace.getId())).split(",");
for (int i = 0; i < split.length; i++) {
BiConsumer<PlatSpaceSplitDTO, String> e = list.get(i);
e.accept(platSpaceSplitDTO, split[i]);
}
platSpaceSplitDTO.setRoomId(platRoom.getId());
platSpaceSplitDTO.setBedId(platBed.getId());
platSpaceSplitDTO.setSpacePath(TreeUtil.path(platSpace.getParentPath(), Arrays.asList(
platSpace.getId(),
platRoom.getId(),
platBed.getId()
)));
return platSpaceSplitDTO;
}
@Override
public List<PlatSpace> listChild(List<String> spaceIds) {
return baseMapper.listChild(spaceIds);
......@@ -250,7 +284,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
return BeanDtoVoUtils.listVo(spaces, PlatSpaceAddDTO.class);
}
private PlatSpaceVO childVo(PlatSpaceVO vo,Map<String,List<PlatSpaceVO>> map) {
private PlatSpaceVO childVo(PlatSpaceVO vo, Map<String, List<PlatSpaceVO>> map) {
if (!map.containsKey(vo.getId())) {
return vo;
......@@ -268,17 +302,17 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
@Override
public PlatSpaceVO child(PlatSpaceVO vo,Map<String,List<PlatSpace>> map){
public PlatSpaceVO child(PlatSpaceVO vo, Map<String, List<PlatSpace>> map) {
if(!map.containsKey(vo.getId())){
if (!map.containsKey(vo.getId())) {
return vo;
}
List<PlatSpace> list = map.get(vo.getId());
List<PlatSpaceVO> listChild = new ArrayList<>();
for(PlatSpace item:list){
for (PlatSpace item : list) {
PlatSpaceVO dto = convertToVO(item);
this.child(dto,map);
this.child(dto, map);
listChild.add(dto);
}
vo.setChildren(listChild);
......@@ -286,7 +320,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
}
@Override
public PlatSpaceVO convertToVO(PlatSpace space){
public PlatSpaceVO convertToVO(PlatSpace space) {
PlatSpaceVO vo = new PlatSpaceVO();
vo.setName(space.getName());
......@@ -305,18 +339,18 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
try {
List<PlatSpace> listPlatSpace = list(new LambdaQueryWrapper<>());
List<PlatSpace> firstSpace = listPlatSpace.stream().filter(item->item.getParentId() == null).collect(Collectors.toList());
Map<String,String> firstSpaceNameMap = firstSpace.stream().collect(Collectors.toMap(PlatSpace::getName,PlatSpace::getId,(k1,k2)->k1));
List<PlatSpace> firstSpace = listPlatSpace.stream().filter(item -> item.getParentId() == null).collect(Collectors.toList());
Map<String, String> firstSpaceNameMap = firstSpace.stream().collect(Collectors.toMap(PlatSpace::getName, PlatSpace::getId, (k1, k2) -> k1));
List<PlatSpace> listChildren = listPlatSpace.stream().filter(item->item.getParentId() != null).collect(Collectors.toList());
Map<String,List<PlatSpace>> childrenMap = listChildren.stream().collect(Collectors.groupingBy(PlatSpace::getParentId));
Map<String,String> childrenIdMap = listChildren.stream().collect(Collectors.toMap(item->item.getParentId()+item.getName(),item->item.getId(),(k1,k2)->k1));
List<PlatSpace> listChildren = listPlatSpace.stream().filter(item -> item.getParentId() != null).collect(Collectors.toList());
Map<String, List<PlatSpace>> childrenMap = listChildren.stream().collect(Collectors.groupingBy(PlatSpace::getParentId));
Map<String, String> childrenIdMap = listChildren.stream().collect(Collectors.toMap(item -> item.getParentId() + item.getName(), item -> item.getId(), (k1, k2) -> k1));
List<PlatSpaceImportDTO> list = ExcelUtil.importExcel(null,3,excelFile,PlatSpaceImportDTO.class);
List<PlatSpaceImportDTO> list = ExcelUtil.importExcel(null, 3, excelFile, PlatSpaceImportDTO.class);
List<ExcelErrorVo> errorVoList = new ArrayList<>(10);
List<String> excelField = Arrays.asList("一级*","二级","三级","四级","房间名*","床位数量");
List<String> excelField = Arrays.asList("一级*", "二级", "三级", "四级", "房间名*", "床位数量");
int startRow = 3;
......@@ -331,75 +365,75 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
Integer errorCount = 0;
Integer successCount = 0;
boolean errorFlag = false;
for(int i=0;i<list.size();i++){
for (int i = 0; i < list.size(); i++) {
PlatSpaceImportDTO item = list.get(i);
if(StringUtil.isEmpty(item.getCommunity())){
errorVoList.add(new ExcelErrorVo(i+3,excelField.get(0),"第一层级必填"));
if (StringUtil.isEmpty(item.getCommunity())) {
errorVoList.add(new ExcelErrorVo(i + 3, excelField.get(0), "第一层级必填"));
errorFlag = true;
}
if(StringUtil.isEmpty(item.getFloor())){
errorVoList.add(new ExcelErrorVo(i+3,excelField.get(4),"房间名必填"));
if (StringUtil.isEmpty(item.getFloor())) {
errorVoList.add(new ExcelErrorVo(i + 3, excelField.get(4), "房间名必填"));
errorFlag = true;
}
String key = item.getCommunity();
//第二层级
if(StringUtil.isNotEmpty(item.getBuilding())){
if (StringUtil.isNotEmpty(item.getBuilding())) {
key = key + "-" + item.getBuilding();
}
//第三层级
if(StringUtil.isNotEmpty(item.getUnit())){
if (StringUtil.isNotEmpty(item.getUnit())) {
key = key + "-" + item.getUnit();
}
//第四层级
if(StringUtil.isNotEmpty(item.getFloor())){
if (StringUtil.isNotEmpty(item.getFloor())) {
key = key + "-" + item.getFloor();
}
if(listKey.contains(key)){
errorVoList.add(new ExcelErrorVo(i+3,excelField.get(0),"该空间下,房间名已存在"));
if (listKey.contains(key)) {
errorVoList.add(new ExcelErrorVo(i + 3, excelField.get(0), "该空间下,房间名已存在"));
errorFlag = true;
}
if(errorFlag){
if (errorFlag) {
errorCount++;
}else{
} else {
successCount++;
}
}
String orgId = TokenUtil.getTntUserDetail().getOrgId();
if(errorVoList.isEmpty()){
if (errorVoList.isEmpty()) {
for(int i=0;i<list.size();i++){
for (int i = 0; i < list.size(); i++) {
PlatSpaceImportDTO item = list.get(i);
//第一层级
String firstId = null;
if(!firstSpaceNameMap.containsKey(item.getCommunity())){
if (!firstSpaceNameMap.containsKey(item.getCommunity())) {
PlatSpace platSpace = new PlatSpace();
platSpace.setName(item.getCommunity());
platSpace.setType(PlatSpaceEnum.TypeEnum.COMMUNITY.getValue());
platSpace.setOrgId(orgId);
save(platSpace);
firstSpaceNameMap.put(platSpace.getName(),platSpace.getId());
firstSpaceNameMap.put(platSpace.getName(), platSpace.getId());
firstId = platSpace.getId();
}else{
} else {
firstId = firstSpaceNameMap.get(item.getCommunity());
}
//第二层级
String secondId = null;
if(StringUtil.isNotEmpty(item.getBuilding())){
if (StringUtil.isNotEmpty(item.getBuilding())) {
String secondKey = firstId + "-" + item.getBuilding();
if(!childrenIdMap.containsKey(secondKey)){
if (!childrenIdMap.containsKey(secondKey)) {
PlatSpace platSpace = new PlatSpace();
platSpace.setName(item.getBuilding());
platSpace.setType(PlatSpaceEnum.TypeEnum.BUILDING.getValue());
......@@ -407,49 +441,49 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
platSpace.setParentId(firstId);
platSpace.setParentPath(firstId);
save(platSpace);
childrenIdMap.put(secondKey,platSpace.getId());
childrenIdMap.put(secondKey, platSpace.getId());
secondId = platSpace.getId();
}else{
} else {
secondId = childrenIdMap.get(secondKey);
}
}
//第三级
String threeId = null;
if(StringUtil.isNotEmpty(item.getUnit())){
if (StringUtil.isNotEmpty(item.getUnit())) {
String threeKey = secondId + "-" + item.getUnit();
if(!childrenIdMap.containsKey(threeKey)){
if (!childrenIdMap.containsKey(threeKey)) {
PlatSpace platSpace = new PlatSpace();
platSpace.setName(item.getBuilding());
platSpace.setType(PlatSpaceEnum.TypeEnum.UNIT.getValue());
platSpace.setOrgId(orgId);
platSpace.setParentId(secondId);
platSpace.setParentPath(firstId+","+secondId);
platSpace.setParentPath(firstId + "," + secondId);
save(platSpace);
childrenIdMap.put(threeKey,platSpace.getId());
childrenIdMap.put(threeKey, platSpace.getId());
threeId = platSpace.getId();
}else{
} else {
threeId = childrenIdMap.get(threeKey);
}
}
//第四级
String fourId = null;
if(StringUtil.isNotEmpty(item.getFloor())){
if (StringUtil.isNotEmpty(item.getFloor())) {
String fourKey = threeId + "-" + item.getFloor();
if(!childrenIdMap.containsKey(fourKey)){
if (!childrenIdMap.containsKey(fourKey)) {
PlatSpace platSpace = new PlatSpace();
platSpace.setName(item.getBuilding());
platSpace.setType(PlatSpaceEnum.TypeEnum.FLOOR.getValue());
platSpace.setOrgId(orgId);
platSpace.setParentId(threeId);
platSpace.setParentPath(firstId+","+secondId + "," + threeId);
platSpace.setParentPath(firstId + "," + secondId + "," + threeId);
save(platSpace);
childrenIdMap.put(fourKey,platSpace.getId());
childrenIdMap.put(fourKey, platSpace.getId());
fourId = platSpace.getId();
}else{
} else {
fourId = childrenIdMap.get(fourKey);
}
}
......@@ -459,13 +493,13 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
platRoomDTO.setName(item.getRoomName());
platRoomDTO.setBedNumber(item.getBedNumber());
String spaceId = null;
if(firstId != null){
if (firstId != null) {
spaceId = firstId;
}else if(secondId != null){
} else if (secondId != null) {
spaceId = secondId;
}else if(threeId != null){
} else if (threeId != null) {
spaceId = threeId;
}else if(fourId != null){
} else if (fourId != null) {
spaceId = fourId;
}
platRoomDTO.setSpaceId(spaceId);
......@@ -477,7 +511,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
excelImportVo.setSuccessCount(successCount);
excelImportVo.setList(errorVoList);
return excelImportVo;
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
......@@ -488,7 +522,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
public List<PlatSpaceVO> parentListTree(PlatSpaceQueryDTO dto) {
//查询用户权限组织id
List<PlatOrg> orgs = platOrgService.belongToScopeList(new PlatOrg());
if(orgs.isEmpty()){
if (orgs.isEmpty()) {
return new ArrayList<>();
}
//房间
......@@ -497,27 +531,27 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
List<String> orgIds = orgs.stream().map(PlatOrg::getId).collect(Collectors.toList());
LambdaQueryWrapper<PlatSpace> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(StringUtil.isNotEmpty(dto.getName()),PlatSpace::getName,dto.getName());
queryWrapper.like(StringUtil.isNotEmpty(dto.getName()), PlatSpace::getName, dto.getName());
queryWrapper.in(PlatSpace::getOrgId, orgIds);
if(!spaceIds.isEmpty()){
if (!spaceIds.isEmpty()) {
queryWrapper.notIn(PlatSpace::getId, spaceIds);
}
List<PlatSpace> list = this.list(queryWrapper);
list = list.stream()
.filter(s->(StringUtil.isNotEmpty(s.getParentPath()) && s.getParentPath().split(",").length < 3)
|| StringUtil.isEmpty(s.getParentPath()))
.filter(s -> (StringUtil.isNotEmpty(s.getParentPath()) && s.getParentPath().split(",").length < 3)
|| StringUtil.isEmpty(s.getParentPath()))
.collect(Collectors.toList());
//父级
List<PlatSpace> listParent = list.stream().filter(item->StringUtil.isEmpty(item.getParentId())).collect(Collectors.toList());
List<PlatSpace> listParent = list.stream().filter(item -> StringUtil.isEmpty(item.getParentId())).collect(Collectors.toList());
//子集
List<PlatSpace> listChild = list.stream().filter(item->item.getParentId() != null).collect(Collectors.toList());
Map<String,List<PlatSpace>> map = listChild.stream().collect(Collectors.groupingBy(PlatSpace::getParentId));
List<PlatSpace> listChild = list.stream().filter(item -> item.getParentId() != null).collect(Collectors.toList());
Map<String, List<PlatSpace>> map = listChild.stream().collect(Collectors.groupingBy(PlatSpace::getParentId));
List<PlatSpaceVO> data = new ArrayList<>();
for(PlatSpace space:listParent){
for (PlatSpace space : listParent) {
PlatSpaceVO vo = convertToVO(space);
vo = child(vo,map);
vo = child(vo, map);
data.add(vo);
}
return data;
......
package com.makeit.service.wechat.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.makeit.dto.platform.auth.PlatOrgSplitDTO;
import com.makeit.entity.platform.elder.PlatElderChildrenInfo;
import com.makeit.service.platform.auth.PlatOrgService;
import com.makeit.service.platform.elder.PlatElderChildrenInfoService;
import com.makeit.service.wechat.PlatElderChildrenInfoUserLoginWechatService;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
......@@ -24,6 +26,9 @@ public class PlatElderChildrenInfoUserLoginWechatServiceImpl implements PlatElde
@Autowired
private PlatElderChildrenInfoService platElderChildrenInfoService;
@Autowired
private PlatOrgService platOrgService;
@Override
@Transactional
public WechatUserInfo login(WechatLoginPhoneDTO dto) {
......@@ -34,8 +39,19 @@ public class PlatElderChildrenInfoUserLoginWechatServiceImpl implements PlatElde
.eq(PlatElderChildrenInfo::getOpenid, userInfo.getOpenId()));
if (childrenInfo == null) {
childrenInfo = new PlatElderChildrenInfo();
childrenInfo.setOpenid(userInfo.getOpenId());
childrenInfo.setName(userInfo.getNickName());
PlatOrgSplitDTO vo = platOrgService.getOrgSplitVO(dto.getOrgId());
childrenInfo = new PlatElderChildrenInfo();
childrenInfo.setCityOrgId(vo.getCityOrgId());
childrenInfo.setDistrictOrgId(vo.getDistrictOrgId());
childrenInfo.setStreetOrgId(vo.getStreetOrgId());
childrenInfo.setOrgPath(vo.getOrgPath());
}
childrenInfo.setPhone(userInfo.getPhoneNumber());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment