通过行政区划下载excel新增
parent
497a655ee8
commit
8efc4678c4
|
|
@ -3,11 +3,9 @@ package com.whdc.controller;
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.whdc.exception.MyException;
|
||||||
import com.whdc.model.dto.AddressBootDto;
|
import com.whdc.model.dto.AddressBootDto;
|
||||||
import com.whdc.model.entity.AbUdR;
|
import com.whdc.model.entity.*;
|
||||||
import com.whdc.model.entity.AddressBook;
|
|
||||||
import com.whdc.model.entity.Organization;
|
|
||||||
import com.whdc.model.entity.User;
|
|
||||||
import com.whdc.model.enums.Role;
|
import com.whdc.model.enums.Role;
|
||||||
import com.whdc.model.enums.VersionsType;
|
import com.whdc.model.enums.VersionsType;
|
||||||
import com.whdc.model.group.Insert;
|
import com.whdc.model.group.Insert;
|
||||||
|
|
@ -429,22 +427,26 @@ public class AddressBookController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "通过行政区划下载excel")
|
@ApiOperation(value = "通过行政区划下载excel")
|
||||||
@GetMapping(value = "getExcel/{adnm}")
|
@GetMapping(value = "getExcel/{adnm}")
|
||||||
public ResultJson getExcel(@PathVariable("adnm") String adnm, HttpServletResponse response) {
|
public void getExcel(@PathVariable("adnm") String adnm, HttpServletResponse response) {
|
||||||
|
|
||||||
List<AdcdTree> tree = adinfoService.tree(adnm, adnm);
|
// 查询全部标识
|
||||||
|
if ("all".equals(adnm)) {
|
||||||
|
adnm = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(tree)){
|
List<AdcdTree> tree = adinfoService.tree(null, null);
|
||||||
return ResultJson.error("当前行政区划不存在");
|
|
||||||
|
if (CollectionUtils.isEmpty(tree)) {
|
||||||
|
throw new MyException("当前行政区划不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<AddressBook> addressBooks = service.lambdaQuery().isNotNull(AddressBook::getAdcd)
|
List<AddressBook> addressBooks = service.lambdaQuery().isNotNull(AddressBook::getAdcd)
|
||||||
.list();
|
.list();
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(addressBooks)) {
|
if (CollectionUtils.isEmpty(addressBooks)) {
|
||||||
return ResultJson.error("行政区划责任人为空");
|
throw new MyException("行政区划责任人为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, List<AddressBook>> abMap = addressBooks.stream().collect(Collectors.groupingBy(AddressBook::getAdcd, Collectors.toList()));
|
Map<String, List<AddressBook>> abMap = addressBooks.stream().collect(Collectors.groupingBy(AddressBook::getAdcd, Collectors.toList()));
|
||||||
|
|
@ -452,32 +454,56 @@ public class AddressBookController {
|
||||||
// 行政区划责任人数据
|
// 行政区划责任人数据
|
||||||
List<ExcelABVo> data = Lists.newArrayList();
|
List<ExcelABVo> data = Lists.newArrayList();
|
||||||
|
|
||||||
tree.forEach(t ->{
|
String finalAdnm = adnm;
|
||||||
|
for (int i = 0; i < tree.size(); i++) {
|
||||||
|
AdcdTree t = tree.get(i);
|
||||||
String adcd = t.getAdcd();
|
String adcd = t.getAdcd();
|
||||||
String cityAdnm = t.getAdnm();
|
String cityAdnm = t.getAdnm();
|
||||||
List<AddressBook> books = abMap.get(adcd);
|
List<AddressBook> books = abMap.get(adcd);
|
||||||
books.forEach(b ->{
|
if (CollectionUtils.isEmpty(books)) {
|
||||||
data.add(new ExcelABVo(cityAdnm,cityAdnm,b.getName(),b.getPosition(),b.getPhone()));
|
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()));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
t.getChildren().forEach(tc ->{
|
List<AdcdTree> children = t.getChildren();
|
||||||
String tcAdcd = tc.getAdcd();
|
if (CollectionUtils.isNotEmpty(children)) {
|
||||||
String tcCityAdnm = tc.getAdnm();
|
for (int i1 = 1; i1 < children.size(); i1++) {
|
||||||
List<AddressBook> tcBooks = abMap.get(tcAdcd);
|
AdcdTree tc = children.get(i1);
|
||||||
books.forEach(b ->{
|
String tcAdcd = tc.getAdcd();
|
||||||
data.add(new ExcelABVo(cityAdnm,tcCityAdnm,b.getName(),b.getPosition(),b.getPhone()));
|
String tcCityAdnm = tc.getAdnm();
|
||||||
});
|
List<AddressBook> tcBooks = abMap.get(tcAdcd);
|
||||||
});
|
if (CollectionUtils.isEmpty(tcBooks)) {
|
||||||
});
|
continue;
|
||||||
|
}
|
||||||
|
tcBooks.forEach(b -> {
|
||||||
|
if (StringUtils.isNotBlank(finalAdnm)) {
|
||||||
|
if (cityAdnm.equals(finalAdnm) || tcCityAdnm.equals(finalAdnm)) {
|
||||||
|
data.add(new ExcelABVo(cityAdnm, tcCityAdnm, b.getName(), b.getPosition(), b.getPhone()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
data.add(new ExcelABVo(cityAdnm, tcCityAdnm, b.getName(), b.getPosition(), b.getPhone()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
if (CollectionUtils.isEmpty(data)) {
|
if (CollectionUtils.isEmpty(data)) {
|
||||||
return ResultJson.error("当前行政区划责任人为空");
|
throw new MyException("当前行政区划责任人为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
ExcelCommon.exportExcel(data,
|
ExcelCommon.exportExcel(data,
|
||||||
"防汛抗旱通讯录", "防汛抗旱通讯录", ExcelABVo.class, "防汛抗旱通讯录_"+ adnm +"_" + LocalDateTime.now() + ".xlsx",
|
"防汛抗旱通讯录", "防汛抗旱通讯录", ExcelABVo.class, "防汛抗旱通讯录_" + adnm + "_" + LocalDateTime.now() + ".xlsx",
|
||||||
response);
|
response);
|
||||||
return ResultJson.ok("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue