package com.fjhx.service.flow;

import com.fjhx.params.JumpVo;
import com.fjhx.params.water.WaterVo;
import com.fjhx.service.water.WaterService;
import com.fjhx.utils.ExampleAbstract;
import com.fjhx.utils.FlowConstructor;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
 * 退货报废审批流
 */
@Service
public class ReturnOrScrapIssueFlowService {

    @Autowired
    private WaterService waterService;

    private final FlowConstructor flowConstructor = FlowConstructor.init(new ExampleAbstract() {

        @Override
        public String getCode() {
            return "js_returnOrScrapIssue";
        }

        @Override
        public void end() {
            WaterVo waterVo = getCacheData(WaterVo.class);
            waterService.add(waterVo);
        }

    });

    @Transactional(rollbackFor = Exception.class)
    public void create(WaterVo waterVo) {
        String title = Objects.requireNonNull(AuthUtil.getUser()).getUserName() + "的退货/报损申请";
        flowConstructor.create(waterVo.getId(), title, waterVo.getRemark(), waterVo);
    }

    @Transactional(rollbackFor = Exception.class)
    public void jump(JumpVo jumpVo) {
        flowConstructor.jump(jumpVo);
    }

}
