DoctorController.java 9.2 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
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
package com.lyms.talkonlineweb.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyms.talkonlineweb.domain.*;
import com.lyms.talkonlineweb.result.BaseResponse;
import com.lyms.talkonlineweb.service.*;
import com.lyms.talkonlineweb.util.Constant;
import com.lyms.talkonlineweb.util.HXService;
import com.lyms.talkonlineweb.util.JwtUtils;
import com.lyms.talkonlineweb.util.StringUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
* 医生管理
*/
@RestController
@RequestMapping("doctor")
@Log4j2
public class DoctorController {

@Autowired
private LymsDoctorService lymsDoctorService;

@Autowired
private LymsHdepartService lymsHdepartService;
@Autowired
private LymsHospitalService lymsHospitalService;
@Autowired
private LymsDictService lymsDictService;

@Autowired
private LymsLogsCrudService lymsLogsCrudService;

@Autowired
private HXService hxService;

@Autowired
private AppgetdoctorlistInfoService appgetdoctorlistInfoService;

/**
* 获取医生列表
* @param doctor
* @param current
* @param size
* @return
*/
@GetMapping("sltDoctorLst")
public BaseResponse sltDoctorLst(LymsDoctor doctor, int current, int size){
BaseResponse baseResponse=new BaseResponse();
Page<LymsDoctor> page=new Page<>(current,size);
Page<LymsDoctor> doctorPagePage=lymsDoctorService.page(page, Wrappers.query(doctor).orderByDesc("updated_time","createdtime"));
conDocCode(doctorPagePage);
baseResponse.setObject(doctorPagePage);

return baseResponse;
}

public void conDocCode(Page<LymsDoctor> doctorPagePage){
Map param=new HashMap();
param.put("vtype",4);
List<LymsDict> dLst=lymsDictService.listByMap(param);
doctorPagePage.getRecords().forEach(d->{
param.clear();
param.put("did",d.getDpid());
List<LymsHdepart> departLst=lymsHdepartService.listByMap(param);
if(departLst.size()>0){
LymsHdepart depart=departLst.get(0);
d.setHname(depart.getHname());
d.setDdname(depart.getDname());
dLst.forEach(dd->{
if(dd.getCode()==d.getLvl()){
d.setLname(dd.getValue());
}
});
}
});
}


/**
* 保存或更新医生信息
* @param doctor
* @return
*/
@PostMapping("saveDoctor")
public BaseResponse saveDoctor(@Validated LymsDoctor doctor, BindingResult result){
BaseResponse baseResponse=new BaseResponse();
baseResponse.setErrormsg("");
//操作记录标识
Integer did=0;
if(doctor.getDid()==null){
doctor.setCreatedtime(new Date());
LymsDoctor depart2=new LymsDoctor();
depart2.setDlogin(doctor.getDlogin());
List<LymsDoctor> dLst=lymsDoctorService.list(Wrappers.query(depart2));
if (dLst.size()>0) {
baseResponse.setErrormsg("不能创建重复账号");
baseResponse.setErrorcode(1);
return baseResponse;
}
LymsHdepart hdepart=lymsHdepartService.getById(doctor.getDpid());
if(doctor.getHxid()==null ){
JSONObject json=hxService.addUser(doctor.getDlogin(),Constant.COMMON_PASSWD,doctor.getDname()+","+hdepart.getDname()+","+hdepart.getHname());
JSONArray rArr=json.getJSONArray("entities");
if(rArr.size()>0){
doctor.setHxid(rArr.getJSONObject(0).getString("uuid"));
}
// lymsDoctorService.saveOrUpdate(doctor);
}
}else{
did=1;
doctor.setUpdatedTime(new Date());
}
if(result.hasErrors()){
baseResponse.setErrorcode(1);
result.getAllErrors().forEach(e->{
baseResponse.setErrormsg(baseResponse.getErrormsg()+e.getDefaultMessage());
});

return baseResponse;
}

boolean f=lymsDoctorService.saveOrUpdate(doctor);
lymsLogsCrud(doctor,did);
baseResponse.setErrorcode(f==true?0:1);
return baseResponse;
}

/**
* 删除医生
* @param did
* @return
*/
@GetMapping("delDoctor")
public BaseResponse delDoctor(int did){
BaseResponse baseResponse=new BaseResponse();
//操作记保存参数
LymsDoctor doctor=lymsDoctorService.getById(did);
boolean f=lymsDoctorService.removeById(did);
if (!StringUtils.isEmpty(doctor.getDlogin())){
JSONObject rs=hxService.delUser(doctor.getDlogin());
log.info(rs);
}
//保存操作记录
lymsLogsCrud(doctor,null);
baseResponse.setErrorcode(f==true?0:1);
return baseResponse;
}

/**
* 医生登录
* @param doctor
* @return
*/
@PostMapping("loginDoctor")
public BaseResponse loginDoctor(@RequestBody LymsDoctor doctor){
BaseResponse baseResponse=new BaseResponse();
List<LymsDoctor> dLst=lymsDoctorService.list(Wrappers.query(doctor));
baseResponse.setErrorcode(1);
if (dLst.size()>0) {
doctor=dLst.get(0);
doctor.setDpasswd(null);
baseResponse.setObject(doctor);
String jwt = JwtUtils.createJWT("1", doctor.getDlogin(), Constant.JWT_TTL);
Map<String,Object> map=new HashMap<>();
map.put("doctor",doctor);
map.put("token",jwt);
baseResponse.setErrorcode(0);
baseResponse.setObject(map);
}
return baseResponse;
}

/**
* 统计医生信息
* @return
*/
@GetMapping("statDoctor")
public BaseResponse statDoctor(Integer hid){
BaseResponse baseResponse=new BaseResponse();
Map<String,Object> stat=lymsDoctorService.statDoctor(hid);
baseResponse.setObject(stat);
return baseResponse;
}

/**
* 操作记录
* @param doctor
* @param did
*/
public void lymsLogsCrud(LymsDoctor doctor,Integer did){
LymsLogsCrud lymsLogsCrud=new LymsLogsCrud();
if(null!=did){
lymsLogsCrud.setCrudtype(did==1?"编辑科室":"新增科室");
}else {
lymsLogsCrud.setCrudtype("删除科室");
}
lymsLogsCrud.setCreatedbyname(doctor.getCreatedbyname());
lymsLogsCrud.setUpdatedbyname(doctor.getUpdatedbyname());
lymsLogsCrud.setHname(doctor.getHname());
lymsLogsCrud.setHdname(doctor.getDname());
lymsLogsCrud.setCreatdata(new Date());
lymsLogsCrud.setCreatdata(new Date());
lymsLogsCrud.setType(2);
lymsLogsCrudService.save(lymsLogsCrud);

}

/**
* 查询单个医生的信息
* @param doctor
* @return
*/
@GetMapping("queryDoctor")
public BaseResponse delDoctor(LymsDoctor doctor){
BaseResponse baseResponse=new BaseResponse();
LymsDoctor doctor2=lymsDoctorService.getOne(Wrappers.query(doctor));
LymsHdepart hdepart=lymsHdepartService.getById(doctor2.getDpid());
doctor2.setDdname(hdepart.getDname());
doctor2.setHname(hdepart.getHname());
Map param=new HashMap();
param.put("vtype",4);
param.put("code",doctor2.getLvl());
List<LymsDict> dLst=lymsDictService.listByMap(param);
if (dLst.size()>0){
doctor2.setLname(dLst.get(0).getValue());
}
baseResponse.setObject(doctor2);
return baseResponse;
}

/**
* 小程序用户端-根据医院id获取医生信息
* @param hid
* @param current
* @param size
* @return
*/
@GetMapping("appGetDoctorList")
public BaseResponse appGetDoctorList(AppgetdoctorlistInfo appgetdoctorlistInfo, int current, int size){
BaseResponse baseResponse=new BaseResponse();
LambdaQueryWrapper<AppgetdoctorlistInfo> queryWrapper = new QueryWrapper().lambda();
queryWrapper.setEntity(appgetdoctorlistInfo);
if(StringUtil.isNotEmpty(appgetdoctorlistInfo.getSearchinfo())){
queryWrapper.like(AppgetdoctorlistInfo::getDname, appgetdoctorlistInfo.getSearchinfo())
.or().like(AppgetdoctorlistInfo::getDpname,appgetdoctorlistInfo.getSearchinfo())
.or().like(AppgetdoctorlistInfo::getLvlname, appgetdoctorlistInfo.getSearchinfo());
}
Page<AppgetdoctorlistInfo> page=new Page<>(current,size);
Page<AppgetdoctorlistInfo> appgetdoctorlistInfoPage=appgetdoctorlistInfoService.page(page,queryWrapper);
baseResponse.setObject(appgetdoctorlistInfoPage);

return baseResponse;
}
}