HospitalController.java 4.15 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
package com.lyms.talkonlineweb.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyms.talkonlineweb.domain.LymsDict;
import com.lyms.talkonlineweb.domain.LymsHospital;
import com.lyms.talkonlineweb.domain.LymsLogsCrud;
import com.lyms.talkonlineweb.domain.LymsRole;
import com.lyms.talkonlineweb.result.BaseResponse;
import com.lyms.talkonlineweb.service.LymsDictService;
import com.lyms.talkonlineweb.service.LymsHospitalService;
import com.lyms.talkonlineweb.service.LymsLogsCrudService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
* 医院管理
*/
@RestController
@RequestMapping("hosp")
public class HospitalController {

@Autowired
private LymsDictService lymsDictService;

@Autowired
private LymsHospitalService lymsHospitalService;

@Autowired
private LymsLogsCrudService lymsLogsCrudService;

/**
* 获取医院列表
* @param hospital
* @param current
* @param size
* @return
*/
@GetMapping("sltHospLst")
public BaseResponse sltHospLst(LymsHospital hospital,int current,int size){
BaseResponse baseResponse=new BaseResponse();
Page<LymsHospital> page=new Page<>(current,size);
Page<LymsHospital> hospPage=lymsHospitalService.page(page, Wrappers.query(hospital).orderByDesc("updatedtime","createdtime"));
converDict(hospPage);
baseResponse.setObject(hospPage);

return baseResponse;
}

/**
* 获取所有医院列表
* @param hospital
* @return
*/
@GetMapping("getAllHospLst")
public BaseResponse getAllHospLst(LymsHospital hospital){
BaseResponse baseResponse=new BaseResponse();
List<LymsHospital> hospPage=lymsHospitalService.list( Wrappers.query(hospital).orderByDesc("updatedtime","createdtime"));

LymsDict dict=new LymsDict();
dict.setVtype(1);
List<LymsDict> lvlList=lymsDictService.list(Wrappers.query(dict));
dict.setVtype(2);
List<LymsDict> tList=lymsDictService.list(Wrappers.query(dict));

hospPage.forEach(r->{
for(LymsDict d:lvlList){
if(d.getCode()==r.getHlevel()){
r.setLvlname(d.getValue());
}
}
for(LymsDict d:tList){
if(d.getCode()==r.getHtype()){
r.setTname(d.getValue());
}
}
});

baseResponse.setObject(hospPage);

return baseResponse;
}

private void converDict(Page<LymsHospital> hospPage){
LymsDict dict=new LymsDict();
dict.setVtype(1);
List<LymsDict> lvlList=lymsDictService.list(Wrappers.query(dict));
dict.setVtype(2);
List<LymsDict> tList=lymsDictService.list(Wrappers.query(dict));
hospPage.getRecords().forEach(r->{
for(LymsDict d:lvlList){
if(d.getCode()==r.getHlevel()){
r.setLvlname(d.getValue());
}
}
for(LymsDict d:tList){
if(d.getCode()==r.getHtype()){
r.setTname(d.getValue());
}
}
});
}

/**
* 保存或更新医院信息
* @param hospital
* @return
*/
@PostMapping("saveHosp")
public BaseResponse saveHosp(@RequestBody LymsHospital hospital){
BaseResponse baseResponse=new BaseResponse();
if(hospital.getHid()==null){
hospital.setCreatedtime(new Date());
}else{
hospital.setUpdatedtime(new Date());
}
boolean f=lymsHospitalService.saveOrUpdate(hospital);

baseResponse.setErrorcode(f==true?0:1);
return baseResponse;
}

/**
* 删除医院
* @param hid
* @return
*/
@GetMapping("delHosp")
public BaseResponse delHosp(int hid){
BaseResponse baseResponse=new BaseResponse();
boolean f=lymsHospitalService.removeById(hid);
baseResponse.setErrorcode(f==true?0:1);
return baseResponse;
}

}