Initial commit

This commit is contained in:
2024-02-14 16:47:29 +08:00
commit 5135f009a9
36 changed files with 1777 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.landaiqing</groupId>
<artifactId>jc-club-subject</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>jc-club-application-controller</artifactId>
<packaging>jar</packaging>
<name>jc-club-application-controller</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>com.landaiqing</groupId>
<artifactId>jc-club-infra</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.landaiqing</groupId>
<artifactId>jc-club-domain</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,155 @@
package com.landaiqing.subject.application.controller;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Preconditions;
import com.landaiqing.subject.application.convert.SubjectCategoryDTOConverter;
import com.landaiqing.subject.application.dto.SubjectCategoryDTO;
import com.landaiqing.subject.common.entity.Result;
import com.landaiqing.subject.domain.entity.SubjectCategoryBO;
import com.landaiqing.subject.domain.service.SubjectCategoryDomainService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 刷题分类controller
*
* @author landaiqing
* @date 2024/2/7
*/
@RestController
@RequestMapping("/subject/category")
@Slf4j
public class SubjectCategoryController {
@Resource
private SubjectCategoryDomainService subjectCategoryDomainService;
/**
* @description: 新增分类
* @param: [subjectCategoryDTO]
* @return: com.landaiqing.subject.common.entity.Result<java.lang.Boolean>
* @author landaiqing
* @date: 2024/2/13 20:19
*/
@PostMapping("/add")
public Result<Boolean> add(@RequestBody SubjectCategoryDTO subjectCategoryDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectCategoryController.add.dto:{}", JSON.toJSONString(subjectCategoryDTO));
}
Preconditions.checkNotNull(subjectCategoryDTO.getCategoryType(), "分类类型不能为空!");
Preconditions.checkArgument(!StringUtils.isBlank(subjectCategoryDTO.getCategoryName()), "分类的名称不能为空!");
Preconditions.checkNotNull(subjectCategoryDTO.getParentId(), "分类父级不能为空!");
SubjectCategoryBO subjectCategoryBO = SubjectCategoryDTOConverter.INSTANCE.convertDtoToCategoryBO(subjectCategoryDTO);
subjectCategoryDomainService.add(subjectCategoryBO);
return Result.ok(true);
} catch (Exception e) {
log.error("SubjectCategoryController.add.error:{}", e.getMessage(), e);
return Result.fail(e.getMessage());
}
}
/**
* @description: 查询岗位大类
* @param: [subjectCategoryDTO]
* @return: com.landaiqing.subject.common.entity.Result<java.util.List < com.landaiqing.subject.application.dto.SubjectCategoryDTO>>
* @author landaiqing
* @date: 2024/2/13 20:19
*/
@PostMapping("/queryPrimaryCategory")
public Result<List<SubjectCategoryDTO>> queryPrimaryCategory(@RequestBody SubjectCategoryDTO subjectCategoryDTO) {
try {
SubjectCategoryBO subjectCategoryBO = SubjectCategoryDTOConverter.INSTANCE.
convertDtoToCategoryBO(subjectCategoryDTO);
List<SubjectCategoryBO> subjectCategoryBOList = subjectCategoryDomainService.queryCategory(subjectCategoryBO);
List<SubjectCategoryDTO> subjectCategoryDTOList = SubjectCategoryDTOConverter.INSTANCE.
convertBoToCategoryDTOList(subjectCategoryBOList);
return Result.ok(subjectCategoryDTOList);
} catch (Exception e) {
log.error("SubjectCategoryController.queryPrimaryCategory.error:{}", e.getMessage(), e);
return Result.fail("查询失败");
}
}
/**
* @description: 根据分类id查二级分类
* @param: [subjectCategoryDTO]
* @return: com.landaiqing.subject.common.entity.Result<java.util.List < com.landaiqing.subject.application.dto.SubjectCategoryDTO>>
* @author landaiqing
* @date: 2024/2/13 20:19
*/
@PostMapping("/queryCategoryByPrimary")
public Result<List<SubjectCategoryDTO>> queryCategoryByPrimary(@RequestBody SubjectCategoryDTO subjectCategoryDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectCategoryController.queryCategoryByPrimary.dto:{}"
, JSON.toJSONString(subjectCategoryDTO));
}
Preconditions.checkNotNull(subjectCategoryDTO.getParentId(), "分类id不能为空");
SubjectCategoryBO subjectCategoryBO = SubjectCategoryDTOConverter.INSTANCE.
convertDtoToCategoryBO(subjectCategoryDTO);
List<SubjectCategoryBO> subjectCategoryBOList = subjectCategoryDomainService.queryCategory(subjectCategoryBO);
List<SubjectCategoryDTO> subjectCategoryDTOList = SubjectCategoryDTOConverter.INSTANCE.
convertBoToCategoryDTOList(subjectCategoryBOList);
return Result.ok(subjectCategoryDTOList);
} catch (Exception e) {
log.error("SubjectCategoryController.queryPrimaryCategory.error:{}", e.getMessage(), e);
return Result.fail("查询失败");
}
}
/**
* @description: 更新分类
* @param: [subjectCategoryDTO]
* @return: com.landaiqing.subject.common.entity.Result<java.lang.Boolean>
* @author landaiqing
* @date: 2024/2/14 14:42
*/
@PostMapping("/update")
public Result<Boolean> update(@RequestBody SubjectCategoryDTO subjectCategoryDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectCategoryController.update.dto:{}"
, JSON.toJSONString(subjectCategoryDTO));
}
SubjectCategoryBO subjectCategoryBO = SubjectCategoryDTOConverter.INSTANCE.convertDtoToCategoryBO(subjectCategoryDTO);
Boolean result = subjectCategoryDomainService.update(subjectCategoryBO);
return Result.ok(result);
} catch (Exception e) {
log.error("SubjectCategoryController.update.error:{}", e.getMessage(), e);
return Result.fail("更新分类失败");
}
}
/**
* @description: 删除分类
* @param: [subjectCategoryDTO]
* @return: com.landaiqing.subject.common.entity.Result<java.lang.Boolean>
* @author landaiqing
* @date: 2024/2/14 15:05
*/
@PostMapping("/delete")
public Result<Boolean> delete(@RequestBody SubjectCategoryDTO subjectCategoryDTO) {
try {
if (log.isInfoEnabled()) {
log.info("SubjectCategoryController.delete.dto:{}"
, JSON.toJSONString(subjectCategoryDTO));
}
SubjectCategoryBO subjectCategoryBO = SubjectCategoryDTOConverter.INSTANCE.convertDtoToCategoryBO(subjectCategoryDTO);
Boolean result = subjectCategoryDomainService.delete(subjectCategoryBO);
return Result.ok(result);
} catch (Exception e) {
log.error("SubjectCategoryController.delete.error:{}", e.getMessage(), e);
return Result.fail("删除分类失败");
}
}
}

