package cn.com.qmth.mps.service.impl; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.qmth.boot.core.exception.StatusException; import cn.com.qmth.mps.bean.PaperDetail; import cn.com.qmth.mps.bean.PaperDetailUnit; import cn.com.qmth.mps.bean.User; import cn.com.qmth.mps.dao.PaperDetailDao; import cn.com.qmth.mps.entity.PaperDetailEntity; import cn.com.qmth.mps.entity.PaperEntity; import cn.com.qmth.mps.enums.Role; import cn.com.qmth.mps.service.PaperDetailService; import cn.com.qmth.mps.service.PaperDetailUnitService; import cn.com.qmth.mps.service.PaperGroupService; import cn.com.qmth.mps.service.PaperService; import cn.com.qmth.mps.util.Calculator; import cn.com.qmth.mps.vo.paper.StructDomain; @Service public class PaperDetailServiceImpl extends ServiceImpl implements PaperDetailService { @Autowired private PaperGroupService paperGroupService; @Autowired private PaperDetailUnitService paperDetailUnitService; @Autowired private PaperService paperService; @Override public List getStructInfo(Long paperId) { List ret = new ArrayList<>(); List es = getByPaperId(paperId); if (CollectionUtils.isEmpty(es)) { return ret; } Map map=new HashMap<>(); for(PaperDetailEntity e:es) { PaperDetail vo=new PaperDetail(); vo.setName(e.getName()); vo.setNumber(e.getNumber()); map.put(e.getId(), vo); ret.add(vo); } Map> units=paperDetailUnitService.getStructInfo(paperId); if (units==null||units.size()==0) { return ret; } for(Long key:units.keySet()) { map.get(key).setUnits(units.get(key)); } return ret; } @Override public List getByPaperId(Long paperId) { QueryWrapper wrapper = new QueryWrapper<>(); LambdaQueryWrapper lw = wrapper.lambda(); lw.eq(PaperDetailEntity::getPaperId, paperId); return this.list(wrapper); } @Transactional @Override public void structSave(StructDomain domain, User user) { if (domain.getPaperId() == null) { throw new StatusException("试卷结构ID不能为空"); } if (domain.getTotalScore() == null) { throw new StatusException("试卷满分不能为空"); } if (domain.getTotalScore()<=0) { throw new StatusException("试卷满分必须大于0"); } String total=domain.getTotalScore().toString(); if (total.indexOf(".") wrapper = new QueryWrapper<>(); LambdaQueryWrapper lw = wrapper.lambda(); lw.eq(PaperDetailEntity::getPaperId, paperId); this.remove(wrapper); } @Transactional @Override public void structSubmit(StructDomain domain, User user) { if (domain.getPaperId() == null) { throw new StatusException("试卷结构ID不能为空"); } if (domain.getTotalScore() == null) { throw new StatusException("试卷满分不能为空"); } if (domain.getTotalScore()<=0) { throw new StatusException("试卷满分必须大于0"); } String total=domain.getTotalScore().toString(); if (total.indexOf(".")