package com.czg.service.product.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.ThreadUtil;
import com.czg.product.service.SensitiveOperationService;
import com.czg.sa.StpKit;
import com.czg.service.product.mapper.ConsInfoMapper;
import com.czg.service.product.util.WxAccountUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 敏感操作ServiceImpl
 *
 * @author tankaikai
 * @since 2025-03-17 11:47
 */
@Service
@Slf4j
public class SensitiveOperationServiceImpl implements SensitiveOperationService {

    @Resource
    private ConsInfoMapper consInfoMapper;
    @Resource
    private WxAccountUtil wxAccountUtil;

    @Override
    public void send(String operationDesc) {
        log.info("------------------------------------------------敏感操作通知开始1");
        Long shopId = StpKit.USER.getShopId(0L);
        String userName = StpKit.USER.getAccount();
        List<String> openIdList = consInfoMapper.findOpenIdList(shopId, "ope");
        if (CollUtil.isEmpty(openIdList)) {
            return;
        }
        log.info("------------------------------------------------敏感操作通知开始2");
        ThreadUtil.execAsync(() -> {
            log.info("------------------------------------------------敏感操作通知开始3");
            wxAccountUtil.sendOperationMsg(openIdList, userName, operationDesc);
            log.info("------------------------------------------------敏感操作通知开始4");
        });
    }
}
