|
|
@@ -0,0 +1,213 @@
|
|
|
+package cn.hnthyy.thmz.service.impl.thmz;
|
|
|
+
|
|
|
+import cn.hnthyy.thmz.Utils.HttpUtil;
|
|
|
+import cn.hnthyy.thmz.Utils.TokenUtil;
|
|
|
+import cn.hnthyy.thmz.entity.MzException;
|
|
|
+import cn.hnthyy.thmz.entity.his.mz.MzPatientMi;
|
|
|
+import cn.hnthyy.thmz.entity.thmz.*;
|
|
|
+import cn.hnthyy.thmz.enums.GenderEnum;
|
|
|
+import cn.hnthyy.thmz.mapper.thmz.EvaluateMapper;
|
|
|
+import cn.hnthyy.thmz.service.his.mz.MzPatientMiService;
|
|
|
+import cn.hnthyy.thmz.service.his.mz.MzPharmacyService;
|
|
|
+import cn.hnthyy.thmz.service.thmz.EvaluationService;
|
|
|
+import cn.hnthyy.thmz.service.thmz.RoleService;
|
|
|
+import cn.hnthyy.thmz.service.thmz.UserRoleRelationService;
|
|
|
+import cn.hnthyy.thmz.service.thmz.WindowsService;
|
|
|
+import cn.hnthyy.thmz.socket.EvaluationWebSocket;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.json.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class EvaluationServiceImpl implements EvaluationService {
|
|
|
+ @Autowired
|
|
|
+ private EvaluationWebSocket evaluationWebSocket;
|
|
|
+ @Autowired
|
|
|
+ private WindowsService windowsService;
|
|
|
+ @Autowired
|
|
|
+ private UserRoleRelationService userRoleRelationService;
|
|
|
+ @Autowired
|
|
|
+ private RoleService roleService;
|
|
|
+ @Autowired
|
|
|
+ private MzPatientMiService mzPatientMiService;
|
|
|
+ @Autowired
|
|
|
+ private MzPharmacyService mzPharmacyService;
|
|
|
+ @SuppressWarnings("all")
|
|
|
+ @Autowired
|
|
|
+ private EvaluateMapper evaluateMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 客户端与患者的对应关系
|
|
|
+ */
|
|
|
+ private static ConcurrentHashMap<String, Map<String,Object>> clientAndPatientMap = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void login(HttpServletRequest httpServletRequest) {
|
|
|
+ String requestIp = HttpUtil.getIPAddress(httpServletRequest);
|
|
|
+ if (StringUtils.isBlank(requestIp)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Windows windows = windowsService.queryLastWindowsIpAddress(requestIp);
|
|
|
+ if (windows == null || StringUtils.isBlank(windows.getClientIpAddress())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ evaluationWebSocket.login(windows.getClientIpAddress());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void loginOut(String clientIpAddress) {
|
|
|
+ Map<String, Object> resultMap = new HashMap();
|
|
|
+ resultMap.put("type", "url");
|
|
|
+ resultMap.put("url", "/thmz/client-welcome");
|
|
|
+ evaluationWebSocket.appointSending(clientIpAddress, JSONObject.valueToString(resultMap));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getUserInfo(HttpServletRequest httpServletRequest) {
|
|
|
+ User tokenUser = null;
|
|
|
+ try {
|
|
|
+ tokenUser = TokenUtil.getUser(httpServletRequest);
|
|
|
+ List<UserRoleRelation> userRoleRelations = userRoleRelationService.queryByUserId(tokenUser.getId());
|
|
|
+ Role role = roleService.queryById(userRoleRelations.get(0).getRoleId());
|
|
|
+ Map<String, Object> resultMap = new HashMap();
|
|
|
+ resultMap.put("name", tokenUser.getUserName());
|
|
|
+ resultMap.put("role", role.getRoleName());
|
|
|
+ resultMap.put("userCode", tokenUser.getUserCode());
|
|
|
+ resultMap.put("clientProfileImage", tokenUser.getClientProfileImage());
|
|
|
+ resultMap.put("url", "client-index");
|
|
|
+ return resultMap;
|
|
|
+ } catch (MzException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sendPriceInfo(Map<String, Object> params, HttpServletRequest httpServletRequest) throws MzException {
|
|
|
+ if (params == null) {
|
|
|
+ throw new MzException("推送价格消息到评价器失败,参数为空!");
|
|
|
+ }
|
|
|
+ String patientId = (String) params.get("patientId");
|
|
|
+ if (StringUtils.isBlank(patientId)) {
|
|
|
+ throw new MzException("推送价格消息到评价器失败,患者ID参数为空!");
|
|
|
+ }
|
|
|
+ MzPatientMi mzPatientMi = mzPatientMiService.queryByPatientId(patientId);
|
|
|
+ if (mzPatientMi == null) {
|
|
|
+ throw new MzException("推送价格消息到评价器失败,患者信息不存在!");
|
|
|
+ }
|
|
|
+ String name = mzPatientMi.getName();
|
|
|
+ String call = "先生";
|
|
|
+ if(GenderEnum.WOMAN.code.equals(mzPatientMi.getSex())){
|
|
|
+ call = "女士";
|
|
|
+ }
|
|
|
+ if (mzPatientMi.getAge() != null && mzPatientMi.getAge() <= 16) {
|
|
|
+ call = "小朋友";
|
|
|
+ }
|
|
|
+ String requestIp = HttpUtil.getIPAddress(httpServletRequest);
|
|
|
+ if (StringUtils.isBlank(requestIp)) {
|
|
|
+ throw new MzException("推送价格消息到评价器失败,请求客户端IP为空!");
|
|
|
+ }
|
|
|
+ Windows windows = windowsService.queryLastWindowsIpAddress(requestIp);
|
|
|
+ if (windows == null || StringUtils.isBlank(windows.getClientIpAddress())) {
|
|
|
+ throw new MzException("推送价格消息到评价器失败,请求客户端对应的评价器IP为空!");
|
|
|
+ }
|
|
|
+ BigDecimal needPay = new BigDecimal((String) params.get("needPay")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal pay = new BigDecimal((Integer) params.get("pay")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal changeAmount=null;
|
|
|
+ try{
|
|
|
+ changeAmount = new BigDecimal((Integer) params.get("changeAmount")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }catch (ClassCastException e){
|
|
|
+ changeAmount = new BigDecimal((String) params.get("changeAmount")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ params.put("name", name);
|
|
|
+ params.put("call", call);
|
|
|
+ params.put("needPay", needPay.toString());
|
|
|
+ params.put("pay", pay.toString());
|
|
|
+ params.put("changeAmount", changeAmount.toString());
|
|
|
+ String message = name + call + ",您好!您本次就诊,应付金额为" + needPay + "元,实际支付金额为" + pay + "元,应找零金额为" + changeAmount + "元。";
|
|
|
+ String res = mzPharmacyService.callNumberAudio(message);
|
|
|
+ JSONObject resObj = new JSONObject(res);
|
|
|
+ Integer code = (Integer) resObj.get("code");
|
|
|
+ if (code == 200) {
|
|
|
+ params.put("messageAudio", resObj.get("data").toString());
|
|
|
+ }
|
|
|
+ evaluationWebSocket.setPriceInfo(windows.getClientIpAddress(), params);
|
|
|
+ Map<String, Object> resultMap = new HashMap();
|
|
|
+ resultMap.put("type", "url");
|
|
|
+ resultMap.put("url", "/thmz/client-price");
|
|
|
+ evaluationWebSocket.appointSending(windows.getClientIpAddress(), JSONObject.valueToString(resultMap));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void toEvaluation(String patientId,User tokenUser,HttpServletRequest httpServletRequest) {
|
|
|
+ String requestIp = HttpUtil.getIPAddress(httpServletRequest);
|
|
|
+ if (StringUtils.isBlank(requestIp)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Windows windows = windowsService.queryLastWindowsIpAddress(requestIp);
|
|
|
+ if (windows == null || StringUtils.isBlank(windows.getClientIpAddress())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String,Object> clientMap = new HashMap<>();
|
|
|
+ clientMap.put("patientId",patientId);
|
|
|
+ clientMap.put("tokenUser",tokenUser);
|
|
|
+ clientAndPatientMap.put(windows.getClientIpAddress(),clientMap);
|
|
|
+ Map<String, Object> resultMap = new HashMap();
|
|
|
+ resultMap.put("type", "url");
|
|
|
+ resultMap.put("url", "/thmz/client-evaluate");
|
|
|
+ evaluationWebSocket.appointSending(windows.getClientIpAddress(), JSONObject.valueToString(resultMap));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String saveEvaluate(Integer evaluateCode,String requestIp) throws MzException {
|
|
|
+ Map<String,Object> clientMap =clientAndPatientMap.get(requestIp);
|
|
|
+ if(clientMap==null){
|
|
|
+ throw new MzException("当前评价器没有患者信息");
|
|
|
+ }
|
|
|
+ String patientId=(String)clientMap.get("patientId");
|
|
|
+ if(StringUtils.isBlank(patientId)){
|
|
|
+ throw new MzException("当前评价器没有患者信息");
|
|
|
+ }
|
|
|
+ User tokenUser=(User)clientMap.get("tokenUser");
|
|
|
+ if(tokenUser==null || StringUtils.isBlank(tokenUser.getUserIdCode()) || StringUtils.isBlank(tokenUser.getUserName())){
|
|
|
+ throw new MzException("当前评价器没有被评价人信息");
|
|
|
+ }
|
|
|
+ MzPatientMi mzPatientMi=mzPatientMiService.queryByPatientId(patientId);
|
|
|
+ if(mzPatientMi==null || StringUtils.isBlank(mzPatientMi.getName())){
|
|
|
+ throw new MzException("患者信息不正确");
|
|
|
+ }
|
|
|
+ Evaluate evaluate= new Evaluate();
|
|
|
+ evaluate.setEvaluate(evaluateCode);
|
|
|
+ evaluate.setPatientId(patientId);
|
|
|
+ evaluate.setPatientName(mzPatientMi.getName());
|
|
|
+ evaluate.setUserIdCode(tokenUser.getUserIdCode());
|
|
|
+ evaluate.setUserName(tokenUser.getUserName());
|
|
|
+ evaluate.setEvaluateTime(new Date());
|
|
|
+ evaluateMapper.insertEvaluate(evaluate);
|
|
|
+ String res = mzPharmacyService.callNumberAudio("感谢您对我的评价,再见!");
|
|
|
+ JSONObject resObj = new JSONObject(res);
|
|
|
+ Integer code = (Integer) resObj.get("code");
|
|
|
+ if (code == 200) {
|
|
|
+ return resObj.get("data").toString();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer queryCountEvaluate(Evaluate evaluate) {
|
|
|
+ return evaluateMapper.selectCountEvaluate(evaluate);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Evaluate> queryEvaluateWithPage(Evaluate evaluate) {
|
|
|
+ return evaluateMapper.selectEvaluateWithPage(evaluate);
|
|
|
+ }
|
|
|
+}
|