package com.zcloud.personnel.positioning.command;

import com.zcloud.personnel.positioning.domain.gateway.AreaGateway;
import com.zcloud.personnel.positioning.domain.model.AreaE;
import com.zcloud.personnel.positioning.dto.AreaAddCmd;
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 AreaAddExe {
    private final AreaGateway areaGateway;

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