package com.zcloud.primeport.command;

import com.zcloud.primeport.domain.gateway.MkmjSwipeCardRecordGateway;
import com.zcloud.primeport.domain.model.MkmjSwipeCardRecordE;
import com.zcloud.primeport.dto.MkmjSwipeCardRecordAddCmd;
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 dearLin
 * @Date 2026-04-22 17:03:59
 */
@Component
@AllArgsConstructor
public class MkmjSwipeCardRecordAddExe {
    private final MkmjSwipeCardRecordGateway mkmjSwipeCardRecordGateway;

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

