From b82d10d935194ac94eed5bafd8a4b952ca5a2ea3 Mon Sep 17 00:00:00 2001
From: 吴学文 <wuxuewen@wuxuewendeMacBook-Pro.local>
Date: 星期五, 10 五月 2019 14:30:25 +0800
Subject: [PATCH] 加入业主管理模块

---
 UserService/src/main/java/com/java110/user/smo/impl/UserServiceSMOImpl.java |  243 +++++++++++++++++++++++-------------------------
 1 files changed, 117 insertions(+), 126 deletions(-)

diff --git a/UserService/src/main/java/com/java110/user/smo/impl/UserServiceSMOImpl.java b/UserService/src/main/java/com/java110/user/smo/impl/UserServiceSMOImpl.java
index 22b9271..6a169c9 100644
--- a/UserService/src/main/java/com/java110/user/smo/impl/UserServiceSMOImpl.java
+++ b/UserService/src/main/java/com/java110/user/smo/impl/UserServiceSMOImpl.java
@@ -2,160 +2,151 @@
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.JSONPath;
+import com.java110.common.cache.MappingCache;
+import com.java110.common.constant.KafkaConstant;
+import com.java110.common.constant.MappingConstant;
+import com.java110.common.constant.ResponseConstant;
+import com.java110.common.constant.StateConstant;
+import com.java110.common.exception.SMOException;
+import com.java110.common.kafka.KafkaFactory;
 import com.java110.common.log.LoggerEngine;
+import com.java110.common.util.Assert;
+import com.java110.common.util.DateUtil;
 import com.java110.common.util.ProtocolUtil;
-import com.java110.entity.user.BoCust;
-import com.java110.feign.base.IPrimaryKeyService;
-import com.java110.user.smo.IUserServiceSMO;
 import com.java110.core.base.smo.BaseServiceSMO;
-import org.apache.commons.lang.math.NumberUtils;
+import com.java110.core.context.BusinessServiceDataFlow;
+import com.java110.core.factory.DataFlowFactory;
+import com.java110.entity.center.DataFlowLinksCost;
+import com.java110.entity.center.DataFlowLog;
+import com.java110.entity.order.BusiOrder;
+import com.java110.entity.user.BoCust;
+import com.java110.entity.user.BoCustAttr;
+import com.java110.entity.user.Cust;
+import com.java110.entity.user.CustAttr;
+import com.java110.event.service.BusinessServiceDataFlowEventPublishing;
+import com.java110.user.dao.IUserServiceDao;
+import com.java110.user.smo.IUserServiceSMO;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
 
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 鐢ㄦ埛鏈嶅姟淇℃伅绠$悊涓氬姟淇℃伅瀹炵幇
  * Created by wuxw on 2017/4/5.
  */
 @Service("userServiceSMOImpl")
+@Transactional
 public class UserServiceSMOImpl extends BaseServiceSMO implements IUserServiceSMO {
 
+    private  static Logger logger = LoggerFactory.getLogger(UserServiceSMOImpl.class);
+
+
     @Autowired
-    IPrimaryKeyService iPrimaryKeyService;
+    IUserServiceDao iUserServiceDao;
 
     //鏂板鐢ㄦ埛
-    private final static String USER_ACTION_ADD = "ADD";
+    private static final String USER_ACTION_ADD = "ADD";
 
     //鏂板鐢ㄦ埛
-    private final static String USER_ACTION_KIP = "KIP";
+    private static final String USER_ACTION_KIP = "KIP";
 
     //鏂板鐢ㄦ埛
-    private final static String USER_ACTION_DEL = "DEL";
-
-    /**
-     * 淇濆瓨鐢ㄦ埛淇℃伅
-     *
-     * @param userInfoJson 鍏ュ弬涓虹敤鎴蜂俊鎭痡son浼�
-     * @return
-     */
-    public String saveUser(String userInfoJson) {
-
-        JSONObject reqUserJSON = null;
-        try {
-            reqUserJSON = this.simpleValidateJSON(userInfoJson);
-            //boCust澧炲姞Action (鍔ㄤ綔)
-            if (reqUserJSON.containsKey("boCust")) {
-                JSONObject boCust = reqUserJSON.getJSONObject("boCust");
-                boCust.put("state", USER_ACTION_ADD);
-            }
-            //boCustAttr澧炲姞Action锛堝姩浣滐級
-            if (reqUserJSON.containsKey("boCustAttr")) {
-                JSONArray boCustAttrs = reqUserJSON.getJSONArray("boCustAttr");
-
-                for (int attrIndex = 0; attrIndex < boCustAttrs.size(); attrIndex++) {
-                    JSONObject boCustAttr = boCustAttrs.getJSONObject(attrIndex);
-                    boCustAttr.put("state", USER_ACTION_ADD);
-                }
-            }
-        } catch (RuntimeException e) {
-            //杩斿洖寮傚父淇℃伅
-            return e.getMessage();
-        }
-        return soUserService(reqUserJSON.toJSONString());
-    }
+    private static final String USER_ACTION_DEL = "DEL";
 
 
-    /**
-     * 鎵�鏈夋湇鍔″鐞嗙被
-     *
-     * @param userInfoJson
-     * @return
-     */
-    public String soUserService(String userInfoJson) {
-        LoggerEngine.debug("鐢ㄦ埛鏈嶅姟鎿嶄綔瀹㈡埛鍏ュ弬锛�" + userInfoJson);
-        String resultUserInfo = null;
-        JSONObject reqUserJSON = null;
-        try {
-            reqUserJSON = this.simpleValidateJSON(userInfoJson);
-            //1.0瑙勫垯鏍¢獙锛屾姤鏂囨槸鍚﹀悎娉�
-
-            if(reqUserJSON.containsKey("boCust")){
-
-            }
-
-            if(reqUserJSON.containsKey("boCustAttr")){
-
-            }
-
-            //2.0
-        } catch (Exception e) {
-            LoggerEngine.error("鏈嶅姟澶勭悊鍑虹幇寮傚父锛�", e);
-        } finally {
-            LoggerEngine.debug("鐢ㄦ埛鏈嶅姟鎿嶄綔瀹㈡埛鍑哄弬锛�" + resultUserInfo);
-            return resultUserInfo;
-        }
-    }
-
-    /**
-     * {
-     *     boCust:[{},{}]
-     * }
-     * 瀹㈡埛淇″績澶勭悊
-     * @param boCusts
-     * @return
-     * @throws Exception
-     */
-    public String soBoCust(String boCusts) throws Exception{
-        // 灏� jsonArray 杞负list<BoCust> 瀵硅薄
-        JSONObject jsonObject = JSONObject.parseObject(boCusts);
-
-        List<BoCust> boCustList = JSONObject.parseArray(jsonObject.getJSONArray("boCust").toJSONString(), BoCust.class);
-
-        //淇濆瓨鏁版嵁
-
-        for(BoCust boCust : boCustList){
-            int custId = NumberUtils.toInt(boCust.getBoId(),-1);
-            //濡傛灉瀹㈡埛ID灏忎簬0 锛屽垯鑷繁鐢熸垚瀹㈡埛ID,杩欎釜鍙湁鍦ㄦ湁 涓婚敭鐢熸垚鏈嶅姟鏃朵娇鐢紝鍚﹀垯涓轰簡闃叉鍑洪敊锛岄渶瑕佸墠娈佃皟鐢ㄦ椂闇�瑕佺敓鎴恈ustId
-            if(custId < 0 ){
-                JSONObject data = new JSONObject();
-                data.put("type","CUST_ID");
-                //{"RESULT_CODE":"0000","RESULT_INFO":{"user_id":"7020170411000041"},"RESULT_MSG":"鎴愬姛"}
-                String custIdJSONStr = iPrimaryKeyService.queryPrimaryKey(data.toJSONString());
-                JSONObject custIdJSONTmp = JSONObject.parseObject(custIdJSONStr);
-                if(custIdJSONTmp.containsKey("RESULT_CODE")
-                        && ProtocolUtil.RETURN_MSG_SUCCESS.equals(custIdJSONTmp.getString("RESULT_CODE"))
-                        && custIdJSONTmp.containsKey("RESULT_INFO")){
-                    //浠庢帴鍙g敓鎴恈ustId
-                    custId = NumberUtils.toInt(custIdJSONTmp.getJSONObject("RESULT_INFO").getString("CUST_ID"),-1);
-                }
-            }
-
-            boCust.setCustId(custId+"");
-        }
-        return "";
-    }
-
-    /**
-     * 瀹㈡埛淇℃伅灞炴�у鐞�
-     * 鍗忚锛�
-     *{
-     *     boCustAttr:[{},{}]
-     * }
-     * @param boCustAttrs
-     * @return
-     * @throws Exception
-     */
     @Override
-    public String soBoCustAttr(String boCustAttrs) throws Exception {
-        return null;
+    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) {
+            logger.error("鐢ㄦ埛淇℃伅澶勭悊寮傚父", e);
+            throw new SMOException(ResponseConstant.RESULT_PARAM_ERROR, "鐢ㄦ埛淇℃伅澶勭悊寮傚父" + e.getMessage());
+        } finally {
+            if (businessServiceDataFlow == null) {
+                return null;
+            }
+
+            //杩欓噷璁板綍鏃ュ織
+            Date endDate = DateUtil.getCurrentDate();
+
+            businessServiceDataFlow.setEndDate(endDate);
+            //娣诲姞鑰楁椂
+            DataFlowFactory.addCostTime(businessServiceDataFlow, "service", "涓氬姟澶勭悊鎬昏�楁椂",
+                    businessServiceDataFlow.getStartDate(), businessServiceDataFlow.getEndDate());
+            //淇濆瓨鑰楁椂
+            saveCostTimeLogMessage(businessServiceDataFlow);
+            //淇濆瓨鏃ュ織
+            saveLogMessage(businessServiceDataFlow);
+        }
+        return businessServiceDataFlow.getResJson();
     }
 
-    public IPrimaryKeyService getiPrimaryKeyService() {
-        return iPrimaryKeyService;
+
+    /**
+     * 淇濆瓨鏃ュ織淇℃伅
+     *
+     * @param businessServiceDataFlow 涓氬姟鏃ュ織瀵硅薄
+     */
+    private void saveLogMessage(BusinessServiceDataFlow businessServiceDataFlow) {
+
+        try {
+            if (MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_LOG_ON_OFF))) {
+                for (DataFlowLog dataFlowLog : businessServiceDataFlow.getLogDatas()) {
+                    KafkaFactory.sendKafkaMessage(KafkaConstant.TOPIC_LOG_NAME, "", JSONObject.toJSONString(dataFlowLog));
+                }
+            }
+        } catch (Exception e) {
+            logger.error("鎶ラ敊鏃ュ織鍑洪敊浜嗭紝", e);
+        }
     }
 
-    public void setiPrimaryKeyService(IPrimaryKeyService iPrimaryKeyService) {
-        this.iPrimaryKeyService = iPrimaryKeyService;
+    /**
+     * 淇濆瓨鑰楁椂淇℃伅
+     *
+     * @param businessServiceDataFlow
+     */
+    private void saveCostTimeLogMessage(BusinessServiceDataFlow businessServiceDataFlow) {
+        try {
+            if (MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_COST_TIME_ON_OFF))) {
+                List<DataFlowLinksCost> dataFlowLinksCosts = businessServiceDataFlow.getLinksCostDates();
+                JSONObject costDate = new JSONObject();
+                JSONArray costDates = new JSONArray();
+                JSONObject newObj = null;
+                for (DataFlowLinksCost dataFlowLinksCost : dataFlowLinksCosts) {
+                    newObj = JSONObject.parseObject(JSONObject.toJSONString(dataFlowLinksCost));
+                    newObj.put("dataFlowId", businessServiceDataFlow.getDataFlowId());
+                    newObj.put("transactionId", businessServiceDataFlow.getTransactionId());
+                    costDates.add(newObj);
+                }
+                costDate.put("costDates", costDates);
+
+                KafkaFactory.sendKafkaMessage(KafkaConstant.TOPIC_COST_TIME_LOG_NAME, "", costDate.toJSONString());
+            }
+        } catch (Exception e) {
+            logger.error("鎶ラ敊鏃ュ織鍑洪敊浜嗭紝", e);
+        }
+    }
+
+
+    public IUserServiceDao getiUserServiceDao() {
+        return iUserServiceDao;
+    }
+
+    public void setiUserServiceDao(IUserServiceDao iUserServiceDao) {
+        this.iUserServiceDao = iUserServiceDao;
     }
 }

--
Gitblit v1.8.0