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 |  330 +++++++++++++++----------------------------------------
 1 files changed, 90 insertions(+), 240 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 7fa9dd9..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,22 +2,44 @@
 
 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.core.base.smo.BaseServiceSMO;
+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.feign.base.IPrimaryKeyService;
+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 com.java110.core.base.smo.BaseServiceSMO;
-import org.apache.commons.lang.math.NumberUtils;
 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;
 
 /**
  * 鐢ㄦ埛鏈嶅姟淇℃伅绠$悊涓氬姟淇℃伅瀹炵幇
@@ -27,270 +49,98 @@
 @Transactional
 public class UserServiceSMOImpl extends BaseServiceSMO implements IUserServiceSMO {
 
-    @Autowired
-    IPrimaryKeyService iPrimaryKeyService;
+    private  static Logger logger = LoggerFactory.getLogger(UserServiceSMOImpl.class);
+
 
     @Autowired
     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) throws Exception{
-
-        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);
-    }
+    private static final String USER_ACTION_DEL = "DEL";
 
 
-    /**
-     * 鎵�鏈夋湇鍔″鐞嗙被
-     *
-     * @param userInfoJson
-     * @return
-     */
-    public String soUserService(JSONObject userInfoJson) throws Exception{
-        LoggerEngine.debug("鐢ㄦ埛鏈嶅姟鎿嶄綔瀹㈡埛鍏ュ弬锛�" + userInfoJson);
-        JSONObject paramJson = new JSONObject();
-
-        JSONObject resultInfo = null;
-
-        if (userInfoJson == null){
-            throw new IllegalArgumentException("soUserService 鍏ュ弬 涓虹┖"+userInfoJson);
-        }
-         // 瀹㈡埛淇℃伅澶勭悊
-            if(userInfoJson.containsKey("boCust")){
-                JSONArray boCusts = userInfoJson.getJSONArray("boCust");
-                JSONObject boCustObj = new JSONObject();
-                boCustObj.put("boCust",boCusts);
-                String returnSaveBoCust = this.soBoCust(boCustObj.toJSONString());
-
-                if(!ProtocolUtil.validateReturnJson(returnSaveBoCust,paramJson)){
-
-                    throw new RuntimeException("淇濆瓨 bo_cust 澶辫触锛�"+boCustObj+(paramJson != null
-                            && paramJson.containsKey("RESULT_MSG")?paramJson.getString("RESULT_MSG"):"鏈煡寮傚父"));
-                }
-
-                resultInfo = paramJson.getJSONObject("RESULT_INFO");
-            }
-
-            //瀹㈡埛灞炴�т俊鎭鐞�
-            if(userInfoJson.containsKey("boCustAttr")){
-
-                JSONArray boCustAttrs = userInfoJson.getJSONArray("boCustAttr");
-                JSONObject boCustAttrObj = new JSONObject();
-                boCustAttrObj.put("boCustAttr",boCustAttrs);
-                String returnSaveBoCustAttr = soBoCustAttr(boCustAttrObj.toJSONString());
-
-                if(!ProtocolUtil.validateReturnJson(returnSaveBoCustAttr,paramJson)){
-
-                    throw new RuntimeException("淇濆瓨 bo_cust 澶辫触锛�"+boCustAttrObj+(paramJson != null
-                            && paramJson.containsKey("RESULT_MSG")?paramJson.getString("RESULT_MSG"):"鏈煡寮傚父"));
-                }
-            }
-
-        return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"鎴愬姛",resultInfo);
-
-    }
-
-    /**
-     * {
-     *     boCust:[{},{}]
-     * }
-     * 瀹㈡埛淇″績澶勭悊
-     *
-     *
-     * @param boCusts
-     * @return 鎴愬姛 浼氬甫涓婂鐞嗗鎴风殑瀹㈡埛ID
-     * {'RESULT_CODE':'0000','RESULT_MSG':'鎴愬姛','RESULT_INFO':{'custId':'7000123,718881991}}
-     * @throws Exception
-     */
-    public String soBoCust(String boCusts) throws Exception{
-        // 灏� jsonArray 杞负list<BoCust> 瀵硅薄
-        JSONObject jsonObject = JSONObject.parseObject(boCusts);
-
-        JSONObject resultInfo = new JSONObject();
-
-        String custIds = "";
-
-        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+"");
-
-            //淇濆瓨鏁版嵁鑷� bo_cust 琛ㄤ腑
-            int saveBoCustFlag = iUserServiceDao.saveDataToBoCust(boCust);
-
-            if(saveBoCustFlag < 1){ // 濡傛灉娌℃湁淇濆瓨鎴愬姛锛屾姏鍑哄紓甯革紝鏈変簨鐗� 鍥為��浜嬬墿
-                throw new RuntimeException("淇濆瓨杩囩▼[bo_cust]鏁版嵁澶辫触,鍗拌薄璁板綍鏁颁负"+saveBoCustFlag+"锛宐oCust : "+boCust);
-            }
-            //寤烘。 澶勭悊 瀹炰緥鏁版嵁
-            int saveCustFlag = 0;
-            if("ADD".equals(boCust.getState())){
-                saveCustFlag  = iUserServiceDao.saveDataToCust(boCust.convert());
-            }else if("DEL".equals(boCust.getState())){
-                saveCustFlag = iUserServiceDao.deleteDataToCust(boCust.convert());
-            }else if("KIP".equals(boCust.getState())){
-                //鎸夌悊杩欓噷鍒颁笉浜嗭紝KIP琛ㄧず瀹炰緥鏁版嵁涓嶅彉锛屾墍浠ヨ繖閲岄粯璁ゅ啓鎴�1 璁や负鏄垚鍔�
-                saveCustFlag = 1;
-            }else{
-                //杩欓噷鍗曠嫭鎶涘嚭寮傚父锛屼笉璧颁笅闈㈢粺涓�寮傚父鎶涘嚭锛屾槸涓轰簡璇存槑鏇村叿浣撶偣
-                throw new RuntimeException("鍏ュ弬閿欒boCust 鐨� state 鐩墠鍙敮鎸� [ADD,DEL,KIP] , boCust : " +boCust);
-            }
-
-
-            if(saveCustFlag < 1){
-                throw new RuntimeException("淇濆瓨瀹炰緥[cust]鏁版嵁澶辫触锛屽奖鍝嶈褰曟暟涓�"+saveCustFlag+", cust : "+boCust.convert());
-            }
-
-            custIds +=","+custId;
-        }
-
-        //鍘婚櫎绗竴涓�楀彿
-        if (custIds.length()>0){
-            custIds = custIds.substring(1);
-        }
-
-        resultInfo.put("custId",custIds);
-
-        return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"鎴愬姛",resultInfo);
-    }
-
-    /**
-     * 娉ㄦ剰鍦ㄨ皟鐢ㄨ繖涓帴鍙f椂锛岀浉搴旂殑瀹㈡埛淇℃伅蹇呴』瀛樺湪
-     *
-     *
-     * 瀹㈡埛淇℃伅灞炴�у鐞�
-     * 鍗忚锛�
-     *{
-     *     boCustAttr:[{},{}]
-     * }
-     * @param boCustAttrs
-     * @return
-     * @throws Exception
-     */
     @Override
