新增市县通讯录导入导出接口
parent
7440532d64
commit
6845a14cd5
|
|
@ -2,6 +2,7 @@ package com.whdc.controller;
|
||||||
|
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.whdc.exception.MyException;
|
import com.whdc.exception.MyException;
|
||||||
|
|
@ -17,6 +18,7 @@ import com.whdc.model.group.Update;
|
||||||
import com.whdc.model.vo.AdcdTree;
|
import com.whdc.model.vo.AdcdTree;
|
||||||
import com.whdc.model.vo.AddressBookVo;
|
import com.whdc.model.vo.AddressBookVo;
|
||||||
import com.whdc.model.vo.ExcelABVo;
|
import com.whdc.model.vo.ExcelABVo;
|
||||||
|
import com.whdc.model.vo.ExcelDataVo;
|
||||||
import com.whdc.service.*;
|
import com.whdc.service.*;
|
||||||
import com.whdc.utils.ExcelCommon;
|
import com.whdc.utils.ExcelCommon;
|
||||||
import com.whdc.utils.ResultJson;
|
import com.whdc.utils.ResultJson;
|
||||||
|
|
@ -39,6 +41,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -57,6 +60,7 @@ import static com.whdc.service.impl.AdinfoServiceImpl.TREE_ALL;
|
||||||
public class AddressBookController {
|
public class AddressBookController {
|
||||||
|
|
||||||
public static final String ADDRESS_BOOK_REDIS_KEY = REDIS_KEY + "addressbook";
|
public static final String ADDRESS_BOOK_REDIS_KEY = REDIS_KEY + "addressbook";
|
||||||
|
public static final String ADDRESS_BOOK_TEMP_REDIS_KEY = ADDRESS_BOOK_REDIS_KEY + "temp:";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IAddressBookService service;
|
private IAddressBookService service;
|
||||||
|
|
@ -77,7 +81,7 @@ public class AddressBookController {
|
||||||
private IAbUdRService abUdRService;
|
private IAbUdRService abUdRService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisTemplate redisTemplate;
|
private RedisTemplate<String,String> redisTemplate;
|
||||||
|
|
||||||
|
|
||||||
// @ApiOperation(value = "查询所有")
|
// @ApiOperation(value = "查询所有")
|
||||||
|
|
@ -533,6 +537,73 @@ public class AddressBookController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation(value = "查询行政区划联系人")
|
||||||
|
@GetMapping(value = "getAdcdUser")
|
||||||
|
public ResultJson<List<ExcelABVo>> getAdcdUser() {
|
||||||
|
|
||||||
|
List<AdcdTree> tree = adinfoService.tree(TREE_ALL, TREE_ALL);
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(tree)) {
|
||||||
|
throw new MyException("当前行政区划不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// List<AddressBook> addressBooks = service.lambdaQuery().isNotNull(AddressBook::getAdcd)
|
||||||
|
// .list();
|
||||||
|
List<AddressBook> addressBooks = service.lambdaQuery().likeLeft(AddressBook::getAdcd, "000000000")
|
||||||
|
.list();
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(addressBooks)) {
|
||||||
|
throw new MyException("行政区划责任人为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, List<AddressBook>> abMap = addressBooks.stream().collect(Collectors.groupingBy(AddressBook::getAdcd, Collectors.toList()));
|
||||||
|
|
||||||
|
// 行政区划责任人数据
|
||||||
|
List<ExcelABVo> data = Lists.newArrayList();
|
||||||
|
|
||||||
|
for (int i = 0; i < tree.size(); i++) {
|
||||||
|
AdcdTree t = tree.get(i);
|
||||||
|
// String adcd = t.getAdcd();
|
||||||
|
String cityAdnm = t.getAdnm();
|
||||||
|
// List<AddressBook> books = abMap.get(adcd);
|
||||||
|
// if (CollectionUtils.isEmpty(books)) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// books.forEach(b -> {
|
||||||
|
// if (StringUtils.isNotBlank(finalAdnm)) {
|
||||||
|
// if (cityAdnm.equals(finalAdnm)) {
|
||||||
|
// data.add(new ExcelABVo(cityAdnm, cityAdnm, b.getName(), b.getPosition(), b.getPhone()));
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// data.add(new ExcelABVo(cityAdnm, cityAdnm, b.getName(), b.getPosition(), b.getPhone()));
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
List<AdcdTree> children = t.getChildren();
|
||||||
|
if (CollectionUtils.isNotEmpty(children)) {
|
||||||
|
for (int i1 = 1; i1 < children.size(); i1++) {
|
||||||
|
AdcdTree tc = children.get(i1);
|
||||||
|
String tcAdcd = tc.getAdcd();
|
||||||
|
String tcCityAdnm = tc.getAdnm();
|
||||||
|
List<AddressBook> tcBooks = abMap.get(tcAdcd);
|
||||||
|
if (CollectionUtils.isEmpty(tcBooks)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tcBooks.forEach(b -> {
|
||||||
|
data.add(new ExcelABVo(cityAdnm, tcCityAdnm, b.getName(), b.getPosition(), b.getPhone()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CollectionUtils.isEmpty(data)) {
|
||||||
|
throw new MyException("当前行政区划责任人为空");
|
||||||
|
}
|
||||||
|
return ResultJson.ok(data);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "通过行政区划下载excel")
|
@ApiOperation(value = "通过行政区划下载excel")
|
||||||
@GetMapping(value = "getExcel/{adnm}")
|
@GetMapping(value = "getExcel/{adnm}")
|
||||||
public void getExcel(@PathVariable("adnm")
|
public void getExcel(@PathVariable("adnm")
|
||||||
|
|
@ -612,22 +683,36 @@ public class AddressBookController {
|
||||||
}
|
}
|
||||||
|
|
||||||
ExcelCommon.exportExcel(data,
|
ExcelCommon.exportExcel(data,
|
||||||
null, "防汛抗旱通讯录", ExcelABVo.class, "防汛抗旱通讯录_" + adnm + "_" + LocalDateTime.now() + ".xlsx",
|
null, "防汛抗旱通讯录", ExcelABVo.class, "防汛抗旱通讯录_" + LocalDateTime.now() + ".xlsx",
|
||||||
response);
|
response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "解析文件数据")
|
@ApiOperation(value = "解析文件数据")
|
||||||
@PostMapping(value = "getExcelData")
|
@PostMapping(value = "getExcelData")
|
||||||
public ResultJson<List<ExcelABVo>> getExcelData(MultipartFile file) {
|
public ResultJson<ExcelDataVo> getExcelData(MultipartFile file) {
|
||||||
|
|
||||||
List<ExcelABVo> appends = ExcelCommon.importExcel(file, 0, 1, ExcelABVo.class);
|
List<ExcelABVo> appends = ExcelCommon.importExcel(file, 0, 1, ExcelABVo.class);
|
||||||
return ResultJson.ok(appends);
|
|
||||||
|
ExcelDataVo excelDataVo = new ExcelDataVo();
|
||||||
|
excelDataVo.setList(appends);
|
||||||
|
if (CollectionUtils.isNotEmpty(appends)){
|
||||||
|
String key = UUID.randomUUID().toString().replaceAll("-", "");
|
||||||
|
redisTemplate.opsForValue().set(ADDRESS_BOOK_TEMP_REDIS_KEY + key, JSON.toJSONString(appends), 30, TimeUnit.MINUTES);
|
||||||
|
excelDataVo.setKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResultJson.ok(excelDataVo);
|
||||||
}
|
}
|
||||||
@ApiOperation(value = "行政区划联系人导入")
|
@ApiOperation(value = "行政区划联系人导入")
|
||||||
@PostMapping(value = "uploadExcel")
|
@PostMapping(value = "uploadExcel")
|
||||||
public ResultJson uploadExcel(MultipartFile file) {
|
public ResultJson uploadExcel(@RequestBody ExcelDataVo data) {
|
||||||
|
|
||||||
List<ExcelABVo> appends = ExcelCommon.importExcel(file, 0, 1, ExcelABVo.class);
|
// List<ExcelABVo> appends = ExcelCommon.importExcel(file, 0, 1, ExcelABVo.class);
|
||||||
|
String s = redisTemplate.opsForValue().get(ADDRESS_BOOK_TEMP_REDIS_KEY + data.getKey());
|
||||||
|
if (StringUtils.isBlank(s)){
|
||||||
|
throw new MyException("文件已过期");
|
||||||
|
}
|
||||||
|
List<ExcelABVo> appends = JSON.parseArray(s, ExcelABVo.class);
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(appends)) {
|
if (CollectionUtils.isEmpty(appends)) {
|
||||||
throw new MyException("文件为空");
|
throw new MyException("文件为空");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.whdc.model.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description:
|
||||||
|
* Created by XuSan on 2024/5/28.
|
||||||
|
*
|
||||||
|
* @author XuSan
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ExcelDataVo {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "数据")
|
||||||
|
private List<ExcelABVo> list;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "键")
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -52,6 +52,7 @@ public class ExcelCommon {
|
||||||
response.setHeader("content-Type", "application/vnd.ms-excel");
|
response.setHeader("content-Type", "application/vnd.ms-excel");
|
||||||
response.setHeader("Content-Disposition",
|
response.setHeader("Content-Disposition",
|
||||||
"attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
"attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||||
|
// "attachment;filename=" + URLEncoder.encode(fileName, "iso8859-1"));
|
||||||
workbook.write(response.getOutputStream());
|
workbook.write(response.getOutputStream());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue