|  | @@ -1,10 +1,19 @@
 | 
	
		
			
				|  |  |  package com.fs.qw.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.fs.common.exception.CustomException;
 | 
	
		
			
				|  |  |  import com.fs.common.utils.DateUtils;
 | 
	
		
			
				|  |  | +import com.fs.company.domain.CompanyUser;
 | 
	
		
			
				|  |  | +import com.fs.company.service.ICompanyUserService;
 | 
	
		
			
				|  |  | +import com.fs.his.domain.FsFirstDiagnosis;
 | 
	
		
			
				|  |  | +import com.fs.his.domain.FsUser;
 | 
	
		
			
				|  |  | +import com.fs.his.mapper.FsFirstDiagnosisMapper;
 | 
	
		
			
				|  |  | +import com.fs.his.service.IFsUserService;
 | 
	
		
			
				|  |  |  import com.fs.qw.domain.QwExternalContactInfo;
 | 
	
		
			
				|  |  |  import com.fs.qw.mapper.QwExternalContactInfoMapper;
 | 
	
		
			
				|  |  |  import com.fs.qw.mapper.QwExternalContactMapper;
 | 
	
		
			
				|  |  |  import com.fs.qw.service.IQwExternalContactInfoService;
 | 
	
		
			
				|  |  | +import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  | +import org.jetbrains.annotations.NotNull;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.scheduling.annotation.Async;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
	
		
			
				|  | @@ -18,6 +27,7 @@ import java.util.List;
 | 
	
		
			
				|  |  |   * @author fs
 | 
	
		
			
				|  |  |   * @date 2024-11-22
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  | +@Slf4j
 | 
	
		
			
				|  |  |  @Service
 | 
	
		
			
				|  |  |  public class QwExternalContactInfoServiceImpl implements IQwExternalContactInfoService
 | 
	
		
			
				|  |  |  {
 | 
	
	
		
			
				|  | @@ -25,6 +35,12 @@ public class QwExternalContactInfoServiceImpl implements IQwExternalContactInfoS
 | 
	
		
			
				|  |  |      private QwExternalContactInfoMapper qwExternalContactInfoMapper;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      QwExternalContactMapper qwExternalContactMapper;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private ICompanyUserService companyUserService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private IFsUserService userService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private FsFirstDiagnosisMapper diagnosisMapper;
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 查询外部联系人信息表
 | 
	
		
			
				|  |  |       *
 | 
	
	
		
			
				|  | @@ -141,4 +157,48 @@ public class QwExternalContactInfoServiceImpl implements IQwExternalContactInfoS
 | 
	
		
			
				|  |  |      public void updateQwExternalContactInfoByExternalContactId(QwExternalContactInfo qwExternalContactInfo) {
 | 
	
		
			
				|  |  |          qwExternalContactInfoMapper.updateQwExternalContactInfoByExternalContactId(qwExternalContactInfo);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Boolean generateDiagnosis(Long exId, Long companyUserId, Long userId) {
 | 
	
		
			
				|  |  | +        log.info("生成初诊单参数=============>exId:{},companyUserId:{},userId:{}", exId, companyUserId, userId);
 | 
	
		
			
				|  |  | +        if (exId == null || companyUserId == null || userId == null) {
 | 
	
		
			
				|  |  | +            throw new CustomException("参数异常");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        QwExternalContactInfo qwExternalContactInfo = qwExternalContactInfoMapper.selectQwExternalContactInfoByExternalContactId(exId);
 | 
	
		
			
				|  |  | +        if (qwExternalContactInfo == null) {
 | 
	
		
			
				|  |  | +            throw new CustomException("外部联系人信息不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        log.info("外部联系人信息:{}", qwExternalContactInfo);
 | 
	
		
			
				|  |  | +        CompanyUser companyUser = companyUserService.selectCompanyUserById(companyUserId);
 | 
	
		
			
				|  |  | +        if (companyUser == null) {
 | 
	
		
			
				|  |  | +            throw new CustomException("公司用户信息不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        log.info("销售信息:{}", companyUser);
 | 
	
		
			
				|  |  | +        FsUser fsUser = userService.selectFsUserByUserId(userId);
 | 
	
		
			
				|  |  | +        if (fsUser == null) {
 | 
	
		
			
				|  |  | +            throw new CustomException("用户信息不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        log.info("用户信息:{}", fsUser);
 | 
	
		
			
				|  |  | +        FsFirstDiagnosis diagnosis = getFsFirstDiagnosis(companyUserId, userId, qwExternalContactInfo);
 | 
	
		
			
				|  |  | +        int i = diagnosisMapper.insertFsFirstDiagnosis(diagnosis);
 | 
	
		
			
				|  |  | +        return i > 0;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static @NotNull FsFirstDiagnosis getFsFirstDiagnosis(Long companyUserId, Long userId, QwExternalContactInfo qwExternalContactInfo) {
 | 
	
		
			
				|  |  | +        FsFirstDiagnosis diagnosis = new FsFirstDiagnosis();
 | 
	
		
			
				|  |  | +        diagnosis.setUserId(userId);
 | 
	
		
			
				|  |  | +        diagnosis.setQwUserId(companyUserId);
 | 
	
		
			
				|  |  | +        diagnosis.setAge(qwExternalContactInfo.getAge());
 | 
	
		
			
				|  |  | +        long sex = 0L;
 | 
	
		
			
				|  |  | +        if ("男".equals(qwExternalContactInfo.getSex())) {
 | 
	
		
			
				|  |  | +            sex = 1L;
 | 
	
		
			
				|  |  | +        } else if ("女".equals(qwExternalContactInfo.getSex())) {
 | 
	
		
			
				|  |  | +            sex = 2L;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        diagnosis.setGender(sex);
 | 
	
		
			
				|  |  | +        diagnosis.setPhone(qwExternalContactInfo.getPhone());
 | 
	
		
			
				|  |  | +        diagnosis.setPatientName(qwExternalContactInfo.getName());
 | 
	
		
			
				|  |  | +        diagnosis.setPhysicalCondition(qwExternalContactInfo.getBody());
 | 
	
		
			
				|  |  | +        return diagnosis;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |