package com.zcloud.basic.info.command;

import com.zcloud.basic.info.domain.gateway.UserChangeRecordGateway;
import com.zcloud.basic.info.domain.model.UserChangeRecordE;
import com.zcloud.basic.info.dto.UserChangeRecordAddCmd;
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:18
 */
@Component
@AllArgsConstructor
public class UserChangeRecordAddExe {
    private final UserChangeRecordGateway userChangeRecordGateway;

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

