|
@@ -7,8 +7,8 @@ import cn.com.ty.lift.enterprise.custom.dao.mapper.PropertyCompanyMapper;
|
|
|
import cn.com.ty.lift.enterprise.custom.service.PropertyCompanyService;
|
|
|
import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.poi.excel.BigExcelWriter;
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelWriter;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
@@ -18,8 +18,9 @@ import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.*;
|
|
|
+import java.io.IOException;
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -37,22 +38,19 @@ import java.util.List;
|
|
|
public class PropertyCompanyServiceImpl extends ServiceImpl<PropertyCompanyMapper, PropertyCompany> implements PropertyCompanyService {
|
|
|
private final PropertyContactServiceImpl propertyContactService;
|
|
|
|
|
|
- public RestResponse propertyCompanies(PropertyCompanyReq req) {
|
|
|
- Page<PropertyCompany> page = new Page<>(req.getPageNum(), req.getPageSize());
|
|
|
+ public RestResponse propertyCompanies(PropertyCompanyReq request) {
|
|
|
+ Page<PropertyCompany> page = new Page<>(request.getPageNum(), request.getPageSize());
|
|
|
//根据请求参数查询客户列表
|
|
|
IPage<PropertyCompany> records = this
|
|
|
.page(page, new QueryWrapper<PropertyCompany>()
|
|
|
.select("id", "mt_company_id", "name", "mailing_address", "status")
|
|
|
- .eq(req.getMtCompanyId() != null, "mt_company_id", req.getMtCompanyId())
|
|
|
+ .eq(request.getMtCompanyId() != null, "mt_company_id", request.getMtCompanyId())
|
|
|
.ne("status", 0)
|
|
|
- .and(req.getInfo() != null, c ->
|
|
|
- c
|
|
|
- .like("name", req.getInfo())
|
|
|
- .or()
|
|
|
- .like("address", req.getInfo())
|
|
|
- .or()
|
|
|
- .like("mailing_address", req.getInfo())
|
|
|
- ));
|
|
|
+ .and(request.getInfo() != null, companyQueryWrapper ->
|
|
|
+ companyQueryWrapper
|
|
|
+ .like("name", request.getInfo())
|
|
|
+ .or().like("address", request.getInfo())
|
|
|
+ .or().like("mailing_address", request.getInfo())));
|
|
|
if (records.getRecords().isEmpty()) {
|
|
|
return RestResponse.success();
|
|
|
}
|
|
@@ -92,70 +90,38 @@ public class PropertyCompanyServiceImpl extends ServiceImpl<PropertyCompanyMappe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void export(PropertyCompany propertyCompany, HttpServletResponse res) {
|
|
|
- String fileName = "甲方公司_" + LocalDate.now().toString() + ".xlsx";
|
|
|
+ public void export(PropertyCompany propertyCompany, HttpServletResponse response) {
|
|
|
List<PropertyCompany> companies = this.list(new QueryWrapper<PropertyCompany>()
|
|
|
.select("id", "name", "mailing_address", "status")
|
|
|
.eq("mt_company_id", propertyCompany.getMtCompanyId())
|
|
|
.ne("status", 0));
|
|
|
-
|
|
|
List<List<?>> rows = new ArrayList<>();
|
|
|
//设置列头
|
|
|
- rows.add(CollUtil.newArrayList("甲方公司id", "名称", "通讯地址", "状态,1正常 2有关联项目"));
|
|
|
- companies.forEach(c -> {
|
|
|
- List<?> row = CollUtil.newArrayList(c.getId().toString(), c.getName(), c.getMailingAddress(), c.getStatus());
|
|
|
+ rows.add(CollUtil.newArrayList("甲方公司id", "名称", "通讯地址", "状态"));
|
|
|
+ companies.forEach(company -> {
|
|
|
+ List<?> row = CollUtil.newArrayList(
|
|
|
+ company.getId()
|
|
|
+ , company.getName()
|
|
|
+ , null != company.getMailingAddress() ? company.getMailingAddress() : "无"
|
|
|
+ , company.getStatus() == 1 ? "无关联项目" : "有关联项目");
|
|
|
rows.add(row);
|
|
|
});
|
|
|
- BigExcelWriter writer = ExcelUtil.getBigWriter(System.getProperty("user.dir") + "/" + fileName);
|
|
|
+
|
|
|
+ ExcelWriter writer = ExcelUtil.getWriter(true);
|
|
|
//设置列宽
|
|
|
writer.setColumnWidth(0, 25);
|
|
|
writer.setColumnWidth(1, 35);
|
|
|
writer.setColumnWidth(2, 40);
|
|
|
writer.setColumnWidth(3, 25);
|
|
|
- // 一次性写出内容,使用默认样式
|
|
|
- writer.write(rows);
|
|
|
- // 关闭writer,释放内存
|
|
|
- writer.close();
|
|
|
-
|
|
|
- res.setHeader("Content-Disposition", "attachment; filename=" + fileName);
|
|
|
- res.setHeader("content-type", "application/x-msdownload;");
|
|
|
- res.setContentType("text/plain; charset=utf-8");
|
|
|
- byte[] buff = new byte[1024];
|
|
|
- BufferedInputStream bis = null;
|
|
|
- OutputStream os = null;
|
|
|
|
|
|
- File file = new File(System.getProperty("user.dir") + "/" + fileName);
|
|
|
- try {
|
|
|
- os = res.getOutputStream();
|
|
|
- bis = new BufferedInputStream(new FileInputStream(file));
|
|
|
- int i = bis.read(buff);
|
|
|
-
|
|
|
- while (i != -1) {
|
|
|
- os.write(buff, 0, buff.length);
|
|
|
- os.flush();
|
|
|
- i = bis.read(buff);
|
|
|
- }
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + LocalDate.now().toString() + ".xlsx");
|
|
|
+ try (ServletOutputStream out = response.getOutputStream()) {
|
|
|
+ writer.write(rows);
|
|
|
+ writer.flush(out, true);
|
|
|
+ writer.close();
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
- } finally {
|
|
|
- if (os != null) {
|
|
|
- try {
|
|
|
- os.close();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- if (bis != null) {
|
|
|
- try {
|
|
|
- bis.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (file.exists()) {
|
|
|
- file.delete();
|
|
|
}
|
|
|
}
|
|
|
}
|