ServiceOrderController.java
4.03 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.data.id.IdUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import vion.dto.ServiceOrderDTO;
import vion.model.Dictionary;
import vion.model.ServiceOrder;
import vion.service.IDictionaryService;
import vion.service.IServiceOrderService;
import vion.vo.ServiceOrderVO;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 服务单
*
* @author HlQ
* @date 2023/11/21
*/
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class ServiceOrderController {
private final IServiceOrderService serviceOrderService;
private final IDictionaryService dictionaryService;
private final Converter converter;
@GetMapping("/orders")
@SaCheckPermission(value = "order:list", orRole = "admin")
public Page<ServiceOrderVO> getServiceOrderList(ServiceOrderDTO data) {
return serviceOrderService.getServiceOrderList(data);
}
@GetMapping("/order/{id}")
@SaCheckPermission(value = "order:query", orRole = "admin")
public ServiceOrder getOrderById(@PathVariable Long id) {
return serviceOrderService.getById(id);
}
@PostMapping("/order")
@SaCheckPermission(value = "order:save", orRole = "admin")
public Object save(@RequestBody ServiceOrderDTO serviceOrderDTO) {
Long count = serviceOrderService.lambdaQuery().eq(ServiceOrder::getTaskId, serviceOrderDTO.getTaskId()).count();
Assert.isFalse(count > 0, "该工单已存在服务单,不能重复创建!");
ServiceOrder serviceOrder = converter.convert(serviceOrderDTO, ServiceOrder.class);
serviceOrder.setUnid(IdUtil.nanoId());
return serviceOrderService.save(serviceOrder) ? serviceOrder.getId() : "创建失败";
}
@PostMapping("/order/{id}")
@SaCheckPermission(value = "order:edit", orRole = "admin")
public String update(@PathVariable Long id, @RequestBody ServiceOrderDTO serviceOrderDTO) {
ServiceOrder serviceOrder = converter.convert(serviceOrderDTO, ServiceOrder.class);
serviceOrder.setId(id);
return serviceOrderService.updateById(serviceOrder) ? "更新成功" : "更新失败";
}
@DeleteMapping("/order/{id}")
@SaCheckPermission(value = "order:remove", orRole = "admin")
public String remove(@PathVariable Long id) {
return serviceOrderService.removeById(id) ? "删除成功" : "删除失败";
}
@GetMapping("/order/sign/{unid}")
public ServiceOrderVO getOrderByUnid(@PathVariable String unid) {
// todo 字典加入缓存
List<Dictionary> dictionaryList = dictionaryService.lambdaQuery().eq(Dictionary::getType, "service_type").list();
Map<Integer, String> serviceTypeMap = dictionaryList.stream().collect(Collectors.toMap(Dictionary::getKey, Dictionary::getValue));
ServiceOrder order = serviceOrderService.lambdaQuery().eq(ServiceOrder::getUnid, unid).one();
ServiceOrderVO vo = converter.convert(order, ServiceOrderVO.class);
vo.setServiceType(serviceTypeMap.get(order.getServiceType()));
return vo;
}
/**
* 签字专用更新接口
*
* @param unid 服务单unid
* @param serviceOrderDTO dto
* @return java.lang.String
*/
@PostMapping("/order/sign/{unid}")
public String updateByUnid(@PathVariable String unid, @RequestBody ServiceOrderDTO serviceOrderDTO) {
ServiceOrder serviceOrder = converter.convert(serviceOrderDTO, ServiceOrder.class);
return serviceOrderService.lambdaUpdate().eq(ServiceOrder::getUnid, unid).update(serviceOrder) ? "提交成功" : "提交失败";
}
@GetMapping("/order/pushWechat")
@SaCheckPermission(value = "order:wechatPush", orRole = "admin")
public String sendOrder(Long id) {
return serviceOrderService.sendOrder(id);
}
}