package com.zcloud.personnel.positioning.command;

import com.zcloud.personnel.positioning.domain.gateway.SyncTaskGateway;
import com.zcloud.personnel.positioning.domain.model.SyncTaskE;
import com.zcloud.personnel.positioning.dto.SyncTaskAddCmd;
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 SyncTaskAddExe {
    private final SyncTaskGateway syncTaskGateway;

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