Commit a42c0502 authored by lcl's avatar lcl

客户批量导入

parent 0828d84e
package com.dsk.web.controller.customer; package com.dsk.web.controller.customer;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.http.HttpException;
import com.dsk.common.annotation.Log; import com.dsk.common.annotation.Log;
import com.dsk.common.annotation.RepeatSubmit; import com.dsk.common.annotation.RepeatSubmit;
import com.dsk.common.core.controller.BaseController; import com.dsk.common.core.controller.BaseController;
...@@ -12,13 +15,18 @@ import com.dsk.system.domain.customer.Customer; ...@@ -12,13 +15,18 @@ import com.dsk.system.domain.customer.Customer;
import com.dsk.system.domain.customer.dto.CustomerBusinessSearchDto; import com.dsk.system.domain.customer.dto.CustomerBusinessSearchDto;
import com.dsk.system.domain.customer.dto.CustomerSearchDto; import com.dsk.system.domain.customer.dto.CustomerSearchDto;
import com.dsk.system.service.ICustomerService; import com.dsk.system.service.ICustomerService;
import com.dsk.web.controller.search.service.BusinessOpportunityRadarService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 客户相关 * 客户相关
...@@ -32,6 +40,8 @@ public class CustomerController extends BaseController { ...@@ -32,6 +40,8 @@ public class CustomerController extends BaseController {
@Autowired @Autowired
private ICustomerService baseService; private ICustomerService baseService;
@Autowired
private BusinessOpportunityRadarService opportunityRadarService;
/** /**
* 查询客户列表 * 查询客户列表
...@@ -94,6 +104,30 @@ public class CustomerController extends BaseController { ...@@ -94,6 +104,30 @@ public class CustomerController extends BaseController {
//@PreAuthorize("@ss.hasPermi('customer:importData')") //@PreAuthorize("@ss.hasPermi('customer:importData')")
@PostMapping("/importData") @PostMapping("/importData")
public AjaxResult importData(@RequestPart("file") MultipartFile file) throws Exception { public AjaxResult importData(@RequestPart("file") MultipartFile file) throws Exception {
return AjaxResult.success(baseService.importData(new ExcelUtil<>(Customer.class).importExcel(file.getInputStream(), 3))); List<Customer> customerList = new ExcelUtil<>(Customer.class).importExcel(file.getInputStream(), 2);
List<String> resultList = new ArrayList<>();
for (Customer customer : customerList) {
if (ObjectUtils.isEmpty(customer.getCompanyName())) {
continue;
}
try {
Map<String, Object> map = opportunityRadarService.enterpriseByName(customer.getCompanyName());
if(ObjectUtils.isEmpty(map)){
throw new HttpException("远程调用匹配接口失败!");
}
Map<String, Object> obj = BeanUtil.beanToMap(map.get("data"));
if(!ObjectUtils.isEmpty(obj)){
customer.setCompanyId(MapUtil.getInt(obj,"jskEid"));
customer.setLegalPerson(MapUtil.getStr(obj,"legalPerson"));
customer.setRegisterCapital(MapUtil.getStr(obj,"registeredCapital"));
customer.setRegisterAddress(MapUtil.getStr(obj,"domicile"));
customer.setCreditCode(MapUtil.getStr(obj,"creditCode"));
}
baseService.add(customer);
} catch (Exception e) {
resultList.add(customer.getCompanyName().concat(":").concat(e.getMessage()));
}
}
return AjaxResult.success(resultList);
} }
} }
...@@ -38,7 +38,7 @@ public class CustomerUser implements Serializable { ...@@ -38,7 +38,7 @@ public class CustomerUser implements Serializable {
* 创建时间 * 创建时间
*/ */
@TableField(fill = FieldFill.INSERT) @TableField(fill = FieldFill.INSERT)
private Date careteTime; private Date createTime;
/** /**
* 修改时间 * 修改时间
*/ */
......
...@@ -29,6 +29,4 @@ public interface ICustomerService { ...@@ -29,6 +29,4 @@ public interface ICustomerService {
List<CustomerBusinessListVo> selectBusinessList(CustomerBusinessSearchDto dto); List<CustomerBusinessListVo> selectBusinessList(CustomerBusinessSearchDto dto);
List<String> importData(List<Customer> customerList);
} }
...@@ -2,6 +2,7 @@ package com.dsk.system.service.impl; ...@@ -2,6 +2,7 @@ package com.dsk.system.service.impl;
import cn.hutool.core.bean.BeanException; import cn.hutool.core.bean.BeanException;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dsk.common.core.domain.AjaxResult; import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.exception.ServiceException; import com.dsk.common.exception.ServiceException;
...@@ -19,6 +20,7 @@ import com.dsk.system.mapper.CustomerUserMapper; ...@@ -19,6 +20,7 @@ import com.dsk.system.mapper.CustomerUserMapper;
import com.dsk.system.service.IBusinessInfoService; import com.dsk.system.service.IBusinessInfoService;
import com.dsk.system.service.ICustomerService; import com.dsk.system.service.ICustomerService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -46,8 +48,6 @@ public class CustomerServiceImpl implements ICustomerService { ...@@ -46,8 +48,6 @@ public class CustomerServiceImpl implements ICustomerService {
private CustomerUserMapper customerUserMapper; private CustomerUserMapper customerUserMapper;
@Autowired @Autowired
private IBusinessInfoService businessInfoService; private IBusinessInfoService businessInfoService;
@Autowired
private DskOpenApiUtil dskOpenApiUtil;
@Override @Override
public List<CustomerListVo> selectList(CustomerSearchDto dto) { public List<CustomerListVo> selectList(CustomerSearchDto dto) {
...@@ -117,34 +117,4 @@ public class CustomerServiceImpl implements ICustomerService { ...@@ -117,34 +117,4 @@ public class CustomerServiceImpl implements ICustomerService {
dto.setUserId(SecurityUtils.getUserId()); dto.setUserId(SecurityUtils.getUserId());
return businessInfoService.selectCustomerBusinessList(dto); return businessInfoService.selectCustomerBusinessList(dto);
} }
@Override
public List<String> importData(List<Customer> customerList) {
List<String> resultList = new ArrayList<>();
for (Customer customer : customerList) {
if (ObjectUtils.isEmpty(customer.getCompanyName())) {
continue;
}
try {
//TODO 名称查询企业信息
this.add(customer);
} catch (Exception e) {
resultList.add(customer.getCompanyName().concat(e.getMessage()));
}
}
return resultList;
}
private Map<String, Object> enterpriseByName(String keyword) {
try {
Map<String, Object> params = new HashMap<>();
params.put("keyword", keyword);
Map<String, Object> map = dskOpenApiUtil.requestBody("/nationzj/enterprice/findByName", params);
return (Map<String, Object>) map.get("data");
} catch (Exception e) {
log.error("企业名称匹配企业信息失败:" + keyword);
return null;
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment