Explorar o código

客户excel导出

yzc hai 1 ano
pai
achega
529fcd08cd

+ 5 - 0
hx-customer/pom.xml

@@ -22,6 +22,11 @@
             <groupId>com.fjhx</groupId>
             <artifactId>hx-common</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>easyexcel</artifactId>
+        </dependency>
     </dependencies>
 
 

+ 9 - 2
hx-customer/src/main/java/com/fjhx/customer/controller/customer/CustomerController.java

@@ -1,8 +1,6 @@
 package com.fjhx.customer.controller.customer;
 
-import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.fjhx.common.constant.SourceConstant;
 import com.fjhx.customer.entity.customer.dto.CustomerDto;
 import com.fjhx.customer.entity.customer.dto.CustomerSelectDto;
 import com.fjhx.customer.entity.customer.vo.CustomerVo;
@@ -15,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.Map;
 
 /**
@@ -131,4 +130,12 @@ public class CustomerController {
         return customerService.tagStatistics(customerDto);
     }
 
+    /**
+     * 导出excel
+     */
+    @PostMapping("/exportExcel")
+    public void exportExcel(@RequestBody CustomerSelectDto dto, HttpServletResponse httpServletResponse) {
+        customerService.exportExcel(dto, httpServletResponse);
+    }
+
 }

+ 123 - 0
hx-customer/src/main/java/com/fjhx/customer/entity/customer/CustomerExcelBo.java

@@ -0,0 +1,123 @@
+package com.fjhx.customer.entity.customer;
+
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+@Getter
+@Setter
+@ExcelIgnoreUnannotated
+public class CustomerExcelBo {
+    private final int columnWidth = 16;
+    private final int columnWidth1 = 20;
+
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("客户名称")
+    private String name;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("客户编号")
+    private String customerCode;
+    @ExcelProperty("国家")
+    private String countryName;
+    @ExcelProperty("省")
+    private String provinceName;
+    @ExcelProperty("市")
+    private String cityName;
+
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("详细地址")
+    private String address;
+    @ExcelProperty("业务员")
+    private String userName;
+
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("业务部门")
+    private String deptName;
+
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("主营品类")
+    private String mainCategories;
+
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("公司规模")
+    private String companySize;
+
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("结算方式")
+    private String settlementMode;
+
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("客户类型")
+    private String status;
+
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("客户等级")
+    private String lvName;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("维系级别")
+    private String maintainLevel;
+
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("新老客户")
+    private String newOld;
+
+    @ColumnWidth(columnWidth1)
+    @ExcelProperty("要求年订单量")
+    private String annualQuantity;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("回访要求")
+    private String followUpAsk;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("提醒设置")
+    private String remind;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("建群时间")
+    private Date createGroupTime;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("客户状态")
+    private String state;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("客户来源")
+    private String source;
+    @ExcelProperty("传真")
+    private String fax;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("客户标签")
+    private String tag;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("发票信息")
+    private String invoiceType;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("合作状态")
+    private String cooperateStatus;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("公司名称")
+    private String accountName;
+    @ExcelProperty("税号")
+    private String dutyParagraph;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("账户地址")
+    private String accountAddress;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("账户电话")
+    private String accountTel;
+    @ColumnWidth(columnWidth1)
+    @ExcelProperty("账户开户行")
+    private String accountBank;
+    @ColumnWidth(columnWidth)
+    @ExcelProperty("账户账号")
+    private String accountNumber;
+    @ColumnWidth(columnWidth1)
+    @ExcelProperty("对私账户名称")
+    private String privAccountName;
+    @ColumnWidth(columnWidth1)
+    @ExcelProperty("对私开户行")
+    private String privAccountBank;
+    @ColumnWidth(columnWidth1)
+    @ExcelProperty("对私账户账号")
+    private String privAccountNumber;
+}

+ 3 - 0
hx-customer/src/main/java/com/fjhx/customer/entity/customer/vo/CustomerVo.java

@@ -89,4 +89,7 @@ public class CustomerVo extends Customer implements SetCustomizeAreaName {
      * 客户等级名称
      */
     private String lvName;
+
+    private String userName;
+
 }

+ 1 - 1
hx-customer/src/main/java/com/fjhx/customer/mapper/customer/CustomerMapper.java

@@ -25,7 +25,7 @@ public interface CustomerMapper extends BaseMapper<Customer> {
     /**
      * 客户表列表
      */
-    List<CustomerVo> getList(@Param("ew") IWrapper<Customer> wrapper);
+    List<CustomerVo> getList(@Param("ew") IWrapper<CustomerVo> wrapper);
 
     /**
      * 客户表分页

+ 4 - 1
hx-customer/src/main/java/com/fjhx/customer/service/customer/CustomerService.java

@@ -9,6 +9,7 @@ import com.fjhx.customer.entity.customer.vo.CustomerVo;
 import com.ruoyi.common.core.service.BaseService;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 import java.util.Map;
 
@@ -23,7 +24,7 @@ import java.util.Map;
 public interface CustomerService extends BaseService<Customer> {
 
 
-    List<CustomerVo> getList(IWrapper<Customer> wrapper);
+    List<CustomerVo> getList(IWrapper<CustomerVo> wrapper);
 
     Page<CustomerVo> selPage(CustomerSelectDto dto);
 
@@ -98,4 +99,6 @@ public interface CustomerService extends BaseService<Customer> {
      * 根据客户id获取客户信息
      */
     List<CustomerVo> getCustomerInfoByIds(List<Long> customerIds);
+
+    void exportExcel(CustomerSelectDto dto, HttpServletResponse httpServletResponse);
 }

+ 1 - 1
hx-customer/src/main/java/com/fjhx/customer/service/customer/impl/CustomerLvServiceImpl.java

@@ -79,7 +79,7 @@ public class CustomerLvServiceImpl extends ServiceImpl<CustomerLvMapper, Custome
     @Scheduled(cron = "0 0 0 * * ?")
     void customerAutoTransfer() {
         TenantHolder.setIgnore(true);
-        List<CustomerVo> list = customerService.getList(IWrapper.<Customer>getWrapper()
+        List<CustomerVo> list = customerService.getList(IWrapper.<CustomerVo>getWrapper()
                 .apply("DATEDIFF(now(),IFNULL(c.last_follow_time, NOW())) >cul.max_not_follow")
                 .isNotNull("cul.max_not_follow")
                 .isNotNull("c.user_id")

+ 58 - 11
hx-customer/src/main/java/com/fjhx/customer/service/customer/impl/CustomerServiceImpl.java

@@ -13,6 +13,8 @@ import com.fjhx.area.utils.CustomizeAreaUtil;
 import com.fjhx.common.constant.SourceConstant;
 import com.fjhx.common.entity.coding.bo.CustomerCodeAndCountryId;
 import com.fjhx.common.service.coding.CodingRuleCustomerService;
+import com.fjhx.common.utils.excel.util.ExcelUtil;
+import com.fjhx.customer.entity.customer.CustomerExcelBo;
 import com.fjhx.customer.entity.customer.dto.CustomerDto;
 import com.fjhx.customer.entity.customer.dto.CustomerSelectDto;
 import com.fjhx.customer.entity.customer.po.Customer;
@@ -29,6 +31,8 @@ import com.fjhx.file.utils.ObsFileUtil;
 import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
 import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
 import com.fjhx.tenant.service.dict.DictTenantDataService;
+import com.fjhx.tenant.utils.DeptUstil;
+import com.fjhx.tenant.utils.DictUtils;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.exception.ServiceException;
@@ -41,6 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -68,7 +73,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
 
 
     @Override
-    public List<CustomerVo> getList(IWrapper<Customer> wrapper) {
+    public List<CustomerVo> getList(IWrapper<CustomerVo> wrapper) {
         return baseMapper.getList(wrapper);
     }
 
@@ -106,16 +111,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         return page;
     }
 
-    /**
-     * 查询客户的列表
-     *
-     * @param dto
-     * @return
-     */
-    @Override
-    public Page<CustomerVo> getPage(CustomerSelectDto dto) {
-
-        IWrapper<CustomerVo> wrapper = IWrapper.getWrapper();
+    private void setPageWrapper(IWrapper<CustomerVo> wrapper, CustomerSelectDto dto) {
 
         // 客户来源查询
         wrapper.eq("c", Customer::getSource, dto.getSource());
@@ -206,6 +202,20 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
 
         wrapper.orderByDesc("c", Customer::getAllocationTime);
         wrapper.orderByDesc("c", Customer::getCreateTime);
+    }
+
+    /**
+     * 查询客户的列表
+     *
+     * @param dto
+     * @return
+     */
+    @Override
+    public Page<CustomerVo> getPage(CustomerSelectDto dto) {
+
+        IWrapper<CustomerVo> wrapper = IWrapper.getWrapper();
+
+        setPageWrapper(wrapper, dto);
 
         Page<CustomerVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
 
@@ -233,6 +243,8 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
         }
 
         // 赋值是否置顶
+        List<Long> customerIds = customerTopService.listObject(CustomerTop::getCustomerId,
+                q -> q.eq(CustomerTop::getUserId, SecurityUtils.getUserId()));
         for (CustomerVo record : records) {
             record.setIsTop(customerIds.contains(record.getId()) ? 1 : 0);
         }
@@ -583,4 +595,39 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
 
         return customerVos;
     }
+
+    @Override
+    public void exportExcel(CustomerSelectDto dto, HttpServletResponse httpServletResponse) {
+        IWrapper<CustomerVo> wrapper = IWrapper.getWrapper();
+        setPageWrapper(wrapper, dto);
+        List<CustomerVo> list = getList(wrapper);
+        CustomizeAreaUtil.setAreaName(list);
+        UserUtil.assignmentNickName(list, CustomerVo::getUserId, CustomerVo::setUserName);
+
+        DeptUstil.assignmentNickName(list, Customer::getDeptId, CustomerVo::setDeptName);
+
+        Map<String, Map<String, String>> allDictMap = DictUtils.getAllDictKVMap();
+        for (CustomerVo customerVo : list) {
+            customerVo.setCompanySize(allDictMap.get("customer_scale").get(customerVo.getCompanySize()));
+            customerVo.setSettlementMode(allDictMap.get("settlement_way").get(customerVo.getSettlementMode()));
+            customerVo.setStatus(allDictMap.get("customer_status").get(customerVo.getStatus()));
+            customerVo.setLevel(allDictMap.get("customer_slevel").get(customerVo.getLevel()));
+            customerVo.setNewOld(allDictMap.get("newold_customer").get(customerVo.getNewOld()));
+            customerVo.setState(allDictMap.get("customer_state").get(customerVo.getState()));
+            customerVo.setSource(allDictMap.get("customer_source").get(customerVo.getSource()));
+            String tags = customerVo.getTag();
+            if (ObjectUtil.isNotEmpty(tags)) {
+                StringJoiner stringJoiner = new StringJoiner(",");
+                for (String tag : tags.split(",")) {
+                    stringJoiner.add(allDictMap.get("customer_tag").get(tag));
+                }
+                customerVo.setTag(stringJoiner.toString());
+            }
+            customerVo.setInvoiceType(allDictMap.get("invoice_type").get(customerVo.getInvoiceType()));
+            customerVo.setCooperateStatus(allDictMap.get("cooperation_status").get(customerVo.getCooperateStatus()));
+        }
+
+        List<CustomerExcelBo> customerExcelBos = BeanUtil.copyToList(list, CustomerExcelBo.class);
+        ExcelUtil.export(httpServletResponse, customerExcelBos, CustomerExcelBo.class);
+    }
 }

+ 3 - 0
hx-customer/src/main/resources/mapper/customer/CustomerMapper.xml

@@ -53,6 +53,9 @@
                c.priv_account_number,
                c.last_follow_time,
                c.duty_paragraph,
+               c.fax,
+               c.level,
+               c.customer_lv_id,
                IFNULL(t1.followCount, 0)    AS followCount,
                t1.lastSaleDate,
                IFNULL(t1.lastSaleDay, 0)    as lastSaleDay,