zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package cn.autoform.web.controller.CscApi;
 
import cn.autoform.bean.system.UserInfo;
import cn.autoform.fw.exception.RestResult;
import cn.autoform.fw.utility.RestResultGenerator;
import cn.autoform.util.thread.Keys;
import cn.autoform.util.thread.ThreadData;
import cn.autoform.web.client.CscApiService;
import cn.autoform.web.client.bean.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.Map;
 
@RestController
public class CscApiController {
 
    @Autowired
    private CscApiService cscApi;
    
    
    /**
     * 根据租户id查询租户对应的组织机构信息
     * @return
     */
    @RequestMapping(value = "${requset.findOrganizationByTenantId}", method = RequestMethod.POST)
    public RestResult<Map<String,Object>> findOrganizationByTenantId(@RequestBody Map<String,Object> map){
        return RestResultGenerator.genSuccessResult(cscApi.findOrganizationByTenantId(map));
    }
    
    /**
     * 根据comanyID查询组织机构
     */
    @RequestMapping(value = "${requset.findRelationDetail}", method = RequestMethod.POST)
    public RestResult<List<Organization>> findRelationDetail(@RequestBody Map<String,Object> map){
        return RestResultGenerator.genSuccessResult(
                cscApi.findRelationDetail(new ModelMap("companyId", ThreadData.get(Keys.COMPANY_ID))));
    }
    
    /**
     * 根据comanyID查询组织机构,用于切换公司信息
     */
    @RequestMapping(value = "${requset.findTenantsAndCompanys}", method = RequestMethod.POST)
    public RestResult<TenantsAndCompanys> findTenantsAndCompanys(){
        return RestResultGenerator.genSuccessResult(cscApi.findTenantsAndCompanys());
    }
    
    /**
     * 根据comanyID查询组织机构,用于切换公司信息
     */
    @RequestMapping(value = "${requset.userInfo}", method = RequestMethod.POST)
    public RestResult<UserInfo> userInfo(){
        UserInfo user = new UserInfo();
        //取出当前用户所在公司ID
        TenantsAndCompanys o = null;
        o = cscApi.findTenantsAndCompanys();
        if(o==null){
            return RestResultGenerator.genSuccessResult(user);
        }
        
        boolean flase = false;
        for(Tenant tenant :o.getTenants()){
            user.setTenantId(tenant.getId());
                for(Company com :tenant.getCompanys()){
                    user.setCompanyId(com.getId());
                    user.setHotInfoCompanyId(com.getHotInfoCompanyId());
                    for(SystemManager sys :com.getData()){
                        user.setServiceId(sys.getId());
                    }
//                    flase = true;
//                    break;
                }
//                if(flase){
//                    break;
//                }
        }
        if(user.getTenantId() == null){
            
            System.out.println("进入"+user.getTenantId());
            return RestResultGenerator.genSuccessResult(user);
        }
        Organization org = cscApi.findOrganization(user.getTenantId());
        
        user.setUid(org.getCode());
        return RestResultGenerator.genSuccessResult(user);
    }
    public Object getUserId(List<Organization> orgs,String openId,UserInfo user){
        for(Organization org : orgs){
            for(User users: org.getUsers()){
                if(users.getOpenId().equals(openId)){
                    user.setUid(users.getId());
                    return null;
                }
            }
        }
        return null;
    }
 
    
 
}