Pre Merge pull request !227 from wuKong/feat(promotion)-添加DIY模板类型功能支持
commit
df7663878f
|
|
@ -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;
|
||||
|
||||
/**
|
||||
* 模板平台
|
||||
* <a href="https://uniapp.dcloud.net.cn/api/system/info.html#uniplatform">uniPlatform</a>
|
||||
* <a href="https://uniapp.dcloud.net.cn/tutorial/platform.html">条件编译</a>
|
||||
* @author wuKong
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum DiyTemplatePlatformEnum implements ArrayValuable<String> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String> previewPicUrls;
|
||||
|
||||
@Schema(description = "模板平台", requiredMode = Schema.RequiredMode.REQUIRED, example = "默认")
|
||||
@InEnum(DiyTemplatePlatformEnum.class)
|
||||
private String platform;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -38,9 +38,11 @@ public class AppDiyTemplateController {
|
|||
// TODO @疯狂:要不要把 used 和 get 接口合并哈;不传递 id,直接拿默认;
|
||||
@GetMapping("/used")
|
||||
@Operation(summary = "使用中的装修模板")
|
||||
@Parameter(name = "platform", description = "装修模板平台", example = "1024")
|
||||
@PermitAll
|
||||
public CommonResult<AppDiyTemplatePropertyRespVO> getUsedDiyTemplate() {
|
||||
DiyTemplateDO diyTemplate = diyTemplateService.getUsedDiyTemplate();
|
||||
public CommonResult<AppDiyTemplatePropertyRespVO> getUsedDiyTemplate(@RequestParam(value = "platform",
|
||||
required = false) String platform) {
|
||||
DiyTemplateDO diyTemplate = diyTemplateService.getUsedDiyTemplate(platform);
|
||||
return success(buildVo(diyTemplate));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
/**
|
||||
* 是否使用
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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<DiyTemplateDO> {
|
|||
return selectPage(reqVO, new LambdaQueryWrapperX<DiyTemplateDO>()
|
||||
.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<DiyTemplateDO> {
|
|||
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<DiyTemplateDO>()
|
||||
.eq(DiyTemplateDO::getUsed, used)
|
||||
.orderByDesc(DiyTemplateDO::getUpdateTime)
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
|
||||
default DiyTemplateDO selectByName(String name) {
|
||||
return selectOne(DiyTemplateDO::getName, name);
|
||||
|
|
|
|||
|
|
@ -72,6 +72,6 @@ public interface DiyTemplateService {
|
|||
*
|
||||
* @return 装修模板
|
||||
*/
|
||||
DiyTemplateDO getUsedDiyTemplate();
|
||||
DiyTemplateDO getUsedDiyTemplate(String platform);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue