|  | @ -12,6 +12,7 @@ import com.yihu.jw.entity.base.servicePackage.ServicePackageItemDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.servicePackage.ServicePackageRecordDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.servicePackage.ServicePackageSignRecordDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.archive.ArchiveDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.care.sign.CapacityAssessmentRecordDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.service.BasePatientMedicardCardService;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.PageEnvelop;
 | 
	
	
		
			
				|  | @ -29,6 +30,7 @@ import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  *
 | 
	
	
		
			
				|  | @ -44,7 +46,8 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
 | 
	
		
			
				|  |  |     private ServicePackageDao servicePackageDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ServicePackageItemDao servicePackageItemDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private CapacityAssessmentRecordService capacityAssessmentRecordService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ServicePackageSignRecordDao servicePackageSignRecordDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
	
		
			
				|  | @ -265,8 +268,10 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
 | 
	
		
			
				|  |  |     @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |     public ServicePackageSignRecordDO servicePackageSign(String jsonData,String doctorId,String patientId) throws Exception{
 | 
	
		
			
				|  |  |         ServicePackageSignRecordDO signRecordDO = objectMapper.readValue(jsonData, ServicePackageSignRecordDO.class);
 | 
	
		
			
				|  |  |         signRecordDO.setPatient(patientId);
 | 
	
		
			
				|  |  |         List<ServicePackageRecordDO> recordDOList = signRecordDO.getRecordDOList();
 | 
	
		
			
				|  |  |         String signId = signRecordDO.getId();
 | 
	
		
			
				|  |  |         List<String> idList = new ArrayList<>();
 | 
	
		
			
				|  |  |         if(StringUtil.isEmpty(signId)){
 | 
	
		
			
				|  |  |             List<ServicePackageSignRecordDO> signRecordDOs = servicePackageSignRecordDao.findByStatusAndPatient(1,signRecordDO.getPatient());
 | 
	
		
			
				|  |  |             if(signRecordDOs.size()==0){
 | 
	
	
		
			
				|  | @ -283,19 +288,32 @@ public class ServicePackageService extends BaseJpaService<ServicePackageDO, Serv
 | 
	
		
			
				|  |  |                 signId = signRecordDO.getId();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 //建档状态修改
 | 
	
		
			
				|  |  |                 ArchiveDO archiveDO = archiveDao.findByPatientAndDoctorCode(signRecordDO.getPatient(),doctorId);
 | 
	
		
			
				|  |  |                 ArchiveDO archiveDO = archiveDao.findByPatientAndDoctorCode(patientId,doctorId);
 | 
	
		
			
				|  |  |                 if(archiveDO!=null){
 | 
	
		
			
				|  |  |                     archiveDO.setSignStatus(1);
 | 
	
		
			
				|  |  |                     archiveDao.save(archiveDO);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 signId = signRecordDOs.get(0).getId();
 | 
	
		
			
				|  |  |                 List<ServicePackageRecordDO> existList = servicePackageRecordDao.findBySignId(signId);
 | 
	
		
			
				|  |  |                 idList = existList.stream().map(ServicePackageRecordDO::getServicePackageId).collect(Collectors.toList());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         for (ServicePackageRecordDO recordDO:recordDOList){
 | 
	
		
			
				|  |  |         Iterator<ServicePackageRecordDO> iterator = recordDOList.iterator();
 | 
	
		
			
				|  |  |         while (iterator.hasNext()) {
 | 
	
		
			
				|  |  |             ServicePackageRecordDO recordDO = iterator.next();
 | 
	
		
			
				|  |  |             recordDO.setPatient(patientId);
 | 
	
		
			
				|  |  |             recordDO.setSignId(signId);
 | 
	
		
			
				|  |  |             if (idList.contains(recordDO.getServicePackageId())) {
 | 
	
		
			
				|  |  |                 iterator.remove();//使用迭代器的删除方法删除
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(recordDOList.size()>0){
 | 
	
		
			
				|  |  |             CapacityAssessmentRecordDO capacityAssessmentRecordDO = capacityAssessmentRecordService.findAssessmentByPatientId(patientId);
 | 
	
		
			
				|  |  |             capacityAssessmentRecordDO.setServicePackageStatus(1);
 | 
	
		
			
				|  |  |             capacityAssessmentRecordService.save(capacityAssessmentRecordDO);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         servicePackageRecordDao.save(recordDOList);
 | 
	
		
			
				|  |  |         return signRecordDO;
 |