ContractController.java
8.53 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
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 org.apache.poi.ss.usermodel.Workbook;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.text.CharSequenceUtil;
import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.core.util.ObjUtil;
import org.dromara.hutool.json.JSONObject;
import org.springframework.web.bind.annotation.*;
import vion.cron.ContractRunner;
import vion.dto.ContractDTO;
import vion.dto.RContractStoreDTO;
import vion.dto.RContractTeamDTO;
import vion.model.RContractProduct;
import vion.model.RContractStore;
import vion.model.RContractUser;
import vion.service.IContractService;
import vion.service.IRContractStoreService;
import vion.utils.excel.AttachmentExportUtil;
import vion.vo.ContractVO;
import vion.vo.UserVO;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 合同管理
*/
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class ContractController {
private final IContractService contractService;
private final IRContractStoreService contractStoreService;
private final ContractRunner contractRunner;
@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("/contractMain")
@SaCheckPermission(value = "contract:listMain", orRole = "admin")
public Page<ContractVO> listMain(ContractDTO dto) {
return contractService.listByMain(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:save", orRole = "admin")
public String bindStore(@RequestBody RContractStoreDTO dto) {
Assert.notNull(dto.getContractId(), "合同id不能为空");
Assert.notNull(dto.getStoreId(), "项目id不能为空");
RContractStore contractStore = new RContractStore();
contractStore.setContractId(dto.getContractId());
contractStore.setStoreId(dto.getStoreId());
return contractStoreService.save(contractStore) ? "绑定成功" : "绑定失败";
}
@DeleteMapping("/contract/store")
@SaCheckPermission(value = "contract:store:remove", orRole = "admin")
public String unbindStore(@RequestBody RContractStoreDTO dto) {
Assert.notNull(dto.getContractId(), "合同id不能为空");
Assert.notNull(dto.getStoreId(), "项目id不能为空");
return contractStoreService.lambdaUpdate()
.eq(RContractStore::getContractId, dto.getContractId())
.eq(RContractStore::getStoreId, dto.getStoreId())
.remove() ? "解绑成功" : "解绑失败";
}
@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 Map<String, Object> analyze(ContractDTO dto) {
return contractService.analyze(dto);
}
@PostMapping("/contract/dispatch")
@SaCheckPermission(value = "contract:dispatch", orRole = "admin")
public String dispatch(@RequestBody RContractTeamDTO dto) {
return contractService.dispatch(dto);
}
@GetMapping("/contract/sale")
@SaCheckPermission(value = "contract:sale:list", orRole = "admin")
public Page<RContractUser> getSaleList(RContractUser dto) {
return contractService.getSaleList(dto);
}
@PostMapping("/contract/assignSale")
@SaCheckPermission(value = "contract:assignSale", orRole = "admin")
public String assignSale(@RequestBody RContractUser dto) {
return contractService.assignSale(dto);
}
@PostMapping("/contract/unbindSale")
@SaCheckPermission(value = "contract:unbindSale", orRole = "admin")
public String unbindSale(@RequestBody RContractUser dto) {
return contractService.unbindSale(dto);
}
/*@PostMapping("/contractSync")
@SaCheckPermission(value = "contract:sync", orRole = "admin")
public String manualSyncContract() {
contractRunner.contractSync();
return "成功";
}*/
@PostMapping("/contractSync1")
@SaCheckPermission(value = "contract:sync1", orRole = "admin")
public String manualSyncContract1() {
contractRunner.contractSync1();
return "成功";
}
@PostMapping("/contract/createCRMContract")
@SaCheckPermission(value = "contract:createCRM", orRole = "admin")
public String createCRMContract(@RequestBody String contractJson) {
return contractService.createContract(CharSequenceUtil.removeAll(contractJson, '\r', '\n', ' '));
}
@GetMapping("/contract/getCRMProduct")
@SaCheckPermission(value = "contract:CRMProduct", orRole = "admin")
public JSONObject getCRMProduct(@RequestParam String name,
@RequestParam String code,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "20") Integer pageSize) {
return contractService.getCRMProduct(name, code, page, pageSize);
}
@GetMapping("/contract/product")
@SaCheckPermission(value = "contract:product", orRole = "admin")
public List<RContractProduct> getProduct(@RequestParam String contractNo) {
return contractService.getProduct(contractNo);
}
@GetMapping("/contract/export")
@SaCheckPermission(value = "contract:export", orRole = "admin")
public void pointExport(ContractDTO dto, HttpServletResponse response) {
UserVO user = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
dto.setPageSize(30000);
Page<ContractVO> voPage = contractService.list(dto);
try (DefaultExcelBuilder<ContractVO> defaultExcelBuilder = DefaultExcelBuilder.of(ContractVO.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("合同列表_{}", DateUtil.formatDateTime(new Date())), response);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@GetMapping("/contract/fileSync")
@SaCheckPermission(value = "contract:fileSync", orRole = "admin")
public String fileSync(String[] contractNoList) {
return contractService.syncContractFile(contractNoList);
}
}