知识课堂
parent
32061d3d28
commit
663ae7c090
|
|
@ -0,0 +1,165 @@
|
|||
package com.fjrcloud.community.module.community.controller.admin.knowledgeclass;
|
||||
|
||||
import com.fjrcloud.community.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import com.fjrcloud.community.framework.common.pojo.CommonResult;
|
||||
import com.fjrcloud.community.framework.common.pojo.PageParam;
|
||||
import com.fjrcloud.community.framework.common.pojo.PageResult;
|
||||
import com.fjrcloud.community.framework.common.util.object.BeanUtils;
|
||||
import com.fjrcloud.community.framework.excel.core.util.ExcelUtils;
|
||||
import com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo.KnowledgeClassPageReqVO;
|
||||
import com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo.KnowledgeClassRespVO;
|
||||
import com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo.KnowledgeClassSaveReqVO;
|
||||
import com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass.KnowledgeClassDO;
|
||||
import com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass.KnowledgeScopeDO;
|
||||
import com.fjrcloud.community.module.community.dal.mysql.knowledgeclass.KnowledgeScopeMapper;
|
||||
import com.fjrcloud.community.module.community.service.knowledgeclass.KnowledgeClassService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.fjrcloud.community.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static com.fjrcloud.community.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 管理后台 - 知识课堂
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@Tag(name = "管理后台 - 知识课堂")
|
||||
@RestController
|
||||
@RequestMapping("/community/knowledge-class")
|
||||
@Validated
|
||||
public class KnowledgeClassController {
|
||||
|
||||
@Resource
|
||||
private KnowledgeClassService knowledgeClassService;
|
||||
|
||||
@Resource
|
||||
private KnowledgeScopeMapper knowledgeScopeMapper;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建知识课堂")
|
||||
@PreAuthorize("@ss.hasPermission('community:knowledge-class:create')")
|
||||
public CommonResult<Long> createKnowledgeClass(@Valid @RequestBody KnowledgeClassSaveReqVO createReqVO) {
|
||||
return success(knowledgeClassService.createKnowledgeClass(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新知识课堂")
|
||||
@PreAuthorize("@ss.hasPermission('community:knowledge-class:update')")
|
||||
public CommonResult<Boolean> updateKnowledgeClass(@Valid @RequestBody KnowledgeClassSaveReqVO updateReqVO) {
|
||||
knowledgeClassService.updateKnowledgeClass(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除知识课堂")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('community:knowledge-class:delete')")
|
||||
public CommonResult<Boolean> deleteKnowledgeClass(@RequestParam("id") Long id) {
|
||||
knowledgeClassService.deleteKnowledgeClass(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除知识课堂")
|
||||
@PreAuthorize("@ss.hasPermission('community:knowledge-class:delete')")
|
||||
public CommonResult<Boolean> deleteKnowledgeClassList(@RequestParam("ids") List<Long> ids) {
|
||||
knowledgeClassService.deleteKnowledgeClassListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得知识课堂")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('community:knowledge-class:query')")
|
||||
public CommonResult<KnowledgeClassRespVO> getKnowledgeClass(@RequestParam("id") Long id) {
|
||||
KnowledgeClassDO knowledgeClass = knowledgeClassService.getKnowledgeClass(id);
|
||||
KnowledgeClassRespVO respVO = BeanUtils.toBean(knowledgeClass, KnowledgeClassRespVO.class);
|
||||
|
||||
List<KnowledgeScopeDO> scopeList = knowledgeScopeMapper.selectListByKnowledgeId(id);
|
||||
if (scopeList != null && !scopeList.isEmpty()) {
|
||||
List<Long> communityIds = scopeList.stream()
|
||||
.map(KnowledgeScopeDO::getCommunityId)
|
||||
.collect(Collectors.toList());
|
||||
respVO.setCommunityIds(communityIds);
|
||||
|
||||
List<String> communityNames = scopeList.stream()
|
||||
.map(KnowledgeScopeDO::getCommunityName)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
respVO.setCommunityNames(communityNames);
|
||||
}
|
||||
|
||||
return success(respVO);
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得知识课堂分页")
|
||||
@PreAuthorize("@ss.hasPermission('community:knowledge-class:query')")
|
||||
public CommonResult<PageResult<KnowledgeClassRespVO>> getKnowledgeClassPage(@Valid KnowledgeClassPageReqVO pageReqVO) {
|
||||
PageResult<KnowledgeClassDO> pageResult = knowledgeClassService.getKnowledgeClassPage(pageReqVO);
|
||||
PageResult<KnowledgeClassRespVO> respVOPageResult = BeanUtils.toBean(pageResult, KnowledgeClassRespVO.class);
|
||||
|
||||
for (KnowledgeClassRespVO respVO : respVOPageResult.getList()) {
|
||||
List<KnowledgeScopeDO> scopeList = knowledgeScopeMapper.selectListByKnowledgeId(respVO.getId());
|
||||
if (scopeList != null && !scopeList.isEmpty()) {
|
||||
List<Long> communityIds = scopeList.stream()
|
||||
.map(KnowledgeScopeDO::getCommunityId)
|
||||
.collect(Collectors.toList());
|
||||
respVO.setCommunityIds(communityIds);
|
||||
|
||||
List<String> communityNames = scopeList.stream()
|
||||
.map(KnowledgeScopeDO::getCommunityName)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
respVO.setCommunityNames(communityNames);
|
||||
}
|
||||
}
|
||||
|
||||
return success(respVOPageResult);
|
||||
}
|
||||
|
||||
@PutMapping("/publish")
|
||||
@Operation(summary = "发布知识课堂")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('community:knowledge-class:publish')")
|
||||
public CommonResult<Boolean> publishKnowledgeClass(@RequestParam("id") Long id) {
|
||||
knowledgeClassService.publishKnowledgeClass(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/unpublish")
|
||||
@Operation(summary = "下架知识课堂")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('community:knowledge-class:unpublish')")
|
||||
public CommonResult<Boolean> unpublishKnowledgeClass(@RequestParam("id") Long id) {
|
||||
knowledgeClassService.unpublishKnowledgeClass(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出知识课堂 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('community:knowledge-class:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportKnowledgeClassExcel(@Valid KnowledgeClassPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<KnowledgeClassDO> list = knowledgeClassService.getKnowledgeClassPage(pageReqVO).getList();
|
||||
ExcelUtils.write(response, "知识课堂.xls", "数据", KnowledgeClassRespVO.class,
|
||||
BeanUtils.toBean(list, KnowledgeClassRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo;
|
||||
|
||||
import com.fjrcloud.community.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 管理后台 - 知识课堂分页 Request VO
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@Schema(description = "管理后台 - 知识课堂分页 Request VO")
|
||||
@Data
|
||||
public class KnowledgeClassPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "课堂标题", example = "法律知识小课堂")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "是否展示(0-隐藏,1-展示)", example = "1")
|
||||
private Boolean isDisplay;
|
||||
|
||||
@Schema(description = "课堂类型(1-法律小课堂,2-小区治理)", example = "1")
|
||||
private Integer classType;
|
||||
|
||||
@Schema(description = "小区ID", example = "1")
|
||||
private Long communityId;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 管理后台 - 知识课堂 Response VO
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@Schema(description = "管理后台 - 知识课堂 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class KnowledgeClassRespVO {
|
||||
|
||||
@Schema(description = "课堂编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty("编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "课堂标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "法律知识小课堂第一期")
|
||||
@ExcelProperty("课堂标题")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "课堂内容(富文本)", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("课堂内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "封面图片URL", example = "https://xxx.com/image.jpg")
|
||||
@ExcelProperty("封面图片")
|
||||
private String coverImage;
|
||||
|
||||
@Schema(description = "课堂类型(1-法律小课堂,2-小区治理)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty("课堂类型")
|
||||
private Integer classType;
|
||||
|
||||
@Schema(description = "是否展示(0-隐藏,1-展示)", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||
@ExcelProperty("是否展示")
|
||||
private Boolean isDisplay;
|
||||
|
||||
@Schema(description = "浏览次数", example = "100")
|
||||
@ExcelProperty("浏览次数")
|
||||
private Integer viewCount;
|
||||
|
||||
@Schema(description = "点赞数", example = "50")
|
||||
@ExcelProperty("点赞数")
|
||||
private Integer likeCount;
|
||||
|
||||
@Schema(description = "小区ID列表(发布范围)", example = "[1, 2, 3]")
|
||||
private List<Long> communityIds;
|
||||
|
||||
@Schema(description = "小区名称列表", example = "[\"阳光小区\", \"花园小区\"]")
|
||||
private List<String> communityNames;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 管理后台 - 知识课堂新增/修改 Request VO
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@Schema(description = "管理后台 - 知识课堂新增/修改 Request VO")
|
||||
@Data
|
||||
public class KnowledgeClassSaveReqVO {
|
||||
|
||||
@Schema(description = "课堂编号", example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "课堂标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "法律知识小课堂第一期")
|
||||
@NotEmpty(message = "课堂标题不能为空")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "课堂内容(富文本)", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "课堂内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "封面图片URL", example = "https://xxx.com/image.jpg")
|
||||
private String coverImage;
|
||||
|
||||
@Schema(description = "课堂类型(1-法律小课堂,2-小区治理)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "课堂类型不能为空")
|
||||
private Integer classType;
|
||||
|
||||
@Schema(description = "是否展示(0-隐藏,1-展示)", example = "false")
|
||||
private Boolean isDisplay;
|
||||
|
||||
@Schema(description = "小区ID列表(发布范围)", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2, 3]")
|
||||
@NotNull(message = "发布范围不能为空")
|
||||
private List<Long> communityIds;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
package com.fjrcloud.community.module.community.controller.app.knowledgeclass;
|
||||
|
||||
import com.fjrcloud.community.framework.common.pojo.CommonResult;
|
||||
import com.fjrcloud.community.framework.common.pojo.PageResult;
|
||||
import com.fjrcloud.community.framework.common.util.object.BeanUtils;
|
||||
import com.fjrcloud.community.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo.KnowledgeClassPageReqVO;
|
||||
import com.fjrcloud.community.module.community.controller.app.knowledgeclass.vo.AppKnowledgeClassPageReqVO;
|
||||
import com.fjrcloud.community.module.community.controller.app.knowledgeclass.vo.AppKnowledgeClassRespVO;
|
||||
import com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass.KnowledgeClassDO;
|
||||
import com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass.KnowledgeScopeDO;
|
||||
import com.fjrcloud.community.module.community.dal.mysql.knowledgeclass.KnowledgeScopeMapper;
|
||||
import com.fjrcloud.community.module.community.service.knowledgeclass.KnowledgeClassService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.fjrcloud.community.framework.common.pojo.CommonResult.success;
|
||||
|
||||
/**
|
||||
* 用户APP - 知识课堂
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@Tag(name = "用户APP - 知识课堂")
|
||||
@RestController
|
||||
@RequestMapping("/community/knowledge-class")
|
||||
@Validated
|
||||
public class AppKnowledgeClassController {
|
||||
|
||||
@Resource
|
||||
private KnowledgeClassService knowledgeClassService;
|
||||
|
||||
@Resource
|
||||
private KnowledgeScopeMapper knowledgeScopeMapper;
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获取知识课堂分页列表")
|
||||
public CommonResult<PageResult<AppKnowledgeClassRespVO>> getKnowledgeClassPage(@Validated AppKnowledgeClassPageReqVO pageReqVO) {
|
||||
KnowledgeClassPageReqVO adminPageReqVO = new KnowledgeClassPageReqVO();
|
||||
adminPageReqVO.setPageNo(pageReqVO.getPageNo());
|
||||
adminPageReqVO.setPageSize(pageReqVO.getPageSize());
|
||||
adminPageReqVO.setTitle(pageReqVO.getTitle());
|
||||
adminPageReqVO.setCommunityId(pageReqVO.getCommunityId());
|
||||
adminPageReqVO.setClassType(pageReqVO.getClassType());
|
||||
adminPageReqVO.setIsDisplay(true);
|
||||
|
||||
PageResult<KnowledgeClassDO> pageResult = knowledgeClassService.getKnowledgeClassPage(adminPageReqVO);
|
||||
return success(buildAppKnowledgeClassPageResult(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获取知识课堂详情")
|
||||
public CommonResult<AppKnowledgeClassRespVO> getKnowledgeClass(@RequestParam("id") Long id) {
|
||||
knowledgeClassService.incrementViewCount(id);
|
||||
|
||||
KnowledgeClassDO knowledgeClass = knowledgeClassService.getKnowledgeClass(id);
|
||||
return success(buildAppKnowledgeClassRespVO(knowledgeClass));
|
||||
}
|
||||
|
||||
@PostMapping("/like")
|
||||
@Operation(summary = "点赞知识课堂")
|
||||
public CommonResult<Boolean> likeKnowledgeClass(@RequestParam("knowledgeId") Long knowledgeId) {
|
||||
Long memberId = SecurityFrameworkUtils.getLoginUserId();
|
||||
knowledgeClassService.likeKnowledgeClass(knowledgeId, memberId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/unlike")
|
||||
@Operation(summary = "取消点赞知识课堂")
|
||||
public CommonResult<Boolean> unlikeKnowledgeClass(@RequestParam("knowledgeId") Long knowledgeId) {
|
||||
Long memberId = SecurityFrameworkUtils.getLoginUserId();
|
||||
knowledgeClassService.unlikeKnowledgeClass(knowledgeId, memberId);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/liked")
|
||||
@Operation(summary = "是否已点赞")
|
||||
public CommonResult<Boolean> isLiked(@RequestParam("knowledgeId") Long knowledgeId) {
|
||||
Long memberId = SecurityFrameworkUtils.getLoginUserId();
|
||||
boolean liked = knowledgeClassService.isLiked(knowledgeId, memberId);
|
||||
return success(liked);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 App 端知识课堂分页结果
|
||||
*
|
||||
* @param pageResult 分页结果
|
||||
* @return App 端分页结果
|
||||
*/
|
||||
private PageResult<AppKnowledgeClassRespVO> buildAppKnowledgeClassPageResult(PageResult<KnowledgeClassDO> pageResult) {
|
||||
PageResult<AppKnowledgeClassRespVO> respVOPageResult = BeanUtils.toBean(pageResult, AppKnowledgeClassRespVO.class);
|
||||
|
||||
for (int i = 0; i < respVOPageResult.getList().size(); i++) {
|
||||
AppKnowledgeClassRespVO respVO = respVOPageResult.getList().get(i);
|
||||
KnowledgeClassDO knowledgeClass = pageResult.getList().get(i);
|
||||
fillAppKnowledgeClassRespVO(respVO, knowledgeClass);
|
||||
}
|
||||
|
||||
return respVOPageResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 App 端知识课堂响应对象
|
||||
*
|
||||
* @param knowledgeClass 知识课堂 DO
|
||||
* @return App 端响应 VO
|
||||
*/
|
||||
private AppKnowledgeClassRespVO buildAppKnowledgeClassRespVO(KnowledgeClassDO knowledgeClass) {
|
||||
AppKnowledgeClassRespVO respVO = BeanUtils.toBean(knowledgeClass, AppKnowledgeClassRespVO.class);
|
||||
fillAppKnowledgeClassRespVO(respVO, knowledgeClass);
|
||||
return respVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充 App 端知识课堂响应对象
|
||||
*
|
||||
* @param respVO 响应 VO
|
||||
* @param knowledgeClass 知识课堂 DO
|
||||
*/
|
||||
private void fillAppKnowledgeClassRespVO(AppKnowledgeClassRespVO respVO, KnowledgeClassDO knowledgeClass) {
|
||||
Long memberId = SecurityFrameworkUtils.getLoginUserId();
|
||||
boolean liked = knowledgeClassService.isLiked(knowledgeClass.getId(), memberId);
|
||||
respVO.setLiked(liked);
|
||||
|
||||
List<KnowledgeScopeDO> scopeList = knowledgeScopeMapper.selectListByKnowledgeId(respVO.getId());
|
||||
if (scopeList != null && !scopeList.isEmpty()) {
|
||||
List<String> communityNames = scopeList.stream()
|
||||
.map(KnowledgeScopeDO::getCommunityName)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
respVO.setCommunityNames(communityNames);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.fjrcloud.community.module.community.controller.app.knowledgeclass.vo;
|
||||
|
||||
import com.fjrcloud.community.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户APP - 知识课堂分页 Request VO
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@Schema(description = "用户APP - 知识课堂分页 Request VO")
|
||||
@Data
|
||||
public class AppKnowledgeClassPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "课堂标题", example = "法律知识")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "课堂类型(1-法律小课堂,2-小区治理)", example = "1")
|
||||
private Integer classType;
|
||||
|
||||
@Schema(description = "小区ID", example = "1")
|
||||
private Long communityId;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package com.fjrcloud.community.module.community.controller.app.knowledgeclass.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户APP - 知识课堂 Response VO
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@Schema(description = "用户APP - 知识课堂 Response VO")
|
||||
@Data
|
||||
public class AppKnowledgeClassRespVO {
|
||||
|
||||
@Schema(description = "课堂编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "课堂标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "法律知识小课堂第一期")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "课堂内容(富文本)", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String content;
|
||||
|
||||
@Schema(description = "封面图片URL", example = "https://xxx.com/image.jpg")
|
||||
private String coverImage;
|
||||
|
||||
@Schema(description = "课堂类型(1-法律小课堂,2-小区治理)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer classType;
|
||||
|
||||
@Schema(description = "浏览次数", example = "100")
|
||||
private Integer viewCount;
|
||||
|
||||
@Schema(description = "点赞数", example = "50")
|
||||
private Integer likeCount;
|
||||
|
||||
@Schema(description = "是否已点赞", example = "true")
|
||||
private Boolean liked;
|
||||
|
||||
@Schema(description = "小区名称列表", example = "[\"阳光小区\", \"花园小区\"]")
|
||||
private List<String> communityNames;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fjrcloud.community.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 知识课堂 DO
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@TableName("comm_knowledge_class")
|
||||
@KeySequence("comm_knowledge_class_seq")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class KnowledgeClassDO extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
private String title;
|
||||
|
||||
private String content;
|
||||
|
||||
private String coverImage;
|
||||
|
||||
private Integer classType;
|
||||
|
||||
private Integer viewCount;
|
||||
|
||||
private Integer likeCount;
|
||||
|
||||
private Boolean isDisplay;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fjrcloud.community.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 知识课堂点赞记录 DO
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@TableName("comm_knowledge_like")
|
||||
@KeySequence("comm_knowledge_like_seq")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class KnowledgeLikeDO extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
private Long knowledgeId;
|
||||
|
||||
private Long memberId;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fjrcloud.community.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 知识课堂小区关联 DO
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@TableName("comm_knowledge_scope")
|
||||
@KeySequence("comm_knowledge_scope_seq")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class KnowledgeScopeDO extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
private Long knowledgeId;
|
||||
|
||||
private Long communityId;
|
||||
|
||||
private String communityName;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.fjrcloud.community.module.community.dal.mysql.knowledgeclass;
|
||||
|
||||
import com.fjrcloud.community.framework.common.pojo.PageResult;
|
||||
import com.fjrcloud.community.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.fjrcloud.community.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo.KnowledgeClassPageReqVO;
|
||||
import com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass.KnowledgeClassDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 知识课堂 Mapper
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@Mapper
|
||||
public interface KnowledgeClassMapper extends BaseMapperX<KnowledgeClassDO> {
|
||||
|
||||
/**
|
||||
* 分页查询知识课堂列表
|
||||
*
|
||||
* @param reqVO 分页查询条件
|
||||
* @return 分页结果
|
||||
*/
|
||||
default PageResult<KnowledgeClassDO> selectPage(KnowledgeClassPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<KnowledgeClassDO>()
|
||||
.likeIfPresent(KnowledgeClassDO::getTitle, reqVO.getTitle())
|
||||
.eqIfPresent(KnowledgeClassDO::getIsDisplay, reqVO.getIsDisplay())
|
||||
.eqIfPresent(KnowledgeClassDO::getClassType, reqVO.getClassType())
|
||||
.apply(reqVO.getCommunityId() != null,
|
||||
"EXISTS (SELECT 1 FROM comm_knowledge_scope WHERE knowledge_id = comm_knowledge_class.id AND community_id = {0})",
|
||||
reqVO.getCommunityId())
|
||||
.orderByDesc(KnowledgeClassDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package com.fjrcloud.community.module.community.dal.mysql.knowledgeclass;
|
||||
|
||||
import com.fjrcloud.community.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass.KnowledgeLikeDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 知识课堂点赞记录 Mapper
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@Mapper
|
||||
public interface KnowledgeLikeMapper extends BaseMapperX<KnowledgeLikeDO> {
|
||||
|
||||
/**
|
||||
* 根据知识课堂ID和会员ID查询点赞记录
|
||||
*
|
||||
* @param knowledgeId 知识课堂ID
|
||||
* @param memberId 会员ID
|
||||
* @return 点赞记录
|
||||
*/
|
||||
default KnowledgeLikeDO selectByKnowledgeIdAndMemberId(Long knowledgeId, Long memberId) {
|
||||
return selectOne(KnowledgeLikeDO::getKnowledgeId, knowledgeId,
|
||||
KnowledgeLikeDO::getMemberId, memberId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据知识课堂ID统计点赞数
|
||||
*
|
||||
* @param knowledgeId 知识课堂ID
|
||||
* @return 点赞数
|
||||
*/
|
||||
default Long selectCountByKnowledgeId(Long knowledgeId) {
|
||||
return selectCount(KnowledgeLikeDO::getKnowledgeId, knowledgeId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package com.fjrcloud.community.module.community.dal.mysql.knowledgeclass;
|
||||
|
||||
import com.fjrcloud.community.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass.KnowledgeScopeDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 知识课堂小区关联 Mapper
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@Mapper
|
||||
public interface KnowledgeScopeMapper extends BaseMapperX<KnowledgeScopeDO> {
|
||||
|
||||
/**
|
||||
* 根据知识课堂ID查询小区关联列表
|
||||
*
|
||||
* @param knowledgeId 知识课堂ID
|
||||
* @return 小区关联列表
|
||||
*/
|
||||
default List<KnowledgeScopeDO> selectListByKnowledgeId(Long knowledgeId) {
|
||||
return selectList(KnowledgeScopeDO::getKnowledgeId, knowledgeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据知识课堂ID物理删除关联(真删除)
|
||||
*
|
||||
* @param knowledgeId 知识课堂ID
|
||||
* @return 删除数量
|
||||
*/
|
||||
default int deleteByKnowledgeId(Long knowledgeId) {
|
||||
List<KnowledgeScopeDO> list = selectList(KnowledgeScopeDO::getKnowledgeId, knowledgeId);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (KnowledgeScopeDO scope : list) {
|
||||
count += deleteAbsoluteById(scope.getId());
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入知识课堂小区关联
|
||||
*
|
||||
* @param knowledgeId 知识课堂ID
|
||||
* @param communityIds 小区ID列表
|
||||
* @param communityNames 小区名称列表
|
||||
* @return 插入数量
|
||||
*/
|
||||
default int insertBatch(Long knowledgeId, List<Long> communityIds, List<String> communityNames) {
|
||||
if (communityIds == null || communityIds.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < communityIds.size(); i++) {
|
||||
KnowledgeScopeDO scope = new KnowledgeScopeDO();
|
||||
scope.setKnowledgeId(knowledgeId);
|
||||
scope.setCommunityId(communityIds.get(i));
|
||||
if (communityNames != null && i < communityNames.size()) {
|
||||
scope.setCommunityName(communityNames.get(i));
|
||||
}
|
||||
count += insert(scope);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -44,4 +44,10 @@ public interface ErrorCodeConstants {
|
|||
|
||||
ErrorCode COMMUNITY_POST_NOT_DRAFT = new ErrorCode(2_005_000_001, "只有草稿状态的动态才能修改");
|
||||
|
||||
ErrorCode KNOWLEDGE_CLASS_NOT_EXISTS = new ErrorCode(2_006_000_000, "知识课堂不存在");
|
||||
|
||||
ErrorCode KNOWLEDGE_ALREADY_LIKED = new ErrorCode(2_006_000_001, "已经点赞过了");
|
||||
|
||||
ErrorCode KNOWLEDGE_NOT_LIKED = new ErrorCode(2_006_000_002, "还未点赞");
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,109 @@
|
|||
package com.fjrcloud.community.module.community.service.knowledgeclass;
|
||||
|
||||
import com.fjrcloud.community.framework.common.pojo.PageResult;
|
||||
import com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo.KnowledgeClassPageReqVO;
|
||||
import com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo.KnowledgeClassSaveReqVO;
|
||||
import com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass.KnowledgeClassDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 知识课堂 Service 接口
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
public interface KnowledgeClassService {
|
||||
|
||||
/**
|
||||
* 创建知识课堂
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createKnowledgeClass(@Valid KnowledgeClassSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新知识课堂
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateKnowledgeClass(@Valid KnowledgeClassSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除知识课堂
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteKnowledgeClass(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除知识课堂
|
||||
*
|
||||
* @param ids 编号列表
|
||||
*/
|
||||
void deleteKnowledgeClassListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得知识课堂
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 知识课堂
|
||||
*/
|
||||
KnowledgeClassDO getKnowledgeClass(Long id);
|
||||
|
||||
/**
|
||||
* 获得知识课堂分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 知识课堂分页
|
||||
*/
|
||||
PageResult<KnowledgeClassDO> getKnowledgeClassPage(KnowledgeClassPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 发布知识课堂
|
||||
*
|
||||
* @param id 知识课堂ID
|
||||
*/
|
||||
void publishKnowledgeClass(Long id);
|
||||
|
||||
/**
|
||||
* 下架知识课堂
|
||||
*
|
||||
* @param id 知识课堂ID
|
||||
*/
|
||||
void unpublishKnowledgeClass(Long id);
|
||||
|
||||
/**
|
||||
* 增加知识课堂浏览次数
|
||||
*
|
||||
* @param id 知识课堂ID
|
||||
*/
|
||||
void incrementViewCount(Long id);
|
||||
|
||||
/**
|
||||
* 点赞知识课堂
|
||||
*
|
||||
* @param knowledgeId 知识课堂ID
|
||||
* @param memberId 会员ID
|
||||
*/
|
||||
void likeKnowledgeClass(Long knowledgeId, Long memberId);
|
||||
|
||||
/**
|
||||
* 取消点赞知识课堂
|
||||
*
|
||||
* @param knowledgeId 知识课堂ID
|
||||
* @param memberId 会员ID
|
||||
*/
|
||||
void unlikeKnowledgeClass(Long knowledgeId, Long memberId);
|
||||
|
||||
/**
|
||||
* 是否已点赞
|
||||
*
|
||||
* @param knowledgeId 知识课堂ID
|
||||
* @param memberId 会员ID
|
||||
* @return 是否已点赞
|
||||
*/
|
||||
boolean isLiked(Long knowledgeId, Long memberId);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,260 @@
|
|||
package com.fjrcloud.community.module.community.service.knowledgeclass;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.fjrcloud.community.framework.common.exception.ErrorCode;
|
||||
import com.fjrcloud.community.framework.common.pojo.PageResult;
|
||||
import com.fjrcloud.community.framework.common.util.object.BeanUtils;
|
||||
import com.fjrcloud.community.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.fjrcloud.community.framework.tenant.core.context.TenantContextHolder;
|
||||
import com.fjrcloud.community.framework.tenant.core.util.TenantUtils;
|
||||
import com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo.KnowledgeClassPageReqVO;
|
||||
import com.fjrcloud.community.module.community.controller.admin.knowledgeclass.vo.KnowledgeClassSaveReqVO;
|
||||
import com.fjrcloud.community.module.community.dal.dataobject.community.CommunityDO;
|
||||
import com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass.KnowledgeClassDO;
|
||||
import com.fjrcloud.community.module.community.dal.dataobject.knowledgeclass.KnowledgeLikeDO;
|
||||
import com.fjrcloud.community.module.community.dal.mysql.community.CommunityMapper;
|
||||
import com.fjrcloud.community.module.community.dal.mysql.knowledgeclass.KnowledgeClassMapper;
|
||||
import com.fjrcloud.community.module.community.dal.mysql.knowledgeclass.KnowledgeLikeMapper;
|
||||
import com.fjrcloud.community.module.community.dal.mysql.knowledgeclass.KnowledgeScopeMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.fjrcloud.community.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.fjrcloud.community.module.community.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 知识课堂 Service 实现类
|
||||
*
|
||||
* @author fjrcloud
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class KnowledgeClassServiceImpl implements KnowledgeClassService {
|
||||
|
||||
/**
|
||||
* 超级管理员租户ID
|
||||
*/
|
||||
private static final Long SYSTEM_TENANT_ID = 1L;
|
||||
|
||||
@Resource
|
||||
private KnowledgeClassMapper knowledgeClassMapper;
|
||||
|
||||
@Resource
|
||||
private KnowledgeScopeMapper knowledgeScopeMapper;
|
||||
|
||||
@Resource
|
||||
private KnowledgeLikeMapper knowledgeLikeMapper;
|
||||
|
||||
@Resource
|
||||
private CommunityMapper communityMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createKnowledgeClass(KnowledgeClassSaveReqVO createReqVO) {
|
||||
KnowledgeClassDO knowledgeClass = BeanUtils.toBean(createReqVO, KnowledgeClassDO.class);
|
||||
|
||||
if (createReqVO.getIsDisplay() == null) {
|
||||
knowledgeClass.setIsDisplay(false);
|
||||
}
|
||||
knowledgeClass.setViewCount(0);
|
||||
knowledgeClass.setLikeCount(0);
|
||||
knowledgeClassMapper.insert(knowledgeClass);
|
||||
|
||||
if (createReqVO.getCommunityIds() != null && !createReqVO.getCommunityIds().isEmpty()) {
|
||||
List<String> communityNames = getCommunityNamesByIds(createReqVO.getCommunityIds());
|
||||
knowledgeScopeMapper.insertBatch(knowledgeClass.getId(), createReqVO.getCommunityIds(), communityNames);
|
||||
}
|
||||
|
||||
return knowledgeClass.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateKnowledgeClass(KnowledgeClassSaveReqVO updateReqVO) {
|
||||
KnowledgeClassDO oldKnowledgeClass = validateKnowledgeClassExists(updateReqVO.getId());
|
||||
|
||||
KnowledgeClassDO updateObj = BeanUtils.toBean(updateReqVO, KnowledgeClassDO.class);
|
||||
|
||||
knowledgeClassMapper.updateById(updateObj);
|
||||
|
||||
knowledgeScopeMapper.deleteByKnowledgeId(updateReqVO.getId());
|
||||
if (updateReqVO.getCommunityIds() != null && !updateReqVO.getCommunityIds().isEmpty()) {
|
||||
List<String> communityNames = getCommunityNamesByIds(updateReqVO.getCommunityIds());
|
||||
knowledgeScopeMapper.insertBatch(updateReqVO.getId(), updateReqVO.getCommunityIds(), communityNames);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteKnowledgeClass(Long id) {
|
||||
validateKnowledgeClassExists(id);
|
||||
knowledgeClassMapper.deleteById(id);
|
||||
knowledgeScopeMapper.deleteByKnowledgeId(id);
|
||||
knowledgeLikeMapper.delete(new LambdaQueryWrapperX<KnowledgeLikeDO>()
|
||||
.eq(KnowledgeLikeDO::getKnowledgeId, id));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteKnowledgeClassListByIds(List<Long> ids) {
|
||||
knowledgeClassMapper.deleteByIds(ids);
|
||||
for (Long id : ids) {
|
||||
knowledgeScopeMapper.deleteByKnowledgeId(id);
|
||||
knowledgeLikeMapper.delete(new LambdaQueryWrapperX<KnowledgeLikeDO>()
|
||||
.eq(KnowledgeLikeDO::getKnowledgeId, id));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnowledgeClassDO getKnowledgeClass(Long id) {
|
||||
return knowledgeClassMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<KnowledgeClassDO> getKnowledgeClassPage(KnowledgeClassPageReqVO pageReqVO) {
|
||||
Long tenantId = TenantContextHolder.getTenantId();
|
||||
|
||||
if (pageReqVO.getCommunityId() == null) {
|
||||
if (SYSTEM_TENANT_ID.equals(tenantId)) {
|
||||
return TenantUtils.executeIgnore(() -> knowledgeClassMapper.selectPage(pageReqVO));
|
||||
}
|
||||
pageReqVO.setCommunityId(tenantId);
|
||||
}
|
||||
|
||||
return knowledgeClassMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void publishKnowledgeClass(Long id) {
|
||||
KnowledgeClassDO knowledgeClass = validateKnowledgeClassExists(id);
|
||||
|
||||
if (knowledgeClass.getIsDisplay()) {
|
||||
throw exception(new ErrorCode(2_006_000_003, "该知识课堂已经是展示状态"));
|
||||
}
|
||||
|
||||
KnowledgeClassDO updateObj = new KnowledgeClassDO();
|
||||
updateObj.setId(id);
|
||||
updateObj.setIsDisplay(true);
|
||||
knowledgeClassMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void unpublishKnowledgeClass(Long id) {
|
||||
KnowledgeClassDO knowledgeClass = validateKnowledgeClassExists(id);
|
||||
|
||||
if (!knowledgeClass.getIsDisplay()) {
|
||||
throw exception(new ErrorCode(2_006_000_004, "该知识课堂已经下架"));
|
||||
}
|
||||
|
||||
KnowledgeClassDO updateObj = new KnowledgeClassDO();
|
||||
updateObj.setId(id);
|
||||
updateObj.setIsDisplay(false);
|
||||
knowledgeClassMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void incrementViewCount(Long id) {
|
||||
KnowledgeClassDO knowledgeClass = validateKnowledgeClassExists(id);
|
||||
|
||||
KnowledgeClassDO updateObj = new KnowledgeClassDO();
|
||||
updateObj.setId(id);
|
||||
updateObj.setViewCount(knowledgeClass.getViewCount() + 1);
|
||||
knowledgeClassMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void likeKnowledgeClass(Long knowledgeId, Long memberId) {
|
||||
validateKnowledgeClassExists(knowledgeId);
|
||||
|
||||
KnowledgeLikeDO existingLike = knowledgeLikeMapper.selectByKnowledgeIdAndMemberId(knowledgeId, memberId);
|
||||
if (existingLike != null) {
|
||||
throw exception(KNOWLEDGE_ALREADY_LIKED);
|
||||
}
|
||||
|
||||
KnowledgeLikeDO likeDO = new KnowledgeLikeDO();
|
||||
likeDO.setKnowledgeId(knowledgeId);
|
||||
likeDO.setMemberId(memberId);
|
||||
knowledgeLikeMapper.insert(likeDO);
|
||||
|
||||
KnowledgeClassDO knowledgeClass = knowledgeClassMapper.selectById(knowledgeId);
|
||||
KnowledgeClassDO updateObj = new KnowledgeClassDO();
|
||||
updateObj.setId(knowledgeId);
|
||||
updateObj.setLikeCount(knowledgeClass.getLikeCount() + 1);
|
||||
knowledgeClassMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void unlikeKnowledgeClass(Long knowledgeId, Long memberId) {
|
||||
KnowledgeLikeDO existingLike = knowledgeLikeMapper.selectByKnowledgeIdAndMemberId(knowledgeId, memberId);
|
||||
if (existingLike == null) {
|
||||
throw exception(KNOWLEDGE_NOT_LIKED);
|
||||
}
|
||||
|
||||
knowledgeLikeMapper.deleteById(existingLike.getId());
|
||||
|
||||
KnowledgeClassDO knowledgeClass = knowledgeClassMapper.selectById(knowledgeId);
|
||||
if (knowledgeClass.getLikeCount() > 0) {
|
||||
KnowledgeClassDO updateObj = new KnowledgeClassDO();
|
||||
updateObj.setId(knowledgeId);
|
||||
updateObj.setLikeCount(knowledgeClass.getLikeCount() - 1);
|
||||
knowledgeClassMapper.updateById(updateObj);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLiked(Long knowledgeId, Long memberId) {
|
||||
KnowledgeLikeDO likeDO = knowledgeLikeMapper.selectByKnowledgeIdAndMemberId(knowledgeId, memberId);
|
||||
return likeDO != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验知识课堂是否存在
|
||||
*
|
||||
* @param id 知识课堂ID
|
||||
* @return 知识课堂对象
|
||||
*/
|
||||
private KnowledgeClassDO validateKnowledgeClassExists(Long id) {
|
||||
KnowledgeClassDO knowledgeClass = knowledgeClassMapper.selectById(id);
|
||||
if (knowledgeClass == null) {
|
||||
throw exception(KNOWLEDGE_CLASS_NOT_EXISTS);
|
||||
}
|
||||
return knowledgeClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据小区ID列表批量查询小区名称
|
||||
*
|
||||
* @param communityIds 小区ID列表
|
||||
* @return 小区名称列表(与输入顺序一致,不存在的小区返回null)
|
||||
*/
|
||||
private List<String> getCommunityNamesByIds(List<Long> communityIds) {
|
||||
if (CollUtil.isEmpty(communityIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<CommunityDO> communities = communityMapper.selectByIds(communityIds);
|
||||
|
||||
Map<Long, String> communityNameMap = communities.stream()
|
||||
.filter(community -> community.getCommunityName() != null)
|
||||
.collect(Collectors.toMap(CommunityDO::getId, CommunityDO::getCommunityName));
|
||||
|
||||
return communityIds.stream()
|
||||
.map(communityNameMap::get)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue