package com.red.circle.other.app.command.dynamic.delete;

import com.red.circle.common.business.dto.cmd.IdLongCmd;
import com.red.circle.framework.mybatis.constant.PageConstant;
import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicMessage;
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicMessageService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 动态-删除我的消息.
 * </p>
 *
 * @author pengshigang
 * @since 2022-04-13
 */
@Component
@RequiredArgsConstructor
public class DynamicMessageDelCmdExe {

  private final DynamicMessageService dynamicMessageService;

  public void execute(IdLongCmd cmd) {

    dynamicMessageService.update()
        .set(DynamicMessage::getDel, Boolean.TRUE)
        .set(DynamicMessage::getReading, Boolean.TRUE)
        .eq(DynamicMessage::getId, cmd.getId())
        .eq(DynamicMessage::getToUserId, cmd.getReqUserId())
        .last(PageConstant.LIMIT_ONE)
        .execute();

  }

}
