| | |
| | | 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.context.DataFlow; |
| | | import com.java110.core.factory.DataFlowFactory; |
| | | import com.java110.core.factory.DataTransactionFactory; |
| | | 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.feign.base.IPrimaryKeyService; |
| | | 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; |
| | |
| | | @Transactional |
| | | public class UserServiceSMOImpl extends BaseServiceSMO implements IUserServiceSMO { |
| | | |
| | | @Autowired |
| | | private final static Logger logger = LoggerFactory.getLogger(UserServiceSMOImpl.class); |
| | | |
| | | //@Autowired |
| | | IPrimaryKeyService iPrimaryKeyService; |
| | | |
| | | @Autowired |
| | |
| | | if (userInfoJson == null){ |
| | | throw new IllegalArgumentException("soUserService 入参 为空"+userInfoJson); |
| | | } |
| | | // 客户信息处理 处理boCust节点 |
| | | doProcessBoCust(userInfoJson,paramJson,custIdKey,resultInfo); |
| | | |
| | | //客户属性信息处理 处理boCustAttr节点 |
| | | doProcessBoCustAttr(userInfoJson,paramJson,custIdKey,resultInfo); |
| | | // 客户信息处理 处理boCust节点 |
| | | doProcessBoCust(userInfoJson, paramJson, custIdKey, resultInfo); |
| | | |
| | | //客户属性信息处理 处理boCustAttr节点 |
| | | doProcessBoCustAttr(userInfoJson, paramJson, custIdKey, resultInfo); |
| | | |
| | | return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"成功",resultInfo); |
| | | |
| | |
| | | @Override |
| | | public String soUserServiceForOrderService(JSONObject userInfoJson) throws Exception { |
| | | |
| | | Assert.isNull(userInfoJson,"data","请求报文缺少 data 节点,请检查"); |
| | | Assert.isNotNull(userInfoJson,"data","请求报文缺少 data 节点,请检查"); |
| | | |
| | | JSONArray custInfos = userInfoJson.getJSONArray("data"); |
| | | |
| | |
| | | for(int boIdIndex = 0 ; boIdIndex < datas.size(); boIdIndex++){ |
| | | JSONObject data = datas.getJSONObject(boIdIndex); |
| | | |
| | | Assert.isNull(data,"boId","当前节点中没有包含boId节点格式错误"+data); |
| | | Assert.isNotNull(data,"boId","当前节点中没有包含boId节点格式错误"+data); |
| | | |
| | | // 复原Cust |
| | | doDeleteBoCust(data); |
| | |
| | | return ProtocolUtil.createResultMsg(ProtocolUtil.RETURN_MSG_SUCCESS,"成功",JSONObject.parseObject(JSONObject.toJSONString(newCust))); |
| | | } |
| | | |
| | | /** |
| | | * 根据olID查询客户信息 |
| | | * @param busiOrderStr |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public String queryCustInfoByOlId(String busiOrderStr) throws Exception{ |
| | | return doQueryCustInfoByOlId(busiOrderStr,false); |
| | | } |
| | | |
| | | /** |
| | | * 根据olID查询客户信息 需要作废的发起的报文 |
| | | * @param busiOrderStr |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public String queryNeedDeleteCustInfoByOlId(String busiOrderStr) throws Exception{ |
| | | return doQueryCustInfoByOlId(busiOrderStr,true); |
| | | } |
| | | |
| | | /** |
| | | * 查询客户订单信息 |
| | | * @param busiOrderStr 订单项信息 |
| | | * @param isNeedDelete 是否是撤单报文 true 查询撤单报文 false |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private String doQueryCustInfoByOlId(String busiOrderStr,Boolean isNeedDelete) throws Exception{ |
| | | BusiOrder busiOrder = JSONObject.parseObject(busiOrderStr, BusiOrder.class); |
| | | |
| | | if(busiOrder == null || "".equals(busiOrder.getOlId())){ |
| | | throw new IllegalArgumentException("客户信息查询入参为空,olId 为空 "+busiOrderStr); |
| | | } |
| | | |
| | | Cust cust = new Cust(); |
| | | cust.setVersionId(busiOrder.getOlId()); |
| | | //根据版本ID查询实例数据 |
| | | Cust newCust = iUserServiceDao.queryDataToCust(cust); |
| | | JSONObject returnJson = JSONObject.parseObject("{'data':{}}"); |
| | | if(newCust == null){ |
| | | return returnJson.toJSONString(); |
| | | } |
| | | |
| | | BoCust boCust = new BoCust(); |
| | | |
| | | boCust.setBoId(busiOrder.getBoId()); |
| | | boCust.setCustId(newCust.getCustId()); |
| | | boCust.setVersionId(busiOrder.getOlId()); |
| | | |
| | | List<BoCust> boCusts = iUserServiceDao.queryBoCust(boCust); |
| | | |
| | | |
| | | //一般情况下没有这种情况存在,除非 人工 改了数据,或没按流程完成数据处理 |
| | | if(boCusts == null || boCusts.size() == 0){ |
| | | return returnJson.toJSONString(); |
| | | } |
| | | |
| | | |
| | | JSONArray boCustArray = new JSONArray(); |
| | | //单纯的删除 和单纯 增加 |
| | | for(int boCustIndex = 0 ; boCustIndex < boCusts.size();boCustIndex++) { |
| | | BoCust newBoCust = boCusts.get(boCustIndex); |
| | | if(isNeedDelete) { |
| | | if (StateConstant.STATE_DEL.equals(newBoCust.getState())) { |
| | | newBoCust.setBoId(""); |
| | | newBoCust.setState(StateConstant.STATE_ADD); |
| | | } else if (StateConstant.STATE_ADD.equals(newBoCust.getState())) { |
| | | newBoCust.setState(StateConstant.STATE_DEL); |
| | | } else { |
| | | newBoCust.setState(StateConstant.STATE_KIP); |
| | | } |
| | | } |
| | | boCustArray.add(newBoCust); |
| | | } |
| | | returnJson.getJSONObject("data").put("boCust",JSONObject.toJSONString(boCustArray)); |
| | | |
| | | |
| | | //属性处理 |
| | | CustAttr oldCustAttr = new CustAttr(); |
| | | oldCustAttr.setCustId(newCust.getCustId()); |
| | | oldCustAttr.setVersionId(busiOrder.getOlId()); |
| | | List<CustAttr> custAttrs = iUserServiceDao.queryDataToCustAttr(oldCustAttr); |
| | | if(custAttrs == null || custAttrs.size() == 0){ |
| | | return returnJson.toJSONString(); |
| | | } |
| | | /** |
| | | * 查询客户查询的过程数据 |
| | | */ |
| | | BoCustAttr boCustAttr = new BoCustAttr(); |
| | | boCustAttr.setCustId(newCust.getCustId()); |
| | | boCustAttr.setVersionId(busiOrder.getOlId()); |
| | | List<BoCustAttr> boCustAttrs = iUserServiceDao.queryBoCustAttr(boCustAttr); |
| | | |
| | | |
| | | //一般情况下没有这种情况存在,除非 人工 改了数据,或没按流程完成数据处理 |
| | | if(boCustAttrs == null || boCustAttrs.size() == 0){ |
| | | return returnJson.toJSONString(); |
| | | } |
| | | |
| | | |
| | | JSONArray boCustAttrArray = new JSONArray(); |
| | | //单纯的删除 和单纯 增加 |
| | | for(BoCustAttr newBoCustAttr : boCustAttrs) { |
| | | if(isNeedDelete) { |
| | | if (StateConstant.STATE_DEL.equals(newBoCustAttr.getState())) { |
| | | newBoCustAttr.setBoId(""); |
| | | newBoCustAttr.setState(StateConstant.STATE_ADD); |
| | | } else if (StateConstant.STATE_ADD.equals(newBoCustAttr.getState())) { |
| | | newBoCustAttr.setState(StateConstant.STATE_DEL); |
| | | } else { |
| | | newBoCustAttr.setState(StateConstant.STATE_KIP); |
| | | } |
| | | } |
| | | boCustAttrArray.add(newBoCustAttr); |
| | | } |
| | | |
| | | returnJson.getJSONObject("data").put("boCustAttr",JSONObject.toJSONString(boCustAttrArray)); |
| | | |
| | | return returnJson.toJSONString(); |
| | | |
| | | } |
| | | /** |
| | | * 处理boCust 节点 |
| | | * @throws Exception |
| | |
| | | return preBoCustAttrs; |
| | | } |
| | | |
| | | |
| | | @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) { |
| | | 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(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 保存日志信息 |
| | | * @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); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保存耗时信息 |
| | | * @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 IPrimaryKeyService getiPrimaryKeyService() { |
| | | return iPrimaryKeyService; |
| | | } |