wuxw 1 год назад
Родитель
Сommit
c85cb58101

+ 21 - 0
java110-utils/src/main/java/com/java110/utils/util/UrlParamToJsonUtil.java

@@ -3,6 +3,8 @@ package com.java110.utils.util;
 import com.alibaba.fastjson.JSONException;
 import com.alibaba.fastjson.JSONObject;
 
+import java.net.URLEncoder;
+
 public class UrlParamToJsonUtil {
 
     public static JSONObject getJson(String paramStr) {
@@ -30,4 +32,23 @@ public class UrlParamToJsonUtil {
         }
         return obj;
     }
+
+    public static String jsonToUrlParam(JSONObject json)  {
+        StringBuilder params = new StringBuilder();
+        json.keySet().forEach(key -> {
+            String value = json.getString(key);
+            try {
+                String encodedKey = URLEncoder.encode(key, "UTF-8");
+                String encodedValue = URLEncoder.encode(value, "UTF-8");
+                params.append(encodedKey).append("=").append(encodedValue).append("&");
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+        });
+        // 删除最后一个'&'
+        if (params.length() > 0) {
+            params.deleteCharAt(params.length() - 1);
+        }
+        return params.toString();
+    }
 }

+ 6 - 6
service-api/src/main/java/com/java110/api/configuration/ServiceConfiguration.java

@@ -70,13 +70,13 @@ public class ServiceConfiguration {
 //        exclusions.append("/app/room.queryRooms,");
         exclusions.append("/app/room.queryRoomsByApp,");
         exclusions.append("/app/productCategory/queryMainCategoryAllGoods,");
-        exclusions.append("/app/productCategory/queryMainCategory,");
+        exclusions.append("/app/mall.queryMainCategory,");
 
-        exclusions.append("/app/product.queryPhoneMainCategoryProduct,");
+        exclusions.append("/app/mall.queryPhoneMainCategoryProduct,");
 
         exclusions.append("/app/shop/queryShopCommunity,");
-        exclusions.append("/app/shopType/queryShopType,");
-        exclusions.append("/app/housekeepingType/queryHousekeepingType,");
+        exclusions.append("/app/mall.queryShopType,");
+        exclusions.append("/app/mall.queryHousekeepingType,");
         exclusions.append("/app/couponUser.listCouponUser,");
         exclusions.append("/app/machine.customCarInOutCmd,");
         exclusions.append("/callComponent/propertyRightRegistration.savePropertyRightRegistration,");
@@ -96,11 +96,11 @@ public class ServiceConfiguration {
         exclusions.append("/app/reserve.listReserveCatalog,");
         exclusions.append("/app/reserve.listReserveGoods,");
         exclusions.append("/app/reserve.listReserveParams,");
-        exclusions.append("/app/productGroup.listProductGroup,");//拼团商品
+        exclusions.append("/app/mall.listProductGroup,");//拼团商品
         exclusions.append("/app/product/queryGroupProduct,");//拼团商品
         exclusions.append("/app/product/querySeckillProduct,");//秒杀商品
 
-        exclusions.append("/app/productSeckill.listProductSeckill,");//秒杀商品
+        exclusions.append("/app/mall.listProductSeckill,");//秒杀商品
         exclusions.append("/app/system.listRegisterProtocol,");//查询注册信息
         exclusions.append("/app/chargeMachine.listChargeMachine,");//查询注册信息
         exclusions.append("/app/chargeMachine.listChargeMachinePort,");//查询充电桩

+ 37 - 0
service-job/src/main/java/com/java110/job/cmd/mall/ListProductGroupCmd.java

@@ -0,0 +1,37 @@
+package com.java110.job.cmd.mall;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.job.mall.ISendMall;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.UrlParamToJsonUtil;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.text.ParseException;
+
+@Java110Cmd(serviceCode = "mall.listProductGroup")
+public class ListProductGroupCmd extends Cmd {
+
+    @Autowired
+    private ISendMall sendMallImpl;
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        String mallSwitch = MappingCache.getValue("MALL", "MALL_SWITCH");
+        if (!"ON".equals(mallSwitch)) {
+            throw new CmdException("商城系统未部署");
+        }
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        String param = UrlParamToJsonUtil.jsonToUrlParam(reqJson);
+        ResultVo resultVo = sendMallImpl.get("/mall/api/productGroup.listProductGroup?" + param);
+
+        context.setResponseEntity(ResultVo.createResponseEntity(resultVo));
+    }
+}

+ 36 - 0
service-job/src/main/java/com/java110/job/cmd/mall/ListProductSeckillCmd.java

@@ -0,0 +1,36 @@
+package com.java110.job.cmd.mall;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.job.mall.ISendMall;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.UrlParamToJsonUtil;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.text.ParseException;
+
+@Java110Cmd(serviceCode = "mall.listProductSeckill")
+public class ListProductSeckillCmd extends Cmd {
+    @Autowired
+    private ISendMall sendMallImpl;
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        String mallSwitch = MappingCache.getValue("MALL", "MALL_SWITCH");
+        if (!"ON".equals(mallSwitch)) {
+            throw new CmdException("商城系统未部署");
+        }
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        String param = UrlParamToJsonUtil.jsonToUrlParam(reqJson);
+        ResultVo resultVo = sendMallImpl.get("/mall/api/productSeckill.listProductSeckill?" + param);
+
+        context.setResponseEntity(ResultVo.createResponseEntity(resultVo));
+    }
+}

+ 39 - 0
service-job/src/main/java/com/java110/job/cmd/mall/QueryHousekeepingTypeCmd.java

@@ -0,0 +1,39 @@
+package com.java110.job.cmd.mall;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.job.mall.ISendMall;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.UrlParamToJsonUtil;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.text.ParseException;
+
+
+@Java110Cmd(serviceCode = "mall.queryHousekeepingType")
+public class QueryHousekeepingTypeCmd extends Cmd {
+
+    @Autowired
+    private ISendMall sendMallImpl;
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        String mallSwitch = MappingCache.getValue("MALL", "MALL_SWITCH");
+        if (!"ON".equals(mallSwitch)) {
+            throw new CmdException("商城系统未部署");
+        }
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        String param = UrlParamToJsonUtil.jsonToUrlParam(reqJson);
+        ResultVo resultVo = sendMallImpl.get("/mall/api/housekeepingType.queryHousekeepingType?" + param);
+
+        context.setResponseEntity(ResultVo.createResponseEntity(resultVo));
+    }
+}

+ 38 - 0
service-job/src/main/java/com/java110/job/cmd/mall/QueryMainCategoryCmd.java

@@ -0,0 +1,38 @@
+package com.java110.job.cmd.mall;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.job.mall.ISendMall;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.UrlParamToJsonUtil;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.text.ParseException;
+
+@Java110Cmd(serviceCode = "mall.queryMainCategory")
+public class QueryMainCategoryCmd extends Cmd {
+
+    @Autowired
+    private ISendMall sendMallImpl;
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        String mallSwitch = MappingCache.getValue("MALL", "MALL_SWITCH");
+        if (!"ON".equals(mallSwitch)) {
+            throw new CmdException("商城系统未部署");
+        }
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        String param = UrlParamToJsonUtil.jsonToUrlParam(reqJson);
+        ResultVo resultVo = sendMallImpl.get("/mall/api/productCategory.queryMainCategory?" + param);
+
+        context.setResponseEntity(ResultVo.createResponseEntity(resultVo));
+    }
+}

+ 38 - 0
service-job/src/main/java/com/java110/job/cmd/mall/QueryPhoneMainCategoryProductCmd.java

@@ -0,0 +1,38 @@
+package com.java110.job.cmd.mall;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.job.mall.ISendMall;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.UrlParamToJsonUtil;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.text.ParseException;
+
+@Java110Cmd(serviceCode = "mall.queryPhoneMainCategoryProduct")
+public class QueryPhoneMainCategoryProductCmd extends Cmd {
+
+    @Autowired
+    private ISendMall sendMallImpl;
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        String mallSwitch = MappingCache.getValue("MALL", "MALL_SWITCH");
+        if (!"ON".equals(mallSwitch)) {
+            throw new CmdException("商城系统未部署");
+        }
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+        String param = UrlParamToJsonUtil.jsonToUrlParam(reqJson);
+        ResultVo resultVo = sendMallImpl.get("/mall/api/product.queryPhoneMainCategoryProduct?" + param);
+
+        context.setResponseEntity(ResultVo.createResponseEntity(resultVo));
+    }
+}

+ 44 - 0
service-job/src/main/java/com/java110/job/cmd/mall/QueryShopTypeCmd.java

@@ -0,0 +1,44 @@
+package com.java110.job.cmd.mall;
+
+import com.alibaba.fastjson.JSONObject;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
+import com.java110.job.mall.ISendMall;
+import com.java110.utils.cache.MappingCache;
+import com.java110.utils.exception.CmdException;
+import com.java110.utils.util.Assert;
+import com.java110.utils.util.UrlParamToJsonUtil;
+import com.java110.vo.ResultVo;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.text.ParseException;
+
+/**
+ * 查询商铺类型
+ */
+@Java110Cmd(serviceCode = "mall.queryShopType")
+public class QueryShopTypeCmd extends Cmd {
+
+    @Autowired
+    private ISendMall sendMallImpl;
+
+    @Override
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+
+        String mallSwitch = MappingCache.getValue("MALL", "MALL_SWITCH");
+        if (!"ON".equals(mallSwitch)) {
+            throw new CmdException("商城系统未部署");
+        }
+    }
+
+    @Override
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
+
+        String param = UrlParamToJsonUtil.jsonToUrlParam(reqJson);
+        ResultVo resultVo = sendMallImpl.get("/mall/api/shopType.queryShopType?" + param);
+
+        context.setResponseEntity(ResultVo.createResponseEntity(resultVo));
+    }
+}

+ 27 - 4
service-job/src/main/java/com/java110/job/mall/SendMallImpl.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
 import com.java110.core.client.RestTemplate;
 import com.java110.core.factory.AuthenticationFactory;
 import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.core.log.LoggerFactory;
+import com.java110.db.dao.impl.QueryServiceDAOImpl;
 import com.java110.dto.machine.MachineTranslateErrorDto;
 import com.java110.intf.common.IMachineTranslateErrorInnerServiceSMO;
 import com.java110.job.adapt.hcIot.IotConstant;
@@ -14,18 +16,21 @@ import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.util.DateUtil;
 import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
+import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.HttpStatusCodeException;
 
 import java.util.Date;
 import java.util.UUID;
 
 @Service
 public class SendMallImpl implements ISendMall {
+    private final static Logger logger = LoggerFactory.getLogger(SendMallImpl.class);
 
     public static final String GET_TOKEN_URL = "/mall/api/login.pcUserLogin";
     private static final String DEFAULT_MALL_URL = "https://mall.homecommunity.cn";
@@ -44,9 +49,19 @@ public class SendMallImpl implements ISendMall {
 
     @Override
     public ResultVo get(String url) {
-        HttpHeaders header = getHeaders(url, "", HttpMethod.POST);
+        url = getUrl(url);
+        HttpHeaders header = getHeaders(url, "", HttpMethod.GET);
         HttpEntity<String> httpEntity = new HttpEntity<String>("", header);
-        ResponseEntity<String> tokenRes = outRestTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
+        ResponseEntity<String> tokenRes = null;
+        try {
+            tokenRes = outRestTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
+        } catch (HttpStatusCodeException e) {
+            logger.error("调用异常", e);
+            return new ResultVo(ResultVo.CODE_ERROR, e.getResponseBodyAsString());
+        } catch (Exception e) {
+            logger.error("调用异常", e);
+            return new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
+        }
 
         String body = tokenRes.getBody();
         JSONObject paramOut = JSONObject.parseObject(body);
@@ -59,8 +74,16 @@ public class SendMallImpl implements ISendMall {
         url = getUrl(url);
         HttpHeaders header = getHeaders(url, paramIn.toJSONString(), HttpMethod.POST);
         HttpEntity<String> httpEntity = new HttpEntity<String>(paramIn.toJSONString(), header);
-        ResponseEntity<String> tokenRes = outRestTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
-
+        ResponseEntity<String> tokenRes = null;
+        try {
+            tokenRes = outRestTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
+        } catch (HttpStatusCodeException e) {
+            logger.error("调用异常", e);
+            return new ResultVo(ResultVo.CODE_ERROR, e.getResponseBodyAsString());
+        } catch (Exception e) {
+            logger.error("调用异常", e);
+            return new ResultVo(ResultVo.CODE_ERROR, e.getMessage());
+        }
         String body = tokenRes.getBody();
         JSONObject paramOut = JSONObject.parseObject(body);
 

+ 5 - 5
springboot/src/main/java/com/java110/boot/configuration/ServiceConfiguration.java

@@ -70,11 +70,11 @@ public class ServiceConfiguration {
 //        exclusions.append("/app/room.queryRooms,");
         exclusions.append("/app/room.queryRoomsByApp,");
         exclusions.append("/app/productCategory/queryMainCategoryAllGoods,");
-        exclusions.append("/app/productCategory/queryMainCategory,");
-        exclusions.append("/app/product.queryPhoneMainCategoryProduct,");
+        exclusions.append("/app/mall.queryMainCategory,");
+        exclusions.append("/app/mall.queryPhoneMainCategoryProduct,");
         exclusions.append("/app/shop/queryShopCommunity,");
-        exclusions.append("/app/shopType/queryShopType,");
-        exclusions.append("/app/housekeepingType/queryHousekeepingType,");
+        exclusions.append("/app/mall.queryShopType,");
+        exclusions.append("/app/mall.queryHousekeepingType,");
         exclusions.append("/app/couponUser.listCouponUser,");
         exclusions.append("/app/machine.customCarInOutCmd,");
         exclusions.append("/callComponent/propertyRightRegistration.savePropertyRightRegistration,");
@@ -98,7 +98,7 @@ public class ServiceConfiguration {
         exclusions.append("/app/product/queryGroupProduct,");//拼团商品
         exclusions.append("/app/product/querySeckillProduct,");//秒杀商品
 
-        exclusions.append("/app/productSeckill.listProductSeckill,");//秒杀商品
+        exclusions.append("/app/mall.listProductSeckill,");//秒杀商品
         exclusions.append("/app/system.listRegisterProtocol,");//查询注册信息
         exclusions.append("/app/chargeMachine.listChargeMachine,");//查询充电桩
         exclusions.append("/app/chargeMachine.listChargeMachinePort,");//查询充电桩