From 42ffa68c1719fee283a4ce4feb4221006e234f0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=82=B3=E8=BC=B8=E5=8A=A9=E6=89=8B?=
<1766219146@qq.com>
Date: Mon, 22 Aug 2022 19:26:24 +0800
Subject: [PATCH] shl
---
pom.xml | 16 ++++
.../irs/controller/EnterpriseController.java | 78 +++++++++++++++----
.../com/sixteam/irs/entity/Enterprise.java | 12 +++
.../sixteam/irs/mapper/EnterpriseMapper.java | 1 +
.../irs/service/EnterpriseService.java | 4 +-
.../service/Impl/EnterpriceServiceImpl.java | 20 ++---
.../sixteam/irs/mapper/EnterpriseMapper.xml | 2 +
7 files changed, 110 insertions(+), 23 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4c7f134..e484f5f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -108,6 +108,22 @@
thymeleaf-extras-java8time
+
+ cn.afterturn
+ easypoi-base
+ 4.1.0
+
+
+ cn.afterturn
+ easypoi-web
+ 4.1.0
+
+
+ cn.afterturn
+ easypoi-annotation
+ 4.1.0
+
+
diff --git a/src/main/java/com/sixteam/irs/controller/EnterpriseController.java b/src/main/java/com/sixteam/irs/controller/EnterpriseController.java
index 57f2e04..deab798 100644
--- a/src/main/java/com/sixteam/irs/controller/EnterpriseController.java
+++ b/src/main/java/com/sixteam/irs/controller/EnterpriseController.java
@@ -1,15 +1,24 @@
package com.sixteam.irs.controller;
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
+import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.sixteam.irs.entity.Enterprise;
-import com.sixteam.irs.entity.R;
import com.sixteam.irs.entity.User;
import com.sixteam.irs.service.EnterpriseService;
+import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URLEncoder;
import java.util.List;
@RestController
@@ -21,32 +30,35 @@ public class EnterpriseController {
private EnterpriseService enterpriseService;
//查询所有企业
- @RequestMapping("/getAllEnterprise")
@ResponseBody
- public List getAllEnterprise(HttpServletRequest request){
- List enterpriseList = enterpriseService.findAllEnterprise();
- return enterpriseList;
+ @RequestMapping("/getAllEnterprise")
+ public List getAllEnterprise(HttpServletRequest request) {
+ List getAllEnterprise = enterpriseService.findAllEnterprise();
+
+ return getAllEnterprise;
}
@RequestMapping("/toAddEnterprise")
- public String toAddEnterprise(){
+ public String toAddEnterprise() {
return "/test/enterprise/添加企业页面.html";
}
@RequestMapping("/addEnterprise")
- @ResponseBody
- public R addEnterprise(Enterprise enterprise, HttpServletRequest request){
- System.out.println(enterpriseService.addEnterprise(enterprise));
- return enterpriseService.addEnterprise(enterprise);
-
+ public String addEnterprise(Enterprise enterprise, HttpServletRequest request) {
+ if (enterpriseService.addEnterprise(enterprise) > 0) {
+ return "redirect:/enterprise/getAllEnterprise";
+ } else {
+ request.setAttribute("errorMessage", "删除错误");
+ return "/test/错误页面";
+ }
}
@RequestMapping(value = "/delEnterprise")
public String delEnterprise(Enterprise enterprise, Model model) {
- if (enterpriseService.delEnterprise(enterprise)>0) {
+ if (enterpriseService.delEnterprise(enterprise) > 0) {
return "redirect:/enterprise/getAllEnterprise";
} else {
@@ -68,7 +80,7 @@ public class EnterpriseController {
@RequestMapping(value = "/updateEnterprise")
public String updateUser(Enterprise enterprise, Model model) {
- if (enterpriseService.updateEnterprise(enterprise)>0) {
+ if (enterpriseService.updateEnterprise(enterprise) > 0) {
return "redirect:/enterprise/getAllEnterprise";
} else {
@@ -78,4 +90,44 @@ public class EnterpriseController {
}
}
+ /**
+ * 导出excel
+ *
+ * @param response
+ * @throws IOException
+ */
+ @RequestMapping("/export")
+ public void ExportExel(HttpServletResponse response) throws IOException{
+ List enterprises = enterpriseService.findAllEnterprise();
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("企业列表信息","企业信息"),Enterprise.class,enterprises);
+ response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("企业列表.xls", "UTF-8"));
+ ServletOutputStream outputStream = response.getOutputStream();
+ workbook.write(outputStream);
+ outputStream.close();
+ workbook.close();
+ }
+
+ /**
+ * excel导入
+ *
+ * @param excelFile
+ * @return
+ * @throws Exception
+ */
+ @RequestMapping("/import")
+ public String importExcel(MultipartFile excelFile) throws Exception {
+// log.info("文件名:"+excelFile.getOriginalFilename());
+ //excel导入
+ ImportParams params = new ImportParams();
+ params.setTitleRows(1);
+ params.setHeadRows(1);
+
+ List enterprises = ExcelImportUtil.importExcel(excelFile.getInputStream(), Enterprise.class, params);
+// for (User user : users) {
+// System.out.println(user);
+// }
+ enterpriseService.savaAll(enterprises);
+ return "redirect:/enterprise/getAllEnterprise";
+ }
+
}
diff --git a/src/main/java/com/sixteam/irs/entity/Enterprise.java b/src/main/java/com/sixteam/irs/entity/Enterprise.java
index 9fb2582..74fa4b7 100644
--- a/src/main/java/com/sixteam/irs/entity/Enterprise.java
+++ b/src/main/java/com/sixteam/irs/entity/Enterprise.java
@@ -1,15 +1,27 @@
package com.sixteam.irs.entity;
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
+
import java.util.List;
+@ExcelTarget("enterprises")
public class Enterprise {
+ @Excel(name = "编号")
private String eId;//企业id
+ @Excel(name = "企业名称")
private String eName;//企业名称
+ @Excel(name = "企业介绍")
private String eIntroduce;//企业介绍
+ @Excel(name = "企业成立时间")
private String eStart;//企业成立时间
+ @Excel(name = "企业类型")
private String eType;//企业类型,定位
+ @Excel(name = "企业创始人")
private String eFounder;//企业创始人
+ @Excel(name = "企业地点")
private String eAddress;//企业地点
+ @Excel(name = "企业状态")
private String eState;//企业申请认证 已通过/未通过
diff --git a/src/main/java/com/sixteam/irs/mapper/EnterpriseMapper.java b/src/main/java/com/sixteam/irs/mapper/EnterpriseMapper.java
index 3e8cad9..7b49bd0 100644
--- a/src/main/java/com/sixteam/irs/mapper/EnterpriseMapper.java
+++ b/src/main/java/com/sixteam/irs/mapper/EnterpriseMapper.java
@@ -21,5 +21,6 @@ public interface EnterpriseMapper {
int updateEnterprise(Enterprise enterprise);
List findEnterpriseByName(Enterprise enterprise);
+
}
diff --git a/src/main/java/com/sixteam/irs/service/EnterpriseService.java b/src/main/java/com/sixteam/irs/service/EnterpriseService.java
index e568e8d..b910e14 100644
--- a/src/main/java/com/sixteam/irs/service/EnterpriseService.java
+++ b/src/main/java/com/sixteam/irs/service/EnterpriseService.java
@@ -8,7 +8,7 @@ import java.util.List;
public interface EnterpriseService {
- R addEnterprise(Enterprise enterprise);//添加企业
+ int addEnterprise(Enterprise enterprise);//添加企业
List findAllEnterprise();
@@ -19,4 +19,6 @@ public interface EnterpriseService {
int delEnterprise(Enterprise enterprise);
int updateEnterprise(Enterprise enterprise);
+
+ void savaAll(List enterprises);
}
diff --git a/src/main/java/com/sixteam/irs/service/Impl/EnterpriceServiceImpl.java b/src/main/java/com/sixteam/irs/service/Impl/EnterpriceServiceImpl.java
index 259bd55..9db8327 100644
--- a/src/main/java/com/sixteam/irs/service/Impl/EnterpriceServiceImpl.java
+++ b/src/main/java/com/sixteam/irs/service/Impl/EnterpriceServiceImpl.java
@@ -35,15 +35,9 @@ public class EnterpriceServiceImpl implements EnterpriseService {
}
@Override
- public R addEnterprise(Enterprise enterprise) {
-
- Enterprise enterprise1 = new Enterprise();
- enterprise1.seteId(UuidUtils.uuid());
- BeanUtils.copyProperties(enterprise1, enterprise);
- if (enterpriseMapper.addEnterprise(enterprise1) > 0) {
- return R.success("添加记录成功");
- }
- return R.error("添加时,发生异常");
+ public int addEnterprise(Enterprise enterprise) {
+ enterprise.seteId(UuidUtils.uuid());
+ return enterpriseMapper.addEnterprise(enterprise);
}
@Override
@@ -55,4 +49,12 @@ public class EnterpriceServiceImpl implements EnterpriseService {
public int updateEnterprise(Enterprise enterprise) {
return enterpriseMapper.updateEnterprise(enterprise);
}
+
+ @Override
+ public void savaAll(List enterprises) {
+ for (Enterprise enterprise : enterprises){
+ enterprise.seteId(UuidUtils.uuid());
+ enterpriseMapper.addEnterprise(enterprise);
+ }
+ }
}
diff --git a/src/main/resources/com/sixteam/irs/mapper/EnterpriseMapper.xml b/src/main/resources/com/sixteam/irs/mapper/EnterpriseMapper.xml
index 1805287..fcd13b9 100644
--- a/src/main/resources/com/sixteam/irs/mapper/EnterpriseMapper.xml
+++ b/src/main/resources/com/sixteam/irs/mapper/EnterpriseMapper.xml
@@ -47,4 +47,6 @@
where e_id = #{eId}
+
+
\ No newline at end of file
--
Gitee