DataHandingService.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.yihu.wlyy.statistics.data;
  2. import com.yihu.wlyy.statistics.dao.DoctorDao;
  3. import com.yihu.wlyy.statistics.dao.PatientDao;
  4. import com.yihu.wlyy.statistics.model.doctor.Doctor;
  5. import com.yihu.wlyy.statistics.model.patient.Patient;
  6. import com.yihu.wlyy.statistics.util.MD5;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import org.springframework.transaction.annotation.Transactional;
  10. import org.springframework.util.StringUtils;
  11. import java.util.List;
  12. import java.util.UUID;
  13. /**
  14. * Created by Administrator on 2016.10.17.
  15. */
  16. @Service
  17. public class DataHandingService {
  18. @Autowired
  19. private PatientDao patientDao;
  20. @Autowired
  21. private DoctorDao doctorDao;
  22. @Transactional
  23. public String producePatientAndDoctorPassword() {
  24. int patientCount=0;
  25. int patientErrorCount=0;
  26. int doctorCount=0;
  27. int doctorErrorCount=0;
  28. List<Patient> patients= patientDao.findAllIdCardPatientAndNoPassword();
  29. for (Patient patient:patients){
  30. String idcard=patient.getIdcard();
  31. if(!StringUtils.isEmpty(patient.getPassword())||StringUtils.isEmpty(idcard)||(idcard.length()!=15&&idcard.length()!=18)){
  32. patientErrorCount++;
  33. continue;
  34. }
  35. String password=idcard.substring(idcard.length()-6);
  36. String salt= UUID.randomUUID().toString().replace("-","");
  37. patient.setSalt(salt);
  38. patient.setPassword(MD5.GetMD5Code(password+salt));
  39. patientCount++;
  40. }
  41. patientDao.save(patients);
  42. List<Doctor> doctors= doctorDao.findAllNoPasswordDoctors();
  43. for (Doctor doctor:doctors){
  44. String phone= doctor.getMobile();
  45. if(!StringUtils.isEmpty(doctor.getPassword())||StringUtils.isEmpty(phone)||phone.length()!=11){
  46. doctorErrorCount++;
  47. continue;
  48. }
  49. String password=phone.substring(5);
  50. String salt= UUID.randomUUID().toString().replace("-","");
  51. doctor.setSalt(salt);
  52. doctor.setPassword(MD5.GetMD5Code(password+salt));
  53. doctorCount++;
  54. }
  55. doctorDao.save(doctors);
  56. return "更新患者(默认身份证后六位):"+patientCount+",有身份证异常的患者:"+patientErrorCount+",更新医生(默认电话后六位):"+doctorCount+",有电话号码异常的医生:"+doctorErrorCount;
  57. }
  58. }