ContractController.java
5.21 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
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import vion.cron.ContractRunner;
import vion.dto.ContractDTO;
import vion.dto.RContractStoreDTO;
import vion.model.RContractStore;
import vion.service.IContractService;
import vion.service.IRContractStoreService;
import vion.vo.ContractVO;
import java.util.List;
import java.util.stream.Collectors;
/**
* 合同管理
*/
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class ContractController {
private final IContractService contractService;
private final ContractRunner contractRunner;
private final IRContractStoreService contractStoreService;
@GetMapping("/contract")
@SaCheckPermission(value = "contract:list", orRole = "admin")
public Page<ContractVO> list(ContractDTO dto) {
return contractService.list(dto);
}
@GetMapping("/contractPart")
@SaCheckPermission(value = "contract:listPart", orRole = "admin")
public Page<ContractVO> listPart(ContractDTO dto) {
return contractService.listPart(dto);
}
@GetMapping("/contract/{id}")
@SaCheckPermission(value = "contract:query", orRole = "admin")
public ContractVO getById(@PathVariable Long id) {
return contractService.getVOById(id);
}
@GetMapping("/contractByNo/{no}")
@SaCheckPermission(value = "contract:queryByNo", orRole = "admin")
public ContractVO getByNo(@PathVariable String no) {
return contractService.getByNo(no);
}
@PostMapping("/contract/{id}")
@SaCheckPermission(value = "contract:edit", orRole = "admin")
public String updateById(@PathVariable Long id, ContractDTO dto) {
return contractService.updateById(id, null, dto);
}
@PostMapping("/contract/store")
@SaCheckPermission(value = "contract:store:edit", orRole = "admin")
public String saveOrUpdateRContractStore(@RequestBody RContractStoreDTO dto) {
Assert.isFalse(ArrayUtil.isAllNotNull(dto.getStoreId(), dto.getContractId()), "合同id和项目id不能同时传值");
if (ObjUtil.isNotNull(dto.getContractId())) {
contractStoreService.lambdaUpdate()
.eq(RContractStore::getContractId, dto.getContractId())
.remove();
Opt.ofEmptyAble(dto.getStoreIds())
.ifPresent(storeIds -> {
List<RContractStore> contractStoreList = storeIds.stream()
.map(storeId -> {
RContractStore contractStore = new RContractStore();
contractStore.setContractId(dto.getContractId());
contractStore.setStoreId(storeId);
return contractStore;
}).collect(Collectors.toList());
contractStoreService.saveBatch(contractStoreList);
});
}
if (ObjUtil.isNotNull(dto.getStoreId())) {
contractStoreService.lambdaUpdate()
.eq(RContractStore::getStoreId, dto.getStoreId())
.remove();
Opt.ofEmptyAble(dto.getContractIds())
.ifPresent(contractIds -> {
List<RContractStore> contractStoreList = contractIds.stream()
.map(contractId -> {
RContractStore contractStore = new RContractStore();
contractStore.setContractId(contractId);
contractStore.setStoreId(dto.getStoreId());
return contractStore;
}).collect(Collectors.toList());
contractStoreService.saveBatch(contractStoreList);
});
}
return "成功";
}
@GetMapping("/contract/store")
@SaCheckPermission(value = "contract:store:query", orRole = "admin")
public List<RContractStore> getRContractStore(Long contractId, Long storeId) {
return contractStoreService.lambdaQuery()
.eq(ObjUtil.isNotNull(contractId), RContractStore::getContractId, contractId)
.eq(ObjUtil.isNotNull(storeId), RContractStore::getStoreId, storeId)
.list();
}
@GetMapping("/contract/calAmount")
@SaCheckPermission(value = "contract:calAmount", orRole = "admin")
public JSONObject calAmount(ContractDTO dto) {
return contractService.calAmount(dto);
}
@GetMapping("/contract/analyze")
@SaCheckPermission(value = "contract:analyze", orRole = "admin")
public Object analyze(ContractDTO dto) {
return contractService.analyze(dto);
}
@PostMapping("/contractSync")
@SaCheckPermission(value = "contract:sync", orRole = "admin")
public String manualSyncContract() {
return contractRunner.contractSync() ? "成功" : "失败";
}
}