package org.springblade.payment.handle.handler;

import org.springblade.core.mp.base.BaseService;
import org.springblade.ldt.bills.entity.Bills;
import org.springblade.ldt.bills.service.IBillsService;
import org.springblade.ldt.user.entity.LoginUser;
import org.springblade.ldt.user.service.ILoginUserService;
import org.springblade.payment.entity.SuccessParams;
import org.springblade.payment.event.UserPayCsEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
 * @author: lianghanqiang
 * @description: 执行事务插入操作
 * @since: 9/1/21 -- 10:33 AM
 */
@Component
public class DataHandle {

	@Autowired
	private ApplicationEventPublisher applicationEventPublisher;

	@Transactional(propagation = Propagation.REQUIRES_NEW)
	public <T> boolean saveOrUpdateEntity(BaseService<T> service,T t) {
		if(Objects.isNull(t)){
			return true;
		}
		return service.saveOrUpdate(t);
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public void publishEvent(ApplicationEvent applicationEvent){
		applicationEventPublisher.publishEvent(applicationEvent);
	}
}
