4 changed files with 171 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 ServiceProjectScopeResultDTO { |
|||
|
|||
private String objectId; |
|||
private String objectName; |
|||
private String objectType; |
|||
|
|||
private List<ServiceProjectScopeResultDTO> children; |
|||
|
|||
} |
@ -0,0 +1,35 @@ |
|||
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.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.dto.result.ServiceProjectScopeResultDTO; |
|||
import com.epmet.service.ServiceProjectService; |
|||
import com.epmet.service.impl.ServiceProjectServiceImpl; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
/** |
|||
* 服务项目 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("icServiceProject") |
|||
public class ServiceProjectController { |
|||
|
|||
@Autowired |
|||
public ServiceProjectService serviceProjectService; |
|||
|
|||
|
|||
/** |
|||
* 服务范围树查询 |
|||
* @return |
|||
*/ |
|||
@RequestMapping("service/serviceScopeTree") |
|||
public Result<ServiceProjectScopeResultDTO> getServiceScopeTree(@LoginUser TokenDto loginInfo) { |
|||
ServiceProjectScopeResultDTO r = serviceProjectService.getServiceScopeTree(loginInfo.getUserId()); |
|||
return new Result<ServiceProjectScopeResultDTO>().ok(r); |
|||
} |
|||
} |
@ -0,0 +1,9 @@ |
|||
package com.epmet.service; |
|||
|
|||
import com.epmet.commons.mybatis.service.BaseService; |
|||
import com.epmet.dto.result.ServiceProjectScopeResultDTO; |
|||
import com.epmet.entity.IcPlaceOrgEntity; |
|||
|
|||
public interface ServiceProjectService { |
|||
ServiceProjectScopeResultDTO getServiceScopeTree(String staffId); |
|||
} |
@ -0,0 +1,107 @@ |
|||
package com.epmet.service.impl; |
|||
|
|||
import com.epmet.commons.mybatis.service.BaseService; |
|||
import com.epmet.dao.CustomerAgencyDao; |
|||
import com.epmet.dao.CustomerGridDao; |
|||
import com.epmet.dao.IcNeighborHoodDao; |
|||
import com.epmet.dto.IcNeighborHoodDTO; |
|||
import com.epmet.dto.result.AgencyTreeResultDTO; |
|||
import com.epmet.dto.result.ServiceProjectScopeResultDTO; |
|||
import com.epmet.entity.CustomerAgencyEntity; |
|||
import com.epmet.entity.IcPlaceOrgEntity; |
|||
import com.epmet.service.CustomerAgencyService; |
|||
import com.epmet.service.NeighborHoodService; |
|||
import com.epmet.service.ServiceProjectService; |
|||
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 ServiceProjectServiceImpl implements ServiceProjectService { |
|||
|
|||
@Autowired |
|||
private CustomerAgencyDao agencyDao; |
|||
|
|||
@Autowired |
|||
private CustomerGridDao gridDao; |
|||
|
|||
@Autowired |
|||
private IcNeighborHoodDao neighborHoodDao; |
|||
|
|||
@Autowired |
|||
private CustomerAgencyService customerAgencyService; |
|||
|
|||
public ServiceProjectServiceImpl() { |
|||
System.out.println(6); |
|||
} |
|||
|
|||
@Override |
|||
public ServiceProjectScopeResultDTO getServiceScopeTree(String staffId) { |
|||
AgencyTreeResultDTO orgTreeData = customerAgencyService.getOrgTreeData(staffId); |
|||
|
|||
ServiceProjectScopeResultDTO rootScope = new ServiceProjectScopeResultDTO(); |
|||
rootScope.setObjectId(orgTreeData.getAgencyId()); |
|||
rootScope.setObjectType(orgTreeData.getLevel()); |
|||
rootScope.setObjectName(orgTreeData.getAgencyName()); |
|||
rootScope.setChildren(convert2ServiceProjectScope(orgTreeData.getSubAgencyList())); |
|||
|
|||
return rootScope; |
|||
} |
|||
|
|||
private List<ServiceProjectScopeResultDTO> convert2ServiceProjectScope(List<AgencyTreeResultDTO> oldChildren) { |
|||
|
|||
ArrayList<ServiceProjectScopeResultDTO> scopes = new ArrayList<>(); |
|||
|
|||
for (AgencyTreeResultDTO oldChild : oldChildren) { |
|||
ServiceProjectScopeResultDTO scope = new ServiceProjectScopeResultDTO(); |
|||
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<ServiceProjectScopeResultDTO> neighborhoodScopes = neighborhoods.stream().map(n -> new ServiceProjectScopeResultDTO(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<ServiceProjectScopeResultDTO> subOrgScope = convert2ServiceProjectScope(subAgencyList); |
|||
scope.setChildren(subOrgScope); |
|||
} |
|||
} |
|||
|
|||
scopes.add(scope); |
|||
} |
|||
|
|||
return scopes; |
|||
} |
|||
|
|||
//public void recursiveFillChildren(ServiceProjectScopeResultDTO parentObject) {
|
|||
// String parentObjectType = parentObject.getObjectType();
|
|||
// if ("grid".equals(parentObjectType)) {
|
|||
// // 如果父级是网格,那么查询子级小区
|
|||
// neighborHoodService.listNeighborhood()
|
|||
// } else if ("agency".equals(parentObjectType)) {
|
|||
// // 如果父级是单位,那么查询子级单位或者网格
|
|||
// String parentObjectId = parentObject.getObjectId();
|
|||
// if ("community".equals(parentObject)) {
|
|||
// gridDao.get
|
|||
// } else {
|
|||
// agencyDao.getSubAgencyList()
|
|||
// }
|
|||
// }
|
|||
//
|
|||
//}
|
|||
} |
Loading…
Reference in new issue