package com.gic.haoban.manage.service.service.out.impl.send;

import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.send.DealQwSendDTO;
import com.gic.haoban.manage.api.service.send.QwSendApiService;
import com.gic.haoban.manage.service.service.send.QwSendMsgService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * Created by wangzubo on 2022/11/1.
 */
@Service("qwSendApiService")
@Slf4j
public class QwSendApiServiceImpl implements QwSendApiService {

    @Autowired
    private QwSendMsgService qwSendMsgService;

    @Override
    public ServiceResponse<Void> qwSendRefreshByMQ(String message) {
        if (StringUtils.isBlank(message)) {
            return ServiceResponse.success();
        }
        log.info("刷新企微发送记录:{}", message);
        DealQwSendDTO dealQwSendDTO = JSONObject.parseObject(message, DealQwSendDTO.class);
        Integer refreshType = dealQwSendDTO.getRefreshType();
        if (Objects.equals(refreshType,1)) {
            qwSendMsgService.finishQwSend(dealQwSendDTO.getFinishQwSend());
        } else if (Objects.equals(refreshType, 2)) {
            qwSendMsgService.refreshQwSendLog(dealQwSendDTO.getQwSendMsg());
        }
        return ServiceResponse.success();
    }
}
