package com.xtd.project.activiti.event.listener;

import com.xtd.common.utils.SpringUtil;
import com.xtd.project.assets.domain.DbAssetsStock;
import com.xtd.project.assets.domain.DbAssetsStockScrap;
import com.xtd.project.assets.mapper.DbAssetsStockMapper;
import com.xtd.project.assets.mapper.DbAssetsStockScrapMapper;
import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class ScrapEndListener implements ExecutionListener {

    protected final Logger logger = LoggerFactory.getLogger(ScrapEndListener.class);

    @Autowired
    private TaskService taskService;


    @Override
    public void notify(DelegateExecution delegateExecution) {
        DbAssetsStockMapper dbAssetsStockMapper = SpringUtil.getBean(DbAssetsStockMapper.class);
        DbAssetsStockScrapMapper dbAssetsStockScrapMapper = SpringUtil.getBean(DbAssetsStockScrapMapper.class);
        String id = delegateExecution.getId();
        DbAssetsStockScrap formData = (DbAssetsStockScrap) delegateExecution.getVariable("formData");
        //获取到库存id
        Long dbAsStId = formData.getDbAsStId();
        DbAssetsStock dbAssetsStock = new DbAssetsStock();
        dbAssetsStock.setaId(dbAsStId);
        //设置为表单锁定
        //设置为报废
        dbAssetsStock.setStorageStatus(3L);
        dbAssetsStockMapper.updateDbAssetsStock(dbAssetsStock);
        logger.info("更新入库信息");
        //设置为审核通过
        formData.setState(2);
        dbAssetsStockScrapMapper.updateDbAssetsStockScrap(formData);
        logger.info("更新报废状态信息");
    }
}
