diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/diy/DiyTemplatePlatformEnum.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/diy/DiyTemplatePlatformEnum.java
new file mode 100644
index 000000000..c988b9a22
--- /dev/null
+++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/diy/DiyTemplatePlatformEnum.java
@@ -0,0 +1,56 @@
+package cn.iocoder.yudao.module.promotion.enums.diy;
+
+import cn.iocoder.yudao.framework.common.core.ArrayValuable;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Arrays;
+
+/**
+ * 模板平台
+ * uniPlatform
+ * 条件编译
+ * @author wuKong
+ */
+@AllArgsConstructor
+@Getter
+public enum DiyTemplatePlatformEnum implements ArrayValuable {
+ DEFAULT("","默认"),
+ APP("app", "App"),
+ WEB("web", "Web"),
+ MP_WEIXIN("mp-weixin", "微信小程序"),
+ MP_ALIPAY("mp-alipay", "支付宝小程序"),
+ MP_BAIDU("mp-baidu", "百度小程序"),
+ MP_TOUTIAO("mp-toutiao", "抖音小程序"),
+ MP_LARK("mp-lark", "飞书小程序"),
+ MP_QQ("mp-qq", "QQ小程序"),
+ MP_KUAISHOU("mp-kuaishou", "快手小程序"),
+ MP_JD("mp-jd", "京东小程序"),
+ MP_360("mp-360", "360小程序"),
+ MP_HARMONY("mp-harmony", "鸿蒙元服务"),
+ QUICKAPP_WEBVIEW("quickapp-webview", "快应用通用(包含联盟、华为)"),
+ QUICKAPP_WEBVIEW_UNION("quickapp-webview-union", "快应用联盟"),
+ QUICKAPP_WEBVIEW_HUAWEI("quickapp-webview-huawei", "快应用华为"),
+ //微信小程序/支付宝小程序/百度小程序/抖音小程序/飞书小程序/QQ 小程序/360 小程序/鸿蒙元服务/小红书小程序/京东小程序/快手小程序
+ MP("mp", "小程序"),
+ //OTHER_BUSINESS_SCEN("other-business-scen", "其他自定义业务场景"),
+ ;
+
+ private static final String[] ARRAYS =
+ Arrays.stream(values()).map(DiyTemplatePlatformEnum::getPlatform).toArray(String[]::new);
+ /**
+ * 可以是uniPlatform
+ * 也可以是其他自定义的业务场景
+ */
+ private final String platform;
+
+ /**
+ * name
+ */
+ private final String name;
+
+ @Override
+ public String[] array() {
+ return ARRAYS;
+ }
+}
diff --git a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplateBaseVO.java b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplateBaseVO.java
index 63d1d08ae..177f74ec8 100644
--- a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplateBaseVO.java
+++ b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplateBaseVO.java
@@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template;
+import cn.iocoder.yudao.framework.common.validation.InEnum;
+import cn.iocoder.yudao.module.promotion.enums.diy.DiyTemplatePlatformEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
@@ -23,4 +25,8 @@ public class DiyTemplateBaseVO {
@Schema(description = "预览图", example = "[https://www.iocoder.cn/1.jpg]")
private List previewPicUrls;
+ @Schema(description = "模板平台", requiredMode = Schema.RequiredMode.REQUIRED, example = "默认")
+ @InEnum(DiyTemplatePlatformEnum.class)
+ private String platform;
+
}
diff --git a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePageReqVO.java b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePageReqVO.java
index 1099226f9..9e4e9606f 100644
--- a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePageReqVO.java
+++ b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePageReqVO.java
@@ -20,6 +20,9 @@ public class DiyTemplatePageReqVO extends PageParam {
@Schema(description = "模板名称", example = "默认主题")
private String name;
+ @Schema(description = "模板平台", example = "默认")
+ private String platform;
+
@Schema(description = "是否使用", example = "true")
private Boolean used;
diff --git a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java
index 2146024e8..565155211 100644
--- a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java
+++ b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java
@@ -38,9 +38,11 @@ public class AppDiyTemplateController {
// TODO @疯狂:要不要把 used 和 get 接口合并哈;不传递 id,直接拿默认;
@GetMapping("/used")
@Operation(summary = "使用中的装修模板")
+ @Parameter(name = "platform", description = "装修模板平台", example = "1024")
@PermitAll
- public CommonResult getUsedDiyTemplate() {
- DiyTemplateDO diyTemplate = diyTemplateService.getUsedDiyTemplate();
+ public CommonResult getUsedDiyTemplate(@RequestParam(value = "platform",
+ required = false) String platform) {
+ DiyTemplateDO diyTemplate = diyTemplateService.getUsedDiyTemplate(platform);
return success(buildVo(diyTemplate));
}
diff --git a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyTemplateDO.java b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyTemplateDO.java
index 1b7e1d592..2b06688bb 100644
--- a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyTemplateDO.java
+++ b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/diy/DiyTemplateDO.java
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.diy;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.framework.mybatis.core.type.StringListTypeHandler;
+import cn.iocoder.yudao.module.promotion.enums.diy.DiyTemplatePlatformEnum;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
@@ -38,6 +39,11 @@ public class DiyTemplateDO extends BaseDO {
* 模板名称
*/
private String name;
+ /**
+ * 模板平台
+ * {@link DiyTemplatePlatformEnum}
+ */
+ private String platform;
/**
* 是否使用
*/
diff --git a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyTemplateMapper.java b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyTemplateMapper.java
index ca3c6284e..1a2e29ce4 100644
--- a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyTemplateMapper.java
+++ b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyTemplateMapper.java
@@ -1,10 +1,12 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.diy;
+import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplatePageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO;
+import cn.iocoder.yudao.module.promotion.enums.diy.DiyTemplatePlatformEnum;
import org.apache.ibatis.annotations.Mapper;
/**
@@ -19,6 +21,7 @@ public interface DiyTemplateMapper extends BaseMapperX {
return selectPage(reqVO, new LambdaQueryWrapperX()
.likeIfPresent(DiyTemplateDO::getName, reqVO.getName())
.eqIfPresent(DiyTemplateDO::getUsed, reqVO.getUsed())
+ .eqIfPresent(DiyTemplateDO::getPlatform, reqVO.getPlatform())
.betweenIfPresent(DiyTemplateDO::getUsedTime, reqVO.getUsedTime())
.betweenIfPresent(DiyTemplateDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(DiyTemplateDO::getUsed) // 排序规则1:已使用的排到最前面
@@ -28,6 +31,27 @@ public interface DiyTemplateMapper extends BaseMapperX {
default DiyTemplateDO selectByUsed(boolean used) {
return selectOne(DiyTemplateDO::getUsed, used);
}
+ default DiyTemplateDO selectByUsed(boolean used, String platform) {
+ return selectOne(DiyTemplateDO::getUsed, used, DiyTemplateDO::getPlatform, platform);
+ }
+
+ default DiyTemplateDO selectAppByUsed(boolean used, String platform) {
+ // 没传值(版本过度逻辑)找默认,没找到,取最近一次使用的模板
+ if (ObjectUtil.isNull(platform)) {
+ DiyTemplateDO defaultDiyTemplate = selectByUsed(used, DiyTemplatePlatformEnum.DEFAULT.getPlatform());
+ return ObjectUtil.isNotEmpty(defaultDiyTemplate) ? defaultDiyTemplate : lastUsedTemplate(true);
+ }
+ // 有传值,没找到,取默认
+ DiyTemplateDO diyTemplate = selectByUsed(used, platform);
+ return ObjectUtil.isNotEmpty(diyTemplate) ? diyTemplate : selectByUsed(true, DiyTemplatePlatformEnum.DEFAULT.getPlatform());
+ }
+
+ default DiyTemplateDO lastUsedTemplate(boolean used) {
+ return selectOne(new LambdaQueryWrapperX()
+ .eq(DiyTemplateDO::getUsed, used)
+ .orderByDesc(DiyTemplateDO::getUpdateTime)
+ .last("LIMIT 1"));
+ }
default DiyTemplateDO selectByName(String name) {
return selectOne(DiyTemplateDO::getName, name);
diff --git a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateService.java b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateService.java
index 566e4a75e..0173d51b0 100644
--- a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateService.java
+++ b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateService.java
@@ -72,6 +72,6 @@ public interface DiyTemplateService {
*
* @return 装修模板
*/
- DiyTemplateDO getUsedDiyTemplate();
+ DiyTemplateDO getUsedDiyTemplate(String platform);
}
diff --git a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateServiceImpl.java b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateServiceImpl.java
index 6959e827d..7d3d5fb6c 100644
--- a/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateServiceImpl.java
+++ b/yudao-module-mall/yudao-module-promotion-server/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateServiceImpl.java
@@ -125,10 +125,10 @@ public class DiyTemplateServiceImpl implements DiyTemplateService {
@Override
public void useDiyTemplate(Long id) {
// 校验存在
- validateDiyTemplateExists(id);
+ DiyTemplateDO diyTemplateDO = validateDiyTemplateExists(id);
// TODO @疯狂:要不已使用的情况,抛个业务异常?
- // 已使用的更新为未使用
- DiyTemplateDO used = diyTemplateMapper.selectByUsed(true);
+ // 已使用的更新为未使用,加入模板类型判断
+ DiyTemplateDO used = diyTemplateMapper.selectByUsed(true, diyTemplateDO.getPlatform());
if (used != null) {
// 如果 id 相同,说明未发生变化
if (used.getId().equals(id)) {
@@ -164,8 +164,8 @@ public class DiyTemplateServiceImpl implements DiyTemplateService {
}
@Override
- public DiyTemplateDO getUsedDiyTemplate() {
- return diyTemplateMapper.selectByUsed(true);
+ public DiyTemplateDO getUsedDiyTemplate(String platform) {
+ return diyTemplateMapper.selectAppByUsed(true, platform);
}
}