From b0a91a555a1e1af3fc46a3659bc850cf3cff17c7 Mon Sep 17 00:00:00 2001 From: memorylkf <312904636@qq.com> Date: Tue, 30 Dec 2025 11:39:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20[=E8=AF=95=E9=AA=8C=E7=AE=A1=E7=90=86]?= =?UTF-8?q?=20=E8=AE=BE=E7=BD=AE=E5=AD=A6=E7=A7=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/StudySubjectController.java | 38 ++++++------- .../com/hxhq/business/domain/StudySubject.java | 2 + .../business/form/study/StudySubjectSaveForm.java | 36 ++++++++++++ .../business/service/IStudySubjectService.java | 16 ++++-- .../service/impl/StudySubjectServiceImpl.java | 64 +++++++++++++++++----- 5 files changed, 118 insertions(+), 38 deletions(-) create mode 100644 hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/study/StudySubjectSaveForm.java diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudySubjectController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudySubjectController.java index 4cb2516..c58470c 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudySubjectController.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudySubjectController.java @@ -1,8 +1,10 @@ package com.hxhq.business.controller; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import com.hxhq.business.form.study.StudySubjectSaveForm; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.hxhq.business.domain.StudySubject; @@ -28,38 +30,34 @@ public class StudySubjectController extends BaseController /** * 查询试验-学科列表 */ - @GetMapping("/list") - public TableDataInfo list(StudySubject studySubject) + @GetMapping("/listByStudyId") + public AjaxResult list(Long studyId) { - startPage(); - List list = studySubjectService.queryList(studySubject); - return getDataTable(list); + if(studyId==null || studyId.longValue()<=0){ + return AjaxResult.success(new ArrayList<>()); + } + return AjaxResult.success(studySubjectService.getListByStudyId(studyId)); } /** - * 获取试验-学科详细信息 + * 查询试验-学科列表 */ - @GetMapping(value = "/info") - public AjaxResult getInfo(Long id) + @GetMapping("/getAllListByStudyId") + public AjaxResult getAllListByStudyId(Long studyId) { - return AjaxResult.success(studySubjectService.getById(id)); + return AjaxResult.success(studySubjectService.getAllListByStudyId(studyId)); } /** * 新增试验-学科信息 */ @PostMapping("/save") - public AjaxResult save(@RequestBody StudySubject studySubject) - { - return toAjax(studySubjectService.saveOrUpdate(studySubject)); - } - - /** - * 删除试验-学科信息 - */ - @PostMapping("/delete") - public AjaxResult delete(@RequestBody Long[] ids) + public AjaxResult save(@RequestBody StudySubjectSaveForm form) { - return toAjax(studySubjectService.removeByIds(Arrays.asList(ids))); + if(form.getStudyId()==null || form.getStudyId().longValue()<=0 || form.getSubjectList()==null){ + return AjaxResult.error("参数有误"); + } + studySubjectService.saveInfo(form); + return AjaxResult.success(); } } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/StudySubject.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/StudySubject.java index d430b9d..a5a93ab 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/StudySubject.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/StudySubject.java @@ -1,5 +1,6 @@ package com.hxhq.business.domain; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.hxhq.common.core.domain.MpBaseEntity; @@ -33,6 +34,7 @@ public class StudySubject extends MpBaseEntity /** * 是否选中 */ + @TableField(exist = false) private Boolean select; diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/study/StudySubjectSaveForm.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/study/StudySubjectSaveForm.java new file mode 100644 index 0000000..3d66eff --- /dev/null +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/study/StudySubjectSaveForm.java @@ -0,0 +1,36 @@ +package com.hxhq.business.form.study; + +import com.hxhq.business.domain.StudySubject; + +import java.util.List; + +/** + * @author memory + */ +public class StudySubjectSaveForm { + + /** + * 试验id + */ + private Long studyId; + /** + * 学科信息 + */ + private List subjectList; + + public Long getStudyId() { + return studyId; + } + + public void setStudyId(Long studyId) { + this.studyId = studyId; + } + + public List getSubjectList() { + return subjectList; + } + + public void setSubjectList(List subjectList) { + this.subjectList = subjectList; + } +} diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStudySubjectService.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStudySubjectService.java index b6c5dfb..8cebd4f 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStudySubjectService.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStudySubjectService.java @@ -3,6 +3,7 @@ package com.hxhq.business.service; import java.util.List; import com.hxhq.business.domain.StudySubject; import com.baomidou.mybatisplus.extension.service.IService; +import com.hxhq.business.form.study.StudySubjectSaveForm; /** * 试验-学科Service接口 @@ -13,12 +14,11 @@ import com.baomidou.mybatisplus.extension.service.IService; public interface IStudySubjectService extends IService { /** - * 查询试验-学科列表 - * - * @param studySubject 试验-学科 - * @return 试验-学科集合 + * 获取已经设置的学科信息 + * @param studyId + * @return */ - public List queryList(StudySubject studySubject); + List getListByStudyId(Long studyId); /** * 获取试验下的学科设置信息(含未设置的学科) @@ -27,4 +27,10 @@ public interface IStudySubjectService extends IService */ List getAllListByStudyId(Long studyId); + /** + * 设置学科信息 + * @param form + */ + void saveInfo(StudySubjectSaveForm form); + } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudySubjectServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudySubjectServiceImpl.java index 34659fa..d35d0bc 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudySubjectServiceImpl.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudySubjectServiceImpl.java @@ -6,11 +6,17 @@ import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hxhq.business.domain.Study; +import com.hxhq.business.form.study.StudySubjectSaveForm; +import com.hxhq.business.service.IStudyService; +import com.hxhq.common.core.exception.ServiceException; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.hxhq.business.mapper.StudySubjectMapper; import com.hxhq.business.domain.StudySubject; import com.hxhq.business.service.IStudySubjectService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.transaction.annotation.Transactional; /** * 试验-学科Service业务层处理 @@ -21,18 +27,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service public class StudySubjectServiceImpl extends ServiceImpl implements IStudySubjectService { - /** - * 查询试验-学科列表 - * - * @param studySubject 试验-学科 - * @return 试验-学科 - */ - @Override - public List queryList(StudySubject studySubject) - { - QueryWrapper queryWrapper = Wrappers.query(); - return this.list(queryWrapper); - } + @Autowired + private IStudyService studyService; /** * 获取试验下的学科设置信息(含未设置的学科) @@ -69,9 +65,51 @@ public class StudySubjectServiceImpl extends ServiceImpl getListByStudyId(Long studyId){ + @Override + public List getListByStudyId(Long studyId){ QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("study_id",studyId); return list(queryWrapper); } + + @Override + @Transactional(rollbackFor = Exception.class) + public void saveInfo(StudySubjectSaveForm form) { + Study study = studyService.getById(form.getStudyId()); + if(study==null){ + throw new ServiceException("试验不存在"); + } + //传入的学科信息 + List itemList = form.getSubjectList(); + + //已经设置的学科信息 + List oldList = getListByStudyId(form.getStudyId()); + List deleteList = new ArrayList<>(); + List addList = new ArrayList<>(); + List modifyList = new ArrayList<>(); + + for(StudySubject item : itemList){ + if(oldList.stream().filter(o->o.getDeptId().equals(item.getDeptId())).collect(Collectors.toList()).size()==0){ + item.setStudyId(form.getStudyId()); + addList.add(item); + }else{ + modifyList.add(item); + } + } + + for(StudySubject old : oldList){ + if(itemList.stream().filter(o->o.getDeptId().equals(old.getDeptId())).collect(Collectors.toList()).size()==0){ + deleteList.add(old); + } + } + if(addList.size()>0){ + saveBatch(addList); + } + if(modifyList.size()>0){ + updateBatchById(modifyList); + } + if(deleteList.size()>0){ + removeBatchByIds(deleteList); + } + } }