diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudySubjectUserController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudySubjectUserController.java index 4bfbc10..e28b602 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudySubjectUserController.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudySubjectUserController.java @@ -3,6 +3,7 @@ package com.hxhq.business.controller; import java.util.Arrays; import java.util.List; +import com.hxhq.business.form.study.StudySubjectUserSaveForm; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.hxhq.business.domain.StudySubjectUser; @@ -28,38 +29,24 @@ public class StudySubjectUserController extends BaseController /** * 查询试验-学科-成员列表 */ - @GetMapping("/list") - public TableDataInfo list(StudySubjectUser studySubjectUser) + @GetMapping("/getListByStudySubjectId") + public AjaxResult getListByStudySubjectId(Long studySubjectId) { - startPage(); - List list = studySubjectUserService.queryList(studySubjectUser); - return getDataTable(list); - } - - /** - * 获取试验-学科-成员详细信息 - */ - @GetMapping(value = "/info") - public AjaxResult getInfo(Long id) - { - return AjaxResult.success(studySubjectUserService.getById(id)); + return AjaxResult.success(studySubjectUserService.getListByStudySubjectId(studySubjectId)); } /** * 新增试验-学科-成员信息 + * @param form + * @return */ @PostMapping("/save") - public AjaxResult save(@RequestBody StudySubjectUser studySubjectUser) - { - return toAjax(studySubjectUserService.saveOrUpdate(studySubjectUser)); - } - - /** - * 删除试验-学科-成员信息 - */ - @PostMapping("/delete") - public AjaxResult delete(@RequestBody Long[] ids) + public AjaxResult save(@RequestBody StudySubjectUserSaveForm form) { - return toAjax(studySubjectUserService.removeByIds(Arrays.asList(ids))); + if(form.getStudySubjectId()==null || form.getStudySubjectId().longValue()<=0 || form.getSubjectUserList()==null){ + return AjaxResult.error("参数有误"); + } + studySubjectUserService.saveInfo(form); + return AjaxResult.success(); } } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/study/StudySubjectUserSaveForm.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/study/StudySubjectUserSaveForm.java new file mode 100644 index 0000000..43d89b9 --- /dev/null +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/study/StudySubjectUserSaveForm.java @@ -0,0 +1,37 @@ +package com.hxhq.business.form.study; + +import com.hxhq.business.domain.StudySubject; +import com.hxhq.business.domain.StudySubjectUser; + +import java.util.List; + +/** + * @author memory + */ +public class StudySubjectUserSaveForm { + + /** + * 试验学科id + */ + private Long studySubjectId; + /** + * 成员列表 + */ + private List subjectUserList; + + public Long getStudySubjectId() { + return studySubjectId; + } + + public void setStudySubjectId(Long studySubjectId) { + this.studySubjectId = studySubjectId; + } + + public List getSubjectUserList() { + return subjectUserList; + } + + public void setSubjectUserList(List subjectUserList) { + this.subjectUserList = subjectUserList; + } +} diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStudySubjectUserService.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStudySubjectUserService.java index 891fdea..f68ba42 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStudySubjectUserService.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStudySubjectUserService.java @@ -3,6 +3,7 @@ package com.hxhq.business.service; import java.util.List; import com.hxhq.business.domain.StudySubjectUser; import com.baomidou.mybatisplus.extension.service.IService; +import com.hxhq.business.form.study.StudySubjectUserSaveForm; /** * 试验-学科-成员Service接口 @@ -13,11 +14,22 @@ import com.baomidou.mybatisplus.extension.service.IService; public interface IStudySubjectUserService extends IService { /** - * 查询试验-学科-成员列表 - * - * @param studySubjectUser 试验-学科-成员 - * @return 试验-学科-成员集合 + * 获取试验学科下的成员列表 + * @param studySubjectId + * @return */ - public List queryList(StudySubjectUser studySubjectUser); + List getListByStudySubjectId(Long studySubjectId); + + /** + * 保存成员信息 + * @param form + */ + void saveInfo(StudySubjectUserSaveForm form); + + /** + * 根据studySubjectId进下删除 + * @param studySubjectId + */ + void deleteByStudySubjectId(Long studySubjectId); } 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 d35d0bc..c3fc045 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 @@ -9,6 +9,7 @@ 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.business.service.IStudySubjectUserService; import com.hxhq.common.core.exception.ServiceException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,8 @@ public class StudySubjectServiceImpl extends ServiceImpl exists = existsList.stream().filter(o->o.getDeptId().equals(subject.getDeptId())).collect(Collectors.toList()); if(exists.size()>0){ - info.setSelect(true); + info.setId(exists.get(0).getId()); + info.setStudyId(exists.get(0).getStudyId()); info.setLeader(exists.get(0).getLeader()); info.setLeaderName(exists.get(0).getLeaderName()); + info.setSelect(true); }else{ info.setSelect(false); } @@ -110,6 +115,9 @@ public class StudySubjectServiceImpl extends ServiceImpl0){ removeBatchByIds(deleteList); + for(StudySubject del : deleteList){ + studySubjectUserService.deleteByStudySubjectId(del.getId()); + } } } } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudySubjectUserServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudySubjectUserServiceImpl.java index 75d05df..1636681 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudySubjectUserServiceImpl.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudySubjectUserServiceImpl.java @@ -1,13 +1,24 @@ package com.hxhq.business.service.impl; +import java.util.ArrayList; import java.util.List; +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.domain.StudySubject; +import com.hxhq.business.form.study.StudySubjectUserSaveForm; +import com.hxhq.business.service.IStudyService; +import com.hxhq.business.service.IStudySubjectService; +import com.hxhq.common.core.exception.ServiceException; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.hxhq.business.mapper.StudySubjectUserMapper; import com.hxhq.business.domain.StudySubjectUser; import com.hxhq.business.service.IStudySubjectUserService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.transaction.annotation.Transactional; /** * 试验-学科-成员Service业务层处理 @@ -18,17 +29,62 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service public class StudySubjectUserServiceImpl extends ServiceImpl implements IStudySubjectUserService { - /** - * 查询试验-学科-成员列表 - * - * @param studySubjectUser 试验-学科-成员 - * @return 试验-学科-成员 - */ + @Autowired + private IStudySubjectService studySubjectService; + @Override - public List queryList(StudySubjectUser studySubjectUser) - { - QueryWrapper queryWrapper = Wrappers.query(); - return this.list(queryWrapper); + public List getListByStudySubjectId(Long studySubjectId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("study_subject_id",studySubjectId); + return list(queryWrapper); } + @Override + @Transactional(rollbackFor = Exception.class) + public void saveInfo(StudySubjectUserSaveForm form) { + StudySubject studySubject = studySubjectService.getById(form.getStudySubjectId()); + if(studySubject==null){ + throw new ServiceException("试验学科不存在"); + } + //传入的成员信息 + List itemList = form.getSubjectUserList(); + //已经设置的学科信息 + List oldList = getListByStudySubjectId(form.getStudySubjectId()); + List deleteList = new ArrayList<>(); + List addList = new ArrayList<>(); + List modifyList = new ArrayList<>(); + + for(StudySubjectUser item : itemList){ + List existsList = oldList.stream().filter(o->o.getUserId().equals(item.getUserId())).collect(Collectors.toList()); + if(existsList.size()==0){ + item.setStudySubjectId(form.getStudySubjectId()); + addList.add(item); + }else{ + item.setId(existsList.get(0).getId()); + modifyList.add(item); + } + } + + for(StudySubjectUser old : oldList){ + if(itemList.stream().filter(o->o.getUserId().equals(old.getUserId())).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); + } + } + + @Override + public void deleteByStudySubjectId(Long studySubjectId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("study_subject_id",studySubjectId); + remove(queryWrapper); + } } diff --git a/hxhq-modules/hxhq-system/src/main/resources/bootstrap.yml b/hxhq-modules/hxhq-system/src/main/resources/bootstrap.yml index 36474bb..558378b 100644 --- a/hxhq-modules/hxhq-system/src/main/resources/bootstrap.yml +++ b/hxhq-modules/hxhq-system/src/main/resources/bootstrap.yml @@ -3,7 +3,9 @@ server: port: 9201 # Spring -spring: +spring: + main: + allow-circular-references: true application: # 应用名称 name: hxhq-system