提交 ad7bdcf5 authored 作者: 张光耀's avatar 张光耀

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/diaoyun/zion/chinafrica/enums/PlatformEnum.java
#	src/main/java/com/diaoyun/zion/chinafrica/factory/ItemSpiderFactory.java
# 项目概述
主体框架为spring boot,接口是restful风格,登录使用spring security的token做认证,token使用redis做了存储,数据访问使用mybatis,
数据连接池用druid,数据库为mysql。
# 配置文件
1. application.yml
* 数据库、spring等系统主要配置都在此文件
2. properties/domain.properties
* 自定义的一些配置,比如邮箱、stripe账号、腾讯ai相关的配置等等
3. logback-spring.xml
* 日志配置文件
# 项目层次结构
项目大致分为两个包和相关的资源文件,两个包分别是com.diaoyun.zion.master和com.diaoyun.zion.chinafrica。
1. master这个包下面放的是项目通用的类,比如项目模块配置类、异常处理、spring security相关的东西。
* base 放的是基类
* bo 业务用到的封装类
* captcha 邮箱发送验证码相关的类,源邮箱需要开启 SMTP、POP3服务
* common 公用的功能类,比如redis、管理token相关的类
* config 项目模块注册的配置类。比如redis、mysql扫描、freemarker(生成邮件模板)、swagger文档等等
* dao 数据访问基类
* enums 枚举类
* exception 异常处理相关
* gson。spring boot默认使用jackson 作为将返回结果转化为json字符串的工具类,但是jackson在转化比较复杂的返
回结果时会出问题,而gson可以比较完美的序列化,所以项目中使用gson替代默认的jackson。
* listener 监听器,目前监听订单的过期,再取消订单。为此redis需要确保redis.conf(在redis安装路径下)
已添加配置
```properties
notify-keyspace-events Ex
```
* security 放的是spring security、jwt相关的文件。代码参照以下项目,详细可点击查看
[https://github.com/murraco/spring-boot-jwt](https://github.com/murraco/spring-boot-jwt)
* thread 存放线程相关类,主要是翻译所用多线程
* util 一些工具类
* validator 数据验证相关的类
2. chinafrica放的是非洲app的业务相关的东西
* api 放的是提供给第三方的接口
* bis 业务类,目前有爬虫和stripe支付
* client 登录认证相关
* constant 一些常量
* controller 非洲app业务相关的控制层
* dao 非洲app业务相关的数据访问层
* entity 非洲app业务相关的数据层实体类
* enums 非洲app业务相关的枚举
* factory 工厂类
* service 非洲app业务相关的服务类
* vo 非洲app业务相关的业务数据映射类
3. 资源文件
* mapper 数据库映射文件
* mybatis mybatis配置文件
* properties 自定义的配置文件
* static 静态资源,系统能直接访问目录下的文件
* templates 页面模板文件,目前只有一个邮件模板
* banner.txt 启动显示文字
* logback-spring.xml 日志配置文件
4. test 包
*
# 接口文档地址
[http://localhost:8083/zion/swagger-ui.html](http://localhost:8083/zion/swagger-ui.html)
\ No newline at end of file
package com.diaoyun.zion.chinafrica.bis.impl;
import com.diaoyun.zion.chinafrica.bis.IItemSpider;
import com.diaoyun.zion.chinafrica.enums.PlatformEnum;
import com.diaoyun.zion.chinafrica.vo.ProductResponse;
import com.diaoyun.zion.master.util.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.http.message.BasicHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
/**
* Gap数据爬虫
*/
@Component("gapItemSpider")
public class GapItemSpider implements IItemSpider {
private static Logger logger = LoggerFactory.getLogger(GapItemSpider.class);
//Gap商品详情
private static final String gapUrl="https://apicn.gap.cn/gap/store/product/list/searchProductByCondition.do";
@Override
public JSONObject captureItem(String targetUrl) throws URISyntaxException, IOException, ExecutionException, InterruptedException, TimeoutException {
JSONObject resultObj;
//获取链接中的商品spuCode
String itemId= getItemId(targetUrl);
Map<String,Object> paramMap=new HashMap<>();
JSONArray conditionList=new JSONArray();
JSONObject valueObj =new JSONObject();
JSONObject condition =new JSONObject();
valueObj.put("key","style");
valueObj.put("valueType","basic");
valueObj.put("value",new String [] {itemId});
conditionList.add(valueObj);
condition.put("conditionList",conditionList);
paramMap.put("data",condition);
//获取请求结果
String content = HttpClientUtil.sendPostWithBodyParameter(gapUrl,paramMap);
resultObj=JSONObject.fromObject(content);
if(resultObj.getBoolean("success")) {
//格式化为封装数据
ProductResponse productResponse = SpiderUtil.formatGapProductResponse(resultObj.getJSONObject("data"));
resultObj=JSONObject.fromObject(productResponse);
}
return resultObj;
}
private String getItemId(String targetUrl) {
String spuCode=targetUrl.substring(targetUrl.lastIndexOf("/")+1);
int firstUnder=spuCode.indexOf("_");
int lastUnder=spuCode.lastIndexOf("_");
return spuCode.substring(firstUnder+1,lastUnder);
}
}
package com.diaoyun.zion.chinafrica.bis.impl;
import com.diaoyun.zion.chinafrica.bis.IItemSpider;
import com.diaoyun.zion.chinafrica.enums.PlatformEnum;
import com.diaoyun.zion.chinafrica.vo.ProductResponse;
import com.diaoyun.zion.master.util.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
/**
* Gap数据爬虫
*/
@Component("nikeItemSpider")
public class NikeItemSpider implements IItemSpider {
private static Logger logger = LoggerFactory.getLogger(NikeItemSpider.class);
@Override
public JSONObject captureItem(String targetUrl) throws URISyntaxException, IOException, ExecutionException, InterruptedException, TimeoutException {
JSONObject resultObj;
//获取url中的网页内容 >
String content = HttpClientUtil.getContentByUrl(targetUrl, PlatformEnum.NIKE.getValue());
//获取商品相关信息,详情放在<script> 标签的 window.INITIAL_REDUX_STATE 变量中
resultObj = JsoupUtil.getItemDetailByName(content, "window.INITIAL_REDUX_STATE");
//格式化为封装数据
ProductResponse productResponse = SpiderUtil.formatNikeProductResponse(resultObj);
resultObj = JSONObject.fromObject(productResponse);
return resultObj;
}
}
......@@ -38,8 +38,8 @@ public class TmItemSpider implements IItemSpider {
List<Map<String, Object>> futureList= new ArrayList<>();
//获取url中的网页内容
String content = HttpClientUtil.getContentByUrl(targetUrl,PlatformEnum.TM.getValue());
//获取商品详情
JSONObject infoMap= JsoupUtil.getTmItemDetail(content);
//获取商品详情 观察数据可发现商品数据在 _DATA_Detail 变量中
JSONObject infoMap= JsoupUtil.getItemDetailByName(content,"_DATA_Detail");
JSONObject skuBaseMap= (JSONObject) infoMap.get("skuBase");
if(!(skuBaseMap.get("props") instanceof JSONNull)) {
JSONArray propsArray= (JSONArray) skuBaseMap.get("props");
......
package com.diaoyun.zion.chinafrica.client;
import org.springframework.http.HttpStatus;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
* Filter基类
*
* @author Joe
*/
public abstract class ClientFilter extends ParamFilter implements Filter {
public abstract boolean isAccessAllowed(HttpServletRequest request, HttpServletResponse response)
throws IOException;
protected boolean isAjaxRequest(HttpServletRequest request) {
String requestedWith = request.getHeader("X-Requested-With");
return requestedWith != null ? "XMLHttpRequest".equals(requestedWith) : false;
}
protected void responseJson(HttpServletResponse response, int code, String message) throws IOException {
response.setContentType("application/json;charset=UTF-8");
response.setStatus(HttpStatus.OK.value());
PrintWriter writer = response.getWriter();
writer.write(new StringBuilder().append("{\"code\":").append(code).append(",\"message\":\"").append(message)
.append("\"}").toString());
writer.flush();
writer.close();
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException {
}
@Override
public void destroy() {
}
}
\ No newline at end of file
package com.diaoyun.zion.chinafrica.client;
import com.diaoyun.zion.chinafrica.rpc.AuthenticationRpcService;
/**
* 参数注入Filter
*
* @author Joe
*/
public class ParamFilter {
// 单点登录服务端URL TODO 改为配置
protected String ssoServerUrl="/zion";
// 单点登录服务端提供的RPC服务,由Spring容器注入
protected AuthenticationRpcService authenticationRpcService;
public void setSsoServerUrl(String ssoServerUrl) {
this.ssoServerUrl = ssoServerUrl;
}
public String getSsoServerUrl() {
return ssoServerUrl;
}
public void setAuthenticationRpcService(AuthenticationRpcService authenticationRpcService) {
this.authenticationRpcService = authenticationRpcService;
}
public AuthenticationRpcService getAuthenticationRpcService() {
return authenticationRpcService;
}
}
\ No newline at end of file
package com.diaoyun.zion.chinafrica.client;
import java.io.Serializable;
/**
* 已登录用户信息
*
* @author Joe
*/
public class SessionUser implements Serializable {
private static final long serialVersionUID = 1764365572138947234L;
// 登录用户访问Token
private String token;
// 登录名
private String account;
public SessionUser() {
super();
}
public SessionUser(String token, String account) {
super();
this.token = token;
this.account = account;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
}
package com.diaoyun.zion.chinafrica.client;
import org.springframework.web.util.WebUtils;
import javax.servlet.http.HttpServletRequest;
/**
* 当前已登录用户Session工具
*
* @author Joe
*/
public class SessionUtils {
/**
* 用户信息
*/
public static final String SESSION_USER = "_sessionUser";
/**
* 用户权限
*/
public static final String SESSION_USER_PERMISSION = "_sessionUserPermission";
public static SessionUser getSessionUser(HttpServletRequest request) {
return (SessionUser) WebUtils.getSessionAttribute(request, SESSION_USER);
}
public static void setSessionUser(HttpServletRequest request, SessionUser sessionUser) {
WebUtils.setSessionAttribute(request, SESSION_USER, sessionUser);
}
/*public static SessionPermission getSessionPermission(HttpServletRequest request) {
return (SessionPermission) WebUtils.getSessionAttribute(request, SESSION_USER_PERMISSION);
}*/
/*public static void setSessionPermission(HttpServletRequest request, SessionPermission sessionPermission) {
WebUtils.setSessionAttribute(request, SESSION_USER_PERMISSION, sessionPermission);
}*/
public static void invalidate(HttpServletRequest request){
setSessionUser(request, null);
//setSessionPermission(request, null);
}
}
\ No newline at end of file
package com.diaoyun.zion.chinafrica.client;
import org.apache.http.Consts;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
/**
* 登录及Token验证Filter
* 没做完,暂时不开启
* @author Joe
*/
/*@WebFilter(filterName = "SsoFilter",urlPatterns = {"/*"})*/
public class SsoFilter extends ClientFilter {
// sso授权回调参数token名称
public static final String SSO_TOKEN_NAME = "__vt_param__";
@Override
public boolean isAccessAllowed(HttpServletRequest request, HttpServletResponse response) throws IOException {
String token = getLocalToken(request);
if (token == null) {
token = request.getParameter(SSO_TOKEN_NAME);
if (token != null) {
invokeAuthInfoInSession(request, token);
// 再跳转一次当前URL,以便去掉URL中token参数
response.sendRedirect(getRemoveTokenBackUrl(request));
return false;
}
}
else if (authenticationRpcService.validate(token)) {// 验证token是否有效
return true;
}
redirectLogin(request, response);
return false;
}
/**
* 获取Session中token
*
* @param request
* @return
*/
private String getLocalToken(HttpServletRequest request) {
SessionUser sessionUser = SessionUtils.getSessionUser(request);
return sessionUser == null ? null : sessionUser.getToken();
}
/**
* 存储sessionUser
*
* @param request
* @return
* @throws IOException
*/
private void invokeAuthInfoInSession(HttpServletRequest request, String token) throws IOException {
SessionUser sessionUser = authenticationRpcService.findAuthInfo(token);
if (sessionUser != null) {
SessionUtils.setSessionUser(request, new SessionUser(token, sessionUser.getAccount()));
}
}
/**
* 跳转登录
*
* @param request
* @param response
* @throws IOException
*/
private void
redirectLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
if (isAjaxRequest(request)) {
responseJson(response, SsoResultCode.SSO_TOKEN_ERROR, "未登录或已超时");
}
else {
SessionUtils.invalidate(request);
String backUrl=getBackUrl(request);
String ssoLoginUrl = new StringBuilder().append(ssoServerUrl)
.append("/login?backUrl=").append(URLEncoder.encode(backUrl, Consts.UTF_8.name())).toString();
response.sendRedirect(ssoLoginUrl);
}
}
/**
* 去除返回地址中的token参数
* @param request
* @return
*/
private String getRemoveTokenBackUrl(HttpServletRequest request) {
String backUrl = getBackUrl(request);
return backUrl.substring(0, backUrl.indexOf(SSO_TOKEN_NAME) - 1);
}
/**
* 返回地址
* @param request
* @return
*/
private String getBackUrl(HttpServletRequest request) {
return new StringBuilder().append(request.getRequestURL())
.append(request.getQueryString() == null ? "" : "?" + request.getQueryString()).toString();
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
String path = ((HttpServletRequest) request).getRequestURI();
if (path.contains("/login")||path.contains("/css/")||path.contains("/js/")) {
try {
chain.doFilter(request, response); // 排除的url
} catch (ServletException e) {
e.printStackTrace();
}
} else {
isAccessAllowed(httpRequest,httpResponse);
}
}
@Override
public void destroy() {
}
}
\ No newline at end of file
package com.diaoyun.zion.chinafrica.client;
/**
* 单点登录权限返回码
*
* @author Joe
*/
public class SsoResultCode {
// SSO 用户授权出错
public final static int SSO_TOKEN_ERROR = 1001; // TOKEN未授权或已过期
public final static int SSO_PERMISSION_ERROR = 1002; // 没有访问权限
}
......@@ -24,4 +24,7 @@ public class KeyConstant {
/////////////////订单 END////////////////
//验证码前缀
public final static String CAPTCHA="captcha_";
//自定义id头部
public final static String CUSTOMIZE_ID="customizeId_";
}
......@@ -57,6 +57,8 @@ public class LoginController extends BaseController {
@ApiOperation("第三方登录")
@PostMapping("/thirdParty")
// TODO
@Deprecated
public Result<TbCfUserInfoVo> loginByThirdParty(@ApiParam("第三方账号") @RequestParam(required = false) String amount,
@ApiParam("用户昵称 url编码") @RequestParam(required = false) String nick,
@ApiParam("账号类型") @RequestParam(required = false) String userType) throws UnsupportedEncodingException {
......
......@@ -25,6 +25,7 @@ import java.util.Map;
@Api(tags = "报关类型")
@RestController
@RequestMapping("categoryhs")
@Deprecated
public class TbCfCategoryHsController {
@Autowired
private TbCfCategoryHsService tbCfCategoryHsService;
......
package com.diaoyun.zion.chinafrica.controller;
import com.diaoyun.zion.chinafrica.service.TbCfCouponUseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 使用优惠券记录Controller
*
* @author G
* @date 2019-08-14 09:11:47
*/
@RestController
@RequestMapping("tbcfcouponUse")
public class TbCfCouponUseController {
@Autowired
private TbCfCouponUseService tbCfCouponUseService;
}
package com.diaoyun.zion.chinafrica.controller;
import com.diaoyun.zion.chinafrica.service.TbCfFeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* 手续费Controller
*
* @author G
* @date 2019-08-14 09:11:48
*/
@RestController
@RequestMapping("fee")
public class TbCfFeeController {
@Autowired
private TbCfFeeService tbCfFeeService;
}
package com.diaoyun.zion.chinafrica.controller;
import com.diaoyun.zion.chinafrica.service.TbCfFinanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* 财务明细Controller
*
* @author G
* @date 2019-08-14 09:11:48
*/
@RestController
@RequestMapping("tbcffinance")
public class TbCfFinanceController {
@Autowired
private TbCfFinanceService tbCfFinanceService;
}
package com.diaoyun.zion.chinafrica.controller;
import com.diaoyun.zion.chinafrica.service.TbCfItemOrderRService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* 订单商品对应表Controller
*
* @author G
* @date 2019-08-14 09:11:48
*/
@RestController
@RequestMapping("tbcfitemorderr")
public class TbCfItemOrderRController {
@Autowired
private TbCfItemOrderRService tbCfItemOrderRService;
}
package com.diaoyun.zion.chinafrica.controller;
import com.diaoyun.zion.chinafrica.service.TbCfPlatformOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* 第三方平台对应订单信息Controller
*
* @author G
* @date 2019-08-14 09:11:48
*/
@RestController
@RequestMapping("tbcfplatformorder")
public class TbCfPlatformOrderController {
@Autowired
private TbCfPlatformOrderService tbCfPlatformOrderService;
}
......@@ -2,6 +2,7 @@ package com.diaoyun.zion.chinafrica.controller;
import com.diaoyun.zion.chinafrica.service.TbCfStoreService;
import com.diaoyun.zion.master.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
* @author lipengjun
* @date 2019-09-05 16:51:07
*/
@Api(tags = "店铺独立站")
@RestController
@RequestMapping("/store")
public class TbCfStoreController {
......
package com.diaoyun.zion.chinafrica.controller;
import com.diaoyun.zion.chinafrica.service.TbCfTakeCouponService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 用户领取优惠券列表Controller
*
* @author lipengjun
* @date 2019-08-29 11:33:33
*/
@RestController
@RequestMapping("tbcftakecoupon")
public class TbCfTakeCouponController {
@Autowired
private TbCfTakeCouponService tbCfTakeCouponService;
}
package com.diaoyun.zion.chinafrica.controller;
import com.diaoyun.zion.chinafrica.service.TbCfTaxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* 税费管理Controller
*
* @author G
* @date 2019-08-14 09:11:48
*/
@RestController
@RequestMapping("tbcftax")
public class TbCfTaxController {
@Autowired
private TbCfTaxService tbCfTaxService;
}
......@@ -18,5 +18,5 @@ public interface TbCfStationItemDao extends BaseDao<TbCfStationItemEntity> {
* 获取商品独立站
* @return
*/
List<TbCfPlatformEntity> getItemStationList();
List<TbCfStationItemEntity> getItemStationList();
}
......@@ -18,5 +18,5 @@ public interface TbCfStoreDao extends BaseDao<TbCfStoreEntity> {
* 获取店铺独立站
* @return
*/
List<TbCfPlatformEntity> getStoreStationList();
List<TbCfStoreEntity> getStoreStationList();
}
......@@ -46,7 +46,7 @@ public class TbCfCouponEntity implements Serializable {
/**
* 那些站点可以使用,1111为全部
*/
@ApiModelProperty("些站点可以使用(暂无用)")
@ApiModelProperty("些站点可以使用(暂无用)")
private String withStationId;
/**
* 满多少金额可以使用
......@@ -96,7 +96,7 @@ public class TbCfCouponEntity implements Serializable {
/**
* 有效标志,0无效,1生效,2过期
*/
@ApiModelProperty("有效标志,0无效,1生效,2过期")
@ApiModelProperty("有效标志,0无效,1生效,2过期,暂没完全使用")
private Integer status;
/**
* 创建人
......
......@@ -34,7 +34,7 @@ public class TbCfHomePageEntity implements Serializable {
*/
private String imgUrl;
/**
* 是否支持浏览
* 是否支持浏览,1支持,0不支持
*/
private Integer scanFlag;
/**
......
package com.diaoyun.zion.chinafrica.rpc;
import com.diaoyun.zion.chinafrica.client.SessionUser;
import com.diaoyun.zion.chinafrica.vo.TbCfUserInfoVo;
import java.util.List;
/**
* 身份认证授权服务接口
*
* @author Joe
*/
public interface AuthenticationRpcService {
/**
* 验证是否已经登录
*
* @param token
* 授权码
* @return
*/
boolean validate(String token);
/**
* 根据登录的Token和应用编码获取授权用户信息
*
* @param token
* 授权码
* @return
*/
SessionUser findAuthInfo(String token);
}
package com.diaoyun.zion.chinafrica.rpc.impl;
import com.diaoyun.zion.chinafrica.client.SessionUser;
import com.diaoyun.zion.chinafrica.rpc.AuthenticationRpcService;
import com.diaoyun.zion.chinafrica.vo.TbCfUserInfoVo;
import com.diaoyun.zion.master.common.TokenManager;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service("authenticationRpcService")
public class AuthenticationRpcServiceImpl implements AuthenticationRpcService {
@Resource(name="redisTokenManager")
private TokenManager tokenManager;
@Override
public boolean validate(String token) {
return tokenManager.validate(token) != null;
}
@Override
public SessionUser findAuthInfo(String token) {
TbCfUserInfoVo user = tokenManager.validate(token);
if (user != null) {
return new SessionUser(token,user.getAccount());
}
return null;
}
}
......@@ -47,6 +47,10 @@ public class SpiderServiceImpl implements SpiderService {
platformEnum=PlatformEnum.TB;
} else if(targetUrl.contains("tmall.com/item.htm")) {
platformEnum=PlatformEnum.TM;
} else if(targetUrl.contains("www.gap.cn/pdp/")) {
platformEnum=PlatformEnum.GAP;
} else if(targetUrl.contains("www.nike.com/cn/t/")) {
platformEnum=PlatformEnum.NIKE;
}
return platformEnum;
}
......
......@@ -632,8 +632,8 @@ public class TbCfOrderServiceImpl implements TbCfOrderService {
expressCost = expressCost.multiply(itemNum);
totalExpressCost = totalExpressCost.add(expressCost);
}
/*获取人民币汇率 1美元换取人民币*/
BigDecimal rate = spiderService.getExchangeRate(null);
/*获取人民币汇率 1美元换取人民币 TODO 汇率接口出问题,暂设置为1 */
BigDecimal rate = new BigDecimal(1);//spiderService.getExchangeRate(null);
itemsPrice = itemsPrice.divide(rate, 2, BigDecimal.ROUND_UP);
//计算手续费
BigDecimal fee = countFee(itemsPrice);
......
......@@ -66,8 +66,8 @@ public class TbCfStationItemServiceImpl implements TbCfStationItemService {
public Result getItemStationList(Integer pageNum, Integer pageSize) {
Result<PageInfo> result = new Result<>();
startPage(pageNum,pageSize);
List<TbCfPlatformEntity> tbCfPlatformList=tbCfStationItemDao.getItemStationList();
PageInfo<TbCfPlatformEntity> pageInfo = new PageInfo<>(tbCfPlatformList);
List<TbCfStationItemEntity> tbCfStationItemList=tbCfStationItemDao.getItemStationList();
PageInfo<TbCfStationItemEntity> pageInfo = new PageInfo<>(tbCfStationItemList);
result.setData(pageInfo);
return result;
}
......
......@@ -65,8 +65,8 @@ public class TbCfStoreServiceImpl implements TbCfStoreService {
public Result getStoreStationList(Integer pageNum, Integer pageSize) {
Result<PageInfo> result = new Result<>();
startPage(pageNum,pageSize);
List<TbCfPlatformEntity> tbCfPlatformList=tbCfStoreDao.getStoreStationList();
PageInfo<TbCfPlatformEntity> pageInfo = new PageInfo<>(tbCfPlatformList);
List<TbCfStoreEntity> tbCfStoreList=tbCfStoreDao.getStoreStationList();
PageInfo<TbCfStoreEntity> pageInfo = new PageInfo<>(tbCfStoreList);
result.setData(pageInfo);
return result;
}
......
package com.diaoyun.zion.chinafrica.service.impl;
import com.diaoyun.zion.chinafrica.client.SessionUser;
import com.diaoyun.zion.chinafrica.client.SessionUtils;
import com.diaoyun.zion.chinafrica.constant.EmailTemplateConstant;
import com.diaoyun.zion.chinafrica.constant.KeyConstant;
import com.diaoyun.zion.chinafrica.dao.TbCfCouponDao;
......@@ -20,33 +18,25 @@ import com.diaoyun.zion.master.common.TokenManager;
import com.diaoyun.zion.master.config.DomainProperties;
import com.diaoyun.zion.master.enums.ResultCodeEnum;
import com.diaoyun.zion.master.enums.SexEnum;
import com.diaoyun.zion.master.enums.TrueFalseEnum;
import com.diaoyun.zion.master.enums.UserTypeEnum;
import com.diaoyun.zion.master.exception.ApplicationException;
import com.diaoyun.zion.master.exception.ValidateException;
import com.diaoyun.zion.master.security.JwtTokenProvider;
import com.diaoyun.zion.master.util.*;
import com.diaoyun.zion.master.validator.Validator;
import freemarker.template.TemplateException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.mail.EmailException;
import org.apache.http.Consts;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -357,6 +347,8 @@ public class TbCfUserInfoServiceImpl implements TbCfUserInfoService {
result.setCode(ResultCodeEnum.VALIDATE_ERROR.getCode());
result.setMessage("Verification code error");
} else {
Integer randomCode = RandomCodeHelper.producedRandomCode(6);
captchaRedisCache.set(KeyConstant.CAPTCHA + account, randomCode, 1800);
//authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(loginUser.getAccount(), oldPassword));
TbCfUserInfoEntity existUser = findByAccount(account);
String userId = existUser.getUserId();
......
......@@ -9,5 +9,21 @@ public class DynStock {
//可用总的库存数
private int sellableQuantity;
//sku对应的库存数
private List<ProductSku> sku;
private List<ProductSkuStock> productSkuStockList;
public int getSellableQuantity() {
return sellableQuantity;
}
public void setSellableQuantity(int sellableQuantity) {
this.sellableQuantity = sellableQuantity;
}
public List<ProductSkuStock> getProductSkuStockList() {
return productSkuStockList;
}
public void setProductSkuStockList(List<ProductSkuStock> productSkuStockList) {
this.productSkuStockList = productSkuStockList;
}
}
......@@ -4,7 +4,7 @@ package com.diaoyun.zion.chinafrica.vo;
* 原始价格
*/
public class OriginalPrice {
//sku字符串 ;1627207:425613015;
//sku id标识 ;1627207:425613015;
private String skuStr;
//sku对应价格
private String price;
......
......@@ -4,7 +4,7 @@ package com.diaoyun.zion.chinafrica.vo;
* 商品促销价格
*/
public class ProductPromotion {
//sku字符串 ;1627207:425613015;
//sku id标识 ;1627207:425613015;
private String skuStr;
//sku对应价格
private String price;
......
......@@ -44,4 +44,24 @@ public class ProductProp {
public void setTranslate(String translate) {
this.translate = translate;
}
@Override
public boolean equals(Object obj) {
if(obj==null)
return false;
if(this==obj)
return true;
if(obj instanceof ProductProp) {
ProductProp productProp =(ProductProp) obj;
if(productProp.propId.equals(this.propId)) {
return true;
}
}
return false;
}
@Override
public int hashCode() {
return propId.hashCode();
}
}
package com.diaoyun.zion.chinafrica.vo;
import java.util.List;
import java.util.Set;
/**
* 商品属性list
*/
@Deprecated
public class ProductProps {
//属性名 比如颜色
private String name;
//翻译
private String translate;
//商品属性
private List<ProductProp> prop;
private Set<ProductProp> propSet;
public String getName() {
return name;
......@@ -29,11 +30,11 @@ public class ProductProps {
this.translate = translate;
}
public List<ProductProp> getProp() {
return prop;
public Set<ProductProp> getPropSet() {
return propSet;
}
public void setProp(List<ProductProp> prop) {
this.prop = prop;
public void setPropSet(Set<ProductProp> propSet) {
this.propSet = propSet;
}
}
package com.diaoyun.zion.chinafrica.vo;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 爬取数据后,返回页面的商品详情数据
......@@ -8,36 +10,59 @@ import java.util.List;
public class ProductResponse {
//原始价格 有优惠的话还有优惠价
private List<OriginalPrice> originalPrice;
private List<OriginalPrice> originalPriceList;
//是否包促销价格 true 有促销价格,false\null没有促销价格
private boolean promotionFlag;
//促销价格
private List<ProductPromotion> promotion;
//一口价,就是商品一开始展示的价格,比如多sku的情况下展示 18.80-49.90
private List<ProductPromotion> promotionList;
//原价一口价,就是商品一开始展示的价格,比如多sku多价格的情况下展示 18.80-49.90
private String price;
//促销一口价
private String salePrice;
//是否包含库存信息 有些商品没有库存信息,可以当作是有货 true 有库存信息,false没有
private boolean stockFlag;
//库存
private DynStock dynStock;
//是否包含商品属性,有些商品没有属性
private boolean propFlag;
//商品属性
private List<ProductProps> propList;
//商品属性 颜色:红色,蓝色;尺码:S,l,M
private Map<String, Set<ProductProp>> productPropSet;
//商品信息
private ItemInfo itemInfo;
//商品来源平台 PlatformEnum
private String platform;
public List<OriginalPrice> getOriginalPrice() {
return originalPrice;
public boolean isStockFlag() {
return stockFlag;
}
public void setStockFlag(boolean stockFlag) {
this.stockFlag = stockFlag;
}
public List<OriginalPrice> getOriginalPriceList() {
return originalPriceList;
}
public void setOriginalPriceList(List<OriginalPrice> originalPriceList) {
this.originalPriceList = originalPriceList;
}
public void setOriginalPrice(List<OriginalPrice> originalPrice) {
this.originalPrice = originalPrice;
public List<ProductPromotion> getPromotionList() {
return promotionList;
}
public List<ProductPromotion> getPromotion() {
return promotion;
public String getSalePrice() {
return salePrice;
}
public void setPromotion(List<ProductPromotion> promotion) {
this.promotion = promotion;
public void setSalePrice(String salePrice) {
this.salePrice = salePrice;
}
public void setPromotionList(List<ProductPromotion> promotionList) {
this.promotionList = promotionList;
}
public String getPrice() {
......@@ -64,12 +89,12 @@ public class ProductResponse {
this.propFlag = propFlag;
}
public List<ProductProps> getPropList() {
return propList;
public Map<String, Set<ProductProp>> getProductPropSet() {
return productPropSet;
}
public void setPropList(List<ProductProps> propList) {
this.propList = propList;
public void setProductPropSet(Map<String, Set<ProductProp>> productPropSet) {
this.productPropSet = productPropSet;
}
public ItemInfo getItemInfo() {
......@@ -87,4 +112,12 @@ public class ProductResponse {
public void setPlatform(String platform) {
this.platform = platform;
}
public boolean isPromotionFlag() {
return promotionFlag;
}
public void setPromotionFlag(boolean promotionFlag) {
this.promotionFlag = promotionFlag;
}
}
......@@ -3,11 +3,11 @@ package com.diaoyun.zion.chinafrica.vo;
/**
* sku 库存
*/
public class ProductSku {
//sku拼接的字符串 ;1627207:425613015;
public class ProductSkuStock {
//sku id标识 ;1627207:425613015;
private String skuStr;
//可销售库存数量
private String sellableQuantity;
private int sellableQuantity;
public String getSkuStr() {
return skuStr;
......@@ -17,11 +17,11 @@ public class ProductSku {
this.skuStr = skuStr;
}
public String getSellableQuantity() {
public int getSellableQuantity() {
return sellableQuantity;
}
public void setSellableQuantity(String sellableQuantity) {
public void setSellableQuantity(int sellableQuantity) {
this.sellableQuantity = sellableQuantity;
}
}
......@@ -22,12 +22,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.io.UnsupportedEncodingException;
import java.net.*;
import java.nio.charset.Charset;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class HttpClientUtil {
private static Logger logger = LoggerFactory.getLogger(HttpClientUtil.class);
......@@ -40,6 +40,7 @@ public class HttpClientUtil {
* @throws IOException
*/
public static String getContentByUrl(String sourceUrl, String sourceType) throws URISyntaxException, IOException {
sourceUrl= urlEncode(sourceUrl,Consts.UTF_8.name());
URL url = new URL(sourceUrl);
//构建URI
URI uri=new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null);
......@@ -235,4 +236,25 @@ public class HttpClientUtil {
sibClient.close();
return sibContent;
}
/**
* 对链接进行url编码
* @param url
* @param chartSet
* @return
*/
public static String urlEncode(String url,String chartSet)
{
try {
Matcher matcher = Pattern.compile("[^\\x00-\\xff]").matcher(url);//双字节,包括中文和中文符号[^\x00-\xff] 中文[\u4e00-\u9fa5]
while (matcher.find()) {
String tmp=matcher.group();
url=url.replaceAll(tmp,java.net.URLEncoder.encode(tmp,chartSet));
}
} catch (UnsupportedEncodingException e) {
logger.error("双字节编码异常:", e);
}
return url;
}
}
......@@ -34,7 +34,7 @@ public class JsoupUtil {
String varArr[] = configGroup.split(";");
for (String variable : varArr) {
//获取g_config 变量
Pattern variablePattern = Pattern.compile("(var){1,1}\\s+(g_config){1,1}\\s+={1,1}[\\s\\S]*"); // Regex for the value of the key
Pattern variablePattern = Pattern.compile("(g_config){1,1}\\s+={1,1}[\\s\\S]*"); // Regex for the value of the key
Matcher varMatcher = variablePattern.matcher(variable);
while (varMatcher.find()) {
String configStr = varMatcher.group();
......@@ -87,7 +87,7 @@ public class JsoupUtil {
for (DataNode dataNode : element.dataNodes()) {
String dataStr = dataNode.getWholeData();
//获取带有 g_config 变量的 script 标签
Pattern p = Pattern.compile("(var){1,1}\\s+(" + variableName + "){1,1}\\s+={1,1}[\\s\\S]*(;){1,1}"); // Regex for the value of the key
Pattern p = Pattern.compile("(" + variableName + "){1,1}\\s*={1,1}[\\s\\S]*(;){1,1}"); // Regex for the value of the key
Matcher m = p.matcher(dataStr); // you have to use html here and NOT text! Text will drop the 'key' part
while ((m.find())) {
//System.out.println(m.group());
......@@ -212,33 +212,20 @@ public class JsoupUtil {
}
/**
* 获取天猫商品详情 手机端的,手机端在香港会返回与大陆不一样的页面信息
* 获取变量的值
*
* @param content
* @return
*/
public static JSONObject getTmItemDetail(String content) {
String variableName = "_DATA_Detail";
public static JSONObject getItemDetailByName(String content, String variableName) {
String detailStr = getScriptContent(content, variableName);
//Map<String, String> returnMap = new HashMap<>();
int firstBrackets=detailStr.indexOf("{");
int lastbrackets=detailStr.lastIndexOf("}");
detailStr=detailStr.substring(firstBrackets,lastbrackets+1);
JSONObject dataMap= JSONObject.fromObject(detailStr);
return dataMap;
}
/**
* 获取天猫商品详情
*
* @param content
* @return
*/
/* public static JSONObject getTmItemDetail(String content) {
//String variableName = "TShop.Setup";
String detailStr = getTmScriptContent(content);
JSONObject dataMap= JSONObject.fromObject(detailStr);
return dataMap;
}*/
}
......@@ -154,9 +154,7 @@
<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfUserInfoEntity">
update tb_cf_user_info
<set>
<if test="userNo != null">`user_no` = #{userNo},</if>
<if test="userType != null">`user_type` = #{userType},</if>
<if test="account != null">`account` = #{account},</if>
<if test="avatar != null">`avatar` = #{avatar},</if>
<if test="nick != null">`nick` = #{nick},</if>
<if test="phone != null">`phone` = #{phone},</if>
......@@ -167,7 +165,7 @@
<if test="loginCount != null">`login_count` = #{loginCount},</if>
<if test="email != null">`email` = #{email},</if>
<if test="facebook != null">`facebook` = #{facebook},</if>
<if test="createTime != null">`create_time` = #{createTime},</if>
<if test="sex != null">`sex` = #{sex},</if>
<if test="defaultAddressId != null">`default_address_id` = #{defaultAddressId},</if>
<if test="invitedUserId != null">`invited_user_id` = #{invitedUserId},</if>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论