liujie
2 天以前 58723309804cd6afa11e086ccac5346bcad61c0d
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
package com.ruoyi.web.controller.system;
 
 
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.BasePage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.utils.QiChaChaUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.AddScheduleDto;
import com.ruoyi.system.dto.CompanyUpdateStatusDto;
import com.ruoyi.system.dto.EditCompanyDto;
import com.ruoyi.system.dto.PushCompanyDto;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.MyPushCompanyListQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.CompanyDetailVo;
import com.ruoyi.system.vo.MyPushCompanyListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
 
@Slf4j
@RestController
@RequestMapping("/company")
@Api(tags = "发布模块")
public class CompanyController {
 
    @Autowired
    private TbCompanyService tbCompanyService;
 
    @Autowired
    private TbIndustryService industryService;
 
    @Autowired
    private TbOrderService orderService;
 
    @Autowired
    private TokenService tokenService;
 
    @Autowired
    private TbScheduleService scheduleService;
 
    @Autowired
    private TbMessageService messageService;
 
    @Autowired
    private TbLicenceService licenceService;
 
    @Autowired
    private TbCompanyTypeService companyTypeService;
 
    @Autowired
    private TbQichachaService tbQichachaService;
 
    @Autowired
    private RedisCache redisCache;
 
 
 
 
    @ApiOperation(value = "获取我发布的公司",tags = {"发布模块"})
    @GetMapping("/getMyPushCompanyList")
    public R< HashMap<String, Object>> getMyPushCompanyList(MyPushCompanyListQuery query) {
        LoginUser loginUser = tokenService.getLoginUser();
        if(loginUser==null){
            return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录");
        }
        Long userId = loginUser.getUserId();
        Page<MyPushCompanyListVo> page = tbCompanyService.getMyPushCompanyList(query,userId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",page);
        map = tbCompanyService.getMyPushCompanyListNum(userId,map);
        return R.ok(map);
    }
 
 
    @ApiOperation(value = "获取上次发布的信息",tags = {"发布模块"})
    @GetMapping("/getMyPushCompanyLast")
    public R<HashMap<String, Object>> getMyPushCompanyLast() {
        LoginUser loginUser = tokenService.getLoginUser();
        if(loginUser==null){
            return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录");
        }
        Long userId = loginUser.getUserId();
        TbCompany company = tbCompanyService.getOne(new LambdaQueryWrapper<TbCompany>().eq(TbCompany::getUserId,userId).orderByDesc(TbCompany::getCreateTime).last("limit 1"));
        HashMap<String, Object> map = new HashMap<>();
        if(company!=null){
            map.put("recipient",company.getRecipient());
            map.put("recipientAddress",company.getRecipientAddress());
        }else {
            map.put("recipient","");
            map.put("recipientAddress","");
        }
        return R.ok(map);
    }
 
 
 
    @ApiOperation(value = "获取行业信息",tags = {"发布模块"})
    @GetMapping("/getIndustryList")
    public R<List<TbIndustry>> getIndustryList() {
        List<TbIndustry> page1 = industryService.list(new LambdaQueryWrapper<TbIndustry>().eq(TbIndustry::getDelFlag,0).orderByDesc(TbIndustry::getOrderNum));
        return R.ok(page1);
    }
 
    @ApiOperation(value = "获取公司类型信息",tags = {"发布模块"})
    @GetMapping("/getCompanyTypeList")
    public R<List<TbCompanyType>> getCompanyTypeList() {
        List<TbCompanyType> page1 = companyTypeService.list(new LambdaQueryWrapper<TbCompanyType>().eq(TbCompanyType::getDelFlag,0).orderByDesc(TbCompanyType::getOrderNum));
        return R.ok(page1);
    }
 
    @ApiOperation(value = "获取许可证信息",tags = {"发布模块"})
    @GetMapping("/getLicenceList")
    public R<List<TbLicence>> getLicenceList() {
        List<TbLicence> page1 = licenceService.list(new LambdaQueryWrapper<TbLicence>().eq(TbLicence::getDelFlag,0).orderByDesc(TbLicence::getOrderNum));
        return R.ok(page1);
    }
    private static boolean checkName(String name,String sign) {
        Object report = getReport(sign);
        JSONObject jsonObject = JSONObject.parseObject(report.toString());
        Object data = jsonObject.get("data");
        JSONObject jsonObject1 = JSONObject.parseObject(data.toString());
        String company = jsonObject1.get("company").toString();
        if(name.equals(company)){
            return false;
        }
        return true;
    }
 
    public static void main(String[] args) {
        Object report = getReport("ZZE2025070102412440776825");
        System.out.println(report);
    }
    @ApiOperation(value = "立即发布",tags = {"发布模块"})
    @PostMapping("/pushCompany")
    public synchronized R<?> pushCompany(@Valid @RequestBody PushCompanyDto dto) {
        LoginUser loginUser = tokenService.getLoginUser();
        if(loginUser==null){
            return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录");
        }
        Long userId = loginUser.getUserId();
        long count = tbCompanyService.count(new LambdaQueryWrapper<TbCompany>().eq(TbCompany::getIsDelete,0).eq(TbCompany::getCompanyName, dto.getCompanyName()).ne(TbCompany::getStatus, 3));
        if (count > 0) {
            return R.fail("该公司已发布");
        }
        // 判断水母报告和 公司名称是否一致
        String link = dto.getLink();
        String sign = extractSnFromUrl(link);
        boolean b = checkName(dto.getCompanyName(), sign);
        if(b){
            return R.fail("水母报告和公司名称不一致");
        }
 
        String companyId = tbCompanyService.pushCompany(dto, userId);
        return R.ok(companyId);
    }
 
    @ApiOperation(value = "发布前获取公司信息--企查查",tags = {"发布模块"})
    @GetMapping("/getCompanyFromQiChaCha")
    public R<Object> getCompanyFromQiChaCha(@RequestParam String companyName) {
        long count = tbCompanyService.count(new LambdaQueryWrapper<TbCompany>().eq(TbCompany::getCompanyName,companyName).eq(TbCompany::getIsDelete,0).ne(TbCompany::getStatus, 3));
        if (count > 0) {
            return R.fail("该公司已发布");
        }
        Object cacheObject = redisCache.getCacheObject("push_" + companyName);
        if(cacheObject!=null){
            return R.ok(cacheObject);
        }
        Object qiChaChaToken = QiChaChaUtil.getQiChaChaCompanyInfo(companyName);
        TbQichacha tbQichacha = new TbQichacha();
        tbQichacha.setType(1);
        tbQichachaService.save(tbQichacha);
        if(qiChaChaToken==null){
            return R.fail("查询公司信息失败请联系客服");
        }
        redisCache.setCacheObject("push_" + companyName, qiChaChaToken, 24, TimeUnit.HOURS);
        return R.ok(qiChaChaToken);
    }
 
 
 
    @ApiOperation(value = "编辑公司",tags = {"发布模块"})
    @PostMapping("/editCompany")
    public R<?> editCompany(@Valid @RequestBody EditCompanyDto dto) {
        LoginUser loginUser = tokenService.getLoginUser();
        if(loginUser==null){
            return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录");
        }
        Long userId = loginUser.getUserId();
 
        TbCompany company = tbCompanyService.getById(dto.getId());
        if (company == null || !company.getUserId().equals(userId.toString())) {
            return R.fail("非法操作");
        }
 
        long count1 = tbCompanyService.count(new LambdaQueryWrapper<TbCompany>().eq(TbCompany::getCompanyName, dto.getCompanyName()).eq(TbCompany::getIsDelete,0).ne(TbCompany::getId,dto.getId()).ne(TbCompany::getStatus, 3));
        if (count1 > 0) {
            return R.fail("该公司已发布");
        }
 
        long count = orderService.count(new LambdaQueryWrapper<TbOrder>().eq(TbOrder::getCompanyId, dto.getId()).in(TbOrder::getStatus, 3, 4, 5));
        if (count > 0) {
            return R.fail("订单状态不能修改");
        }
        // 判断水母报告和 公司名称是否一致
        String link = dto.getLink();
        String sign = extractSnFromUrl(link);
        boolean b = checkName(dto.getCompanyName(), sign);
        if(b){
            return R.fail("水母报告和公司名称不一致");
        }
        tbCompanyService.editCompany(dto,company,userId);
        return R.ok(dto.getId());
    }
 
 
    @ApiOperation(value = "上下架",tags = {"发布模块"})
    @PostMapping("/companyUpdateStatus")
    public R<?> companyUpdateStatus(@Valid @RequestBody CompanyUpdateStatusDto dto) {
        LoginUser loginUser = tokenService.getLoginUser();
        if(loginUser==null){
            return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录");
        }
        Long userId = loginUser.getUserId();
        TbCompany company = tbCompanyService.getById(dto.getId());
        if (company == null || !company.getUserId().equals(userId.toString())) {
            return R.fail("非法操作");
        }
        long count = orderService.count(new LambdaQueryWrapper<TbOrder>().eq(TbOrder::getCompanyId, dto.getId()).in(TbOrder::getStatus, 3, 4, 5));
        if (count > 0) {
            return R.fail("订单状态不能修改");
        }
        if(dto.getStatus()<1 || dto.getStatus()>2){
            return R.fail("状态错误");
        }
        if(dto.getStatus()==2){
            orderService.update(new LambdaUpdateWrapper<TbOrder>().eq(TbOrder::getCompanyId,dto.getId()).set(TbOrder::getStatus,-1));
        }
        company.setStatus(dto.getStatus());
        tbCompanyService.updateById(company);
        return R.ok();
    }
 
 
    @ApiOperation(value = "删除公司",tags = {"发布模块"})
    @DeleteMapping("/delete/{id}")
    public R<?> delete(@PathVariable("id")String id) {
        LoginUser loginUser = tokenService.getLoginUser();
        if(loginUser==null){
            return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录");
        }
        Long userId = loginUser.getUserId();
        TbCompany company = tbCompanyService.getById(id);
        if (company == null || !company.getUserId().equals(userId.toString())) {
            return R.fail("非法操作");
        }
        long count = orderService.count(new LambdaQueryWrapper<TbOrder>().eq(TbOrder::getCompanyId,id).in(TbOrder::getStatus, 3, 4, 5));
        if (company.getStatus()!=1) {
            return R.fail("订单状态不能修改");
        }
        company.setIsDelete(1);
        tbCompanyService.updateById(company);
        return R.ok();
    }
 
 
 
    @ApiOperation(value = "确认订单",tags = {"发布模块"})
    @PostMapping("/confirmOrder")
    public R<?> confirmOrder(String orderId) {
        if(StringUtils.isEmpty(orderId)){
            return R.fail("参数错误");
        }
        LoginUser loginUser = tokenService.getLoginUser();
        if(loginUser==null){
            return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录");
        }
        Long userId = loginUser.getUserId();
        TbOrder order = orderService.getById(orderId);
        if(order==null){
            return R.fail("订单不存在");
        }
        TbCompany company = tbCompanyService.getById(order.getCompanyId());
        if (company == null || !company.getUserId().equals(userId.toString())) {
            return R.fail("非法操作");
        }
        if(order.getStatus()!=2){
            return R.fail("该订单状态不需要确认");
        }
        order.setStatus(3);
        order.setConfirmTime(new Date());
        order.updateById();
 
        return R.ok();
    }
 
 
    @ApiOperation(value = "取消确认订单",tags = {"发布模块"})
    @PostMapping("/cancelConfirmOrder")
    public R<?> cancelConfirmOrder(String orderId) {
        if(StringUtils.isEmpty(orderId)){
            return R.fail("参数错误");
        }
        LoginUser loginUser = tokenService.getLoginUser();
        if(loginUser==null){
            return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录");
        }
        Long userId = loginUser.getUserId();
        TbOrder order = orderService.getById(orderId);
        if(order==null){
            return R.fail("订单不存在");
        }
        TbCompany company = tbCompanyService.getById(order.getCompanyId());
        if (company == null || !company.getUserId().equals(userId.toString())) {
            return R.fail("非法操作");
        }
        // 待支付才能取消订单  已确认后
        if(order.getStatus()!=3){
            return R.fail("该订单状态不需要确认");
        }
        order.setStatus(-1);
        order.setCancelType(1);
        order.updateById();
 
        company.setStatus(1);
        company.updateById();
 
 
        messageService.addMessage("您有订单被取消", order.getUserId(),order.getId(),2);
        return R.ok();
    }
 
    @ApiOperation(value = "添加办理进度",tags = {"发布模块"})
    @PostMapping("/addSchedule")
    public R<?> addSchedule(@RequestBody @Valid AddScheduleDto dto) {
        LoginUser loginUser = tokenService.getLoginUser();
        if(loginUser==null){
            return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录");
        }
        Long userId = loginUser.getUserId();
        TbOrder order = orderService.getById(dto.getOrderId());
        if(order==null){
            return R.fail("订单不存在");
        }
        TbCompany company = tbCompanyService.getById(order.getCompanyId());
        if (company == null || !company.getUserId().equals(userId.toString())) {
            return R.fail("非法操作");
        }
        scheduleService.addSchedule(dto,userId);
 
        messageService.addMessage("您的订单有新的进度提醒", order.getUserId(),order.getId(),2);
        return R.ok();
    }
 
 
 
    private static Object getReport(String sign){
        HttpRequest post = HttpUtil.createPost("https://shuimui.szsmjr.com/index/index/result");
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("Origin","https://shuimui.szsmjr.com");
        post.addHeaders(stringStringHashMap);
        post.body("{\"sn\":\""+sign+"\"}");
        HttpResponse execute = post.execute();
        String body = execute.body();
        JSONObject jsonObject = JSONObject.parseObject(body);
        return jsonObject;
    }
 
 
    @ApiOperation(value = "已完成",tags = {"发布模块"})
    @PostMapping("/saleSuccessOrder")
    public R<?> saleSuccessOrder(String orderId) {
        if(StringUtils.isEmpty(orderId)){
            return R.fail("参数错误");
        }
        LoginUser loginUser = tokenService.getLoginUser();
        if(loginUser==null){
            return R.fail(HttpStatus.UNAUTHORIZED,"请重新登录");
        }
        Long userId = loginUser.getUserId();
        TbOrder order = orderService.getById(orderId);
        if(order==null){
            return R.fail("订单不存在");
        }
        TbCompany company = tbCompanyService.getById(order.getCompanyId());
        if (company == null || !company.getUserId().equals(userId.toString())) {
            return R.fail("非法操作");
        }
        if(order.getStatus()!=4){
            return R.fail("该订单状态不能完成");
        }
        order.setStatus(5);
        order.setSellerFinishTime(new Date());
        order.updateById();
 
        messageService.addMessage("您有订单卖家已完成,等待确认", order.getUserId(),orderId,2);
        return R.ok();
    }
 
 
    @ApiOperation(value = "公司详情",tags = {"发布模块"})
    @GetMapping("/companyDetail")
    public R<CompanyDetailVo> companyDetail(@RequestParam String companyId) throws Exception {
        if(StringUtils.isEmpty(companyId)){
            return R.fail("参数错误");
        }
        CompanyDetailVo companyDetailVo = tbCompanyService.companyDetail(companyId,null);
        Object qiChaChaCompanyExceptionCheck = QiChaChaUtil.getQiChaChaCompanyExceptionCheck(companyDetailVo.getCompanyName());
        if(qiChaChaCompanyExceptionCheck!=null && qiChaChaCompanyExceptionCheck.toString().contains("query_type")){
            TbQichacha tbQichacha = new TbQichacha();
            tbQichacha.setType(2);
            tbQichacha.insert();
        }
        companyDetailVo.setCompanyExceptionInfo(qiChaChaCompanyExceptionCheck);
        companyDetailVo.setEstablishTime(companyDetailVo.getEstablishTime().substring(0,10));
        return R.ok(companyDetailVo);
    }
 
 
    @ApiOperation(value = "公司详情--异常信息",tags = {"发布模块"})
    @GetMapping("/qiChaChaCompanyExceptionCheck")
    public R<Object> qiChaChaCompanyExceptionCheck(@RequestParam String companyName) {
        Object qiChaChaCompanyExceptionCheck = QiChaChaUtil.getQiChaChaCompanyExceptionCheck(companyName);
        if(qiChaChaCompanyExceptionCheck!=null && qiChaChaCompanyExceptionCheck.toString().contains("query_type")){
            TbQichacha tbQichacha = new TbQichacha();
            tbQichacha.setType(2);
            tbQichacha.insert();
        }
        return R.ok(qiChaChaCompanyExceptionCheck);
    }
 
    @ApiOperation(value = "公司详情--财务征信信息",tags = {"发布模块"})
    @GetMapping("/companyDetailDataInfo")
    public R<Object> companyDetailDataInfo(@RequestParam String companyId) {
        if(StringUtils.isEmpty(companyId)){
            return R.fail("参数错误");
        }
        TbCompany company = tbCompanyService.getById(companyId);
        String link = company.getLink();
        String[] split = link.split("=");
        String sign =split [split.length-1];
        Object report = getReport(sign);
        return R.ok(report);
    }
 
 
    /**
     * 从URL中提取sn参数
     * @param url 包含sn参数的URL
     * @return sn参数值
     */
    public static String extractSnFromUrl(String url) {
        if (url == null || url.isEmpty()) {
            return null;
        }
 
        // 查找sn参数的位置
        String snParam = "sn=";
        int startIndex = url.indexOf(snParam);
 
        if (startIndex == -1) {
            return null; // 未找到sn参数
        }
 
        // 计算sn值的起始位置
        startIndex += snParam.length();
 
        // 查找sn值的结束位置(遇到&或字符串结束)
        int endIndex = url.indexOf("&", startIndex);
        if (endIndex == -1) {
            endIndex = url.length();
        }
 
        // 提取并返回sn值
        return url.substring(startIndex, endIndex);
    }
 
 
 
 
 
 
}