-    public String soBoCustAttr(String boCustAttrs) throws Exception {
+    public JSONObject service(BusinessServiceDataFlow businessServiceDataFlow) throws SMOException {
+        try {
+            Assert.hasLength(businessServiceDataFlow.getbId(), "bId 涓嶈兘涓虹┖");
 
-        //杩欓噷鍙互鍔犲叆鍩烘湰瀹㈡埛淇℃伅鏄惁瀛樺湪鐨勬牎楠岋紝鏆傛椂娌℃湁蹇呰瀹炵幇
-
-        // 灏� jsonArray 杞负list<BoCust> 瀵硅薄
-        JSONObject jsonObject = JSONObject.parseObject(boCustAttrs);
-
-        List<BoCustAttr> boCustAttrList = JSONObject.parseArray(jsonObject.getJSONArray("boCustAttr").toJSONString(), BoCustAttr.class);
-
-        //淇濆瓨鏁版嵁
-
-        for(BoCustAttr boCustAttr : boCustAttrList) {
-
-            //淇濆瓨鏁版嵁鑷� bo_cust_attr 琛ㄤ腑
-            int saveBoCustAttrFlag = iUserServiceDao.saveDataToBoCustAttr(boCustAttr);
-
-            if(saveBoCustAttrFlag < 1){ // 濡傛灉娌℃湁淇濆瓨鎴愬姛锛屾姏鍑哄紓甯革紝鏈変簨鐗� 鍥為��浜嬬墿
-                throw new RuntimeException("淇濆瓨杩囩▼[bo_cust_attr]鏁版嵁澶辫触,鍗拌薄璁板綍鏁颁负"+saveBoCustAttrFlag+"锛宐oCustAttr : "+boCustAttr);
+            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;
             }
 
-            //寤烘。 澶勭悊 瀹炰緥鏁版嵁
-            int saveCustAttrFlag = 0;
-            if("ADD".equals(boCustAttr.getState())){
-                saveCustAttrFlag  = iUserServiceDao.saveDataToCustAttr(boCustAttr.convert());
-            }else if("DEL".equals(boCustAttr.getState())){
-                saveCustAttrFlag = iUserServiceDao.deleteDataToCustAttr(boCustAttr.convert());
-            }else if("KIP".equals(boCustAttr.getState())){
-                //鎸夌悊杩欓噷鍒颁笉浜嗭紝KIP琛ㄧず瀹炰緥鏁版嵁涓嶅彉锛屾墍浠ヨ繖閲岄粯璁ゅ啓鎴�1 璁や负鏄垚鍔�
-                saveCustAttrFlag = 1;
-            }else{
-                //杩欓噷鍗曠嫭鎶涘嚭寮傚父锛屼笉璧颁笅闈㈢粺涓�寮傚父鎶涘嚭锛屾槸涓轰簡璇存槑鏇村叿浣撶偣
-                throw new RuntimeException("鍏ュ弬閿欒boCustAttr 鐨� state 鐩墠鍙敮鎸� [ADD,DEL,KIP] , boCust : " +boCustAttr);
-            }
+            //杩欓噷璁板綍鏃ュ織
+            Date endDate = DateUtil.getCurrentDate();
 
-            if(saveCustAttrFlag < 1){
-                throw new RuntimeException("淇濆瓨瀹炰緥[cust_attr]鏁版嵁澶辫触锛屽奖鍝嶈褰曟暟涓�"+saveCustAttrFlag+", cust : "+boCustAttr.convert());
-            }
+            businessServiceDataFlow.setEndDate(endDate);
+            //娣诲姞鑰楁椂
+            DataFlowFactory.addCostTime(businessServiceDataFlow, "service", "涓氬姟澶勭悊鎬昏�楁椂",
+                    businessServiceDataFlow.getStartDate(), businessServiceDataFlow.getEndDate());
+            //淇濆瓨鑰楁椂
+            saveCostTimeLogMessage(businessServiceDataFlow);
+            //淇濆瓨鏃ュ織
+            saveLogMessage(businessServiceDataFlow);
         }
-
-        return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"鎴愬姛",null);
+        return businessServiceDataFlow.getResJson();
     }
 
 
     /**
-     * 鏌ヨ瀹㈡埛淇℃伅
-     * 鍖呮嫭 鍩烘湰淇℃伅cust 鍜� 灞炴�т俊鎭� custAttr
-     * @param cust
-     * @return
-     * @throws Exception
+     * 淇濆瓨鏃ュ織淇℃伅
+     *
+     * @param businessServiceDataFlow 涓氬姟鏃ュ織瀵硅薄
      */
-    public String queryCust(Cust cust) throws Exception{
-        LoggerEngine.debug("瀹㈡埛淇℃伅鏌ヨ鍏ュ弬锛�" + cust);
-        if(cust == null || StringUtils.isBlank(cust.getCustId()) ){
-            throw new IllegalArgumentException("瀹㈡埛淇℃伅鏌ヨ鍏ュ弬涓虹┖锛宑ustId 涓虹┖ "+cust);
+    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);
         }
-        Cust newCust = iUserServiceDao.queryDataToCust(cust);
+    }
 
-        if(newCust == null){
-            return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_ERROR,"鏈壘鍒扮敤鎴蜂俊鎭�",null);
+    /**
+     * 淇濆瓨鑰楁椂淇℃伅
+     *
+     * @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);
         }
-
-        return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"鎴愬姛",JSONObject.parseObject(JSONObject.toJSONString(newCust)));
     }
 
-    public IPrimaryKeyService getiPrimaryKeyService() {
-        return iPrimaryKeyService;
-    }
-
-    public void setiPrimaryKeyService(IPrimaryKeyService iPrimaryKeyService) {
-        this.iPrimaryKeyService = iPrimaryKeyService;
-    }
 
     public IUserServiceDao getiUserServiceDao() {
         return iUserServiceDao;

--
Gitblit v1.8.0