johnswang
2022-01-15 739c878977416f838ab591af58c20ab1378c2c30
src/com/yc/sdk/shopping/action/Cart.java
@@ -855,17 +855,20 @@
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        SettingEntity settingEntity = null;
        long ms = System.currentTimeMillis();
        try {
           System.out.println(getClass() + " 10 " + (System.currentTimeMillis() - ms));
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);
            System.out.println(getClass() + " 20 " + (System.currentTimeMillis() - ms));
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());// 切换数据源
            settingEntity = settingIfc.getSettingEntity(request);
            System.out.println(getClass() + " 30 " + (System.currentTimeMillis() - ms));
            //取网店 shopcccode
            ShopCcCodeEntity shopCcCodeEntity = ShopCcCode.getShopCcCode(settingEntity, request);
            System.out.println(getClass() + " 40 " + (System.currentTimeMillis() - ms));
            // 必录检查
            errJson = this.checkRequired(params, matCode, hostUrl, wxQueryString, isMoblieBrowser);
            System.out.println(getClass() + " 50 " + (System.currentTimeMillis() - ms));
            if (errJson != null && errJson.has("error")) {
                this.printJson(response, errJson.toString());
                return;
@@ -893,7 +896,7 @@
                return;
            }
            System.out.println(getClass() + " 60 " + (System.currentTimeMillis() - ms));
            boolean found = false;
            for (String key : params.keySet()) {
                if (!key.startsWith("option")) {
@@ -913,7 +916,7 @@
            if (found) {
                optionStrJson = json.toString();
            }
            System.out.println(getClass() + " 70 " + (System.currentTimeMillis() - ms));
            CartEntity cart = new CartEntity();
            cart.setMatCode(matCode);
            cart.setCltCode(cltCode);
@@ -968,8 +971,11 @@
                    .setSkuId10(skuId10 == null || "".equals(skuId10) ? null : Integer.parseInt(skuId10));
            cart.setShopCcCode(shopCcCodeEntity.getShopCcCode());
            System.out.println(getClass() + " 80 " + (System.currentTimeMillis() - ms));
            List<CartEntity> cartList = cartIfc.addToCartAndReturnCartList(cart);
            System.out.println(getClass() + " 90 " + (System.currentTimeMillis() - ms));
            CartEntity cartEntity = cartList != null&& cartList.size()>0?cartList.get(0):null;
            System.out.println(getClass() + " 100 " + (System.currentTimeMillis() - ms));
            if (cartEntity != null) {
                //立即下单
                String selectedCattIds = (String) session.getAttribute(SettingKey.CHECKBOX);
@@ -985,8 +991,10 @@
//            cartIfc.refrshCart(cartId, cart.getCltCode());
//            }
            //List<CartEntity> cartList = cartIfc.getCartList(userCode, sessionId, cart.getOpenId(), cltCode, shopCcCodeEntity.getShopCcCode()); // 重新取一次数,确保购物车显示正确
            System.out.println(getClass() + " 110 " + (System.currentTimeMillis() - ms));
            CurrencyEntity currencyEntity = new CurrencyEntity(request);
            System.out.println(getClass() + " 120 " + (System.currentTimeMillis() - ms));
            /******** 购物车 开始清单输出 *************/
            DecimalFormat df = new DecimalFormat("0.00");
            //double selectTotalAmount = 0;  //给 footer.jsp 页面使用,用于赋初值
@@ -1005,6 +1013,7 @@
            //组装 json array 输出
            JsonArray cartListJsonArray = this.getCartJsonArray(request, settingEntity, cartList, currencyEntity, dataSourceEntity);
            System.out.println(getClass() + " 130 " + (System.currentTimeMillis() - ms));
            json.add("list", cartListJsonArray);
            json.addProperty("SelectTotalAmount", df.format(cartEntity==null?0:cartEntity.getSelectedTotalAmount())) ; //   df.format(selectTotalAmount));
@@ -1017,11 +1026,12 @@
            //double totalWeight = (list!=null&&list.size()>0?list.get(0).getTotalWeight():0);
            double totalAmount = cartEntity==null?0:cartEntity.getTotalAmount(); 
            System.out.println(getClass() + " 140 " + (System.currentTimeMillis() - ms));
            //取刚才加入购物车的物料信息
            List<CartEntity> matCodeEntityList = cartList.stream().filter((CartEntity c) -> c.getCartId().equals(cartEntity.getCurrentCartId())).collect(Collectors.toList());
            CartEntity cartEntityForMatCode = matCodeEntityList != null && matCodeEntityList.size() > 0 ? matCodeEntityList.get(0) : null;
            System.out.println(getClass() + " 150 " + (System.currentTimeMillis() - ms));
            json.addProperty("success", "成功添加商品 <a href=\"" + hostUrl + SettingKey.getMatCodeUrl(null, matCode, isMoblieBrowser)
                    + (wxQueryString == null || "".equals(wxQueryString) ? "" : "&" + wxQueryString) + "\">"
                    + (cartEntityForMatCode == null ? "" : (settingEntity.isShowMatName() ? cartEntityForMatCode.getMatName() : "商品")) + "</a>到您的 <a href=\"" + hostUrl
@@ -1046,7 +1056,9 @@
            json.addProperty("CartQuantitySumForMatCode", cartEntityForMatCode!=null?cartEntityForMatCode.getCartQuantitySumForMatCode():0);
            json.addProperty("CartQuantity", cartEntityForMatCode!=null?cartEntityForMatCode.getQuantity():0);  //当前 cartid 的购物车数量
            
            System.out.println(getClass() + " 160 " + (System.currentTimeMillis() - ms));
            this.printJson(response, json.toString());
            System.out.println(getClass() + " 170 " + (System.currentTimeMillis() - ms));
            return;
        } catch (Exception e) {
            e.printStackTrace();