shiyunteng
2026-09-18 c5c284896ce6428cffc5092e9cdef4fefc23409f
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
package com.by4cloud.platformx.business.controller;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.by4cloud.platformx.business.entity.Product;
import com.by4cloud.platformx.business.vo.BusinessCustomerSelectVo;
import com.by4cloud.platformx.common.core.util.R;
import com.by4cloud.platformx.common.log.annotation.SysLog;
import com.by4cloud.platformx.business.entity.BusinessCustomer;
import com.by4cloud.platformx.business.service.BusinessCustomerService;
import com.by4cloud.platformx.common.security.annotation.Inner;
import com.by4cloud.platformx.common.security.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import com.by4cloud.platformx.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
 
/**
 * 客商信息
 *
 * @author platformx
 * @date 2026-05-07 10:13:22
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/businessCustomer" )
@Tag(description = "businessCustomer" , name = "客商信息管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class BusinessCustomerController {
 
    private final  BusinessCustomerService businessCustomerService;
 
    @Value("${dept.smj}")
    private String smj;
 
    @Value("${dept.smjsc}")
    private String smjsc;
 
    @Value("${dept.smjzt}")
    private String smjzt;
 
    /**
     * 分页查询
     * @param page 分页对象
     * @param businessCustomer 客商信息
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('business_businessCustomer_view')" )
    public R getBusinessCustomerPage(@ParameterObject Page page, @ParameterObject BusinessCustomer businessCustomer) {
 
        if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smj) || StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjsc) ||
                StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)) {
            LambdaQueryWrapper<BusinessCustomer> wrapper = Wrappers.lambdaQuery();
            wrapper.eq(businessCustomer.getIndustryId()!=null,BusinessCustomer::getIndustryId,businessCustomer.getIndustryId());
            wrapper.eq(businessCustomer.getAreaId()!=null,BusinessCustomer::getAreaId,businessCustomer.getAreaId());
            wrapper.like(StrUtil.isNotEmpty(businessCustomer.getCompanyName()),BusinessCustomer::getCompanyName,businessCustomer.getCompanyName());
            List<String> smjList = new ArrayList<>();
            smjList.add(smj);
            smjList.add(smjsc);
            smjList.add(smjzt);
            wrapper.in(BusinessCustomer::getCompId, smjList);
            wrapper.orderByDesc(BusinessCustomer::getCreateTime);
            return R.ok(businessCustomerService.page(page, wrapper));
        }
        LambdaQueryWrapper<BusinessCustomer> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(businessCustomer.getIndustryId()!=null,BusinessCustomer::getIndustryId,businessCustomer.getIndustryId());
        wrapper.eq(businessCustomer.getAreaId()!=null,BusinessCustomer::getAreaId,businessCustomer.getAreaId());
        wrapper.like(StrUtil.isNotEmpty(businessCustomer.getCompanyName()),BusinessCustomer::getCompanyName,businessCustomer.getCompanyName());
        wrapper.orderByDesc(BusinessCustomer::getCreateTime);
        return R.ok(businessCustomerService.pageByScope(page, wrapper));
    }
 
    /**
     * 分页查询
     * @param businessCustomer 客商信息
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/list" )
    @PreAuthorize("@pms.hasPermission('business_businessCustomer_view')" )
    public R getBusinessCustomerList(@ParameterObject BusinessCustomer businessCustomer) {
 
        if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smj) || StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjsc) ||
                StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)) {
            LambdaQueryWrapper<BusinessCustomer> wrapper = Wrappers.lambdaQuery();
            wrapper.like(StrUtil.isNotEmpty(businessCustomer.getCompanyName()),BusinessCustomer::getCompanyName,businessCustomer.getCompanyName());
            List<String> smjList = new ArrayList<>();
            smjList.add(smj);
            smjList.add(smjsc);
            smjList.add(smjzt);
            wrapper.in(BusinessCustomer::getCompId, smjList);
            List<BusinessCustomer> businessCustomerList = businessCustomerService.list(wrapper);
            if (CollUtil.isNotEmpty(businessCustomerList)){
                List<BusinessCustomerSelectVo> voList = BeanUtil.copyToList(businessCustomerList, BusinessCustomerSelectVo.class);
                if (voList.size()>1000){
                    return R.ok(voList.subList(0,1000));
                }
                return R.ok(voList);
            }
        }
        LambdaQueryWrapper<BusinessCustomer> wrapper = Wrappers.lambdaQuery();
        wrapper.like(StrUtil.isNotEmpty(businessCustomer.getCompanyName()),BusinessCustomer::getCompanyName,businessCustomer.getCompanyName());
        List<BusinessCustomer> businessCustomerList = businessCustomerService.listByScope(wrapper);
        if (CollUtil.isNotEmpty(businessCustomerList)){
            List<BusinessCustomerSelectVo> voList = BeanUtil.copyToList(businessCustomerList, BusinessCustomerSelectVo.class);
            if (voList.size()>1000){
                return R.ok(voList.subList(0,1000));
            }
            return R.ok(voList);
        }
        return R.ok();
    }
 
    /**
     * 通过id查询客商信息
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('business_businessCustomer_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(businessCustomerService.getById(id));
    }
 
    /**
     * 新增客商信息
     * @param businessCustomer 客商信息
     * @return R
     */
    @Operation(summary = "新增客商信息" , description = "新增客商信息" )
    @SysLog("新增客商信息" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('business_businessCustomer_add')" )
    public R save(@RequestBody BusinessCustomer businessCustomer) {
        return R.ok(businessCustomerService.save(businessCustomer));
    }
 
    /**
     * 修改客商信息
     * @param businessCustomer 客商信息
     * @return R
     */
    @Operation(summary = "修改客商信息" , description = "修改客商信息" )
    @SysLog("修改客商信息" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('business_businessCustomer_edit')" )
    public R updateById(@RequestBody BusinessCustomer businessCustomer) {
        return R.ok(businessCustomerService.updateById(businessCustomer));
    }
 
    /**
     * 通过id删除客商信息
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除客商信息" , description = "通过id删除客商信息" )
    @SysLog("通过id删除客商信息" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('business_businessCustomer_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(businessCustomerService.removeBatchByIds(CollUtil.toList(ids)));
    }
 
 
    /**
     * 导出excel 表格
     * @param businessCustomer 查询条件
        * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('business_businessCustomer_export')" )
    public List<BusinessCustomer> export(BusinessCustomer businessCustomer,Long[] ids) {
        return businessCustomerService.list(Wrappers.lambdaQuery(businessCustomer).in(ArrayUtil.isNotEmpty(ids), BusinessCustomer::getId, ids));
    }
 
    /**
     * 同步主数据 企业名称 法人 三合一码 银行信息
     * @return R
     */
    @Inner(value = false)
    @GetMapping("/syncMainBusCus/{compId}" )
    public R syncMainBusCus(@PathVariable("compId")String compId) {
        return R.ok(businessCustomerService.syncMainBusCus(compId));
    }
 
    /**
     * 同步主数据 企业名称 法人 三合一码 银行信息
     * @return R
     */
    @GetMapping("/queryMainBC/{companyName}" )
    public R queryMainBC(@PathVariable("companyName")String companyName) {
        return R.ok(businessCustomerService.queryMainBC(companyName));
    }
}