feat: 题目标签开发

This commit is contained in:
2024-02-14 20:15:24 +08:00
parent 5135f009a9
commit 37fb0ea196
22 changed files with 1819 additions and 0 deletions

View File

@@ -0,0 +1,130 @@
package com.landaiqing.subject.application.controller;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Preconditions;
import com.landaiqing.subject.application.convert.SubjectLabelDTOConverter;
import com.landaiqing.subject.application.dto.SubjectLabelDTO;
import com.landaiqing.subject.common.entity.Result;
import com.landaiqing.subject.domain.entity.SubjectLabelBO;
import com.landaiqing.subject.domain.service.SubjectLabelDomainService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* @Classname SubjectLabelController
* @BelongsProject: jc-club
* @BelongsPackage: com.landaiqing.subject.application.controller
* @Author: landaiqing
* @CreateTime: 2024-02-14 17:03
* @Description: 标签controller
* @Version: 1.0
*/
@RestController
@RequestMapping("/subject/label")
@Slf4j
public class SubjectLabelController {
@Resource
private SubjectLabelDomainService subjectLabelDomainService;
/**
* @description: 新增标签
* @param: [subjectLabelDTO]
* @return: com.landaiqing.subject.common.entity.Result<java.lang.Boolean>
* @author landaiqing
* @date: 2024/2/14 17:46
*/
@PostMapping("/add")
public Result<Boolean> add(@RequestBody SubjectLabelDTO subjectLabelDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectLabelController.add.dto:{}", JSON.toJSONString(subjectLabelDTO));
}
Preconditions.checkArgument(!StringUtils.isBlank(subjectLabelDTO.getLabelName()), "标签的名称不能为空!");
SubjectLabelBO subjectLabelBO = SubjectLabelDTOConverter.INSTANCE.convertDtoToLabelBO(subjectLabelDTO);
Boolean result = subjectLabelDomainService.add(subjectLabelBO);
return Result.ok(result);
} catch (Exception e) {
log.error("SubjectLabelController.add.error:{}", e.getMessage(), e);
return Result.fail("新增标签失败!");
}
}
/**
* @description: 更新标签
* @param: [subjectLabelDTO]
* @return: com.landaiqing.subject.common.entity.Result<java.lang.Boolean>
* @author landaiqing
* @date: 2024/2/14 17:53
*/
@PostMapping("/update")
public Result<Boolean> update(@RequestBody SubjectLabelDTO subjectLabelDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectLabelController.update.dto:{}", JSON.toJSONString(subjectLabelDTO));
}
Preconditions.checkNotNull(subjectLabelDTO.getId(), "标签id不能为空");
SubjectLabelBO subjectLabelBO = SubjectLabelDTOConverter.INSTANCE.convertDtoToLabelBO(subjectLabelDTO);
Boolean result = subjectLabelDomainService.update(subjectLabelBO);
return Result.ok(result);
} catch (Exception e) {
log.error("SubjectLabelController.update.error:{}", e.getMessage(), e);
return Result.fail("更新标签失败");
}
}
/**
* @description: 删除标签
* @param: [subjectLabelDTO]
* @return: com.landaiqing.subject.common.entity.Result<java.lang.Boolean>
* @author landaiqing
* @date: 2024/2/14 17:53
*/
@PostMapping("/delete")
public Result<Boolean> delete(@RequestBody SubjectLabelDTO subjectLabelDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectLabelController.delete.dto:{}", JSON.toJSONString(subjectLabelDTO));
}
Preconditions.checkNotNull(subjectLabelDTO.getId(), "标签id不能为空");
SubjectLabelBO subjectLabelBO = SubjectLabelDTOConverter.INSTANCE.convertDtoToLabelBO(subjectLabelDTO);
Boolean result = subjectLabelDomainService.delete(subjectLabelBO);
return Result.ok(result);
} catch (Exception e) {
log.error("SubjectLabelController.delete.error:{}", e.getMessage(), e);
return Result.fail("删除标签失败");
}
}
/**
* @description: 查询分类下的标签
* @param: [subjectLabelDTO]
* @return: com.landaiqing.subject.common.entity.Result<java.util.List<com.landaiqing.subject.application.dto.SubjectLabelDTO>>
* @author landaiqing
* @date: 2024/2/14 18:57
*/
@PostMapping("/queryLabelByCategoryId")
public Result<List<SubjectLabelDTO>> queryLabelByCategoryId(@RequestBody SubjectLabelDTO subjectLabelDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectLabelController.queryLabelByCategoryId.dto:{}",
JSON.toJSONString(subjectLabelDTO));
}
Preconditions.checkNotNull(subjectLabelDTO.getCategoryId(), "分类id不能为空");
SubjectLabelBO subjectLabelBO = SubjectLabelDTOConverter.INSTANCE.convertDtoToLabelBO(subjectLabelDTO);
List<SubjectLabelBO> resultList = subjectLabelDomainService.queryLabelByCategoryId(subjectLabelBO);
List<SubjectLabelDTO> subjectLabelDTOS = SubjectLabelDTOConverter.INSTANCE.convertBOToLabelDTOList(resultList);
return Result.ok(subjectLabelDTOS);
} catch (Exception e) {
log.error("SubjectLabelController.queryLabelByCategoryId.error:{}", e.getMessage(), e);
return Result.fail("查询标签失败");
}
}
}

View File

@@ -0,0 +1,26 @@
package com.landaiqing.subject.application.convert;
import com.landaiqing.subject.application.dto.SubjectLabelDTO;
import com.landaiqing.subject.domain.entity.SubjectLabelBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 标签dto转换器
*
* @author: landaiqing
* @date: 2024/2/14
*/
@Mapper
public interface SubjectLabelDTOConverter {
SubjectLabelDTOConverter INSTANCE = Mappers.getMapper(SubjectLabelDTOConverter.class);
SubjectLabelBO convertDtoToLabelBO(SubjectLabelDTO subjectLabelDTO);
List<SubjectLabelDTO> convertBOToLabelDTOList(List<SubjectLabelBO> boList);
}

View File

@@ -0,0 +1,36 @@
package com.landaiqing.subject.application.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 题目标签DTO
*
* @author makejava
* @since 2024-02-14 17:08:06
*/
@Data
public class SubjectLabelDTO implements Serializable {
/**
* 主键
*/
private Long id;
/**
* 分类id
*/
private Long categoryId;
/**
* 标签分类
*/
private String labelName;
/**
* 排序
*/
private Integer sortNum;
}