Merge branch 'master' of http://git.51jingcheng.com/ck/bsd_cases
commit
a408b44076
@ -0,0 +1,3 @@
|
|||||||
|
/.idea/
|
||||||
|
/target/
|
||||||
|
/case.iml
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package com.bsd.cases.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bsd.cases.model.CaseRecommend;
|
||||||
|
import com.bsd.cases.service.CaseRecommendService;
|
||||||
|
import com.bsd.cases.util.AjaxResult;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/case-recommend")
|
||||||
|
public class CaseRecommendController {
|
||||||
|
@Resource
|
||||||
|
private CaseRecommendService caseRecommendService;
|
||||||
|
|
||||||
|
@RequestMapping("/get-case-recommend")
|
||||||
|
public AjaxResult getAllCategory(HttpServletRequest request) {
|
||||||
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
|
List<CaseRecommend> caseRecommendList = caseRecommendService.getCaseRecommend();
|
||||||
|
if (null!=caseRecommendList){
|
||||||
|
ajaxResult.setRetcode(AjaxResult.SUCCESS);
|
||||||
|
ajaxResult.setData(caseRecommendList);
|
||||||
|
}else {
|
||||||
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
||||||
|
}
|
||||||
|
return ajaxResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package com.bsd.cases.mapper;
|
||||||
|
|
||||||
|
import com.bsd.cases.model.CaseRecommend;
|
||||||
|
import com.bsd.cases.util.CommonMapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface CaseRecommendMapper extends CommonMapper<CaseRecommend> {
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.bsd.cases.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("case_recommend")
|
||||||
|
public class CaseRecommend extends BaseEntity{
|
||||||
|
|
||||||
|
private Long contentId;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package com.bsd.cases.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CaseRecommendService<CaseRecommend> extends BaseService<CaseRecommend> {
|
||||||
|
List<CaseRecommend> getCaseRecommend();
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package com.bsd.cases.service.impl;
|
||||||
|
|
||||||
|
import com.bsd.cases.constants.Constants;
|
||||||
|
import com.bsd.cases.mapper.CaseRecommendMapper;
|
||||||
|
import com.bsd.cases.model.CaseRecommend;
|
||||||
|
import com.bsd.cases.service.CaseRecommendService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import tk.mybatis.mapper.entity.Example;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service("caseRecommendService")
|
||||||
|
@Transactional
|
||||||
|
public class CaseRecommendServiceImpl extends BaseServiceImpl<CaseRecommendMapper, CaseRecommend>
|
||||||
|
implements CaseRecommendService<CaseRecommend> {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CaseRecommendMapper caseRecommendMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首页获取banner图
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<CaseRecommend> getCaseRecommend() {
|
||||||
|
Example example = new Example(CaseRecommend.class);
|
||||||
|
Example.Criteria criteria = example.createCriteria();
|
||||||
|
criteria.andEqualTo("state",Constants.STATE_VALID);
|
||||||
|
example.setOrderByClause("sort asc");
|
||||||
|
List<CaseRecommend> caseRecommendList = caseRecommendMapper.selectByExample(example);
|
||||||
|
return caseRecommendList;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,99 +0,0 @@
|
|||||||
package com.bsd.cases.service.impl;
|
|
||||||
|
|
||||||
import com.bsd.cases.service.WxMpConfigStorage;
|
|
||||||
import com.bsd.cases.service.WxMpService;
|
|
||||||
import com.bsd.cases.util.wx.common.bean.WxAccessToken;
|
|
||||||
import com.bsd.cases.util.wx.common.bean.result.WxError;
|
|
||||||
import com.bsd.cases.util.wx.common.exception.WxErrorException;
|
|
||||||
import com.bsd.cases.util.wx.common.session.StandardSessionManager;
|
|
||||||
import com.bsd.cases.util.wx.common.session.WxSessionManager;
|
|
||||||
import com.bsd.cases.util.wx.common.util.crypto.SHA1;
|
|
||||||
|
|
||||||
import org.apache.http.HttpHost;
|
|
||||||
import org.apache.http.client.ClientProtocolException;
|
|
||||||
import org.apache.http.client.config.RequestConfig;
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.impl.client.*;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class WxMpServiceImpl implements WxMpService {
|
|
||||||
|
|
||||||
protected final Logger log = LoggerFactory.getLogger(WxMpServiceImpl.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 全局的是否正在刷新access token的锁
|
|
||||||
*/
|
|
||||||
protected final Object globalAccessTokenRefreshLock = new Object();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 全局的是否正在刷新jsapi_ticket的锁
|
|
||||||
*/
|
|
||||||
protected final Object globalJsapiTicketRefreshLock = new Object();
|
|
||||||
|
|
||||||
protected WxMpConfigStorage wxMpConfigStorage;
|
|
||||||
|
|
||||||
protected CloseableHttpClient httpClient;
|
|
||||||
|
|
||||||
protected HttpHost httpProxy;
|
|
||||||
|
|
||||||
private int retrySleepMillis = 1000;
|
|
||||||
|
|
||||||
private int maxRetryTimes = 5;
|
|
||||||
|
|
||||||
protected WxSessionManager sessionManager = new StandardSessionManager();
|
|
||||||
|
|
||||||
public boolean checkSignature(String timestamp, String nonce, String signature) {
|
|
||||||
try {
|
|
||||||
return SHA1.gen(wxMpConfigStorage.getToken(), timestamp, nonce).equals(signature);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAccessToken() throws WxErrorException {
|
|
||||||
return getAccessToken(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
|
|
||||||
if (forceRefresh) {
|
|
||||||
wxMpConfigStorage.expireAccessToken();
|
|
||||||
}
|
|
||||||
if (wxMpConfigStorage.isAccessTokenExpired()) {
|
|
||||||
synchronized (globalAccessTokenRefreshLock) {
|
|
||||||
if (wxMpConfigStorage.isAccessTokenExpired()) {
|
|
||||||
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential"
|
|
||||||
+ "&appid=" + wxMpConfigStorage.getAppId()
|
|
||||||
+ "&secret=" + wxMpConfigStorage.getSecret();
|
|
||||||
try {
|
|
||||||
HttpGet httpGet = new HttpGet(url);
|
|
||||||
if (httpProxy != null) {
|
|
||||||
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
|
|
||||||
httpGet.setConfig(config);
|
|
||||||
}
|
|
||||||
CloseableHttpResponse response = getHttpclient().execute(httpGet);
|
|
||||||
String resultContent = new BasicResponseHandler().handleResponse(response);
|
|
||||||
WxError error = WxError.fromJson(resultContent);
|
|
||||||
if (error.getErrorCode() != 0) {
|
|
||||||
throw new WxErrorException(error);
|
|
||||||
}
|
|
||||||
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
|
|
||||||
wxMpConfigStorage.updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());
|
|
||||||
} catch (ClientProtocolException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return wxMpConfigStorage.getAccessToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CloseableHttpClient getHttpclient() {
|
|
||||||
return httpClient;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.bsd.cases.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CaseCategoryVo {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Integer level;
|
||||||
|
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
private String parentName;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.bsd.cases.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CaseSearchVo {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
/**
|
||||||
|
* type 是 0 就是category type 是 1 是content
|
||||||
|
*/
|
||||||
|
private Integer type;
|
||||||
|
}
|
||||||
@ -1,5 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.bsd.cases.mapper.CaseCategoryMapper">
|
<mapper namespace="com.bsd.cases.mapper.CaseCategoryMapper">
|
||||||
|
<select id="search" resultType="com.bsd.cases.vo.CaseSearchVo">
|
||||||
|
SELECT id,type,`name`,url FROM (SELECT id , 0 as type,`name`,url FROM case_category
|
||||||
|
union all
|
||||||
|
SELECT id ,1 as type,content_title as `name`,url from case_content ) a
|
||||||
|
WHERE a.`name` LIKE CONCAT('%',#{name},'%')
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Loading…
Reference in New Issue