| | |
| | | package com.fh.controller.outer; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.fh.entity.RestResult; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.apache.shiro.authc.AuthenticationException; |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | |
| | | import org.apache.shiro.session.Session; |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.ui.ModelMap; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | |
| | | map.put("data", data); |
| | | return JSON.toJSONString(map); |
| | | } |
| | | |
| | | |
| | | public static final Optional<Map<String, Object>> COMPANY_MAPPING = Optional.ofNullable( |
| | | new ModelMap("14", 3) |
| | | .addAttribute("100000001", "7") |
| | | ); |
| | | |
| | | /** |
| | | * 获取租户及公司信息 |
| | | * @param openId |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @RequestMapping(value="/user/tenant", method=RequestMethod.GET,produces="application/json;charset=UTF-8") |
| | | @RequestMapping(value="/user/tenant", method=RequestMethod.GET) |
| | | @ResponseBody |
| | | public Object getTenant(String openId) throws Exception { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | Map<String, Object> data = new HashMap<>(); |
| | | List<Object> tenants = new ArrayList<Object>(); |
| | | PageData pd = new PageData(); |
| | | pd.put("USER_ID", openId); |
| | | List<PageData> tenantList = tenantService.getTeanatListByUserid(pd); |
| | | if (tenantList != null && tenantList.size() >0) { |
| | | for (PageData t: tenantList) { |
| | | Map<String, Object> tenant = new HashMap<>(); |
| | | tenant.put("code", String.valueOf(t.get("TENANT_ID"))); |
| | | tenant.put("id", "100000001"); |
| | | tenant.put("name", String.valueOf(t.get("TENANT_NAME"))); |
| | | tenant.put("orgCode", "999999999"); |
| | | |
| | | List<Object> companys = new ArrayList<Object>(); |
| | | Map<String, Object> company = new HashMap<>(); |
| | | company.put("code", String.valueOf(t.get("TENANT_ID"))); |
| | | company.put("hotInfoCompanyId", String.valueOf(t.get("TENANT_ID"))); |
| | | company.put("id", "7"); |
| | | company.put("name", String.valueOf(t.get("TENANT_NAME"))); |
| | | company.put("orgCode", "999999999"); |
| | | company.put("tenantId", String.valueOf(t.get("TENANT_ID"))); |
| | | companys.add(company); |
| | | |
| | | tenant.put("companys", companys); |
| | | tenants.add(tenant); |
| | | } |
| | | } |
| | | data.put("tenants", tenants); |
| | | map.put("data", data); |
| | | map.put(RSP_CODE, Const.C0000); |
| | | map.put(RSP_MSG, Const.M0000); |
| | | return JSON.toJSONString(map); |
| | | public RestResult<ModelMap> getTenant(String openId) throws Exception { |
| | | List<PageData> tenantList = tenantService.getTeanatListByUserid(new PageData(new ModelMap("USER_ID", openId))); |
| | | List<Object> tenants = tenantList.stream() |
| | | .map(t->{ |
| | | String tenantId = Objects.toString(t.get("TENANT_ID")); |
| | | String companyId = COMPANY_MAPPING.map(c->c.get(tenantId)).map(Object::toString).orElse(tenantId); |
| | | return new ModelMap() |
| | | .addAttribute("code" , tenantId) |
| | | .addAttribute("id" , tenantId) |
| | | .addAttribute("name" , t.get("TENANT_NAME")) |
| | | .addAttribute("orgCode", tenantId) |
| | | .addAttribute("companys", Arrays.asList( |
| | | new ModelMap("code", companyId) |
| | | .addAttribute("hotInfoCompanyId", companyId) |
| | | .addAttribute("id", companyId) |
| | | .addAttribute("name", t.get("TENANT_NAME")) |
| | | .addAttribute("orgCode", companyId) |
| | | .addAttribute("tenantId", tenantId) |
| | | )); |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | return RestResult.success( |
| | | new ModelMap("tenants", tenants) |
| | | ); |
| | | } |
| | | |
| | | } |