浏览代码

新增订单下单锁定

赵冬冬 4 年之前
父节点
当前提交
7d7de1160c

+ 7 - 0
carbon-h5/carbon-h5-service/pom.xml

@@ -133,6 +133,13 @@
             <groupId>com.hcloud.microserver</groupId>
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
+
+        <!--redisson-->
+        <dependency>
+            <groupId>org.redisson</groupId>
+            <artifactId>redisson</artifactId>
+            <version>3.5.0</version>
+        </dependency>
     </dependencies>
 
 

+ 34 - 0
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/config/RedissonConfig.java

@@ -0,0 +1,34 @@
+package com.hcloud.microserver.h5.config;
+
+import org.redisson.Redisson;
+import org.redisson.api.RedissonClient;
+import org.redisson.config.Config;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+
+/**
+ * redisson通用化配置
+ **/
+@Configuration
+public class RedissonConfig {
+    @Autowired
+    private Environment env;
+
+    @Value("${myredis.address}")
+    private String address;
+    @Value("${myredis.passord}")
+    private String password;
+
+    @Bean
+    public RedissonClient redissonClient() {
+        Config config = new Config();
+        config.useSingleServer()
+                .setAddress(address)
+                .setPassword(password);
+        RedissonClient client = Redisson.create(config);
+        return client;
+    }
+}

+ 154 - 104
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/controller/web/OrderManagerController.java

@@ -3,6 +3,7 @@ package com.hcloud.microserver.h5.controller.web;
 import com.github.pagehelper.PageInfo;
 import com.google.common.collect.Lists;
 import com.hcloud.microserver.h5.bo.CredentialInfoBO;
+import com.hcloud.microserver.h5.bo.OrderInfoBO;
 import com.hcloud.microserver.h5.common.BaseInfoDO;
 import com.hcloud.microserver.h5.common.CarbonBaseController;
 import com.hcloud.microserver.h5.forms.OrderQueryForm;
@@ -16,6 +17,8 @@ import com.hcloud.microserver.facade.carbon.entity.GoodsInfo;
 import com.hcloud.microserver.facade.carbon.forms.*;
 import io.swagger.annotations.*;
 import lombok.extern.slf4j.Slf4j;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -33,7 +36,7 @@ import java.util.Objects;
 public class OrderManagerController extends CarbonBaseController {
 
     @Autowired
-    private OrderInfoService orderClient;
+    private OrderInfoService orderInfoService;
 
     @Autowired
     private OrderPayService orderPayApplyClient;
@@ -57,18 +60,18 @@ public class OrderManagerController extends CarbonBaseController {
     private OrderPayApplyService orderPayApplyService;
 
 
-    @ApiOperation(value = "查询爱心用户订单信息",notes = "分类查询爱心用户订单")
+    @ApiOperation(value = "查询爱心用户订单信息", notes = "分类查询爱心用户订单")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "orderType",value = "爱心用户信息", dataType = "Integer",paramType = "query")
+            @ApiImplicitParam(name = "orderType", value = "爱心用户信息", dataType = "Integer", paramType = "query")
     })
-    @ApiResponse(code =0,message = "操作成功")
+    @ApiResponse(code = 0, message = "操作成功")
     @PostMapping("/searchByPage")
     @AuthCarbonValidate
-    public ResponseBase searchCustomerOrderByClass(@RequestBody OrderQueryForm queryForm){
-        BaseInfoDO baseInfoDO = this.initiSaveObject();
-        if(baseInfoDO==null){return responseError(new ResultVO(ResultEnum.TOKEN_EXPIRED));}
+    public ResponseBase searchCustomerOrderByClass(@RequestBody OrderQueryForm queryForm) {
+        CustomerInfoForm customerInfo = customerService.getCurrentMember();
+
         GoodsOrderInfoForm goodsOrderInfoForm = new GoodsOrderInfoForm();
-        goodsOrderInfoForm.setFkCustomerGuid(baseInfoDO.getCustomerId());
+        goodsOrderInfoForm.setFkCustomerGuid(customerInfo.getGuid());
         goodsOrderInfoForm.setOrderStatus(queryForm.getOrderStatus());
         goodsOrderInfoForm.setPageNo(queryForm.getPage());
         goodsOrderInfoForm.setPageSize(queryForm.getPageSize());
@@ -76,144 +79,186 @@ public class OrderManagerController extends CarbonBaseController {
         return responseSuccess(resultVO);
     }
 
-    public ResultVO getGoods(GoodsOrderInfoForm goodsOrderInfoForm){
-        PageInfo pageInfo =orderClient.searchOrderInfoByCustomerId(goodsOrderInfoForm);
+    @ApiOperation(value = "查询爱心用户订单信息", notes = "分类查询爱心用户订单")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "orderType", value = "爱心用户信息", dataType = "Integer", paramType = "query")
+    })
+    @ApiResponse(code = 0, message = "操作成功")
+    @GetMapping("/info")
+    @AuthCarbonValidate
+    public ResponseBase info(@RequestParam String orderId) {
+        GoodsOrderInfoForm orderInfoBO = orderDetailInfoService.info(orderId);
+        return resultVOSuccess(orderInfoBO);
+    }
+
+
+    public ResultVO getGoods(GoodsOrderInfoForm goodsOrderInfoForm) {
+        PageInfo pageInfo = orderInfoService.searchOrderInfoByCustomerId(goodsOrderInfoForm);
         List list = pageInfo.getList();
-        if(null!=list && list.size()>0){
-            List<GoodsOrderInfoForm> orderInfoFormList = BeanCopyUtil.convertList(list,GoodsOrderInfoForm.class);
-            for (GoodsOrderInfoForm form:orderInfoFormList) {
+        if (null != list && list.size() > 0) {
+            List<GoodsOrderInfoForm> orderInfoFormList = BeanCopyUtil.convertList(list, GoodsOrderInfoForm.class);
+            for (GoodsOrderInfoForm form : orderInfoFormList) {
                 String guid = form.getGuid();
-                List<GoodsOrderDetailForm> detailFormList =orderDetailInfoService.getOrderDetailListByOrderId(guid);
+                List<GoodsOrderDetailForm> detailFormList = orderDetailInfoService.getOrderDetailListByOrderId(guid);
                 form.setGoodsOrderDetailForm(detailFormList);
             }
-            return success(orderInfoFormList,pageInfo.getTotal());
+            return success(orderInfoFormList, pageInfo.getTotal());
         }
-        return success(pageInfo.getList(),pageInfo.getTotal());
+        return success(pageInfo.getList(), pageInfo.getTotal());
     }
 
-    @ApiOperation(value = "查询爱心用户证书信息",notes = "分类查询爱心用户证书")
+    @ApiOperation(value = "查询爱心用户证书信息", notes = "分类查询爱心用户证书")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "customerInfoForm",value = "爱心用户信息", dataType = "CustomerInfoForm")
+            @ApiImplicitParam(name = "customerInfoForm", value = "爱心用户信息", dataType = "CustomerInfoForm")
     })
-    @ApiResponse(code =0,message = "操作成功")
+    @ApiResponse(code = 0, message = "操作成功")
     @PostMapping("/searchCredentialList")
     @AuthCarbonValidate
-    public ResponseBase searchCredentialInfo(@RequestBody GoodsCredentialInfoForm goodsCredentialInfoForm){
+    public ResponseBase searchCredentialInfo(@RequestBody GoodsCredentialInfoForm goodsCredentialInfoForm) {
         BaseInfoDO baseInfoDO = this.initiSaveObject();
-        if(baseInfoDO==null){return responseError(new ResultVO(ResultEnum.TOKEN_EXPIRED));}
+        if (baseInfoDO == null) {
+            return responseError(new ResultVO(ResultEnum.TOKEN_EXPIRED));
+        }
         goodsCredentialInfoForm.setFkCustomerId(baseInfoDO.getCustomerId());
         PageInfo pageInfo = credentialInfoService.searchCredentialByPage(goodsCredentialInfoForm);
-        ResultVO resultVO = success(pageInfo.getList(),pageInfo.getTotal());
+        ResultVO resultVO = success(pageInfo.getList(), pageInfo.getTotal());
         return responseSuccess(resultVO);
     }
 
 
-    @ApiOperation(value = "生成订单信息",notes = "生成订单信息")
+    @ApiOperation(value = "生成订单信息", notes = "生成订单信息")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "orderId",value = "订单Id", dataType = "String")
+            @ApiImplicitParam(name = "orderId", value = "订单Id", dataType = "String")
     })
-    @ApiResponse(code =0,message = "操作成功")
+    @ApiResponse(code = 0, message = "操作成功")
     @PostMapping("/saveOrderInfo")
     @AuthCarbonValidate
-    public ResponseBase saveOrderInfo(@RequestBody GoodsOrderInfoForm goodsOrderInfoForm){
+    public ResponseBase saveOrderInfo(@RequestBody GoodsOrderInfoForm goodsOrderInfoForm) {
         CustomerInfoForm member = customerService.getCurrentMember();
-        if(member==null){return responseError(new ResultVO(ResultEnum.TOKEN_EXPIRED));}
-        log.info("order info is ================>{}",goodsOrderInfoForm);
-        log.info("baseInfo===============>{}",member);
+        if (member == null) {
+            return responseError(new ResultVO(ResultEnum.TOKEN_EXPIRED));
+        }
+        log.info("order info is ================>{}", goodsOrderInfoForm);
+        log.info("baseInfo===============>{}", member);
         goodsOrderInfoForm.setFkCustomerGuid(member.getGuid());
-
-
-
         ResultVO resultVO = saveOrderInfoAndPayOrderInfo(goodsOrderInfoForm);
-        if(resultVO.getCode()==0){return responseSuccess(resultVO);}
+        if (resultVO.getCode() == 0) {
+            return responseSuccess(resultVO);
+        }
         return responseError(resultVO);
     }
 
+    @Autowired
+    private RedissonClient redissonClient;
+    //商品秒杀核心业务逻辑的处理-redisson的分布式锁
+
     public ResultVO saveOrderInfoAndPayOrderInfo(GoodsOrderInfoForm goodsOrderInfoForm) {
         int i = convertOrderInfoForm(goodsOrderInfoForm);
-        if(i==1){
-            String orderId = orderClient.saveFullOrderInfo(goodsOrderInfoForm);
-            if(orderId==null){return failure();}
+        if (i == 1) {
+            List<GoodsInfoForm> goodsList = goodsOrderInfoForm.getGoodsList();
+            GoodsInfoForm goodsInfoForm = goodsList.get(0);
+            String key = "dec_store_lock_" + goodsInfoForm.getGuid();
+            RLock lock = redissonClient.getLock(key);
+            boolean locked = lock.isLocked();
+            try {
+                //加锁 操作很类似Java的ReentrantLock机制
+                lock.lock();
+                String orderId = orderInfoService.saveFullOrderInfo(goodsOrderInfoForm);
+                if (orderId == null) {
+                    return failure();
+                }
+            } catch (Exception e) {
+                System.out.println(e.getMessage());
+                return failure();
+            } finally {
+                //解锁
+                lock.unlock();
+            }
             return success(goodsOrderInfoForm);
-        }else if(i==-1){
+        } else if (i == -1) {
             return new ResultVO(ResultEnum.GOODS_BUY_AUTH);
         }
         return failure();
     }
 
 
-
-
-    @ApiOperation(value = "取消订单",notes = "取消订单")
+    @ApiOperation(value = "取消订单", notes = "取消订单")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "orderId",value = "订单Id", dataType = "String")
+            @ApiImplicitParam(name = "orderId", value = "订单Id", dataType = "String")
     })
