ABasDeptInfoFacade.java 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package com.diagbot.facade.databack;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.diagbot.dto.RespDTO;
  4. import com.diagbot.dto.data.ABasDeptInfoDTO;
  5. import com.diagbot.entity.BasDeptInfo;
  6. import com.diagbot.enums.IsDeleteEnum;
  7. import com.diagbot.service.impl.BasDeptInfoServiceImpl;
  8. import com.diagbot.util.BeanUtil;
  9. import com.diagbot.util.TZDBConn;
  10. import com.diagbot.vo.data.ABasDeptInfoVO;
  11. import com.google.common.collect.Lists;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.beans.factory.annotation.Qualifier;
  14. import org.springframework.stereotype.Component;
  15. import java.util.Date;
  16. import java.util.List;
  17. @Component
  18. public class ABasDeptInfoFacade {
  19. @Autowired
  20. @Qualifier("basDeptInfoServiceImpl")
  21. private BasDeptInfoServiceImpl basDeptInfoServiceImpl;
  22. private TZDBConn tzDBConn = new TZDBConn();
  23. /**
  24. * 同步前一天科室的信息
  25. */
  26. public void executeDept() {
  27. String sql="select * from hi_deptinfo where cjcxrq>=dateadd(day,-2,getdate()) and cjcxrq<=getdate()";
  28. List<BasDeptInfo> basDeptInfoList = tzDBConn.getDeptInfo(sql);
  29. execute(basDeptInfoList);
  30. }
  31. /**
  32. * 同步历史数据
  33. */
  34. public void executeDeptPast(){
  35. String sql="select * from hi_deptinfo where cjcxrq>=dateadd(day,-2,getdate()) and cjcxrq<=getdate()";
  36. List<BasDeptInfo> basDeptInfoList = tzDBConn.getDeptInfo(sql);
  37. execute(basDeptInfoList);
  38. }
  39. public void executeDeptPort(){
  40. }
  41. /**
  42. * 通过接口同步数据
  43. * @param list
  44. * @return
  45. */
  46. public RespDTO<List<ABasDeptInfoDTO>> executeDept(List<ABasDeptInfoVO> list) {
  47. if(list!=null && list.size()>0){
  48. List<BasDeptInfo> basDeptInfoList=Lists.newArrayList();
  49. List<ABasDeptInfoDTO> basDeptInfoDtoList=Lists.newArrayList();
  50. basDeptInfoList=BeanUtil.listCopyTo(list,BasDeptInfo.class);
  51. basDeptInfoDtoList=BeanUtil.listCopyTo(list,ABasDeptInfoDTO.class);
  52. //循环验证数据有效性
  53. for (BasDeptInfo basDeptInfo:basDeptInfoList) {
  54. if("".equals(basDeptInfo.getDeptId())) {
  55. return RespDTO.onError("请输入科室编码!");
  56. }else if(basDeptInfo.getHospitalId()==null){
  57. return RespDTO.onError("请输入医院编码!");
  58. }else if("".equals(basDeptInfo.getDeptName())){
  59. return RespDTO.onError("请输入科室名称!");
  60. }
  61. }
  62. execute(basDeptInfoList);
  63. return RespDTO.onSuc(basDeptInfoDtoList);
  64. }else {
  65. return RespDTO.onError("未接收到数据!");
  66. }
  67. }
  68. public void execute(List<BasDeptInfo> basDeptInfoList){
  69. basDeptInfoList.stream().forEach(s -> {
  70. QueryWrapper<BasDeptInfo> queryWrapper = new QueryWrapper<>();
  71. queryWrapper.in("dept_id", s.getDeptId());
  72. queryWrapper.eq("hospital_id", s.getHospitalId());
  73. queryWrapper.eq("is_deleted",IsDeleteEnum.N);
  74. BasDeptInfo basDeptInfo = basDeptInfoServiceImpl.getOne(queryWrapper);
  75. if (basDeptInfo != null) {
  76. s.setGmtModified(new Date());
  77. basDeptInfoServiceImpl.update(s,queryWrapper);
  78. } else {
  79. s.setGmtCreate(new Date());
  80. basDeptInfoServiceImpl.save(s);
  81. }
  82. });
  83. }
  84. }