package com.zcloud.basic.info.command;

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


/**
 * web-app
 *
 * @Author zhaokai
 * @Date 2026-01-05 14:12:18
 */
@Component
@AllArgsConstructor
public class UserExpandInfoAddExe {
    private final UserExpandInfoGateway userExpandInfoGateway;

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

