1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package com.diagbot.facade.databack;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.diagbot.dto.RespDTO;
- import com.diagbot.dto.data.ABasDeptInfoDTO;
- import com.diagbot.entity.BasDeptInfo;
- import com.diagbot.enums.IsDeleteEnum;
- import com.diagbot.service.impl.BasDeptInfoServiceImpl;
- import com.diagbot.util.BeanUtil;
- import com.diagbot.util.TZDBConn;
- import com.diagbot.vo.data.ABasDeptInfoVO;
- import com.google.common.collect.Lists;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.stereotype.Component;
- import java.util.Date;
- import java.util.List;
- @Component
- public class ABasDeptInfoFacade {
- @Autowired
- @Qualifier("basDeptInfoServiceImpl")
- private BasDeptInfoServiceImpl basDeptInfoServiceImpl;
- private TZDBConn tzDBConn = new TZDBConn();
- /**
- * 同步前一天科室的信息
- */
- public void executeDept() {
- String sql="select * from hi_deptinfo where cjcxrq>=dateadd(day,-2,getdate()) and cjcxrq<=getdate()";
- List<BasDeptInfo> basDeptInfoList = tzDBConn.getDeptInfo(sql);
- execute(basDeptInfoList);
- }
- /**
- * 同步历史数据
- */
- public void executeDeptPast(){
- String sql="select * from hi_deptinfo where cjcxrq>=dateadd(day,-2,getdate()) and cjcxrq<=getdate()";
- List<BasDeptInfo> basDeptInfoList = tzDBConn.getDeptInfo(sql);
- execute(basDeptInfoList);
- }
- public void executeDeptPort(){
- }
- /**
- * 通过接口同步数据
- * @param list
- * @return
- */
- public RespDTO<List<ABasDeptInfoDTO>> executeDept(List<ABasDeptInfoVO> list) {
- if(list!=null && list.size()>0){
- List<BasDeptInfo> basDeptInfoList=Lists.newArrayList();
- List<ABasDeptInfoDTO> basDeptInfoDtoList=Lists.newArrayList();
- basDeptInfoList=BeanUtil.listCopyTo(list,BasDeptInfo.class);
- basDeptInfoDtoList=BeanUtil.listCopyTo(list,ABasDeptInfoDTO.class);
- //循环验证数据有效性
- for (BasDeptInfo basDeptInfo:basDeptInfoList) {
- if("".equals(basDeptInfo.getDeptId())) {
- return RespDTO.onError("请输入科室编码!");
- }else if(basDeptInfo.getHospitalId()==null){
- return RespDTO.onError("请输入医院编码!");
- }else if("".equals(basDeptInfo.getDeptName())){
- return RespDTO.onError("请输入科室名称!");
- }
- }
- execute(basDeptInfoList);
- return RespDTO.onSuc(basDeptInfoDtoList);
- }else {
- return RespDTO.onError("未接收到数据!");
- }
- }
- public void execute(List<BasDeptInfo> basDeptInfoList){
- basDeptInfoList.stream().forEach(s -> {
- QueryWrapper<BasDeptInfo> queryWrapper = new QueryWrapper<>();
- queryWrapper.in("dept_id", s.getDeptId());
- queryWrapper.eq("hospital_id", s.getHospitalId());
- queryWrapper.eq("is_deleted",IsDeleteEnum.N);
- BasDeptInfo basDeptInfo = basDeptInfoServiceImpl.getOne(queryWrapper);
- if (basDeptInfo != null) {
- s.setGmtModified(new Date());
- basDeptInfoServiceImpl.update(s,queryWrapper);
- } else {
- s.setGmtCreate(new Date());
- basDeptInfoServiceImpl.save(s);
- }
- });
- }
- }
|