StoreController.java
11.6 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.array.ArrayUtil;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.lang.Opt;
import org.dromara.hutool.core.map.MapUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.springframework.web.bind.annotation.*;
import vion.dto.StatusDTO;
import vion.dto.StoreDTO;
import vion.model.RStoreConfederate;
import vion.model.RStoreUser;
import vion.model.Store;
import vion.model.StoreLog;
import vion.service.IRStoreConfederateService;
import vion.service.IRStoreUserService;
import vion.service.IStoreLogService;
import vion.service.IStoreService;
import vion.vo.StoreVO;
import vion.vo.UserVO;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@Slf4j
public class StoreController {
private final IStoreService storeService;
private final IRStoreUserService storeUserService;
private final IStoreLogService storeLogService;
private final IRStoreConfederateService storeConfederateService;
private final Converter converter;
@PostMapping("/store")
@SaCheckPermission(value = "store:list", orRole = "admin")
public Page<StoreVO> getStoreList(StoreDTO data, @RequestBody(required = false) List<OrderItem> orderItemList) {
return storeService.getStoreList(data, orderItemList);
}
@GetMapping("/store")
@SaCheckPermission(value = "store:query", orRole = "admin")
public StoreVO getStoreById(@RequestParam Long id) {
Store store = storeService.getById(id);
return converter.convert(store, StoreVO.class);
}
@GetMapping("/storeList")
@SaCheckPermission(value = "store:list1", orRole = "admin")
public List<StoreVO> getStoreList(Long id, Long accountId, String name, Integer limit) {
List<Store> storeList = storeService.lambdaQuery()
.eq(ObjUtil.isNotNull(accountId), Store::getAccountId, accountId)
.eq(ObjUtil.isNotNull(id), Store::getId, id)
.like(StrUtil.isNotBlank(name), Store::getName, name)
.last(ObjUtil.isNotNull(limit), "limit " + limit)
.list();
var storeIdList = storeList.stream().map(Store::getId).toList();
var storeId2UserIdMap = Opt.ofEmptyAble(storeIdList)
.map(l -> storeUserService.lambdaQuery().in(RStoreUser::getStoreId, l).eq(RStoreUser::getIsMain, 1).list())
.map(suList -> suList.stream().collect(Collectors.toMap(RStoreUser::getStoreId, RStoreUser::getUserId)))
.orElse(MapUtil.empty());
var voList = converter.convert(storeList, StoreVO.class);
voList.forEach(v -> v.setMainUser(storeId2UserIdMap.getOrDefault(v.getId(), null)));
return voList;
}
@PostMapping("/stores")
@SaCheckPermission(value = "store:editAndSave", orRole = "admin")
public Object saveOrUpdate(@RequestBody StoreDTO data) {
UserVO user = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Store store = converter.convert(data, Store.class);
if (data.getId() != null) {
store.setModifyUser(user.getId());
} else {
// 创建项目时,默认维保状态为 --
store.setMaintainStatus("--");
store.setCreateUser(user.getId());
}
return storeService.saveOrUpdate(store) ? Map.of("id", store.getId()) : "失败";
}
@PostMapping("/updateStoreStatus")
@SaCheckPermission(value = "store:editStatus", orRole = "admin")
public Object updateStoreStage(@RequestBody StatusDTO statusDTO, @RequestHeader String token) {
return storeService.updateStoreStage(statusDTO, token);
}
@PostMapping("/store/bindContract")
@SaCheckPermission(value = "store:bindContract", orRole = "admin")
public String setMasterContract(@RequestBody StoreDTO dto) {
return storeService.lambdaUpdate().eq(Store::getId, dto.getId()).set(Store::getMasterContract, dto.getMasterContract()).update(new Store()) ? "绑定主合同成功" : "绑定主合同失败";
}
@GetMapping("/store/manualCal")
@SaCheckPermission(value = "store:calMaintainStatus", orRole = "admin")
// todo 权限未加,前端未使用到该接口
public String manualCalMaintainStatus(@RequestParam(required = false) List<Long> storeIdList) {
return storeService.calMaintainStatus(storeIdList);
}
@GetMapping("/store/user/{storeId}")
@SaCheckPermission(value = "store:user:list", orRole = "admin")
public List<RStoreUser> getUserList(@PathVariable Long storeId) {
return storeUserService.lambdaQuery().eq(RStoreUser::getStoreId, storeId).list();
}
@PostMapping("/store/assignUser")
@SaCheckPermission(value = "store:assignUser", orRole = "admin")
public String assignUser(@RequestBody RStoreUser storeUser) {
storeUserService.lambdaUpdate().eq(RStoreUser::getStoreId, storeUser.getStoreId()).remove();
Opt.ofNullable(storeUser.getStoreUsers())
.ifPresent(su -> storeUserService.saveBatch(Arrays.asList(su)));
return "成功";
}
@GetMapping("/store/log/{storeId}")
@SaCheckPermission(value = "store:log:list", orRole = "admin")
public Page<StoreLog> getLogList(@PathVariable Long storeId, StoreLog storeLog) {
storeLog.setStoreId(storeId);
return storeLogService.lambdaQuery(storeLog)
.page(Page.of(storeLog.getPageNum(), storeLog.getPageSize()));
}
@PostMapping("/store/log")
@SaCheckPermission(value = "store:log:save", orRole = "admin")
public String saveLog(@RequestBody StoreLog storeLog) {
return storeLogService.save(storeLog) ? "新增成功" : "新增失败";
}
@DeleteMapping("/store/log/{logId}")
@SaCheckPermission(value = "store:log:delete", orRole = "admin")
public String delLog(@PathVariable Long logId) {
return storeLogService.removeById(logId) ? "删除成功" : "删除失败";
}
@PostMapping("/store/log/{logId}")
@SaCheckPermission(value = "store:log:edit", orRole = "admin")
public String updateLog(@PathVariable Long logId, @RequestBody StoreLog storeLog) {
storeLog.setId(logId);
return storeLogService.updateById(storeLog) ? "更新成功" : "更新失败";
}
@GetMapping("/store/screen")
@SaCheckPermission(value = "store:screen", orRole = "admin")
public List<StoreVO> storeScreen() {
return storeService.storeScreen();
}
@PostMapping("/store/merge")
@SaCheckPermission(value = "store:merge", orRole = "admin")
public String mergeStore(@RequestBody StoreDTO dto) {
Assert.isFalse(ArrayUtil.hasNull(dto.getSourceId(), dto.getTargetId()), "合并项目id不能为空");
return storeService.mergeStore(dto);
}
@PostMapping("/store/tag/{id}")
@SaCheckPermission(value = "store:tag", orRole = "admin")
public String addTag(@PathVariable Long id, @RequestBody List<Long> tagIdList) {
return storeService.addTag(id, tagIdList);
}
@GetMapping("/store/fileDetail")
@SaCheckPermission(value = "store:fileDetail", orRole = "admin")
public List<Map<String, Number>> fileDetail(@RequestParam List<Long> storeIdList) {
return storeService.fileDetail(storeIdList);
}
@GetMapping("/store/logNotify")
@SaCheckPermission(value = "store:logNotify", orRole = "admin")
public String logNotify(Long id, String[] userIdStr) {
return storeService.logNotify(id, userIdStr) ? "钉钉提醒成功" : "钉钉提醒失败";
}
@GetMapping("/store/addCron")
@SaCheckPermission(value = "store:addCron", orRole = "admin")
public String addCron(Long storeId, String storeName, String cronStr, String userId) {
return storeService.addCron(storeId, storeName, cronStr, userId);
}
@GetMapping("/store/stopCron")
@SaCheckPermission(value = "store:stopCron", orRole = "admin")
public String stopCron(Long storeId) {
return storeService.stopCron(storeId);
}
@GetMapping("/store/statStage")
@SaCheckPermission(value = "store:statStage", orRole = "admin")
public Map<Integer, Long> statStage() {
return storeService.statState();
}
@GetMapping("/store/confederate")
@SaCheckPermission(value = "store:confederate:list", orRole = "admin")
public Page<RStoreConfederate> list(RStoreConfederate storeConfederate) {
return storeConfederateService.lambdaQuery(storeConfederate).page(Page.of(storeConfederate.getPageNum(), storeConfederate.getPageSize()));
}
@GetMapping("/store/confederate/{id}")
@SaCheckPermission(value = "store:confederate:query", orRole = "admin")
public RStoreConfederate getById(@PathVariable Long id) {
return storeConfederateService.getById(id);
}
@PostMapping("/store/confederate")
@SaCheckPermission(value = "store:confederate:save", orRole = "admin")
public String save(@RequestBody RStoreConfederate storeConfederate) {
return storeConfederateService.save(storeConfederate) ? "新增成功" : "新增失败";
}
@PostMapping("/store/confederate/{id}")
@SaCheckPermission(value = "store:confederate:edit", orRole = "admin")
public String update(@PathVariable Long id, @RequestBody RStoreConfederate storeConfederate) {
storeConfederate.setId(id);
return storeConfederateService.updateById(storeConfederate) ? "修改成功" : "修改失败";
}
@DeleteMapping("/store/confederate/{id}")
@SaCheckPermission(value = "store:confederate:remove", orRole = "admin")
public String remove(@PathVariable Long id) {
return storeConfederateService.removeById(id) ? "删除成功" : "删除失败";
}
@GetMapping("/store/fileNotify")
@SaCheckPermission(value = "store:fileNotify", orRole = "admin")
public String fileNotify(String storeName, String contractNo, String sourceName, String[] fileNameArr, String[] userIdStr) {
Assert.notEmpty(userIdStr, "未选择提醒人");
return storeService.fileNotify(storeName, contractNo, sourceName, fileNameArr, userIdStr) ? "钉钉提醒成功" : "钉钉提醒失败";
}
@PostMapping("/store/file/table")
@SaCheckPermission(value = "store:file:table", orRole = "admin")
public Map<String, Map<String, Map<String, Long>>> storeFileTable(StoreDTO data,
@RequestBody(required = false) List<OrderItem> orderItemList,
HttpServletResponse response) {
return storeService.storeFileTable(data, orderItemList, response);
}
@PostMapping("/store/file/export")
@SaCheckPermission(value = "store:file:export", orRole = "admin")
public void storeFileExport(StoreDTO data,
@RequestBody(required = false) List<OrderItem> orderItemList,
HttpServletResponse response) {
storeService.storeFileExport(data, orderItemList, response);
}
@GetMapping("/store/mainUser/table")
@SaCheckPermission(value = "store:mainUser:table", orRole = "admin")
public Map<String, Map<String, Long>> storeTableByMainUser() {
return storeService.storeTableByMainUser();
}
}