|
|
@@ -0,0 +1,243 @@
|
|
|
+package com.fs.hisStore.service.impl;
|
|
|
+
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.fs.common.BeanCopyUtils;
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
+import com.fs.company.mapper.CompanyUserMapper;
|
|
|
+import com.fs.his.domain.FsDoctor;
|
|
|
+import com.fs.his.mapper.FsDoctorMapper;
|
|
|
+import com.fs.his.service.IFsDoctorService;
|
|
|
+import com.fs.his.service.IFsQuestionAndAnswerService;
|
|
|
+import com.fs.his.vo.AnswerVO;
|
|
|
+import com.fs.his.vo.FsQuestionAndAnswerVO;
|
|
|
+import com.fs.hisStore.param.FsUserInformationCollectionParam;
|
|
|
+import com.fs.hisStore.vo.FsUserInformationCollectionVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.fs.hisStore.mapper.FsUserInformationCollectionMapper;
|
|
|
+import com.fs.hisStore.domain.FsUserInformationCollection;
|
|
|
+import com.fs.hisStore.service.IFsUserInformationCollectionService;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户信息采集Service业务层处理
|
|
|
+ *
|
|
|
+ * @author fs
|
|
|
+ * @date 2025-10-14
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class FsUserInformationCollectionServiceImpl extends ServiceImpl<FsUserInformationCollectionMapper, FsUserInformationCollection> implements IFsUserInformationCollectionService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CompanyUserMapper companyUserMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsDoctorMapper doctorMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsDoctorService iFsDoctorService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsQuestionAndAnswerService questionAndAnswerService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询用户信息采集
|
|
|
+ *
|
|
|
+ * @param id 用户信息采集主键
|
|
|
+ * @return 用户信息采集
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public FsUserInformationCollection selectFsUserInformationCollectionById(Long id)
|
|
|
+ {
|
|
|
+ return baseMapper.selectFsUserInformationCollectionById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询用户信息采集列表
|
|
|
+ *
|
|
|
+ * @param fsUserInformationCollection 用户信息采集
|
|
|
+ * @return 用户信息采集
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<FsUserInformationCollection> selectFsUserInformationCollectionList(FsUserInformationCollection fsUserInformationCollection)
|
|
|
+ {
|
|
|
+ return baseMapper.selectFsUserInformationCollectionList(fsUserInformationCollection);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增用户信息采集
|
|
|
+ *
|
|
|
+ * @param param 用户信息采集
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insertFsUserInformationCollection(FsUserInformationCollectionParam param)
|
|
|
+ {
|
|
|
+
|
|
|
+ FsUserInformationCollection fsUserInformationCollection = getFsUserInformationCollection(param);
|
|
|
+ fsUserInformationCollection.setCreateTime(DateUtils.getNowDate());
|
|
|
+ return baseMapper.insertFsUserInformationCollection(fsUserInformationCollection);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改用户信息采集
|
|
|
+ *
|
|
|
+ * @param param 用户信息采集
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int updateFsUserInformationCollection(FsUserInformationCollectionParam param)
|
|
|
+ {
|
|
|
+ FsUserInformationCollection fsUserInformationCollection = getFsUserInformationCollection(param);
|
|
|
+ fsUserInformationCollection.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ return baseMapper.updateFsUserInformationCollection(fsUserInformationCollection);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除用户信息采集
|
|
|
+ *
|
|
|
+ * @param ids 需要删除的用户信息采集主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteFsUserInformationCollectionByIds(Long[] ids)
|
|
|
+ {
|
|
|
+ return baseMapper.deleteFsUserInformationCollectionByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除用户信息采集信息
|
|
|
+ *
|
|
|
+ * @param id 用户信息采集主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteFsUserInformationCollectionById(Long id)
|
|
|
+ {
|
|
|
+ return baseMapper.deleteFsUserInformationCollectionById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FsUserInformationCollectionVO getInfo(FsUserInformationCollection map) {
|
|
|
+ FsUserInformationCollectionVO vo = new FsUserInformationCollectionVO();
|
|
|
+ Long userId = map.getUserId();
|
|
|
+ Long questionId = map.getQuestionId();
|
|
|
+ FsUserInformationCollection fsUserInformationCollection = baseMapper.selectByUserId(userId);
|
|
|
+ if (fsUserInformationCollection != null) {
|
|
|
+ vo.setQuestionId(fsUserInformationCollection.getQuestionId());
|
|
|
+ vo.setId(fsUserInformationCollection.getId());
|
|
|
+ vo.setAmount(fsUserInformationCollection.getAmount());
|
|
|
+ vo.setPackageId(fsUserInformationCollection.getPackageId());
|
|
|
+ vo.setPayType(fsUserInformationCollection.getPayType());
|
|
|
+ if (map.getQuestionId() == null) {
|
|
|
+ FsQuestionAndAnswerVO questionAndAnswerVO = questionAndAnswerService.selectFsQuestionAndAnswerById(fsUserInformationCollection.getQuestionId());
|
|
|
+ List<AnswerVO> answerVOS = JSON.parseArray(fsUserInformationCollection.getJsonInfo(), AnswerVO.class);
|
|
|
+ List<AnswerVO> collect = getAnswerVOs(answerVOS, questionAndAnswerVO.getAnswers());
|
|
|
+ vo.setAnswers(collect);
|
|
|
+ } else {
|
|
|
+ vo.setAnswers(JSON.parseArray(fsUserInformationCollection.getJsonInfo(), AnswerVO.class));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (questionId != null) {
|
|
|
+ vo.setQuestionId(questionId);
|
|
|
+ //问答数据
|
|
|
+ FsQuestionAndAnswerVO questionAndAnswerVO = questionAndAnswerService.selectFsQuestionAndAnswerById(questionId);
|
|
|
+ if (questionAndAnswerVO != null) {
|
|
|
+ questionAndAnswerVO.getAnswers().forEach(answerVO -> {
|
|
|
+ answerVO.setFlag(false);
|
|
|
+ });
|
|
|
+ if (fsUserInformationCollection != null) {
|
|
|
+ vo.getAnswers().addAll(questionAndAnswerVO.getAnswers());
|
|
|
+ vo.setAnswers(getAnswerVOs(vo.getAnswers(),questionAndAnswerVO.getAnswers()));
|
|
|
+ } else {
|
|
|
+ //返回问答
|
|
|
+ vo.setAnswers(questionAndAnswerVO.getAnswers());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(vo.getAnswers())){
|
|
|
+ //有值且为true排前面
|
|
|
+ List<AnswerVO> collect = vo.getAnswers().stream()
|
|
|
+ .sorted(Comparator.comparing(AnswerVO::getValue, Comparator.nullsFirst(Integer::compareTo)).reversed()).collect(Collectors.toList())
|
|
|
+ .stream()
|
|
|
+ .sorted((a,b)-> Boolean.compare(b.getFlag(),a.getFlag())).collect(Collectors.toList());
|
|
|
+ vo.setAnswers(collect);
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<AnswerVO> getAnswerVOs(List<AnswerVO> target,List<AnswerVO> source) {
|
|
|
+ target.addAll(source);
|
|
|
+ return target.stream()
|
|
|
+ .collect(Collectors.groupingBy(AnswerVO::getTitle))
|
|
|
+ .values().stream()
|
|
|
+ .map(group -> group.stream().reduce((a, b) -> a).orElse(null))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private FsUserInformationCollection getFsUserInformationCollection(FsUserInformationCollectionParam param) {
|
|
|
+ FsUserInformationCollection fsUserInformationCollection = new FsUserInformationCollection();
|
|
|
+ if (!CollectionUtils.isEmpty(param.getAnswers())) {
|
|
|
+ param.getAnswers().forEach(answer -> {
|
|
|
+ if (answer.getFlag() == null) {
|
|
|
+ answer.setFlag(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ fsUserInformationCollection.setJsonInfo(JSON.toJSONString(param.getAnswers()));
|
|
|
+ fsUserInformationCollection.setUserId(param.getUserId());
|
|
|
+ fsUserInformationCollection.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ fsUserInformationCollection.setQuestionId(param.getQuestionId());
|
|
|
+ fsUserInformationCollection.setId(param.getId());
|
|
|
+ fsUserInformationCollection.setPackageId(param.getPackageId());
|
|
|
+ fsUserInformationCollection.setPayType(param.getPayType());
|
|
|
+ fsUserInformationCollection.setAmount(param.getAmount());
|
|
|
+ //获取医生信息
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectCompanyUserById(param.getCompanyUserId());
|
|
|
+ if (companyUser == null) {
|
|
|
+ throw new CustomException("销售不存在");
|
|
|
+ }
|
|
|
+ Long doctorId = null;
|
|
|
+ if (companyUser.getDoctorId() != null) {
|
|
|
+ FsDoctor doctor = doctorMapper.selectFsDoctorByDoctorId(companyUser.getDoctorId());
|
|
|
+ if (doctor != null) {
|
|
|
+ doctorId = doctor.getDoctorId();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //随机获取医生id
|
|
|
+ doctorId = iFsDoctorService.selectFsDoctorDoctorByPackage();
|
|
|
+ }
|
|
|
+ fsUserInformationCollection.setDoctorId(doctorId);
|
|
|
+
|
|
|
+ return fsUserInformationCollection;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String str1 = "[{\"options\":[{\"flag\":false,\"name\":\"通天\",\"value\":0},{\"flag\":false,\"name\":\"哈哈\",\"value\":1}],\"title\":\"测试标题1\",\"value\":1},{\"options\":[{\"flag\":false,\"name\":\"呼呼\",\"value\":0},{\"flag\":false,\"name\":\"嘻嘻\",\"value\":1}],\"title\":\"测试标题2\",\"value\":1},{\"options\":[{\"flag\":false,\"name\":\"胸痛\",\"value\":0},{\"flag\":false,\"name\":\"胸闷\",\"value\":1},{\"flag\":false,\"name\":\"头晕\",\"value\":2},{\"flag\":false,\"name\":\"肢体麻木\",\"value\":3},{\"flag\":false,\"name\":\"无\",\"value\":4}],\"title\":\"您目前是否有心脑血管相关症状,如胸痛、胸闷、头晕、肢体麻木等?\",\"value\":1}]";
|
|
|
+ String str2 = "[{\"options\":[{\"flag\":true,\"name\":\"胸痛\",\"value\":0},{\"flag\":true,\"name\":\"胸闷\",\"value\":1},{\"flag\":true,\"name\":\"头晕\",\"value\":2},{\"flag\":true,\"name\":\"肢体麻木\",\"value\":3},{\"flag\":true,\"name\":\"无\",\"value\":4}],\"title\":\"您目前是否有心脑血管相关症状,如胸痛、胸闷、头晕、肢体麻木等?\",\"value\":1},{\"options\":[{\"flag\":false,\"name\":\"胃疼\",\"value\":0},{\"flag\":false,\"name\":\"反酸\",\"value\":1},{\"flag\":false,\"name\":\"恶心\",\"value\":2},{\"flag\":false,\"name\":\"呕吐\",\"value\":3},{\"flag\":false,\"name\":\"黑便\",\"value\":4},{\"flag\":false,\"name\":\"无\",\"value\":5}],\"title\":\"您近期是否出现胃部不适症状,如胃痛、反酸、恶心、呕吐或黑便?\",\"value\":1}]";
|
|
|
+ List<AnswerVO> vo1 = null;
|
|
|
+ List<AnswerVO> vo2 = JSON.parseArray(str2, AnswerVO.class);
|
|
|
+ System.out.println(vo1);
|
|
|
+ System.out.println(vo2);
|
|
|
+ vo2.addAll(vo1);
|
|
|
+ Map<String, List<AnswerVO>> collect = vo2.stream()
|
|
|
+ .collect(Collectors.groupingBy(AnswerVO::getTitle));
|
|
|
+ List<AnswerVO> collect1 = vo2.stream()
|
|
|
+ .collect(Collectors.groupingBy(AnswerVO::getTitle))
|
|
|
+ .values().stream()
|
|
|
+ .map(group -> group.stream().reduce((a, b) -> a).orElse(null)).collect(Collectors.toList());
|
|
|
+ System.out.println(JSON.toJSONString(collect));
|
|
|
+ System.out.println(JSON.toJSONString(collect1));
|
|
|
+ }
|
|
|
+}
|