ServiceOrderController.java
3.82 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
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.dromara.hutool.core.data.id.IdUtil;
import org.dromara.hutool.core.lang.Assert;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.web.bind.annotation.*;
import vion.constant.RedisKeyEnum;
import vion.dto.ServiceOrderDTO;
import vion.model.ServiceOrder;
import vion.service.IServiceOrderService;
import vion.vo.ServiceOrderVO;
/**
* 服务单
*
* @author HlQ
* @date 2023/11/21
*/
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class ServiceOrderController {
private final IServiceOrderService serviceOrderService;
private final RedissonClient redissonClient;
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) {
RMap<Integer, String> serviceTypeMap = redissonClient.getMap(RedisKeyEnum.DICT_PREFIX.getVal() + RedisKeyEnum.SERVICE_TYPE.getVal());
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);
}
}