package org.springblade.flow.activity.listener;

import cn.hutool.core.convert.Convert;
import lombok.NoArgsConstructor;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.flow.activity.entity.ActivityEnum;
import org.springblade.ldt.activity.entity.Activity;
import org.springblade.ldt.activity.service.IActivityService;
import org.springframework.util.Assert;

/**
 * @author: lianghanqiang
 * @description: 平台审核完毕处理
 * @since: 9/3/21 -- 10:53 AM
 */
@NoArgsConstructor
public class ActivityMallCompleteListener implements TaskListener {

	private IActivityService activityService;

	{
		activityService = SpringUtil.getBean(IActivityService.class);
	}

	@Override
	public void notify(DelegateTask delegateTask) {

		long businessId = Convert.toLong(delegateTask.getVariable("businessId"));
		boolean pass = Convert.toBool(delegateTask.getVariable("pass"));

		Activity activity = activityService.getById(businessId);

		activity.setAuditStatus(pass? ActivityEnum.WAITING_PLATFORM.name():ActivityEnum.FAIL.name());

		Assert.isTrue(activityService.saveOrUpdate(activity),()->{throw  new ServiceException("活动审核： 商场审核完毕处理异常");});
	}
}
