package com.hzs.sale.order.service.impl;

import cn.hutool.json.JSONUtil;
import com.hzs.common.core.enums.EApprovalBusiness;
import com.hzs.common.domain.sale.order.SaOrder;
import com.hzs.sale.order.service.ISaOrderRevokeService;
import com.hzs.system.sys.IApprovalServiceApi;
import com.hzs.system.sys.dto.ApprovalSubmitDTO;
import com.hzs.system.sys.dto.LoginUser;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * 撤单逻辑类
 */
@Service
public class SaOrderRevokeServiceImpl implements ISaOrderRevokeService {

    @DubboReference
    IApprovalServiceApi iApprovalServiceApi;

    @Override
    public void revokeSaOrder(SaOrder saOrder, LoginUser loginUser) {
        ApprovalSubmitDTO approvalSubmitDTO = ApprovalSubmitDTO.builder()
                .eApprovalBusiness(EApprovalBusiness.ORDER_CANCEL)
                .businessCode(saOrder.getOrderCode())
                .businessData(JSONUtil.toJsonStr(saOrder))
                .build();
        iApprovalServiceApi.submit(approvalSubmitDTO, loginUser);
    }
}
