Przeglądaj źródła

德顺评价器

lighter 1 rok temu
rodzic
commit
3be836a2e5

+ 126 - 0
src/main/java/thyyxxk/webserver/controller/api/bjdeshun/EvaluatorController.java

@@ -0,0 +1,126 @@
+package thyyxxk.webserver.controller.api.bjdeshun;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
+import thyyxxk.webserver.config.auth.PassToken;
+import thyyxxk.webserver.config.exception.BizException;
+import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.dao.his.api.bjdeshun.EvaluatorDao;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.api.bjdeshun.EvaluateRecord;
+import thyyxxk.webserver.service.redislike.RedisLikeService;
+import thyyxxk.webserver.utils.IpAddressUtil;
+import thyyxxk.webserver.utils.ResultVoUtil;
+import thyyxxk.webserver.utils.StringUtil;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+@RestController
+@RequestMapping("/api/bjdeshun/evaluator")
+public class EvaluatorController {
+    private final EvaluatorDao dao;
+    private final RedisLikeService redis;
+    private static final String CLIENT = "http://{IP}:10791/inf/{ACTION}";
+
+    @Autowired
+    public EvaluatorController(EvaluatorDao dao, RedisLikeService redis) {
+        this.dao = dao;
+        this.redis = redis;
+    }
+
+    @PassToken
+    @PostMapping("/start")
+    public ResultVo<String> start(HttpServletRequest request, @RequestBody EvaluateRecord body) throws Exception {
+        QueryWrapper<EvaluateRecord> wrapper = new QueryWrapper<>();
+        wrapper.eq("pat_no", body.getPatNo());
+        wrapper.eq("times", body.getTimes());
+        wrapper.eq("type", body.getType());
+        int count = dao.selectCount(wrapper);
+        if (count > 0) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR,
+                    "该笔交易已完成评价,请勿重复发起。");
+        }
+        if (StringUtil.isBlank(body.getClientIp())) {
+            body.setClientIp(IpAddressUtil.getIPAddress(request));
+        }
+        if (notSignedIn(body.getClientIp())) {
+            signIn(body);
+        }
+        return executeCall(body);
+    }
+
+    private boolean notSignedIn(String ip) {
+        String url = CLIENT.replace("{IP}", ip)
+                .replace("{ACTION}", "LS");
+        String result = new RestTemplate().postForObject(url, null, String.class);
+        log.info("查询登录状态:{}", result);
+        if (null == result) {
+            return true;
+        }
+        JSONObject resultJson = JSONObject.parseObject(result.trim());
+        JSONObject info = resultJson.getJSONObject("info");
+        return StringUtil.isBlank(info.getString("name"));
+    }
+
+    private void signIn(EvaluateRecord body) throws Exception {
+        JSONObject params = new JSONObject();
+        params.put("num", redis.getCodeRs(body.getStaffId()));
+        params.put("name", body.getStaffName());
+        params.put("photo", "https://staticweb.hnthyy.cn/images/employee-portrait/test.jpg");
+        String url = CLIENT.replace("{IP}", body.getClientIp())
+                .replace("{ACTION}", "SS");
+        String result = new RestTemplate().postForObject(url, params, String.class);
+        log.info("执行登录:{}", result);
+        if (null == result) {
+            throw new BizException(ExceptionEnum.NETWORK_ERROR);
+        }
+        boolean unSignedIn;
+        do {
+            TimeUnit.SECONDS.sleep(2);
+            unSignedIn = notSignedIn(body.getClientIp());
+        } while (unSignedIn);
+    }
+
+    private String queryProgress(String ip) {
+        String url = CLIENT.replace("{IP}", ip)
+                .replace("{ACTION}", "PR");
+        String result = new RestTemplate().postForObject(url, null, String.class);
+        log.info("查询耗时操作进度:{}", result);
+        if (null == result) {
+            throw new BizException(ExceptionEnum.NETWORK_ERROR);
+        }
+        JSONObject resultJson = JSONObject.parseObject(result.trim());
+        String progress = resultJson.getString("progress");
+        if (StringUtil.isBlank(progress)) {
+            throw new BizException(ExceptionEnum.NETWORK_ERROR);
+        }
+        return progress;
+    }
+
+    private ResultVo<String> executeCall(EvaluateRecord body) {
+        String url = CLIENT.replace("{IP}", body.getClientIp())
+                .replace("{ACTION}", "ES");
+        String result = new RestTemplate().postForObject(url, null, String.class);
+        log.info("评价结果:{}", result);
+        if (null == result) {
+            return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
+        }
+        JSONObject resultJson = JSONObject.parseObject(result.trim());
+        Integer data = resultJson.getInteger("data");
+        if (null == data) {
+            return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
+        }
+        // 评价器只有4个按键,
+        // 原始值是 1-很满意,2-满意,3-基本满意,4-不满意。
+        // 通过 6-x 转换为 2-不满意,3-基本满意,4-满意,5-很满意
+        body.setRateValue(6 - data);
+        dao.insert(body);
+        return ResultVoUtil.success();
+    }
+}

+ 9 - 0
src/main/java/thyyxxk/webserver/dao/his/api/bjdeshun/EvaluatorDao.java

@@ -0,0 +1,9 @@
+package thyyxxk.webserver.dao.his.api.bjdeshun;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import thyyxxk.webserver.entity.api.bjdeshun.EvaluateRecord;
+
+@Mapper
+public interface EvaluatorDao extends BaseMapper<EvaluateRecord> {
+}

+ 23 - 0
src/main/java/thyyxxk/webserver/entity/api/bjdeshun/EvaluateRecord.java

@@ -0,0 +1,23 @@
+package thyyxxk.webserver.entity.api.bjdeshun;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+@TableName(value = "t_evaluate_record")
+public class EvaluateRecord {
+    @TableId(type = IdType.AUTO)
+    private Integer id;
+    private String patNo;
+    private Integer times;
+    private EvaluateType type;
+    private Integer rateValue;
+    private Date rateTime;
+    private String clientIp;
+    private String staffId;
+    private String staffName;
+}

+ 6 - 0
src/main/java/thyyxxk/webserver/entity/api/bjdeshun/EvaluateType.java

@@ -0,0 +1,6 @@
+package thyyxxk.webserver.entity.api.bjdeshun;
+
+public enum EvaluateType {
+    WINDOW_CHARGE,
+    DOCTOR_TREAT,
+}