shiyj
2019-07-07 348c483d9e8cf81c485289a44c717fe1c23f4065
CommunityService/src/main/java/com/java110/community/smo/impl/CommunityServiceSMOImpl.java
@@ -33,78 +33,80 @@
@Transactional
public class CommunityServiceSMOImpl extends BaseServiceSMO implements ICommunityServiceSMO {
    private final static Logger logger = LoggerFactory.getLogger(CommunityServiceSMOImpl.class);
    private static Logger logger = LoggerFactory.getLogger(CommunityServiceSMOImpl.class);
        @Override
        public JSONObject service(BusinessServiceDataFlow businessServiceDataFlow) throws SMOException {
            try {
                Assert.hasLength(businessServiceDataFlow.getbId(),"bId 不能为空");
    @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);
            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;
            }
            return businessServiceDataFlow.getResJson();
            //这里记录日志
            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){
    private void saveLogMessage(BusinessServiceDataFlow businessServiceDataFlow) {
        try{
            if(MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_LOG_ON_OFF))){
                for(DataFlowLog dataFlowLog :businessServiceDataFlow.getLogDatas()) {
        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);
        } 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))){
    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){
                for (DataFlowLinksCost dataFlowLinksCost : dataFlowLinksCosts) {
                    newObj = JSONObject.parseObject(JSONObject.toJSONString(dataFlowLinksCost));
                    newObj.put("dataFlowId",businessServiceDataFlow.getDataFlowId());
                    newObj.put("transactionId",businessServiceDataFlow.getTransactionId());
                    newObj.put("dataFlowId", businessServiceDataFlow.getDataFlowId());
                    newObj.put("transactionId", businessServiceDataFlow.getTransactionId());
                    costDates.add(newObj);
                }
                costDate.put("costDates",costDates);
                costDate.put("costDates", costDates);
                KafkaFactory.sendKafkaMessage(KafkaConstant.TOPIC_COST_TIME_LOG_NAME,"",costDate.toJSONString());
                KafkaFactory.sendKafkaMessage(KafkaConstant.TOPIC_COST_TIME_LOG_NAME, "", costDate.toJSONString());
            }
        }catch (Exception e){
            logger.error("报错日志出错了,",e);
        } catch (Exception e) {
            logger.error("报错日志出错了,", e);
        }
    }
}