PointDesignController.java
5.46 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.liaochong.myexcel.core.DefaultExcelBuilder;
import com.github.liaochong.myexcel.core.watermark.Watermark;
import com.github.liaochong.myexcel.utils.WatermarkUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.dromara.hutool.core.date.TimeUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.springframework.web.bind.annotation.*;
import vion.dto.PointInfoDTO;
import vion.model.RejectInfo;
import vion.service.IPointInfoService;
import vion.third.WechatMod;
import vion.utils.excel.AttachmentExportUtil;
import vion.vo.PointInfoVO;
import vion.vo.UserVO;
import java.awt.*;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
/**
* 点位管理
*
* @author HlQ
* @date 2024/1/8
*/
@RestController
@RequestMapping("/api/point")
@RequiredArgsConstructor
@Slf4j
public class PointDesignController {
private final IPointInfoService pointInfoService;
private final WechatMod wechatMod;
@PostMapping("/frontSubmit")
public Object frontSubmit(PointInfoDTO dto) {
return pointInfoService.frontSubmit(dto);
}
@PostMapping
@SaCheckPermission(value = "point:save", orRole = "admin")
public Object save(PointInfoDTO dto) {
return pointInfoService.save(dto);
}
@PostMapping("/{id}")
@SaCheckPermission(value = "point:edit", orRole = "admin")
public String updById(@PathVariable Long id, PointInfoDTO dto) {
return pointInfoService.upd(id, null, dto);
}
@PostMapping("/upd/{uuid}")
public String updById(@PathVariable String uuid, PointInfoDTO dto) {
return pointInfoService.upd(null, uuid, dto);
}
@GetMapping
@SaCheckPermission(value = "point:list", orRole = "admin")
public Page<PointInfoVO> list(PointInfoDTO dto) {
return pointInfoService.list(dto);
}
@GetMapping("/{id}")
@SaCheckPermission(value = "point:query", orRole = "admin")
public PointInfoVO getPointById(@PathVariable Long id) {
return pointInfoService.getPointDetail(id, null);
}
@GetMapping("/get/{uuid}")
public PointInfoVO getPointByUuid(@PathVariable String uuid) {
return pointInfoService.getPointDetail(null, uuid);
}
@DeleteMapping("/{id}")
@SaCheckPermission(value = "point:remove", orRole = "admin")
public String delById(@PathVariable Long id) {
return pointInfoService.delById(id);
}
@PostMapping("/client/reject")
public String clientReject(@RequestBody RejectInfo dto) {
return pointInfoService.reject(dto, "client");
}
@PostMapping("/reject")
@SaCheckPermission(value = "point:reject", orRole = "admin")
public String reject(@RequestBody RejectInfo dto) {
return pointInfoService.reject(dto, null);
}
@GetMapping("/reject/{pointId}")
@SaCheckPermission(value = "point:reject:list", orRole = "admin")
public Page<RejectInfo> rejectInfoList(@PathVariable Long pointId, RejectInfo dto) {
return pointInfoService.rejectInfoList(pointId, dto);
}
@GetMapping("/reject/uuid/{uuid}")
public Page<RejectInfo> rejectInfoPage(@PathVariable String uuid, RejectInfo dto) {
return pointInfoService.rejectInfoList(uuid, dto);
}
@GetMapping("/desgin/push")
@SaCheckPermission(value = "point:design:push", orRole = "admin")
public Object designPush(Long pointId, String pushType) {
return pointInfoService.designPush(pointId, null, pushType);
}
@GetMapping("/export")
@SaCheckPermission(value = "point:export", orRole = "admin")
public void pointExport(PointInfoDTO dto, HttpServletResponse response) {
UserVO user = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
dto.setPageSize(30000);
Page<PointInfoVO> voPage = pointInfoService.list(dto);
voPage.getRecords().forEach(v -> v.setPointUrl("https://yunwei.vionyun.com:8443/wap/setup-device?uuid=" + v.getUuid()));
try (DefaultExcelBuilder<PointInfoVO> defaultExcelBuilder = DefaultExcelBuilder.of(PointInfoVO.class)) {
Workbook workbook = defaultExcelBuilder.build(voPage.getRecords());
// 水印添加指定字体,并在服务器上安装 SimSun 字体,解决中文字体变成方块的问题
Watermark watermark = new Watermark();
watermark.setText(user.getUsername() + "-" + user.getPhone());
watermark.setFont(new Font("SimSun", Font.PLAIN, 16));
WatermarkUtil.addWatermark(workbook, watermark);
AttachmentExportUtil.export(workbook, StrUtil.format("点位设计列表_{}", TimeUtil.formatNormal(LocalDateTime.now())), response);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@PostMapping("/install/submit/{uuid}")
public String installSubmit(@PathVariable String uuid, @RequestBody List<String> deviceList) {
return pointInfoService.installSubmit(uuid, deviceList);
}
@GetMapping("/getBindQRCode")
public String getBindQRCode(String uuid) {
return wechatMod.genBindOpenidQRCode(uuid);
}
@GetMapping("/getBindOpenid")
public Object genBindOpenidQRCode(String uuid, String code) {
return pointInfoService.bindOpenid(uuid, code);
}
}