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;
}
}