package com.zcloud.basic.info.command;

import com.zcloud.basic.info.domain.gateway.UserJobHandoverGateway;
import com.zcloud.basic.info.domain.model.UserJobHandoverE;
import com.zcloud.basic.info.dto.UserJobHandoverAddCmd;
import com.alibaba.cola.exception.BizException;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * web-app
 *
 * @Author SondonYong
 * @Date 2025-12-02 14:08:56
 */
@Component
@AllArgsConstructor
public class UserJobHandoverAddExe {
    private final UserJobHandoverGateway userJobHandoverGateway;

    @Transactional(rollbackFor = Exception.class)
    public boolean execute(UserJobHandoverAddCmd cmd) {
        UserJobHandoverE userJobHandoverE = new UserJobHandoverE();
        BeanUtils.copyProperties(cmd, userJobHandoverE);
        boolean res = false;
        try {
            res = userJobHandoverGateway.add(userJobHandoverE);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if (!res) {
            throw new BizException("保存失败");
        }
        return true;
    }
}

