|
@@ -1,8 +1,8 @@
|
|
|
package cn.com.ty.lift.enterprise.organization.service;
|
|
|
|
|
|
import cn.com.ty.lift.common.constants.ApiConstants;
|
|
|
+import cn.com.ty.lift.enterprise.organization.dao.entity.Organization;
|
|
|
import cn.com.ty.lift.enterprise.organization.dao.entity.Project;
|
|
|
-import cn.com.ty.lift.enterprise.organization.dao.entity.model.OrganizationReq;
|
|
|
import cn.com.ty.lift.enterprise.organization.service.impl.ProjectServiceImpl;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -21,43 +21,43 @@ public class OrganizationService {
|
|
|
* @description 获取省,市,区,项目列表
|
|
|
* @date 2019/12/17 10:05
|
|
|
*/
|
|
|
- public RestResponse organization(OrganizationReq req) {
|
|
|
- List<HashMap<String, String>> areas;
|
|
|
- HashMap<String, Object> result;
|
|
|
-
|
|
|
- List<Project> list = projectService.list(new QueryWrapper<Project>()
|
|
|
- .select("province", "city", "district")
|
|
|
- .eq("mt_company_id", req.getMtCompanyId()));
|
|
|
-
|
|
|
- if (req.getDistrict() != null) {
|
|
|
- List<HashMap<String, String>> projects = projectService.getBaseMapper().projects(req.getMtCompanyId(), req.getDistrict());
|
|
|
- if (projects.isEmpty()) {
|
|
|
- return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
- }
|
|
|
- //如果查询到了项目
|
|
|
- result = new HashMap<>();
|
|
|
- result.put("projectNum", projects.size());
|
|
|
- result.put("projects", projects);
|
|
|
- return RestResponse.ok(result, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
- } else if (req.getCity() != null) {
|
|
|
- areas = projectService.getBaseMapper().districts(req.getMtCompanyId(), req.getCity());
|
|
|
- } else if (req.getProvince() != null) {
|
|
|
- areas = projectService.getBaseMapper().cities(req.getMtCompanyId(), req.getProvince());
|
|
|
- } else {
|
|
|
- areas = projectService.getBaseMapper().provinces(req.getMtCompanyId());
|
|
|
- if (areas.isEmpty()) {
|
|
|
- return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
- }
|
|
|
- }
|
|
|
- if (areas.isEmpty()) {
|
|
|
- return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
- }
|
|
|
- //如果查询到了区域
|
|
|
- result = new HashMap<>();
|
|
|
- result.put("areaNum", areas.size());
|
|
|
- result.put("areas", areas);
|
|
|
- return RestResponse.ok(result, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
- }
|
|
|
+// public RestResponse organization(OrganizationReq req) {
|
|
|
+// List<HashMap<String, String>> areas;
|
|
|
+// HashMap<String, Object> result;
|
|
|
+//
|
|
|
+// List<Project> list = projectService.list(new QueryWrapper<Project>()
|
|
|
+// .select("province", "city", "district")
|
|
|
+// .eq("mt_company_id", req.getMtCompanyId()));
|
|
|
+//
|
|
|
+// if (req.getDistrict() != null) {
|
|
|
+// List<HashMap<String, String>> projects = projectService.getBaseMapper().projects(req.getMtCompanyId(), req.getDistrict());
|
|
|
+// if (projects.isEmpty()) {
|
|
|
+// return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
+// }
|
|
|
+// //如果查询到了项目
|
|
|
+// result = new HashMap<>();
|
|
|
+// result.put("projectNum", projects.size());
|
|
|
+// result.put("projects", projects);
|
|
|
+// return RestResponse.ok(result, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
+// } else if (req.getCity() != null) {
|
|
|
+// areas = projectService.getBaseMapper().districts(req.getMtCompanyId(), req.getCity());
|
|
|
+// } else if (req.getProvince() != null) {
|
|
|
+// areas = projectService.getBaseMapper().cities(req.getMtCompanyId(), req.getProvince());
|
|
|
+// } else {
|
|
|
+// areas = projectService.getBaseMapper().provinces(req.getMtCompanyId());
|
|
|
+// if (areas.isEmpty()) {
|
|
|
+// return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (areas.isEmpty()) {
|
|
|
+// return RestResponse.ok(null, ApiConstants.RESULT_NO_DATA, "无数据");
|
|
|
+// }
|
|
|
+// //如果查询到了区域
|
|
|
+// result = new HashMap<>();
|
|
|
+// result.put("areaNum", areas.size());
|
|
|
+// result.put("areas", areas);
|
|
|
+// return RestResponse.ok(result, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
+// }
|
|
|
|
|
|
public RestResponse users(Project project) {
|
|
|
List<HashMap<String, Object>> projectUsers = projectService.getBaseMapper().users(project.getId());
|
|
@@ -90,7 +90,172 @@ public class OrganizationService {
|
|
|
return RestResponse.ok(projectUsers, ApiConstants.RESULT_SUCCESS, "查询成功");
|
|
|
}
|
|
|
|
|
|
- public Integer childNum(List<HashMap<String, String>> areas, List<HashMap<String, String>> projects) {
|
|
|
+ public RestResponse organizationTree(Long mtCompanyId) {
|
|
|
+ List<Organization> ps = new ArrayList<>();
|
|
|
+ List<Organization> cs = new ArrayList<>();
|
|
|
+ List<Organization> ds = new ArrayList<>();
|
|
|
+
|
|
|
+ Organization organization;
|
|
|
+ List<Project> projects = projectService.list(new QueryWrapper<Project>()
|
|
|
+ .select("id", "project_name", "province", "city", "district", "num")
|
|
|
+ .eq("mt_company_id", mtCompanyId)
|
|
|
+ );
|
|
|
+
|
|
|
+ for (Project project : projects) {
|
|
|
+ if (project.getProjectName() == null || project.getDistrict() == null || project.getCity() == null || project.getProvince() == null)
|
|
|
+ continue;
|
|
|
+ organization = new Organization();
|
|
|
+ String district = project.getDistrict();
|
|
|
+ String city = project.getCity();
|
|
|
+ String province = project.getProvince();
|
|
|
+
|
|
|
+ organization.setAreaName(district);
|
|
|
+ organization.setLevel(3);
|
|
|
+ //获取区列表和区下的项目
|
|
|
+ if (ds.isEmpty()) {
|
|
|
+ organization.setProjects(new ArrayList<>());
|
|
|
+ organization.getProjects().add(project);
|
|
|
+ ds.add(organization);
|
|
|
+ } else {
|
|
|
+ boolean flag = false;
|
|
|
+ for (Organization d : ds) {
|
|
|
+ if (d.getAreaName().equals(district)) {
|
|
|
+ d.getProjects().add(project);
|
|
|
+ flag = false;
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ flag = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (flag) {
|
|
|
+ organization.setProjects(new ArrayList<>());
|
|
|
+ organization.getProjects().add(project);
|
|
|
+ ds.add(organization);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ organization = new Organization();
|
|
|
+
|
|
|
+ organization.setAreaName(city);
|
|
|
+ organization.setLevel(2);
|
|
|
+ //获取市列表
|
|
|
+ if (cs.isEmpty()) {
|
|
|
+ cs.add(organization);
|
|
|
+ } else {
|
|
|
+ boolean flag = true;
|
|
|
+ for (Organization c : cs) {
|
|
|
+ if (c.getAreaName().equals(city)) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (flag)
|
|
|
+ cs.add(organization);
|
|
|
+ }
|
|
|
+ organization = new Organization();
|
|
|
|
|
|
+ organization.setAreaName(province);
|
|
|
+ organization.setLevel(1);
|
|
|
+ //获取省列表
|
|
|
+ if (ps.isEmpty()) {
|
|
|
+ ps.add(organization);
|
|
|
+ } else {
|
|
|
+ boolean flag = true;
|
|
|
+ for (Organization p : ps) {
|
|
|
+ if (p.getAreaName().equals(province)) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (flag)
|
|
|
+ ps.add(organization);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (Organization d : ds) {
|
|
|
+ //获取市名
|
|
|
+ String city = d.getProjects().get(0).getCity();
|
|
|
+ for (Organization c : cs) {
|
|
|
+ if (c.getAreaName().equals(city)) {
|
|
|
+ if (c.getOrganizations() == null) {
|
|
|
+ c.setOrganizations(new ArrayList<>());
|
|
|
+ }
|
|
|
+ c.getOrganizations().add(d);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Organization c : cs) {
|
|
|
+ //获取省名
|
|
|
+ String province = c.getOrganizations().get(0).getProjects().get(0).getProvince();
|
|
|
+ for (Organization p : ps) {
|
|
|
+ if (p.getAreaName().equals(province)) {
|
|
|
+ if (p.getOrganizations() == null) {
|
|
|
+ p.setOrganizations(new ArrayList<>());
|
|
|
+ }
|
|
|
+ p.getOrganizations().add(c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ps.isEmpty()) {
|
|
|
+ return RestResponse.ok(null,ApiConstants.RESULT_NO_DATA,"无数据");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(null,ApiConstants.RESULT_SUCCESS,"成功");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+// public Map<String, List> organizationTree1(Long mtCompanyId) {
|
|
|
+// Map<String, List> ps = new HashMap<>();
|
|
|
+// Map<String, List> cs = new HashMap<>();
|
|
|
+// Map<String, List> ds = new HashMap<>();
|
|
|
+//
|
|
|
+// List<Project> projects = projectService.list(new QueryWrapper<Project>()
|
|
|
+// .select("id", "project_name", "province", "city", "district", "num")
|
|
|
+// .eq("mt_company_id", mtCompanyId)
|
|
|
+// );
|
|
|
+//
|
|
|
+// for (Project project : projects) {
|
|
|
+// if (project.getProjectName() == null || project.getDistrict() == null || project.getCity() == null || project.getProvince() == null)
|
|
|
+// continue;
|
|
|
+//
|
|
|
+// String district = project.getDistrict();
|
|
|
+// String city = project.getCity();
|
|
|
+// String province = project.getProvince();
|
|
|
+//
|
|
|
+// //获取区列表和区下的项目
|
|
|
+// if (!ds.containsKey(district)) {
|
|
|
+// ds.put(district, new ArrayList());
|
|
|
+// }
|
|
|
+// if (ds.get(district) instanceof ArrayList) {
|
|
|
+// ds.get(district).add(project);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //获取市列表
|
|
|
+// if (!cs.containsKey(city)) {
|
|
|
+// cs.put(city, new ArrayList());
|
|
|
+// }
|
|
|
+//
|
|
|
+// //获取省列表
|
|
|
+// if (!ps.containsKey(province)) {
|
|
|
+// ps.put(province, new ArrayList());
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// for (Map.Entry<String, List> entry : ds.entrySet()) {
|
|
|
+// for (Project project : projects) {
|
|
|
+// if (entry.getKey().equals(project.getDistrict())) {
|
|
|
+// cs.get(project.getCity()).add(entry);
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// for (Map.Entry<String, List> entry : cs.entrySet()) {
|
|
|
+// for (Project project : projects) {
|
|
|
+// if (entry.getKey().equals(project.getCity())) {
|
|
|
+// ps.get(project.getProvince()).add(entry);
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return ps;
|
|
|
+// }
|
|
|
}
|