package com.zcloud.basic.info.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.basic.info.domain.gateway.PostGateway;
import com.zcloud.basic.info.domain.model.PostE;
import com.zcloud.basic.info.dto.PostUpdateCmd;
import com.zcloud.basic.info.persistence.dataobject.PostDO;
import com.zcloud.basic.info.persistence.repository.PostRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;



/**
 * web-app
 *
 * @Author SondonYong
 * @Date 2025-10-31 17:24:05
 */
@Component
@AllArgsConstructor
public class PostUpdateExe {
    private final PostGateway postGateway;
    private final PostRepository postRepository;
    @Transactional(rollbackFor = Exception.class)
    public void execute(PostUpdateCmd postUpdateCmd) {

        PostDO postDO = postRepository.getById(postUpdateCmd.getId());
        if (postDO == null) {
            throw new BizException("岗位不存在");
        }

        PostE postE = new PostE();
        BeanUtils.copyProperties(postUpdateCmd, postE);
        boolean res = postGateway.update(postE);

        if (!res) {
            throw new BizException("修改失败");
        }

    }
}

