Explorar el Código

同步过程测试完成,异步过程未测试

wuxw7 hace 7 años
padre
commit
ac70082e18

+ 4 - 4
CenterService/src/main/java/com/java110/center/smo/impl/CenterServiceSMOImpl.java

@@ -33,7 +33,7 @@ import java.util.*;
  * Created by wuxw on 2018/4/13.
  */
 @Service("centerServiceSMOImpl")
-@Transactional
+//@Transactional
 public class CenterServiceSMOImpl extends LoggerEngine implements ICenterServiceSMO {
 
     @Autowired
@@ -852,7 +852,7 @@ public class CenterServiceSMOImpl extends LoggerEngine implements ICenterService
             JSONObject responseJson = doRequestBusinessSystem(dataFlow, service, requestBusinessJson);
             //添加需要撤单的业务信息
             deleteBusinesses.add(business);
-            updateBusinessStatusCdByBId(business.getbId(),StatusConstant.STATUS_CD_BUSINESS);
+            updateBusinessStatusCdByBId(business.getbId(),StatusConstant.STATUS_CD_COMPLETE);
             DataFlowFactory.addCostTime(dataFlow, business.getServiceCode(), "调用"+business.getServiceName()+"耗时", businessStartDate);
             saveLogMessage(requestBusinessJson,responseJson);
         }
