|
|
@@ -0,0 +1,176 @@
|
|
|
+package com.fs.hisStore.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
+import com.fs.his.domain.FsUser;
|
|
|
+import com.fs.his.domain.FsUserAddress;
|
|
|
+import com.fs.his.dto.CPWUserAndAddressAddDTO;
|
|
|
+import com.fs.his.dto.CPWUserBaseInfoAddDTO;
|
|
|
+import com.fs.his.dto.CPWUserInfoCollectionAddDTO;
|
|
|
+import com.fs.his.mapper.FsUserAddressMapper;
|
|
|
+import com.fs.his.mapper.FsUserMapper;
|
|
|
+import com.fs.his.service.IFsQuestionAndAnswerService;
|
|
|
+import com.fs.his.utils.IdCardUtil;
|
|
|
+import com.fs.his.vo.FsQuestionAndAnswerVO;
|
|
|
+import com.fs.his.vo.SubmitUserInformationVO;
|
|
|
+import com.fs.hisStore.domain.FsUserInformationCollection;
|
|
|
+import com.fs.hisStore.mapper.FsUserInformationCollectionMapper;
|
|
|
+import com.fs.hisStore.service.IOpenApiCPWUserInformationService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static com.fs.his.utils.PhoneUtil.decryptPhone;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 对接-超拼网-信息采集服务实现类
|
|
|
+ * */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class OpenApiCPWUserInformationServiceImpl implements IOpenApiCPWUserInformationService {
|
|
|
+
|
|
|
+ /** 默认患者问题模板id */
|
|
|
+ private static final Long QUESTION_ID = 10L;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFsQuestionAndAnswerService questionAndAnswerService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserMapper fsUserMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserAddressMapper fsUserAddressMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserInformationCollectionMapper fsUserInformationCollectionMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FsQuestionAndAnswerVO getInformationTemplate() {
|
|
|
+ try {
|
|
|
+ FsQuestionAndAnswerVO questionAndAnswerVo = questionAndAnswerService.selectFsQuestionAndAnswerById(QUESTION_ID);
|
|
|
+ if (questionAndAnswerVo == null) {
|
|
|
+ log.error("未找到患者问题模板,模板id:{}", QUESTION_ID);
|
|
|
+ throw new CustomException("未找到信息采集模板", 404);
|
|
|
+ }
|
|
|
+ return questionAndAnswerVo;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取信息采集模板失败", e);
|
|
|
+ throw new CustomException("获取信息采集模板失败,请稍后重试", 500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SubmitUserInformationVO createUserInformationCPW(CPWUserAndAddressAddDTO cpwUserAndAddressAddDTO) {
|
|
|
+ SubmitUserInformationVO resultVO=new SubmitUserInformationVO();
|
|
|
+ //创建fs_user用户信息
|
|
|
+ CPWUserBaseInfoAddDTO userBaseInfo = cpwUserAndAddressAddDTO.getUserBaseInfo();
|
|
|
+ FsUser addFsUser = transformUserDtoToFsUser(userBaseInfo);
|
|
|
+ int addResult1 = fsUserMapper.insertFsUser(addFsUser);
|
|
|
+ if (addResult1 <= 0) {
|
|
|
+ throw new CustomException("用户信息保存失败", 500);
|
|
|
+ }
|
|
|
+ //新增fs_user_address用户地址信息
|
|
|
+ FsUserAddress address=buildUserAddress(cpwUserAndAddressAddDTO.getAddress(),addFsUser);
|
|
|
+ int addResult2 = fsUserAddressMapper.insertFsUserAddress(address);
|
|
|
+ if (addResult2 <= 0) {
|
|
|
+ throw new CustomException("用户地址信息保存失败", 500);
|
|
|
+ }
|
|
|
+ resultVO.setUserId(addFsUser.getUserId());
|
|
|
+ resultVO.setStatus(BigDecimal.ONE.intValue());
|
|
|
+ resultVO.setMessage("提交成功");
|
|
|
+ resultVO.setSubmitTime(DateUtils.getTime());
|
|
|
+ return resultVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ //@Transactional(rollbackFor = Exception.class)
|
|
|
+ public SubmitUserInformationVO submitUserInformation(CPWUserInfoCollectionAddDTO collectionAddDTO) {
|
|
|
+ //新增fs_user_information_collection用户采集信息
|
|
|
+ Long userId = collectionAddDTO.getUserId();
|
|
|
+ FsUser fsUserQueryCondition=new FsUser();
|
|
|
+ fsUserQueryCondition.setUserId(userId);
|
|
|
+ fsUserQueryCondition.setUserSource(2);//超拼网用户
|
|
|
+ List<FsUser> fsUsers = fsUserMapper.selectFsUserList(fsUserQueryCondition);
|
|
|
+ if (CollectionUtils.isEmpty(fsUsers)) {
|
|
|
+ log.error("超拼网提交用户采集信息,用户不存在,用户id:{}", userId);
|
|
|
+ throw new CustomException("用户不存在", 500);
|
|
|
+ }
|
|
|
+ FsUserInformationCollection fsUserInformationCollection = transformUserDtoToFsUserCollection(collectionAddDTO,fsUsers.get(0));
|
|
|
+ int addResult = fsUserInformationCollectionMapper.insertFsUserInformationCollection(fsUserInformationCollection);
|
|
|
+ if (addResult <= 0) {
|
|
|
+ throw new CustomException("采集信息保存失败", 500);
|
|
|
+ }
|
|
|
+ //构建成功返回结果
|
|
|
+ SubmitUserInformationVO resultVO = new SubmitUserInformationVO();
|
|
|
+ resultVO.setUserId(fsUserInformationCollection.getUserId());
|
|
|
+ resultVO.setCollectionId(fsUserInformationCollection.getId());
|
|
|
+ resultVO.setStatus(BigDecimal.ONE.intValue());
|
|
|
+ resultVO.setMessage("提交成功");
|
|
|
+ resultVO.setSubmitTime(DateUtils.getTime());
|
|
|
+ log.info("超拼网---用户采集信息提交成功,userId: {}, collectionId: {}",
|
|
|
+ userId, fsUserInformationCollection.getId());
|
|
|
+ return resultVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object pushPrescription(String userId, String prescriptionId) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转换用户信息fs_user
|
|
|
+ * */
|
|
|
+ private FsUser transformUserDtoToFsUser(CPWUserBaseInfoAddDTO userBaseInfo) {
|
|
|
+ FsUser fsUser=new FsUser();
|
|
|
+ fsUser.setRealName(userBaseInfo.getRealName());
|
|
|
+ fsUser.setNickname("超拼网用户"+userBaseInfo.getUserPhone().substring(userBaseInfo.getUserPhone().length()-4));
|
|
|
+ fsUser.setIdCard(userBaseInfo.getIdCard());
|
|
|
+ fsUser.setVipLevel(BigDecimal.ZERO.intValue());
|
|
|
+ fsUser.setUserSource(2);//超拼网用户
|
|
|
+ fsUser.setIsDel(BigDecimal.ZERO.intValue());
|
|
|
+ fsUser.setStatus(BigDecimal.ONE.intValue());
|
|
|
+ fsUser.setCreateTime(DateUtils.getNowDate());
|
|
|
+ fsUser.setPhone(userBaseInfo.getUserPhone());
|
|
|
+ return fsUser;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建用户地址信息
|
|
|
+ * */
|
|
|
+ private FsUserAddress buildUserAddress(FsUserAddress fsUserAddress,FsUser addFsUser) {
|
|
|
+ fsUserAddress.setUserId(addFsUser.getUserId());
|
|
|
+ fsUserAddress.setPhone(decryptPhone(addFsUser.getPhone()));
|
|
|
+ fsUserAddress.setDetail(fsUserAddress.getDetail().trim());
|
|
|
+ fsUserAddress.setCreateTime(DateUtils.getNowDate());
|
|
|
+ fsUserAddress.setIsDefault(BigDecimal.ONE.intValue());
|
|
|
+ fsUserAddress.setIsDel(BigDecimal.ZERO.intValue());
|
|
|
+ return fsUserAddress;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 转换用户采集信息fs_user_information_collection
|
|
|
+ * */
|
|
|
+ private FsUserInformationCollection transformUserDtoToFsUserCollection(CPWUserInfoCollectionAddDTO collectionAddDTO,FsUser fsUser) {
|
|
|
+ FsUserInformationCollection fsUserInformationCollection=new FsUserInformationCollection();
|
|
|
+ fsUserInformationCollection.setUserId(collectionAddDTO.getUserId());
|
|
|
+ fsUserInformationCollection.setQuestionId(QUESTION_ID);
|
|
|
+ fsUserInformationCollection.setUserName(fsUser.getRealName());
|
|
|
+ fsUserInformationCollection.setUserPhoneFour(fsUser.getPhone().substring(fsUser.getPhone().length()-4));//手机号后四位
|
|
|
+ fsUserInformationCollection.setSex((long) IdCardUtil.getGenderByIdCard(fsUser.getIdCard()));
|
|
|
+ fsUserInformationCollection.setAge(IdCardUtil.getAgeByIdCard(fsUser.getIdCard()));//年龄
|
|
|
+ fsUserInformationCollection.setAllergy(collectionAddDTO.getAllergy());
|
|
|
+ fsUserInformationCollection.setRemark(collectionAddDTO.getRemark());
|
|
|
+ fsUserInformationCollection.setInfoSource(2);//超拼网用户采集信息
|
|
|
+ fsUserInformationCollection.setCreateTime(DateUtils.getNowDate());
|
|
|
+ fsUserInformationCollection.setUserConfirm(BigDecimal.ZERO.intValue());//用户第一次确认 0-未确认 1-已确认
|
|
|
+ fsUserInformationCollection.setUserConfirm2(BigDecimal.ZERO.intValue());//用户第二次确认 0-未确认 1-已确认
|
|
|
+ fsUserInformationCollection.setDoctorConfirm(BigDecimal.ZERO.intValue());//医生确认开方 0-未确认 1-已确认
|
|
|
+ fsUserInformationCollection.setJsonInfo(JSON.toJSONString(collectionAddDTO.getAnswers()));//采集信息
|
|
|
+ return fsUserInformationCollection;
|
|
|
+ }
|
|
|
+}
|