4 changed files with 138 additions and 0 deletions
@ -0,0 +1,20 @@ |
|||||
|
package com.epmet.dto.result; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Data |
||||
|
@NoArgsConstructor |
||||
|
@AllArgsConstructor |
||||
|
public class UserHouseScopeResultDTO { |
||||
|
|
||||
|
private String objectId; |
||||
|
private String objectName; |
||||
|
private String objectType; |
||||
|
|
||||
|
private List<UserHouseScopeResultDTO> children; |
||||
|
|
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
package com.epmet.controller; |
||||
|
|
||||
|
import com.epmet.commons.tools.annotation.LoginUser; |
||||
|
import com.epmet.commons.tools.security.dto.TokenDto; |
||||
|
import com.epmet.commons.tools.utils.Result; |
||||
|
import com.epmet.dto.result.UserHouseScopeResultDTO; |
||||
|
import com.epmet.service.UserHouseScopeService; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
/** |
||||
|
* 服务项目 |
||||
|
*/ |
||||
|
@RestController |
||||
|
@RequestMapping("userhouse") |
||||
|
public class UserHouseScopeController { |
||||
|
|
||||
|
@Autowired |
||||
|
public UserHouseScopeService userHouseScopeService; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 服务范围树查询 |
||||
|
* @return |
||||
|
*/ |
||||
|
@RequestMapping("service/serviceScopeTree") |
||||
|
public Result<UserHouseScopeResultDTO> getServiceScopeTree(@LoginUser TokenDto loginInfo) { |
||||
|
UserHouseScopeResultDTO r = userHouseScopeService.getServiceScopeTree(loginInfo.getUserId()); |
||||
|
return new Result<UserHouseScopeResultDTO>().ok(r); |
||||
|
} |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
package com.epmet.service; |
||||
|
|
||||
|
import com.epmet.dto.result.UserHouseScopeResultDTO; |
||||
|
|
||||
|
public interface UserHouseScopeService { |
||||
|
UserHouseScopeResultDTO getServiceScopeTree(String staffId); |
||||
|
} |
@ -0,0 +1,79 @@ |
|||||
|
package com.epmet.service.impl; |
||||
|
|
||||
|
import com.epmet.dao.IcNeighborHoodDao; |
||||
|
import com.epmet.dto.IcNeighborHoodDTO; |
||||
|
import com.epmet.dto.result.AgencyTreeResultDTO; |
||||
|
import com.epmet.dto.result.UserHouseScopeResultDTO; |
||||
|
import com.epmet.service.CustomerAgencyService; |
||||
|
import com.epmet.service.UserHouseScopeService; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.util.CollectionUtils; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Service |
||||
|
public class UserHouseScopeServiceImpl implements UserHouseScopeService { |
||||
|
|
||||
|
@Autowired |
||||
|
private IcNeighborHoodDao neighborHoodDao; |
||||
|
|
||||
|
@Autowired |
||||
|
private CustomerAgencyService customerAgencyService; |
||||
|
|
||||
|
public UserHouseScopeServiceImpl() { |
||||
|
System.out.println(6); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public UserHouseScopeResultDTO getServiceScopeTree(String staffId) { |
||||
|
AgencyTreeResultDTO orgTreeData = customerAgencyService.getOrgTreeData(staffId); |
||||
|
|
||||
|
UserHouseScopeResultDTO rootScope = new UserHouseScopeResultDTO(); |
||||
|
rootScope.setObjectId(orgTreeData.getAgencyId()); |
||||
|
rootScope.setObjectType(orgTreeData.getLevel()); |
||||
|
rootScope.setObjectName(orgTreeData.getAgencyName()); |
||||
|
rootScope.setChildren(convert2ServiceProjectScope(orgTreeData.getSubAgencyList())); |
||||
|
|
||||
|
return rootScope; |
||||
|
} |
||||
|
|
||||
|
private List<UserHouseScopeResultDTO> convert2ServiceProjectScope(List<AgencyTreeResultDTO> oldChildren) { |
||||
|
|
||||
|
ArrayList<UserHouseScopeResultDTO> scopes = new ArrayList<>(); |
||||
|
|
||||
|
for (AgencyTreeResultDTO oldChild : oldChildren) { |
||||
|
UserHouseScopeResultDTO scope = new UserHouseScopeResultDTO(); |
||||
|
scope.setObjectId(oldChild.getAgencyId()); |
||||
|
scope.setObjectType(oldChild.getLevel()); |
||||
|
scope.setObjectName(oldChild.getAgencyName()); |
||||
|
if ("grid".equals(oldChild.getLevel())) { |
||||
|
// 如果是网格,那么还要查询网格下的小区
|
||||
|
List<IcNeighborHoodDTO> neighborhoods = neighborHoodDao.selectNeighborList(oldChild.getAgencyId()); |
||||
|
|
||||
|
List<UserHouseScopeResultDTO> neighborhoodScopes = neighborhoods.stream().map(n -> new UserHouseScopeResultDTO(n.getId(), |
||||
|
n.getNeighborHoodName(), |
||||
|
"neighborhood", |
||||
|
null)).collect(Collectors.toList()); |
||||
|
|
||||
|
scope.setChildren(neighborhoodScopes); |
||||
|
} else { |
||||
|
// 递归处理子级
|
||||
|
List<AgencyTreeResultDTO> subAgencyList = oldChild.getSubAgencyList(); |
||||
|
if (subAgencyList != null && !CollectionUtils.isEmpty(subAgencyList)) { |
||||
|
List<UserHouseScopeResultDTO> subOrgScope = convert2ServiceProjectScope(subAgencyList); |
||||
|
scope.setChildren(subOrgScope); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
scopes.add(scope); |
||||
|
} |
||||
|
|
||||
|
return scopes; |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue