java110 лет назад: 3
Родитель
Сommit
2e47b2a8ed

+ 50 - 0
java110-interface/src/main/java/com/java110/intf/fee/ITempCarFeeCreateOrderV1InnerServiceSMO.java

@@ -0,0 +1,50 @@
+/*
+ * Copyright 2017-2020 吴学文 and java110 team.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.java110.intf.fee;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.config.feign.FeignConfiguration;
+import com.java110.dto.tempCarFeeConfig.TempCarFeeConfigDto;
+import com.java110.po.tempCarFeeConfig.TempCarFeeConfigPo;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import java.util.List;
+
+/**
+ * 类表述: 服务之前调用的接口类,不对外提供接口能力 只用于接口建调用
+ * add by 吴学文 at 2022-06-27 11:41:00 mail: 928255095@qq.com
+ * open source address: https://gitee.com/wuxw7/MicroCommunity
+ * 官网:http://www.homecommunity.cn
+ * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
+ * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
+ */
+@FeignClient(name = "fee-service", configuration = {FeignConfiguration.class})
+@RequestMapping("/tempCarFeeCreateOrderV1Api")
+public interface ITempCarFeeCreateOrderV1InnerServiceSMO {
+
+
+    @RequestMapping(value = "/createOrder", method = RequestMethod.POST)
+    public ResponseEntity<String> createOrder(@RequestBody JSONObject reqJson);
+
+    @RequestMapping(value = "/notifyOrder", method = RequestMethod.POST)
+    public ResponseEntity<String> notifyOrder(@RequestBody JSONObject reqJson);
+
+
+}

+ 178 - 0
service-acct/src/main/java/com/java110/acct/cmd/alipay/PayTempCarFeeCmd.java

@@ -0,0 +1,178 @@
+package com.java110.acct.cmd.alipay;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.context.IPageData;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.core.factory.CallApiServiceFactory;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.ownerCarOpenUser.OwnerCarOpenUserDto;
+import com.java110.dto.parking.ParkingAreaDto;
+import com.java110.dto.smallWeChat.SmallWeChatDto;
+import com.java110.intf.community.IParkingAreaV1InnerServiceSMO;
+import com.java110.intf.fee.ITempCarFeeCreateOrderV1InnerServiceSMO;
+import com.java110.intf.store.ISmallWechatV1InnerServiceSMO;
+import com.java110.intf.user.IOwnerCarOpenUserV1InnerServiceSMO;
+import com.java110.po.ownerCarOpenUser.OwnerCarOpenUserPo;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.constant.WechatConstant;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.factory.ApplicationContextFactory;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.StringUtil;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Java110Cmd(serviceCode = "alipay.payTempCarFee")
+public class PayTempCarFeeCmd extends Cmd {
+
+    @Autowired
+    private IOwnerCarOpenUserV1InnerServiceSMO ownerCarOpenUserV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IParkingAreaV1InnerServiceSMO parkingAreaV1InnerServiceSMOImpl;
+
+    @Autowired
+    private ISmallWechatV1InnerServiceSMO smallWechatV1InnerServiceSMOImpl;
+
+    @Autowired
+    private ITempCarFeeCreateOrderV1InnerServiceSMO tempCarFeeCreateOrderV1InnerServiceSMOImpl;
+
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
+        Assert.jsonObjectHaveKey(reqJson, "carNum", "请求报文中未包含房屋信息节点");
+        Assert.jsonObjectHaveKey(reqJson, "appId", "请求报文中未包含appId节点");
+        Assert.jsonObjectHaveKey(reqJson, "openId", "请求报文中未包含openId节点");
+        Assert.jsonObjectHaveKey(reqJson, "paId", "请求报文中未包含paId节点");
+        Assert.jsonObjectHaveKey(reqJson, "inoutId", "请求报文中未包含inoutId节点");
+        Assert.jsonObjectHaveKey(reqJson, "couponList", "请求报文中未包含couponList节点");
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        ResponseEntity responseEntity = null;
+
+        //根据paId 查询communityId
+        ParkingAreaDto parkingAreaDto = new ParkingAreaDto();
+        parkingAreaDto.setPaId(reqJson.getString("paId"));
+        List<ParkingAreaDto> parkingAreaDtos = parkingAreaV1InnerServiceSMOImpl.queryParkingAreas(parkingAreaDto);
+
+        Assert.listOnlyOne(parkingAreaDtos, "停车场不存在");
+        reqJson.put("communityId", parkingAreaDtos.get(0).getCommunityId());
+        SmallWeChatDto smallWeChatDto = getSmallWechat( reqJson);
+
+        if (smallWeChatDto == null) { //从配置文件中获取 小程序配置信息
+            smallWeChatDto = new SmallWeChatDto();
+            smallWeChatDto.setAppId(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "wechatAppId"));
+            smallWeChatDto.setAppSecret(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "wechatAppSecret"));
+            smallWeChatDto.setMchId(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "mchId"));
+            smallWeChatDto.setPayPassword(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "key"));
+        }
+        JSONArray couponList = reqJson.getJSONArray("couponList");
+        List<String> couponIds = new ArrayList<String>();
+        if (couponList != null && couponList.size() > 0) {
+            for (int couponIndex = 0; couponIndex < couponList.size(); couponIndex++) {
+                couponIds.add(couponList.getJSONObject(couponIndex).getString("couponId"));
+            }
+        }
+
+        //查询用户ID
+        reqJson.put("userId", "-1");
+
+        JSONObject paramIn = new JSONObject();
+        paramIn.put("paId",reqJson.getString("paId"));
+        paramIn.put("carNum",reqJson.getString("carNum"));
+        paramIn.put("machineId",reqJson.getString("machineId"));
+        paramIn.put("couponIds",StringUtils.join(couponIds, ","));
+        responseEntity = tempCarFeeCreateOrderV1InnerServiceSMOImpl.createOrder(paramIn);
+
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+            context.setResponseEntity(responseEntity);
+            return ;
+        }
+        JSONObject orderInfo = JSONObject.parseObject(responseEntity.getBody().toString());
+        if (orderInfo.getIntValue("code") != 0) {
+            throw new IllegalArgumentException("缴费失败");
+        }
+        JSONObject fee = orderInfo.getJSONObject("data");
+
+        double money = fee.getDouble("receivedAmount");
+
+        String orderId = fee.getString("oId");
+        //需要判断金额是否 == 0 等于0 直接掉缴费通知接口
+        if (money <= 0) {
+            JSONObject paramOut = new JSONObject();
+            paramOut.put("oId", orderId);
+            responseEntity = tempCarFeeCreateOrderV1InnerServiceSMOImpl.notifyOrder(paramIn);
+            JSONObject param = new JSONObject();
+            if (responseEntity.getStatusCode() != HttpStatus.OK) {
+                param.put("code", "101");
+                param.put("msg", "扣费为0回调失败");
+                context.setResponseEntity(new ResponseEntity(JSONObject.toJSONString(param), HttpStatus.OK));
+                return ;
+            }
+            param.put("code", "100");
+            param.put("msg", "扣费为0回调成功");
+            context.setResponseEntity(new ResponseEntity(JSONObject.toJSONString(param), HttpStatus.OK));
+            return ;
+        }
+        String openId = reqJson.getString("openId");
+        String payAdapt = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_ADAPT);
+        //payAdapt = StringUtil.isEmpty(payAdapt) ? DEFAULT_PAY_ADAPT : payAdapt;
+        //支付适配器
+//        IPayAdapt tPayAdapt = ApplicationContextFactory.getBean(payAdapt, IPayAdapt.class);
+//        Map result = tPayAdapt.java110Payment(outRestTemplate, paramIn.getString("feeName"), paramIn.getString("tradeType"),
+//                orderId, money, openId, smallWeChatDto, wechatAuthProperties.getTempCarFeeNotifyUrl());
+   //     responseEntity = new ResponseEntity(JSONObject.toJSONString(result), HttpStatus.OK);
+//        if (!"0".equals(result.get("code"))) {
+//            context.setResponseEntity(responseEntity);
+//            return ;
+//        }
+//        JSONObject saveFees = new JSONObject();
+//        saveFees.put("orderId", paramIn.getString("inoutId"));
+//        saveFees.put("carNum", paramIn.getString("carNum"));
+//        saveFees.put("amount", money);
+//        saveFees.put("paId", paramIn.getString("paId"));
+//        saveFees.put("payTime", DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_A));
+//        saveFees.put("payType", "2");
+//        CommonCache.setValue(FeeDto.REDIS_PAY_TEMP_CAR_FEE + orderId, saveFees.toJSONString(), CommonCache.PAY_DEFAULT_EXPIRE_TIME);
+        //记录openId 和车辆关系 以免每次 输入 车牌号麻烦
+        OwnerCarOpenUserPo ownerCarOpenUserPo = new OwnerCarOpenUserPo();
+        ownerCarOpenUserPo.setCarNum(reqJson.getString("carNum"));
+        ownerCarOpenUserPo.setNickname("未获取");
+        ownerCarOpenUserPo.setHeadimgurl("为获取");
+        ownerCarOpenUserPo.setOpenId(openId);
+        ownerCarOpenUserPo.setOpenType(OwnerCarOpenUserDto.OPEN_TYPE_ALIPAY);
+        ownerCarOpenUserPo.setOpenUserId(GenerateCodeFactory.getGeneratorId("10"));
+        ownerCarOpenUserV1InnerServiceSMOImpl.saveOwnerCarOpenUser(ownerCarOpenUserPo);
+    }
+
+    private SmallWeChatDto getSmallWechat(JSONObject paramIn) {
+
+        SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
+        smallWeChatDto.setAppId(paramIn.getString("appId"));
+        smallWeChatDto.setObjId(paramIn.getString("communityId"));
+        smallWeChatDto.setRow(1);
+        smallWeChatDto.setPage(1);
+        List<SmallWeChatDto> smallWeChatDtos = smallWechatV1InnerServiceSMOImpl.querySmallWechats(smallWeChatDto);
+
+
+        if (smallWeChatDtos == null || smallWeChatDtos.size() < 1) {
+            return null;
+        }
+
+        return smallWeChatDtos.get(0);
+    }
+}

+ 3 - 59
service-fee/src/main/java/com/java110/fee/cmd/tempCarFee/NotifyTempCarFeeOrderCmd.java

@@ -13,6 +13,7 @@ import com.java110.dto.tempCarFeeConfig.TempCarPayOrderDto;
 import com.java110.fee.bmo.tempCarFee.IGetTempCarFeeRules;
 import com.java110.fee.bmo.tempCarFee.IGetTempCarFeeRules;
 import com.java110.intf.acct.ICouponUserDetailV1InnerServiceSMO;
 import com.java110.intf.acct.ICouponUserDetailV1InnerServiceSMO;
 import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
 import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
+import com.java110.intf.fee.ITempCarFeeCreateOrderV1InnerServiceSMO;
 import com.java110.po.couponUser.CouponUserPo;
 import com.java110.po.couponUser.CouponUserPo;
 import com.java110.po.couponUserDetail.CouponUserDetailPo;
 import com.java110.po.couponUserDetail.CouponUserDetailPo;
 import com.java110.utils.cache.CommonCache;
 import com.java110.utils.cache.CommonCache;
@@ -38,11 +39,7 @@ import java.util.List;
 public class NotifyTempCarFeeOrderCmd extends Cmd {
 public class NotifyTempCarFeeOrderCmd extends Cmd {
 
 
     @Autowired
     @Autowired
-    private IGetTempCarFeeRules getTempCarFeeRulesImpl;
-    @Autowired
-    private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
-    @Autowired
-    private ICouponUserDetailV1InnerServiceSMO couponUserDetailV1InnerServiceSMOImpl;
+    private ITempCarFeeCreateOrderV1InnerServiceSMO tempCarFeeCreateOrderV1InnerServiceSMOImpl;
     //{"amount":20.0,"payType":"2","orderId":"19c4321c-b5d5-405f-b2ff-20e86a2e7f3e",
     //{"amount":20.0,"payType":"2","orderId":"19c4321c-b5d5-405f-b2ff-20e86a2e7f3e",
     // "payTime":"2021-10-17 17:29:54","paId":"102021101160020175","carNum":"青A88888","oId":"102021101724760012"}
     // "payTime":"2021-10-17 17:29:54","paId":"102021101160020175","carNum":"青A88888","oId":"102021101724760012"}
     @Override
     @Override
@@ -53,59 +50,6 @@ public class NotifyTempCarFeeOrderCmd extends Cmd {
     @Override
     @Override
     @Java110Transactional
     @Java110Transactional
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
-        String paramIn = CommonCache.getAndRemoveValue("queryTempCarFeeOrder" + reqJson.getString("oId"));
-        if (StringUtil.isEmpty(paramIn)) {
-            throw new CmdException("已经处理过了 再不处理");
-        }
-        JSONObject paramObj = JSONObject.parseObject(paramIn);
-        paramObj.putAll(reqJson);
-        System.out.println("获取到内存中的数据了++++++++++++==》"+paramObj.toJSONString());
-        modifyCouponUser(paramObj);
-        TempCarPayOrderDto tempCarPayOrderDto = BeanConvertUtil.covertBean(paramObj, TempCarPayOrderDto.class);
-        ResponseEntity<String> responseEntity = getTempCarFeeRulesImpl.notifyTempCarFeeOrder(tempCarPayOrderDto);
-        cmdDataFlowContext.setResponseEntity(responseEntity);
-    }
-
-    private void modifyCouponUser(JSONObject paramObj) {
-        if (!paramObj.containsKey("couponPrice") || paramObj.getDouble("couponPrice") <= 0) {
-            return;
-        }
-        //FeeDto feeInfo = (FeeDto) paramObj.get("feeInfo");
-        CouponUserDto couponUserDto = null;
-        JSONArray couponUserDtos = paramObj.getJSONArray("couponUserDtos");
-        CouponUserDto couponUser = null;
-        for (int accountIndex = 0; accountIndex < couponUserDtos.size(); accountIndex++) {
-            couponUser = BeanConvertUtil.covertBean(couponUserDtos.getJSONObject(accountIndex), CouponUserDto.class);
-            couponUserDto = new CouponUserDto();
-            couponUserDto.setCouponId(couponUser.getCouponId());
-            couponUserDto.setState(CouponUserDto.COUPON_STATE_RUN);
-            List<CouponUserDto> couponUserDtos1 = couponUserV1InnerServiceSMOImpl.queryCouponUsers(couponUserDto);
-            if (couponUserDtos1 == null || couponUserDtos1.size() < 1) {
-                throw new CmdException("优惠券被使用");
-            }
-            CouponUserPo couponUserPo = new CouponUserPo();
-            couponUserPo.setState(CouponUserDto.COUPON_STATE_STOP);
-            couponUserPo.setCouponId(couponUser.getCouponId());
-            int fage = couponUserV1InnerServiceSMOImpl.updateCouponUser(couponUserPo);
-            if (fage < 1) {
-                throw new CmdException("更新优惠卷信息失败");
-            }
-            CouponUserDetailPo couponUserDetailPo = new CouponUserDetailPo();
-            couponUserDetailPo.setUoId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_usId));
-            couponUserDetailPo.setCouponId(couponUser.getCouponId());
-            couponUserDetailPo.setUserId(couponUser.getUserId());
-            couponUserDetailPo.setCouponName(couponUser.getCouponName());
-            couponUserDetailPo.setUserName(couponUser.getUserName());
-            couponUserDetailPo.setObjId(paramObj.getString("carNum"));
-            couponUserDetailPo.setObjType("车辆");
-            couponUserDetailPo.setOrderId(paramObj.getString("oId"));
-            fage = couponUserDetailV1InnerServiceSMOImpl.saveCouponUserDetail(couponUserDetailPo);
-            if (fage < 1) {
-                throw new CmdException("新增优惠卷使用记录信息失败");
-            }
-        }
-
-        paramObj.put("remark", paramObj.getString("remark") + "-优惠劵抵扣" + paramObj.getDouble("couponPrice") + "元");
-
+        cmdDataFlowContext.setResponseEntity(tempCarFeeCreateOrderV1InnerServiceSMOImpl.notifyOrder(reqJson));
     }
     }
 }
 }

+ 4 - 67
service-fee/src/main/java/com/java110/fee/cmd/tempCarFee/QueryTempCarFeeOrderCmd.java

@@ -11,6 +11,7 @@ import com.java110.dto.couponUser.CouponUserDto;
 import com.java110.dto.tempCarFeeConfig.TempCarPayOrderDto;
 import com.java110.dto.tempCarFeeConfig.TempCarPayOrderDto;
 import com.java110.fee.bmo.tempCarFee.IGetTempCarFeeRules;
 import com.java110.fee.bmo.tempCarFee.IGetTempCarFeeRules;
 import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
 import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
+import com.java110.intf.fee.ITempCarFeeCreateOrderV1InnerServiceSMO;
 import com.java110.utils.cache.CommonCache;
 import com.java110.utils.cache.CommonCache;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.Assert;
@@ -37,9 +38,8 @@ import java.util.List;
 @Java110Cmd(serviceCode = "tempCarFee.queryTempCarFeeOrder")
 @Java110Cmd(serviceCode = "tempCarFee.queryTempCarFeeOrder")
 public class QueryTempCarFeeOrderCmd extends Cmd {
 public class QueryTempCarFeeOrderCmd extends Cmd {
     @Autowired
     @Autowired
-    private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
-    @Autowired
-    private IGetTempCarFeeRules getTempCarFeeRulesImpl;
+    private ITempCarFeeCreateOrderV1InnerServiceSMO tempCarFeeCreateOrderV1InnerServiceSMOImpl;
+
 
 
     @Override
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
@@ -51,71 +51,8 @@ public class QueryTempCarFeeOrderCmd extends Cmd {
 
 
     @Override
     @Override
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
-        TempCarPayOrderDto tempCarPayOrderDto = new TempCarPayOrderDto();
-        tempCarPayOrderDto.setPaId(reqJson.getString("paId"));
-        tempCarPayOrderDto.setCarNum(reqJson.getString("carNum"));
-        ResponseEntity<String> responseEntity = getTempCarFeeRulesImpl.getTempCarFeeOrder(tempCarPayOrderDto);
-
-        if (responseEntity.getStatusCode() != HttpStatus.OK) {
-            cmdDataFlowContext.setResponseEntity(responseEntity);
-            return;
-        }
-        JSONObject orderInfo = JSONObject.parseObject(responseEntity.getBody().toString());
-        if (orderInfo.getIntValue("code") != 0) {
-            cmdDataFlowContext.setResponseEntity(responseEntity);
-            return;
-        }
-
-        JSONObject fee = orderInfo.getJSONObject("data");
-        //double money = fee.getDouble("payCharge");
-        BigDecimal money = new BigDecimal(fee.getDouble("payCharge"));
-        //3.0 考虑优惠卷
-        double couponPrice = checkCouponUser(reqJson);
-        money = money.subtract(new BigDecimal(couponPrice)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
-
-        double receivedAmount = money.doubleValue();
-        //所有 优惠折扣计算完后,如果总金额小于等于0,则返回总扣款为0
-        if (receivedAmount <= 0) {
-            receivedAmount = 0.0;
-        }
-        fee.put("receivedAmount", receivedAmount);
-        fee.put("oId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_oId));
-        JSONObject outParm = new JSONObject();
-        outParm.put("data",fee);
-        outParm.put("code","0");
-        outParm.put("msg","成功");
-        ResponseEntity<String> responseEntitys = new ResponseEntity<>(outParm.toJSONString(), HttpStatus.OK);
-        fee.putAll(reqJson);
-        CommonCache.setValue("queryTempCarFeeOrder" + fee.getString("oId"), fee.toJSONString(), 24 * 60 * 60);
-        cmdDataFlowContext.setResponseEntity(responseEntitys);
+        cmdDataFlowContext.setResponseEntity(tempCarFeeCreateOrderV1InnerServiceSMOImpl.createOrder(reqJson));
     }
     }
 
 
-    private double checkCouponUser(JSONObject paramObj) {
-
-        BigDecimal couponPrice = new BigDecimal(0.0);
-        String couponIds = paramObj.getString("couponIds");
-        if (couponIds == null || "".equals(couponIds)) {
-            paramObj.put("couponPrice", couponPrice.doubleValue());
-            paramObj.put("couponUserDtos", new JSONArray()); //这里考虑空
-            return couponPrice.doubleValue();
-        }
 
 
-        List<String> result = Arrays.asList(couponIds.split(","));
-        CouponUserDto couponUserDto = new CouponUserDto();
-        couponUserDto.setCouponIds(result.toArray(new String[result.size()]));
-        List<CouponUserDto> couponUserDtos = couponUserV1InnerServiceSMOImpl.queryCouponUsers(couponUserDto);
-        if (couponUserDtos == null || couponUserDtos.size() < 1) {
-            paramObj.put("couponPrice", couponPrice.doubleValue());
-            return couponPrice.doubleValue();
-        }
-        for (CouponUserDto couponUser : couponUserDtos) {
-            //不计算已过期购物券金额
-            if (couponUser.getEndTime().compareTo(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B)) >= 0) {
-                couponPrice = couponPrice.add(new BigDecimal(Double.parseDouble(couponUser.getActualPrice())));
-            }
-        }
-        paramObj.put("couponPrice", couponPrice.doubleValue());
-        paramObj.put("couponUserDtos", BeanConvertUtil.beanCovertJSONArray(couponUserDtos));
-        return couponPrice.doubleValue();
-    }
 }
 }

+ 167 - 0
service-fee/src/main/java/com/java110/fee/smo/impl/TempCarFeeCreateOrderV1InnerServiceSMOImpl.java

@@ -0,0 +1,167 @@
+package com.java110.fee.smo.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.base.smo.BaseServiceSMO;
+import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.dto.couponUser.CouponUserDto;
+import com.java110.dto.tempCarFeeConfig.TempCarPayOrderDto;
+import com.java110.fee.bmo.tempCarFee.IGetTempCarFeeRules;
+import com.java110.intf.acct.ICouponUserDetailV1InnerServiceSMO;
+import com.java110.intf.acct.ICouponUserV1InnerServiceSMO;
+import com.java110.intf.fee.ITempCarFeeCreateOrderV1InnerServiceSMO;
+import com.java110.po.couponUser.CouponUserPo;
+import com.java110.po.couponUserDetail.CouponUserDetailPo;
+import com.java110.po.tempCarFeeConfig.TempCarFeeConfigPo;
+import com.java110.utils.cache.CommonCache;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.DateUtil;
+import com.java110.utils.util.StringUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.List;
+
+@RestController
+public class TempCarFeeCreateOrderV1InnerServiceSMOImpl  extends BaseServiceSMO implements ITempCarFeeCreateOrderV1InnerServiceSMO {
+
+    @Autowired
+    private ICouponUserV1InnerServiceSMO couponUserV1InnerServiceSMOImpl;
+    @Autowired
+    private IGetTempCarFeeRules getTempCarFeeRulesImpl;
+
+    @Autowired
+    private ICouponUserDetailV1InnerServiceSMO couponUserDetailV1InnerServiceSMOImpl;
+
+    @Override
+    public ResponseEntity<String> createOrder(@RequestBody JSONObject reqJson) {
+
+        TempCarPayOrderDto tempCarPayOrderDto = new TempCarPayOrderDto();
+        tempCarPayOrderDto.setPaId(reqJson.getString("paId"));
+        tempCarPayOrderDto.setCarNum(reqJson.getString("carNum"));
+        ResponseEntity<String> responseEntity = getTempCarFeeRulesImpl.getTempCarFeeOrder(tempCarPayOrderDto);
+
+        if (responseEntity.getStatusCode() != HttpStatus.OK) {
+            return responseEntity;
+        }
+        JSONObject orderInfo = JSONObject.parseObject(responseEntity.getBody().toString());
+        if (orderInfo.getIntValue("code") != 0) {
+            return responseEntity;
+        }
+
+        JSONObject fee = orderInfo.getJSONObject("data");
+        //double money = fee.getDouble("payCharge");
+        BigDecimal money = new BigDecimal(fee.getDouble("payCharge"));
+        //3.0 考虑优惠卷
+        double couponPrice = checkCouponUser(reqJson);
+        money = money.subtract(new BigDecimal(couponPrice)).setScale(2, BigDecimal.ROUND_HALF_EVEN);
+
+        double receivedAmount = money.doubleValue();
+        //所有 优惠折扣计算完后,如果总金额小于等于0,则返回总扣款为0
+        if (receivedAmount <= 0) {
+            receivedAmount = 0.0;
+        }
+        fee.put("receivedAmount", receivedAmount);
+        fee.put("oId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_oId));
+        JSONObject outParm = new JSONObject();
+        outParm.put("data",fee);
+        outParm.put("code","0");
+        outParm.put("msg","成功");
+        ResponseEntity<String> responseEntitys = new ResponseEntity<>(outParm.toJSONString(), HttpStatus.OK);
+        fee.putAll(reqJson);
+        CommonCache.setValue("queryTempCarFeeOrder" + fee.getString("oId"), fee.toJSONString(), 24 * 60 * 60);
+        return responseEntitys;
+    }
+
+    @Override
+    public ResponseEntity<String> notifyOrder(@RequestBody JSONObject reqJson) {
+        String paramIn = CommonCache.getAndRemoveValue("queryTempCarFeeOrder" + reqJson.getString("oId"));
+        if (StringUtil.isEmpty(paramIn)) {
+            throw new CmdException("已经处理过了 再不处理");
+        }
+        JSONObject paramObj = JSONObject.parseObject(paramIn);
+        paramObj.putAll(reqJson);
+        modifyCouponUser(paramObj);
+        TempCarPayOrderDto tempCarPayOrderDto = BeanConvertUtil.covertBean(paramObj, TempCarPayOrderDto.class);
+        ResponseEntity<String> responseEntity = getTempCarFeeRulesImpl.notifyTempCarFeeOrder(tempCarPayOrderDto);
+        return responseEntity;
+    }
+
+    private double checkCouponUser(JSONObject paramObj) {
+
+        BigDecimal couponPrice = new BigDecimal(0.0);
+        String couponIds = paramObj.getString("couponIds");
+        if (couponIds == null || "".equals(couponIds)) {
+            paramObj.put("couponPrice", couponPrice.doubleValue());
+            paramObj.put("couponUserDtos", new JSONArray()); //这里考虑空
+            return couponPrice.doubleValue();
+        }
+
+        List<String> result = Arrays.asList(couponIds.split(","));
+        CouponUserDto couponUserDto = new CouponUserDto();
+        couponUserDto.setCouponIds(result.toArray(new String[result.size()]));
+        List<CouponUserDto> couponUserDtos = couponUserV1InnerServiceSMOImpl.queryCouponUsers(couponUserDto);
+        if (couponUserDtos == null || couponUserDtos.size() < 1) {
+            paramObj.put("couponPrice", couponPrice.doubleValue());
+            return couponPrice.doubleValue();
+        }
+        for (CouponUserDto couponUser : couponUserDtos) {
+            //不计算已过期购物券金额
+            if (couponUser.getEndTime().compareTo(DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B)) >= 0) {
+                couponPrice = couponPrice.add(new BigDecimal(Double.parseDouble(couponUser.getActualPrice())));
+            }
+        }
+        paramObj.put("couponPrice", couponPrice.doubleValue());
+        paramObj.put("couponUserDtos", BeanConvertUtil.beanCovertJSONArray(couponUserDtos));
+        return couponPrice.doubleValue();
+    }
+
+    private void modifyCouponUser(JSONObject paramObj) {
+        if (!paramObj.containsKey("couponPrice") || paramObj.getDouble("couponPrice") <= 0) {
+            return;
+        }
+        //FeeDto feeInfo = (FeeDto) paramObj.get("feeInfo");
+        CouponUserDto couponUserDto = null;
+        JSONArray couponUserDtos = paramObj.getJSONArray("couponUserDtos");
+        CouponUserDto couponUser = null;
+        for (int accountIndex = 0; accountIndex < couponUserDtos.size(); accountIndex++) {
+            couponUser = BeanConvertUtil.covertBean(couponUserDtos.getJSONObject(accountIndex), CouponUserDto.class);
+            couponUserDto = new CouponUserDto();
+            couponUserDto.setCouponId(couponUser.getCouponId());
+            couponUserDto.setState(CouponUserDto.COUPON_STATE_RUN);
+            List<CouponUserDto> couponUserDtos1 = couponUserV1InnerServiceSMOImpl.queryCouponUsers(couponUserDto);
+            if (couponUserDtos1 == null || couponUserDtos1.size() < 1) {
+                throw new CmdException("优惠券被使用");
+            }
+            CouponUserPo couponUserPo = new CouponUserPo();
+            couponUserPo.setState(CouponUserDto.COUPON_STATE_STOP);
+            couponUserPo.setCouponId(couponUser.getCouponId());
+            int fage = couponUserV1InnerServiceSMOImpl.updateCouponUser(couponUserPo);
+            if (fage < 1) {
+                throw new CmdException("更新优惠卷信息失败");
+            }
+            CouponUserDetailPo couponUserDetailPo = new CouponUserDetailPo();
+            couponUserDetailPo.setUoId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_usId));
+            couponUserDetailPo.setCouponId(couponUser.getCouponId());
+            couponUserDetailPo.setUserId(couponUser.getUserId());
+            couponUserDetailPo.setCouponName(couponUser.getCouponName());
+            couponUserDetailPo.setUserName(couponUser.getUserName());
+            couponUserDetailPo.setObjId(paramObj.getString("carNum"));
+            couponUserDetailPo.setObjType("车辆");
+            couponUserDetailPo.setOrderId(paramObj.getString("oId"));
+            fage = couponUserDetailV1InnerServiceSMOImpl.saveCouponUserDetail(couponUserDetailPo);
+            if (fage < 1) {
+                throw new CmdException("新增优惠卷使用记录信息失败");
+            }
+        }
+
+        paramObj.put("remark", paramObj.getString("remark") + "-优惠劵抵扣" + paramObj.getDouble("couponPrice") + "元");
+
+    }
+}