Commit 8c40abcc authored by 刘基明's avatar 刘基明

热点数据

parent a98e8975
...@@ -35,9 +35,6 @@ public class ThemeController { ...@@ -35,9 +35,6 @@ public class ThemeController {
@ResponseBody @ResponseBody
public CommonResp<CreateThemeResp> publishTheme(@Validated @RequestBody CreateThemeReq req) { public CommonResp<CreateThemeResp> publishTheme(@Validated @RequestBody CreateThemeReq req) {
String userId = userHolder.getUserId(); String userId = userHolder.getUserId();
if(StringUtils.isEmpty(userId)){
throw new BizException("用户为空");
}
return CommonResp.success(themeManager.publishTheme(req, userId)); return CommonResp.success(themeManager.publishTheme(req, userId));
} }
......
...@@ -73,18 +73,24 @@ public class ThemeManager { ...@@ -73,18 +73,24 @@ public class ThemeManager {
BeanUtils.copyProperties(req, themeEntity); BeanUtils.copyProperties(req, themeEntity);
themeEntity.setAuthorId(userId); themeEntity.setAuthorId(userId);
themeEntity.setContent(JsonUtil.toJson(req.getContent())); themeEntity.setContent(JsonUtil.toJson(req.getContent()));
//保存附件表
List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId());
if (StringUtils.isEmpty(req.getEditThemeId())) { if (StringUtils.isEmpty(req.getEditThemeId())) {
//新建 //新建
themeService.insertTheme(themeEntity); themeService.insertTheme(themeEntity);
themeAttachmentService.insertList(themeAttachments);
} else { } else {
//修改 //修改
themeService.update(themeEntity, req.getEditThemeId()); themeService.update(themeEntity, req.getEditThemeId());
themeEntity.setThemeId(req.getEditThemeId()); themeEntity.setThemeId(req.getEditThemeId());
themeAttachmentService.deleteByThemeId(req.getEditThemeId());
themeAttachmentService.insertList(themeAttachments);
} }
//保存附件表
List<ThemeAttachmentEntity> themeAttachments = ConvertUtil.themeReqToAttachmentList(req, themeEntity.getThemeId());
themeAttachmentService.insertList(themeAttachments);
return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build(); return CreateThemeResp.builder().themeId(themeEntity.getThemeId()).build();
} }
...@@ -311,15 +317,15 @@ public class ThemeManager { ...@@ -311,15 +317,15 @@ public class ThemeManager {
String formerThemeId = themeQo.getFormerThemeId(); String formerThemeId = themeQo.getFormerThemeId();
if (StringUtils.isNotEmpty(formerThemeId)) { if (StringUtils.isNotEmpty(formerThemeId)) {
ThemeQo formerTheme = ConvertUtil.themeEntityToQo2(themeService.queryByThemeId(formerThemeId)); ThemeQo formerTheme = ConvertUtil.themeEntityToQo2(themeService.queryByThemeId(formerThemeId));
if (formerTheme == null) { if (formerTheme != null) {
throw new BizException("转发主题Id错误,id:" + formerThemeId);
}
//单个查询详情 //单个查询详情
productService.getAttachDetail(formerTheme); productService.getAttachDetail(formerTheme);
FormerThemeQo f = ConvertUtil.themeQo2FormerThemeQo(formerTheme); FormerThemeQo f = ConvertUtil.themeQo2FormerThemeQo(formerTheme);
themeQo.setFormerTheme(f); themeQo.setFormerTheme(f);
} }
}
} }
......
package com.tanpu.community.service; package com.tanpu.community.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.dao.entity.community.ThemeAttachmentEntity; import com.tanpu.community.dao.entity.community.ThemeAttachmentEntity;
import com.tanpu.community.dao.mapper.community.ThemeAttachmentMapper; import com.tanpu.community.dao.mapper.community.ThemeAttachmentMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
...@@ -17,14 +18,21 @@ public class ThemeAttachmentService { ...@@ -17,14 +18,21 @@ public class ThemeAttachmentService {
public List<ThemeAttachmentEntity> selectByThemeId(String themeId){ public List<ThemeAttachmentEntity> selectByThemeId(String themeId){
return themeAttachmentMapper.selectList(new LambdaQueryWrapper<ThemeAttachmentEntity>() return themeAttachmentMapper.selectList(new LambdaQueryWrapper<ThemeAttachmentEntity>()
.eq(ThemeAttachmentEntity::getThemeId,themeId)); .eq(ThemeAttachmentEntity::getThemeId,themeId)
.eq(ThemeAttachmentEntity::getDeleteTag,DeleteTagEnum.NOT_DELETED));
} }
@Transactional
public void insertList(List<ThemeAttachmentEntity> themeAttachments) { public void insertList(List<ThemeAttachmentEntity> themeAttachments) {
for (ThemeAttachmentEntity themeAttachment : themeAttachments) { for (ThemeAttachmentEntity themeAttachment : themeAttachments) {
themeAttachmentMapper.insert(themeAttachment); themeAttachmentMapper.insert(themeAttachment);
} }
return; return;
} }
public int deleteByThemeId(String themeId) {
ThemeAttachmentEntity target = ThemeAttachmentEntity.builder().deleteTag(DeleteTagEnum.DELETED.getCode()).build();
LambdaUpdateWrapper<ThemeAttachmentEntity> update = new LambdaUpdateWrapper<ThemeAttachmentEntity>().eq(ThemeAttachmentEntity::getThemeId, themeId);
return themeAttachmentMapper.update(target,update);
}
} }
...@@ -166,12 +166,26 @@ public class ConvertUtil { ...@@ -166,12 +166,26 @@ public class ConvertUtil {
.themeId(themeId) .themeId(themeId)
.build()); .build());
} }
} else { } else if ((content.getType().equals(RelTypeEnum.SINGLE_IMG.type))) {
if (StringUtils.isEmpty(content.getValue())){
list.add(ThemeAttachmentEntity.builder() list.add(ThemeAttachmentEntity.builder()
.attachType(Integer.valueOf(content.getType())) .attachType(Integer.valueOf(content.getType()))
.attachId(content.getValue()) .attachId(content.getValue())
.themeId(themeId) .themeId(themeId)
.build()); .build());
}else {
List<ImagesDTO> imgList = content.getImgList();
for (ImagesDTO imagesDTO : imgList) {
list.add(ThemeAttachmentEntity.builder()
.attachType(Integer.valueOf(RelTypeEnum.SINGLE_IMG.type))
.attachId(imagesDTO.getRelId())
.themeId(themeId)
.build());
}
}
} else {
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment