package com.storlead.sales.service.impl.customer;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.storlead.framework.util.LoginUserUtil;
import com.storlead.framework.auth.vo.LoginUser;
import com.storlead.framework.mybatis.entity.SysBaseField;
import com.storlead.message.enums.MessageTypeEnum;
import com.storlead.message.service.impl.MessageService;
import com.storlead.sales.pojo.dto.customer.CustomerSearchDTO;
import com.storlead.sales.pojo.entity.customer.*;
import com.storlead.sales.pojo.vo.customer.*;
import com.storlead.sales.enums.ResourceTypeEnum;
import com.storlead.sales.pojo.entity.target.TargetPlanEntity;
import com.storlead.sales.pojo.entity.target.TargetQuotaEntity;
import com.storlead.sales.service.customer.*;
import com.storlead.sales.service.target.TargetPlanService;
import com.storlead.sales.service.target.TargetQuotaService;
import com.storlead.user.mapper.UserMapper;
import com.storlead.user.pojo.entity.DeptEntity;
import com.storlead.user.pojo.entity.UserEntity;
import com.storlead.user.service.IDepartService;
import com.storlead.user.service.IUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.*;

/**
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2024-07-03 10:33
 */
@Service
public class MessageAssembleServiceImpl implements MessageAssembleService {

    @Resource
    private CustomerService customerService;

    @Resource
    private BusinessService businessService;

    @Resource
    private OrderFormService orderFormService;

    @Resource
    private MessageService messageService;

    @Resource
    private IDepartService departService;

    @Resource
    private CustomerFollowUpService customerFollowUpService;

    @Resource
    private LiaisonService liaisonService;
    @Resource
    private TargetPlanService targetPlanService;
    @Resource
    private TargetQuotaService targetQuotaService;
    @Resource
    private RecordCommentService recordCommentService;
    @Resource
    private UserMapper userMapper;
    @Resource
    private IUserService userService;
    @Resource
    private BulletinService bulletinService;

