ChenJiaHe
2020-12-12 8bc3c99b8afeb76573bafa7a7ec51b551f500662
优化
2个文件已添加
6个文件已修改
166 ■■■■■ 已修改文件
src/main/java/com/hx/common/dao/CommonDao.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/common/service/CommonService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/common/service/impl/CommonDaoImpl.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/common/service/impl/CommonServiceImpl.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/util/HttpUtil.java 30 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/util/StringUtils.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/util/gaode/AddressCode.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/util/gaode/GaoDeMapUtil.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/common/dao/CommonDao.java
@@ -27,6 +27,13 @@
     */
    <T extends Serializable> int selectCount(Class<?> mapperClass, SqlSentence sqlSentence);
    /**查询条数
     * @param mapperClass mapper类
     * @param sqlSentence  查询参数类
     * @return 返回条数
     */
    <T extends Serializable> int selectCountSql(Class<?> mapperClass, SqlSentence sqlSentence);
    /**查询列表,返回实体类的List
     * @param mapperClass mapper类
     * @param sqlSentence 查询参数类
src/main/java/com/hx/common/service/CommonService.java
@@ -27,6 +27,14 @@
     */
    <T extends Serializable> int selectCount(Class<?> mapperClass, SqlSentence sqlSentence);
    /**查询条数
     * @param mapperClass mapper类
     * @param sqlSentence  查询参数类
     * @return 返回条数
     */
    <T extends Serializable> int selectCountSql(Class<?> mapperClass, SqlSentence sqlSentence);
    /**查询列表,返回实体类的List
     * @param mapperClass mapper类
     * @param sqlSentence 查询参数类
src/main/java/com/hx/common/service/impl/CommonDaoImpl.java
@@ -28,12 +28,20 @@
        return sqlSessionFactory.openSession().insert(getStatement(mapperClass,"insert"),entity);
    }
    /**获取条数*/
    /**获取条数
     * @return*/
    @Override
    public <T extends Serializable> int selectCount(Class<?> mapperClass,SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCount"),sqlSentence);
    }
    /**获取条数
     * @return*/
    @Override
    public <T extends Serializable> int selectCountSql(Class<?> mapperClass, SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCountSql"),sqlSentence);
    }
    /**获取列表*/
    @Override
    public <T extends Serializable> List<T> selectList(Class<?> mapperClass, SqlSentence sqlSentence) {
src/main/java/com/hx/common/service/impl/CommonServiceImpl.java
@@ -31,6 +31,12 @@
        return commonDao.selectCount(mapperClass,sqlSentence);
    }
    /**获取条数*/
    @Override
    public <T extends Serializable> int selectCountSql(Class<?> mapperClass,SqlSentence sqlSentence) {
        return commonDao.selectCountSql(mapperClass,sqlSentence);
    }
    /**获取列表*/
    @Override
    public <T extends Serializable> List<T> selectList(Class<?> mapperClass, SqlSentence sqlSentence) {
src/main/java/com/hx/util/HttpUtil.java
@@ -6,6 +6,8 @@
import org.springframework.web.multipart.MultipartFile;
import javax.activation.MimetypesFileTypeMap;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -23,6 +25,27 @@
    /**回车换行,用于一行的结尾*/
    private static final String LINE_END = "\r\n";
    public static String getInputStream(HttpServletRequest request) throws Exception {
        ServletInputStream stream = null;
        BufferedReader reader = null;
        StringBuffer sb = new StringBuffer();
        try {
            stream = request.getInputStream();
            // 获取响应
            reader = new BufferedReader(new InputStreamReader(stream));
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
        } catch (IOException e) {
            //logger.error(e);
            throw new RuntimeException("读取返回支付接口数据流出现异常!");
        } finally {
            reader.close();
        }
        //logger.info("输入流返回的内容:" + sb.toString());
        return sb.toString();
    }
    public static String post(String requestUrl, String accessToken, String params)
            throws Exception {
@@ -162,13 +185,6 @@
            // //System.out.println("HttpURLUtil:"+wxMsgXml);
        } catch (Exception e) {
            e.printStackTrace();
            obj = new JSONObject();
            try {
                obj.put("status", 1);
                obj.put("errMsg", e.getMessage());
            } catch (JSONException e1) {
                e1.printStackTrace();
            }
        } finally {
            if (con != null) {
                con.disconnect();
src/main/java/com/hx/util/StringUtils.java
@@ -228,6 +228,16 @@
        return null == str || str.trim().length() == 0 || "undefined".equals(str);
    }
    /**判断空*/
    public static boolean isNull(String str) {
        return null == str || str.trim().length() == 0 || "undefined".equals(str);
    }
    /**判断非空*/
    public static boolean noNull(String str) {
        return null != str && str.trim().length() != 0 && !"undefined".equals(str);
    }
    /**
     * 判断字符内容中是否存在一个为空的字符�?
     * <p>
src/main/java/com/hx/util/gaode/AddressCode.java
New file
@@ -0,0 +1,42 @@
package com.hx.util.gaode;
/**
 * 获取地址经纬度
 * 响应实体化
 */
public class AddressCode {
    /**经度*/
    private String lng;
    /**维度*/
    private String lat;
    /**城市编码*/
    private String cityCode;
    public AddressCode() {
    }
    public String getLng() {
        return lng;
    }
    public void setLng(String lng) {
        this.lng = lng;
    }
    public String getLat() {
        return lat;
    }
    public void setLat(String lat) {
        this.lat = lat;
    }
    public String getCityCode() {
        return cityCode;
    }
    public void setCityCode(String cityCode) {
        this.cityCode = cityCode;
    }
}
src/main/java/com/hx/util/gaode/GaoDeMapUtil.java
New file
@@ -0,0 +1,53 @@
package com.hx.util.gaode;
import com.hx.util.HttpUtil;
import com.hx.util.StringUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
 * 高德地图工具
 * @author mgchen
 *
 */
public class GaoDeMapUtil {
    /**获取经纬度*/
    public static String URL_CODE = "https://restapi.amap.com/v3/geocode/geo";
    /**
     * 获取地址的经纬度
     * @param address
     * @param key
     * @return
     */
    public static AddressCode addressCode(String address,String key) {
        AddressCode addressCode = null;
        //URL_CODE = URL_CODE+"?key="+key+"&address="+URLEncoder.encode(address,"UTF-8");//地址编译
        URL_CODE = URL_CODE+"?key="+key+"&address="+address;
        JSONObject data = HttpUtil.HttpURLUtil(URL_CODE,null);
        if(data.optInt("status",0) == 1){
            JSONArray geocodes = data.getJSONArray("geocodes");
            if(geocodes.size()==1){
                JSONObject locationObj = geocodes.getJSONObject(0);
                String location = locationObj.optString("location");
                if(StringUtils.noNull(location)){
                    String[] locations = location.split(",");
                    if(locations.length != 2){
                        return null;
                    }
                    addressCode = new AddressCode();
                    addressCode.setLng(locations[0]);
                    addressCode.setLat(locations[1]);
                    addressCode.setCityCode(locationObj.optString("citycode"));
                }
            }
        }
        return addressCode;
    }
}