package com.zcloud.basic.info.command;

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


/**
 * web-app
 *
 * @Author zhangyue
 * @Date 2025-11-06 19:15:36
 */
@Component
@AllArgsConstructor
public class UserEmploymentLogAddExe {
    private final UserEmploymentLogGateway userEmploymentLogGateway;

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

