package cn.superdesk.uniorder.event.enterpriseTrigger;

import cn.superdesk.uniorder.common.enums.common.CommonEnabledEnum;
import cn.superdesk.uniorder.common.enums.common.CommonSoftDeleteEnum;
import cn.superdesk.uniorder.dao.entity.organisation.SysEnterprise;
import cn.superdesk.uniorder.service.order.base.CommonOrderProcessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2021/7/5 上午10:38
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/7/5 上午10:38
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Component
public class EnterpriseListener {

	@Autowired
	private CommonOrderProcessService commonOrderProcessService;

	@Async
	@EventListener
	public void handleEnterpriseEvent(EnterpriseEvent event) {

		SysEnterprise sysEnterprise = event.getSysEnterprise();

		// TODO SysEnterprise 合法性 验证

		commonOrderProcessService.cascadeUpdateTableUnifiedOrderFieldVirtName(sysEnterprise.getEnterpriseId(), sysEnterprise.getEnterpriseName());

		if (sysEnterprise.getDeleted().equals(CommonSoftDeleteEnum.删除.getKey())
				|| sysEnterprise.getEnabled().equals(CommonEnabledEnum.禁用.getKey())) {
			// TODO 触发

			commonOrderProcessService.cascadeUpdateTableEnterpriseFieldIsHasOrder(sysEnterprise.getEnterpriseId(), sysEnterprise.getEnterpriseName());
		}
	}
}
