package com.zcloud.personnel.positioning.command;

import com.zcloud.personnel.positioning.domain.gateway.AlarmDisposeRecordGateway;
import com.zcloud.personnel.positioning.domain.model.AlarmDisposeRecordE;
import com.zcloud.personnel.positioning.dto.AlarmDisposeRecordAddCmd;
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 AlarmDisposeRecordAddExe {
    private final AlarmDisposeRecordGateway alarmDisposeRecordGateway;

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