营销:接入 APP 装修页面

This commit is contained in:
owen 2024-01-11 11:55:25 +08:00
parent 680718c78f
commit d6b59743a3
3 changed files with 56 additions and 19 deletions

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.promotion.controller.app.diy;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.promotion.controller.app.diy.vo.AppDiyPagePropertyRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO;
import cn.iocoder.yudao.module.promotion.service.diy.DiyPageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "用户 APP - 装修页面")
@RestController
@RequestMapping("/promotion/diy-page")
@Validated
public class AppDiyPageController {
@Resource
private DiyPageService diyPageService;
@GetMapping("/get")
@Operation(summary = "获得装修页面")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
public CommonResult<AppDiyPagePropertyRespVO> getDiyPage(@RequestParam("id") Long id) {
DiyPageDO diyPage = diyPageService.getDiyPage(id);
return success(BeanUtils.toBean(diyPage, AppDiyPagePropertyRespVO.class));
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.promotion.controller.app.diy.vo; package cn.iocoder.yudao.module.promotion.controller.app.diy.vo;
import com.fasterxml.jackson.annotation.JsonRawValue;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.ToString; import lombok.ToString;
@ -16,6 +17,7 @@ public class AppDiyPagePropertyRespVO {
private String name; private String name;
@Schema(description = "页面属性", example = "[]") @Schema(description = "页面属性", example = "[]")
@JsonRawValue
private String property; private String property;
} }

View File

@ -11,11 +11,11 @@ import cn.iocoder.yudao.module.promotion.convert.diy.DiyPageConvert;
import cn.iocoder.yudao.module.promotion.convert.diy.DiyTemplateConvert; import cn.iocoder.yudao.module.promotion.convert.diy.DiyTemplateConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.diy.DiyTemplateMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.diy.DiyTemplateMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -36,7 +36,7 @@ public class DiyTemplateServiceImpl implements DiyTemplateService {
@Resource @Resource
private DiyPageService diyPageService; private DiyPageService diyPageService;
// TODO @疯狂事务 @Transactional(rollbackFor = Exception.class)
@Override @Override
public Long createDiyTemplate(DiyTemplateCreateReqVO createReqVO) { public Long createDiyTemplate(DiyTemplateCreateReqVO createReqVO) {
// 校验名称唯一 // 校验名称唯一
@ -121,8 +121,8 @@ public class DiyTemplateServiceImpl implements DiyTemplateService {
return diyTemplateMapper.selectPage(pageReqVO); return diyTemplateMapper.selectPage(pageReqVO);
} }
@Transactional(rollbackFor = Exception.class)
@Override @Override
// TODO @疯狂事务
public void useDiyTemplate(Long id) { public void useDiyTemplate(Long id) {
// 校验存在 // 校验存在
validateDiyTemplateExists(id); validateDiyTemplateExists(id);
@ -134,10 +134,23 @@ public class DiyTemplateServiceImpl implements DiyTemplateService {
if (used.getId().equals(id)) { if (used.getId().equals(id)) {
return; return;
} }
this.updateUsed(used.getId(), false, null); this.updateTemplateUsed(used.getId(), false, null);
} }
// 更新为已使用 // 更新为已使用
this.updateUsed(id, true, LocalDateTime.now()); this.updateTemplateUsed(id, true, LocalDateTime.now());
}
/**
* 更新模板是否使用
*
* @param id 模板编号
* @param used 是否使用
* @param usedTime 使用时间
*/
private void updateTemplateUsed(Long id, Boolean used, LocalDateTime usedTime) {
DiyTemplateDO updateObj = new DiyTemplateDO().setId(id)
.setUsed(used).setUsedTime(usedTime);
diyTemplateMapper.updateById(updateObj);
} }
@Override @Override
@ -155,18 +168,4 @@ public class DiyTemplateServiceImpl implements DiyTemplateService {
return diyTemplateMapper.selectByUsed(true); return diyTemplateMapper.selectByUsed(true);
} }
// TODO @疯狂挪到 useDiyTemplate 下面改名 updateTemplateUsed 会不会好点哈
/**
* 更新模板是否使用
*
* @param id 模板编号
* @param used 是否使用
* @param usedTime 使用时间
*/
private void updateUsed(Long id, Boolean used, LocalDateTime usedTime) {
DiyTemplateDO updateObj = new DiyTemplateDO().setId(id)
.setUsed(used).setUsedTime(usedTime);
diyTemplateMapper.updateById(updateObj);
}
} }