| | |
| | | import org.aspectj.lang.annotation.*; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | |
| | | if (urls.length == 6) { |
| | | componentCode = urls[4]; |
| | | componentMethod = urls[5]; |
| | | } else { |
| | | componentCode = "api"; |
| | | componentMethod = "callApi"; |
| | | } |
| | | } else if (url.contains("flow")) { //流程处理 |
| | | String[] urls = url.split("/"); |
| | |
| | | } |
| | | } |
| | | pd = PageData.newInstance().builder(userId, userName, this.getToken(request), reqData, componentCode, componentMethod, url, sessionId, appId); |
| | | pd.setMethod(request.getMethod().equals("GET") ? HttpMethod.GET : HttpMethod.POST); |
| | | request.setAttribute(CommonConstant.CONTEXT_PAGE_DATA, pd); |
| | | |
| | | } |
| | | |
| | | @AfterReturning(returning = "ret", pointcut = "dataProcess()") |
| New file |
| | |
| | | package com.java110.front.components.api; |
| | | |
| | | |
| | | import com.java110.core.context.IPageData; |
| | | import com.java110.front.smo.common.ICommonGetSMO; |
| | | import com.java110.front.smo.common.ICommonPostSMO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | |
| | | /** |
| | | * 活动组件管理类 |
| | | * <p> |
| | | * add by wuxw |
| | | * <p> |
| | | * 2019-06-29 |
| | | */ |
| | | @Component("api") |
| | | public class ApiComponent { |
| | | |
| | | @Autowired |
| | | private ICommonGetSMO commonGetSMOImpl; |
| | | |
| | | @Autowired |
| | | private ICommonPostSMO commonPostSMOImpl; |
| | | |
| | | /** |
| | | * 查询活动列表 |
| | | * |
| | | * @param pd 页面数据封装 |
| | | * @return 返回 ResponseEntity 对象 |
| | | */ |
| | | public ResponseEntity<String> callApi(IPageData pd) { |
| | | |
| | | // get方式调用 |
| | | if(HttpMethod.GET == pd.getMethod()){ |
| | | return commonGetSMOImpl.doService(pd); |
| | | } |
| | | //post 方式调用 |
| | | return commonPostSMOImpl.doService(pd); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | |
| | | /** |
| | | * 前台调用api方法 |
| | | * add by wuxw 2020-03-16 |
| | | * |
| | | * @return |
| | | */ |
| | | |
| | | @RequestMapping(path = "/callComponent/{api}") |
| | | public ResponseEntity<String> callApi( |
| | | @PathVariable String api, |
| | | //@RequestBody String info, |
| | | HttpServletRequest request) { |
| | | ResponseEntity<String> responseEntity = null; |
| | | String componentCode = "api"; |
| | | String componentMethod = "callApi"; |
| | | try { |
| | | Assert.hasLength(api, "参数错误,未传入api编码"); |
| | | |
| | | IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA); |
| | | pd.setApiUrl("/api/" + api); |
| | | //权限校验 |
| | | hasPrivilege(restTemplate, pd, "/" + api); |
| | | |
| | | Object componentInstance = ApplicationContextFactory.getBean(componentCode); |
| | | |
| | | Assert.notNull(componentInstance, "未找到组件对应的处理类,请确认 " + componentCode); |
| | | |
| | | Method cMethod = componentInstance.getClass().getDeclaredMethod(componentMethod, IPageData.class); |
| | | |
| | | Assert.notNull(cMethod, "未找到组件对应处理类的方法,请确认 " + componentCode + "方法:" + componentMethod); |
| | | |
| | | |
| | | logger.debug("组件编码{},组件方法{},pd 为{}", componentCode, componentMethod, pd.toString()); |
| | | |
| | | responseEntity = (ResponseEntity<String>) cMethod.invoke(componentInstance, pd); |
| | | |
| | | } catch (SMOException e) { |
| | | /*MultiValueMap<String, String> headers = new HttpHeaders(); |
| | | headers.add("code", e.getResult().getCode());*/ |
| | | logger.error("调用api异常", e); |
| | | responseEntity = new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } catch (Exception e) { |
| | | logger.error("调用api异常", e); |
| | | String msg = ""; |
| | | if (e instanceof InvocationTargetException) { |
| | | Throwable targetEx = ((InvocationTargetException) e).getTargetException(); |
| | | if (targetEx != null) { |
| | | msg = targetEx.getMessage(); |
| | | } |
| | | } else { |
| | | msg = e.getMessage(); |
| | | } |
| | | responseEntity = new ResponseEntity<>(msg, HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } finally { |
| | | logger.debug("api调用返回信息为{}", responseEntity); |
| | | return responseEntity; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 调用组件方法 |
| | | * add by wuxw 2020-03-16 |
| | |
| | | reqData = paramObj.toJSONString(); |
| | | } |
| | | |
| | | IPageData newPd = PageData.newInstance().builder(pd.getUserId(),pd.getUserName(), pd.getToken(), |
| | | IPageData newPd = PageData.newInstance().builder(pd.getUserId(), pd.getUserName(), pd.getToken(), |
| | | reqData, pd.getComponentCode(), pd.getComponentMethod(), "", pd.getSessionId(), ""); |
| | | return newPd; |
| | | } |
| | |
| | | package com.java110.core.context; |
| | | |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | |
| | | /** |
| | |
| | | //设置调用api 服务地址 |
| | | public void setApiUrl(String apiUrl); |
| | | |
| | | public HttpMethod getMethod(); |
| | | |
| | | public void setMethod(HttpMethod method); |
| | | |
| | | /** |
| | | * 构建 pd 对象 |
| | | * @param userId 用户ID |
| | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.utils.util.DateUtil; |
| | | import org.springframework.http.HttpMethod; |
| | | import org.springframework.http.ResponseEntity; |
| | | |
| | | import java.io.Serializable; |
| | |
| | | private String url; |
| | | |
| | | private String apiUrl; |
| | | |
| | | private HttpMethod method; |
| | | |
| | | private ResponseEntity responseEntity; |
| | | |
| | |
| | | public void setApiUrl(String apiUrl) { |
| | | this.apiUrl = apiUrl; |
| | | } |
| | | |
| | | public HttpMethod getMethod() { |
| | | return method; |
| | | } |
| | | |
| | | public void setMethod(HttpMethod method) { |
| | | this.method = method; |
| | | } |
| | | } |
| | |
| | | |
| | | <!-- 保存活动信息 add by wuxw 2018-07-03 --> |
| | | <insert id="saveBusinessActivitiesInfo" parameterType="Map"> |
| | | insert into business_activities( |
| | | collect_count,like_count,title,read_count,user_name,user_id,activities_id,operate,type_cd,context,start_time,end_time,community_id,b_id,header_img,state |
| | | ) values ( |
| | | #{collectCount},#{likeCount},#{title},#{readCount},#{userName},#{userId},#{activitiesId},#{operate},#{typeCd},#{context},#{startTime},#{endTime}, |
| | | #{communityId},#{bId},#{headerImg},#{state} |
| | | ) |
| | | </insert> |
| | | insert into business_activities( |
| | | collect_count,like_count,title,read_count,user_name,user_id,activities_id,operate,type_cd,context,start_time,end_time,community_id,b_id,header_img,state |
| | | ) values ( |
| | | #{collectCount},#{likeCount},#{title},#{readCount},#{userName},#{userId},#{activitiesId},#{operate},#{typeCd},#{context},#{startTime},#{endTime}, |
| | | #{communityId},#{bId},#{headerImg},#{state} |
| | | ) |
| | | </insert> |
| | | |
| | | |
| | | <!-- 查询活动信息(Business) add by wuxw 2018-07-03 --> |