    /**
     * 组装客户Map
     */
    @Override
    public void sendCustomerEventMessages(Long custormerId, String messageEventCode)  {
        CustomerMessageVO vo = new CustomerMessageVO();
        CustomerVO customer = customerService.getCustomerVOById(custormerId);
        if (Objects.isNull(customer)) {
            return;
        }
        if (Objects.nonNull(customer)) {
            BeanUtils.copyProperties(customer, vo);
        }
        if (ObjectUtils.isNull(customer.getContinent()) || Objects.isNull(customer.getCountry())){
            vo.setAreaName("官网");
        }else {
            vo.setAreaName(customer.getContinent()+"/"+customer.getCountry());
        }

        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(customer.getOwnerByName());
        }
        Set<Long> userIds = new HashSet<>();
        userIds.add(vo.getOwnerBy());
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,customer.getCustomerForm().toString(),messageEventCode,userIds,"site","wecom","sms","mail");
    }

    /**
     * 客户置公Map
     */
    @Override
    public void sendCustomerPublicMessages(Long custormerId, String messageEventCode) {
        CustomerMessageVO vo = new CustomerMessageVO();
        CustomerSearchDTO customerSearchDTO = new CustomerSearchDTO();
        customerSearchDTO.setId(custormerId);
        CustomerAllVO customer = customerService.getCustomerAllVOById(customerSearchDTO);
        if (Objects.isNull(customer)) {
            return;
        }
        if (Objects.nonNull(customer)) {
            BeanUtils.copyProperties(customer, vo);
        }
        if (ObjectUtils.isNull(customer.getContinent()) || Objects.isNull(customer.getCountry())){
            vo.setAreaName("官网");
        }else {
            vo.setAreaName(customer.getContinent()+"/"+customer.getCountry());
        }

        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(customer.getOwnerByName());
        }
        UserEntity user = userMapper.getUserInfoById(customer.getFormerOwnerBy());
        DeptEntity deptEntity = departService.getById(user.getDeptId());
        Set<Long> userIds = new HashSet<>();
        userIds.add(deptEntity.getManagerId());
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,customer.getCustomerForm().toString(),messageEventCode,userIds,"site","wecom","sms","mail");
    }

    /**
     * 组装客户Map
     */
    @Override
    public void sendCustomerEventMessages(Long custormerId, String messageEventCode, Set<Long> toUserIds)  {
        CustomerMessageVO vo = new CustomerMessageVO();
        CustomerVO customer = customerService.getCustomerVOById(custormerId);
        if (Objects.isNull(customer)) {
            return;
        }
        if (Objects.nonNull(customer)) {
            BeanUtils.copyProperties(customer, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(customer.getOwnerByName());
        }
//        vo.setAreaName(customer.getContinent()+"/"+customer.getCountry());
        if (ObjectUtils.isNull(customer.getContinent()) || Objects.isNull(customer.getCountry())){
            vo.setAreaName("官网");
        }else {
            vo.setAreaName(customer.getContinent()+"/"+customer.getCountry());
        }
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,customer.getCustomerForm().toString(),messageEventCode,toUserIds,"site","wecom","sms","mail");
    }

    @Override
    public void sendWebAddClusEventMessages(CustomerEntity customer, LiaisonEntity liaison, String messageEventCode, Set<Long> toUserIds)  {
        CustomerMessageVO vo = new CustomerMessageVO();
        if (Objects.nonNull(customer)) {
            BeanUtils.copyProperties(customer, vo);
        }
        vo.setLiaisonName(liaison.getName());
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,customer.getCustomerForm().toString(),messageEventCode,toUserIds,"site","wecom","sms","mail");
    }

    /**
     * 商机发送消息
     * @param bussinessId
     * @param messageEventCode
     */
    @Override
    public void sendBusinessEventMessages(Long bussinessId, String messageEventCode, Set<Long> toUserIds) {

        BusinessMessageVO vo = new BusinessMessageVO();
        BusinessDetailVO businessDetailVO = businessService.getBusinessVOById(bussinessId);
        if (Objects.isNull(businessDetailVO)) {
            return;
        }
        if (Objects.nonNull(businessDetailVO)) {
            BeanUtils.copyProperties(businessDetailVO, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(businessDetailVO.getOwnerByName());
        }

        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,"30",messageEventCode,toUserIds,"site","wecom","sms","mail");

    }

    @Override
    public void sendBusinessEventMessages(Long bussinessId, String messageEventCode) {

        BusinessMessageVO vo = new BusinessMessageVO();
        BusinessDetailVO businessDetailVO = businessService.getBusinessVOById(bussinessId);
        if (Objects.isNull(businessDetailVO)) {
            return;
        }
        if (Objects.nonNull(businessDetailVO)) {
            BeanUtils.copyProperties(businessDetailVO, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(businessDetailVO.getOwnerByName());
        }
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,"30",messageEventCode,null,"site","wecom","sms","mail");

    }

    /**
     * 订单业务发送消息
     * @param orderId
     * @param messageEventCode
     */
    @Override
    public void sendOrderEventMessages(Long orderId, String messageEventCode) {
        OrderMessageVO vo = new OrderMessageVO();
        OrderFormDetailVO orderFormDetailVO = orderFormService.getOrderFormVOById(orderId);
        if (Objects.isNull(orderFormDetailVO)) {
            return;
        }
        if (Objects.nonNull(orderFormDetailVO)) {
            BeanUtils.copyProperties(orderFormDetailVO, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(orderFormDetailVO.getOwnerByName());
        }
        Set<Long> userIds = new HashSet<>();
        userIds.add(vo.getOwnerBy());
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
         messageService.autoMatchEventSendMessage(messageMap,"40",messageEventCode,userIds,"site","wecom","sms","mail");
    }

    @Override
    public void sendOrderParentEventMessages(Long orderId, String messageEventCode) {
        OrderMessageVO vo = new OrderMessageVO();
        OrderFormDetailVO orderFormDetailVO = orderFormService.getOrderFormVOById(orderId);
        if (Objects.isNull(orderFormDetailVO)) {
            return;
        }
        if (Objects.nonNull(orderFormDetailVO)) {
            BeanUtils.copyProperties(orderFormDetailVO, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(orderFormDetailVO.getOwnerByName());
        }
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,"40",messageEventCode,null,"site","wecom","sms","mail");
    }


    @Override
    public void sendOrderEventMessages(Long custormerId, String messageEventCode, Set<Long> toUserIds) {
        OrderMessageVO vo = new OrderMessageVO();
        OrderFormDetailVO orderFormDetailVO = orderFormService.getOrderFormVOById(custormerId);
        if (Objects.isNull(orderFormDetailVO)) {
            return;
        }
        if (Objects.nonNull(orderFormDetailVO)) {
            BeanUtils.copyProperties(orderFormDetailVO, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(orderFormDetailVO.getOwnerByName());
        }
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,"40",messageEventCode,toUserIds,"site","wecom","sms","mail");
    }

    @Override
    public void sendFollowEventMessages(Long followId, String messageEventCode) {
        FollowMessageVO vo = new FollowMessageVO();
        CustomerFollowUpDetailVO detailVO = customerFollowUpService.getVOById(followId);
        if (Objects.isNull(detailVO)) {
            return;
        }
        if (Objects.nonNull(detailVO)) {
            BeanUtils.copyProperties(detailVO, vo);
        }
        vo.setResourceTypeName(ResourceTypeEnum.getCodeByValue(detailVO.getResourceType()));
        String resourceName = customerFollowUpService.getResourceTyepName(detailVO.getResourceType(),detailVO.getResourceTypeId().toString());
        vo.setResourceName(resourceName);
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(detailVO.getOwnerByName());
        }
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,"90",messageEventCode,null,"site","wecom","sms","mail");
    }

    @Override
    public void sendFollowEventMessages(Long followId, String messageEventCode, Set<Long> toUserIds) {
        FollowMessageVO vo = new FollowMessageVO();
        CustomerFollowUpDetailVO detailVO = customerFollowUpService.getVOById(followId);
        if (Objects.isNull(detailVO)) {
            return;
        }
        if (Objects.nonNull(detailVO)) {
            BeanUtils.copyProperties(detailVO, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(detailVO.getOwnerByName());
        }
        vo.setResourceTypeName(ResourceTypeEnum.getCodeByValue(detailVO.getResourceType()));
        String resourceName = customerFollowUpService.getResourceTyepName(detailVO.getResourceType(),detailVO.getResourceTypeId().toString());
        vo.setResourceName(resourceName);
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        if (Objects.nonNull(detailVO.getResourceTypeId())) {
            messageMap.put("id",detailVO.getResourceTypeId());
        }
        messageMap.put("callbackUrl",getRouteUrl(detailVO.getResourceType()));
        messageService.autoMatchEventSendMessage(messageMap,"90",messageEventCode,toUserIds,"site","wecom","sms","mail");
    }


    /**
     * 联系人发送消息
     * @param liaisonId
     * @param messageEventCode
     */
    @Override
    public void sendLiaisonEventMessages(Long liaisonId, String messageEventCode, Set<Long> toUserIds) {

        LiaisonMessageVO vo = new LiaisonMessageVO();
        LiaisonListVO  liaisonVo = liaisonService.getLiaisonById(liaisonId);
        if (Objects.isNull(liaisonVo)) {
            return;
        }
        if (Objects.nonNull(liaisonVo)) {
            BeanUtils.copyProperties(liaisonVo, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(liaisonVo.getOwnerByName());
        }
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,"20",messageEventCode,toUserIds,"site","wecom","sms","mail");

    }

    @Override
    public void sendLiaisonEventMessages(Long liaisonId, String messageEventCode) {

        LiaisonMessageVO vo = new LiaisonMessageVO();
        LiaisonListVO  liaisonVo = liaisonService.getLiaisonById(liaisonId);
        if (Objects.isNull(liaisonVo)) {
            return;
        }
        if (Objects.nonNull(liaisonVo)) {
            BeanUtils.copyProperties(liaisonVo, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(liaisonVo.getOwnerByName());
        }
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,"20",messageEventCode,null,"site","wecom","sms","mail");

    }

    @Override
    public void sendTargetEventMessages(Long targetQuotaId, String messageEventCode, Set<Long> toUserIds, String jump) {

        TargetQuotaEntity targetQuotaEntity = targetQuotaService.getById(targetQuotaId);
        Long targetPlanId = targetQuotaEntity.getTargetPlanId();
        PerformanceGoalMessgeVO vo = new PerformanceGoalMessgeVO();
        TargetPlanEntity targetPlanEntity = targetPlanService.getById(targetPlanId);
        if (Objects.isNull(targetPlanEntity)) {
            return;
        }
        BeanUtils.copyProperties(targetPlanEntity,vo);
        SysBaseField.dictFiled(vo);
        SysBaseField.orgFileds(vo);
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        vo.setOperateByName(loginUser.getRealName());

        vo.setJump(jump);
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);

        messageService.autoMatchEventSendMessage(messageMap,MessageTypeEnum.PERFORMANCE_GOAL.getCode(),messageEventCode,toUserIds,"site","wecom","sms","mail");

    }

    @Override
    public void sendTargetPlanEventMessages(Long targetPlanId, String messageEventCode, Set<Long> toUserIds, String jump) {

        if (CollectionUtils.isEmpty(toUserIds)){
            return;
        }
        PerformanceGoalMessgeVO vo = new PerformanceGoalMessgeVO();
        TargetPlanEntity targetPlanEntity = targetPlanService.getById(targetPlanId);
        if (Objects.isNull(targetPlanEntity)) {
            return;
        }
        BeanUtils.copyProperties(targetPlanEntity,vo);
        SysBaseField.dictFiled(vo);
        SysBaseField.orgFileds(vo);
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        vo.setOperateByName(loginUser.getRealName());
        vo.setJump(jump);
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);

        messageService.autoMatchEventSendMessage(messageMap,MessageTypeEnum.PERFORMANCE_GOAL.getCode(),messageEventCode,toUserIds,"site","wecom","sms","mail");

    }

    @Override
    public void sendTargetEventMessages(TargetQuotaEntity targetQuotaEntity, String messageEventCode, Set<Long> toUserIds, String jump) {

//        TargetQuotaEntity targetQuotaEntity = targetQuotaService.getById(targetQuotaId);
        Long targetPlanId = targetQuotaEntity.getTargetPlanId();
        PerformanceGoalMessgeVO vo = new PerformanceGoalMessgeVO();
        TargetPlanEntity targetPlanEntity = targetPlanService.getById(targetPlanId);
        if (Objects.isNull(targetPlanEntity)) {
            return;
        }
        BeanUtils.copyProperties(targetPlanEntity,vo);
        SysBaseField.dictFiled(vo);
        SysBaseField.orgFileds(vo);
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        vo.setOperateByName(loginUser.getRealName());
        vo.setJump(jump);
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);

        messageService.autoMatchEventSendMessage(messageMap,MessageTypeEnum.PERFORMANCE_GOAL.getCode(),messageEventCode,toUserIds,"site","wecom","sms","mail");

    }

    @Override
    public void sendTargetEventMessages(Long targetQuotaId, String messageEventCode, String jump) {


    }


    @Override
    public void sendRecordCommentMessages(Long followId, String messageEventCode) {
        FollowMessageVO vo = new FollowMessageVO();
        CustomerFollowUpDetailVO detailVO = customerFollowUpService.getVOById(followId);
        CustomerVO customerVO = customerService.getCustomerVOById(detailVO.getCustomerId());
        if (Objects.isNull(detailVO)) {
            return;
        }
        if (Objects.nonNull(detailVO)) {
            BeanUtils.copyProperties(detailVO, vo);
        }
        vo.setResourceTypeName(ResourceTypeEnum.getCodeByValue(detailVO.getResourceType()));
        String resourceName = customerFollowUpService.getResourceTyepName(detailVO.getResourceType(),detailVO.getResourceTypeId().toString());
        CustomerEntity customerEntity = customerService.getById(detailVO.getCustomerId());
        vo.setCustomerName(customerEntity.getCustomerName());
        vo.setResourceName(resourceName);
        vo.setId(customerEntity.getId());
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(detailVO.getOwnerByName());
        }
        Set<Long> userIds = new HashSet<>();
        userIds.add(detailVO.getOwnerBy());
        if (detailVO.getOwnerBy()!= customerVO.getOwnerBy()){
            userIds.add(customerVO.getOwnerBy());
        }
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        messageService.autoMatchEventSendMessage(messageMap,customerEntity.getCustomerForm().toString(),messageEventCode,userIds,"site","wecom","sms","mail");
    }

    @Override
    public void sendBulletinMessages(Long bulletinId, String messageEventCode,String remindMode) {
        BulletinMessageVO vo = new BulletinMessageVO();
        BulletinDetailVO bulletinDetailVO = bulletinService.getBulletinDetailVOById(bulletinId);
        if (Objects.isNull(bulletinDetailVO)) {
            return;
        }
        if (Objects.nonNull(bulletinDetailVO)) {
            BeanUtils.copyProperties(bulletinDetailVO, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(bulletinDetailVO.getPublisher());
        }
        LambdaQueryWrapper<UserEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserEntity::getIsDelete,0);
        queryWrapper.eq(UserEntity::getEnabled,true);
        List<UserEntity> userEntities = userService.list(queryWrapper);
        Set<Long> userIds = new HashSet<>();
        for (UserEntity entity : userEntities) {
            userIds.add(entity.getId());
        }
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        // 拆解 remindMode 字符串
        String[] channels = remindMode.split(",");

        // 判断渠道数量
        if (channels.length > 1) {
            // 大于一个渠道时，拆解并传递
            messageService.autoMatchEventSendMessage(messageMap,"120",messageEventCode,userIds,channels);
        } else {
            messageService.autoMatchEventSendMessage(messageMap,"120",messageEventCode,userIds,remindMode);
        }

    }

    @Override
    public void sendBulletinMessages(Long bulletinId, String messageEventCode, Set<Long> toUserIds,String remindMode) {
        BulletinMessageVO vo = new BulletinMessageVO();
        BulletinDetailVO bulletinDetailVO = bulletinService.getBulletinDetailVOById(bulletinId);
        if (Objects.isNull(bulletinDetailVO)) {
            return;
        }
        if (Objects.nonNull(bulletinDetailVO)) {
            BeanUtils.copyProperties(bulletinDetailVO, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(bulletinDetailVO.getPublisher());
        }

        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        // 拆解 remindMode 字符串
        String[] channels = remindMode.split(",");
        // 判断渠道数量
        if (channels.length > 1) {
            // 大于一个渠道时，拆解并传递
            messageService.autoMatchEventSendMessage(messageMap,"120",messageEventCode,toUserIds,channels);
        } else {
            messageService.autoMatchEventSendMessage(messageMap,"120",messageEventCode,toUserIds,remindMode);
        }
    }

    @Override
    public void sendBulletinCommentMessages(Long userId,Long bulletinId, String messageEventCode) {
        BulletinMessageVO vo = new BulletinMessageVO();
        BulletinDetailVO bulletinDetailVO = bulletinService.getBulletinDetailVOById(bulletinId);
        if (Objects.isNull(bulletinDetailVO)) {
            return;
        }
        if (Objects.nonNull(bulletinDetailVO)) {
            BeanUtils.copyProperties(bulletinDetailVO, vo);
        }
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        if (Objects.nonNull(loginUser)) {
            vo.setOperateByName(loginUser.getRealName());
        } else {
            vo.setOperateByName(bulletinDetailVO.getPublisher());
        }
        LambdaQueryWrapper<UserEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserEntity::getIsDelete, 0);
        queryWrapper.eq(UserEntity::getId,bulletinDetailVO.getOwnerBy());
        List<UserEntity> userEntities = userService.list(queryWrapper);
        Set<Long> userIds = new HashSet<>();
        if (Objects.nonNull(userId)) {
            userIds.add(Long.valueOf(userId));
        }
        for (UserEntity entity : userEntities) {
            userIds.add(entity.getId());
        }
        String remindMode = bulletinDetailVO.getRemindMode();
        Map<String,Object> messageMap = BeanUtil.beanToMap(vo);
        // 拆解 remindMode 字符串
        String[] channels = remindMode.split(",");

        // 判断渠道数量
        if (channels.length > 1) {
            // 大于一个渠道时，拆解并传递
            messageService.autoMatchEventSendMessage(messageMap,"120",messageEventCode,userIds,channels);
        } else {
            messageService.autoMatchEventSendMessage(messageMap,"120",messageEventCode,userIds,remindMode);
        }
    }


    public String getRouteUrl(String resourceType) {
        if (MessageTypeEnum.CUSTOMER.getCode().equals(resourceType)) {
            return  "/customer/customerDetail?id=${id}$";
        } else if (MessageTypeEnum.CLUS.getCode().equals(resourceType)) {
            return  "/clue/detail?id=${id}$";
        } else if (MessageTypeEnum.LIAISON.getCode().equals(resourceType)) {
            return  "/liaison/detail?id=${id}$";
        } else if (MessageTypeEnum.BUSINESS.getCode().equals(resourceType)) {
            return  "/business_opportunity/detail?id=${id}$&type=detail&from=allBusiness";
        } else if (MessageTypeEnum.ORDER_FORM.getCode().equals(resourceType)) {
            return  "/order/detail?id=${id}$";
        }
        return "";
    }
}