@@ -881,7 +881,7 @@ public class CenterServiceSMOImpl extends LoggerEngine implements ICenterService
         String responseMessage;
         if(service.getMethod() == null || "".equals(service.getMethod())) {//post方式
             //http://user-service/test/sayHello
-            responseMessage = restTemplate.postForObject(service.getUrl(),requestBusinessJson,String.class);
+            responseMessage = restTemplate.postForObject(service.getUrl(),requestBusinessJson.toJSONString(),String.class);
         }else{//webservice方式
             responseMessage = (String) WebServiceAxisClient.callWebService(service.getUrl(),service.getMethod(),
                     new Object[]{dataFlow.getRequestBusinessJson().toJSONString()},
@@ -895,7 +895,7 @@ public class CenterServiceSMOImpl extends LoggerEngine implements ICenterService
 
         Assert.jsonObjectHaveKey(responseJson,"response","下游返回报文格式错误,没有包含responseJson节点【"+service.getUrl()+"】");
 
-        JSONObject responseInfo = responseJson.getJSONObject("responseJson");
+        JSONObject responseInfo = responseJson.getJSONObject("response");
 
         Assert.jsonObjectHaveKey(responseInfo,"code","下游返回报文格式错误,response 节点中没有包含code节点【"+service.getUrl()+"】");
 

+ 14 - 0
UserService/doc/start_userService.sh

@@ -0,0 +1,14 @@
+#!/bin/bash
+#### debug model prod
+#nohup java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar -Dspring.profiles.active=dev UserService.jar > user.log 2>&1 &
+
+#### normal prod model
+#nohup java -jar -Dspring.profiles.active=prod UserService.jar > user.log 2>&1 &
+
+#### normal test model
+#nohup java -jar -Dspring.profiles.active=test UserService.jar > user.log 2>&1 &
+
+#### normal dev model
+nohup java -jar -Dspring.profiles.active=dev UserService.jar > user.log 2>&1 &
+
+tail -100f user.log

+ 10 - 0
UserService/pom.xml

@@ -15,6 +15,8 @@
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>1.7</maven.compiler.source>
+        <maven.compiler.target>1.7</maven.compiler.target>
     </properties>
 
     <dependencies>
@@ -32,6 +34,7 @@
 
 
     <build>
+        <finalName>UserService</finalName>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
@@ -59,6 +62,13 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <mainClass>com.java110.user.UserServiceApplicationStart</mainClass>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 </project>

+ 8 - 8
UserService/src/main/java/com/java110/user/listener/SaveUserInfoListener.java

@@ -54,7 +54,7 @@ public class SaveUserInfoListener extends LoggerEngine implements BusinessServic
     private void doSaveUserInfo(DataFlowContext dataFlowContext){
         String businessType = dataFlowContext.getOrder().getBusinessType();
         Business business = dataFlowContext.getCurrentBusiness();
-        Assert.hasLength(business.getbId(),"bId 不能为空");
+        //Assert.hasLength(business.getbId(),"bId 不能为空");
         // Instance 过程
         if(StatusConstant.REQUEST_BUSINESS_TYPE_INSTANCE.equals(businessType)){
             //doComplateUserInfo(business);
@@ -76,7 +76,7 @@ public class SaveUserInfoListener extends LoggerEngine implements BusinessServic
     private void doDeleteInstanceUserInfo(DataFlowContext dataFlowContext,Business business) {
 
         String bId = business.getbId();
-        Assert.hasLength(bId,"请求报文中没有包含 bId");
+        //Assert.hasLength(bId,"请求报文中没有包含 bId");
         Map info = new HashMap();
         info.put("bId",bId);
         Map userInfo = userServiceDaoImpl.queryUserInfo(info);
@@ -111,9 +111,9 @@ public class SaveUserInfoListener extends LoggerEngine implements BusinessServic
 
         JSONObject data = business.getDatas();
 
-        Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理");
+        //Assert.notEmpty(data,"没有datas 节点,或没有子节点需要处理");
 
-        Assert.jsonObjectHaveKey(data,"businessUser","datas 节点下没有包含 businessUser 节点");
+        //Assert.jsonObjectHaveKey(data,"businessUser","datas 节点下没有包含 businessUser 节点");
 
         //JSONObject businessUser = data.getJSONObject("businessUser");
         Map info = new HashMap();
@@ -190,14 +190,14 @@ public class SaveUserInfoListener extends LoggerEngine implements BusinessServic
             JSONObject userAttr = businessUserAttrs.getJSONObject(userAttrIndex);
             Assert.jsonObjectHaveKey(userAttr,"attrId","businessUserAttr 节点下没有包含 attrId 节点");
 
-            if(businessUser.getInteger("attrId") < 0){
+            if(userAttr.getInteger("attrId") < 0){
                 String attrId = SequenceUtil.getAttrId();
                 userAttr.put("attrId",attrId);
             }
 
-            businessUser.put("bId",business.getbId());
-            businessUser.put("userId",businessUser.getString("userId"));
-            businessUser.put("operate", StatusConstant.OPERATE_ADD);
+            userAttr.put("bId",business.getbId());
+            userAttr.put("userId",businessUser.getString("userId"));
+            userAttr.put("operate", StatusConstant.OPERATE_ADD);
 
             userServiceDaoImpl.saveBusinessUserAttr(userAttr);
         }

+ 1 - 1
UserService/src/main/java/com/java110/user/rest/UserServiceRest.java

@@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
  * 用户服务提供类
  * Created by wuxw on 2017/4/5.
  */
-@RestController
+//@RestController
 public class UserServiceRest extends BaseController implements IUserService {
 
     @Autowired

+ 3 - 1
UserService/src/main/java/com/java110/user/smo/impl/UserServiceSMOImpl.java

@@ -46,7 +46,7 @@ import java.util.*;
 @Transactional
 public class UserServiceSMOImpl extends BaseServiceSMO implements IUserServiceSMO {
 
-    @Autowired
+    //@Autowired
     IPrimaryKeyService iPrimaryKeyService;
 
     @Autowired
@@ -762,6 +762,8 @@ public class UserServiceSMOImpl extends BaseServiceSMO implements IUserServiceSM
     @Override
     public JSONObject service(BusinessServiceDataFlow businessServiceDataFlow) throws SMOException {
         try {
+            Assert.hasLength(businessServiceDataFlow.getbId(),"bId 不能为空");
+
             BusinessServiceDataFlowEventPublishing.multicastEvent(businessServiceDataFlow);
             Assert.notEmpty(businessServiceDataFlow.getResJson(),"用户服务["+businessServiceDataFlow.getCurrentBusiness().getServiceCode()+"]没有返回内容");
         } catch (Exception e) {

+ 1 - 1
UserService/src/main/resources/application.yml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: dev
+    active: test

+ 0 - 17
UserService/src/test/java/com/java110/user/AppTest.java

@@ -34,24 +34,7 @@ public class AppTest
      */
     public void testApp()
     {
-        String url = "http://135.192.70.67:9084/serviceAgent/http/FactorageManager_ForAgent?AppKey=2017082401";
-        String function = "queryOrderInfo";
 
-        String xml  = "<QueryOrderInfoRequest>\n" +
-                "\t<accNbr>18009706604</accNbr>\n" +
-                "\t<accNbrType>1</accNbrType> \n" +
-                "\t<areaCode>0971</areaCode>\n" +
-                "\t<channelId></channelId>\n" +
-                "\t<staffCode></staffCode> \t\n" +
-                "</QueryOrderInfoRequest>";
-
-        try {
-            Object retObj = WebServiceAxisClient.callWebService(url, function, new Object[]{xml});
-
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
 
     }
 }

+ 1 - 1
java110-common/src/main/java/com/java110/common/util/SequenceUtil.java

@@ -121,7 +121,7 @@ public class SequenceUtil {
 
     public static String getUserId(){
         if(!MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_NEED_INVOKE_GENERATE_ID))){
-            return prefixMap.get("userId") + DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_H) + nextId("%08d");
+            return prefixMap.get("userId") + nextId("%08d");
         }
         //调用服务
         return null;

+ 19 - 2
java110-config/db/CenterService/create_table.db

@@ -21,9 +21,11 @@ CREATE TABLE c_orders_attrs(
     o_id VARCHAR(18) NOT NULL COMMENT '订单ID',
     attr_id VARCHAR(18) NOT NULL COMMENT '属性id',
     spec_cd VARCHAR(12) NOT NULL COMMENT '规格id,参考spec表',
-    value VARCHAR(50) NOT NULL COMMENT '属性值'
+    `value` VARCHAR(50) NOT NULL COMMENT '属性值'
 );
 
+
+
 -- c_business
 
 CREATE TABLE c_business(
@@ -42,7 +44,7 @@ CREATE TABLE c_business_attrs(
     b_id VARCHAR(18) NOT NULL COMMENT '订单ID',
     attr_id VARCHAR(18) NOT NULL COMMENT '属性id',
     spec_cd VARCHAR(12) NOT NULL COMMENT '规格id,参考spec表',
-    VALUE VARCHAR(50) NOT NULL COMMENT '属性值'
+    `value` VARCHAR(50) NOT NULL COMMENT '属性值'
 );
 
 -- c_status
@@ -77,6 +79,8 @@ CREATE TABLE c_order_type(
 );
 
 
+
+
 -- c_business_type
 
 CREATE TABLE c_business_type(
@@ -100,6 +104,9 @@ CREATE TABLE spec(
     create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'
 );
 
+insert into spec(domain,spec_cd,name,description) values('ORDERS','100001','订单来源','订单来源');
+insert into spec(domain,spec_cd,name,description) values('BUSINESS','200001','推荐UserID','推荐UserID');
+
 -- c_route
 
 CREATE TABLE c_route(
@@ -198,6 +205,7 @@ CREATE TABLE c_service_sql(
 -- 测试用
 
 insert into c_order_type(order_type_cd,`name`,description) values('Q','查询单','查询单');
+insert into c_order_type(order_type_cd,`name`,description) values('D','受理单','受理单');
 
 insert into c_app(app_id,`name`,security_code,remark,status_cd)
 values('8000418001','内部测试应用','WEBURFPKIFJUHNCJUEIKMKJUJHULSMNCHDY89KMC','记得删除','0');
@@ -205,6 +213,9 @@ values('8000418001','内部测试应用','WEBURFPKIFJUHNCJUEIKMKJUJHULSMNCHDY89K
 insert into c_app(app_id,`name`,security_code,remark,status_cd)
 values('8000418002','控制中心应用','WEBURFPKIFJUHNCJUEIKMKJUJHULSMNCHDY89KMC','控制中心应用','0');
 
+insert into c_app(app_id,`name`,security_code,remark,status_cd)
+values('8000418003','用户管理应用','WEBURFPKIFJUHNCJUEIKMKJUJHULSMNCHDY89KMC','用户管理应用','0');
+
 
 insert into c_service(service_code,business_type_cd,`name`,seq,url,provide_app_id,status_cd)
 values('query.user.userInfo','Q','用户信息查询',1,'http://...','8000418001','0');
@@ -255,6 +266,9 @@ VALUES('delete.center.mapping','Q','删除映射信息',1,'http://center-service
 INSERT INTO c_service(service_code,business_type_cd,`name`,seq,url,provide_app_id)
 VALUES('update.center.mapping','Q','修改映射信息',1,'http://center-service/businessApi/do','8000418002');
 
+INSERT INTO c_service(service_code,business_type_cd,`name`,seq,url,provide_app_id)
+VALUES('update.center.mapping','D','保存用户信息',1,'http://user-service/userApi/service','8000418003');
+
 insert into c_route(app_id,service_id,invoke_model,order_type_cd,status_cd) values(
 '8000418001','1','S','Q','0'
 );
@@ -313,6 +327,9 @@ INSERT INTO c_route(app_id,service_id,invoke_model,order_type_cd,status_cd) VALU
 INSERT INTO c_route(app_id,service_id,invoke_model,order_type_cd,status_cd) VALUES(
 '8000418002','16','S','Q','0'
 );
+INSERT INTO c_route(app_id,service_id,invoke_model,order_type_cd,status_cd) VALUES(
+'8000418002','17','S','Q','0'
+);
 
 
 

+ 4 - 4
java110-config/src/main/resources/mapper/user/UserServiceDaoImplMapper.xml

@@ -157,17 +157,17 @@
     <!-- 保存用户属性 -->
     <insert id="saveBusinessUserAttr" parameterType="map">
         insert into business_user_attr(b_id,user_id,attr_id,spec_cd,value,operate)
-        values(#{bId},#{userId},#{attId},#{specCd},#{value},#{operate})
+        values(#{bId},#{userId},#{attrId},#{specCd},#{value},#{operate})
     </insert>
     <!-- 实例数据 -->
     <insert id="saveUserInfoInstance" parameterType="map">
         insert into u_user(user_id,name,email,address,password,location_cd,age,sex,tel,level_cd,b_id,status_cd)
-        select bu.user_id,bu.name,bu.email,bu.address,bu.password,bu.location_cd,bu.age,bu.sex,bu.tel,bu.level_cd,bu.b_id,'0' from business_user bu where bu.operate = 'ADD' and bu.b_id=#{bId}
+        select bu.user_id,bu.name,bu.email,bu.address,bu.password,bu.location_cd,bu.age,bu.sex,bu.tel,bu.level_cd,bu.b_id,'0' from business_user bu where bu.operate = 'ADD' and bu.b_id=#{b_id}
     </insert>
 
     <insert id="saveUserAttrInstance" parameterType="map">
         insert into u_user_attr(attr_id,user_id,spec_cd,value,b_id,status_cd)
-        select bua.attr_id,bua.user_id,bua.spec_cd,bua.value,'0' from business_user_attr bua where bua.operate='ADD' and bua.b_id=#{bId}
+        select bua.attr_id,bua.user_id,bua.spec_cd,bua.value,bua.b_id,'0' from business_user_attr bua where bua.operate='ADD' and bua.b_id=#{b_id}
     </insert>
 
     <update id="updateUserInfoInstance" parameterType="map">
@@ -183,7 +183,7 @@
         </if>
     </update>
 
-    <update id="updateUserInfoInstance" parameterType="map">
+    <update id="updateUserAttrInstance" parameterType="map">
         update u_user_attr ua set ua.status_cd = #{statusCd} where 1 = 1
         <if test="bId != null and bId != ''">
             and ua.b_id = #{bId}

+ 11 - 13
java110-core/src/main/java/com/java110/core/factory/DataFlowFactory.java

@@ -168,20 +168,19 @@ public class DataFlowFactory {
      */
     public static List<Map> getBusiness(DataFlow dataFlow){
         List<Map> businesss = new ArrayList<Map>();
-        JSONArray reqBusiness = dataFlow.getReqBusiness();
+        List<Business> businesses= dataFlow.getBusinesses();
         Map busiMap = null;
-        for(int businessIndex = 0 ; businessIndex < reqBusiness.size();businessIndex ++) {
-            JSONObject business = reqBusiness.getJSONObject(businessIndex);
+        for(Business business : businesses) {
             if(business == null){
                 continue;
             }
-            business.put("bId",SequenceUtil.getBId());
+            business.setbId(SequenceUtil.getBId());
             busiMap = new HashMap();
             busiMap.put("oId",dataFlow.getoId());
-            busiMap.put("businessTypeCd",getService(dataFlow,business.getString("serviceCode")).getBusinessTypeCd());
-            busiMap.put("remark",business.getString("remark"));
+            busiMap.put("businessTypeCd",getService(dataFlow,business.getServiceCode()).getBusinessTypeCd());
+            busiMap.put("remark",business.getRemark());
             busiMap.put("statusCd",StatusConstant.STATUS_CD_SAVE);
-            busiMap.put("bId",business.getString("bId"));
+            busiMap.put("bId",business.getbId());
             businesss.add(busiMap);
         }
         return businesss;
@@ -212,17 +211,16 @@ public class DataFlowFactory {
      */
     public static List<Map> getBusinessAttrs(DataFlow dataFlow){
         List<Map> businessAttrs = new ArrayList<Map>();
-        JSONArray reqBusiness = dataFlow.getReqBusiness();
-        for(int businessIndex = 0 ; businessIndex < reqBusiness.size();businessIndex ++) {
-            JSONObject business = reqBusiness.getJSONObject(businessIndex);
-            if (!business.containsKey("attrs") && business.getJSONArray("attrs").size() == 0) {
+        List<Business> businesses = dataFlow.getBusinesses();
+        for(Business business :businesses) {
+            if (business.getAttrs() == null || business.getAttrs().size() ==0) {
                 continue;
             }
-            JSONArray attrs = business.getJSONArray("attrs");
+            JSONArray attrs = business.getAttrs();
             Map attrMap = null;
             for (int attrIndex = 0; attrIndex < attrs.size(); attrIndex++) {
                 attrMap = new HashMap();
-                attrMap.put("bId", business.getString("bId"));
+                attrMap.put("bId", business.getbId());
                 attrMap.put("attrId", SequenceUtil.getAttrId());
                 attrMap.put("specCd", attrs.getJSONObject(attrIndex).getString("specCd"));
                 attrMap.put("value", attrs.getJSONObject(attrIndex).getString("value"));

+ 2 - 2
java110-event/src/main/java/com/java110/event/service/BusinessServiceDataFlowEventPublishing.java

@@ -60,7 +60,7 @@ public class BusinessServiceDataFlowEventPublishing extends LoggerEngine {
      */
     public static List<BusinessServiceDataFlowListener> getListeners(String serviceCode){
 
-        Assert.isNull(serviceCode,"获取需要发布的事件处理侦听时,传递事件为空,请检查");
+        Assert.hasLength(serviceCode,"获取需要发布的事件处理侦听时,传递事件为空,请检查");
 
         //先从缓存中获取,为了提升效率
         if(cacheListenersMap.containsKey(serviceCode)){
@@ -109,7 +109,7 @@ public class BusinessServiceDataFlowEventPublishing extends LoggerEngine {
      */
     public static void multicastEvent(String serviceCode,DataFlowContext dataFlowContext,String asyn) throws  BusinessException{
         try {
-            BusinessServiceDataFlowEvent targetDataFlowEvent = new BusinessServiceDataFlowEvent(null,dataFlowContext);
+            BusinessServiceDataFlowEvent targetDataFlowEvent = new BusinessServiceDataFlowEvent(serviceCode,dataFlowContext);
 
             multicastEvent(serviceCode,targetDataFlowEvent, asyn);
         }catch (Exception e){

+ 8 - 6
java110-event/src/main/java/com/java110/event/service/init/SystemStartLoadBusinessConfigure.java

@@ -63,12 +63,14 @@ public class SystemStartLoadBusinessConfigure {
 
             //这里不能直接反射,这样 IXXXService 无法注入,所以直接从spring 中获取已经注入的
             //AppListener<?> appListener = (AppListener<?>)Class.forName(listener).newInstance();
-
-            BusinessServiceDataFlowListener businessServiceDataFlowListener = (BusinessServiceDataFlowListener) ApplicationContextFactory.getBean(listener);
-
-            //将 listener 放入 AppEventPublishing 中方便后期操作
-            //注册侦听
-            BusinessServiceDataFlowEventPublishing.addListenner(businessServiceDataFlowListener);
+            try {
+                BusinessServiceDataFlowListener businessServiceDataFlowListener = (BusinessServiceDataFlowListener) ApplicationContextFactory.getBean(listener);
+                //将 listener 放入 AppEventPublishing 中方便后期操作
+                //注册侦听
+                BusinessServiceDataFlowEventPublishing.addListenner(businessServiceDataFlowListener);
+            }catch (Exception e){
+
+            }
         }
     }