|
|
@@ -1,5 +1,6 @@
|
|
|
package com.fs.company.controller.newAdv;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
@@ -7,16 +8,24 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.fs.common.result.Result;
|
|
|
import com.fs.newAdv.domain.LandingPageTemplate;
|
|
|
+import com.fs.newAdv.domain.Lead;
|
|
|
+import com.fs.newAdv.domain.Site;
|
|
|
+import com.fs.newAdv.dto.req.LandingIndexReq;
|
|
|
+import com.fs.newAdv.enums.AdvertiserTypeEnum;
|
|
|
import com.fs.newAdv.service.ILandingPageTemplateService;
|
|
|
-import lombok.Data;
|
|
|
+import com.fs.newAdv.service.ILeadService;
|
|
|
+import com.fs.newAdv.service.ISiteService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import javax.validation.constraints.NotBlank;
|
|
|
-import javax.validation.constraints.NotNull;
|
|
|
-import java.util.List;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 投放页面模板Controller
|
|
|
@@ -32,15 +41,16 @@ public class LandingPageTemplateController {
|
|
|
|
|
|
@Autowired
|
|
|
private ILandingPageTemplateService templateService;
|
|
|
+ @Autowired
|
|
|
+ private ISiteService siteService;
|
|
|
+ @Autowired
|
|
|
+ private ILeadService leadService;
|
|
|
|
|
|
/**
|
|
|
* 分页查询模板列表
|
|
|
*
|
|
|
- * @param page 当前页
|
|
|
- * @param size 每页大小
|
|
|
* @param templateName 模板名称(模糊查询)
|
|
|
* @param templateType 模板类型
|
|
|
- * @param domainId 关联域名ID
|
|
|
* @param status 状态
|
|
|
* @return 模板列表
|
|
|
*/
|
|
|
@@ -50,11 +60,8 @@ public class LandingPageTemplateController {
|
|
|
@RequestParam(defaultValue = "10") Integer pageSize,
|
|
|
@RequestParam(required = false) String templateName,
|
|
|
@RequestParam(required = false) String templateType,
|
|
|
- @RequestParam(required = false) Long domainId,
|
|
|
@RequestParam(required = false) Integer status) {
|
|
|
|
|
|
- log.info("分页查询模板列表 | page={}, size={}, templateName={}, templateType={}, domainId={}, status={}",
|
|
|
- pageNum, pageSize, templateName, templateType, domainId, status);
|
|
|
|
|
|
Page<LandingPageTemplate> pageParam = new Page<>(pageNum, pageSize);
|
|
|
LambdaQueryWrapper<LandingPageTemplate> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
@@ -65,9 +72,6 @@ public class LandingPageTemplateController {
|
|
|
if (StrUtil.isNotBlank(templateType)) {
|
|
|
queryWrapper.eq(LandingPageTemplate::getTemplateType, templateType);
|
|
|
}
|
|
|
- if (domainId != null) {
|
|
|
- queryWrapper.eq(LandingPageTemplate::getDomainId, domainId);
|
|
|
- }
|
|
|
if (status != null) {
|
|
|
queryWrapper.eq(LandingPageTemplate::getStatus, status);
|
|
|
}
|
|
|
@@ -86,8 +90,6 @@ public class LandingPageTemplateController {
|
|
|
*/
|
|
|
@GetMapping("/{id}")
|
|
|
public Result<LandingPageTemplate> getById(@PathVariable String id) {
|
|
|
- log.info("查询模板详情 | id={}", id);
|
|
|
-
|
|
|
LandingPageTemplate template = templateService.getById(id);
|
|
|
if (template == null) {
|
|
|
return Result.error("模板不存在");
|
|
|
@@ -103,10 +105,9 @@ public class LandingPageTemplateController {
|
|
|
* @return 操作结果
|
|
|
*/
|
|
|
@PostMapping
|
|
|
- public Result<LandingPageTemplate> create(@RequestBody @Validated TemplateCreateRequest request) {
|
|
|
+ public Result<Void> create(@RequestBody @Validated LandingPageTemplate request) {
|
|
|
log.info("新增模板 | templateName={}, templateType={}",
|
|
|
- request.getTemplateName(), request.getTemplateType());
|
|
|
-
|
|
|
+ request.getTemplateName(), request.getTemplateType());
|
|
|
// 验证JSON格式
|
|
|
if (StrUtil.isNotBlank(request.getTemplateData())) {
|
|
|
try {
|
|
|
@@ -115,209 +116,72 @@ public class LandingPageTemplateController {
|
|
|
return Result.error("模板数据格式不正确,必须是有效的JSON");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- LandingPageTemplate template = new LandingPageTemplate();
|
|
|
- template.setTemplateName(request.getTemplateName());
|
|
|
- template.setTemplateData(request.getTemplateData());
|
|
|
- template.setTemplateType(request.getTemplateType() != null ? request.getTemplateType() : "DEFAULT");
|
|
|
- template.setDomainId(request.getDomainId());
|
|
|
- template.setStatus(request.getStatus() != null ? request.getStatus() : 1);
|
|
|
- template.setRemark(request.getRemark());
|
|
|
-
|
|
|
- boolean success = templateService.save(template);
|
|
|
+ boolean success = templateService.save(request);
|
|
|
if (!success) {
|
|
|
return Result.error("新增模板失败");
|
|
|
}
|
|
|
|
|
|
- log.info("新增模板成功 | id={}", template.getId());
|
|
|
- return Result.success(template);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新模板
|
|
|
- *
|
|
|
- * @param id 模板ID
|
|
|
- * @param request 模板信息
|
|
|
- * @return 操作结果
|
|
|
- */
|
|
|
- @PutMapping("/{id}")
|
|
|
- public Result<String> update(@PathVariable String id,
|
|
|
- @RequestBody @Validated TemplateUpdateRequest request) {
|
|
|
- log.info("更新模板 | id={}, templateName={}", id, request.getTemplateName());
|
|
|
-
|
|
|
- LandingPageTemplate template = templateService.getById(id);
|
|
|
- if (template == null) {
|
|
|
- return Result.error("模板不存在");
|
|
|
- }
|
|
|
-
|
|
|
- // 验证JSON格式
|
|
|
- if (StrUtil.isNotBlank(request.getTemplateData())) {
|
|
|
- try {
|
|
|
- JSONUtil.parseObj(request.getTemplateData());
|
|
|
- } catch (Exception e) {
|
|
|
- return Result.error("模板数据格式不正确,必须是有效的JSON");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- template.setTemplateName(request.getTemplateName());
|
|
|
- template.setTemplateData(request.getTemplateData());
|
|
|
- template.setTemplateType(request.getTemplateType());
|
|
|
- template.setDomainId(request.getDomainId());
|
|
|
- template.setStatus(request.getStatus());
|
|
|
- template.setRemark(request.getRemark());
|
|
|
-
|
|
|
- boolean success = templateService.updateById(template);
|
|
|
- if (!success) {
|
|
|
- return Result.error("更新模板失败");
|
|
|
- }
|
|
|
-
|
|
|
- log.info("更新模板成功 | id={}", id);
|
|
|
- return Result.success("更新成功");
|
|
|
+ return Result.success();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 删除模板
|
|
|
- *
|
|
|
- * @param id 模板ID
|
|
|
- * @return 操作结果
|
|
|
- */
|
|
|
- @DeleteMapping("/{id}")
|
|
|
- public Result<String> delete(@PathVariable String id) {
|
|
|
- log.info("删除模板 | id={}", id);
|
|
|
-
|
|
|
- LandingPageTemplate template = templateService.getById(id);
|
|
|
- if (template == null) {
|
|
|
- return Result.error("模板不存在");
|
|
|
- }
|
|
|
-
|
|
|
- boolean success = templateService.removeById(id);
|
|
|
- if (!success) {
|
|
|
- return Result.error("删除模板失败");
|
|
|
- }
|
|
|
-
|
|
|
- log.info("删除模板成功 | id={}", id);
|
|
|
- return Result.success("删除成功");
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
- * 批量删除模板
|
|
|
- *
|
|
|
- * @param ids 模板ID列表
|
|
|
- * @return 操作结果
|
|
|
+ * 落地页访问
|
|
|
*/
|
|
|
- @DeleteMapping("/batch")
|
|
|
- public Result<String> batchDelete(@RequestBody List<String> ids) {
|
|
|
- log.info("批量删除模板 | ids={}", ids);
|
|
|
-
|
|
|
- if (ids == null || ids.isEmpty()) {
|
|
|
- return Result.error("请选择要删除的模板");
|
|
|
- }
|
|
|
-
|
|
|
- boolean success = templateService.removeByIds(ids);
|
|
|
- if (!success) {
|
|
|
- return Result.error("批量删除模板失败");
|
|
|
- }
|
|
|
-
|
|
|
- log.info("批量删除模板成功 | count={}", ids.size());
|
|
|
- return Result.success("删除成功");
|
|
|
+ @PostMapping("/index")
|
|
|
+ public Result<LandingPageTemplate> track(
|
|
|
+ @Valid @RequestBody LandingIndexReq req) {
|
|
|
+ log.info("落地页访问追踪:req={},params={}", req, req.getAllParams());
|
|
|
+ Long siteId = Long.valueOf(req.getAllParams().get("siteId"));
|
|
|
+ Site byId = siteService.getById(siteId);
|
|
|
+ // 保存落地页访问记录
|
|
|
+ saveLandingIndexTrace(siteId, req.getAllParams());
|
|
|
+ // 查询落地页模板
|
|
|
+ return Result.success(templateService.getById(byId.getLaunchPageId()));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 启用/禁用模板
|
|
|
- *
|
|
|
- * @param id 模板ID
|
|
|
- * @param status 状态(0禁用 1启用)
|
|
|
- * @return 操作结果
|
|
|
- */
|
|
|
- @PutMapping("/{id}/status")
|
|
|
- public Result<String> updateStatus(@PathVariable String id, @RequestParam Integer status) {
|
|
|
- log.info("修改模板状态 | id={}, status={}", id, status);
|
|
|
-
|
|
|
- LandingPageTemplate template = templateService.getById(id);
|
|
|
- if (template == null) {
|
|
|
- return Result.error("模板不存在");
|
|
|
- }
|
|
|
-
|
|
|
- template.setStatus(status);
|
|
|
- boolean success = templateService.updateById(template);
|
|
|
- if (!success) {
|
|
|
- return Result.error("修改状态失败");
|
|
|
- }
|
|
|
-
|
|
|
- log.info("修改模板状态成功 | id={}, status={}", id, status);
|
|
|
- return Result.success("修改成功");
|
|
|
+ public void saveLandingIndexTrace(Long siteId, Map<String, String> allParams) {
|
|
|
+ Site byId = siteService.getById(siteId);
|
|
|
+ Long advertiserId = byId.getAdvertiserId();
|
|
|
+ String traceId = getTraceIdByAdvertiser(Objects.requireNonNull(AdvertiserTypeEnum.getByCode(advertiserId)), allParams);
|
|
|
+ Lead byTraceId = leadService.getByTraceId(traceId);
|
|
|
+ if (ObjectUtil.isEmpty(byTraceId)) {
|
|
|
+ byTraceId = new Lead();
|
|
|
+ byTraceId.setAdvertiserId(advertiserId);
|
|
|
+ byTraceId.setSiteId(siteId);
|
|
|
+ leadService.save(byTraceId);
|
|
|
+ }
|
|
|
+ if (!Objects.equals(byTraceId.getSiteId(), siteId)) {
|
|
|
+ log.info("落地页站点信息异常:{}---{}", byTraceId.getSiteId(), siteId);
|
|
|
+ }
|
|
|
+ if (!Objects.equals(byTraceId.getAdvertiserId(), advertiserId)) {
|
|
|
+ log.info("落地页站点信息异常:{}---{}", byTraceId.getAdvertiserId(), advertiserId);
|
|
|
+ }
|
|
|
+ byTraceId.setLandingPageRawParams(JSONUtil.toJsonStr(allParams));
|
|
|
+ byTraceId.setLandingPageTrigger(1);
|
|
|
+ byTraceId.setLandingPageTs(LocalDateTime.now());
|
|
|
+ byTraceId.setUpdateTime(LocalDateTime.now());
|
|
|
+ leadService.updateById(byTraceId);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 复制模板
|
|
|
- *
|
|
|
- * @param id 源模板ID
|
|
|
- * @return 新模板
|
|
|
- */
|
|
|
- @PostMapping("/{id}/copy")
|
|
|
- public Result<LandingPageTemplate> copyTemplate(@PathVariable String id) {
|
|
|
- log.info("复制模板 | id={}", id);
|
|
|
-
|
|
|
- LandingPageTemplate sourceTemplate = templateService.getById(id);
|
|
|
- if (sourceTemplate == null) {
|
|
|
- return Result.error("源模板不存在");
|
|
|
- }
|
|
|
-
|
|
|
- LandingPageTemplate newTemplate = new LandingPageTemplate();
|
|
|
- newTemplate.setTemplateName(sourceTemplate.getTemplateName() + "_副本");
|
|
|
- newTemplate.setTemplateData(sourceTemplate.getTemplateData());
|
|
|
- newTemplate.setTemplateType(sourceTemplate.getTemplateType());
|
|
|
- newTemplate.setDomainId(sourceTemplate.getDomainId());
|
|
|
- newTemplate.setStatus(0); // 默认禁用
|
|
|
- newTemplate.setRemark(sourceTemplate.getRemark());
|
|
|
|
|
|
- boolean success = templateService.save(newTemplate);
|
|
|
- if (!success) {
|
|
|
- return Result.error("复制模板失败");
|
|
|
+ private String getTraceIdByAdvertiser(AdvertiserTypeEnum byCode, Map<String, String> allParams) {
|
|
|
+ switch (byCode) {
|
|
|
+ case OCEANENGINE:
|
|
|
+ return allParams.get("click_id");
|
|
|
+ case TENCENT:
|
|
|
+ return allParams.get("click_id");
|
|
|
+ case OPPO:
|
|
|
+ return allParams.get("traceId");
|
|
|
+ case BAIDU:
|
|
|
+ return allParams.get("bdVid");
|
|
|
+ case VIVO:
|
|
|
+ return allParams.get("requestId");
|
|
|
+ case IQIYI:
|
|
|
+ return allParams.get("traceId");
|
|
|
+ default:
|
|
|
+ return null;
|
|
|
}
|
|
|
-
|
|
|
- log.info("复制模板成功 | sourceId={}, newId={}", id, newTemplate.getId());
|
|
|
- return Result.success(newTemplate);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 模板创建请求DTO
|
|
|
- */
|
|
|
- @Data
|
|
|
- public static class TemplateCreateRequest {
|
|
|
- @NotBlank(message = "模板名称不能为空")
|
|
|
- private String templateName;
|
|
|
-
|
|
|
- private String templateData;
|
|
|
-
|
|
|
- private String templateType;
|
|
|
-
|
|
|
- private Long domainId;
|
|
|
-
|
|
|
- private Integer status;
|
|
|
-
|
|
|
- private String remark;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 模板更新请求DTO
|
|
|
- */
|
|
|
- @Data
|
|
|
- public static class TemplateUpdateRequest {
|
|
|
- @NotBlank(message = "模板名称不能为空")
|
|
|
- private String templateName;
|
|
|
-
|
|
|
- private String templateData;
|
|
|
-
|
|
|
- @NotBlank(message = "模板类型不能为空")
|
|
|
- private String templateType;
|
|
|
-
|
|
|
- private Long domainId;
|
|
|
-
|
|
|
- @NotNull(message = "状态不能为空")
|
|
|
- private Integer status;
|
|
|
-
|
|
|
- private String remark;
|
|
|
}
|
|
|
}
|
|
|
|