|
|
@ -1,21 +1,16 @@ |
|
|
|
package cn.soul2.jyjc.admin.repository.impl; |
|
|
|
package cn.soul2.jyjc.admin.repository.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.soul2.jyjc.admin.dto.AnswerPageQueryDTO; |
|
|
|
import cn.soul2.jyjc.admin.dto.AnswerPageQueryDTO; |
|
|
|
import cn.soul2.jyjc.admin.entity.AnswerDetailsDO; |
|
|
|
import cn.soul2.jyjc.admin.entity.*; |
|
|
|
import cn.soul2.jyjc.admin.entity.AnswerSheetDO; |
|
|
|
|
|
|
|
import cn.soul2.jyjc.admin.entity.QrDO; |
|
|
|
|
|
|
|
import cn.soul2.jyjc.admin.entity.QuestionnaireDO; |
|
|
|
|
|
|
|
import cn.soul2.jyjc.admin.mapper.AnswerSheetMapper; |
|
|
|
import cn.soul2.jyjc.admin.mapper.AnswerSheetMapper; |
|
|
|
import cn.soul2.jyjc.admin.repository.IAnswerDetailsRepository; |
|
|
|
import cn.soul2.jyjc.admin.repository.*; |
|
|
|
import cn.soul2.jyjc.admin.repository.IAnswerSheetRepository; |
|
|
|
|
|
|
|
import cn.soul2.jyjc.admin.repository.IQrRepository; |
|
|
|
|
|
|
|
import cn.soul2.jyjc.admin.repository.IQuestionnaireRepository; |
|
|
|
|
|
|
|
import cn.soul2.jyjc.admin.utils.base.PageUtils; |
|
|
|
import cn.soul2.jyjc.admin.utils.base.PageUtils; |
|
|
|
import cn.soul2.jyjc.admin.vo.AnswerDetailsVO; |
|
|
|
import cn.soul2.jyjc.admin.vo.AnswerDetailsVO; |
|
|
|
import cn.soul2.jyjc.admin.vo.AnswerSheetVO; |
|
|
|
import cn.soul2.jyjc.admin.vo.AnswerSheetVO; |
|
|
|
import cn.soul2.jyjc.admin.vo.base.VPage; |
|
|
|
import cn.soul2.jyjc.admin.vo.base.VPage; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
@ -25,10 +20,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
|
|
|
|
|
|
|
|
|
import javax.transaction.Transactional; |
|
|
|
import javax.transaction.Transactional; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.*; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -51,36 +43,86 @@ public class AnswerSheetRepositoryImpl extends ServiceImpl<AnswerSheetMapper, An |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private IAnswerDetailsRepository detailsRepository; |
|
|
|
private IAnswerDetailsRepository detailsRepository; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private ISubjectItemsRepository subjectItemsRepository; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private ISubjectRepository subjectRepository; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public VPage<AnswerSheetVO> page(AnswerPageQueryDTO dto) { |
|
|
|
public VPage<AnswerSheetVO> page(AnswerPageQueryDTO dto) { |
|
|
|
LambdaQueryWrapper<AnswerSheetDO> query = Wrappers.lambdaQuery(); |
|
|
|
LambdaQueryWrapper<AnswerSheetDO> query = Wrappers.lambdaQuery(); |
|
|
|
query.eq(StringUtils.isNotBlank(dto.getRespondent()), AnswerSheetDO::getRespondent, dto.getRespondent()) |
|
|
|
query.eq(StringUtils.isNotBlank(dto.getRespondent()), AnswerSheetDO::getRespondent, dto.getRespondent()) |
|
|
|
.eq(dto.getStatus() != null, AnswerSheetDO::getStatus, dto.getStatus()) |
|
|
|
.eq(dto.getStatus() != null, AnswerSheetDO::getStatus, dto.getStatus()) |
|
|
|
|
|
|
|
.eq(StringUtils.isNotBlank(dto.getQnId()), AnswerSheetDO::getQnId, dto.getQnId()) |
|
|
|
.orderByDesc(AnswerSheetDO::getUpdatedTime).orderByDesc(AnswerSheetDO::getCreatedTime); |
|
|
|
.orderByDesc(AnswerSheetDO::getUpdatedTime).orderByDesc(AnswerSheetDO::getCreatedTime); |
|
|
|
VPage<AnswerSheetDO> page = PageUtils.to(super.page(PageUtils.build(dto), query)); |
|
|
|
VPage<AnswerSheetDO> page = PageUtils.to(super.page(PageUtils.build(dto), query)); |
|
|
|
List<AnswerSheetDO> rows = page.getRows(); |
|
|
|
List<AnswerSheetDO> rows = page.getRows(); |
|
|
|
Set<String> qnSet = rows.stream().map(AnswerSheetDO::getQnId).collect(Collectors.toSet()); |
|
|
|
Set<String> qnSet = rows.stream().map(AnswerSheetDO::getQnId).collect(Collectors.toSet()); |
|
|
|
Set<String> qrSet = rows.stream().map(AnswerSheetDO::getQrId).collect(Collectors.toSet()); |
|
|
|
Set<String> qrSet = rows.stream().map(AnswerSheetDO::getQrId).collect(Collectors.toSet()); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, QuestionnaireDO> qnMap = questionnaireRepository.listByIds(qnSet).stream().collect(Collectors.toMap(QuestionnaireDO::getId, o -> o, (o1, o2) -> o1)); |
|
|
|
Map<String, QuestionnaireDO> qnMap; |
|
|
|
Map<String, QrDO> qrMap = qrRepository.listByIds(qrSet).stream().collect(Collectors.toMap(QrDO::getId, o -> o, (o1, o2) -> o1)); |
|
|
|
if (CollectionUtils.isNotEmpty(qnSet)) { |
|
|
|
|
|
|
|
qnMap = questionnaireRepository.listByIds(qnSet).stream().collect(Collectors.toMap(QuestionnaireDO::getId, o -> o, (o1, o2) -> o1)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
qnMap = new HashMap<>(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Map<String, QrDO> qrMap; |
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(qrSet)) { |
|
|
|
|
|
|
|
qrMap = qrRepository.listByIds(qrSet).stream().collect(Collectors.toMap(QrDO::getId, o -> o, (o1, o2) -> o1)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
qrMap = new HashMap<>(); |
|
|
|
|
|
|
|
} |
|
|
|
List<AnswerDetailsDO> detailsDOList = detailsRepository.listBySheetIds(rows.stream().map(AnswerSheetDO::getId).collect(Collectors.toList())); |
|
|
|
List<AnswerDetailsDO> detailsDOList = detailsRepository.listBySheetIds(rows.stream().map(AnswerSheetDO::getId).collect(Collectors.toList())); |
|
|
|
|
|
|
|
// List<String> sids = detailsDOList.stream()
|
|
|
|
|
|
|
|
// .filter(e -> e.getSubjectType() == 0 || e.getSubjectType() == 1)
|
|
|
|
|
|
|
|
// .map(AnswerDetailsDO::getAnswerContent)
|
|
|
|
|
|
|
|
// .flatMap(ids -> Arrays.stream(ids.split(",")))
|
|
|
|
|
|
|
|
// .collect(Collectors.toList());
|
|
|
|
|
|
|
|
Map<String, SubjectDO> sMap = subjectRepository.mapByIds(detailsDOList.stream().map(AnswerDetailsDO::getSubjectId).collect(Collectors.toList())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<Integer, List<String>> sidsMap = detailsDOList.stream() |
|
|
|
|
|
|
|
.filter(e -> e.getSubjectType() == 0 || e.getSubjectType() == 1) |
|
|
|
|
|
|
|
.collect(Collectors.groupingBy(AnswerDetailsDO::getSubjectType, |
|
|
|
|
|
|
|
Collectors.mapping(AnswerDetailsDO::getAnswerContent, Collectors.toList()))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> sids = new ArrayList<>(sidsMap.getOrDefault(0, Collections.emptyList())); |
|
|
|
|
|
|
|
if (sidsMap.containsKey(1)) { |
|
|
|
|
|
|
|
sids.addAll(sidsMap.get(1) |
|
|
|
|
|
|
|
.stream().flatMap(ids -> Arrays.stream(ids.split(","))) |
|
|
|
|
|
|
|
.collect(Collectors.toList())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Map<String, SubjectItemsDO> siMap = subjectItemsRepository.mapByIds(sids); |
|
|
|
|
|
|
|
|
|
|
|
return PageUtils.to(page, rows.stream().map(row -> { |
|
|
|
return PageUtils.to(page, rows.stream().map(row -> { |
|
|
|
AnswerSheetVO vo = new AnswerSheetVO(); |
|
|
|
AnswerSheetVO vo = new AnswerSheetVO(); |
|
|
|
BeanUtils.copyProperties(row, vo); |
|
|
|
BeanUtils.copyProperties(row, vo); |
|
|
|
|
|
|
|
vo.setSubmitTime(row.getUpdatedTime()); |
|
|
|
if (qnMap.containsKey(row.getQnId())) { |
|
|
|
if (qnMap.containsKey(row.getQnId())) { |
|
|
|
vo.setQnName(qnMap.get(row.getQnId()).getName()); |
|
|
|
vo.setQnName(qnMap.get(row.getQnId()).getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (qrMap.containsKey(row.getQrId())) { |
|
|
|
if (qrMap.containsKey(row.getQrId())) { |
|
|
|
vo.setQnName(qrMap.get(row.getQrId()).getTip()); |
|
|
|
vo.setQrTip(qrMap.get(row.getQrId()).getTip()); |
|
|
|
} |
|
|
|
} |
|
|
|
vo.setDetails(detailsDOList.stream().filter(d -> d.getAnswerSheetId().equals(row.getId())).map(d -> { |
|
|
|
vo.setDetails(detailsDOList.stream().filter(d -> d.getAnswerSheetId().equals(row.getId())).map(d -> { |
|
|
|
AnswerDetailsVO detailsVO = new AnswerDetailsVO(); |
|
|
|
AnswerDetailsVO dv = new AnswerDetailsVO(); |
|
|
|
BeanUtils.copyProperties(d, detailsVO); |
|
|
|
BeanUtils.copyProperties(d, dv); |
|
|
|
return detailsVO; |
|
|
|
dv.setType(d.getSubjectType()); |
|
|
|
|
|
|
|
if (d.getSubjectType() == 2) { |
|
|
|
|
|
|
|
dv.setAnswerContent(d.getAnswerContent()); |
|
|
|
|
|
|
|
} else if (d.getSubjectType() == 1) { |
|
|
|
|
|
|
|
dv.setAnswerContent(Arrays.stream(d.getAnswerContent().split(",")) |
|
|
|
|
|
|
|
.map(id -> (siMap.containsKey(id) ? siMap.get(id).getContent() : id)) |
|
|
|
|
|
|
|
.collect(Collectors.joining(","))); |
|
|
|
|
|
|
|
} else if (d.getSubjectType() == 0) { |
|
|
|
|
|
|
|
dv.setAnswerContent(siMap.containsKey(d.getAnswerContent()) ? siMap.get(d.getAnswerContent()).getContent() : d.getAnswerContent()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
dv.setAnswerContent(d.getAnswerContent()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dv.setTitle(sMap.containsKey(d.getSubjectId()) ? sMap.get(d.getSubjectId()).getTitle() : "") |
|
|
|
|
|
|
|
.setContent(sMap.containsKey(d.getSubjectId()) ? sMap.get(d.getSubjectId()).getContent() : ""); |
|
|
|
|
|
|
|
return dv; |
|
|
|
}).collect(Collectors.toList())); |
|
|
|
}).collect(Collectors.toList())); |
|
|
|
|
|
|
|
|
|
|
|
return vo; |
|
|
|
return vo; |
|
|
|
}).collect(Collectors.toList())); |
|
|
|
}).collect(Collectors.toList())); |
|
|
|
} |
|
|
|
} |
|
|
|