From 4021b60ead8e2452040925c833aef6f687a7ccd5 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Tue, 29 Jul 2025 12:08:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E8=B4=AD=E5=85=A5=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/pda/config/ModuleFunction.java | 44 +++ .../modules/pda/config/SecurityConfig.java | 47 ++++ .../modules/pda/config/XuJieConfig.java | 47 ++++ .../gaotao/modules/pda/dao/TransNoDao.java | 57 ++++ .../modules/pda/dao/impl/TransNoDaoImpl.java | 87 ++++++ .../com/gaotao/modules/pda/utils/DBUtil.java | 102 +++++++ .../gaotao/modules/pda/utils/DateUtils.java | 135 ++++++++++ .../modules/pda/utils/DecimalUtils.java | 156 +++++++++++ .../modules/pda/utils/HttpClientUtil.java | 250 ++++++++++++++++++ .../com/gaotao/modules/pda/utils/MD5.java | 57 ++++ .../modules/pda/utils/ResponseData.java | 69 +++++ 11 files changed, 1051 insertions(+) create mode 100644 src/main/java/com/gaotao/modules/pda/config/ModuleFunction.java create mode 100644 src/main/java/com/gaotao/modules/pda/config/SecurityConfig.java create mode 100644 src/main/java/com/gaotao/modules/pda/config/XuJieConfig.java create mode 100644 src/main/java/com/gaotao/modules/pda/dao/TransNoDao.java create mode 100644 src/main/java/com/gaotao/modules/pda/dao/impl/TransNoDaoImpl.java create mode 100644 src/main/java/com/gaotao/modules/pda/utils/DBUtil.java create mode 100644 src/main/java/com/gaotao/modules/pda/utils/DateUtils.java create mode 100644 src/main/java/com/gaotao/modules/pda/utils/DecimalUtils.java create mode 100644 src/main/java/com/gaotao/modules/pda/utils/HttpClientUtil.java create mode 100644 src/main/java/com/gaotao/modules/pda/utils/MD5.java create mode 100644 src/main/java/com/gaotao/modules/pda/utils/ResponseData.java diff --git a/src/main/java/com/gaotao/modules/pda/config/ModuleFunction.java b/src/main/java/com/gaotao/modules/pda/config/ModuleFunction.java new file mode 100644 index 0000000..d6e397f --- /dev/null +++ b/src/main/java/com/gaotao/modules/pda/config/ModuleFunction.java @@ -0,0 +1,44 @@ +package com.gaotao.modules.pda.config; + +/** + * + * @ClassName: ModuleFunction + * @Description: 关联配置文件数据 + * @author lirui + * @date 2018年3月29日 + * + */ +public class ModuleFunction { + private String name;//名称 + private String mark;//标记 + private String url;//路径 + + public ModuleFunction() { + // TODO Auto-generated constructor stub + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMark() { + return mark; + } + + public void setMark(String mark) { + this.mark = mark; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + +} diff --git a/src/main/java/com/gaotao/modules/pda/config/SecurityConfig.java b/src/main/java/com/gaotao/modules/pda/config/SecurityConfig.java new file mode 100644 index 0000000..90beae6 --- /dev/null +++ b/src/main/java/com/gaotao/modules/pda/config/SecurityConfig.java @@ -0,0 +1,47 @@ +package com.gaotao.modules.pda.config;//package com.gaotao.modules.pda.config; +// +// +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.context.annotation.Configuration; +// +// +//@Configuration +//@EnableWebSecurity +//@EnableGlobalMethodSecurity(prePostEnabled = true) +//public class SecurityConfig extends WebSecurityConfigurerAdapter { +// +// @Autowired +// CustomUserDetailsService userDetailsService; +// +// @Autowired +// CustomAuthSuccessHandler authSuccessHandler; +// +// @Autowired +// CustomPasswordEncoder passwordEncoder; +// @Autowired +// private CustomAuthFailureHandler authFailureHandler; +// +// @Override +// protected void configure(HttpSecurity http) throws Exception { +// http.headers().frameOptions().disable();//解决Spring Boot不允许加载iframe问题解决 +// http.csrf().disable() +// .authorizeRequests() +// .antMatchers("/js/**", "/img/**", "/css/**","/bootstrap/**", "/order/json", "/jeasyui/**").permitAll() +// .anyRequest().authenticated() +// .and() +// .formLogin() +// .successHandler(authSuccessHandler) +// //.failureUrl("/login?error=true") +// .failureHandler(authFailureHandler) +// .loginPage("/login") +// .permitAll() +// .and() +// .logout() +// .permitAll(); +// } +// +// //private PasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); +// public void configure(AuthenticationManagerBuilder auth) throws Exception { +// auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder); +// } +//} diff --git a/src/main/java/com/gaotao/modules/pda/config/XuJieConfig.java b/src/main/java/com/gaotao/modules/pda/config/XuJieConfig.java new file mode 100644 index 0000000..29ef0d4 --- /dev/null +++ b/src/main/java/com/gaotao/modules/pda/config/XuJieConfig.java @@ -0,0 +1,47 @@ +package com.gaotao.modules.pda.config; + + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +import java.util.List; + +@ConfigurationProperties(prefix = "xujie") +@Configuration +public class XuJieConfig { + private String webservice;// webservice的路径 + private String excelpath;// excel服务器地址路径 + private List modulefunction; + + + public XuJieConfig() { + super(); + // TODO Auto-generated constructor stub + } + + public String getWebservice() { + return webservice; + } + + public void setWebservice(String webservice) { + this.webservice = webservice; + } + + public String getExcelpath() { + return excelpath; + } + + public void setExcelpath(String excelpath) { + this.excelpath = excelpath; + } + + public List getModulefunction() { + return modulefunction; + } + + public void setModulefunction(List modulefunction) { + this.modulefunction = modulefunction; + } + + +} diff --git a/src/main/java/com/gaotao/modules/pda/dao/TransNoDao.java b/src/main/java/com/gaotao/modules/pda/dao/TransNoDao.java new file mode 100644 index 0000000..b7e87e7 --- /dev/null +++ b/src/main/java/com/gaotao/modules/pda/dao/TransNoDao.java @@ -0,0 +1,57 @@ +package com.gaotao.modules.pda.dao; + +import java.util.List; +import java.util.Map; + +/** + * +* @ClassName: TransNoDao +* @Description: 获取通用的交易号码 +* @author lirui +* @date 2018年4月8日 +* + */ +public interface TransNoDao { + + /** + * + * @Title: getTransNo + * @Description: 获取当前的交易号 + * @author lirui + * @date 2018年4月8日 + * @param @param site + * @param @param type + * @param @return 参数 + * @return String 返回类型 + * @throws + */ + String getTransNo(String site,String type); + + /** + * + * @Title: updateTransNo + * @Description: 更新当前的交易号 + * @author lirui + * @date 2018年4月8日 + * @param @param site + * @param @param type 参数 + * @return void 返回类型 + * @throws + */ + void updateTransNo(String site,String type); + + /** + * + * @Title: getRollTrees + * @Description: 测试存储过程 + * @author lirui + * @date 2018年11月27日 + * @param @param site + * @param @param rollNo + * @param @return 参数 + * @return List> 返回类型 + * @throws + */ + List> getRollTrees(String site, String rollNo); + +} diff --git a/src/main/java/com/gaotao/modules/pda/dao/impl/TransNoDaoImpl.java b/src/main/java/com/gaotao/modules/pda/dao/impl/TransNoDaoImpl.java new file mode 100644 index 0000000..2e94b0b --- /dev/null +++ b/src/main/java/com/gaotao/modules/pda/dao/impl/TransNoDaoImpl.java @@ -0,0 +1,87 @@ +package com.gaotao.modules.pda.dao.impl; + + +import com.gaotao.modules.pda.dao.TransNoDao; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.CallableStatementCallback; +import org.springframework.jdbc.core.CallableStatementCreator; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +import java.sql.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** +* +* @ClassName: TransNoDaoImpl +* @Description: 通用交易号方法实现 +* @author lirui +* @date 2018年4月8日 +* +*/ +@Repository +public class TransNoDaoImpl implements TransNoDao { + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Override + public String getTransNo(String site, String type) { + String sql = "SELECT dbo.Get_TransNo(?,?)"; + List params = new ArrayList<>(); + params.add(site); + params.add(type); + return jdbcTemplate.queryForObject(sql, String.class, params.toArray()); + } + + @Override + public void updateTransNo(String site, String type) { + String sql = "exec dbo.UpdateTransNo ?,?"; + List params = new ArrayList<>(); + params.add(site); + params.add(type); + jdbcTemplate.update(sql,params.toArray()); + } + + @Override + public List> getRollTrees(String site, String rollNo) { + return jdbcTemplate.execute(new CallableStatementCreator() { + + @Override + public CallableStatement createCallableStatement(Connection con) throws SQLException { + String sql = "EXEC getRollTrees ?,?"; + CallableStatement cs = con.prepareCall(sql); + cs.setString(1, site); + cs.setString(2, rollNo); + return cs; + } + }, new CallableStatementCallback>>() { + @Override + public List> doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException { + List> list = new ArrayList<>(); + ResultSet rs = cs.executeQuery(); + ResultSetMetaData rmd = rs.getMetaData(); + int columnCount = rmd.getColumnCount(); + System.out.println("columnCount: " + columnCount); + while (rs.next()) { + Map rowMap = new HashMap<>(); + rowMap.put("site", rs.getString("site")); + rowMap.put("rollNo", rs.getString("rollNo")); + rowMap.put("oriRollNo", rs.getString("oriRollNo")); + rowMap.put("rollLevel", rs.getString("rollLevel")); + list.add(rowMap); + } + rs.close(); + return list; + } + }); + } + + + + +} diff --git a/src/main/java/com/gaotao/modules/pda/utils/DBUtil.java b/src/main/java/com/gaotao/modules/pda/utils/DBUtil.java new file mode 100644 index 0000000..b3aa1e9 --- /dev/null +++ b/src/main/java/com/gaotao/modules/pda/utils/DBUtil.java @@ -0,0 +1,102 @@ +package com.gaotao.modules.pda.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.stereotype.Component; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@Component +public class DBUtil { + @Autowired + public JdbcTemplate jdbcTemplate; + + @Autowired + public NamedParameterJdbcTemplate parameterJdbcTemplate; + + private Logger logger = LoggerFactory.getLogger(getClass()); + private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + public boolean exist(String sql, Object... args) { + long start = System.currentTimeMillis(); + try { + List> rows = jdbcTemplate.queryForList(sql, args); + return rows.size() > 0; + } finally { + log("SQL(" + (System.currentTimeMillis() - start) + "ms):" + sql, args); + } + } + + public int execute(String sql, Object... args) { + long start = System.currentTimeMillis(); + try { + return jdbcTemplate.update(sql, args); + } finally { + log("SQL(" + (System.currentTimeMillis() - start) + "ms):" + sql, args); + } + } + + public Map findOne(String sql, Object... args) { + long start = System.currentTimeMillis(); + try { + List> rows = jdbcTemplate.queryForList(sql, args); + if (rows.size() > 0) { + return rows.get(0); + } + return null; + } catch (Exception ex) { + throw ex; + } finally { + log("SQL(" + (System.currentTimeMillis() - start) + "ms):" + sql, args); + } + } + + public List> findList(String sql, Object... args) { + long start = System.currentTimeMillis(); + try { + return jdbcTemplate.queryForList(sql, args); + } finally { + log("SQL(" + (System.currentTimeMillis() - start) + "ms):" + sql, args); + } + } + + public void log(String sql, Object... args) { + StringBuilder parameters = new StringBuilder(); + for (Object obj : args) { + parameters.append(obj.toString()).append(","); + } + logger.info(sql + " -- parameters=" + parameters.toString()); + } + + public Date formatDate(Object date) { + if (date == null) return null; + try { + return dateFormat.parse(date.toString()); + } catch (ParseException e) { + e.printStackTrace(); + return null; + } + } + + public Double getDouble(Object obj) { + if (obj == null) return null; + return Double.parseDouble(obj.toString()); + } + + public Boolean getBoolean(Object obj) { + if (obj == null) return null; + return obj.toString().equalsIgnoreCase("Y"); + } + + public String getString(Object obj) { + if (obj == null) return ""; + return obj.toString().toString(); + } +} \ No newline at end of file diff --git a/src/main/java/com/gaotao/modules/pda/utils/DateUtils.java b/src/main/java/com/gaotao/modules/pda/utils/DateUtils.java new file mode 100644 index 0000000..281253e --- /dev/null +++ b/src/main/java/com/gaotao/modules/pda/utils/DateUtils.java @@ -0,0 +1,135 @@ +package com.gaotao.modules.pda.utils; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +/** + * + * @ClassName: DateUtils + * @Description: 日期的工具类 + * @author LR + * @date 2017年6月12日 下午5:08:39 + * + */ +public class DateUtils { + + /** + * + * + * @author LR + * @Description: 获取当前时间的年月日时分秒 + * @UpdateUser LR + * @UpdateRemark [说明本次修改内容] + * + */ + public static String getStringNow() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sdf.format(new Date()); + } + + /** + * + * @Title: getStringDate + * @author LR + * @Description: 返回String类型的yyyy-MM-dd的日期 + * @param @param date + * @param @return 设定文件 + * @return String 返回类型 + * @throws + */ + public static String getStringDate(Date date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + return sdf.format(date); + } + + /** + * + * @Title: getStringDate + * @author LR + * @Description: 根据模版获取相应时间的格式 + * @param @param date + * @param @param parten + * @param @return 设定文件 + * @return String 返回类型 + * @throws + */ + public static String getStringDate(Date date, String parten) { + SimpleDateFormat sdf = new SimpleDateFormat(parten); + return sdf.format(date); + } + + /** + * + * @Title: getYesterday + * @author LR + * @Description: 获取昨日的String类型的yyyy-MM-dd的日期 + * @param @return 设定文件 + * @return String 返回类型 + * @throws + */ + public static String getStringYesterday() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.DAY_OF_MONTH, -1); + return sdf.format(cal.getTime()); + } + + /** + * + * @Title: getYesterday + * @author LR + * @Description: 获取明天的String类型的yyyy-MM-dd的日期 + * @param @return 设定文件 + * @return String 返回类型 + * @throws + */ + public static String getStringTomorrow() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.DAY_OF_MONTH, +1); + return sdf.format(cal.getTime()); + } + + /** + * + * + * @author LR + * @throws ParseException + * @Description: String转换date + * @UpdateUser LR + * @UpdateRemark [说明本次修改内容] + * + */ + public static Date getDate(String time) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + return sdf.parse(time); + + } + + /** + * + * @Title: getLastMonth + * @author LR + * @Description: 获取上一个月的YYYY-MM + * @param @param date + * @param @return 设定文件 + * @return String 返回类型 + * @throws + */ + public static String getLastMonth(Date date) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.add(Calendar.MONTH, -1); + Date lastDate = cal.getTime(); + return sdf.format(lastDate); + } + + public static Date getDateByParten(String date, String parten) + throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat(parten); + return sdf.parse(date); + } +} diff --git a/src/main/java/com/gaotao/modules/pda/utils/DecimalUtils.java b/src/main/java/com/gaotao/modules/pda/utils/DecimalUtils.java new file mode 100644 index 0000000..98f32fb --- /dev/null +++ b/src/main/java/com/gaotao/modules/pda/utils/DecimalUtils.java @@ -0,0 +1,156 @@ +package com.gaotao.modules.pda.utils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** +* @ClassName: DecimalUtils +* @Description: 进制专用工具类 +* @author LR +* @date 2019年7月5日 +* +*/ +public class DecimalUtils { + + /** + * @Title: getDecimalNums + * @Description: 获取当前数据进制转换成的(返回十进制对应的位数,从右往左方向) + * @author LR + * @date 2019年7月5日 + * @param @param nums + * @param @param i + * @param @return 参数 + * @return char [] 返回类型 + * @throws + */ + public static List convertDecimalToArbitrary(List resultInt, int nums, int decimal) { + //循环算出商 余数 + int quotient = nums / decimal; + int remainder = nums % decimal; + resultInt.add(remainder); + //判断是否递归调用 + if(quotient >= decimal){ + resultInt = convertDecimalToArbitrary(resultInt, quotient, decimal); + }else{ + resultInt.add(quotient); + } + return resultInt; + } + + /** + * + * @Title: getNextArr + * @Description: 获取下一个字符数组 + * @author LR + * @date 2019年7月5日 + * @param @param tempArr + * @param @param num + * @param @param index + * @param @return 参数 + * @return char[] 返回类型 + * @throws + */ + public static char[] getNextArr(char[] tempArr, int index, char[] strArr, Map charMap) { + //获取当前的字符 + char temp = tempArr[index]; + //获取字符对应的下表 + int tempNums = charMap.get(temp) + 1; + //判断是否需要向前进1 + if(tempNums == 34){ + //重置当前的位数 + tempArr[index] = '0'; + index -= 1; + //但是index必须大于零 + if(index == -1){ + System.err.println("超过上限!"); + return null; + } + //递归算法 + tempArr = getNextArr(tempArr, index, strArr, charMap); + }else{ + tempArr[index] = strArr[tempNums]; + } + return tempArr; + } + + /** + * + * @Title: convertArbitraryToDeciamal + * @Description: 任意进制转换成十进制数子 + * @author LR + * @date 2019年7月8日 + * @param @param tempArr + * @param @param strArr + * @param @param decimal + * @param @return 参数 + * @return List 返回类型 + * @throws + */ + public static int convertArbitraryToDeciamal(char[] tempArr, Map charMap, int decimal){ + List intNums = new ArrayList<>(); + //获取序列对应的字符串 + for(int i = 0; i resultInt = new ArrayList<>(); resultInt = + * convertDecimalToArbitrary(resultInt, 100000, 34); + * Collections.reverse(resultInt); System.out.println(resultInt.toString()); + */ + char[] strArr = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', + 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; + Map intMap = new HashMap<>(); + Map charMap = new HashMap<>(); + //把字符存入map中形成对应的关系 + for(int i = 0; i < strArr.length; i++){ + intMap.put(i, strArr[i]); + charMap.put(strArr[i], i); + } + //设置起始值 + char[] startArr = new char[]{'0', '0', '0', '0', '0'}; + char[] tempArr = new char[5]; + Map resultMap = new HashMap<>(); + //把第一个数值直接缓存进去 + resultMap.put(0, String.copyValueOf(startArr)); + //赋初始值 + tempArr = startArr; + int byteToMb = 1024 * 1024; + Runtime rt = Runtime.getRuntime(); + long vmTotal = rt.totalMemory() / byteToMb; + long vmFree = rt.freeMemory() / byteToMb; + long vmUse = vmTotal - vmFree; + System.out.println("JVM内存已用的空间为:" + vmUse + " MB"); + long start_mis = System.currentTimeMillis(); + for(int i = 1; i < 10000000; i++){ + tempArr = getNextArr(tempArr, 4, strArr, charMap); + resultMap.put(i, String.copyValueOf(tempArr)); + } + long end_mis = System.currentTimeMillis(); + long vmTotal1 = rt.totalMemory() / byteToMb; + long vmFree1 = rt.freeMemory() / byteToMb; + long vmUse1 = vmTotal1 - vmFree1; + System.out.println("JVM内存已用的空间为:" + vmUse1 + " MB"); + System.out.println(end_mis - start_mis); + System.out.println(resultMap.size()); + System.out.println(String.valueOf(tempArr)); + int resultNums = convertArbitraryToDeciamal(resultMap.get(98).toCharArray(), charMap, 34); + System.out.println(resultNums); + } + +} \ No newline at end of file diff --git a/src/main/java/com/gaotao/modules/pda/utils/HttpClientUtil.java b/src/main/java/com/gaotao/modules/pda/utils/HttpClientUtil.java new file mode 100644 index 0000000..c280e97 --- /dev/null +++ b/src/main/java/com/gaotao/modules/pda/utils/HttpClientUtil.java @@ -0,0 +1,250 @@ +package com.gaotao.modules.pda.utils;//package com.gaotao.modules.pda.utils; + +import com.alibaba.fastjson.JSON; +import com.gaotao.common.utils.R; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.http.*; +import org.apache.http.client.HttpClient; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * + * @ClassName: HttpClientUtil + * @Description: 处理http请求 + * @author lirui + * @date 2018年4月7日 + * + */ +@Slf4j +public class HttpClientUtil { + + /** + * + * @Title: doGet + * @Description: get请求 + * @author lirui + * @date 2018年4月28日 + * @param @param url + * @param @param paramsMap + * @param @return 参数 + * @return ResponseData 返回类型 + * @throws + */ + public static ResponseData doGet(String url,Map paramsMap){ + ResponseData responseData = new ResponseData(); + List params = new ArrayList(); + //设置参数 + for(Map.Entry entry : paramsMap.entrySet()){ + params.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); + } + try { + //转字符串参数 + String str = EntityUtils.toString(new UrlEncodedFormEntity(params,Consts.UTF_8)); + HttpClient httpClient = HttpClients.createDefault(); + HttpGet httpGet = new HttpGet(url+"?"+str); + //设置请求的配置数据 + RequestConfig config = RequestConfig.custom() + .setConnectTimeout(180000) + .setConnectionRequestTimeout(120000).build(); + httpGet.setConfig(config); + HttpResponse response = httpClient.execute(httpGet); + log.info("发送sap请求 ----------------"); + //获取请求的状态码 + int statusCode = response.getStatusLine().getStatusCode(); + if(statusCode==HttpStatus.SC_OK){ + responseData.setSuccess(true); + responseData.setCode(statusCode+""); + HttpEntity entity = response.getEntity(); + log.info("发送sap成功 ----------------"); + String result = StringEscapeUtils.unescapeHtml4(EntityUtils.toString(entity,Consts.UTF_8)); + responseData.setMsg(result); + }else{ + log.info("发送sap失败 ----------------"); + responseData.setCode(statusCode+""); + responseData.setMsg("错误码:"+statusCode); + } + } catch (ParseException e) { + + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return responseData; + } + + /** + * + * @Title: doPost + * @Description: TODO(这里用一句话描述这个方法的作用) + * @author lirui + * @date 2018年4月28日 + * @param @param url + * @param @param paramsMap + * @param @return 参数 + * @return ResponseData 返回类型 + * @throws + */ + public static R doPost(String url,Map paramsMap){ + + List params = new ArrayList(); + //设置参数 + for(Map.Entry entry : paramsMap.entrySet()){ + params.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); + } + try { + HttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + //设置请求的配置数据 + RequestConfig config = RequestConfig.custom() + .setConnectTimeout(180000) + .setConnectionRequestTimeout(120000).build(); + httpPost.setConfig(config); + HttpResponse response = httpClient.execute(httpPost); + //获取请求的状态码 + int statusCode = response.getStatusLine().getStatusCode(); + if(statusCode==HttpStatus.SC_OK){ + HttpEntity entity = response.getEntity(); + String result = StringEscapeUtils.unescapeHtml4(EntityUtils.toString(entity,Consts.UTF_8)); + return R.ok(result); + }else{ + return R.error(statusCode,"错误码:"+statusCode); + } + } catch (ParseException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return R.ok(); + } + + + /** + * + * @Title: doPost + * @Description: post请求数据不封装 + * @author lirui + * @date 2018年4月28日 + * @param @param url + * @param @param paramsMap + * @param @return 参数 + * @return ResponseData 返回类型 + * @throws + */ + public static ResponseData doPostSendEntity(String url, Map paramsMap){ + ResponseData responseData = new ResponseData(); + List params = new ArrayList(); + //设置参数 + for(Map.Entry entry : paramsMap.entrySet()){ + params.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString())); + } + try { + HttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(params, "UTF-8"); + httpPost.setEntity(formEntity); + formEntity.setContentType("application/x-www-form-urlencoded"); + //设置请求的配置数据 + RequestConfig config = RequestConfig.custom() + .setConnectTimeout(180000) + .setConnectionRequestTimeout(120000).build(); + httpPost.setConfig(config); + HttpResponse response = httpClient.execute(httpPost); + //获取请求的状态码 + int statusCode = response.getStatusLine().getStatusCode(); + if(statusCode == HttpStatus.SC_OK){ + HttpEntity entity = response.getEntity(); + String result = StringEscapeUtils.unescapeHtml4(EntityUtils.toString(entity,Consts.UTF_8)); + Map resultMap = JSON.parseObject(result); + statusCode = (int) resultMap.get("StatusCode"); + responseData.setCode(statusCode+""); + String msg = (String) resultMap.get("ResultMsg"); + //成功失败区分开来 + if(HttpStatus.SC_OK == statusCode) { + responseData.setSuccess(true); + }else { + responseData.setSuccess(false); + } + responseData.setMsg(msg); + }else{ + responseData.setCode(statusCode+""); + responseData.setMsg("错误码:"+statusCode); + } + } catch (Exception e) { + responseData.setMsg("异常"+e.getMessage()); + e.printStackTrace(); + } + return responseData; + } + + + /** + * + * @Title: doPostSendForm + * @Description: 请求form请求数据 + * @author LR + * @date 2019年11月22日 + * @param @param url + * @param @param paramsMap + * @param @return 参数 + * @return ResponseData 返回类型 + * @throws + */ + public static ResponseData doPostByRaw(String url, Object inData){ + ResponseData responseData = new ResponseData(); + try { + HttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + String jsonStr = JSON.toJSONString(inData); + StringEntity requestEntity = new StringEntity(jsonStr, "UTF-8"); + requestEntity.setContentEncoding("UTF-8"); + httpPost.setHeader("Content-type", "application/json"); + httpPost.setEntity(requestEntity); + //设置请求的配置数据 + RequestConfig config = RequestConfig.custom() + .setConnectTimeout(180000) + .setConnectionRequestTimeout(120000).build(); + httpPost.setConfig(config); + HttpResponse response = httpClient.execute(httpPost); + //获取请求的状态码 + int statusCode = response.getStatusLine().getStatusCode(); + if(statusCode== HttpStatus.SC_OK){ + responseData.setSuccess(true); + responseData.setCode(statusCode+""); + HttpEntity entity = response.getEntity(); + String result = StringEscapeUtils.unescapeHtml4(EntityUtils.toString(entity, Consts.UTF_8)); + Map resultMap = JSON.parseObject(result); + statusCode = (int) resultMap.get("StatusCode"); + responseData.setCode(statusCode+""); + String msg = (String) resultMap.get("ResultMsg"); + //成功失败区分开来 + if(HttpStatus.SC_OK == statusCode) { + responseData.setSuccess(true); + }else { + responseData.setSuccess(false); + } + responseData.setMsg(msg); + }else{ + responseData.setCode(statusCode+""); + responseData.setMsg("错误码:"+statusCode); + } + } catch (ParseException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return responseData; + } +} diff --git a/src/main/java/com/gaotao/modules/pda/utils/MD5.java b/src/main/java/com/gaotao/modules/pda/utils/MD5.java new file mode 100644 index 0000000..d1b2491 --- /dev/null +++ b/src/main/java/com/gaotao/modules/pda/utils/MD5.java @@ -0,0 +1,57 @@ +package com.gaotao.modules.pda.utils; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/* + * MD5 算法 +*/ +public class MD5 { + + // 全局数组 + private final static String[] strDigits = { "0", "1", "2", "3", "4", "5", + "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; + + public MD5() { + } + + // 返回形式为数字跟字符串 + private static String byteToArrayString(byte bByte) { + int iRet = bByte; + // System.out.println("iRet="+iRet); + if (iRet < 0) { + iRet += 256; + } + int iD1 = iRet / 16; + int iD2 = iRet % 16; + return strDigits[iD1] + strDigits[iD2]; + } + + + // 转换字节数组为16进制字串 + private static String byteToString(byte[] bByte) { + StringBuffer sBuffer = new StringBuffer(); + for (int i = 0; i < bByte.length; i++) { + sBuffer.append(byteToArrayString(bByte[i])); + } + return sBuffer.toString(); + } + + public static String GetMD5Code(String strObj) { + String resultString = null; + try { + resultString = new String(strObj); + MessageDigest md = MessageDigest.getInstance("MD5"); + // md.digest() 该函数返回值为存放哈希值结果的byte数组 + resultString = byteToString(md.digest(strObj.getBytes())); + } catch (NoSuchAlgorithmException ex) { + ex.printStackTrace(); + } + return resultString; + } + + public static void main(String[] args) { + String str = GetMD5Code("123456"); + System.out.println(str); + } +} \ No newline at end of file diff --git a/src/main/java/com/gaotao/modules/pda/utils/ResponseData.java b/src/main/java/com/gaotao/modules/pda/utils/ResponseData.java new file mode 100644 index 0000000..29e4030 --- /dev/null +++ b/src/main/java/com/gaotao/modules/pda/utils/ResponseData.java @@ -0,0 +1,69 @@ +package com.gaotao.modules.pda.utils; + +import java.io.Serializable; + +/** + * + * @ClassName: ResponseData + * @Description: 信息返回类 + * @author lirui + * @date 2018年3月29日 + * + */ +public class ResponseData implements Serializable { + private static final long serialVersionUID = 8108588679509838467L; + + private boolean success = false; + + private String msg = ""; + + private Object obj = null;// 存数据 + + private String code = "400";// 200正常401失效500弹窗 + + public ResponseData() { + // TODO Auto-generated constructor stub + } + + public ResponseData(String msg) { + super(); + this.msg = msg; + } + + public ResponseData(Object obj) { + super(); + this.obj = obj; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public String getMsg() { + return msg; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public Object getObj() { + return obj; + } + + public void setObj(Object obj) { + this.obj = obj; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } +}