package com.zcloud.personnel.positioning.command;

import com.zcloud.personnel.positioning.domain.gateway.TerminalBindGateway;
import com.zcloud.personnel.positioning.domain.model.TerminalBindE;
import com.zcloud.personnel.positioning.dto.TerminalBindAddCmd;
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 fangjiakai
 * @Date 2026-07-07
 */
@Component
@AllArgsConstructor
public class TerminalBindAddExe {
    private final TerminalBindGateway terminalBindGateway;

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