Browse Source

危机值开发完成

hurugang 5 years ago
parent
commit
b4912be318

+ 3 - 1
src/main/java/cn/hnthyy/thmz/ThmzApplication.java

@@ -16,7 +16,9 @@ public class ThmzApplication extends SpringBootServletInitializer {
     public static void main(String[] args) {
         log.info("服务启动成功");
         SpringApplication.run(ThmzApplication.class, args);
-        String address = "http://127.0.0.1:7611/hubo/WebService";
+
+        //发布webservice服务
+        String address = "http://127.0.0.1:7611/webService/criticalWebService";
         //发布WebService,WebServiceImpl类是WebServie接口的具体实现类
         Endpoint.publish(address, new CriticalWebServiceImpl());
         System.out.println("使用WebServicePublishListener发布webservice成功!");

+ 40 - 0
src/main/java/cn/hnthyy/thmz/Utils/SpringBeanUtils.java

@@ -0,0 +1,40 @@
+package cn.hnthyy.thmz.Utils;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Service;
+
+
+@Service
+public class SpringBeanUtils implements ApplicationContextAware {
+    private static ApplicationContext context;
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        this.context=applicationContext;
+    }
+    public static <T> T getBean(Class<T> requiredType){
+
+        if(context==null){
+            throw new IllegalStateException("spring 环境没有启动!");
+        }
+       return context.getBean(requiredType);
+    }
+    public static <T> T getBean(String beanName,Class<T> requiredType){
+
+        if(context==null){
+            throw new IllegalStateException("spring 环境没有启动!");
+        }
+        return context.getBean(beanName,requiredType);
+
+    }
+
+    public static ApplicationContext getContext(){
+
+
+        if(context==null){
+            throw new IllegalStateException("spring 环境没有启动!");
+        }
+        return context;
+    }
+}

+ 5 - 5
src/main/java/cn/hnthyy/thmz/mapper/his/EmployeeMapper.java

@@ -13,7 +13,7 @@ public interface EmployeeMapper {
      * @param codeRs
      * @return
      */
-    @Select(" select top 1 rtrim(code) employeeCode,rtrim(name) employeeName,del_flag,rtrim(mark) mark,emp_tit_code from a_employee_mi  where  code_rs =#{codeRs}")
+    @Select(" select top 1 rtrim(code) employeeCode,rtrim(name) employeeName,del_flag,rtrim(mark) mark,emp_tit_code,rtrim(code_rs)  code_rs from a_employee_mi  where  code_rs =#{codeRs}")
     Employee selectByCodeRs(@Param("codeRs") String codeRs);
 
 
@@ -24,7 +24,7 @@ public interface EmployeeMapper {
      * @return
      */
     @Select({"<script>",
-            "select rtrim(code) employee_code,rtrim(name) employee_name,del_flag,rtrim(mark) mark,rtrim(dept_code) dept_code,emp_tit_code from a_employee_mi where (del_flag is null or del_flag =0 ) ",
+            "select rtrim(code) employee_code,rtrim(name) employee_name,del_flag,rtrim(mark) mark,rtrim(dept_code) dept_code,emp_tit_code,rtrim(code_rs)  code_rs from a_employee_mi where (del_flag is null or del_flag =0 ) ",
             "<when test='depts!=null'>",
             " and  dept_code in",
             "<foreach item='item' index='index' collection='depts' open='(' separator=',' close=')'>",
@@ -42,7 +42,7 @@ public interface EmployeeMapper {
      * @return
      */
     @Select({"<script>",
-            "select rtrim(code) employee_code,rtrim(name) employee_name,del_flag,rtrim(mark) mark,emp_tit_code from a_employee_mi where (del_flag is null or del_flag =0 )",
+            "select rtrim(code) employee_code,rtrim(name) employee_name,del_flag,rtrim(mark) mark,emp_tit_code,rtrim(code_rs)  code_rs from a_employee_mi where (del_flag is null or del_flag =0 )",
             "<when test='dept!=null'>",
             " and dept_code =#{dept}",
             "</when>",
@@ -56,7 +56,7 @@ public interface EmployeeMapper {
      * @param name
      * @return
      */
-    @Select(" select top 1 rtrim(code) employeeCode,rtrim(name) employeeName,del_flag,rtrim(mark) mark,emp_tit_code from a_employee_mi  where name =#{name} and (del_flag is null or del_flag =0 )")
+    @Select(" select top 1 rtrim(code) employeeCode,rtrim(name) employeeName,del_flag,rtrim(mark) mark,emp_tit_code,rtrim(code_rs)  code_rs from a_employee_mi  where name =#{name} and (del_flag is null or del_flag =0 )")
     Employee selectByUserName(@Param("name") String name);
 
 
@@ -66,7 +66,7 @@ public interface EmployeeMapper {
      * @param code
      * @return
      */
-    @Select(" select top 1 rtrim(code) employeeCode,rtrim(name) employeeName,del_flag,rtrim(mark) mark,emp_tit_code from a_employee_mi  where  code =#{code} and (del_flag is null or del_flag =0 )")
+    @Select(" select top 1 rtrim(code) employeeCode,rtrim(name) employeeName,del_flag,rtrim(mark) mark,emp_tit_code,rtrim(code_rs)  code_rs from a_employee_mi  where  code =#{code} and (del_flag is null or del_flag =0 )")
     Employee selectByUserCode(@Param("code") String code);
 
 

+ 66 - 17
src/main/java/cn/hnthyy/thmz/webservice/service/impl/CriticalWebServiceImpl.java

@@ -1,46 +1,95 @@
 package cn.hnthyy.thmz.webservice.service.impl;
 
 
+import cn.hnthyy.thmz.Utils.SpringBeanUtils;
+import cn.hnthyy.thmz.entity.his.Employee;
+import cn.hnthyy.thmz.service.his.EmployeeService;
+import cn.hnthyy.thmz.service.impl.his.EmployeeServiceImpl;
+import cn.hnthyy.thmz.service.impl.thmz.MessageServiceImpl;
+import cn.hnthyy.thmz.service.thmz.MessageService;
 import cn.hnthyy.thmz.webservice.service.CriticalWebService;
-import com.fasterxml.jackson.databind.JsonNode;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.json.JSONObject;
 
 import javax.jws.WebService;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @Slf4j
 @WebService
 public class CriticalWebServiceImpl implements CriticalWebService {
-    private String token ="oI9#ur02cbBHdop87e6Y728Ax30IIlgd";
+    private String token = "oI9#ur02cbBHdop87e6Y728Ax30IIlgd";
+    MessageService messageService =(MessageServiceImpl)SpringBeanUtils.getBean(MessageServiceImpl.class);
+    EmployeeService employeeService=(EmployeeServiceImpl)SpringBeanUtils.getBean(EmployeeServiceImpl.class);
     @Override
     public String criticalAccept(String accessToken, String msg) {
-        Map<String,String> resultMap=new HashMap<>();
-        if(StringUtils.isBlank(accessToken)){
-            resultMap.put("Code","false");
-            resultMap.put("Message","token不能为空");
+        Map<String, String> resultMap = new HashMap<>();
+        if (StringUtils.isBlank(accessToken)) {
+            resultMap.put("Code", "false");
+            resultMap.put("Message", "token不能为空");
             log.error("token不能为空");
-            JSONObject jsonObj=new JSONObject(resultMap);
+            JSONObject jsonObj = new JSONObject(resultMap);
             return jsonObj.toString();
         }
-        if(StringUtils.isBlank(msg)){
-            resultMap.put("Code","false");
-            resultMap.put("Message","msg为空");
+        if (StringUtils.isBlank(msg)) {
+            resultMap.put("Code", "false");
+            resultMap.put("Message", "msg为空");
             log.error("msg为空");
-            JSONObject jsonObj=new JSONObject(resultMap);
+            JSONObject jsonObj = new JSONObject(resultMap);
             return jsonObj.toString();
         }
-        if(!token.equals(accessToken)){
-            resultMap.put("Code","false");
-            resultMap.put("Message","token校验失败");
+        if (!token.equals(accessToken)) {
+            resultMap.put("Code", "false");
+            resultMap.put("Message", "token校验失败");
             log.error("token校验失败");
-            JSONObject jsonObj=new JSONObject(resultMap);
+            JSONObject jsonObj = new JSONObject(resultMap);
             return jsonObj.toString();
         }
         JSONObject myJsonObject = new JSONObject(msg);
-
-        return null;
+        if (myJsonObject == null) {
+            resultMap.put("Code", "false");
+            resultMap.put("Message", "消息读取失败");
+            log.error("消息读取失败");
+            JSONObject jsonObj = new JSONObject(resultMap);
+            return jsonObj.toString();
+        }
+        String targetDeptCode = myJsonObject.getString("TargetDeptCode");
+        if(StringUtils.isBlank(targetDeptCode)){
+            resultMap.put("Code", "false");
+            resultMap.put("Message", "目标科室为空");
+            log.error("目标科室为空");
+            JSONObject jsonObj = new JSONObject(resultMap);
+            return jsonObj.toString();
+        }
+        String content = myJsonObject.getString("Content");
+        if(StringUtils.isBlank(content)){
+            resultMap.put("Code", "false");
+            resultMap.put("Message", "消息内容为空");
+            log.error("消息内容为空");
+            JSONObject jsonObj = new JSONObject(resultMap);
+            return jsonObj.toString();
+        }
+        List<Employee> employees=employeeService.queryEmployeeByDept(targetDeptCode.trim());
+        if(employees!=null){
+            String codes=null;
+            for (Employee employee:employees){
+                if(codes==null){
+                    codes= employee.getCodeRs();
+                }else {
+                    codes+=","+employee.getCodeRs();
+                }
+            }
+            if(codes!=null){
+                //messageService.sendWxMessage(codes, content.replaceAll("=",":").replaceAll(" ",""));
+                messageService.sendWxMessage("3210", content.replaceAll("=",":").replaceAll(" ",""));
+            }
+        }
+        resultMap.put("Code", "true");
+        resultMap.put("Message", "");
+        log.info("危机值消息发布成功");
+        JSONObject jsonObj = new JSONObject(resultMap);
+        return jsonObj.toString();
     }
 }