luodangjia
2024-12-10 ee7ce5d1cbf80bee0a15c1e5bc5eaa30858d812b
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
package com.hollywood.applet.controller;
 
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hollywood.applet.dto.*;
import com.hollywood.applet.query.TCompanyQuery;
import com.hollywood.applet.service.TCompanyNeedService;
import com.hollywood.applet.service.TCompanyService;
import com.hollywood.applet.utils.DistanceCalculator;
import com.hollywood.applet.utils.DistanceCalculator1;
import com.hollywood.common.basic.ApiResult;
import com.hollywood.common.basic.PageInfo;
import com.hollywood.common.model.TCompany;
 
import com.hollywood.common.model.TCompanyNeed;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 * 企业管理 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2024-04-23
 */
@Api(tags = "企业管理")
@RestController
@RequestMapping("/t-company")
public class TCompanyController {
 
    private final TCompanyService companyService;
    @Autowired
    private TCompanyNeedService needService;
 
    @Autowired
    public TCompanyController(TCompanyService companyService) {
        this.companyService = companyService;
    }
 
    /**
     * 获取企业管理列表
     */
    @ApiOperation(value = "获取企业管理分页列表")
    @PostMapping(value = "/pageList")
    public ApiResult<PageInfo<CompanyDistanceDto>> pageList(@Validated @RequestBody TCompanyQuery query) {
        return ApiResult.success(companyService.pageList(query));
    }
 
    /**
     * 查看企业管理详情
     */
    @ApiOperation(value = "查看企业管理详情")
    @PostMapping(value = "/getDetailById")
    public ApiResult<CompanyDetailDto> getDetailById(@RequestBody CompanyDetailQuery companyDetailQuery) {
        TCompany byId = companyService.getById(companyDetailQuery.getId());
        CompanyDetailDto companyDetailDto = new CompanyDetailDto();
        BeanUtils.copyProperties(byId,companyDetailDto);
        try {
            companyDetailDto.setDistance(DistanceCalculator1.calculateDistanceBetweenCoordinates(companyDetailQuery.getLat(), companyDetailQuery.getLon(), byId.getLat(), byId.getLon()));
        }catch (Exception e){
            companyDetailDto.setDistance(0);
 
        }
        if (byId.getCityName()!=null){
            companyDetailDto.setCity(byId.getProvinceName()+" | "+byId.getCityName());
        }else {
            companyDetailDto.setCity(byId.getProvinceName());
        }
 
        List<TCompanyNeed> list = needService.list(Wrappers.lambdaQuery(TCompanyNeed.class).eq(TCompanyNeed::getCompanyId, companyDetailQuery.getId()).eq(TCompanyNeed::getStatus,1).orderByDesc(TCompanyNeed::getSortBy));
        List<NeedListDto> needListDtos =new ArrayList<>();
        for (TCompanyNeed tCompanyNeed : list) {
            NeedListDto needListDto =new NeedListDto();
            BeanUtils.copyProperties(tCompanyNeed,needListDto);
            needListDtos.add(needListDto);
        }
        companyDetailDto.setNeedListDtos(needListDtos);
 
        return ApiResult.success(companyDetailDto);
 
 
    }
 
    @ApiOperation(value = "查看供需详情")
    @PostMapping(value = "/getNeedById/{id}")
    public ApiResult<TCompanyNeed> getNeedById(@PathVariable Long id) {
        TCompanyNeed byId = needService.getById(id);
        TCompany byId1 = companyService.getById(byId.getCompanyId());
        byId.setCompanyName(byId1.getCompanyName());
        return ApiResult.success(byId);
    }
 
 
}