ServiceOrderServiceImpl.java
3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package vion.service.impl;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Opt;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import org.springframework.stereotype.Service;
import vion.dto.ServiceOrderDTO;
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 vion.third.WechatMod;
import vion.vo.ServiceOrderVO;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author HlQ
* @date 2023/11/21
*/
@Service
@RequiredArgsConstructor
public class ServiceOrderServiceImpl extends MPJBaseServiceImpl<ServiceOrderMapper, ServiceOrder> implements IServiceOrderService {
private final ITaskService taskService;
private final ITaskTempService taskTempService;
private final WechatMod wechatMod;
private final Converter converter;
@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("微信公众号消息推送失败,请检查工单是否绑定微信用户或联系管理员!");
}
@Override
public Page<ServiceOrderVO> getServiceOrderList(ServiceOrderDTO data) {
ServiceOrder serviceOrder = converter.convert(data, new ServiceOrder());
List<Long> taskIds = null;
if (data.getStoreId() != null) {
taskIds = taskService.getBaseMapper().selectList(Wrappers.lambdaQuery(Task.class)
.select(Task::getId).eq(Task::getStoreId, data.getStoreId()))
.stream().map(Task::getId).collect(Collectors.toList());
}
Page<ServiceOrder> serviceOrderPage = this.lambdaQuery(serviceOrder)
.in(CollectionUtils.isNotEmpty(taskIds), ServiceOrder::getTaskId, taskIds)
.page(Page.of(data.getPageNum(), data.getPageSize()));
List<ServiceOrderVO> orderVOList = serviceOrderPage.getRecords().stream().map(order -> converter.convert(order, new ServiceOrderVO())).collect(Collectors.toList());
return Page.<ServiceOrderVO>of(data.getPageNum(), data.getPageSize(), serviceOrderPage.getTotal()).setRecords(orderVOList);
}
}