package com.moral.controller; import com.moral.Webinterceptor.WebInterceptor; import com.moral.common.util.BeanUtils; import com.moral.entity.AreaNames; import com.moral.entity.Organization; import com.moral.service.AccountService; import com.moral.service.DictionaryDataService; import com.moral.service.OrganizationService; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import static com.moral.common.util.WebUtils.getParametersStartingWith; @RestController @RequestMapping("/web") @CrossOrigin(origins = "*", maxAge = 3600) @SuppressWarnings({"rawtypes", "unchecked", "unused"}) public class WebController { @Resource AccountService accountService; @Resource DictionaryDataService dictionaryDataService; OrganizationService organizationService; @RequestMapping("login") public Map login(HttpServletRequest request){ Map resultMap = new HashMap(); Map parameters = getParametersStartingWith(request, null); if (!(parameters.containsKey("account") && parameters.containsKey("password"))) { resultMap.put("msg", "用户名及密码不允许为空!"); resultMap.put("accountId", -1); } else { resultMap = accountService.screenLoginNew(parameters); // 添加返回行政区信息字符串操作 Object orgId = resultMap.get("orgId"); if (resultMap.get("orgId") != null && resultMap.get("orgId") instanceof Integer) { StringBuilder areaNamesBuilder = new StringBuilder("中国"); if (!((Integer) orgId).equals(dictionaryDataService.querySupperOrgId())) { Organization organization = organizationService.getOrganizationById((Integer) orgId); if (organization.getAreaNames() != null) { Map areaNameMap = BeanUtils.beanToMap(organization.getAreaNames()); List names = areaNameMap.entrySet().stream().filter(item -> { return item.getValue() != null; }).map(item -> { return item.getValue(); }).collect(Collectors.toList()); AreaNames areaNames = organization.getAreaNames(); areaNamesBuilder.append("/"); areaNamesBuilder.append(String.join("/", names)); } // 企业用户 if (organization.getRank() != null && organization.getRank() == 0) { resultMap.put("type", "enterprise"); } else { resultMap.put("type", "government"); } Number mapAreaCode = null; if (organization.getVillageCode() != null) { mapAreaCode = organization.getVillageCode(); } else if (organization.getTownCode() != null) { mapAreaCode = organization.getTownCode(); } else if (organization.getAreaCode() != null) { mapAreaCode = organization.getAreaCode(); } else if (organization.getCityCode() != null) { mapAreaCode = organization.getCityCode(); } else if (organization.getProvinceCode() != null) { mapAreaCode = organization.getProvinceCode(); } resultMap.put("mapAreaCode", mapAreaCode.toString()); } resultMap.put("mapPath", areaNamesBuilder.toString()); } } request.getSession().setAttribute(WebInterceptor.SESSION_KEY,resultMap); return resultMap; } @RequestMapping("add") public String add(){ return "123123"; } }