package com.casic.missiles.service.listeners.processor;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.casic.missiles.dto.flowable.NotifyEventStatusDTO;
import com.casic.missiles.enums.BusinessExceptionEnum;
import com.casic.missiles.enums.notifyevent.ActionStatusBeanEnum;
import com.casic.missiles.exception.BusinessException;
import com.casic.missiles.service.listeners.NotifyEventPostProcessor;
import com.casic.missiles.mapper.equipment.EquipmentApplyMapper;
import com.casic.missiles.model.equipment.EquipmentApply;
import com.casic.missiles.utils.SpringContextUtil;
import org.springframework.stereotype.Service;

/**
 * 审批通过后
 * 修改设备租借状态
 *
 */
@Service(ActionStatusBeanEnum.LEASE_BEAN_NAME)
public class EquipmentLeaseEventPostProcessor implements NotifyEventPostProcessor {
    @Override
    public void doHandleNotifyEvent(NotifyEventStatusDTO notifyEventStatusDTO) {
        EquipmentApplyMapper equipmentApplyMapper = SpringContextUtil.getBean(EquipmentApplyMapper.class);
        UpdateWrapper<EquipmentApply> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", notifyEventStatusDTO.getId()).set("process_result", notifyEventStatusDTO.getStatus());
        if (equipmentApplyMapper.update(null, updateWrapper) <= 0) {
            throw new BusinessException(BusinessExceptionEnum.HANDLE_FAILED);
        }
    }
}
