|
@@ -1,20 +1,29 @@
|
|
|
package com.jpsoft.enterprise.modules.base.controller;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.enterprise.config.OSSConfig;
|
|
|
import com.jpsoft.enterprise.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.enterprise.modules.common.dto.Sort;
|
|
|
import com.jpsoft.enterprise.modules.base.entity.DoubleHundred;
|
|
|
import com.jpsoft.enterprise.modules.base.service.DoubleHundredService;
|
|
|
+import com.jpsoft.enterprise.modules.common.utils.OSSUtil;
|
|
|
import com.jpsoft.enterprise.modules.common.utils.PojoUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -32,6 +41,9 @@ public class DoubleHundredController {
|
|
|
@Autowired
|
|
|
private DoubleHundredService doubleHundredService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+
|
|
|
@ApiOperation(value="创建空记录")
|
|
|
@GetMapping("create")
|
|
|
public MessageResult<DoubleHundred> create(){
|
|
@@ -200,31 +212,112 @@ public class DoubleHundredController {
|
|
|
|
|
|
@ApiOperation(value="列表")
|
|
|
@RequestMapping(value = "pageList",method = RequestMethod.POST)
|
|
|
- public MessageResult<Map> pageList(
|
|
|
+ public MessageResult<Object> pageList(
|
|
|
String id,
|
|
|
+ @RequestParam(value="information",defaultValue="") String information,
|
|
|
+ @RequestParam(value="person",defaultValue="") String person,
|
|
|
+ @RequestParam(value="phone",defaultValue="") String phone,
|
|
|
+ @RequestParam(value="region",defaultValue="") String region,
|
|
|
@RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
@RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
+ @RequestParam(value = "exportFlag", defaultValue = "false") Boolean exportFlag,
|
|
|
@RequestAttribute String subject){
|
|
|
|
|
|
//当前用户ID
|
|
|
System.out.println(subject);
|
|
|
|
|
|
- MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+ MessageResult<Object> msgResult = new MessageResult<>();
|
|
|
|
|
|
Map<String,Object> searchParams = new HashMap<>();
|
|
|
|
|
|
List<Sort> sortList = new ArrayList<>();
|
|
|
- sortList.add(new Sort("id_","asc"));
|
|
|
+ sortList.add(new Sort("create_time","desc"));
|
|
|
|
|
|
if (StringUtils.isNotEmpty(id)) {
|
|
|
searchParams.put("id","%" + id + "%");
|
|
|
}
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(information)) {
|
|
|
+ searchParams.put("information","%" + information + "%");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(person)) {
|
|
|
+ searchParams.put("person","%" + person + "%");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(phone)) {
|
|
|
+ searchParams.put("phone","%" + phone + "%");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(region)) {
|
|
|
+ searchParams.put("region","%" + region + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map> mapList = new ArrayList<>();
|
|
|
+
|
|
|
Page<DoubleHundred> page = doubleHundredService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
|
|
|
+ if(exportFlag) {
|
|
|
+ String filePath = exportXls(page.getResult());
|
|
|
+ msgResult.setData(filePath);
|
|
|
+ }else {
|
|
|
+ msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
+ }
|
|
|
msgResult.setResult(true);
|
|
|
- msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
+
|
|
|
|
|
|
return msgResult;
|
|
|
}
|
|
|
+
|
|
|
+ private String exportXls(List<DoubleHundred> dhList) {
|
|
|
+ String downloadUrl = "";
|
|
|
+
|
|
|
+ Workbook workbook = new HSSFWorkbook();
|
|
|
+ Sheet sheet = workbook.createSheet();
|
|
|
+
|
|
|
+ //表头
|
|
|
+ Row rowTitle = sheet.createRow(0);
|
|
|
+
|
|
|
+ String[] titles = new String[]{"序号","区域","企业信息","联系人","联系电话","企业介绍",
|
|
|
+ "收入(亿)","纳税(万)","企业法人","法人联系方式"};
|
|
|
+
|
|
|
+ for (int i=0;i<titles.length;i++) {
|
|
|
+ Cell cell = rowTitle.createCell(i);
|
|
|
+ cell.setCellValue(titles[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i=0;i<dhList.size();i++){
|
|
|
+ DoubleHundred dh = dhList.get(i);
|
|
|
+
|
|
|
+ Row row = sheet.createRow(i+1);
|
|
|
+
|
|
|
+ int colIndex = 0;
|
|
|
+ row.createCell(colIndex++).setCellValue(i+1);
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.enterprise.modules.common.utils.StringUtils.strValue(dh.getRegion(),""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.enterprise.modules.common.utils.StringUtils.strValue(dh.getInformation(),""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.enterprise.modules.common.utils.StringUtils.strValue(dh.getPerson(),""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.enterprise.modules.common.utils.StringUtils.strValue(dh.getPhone(),""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.enterprise.modules.common.utils.StringUtils.strValue(dh.getIntroduction(),""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.enterprise.modules.common.utils.StringUtils.strValue(dh.getIncome(),""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.enterprise.modules.common.utils.StringUtils.strValue(dh.getPayTaxes(),""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.enterprise.modules.common.utils.StringUtils.strValue(dh.getCorporate(),""));
|
|
|
+ row.createCell(colIndex++).setCellValue(com.jpsoft.enterprise.modules.common.utils.StringUtils.strValue(dh.getCorporatePhone(),""));
|
|
|
+ }
|
|
|
+
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ try {
|
|
|
+ workbook.write(output);
|
|
|
+
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
|
|
|
+ String now = sdf.format(new Date());
|
|
|
+ String fileName = "企业双百强导出" + now + ".xls";
|
|
|
+ downloadUrl = OSSUtil.upload(ossConfig,"doubleHundred",fileName,input);
|
|
|
+ }
|
|
|
+ catch (Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ return downloadUrl;
|
|
|
+ }
|
|
|
}
|