王煜鑫
2018-11-06 1c17c2d749bf943ba183fb25b9cfa565bd422c2b
更新查询租户接口
3 files modified
95 ■■■■ changed files
sourcecode/MVNFHM/src/main/java/com/fh/controller/outer/OuterInterfaceController.java 77 ●●●● patch | view | raw | blame | history
sourcecode/MVNFHM/src/main/java/com/fh/util/PageData.java 4 ●●●● patch | view | raw | blame | history
sourcecode/MVNFHM/src/main/resources/mybatis1/system/TenantMapper.xml 14 ●●●● patch | view | raw | blame | history
sourcecode/MVNFHM/src/main/java/com/fh/controller/outer/OuterInterfaceController.java
@@ -1,14 +1,11 @@
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;
@@ -16,6 +13,7 @@
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;
@@ -223,49 +221,44 @@
        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)
        );
    }
}
sourcecode/MVNFHM/src/main/java/com/fh/util/PageData.java
@@ -49,6 +49,10 @@
    public PageData() {
        map = new HashMap();
    }
    public PageData(Map<String, Object> param){
        map = param;
    }
    
    @Override
    public Object get(Object key) {
sourcecode/MVNFHM/src/main/resources/mybatis1/system/TenantMapper.xml
@@ -209,14 +209,14 @@
        where sys.USER_ID = #{USER_ID}
              and sys.SYSTEM_ID = #{SYSTEM_ID}
    </select>
    <!-- 根据用户ID获取租户列表 -->
    <select id="getTeanatListByUserid" parameterType="pd" resultType="pd">
        SELECT
        *
        FROM
        sys_tenant tenant
        INNER JOIN sys_user_system sys ON tenant.TENANT_ID = sys.TENANT_ID
        where sys.USER_ID = #{USER_ID}
        select
            t.TENANT_ID,
            t.TENANT_NAME
        from sys_user u
        left join sys_tenant t on u.TENANT_ID = t.TENANT_ID
        where USER_ID = #{USER_ID}
    </select>
</mapper>