StoreController.java
3.23 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
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 lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.dto.StatusDTO;
import vion.dto.StoreDTO;
import vion.model.Contract;
import vion.model.RContractStore;
import vion.model.Store;
import vion.service.IContractService;
import vion.service.IRContractStoreService;
import vion.service.IStoreService;
import vion.vo.ContractVO;
import vion.vo.StoreVO;
import vion.vo.UserVO;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping(Global.BASE_URL)
@RequiredArgsConstructor
@Slf4j
public class StoreController {
private final IStoreService storeService;
private final IContractService contractService;
private final IRContractStoreService contractStoreService;
private final Converter converter;
@GetMapping("/stores")
@SaCheckPermission(value = "store:list", orRole="admin")
public Page<StoreVO> getStoreList(StoreDTO data) {
return storeService.getStoreList(data);
}
@GetMapping("/store")
@SaCheckPermission(value = "store:query", orRole="admin")
public StoreVO getStoreById(@RequestParam Integer id) {
Store store = storeService.getById(id);
return converter.convert(store, StoreVO.class);
}
@GetMapping("/storeList")
@SaCheckPermission(value = "store:list1", orRole="admin")
public List<StoreVO> getStoreList(Integer accountId) {
List<Store> storeList = storeService.lambdaQuery()
.eq(accountId != null, Store::getAccountId, accountId)
.list();
return converter.convert(storeList, StoreVO.class);
}
@PostMapping("/stores")
@SaCheckPermission(value = "store:editAndSave", orRole="admin")
public String saveOrUpdate(@RequestBody StoreDTO data, @RequestHeader String token) {
UserVO user = Global.USERNAME_MAP.get(token);
Store store = converter.convert(data, Store.class);
if (data.getId() != null) {
store.setModifyUser(user.getId());
} else {
store.setCreateUser(user.getId());
}
return storeService.saveOrUpdate(store) ? "成功" : "失败";
}
@PostMapping("/updateStoreStatus")
@SaCheckPermission(value = "store:editStatus", orRole="admin")
public Object updateStoreStage(StatusDTO statusDTO, @RequestHeader String token) {
return storeService.updateStoreStage(statusDTO, token);
}
@GetMapping("/store/contract/{id}")
@SaCheckPermission(value = "store:contract", orRole="admin")
// todo 权限未加库
public List<ContractVO> listContractById(@PathVariable Long id) {
List<RContractStore> contractStoreList = contractStoreService.lambdaQuery().eq(RContractStore::getStoreId, id).list();
List<Long> contractIdList = contractStoreList.stream().map(RContractStore::getContractId).collect(Collectors.toList());
List<Contract> contractList = contractService.lambdaQuery().in(Contract::getId, contractIdList).list();
return converter.convert(contractList, ContractVO.class);
}
}