package com.zcloud.personnel.positioning.command;

import com.zcloud.personnel.positioning.domain.gateway.AlarmRecordGateway;
import com.zcloud.personnel.positioning.domain.model.AlarmRecordE;
import com.zcloud.personnel.positioning.dto.AlarmRecordAddCmd;
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 AlarmRecordAddExe {
    private final AlarmRecordGateway alarmRecordGateway;

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