|
|
@@ -0,0 +1,340 @@
|
|
|
+package com.fs.company.controller.newAdv;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+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.entity.LandingPageTemplate;
|
|
|
+import com.fs.newAdv.service.ILandingPageTemplateService;
|
|
|
+import lombok.Data;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 投放页面模板Controller
|
|
|
+ *
|
|
|
+ * @author zhangqin
|
|
|
+ * @date 2025-11-06
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/landing-page-templates")
|
|
|
+@Validated
|
|
|
+public class LandingPageTemplateController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILandingPageTemplateService templateService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询模板列表
|
|
|
+ *
|
|
|
+ * @param page 当前页
|
|
|
+ * @param size 每页大小
|
|
|
+ * @param templateName 模板名称(模糊查询)
|
|
|
+ * @param templateType 模板类型
|
|
|
+ * @param domainId 关联域名ID
|
|
|
+ * @param status 状态
|
|
|
+ * @return 模板列表
|
|
|
+ */
|
|
|
+ @GetMapping("/page")
|
|
|
+ public Result<IPage<LandingPageTemplate>> page(
|
|
|
+ @RequestParam(defaultValue = "1") Integer page,
|
|
|
+ @RequestParam(defaultValue = "10") Integer size,
|
|
|
+ @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={}",
|
|
|
+ page, size, templateName, templateType, domainId, status);
|
|
|
+
|
|
|
+ Page<LandingPageTemplate> pageParam = new Page<>(page, size);
|
|
|
+ LambdaQueryWrapper<LandingPageTemplate> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+
|
|
|
+ if (StrUtil.isNotBlank(templateName)) {
|
|
|
+ queryWrapper.like(LandingPageTemplate::getTemplateName, templateName);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ queryWrapper.orderByDesc(LandingPageTemplate::getCreateTime);
|
|
|
+
|
|
|
+ IPage<LandingPageTemplate> result = templateService.page(pageParam, queryWrapper);
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询所有启用的模板
|
|
|
+ *
|
|
|
+ * @return 模板列表
|
|
|
+ */
|
|
|
+ @GetMapping("/list/enabled")
|
|
|
+ public Result<List<LandingPageTemplate>> listEnabled() {
|
|
|
+ log.info("查询所有启用的模板");
|
|
|
+
|
|
|
+ LambdaQueryWrapper<LandingPageTemplate> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(LandingPageTemplate::getStatus, 1)
|
|
|
+ .orderByDesc(LandingPageTemplate::getCreateTime);
|
|
|
+
|
|
|
+ List<LandingPageTemplate> list = templateService.list(queryWrapper);
|
|
|
+ return Result.success(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据ID查询模板详情
|
|
|
+ *
|
|
|
+ * @param id 模板ID
|
|
|
+ * @return 模板详情
|
|
|
+ */
|
|
|
+ @GetMapping("/{id}")
|
|
|
+ public Result<LandingPageTemplate> getById(@PathVariable String id) {
|
|
|
+ log.info("查询模板详情 | id={}", id);
|
|
|
+
|
|
|
+ LandingPageTemplate template = templateService.getById(id);
|
|
|
+ if (template == null) {
|
|
|
+ return Result.error("模板不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success(template);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增模板
|
|
|
+ *
|
|
|
+ * @param request 模板信息
|
|
|
+ * @return 操作结果
|
|
|
+ */
|
|
|
+ @PostMapping
|
|
|
+ public Result<LandingPageTemplate> create(@RequestBody @Validated TemplateCreateRequest request) {
|
|
|
+ log.info("新增模板 | templateName={}, templateType={}",
|
|
|
+ request.getTemplateName(), request.getTemplateType());
|
|
|
+
|
|
|
+ // 验证JSON格式
|
|
|
+ if (StrUtil.isNotBlank(request.getTemplateData())) {
|
|
|
+ try {
|
|
|
+ JSONUtil.parseObj(request.getTemplateData());
|
|
|
+ } catch (Exception e) {
|
|
|
+ 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);
|
|
|
+ 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("更新成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除模板
|
|
|
+ *
|
|
|
+ * @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("删除成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 启用/禁用模板
|
|
|
+ *
|
|
|
+ * @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("修改成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复制模板
|
|
|
+ *
|
|
|
+ * @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("复制模板失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|