소스 검색

暂时提交

chenyongxing 6 년 전
부모
커밋
785a2a608d

+ 8 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/patient/PatientRequestMapping.java

@ -17,6 +17,14 @@ public class PatientRequestMapping {
        public static final String LIST = "/list";
    }
    /**
     * patientInfo
     */
    public static class PatientInfo extends Basic {
        public static final String PREFIX  = "/patientInfo";
    }
    /**
     * signPackage
     */

+ 4 - 0
common/common-util/pom.xml

@ -65,5 +65,9 @@
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
        </dependency>
    </dependencies>
</project>

+ 56 - 6
common/common-util/src/main/java/com/yihu/jw/util/common/RSAUtils.java

@ -1,15 +1,14 @@
package com.yihu.jw.util.common;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import javax.crypto.Cipher;
import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.springframework.util.Assert;
public class RSAUtils {
@ -37,6 +36,12 @@ public class RSAUtils {
        return new String(Base64.encodeBase64(key.getEncoded()));
    }
    public static String generateBase64PublicKey() {
        KeyPair keyPair = initKey();
        PublicKey publicKey = keyPair.getPublic();
        return new String(Base64.encodeBase64(publicKey.getEncoded()));
    }
    /**
     * 解密
     * @param string
@ -58,15 +63,60 @@ public class RSAUtils {
            throw new RuntimeException(e);
        }
    }
    /** 安全服务提供者 */
    private static final Provider PROVIDER = new BouncyCastleProvider();
    /**
     * 加密
     * @param publicKey
     *            公钥
     * @param data
     *            数据
     * @return 加密后的数据
     */
    public static byte[] encrypt(PublicKey publicKey, byte[] data) {
        Assert.notNull(publicKey);
        Assert.notNull(data);
        try {
            Cipher cipher = Cipher.getInstance("RSA/None/PKCS1Padding", PROVIDER);
            cipher.init(Cipher.ENCRYPT_MODE, publicKey);
            return cipher.doFinal(data);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 加密
     * @param publicKey
     *            公钥
     * @param text
     *            字符串
     * @return Base64编码字符串
     */
    public static String encrypt(PublicKey publicKey, String text) {
        Assert.notNull(publicKey);
        Assert.notNull(text);
        byte[] data = encrypt(publicKey, text.getBytes());
        return data != null ? Base64.encodeBase64String(data) : null;
    }
    public static void main(String[] args) {
        KeyPair keyPair =  initKey();
        // 生成public key
        System.out.println(generateBase64PublicKey(keyPair));
        String aa = encrypt(keyPair.getPublic(), "ee");
        System.out.println(aa);
        // 解密
        System.out.println(decryptBase64("wAfY9JkoKay9SxcPIs1FcG+t6sR+wYwAs/mh9DpfcBraxzqoZdb9LyaAigzFQ0EKck9OyHL0dhv+Uxuw5hHw6CPT0B2Z0i1gwrjDUNaL1gWvqt1pDJVGrIYPLJSjs9xktFhY1jbxQgXGjyCt06Rwid5sJknw90AUO0CyQulfipg=",keyPair));
        System.out.println(decryptBase64(aa,keyPair));
    }
}

+ 812 - 0
common/common-util/src/main/java/com/yihu/jw/util/common/XMLUtil.java

@ -0,0 +1,812 @@
package com.yihu.jw.util.common;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.dom4j.*;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.dom4j.tree.DefaultAttribute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.util.*;
public class XMLUtil {
    private static Logger logger = LoggerFactory.getLogger(XMLUtil.class);
    /**
     * 把xml字符串转换成 Document对象。
     *
     * @param xml 需要转换的xml字符串
     * @return 返回Document对象
     * @throws Exception 如果转换成Document对象异常的话抛出异常。
     */
    public static Document parseXml(String xml) throws Exception {
        try {
            return DocumentHelper.parseText(xml);
        } catch (DocumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new Exception("传入的 xml 不是标准的xml字符串,请检查字符串是否合法。");
        }
    }
    /**
     * 转换成xml字符串
     *
     * @param xmlDoc 需要解析的xml对象
     * @throws Exception
     */
    public static String toXML_UTF_8(Document xmlDoc) throws Exception {
        return toXML(xmlDoc, "UTF-8", true);
    }
    /**
     * 转换成xml字符串
     *
     * @param xmlDoc 需要解析的xml对象
     * @throws Exception
     */
    public static String toXML_GBK(Document xmlDoc) throws Exception {
        return toXML(xmlDoc, "GBK", true);
    }
    /**
     * 转换成xml字符串
     *
     * @param xmlDoc   需要解析的xml对象
     * @param encoding 编码格式:UTF-8、GBK
     * @param iscom    是否为紧凑型格式
     * @return 修正完成后的xml字符串
     * @throws Exception
     */
    public static String toXML(Document xmlDoc, String encoding,
                               boolean iscom) throws Exception {
        ByteArrayOutputStream byteRep = new ByteArrayOutputStream();
        OutputFormat format = null;
        if (iscom) {
            format = OutputFormat.createCompactFormat();// 紧凑型格式
        } else {
            format = OutputFormat.createPrettyPrint();// 缩减型格式
        }
        format.setEncoding(encoding);// 设置编码
        format.setTrimText(false);// 设置text中是否要删除其中多余的空格
        XMLWriter xw;
        try {
            xw = new XMLWriter(byteRep, format);
            xw.write(xmlDoc);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new Exception("传入的编码格式错误,请传入正确的编码。");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            throw new Exception("文档转换成xml字符串时出错。" + xmlDoc.asXML());
        }
        return byteRep.toString();
    }
    /**
     * 对节点Element 添加节点。
     *
     * @param e     需要添加的节点
     * @param name  添加的节点的名称
     * @param value 添加的内容
     *              <br/>
     *              Demo:
     *              < Root > aaa < /Root >
     *              <br/>
     *              call-->  addChildElement(root, "A", "a");
     *              <br/>
     *              result--> < Root >< A >a< /A >< /Root >
     */
    public static void addElement(Element e, String name, Object value) {
        if (isBlank(value)) {
            e.addElement(name).addText("");
        } else {
            e.addElement(name).addText(value.toString());
        }
    }
    /**
     * 判断对象是否为空!(null,"", "null")
     *
     * @param value
     * @return
     */
    private static boolean isBlank(String value) {
        if (value == null || value.length() == 0) {
            return true;
        } else if (StringUtils.isEmpty(value)) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * 判断对象是否非空!(null,"", "null")
     *
     * @param obj
     * @return
     */
    public static boolean isNotBlank(Object obj) {
        return !isBlank(obj);
    }
    /**
     * 判断对象是否为空!(null,"", "null")
     *
     * @param obj
     * @return
     */
    public static boolean isBlank(Object obj) {
        if (obj == null) {
            return true;
        }
        if (obj instanceof String) {
            return isBlank((String) obj);
        } else {
            return isBlank(obj.toString());
        }
    }
    public static void addElement(Element e, String name, Integer value) {
        Element current = e.addElement(name);
        if (value != null) {
            current.setText(Integer.toString(value));
        }
    }
    /**
     * 添加CDATA 类型节点
     *
     * @param e
     * @param name
     * @param value
     */
    public static void addCDATAElement(Element e, String name, String value) {
        Element current = e.addElement(name);
        if (value != null) {
            current.addCDATA(value.trim());
        }
    }
    /**
     * 添加CDATA 类型节点
     *
     * @param e
     * @param name
     * @param value
     */
    public static void addCDATAElement(Element e, String name, Integer value) {
        Element current = e.addElement(name);
        if (value != null) {
            current.addCDATA(value.toString());
        }
    }
    /**
     * 获取节点中的整数
     *
     * @throws Exception
     */
    public static int getInt(Element e, String name, boolean isMust) throws Exception {
        Element current = e.element(name);
        if (current == null || current.getText() == null || "".equals(current.getText().trim()) || current.getText().length() <= 0) {
            if (isMust) {
                throw new Exception("在 $" + e.asXML() + "$中获取节点:" + name + " 的值为空。");
            }
            return 0;
        }
        Integer i = 0;
        try {
            i = Integer.parseInt(current.getTextTrim());
        } catch (NumberFormatException e1) {
            i = 0;
            if (isMust) {
                throw new Exception("在 $" + e.asXML() + "$中获取节点:" + name + " 的值不是整形。");
            }
        }
        return i;
    }
    /**
     * 获取节点中的字符串
     *
     * @throws Exception
     */
    public static String getString(Element e, String name, boolean isMust) throws Exception {
        return getString(e, name, isMust, null);
    }
    /**
     * 获取节点中的字符串
     *
     * @param e
     * @param name
     * @param isMust 是否必填 true 必填  false非必填
     * @param defVal 默认值
     * @return
     * @throws Exception
     */
    public static String getString(Element e, String name, boolean isMust, String defVal) throws Exception {
        Element current = e.element(name);
        if (current == null || current.getText() == null || StringUtils.isEmpty(current.getText().trim())) {
            if (isMust) {
                throw new Exception("在 $" + e.asXML() + "$中获取节点:" + name + " 的值为空。");
            }
            return defVal;
        }
        return current.getTextTrim();
    }
    public static String ElementStringValue(String str) {
        if (str != null) {
            return str;
        } else {
            return "";
        }
    }
    public static Integer ElementIntegerValue(Integer str) {
        if (str != null) {
            return str;
        } else {
            return 0;
        }
    }
    public static String ElementValue(String str) {
        if (str != null && !str.equalsIgnoreCase("null")) {
            return str;
        } else {
            return "";
        }
    }
    public static String xml2json(String xml){
        StringWriter w = new StringWriter();
        ObjectMapper objectMapper = new ObjectMapper();
        XmlMapper xmlMapper = new XmlMapper();
        JsonParser jp;
        try {
            jp = xmlMapper.getFactory().createParser(xml);
            JsonGenerator jg = objectMapper.getFactory().createGenerator(w);
            while (jp.nextToken() != null) {
                String name = jp.getParsingContext().getCurrentName();
                if ("".equals(name)){
                    jp.overrideCurrentName("text");
                }
                jg.copyCurrentEvent(jp);
            }
            jp.close();
            jg.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return w.toString();
    }
    public static String formatXML(Document doc) throws Exception {
        StringWriter out = null;
        try {
            OutputFormat formate = OutputFormat.createPrettyPrint();
            out = new StringWriter();
            XMLWriter writer = new XMLWriter(out, formate);
            writer.write(doc);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            out.close();
        }
        return out.toString();
    }
    // ---------- map转XML--------------
    public static String map2xml(Map<String, String> dataMap) {
        synchronized (XMLUtil.class) {
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            strBuilder.append("<QUERY_FORM>");
            Set<String> objSet = dataMap.keySet();
            for (Object key : objSet) {
                if (key == null) {
                    continue;
                }
                strBuilder.append("<").append(key.toString()).append(">");
                Object value = dataMap.get(key);
                strBuilder.append(coverter(value));
                strBuilder.append("</").append(key.toString()).append(">");
            }
            strBuilder.append("</QUERY_FORM>");
            return strBuilder.toString();
        }
    }
    public static String map2xmlForWx(Map<String, String> dataMap) {
        synchronized (XMLUtil.class) {
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.append("<xml>");
            Set<String> objSet = dataMap.keySet();
            for (Object key : objSet) {
                if (key == null) {
                    continue;
                }
                strBuilder.append("<").append(key.toString()).append(">");
                Object value = dataMap.get(key);
                strBuilder.append(coverter(value));
                strBuilder.append("</").append(key.toString()).append(">");
            }
            strBuilder.append("</xml>");
            return strBuilder.toString();
        }
    }
    public static String coverter(Object[] objects) {
        StringBuilder strBuilder = new StringBuilder();
        for (Object obj : objects) {
            strBuilder.append("<item className=").append(obj.getClass().getName()).append(">\n");
            strBuilder.append(coverter(obj));
            strBuilder.append("</item>\n");
        }
        return strBuilder.toString();
    }
    public static String coverter(Collection<?> objects) {
        StringBuilder strBuilder = new StringBuilder();
        for (Object obj : objects) {
            strBuilder.append("<item className=").append(obj.getClass().getName()).append(">\n");
            strBuilder.append(coverter(obj));
            strBuilder.append("</item>\n");
        }
        return strBuilder.toString();
    }
    public static String coverter(Object object) {
        if (object instanceof Object[]) {
            return coverter((Object[]) object);
        }
        if (object instanceof Collection) {
            return coverter((Collection<?>) object);
        }
        StringBuilder strBuilder = new StringBuilder();
        if (isObject(object)) {
            Class<? extends Object> clz = object.getClass();
            Field[] fields = clz.getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                if (field == null) {
                    continue;
                }
                String fieldName = field.getName();
                Object value = null;
                try {
                    value = field.get(object);
                } catch (IllegalArgumentException e) {
                    continue;
                } catch (IllegalAccessException e) {
                    continue;
                }
                strBuilder.append("<").append(fieldName)
                        .append(" className=\"").append(
                        value.getClass().getName()).append("\">");
                if (isObject(value)) {
                    strBuilder.append(coverter(value));
                } else if (value == null) {
                    strBuilder.append("null");
                } else {
                    strBuilder.append(value.toString() + "");
                }
                strBuilder.append("</").append(fieldName).append(">");
            }
        } else if (object == null) {
            strBuilder.append("null");
        } else {
            strBuilder.append(object.toString());
        }
        return strBuilder.toString();
    }
    private static boolean isObject(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj instanceof String) {
            return false;
        }
        if (obj instanceof Integer) {
            return false;
        }
        if (obj instanceof Double) {
            return false;
        }
        if (obj instanceof Float) {
            return false;
        }
        if (obj instanceof Byte) {
            return false;
        }
        if (obj instanceof Long) {
            return false;
        }
        if (obj instanceof Character) {
            return false;
        }
        if (obj instanceof Short) {
            return false;
        }
        if (obj instanceof Boolean) {
            return false;
        }
        return true;
    }
    // --------------------xml转map---------------
    private static void ele2map(Map map, Element ele)  {
        // 获得当前节点的子节点
        List<Element> elements = ele.elements();
        if (elements.size() == 0) {
            // 没有子节点说明当前节点是叶子节点,直接取值即可
            map.put(ele.getName(), ele.getText());
        } else if (elements.size() == 1) {
            // 只有一个子节点说明不用考虑list的情况,直接继续递归即可
            Map<String, Object> tempMap = new HashMap<String, Object>();
            ele2map(tempMap, elements.get(0));
            //设置标签属性
            setAttributes(tempMap,elements.get(0));
            if (tempMap.size()==1){
                map.put(ele.getName(), ele.getText());
            }else {
                map.put(ele.getName(), tempMap);
            }
        } else {
            // 多个子节点的话就得考虑list的情况了,比如多个子节点有节点名称相同的
            // 构造一个map用来去重
            Map<String, Object> tempMap = new HashMap<String, Object>();
            for (Element element : elements) {
                tempMap.put(element.getName(), null);
            }
            Set<String> keySet = tempMap.keySet();
            for (String string : keySet) {
                Namespace namespace = elements.get(0).getNamespace();
                List<Element> elements2 = ele.elements(new QName(string, namespace));
                // 如果同名的数目大于1则表示要构建list
                if (elements2.size() > 1) {
                    List<Map> list = new ArrayList<Map>();
                    for (Element element : elements2) {
                        Map<String, Object> tempMap1 = new HashMap<String, Object>();
                        ele2map(tempMap1, element);
                        setAttributes(tempMap1,element);//属性值设置
                        list.add(tempMap1);
                    }
                    map.put(string, list);
                } else {
                    // 同名的数量不大于1则直接递归去
                    Map<String, Object> tempMap1 = new HashMap<String, Object>();
                    ele2map(tempMap1, elements2.get(0));
                    setAttributes(tempMap1,elements2.get(0));//属性值设置
                    if (tempMap1.containsKey(string)) {
                        map.put(string, tempMap1.get(string));
                    }else {
                        map.put(string, tempMap1);
                    }
                }
            }
        }
    }
    /**
     *
     * 设置属性值(xml转map)
     * @param map
     * @param element
     */
    public static void setAttributes(Map map,Element element){
        List list = element.attributes();
        Map<String,Object> attrMap = null;
        DefaultAttribute e = null;
        if (!list.isEmpty()) {
            attrMap = new HashMap<>();
            for (int i = 0; i < list.size(); i++) {
                e = (DefaultAttribute) list.get(i);
                attrMap.put(e.getName(),e.getText());
            }
            attrMap.put("text",element.getText());
        }
        if (attrMap!=null && !attrMap.isEmpty()){
            map.put(element.getName(),attrMap);
        }
    }
//============================================
    public static Object xml2map(Element element) {
        System.out.println(element);
        Map<String, Object> map = new HashMap<String, Object>();
        List<Element> elements = element.elements();
        if (elements.size() == 0) {
            map.put(element.getName(), element.getText());
            if (!element.isRootElement()) {
                return element.getText();
            }
        } else if (elements.size() == 1) {
            map.put(elements.get(0).getName(), xml2map(elements.get(0)));
        } else if (elements.size() > 1) {
            // 多个子节点的话就得考虑list的情况了,比如多个子节点有节点名称相同的
            // 构造一个map用来去重
            Map<String, Element> tempMap = new HashMap<String, Element>();
            for (Element ele : elements) {
                tempMap.put(ele.getName(), ele);
            }
            Set<String> keySet = tempMap.keySet();
            for (String string : keySet) {
                Namespace namespace = tempMap.get(string).getNamespace();
                List<Element> elements2 = element.elements(new QName(string, namespace));
                // 如果同名的数目大于1则表示要构建list
                if (elements2.size() > 1) {
                    List<Object> list = new ArrayList<Object>();
                    for (Element ele : elements2) {
                        list.add(xml2map(ele));
                    }
                    map.put(string, list);
                } else {
                    // 同名的数量不大于1则直接递归去
                    map.put(string, xml2map(elements2.get(0)));
                }
            }
        }
        return map;
    }
//    ============================================
    public static Map xmltoMap(String xml) {
        if (!StringUtils.isEmpty(xml)) {
            try {
                Map map = new HashMap();
                Document document = DocumentHelper.parseText(xml);
                Element nodeElement = document.getRootElement();
                List node = nodeElement.elements();
                for (Iterator it = node.iterator(); it.hasNext(); ) {
                    Element elm = (Element) it.next();
                    List list = elm.elements();
                    if(list.size() > 0){
                        Map xmltoMap = xmltoMap(elm.asXML());
                        map.putAll(xmltoMap);
                    }else{
                        map.put(elm.getName(), elm.getText());
                    }
                    elm = null;
                }
                node = null;
                nodeElement = null;
                document = null;
                return map;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
    public static Map xmltoMap2(String xml) {
        Map<String,Object> map = new HashMap<String,Object>();
        Document doc;
        try {
            doc = DocumentHelper.parseText(xml);
            Element el = doc.getRootElement();
            map.put(el.getName(), DiGui(el));
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return map;
    }
    public static void main(String[] args) {
        String aa="<HisTrans>\n" +
                "  <TranCode>GetHealthYE</TranCode>\n" +
                "  <RespMsg />\n" +
                "  <RespCode>0</RespCode>\n" +
                "  <Order>\n" +
                "    <HealthYE>3.94</HealthYE>\n" +
                "    <HospitalizationYE />\n" +
                "  </Order>\n" +
                "</HisTrans>";
//        String aa= "<HisTrans>\n" +
//                "  <TranCode>GetHealthYE</TranCode>\n" +
//                "  <RespMsg />\n" +
//                "  <RespCode>0</RespCode>\n" +
//                "  <Order>\n" +
//                "    <HealthYE>3.94</HealthYE>\n" +
//                "    <HospitalizationYE></HospitalizationYE>\n" +
//                "  </Order>\n" +
//                "</HisTrans>";
        Map map = xmltoMap(aa);
        System.out.println(map);
    }
    public static List xmltoList(String xml) {
        if (!StringUtils.isEmpty(xml)) {
            try {
                List<Map> list = new ArrayList<Map>();
                Document document = DocumentHelper.parseText(xml);
                Element nodesElement = document.getRootElement();
                List nodes = nodesElement.elements();
                for (Iterator its = nodes.iterator(); its.hasNext(); ) {
                    Element nodeElement = (Element) its.next();
                    Map map = xmltoMap(nodeElement.asXML());
                    list.add(map);
                    map = null;
                }
                nodes = null;
                nodesElement = null;
                document = null;
                return list;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
    public static Map DiGui(Element rootElement) {
        // 对节点进行判断
        int flag = hasGradeChrid(rootElement);
        // 存储本层的map,采用LinkedHashMap,保证的顺序
        Map<String, Object> map_this = new LinkedHashMap<String, Object>();
        // 存储子节点的map,采用LinkedHashMap,保证的顺序
        Map<String, Object> map_children = new LinkedHashMap<String, Object>();
        // 获取节点迭代器
        Iterator<Element> iterator = rootElement.elementIterator();
        if (flag == 0) {// 说明该节点所有子节点均有子节点,进入递归
            int num = 0;
            while (iterator.hasNext()) {// 依次继续对节点进行操作
                Element childelement = iterator.next();
                map_children = DiGui(childelement);
                map_this.put(childelement.getName() + "_" + num, map_children);
                num++;
            }
        }
        if (flag == 1) {// 说明该节点的所有子节点均无子节点,封装数据
            while (iterator.hasNext()) {
                Element childelement = iterator.next();
                map_this.put(childelement.getName(),
                        (String) childelement.getData());
            }
        }
        if (flag == 2) {// 说明了该节点的子节点有些拥有子节点,有些不拥有
            int nodes = rootElement.elements().size();// 获取子节点个数
            while (nodes >= 1) {
                nodes--;
                int num = 0;//为了让循环重复的节点,避免了key的冲突
                Element element = iterator.next();
                flag = hasGradeChrid(element);//对节点进行判断
                if (flag == 1) {                          //对于子节点,如果只是普通的子节点,那么直接将数进行封装
                    // 封装如map,String,String
                    map_this.put(element.getName(), element.getData());
                }
                else{                                     //非普通子节点,那么进行递归
                    map_children = DiGui(element);
                    map_this.put(element.getName() + "_" + num, map_children);//为了让循环重复的节点,避免了key的冲突
                }
            }
        }
        return map_this;
    }
    /**
     * 用于判断该节点的类型 0:说明该节点所有子节点均有子节点 1:说明该节点的所有子节点均无子节点 2:说明了该节点的子节点有些拥有子节点,有些不拥有
     *
     * @param rootelement
     * @return
     */
    public static int hasGradeChrid(Element rootelement) {
        int flag = 1;// 初始为1,用与处理对没有子节点的节点进行判断
        StringBuffer flag_arr = new StringBuffer();
        Iterator<Element> iterator = rootelement.elementIterator();
        while (iterator.hasNext()) {
            Element element = iterator.next();// 获取入参rootelement节点的子节点
            // Iterator<Element> iterator_chirld = element.elementIterator();
            if (element.elements().size() > 0) {// 判断是否有子节点
                flag_arr.append("0");
            } else {
                flag_arr.append("1");
            }
        }
        // 如果只包含0,说明该节点所有子节点均有子节点
        if (flag_arr.toString().contains("0")) {
            flag = 0;
        }
        // 如果只包含1,说明该节点的所有子节点均无子节点
        if (flag_arr.toString().contains("1")) {
            flag = 1;
        }
        // 如果同时包含了,0,1,说明了该节点的子节点有些拥有子节点,有些不拥有
        if (flag_arr.toString().contains("0")
                && flag_arr.toString().contains("1")) {
            flag = 2;
        }
        return flag;
    }
    /* ============================== 以下暂时添加,后面可删除 ========================================= */
//    public static String maptoXml(Map map) {
//        Document document = DocumentHelper.createDocument();
//        Element nodeElement = document.addElement("node");
//        for (Object obj : map.keySet()) {
//            Element keyElement = nodeElement.addElement("key");
//            keyElement.addAttribute("label", String.valueOf(obj));
//            keyElement.setText(String.valueOf(map.get(obj)));
//        }
//        return doc2String(document);
//    }
//
//    public static String listtoXml(List list) throws Exception {
//        Document document = DocumentHelper.createDocument();
//        Element nodesElement = document.addElement("nodes");
//        int i = 0;
//        for (Object o : list) {
//            Element nodeElement = nodesElement.addElement("node");
//            if (o instanceof Map) {
//                for (Object obj : ((Map) o).keySet()) {
//                    Element keyElement = nodeElement.addElement("key");
//                    keyElement.addAttribute("label", String.valueOf(obj));
//                    keyElement.setText(String.valueOf(((Map) o).get(obj)));
//                }
//            } else {
//                Element keyElement = nodeElement.addElement("key");
//                keyElement.addAttribute("label", String.valueOf(i));
//                keyElement.setText(String.valueOf(o));
//            }
//            i++;
//        }
//        return doc2String(document);
//    }
//
//    public static String doc2String(Document document) {
//        String s = "";
//        try {
//            // 使用输出流来进行转化
//            ByteArrayOutputStream out = new ByteArrayOutputStream();
//            // 使用UTF-8编码
//            OutputFormat format = new OutputFormat("   ", true, "UTF-8");
//            XMLWriter writer = new XMLWriter(out, format);
//            writer.write(document);
//            s = out.toString("UTF-8");
//        } catch (Exception ex) {
//            ex.printStackTrace();
//        }
//        return s;
//    }
}

+ 59 - 0
common/common-util/src/main/java/com/yihu/jw/util/wechat/WXPayConstants.java

@ -0,0 +1,59 @@
package com.yihu.jw.util.wechat;
import org.apache.http.client.HttpClient;
/**
 * 常量
 */
public class WXPayConstants {
    public enum SignType {
        MD5, HMACSHA256
    }
    public static final String DOMAIN_API = "api.mch.weixin.qq.com";
    public static final String DOMAIN_API2 = "api2.mch.weixin.qq.com";
    public static final String DOMAIN_APIHK = "apihk.mch.weixin.qq.com";
    public static final String DOMAIN_APIUS = "apius.mch.weixin.qq.com";
    public static final String FAIL     = "FAIL";
    public static final String SUCCESS  = "SUCCESS";
    public static final String HMACSHA256 = "HMAC-SHA256";
    public static final String MD5 = "MD5";
    public static final String FIELD_SIGN = "sign";
    public static final String FIELD_SIGN_TYPE = "sign_type";
    public static final String WXPAYSDK_VERSION = "WXPaySDK/3.0.9";
    public static final String USER_AGENT = WXPAYSDK_VERSION +
            " (" + System.getProperty("os.arch") + " " + System.getProperty("os.name") + " " + System.getProperty("os.version") +
            ") Java/" + System.getProperty("java.version") + " HttpClient/" + HttpClient.class.getPackage().getImplementationVersion();
    public static final String MICROPAY_URL_SUFFIX     = "/pay/micropay";
    public static final String UNIFIEDORDER_URL_SUFFIX = "/pay/unifiedorder";
    public static final String ORDERQUERY_URL_SUFFIX   = "/pay/orderquery";
    public static final String REVERSE_URL_SUFFIX      = "/secapi/pay/reverse";
    public static final String CLOSEORDER_URL_SUFFIX   = "/pay/closeorder";
    public static final String REFUND_URL_SUFFIX       = "/secapi/pay/refund";
    public static final String REFUNDQUERY_URL_SUFFIX  = "/pay/refundquery";
    public static final String DOWNLOADBILL_URL_SUFFIX = "/pay/downloadbill";
    public static final String REPORT_URL_SUFFIX       = "/payitil/report";
    public static final String SHORTURL_URL_SUFFIX     = "/tools/shorturl";
    public static final String AUTHCODETOOPENID_URL_SUFFIX = "/tools/authcodetoopenid";
    // sandbox
    public static final String SANDBOX_MICROPAY_URL_SUFFIX     = "/sandboxnew/pay/micropay";
    public static final String SANDBOX_UNIFIEDORDER_URL_SUFFIX = "/sandboxnew/pay/unifiedorder";
    public static final String SANDBOX_ORDERQUERY_URL_SUFFIX   = "/sandboxnew/pay/orderquery";
    public static final String SANDBOX_REVERSE_URL_SUFFIX      = "/sandboxnew/secapi/pay/reverse";
    public static final String SANDBOX_CLOSEORDER_URL_SUFFIX   = "/sandboxnew/pay/closeorder";
    public static final String SANDBOX_REFUND_URL_SUFFIX       = "/sandboxnew/secapi/pay/refund";
    public static final String SANDBOX_REFUNDQUERY_URL_SUFFIX  = "/sandboxnew/pay/refundquery";
    public static final String SANDBOX_DOWNLOADBILL_URL_SUFFIX = "/sandboxnew/pay/downloadbill";
    public static final String SANDBOX_REPORT_URL_SUFFIX       = "/sandboxnew/payitil/report";
    public static final String SANDBOX_SHORTURL_URL_SUFFIX     = "/sandboxnew/tools/shorturl";
    public static final String SANDBOX_AUTHCODETOOPENID_URL_SUFFIX = "/sandboxnew/tools/authcodetoopenid";
}

+ 148 - 0
common/common-util/src/main/java/com/yihu/jw/util/wechat/WeiXinPayUtils.java

@ -0,0 +1,148 @@
package com.yihu.jw.util.wechat;
import com.yihu.jw.util.common.XMLUtil;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.*;
public class WeiXinPayUtils {
    private static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final Random RANDOM = new SecureRandom();
    /**
     *
     * 微信支付,统一下单
     *
     * param 对应的key值参见文档 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1 (sign,nonce_str两个参数,此接口会自动生成)
     *
     * @param param
     * @param appKey
     * @return
     * @throws Exception
     */
    public static Map<String,Object> unifiedorder(Map<String, String> param,String appKey) throws Exception {
        param.put("nonce_str",generateNonceStr());
        WXPayConstants.SignType  wxSignType = WXPayConstants.SignType.MD5;
        String signType = param.get("sign_type");
        if("HMAC-SHA256".equalsIgnoreCase(signType)){
            wxSignType = WXPayConstants.SignType.HMACSHA256;
        }
        //获取微信签名
        String signature = WeiXinPayUtils.generateSignature(param, appKey, wxSignType);
        param.put("sign",signature);
        //参数转化XML
        String params = XMLUtil.map2xmlForWx(param);
        String result = HttpUtil.sendPost("https://api.mch.weixin.qq.com/pay/unifiedorder", params);
        Map<String,Object> wxrs =  XMLUtil.xmltoMap(result);
        return wxrs;
    }
    /**
     * 获取随机字符串 Nonce Str
     *
     * @return String 随机字符串
     */
    private static String generateNonceStr() {
        char[] nonceChars = new char[32];
        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }
        return new String(nonceChars);
    }
    /**
     * 生成签名. 注意,若含有sign_type字段,必须和signType参数保持一致。
     *
     * @param data 待签名数据
     * @param key API密钥
     * @param signType 签名方式
     * @return 签名
     */
    private static String generateSignature(final Map<String, String> data, String key, WXPayConstants.SignType signType) throws Exception {
        Set<String> keySet = data.keySet();
        String[] keyArray = keySet.toArray(new String[keySet.size()]);
        Arrays.sort(keyArray);
        StringBuilder sb = new StringBuilder();
        for (String k : keyArray) {
            if (k.equals(WXPayConstants.FIELD_SIGN)) {
                continue;
            }
            if (data.get(k).trim().length() > 0) // 参数值为空,则不参与签名
                sb.append(k).append("=").append(data.get(k).trim()).append("&");
        }
        sb.append("key=").append(key);
        if (WXPayConstants.SignType.MD5.equals(signType)) {
            return MD5(sb.toString()).toUpperCase();
        }
        else if (WXPayConstants.SignType.HMACSHA256.equals(signType)) {
            return HMACSHA256(sb.toString(), key);
        }
        else {
            throw new Exception(String.format("Invalid sign_type: %s", signType));
        }
    }
    /**
     * 生成 MD5
     *
     * @param data 待处理数据
     * @return MD5结果
     */
    private static String MD5(String data) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] array = md.digest(data.getBytes("UTF-8"));
        StringBuilder sb = new StringBuilder();
        for (byte item : array) {
            sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
        }
        return sb.toString().toUpperCase();
    }
    /**
     * 生成 HMACSHA256
     * @param data 待处理数据
     * @param key 密钥
     * @return 加密结果
     * @throws Exception
     */
    private static String HMACSHA256(String data, String key) throws Exception {
        Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
        SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
        sha256_HMAC.init(secret_key);
        byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8"));
        StringBuilder sb = new StringBuilder();
        for (byte item : array) {
            sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
        }
        return sb.toString().toUpperCase();
    }
    public static void main(String[] args) throws Exception {
        HashMap<String, String> map = new HashMap<>();
        map.put("appid","wx0a06b75a40b28f2a");
        map.put("mch_id","1516700601");
        map.put("body","腾讯充值中心-QQ会员充值");
        map.put("out_trade_no","20181127112445");
        map.put("total_fee","1");
        map.put("spbill_create_ip","192.168.6.109");
        map.put("notify_url","http://www.baidu.com");
        map.put("trade_type","JSAPI");
        map.put("openid", "oDGGt0QrJvH-YbDCHFgjd3Exc0Sw");
        Map<String, Object> pay = unifiedorder(map, "yF4e9Rr1sVdqCF6c7cqqMPSNsCjYGyf9");
        System.out.println("--------------");
    }
}

+ 0 - 39
svr/svr-base/pom.xml

@ -118,11 +118,6 @@
            <artifactId>mysql-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>elasticsearch-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.github.swagger2markup</groupId>
@ -136,41 +131,7 @@
            </exclusions>
        </dependency>
        <!-- 发送邮件 -->
        <dependency>
            <groupId>com.sun.mail</groupId>
            <artifactId>javax.mail</artifactId>
            <version>1.4.7</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <!--   poi xml导入导出工具 start-->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.yihu.ehr</groupId>
                    <artifactId>commons-util</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-collections4</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
        </dependency>
        <!-- xlsx  依赖这个包 -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>

+ 31 - 0
svr/svr-patient/src/main/java/com/yihu/jw/patient/dao/patient/BasePatientDao.java

@ -0,0 +1,31 @@
package com.yihu.jw.patient.dao.patient;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
import java.util.Map;
/**
 * Created by Trick on 2018/8/31.
 */
public interface BasePatientDao extends PagingAndSortingRepository<BasePatientDO, String>, JpaSpecificationExecutor<BasePatientDO> {
    BasePatientDO findByIdAndDel(String id, String del);
    @Query("from BasePatientDO where mobile = ?1")
    List<BasePatientDO> findByMobile(String mobile);
    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,phone as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO where idcard like ?1")
    List<Map<String,Object>> findByIdcard(String idcard, Pageable pageable);
    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,phone as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO where name like ?1")
    List<Map<String,Object>> findByName(String name, Pageable pageable);
    @Query("select id as id,idcard as idcard,name as name,case sex when 1 then '男' when 2 then '女' else '未知' end as sex,phone as phone,committeeName as committeeName,concat(provinceName,cityName,townName,streetName) as address from BasePatientDO")
    List<Map<String,Object>> findBaseInfo(Pageable pageable);
}

+ 352 - 0
svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/patient/PatientInfoEndpint.java

@ -0,0 +1,352 @@
package com.yihu.jw.patient.endpoint.patient;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.patient.dao.patient.BasePatientDao;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.patient.PatientRequestMapping;
import com.yihu.jw.util.common.RSAUtils;
import com.yihu.jw.util.security.MD5;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
@RestController
@RequestMapping(PatientRequestMapping.PatientInfo.PREFIX)
@Api(value = "患者注册,登陆等", description = "患者注册,登陆等", tags = {"居民端 - 患者注册,登陆等"})
public class PatientInfoEndpint extends EnvelopRestEndpoint {
    @Autowired
    private BasePatientDao patientDao;
    @RequestMapping(value = "/getKey", method = RequestMethod.POST)
    public String getKey(){
        String publicKey = RSAUtils.generateBase64PublicKey();
        return publicKey;
    }
    @ApiOperation("居民注册接口")
    @RequestMapping(value = "regist", method = RequestMethod.POST)
    @ResponseBody
    public Envelop regist(@ApiParam(value = "手机号", name = "mobile") @RequestParam(required = true)String mobile ,
                         @ApiParam(value = "验证码", name = "captcha") @RequestParam(value = "captcha", required = true) String captcha,
                         @ApiParam(value = "微信openId", name = "openid") @RequestParam(value = "openid", required = false) String openid,
                         @ApiParam(value = "密码", name = "password") @RequestParam(value = "password", required = true) String password) {
        try {
            Envelop envelop = new Envelop();
            //验证手机是否被注册
            List<BasePatientDO> list =  patientDao.findByMobile(mobile);
            if(list!=null && list.size()>0){
                envelop.setMessage("该手机号已经注册!");
                envelop.setStatus(-1);
                return envelop;
            }
            // 对验证码进行校验 todo cyx
//            int res = smsService.check(mobile, 1, captcha);
//            switch (res) {
//                case -2:
//                    return error(-1, "验证码已过期!");
//                case -1:
//                    return error(-1, "请输入正确的验证码!");
//                case 0:
//                    return error(-1, "验证码无效!");
//            }
            BasePatientDO patient = new BasePatientDO();
            patient.setMobile(mobile);
            //增加密码
            String salt = UUID.randomUUID().toString().replace("-", "");
            patient.setSalt(salt);
//            rsaUtils.setBaseService(patientService);
//            password = rsaUtils.decryptString(password);
//            password = StringUtils.reverse(password);
//            patient.setPassword(MD5.GetMD5Code(password + salt));
//            patient.setSsc(ssc);
//            if(!"undefined".equals(openid) && StringUtils.isNotBlank(openid)){
//                patient.setOpenid(openid);
//                patient.setOpenidTime(new Date());
//            }
////            if (!org.springframework.util.StringUtils.isEmpty(openid)) {
////                patient.setOpenid(openid);
////                patient.setOpenidTime(new Date());
////            }
//            JSONObject json = patientService.register(mobile, MD5.GetMD5Code(password + salt)
//                    ,salt,openid,3);
        } catch (Exception e) {
//            error(e);
////            return error(-1, "注册失败!");
        }
        return null;
    }
//    /**
//     * 患者微信登录接口
//     *
//     * @param captcha  短信号
//     * @param mobile   电话号码
//     * @param password 登录密码
//     * @return
//     */
//    @RequestMapping(value = "login", method = RequestMethod.POST)
//    @ResponseBody
//    public String login(
//            @RequestParam(required = false) String mobile,
//            @RequestParam(required = false) String captcha,
//            @RequestParam(required = false) String password,
//            String openid) {
//        String errorMessage;
//        LoginLog loginLog = new LoginLog();
//        loginLog.setCreateTime(new Date());
//        loginLog.setPhone(mobile);
//        loginLog.setType("2");
//        loginLog.setUserType("1");
//        try {
//            //账号登录 mobile可能是电话号也可能是身份证
//            if (StringUtils.isNoneEmpty(mobile) && StringUtils.isNoneEmpty(password)) {
//                Patient p = patientService.findByIdcard(mobile);
//                if (p == null) {
//                    List<Patient> patients = patientService.findByMobile(mobile);
//                    if (patients.size() > 1) {
//                        return error(-1, "此手机号码存在多个用户,请用身份证进行登录!");
//                    } else if (patients.size() == 1) {
//                        p = patients.get(0);
//                    }
//                }
//                loginLog.setLoginType("2");
//                if (p == null) {
//                    if (mobile.length() == 11) {
//                        errorMessage = "该手机号暂未注册账号,请确认后重新输入!";
//                    } else {
//                        errorMessage = "该身份证号暂未注册账号,请确认后重新输入!";
//                    }
//                    loginLog.setErrorMessage(errorMessage);
//                    loginLogService.saveLog(loginLog);
//                    return error(-1, errorMessage);
//                } else if (p.getStatus() == 0) {
//                    if (mobile.length() == 11) {
//                        errorMessage = "该手机号已被禁止使用!";
//                    } else {
//                        errorMessage = "该身份证号已被禁止使用!";
//                    }
//                    loginLog.setErrorMessage(errorMessage);
//                    loginLogService.saveLog(loginLog);
//                    return error(-1, errorMessage);
//                } else if (p.getStatus() == 2) {
//                    errorMessage = "该账号正在审核中,请确认审核通过后再登录,“如有疑问,拨打400-6677-400转2人工客服”";
//                    loginLog.setErrorMessage(errorMessage);
//                    loginLogService.saveLog(loginLog);
//                    return error(-1, errorMessage);
//                } else if (StringUtils.isEmpty(openid)) {
//                    errorMessage = "无效的OpenID!";
//                    loginLog.setErrorMessage(errorMessage);
//                    loginLogService.saveLog(loginLog);
//                    return error(-1, errorMessage);
//                }
//                loginLog.setUserCode(p.getCode());
//                //解密
//                rsaUtils.setBaseService(patientService);
//                password = rsaUtils.decryptString(password);
//                password = StringUtils.reverse(password);
//                //生成MD5
//                String loginPassword = MD5.GetMD5Code(password + p.getSalt());
//                //判断d登录密码是否正确
//                if (loginPassword.equals(p.getPassword())) {
//                    // 绑定用户手机号和openid
//                    if (StringUtils.isNotBlank(openid) && !"undefined".equals(openid)) {//undefined不更新数据库
//                        //patient.setOpenid(openid);
//                        //1.判斷居民OPenid是不是空
//                        if(StringUtils.isNotBlank(p.getOpenid())){
//                            //如果OPenid与原来用户不相等,则判断登录的openids是否被大于10人登录
//                            if(!p.getOpenid().equals(openid)){
//                                //判断登录的openids是否被大于10人登录
////                                if(!patientService.checkOpenidCount(openid)){
////                                    errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                    return error(-2, errorMessage);
////                                }
//                            }
//                            patientService.updatePatient(p, openid);
//                        }else{
//                            // 判断登录的openids是否被大于10人登录
//                            if(!patientService.checkOpenidCount(openid)){
////                                errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                return error(-2, errorMessage);
//                            }else{
//                                //未达到上限更新用户openid
//                                patientService.updatePatient(p, openid);
//                            }
//                        }
//                    }
//
//                    // 用户校验通过,生成token
//                    Token token = tokenService.newTxToken(p.getCode(), openid);
//                    Map<Object, Object> map = new HashMap<Object, Object>();
//                    map.put("id", p.getId());
//                    map.put("uid", p.getCode());
//                    map.put("name", p.getName());
//                    map.put("token", token.getToken());
//                    map.put("photo", p.getPhoto());
//                    if (StringUtils.isNoneEmpty(openid)) {
//                        //发送微信模板
//                        familyService.sendWXMessage(p);
//                    }
//
//                    loginLog.setLoginType("1");
//                    loginLogService.saveLog(loginLog);
//                    //判断是否打过标签
//                    //if (!(Patient.isWchatTage.yes.getValue() == p.getIsWxtag())) {
//
//                    //清空患者的微信标签
//                    weiXinTagUtil.deleteTagWithOpenid(p.getOpenid());
//                    //给患者打微信标签
//                    weiXinTagUtil.addTagWithOpenid(openid, p.getCode(), p.getName());
//                    //}
//                    return write(200, "登录成功", "data", map);
//                } else {
//                    errorMessage = "密码错误,登录失败";
//                    loginLog.setErrorMessage(errorMessage);
//                    loginLogService.saveLog(loginLog);
//                    return error(-1, errorMessage);
//                }
//            }
//            //短信登录
//            if (StringUtils.isNoneEmpty(mobile) && StringUtils.isNoneEmpty(captcha)) {
//                List<Patient> patients = patientService.findByMobile(mobile);
//                if (patients.size() > 1) {
//                    return error(-1, "此手机存在多个用户,请用身份证和密码登录!");
//                }
//                // 对验证码进行校验
//                int res = smsService.check(mobile, 4, captcha);
//                switch (res) {
//                    case -2: {
//                        errorMessage = "验证码已过期!";
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLogService.saveLog(loginLog);
//                        return error(-1, errorMessage);
//                    }
//                    case -1: {
//                        errorMessage = "请输入正确的验证码!";
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLogService.saveLog(loginLog);
//                        return error(-1, errorMessage);
//                    }
//                    case 0: {
//                        errorMessage = "验证码无效!";
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLogService.saveLog(loginLog);
//                        return error(-1, errorMessage);
//                    }
//                }
//
//                loginLog.setLoginType("1");
//                if (patients == null || patients.size() == 0) {
//                    if (mobile.length() == 11) {
//                        errorMessage = "该手机号暂未注册账号,请确认后重新输入!";
//                    } else {
//                        errorMessage = "该身份证号暂未注册账号,请确认后重新输入!";
//                    }
//                    loginLog.setErrorMessage(errorMessage);
//                    loginLogService.saveLog(loginLog);
//                    return error(-1, errorMessage);
//                } else {
//                    Patient p = null;
//                    if (patients.size() == 1) {
//                        p = patients.get(0);
//                    }
//                    if (p.getStatus() == 0) {
//                        if (mobile.length() == 11) {
//                            errorMessage = "该手机号已被禁止使用!";
//                        } else {
//                            errorMessage = "该身份证号已被禁止使用!";
//                        }
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLogService.saveLog(loginLog);
//                        return error(-1, errorMessage);
//                    } else if (p.getStatus() == 2) {
//                        errorMessage = "该账号正在审核中,请确认审核通过后再登录,“如有疑问,拨打400-6677-400转2人工客服”";
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLogService.saveLog(loginLog);
//                        return error(-1, errorMessage);
//                    } else if (StringUtils.isEmpty(openid)) {
//                        errorMessage = "无效的OpenID!";
//                        loginLog.setErrorMessage(errorMessage);
//                        loginLogService.saveLog(loginLog);
//                        return error(-1, errorMessage);
//                    }
//                    loginLog.setUserCode(p.getCode());
//                    // 绑定用户手机号和openid
////                    if (!StringUtils.equals(p.getOpenid(), openid) && !"undefined".equals(openid)) {//undefined不更新数据库
////                        //patient.setOpenid(openid);
////                        patientService.updatePatient(p, openid);
////                    }
//                    if (StringUtils.isNotBlank(openid) && !"undefined".equals(openid)) {//undefined不更新数据库
//                        //patient.setOpenid(openid);
//                        //1.判斷居民OPenid是不是空
//                        if(StringUtils.isNotBlank(p.getOpenid())){
//                            //如果OPenid与原来用户不相等,则判断登录的openids是否被大于10人登录
//                            if(!p.getOpenid().equals(openid)){
//                                //判断登录的openids是否被大于10人登录
//                                if(!patientService.checkOpenidCount(openid)){
////                                    errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                    return error(-2, errorMessage);
//                                }
//                            }
//                            patientService.updatePatient(p, openid);
//                        }else{
//                            // 判断登录的openids是否被大于10人登录
//                            if(!patientService.checkOpenidCount(openid)){
////                                errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
////                                return error(-2, errorMessage);
//                            }else{
//                                //未达到上限更新用户openid
//                                patientService.updatePatient(p, openid);
//                            }
//                        }
//                    }
//
//                    // 用户校验通过,生成token
//                    Token token = tokenService.newTxToken(p.getCode(), openid);
//                    Map<Object, Object> map = new HashMap<Object, Object>();
//                    map.put("id", p.getId());
//                    map.put("uid", p.getCode());
//                    map.put("name", p.getName());
//                    map.put("token", token.getToken());
//                    map.put("photo", p.getPhoto());
//                    if (StringUtils.isNoneEmpty(openid)) {
//                        //发送微信模板
//                        familyService.sendWXMessage(p);
//                    }
//                    loginLog.setType("1");
//                    loginLogService.saveLog(loginLog);
//                    //判断是否打过标签
//                    //if (!(Patient.isWchatTage.yes.getValue() == p.getIsWxtag())) {
//                    //清空患者的微信标签
//                    weiXinTagUtil.deleteTagWithOpenid(p.getOpenid());
//                    //给患者打微信标签
//                    weiXinTagUtil.addTagWithOpenid(openid, p.getCode(), p.getName());
//                    //}
//                    return write(200, "登录成功", "data", map);
//                }
//            }
//            return error(-1, "登录失败");
//        } catch (Exception e) {
//
//            errorMessage = "系统异常,登录失败";
//            loginLog.setErrorMessage(errorMessage);
//            loginLogService.saveLog(loginLog);
//            error(e);
//            return error(-1, "系统异常,登录失败");
//        }
//    }
}

+ 6 - 0
wlyy-parent-pom/pom.xml

@ -98,6 +98,7 @@
        <version.poi>3.17</version.poi>
        <version.jxl>2.6.10</version.jxl>
        <version.okhttp>3.4.1</version.okhttp>
        <version.jackson-dataformat-xml>2.6.6</version.jackson-dataformat-xml>
        <!-- Version end -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -169,6 +170,11 @@
                <artifactId>common-tracer</artifactId>
                <version>${version.wlyy-common}</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.dataformat</groupId>
                <artifactId>jackson-dataformat-xml</artifactId>
                <version>${version.jackson-dataformat-xml}</version>
            </dependency>
            <!-- Jkzl Starter -->
            <dependency>