diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/AliBusinessCircleOrderController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/AliBusinessCircleOrderController.java index fcf1396ee..cf9b22e36 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/AliBusinessCircleOrderController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/AliBusinessCircleOrderController.java @@ -25,6 +25,8 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; @RestController @RequestMapping("aliCircle") @@ -53,6 +55,27 @@ public class AliBusinessCircleOrderController extends BaseController { return new ResultData(page); } + @ApiOperation("统计接口") + @GetMapping("statistics") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), + }) + @SystemControllerLog(description = "-统计") + public ResultData statistics(@ModelAttribute AliBusinessCircleOrder circleOrder) { + logger.debug("[" + getIpAddr() + "] AliBusinessCircleOrderController::statistics"); + if (null == circleOrder) { + circleOrder = new AliBusinessCircleOrder(); + } + circleOrder.updateTenantInfo(getTenantInfo()); + Integer sumPayAmount = aliBusinessCircleOrderService.sumCirclePayment(circleOrder); + Integer sumRefundAmount = aliBusinessCircleOrderService.sumCircleRefundAmount(circleOrder); + Map resultMap = new HashMap(); + resultMap.put("sumPayAmount",sumPayAmount); + resultMap.put("sumRefundAmount",sumRefundAmount); + return new ResultData(resultMap); + } + @ApiOperation("详情接口") @GetMapping("detail") @ApiImplicitParams({ diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxBusinessCircleOrderController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxBusinessCircleOrderController.java index f422276ed..6e2f38578 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxBusinessCircleOrderController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxBusinessCircleOrderController.java @@ -21,6 +21,8 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; @RestController @RequestMapping("wxCircle") @@ -49,6 +51,27 @@ public class WxBusinessCircleOrderController extends BaseController { return new ResultData(page); } + @ApiOperation("统计接口") + @GetMapping("statistics") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), + }) + @SystemControllerLog(description = "-统计") + public ResultData statistics(@ModelAttribute WxBusinessCircleOrder circleOrder) { + logger.debug("[" + getIpAddr() + "] AliBusinessCircleOrderController::statistics"); + if (null == circleOrder) { + circleOrder = new WxBusinessCircleOrder(); + } + circleOrder.updateTenantInfo(getTenantInfo()); + Integer sumPayAmount = wxBusinessCircleOrderService.sumCirclePayment(circleOrder); + Integer sumRefundAmount = wxBusinessCircleOrderService.sumCircleRefundAmount(circleOrder); + Map resultMap = new HashMap(); + resultMap.put("sumPayAmount",sumPayAmount); + resultMap.put("sumRefundAmount",sumRefundAmount); + return new ResultData(resultMap); + } + @ApiOperation("详情接口") @GetMapping("detail") @ApiImplicitParams({ diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxThirdPartyOrdersController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxThirdPartyOrdersController.java index 30a96009d..d13a17908 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxThirdPartyOrdersController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxThirdPartyOrdersController.java @@ -5,7 +5,6 @@ import com.iformall.annotation.SystemControllerLog; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.controller.base.BaseController; -import com.iformall.domain.po.AliBusinessCircleOrder; import com.iformall.domain.po.WxThirdPartyOrders; import com.iformall.domain.po.base.BaseEntity; import com.iformall.enums.EnumThirdOrderType; @@ -26,6 +25,8 @@ import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; @RestController @RequestMapping("thirdCircle") @@ -54,6 +55,27 @@ public class WxThirdPartyOrdersController extends BaseController { return new ResultData(page); } + @ApiOperation("统计接口") + @GetMapping("statistics") + @ApiImplicitParams({ + @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), + @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), + }) + @SystemControllerLog(description = "-统计") + public ResultData statistics(@ModelAttribute WxThirdPartyOrders circleOrder) { + logger.debug("[" + getIpAddr() + "] AliBusinessCircleOrderController::statistics"); + if (null == circleOrder) { + circleOrder = new WxThirdPartyOrders(); + } + circleOrder.updateTenantInfo(getTenantInfo()); + Integer sumPayAmount = wxThirdPartyOrdersOrderService.sumCirclePayment(circleOrder); + Integer sumRefundAmount = wxThirdPartyOrdersOrderService.sumCircleRefundAmount(circleOrder); + Map resultMap = new HashMap(); + resultMap.put("sumPayAmount",sumPayAmount); + resultMap.put("sumRefundAmount",sumRefundAmount); + return new ResultData(resultMap); + } + @ApiOperation("详情接口") @GetMapping("detail") @ApiImplicitParams({ diff --git a/mallinkBApi/src/main/java/com/iformall/controller/WxCouponOrderController.java b/mallinkBApi/src/main/java/com/iformall/controller/WxCouponOrderController.java index 658f7df1c..8f0f7c696 100644 --- a/mallinkBApi/src/main/java/com/iformall/controller/WxCouponOrderController.java +++ b/mallinkBApi/src/main/java/com/iformall/controller/WxCouponOrderController.java @@ -13,6 +13,8 @@ import com.iformall.domain.vo.WxCouponOrderCVo; import com.iformall.enums.*; import com.iformall.exception.MallinkException; import com.iformall.service.*; +import com.iformall.utils.DateUtils; + import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -153,9 +155,26 @@ public class WxCouponOrderController extends BaseController { @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "string", paramType = "query", required = true) }) public ResultData detail(String couponOrderId) { - if (couponOrderId == null) { + + logger.info("couponOrderController.detail:" + couponOrderId); + + if (StringUtils.isBlank(couponOrderId)) { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); } + + String _decodeCouponOrderId = WxCouponOrderCVo.getDecodeExpiredCouponOrderId(couponOrderId); + if (_decodeCouponOrderId.contains(WxCouponOrderCVo.arg)) { + String[] decodeids = _decodeCouponOrderId.split(WxCouponOrderCVo.arg); + couponOrderId = decodeids[0]; + String expiredtimeStr = decodeids[1]; + logger.info("couponOrderController.detail。decode:[coid]" + couponOrderId+",[time]"+expiredtimeStr); + Date expiredtime = DateUtils.string2Date(expiredtimeStr).getTime(); + if (expiredtime.before(new Date())) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"码已失效,请更新二维码后重试"); + } + } + + Long bUserId = getLoginBUser().getId(); WxMerchantBUser wxMerchantBUser = wxMerchantBUserService.getById(getLoginBUser().getId()); if (wxMerchantBUser == null) { @@ -270,6 +289,18 @@ public class WxCouponOrderController extends BaseController { logger.error("couponOrderId不能为空: " + paramMap.toString()); return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); } + + String _decodeCouponOrderId = WxCouponOrderCVo.getDecodeExpiredCouponOrderId(couponOrderIdStr); + if (_decodeCouponOrderId.contains(WxCouponOrderCVo.arg)) { + String[] decodeids = _decodeCouponOrderId.split(WxCouponOrderCVo.arg); + couponOrderIdStr = decodeids[0]; + String expiredtimeStr = decodeids[1]; + Date expiredtime = DateUtils.string2Date(expiredtimeStr).getTime(); + if (expiredtime.before(new Date())) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"码已失效,请更新二维码后重试"); + } + } + Long couponOrderId = 0L; try { couponOrderId = Long.valueOf(couponOrderIdStr); diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponOrderController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponOrderController.java index 2896546b2..3e9b4c13e 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponOrderController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponOrderController.java @@ -196,6 +196,22 @@ public class WxCouponOrderController extends BaseController { return new ResultData(wxCouponOrderCVo); } + + @ApiOperation(value = "获取动态id") + @GetMapping("dynamicId") + @ApiImplicitParams({ + @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "string", paramType = "query", required = true) + }) + public ResultData dynamicId(String couponOrderId) { + + if (StringUtils.isBlank(couponOrderId) || couponOrderId.equalsIgnoreCase(Constant.UNDEFINED)) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); + } + Map retmap = new HashMap(); + retmap.put("dynamicId", WxCouponOrderCVo.calcuteExpiredCouponOrderId(couponOrderId)); + retmap.put("expiredSeconds", WxCouponOrderCVo.expiredSeconds); + return new ResultData(retmap); + } @ApiOperation(value = "卡券富文本接口") @GetMapping("html") diff --git a/mallinkPublicApi/src/main/java/com/iformall/utils/AppTest.java b/mallinkPublicApi/src/main/java/com/iformall/utils/AppTest.java index b07d83efc..7a24b3bb4 100644 --- a/mallinkPublicApi/src/main/java/com/iformall/utils/AppTest.java +++ b/mallinkPublicApi/src/main/java/com/iformall/utils/AppTest.java @@ -107,7 +107,7 @@ public class AppTest { /** * 创建交易信息 接口 */ - String s = HttpUtil.doPost("https://openapi.malls.iformall.com/api/thirdCircle/order", headMap, JSON.toJSONString(paramMap)); +// String s = HttpUtil.doPost("https://openapi.malls.iformall.com/api/thirdCircle/order", headMap, JSON.toJSONString(paramMap)); // String s = HttpUtil.doPost("http://localhost:7070/public/api/thirdCircle/order", headMap, JSON.toJSONString(paramMap)); @@ -122,7 +122,7 @@ public class AppTest { // String s = HttpUtil.doPost("https://openapitest.malls.iformall.com/api/thirdCircle/pointDeduction", headMap, JSON.toJSONString(paramMap)); - System.out.println(s); +// System.out.println(s); } diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/SysMonitorSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/SysMonitorSchedule.java index 776436157..df571f537 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/SysMonitorSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/SysMonitorSchedule.java @@ -32,55 +32,53 @@ public class SysMonitorSchedule { @Autowired private SysMonitorMapper sysMonitorMapper; - @Async - @Scheduled(cron = "0 */5 * * * *?") // 每隔5分钟检查一下各个网址 - public void checkUrls() { - if(isFmMonitor) { - SysMonitor q = new SysMonitor(); - q.setEnable(EnumSysMonitorStatus.ENABLE.getCode()); - List sysMonitors = sysMonitorMapper.findList(q); - - for (SysMonitor sysMonitor : sysMonitors) { - checkSysMonitor(sysMonitor); - } - } - } - - private void checkSysMonitor(SysMonitor sysMonitor) { - boolean isNormal = true; - for(int i=0;i<3;i++) { - try { - String result = HttpUtil.doGet(sysMonitor.getUrl()); - if (StringUtils.isBlank(result)) { - isNormal = false; - } else { - if (result.length() < 60) { - logger.info(result); - } else { - logger.info(result.substring(0, 50)); - } - } - } catch (RuntimeException e) { - logger.error(e.getMessage()); - isNormal = false; - } - if(isNormal) { - break; - } - } - - if(!isNormal) { - String[] receivers = fmMonitorEmails.split(","); - - String content = sysMonitor.getErrMsg(); - content = content.replace("{name}", sysMonitor.getName()); - content = content.replace("{url}", sysMonitor.getUrl()); - - //发送邮件 - logger.error(sysMonitor.getName() + "访问异常"); - mailService.sendSimpleMail(receivers, sysMonitor.getName() + "访问异常", content); - } - } - +// @Scheduled(cron = "0 */5 * * * *?") // 每隔5分钟检查一下各个网址 +// public void checkUrls() { +// if(isFmMonitor) { +// SysMonitor q = new SysMonitor(); +// q.setEnable(EnumSysMonitorStatus.ENABLE.getCode()); +// List sysMonitors = sysMonitorMapper.findList(q); +// +// for (SysMonitor sysMonitor : sysMonitors) { +// checkSysMonitor(sysMonitor); +// } +// } +// } +// +// private void checkSysMonitor(SysMonitor sysMonitor) { +// boolean isNormal = true; +// for(int i=0;i<3;i++) { +// try { +// String result = HttpUtil.doGet(sysMonitor.getUrl()); +// if (StringUtils.isBlank(result)) { +// isNormal = false; +// } else { +// if (result.length() < 60) { +// logger.info(result); +// } else { +// logger.info(result.substring(0, 50)); +// } +// } +// } catch (RuntimeException e) { +// logger.error(e.getMessage()); +// isNormal = false; +// } +// if(isNormal) { +// break; +// } +// } +// +// if(!isNormal) { +// String[] receivers = fmMonitorEmails.split(","); +// +// String content = sysMonitor.getErrMsg(); +// content = content.replace("{name}", sysMonitor.getName()); +// content = content.replace("{url}", sysMonitor.getUrl()); +// +// //发送邮件 +// logger.error(sysMonitor.getName() + "访问异常"); +// mailService.sendSimpleMail(receivers, sysMonitor.getName() + "访问异常", content); +// } +// } } \ No newline at end of file diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponOrderCVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponOrderCVo.java index 0a1a3935e..d6dc7831f 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponOrderCVo.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/WxCouponOrderCVo.java @@ -2,8 +2,13 @@ package com.iformall.domain.vo; import com.baomidou.mybatisplus.annotation.TableField; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.iformall.common.ErrorCode; +import com.iformall.common.ResultData; import com.iformall.common.SortColumn; import com.iformall.domain.po.WxCouponOrder; +import com.iformall.utils.Base64Util; +import com.iformall.utils.DateUtils; + import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -12,6 +17,8 @@ import java.math.BigDecimal; import java.util.Date; import java.util.List; +import org.apache.commons.lang3.StringUtils; + @JsonIgnoreProperties(value = {"handler"}) @Data @ToString(callSuper = true) @@ -154,4 +161,22 @@ public class WxCouponOrderCVo extends WxCouponOrder { } return priceStr; } + + + public static final int expiredSeconds = 60; + public static final String arg = "&"; + public static String calcuteExpiredCouponOrderId(String couponOrderId) { + if (StringUtils.isBlank(couponOrderId)) { + return null; + } + StringBuffer sb = new StringBuffer().append(couponOrderId).append(arg).append(DateUtils.date2String(DateUtils.getSecondsTimeAfter(expiredSeconds, new Date()))); + return Base64Util.encode(sb.toString().getBytes()); + } + + public static String getDecodeExpiredCouponOrderId(String couponOrderId) { + if (StringUtils.isBlank(couponOrderId)) { + return null; + } + return new String(Base64Util.decode(couponOrderId)); + } } diff --git a/mallinkService/src/main/java/com/iformall/mapper/AliBusinessCircleOrderMapper.java b/mallinkService/src/main/java/com/iformall/mapper/AliBusinessCircleOrderMapper.java index e956a49c1..c28c1064a 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/AliBusinessCircleOrderMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/AliBusinessCircleOrderMapper.java @@ -45,4 +45,6 @@ public interface AliBusinessCircleOrderMapper extends CommonMapper list = wxThirdPartyOrdersMapper.findListVo(circleOrder); excelService.exportExcel(list, null, "第三方积分抵扣", WxThirdPartyOrdersVo.class, "第三方积分抵扣.xlsx", response, false); } + + @Override + public Integer sumCirclePayment(BusinessCircleBase circleOrder) { + Integer sumCirclePayment = wxThirdPartyOrdersMapper.sumCirclePayment(circleOrder); + return sumCirclePayment==null?0:sumCirclePayment; + } + + @Override + public Integer sumCircleRefundAmount(BusinessCircleBase circleOrder) { + Integer sumCircleRefundAmount = wxThirdPartyOrdersMapper.sumCircleRefundAmount(circleOrder); + return sumCircleRefundAmount==null?0:sumCircleRefundAmount; + } } diff --git a/mallinkService/src/main/java/com/iformall/service/park/impl/dahua/DaHuaUtil.java b/mallinkService/src/main/java/com/iformall/service/park/impl/dahua/DaHuaUtil.java index 138db8ac3..0c293ac64 100644 --- a/mallinkService/src/main/java/com/iformall/service/park/impl/dahua/DaHuaUtil.java +++ b/mallinkService/src/main/java/com/iformall/service/park/impl/dahua/DaHuaUtil.java @@ -42,7 +42,8 @@ public class DaHuaUtil { params.put("cipher", cipher); params.put("timestamp", System.currentTimeMillis()); try { - return HttpUtil.doPost(URL, JSONObject.toJSONString(params)); + //return HttpUtil.doPost(URL, JSONObject.toJSONString(params)); + return null; } catch (Exception e) { return null; } diff --git a/mallinkService/src/main/java/com/iformall/utils/DateUtils.java b/mallinkService/src/main/java/com/iformall/utils/DateUtils.java index 5736554e7..982acef03 100755 --- a/mallinkService/src/main/java/com/iformall/utils/DateUtils.java +++ b/mallinkService/src/main/java/com/iformall/utils/DateUtils.java @@ -382,7 +382,34 @@ public class DateUtils { Date date = new Date(myTime * 1000); return formatter.format(date); } + + /** + * 获得当前时间前几秒的时间 + * + * @param hour + * 前几小时 + * @return + */ + public static String getSecondsTimeBefore(int seconds, Date myDate) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + long myTime = (myDate.getTime() / 1000) - seconds; + Date date = new Date(myTime * 1000); + return formatter.format(date); + } + /** + * 获得当前时间后几秒的时间 + * + * @param hour + * 后几小时 + * @return + */ + public static Date getSecondsTimeAfter(int seconds, Date myDate) { + long myTime = (myDate.getTime() / 1000) + seconds; + Date testDate = new Date(myTime * 1000); + return testDate; + } + /** * 获得当前时间后几小时的时间 * @@ -395,7 +422,7 @@ public class DateUtils { Date testDate = new Date(myTime * 1000); return testDate; } - + /** * 获得当前时间后几天的时间 * diff --git a/mallinkService/src/main/java/com/iformall/utils/HttpUtil.java b/mallinkService/src/main/java/com/iformall/utils/HttpUtil.java index 6b5c32194..3f2ec75ad 100644 --- a/mallinkService/src/main/java/com/iformall/utils/HttpUtil.java +++ b/mallinkService/src/main/java/com/iformall/utils/HttpUtil.java @@ -23,6 +23,10 @@ import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.github.binarywang.wxpay.service.WxPayService; + +import cn.binarywang.wx.miniapp.api.WxMaService; + import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; @@ -31,9 +35,15 @@ import java.io.*; import java.net.URI; import java.net.URL; import java.nio.charset.Charset; +import java.security.KeyManagementException; import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; /** @@ -49,32 +59,32 @@ public class HttpUtil { private static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36"; - /** - * get请求 - * @return - */ - public static String doGet(String url) { - try { - CloseableHttpClient client = HttpClients.createDefault(); - //发送get请求 - HttpGet request = new HttpGet(url); - HttpResponse response = client.execute(request); - - /**请求发送成功,并得到响应**/ - if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { - /**读取服务器返回过来的json字符串数据**/ - String strResult = EntityUtils.toString(response.getEntity()); - - return strResult; - } - } - catch (IOException e) { - logger.error(e.getMessage()); - throw new RuntimeException(e); - } - - return null; - } +// /** +// * get请求 +// * @return +// */ +// public static String doGet(String url) { +// try { +// CloseableHttpClient client = HttpClients.createDefault(); +// //发送get请求 +// HttpGet request = new HttpGet(url); +// HttpResponse response = client.execute(request); +// +// /**请求发送成功,并得到响应**/ +// if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { +// /**读取服务器返回过来的json字符串数据**/ +// String strResult = EntityUtils.toString(response.getEntity()); +// +// return strResult; +// } +// } +// catch (IOException e) { +// logger.error(e.getMessage()); +// throw new RuntimeException(e); +// } +// +// return null; +// } /** * get请求 @@ -166,71 +176,71 @@ public class HttpUtil { return null; } - /** - * post请求(用于key-value格式的参数) - * @param url - * @param params - * @return - */ - public static String doPost(String url,Map headMap, Map params){ - - // 定义HttpClient - CloseableHttpClient client = HttpClients.createDefault(); - - BufferedReader in = null; - try { - - // 实例化HTTP方法 - HttpPost request = new HttpPost(); - request.setURI(new URI(url)); - if(headMap != null){ - Set set = headMap.keySet(); - for(String key: set){ - request.addHeader(key,headMap.get(key)); - } - } - - //设置参数 - List nvps = new ArrayList(); - for (Iterator iter = params.keySet().iterator(); iter.hasNext();) { - String name = (String) iter.next(); - String value = String.valueOf(params.get(name)); - nvps.add(new BasicNameValuePair(name, value)); - - //System.out.println(name +"-"+value); - } - request.setEntity(new UrlEncodedFormEntity(nvps,HTTP.UTF_8)); - - HttpResponse response = client.execute(request); - int code = response.getStatusLine().getStatusCode(); - if(code == 200){ //请求成功 - in = new BufferedReader(new InputStreamReader(response.getEntity() - .getContent(),"utf-8")); - StringBuilder sb = new StringBuilder(""); - String line = ""; - String NL = System.getProperty("line.separator"); - while ((line = in.readLine()) != null) { - sb.append(line + NL); - } - - in.close(); - - client.close(); - - return sb.toString(); - } - else{ // - logger.info("状态码:" + code); - client.close(); - } - } - catch(Exception e){ - logger.error(e.getMessage()); - return null; - } - - return null; - } +// /** +// * post请求(用于key-value格式的参数) +// * @param url +// * @param params +// * @return +// */ +// public static String doPost(String url,Map headMap, Map params){ +// +// // 定义HttpClient +// CloseableHttpClient client = HttpClients.createDefault(); +// +// BufferedReader in = null; +// try { +// +// // 实例化HTTP方法 +// HttpPost request = new HttpPost(); +// request.setURI(new URI(url)); +// if(headMap != null){ +// Set set = headMap.keySet(); +// for(String key: set){ +// request.addHeader(key,headMap.get(key)); +// } +// } +// +// //设置参数 +// List nvps = new ArrayList(); +// for (Iterator iter = params.keySet().iterator(); iter.hasNext();) { +// String name = (String) iter.next(); +// String value = String.valueOf(params.get(name)); +// nvps.add(new BasicNameValuePair(name, value)); +// +// //System.out.println(name +"-"+value); +// } +// request.setEntity(new UrlEncodedFormEntity(nvps,HTTP.UTF_8)); +// +// HttpResponse response = client.execute(request); +// int code = response.getStatusLine().getStatusCode(); +// if(code == 200){ //请求成功 +// in = new BufferedReader(new InputStreamReader(response.getEntity() +// .getContent(),"utf-8")); +// StringBuilder sb = new StringBuilder(""); +// String line = ""; +// String NL = System.getProperty("line.separator"); +// while ((line = in.readLine()) != null) { +// sb.append(line + NL); +// } +// +// in.close(); +// +// client.close(); +// +// return sb.toString(); +// } +// else{ // +// logger.info("状态码:" + code); +// client.close(); +// } +// } +// catch(Exception e){ +// logger.error(e.getMessage()); +// return null; +// } +// +// return null; +// } /** * post请求(用于key-value格式的参数,wiwide) @@ -366,111 +376,111 @@ public class HttpUtil { return null; } - /** - * post请求(用于请求json格式的参数) - * @param url - * @param params - * @return - */ - public static String doPost(String url, String params) throws Exception { - - CloseableHttpClient httpclient = HttpClients.createDefault(); - HttpPost httpPost = new HttpPost(url);// 创建httpPost - httpPost.setHeader("Accept", "application/json"); - httpPost.setHeader("Content-Type", "application/json"); - String charSet = "UTF-8"; - StringEntity entity = new StringEntity(params, charSet); - httpPost.setEntity(entity); - CloseableHttpResponse response = null; - - try { - response = httpclient.execute(httpPost); - StatusLine status = response.getStatusLine(); - int state = status.getStatusCode(); - if (state == HttpStatus.SC_OK) { - HttpEntity responseEntity = response.getEntity(); - String jsonString = EntityUtils.toString(responseEntity); - return jsonString; - } - else{ - logger.info("请求返回:"+state+"("+url+")"); - } - } - finally { - if (response != null) { - try { - response.close(); - } catch (IOException e) { - logger.error(e.getMessage()); - } - } - try { - httpclient.close(); - } catch (IOException e) { - logger.error(e.getMessage()); - } - } - return null; - } - - /** - * post请求(用于请求json格式的参数) - * @param url - * @param params - * @return - */ - public static String doPost(String url, Map headMap, String params){ - - CloseableHttpClient httpclient = HttpClients.createDefault(); - HttpPost httpPost = new HttpPost(url);// 创建httpPost - httpPost.setHeader("Accept", "application/json"); - httpPost.setHeader("Content-Type", "application/json"); - - if(headMap != null){ - Set set = headMap.keySet(); - for(String key: set){ - httpPost.addHeader(key,headMap.get(key)); - } - } - - String charSet = "UTF-8"; - StringEntity entity = new StringEntity(params, charSet); - httpPost.setEntity(entity); - CloseableHttpResponse response = null; - - try { - response = httpclient.execute(httpPost); - StatusLine status = response.getStatusLine(); - int state = status.getStatusCode(); - if (state == HttpStatus.SC_OK) { - HttpEntity responseEntity = response.getEntity(); - String jsonString = EntityUtils.toString(responseEntity); - return jsonString; - } - else{ - logger.info("请求返回:"+state+"("+url+")"); - } - } - catch(Exception e){ - logger.error(e.getMessage()); - return null; - } - finally { - if (response != null) { - try { - response.close(); - } catch (IOException e) { - logger.error(e.getMessage()); - } - } - try { - httpclient.close(); - } catch (IOException e) { - logger.error(e.getMessage()); - } - } - return null; - } +// /** +// * post请求(用于请求json格式的参数) +// * @param url +// * @param params +// * @return +// */ +// public static String doPost(String url, String params) throws Exception { +// +// CloseableHttpClient httpclient = HttpClients.createDefault(); +// HttpPost httpPost = new HttpPost(url);// 创建httpPost +// httpPost.setHeader("Accept", "application/json"); +// httpPost.setHeader("Content-Type", "application/json"); +// String charSet = "UTF-8"; +// StringEntity entity = new StringEntity(params, charSet); +// httpPost.setEntity(entity); +// CloseableHttpResponse response = null; +// +// try { +// response = httpclient.execute(httpPost); +// StatusLine status = response.getStatusLine(); +// int state = status.getStatusCode(); +// if (state == HttpStatus.SC_OK) { +// HttpEntity responseEntity = response.getEntity(); +// String jsonString = EntityUtils.toString(responseEntity); +// return jsonString; +// } +// else{ +// logger.info("请求返回:"+state+"("+url+")"); +// } +// } +// finally { +// if (response != null) { +// try { +// response.close(); +// } catch (IOException e) { +// logger.error(e.getMessage()); +// } +// } +// try { +// httpclient.close(); +// } catch (IOException e) { +// logger.error(e.getMessage()); +// } +// } +// return null; +// } + +// /** +// * post请求(用于请求json格式的参数) +// * @param url +// * @param params +// * @return +// */ +// public static String doPost(String url, Map headMap, String params){ +// +// CloseableHttpClient httpclient = HttpClients.createDefault(); +// HttpPost httpPost = new HttpPost(url);// 创建httpPost +// httpPost.setHeader("Accept", "application/json"); +// httpPost.setHeader("Content-Type", "application/json"); +// +// if(headMap != null){ +// Set set = headMap.keySet(); +// for(String key: set){ +// httpPost.addHeader(key,headMap.get(key)); +// } +// } +// +// String charSet = "UTF-8"; +// StringEntity entity = new StringEntity(params, charSet); +// httpPost.setEntity(entity); +// CloseableHttpResponse response = null; +// +// try { +// response = httpclient.execute(httpPost); +// StatusLine status = response.getStatusLine(); +// int state = status.getStatusCode(); +// if (state == HttpStatus.SC_OK) { +// HttpEntity responseEntity = response.getEntity(); +// String jsonString = EntityUtils.toString(responseEntity); +// return jsonString; +// } +// else{ +// logger.info("请求返回:"+state+"("+url+")"); +// } +// } +// catch(Exception e){ +// logger.error(e.getMessage()); +// return null; +// } +// finally { +// if (response != null) { +// try { +// response.close(); +// } catch (IOException e) { +// logger.error(e.getMessage()); +// } +// } +// try { +// httpclient.close(); +// } catch (IOException e) { +// logger.error(e.getMessage()); +// } +// } +// return null; +// } public static String payPost(String url, String params) { @@ -489,9 +499,11 @@ public class HttpUtil { } } + private static OkHttpClient OkHttpClient = new OkHttpClient(); + private static String exec(okhttp3.Request request) { try { - okhttp3.Response response = new OkHttpClient().newCall(request).execute(); + okhttp3.Response response = OkHttpClient.newCall(request).execute(); if (!response.isSuccessful()) throw new RuntimeException("Unexpected code " + response); return response.body().string(); @@ -501,20 +513,36 @@ public class HttpUtil { } } + private static Map sslContextMap = new ConcurrentHashMap(); + private static SSLContext getSSLContext(String certPath, String certPass) throws KeyStoreException, NoSuchAlgorithmException, + CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException, KeyManagementException { + String key = certPath+certPass; + SSLContext sslContext = sslContextMap.get(key); + if ( null == sslContext ) { + synchronized("sslContextLock"+key) { + sslContext = sslContextMap.get(key); + if (null == sslContext) { + KeyStore clientStore = KeyStore.getInstance("PKCS12"); + clientStore.load(new FileInputStream(certPath), certPass.toCharArray()); + KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); + kmf.init(clientStore, certPass.toCharArray()); + KeyManager[] kms = kmf.getKeyManagers(); + sslContext = SSLContext.getInstance("TLS"); + sslContext.init(kms, null, new SecureRandom()); + sslContextMap.put(key, sslContext); + } + } + } + return sslContext; + } + public static String payPostSSL(String url, String data, String certPath, String certPass) { HttpsURLConnection conn = null; OutputStream out = null; InputStream inputStream = null; BufferedReader reader = null; try { - KeyStore clientStore = KeyStore.getInstance("PKCS12"); - clientStore.load(new FileInputStream(certPath), certPass.toCharArray()); - KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); - kmf.init(clientStore, certPass.toCharArray()); - KeyManager[] kms = kmf.getKeyManagers(); - SSLContext sslContext = SSLContext.getInstance("TLS"); - - sslContext.init(kms, null, new SecureRandom()); + SSLContext sslContext = getSSLContext(certPath, certPass); HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); URL _url = new URL(url); conn = (HttpsURLConnection) _url.openConnection(); @@ -554,61 +582,61 @@ public class HttpUtil { } } - private static String ClientCustomSSL(String url, String p12file, String mch_id, String xmlStr) throws Exception{ - KeyStore keyStore = KeyStore.getInstance("PKCS12"); - FileInputStream instream = new FileInputStream(new File(p12file)); - try { - keyStore.load(instream, mch_id.toCharArray()); - } finally { - instream.close(); - } - - // Trust own CA and all self-signed certs - SSLContext sslcontext = SSLContexts.custom() - .loadKeyMaterial(keyStore, mch_id.toCharArray()) - .build(); - // Allow TLSv1 protocol only - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( - sslcontext, - new String[] { "TLSv1" }, - null, - SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); - CloseableHttpClient httpclient = HttpClients.custom() - .setSSLSocketFactory(sslsf) - .build(); - try { - HttpPost httpPost = new HttpPost(url); - StringEntity entityStr = new StringEntity(xmlStr); - entityStr.setContentType("text/xml"); - //logger.info("entityStr--------------"+entityStr); - httpPost.setEntity(entityStr); - - CloseableHttpResponse response = httpclient.execute(httpPost); - try { - HttpEntity entity = response.getEntity(); - - //System.out.println("----------------------------------------"); - //System.out.println(response.getStatusLine()); - if (entity != null) { - //System.out.println("Response content length: " + entity.getContentLength()); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent())); - StringBuilder sb = new StringBuilder(); - String line = null; - while ((line = bufferedReader.readLine()) != null) { - sb.append(line).append("\n"); - } - return sb.toString(); - } - EntityUtils.consume(entity); - } finally { - response.close(); - } - } finally { - httpclient.close(); - return null; - } - - } +// private static String ClientCustomSSL(String url, String p12file, String mch_id, String xmlStr) throws Exception{ +// KeyStore keyStore = KeyStore.getInstance("PKCS12"); +// FileInputStream instream = new FileInputStream(new File(p12file)); +// try { +// keyStore.load(instream, mch_id.toCharArray()); +// } finally { +// instream.close(); +// } +// +// // Trust own CA and all self-signed certs +// SSLContext sslcontext = SSLContexts.custom() +// .loadKeyMaterial(keyStore, mch_id.toCharArray()) +// .build(); +// // Allow TLSv1 protocol only +// SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( +// sslcontext, +// new String[] { "TLSv1" }, +// null, +// SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); +// CloseableHttpClient httpclient = HttpClients.custom() +// .setSSLSocketFactory(sslsf) +// .build(); +// try { +// HttpPost httpPost = new HttpPost(url); +// StringEntity entityStr = new StringEntity(xmlStr); +// entityStr.setContentType("text/xml"); +// //logger.info("entityStr--------------"+entityStr); +// httpPost.setEntity(entityStr); +// +// CloseableHttpResponse response = httpclient.execute(httpPost); +// try { +// HttpEntity entity = response.getEntity(); +// +// //System.out.println("----------------------------------------"); +// //System.out.println(response.getStatusLine()); +// if (entity != null) { +// //System.out.println("Response content length: " + entity.getContentLength()); +// BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(entity.getContent())); +// StringBuilder sb = new StringBuilder(); +// String line = null; +// while ((line = bufferedReader.readLine()) != null) { +// sb.append(line).append("\n"); +// } +// return sb.toString(); +// } +// EntityUtils.consume(entity); +// } finally { +// response.close(); +// } +// } finally { +// httpclient.close(); +// return null; +// } +// +// } } diff --git a/mallinkService/src/main/resources/mapper/AliBusinessCircleOrderMapper.xml b/mallinkService/src/main/resources/mapper/AliBusinessCircleOrderMapper.xml index e5755c273..1e0fcf8a4 100644 --- a/mallinkService/src/main/resources/mapper/AliBusinessCircleOrderMapper.xml +++ b/mallinkService/src/main/resources/mapper/AliBusinessCircleOrderMapper.xml @@ -127,7 +127,7 @@ #{idItem} - order by ${sortColumns} + + + diff --git a/mallinkService/src/main/resources/mapper/WxBusinessCircleOrderMapper.xml b/mallinkService/src/main/resources/mapper/WxBusinessCircleOrderMapper.xml index 3b417b09c..3fe1cc89d 100644 --- a/mallinkService/src/main/resources/mapper/WxBusinessCircleOrderMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxBusinessCircleOrderMapper.xml @@ -148,7 +148,7 @@ #{idItem} - order by ${sortColumns} + select IFNULL(SUM(`pay_amount`),0) as sum_pay_amount from wx_business_circle_order - where 1=1 - - and `tenant_id` = #{tenantId} - - - and `parent_tenant_id` = #{parentTenantId} - - - and `merchant_id` = #{merchantId} - - - and `time_end` >= #{startTime} - - - and `time_end` < #{endTime} - + + and is_refund = 0 + + + diff --git a/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml b/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml index 70e8e061c..9e10e89b2 100644 --- a/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxThirdPartyOrdersMapper.xml @@ -147,7 +147,7 @@ #{idItem} - order by ${sortColumns} + + select + IFNULL(SUM(`pay_amount`),0) as sum_pay_amount + from wx_third_party_orders + + and is_refund = 0 + + + +