diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/controller/LabelsController.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/controller/LabelsController.java new file mode 100644 index 000000000..5660d6cc7 --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/controller/LabelsController.java @@ -0,0 +1,105 @@ +package org.dromara.question.controller; + +import java.util.List; + +import lombok.RequiredArgsConstructor; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.constraints.*; +import cn.dev33.satoken.annotation.SaCheckPermission; +import org.springframework.web.bind.annotation.*; +import org.springframework.validation.annotation.Validated; +import org.dromara.common.idempotent.annotation.RepeatSubmit; +import org.dromara.common.log.annotation.Log; +import org.dromara.common.web.core.BaseController; +import org.dromara.common.mybatis.core.page.PageQuery; +import org.dromara.common.core.domain.R; +import org.dromara.common.core.validate.AddGroup; +import org.dromara.common.core.validate.EditGroup; +import org.dromara.common.log.enums.BusinessType; +import org.dromara.common.excel.utils.ExcelUtil; +import org.dromara.question.domain.vo.LabelsVo; +import org.dromara.question.domain.bo.LabelsBo; +import org.dromara.question.service.ILabelsService; +import org.dromara.common.mybatis.core.page.TableDataInfo; + +/** + * 题目标签 + * + * @author Lion Li + * @date 2023-11-08 + */ +@Validated +@RequiredArgsConstructor +@RestController +@RequestMapping("/question/label") +public class LabelsController extends BaseController { + + private final ILabelsService labelsService; + + /** + * 查询题目标签列表 + */ + @SaCheckPermission("question:label:list") + @GetMapping("/list") + public TableDataInfo list(LabelsBo bo, PageQuery pageQuery) { + return labelsService.queryPageList(bo, pageQuery); + } + + /** + * 导出题目标签列表 + */ + @SaCheckPermission("question:label:export") + @Log(title = "题目标签", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(LabelsBo bo, HttpServletResponse response) { + List list = labelsService.queryList(bo); + ExcelUtil.exportExcel(list, "题目标签", LabelsVo.class, response); + } + + /** + * 获取题目标签详细信息 + * + * @param id 主键 + */ + @SaCheckPermission("question:label:query") + @GetMapping("/{id}") + public R getInfo(@NotNull(message = "主键不能为空") + @PathVariable Long id) { + return R.ok(labelsService.queryById(id)); + } + + /** + * 新增题目标签 + */ + @SaCheckPermission("question:label:add") + @Log(title = "题目标签", businessType = BusinessType.INSERT) + @RepeatSubmit() + @PostMapping() + public R add(@Validated(AddGroup.class) @RequestBody LabelsBo bo) { + return toAjax(labelsService.insertByBo(bo)); + } + + /** + * 修改题目标签 + */ + @SaCheckPermission("question:label:edit") + @Log(title = "题目标签", businessType = BusinessType.UPDATE) + @RepeatSubmit() + @PutMapping() + public R edit(@Validated(EditGroup.class) @RequestBody LabelsBo bo) { + return toAjax(labelsService.updateByBo(bo)); + } + + /** + * 删除题目标签 + * + * @param ids 主键串 + */ + @SaCheckPermission("question:label:remove") + @Log(title = "题目标签", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public R remove(@NotEmpty(message = "主键不能为空") + @PathVariable Long[] ids) { + return toAjax(labelsService.deleteWithValidByIds(List.of(ids), true)); + } +} diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/controller/TitleController.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/controller/TitleController.java index 5e7f061c2..e1de0e848 100644 --- a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/controller/TitleController.java +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/controller/TitleController.java @@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.*; import cn.dev33.satoken.annotation.SaCheckPermission; +import org.dromara.question.domain.bo.TitleResp; import org.springframework.web.bind.annotation.*; import org.springframework.validation.annotation.Validated; import org.dromara.common.idempotent.annotation.RepeatSubmit; @@ -63,7 +64,7 @@ public class TitleController extends BaseController { */ @SaCheckPermission("question:title:query") @GetMapping("/{id}") - public R getInfo(@NotNull(message = "主键不能为空") + public R getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) { return R.ok(titleService.queryById(id)); } diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/Labels.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/Labels.java new file mode 100644 index 000000000..14c692825 --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/Labels.java @@ -0,0 +1,41 @@ +package org.dromara.question.domain; + +import org.dromara.common.mybatis.core.domain.BaseEntity; +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serial; + +/** + * 题目标签对象 f_labels + * + * @author Lion Li + * @date 2023-11-08 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("f_labels") +public class Labels extends BaseEntity { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * + */ + @TableId(value = "id") + private Long id; + + /** + * 标签名称 + */ + private String label; + + /** + * 标签状态 1:启用 0:禁用 + */ + private Integer status; + + +} diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/Options.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/Options.java new file mode 100644 index 000000000..4f8f62101 --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/Options.java @@ -0,0 +1,44 @@ +package org.dromara.question.domain; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.dromara.common.mybatis.core.domain.BaseEntity; + +import java.io.Serial; + +/** + * @author : lvxudong + * @date : 2023/11/8 17:39 + * @className : Options + * @description : + **/ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("f_options") +public class Options extends BaseEntity { + @Serial + private static final long serialVersionUID = 1L; + + /** + * 主键id + */ + @TableId(value = "id") + private Long id; + + /** + * 选项序号 + */ + private Integer serial; + + /** + * 题目id + */ + private Long questionId; + + /** + * 选项内容 + */ + private Long optionContent; +} diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/bo/LabelsBo.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/bo/LabelsBo.java new file mode 100644 index 000000000..93671c91c --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/bo/LabelsBo.java @@ -0,0 +1,42 @@ +package org.dromara.question.domain.bo; + +import org.dromara.question.domain.Labels; +import org.dromara.common.mybatis.core.domain.BaseEntity; +import org.dromara.common.core.validate.AddGroup; +import org.dromara.common.core.validate.EditGroup; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import lombok.EqualsAndHashCode; +import jakarta.validation.constraints.*; + +/** + * 题目标签业务对象 f_labels + * + * @author Lion Li + * @date 2023-11-08 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@AutoMapper(target = Labels.class, reverseConvertGenerate = false) +public class LabelsBo extends BaseEntity { + + /** + * + */ + @NotNull(message = "不能为空", groups = { EditGroup.class }) + private Long id; + + /** + * 标签名称 + */ + @NotBlank(message = "标签名称不能为空", groups = { AddGroup.class, EditGroup.class }) + private String label; + + /** + * 标签状态 1:启用 0:禁用 + */ + @NotNull(message = "标签状态 1:启用 0:禁用不能为空", groups = { AddGroup.class, EditGroup.class }) + private Integer status; + + +} diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/bo/TitleResp.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/bo/TitleResp.java new file mode 100644 index 000000000..684590bfb --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/bo/TitleResp.java @@ -0,0 +1,33 @@ +package org.dromara.question.domain.bo; + +import lombok.Data; +import org.dromara.question.domain.vo.OptionVo; + +import java.io.Serializable; +import java.util.List; + +/** + * @author : lvxudong + * @date : 2023/11/8 17:47 + * @className : TitleResp + * @description : + **/ +@Data +public class TitleResp implements Serializable { + /** + * id + */ + private Long id; + + /** + * 题目 + */ + private String question; + + /** + * 题目标签类型 + */ + private Long labelName; + + private List optionVoList; +} diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/vo/LabelsVo.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/vo/LabelsVo.java new file mode 100644 index 000000000..d91e8d843 --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/vo/LabelsVo.java @@ -0,0 +1,50 @@ +package org.dromara.question.domain.vo; + +import org.dromara.question.domain.Labels; +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import org.dromara.common.excel.annotation.ExcelDictFormat; +import org.dromara.common.excel.convert.ExcelDictConvert; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; +import java.util.Date; + + + +/** + * 题目标签视图对象 f_labels + * + * @author Lion Li + * @date 2023-11-08 + */ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = Labels.class) +public class LabelsVo implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * + */ + @ExcelProperty(value = "") + private Long id; + + /** + * 标签名称 + */ + @ExcelProperty(value = "标签名称") + private String label; + + /** + * 标签状态 1:启用 0:禁用 + */ + @ExcelProperty(value = "标签状态 1:启用 0:禁用") + private Integer status; + + +} diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/vo/OptionVo.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/vo/OptionVo.java new file mode 100644 index 000000000..a9081960b --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/vo/OptionVo.java @@ -0,0 +1,41 @@ +package org.dromara.question.domain.vo; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.baomidou.mybatisplus.annotation.TableId; +import io.github.linpeilie.annotations.AutoMapper; +import lombok.Data; +import org.dromara.question.domain.Title; + +import java.io.Serializable; + +/** + * @author : lvxudong + * @date : 2023/11/8 17:37 + * @className : OptionVo + * @description : + **/ +@Data +@ExcelIgnoreUnannotated +@AutoMapper(target = Title.class) +public class OptionVo implements Serializable { + + /** + * 主键id + */ + private Long id; + + /** + * 选项序号 + */ + private Integer serial; + + /** + * 题目id + */ + private Long questionId; + + /** + * 选项内容 + */ + private Long optionContent; +} diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/vo/TitleVo.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/vo/TitleVo.java index ad05754ee..e60f72933 100644 --- a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/vo/TitleVo.java +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/domain/vo/TitleVo.java @@ -21,7 +21,6 @@ import java.util.Date; * @date 2023-11-08 */ @Data -@ExcelIgnoreUnannotated @AutoMapper(target = Title.class) public class TitleVo implements Serializable { @@ -29,21 +28,18 @@ public class TitleVo implements Serializable { private static final long serialVersionUID = 1L; /** - * + * id */ - @ExcelProperty(value = "") private Long id; /** * 题目 */ - @ExcelProperty(value = "题目") private String question; /** * 题目标签类型 */ - @ExcelProperty(value = "题目标签类型") private Long labelId; diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/mapper/LabelsMapper.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/mapper/LabelsMapper.java new file mode 100644 index 000000000..98c6e0015 --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/mapper/LabelsMapper.java @@ -0,0 +1,15 @@ +package org.dromara.question.mapper; + +import org.dromara.question.domain.Labels; +import org.dromara.question.domain.vo.LabelsVo; +import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; + +/** + * 题目标签Mapper接口 + * + * @author Lion Li + * @date 2023-11-08 + */ +public interface LabelsMapper extends BaseMapperPlus { + +} diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/mapper/OptionMapper.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/mapper/OptionMapper.java new file mode 100644 index 000000000..59a418136 --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/mapper/OptionMapper.java @@ -0,0 +1,15 @@ +package org.dromara.question.mapper; + +import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; +import org.dromara.question.domain.Options; +import org.dromara.question.domain.vo.OptionVo; + +/** + * @author : lvxudong + * @date : 2023/11/8 17:45 + * @className : Option + * @description : + **/ +public interface OptionMapper extends BaseMapperPlus { + +} diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/ILabelsService.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/ILabelsService.java new file mode 100644 index 000000000..f4ff8663d --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/ILabelsService.java @@ -0,0 +1,49 @@ +package org.dromara.question.service; + +import org.dromara.question.domain.Labels; +import org.dromara.question.domain.vo.LabelsVo; +import org.dromara.question.domain.bo.LabelsBo; +import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.common.mybatis.core.page.PageQuery; + +import java.util.Collection; +import java.util.List; + +/** + * 题目标签Service接口 + * + * @author Lion Li + * @date 2023-11-08 + */ +public interface ILabelsService { + + /** + * 查询题目标签 + */ + LabelsVo queryById(Long id); + + /** + * 查询题目标签列表 + */ + TableDataInfo queryPageList(LabelsBo bo, PageQuery pageQuery); + + /** + * 查询题目标签列表 + */ + List queryList(LabelsBo bo); + + /** + * 新增题目标签 + */ + Boolean insertByBo(LabelsBo bo); + + /** + * 修改题目标签 + */ + Boolean updateByBo(LabelsBo bo); + + /** + * 校验并批量删除题目标签信息 + */ + Boolean deleteWithValidByIds(Collection ids, Boolean isValid); +} diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/ITitleService.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/ITitleService.java index 1f5f68c42..88ba82bf3 100644 --- a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/ITitleService.java +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/ITitleService.java @@ -1,6 +1,7 @@ package org.dromara.question.service; import org.dromara.question.domain.Title; +import org.dromara.question.domain.bo.TitleResp; import org.dromara.question.domain.vo.TitleVo; import org.dromara.question.domain.bo.TitleBo; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -20,7 +21,7 @@ public interface ITitleService { /** * 查询题目 */ - TitleVo queryById(Long id); + TitleResp queryById(Long id); /** * 查询题目列表 diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/impl/LabelsServiceImpl.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/impl/LabelsServiceImpl.java new file mode 100644 index 000000000..cd2c0bdca --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/impl/LabelsServiceImpl.java @@ -0,0 +1,110 @@ +package org.dromara.question.service.impl; + +import org.dromara.common.core.utils.MapstructUtils; +import org.dromara.common.core.utils.StringUtils; +import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.common.mybatis.core.page.PageQuery; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.dromara.question.domain.bo.LabelsBo; +import org.dromara.question.domain.vo.LabelsVo; +import org.dromara.question.domain.Labels; +import org.dromara.question.mapper.LabelsMapper; +import org.dromara.question.service.ILabelsService; + +import java.util.List; +import java.util.Map; +import java.util.Collection; + +/** + * 题目标签Service业务层处理 + * + * @author Lion Li + * @date 2023-11-08 + */ +@RequiredArgsConstructor +@Service +public class LabelsServiceImpl implements ILabelsService { + + private final LabelsMapper baseMapper; + + /** + * 查询题目标签 + */ + @Override + public LabelsVo queryById(Long id){ + return baseMapper.selectVoById(id); + } + + /** + * 查询题目标签列表 + */ + @Override + public TableDataInfo queryPageList(LabelsBo bo, PageQuery pageQuery) { + LambdaQueryWrapper lqw = buildQueryWrapper(bo); + Page result = baseMapper.selectVoPage(pageQuery.build(), lqw); + return TableDataInfo.build(result); + } + + /** + * 查询题目标签列表 + */ + @Override + public List queryList(LabelsBo bo) { + LambdaQueryWrapper lqw = buildQueryWrapper(bo); + return baseMapper.selectVoList(lqw); + } + + private LambdaQueryWrapper buildQueryWrapper(LabelsBo bo) { + Map params = bo.getParams(); + LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); + lqw.eq(StringUtils.isNotBlank(bo.getLabel()), Labels::getLabel, bo.getLabel()); + lqw.eq(bo.getStatus() != null, Labels::getStatus, bo.getStatus()); + return lqw; + } + + /** + * 新增题目标签 + */ + @Override + public Boolean insertByBo(LabelsBo bo) { + Labels add = MapstructUtils.convert(bo, Labels.class); + validEntityBeforeSave(add); + boolean flag = baseMapper.insert(add) > 0; + if (flag) { + bo.setId(add.getId()); + } + return flag; + } + + /** + * 修改题目标签 + */ + @Override + public Boolean updateByBo(LabelsBo bo) { + Labels update = MapstructUtils.convert(bo, Labels.class); + validEntityBeforeSave(update); + return baseMapper.updateById(update) > 0; + } + + /** + * 保存前的数据校验 + */ + private void validEntityBeforeSave(Labels entity){ + //TODO 做一些数据校验,如唯一约束 + } + + /** + * 批量删除题目标签 + */ + @Override + public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { + if(isValid){ + //TODO 做一些业务上的校验,判断是否需要校验 + } + return baseMapper.deleteBatchIds(ids) > 0; + } +} diff --git a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/impl/TitleServiceImpl.java b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/impl/TitleServiceImpl.java index 4138cf2e1..dcbba667b 100644 --- a/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/impl/TitleServiceImpl.java +++ b/ruoyi-modules/ruoyi-question/src/main/java/org/dromara/question/service/impl/TitleServiceImpl.java @@ -8,6 +8,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.RequiredArgsConstructor; +import org.dromara.question.domain.Options; +import org.dromara.question.domain.bo.TitleResp; +import org.dromara.question.domain.vo.OptionVo; +import org.dromara.question.mapper.OptionMapper; import org.springframework.stereotype.Service; import org.dromara.question.domain.bo.TitleBo; import org.dromara.question.domain.vo.TitleVo; @@ -31,12 +35,20 @@ public class TitleServiceImpl implements ITitleService { private final TitleMapper baseMapper; + private final OptionMapper optionMapper; + /** * 查询题目 */ @Override - public TitleVo queryById(Long id){ - return baseMapper.selectVoById(id); + public TitleResp queryById(Long id){ + TitleVo titleVo = baseMapper.selectVoById(id); + List options = optionMapper.selectVoList(new LambdaQueryWrapper() + .eq(Options::getQuestionId, titleVo.getId())); + + TitleResp resp = new TitleResp(); + resp.setOptionVoList(options); + return resp; } /** @@ -59,7 +71,6 @@ public class TitleServiceImpl implements ITitleService { } private LambdaQueryWrapper buildQueryWrapper(TitleBo bo) { - Map<String, Object> params = bo.getParams(); LambdaQueryWrapper<Title> lqw = Wrappers.lambdaQuery(); lqw.eq(StringUtils.isNotBlank(bo.getQuestion()), Title::getQuestion, bo.getQuestion()); lqw.eq(bo.getLabelId() != null, Title::getLabelId, bo.getLabelId()); diff --git a/ruoyi-modules/ruoyi-question/src/main/resources/mapper/question/LabelsMapper.xml b/ruoyi-modules/ruoyi-question/src/main/resources/mapper/question/LabelsMapper.xml new file mode 100644 index 000000000..5c176d7ab --- /dev/null +++ b/ruoyi-modules/ruoyi-question/src/main/resources/mapper/question/LabelsMapper.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="org.dromara.question.mapper.LabelsMapper"> + +</mapper>