package com.zcloud.primeport.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.primeport.domain.gateway.PersonMessageGateway;
import com.zcloud.primeport.domain.model.PersonMessageE;
import com.zcloud.primeport.dto.PersonMessageAddCmd;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * web-app
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:20
 */
@Component
@AllArgsConstructor
public class PersonMessageAddExe {
    private final PersonMessageGateway personMessageGateway;

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

