diff --git a/mallinkService/src/main/java/com/iformall/service/park/impl/haikangweishiv3/HaiKangWeiShiV3ParkService.java b/mallinkService/src/main/java/com/iformall/service/park/impl/haikangweishiv3/HaiKangWeiShiV3ParkService.java index b6f7f4699..13cc3b2ea 100644 --- a/mallinkService/src/main/java/com/iformall/service/park/impl/haikangweishiv3/HaiKangWeiShiV3ParkService.java +++ b/mallinkService/src/main/java/com/iformall/service/park/impl/haikangweishiv3/HaiKangWeiShiV3ParkService.java @@ -142,9 +142,9 @@ public class HaiKangWeiShiV3ParkService extends BaseParkService implements ParkA reducefee = Double.parseDouble(reducefeestr); } Double fee = needfee - reducefee; - if (fee <= 0 && StringUtils.isBlank(parkOrderId)) { - parkOrderId = attribute.getString("inRecordSyscode"); - } + //if (fee <= 0 && StringUtils.isBlank(parkOrderId)) { + // parkOrderId = attribute.getString("inRecordSyscode"); + //} Date _createTime = DateUtils.stringToDate(attribute.getString("enterTime"), "yyyy-MM-dd'T'HH:mm:ssZ"); Date _endTime = DateUtils.getMinuteTimeAfter(attribute.getIntValue("parkTime"), _createTime);//离场时间,格式为“yyyy-MM-dd HH:mi:ss” String payPath = ""; @@ -154,6 +154,7 @@ public class HaiKangWeiShiV3ParkService extends BaseParkService implements ParkA } /** + * /api/pms/v1/coupon/addition * @return */ @Override @@ -170,39 +171,26 @@ public class HaiKangWeiShiV3ParkService extends BaseParkService implements ParkA if (null == valueMap) { return new ResultData(ErrorCode.COUPON_IS_EMPTY.getCode(),"当前停车券没有关联停车场优惠券配置。"+coupon.getTitle()); } - String reduceType = valueMap.get("reduceType"); - if (StringUtils.isBlank(reduceType)) { - return new ResultData(ErrorCode.COUPON_IS_EMPTY.getCode(),"当前停车券未设置停车场优惠券配置参数[减免类型]。"+coupon.getTitle()); - } - if ((!"1".equals(reduceType)) && (!"2".equals(reduceType))) { - return new ResultData(ErrorCode.COUPON_IS_EMPTY.getCode(),"当前停车券设置停车场优惠券配置参数[减免类型]值非法。"+coupon.getTitle()); - } - String reduceValueStr = valueMap.get("reduceValue"); - if (StringUtils.isBlank(reduceValueStr)) { - return new ResultData(ErrorCode.COUPON_IS_EMPTY.getCode(),"当前停车券未设置停车场优惠券配置参数[减免数值]。"+coupon.getTitle()); - } - Integer reduceValue = 0; - try { - reduceValue = Integer.parseInt(reduceValueStr); - }catch(Exception e) { - return new ResultData(ErrorCode.COUPON_IS_EMPTY.getCode(),"当前停车券设置停车场优惠券配置参数[减免数值]值非法。"+coupon.getTitle()); + String ruleSyscode = valueMap.get("ruleSyscode"); + if (StringUtils.isBlank(ruleSyscode)) { + return new ResultData(ErrorCode.COUPON_IS_EMPTY.getCode(),"当前停车券没有关联停车场优惠券配置[ruleSyscode]。"+coupon.getTitle()); } - boolean isTimeCash = false; - if ("1".equals(reduceType)) { - isTimeCash = true; + String couponCode = valueMap.get("couponCode"); + if (StringUtils.isBlank(couponCode)) { + return new ResultData(ErrorCode.COUPON_IS_EMPTY.getCode(),"当前停车券没有关联停车场优惠券配置[couponCode]。"+coupon.getTitle()); } -// //查询临停信息,判断缓存是否已经存在 -// JSONObject stopInfo = haikangV3.getCarStopFee(park, carNumber, getCacheToken(park)); -// String inRecordSyscode = stopInfo.getString("inUnid"); -// Integer used = RedisCacheUtils.getCacheInteger(redisTemplate, "carStop:haikangv2StopInfoUseCoupon:"+carNumber+":"+inRecordSyscode); -// if (null == used || (null != used && used.intValue() < 1) ) { -// //do nothing -// }else { -// return new ResultData(ErrorCode.CYF_STOP_FEE_FAIL.getCode(), "已经使用过优惠券, 不能重复使用."); -// } -// -// JSONObject retObj = haikangV3.useCoupon(park,getCacheToken(park),carNumber,isTimeCash,reduceValue,coupon.getValidStartDate(),coupon.getValidEndDate()); -// RedisCacheUtils.cache(redisTemplate, "carStop:haikangv2StopInfoUseCoupon:"+carNumber+":"+inRecordSyscode, 1, 24*3600); + //查询临停信息,判断缓存是否已经存在 + JSONObject stopInfo = haikangV3.getCarStopFee(park, carNumber, getConfig(park)); + String inRecordSyscode = stopInfo.getString("inRecordSyscode"); + Integer used = RedisCacheUtils.getCacheInteger(redisTemplate, "carStop:haikangv3StopInfoUseCoupon:"+carNumber+":"+inRecordSyscode); + if (null == used || (null != used && used.intValue() < 1) ) { + //do nothing + }else { + return new ResultData(ErrorCode.CYF_STOP_FEE_FAIL.getCode(), "已经使用过优惠券, 不能重复使用."); + } + + JSONObject retObj = haikangV3.useCoupon(park,getConfig(park),carNumber,ruleSyscode,couponCode); + RedisCacheUtils.cache(redisTemplate, "carStop:haikangv2StopInfoUseCoupon:"+carNumber+":"+inRecordSyscode, 1, 24*3600); return new ResultData(); } diff --git a/mallinkService/src/main/java/com/iformall/service/park/impl/haikangweishiv3/HaiKangWeiShiV3Util.java b/mallinkService/src/main/java/com/iformall/service/park/impl/haikangweishiv3/HaiKangWeiShiV3Util.java index 76afc8daa..23a745e6f 100644 --- a/mallinkService/src/main/java/com/iformall/service/park/impl/haikangweishiv3/HaiKangWeiShiV3Util.java +++ b/mallinkService/src/main/java/com/iformall/service/park/impl/haikangweishiv3/HaiKangWeiShiV3Util.java @@ -1,6 +1,7 @@ package com.iformall.service.park.impl.haikangweishiv3; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hikvision.artemis.sdk.ArtemisHttpUtil; import com.hikvision.artemis.sdk.config.ArtemisConfig; @@ -58,7 +59,7 @@ public class HaiKangWeiShiV3Util { public static final String QUERY_PRICE = "/api/pms/v1/pay/quickPreBill"; - public static final String COUPON_USE = "http://api.hikparking.com:9016/artemis/api/v1/sendCoupon"; + public static final String COUPON_USE = "/api/pms/v1/coupon/addition"; public static final String NOTIFY_PAID = "/api/pms/v2/pay/receipt"; @@ -87,6 +88,16 @@ public class HaiKangWeiShiV3Util { }; return ArtemisHttpUtil.doPostStringArtemis(config,path, body, null, null, "application/json"); } + + public String callPostApi(ArtemisConfig config,String api,String body) throws Exception { + final String getCamsApi = ARTEMIS_PATH + api; + Map path = new HashMap(2) { + { + put("https://", getCamsApi); + } + }; + return ArtemisHttpUtil.doPostStringArtemis(config,path, body, null, null, "application/json"); + } /** @@ -134,37 +145,38 @@ public class HaiKangWeiShiV3Util { /** * 使用优惠券 **/ - public JSONObject useCoupon(WxPark wxPark,String token,String carNumber,boolean isTime,Integer cashValue,Date startTime,Date endTime){ + public JSONObject useCoupon(WxPark wxPark,ArtemisConfig config,String carNumber,String ruleSyscode,String couponCode){ String vendroParams = wxPark.getVendorParams(); JSONObject vp = JSON.parseObject(vendroParams); - Map params = new HashMap(); - params.put("parkCodes", vp.getString("parkCodes")); - params.put("generateObj", 1); - params.put("plateNo", carNumber); - if (isTime) { - params.put("couponType", 4); - params.put("deductContent", cashValue*60); - }else { - params.put("couponType", 1); - params.put("deductContent", cashValue*100); - } - params.put("startTime", startTime); - params.put("endTime", endTime); - params.put("couponSource", vp.getString("couponSource")); - //String retCode = ProcBussiness(COUPON_USE, params,token); - String retCode = ""; - if (StringUtils.isBlank(retCode)) { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "haikangv2 useCoupon error. has no result"); - } - JSONObject result = JSON.parseObject(retCode); - - String code = result.getString("code"); - if (!code.equals("200") ) { - String message = result.getString("msg"); - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "haikangv2 useCoupon error.["+code+"]"+message); - } - return result; + String merchantSysCode = vp.getString("merchantSyscode"); + + JSONArray array = new JSONArray(); + JSONObject ob = new JSONObject(); + ob.put("ruleSyscode", ruleSyscode); + ob.put("merchantSyscode", merchantSysCode); + ob.put("couponCode", couponCode); + ob.put("plateNo", carNumber); + array.add(ob); + + Map param = new HashMap(); + param.put("coupons", array); + try { + String retCode = callPostApi(config,COUPON_USE, JSON.toJSONString(param)); + if (StringUtils.isBlank(retCode)) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "haikangv3 useCoupon error. has no result"); + } + JSONObject result = JSON.parseObject(retCode); + String code = result.getString("code"); + if (!code.equals("0") ) { + String message = result.getString("msg"); + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "haikangv3 useCoupon error.["+code+"]"+message); + } + return result; + } catch (Exception e) { + log.error("haikangweishiv3 useCoupon error.",e); + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(), "haikangv3 useCoupon error."+e.getMessage()); + } } /**