diff --git a/src/main/java/com/wangym/lombok/job/impl/ExtractJob.java b/src/main/java/com/wangym/lombok/job/impl/ExtractJob.java index 42d6003..cb04a45 100644 --- a/src/main/java/com/wangym/lombok/job/impl/ExtractJob.java +++ b/src/main/java/com/wangym/lombok/job/impl/ExtractJob.java @@ -68,6 +68,7 @@ public Visitable visit(MethodDeclaration n, Void arg) { if (!set.contains(Modifier.publicModifier())) { return null; } + // 公有方法的修饰符去除,本身在接口中的方法就是public的 NodeList newset = NodeList.nodeList(set); newset.remove(Modifier.publicModifier()); diff --git a/src/test/java/com/wangym/lombok/ExtractJobTest.java b/src/test/java/com/wangym/lombok/ExtractJobTest.java index a41721d..965429a 100644 --- a/src/test/java/com/wangym/lombok/ExtractJobTest.java +++ b/src/test/java/com/wangym/lombok/ExtractJobTest.java @@ -22,6 +22,6 @@ public class ExtractJobTest { @Test public void handle() throws IOException { - job.handle(new File("c:/TrackingController.java")); + job.handle(new File("TrackingController.java")); } } diff --git a/src/test/resources/AppFeignClient.java b/src/test/resources/AppFeignClient.java index ae56eca..cdeb627 100644 --- a/src/test/resources/AppFeignClient.java +++ b/src/test/resources/AppFeignClient.java @@ -1,6 +1,6 @@ package cn.jpush.client; -import cn.jpush.portal.client.AppServiceClient; +import com.wangym.portal.client.AppServiceClient; import org.springframework.cloud.openfeign.FeignClient; @FeignClient(value = "portal-base-data-server") diff --git a/src/test/resources/BlackListHelper.java b/src/test/resources/BlackListHelper.java index afc1cc6..9bd3bac 100644 --- a/src/test/resources/BlackListHelper.java +++ b/src/test/resources/BlackListHelper.java @@ -1,7 +1,7 @@ package cn.jpush.http.report.helper; -import cn.jpush.http.report.bean.ExceptionEnum; -import cn.jpush.http.report.exception.BaseException; +import com.wangym.http.report.bean.ExceptionEnum; +import com.wangym.http.report.exception.BaseException; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/src/test/resources/TrackingController.java b/src/test/resources/TrackingController.java new file mode 100644 index 0000000..645f900 --- /dev/null +++ b/src/test/resources/TrackingController.java @@ -0,0 +1,87 @@ +package cn.jpush.jmlink.tracking.controller; + +import com.wangym.jmlink.base.data.common.Constants; +import com.wangym.jmlink.base.data.model.shorturl.ShortUrlParam; +import com.wangym.jmlink.base.data.model.shorturl.ShortUrlResult; +import com.wangym.jmlink.tracking.cache.ShortUrlConfigCache; +import com.wangym.jmlink.tracking.common.RespCode; +import com.wangym.jmlink.tracking.helper.HttpContextHelper; +import com.wangym.jmlink.tracking.model.TrackingEventRequest; +import com.wangym.jmlink.tracking.model.TrackingPayload; +import com.wangym.jmlink.tracking.service.TrackingService; +import com.wangym.jmlink.tracking.utils.IpUtil; +import com.wangym.jmlink.tracking.utils.PlatformUtil; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +@RestController +@RequestMapping("/v1/tracking") +@Slf4j +public class TrackingController { + + @Autowired + private TrackingService trackingService; + @Autowired + private ShortUrlConfigCache shortUrlConfigCache; + + /** + * JS上报接口 + * + * @param param + * @param request + * @return + */ + @ApiOperation(value = "JS上报接口") + @GetMapping(value = "/i") + public ResponseEntity track(@Valid @ModelAttribute TrackingEventRequest param, + HttpServletRequest request) { + String shortUrl = param.getCid(); + if (StringUtils.isBlank(shortUrl)) { + return null; + } + + ShortUrlParam shortUrlParam = new ShortUrlParam(); + shortUrlParam.setShortUrl(shortUrl); + shortUrlParam.setDeleted(Constants.NO); + ShortUrlResult shortUrlResult = shortUrlConfigCache.getConfig(shortUrlParam); + + if (shortUrlResult == null) { + return HttpContextHelper.buildResponse(RespCode.PARAMETER_ERROR); + } + + TrackingPayload trackingPayload = new TrackingPayload(); + + String ip = IpUtil.getRemoteIp(request); + String ua = request.getHeader("User-Agent"); + trackingPayload.setIp(ip); + trackingPayload.setUa(ua); + trackingPayload.setPlatform(PlatformUtil.getPlatform(ua)); + trackingPayload.setItime(System.currentTimeMillis()); + + trackingPayload.setAk(shortUrlResult.getAppKey()); + trackingPayload.setCid(shortUrl); + trackingPayload.setCh(param.getCh().name()); + trackingPayload.setAction(param.getAction().name()); + + log.info("上报数据,appKey:{},trackingPayload:{}", shortUrlResult.getAppKey(), trackingPayload); + + trackingService.tracking(trackingPayload); + return HttpContextHelper.buildResponse(RespCode.OK); + } + + //helloworld method + private void helloworld() { + log.info("helloworld"); + } + +}