View File

@@ -0,0 +1,26 @@
package com.landaiqing.subject.application.controller;
import com.landaiqing.subject.infra.basic.entity.SubjectCategory;
import com.landaiqing.subject.infra.basic.service.SubjectCategoryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* 刷题controller
*
* @author: landaiqing
* @date: 2024/2/7
*/
@RestController
public class SubjectController {
@Resource
private SubjectCategoryService subjectCategoryService;
@GetMapping("/test")
public String test(){
SubjectCategory subjectCategory = subjectCategoryService.queryById(1L);
return subjectCategory.getCategoryName();
}
}

View File

@@ -0,0 +1,25 @@
package com.landaiqing.subject.application.convert;
import com.landaiqing.subject.application.dto.SubjectCategoryDTO;
import com.landaiqing.subject.domain.entity.SubjectCategoryBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* 题目分类dto转换器
*
* @author: landaiqing
* @date: 2024/2/13
*/
@Mapper
public interface SubjectCategoryDTOConverter {
SubjectCategoryDTOConverter INSTANCE = Mappers.getMapper(SubjectCategoryDTOConverter.class);
SubjectCategoryBO convertDtoToCategoryBO(SubjectCategoryDTO subjectCategoryDTO);
SubjectCategoryDTO convertBoToCategoryDTO(SubjectCategoryBO subjectCategoryBO);
List<SubjectCategoryDTO> convertBoToCategoryDTOList(List<SubjectCategoryBO> subjectCategoryDTO);
}

View File

@@ -0,0 +1,49 @@
package com.landaiqing.subject.application.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 题目分类(SubjectCategory)实体类
*
* @author makejava
* @since 2024-02-07 16:17:17
*/
@Data
public class SubjectCategoryDTO implements Serializable {
/**
* 主键
*/
private Long id;
/**
* 分类名称
*/
private String categoryName;
/**
* 分类类型
*/
private Integer categoryType;
/**
* 图标连接
*/
private String imageUrl;
/**
* 父级id
*/
private Long parentId;
/**
* 数量
*/
private Integer count;
}