-    @ApiResponse(code =0,message = "操作成功")
+    @ApiResponse(code = 0, message = "操作成功")
     @PostMapping("/cancelOrderInfo")
     @AuthCarbonValidate
-    public ResponseBase cancelOrderInfo(@RequestParam("orderId") String orderId){
-        int i = orderClient.rollbackOrderInfo(orderId);
-        if(i>0){
+    public ResponseBase cancelOrderInfo(@RequestParam("orderId") String orderId) {
+        int i = orderInfoService.rollbackOrderInfo(orderId);
+        if (i > 0) {
             return responseResultSuccess();
         }
-       return responseResultFailure();
+        return responseResultFailure();
     }
 
-    @ApiOperation(value = "删除订单",notes = "删除订单")
+    @ApiOperation(value = "删除订单", notes = "删除订单")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "orderId",value = "订单Id", dataType = "String")
+            @ApiImplicitParam(name = "orderId", value = "订单Id", dataType = "String")
     })
-    @ApiResponse(code =0,message = "操作成功")
+    @ApiResponse(code = 0, message = "操作成功")
     @GetMapping("/delOrderInfo")
     @AuthCarbonValidate
-    public ResponseBase delOrderInfo(@RequestParam("orderId") String orderId){
+    public ResponseBase delOrderInfo(@RequestParam("orderId") String orderId) {
         ResultVO resultVO = delOrderInfoClient(orderId);
-        if(resultVO.getCode()==0){
+        if (resultVO.getCode() == 0) {
             return responseSuccess(resultVO);
         }
         return responseError(resultVO);
     }
-    public ResultVO delOrderInfoClient( String orderId) {
-        GoodsOrderInfoForm goodsOrderInfoForm = orderClient.getOrderInfoById(orderId);
-        if(Objects.nonNull(goodsOrderInfoForm)){
+
+    public ResultVO delOrderInfoClient(String orderId) {
+        GoodsOrderInfoForm goodsOrderInfoForm = orderInfoService.getOrderInfoById(orderId);
+        if (Objects.nonNull(goodsOrderInfoForm)) {
             Integer orderStatus = goodsOrderInfoForm.getOrderStatus();
-            if(orderStatus==1){
-                int i = orderClient.rollbackOrderInfo(orderId);
-                if(i==0){return failure();}
-            }else {
-                int j = orderClient.delOrderInfoByLogical(orderId);
-                if(j==0){return failure();}
+            if (orderStatus == 1) {
+                int i = orderInfoService.rollbackOrderInfo(orderId);
+                if (i == 0) {
+                    return failure();
+                }
+            } else {
+                int j = orderInfoService.delOrderInfoByLogical(orderId);
+                if (j == 0) {
+                    return failure();
+                }
             }
         }
         return success();
     }
 
 
-    @ApiOperation(value = "生成离线支付申请",notes = "生成离线支付申请,用于用户线下支付购碳资金")
+    @ApiOperation(value = "生成离线支付申请", notes = "生成离线支付申请,用于用户线下支付购碳资金")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "goodsOrderInfoForm",value = "订单信息", dataType = "GoodsOrderInfoForm")
+            @ApiImplicitParam(name = "goodsOrderInfoForm", value = "订单信息", dataType = "GoodsOrderInfoForm")
     })
-    @ApiResponse(code =0,message = "操作成功")
+    @ApiResponse(code = 0, message = "操作成功")
     @PostMapping("/saveOffLineApply")
     @AuthCarbonValidate
-    public ResponseBase saveOffLienPayApply(@RequestBody GoodsOrderInfoForm goodsOrderInfoForm){
+    public ResponseBase saveOffLienPayApply(@RequestBody GoodsOrderInfoForm goodsOrderInfoForm) {
         ResultVO resultVO = savePayApplyInfo(goodsOrderInfoForm);
-       if (resultVO.getCode()==0){
-           return responseSuccess(resultVO);
-       }
-       return responseError(resultVO);
+        if (resultVO.getCode() == 0) {
+            return responseSuccess(resultVO);
+        }
+        return responseError(resultVO);
     }
 
     public ResultVO savePayApplyInfo(GoodsOrderInfoForm goodsOrderInfoForm) {
-        String orderId =  goodsOrderInfoForm.getGuid();
-        if(null!=orderId && !"".equals(orderId)){
-            GoodsOrderInfoForm orderInfoForm = orderClient.getOrderInfoById(orderId);
+        String orderId = goodsOrderInfoForm.getGuid();
+        if (null != orderId && !"".equals(orderId)) {
+            GoodsOrderInfoForm orderInfoForm = orderInfoService.getOrderInfoById(orderId);
             Integer orderSatus = orderInfoForm.getOrderStatus();
-            if(orderSatus!=1){
+            if (orderSatus != 1) {
                 return new ResultVO(ResultEnum.ORDER_PAY_COMPLETE);
             }
-            int i= orderPayApplyService.savePayApplyInfo(goodsOrderInfoForm);
-            if(i==0){return failure();}
+            int i = orderPayApplyService.savePayApplyInfo(goodsOrderInfoForm);
+            if (i == 0) {
+                return failure();
+            }
             return success();
         }
         return failure();
@@ -223,40 +268,42 @@ public class OrderManagerController extends CarbonBaseController {
     @Autowired
     private OrderPayVoucherService orderPayVoucherService;
 
-    @ApiOperation(value = "生成离线支付凭证",notes = "生成离线支付凭证,用于线下支付后的凭证记录")
+    @ApiOperation(value = "生成离线支付凭证", notes = "生成离线支付凭证,用于线下支付后的凭证记录")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "orderPayVoucherForm",value = "凭证信息", dataType = "OrderPayVoucherForm")
+            @ApiImplicitParam(name = "orderPayVoucherForm", value = "凭证信息", dataType = "OrderPayVoucherForm")
     })
-    @ApiResponse(code =0,message = "操作成功")
+    @ApiResponse(code = 0, message = "操作成功")
     @PostMapping("/saveOffLineVoucher")
     @AuthCarbonValidate
-    public ResponseBase saveOffLienPayVoucher(@RequestBody OrderPayVoucherForm orderPayVoucherForm){
+    public ResponseBase saveOffLienPayVoucher(@RequestBody OrderPayVoucherForm orderPayVoucherForm) {
         int i = orderPayVoucherService.savePayVoucherInfoAndOrderInfo(orderPayVoucherForm);
-        if (i>0){
+        if (i > 0) {
             return responseResultSuccess();
         }
         return responseResultFailure();
     }
 
 
-    @ApiOperation(value = "快速购买某一农户下的可售商品",notes = "快速购买某一农户下的可售商品")
+    @ApiOperation(value = "快速购买某一农户下的可售商品", notes = "快速购买某一农户下的可售商品")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "orderQueryForm",value = "购买参数", dataType = "OrderQueryForm")
+            @ApiImplicitParam(name = "orderQueryForm", value = "购买参数", dataType = "OrderQueryForm")
     })
-    @ApiResponse(code =0,message = "操作成功")
+    @ApiResponse(code = 0, message = "操作成功")
     @PostMapping("/saveOrderForFarmer")
     @AuthCarbonValidate
-    public ResponseBase insertOrderInfoByFarmerId(@RequestBody OrderQueryForm orderQueryForm){
+    public ResponseBase insertOrderInfoByFarmerId(@RequestBody OrderQueryForm orderQueryForm) {
         BaseInfoDO baseInfoDO = this.initiSaveObject();
-        if(baseInfoDO==null){return responseError(new ResultVO(ResultEnum.TOKEN_EXPIRED));}
+        if (baseInfoDO == null) {
+            return responseError(new ResultVO(ResultEnum.TOKEN_EXPIRED));
+        }
         return null;
     }
 
-    @ApiOperation(value = "根据证书guid获取证书信息",notes = "根据证书guid获取证书信息")
+    @ApiOperation(value = "根据证书guid获取证书信息", notes = "根据证书guid获取证书信息")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "guid",value = "证书guid", dataType = "string")
+            @ApiImplicitParam(name = "guid", value = "证书guid", dataType = "string")
     })
-    @ApiResponse(code =0,message = "操作成功")
+    @ApiResponse(code = 0, message = "操作成功")
     @GetMapping("/getCredential")
     @AuthCarbonValidate
     public ResponseBase getCredentialInfo(@RequestParam(name = "guid") String guid) {
@@ -265,11 +312,11 @@ public class OrderManagerController extends CarbonBaseController {
         return responseResultSuccess(goodsCredentialInfoForm);
     }
 
-    @ApiOperation(value = "根据订单id获取证书信息",notes = "根据订单id获取证书信息")
+    @ApiOperation(value = "根据订单id获取证书信息", notes = "根据订单id获取证书信息")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "orderId",value = "订单guid", dataType = "string")
+            @ApiImplicitParam(name = "orderId", value = "订单guid", dataType = "string")
     })
