123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package com.yihu.wlyy.statistics.data;
- import com.yihu.wlyy.statistics.dao.DoctorDao;
- import com.yihu.wlyy.statistics.dao.PatientDao;
- import com.yihu.wlyy.statistics.model.doctor.Doctor;
- import com.yihu.wlyy.statistics.model.patient.Patient;
- import com.yihu.wlyy.statistics.util.MD5;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.StringUtils;
- import java.util.List;
- import java.util.UUID;
- /**
- * Created by Administrator on 2016.10.17.
- */
- @Service
- public class DataHandingService {
- @Autowired
- private PatientDao patientDao;
- @Autowired
- private DoctorDao doctorDao;
- @Transactional
- public String producePatientAndDoctorPassword() {
- int patientCount=0;
- int patientErrorCount=0;
- int doctorCount=0;
- int doctorErrorCount=0;
- List<Patient> patients= patientDao.findAllIdCardPatientAndNoPassword();
- for (Patient patient:patients){
- String idcard=patient.getIdcard();
- if(!StringUtils.isEmpty(patient.getPassword())||StringUtils.isEmpty(idcard)||(idcard.length()!=15&&idcard.length()!=18)){
- patientErrorCount++;
- continue;
- }
- String password=idcard.substring(idcard.length()-6);
- String salt= UUID.randomUUID().toString().replace("-","");
- patient.setSalt(salt);
- patient.setPassword(MD5.GetMD5Code(password+salt));
- patientCount++;
- }
- patientDao.save(patients);
- List<Doctor> doctors= doctorDao.findAllNoPasswordDoctors();
- for (Doctor doctor:doctors){
- String phone= doctor.getMobile();
- if(!StringUtils.isEmpty(doctor.getPassword())||StringUtils.isEmpty(phone)||phone.length()!=11){
- doctorErrorCount++;
- continue;
- }
- String password=phone.substring(5);
- String salt= UUID.randomUUID().toString().replace("-","");
- doctor.setSalt(salt);
- doctor.setPassword(MD5.GetMD5Code(password+salt));
- doctorCount++;
- }
- doctorDao.save(doctors);
- return "更新患者(默认身份证后六位):"+patientCount+",有身份证异常的患者:"+patientErrorCount+",更新医生(默认电话后六位):"+doctorCount+",有电话号码异常的医生:"+doctorErrorCount;
- }
- }
|