Authored by csgyoho

Merge branch 'dev_grass_20190108' of http://git.yoho.cn/platform/platform-cms in…

…to dev_grass_20190108
1 -<?xml version="1.0" encoding="UTF-8"?>  
2 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
3 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
4 - <parent>  
5 - <artifactId>yohobuy-platform-cms</artifactId>  
6 - <groupId>com.yoho.dsf</groupId>  
7 - <version>1.0-SNAPSHOT</version>  
8 - </parent>  
9 -  
10 - <modelVersion>4.0.0</modelVersion>  
11 -  
12 - <groupId>com.yoho.dsf.yhplatform</groupId>  
13 - <artifactId>platform-cms-mvc</artifactId>  
14 - <packaging>jar</packaging>  
15 -  
16 - <name>platform-cms-mvc</name>  
17 -  
18 - <properties>  
19 - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
20 - </properties>  
21 - <dependencies>  
22 - <dependency>  
23 - <groupId>com.yoho.service.platform.model</groupId>  
24 - <artifactId>platform-service-model</artifactId>  
25 - </dependency>  
26 - <dependency>  
27 - <groupId>com.yohobuy.platform</groupId>  
28 - <artifactId>platform-common</artifactId>  
29 - </dependency>  
30 - <dependency>  
31 - <groupId>com.yoho.core</groupId>  
32 - <artifactId>yoho-core-redis-cluster</artifactId>  
33 - </dependency>  
34 - </dependencies>  
35 -</project>  
1 -/**  
2 - *  
3 - */  
4 -package com.yohobuy.platform.mvc.bean;  
5 -  
6 -import java.util.List;  
7 -  
8 -import com.yoho.tools.common.beans.BaseBean;  
9 -  
10 -/**  
11 - * @author ping.huang  
12 - * 2016年9月24日  
13 - */  
14 -public class ERPProfileRequestBO extends BaseBean {  
15 -  
16 - /**  
17 - *  
18 - */  
19 - private static final long serialVersionUID = -6299334332126635127L;  
20 -  
21 - private String password;  
22 - private String account;  
23 - private String auth_site;  
24 - private String truename;  
25 - private String staff_code;  
26 - private String email;  
27 - private Integer dept_id;  
28 - private Integer role_id;  
29 - private Integer create_id;  
30 - private Integer pid;  
31 - private String phone;  
32 -  
33 - private List<Integer> pIds;  
34 - private Integer status;  
35 -  
36 - private Integer pageNo;  
37 - private Integer pageSize;  
38 -  
39 - public String getPassword() {  
40 - return password;  
41 - }  
42 - public void setPassword(String password) {  
43 - this.password = password;  
44 - }  
45 - public String getAccount() {  
46 - return account;  
47 - }  
48 - public void setAccount(String account) {  
49 - this.account = account;  
50 - }  
51 - public String getAuth_site() {  
52 - return auth_site;  
53 - }  
54 - public void setAuth_site(String auth_site) {  
55 - this.auth_site = auth_site;  
56 - }  
57 - public String getTruename() {  
58 - return truename;  
59 - }  
60 - public void setTruename(String truename) {  
61 - this.truename = truename;  
62 - }  
63 - public String getStaff_code() {  
64 - return staff_code;  
65 - }  
66 - public void setStaff_code(String staff_code) {  
67 - this.staff_code = staff_code;  
68 - }  
69 - public String getEmail() {  
70 - return email;  
71 - }  
72 - public void setEmail(String email) {  
73 - this.email = email;  
74 - }  
75 - public Integer getDept_id() {  
76 - return dept_id;  
77 - }  
78 - public void setDept_id(Integer dept_id) {  
79 - this.dept_id = dept_id;  
80 - }  
81 - public Integer getRole_id() {  
82 - return role_id;  
83 - }  
84 - public void setRole_id(Integer role_id) {  
85 - this.role_id = role_id;  
86 - }  
87 - public Integer getCreate_id() {  
88 - return create_id;  
89 - }  
90 - public void setCreate_id(Integer create_id) {  
91 - this.create_id = create_id;  
92 - }  
93 - public Integer getPid() {  
94 - return pid;  
95 - }  
96 - public void setPid(Integer pid) {  
97 - this.pid = pid;  
98 - }  
99 - public String getPhone() {  
100 - return phone;  
101 - }  
102 - public void setPhone(String phone) {  
103 - this.phone = phone;  
104 - }  
105 - public Integer getStatus() {  
106 - return status;  
107 - }  
108 - public void setStatus(Integer status) {  
109 - this.status = status;  
110 - }  
111 - public List<Integer> getpIds() {  
112 - return pIds;  
113 - }  
114 - public void setpIds(List<Integer> pIds) {  
115 - this.pIds = pIds;  
116 - }  
117 - public Integer getPageNo() {  
118 - return pageNo;  
119 - }  
120 - public void setPageNo(Integer pageNo) {  
121 - this.pageNo = pageNo;  
122 - }  
123 - public Integer getPageSize() {  
124 - return pageSize;  
125 - }  
126 - public void setPageSize(Integer pageSize) {  
127 - this.pageSize = pageSize;  
128 - }  
129 -  
130 -}  
1 -/**  
2 - *  
3 - */  
4 -package com.yohobuy.platform.mvc.controller;  
5 -  
6 -import javax.annotation.Resource;  
7 -import javax.servlet.http.HttpServletRequest;  
8 -import javax.servlet.http.HttpServletResponse;  
9 -  
10 -import org.apache.commons.lang3.StringUtils;  
11 -import org.slf4j.Logger;  
12 -import org.slf4j.LoggerFactory;  
13 -import org.springframework.stereotype.Controller;  
14 -import org.springframework.web.bind.annotation.RequestMapping;  
15 -  
16 -import com.netflix.config.DynamicPropertyFactory;  
17 -import com.yoho.core.common.utils.MD5;  
18 -import com.yoho.tools.common.beans.Response;  
19 -import com.yohobuy.platform.common.enums.CodeEnum;  
20 -import com.yohobuy.platform.model.users.response.UserInfoResponseBO;  
21 -import com.yohobuy.platform.common.helper.mvc.PlatformConstant;  
22 -import com.yohobuy.platform.mvc.service.ILoginService;  
23 -import com.yohobuy.platform.common.util.SessionUtil;  
24 -  
25 -/**  
26 - * 描述:platform回调cms页面时,验证用户的登录状态  
27 - *  
28 - */  
29 -@Controller  
30 -@RequestMapping("/LoginController")  
31 -public class LoginController {  
32 -  
33 - static Logger log = LoggerFactory.getLogger(LoginController.class);  
34 -  
35 - @Resource  
36 - ILoginService loginService;  
37 -  
38 - private static String SALT= DynamicPropertyFactory.getInstance().getStringProperty("platform.login.salt", "").get();  
39 -  
40 - @RequestMapping("/loginForPid.do")  
41 - public void loginForPid(String pid, String pidMd5, String callbackUrl , HttpServletRequest request, HttpServletResponse response) throws Exception {  
42 - log.info("enter login with pid={},pidAes is {},callbackUrl is {}", pid, pidMd5, callbackUrl);  
43 - if (StringUtils.isEmpty(pid) || StringUtils.isEmpty(pidMd5)) {  
44 - log.warn("loginForPid error. with pid={}, pidMd5={}", pid, pidMd5);  
45 - return;  
46 - }  
47 - UserInfoResponseBO userInfoResponseBO = (UserInfoResponseBO) request.getSession().getAttribute(PlatformConstant.USER_SESSION);  
48 - if (null != userInfoResponseBO && pid.equals(userInfoResponseBO.getPid())) {  
49 - request.setAttribute("pid", pid);  
50 - request.getRequestDispatcher(callbackUrl).forward(request, response);  
51 - } else if (pidMd5.equals(MD5.md5(pid + SALT))) {  
52 - log.info("loginForPid with session is empty. and login start. with pid={}", pid);  
53 - Response<UserInfoResponseBO> responseBO = loginService.loginByPid(pid);  
54 - if (responseBO != null && responseBO.getCode() == CodeEnum.SUCCESS.getCode()) {  
55 - log.info("loginForPid with session is empty. and login success. with pid={}", pid);  
56 - // 登录成功,把用户信息存入redis  
57 - SessionUtil.getOpera().setUser(responseBO.getData());  
58 - request.setAttribute("pid", pid);  
59 - request.getSession().setAttribute(PlatformConstant.USER_SESSION, responseBO.getData());  
60 - request.getRequestDispatcher(callbackUrl).forward(request, response);  
61 - }  
62 - }  
63 - }  
64 -  
65 -}  
1 -package com.yohobuy.platform.mvc.helper;  
2 -  
3 -import com.alibaba.fastjson.JSONObject;  
4 -import com.google.common.collect.Lists;  
5 -import com.netflix.config.DynamicPropertyFactory;  
6 -import com.yoho.tools.common.beans.Response;  
7 -import com.yohobuy.platform.common.enums.CodeEnum;  
8 -import com.yohobuy.platform.common.enums.ErpApiEnum;  
9 -import com.yohobuy.platform.model.users.response.UserInfoResponseBO;  
10 -import com.yohobuy.platform.mvc.bean.ERPProfileRequestBO;  
11 -import org.apache.commons.collections.CollectionUtils;  
12 -import org.apache.commons.collections.MapUtils;  
13 -import org.slf4j.Logger;  
14 -import org.slf4j.LoggerFactory;  
15 -import org.springframework.stereotype.Component;  
16 -import org.springframework.web.client.RestTemplate;  
17 -  
18 -import javax.annotation.Resource;  
19 -import java.util.ArrayList;  
20 -import java.util.List;  
21 -import java.util.Map;  
22 -  
23 -@Component  
24 -public class ErpApiServiceHelper {  
25 -  
26 - static Logger log = LoggerFactory.getLogger(ErpApiServiceHelper.class);  
27 -  
28 - @Resource  
29 - RestTemplate restTemplate;  
30 -  
31 - private static String ERP_DOMAIN = DynamicPropertyFactory.getInstance().getStringProperty("erp.domain", "").get();  
32 - private static String ERP_STORAGE = DynamicPropertyFactory.getInstance().getStringProperty("erp.storage", "").get();  
33 -  
34 -  
35 - /**  
36 - * /account/profile/query_by_id http://192.168.102.47:9098/erp-gateway-web  
37 - /service/account/v1/Profile/getAllBrandProfileDataAuthorityApi http://serve.yohobuy.com  
38 - /account/profile/query_page http://192.168.102.47:9098/erp-gateway-web  
39 - /account/profileDataEntitlement/dataList http://192.168.102.47:9098/erp-gateway-web  
40 - *  
41 - */  
42 -  
43 - /**  
44 - * 根据pid,查询用户  
45 - * @param pid  
46 - * @return  
47 - */  
48 - @SuppressWarnings("unchecked")  
49 - public UserInfoResponseBO getUserByPid(String pid) {  
50 - log.info("getUserByPid with pid={}", pid);  
51 - ERPProfileRequestBO profile = new ERPProfileRequestBO();  
52 - profile.setPid(Integer.parseInt(pid));  
53 -  
54 - Response<Map<String, Object>> resp = restTemplate.postForObject(ERP_DOMAIN + ErpApiEnum.GET_USER_BY_PID.getUrl(), profile, Response.class);  
55 -  
56 - if (resp == null || resp.getCode() != CodeEnum.SUCCESS.getCode()) {  
57 - log.warn("getuserbypid error with pid={}", pid);  
58 - return null;  
59 - }  
60 - UserInfoResponseBO user = toSysUserResponse(resp.getData());  
61 -  
62 - return user;  
63 - }  
64 -  
65 -  
66 - /**  
67 - * 对象转换  
68 - *  
69 - * @param map  
70 - * @return  
71 - */  
72 - private UserInfoResponseBO toSysUserResponse(Map<String, Object> map) {  
73 - if (MapUtils.isEmpty(map)) {  
74 - return null;  
75 - }  
76 - UserInfoResponseBO bo = new UserInfoResponseBO();  
77 -  
78 - bo.setCreate_time(MapUtils.getString(map, "create_time"));  
79 - bo.setEmail(MapUtils.getString(map, "email"));  
80 - bo.setAccount(MapUtils.getString(map, "account"));  
81 - bo.setPhone(MapUtils.getString(map, "phone"));  
82 - bo.setPid(MapUtils.getString(map, "pid"));  
83 - bo.setRole_id(MapUtils.getString(map, "role_id"));  
84 - bo.setStatus(MapUtils.getString(map, "status"));  
85 - bo.setTruename(MapUtils.getString(map, "truename"));  
86 -  
87 - bo.setAuth_site(MapUtils.getString(map, "auth_site"));  
88 - bo.setCreate_date(MapUtils.getString(map, "create_date"));  
89 - bo.setCreate_id(MapUtils.getString(map, "create_id"));  
90 - bo.setDept_id(MapUtils.getString(map, "dept_id"));  
91 - bo.setExpires(MapUtils.getString(map, "expires"));  
92 - bo.setIdentity(MapUtils.getString(map, "identity"));  
93 - bo.setLogin_time(MapUtils.getString(map, "login_time"));  
94 - bo.setLogout_time(MapUtils.getString(map, "logout_time"));  
95 - bo.setStaff_code(MapUtils.getString(map, "staff_code"));  
96 -  
97 - return bo;  
98 - }  
99 -  
100 - /**  
101 - * 北京接口返回:is_all=ture 说明是全品牌,list就是空;is_all = false 说明不是全品牌 品牌id会在list  
102 - * 根据pid,获取用户有品牌权限品牌ID。  
103 - * 如果为-1, 不存在,所有品牌都不展示  
104 - * 如果为空集合,有所有品牌权限  
105 - * 如果不为空 ,有品牌权限品牌ID  
106 - */  
107 - public List<Integer> getBrandIds(String pid) {  
108 - String url = ERP_STORAGE + "/service/account/v1/Profile/getAllBrandProfileDataAuthorityApi";  
109 - try {  
110 - Response<Map<String, Object>> response = restTemplate.postForObject(url, "["+pid+"]", Response.class);  
111 - log.info("call erp method, url:{} and response:{}.", url, response);  
112 - if (response == null || response.getCode() != 200) {  
113 - log.warn("call erp method fail, response:{}.",response);  
114 - // 所有品牌都不展示  
115 - return Lists.newArrayList(-1);  
116 - }  
117 - Map<String,Object> data= (Map<String,Object>) response.getData();  
118 - if ((boolean)data.get("is_all")) {  
119 - //有所有品牌权限  
120 - return Lists.newArrayList();  
121 - }  
122 - Object brandIdData = data.get("list");  
123 - if (brandIdData instanceof List && ((List)brandIdData).isEmpty()) {  
124 - //有所有品牌权限  
125 - return Lists.newArrayList();  
126 - }  
127 - List<Integer> brandIds=Lists.newArrayList();  
128 - List<String> brandIdStrs=(List<String>)brandIdData;  
129 - for (String brandId : brandIdStrs) {  
130 - brandIds.add(Integer.parseInt(brandId));  
131 - }  
132 - return brandIds;  
133 - } catch (Exception e) {  
134 - log.error("call erp method fail, url:{} and error message:{}.", url, e.getMessage());  
135 - // 所有品牌都不展示  
136 - return Lists.newArrayList(-1);  
137 - }  
138 - }  
139 -  
140 - //根据pid获取店铺权限  
141 - public List<Integer> getShopIds(String pid) {  
142 - String url = ERP_DOMAIN + "/account/profileDataEntitlement/dataList";  
143 - List<Integer> list = new ArrayList<>();  
144 - try{  
145 - JSONObject req = new JSONObject();  
146 - req.put("pid",Integer.valueOf(pid));  
147 - req.put("type",2);  
148 - Response<Map<String, Object>> response = restTemplate.postForObject(url, req, Response.class);  
149 - log.info("getShopIds erp method, url:{} and response:{}.", url, response);  
150 - if(response.getCode() != 200){  
151 - log.warn("call erp method fail, response:{}.",response);  
152 - return Lists.newArrayList(-1);  
153 - }  
154 - Map<String,Object> shopsMap = response.getData();  
155 - boolean isAll = (boolean) shopsMap.get("isAll");  
156 - if(isAll){  
157 - //如果是全部权限,这是权限空  
158 - return list;  
159 - }  
160 - List<Map> shopList = (List) shopsMap.get("businessList");  
161 - if (CollectionUtils.isEmpty(shopList)) {  
162 - return Lists.newArrayList(-1);  
163 - }  
164 - for (Map m : shopList){  
165 - list.add(MapUtils.getInteger(m,"id"));  
166 - }  
167 - }catch (Exception e){  
168 - log.info("get shopids from erp-gateway-wab error e={}",e.getMessage());  
169 - return Lists.newArrayList(-1);  
170 - }  
171 - return list;  
172 - }  
173 -  
174 -}  
1 -/**  
2 - *  
3 - */  
4 -package com.yohobuy.platform.mvc.service;  
5 -  
6 -  
7 -import com.yoho.tools.common.beans.Response;  
8 -import com.yohobuy.platform.model.users.response.UserInfoResponseBO;  
9 -  
10 -/**  
11 - * @author ping.huang  
12 - * 2016年8月1日  
13 - */  
14 -public interface ILoginService {  
15 -  
16 - Response<UserInfoResponseBO> loginByPid(String pid);  
17 -}  
1 -/**  
2 - *  
3 - */  
4 -package com.yohobuy.platform.mvc.service.impl;  
5 -  
6 -  
7 -import java.util.List;  
8 -  
9 -import javax.annotation.Resource;  
10 -  
11 -import org.slf4j.Logger;  
12 -import org.slf4j.LoggerFactory;  
13 -import org.springframework.stereotype.Service;  
14 -  
15 -import com.yoho.tools.common.beans.Response;  
16 -import com.yohobuy.platform.model.users.response.UserInfoResponseBO;  
17 -import com.yohobuy.platform.mvc.helper.ErpApiServiceHelper;  
18 -import com.yohobuy.platform.mvc.service.ILoginService;  
19 -  
20 -/**  
21 - * @author ping.huang  
22 - * 2016年8月1日  
23 - */  
24 -@Service  
25 -public class LoginServiceImpl implements ILoginService {  
26 -  
27 - static Logger log = LoggerFactory.getLogger(LoginServiceImpl.class);  
28 -  
29 - @Resource  
30 - ErpApiServiceHelper erpApiServiceHelper;  
31 -  
32 - @Override  
33 - public Response<UserInfoResponseBO> loginByPid(String pid) {  
34 - log.info("loginByPid with pid is {}.", pid);  
35 - UserInfoResponseBO user = erpApiServiceHelper.getUserByPid(pid);  
36 - if(user == null){  
37 - return new Response<>();  
38 - }  
39 - List<Integer> brandIds = erpApiServiceHelper.getBrandIds(pid);  
40 - user.setBrandIds(brandIds);  
41 -  
42 - List<Integer> shopIds = erpApiServiceHelper.getShopIds(pid);  
43 - user.setShopIds(shopIds);  
44 - log.info("loginByPid userInfoResponseBO is {}.", user);  
45 - return new Response<>(user);  
46 - }  
47 -  
48 -}  
1 -package org.mvc;  
2 -  
3 -import junit.framework.Test;  
4 -import junit.framework.TestCase;  
5 -import junit.framework.TestSuite;  
6 -  
7 -/**  
8 - * Unit test for simple App.  
9 - */  
10 -public class AppTest  
11 - extends TestCase  
12 -{  
13 - /**  
14 - * Create the test case  
15 - *  
16 - * @param testName name of the test case  
17 - */  
18 - public AppTest( String testName )  
19 - {  
20 - }  
21 -  
22 - /**  
23 - * @return the suite of tests being tested  
24 - */  
25 - public static Test suite()  
26 - {  
27 - return new TestSuite( AppTest.class );  
28 - }  
29 -  
30 - /**  
31 - * Rigourous Test :-)  
32 - */  
33 - public void testApp()  
34 - {  
35 - assertTrue( true );  
36 - }  
37 -}  
@@ -28,11 +28,6 @@ @@ -28,11 +28,6 @@
28 </dependency> 28 </dependency>
29 <dependency> 29 <dependency>
30 <groupId>com.yoho.dsf.yhplatform</groupId> 30 <groupId>com.yoho.dsf.yhplatform</groupId>
31 - <artifactId>platform-cms-mvc</artifactId>  
32 - <version>${project.version}</version>  
33 - </dependency>  
34 - <dependency>  
35 - <groupId>com.yoho.dsf.yhplatform</groupId>  
36 <artifactId>platform-cms-cms</artifactId> 31 <artifactId>platform-cms-cms</artifactId>
37 <version>${project.version}</version> 32 <version>${project.version}</version>
38 </dependency> 33 </dependency>
@@ -87,7 +82,6 @@ @@ -87,7 +82,6 @@
87 </dependencies> 82 </dependencies>
88 83
89 <modules> 84 <modules>
90 - <module>mvc</module>  
91 <module>cms</module> 85 <module>cms</module>
92 <module>suggest</module> 86 <module>suggest</module>
93 <module>operations</module> 87 <module>operations</module>
@@ -25,10 +25,6 @@ @@ -25,10 +25,6 @@
25 </dependency> 25 </dependency>
26 <dependency> 26 <dependency>
27 <groupId>com.yoho.dsf.yhplatform</groupId> 27 <groupId>com.yoho.dsf.yhplatform</groupId>
28 - <artifactId>platform-cms-mvc</artifactId>  
29 - </dependency>  
30 - <dependency>  
31 - <groupId>com.yoho.dsf.yhplatform</groupId>  
32 <artifactId>platform-cms-operations</artifactId> 28 <artifactId>platform-cms-operations</artifactId>
33 </dependency> 29 </dependency>
34 <dependency> 30 <dependency>