diff --git a/dq-financial-api/src/main/java/com/daqing/financial/crms/CustomerControllerApi.java b/dq-financial-api/src/main/java/com/daqing/financial/crms/CustomerControllerApi.java index 43b02b5a..20f60a65 100644 --- a/dq-financial-api/src/main/java/com/daqing/financial/crms/CustomerControllerApi.java +++ b/dq-financial-api/src/main/java/com/daqing/financial/crms/CustomerControllerApi.java @@ -7,7 +7,9 @@ import com.daqing.framework.domain.crms.request.CustomerRequest; import com.daqing.framework.model.response.ResponseResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; @@ -61,4 +63,22 @@ public interface CustomerControllerApi { */ @ApiOperation(value = "更新企业类型客户信息", notes = "更新企业类型客户信息") ResponseResult updateCompany(CustomerCompanyTO customerCompanyTO); + + /** + * 导入excel数据 + */ + @ApiOperation(value = "导入excel数据", notes = "导入excel数据") + void excelImportCustomer(MultipartFile file); + + /** + * 导出数据到excel + */ + @ApiOperation(value = "导出数据到excel", notes = "导出数据到excel") + void excelExportCustomer(HttpServletResponse response); + + /** + * 导出excel模板 + */ + @ApiOperation(value = "导出excel模板", notes = "导出excel模板") + void excelTemplate(HttpServletResponse response); } diff --git a/dq-financial-api/target/classes/com/daqing/financial/crms/CustomerControllerApi.class b/dq-financial-api/target/classes/com/daqing/financial/crms/CustomerControllerApi.class index d5176bda..319b736f 100644 Binary files a/dq-financial-api/target/classes/com/daqing/financial/crms/CustomerControllerApi.class and b/dq-financial-api/target/classes/com/daqing/financial/crms/CustomerControllerApi.class differ diff --git a/dq-financial-crms/src/main/java/com/daqing/financial/crms/controller/CustomerController.java b/dq-financial-crms/src/main/java/com/daqing/financial/crms/controller/CustomerController.java index 0cf65025..118b574e 100644 --- a/dq-financial-crms/src/main/java/com/daqing/financial/crms/controller/CustomerController.java +++ b/dq-financial-crms/src/main/java/com/daqing/financial/crms/controller/CustomerController.java @@ -9,7 +9,9 @@ import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.utils.PageUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -107,4 +109,34 @@ public class CustomerController implements CustomerControllerApi { boolean result = customerService.updateCustomerCompany(customerCompanyTO.getCustomerEntity(), customerCompanyTO.getCompanyCustomerEntity()); return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); } + + /** + * 导出数据到excel + */ + @Override + @GetMapping("/excelExport") + public void excelExportCustomer(HttpServletResponse response){ + + customerService.excelExportCustomer(response); + } + + /** + * 导出excel模板 + */ + @Override + @GetMapping("/excelTemplate") + public void excelTemplate(HttpServletResponse response){ + + customerService.excelTemplate(response); + } + + /** + * 导入excel数据 + */ + @PostMapping("/excelImport") + @Override + public void excelImportCustomer(MultipartFile file){ + + customerService.excelImportCustomer(file); + } } diff --git a/dq-financial-crms/src/main/java/com/daqing/financial/crms/dao/CustomerDao.java b/dq-financial-crms/src/main/java/com/daqing/financial/crms/dao/CustomerDao.java index 8974471a..cfc687d1 100644 --- a/dq-financial-crms/src/main/java/com/daqing/financial/crms/dao/CustomerDao.java +++ b/dq-financial-crms/src/main/java/com/daqing/financial/crms/dao/CustomerDao.java @@ -33,4 +33,5 @@ public interface CustomerDao extends BaseMapper { boolean updateCustomer(CustomerEntity customerEntity); + List listCustomerId(); } diff --git a/dq-financial-crms/src/main/java/com/daqing/financial/crms/feign/HrmsFeignService.java b/dq-financial-crms/src/main/java/com/daqing/financial/crms/feign/HrmsFeignService.java index 4dd7c1ea..034a388f 100644 --- a/dq-financial-crms/src/main/java/com/daqing/financial/crms/feign/HrmsFeignService.java +++ b/dq-financial-crms/src/main/java/com/daqing/financial/crms/feign/HrmsFeignService.java @@ -2,6 +2,7 @@ package com.daqing.financial.crms.feign; import com.daqing.framework.domain.hrms.EmployeeEntity; import com.daqing.framework.domain.hrms.ext.EmployeeTO; +import com.daqing.framework.domain.hrms.ext.EmployeeVO; import com.daqing.framework.model.response.ResponseResult; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.stereotype.Component; @@ -25,4 +26,6 @@ public interface HrmsFeignService { @GetMapping("/hrms/employee/getEmployeeById") ResponseResult getEmployeeById(@RequestParam("id") Long id); + @GetMapping("/hrms/employee/listEmployeeName") + ResponseResult> listEmployeeName(); } diff --git a/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/CustomerService.java b/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/CustomerService.java index bce1f93f..a5ac912d 100644 --- a/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/CustomerService.java +++ b/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/CustomerService.java @@ -7,7 +7,10 @@ import com.daqing.framework.domain.crms.request.CustomerRequest; import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.utils.PageUtils; import com.daqing.framework.domain.crms.CustomerEntity; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.util.List; import java.util.Map; @@ -33,5 +36,11 @@ public interface CustomerService extends IService { boolean updateCustomerPersonal(CustomerEntity customerEntity, PersonalCustomerEntity personalCustomerEntity); boolean updateCustomerCompany(CustomerEntity customerEntity, CompanyCustomerEntity companyCustomerEntity); + + void excelExportCustomer(HttpServletResponse response); + + void excelImportCustomer(MultipartFile excel); + + void excelTemplate(HttpServletResponse response); } diff --git a/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java b/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java index a263903e..559a7c53 100644 --- a/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java +++ b/dq-financial-crms/src/main/java/com/daqing/financial/crms/service/impl/CustomerServiceImpl.java @@ -18,14 +18,18 @@ import com.daqing.framework.domain.crms.ext.CustomerCompanyVO; import com.daqing.framework.domain.crms.ext.CustomerPersonalVO; import com.daqing.framework.domain.crms.request.CustomerRequest; import com.daqing.framework.domain.hrms.ext.EmployeeTO; +import com.daqing.framework.domain.hrms.ext.EmployeeVO; import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.utils.PageUtils; import com.daqing.framework.utils.SnowflakeIdUtils; +import com.daqing.framework.utils.excel.ExcelUtil; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; import java.text.SimpleDateFormat; import java.util.*; @@ -202,6 +206,67 @@ public class CustomerServiceImpl extends ServiceImpl companyList = new ArrayList<>(); + List personalList = new ArrayList<>(); + List longList = customerDao.listCustomerId(); + for (Long id : longList) { + ResponseResult responseResult = this.queryCustomerById(id); + if ((responseResult.getData()).getClass() == CustomerCompanyVO.class){ + companyList.add((CustomerCompanyVO) responseResult.getData()); + }else { + personalList.add((CustomerPersonalVO) responseResult.getData()); + } + } + ExcelUtil.writeExcelWithSheets(response,personalList,"客户资源信息一览表","个人类型",new CustomerPersonalVO()) + .write(companyList,"企业类型",new CustomerCompanyVO()) + .finish(); + } + + /** + * 导出excel模板 + */ + @Override + public void excelTemplate(HttpServletResponse response) { + List companyList = new ArrayList<>(); + List personalList = new ArrayList<>(); + ExcelUtil.writeExcelWithSheets(response,personalList,"客户资源信息表模板","个人类型",new CustomerPersonalVO()) + .write(companyList,"企业类型",new CustomerCompanyVO()) + .finish(); + } + + /** + * 导入excel数据 + * @param excel + */ + @Override + public void excelImportCustomer(MultipartFile excel) { + //TODO 导入excel数据到数据库,思路耗时太长,有待优化 + List personalList = ExcelUtil.readExcel(excel, new CustomerPersonalVO(), 1); + List companyList = ExcelUtil.readExcel(excel, new CustomerCompanyVO(), 2); + List nameList = hrmsFeignService.listEmployeeName().getData(); + List customerList = new ArrayList<>(); + CustomerEntity customer; + List pcList = new ArrayList<>(); + PersonalCustomerEntity pc; + for (Object personal : personalList) { + customer = new CustomerEntity(); + pc = new PersonalCustomerEntity(); + BeanUtils.copyProperties(personal,customer); + BeanUtils.copyProperties(personal,pc); + customerList.add(customer); + pcList.add(pc); + } + System.out.println(customerList); + System.out.println(pcList); + } + /** * 选择某段时间内客户信息的时间参数校验 * @@ -316,7 +381,7 @@ public class CustomerServiceImpl extends ServiceImpl + + + \ No newline at end of file diff --git a/dq-financial-crms/target/classes/com/daqing/financial/crms/controller/CustomerController.class b/dq-financial-crms/target/classes/com/daqing/financial/crms/controller/CustomerController.class index 41bfed1f..ba8a0af5 100644 Binary files a/dq-financial-crms/target/classes/com/daqing/financial/crms/controller/CustomerController.class and b/dq-financial-crms/target/classes/com/daqing/financial/crms/controller/CustomerController.class differ diff --git a/dq-financial-crms/target/classes/com/daqing/financial/crms/dao/CustomerDao.class b/dq-financial-crms/target/classes/com/daqing/financial/crms/dao/CustomerDao.class index 28a5437a..244e038c 100644 Binary files a/dq-financial-crms/target/classes/com/daqing/financial/crms/dao/CustomerDao.class and b/dq-financial-crms/target/classes/com/daqing/financial/crms/dao/CustomerDao.class differ diff --git a/dq-financial-crms/target/classes/com/daqing/financial/crms/service/CustomerService.class b/dq-financial-crms/target/classes/com/daqing/financial/crms/service/CustomerService.class index 85a53d93..f7c2de0c 100644 Binary files a/dq-financial-crms/target/classes/com/daqing/financial/crms/service/CustomerService.class and b/dq-financial-crms/target/classes/com/daqing/financial/crms/service/CustomerService.class differ diff --git a/dq-financial-crms/target/classes/com/daqing/financial/crms/service/impl/CustomerServiceImpl.class b/dq-financial-crms/target/classes/com/daqing/financial/crms/service/impl/CustomerServiceImpl.class index 41f26e0d..c3c41f41 100644 Binary files a/dq-financial-crms/target/classes/com/daqing/financial/crms/service/impl/CustomerServiceImpl.class and b/dq-financial-crms/target/classes/com/daqing/financial/crms/service/impl/CustomerServiceImpl.class differ diff --git a/dq-financial-crms/target/classes/mapper/crms/CustomerDao.xml b/dq-financial-crms/target/classes/mapper/crms/CustomerDao.xml index af1020c3..dc175407 100644 --- a/dq-financial-crms/target/classes/mapper/crms/CustomerDao.xml +++ b/dq-financial-crms/target/classes/mapper/crms/CustomerDao.xml @@ -83,4 +83,11 @@ WHERE id = #{id} + + + \ No newline at end of file diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/EmployeeController.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/EmployeeController.java index 08648e9a..e3e1e317 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/EmployeeController.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/EmployeeController.java @@ -4,6 +4,7 @@ import com.daqing.financial.hrms.EmployeeControllerApi; import com.daqing.financial.hrms.service.EmployeeService; import com.daqing.framework.domain.hrms.EmployeeEntity; import com.daqing.framework.domain.hrms.ext.EmployeeTO; +import com.daqing.framework.domain.hrms.ext.EmployeeVO; import com.daqing.framework.model.response.ResponseResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -101,4 +102,12 @@ public class EmployeeController implements EmployeeControllerApi { public ResponseResult getEmployeeById(@RequestParam("id") Long id) { return new ResponseResult().SUCCESS(employeeService.getEmployeeById(id)); } + + /** + * 查询所有员工姓名和id + */ + @GetMapping("/listEmployeeName") + public ResponseResult listEmployeeName() { + return new ResponseResult>().SUCCESS(employeeService.listEmployeeName()); + } } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/EmployeeDao.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/EmployeeDao.java index 97455798..0ad091ae 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/EmployeeDao.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/EmployeeDao.java @@ -24,4 +24,6 @@ public interface EmployeeDao extends BaseMapper { EmployeeEntity getEmployeeById(Long id); List listEmployeeByDeptId(Long id); + + List listEmployeeName(); } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/EmployeeService.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/EmployeeService.java index 766a6f0c..0facb246 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/EmployeeService.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/EmployeeService.java @@ -2,6 +2,7 @@ package com.daqing.financial.hrms.service; import com.baomidou.mybatisplus.extension.service.IService; import com.daqing.framework.domain.hrms.ext.EmployeeTO; +import com.daqing.framework.domain.hrms.ext.EmployeeVO; import com.daqing.framework.utils.PageUtils; import com.daqing.framework.domain.hrms.EmployeeEntity; @@ -20,5 +21,7 @@ public interface EmployeeService extends IService { List getEmployeeAndDeptById(List ids); EmployeeEntity getEmployeeById(Long id); + + List listEmployeeName(); } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/EmployeeServiceImpl.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/EmployeeServiceImpl.java index c2972dbc..4d458102 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/EmployeeServiceImpl.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/EmployeeServiceImpl.java @@ -1,6 +1,7 @@ package com.daqing.financial.hrms.service.impl; import com.daqing.framework.domain.hrms.ext.EmployeeTO; +import com.daqing.framework.domain.hrms.ext.EmployeeVO; import org.springframework.stereotype.Service; import java.util.List; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -32,4 +33,10 @@ public class EmployeeServiceImpl extends ServiceImpl listEmployeeName() { + + return this.getBaseMapper().listEmployeeName(); + } + } \ No newline at end of file diff --git a/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDao.xml b/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDao.xml index ca722c24..319113ee 100644 --- a/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDao.xml +++ b/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDao.xml @@ -57,4 +57,10 @@ ON ed.dept_id = d.id WHERE d.id = #{id} + + + \ No newline at end of file diff --git a/dq-framework-model/pom.xml b/dq-framework-model/pom.xml index f8e47283..ab582637 100644 --- a/dq-framework-model/pom.xml +++ b/dq-framework-model/pom.xml @@ -16,5 +16,10 @@ dq-framework-common 1.0-SNAPSHOT + + com.daqing.framework + dq-framework-utils + 0.0.1-SNAPSHOT + \ No newline at end of file diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerCompanyVO.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerCompanyVO.java index d2b6b281..9272e633 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerCompanyVO.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerCompanyVO.java @@ -1,5 +1,7 @@ package com.daqing.framework.domain.crms.ext; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.metadata.BaseRowModel; import lombok.Data; import lombok.ToString; @@ -13,66 +15,81 @@ import java.io.Serializable; */ @Data @ToString -public class CustomerCompanyVO implements Serializable { +public class CustomerCompanyVO extends BaseRowModel implements Serializable { /** * 客户编号 */ + @ExcelProperty(value = "编号",index = 0) private String code; /** * 客户类型:1、企业类型,0:个人类型 */ + @ExcelProperty(value = "企业类型",index = 1) private Integer type; /** * 客户经理 */ + @ExcelProperty(value = "客户经理",index = 2) private String manager; /** * 客户名称 */ + @ExcelProperty(value = "姓名",index = 3) private String name; /** * 联系地址 */ - private String address; + @ExcelProperty(value = "地址",index = 4) + private String addr; /** * 联系电话 */ + @ExcelProperty(value = "电话",index = 5) private String phone; /** * 注册资金 */ + @ExcelProperty(value = "注册资金",index = 6) private String registeredCapital; /** * 所属行业 */ + @ExcelProperty(value = "所属行业",index = 7) private String industry; /** * 成立年限 */ + @ExcelProperty(value = "成立年限",index = 8) private Integer years; /** * 所在区域 */ + @ExcelProperty(value = "所在区域",index = 9) private String region; /** * 股东名称 */ + @ExcelProperty(value = "股东名称",index = 10) private String shareholder; /** * 关联企业 */ + @ExcelProperty(value = "关联企业",index = 11) private String affiliatedCompany; /** * 员工个数 */ + @ExcelProperty(value = "员工个数",index = 12) private String employeeNumber; /** * 联系人 */ + @ExcelProperty(value = "联系人",index = 13) private String linkman; /** * 业务来源 */ + @ExcelProperty(value = "业务来源",index = 14) private String businessSource; } diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerPersonalVO.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerPersonalVO.java index 6ab5b6fe..ae968347 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerPersonalVO.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerPersonalVO.java @@ -1,5 +1,7 @@ package com.daqing.framework.domain.crms.ext; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.metadata.BaseRowModel; import lombok.Data; import lombok.ToString; @@ -13,90 +15,111 @@ import java.io.Serializable; */ @Data @ToString -public class CustomerPersonalVO implements Serializable { +public class CustomerPersonalVO extends BaseRowModel implements Serializable { /** * 客户编号 */ + @ExcelProperty(value = "编号",index = 0) private String code; /** * 客户类型:1、企业类型,0:个人类型 */ + @ExcelProperty(value = "个人类型",index = 1) private Integer type; /** * 客户经理 */ + @ExcelProperty(value = "客户经理",index = 2) private String manager; /** * 客户名称 */ + @ExcelProperty(value = "姓名",index = 3) private String name; /** * 联系地址 */ - private String address; + @ExcelProperty(value = "地址",index = 4) + private String addr; /** * 联系电话 */ + @ExcelProperty(value = "电话",index = 5) private String phone; /** * 身份证号 */ + @ExcelProperty(value = "身份证号",index = 6) private String idCard; /** * 年龄 */ + @ExcelProperty(value = "年龄",index = 7) private Integer age; /** * 性别:1、男,0、女 */ + @ExcelProperty(value = "性别(1:男,0:女)",index = 8) private Integer gender; /** * 婚姻状况:1、已婚,0、未婚 */ + @ExcelProperty(value = "婚姻状况(1:已婚,0:未婚)",index = 9) private Integer maritalStatus; /** * 学历 */ + @ExcelProperty(value = "学历",index = 10) private String education; /** * 工作单位 */ + @ExcelProperty(value = "工作单位",index = 11) private String employer; /** * 职务 */ + @ExcelProperty(value = "职务",index = 12) private String position; /** * 工作年限 */ + @ExcelProperty(value = "工作年限",index = 13) private Integer workingYears; /** * 社保账号 */ + @ExcelProperty(value = "社保账号",index = 14) private String socialSecurityNum; /** * 居住情况 */ + @ExcelProperty(value = "居住情况",index = 15) private String livingSituation; /** * 户籍地址 */ + @ExcelProperty(value = "户籍地址",index = 16) private String residenceAddr; /** * 业务来源 */ + @ExcelProperty(value = "业务来源",index = 17) private String businessSource; /** * 紧急联系人 */ + @ExcelProperty(value = "紧急联系人",index = 18) private String emergencyLinkman; /** * 紧急联系人关系 */ + @ExcelProperty(value = "紧急联系人关系",index = 19) private String emergencyLinkmanRelationship; /** * 紧急联系人电话 */ + @ExcelProperty(value = "紧急联系人电话",index = 20) private String emergencyLinkmanPhone; } diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerTO.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerTO.java index 2af040ac..eb6940ae 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerTO.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/crms/ext/CustomerTO.java @@ -1,5 +1,7 @@ package com.daqing.framework.domain.crms.ext; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.metadata.BaseRowModel; import lombok.Data; import lombok.ToString; diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/ext/EmployeeVO.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/ext/EmployeeVO.java index 82ccda76..04bf2f0b 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/ext/EmployeeVO.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/ext/EmployeeVO.java @@ -1,5 +1,7 @@ package com.daqing.framework.domain.hrms.ext; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.metadata.BaseRowModel; import lombok.Data; import lombok.ToString; diff --git a/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerCompanyVO.class b/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerCompanyVO.class index 29e9e50e..84fb62db 100644 Binary files a/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerCompanyVO.class and b/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerCompanyVO.class differ diff --git a/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerPersonalVO.class b/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerPersonalVO.class index 1b8d25ef..0943290e 100644 Binary files a/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerPersonalVO.class and b/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerPersonalVO.class differ diff --git a/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerTO.class b/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerTO.class index e9fb7b82..d2e2db43 100644 Binary files a/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerTO.class and b/dq-framework-model/target/classes/com/daqing/framework/domain/crms/ext/CustomerTO.class differ diff --git a/dq-framework-model/target/classes/com/daqing/framework/domain/hrms/ext/EmployeeVO.class b/dq-framework-model/target/classes/com/daqing/framework/domain/hrms/ext/EmployeeVO.class index dd2d9724..98407753 100644 Binary files a/dq-framework-model/target/classes/com/daqing/framework/domain/hrms/ext/EmployeeVO.class and b/dq-framework-model/target/classes/com/daqing/framework/domain/hrms/ext/EmployeeVO.class differ diff --git a/dq-framework-utils/pom.xml b/dq-framework-utils/pom.xml index 3a2d7d9d..2adf930b 100644 --- a/dq-framework-utils/pom.xml +++ b/dq-framework-utils/pom.xml @@ -38,19 +38,9 @@ 2.8.2 - org.apache.poi - poi - 4.0.1 - - - org.apache.poi - poi-ooxml - 4.0.1 - - - org.apache.poi - poi-ooxml-schemas - 4.0.1 + com.alibaba + easyexcel + 1.1.2-beta4 \ No newline at end of file diff --git a/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelException.java b/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelException.java new file mode 100644 index 00000000..0e62fd46 --- /dev/null +++ b/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelException.java @@ -0,0 +1,11 @@ +package com.daqing.framework.utils.excel; + + +/** + * 异常 + */ +public class ExcelException extends RuntimeException { + public ExcelException(String message) { + super(message); + } +} diff --git a/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelListener.java b/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelListener.java new file mode 100644 index 00000000..9827553f --- /dev/null +++ b/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelListener.java @@ -0,0 +1,61 @@ +package com.daqing.framework.utils.excel; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; + +import java.util.ArrayList; +import java.util.List; + +/** + * 监听 + */ +public class ExcelListener extends AnalysisEventListener { + + //自定义用于暂时存储data。 + //可以通过实例获取该值 + private List datas = new ArrayList<>(); + + /** + * 通过 AnalysisContext 对象还可以获取当前 sheet,当前行等数据 + */ + @Override + public void invoke(Object object, AnalysisContext context) { + //数据存储到list,供批量处理,或后续自己业务逻辑处理。 + datas.add(object); + //根据业务自行 do something + doSomething(); + + /* + 如数据过大,可以进行定量分批处理 + if(datas.size()<=100){ + datas.add(object); + }else { + doSomething(); + datas = new ArrayList(); + } + */ + + } + + /** + * 根据业务自行实现该方法 + */ + private void doSomething() { + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) { + /* + datas.clear(); + 解析结束销毁不用的资源 + */ + } + + public List getDatas() { + return datas; + } + + public void setDatas(List datas) { + this.datas = datas; + } +} diff --git a/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelUtil.java b/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelUtil.java new file mode 100644 index 00000000..ab88eb44 --- /dev/null +++ b/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelUtil.java @@ -0,0 +1,148 @@ +package com.daqing.framework.utils.excel; + +import com.alibaba.excel.ExcelReader; +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.metadata.BaseRowModel; +import com.alibaba.excel.metadata.Sheet; +import com.alibaba.excel.support.ExcelTypeEnum; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.util.List; + +/** + * 基本工具类 + */ +public class ExcelUtil { + /** + * 读取 Excel(多个 sheet) + * + * @param excel 文件 + * @param rowModel 实体类映射,继承 BaseRowModel 类 + * @return Excel 数据 list + */ + public static List readExcel(MultipartFile excel, BaseRowModel rowModel) { + ExcelListener excelListener = new ExcelListener(); + ExcelReader reader = getReader(excel, excelListener); + if (reader == null) { + return null; + } + for (Sheet sheet : reader.getSheets()) { + if (rowModel != null) { + sheet.setClazz(rowModel.getClass()); + } + reader.read(sheet); + } + return excelListener.getDatas(); + } + + /** + * 读取某个 sheet 的 Excel + * + * @param excel 文件 + * @param rowModel 实体类映射,继承 BaseRowModel 类 + * @param sheetNo sheet 的序号 从1开始 + * @return Excel 数据 list + */ + public static List readExcel(MultipartFile excel, BaseRowModel rowModel, int sheetNo) { + return readExcel(excel, rowModel, sheetNo, 1); + } + + /** + * 读取某个 sheet 的 Excel + * + * @param excel 文件 + * @param rowModel 实体类映射,继承 BaseRowModel 类 + * @param sheetNo sheet 的序号 从1开始 + * @param headLineNum 表头行数,默认为1 + * @return Excel 数据 list + */ + public static List readExcel(MultipartFile excel, BaseRowModel rowModel, int sheetNo, + int headLineNum) { + ExcelListener excelListener = new ExcelListener(); + ExcelReader reader = getReader(excel, excelListener); + if (reader == null) { + return null; + } + reader.read(new Sheet(sheetNo, headLineNum, rowModel.getClass())); + return excelListener.getDatas(); + } + + /** + * 导出 Excel :一个 sheet,带表头 + * + * @param response HttpServletResponse + * @param list 数据 list,每个元素为一个 BaseRowModel + * @param fileName 导出的文件名 + * @param sheetName 导入文件的 sheet 名 + * @param object 映射实体类,Excel 模型 + */ + public static void writeExcel(HttpServletResponse response, List list, + String fileName, String sheetName, BaseRowModel object) { + ExcelWriter writer = new ExcelWriter(getOutputStream(fileName, response), ExcelTypeEnum.XLSX); + Sheet sheet = new Sheet(1, 0, object.getClass()); + sheet.setSheetName(sheetName); + writer.write(list, sheet); + writer.finish(); + } + + /** + * 导出 Excel :多个 sheet,带表头 + * + * @param response HttpServletResponse + * @param list 数据 list,每个元素为一个 BaseRowModel + * @param fileName 导出的文件名 + * @param sheetName 导入文件的 sheet 名 + * @param object 映射实体类,Excel 模型 + */ + public static ExcelWriterFactroy writeExcelWithSheets(HttpServletResponse response, List list, + String fileName, String sheetName, BaseRowModel object) { + ExcelWriterFactroy writer = new ExcelWriterFactroy(getOutputStream(fileName, response), ExcelTypeEnum.XLSX); + Sheet sheet = new Sheet(1, 0, object.getClass()); + sheet.setSheetName(sheetName); + writer.write(list, sheet); + return writer; + } + + /** + * 导出文件时为Writer生成OutputStream + */ + private static OutputStream getOutputStream(String fileName, HttpServletResponse response) { + //创建本地文件 + String filePath = fileName + ".xlsx"; + File dbfFile = new File(filePath); + try { + if (!dbfFile.exists() || dbfFile.isDirectory()) { + dbfFile.createNewFile(); + } + fileName = new String(filePath.getBytes(), "ISO-8859-1"); + response.addHeader("Content-Disposition", "filename=" + fileName); + return response.getOutputStream(); + } catch (IOException e) { + throw new ExcelException("创建文件失败!"); + } + } + + /** + * 返回 ExcelReader + * + * @param excel 需要解析的 Excel 文件 + * @param excelListener new ExcelListener() + */ + private static ExcelReader getReader(MultipartFile excel, + ExcelListener excelListener) { + String filename = excel.getOriginalFilename(); + if (filename == null || (!filename.toLowerCase().endsWith(".xls") && !filename.toLowerCase().endsWith(".xlsx"))) { + throw new ExcelException("文件格式错误!"); + } + InputStream inputStream; + try { + inputStream = new BufferedInputStream(excel.getInputStream()); + return new ExcelReader(inputStream, null, excelListener, false); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } +} diff --git a/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelWriterFactroy.java b/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelWriterFactroy.java new file mode 100644 index 00000000..ec56ad88 --- /dev/null +++ b/dq-framework-utils/src/main/java/com/daqing/framework/utils/excel/ExcelWriterFactroy.java @@ -0,0 +1,51 @@ +package com.daqing.framework.utils.excel; + +import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.metadata.BaseRowModel; +import com.alibaba.excel.metadata.Sheet; +import com.alibaba.excel.support.ExcelTypeEnum; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; + +/** + * 多sheet工具类 + */ +public class ExcelWriterFactroy extends ExcelWriter { + private OutputStream outputStream; + private int sheetNo = 1; + + public ExcelWriterFactroy(OutputStream outputStream, ExcelTypeEnum typeEnum) { + super(outputStream, typeEnum); + this.outputStream = outputStream; + } + + public ExcelWriterFactroy write(List list, String sheetName, + BaseRowModel object) { + this.sheetNo++; + try { + Sheet sheet = new Sheet(sheetNo, 0, object.getClass()); + sheet.setSheetName(sheetName); + this.write(list, sheet); + } catch (Exception ex) { + ex.printStackTrace(); + try { + outputStream.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return this; + } + + @Override + public void finish() { + super.finish(); + try { + outputStream.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/dq-framework-utils/src/main/java/com/daqing/framework/utils/OssFileUtils.java b/dq-framework-utils/src/main/java/com/daqing/framework/utils/oss/OssFileUtils.java similarity index 98% rename from dq-framework-utils/src/main/java/com/daqing/framework/utils/OssFileUtils.java rename to dq-framework-utils/src/main/java/com/daqing/framework/utils/oss/OssFileUtils.java index c02b95ad..fe7cd5b8 100644 --- a/dq-framework-utils/src/main/java/com/daqing/framework/utils/OssFileUtils.java +++ b/dq-framework-utils/src/main/java/com/daqing/framework/utils/oss/OssFileUtils.java @@ -1,4 +1,4 @@ -package com.daqing.framework.utils; +package com.daqing.framework.utils.oss; import com.aliyun.oss.OSSClient; import com.aliyun.oss.model.PutObjectRequest; diff --git a/dq-framework-utils/src/main/java/com/daqing/framework/utils/poi/ExcelAttribute.java b/dq-framework-utils/src/main/java/com/daqing/framework/utils/poi/ExcelAttribute.java deleted file mode 100644 index 06d41b47..00000000 --- a/dq-framework-utils/src/main/java/com/daqing/framework/utils/poi/ExcelAttribute.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.daqing.framework.utils.poi; - -/** - * @auther River - * @date 2020/9/16 17:10 - */ -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ExcelAttribute { - /** - * 对应的列名称 - */ - String name() default ""; - - /** - * excel列的索引 - */ - int sort(); - - /** - * 字段类型对应的格式 - */ - String format() default ""; -} diff --git a/dq-framework-utils/src/main/java/com/daqing/framework/utils/poi/ExcelExportUtil.java b/dq-framework-utils/src/main/java/com/daqing/framework/utils/poi/ExcelExportUtil.java deleted file mode 100644 index cfbed970..00000000 --- a/dq-framework-utils/src/main/java/com/daqing/framework/utils/poi/ExcelExportUtil.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.daqing.framework.utils.poi; - -import lombok.Data; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import javax.servlet.http.HttpServletResponse; - -import java.io.InputStream; -import java.lang.reflect.Field; -import java.net.URLEncoder; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * 导出Excel工具类 - * 基于模板打印的方式导出: - */ -@Data -public class ExcelExportUtil { - - private int rowIndex; //写入数据的起始行 - private int styleIndex; //需要提取的样式所在的行号 - private Class clazz; //对象的字节码 - private Field fields[]; //对象中的所有属性 - - public ExcelExportUtil(Class clazz, int rowIndex, int styleIndex) { - this.clazz = clazz; - this.rowIndex = rowIndex; - this.styleIndex = styleIndex; - fields = clazz.getDeclaredFields(); - } - - /** - * 基于注解导出 - * 参数: - * response: - * InputStream:模板的输入流 - * objs:数据 - * fileName:生成的文件名 - */ - public void export(HttpServletResponse response, InputStream is, List objs, String fileName) throws Exception { - - //1.根据模板创建工作簿 - XSSFWorkbook workbook = new XSSFWorkbook(is); - //2.读取工作表 - Sheet sheet = workbook.getSheetAt(0); - //3.提取公共的样式 - CellStyle[] styles = getTemplateStyles(sheet.getRow(styleIndex)); - //4.根据数据创建每一行和每一个单元格的数据2 - AtomicInteger datasAi = new AtomicInteger(rowIndex); //数字 - for (T t : objs) { - //datasAi.getAndIncrement() :获取数字,并++ i++ - Row row = sheet.createRow(datasAi.getAndIncrement()); - for (int i = 0; i < styles.length; i++) { - Cell cell = row.createCell(i); - cell.setCellStyle(styles[i]); - for (Field field : fields) { - if (field.isAnnotationPresent(ExcelAttribute.class)) { - field.setAccessible(true); - ExcelAttribute ea = field.getAnnotation(ExcelAttribute.class); - if (i == ea.sort()) { - if (field.get(t) != null) { - cell.setCellValue(field.get(t).toString()); - } - } - } - } - } - } - fileName = URLEncoder.encode(fileName, "UTF-8"); - response.setContentType("application/octet-stream"); - response.setHeader("content-disposition", "attachment;filename=" + new String(fileName.getBytes("ISO8859-1"))); - response.setHeader("filename", fileName); - workbook.write(response.getOutputStream()); - } - - CellStyle[] getTemplateStyles(Row row) { - CellStyle[] styles = new CellStyle[row.getLastCellNum()]; - for (int i = 0; i < row.getLastCellNum(); i++) { - styles[i] = row.getCell(i).getCellStyle(); - } - return styles; - } -} \ No newline at end of file diff --git a/dq-framework-utils/src/main/java/com/daqing/framework/utils/poi/ExcelImportUtil.java b/dq-framework-utils/src/main/java/com/daqing/framework/utils/poi/ExcelImportUtil.java deleted file mode 100644 index 9caabad2..00000000 --- a/dq-framework-utils/src/main/java/com/daqing/framework/utils/poi/ExcelImportUtil.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.daqing.framework.utils.poi; - -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.DateUtil; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; - -import java.io.InputStream; -import java.lang.reflect.Field; -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -public class ExcelImportUtil { - - private Class clazz; - private Field fields[]; - - public ExcelImportUtil(Class clazz) { - this.clazz = clazz; - fields = clazz.getDeclaredFields(); - } - - /** - * 基于注解读取excel - */ - public List readExcel(InputStream is, int rowIndex, int cellIndex) { - List list = new ArrayList<>(); - T entity = null; - try { - XSSFWorkbook workbook = new XSSFWorkbook(is); - Sheet sheet = workbook.getSheetAt(0); - // 不准确 - // int rowLength = sheet.getLastRowNum(); - // System.out.println(sheet.getLastRowNum()); - for (int rowNum = rowIndex; rowNum <= sheet.getLastRowNum(); rowNum++) { - Row row = sheet.getRow(rowNum); - entity = (T) clazz.newInstance(); - // System.out.println(row.getLastCellNum()); - for (int j = cellIndex; j < row.getLastCellNum(); j++) { - Cell cell = row.getCell(j); - for (Field field : fields) { - if (field.isAnnotationPresent(ExcelAttribute.class)) { - field.setAccessible(true); - ExcelAttribute ea = field.getAnnotation(ExcelAttribute.class); - if (j == ea.sort()) { - field.set(entity, covertAttrType(field, cell)); - } - } - } - } - Field field = entity.getClass().getDeclaredField("index"); - field.setAccessible(true); - field.set(entity, rowNum); - list.add(entity); - } - } catch (Exception e) { - e.printStackTrace(); - } - return list; - } - - /** - * 类型转换 将cell 单元格格式转为 字段类型 - */ - private Object covertAttrType(Field field, Cell cell) throws Exception { - String fieldType = field.getType().getSimpleName(); - if ("String".equals(fieldType)) { - return getValue(cell); - } else if ("Date".equals(fieldType)) { - return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(getValue(cell)); - } else if ("int".equals(fieldType) || "Integer".equals(fieldType)) { - return Integer.parseInt(getValue(cell)); - } else if ("double".equals(fieldType) || "Double".equals(fieldType)) { - return Double.parseDouble(getValue(cell)); - } else { - return null; - } - } - - - /** - * 格式转为String - * - * @param cell - * @return - */ - public String getValue(Cell cell) { - if (cell == null) { - return ""; - } - switch (cell.getCellType()) { - case STRING: - return cell.getRichStringCellValue().getString().trim(); - case NUMERIC: - if (DateUtil.isCellDateFormatted(cell)) { - Date dt = DateUtil.getJavaDate(cell.getNumericCellValue()); - return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(dt); - } else { - // 防止数值变成科学计数法 - String strCell = ""; - Double num = cell.getNumericCellValue(); - BigDecimal bd = new BigDecimal(num.toString()); - if (bd != null) { - strCell = bd.toPlainString(); - } - // 去除 浮点型 自动加的 .0 - if (strCell.endsWith(".0")) { - strCell = strCell.substring(0, strCell.indexOf(".")); - } - return strCell; - } - case BOOLEAN: - return String.valueOf(cell.getBooleanCellValue()); - default: - return ""; - } - } -} diff --git a/dq-framework-utils/target/classes/META-INF/dq-framework-utils.kotlin_module b/dq-framework-utils/target/classes/META-INF/dq-framework-utils.kotlin_module new file mode 100644 index 00000000..8fb60192 Binary files /dev/null and b/dq-framework-utils/target/classes/META-INF/dq-framework-utils.kotlin_module differ diff --git a/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelException.class b/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelException.class new file mode 100644 index 00000000..a730230f Binary files /dev/null and b/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelException.class differ diff --git a/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelListener.class b/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelListener.class new file mode 100644 index 00000000..0c0724ec Binary files /dev/null and b/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelListener.class differ diff --git a/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelUtil.class b/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelUtil.class new file mode 100644 index 00000000..daa321c3 Binary files /dev/null and b/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelUtil.class differ diff --git a/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelWriterFactroy.class b/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelWriterFactroy.class new file mode 100644 index 00000000..ea702d78 Binary files /dev/null and b/dq-framework-utils/target/classes/com/daqing/framework/utils/excel/ExcelWriterFactroy.class differ diff --git a/dq-framework-utils/target/classes/com/daqing/framework/utils/oss/OssFileUtils.class b/dq-framework-utils/target/classes/com/daqing/framework/utils/oss/OssFileUtils.class new file mode 100644 index 00000000..772548cd Binary files /dev/null and b/dq-framework-utils/target/classes/com/daqing/framework/utils/oss/OssFileUtils.class differ