|
@@ -0,0 +1,109 @@
|
|
|
+package com.welampiot.utils;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.welampiot.dao.GlobalLocationDao;
|
|
|
+import com.welampiot.dao.UserDao;
|
|
|
+import com.welampiot.dto.GlobalLocationDTO;
|
|
|
+import com.welampiot.dto.SectionDTO;
|
|
|
+import com.welampiot.dto.UserDTO;
|
|
|
+import com.welampiot.service.GlobalLocationService;
|
|
|
+import com.welampiot.service.SectionService;
|
|
|
+import com.welampiot.service.UserService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class ToolUtils {
|
|
|
+ private UserDTO user;
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+ @Autowired
|
|
|
+ private SectionService sectionService;
|
|
|
+ @Autowired
|
|
|
+ private GlobalLocationService globalLocationService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户所有路段 id
|
|
|
+ * @param request
|
|
|
+ * @return 如果返回列表为空,表示超管获取到全部路段信息,此时不需要做路段筛选
|
|
|
+ */
|
|
|
+ public List getSectionList(HttpServletRequest request){
|
|
|
+ String username = request.getParameter("username");
|
|
|
+ if (username == null || username.toString().length() == 0) return Collections.singletonList(new int[]{0});
|
|
|
+ UserDTO user1 = userService.findUserByUserName(username);
|
|
|
+ if (user1 == null) return Collections.singletonList(new int[]{0});
|
|
|
+
|
|
|
+ String provinceid = request.getParameter("provinceid");
|
|
|
+ provinceid = provinceid == null || provinceid.equals("0") ? request.getParameter("provinceId") : provinceid;
|
|
|
+ String cityid = request.getParameter("cityid");
|
|
|
+ cityid = cityid == null || cityid.equals("0") ? request.getParameter("cityId") : cityid;
|
|
|
+ String areaid = request.getParameter("areaid");
|
|
|
+ areaid = areaid == null || areaid.equals("0") ? request.getParameter("areaId") : areaid;
|
|
|
+ String sectionid = request.getParameter("sectionid");
|
|
|
+ sectionid = sectionid == null || sectionid.equals("0") ? request.getParameter("sectionId") : sectionid;
|
|
|
+
|
|
|
+ ArrayList<Object> sectionList = new ArrayList<>();
|
|
|
+ if (sectionid != null && sectionid.length() != 0 && !sectionid.equals("0")){
|
|
|
+ sectionList.add(sectionid);
|
|
|
+ return sectionList;
|
|
|
+ }
|
|
|
+ String zone = user1.getZoneList();
|
|
|
+ int role = user1.getRole();
|
|
|
+ List<SectionDTO> maps;
|
|
|
+ List<GlobalLocationDTO> globalLocationList;
|
|
|
+ ArrayList areaList = new ArrayList<>();
|
|
|
+ if ((cityid != null && !cityid.equals("0")) || (provinceid != null && !provinceid.equals("0")) || (areaid != null && !areaid.equals("0"))){
|
|
|
+ if (areaid == null || areaid.equals("0")){
|
|
|
+ ArrayList cityList = new ArrayList<>();
|
|
|
+ if (cityid == null || cityid.equals("0")){
|
|
|
+ globalLocationList = globalLocationService.getListByPid(Integer.valueOf(provinceid));
|
|
|
+ if (globalLocationList.isEmpty()){
|
|
|
+ cityid = provinceid;
|
|
|
+ }else {
|
|
|
+ for (GlobalLocationDTO m :globalLocationList) {
|
|
|
+ cityList.add(m.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (cityList.isEmpty()){
|
|
|
+ globalLocationList = globalLocationService.getListByPid(Integer.valueOf(cityid));
|
|
|
+ }else {
|
|
|
+ globalLocationList = globalLocationService.getListByPidList(cityList);
|
|
|
+ }
|
|
|
+ if (globalLocationList.isEmpty()){
|
|
|
+ areaid = cityid;
|
|
|
+ }else {
|
|
|
+ for (GlobalLocationDTO m :globalLocationList) {
|
|
|
+ areaList.add(m.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ((areaid == null || areaid.length() == 0 || areaid.equals("0")) && areaList.isEmpty()){
|
|
|
+ if (role != 1) {
|
|
|
+ return Arrays.asList(zone.split(","));
|
|
|
+ }else {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (areaid == null || areaid.equals("0")){
|
|
|
+ maps = sectionService.getLIstByPidList(areaList);
|
|
|
+ if (role != 1){
|
|
|
+ return Arrays.asList(zone.split(","));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ maps = sectionService.getListByPid(Integer.valueOf(areaid));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (SectionDTO map:maps) {
|
|
|
+ sectionList.add(map.getId());
|
|
|
+ }
|
|
|
+ if (sectionList.isEmpty()) sectionList.add("0");
|
|
|
+ return sectionList;
|
|
|
+ }
|
|
|
+}
|