-    @ApiResponse(code =0,message = "操作成功")
+    @ApiResponse(code = 0, message = "操作成功")
     @GetMapping("/getCredentialByOrderId")
     @AuthCarbonValidate
     public ResponseBase getCredentialByOrderId(@RequestParam(name = "orderId") String orderId) {
@@ -280,20 +327,21 @@ public class OrderManagerController extends CarbonBaseController {
 
     /**
      * 转换客户订单信息,用于生成客户订单(含快照信息)
+     *
      * @param goodsOrderInfoForm
      * @return
      */
-    private int convertOrderInfoForm(GoodsOrderInfoForm goodsOrderInfoForm){
+    private int convertOrderInfoForm(GoodsOrderInfoForm goodsOrderInfoForm) {
         //生成订单信息的类别
         List<GoodsInfoForm> goodsList = goodsOrderInfoForm.getGoodsList();
         CustomerInfoForm customerInfoForm = customerInfoService.getCustomerInfoById(goodsOrderInfoForm.getFkCustomerGuid());
-        if(Objects.nonNull(customerInfoForm)){
+        if (Objects.nonNull(customerInfoForm)) {
             Integer customerType = customerInfoForm.getCustomerType();
-            String  typeName = "个人账户";
-            if(customerType==2){
-                typeName="履约企业";
-            }else if(customerType==3) {
-                typeName="普通履约企业";
+            String typeName = "个人账户";
+            if (customerType == 2) {
+                typeName = "履约企业";
+            } else if (customerType == 3) {
+                typeName = "普通履约企业";
             }
             goodsOrderInfoForm.setCustomerName(customerInfoForm.getCustomerName());
             goodsOrderInfoForm.setCustomerType(typeName);
@@ -302,17 +350,19 @@ public class OrderManagerController extends CarbonBaseController {
             List<GoodsOrderDetailForm> goodsOrderDetailList = Lists.newArrayList();
             Double amountMoney = 0d;
             Double carbonAmount = 0d;
-            if(null!=goodsList && goodsList.size()>0){
-                for (GoodsInfoForm bean:goodsList) {
+            if (null != goodsList && goodsList.size() > 0) {
+                for (GoodsInfoForm bean : goodsList) {
                     BigDecimal carbon = bean.getCarbonSkin();
                     String goodsId = bean.getGuid();
-                    Integer goodsUse =Integer.valueOf(bean.getGoodsUse()) ;
+                    Integer goodsUse = Integer.valueOf(bean.getGoodsUse());
                     //判断用户类型是否超出购买权限,如果超出购买权限将不允许直接购买
-                    if(customerType==1 && goodsUse==1){
+                    if (customerType == 1 && goodsUse == 1) {
                         return -1;
                     }
                     //有非法商品数量,不生成订单详情
-                    if(carbon.intValue()==0 || Objects.isNull(carbon)){continue;}
+                    if (carbon.intValue() == 0 || Objects.isNull(carbon)) {
+                        continue;
+                    }
                     GoodsOrderDetailForm detailForm = new GoodsOrderDetailForm();
                     GoodsInfo goodsInfo = goodsInfoService.queryByPrimaryKey(goodsId);
                     BigDecimal detailMoney = goodsInfo.getPrice().multiply(carbon);
@@ -321,8 +371,8 @@ public class OrderManagerController extends CarbonBaseController {
                     detailForm.setSaleNum(carbon);
                     detailForm.setGoodsName(goodsInfo.getGoodsName());
                     detailForm.setGoodsPrice(goodsInfo.getPrice());
-                    carbonAmount+=carbon.doubleValue();
-                    amountMoney+=detailMoney.doubleValue();
+                    carbonAmount += carbon.doubleValue();
+                    amountMoney += detailMoney.doubleValue();
                     goodsOrderDetailList.add(detailForm);
                 }
                 goodsOrderInfoForm.setOrderAmount(BigDecimal.valueOf(amountMoney));

+ 2 - 0
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/dao/GoodsOrderInfoMapper.java

@@ -42,4 +42,6 @@ public interface GoodsOrderInfoMapper extends BaseMapper<GoodsOrderInfo,String>
      * @return
      */
     int updateOrderBelongInfo(@Param("oldId") String oldCustomerId ,@Param("newId") String newCustomerId);
+
+    OrderInfoBO info(@Param("guid")String guid);
 }

+ 4 - 0
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/OrderDetailInfoService.java

@@ -3,6 +3,8 @@ package com.hcloud.microserver.h5.service;
 import com.hcloud.microserver.commoncore.base.BaseServie;
 import com.hcloud.microserver.facade.carbon.entity.GoodsOrderDetail;
 import com.hcloud.microserver.facade.carbon.forms.GoodsOrderDetailForm;
+import com.hcloud.microserver.facade.carbon.forms.GoodsOrderInfoForm;
+import com.hcloud.microserver.h5.bo.OrderInfoBO;
 
 import java.util.List;
 
@@ -25,4 +27,6 @@ public interface OrderDetailInfoService extends BaseServie<GoodsOrderDetailForm,
     int batchSaveOrderDetailByList(List<GoodsOrderDetailForm> batchList);
 
     List<GoodsOrderDetail> findByGoodsOrderInfoGuid(String goodsOrderInfoGuid);
+
+    GoodsOrderInfoForm info(String guid);
 }

+ 91 - 65
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/impl/CustomerInfoServiceImpl.java

@@ -71,8 +71,8 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
     @Override
     public PageInfo searchCustomerByPage(CustomerInfoForm customerInfoForm) {
         PageBean pageBean = new PageBean(customerInfoForm);
-        PageHelper.startPage(customerInfoForm.getPageNo(),customerInfoForm.getPageSize());
-        List<CustomerInfoBO> list =  customerInfoMapper.searchCustomerByPage(pageBean);
+        PageHelper.startPage(customerInfoForm.getPageNo(), customerInfoForm.getPageSize());
+        List<CustomerInfoBO> list = customerInfoMapper.searchCustomerByPage(pageBean);
         return new PageInfo(list);
     }
 
@@ -85,18 +85,18 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
     @Override
     public CustomerInfoForm getCustomerInfoById(String customerId) {
         CustomerInfo customerInfo = customerInfoMapper.selectByPrimaryKey(customerId);
-        CustomerInfoForm customerInfoForm = BeanCopyUtil.convertBean(customerInfo,CustomerInfoForm.class);
-        log.info("customerInfoForm==========================>{}",customerInfoForm);
+        CustomerInfoForm customerInfoForm = BeanCopyUtil.convertBean(customerInfo, CustomerInfoForm.class);
+        log.info("customerInfoForm==========================>{}", customerInfoForm);
         //统计爱用用户业务信息
         CustomerInfoBO infoBO = customerInfoMapper.getCustomerStatisticalInfo(customerId);
-        if(null!=infoBO){
+        if (null != infoBO) {
             customerInfoForm.setCarbonAmount(infoBO.getCarbonAmount());
             customerInfoForm.setGoodsNum(infoBO.getGoodsNum());
             customerInfoForm.setFarmerNum(infoBO.getFarmerNum());
         }
         //企业认证信息
         CustomerCompanyInfoForm companyInfoForm = customerCompanyInfoService.getCustomerCompanyInfoByCustomerId(customerId);
-        if(companyInfoForm!=null){
+        if (companyInfoForm != null) {
             customerInfoForm.setCustomerCompanyInfoForm(companyInfoForm);
         }
         return customerInfoForm;
@@ -111,8 +111,10 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
     @Override
     public CustomerInfoForm getCustomerInfoByAccount(String account) {
         CustomerInfo customerInfo = customerInfoMapper.searchCustomerByAccount(account);
-        if(customerInfo==null){return null;}
-        return BeanCopyUtil.convertBean(customerInfo,CustomerInfoForm.class);
+        if (customerInfo == null) {
+            return null;
+        }
+        return BeanCopyUtil.convertBean(customerInfo, CustomerInfoForm.class);
     }
 
     /**
@@ -123,9 +125,11 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
      */
     @Override
     public CustomerInfoForm getCustomerInfoByInfo(String queryStr) {
-        CustomerInfo customerInfo =  customerInfoMapper.getCustomerByInfo(queryStr);
-        if(Objects.isNull(customerInfo)){return null;}
-        return BeanCopyUtil.convertBean(customerInfo,CustomerInfoForm.class);
+        CustomerInfo customerInfo = customerInfoMapper.getCustomerByInfo(queryStr);
+        if (Objects.isNull(customerInfo)) {
+            return null;
+        }
+        return BeanCopyUtil.convertBean(customerInfo, CustomerInfoForm.class);
     }
 
     /**
@@ -137,10 +141,12 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
      */
     @Override
     public CustomerInfoForm getCustomerInfoByChannelInfo(Integer channelType, String threeCode) {
-        CustomerInfoBO customerInfo =customerInfoMapper.getCustomerByThreeCode(channelType,threeCode);
-        log.info("===================>{}",customerInfo);
-        if(customerInfo==null){return new CustomerInfoForm();}
-        return BeanCopyUtil.convertBean(customerInfo,CustomerInfoForm.class);
+        CustomerInfoBO customerInfo = customerInfoMapper.getCustomerByThreeCode(channelType, threeCode);
+        log.info("===================>{}", customerInfo);
+        if (customerInfo == null) {
+            return new CustomerInfoForm();
+        }
+        return BeanCopyUtil.convertBean(customerInfo, CustomerInfoForm.class);
     }
 
     /**
@@ -154,10 +160,12 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
     public int saveCustomerInfoByChannelInfo(CustomerInfoForm customerInfoForm) {
         //保存用户信息
         int i = this.saveSelective(customerInfoForm);
-        if(i==0){throw new RuntimeException();}
+        if (i == 0) {
+            throw new RuntimeException();
+        }
         //保存用户渠道信息
         Integer channelType = customerInfoForm.getLoginType();
-        if(channelType!=null){
+        if (channelType != null) {
             CustomerChannel customerChannel = new CustomerChannel();
             customerChannel.setGuid(GetUUID.getUUID());
             customerChannel.setFkCustomerId(customerInfoForm.getGuid());
@@ -192,28 +200,32 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
     @Transactional(rollbackFor = Exception.class)
     @Override
     public int updateCustomerInfoForWeChat(CustomerInfoForm customerInfoForm) {
-        int i=this.modifyByPrimaryKeySelective(customerInfoForm);
-        if(i>0){
-           CustomerChannel customerChannel =
-                   customerChannelMapper.getChannelInfoByCustomerId(customerInfoForm.getGuid(),customerInfoForm.getChannelType());
-           if(Objects.isNull(customerChannel)){
-               CustomerChannel innerChannel = new CustomerChannel();
-               innerChannel.setGuid(GetUUID.getUUID());
-               innerChannel.setFkCustomerId(customerInfoForm.getGuid());
-               innerChannel.setChannelName("weChat");
-               innerChannel.setChannelKeywordOne(customerInfoForm.getUnionId());
-               innerChannel.setChannelKeywordTwo(customerInfoForm.getWxId());
-               innerChannel.setChannelType(1);
-               int h = customerChannelMapper.insertSelective(innerChannel);
-               if(h==0){throw new RuntimeException();}
-               return h;
-           }else{
-               customerChannel.setChannelKeywordOne(customerInfoForm.getUnionId()==null?"":customerInfoForm.getUnionId());
-               customerChannel.setChannelKeywordTwo(customerInfoForm.getWxId()==null?"":customerInfoForm.getWxId());
-               int j = customerChannelMapper.updateByPrimaryKeySelective(customerChannel);
-               if(j==0){throw new RuntimeException();}
-               return i;
-           }
+        int i = this.modifyByPrimaryKeySelective(customerInfoForm);
+        if (i > 0) {
+            CustomerChannel customerChannel =
+                    customerChannelMapper.getChannelInfoByCustomerId(customerInfoForm.getGuid(), customerInfoForm.getChannelType());
+            if (Objects.isNull(customerChannel)) {
+                CustomerChannel innerChannel = new CustomerChannel();
+                innerChannel.setGuid(GetUUID.getUUID());
+                innerChannel.setFkCustomerId(customerInfoForm.getGuid());
+                innerChannel.setChannelName("weChat");
+                innerChannel.setChannelKeywordOne(customerInfoForm.getUnionId());
+                innerChannel.setChannelKeywordTwo(customerInfoForm.getWxId());
+                innerChannel.setChannelType(1);
+                int h = customerChannelMapper.insertSelective(innerChannel);
+                if (h == 0) {
+                    throw new RuntimeException();
+                }
+                return h;
+            } else {
+                customerChannel.setChannelKeywordOne(customerInfoForm.getUnionId() == null ? "" : customerInfoForm.getUnionId());
+                customerChannel.setChannelKeywordTwo(customerInfoForm.getWxId() == null ? "" : customerInfoForm.getWxId());
+                int j = customerChannelMapper.updateByPrimaryKeySelective(customerChannel);
+                if (j == 0) {
+                    throw new RuntimeException();
+                }
+                return i;
+            }
         }
         return 0;
     }
@@ -229,17 +241,25 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
     @Override
     public int changeCustomerOrderInfo(String oldCustomerId, String newCustomerId) {
         //TODO 更新订单信息
-        int i = goodsOrderInfoMapper.updateOrderBelongInfo(oldCustomerId,newCustomerId);
-        if(i==0){throw new RuntimeException();}
+        int i = goodsOrderInfoMapper.updateOrderBelongInfo(oldCustomerId, newCustomerId);
+        if (i == 0) {
+            throw new RuntimeException();
+        }
         //TODO 更新订单支付流水信息
-        int j = goodsPayOrderMapper.updatePayOrderBelongInfo(oldCustomerId,newCustomerId);
-        if(j==0){throw new RuntimeException();}
+        int j = goodsPayOrderMapper.updatePayOrderBelongInfo(oldCustomerId, newCustomerId);
+        if (j == 0) {
+            throw new RuntimeException();
+        }
         //TODO 更新离线支付申请
-        int h = orderPayApplyMapper.updateOrderPayApplyBelongInfo(oldCustomerId,newCustomerId);
-        if(h==0){throw new RuntimeException();}
+        int h = orderPayApplyMapper.updateOrderPayApplyBelongInfo(oldCustomerId, newCustomerId);
+        if (h == 0) {
+            throw new RuntimeException();
+        }
         //TODO 更新离线支付凭证信息
-        int k = orderPayVoucherMapper.updatePayVoucherBelongInfo(oldCustomerId,newCustomerId);
-        if(k==0){throw new RuntimeException();}
+        int k = orderPayVoucherMapper.updatePayVoucherBelongInfo(oldCustomerId, newCustomerId);
+        if (k == 0) {
+            throw new RuntimeException();
+        }
         return i;
     }
 
@@ -257,21 +277,27 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
         customerInfo.setGuid(customerId);
         customerInfo.setPhone(phone);
         int i = this.modifyByPrimaryKeySelective(customerInfo);
-        if(i==0){throw new RuntimeException();}
+        if (i == 0) {
+            throw new RuntimeException();
+        }
         //查询手机号码是否已经注册为用户
         CustomerInfoForm customerInfoForm = this.getCustomerInfoByInfo(phone);
-        if(Objects.nonNull(customerInfoForm) && !"".equals(customerInfoForm.getGuid())){
+        if (Objects.nonNull(customerInfoForm) && !"".equals(customerInfoForm.getGuid())) {
             //更新(订单信息、支付订单信息、离线支付申请,离线支付凭证)
             String oldCustomerId = customerInfoForm.getGuid();
-            int j =this.changeCustomerOrderInfo(oldCustomerId,customerId);
-            if(j==0){throw new RuntimeException();}
+            int j = this.changeCustomerOrderInfo(oldCustomerId, customerId);
+            if (j == 0) {
+                throw new RuntimeException();
+            }
             //逻辑删除老用户信息
             CustomerInfoForm oldInfo = new CustomerInfoForm();
             oldInfo.setGuid(oldCustomerId);
             oldInfo.setState(0);
             oldInfo.setModifiedTime(new Date());
-            int k =this.modifyByPrimaryKeySelective(oldInfo);
-            if(k==0){throw new RuntimeException();}
+            int k = this.modifyByPrimaryKeySelective(oldInfo);
+            if (k == 0) {
+                throw new RuntimeException();
+            }
         }
         return i;
     }
@@ -279,7 +305,7 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
     @Override
     public Map<String, String> wxlogin(MyWxMpUser wxMpUser) {
         String guid = getString(wxMpUser);
-       return getToken(guid);
+        return getToken(guid);
     }
 
     @Autowired
@@ -291,13 +317,13 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
     @Value("${jwt.tokenHead}")
     private String tokenHead;
 
-    private  Map<String, String> getToken(String guid) {
+    private Map<String, String> getToken(String guid) {
 
         CustomerInfoForm customerInfoById = getCustomerInfoById(guid);
 
         CustomerDetails customerInfo = new CustomerDetails(customerInfoById);
 
-        if (customerInfo == null){
+        if (customerInfo == null) {
             Asserts.fail("登录失败");
         }
         UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(customerInfo, null, customerInfo.getAuthorities());
@@ -320,14 +346,14 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
         String nickname = wxMpUser.getNickname();
         String headImgUrl = wxMpUser.getHeadImgUrl();
         Integer sex = wxMpUser.getSex();
-        if(null == customerInfo){
+        if (null == customerInfo) {
             customerInfo = new CustomerInfo();
             //设置唯一标识
             customerInfo.setGuid(GetUUID.getUUID());
             customerInfo.setUnionId(unionId);
             customerInfo.setWxId(openId);
             customerInfo.setSex(sex);
-            if(null!=phone){
+            if (null != phone) {
                 customerInfo.setPhone(phone);
             }
             customerInfo.setNickName(nickname);
@@ -336,11 +362,11 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
             //状态设置为可用
             customerInfo.setIsEnable(1);
             customerInfoMapper.insertSelective(customerInfo);
-        }else{
+        } else {
             customerInfo.setUnionId(unionId);
             customerInfo.setWxId(openId);
             customerInfo.setSex(sex);
-            if(null!=phone){
+            if (null != phone) {
                 customerInfo.setPhone(phone);
             }
             customerInfo.setNickName(nickname);
@@ -359,26 +385,26 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
     @Override
     public int save(CustomerInfoForm record) {
         record.setGuid(GetUUID.getUUID());
-        CustomerInfo customerInfo = BeanCopyUtil.convertBean(record,CustomerInfo.class);
+        CustomerInfo customerInfo = BeanCopyUtil.convertBean(record, CustomerInfo.class);
         return customerInfoMapper.insert(customerInfo);
     }
 
     @Override
     public int saveSelective(CustomerInfoForm record) {
         record.setGuid(GetUUID.getUUID());
-        CustomerInfo customerInfo = BeanCopyUtil.convertBean(record,CustomerInfo.class);
+        CustomerInfo customerInfo = BeanCopyUtil.convertBean(record, CustomerInfo.class);
         return customerInfoMapper.insertSelective(customerInfo);
     }
 
     @Override
     public CustomerInfoForm queryByPrimaryKey(String guid) {
         CustomerInfo customerInfo = customerInfoMapper.selectByPrimaryKey(guid);
-        return BeanCopyUtil.convertBean(customerInfo,CustomerInfoForm.class);
+        return BeanCopyUtil.convertBean(customerInfo, CustomerInfoForm.class);
     }
 
     @Override
     public int modifyByPrimaryKeySelective(CustomerInfoForm record) {
-        CustomerInfo customerInfo = BeanCopyUtil.convertBean(record,CustomerInfo.class);
+        CustomerInfo customerInfo = BeanCopyUtil.convertBean(record, CustomerInfo.class);
         return customerInfoMapper.updateByPrimaryKeySelective(customerInfo);
     }
 
@@ -390,7 +416,7 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
 
     @Override
     public int modifyByPrimaryKey(CustomerInfoForm record) {
-        CustomerInfo customerInfo = BeanCopyUtil.convertBean(record,CustomerInfo.class);
+        CustomerInfo customerInfo = BeanCopyUtil.convertBean(record, CustomerInfo.class);
         return customerInfoMapper.updateByPrimaryKey(customerInfo);
     }
 

+ 24 - 0
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/impl/OrderDetailInfoServiceImpl.java

@@ -1,12 +1,17 @@
 package com.hcloud.microserver.h5.service.impl;
 
+import com.hcloud.microserver.facade.carbon.forms.GoodsOrderInfoForm;
 import com.hcloud.microserver.h5.bo.OrderDetailInfoBO;
+import com.hcloud.microserver.h5.bo.OrderInfoBO;
 import com.hcloud.microserver.h5.dao.GoodsOrderDetailMapper;
+import com.hcloud.microserver.h5.dao.GoodsOrderInfoMapper;
 import com.hcloud.microserver.h5.service.OrderDetailInfoService;
 import com.hcloud.microserver.commoncore.util.BeanCopyUtil;
 import com.hcloud.microserver.commoncore.util.GetUUID;
 import com.hcloud.microserver.facade.carbon.entity.GoodsOrderDetail;
 import com.hcloud.microserver.facade.carbon.forms.GoodsOrderDetailForm;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -21,6 +26,13 @@ public class OrderDetailInfoServiceImpl implements OrderDetailInfoService {
     @Resource
     private GoodsOrderDetailMapper goodsOrderDetailMapper;
 
+    @Autowired
+    private GoodsOrderInfoMapper goodsOrderInfoMapper;
+
+    @Autowired
+    private OrderDetailInfoService orderDetailInfoService;
+
+
     /**
      * 通过订单Id查询订单明细
      *
@@ -98,4 +110,16 @@ public class OrderDetailInfoServiceImpl implements OrderDetailInfoService {
         GoodsOrderDetail goodsOrderDetail = BeanCopyUtil.convertBean(record,GoodsOrderDetail.class);
         return goodsOrderDetailMapper.updateByPrimaryKey(goodsOrderDetail);
     }
+
+
+    @Override
+    public GoodsOrderInfoForm info(String guid) {
+        OrderInfoBO info = goodsOrderInfoMapper.info(guid);
+        GoodsOrderInfoForm goodsOrderInfoForm=new GoodsOrderInfoForm();
+        BeanUtils.copyProperties(info,goodsOrderInfoForm);
+        List<GoodsOrderDetailForm> detailFormList = orderDetailInfoService.getOrderDetailListByOrderId(guid);
+        goodsOrderInfoForm.setGoodsOrderDetailForm(detailFormList);
+        return goodsOrderInfoForm;
+    }
+
 }

+ 4 - 1
carbon-h5/carbon-h5-service/src/main/resources/bootstrap.yml

@@ -19,4 +19,7 @@ spring:
         prefix: carbon-h5
         file-extension: yml
         # 公共配置文件
-        shared-dataids: carbon-common.yml
+        shared-dataids: carbon-common.yml
+myredis:
+  address: redis://${spring.redis.host}:${spring.redis.port}
+  passord: ${spring.redis.password}

+ 17 - 0
carbon-h5/carbon-h5-service/src/main/resources/com/hcloud/microserver/h5/dao/GoodsOrderInfoMapper.xml

@@ -297,4 +297,21 @@
           set fk_customer_guid = #{newId}
      where fk_customer_guid = #{oldId}
     </update>
+
+
+    <select id="info" resultType="com.hcloud.microserver.h5.bo.OrderInfoBO">
+        SELECT
+        aa.guid,
+        aa.order_no AS orderNo,
+        aa.create_time AS createTime,
+        aa.order_status AS orderStatus,
+        aa.order_amount AS orderAmount,
+        aa.order_carbon_amount AS orderCarbonAmount,
+        aa.pay_no AS payNo
+        FROM
+        t_goods_order_info aa
+        WHERE
+        aa.state = 1
+        AND aa.guid = #{guid}
+    </select>
 </mapper>

+ 19 - 0
common-core/src/main/java/com/hcloud/microserver/commoncore/base/BaseController.java

@@ -109,6 +109,25 @@ public class BaseController {
         return responseBase;
     }
 
+    /**
+     * 操作成功后,返回结果(前后端分离)
+     *
+     * @param
+     * @return
+     */
+    protected ResponseBase resultVOSuccess(Object data) {
+        ResultVO resultVO=new ResultVO();
+        resultVO.setCode(200);
+        resultVO.setData(data);
+        ResponseBase responseBase = new ResponseBase(resultVO.getData());
+        RetHead retHead = new RetHead();
+        retHead.setErrCode(resultVO.getCode().shortValue());
+        retHead.setErrMsg(resultVO.getMsg());
+        retHead.setTotal(resultVO.getCount());
+        responseBase.setRetHead(retHead);
+        return responseBase;
+    }
+
     protected ResponseBase responseSuccess(PageInfo pageInfo) {
         if (Objects.isNull(pageInfo)){ return responseSuccess(success(null, 0));}
         return responseSuccess(success(pageInfo.getList(),pageInfo.getTotal()));