package com.kidgrow.oprationcenter.service.impl;
|
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.kidgrow.advisory.model.AdvisoryDoctorSummary;
|
import com.kidgrow.advisory.model.AdvisoryManager;
|
import com.kidgrow.advisory.model.AdvisorySummary;
|
import com.kidgrow.advisory.model.feign.AdvisoryService;
|
import com.kidgrow.common.model.PageResult;
|
import com.kidgrow.common.model.ResultBody;
|
import com.kidgrow.common.service.impl.SuperServiceImpl;
|
import com.kidgrow.common.utils.StringUtils;
|
import com.kidgrow.oprationcenter.mapper.AdvisoryDoctorInfoMapper;
|
import com.kidgrow.oprationcenter.model.AdvisoryDoctorInfo;
|
import com.kidgrow.oprationcenter.model.AppointmentTime;
|
import com.kidgrow.oprationcenter.model.HospitalScreening;
|
import com.kidgrow.oprationcenter.service.IAdvisoryDoctorInfoService;
|
import com.kidgrow.oprationcenter.service.IAppointmentTimeService;
|
import com.kidgrow.redis.util.RedisUtils;
|
import com.kidgrow.user.feign.DoctorAnswerUserRelationService;
|
import com.kidgrow.user.feign.UserInfoService;
|
import com.kidgrow.user.model.UserInfo;
|
import com.kidgrow.usercenter.feign.SysDoctorService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.collections4.MapUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
import java.text.DecimalFormat;
|
import java.util.*;
|
|
/**
|
* 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
|
*
|
* @Description: <br>
|
* @Project: <br>
|
* @CreateDate: Created in 2021/3/1 14:34 <br>
|
* @Author: <a href="78125310@kidgrow.com">dougang</a>
|
*/
|
@Slf4j
|
@Service
|
|
public class AdvisoryDoctorInfoServiceImpl extends SuperServiceImpl<AdvisoryDoctorInfoMapper, AdvisoryDoctorInfo> implements IAdvisoryDoctorInfoService {
|
|
@Autowired
|
private SysDoctorService doctorService;
|
|
@Autowired
|
private IAppointmentTimeService appointmentTimeService;
|
|
@Autowired
|
private AdvisoryService advisoryService;
|
|
@Autowired
|
private UserInfoService userInfoService;
|
|
@Autowired
|
private RedisUtils redisUtils;
|
|
@Autowired
|
private DoctorAnswerUserRelationService doctorAnswerUserRelationService;
|
|
/**
|
* 医生列表
|
*
|
* @param params
|
* @return
|
*/
|
@Override
|
public PageResult<AdvisoryDoctorInfo> findList(Map<String, Object> params) {
|
Page<AdvisoryDoctorInfo> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
List<AdvisoryDoctorInfo> list = baseMapper.findList(page, params);
|
return PageResult.<AdvisoryDoctorInfo>builder().data(list).code(0).count(page.getTotal()).build();
|
}
|
|
/**
|
* 通过ID删除
|
*
|
* @param id
|
* @return
|
*/
|
@Override
|
public int removeById(Long id) {
|
ResultBody resultBody = doctorAnswerUserRelationService.deletByDoctorId(String.valueOf(id));
|
log.info("删除医生关系返回值=>" + resultBody);
|
|
appointmentTimeService.delByAdvisoryId(id);
|
baseMapper.removeById(id);
|
return 1;
|
}
|
|
/**
|
* 根据条件查询
|
*
|
* @param params
|
* @return
|
*/
|
@Override
|
public List<AdvisoryDoctorInfo> findByObject(Map<String, Object> params) {
|
return baseMapper.findByObject(params);
|
}
|
|
/**
|
* 更新医生信息
|
*
|
* @param map
|
* @return
|
*/
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public ResultBody updateDoctorInfo(Map<String, Object> map) {
|
//医生ID
|
String id = MapUtils.getString(map, "doctorId");
|
//价格
|
double price = MapUtils.getDouble(map, "price") * 100;
|
//最大人数
|
int maxPeople = MapUtils.getIntValue(map, "maxPeople");
|
//预约时间
|
List<AppointmentTime> appointmments = JSONArray.parseArray(JSONArray.toJSONString(map.get("appointments")), AppointmentTime.class);
|
|
AdvisoryDoctorInfo advisoryDoctorInfo = baseMapper.selectById(Long.parseLong(id));
|
if (advisoryDoctorInfo == null) {
|
return ResultBody.failed().msg("查询医生信息失败");
|
}
|
|
advisoryDoctorInfo.setPrice(price);
|
advisoryDoctorInfo.setMaxPeople(maxPeople);
|
|
int b = baseMapper.updateById(advisoryDoctorInfo);
|
if (b == 0) {
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
return ResultBody.failed().msg("操作失败");
|
}
|
|
if (appointmments != null && appointmments.size() > 0) {
|
appointmentTimeService.delByAdvisoryId(Long.parseLong(id));
|
for (AppointmentTime time : appointmments) {
|
time.setAdvisoryId(Long.parseLong(id));
|
appointmentTimeService.saveOrUpdate(time);
|
}
|
}
|
|
return ResultBody.ok().msg("操作成功");
|
}
|
|
/**
|
* 查询咨询医生详情
|
*
|
* @param map
|
* @return
|
*/
|
@Override
|
public ResultBody getDoctorById(Map<String, Object> map) {
|
//医生ID
|
String id = MapUtils.getString(map, "doctorId");
|
//是否需要查询预约时间
|
int apppointmentFlag = MapUtils.getIntValue(map, "apppointmentFlag");
|
|
AdvisoryDoctorInfo byId = baseMapper.selectById(Long.parseLong(id));
|
if (byId == null) {
|
return ResultBody.failed().msg("未找到医生信息");
|
}
|
|
ResultBody byId1 = doctorService.findById(byId.getDoctorId());
|
if (byId1.getCode() != 0 || byId1.getData() == null) {
|
return ResultBody.failed().msg("查询医生信息失败");
|
}
|
|
JSONObject doctor = JSONObject.parseObject(JSONObject.toJSONString(byId1.getData()));
|
|
JSONObject json = new JSONObject();
|
json.put("doctorName", doctor.getString("doctorName"));
|
json.put("departmentName", doctor.getString("departmentName"));
|
json.put("hospitalName", doctor.getString("hospitalName"));
|
json.put("head", doctor.getString("doctorLogo"));
|
json.put("phone", doctor.getString("doctorTel"));
|
json.put("otherLink", doctor.getString("doctorOtherLink"));
|
json.put("about", doctor.getString("doctorAbout"));
|
json.put("price", byId.getPrice() / 100);
|
json.put("specialty", byId.getSpecialty());
|
json.put("service", byId.getService());
|
json.put("maxPeople", byId.getMaxPeople());
|
json.put("rank", doctor.getString("doctorRank"));
|
|
if (apppointmentFlag == 1) {
|
List<AppointmentTime> byAdvisoryId = appointmentTimeService.findByAdvisoryId(Long.parseLong(id));
|
if (byAdvisoryId.size() > 0) {
|
JSONArray array = new JSONArray();
|
JSONObject obj = null;
|
for (AppointmentTime app : byAdvisoryId) {
|
boolean flag = true;
|
for (int i = 0; i < array.size(); i++) {
|
JSONObject jsonObject = array.getJSONObject(i);
|
if (jsonObject.getString("name").equals(app.getName())) {
|
if (app.getAfternoon() == 1) {
|
jsonObject.put("afternoon", 1);
|
} else if (app.getEvening() == 1) {
|
jsonObject.put("evening", 1);
|
} else if (app.getMorning() == 1) {
|
jsonObject.put("morning", 1);
|
}
|
flag = false;
|
array.add(jsonObject);
|
break;
|
}
|
}
|
|
if (flag) {
|
obj = new JSONObject();
|
obj.put("name", app.getName());
|
obj.put("afternoon", app.getAfternoon());
|
obj.put("evening", app.getEvening());
|
obj.put("morning", app.getMorning());
|
array.add(obj);
|
}
|
}
|
json.put("appointments", array);
|
}
|
}
|
|
return ResultBody.ok().data(json);
|
}
|
|
/**
|
* 获取筛查咨询医生列表
|
*
|
* @param hospitalId
|
* @return
|
*/
|
@Override
|
public ResultBody getSreeningAdvisoryDoctorList(Long hospitalId) {
|
Map<String, Object> map = new HashMap<>(16);
|
map.put("hospitalId", hospitalId);
|
|
JSONArray array = new JSONArray();
|
JSONObject json = null;
|
List<AdvisoryDoctorInfo> byObject = baseMapper.findByObject(map);
|
if (byObject.size() > 0) {
|
for (AdvisoryDoctorInfo doc : byObject) {
|
json = new JSONObject();
|
json.put("doctorName", doc.getDoctorName());
|
json.put("departmentName", doc.getDeptName());
|
json.put("hospitalName", doc.getHospitalName());
|
json.put("head", doc.getHead());
|
json.put("about", doc.getIntroduction());
|
json.put("price", doc.getPrice() / 100);
|
json.put("specialty", doc.getSpecialty());
|
json.put("service", doc.getService());
|
json.put("id", String.valueOf(doc.getId()));
|
|
ResultBody byId1 = doctorService.findById(doc.getDoctorId());
|
if (byId1.getCode() == 0 || byId1.getData() != null) {
|
JSONObject doctor = JSONObject.parseObject(JSONObject.toJSONString(byId1.getData()));
|
json.put("rank", doctor.getString("doctorRank"));
|
}
|
|
array.add(json);
|
}
|
}
|
return ResultBody.ok().data(array).msg("操作成功");
|
}
|
|
/**
|
* 获取咨询医生列表
|
*
|
* @param map
|
* @return
|
*/
|
@Override
|
public ResultBody getAdvisoryDoctorList(Map<String, Object> map) {
|
double lat = MapUtils.getDouble(map, "lat");
|
double lon = MapUtils.getDouble(map, "lon");
|
String excludeHospitalId = MapUtils.getString(map, "excludeHospitalId");
|
|
List<Map<String, Object>> array = new ArrayList<>();
|
Map<String, Object> json = null;
|
|
//根据筛查医院ID换取医院ID
|
if (StringUtils.isNotBlank(excludeHospitalId)) {
|
HospitalScreening hget = (HospitalScreening) redisUtils.hget("CUSOTMER_HOSPITAL", excludeHospitalId);
|
if (hget != null) {
|
map.put("excludeHospitalId", hget.getHospitalId());
|
}
|
}
|
|
List<AdvisoryDoctorInfo> byObject = baseMapper.findByObject(map);
|
if (byObject.size() > 0) {
|
for (AdvisoryDoctorInfo adi : byObject) {
|
json = new HashMap<>(16);
|
json.put("doctorName", adi.getDoctorName());
|
json.put("departmentName", adi.getDeptName());
|
json.put("hospitalName", adi.getHospitalName());
|
json.put("head", adi.getHead());
|
json.put("about", adi.getIntroduction());
|
json.put("price", adi.getPrice() / 100);
|
json.put("specialty", adi.getSpecialty());
|
json.put("service", adi.getService());
|
json.put("id", String.valueOf(adi.getId()));
|
double lat1 = StringUtils.isNotBlank(adi.getLatitude()) ? Double.parseDouble(adi.getLatitude()) : 0d;
|
double lon1 = StringUtils.isNotBlank(adi.getLongitude()) ? Double.parseDouble(adi.getLongitude()) : 0d;
|
String distance = getDistance(lat1, lon1, lat, lon);
|
json.put("distance", distance);
|
|
ResultBody byId1 = doctorService.findById(adi.getDoctorId());
|
if (byId1.getCode() == 0 || byId1.getData() != null) {
|
JSONObject doctor = JSONObject.parseObject(JSONObject.toJSONString(byId1.getData()));
|
json.put("rank", doctor.getString("doctorRank"));
|
}
|
|
array.add(json);
|
}
|
|
//按照距离排序(由远到近)
|
Collections.sort(array, new Comparator<Map<String, Object>>() {
|
@Override
|
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
|
String distance1 = o1.get("distance").toString();
|
String distance2 = o2.get("distance").toString();
|
return distance2.compareTo(distance1);
|
}
|
});
|
|
//倒叙list排序
|
Collections.reverse(byObject);
|
}
|
|
return ResultBody.ok().data(array).msg("操作成功");
|
}
|
|
@Override
|
public PageResult<AdvisoryManager> findAll(Map<String, Object> params) {
|
return advisoryService.findAll(params);
|
}
|
|
/**
|
* 后台更新咨询状态
|
*
|
* @param id
|
* @return
|
*/
|
@Override
|
public ResultBody updateStatusByService(String id) {
|
return advisoryService.updateStatusByService(id);
|
}
|
|
/**
|
* 查询注册用户信息
|
*
|
* @param phone
|
* @return
|
*/
|
@Override
|
public UserInfo getUserByPhone(String phone) {
|
UserInfo user = new UserInfo();
|
user.setPhoneNum(phone);
|
ResultBody byObject = userInfoService.findByObject(user);
|
|
if (byObject.getCode() == 0 || byObject.getData() != null) {
|
UserInfo userInfo = JSONObject.parseObject(JSONObject.toJSONString(byObject.getData()), UserInfo.class);
|
if (userInfo != null) {
|
return userInfo;
|
}
|
}
|
return null;
|
}
|
|
/**
|
* 微信退款
|
*
|
* @param map
|
* @return
|
*/
|
@Override
|
public ResultBody refund(Map<String, Object> map) {
|
return advisoryService.refund(map);
|
}
|
|
/**
|
* 按照月/年查询咨询统计数据
|
*
|
* @param map type:1月,2年
|
* riqi: 时间
|
* @return
|
*/
|
@Override
|
public PageResult<AdvisorySummary> summaryBate(Map<String, Object> map) {
|
PageResult<AdvisorySummary> resultBody = null;
|
int type = MapUtils.getIntValue(map, "type");
|
if (type == 1) {
|
resultBody = advisoryService.summaryByMonth(map);
|
}
|
if (type == 2) {
|
resultBody = advisoryService.summaryByYear(map);
|
}
|
return resultBody;
|
}
|
|
/**
|
* 咨询医生统计数据查询
|
*
|
* @param map startTime/EndTime
|
* @return
|
*/
|
@Override
|
public PageResult<AdvisoryDoctorSummary> summaryDoctorByBate(Map<String, Object> map) {
|
return advisoryService.summaryByDoctor(map);
|
}
|
|
/**
|
* @param lat1 经度1
|
* @param lng1 纬度1
|
* @param lat2 经度2
|
* @param lng2 纬度2
|
* @return 距离
|
*/
|
private String getDistance(double lat1, double lng1, double lat2, double lng2) {
|
|
double radLat1 = rad(lat1);
|
double radLat2 = rad(lat2);
|
|
double a = radLat1 - radLat2;
|
double b = rad(lng1) - rad(lng2);
|
|
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
|
+ Math.cos(radLat1) * Math.cos(radLat2)
|
* Math.pow(Math.sin(b / 2), 2)));
|
s = s * 6378.137;
|
s = Math.round(s * 10000d) / 10000d;
|
//s = s * 1000;如果需要返回单位为米
|
|
DecimalFormat df = new DecimalFormat("0.00");//格式化,区小数后两位
|
String distance = df.format(s);
|
|
return distance;
|
}
|
|
private double rad(double d) {
|
return d * Math.PI / 180.0;
|
}
|
|
}
|