Browse Source

feat: [试验管理] 设置学科功能

master
memorylkf 2 weeks ago
parent
commit
b0a91a555a
5 changed files with 118 additions and 38 deletions
  1. +18
    -20
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudySubjectController.java
  2. +2
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/StudySubject.java
  3. +36
    -0
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/study/StudySubjectSaveForm.java
  4. +11
    -5
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStudySubjectService.java
  5. +51
    -13
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudySubjectServiceImpl.java

+ 18
- 20
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/StudySubjectController.java View File

@ -1,8 +1,10 @@
package com.hxhq.business.controller; package com.hxhq.business.controller;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import com.hxhq.business.form.study.StudySubjectSaveForm;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.hxhq.business.domain.StudySubject; 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<StudySubject> 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") @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();
} }
} }

+ 2
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/StudySubject.java View File

@ -1,5 +1,6 @@
package com.hxhq.business.domain; package com.hxhq.business.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.hxhq.common.core.domain.MpBaseEntity; import com.hxhq.common.core.domain.MpBaseEntity;
@ -33,6 +34,7 @@ public class StudySubject extends MpBaseEntity
/** /**
* 是否选中 * 是否选中
*/ */
@TableField(exist = false)
private Boolean select; private Boolean select;

+ 36
- 0
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/study/StudySubjectSaveForm.java View File

@ -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<StudySubject> subjectList;
public Long getStudyId() {
return studyId;
}
public void setStudyId(Long studyId) {
this.studyId = studyId;
}
public List<StudySubject> getSubjectList() {
return subjectList;
}
public void setSubjectList(List<StudySubject> subjectList) {
this.subjectList = subjectList;
}
}

+ 11
- 5
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/IStudySubjectService.java View File

@ -3,6 +3,7 @@ package com.hxhq.business.service;
import java.util.List; import java.util.List;
import com.hxhq.business.domain.StudySubject; import com.hxhq.business.domain.StudySubject;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.hxhq.business.form.study.StudySubjectSaveForm;
/** /**
* 试验-学科Service接口 * 试验-学科Service接口
@ -13,12 +14,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
public interface IStudySubjectService extends IService<StudySubject> public interface IStudySubjectService extends IService<StudySubject>
{ {
/** /**
* 查询试验-学科列表
*
* @param studySubject 试验-学科
* @return 试验-学科集合
* 获取已经设置的学科信息
* @param studyId
* @return
*/ */
public List<StudySubject> queryList(StudySubject studySubject);
List<StudySubject> getListByStudyId(Long studyId);
/** /**
* 获取试验下的学科设置信息(含未设置的学科) * 获取试验下的学科设置信息(含未设置的学科)
@ -27,4 +27,10 @@ public interface IStudySubjectService extends IService
*/ */
List<StudySubject> getAllListByStudyId(Long studyId); List<StudySubject> getAllListByStudyId(Long studyId);
/**
* 设置学科信息
* @param form
*/
void saveInfo(StudySubjectSaveForm form);
} }

+ 51
- 13
hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/StudySubjectServiceImpl.java View File

@ -6,11 +6,17 @@ import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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 org.springframework.stereotype.Service;
import com.hxhq.business.mapper.StudySubjectMapper; import com.hxhq.business.mapper.StudySubjectMapper;
import com.hxhq.business.domain.StudySubject; import com.hxhq.business.domain.StudySubject;
import com.hxhq.business.service.IStudySubjectService; import com.hxhq.business.service.IStudySubjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
/** /**
* 试验-学科Service业务层处理 * 试验-学科Service业务层处理
@ -21,18 +27,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service @Service
public class StudySubjectServiceImpl extends ServiceImpl<StudySubjectMapper, StudySubject> implements IStudySubjectService public class StudySubjectServiceImpl extends ServiceImpl<StudySubjectMapper, StudySubject> implements IStudySubjectService
{ {
/**
* 查询试验-学科列表
*
* @param studySubject 试验-学科
* @return 试验-学科
*/
@Override
public List<StudySubject> queryList(StudySubject studySubject)
{
QueryWrapper<StudySubject> queryWrapper = Wrappers.query();
return this.list(queryWrapper);
}
@Autowired
private IStudyService studyService;
/** /**
* 获取试验下的学科设置信息(含未设置的学科) * 获取试验下的学科设置信息(含未设置的学科)
@ -69,9 +65,51 @@ public class StudySubjectServiceImpl extends ServiceImpl
* @param studyId * @param studyId
* @return * @return
*/ */
private List<StudySubject> getListByStudyId(Long studyId){
@Override
public List<StudySubject> getListByStudyId(Long studyId){
QueryWrapper<StudySubject> queryWrapper = new QueryWrapper<>(); QueryWrapper<StudySubject> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("study_id",studyId); queryWrapper.eq("study_id",studyId);
return list(queryWrapper); 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<StudySubject> itemList = form.getSubjectList();
//已经设置的学科信息
List<StudySubject> oldList = getListByStudyId(form.getStudyId());
List<StudySubject> deleteList = new ArrayList<>();
List<StudySubject> addList = new ArrayList<>();
List<StudySubject> 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);
}
}
} }

Loading…
Cancel
Save