ServiceOrderServiceImpl.java 1.83 KB
package vion.service.impl;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Opt;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import org.springframework.stereotype.Service;
import vion.third.WechatMod;
import vion.mapper.ServiceOrderMapper;
import vion.model.ServiceOrder;
import vion.model.Task;
import vion.service.IServiceOrderService;
import vion.service.ITaskService;
import vion.service.ITaskTempService;

import java.util.List;

/**
 * @author HlQ
 * @date 2023/11/21
 */
@Service
@RequiredArgsConstructor
public class ServiceOrderServiceImpl extends ServiceImpl<ServiceOrderMapper, ServiceOrder> implements IServiceOrderService {

    private final ITaskService taskService;
    private final ITaskTempService taskTempService;
    private final WechatMod wechatMod;

    @Override
    public String sendOrder(Long id) {
        ServiceOrder order = this.getById(id);
        Task task = taskService.getById(order.getTaskId());
        return Opt.ofNullable(task.getTaskTempId())
                .map(tempId -> taskTempService.getById(tempId).getOpenid())
                .map(openid -> {
                    List<WxMpTemplateData> wxMpTemplateDataList = ListUtil.of(
                            new WxMpTemplateData("character_string5", task.getUuid()),
                            new WxMpTemplateData("thing1", order.getSubmitter() + "-" + order.getSubmitPhone()));
                    return wechatMod.sendMsg("NN6N58EOr0BE-D0f2vFipqUek4qtVXp08EJWjJora-M", openid, wxMpTemplateDataList, "https://yunwei.vionyun.com:8443/wap/service-bill?unid=" + order.getUnid());
                })
                .orElse("微信公众号消息推送失败,请检查工单是否绑定微信用户或联系管理员!");
    }
}