Browse Source

Merge remote-tracking branch 'remotes/origin/develop' into release_temp

dev_shibei_match
jianjun 4 years ago
parent
commit
adcc4de766
  1. 296
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java
  2. 47
      epmet-user/epmet-user-server/src/main/java/com/epmet/redis/IcResiUserRedis.java
  3. 60
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java
  4. 53
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java
  5. 183
      epmet-user/epmet-user-server/src/test/java/com/epmet/epmetuser/test/IcResiUserControllerTest.java

296
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java

@ -18,44 +18,35 @@
package com.epmet.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.export.ExcelExportService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.ExcelUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.commons.tools.validator.group.AddGroup;
import com.epmet.commons.tools.validator.group.DefaultGroup;
import com.epmet.commons.tools.validator.group.UpdateGroup;
import com.epmet.dto.IcResiUserDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.excel.IcResiUserExcel;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.OperCustomizeOpenFeignClient;
import com.epmet.service.IcResiUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
@ -69,7 +60,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@RestController
@RequestMapping("icresiuser")
public class IcResiUserController {
private static final String BASE_TABLE_NAME = "ic_resi_user";
private static final String BASE_TABLE_NAME = "ic_resi_user";
@Autowired
private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient;
@ -78,48 +69,6 @@ public class IcResiUserController {
@Autowired
private EpmetUserOpenFeignClient epmetUserOpenFeignClient;
@GetMapping("page")
public Result<PageData<IcResiUserDTO>> page(@RequestParam Map<String, Object> params){
PageData<IcResiUserDTO> page = icResiUserService.page(params);
return new Result<PageData<IcResiUserDTO>>().ok(page);
}
@GetMapping("{id}")
public Result<IcResiUserDTO> get(@PathVariable("id") String id){
IcResiUserDTO data = icResiUserService.get(id);
return new Result<IcResiUserDTO>().ok(data);
}
@PostMapping
public Result save(@RequestBody IcResiUserDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
icResiUserService.save(dto);
return new Result();
}
@PutMapping
public Result update(@RequestBody IcResiUserDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
icResiUserService.update(dto);
return new Result();
}
@PostMapping("delete")
public Result delete(@LoginUser TokenDto tokenDto,@RequestBody DelIcResiUserFormDTO formDTO){
formDTO.setCustomerId(tokenDto.getCustomerId());
ValidatorUtils.validateEntity(formDTO,DelIcResiUserFormDTO.IdGroup.class);
icResiUserService.delete(formDTO);
return new Result();
}
@GetMapping("export")
public void export(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
List<IcResiUserDTO> list = icResiUserService.list(params);
ExcelUtils.exportExcelToTarget(response, null, list, IcResiUserExcel.class);
}
/**
* @Author sun
* @Description 党建互联平台--保存居民信息
@ -140,157 +89,6 @@ public class IcResiUserController {
return new Result();
}
@GetMapping("download/template")
public void downloadTemplate(@RequestParam String customerId) throws Exception {
CustomerFormResultDTO resultForm = getResiFormItems(customerId);
XSSFWorkbook workbook = new XSSFWorkbook();
Map<String, List<ExcelExportEntity>> sheetHeaderMap = buildHeaderByItem(resultForm);
//Workbook workbook = null;
for (Map.Entry<String, List<ExcelExportEntity>> entry : sheetHeaderMap.entrySet()) {
String sheetName = entry.getKey();
List<ExcelExportEntity> headers = entry.getValue();
System.out.println("headers:"+sheetName+JSON.toJSONString(headers));
ExportParams exportParams = new ExportParams(null,sheetName);
//exportParams.setAutoSize(true);
List<Map<String,String>> dataSet = new ArrayList<>();
HashMap<String, String> map = new HashMap<>();
map.put("1","2");
dataSet.add(map);
new ExcelExportService().createSheetForMap(workbook, exportParams, headers, dataSet);
}
FileOutputStream fos = new FileOutputStream("//Users/liujianjun/Downloads/基础信息表/Dow.tt.xls");
workbook.write(fos);
fos.close();
}
@NotNull
private CustomerFormResultDTO getResiFormItems(String customerId) {
CustomerFormQueryDTO queryDTO = new CustomerFormQueryDTO();
queryDTO.setFormCode("resi_base_info");
queryDTO.setCustomerId(customerId);
Result<CustomerFormResultDTO> resultForm = operCustomizeOpenFeignClient.getCustomerForm(queryDTO);
if (resultForm == null || !resultForm.success() ||resultForm.getData() == null){
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
}
System.out.println(JSON.toJSONString(resultForm.getData()));
return resultForm.getData();
}
@NotNull
private Map<String,List<ExcelExportEntity>> buildHeaderByItem(CustomerFormResultDTO resultForm) {
//form中的itemlist 为一级表头 但是要排除每个item中含有childGroup的
List<FormItem> itemList = resultForm.getItemList();
List<FormGroupDTO> groupList = resultForm.getGroupList();
Map<String,List<ExcelExportEntity>> everySheetHeaderMap = new LinkedHashMap<>();
List<ExcelExportEntity> firstSheetHeaderList = new ArrayList<>();
//Map<String, String> groupNameMap = groupList.stream().collect(Collectors.toMap(FormGroupDTO::getGroupId,FormGroupDTO::getLabel));
itemList.forEach(item->{
if (StringUtils.isBlank(item.getColumnName())){
return;
}
if (item.getChildGroup() == null){
ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getColumnName().concat(String.valueOf(item.getColumnNum())),30);
header.setNeedMerge(true);
firstSheetHeaderList.add(header);
return;
}
everySheetHeaderMap.putIfAbsent(resultForm.getFormName(),firstSheetHeaderList);
//这些是动态的 formGroup
if (item.getChildGroup() != null){
//baseTableName单独的一个sheet
System.out.println("childGroup:"+item.getLabel());
if (BASE_TABLE_NAME.equals(item.getTableName())){
// header = new ExcelExportEntity(item.getChildGroup().getLabel(),item.getChildGroup().getTableName());
//header.setNeedMerge(true);
List<ExcelExportEntity> otherSheetHeaderList = new ArrayList<>();
//这里是设置除基础信息之外的sheet的表头
item.getChildGroup().getItemList().forEach(item2->{
if (!BASE_TABLE_NAME.equals(item2.getTableName())){
everySheetHeaderMap.putIfAbsent(item.getLabel(),otherSheetHeaderList);
}
ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum())));
otherSheetHeaderList.add(secondHeader);
if (!"radio".equals(item2.getItemType()) && CollectionUtils.isNotEmpty(item2.getOptions())){
secondHeader.setNeedMerge(true);
List<ExcelExportEntity> thirdHeaderList = new ArrayList<>();
item2.getOptions().forEach(child->{
ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel());
thirdHeaderList.add(thirdHeader);
});
secondHeader.setList(thirdHeaderList);
}
});
//header.setList(secondHeaderList);
//otherSheetHeaderList.add(header);
}
}
});
groupList.forEach(item->{
/* if (!"兴趣爱好".equals(item.getLabel()) && !"宗教信仰".equals(item.getLabel())){
return;
}*/
if (!BASE_TABLE_NAME.equals(item.getTableName())){
return;
}
ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getTableName());
header.setNeedMerge(true);
List<ExcelExportEntity> secondHeaderList = new ArrayList<>();
item.getItemList().forEach(item2->{
ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum())));
secondHeader.setNeedMerge(true);
secondHeaderList.add(secondHeader);
if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(item2.getOptions())){
List<ExcelExportEntity> thirdHeaderList = new ArrayList<>();
item2.getOptions().forEach(child->{
ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel(),child.getValue()+ new Random(1).nextInt(2));
thirdHeader.setNeedMerge(true);
thirdHeaderList.add(thirdHeader);
});
secondHeader.setList(thirdHeaderList);
}
});
header.setList(secondHeaderList);
firstSheetHeaderList.add(header);
System.out.println(JSON.toJSONString(firstSheetHeaderList));
});
return everySheetHeaderMap;
}
private void buildHeader(Map<String, List<ExcelExportEntity>> everySheetHeaderMap, FormItem item, ExcelExportEntity header) {
List<ExcelExportEntity> firstSheetHeaderList = new ArrayList<>();
List<ExcelExportEntity> secondHeaderList = new ArrayList<>();
item.getChildGroup().getItemList().forEach(item2->{
if (!BASE_TABLE_NAME.equals(item2.getTableName())){
everySheetHeaderMap.putIfAbsent(item.getLabel(),firstSheetHeaderList);
}
ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum())));
secondHeader.setNeedMerge(true);
secondHeaderList.add(secondHeader);
if (CollectionUtils.isNotEmpty(item2.getOptions())){
List<ExcelExportEntity> thirdHeaderList = new ArrayList<>();
item2.getOptions().forEach(child->{
ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel());
thirdHeaderList.add(thirdHeader);
});
secondHeader.setList(thirdHeaderList);
}
});
header.setList(secondHeaderList);
firstSheetHeaderList.add(header);
everySheetHeaderMap.putIfAbsent(item.getLabel(),firstSheetHeaderList);
}
/**
* @Description 根据房间号查人
* @Param formDTO
@ -304,32 +102,33 @@ public class IcResiUserController {
}
@PostMapping("listresi")
public Result<PageData<Map<String,Object>>> queryListResi1(@LoginUser TokenDto tokenDto, @RequestBody IcResiUserPageFormDTO pageFormDTO){
public Result<PageData<Map<String, Object>>> queryListResi1(@LoginUser TokenDto tokenDto, @RequestBody IcResiUserPageFormDTO pageFormDTO) {
//pageFormDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
pageFormDTO.setCustomerId(tokenDto.getCustomerId());
pageFormDTO.setStaffId(tokenDto.getUserId());
ValidatorUtils.validateEntity(pageFormDTO,IcResiUserPageFormDTO.AddUserInternalGroup.class);
return new Result<PageData<Map<String,Object>>>().ok(icResiUserService.pageResiMap(pageFormDTO));
ValidatorUtils.validateEntity(pageFormDTO, IcResiUserPageFormDTO.AddUserInternalGroup.class);
return new Result<PageData<Map<String, Object>>>().ok(icResiUserService.pageResiMap(pageFormDTO));
}
/**
* 编辑页面显示居民信息详情
*
* @param pageFormDTO
* @return com.epmet.commons.tools.utils.Result
* @return com.epmet.commons.tools.utils.Result
* @author yinzuomei
* @date 2021/10/28 10:29 上午
*/
@PostMapping("detail")
public Result queryIcResiDetail(@LoginUser TokenDto tokenDto,@RequestBody IcResiDetailFormDTO pageFormDTO){
public Result queryIcResiDetail(@LoginUser TokenDto tokenDto, @RequestBody IcResiDetailFormDTO pageFormDTO) {
//pageFormDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
pageFormDTO.setCustomerId(tokenDto.getCustomerId());
ValidatorUtils.validateEntity(pageFormDTO,IcResiDetailFormDTO.AddUserInternalGroup.class);
ValidatorUtils.validateEntity(pageFormDTO, IcResiDetailFormDTO.AddUserInternalGroup.class);
return new Result().ok(icResiUserService.queryIcResiDetail(pageFormDTO));
}
@RequestMapping(value = "/exportExcel")
public void exportExcel(/*@LoginUser TokenDto tokenDto,*/ @RequestBody IcResiUserPageFormDTO pageFormDTO, HttpServletResponse response) throws IOException {
pageFormDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
public void exportExcel(@RequestHeader String customerId, @RequestBody IcResiUserPageFormDTO pageFormDTO, HttpServletResponse response) throws IOException {
pageFormDTO.setCustomerId(customerId);
pageFormDTO.setPageFlag(false);
CustomerFormResultDTO resiFormItems = getResiFormItems(pageFormDTO.getCustomerId());
@ -337,25 +136,25 @@ public class IcResiUserController {
//主表的
for (FormItem formItem : resiFormItems.getItemList()) {
if (StringUtils.isBlank(formItem.getColumnName())){
if (StringUtils.isBlank(formItem.getColumnName())) {
continue;
}
Map<String, FormItem> itemMap = otherSheetItems.getOrDefault(formItem.getTableName(),new HashMap<>());
otherSheetItems.putIfAbsent(formItem.getTableName(),itemMap);
if (formItem.getItemType().equals("checkbox") || formItem.getItemType().equals("select") || formItem.getItemType().equals("radio")){
Map<String, FormItem> itemMap = otherSheetItems.getOrDefault(formItem.getTableName(), new HashMap<>());
otherSheetItems.putIfAbsent(formItem.getTableName(), itemMap);
if (formItem.getItemType().equals("checkbox") || formItem.getItemType().equals("select") || formItem.getItemType().equals("radio")) {
itemMap.put(formItem.getColumnName().concat(formItem.getColumnNum() == 0 ? "" : formItem.getColumnNum().toString()), formItem);
}
if (formItem.getChildGroup() != null) {
itemMap = otherSheetItems.getOrDefault(formItem.getChildGroup().getTableName(),new HashMap<>());
otherSheetItems.putIfAbsent(formItem.getChildGroup().getTableName(),itemMap);
itemMap = otherSheetItems.getOrDefault(formItem.getChildGroup().getTableName(), new HashMap<>());
otherSheetItems.putIfAbsent(formItem.getChildGroup().getTableName(), itemMap);
for (FormItem2 item2 : formItem.getChildGroup().getItemList()) {
if (StringUtils.isBlank(item2.getColumnName())){
if (StringUtils.isBlank(item2.getColumnName())) {
continue;
}
if (item2.getItemType().equals("checkbox") || item2.getItemType().equals("select") || item2.getItemType().equals("radio")){
itemMap.put(item2.getColumnName().concat(item2.getColumnNum() == 0 ? "" : item2.getColumnNum().toString()), ConvertUtils.sourceToTarget(item2,FormItem.class));
if (item2.getItemType().equals("checkbox") || item2.getItemType().equals("select") || item2.getItemType().equals("radio")) {
itemMap.put(item2.getColumnName().concat(item2.getColumnNum() == 0 ? "" : item2.getColumnNum().toString()), ConvertUtils.sourceToTarget(item2, FormItem.class));
}
}
@ -367,40 +166,40 @@ public class IcResiUserController {
if (groupItem.getItemList() == null) {
continue;
}
Map<String, FormItem> itemMap = otherSheetItems.getOrDefault(groupItem.getTableName(),new HashMap<>());
otherSheetItems.putIfAbsent(groupItem.getTableName(),itemMap);
Map<String, FormItem> itemMap = otherSheetItems.getOrDefault(groupItem.getTableName(), new HashMap<>());
otherSheetItems.putIfAbsent(groupItem.getTableName(), itemMap);
for (FormItem2 formItem2 : groupItem.getItemList()) {
if (StringUtils.isBlank(formItem2.getColumnName())) {
continue;
}
if (formItem2.getItemType().equals("checkbox") || formItem2.getItemType().equals("select")|| formItem2.getItemType().equals("radio")) {
if (formItem2.getItemType().equals("checkbox") || formItem2.getItemType().equals("select") || formItem2.getItemType().equals("radio")) {
itemMap.put(formItem2.getColumnName().concat(formItem2.getColumnNum() == 0 ? "" : formItem2.getColumnNum().toString()), ConvertUtils.sourceToTarget(formItem2, FormItem.class));
}
}
}
Map<String,Map<String, Object>> resiMainList = icResiUserService.getDataForExport(otherSheetItems.get(BASE_TABLE_NAME),pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), BASE_TABLE_NAME, pageFormDTO.getConditions());
Map<String, Map<String, Object>> resiMainList = icResiUserService.getDataForExport(otherSheetItems.get(BASE_TABLE_NAME), pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), BASE_TABLE_NAME, pageFormDTO.getConditions());
//resiMainList = (List<Map<String, Object>>)JSON.parse("[{\"IS_BDHJ\":\"1\",\"IS_SPECIAL\":\"1\",\"IS_XFRY\":\"0\",\"REMARKS\":\"beizhu\",\"IS_PARTY\":\"1\",\"icResiUserId\":\"yzmtest2\",\"HOME_ID\":\"中海国际社区一里城1号楼1单元101\",\"HOUSE_TYPE\":\"平房\",\"UNIT_NAME\":\"1单元\",\"GRID_ID\":\"市北区-市北区第三网格3\",\"IS_DB\":\"0\",\"GENDER\":\"男\",\"BIRTHDAY\":\"2021-10-04\",\"IS_VETERANS\":\"0\",\"IS_MB\":\"0\",\"IS_UNEMPLOYED\":\"0\",\"DEMAND_NAME\":null,\"IS_KC\":\"0\",\"IS_ENSURE_HOUSE\":\"0\",\"IS_SD\":\"0\",\"NAME\":\"尹作梅\",\"RDSJ\":null,\"IS_VOLUNTEER\":\"1\",\"GRID_ID_VALUE\":\"e74829ffc43d5470eba6b5e060c11e63\",\"IS_SZ\":\"0\",\"IS_CJ\":\"0\",\"HOME_ID_VALUE\":\"200\",\"DEMAND_CATEGORY_IDS\":null,\"VILLAGE_NAME\":\"中海国际社区一里城\",\"IS_DBH\":\"0\",\"IS_SN\":\"0\",\"BUILD_NAME\":\"1号楼\",\"IS_YLFN\":\"0\",\"IS_UNITED_FRONT\":\"0\",\"ID_CARD\":\"371325199310260529\",\"MOBILE\":\"15764229697\",\"IS_OLD_PEOPLE\":\"0\",\"DOOR_NAME\":\"101\"},{\"IS_SPECIAL\":\"1\",\"IS_XFRY\":\"0\",\"REMARKS\":\"beizhu\",\"IS_PARTY\":\"1\",\"icResiUserId\":\"yzmtest\",\"HOME_ID\":\"中海国际社区一里城1号楼1单元101\",\"HOUSE_TYPE\":\"平房\",\"UNIT_NAME\":\"1单元\",\"GRID_ID\":\"市北区-市北区第三网格3\",\"IS_DB\":\"0\",\"GENDER\":\"男\",\"BIRTHDAY\":\"2021-10-04\",\"IS_VETERANS\":\"0\",\"IS_MB\":\"0\",\"IS_UNEMPLOYED\":\"0\",\"DEMAND_NAME\":\"心理咨询\",\"IS_KC\":\"0\",\"IS_ENSURE_HOUSE\":\"0\",\"IS_SD\":\"0\",\"NAME\":\"尹作梅\",\"RDSJ\":\"2021-10-28 00:00:00\",\"IS_VOLUNTEER\":\"1\",\"GRID_ID_VALUE\":\"e74829ffc43d5470eba6b5e060c11e63\",\"IS_SZ\":\"0\",\"IS_CJ\":\"0\",\"HOME_ID_VALUE\":\"200\",\"DEMAND_CATEGORY_IDS\":\"10180002\",\"VILLAGE_NAME\":\"中海国际社区一里城\",\"IS_DBH\":\"0\",\"IS_SN\":\"0\",\"BUILD_NAME\":\"1号楼\",\"IS_YLFN\":\"0\",\"IS_UNITED_FRONT\":\"0\",\"ID_CARD\":\"371325199310260529\",\"MOBILE\":\"15764229697\",\"IS_OLD_PEOPLE\":\"0\",\"DOOR_NAME\":\"101\"}]");
log.info("resiMainList:{}", JSON.toJSONString(resiMainList));
String templatePath = "excel/ic_resi_info_cid.xls";
TemplateExportParams params = new TemplateExportParams(templatePath,true);
TemplateExportParams params = new TemplateExportParams(templatePath, true);
Map<Integer,Map<String,Object>> sheetMap = new HashMap<>();
Map<Integer, Map<String, Object>> sheetMap = new HashMap<>();
Map<String, Object> mapData = new HashMap<>();
mapData.put("list", resiMainList.values());
sheetMap.put(0,mapData);
sheetMap.put(0, mapData);
AtomicInteger n = new AtomicInteger();
for (FormItem item : resiFormItems.getItemList()) {
if (item.getChildGroup() != null) {
if (!item.getChildGroup().getTableName().equals(BASE_TABLE_NAME)) {
Map<String, FormItem> itemMap1 = otherSheetItems.get(item.getChildGroup().getTableName());
Map<String,Map<String, Object>> resiChildMap = icResiUserService.getDataForExport(itemMap1, pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), item.getChildGroup().getTableName(), pageFormDTO.getConditions());
resiChildMap.forEach((key,value)-> value.putAll(resiMainList.get(key)));
Map<String, Map<String, Object>> resiChildMap = icResiUserService.getDataForExport(itemMap1, pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), item.getChildGroup().getTableName(), pageFormDTO.getConditions());
resiChildMap.forEach((key, value) -> value.putAll(resiMainList.get(key)));
Map<String, Object> mapData2 = new HashMap<>();
mapData2.put("list", resiChildMap.values());
sheetMap.put(n.incrementAndGet(),mapData2);
sheetMap.put(n.incrementAndGet(), mapData2);
}
}
}
@ -408,8 +207,7 @@ public class IcResiUserController {
Workbook workbook = ExcelExportUtil.exportExcel(sheetMap, params);
workbook.setActiveSheet(0);
//header
String fileName = "居民信息.xls";
String fileName = "居民基本信息.xls";
response.setHeader("content-Type", "application/vnd.ms-excel");
response.addHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(fileName, "UTF-8"));
workbook.write(response.getOutputStream());
@ -417,6 +215,7 @@ public class IcResiUserController {
/**
* excel导入居民基本信息
*
* @param loginUser
* @return
*/
@ -435,37 +234,50 @@ public class IcResiUserController {
}
@PostMapping("test")
public Result<List<Map<String,Object>>> test(@RequestBody DynamicQueryFormDTO formDTO){
public Result<List<Map<String, Object>>> test(@RequestBody DynamicQueryFormDTO formDTO) {
formDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
//formDTO.setCustomerId(tokenDto.getCustomerId());
return new Result<List<Map<String,Object>>>().ok(icResiUserService.dynamicQuery(formDTO.getCustomerId(),
return new Result<List<Map<String, Object>>>().ok(icResiUserService.dynamicQuery(formDTO.getCustomerId(),
formDTO.getFormCode(),
formDTO.getResultTableName(),
formDTO.getConditions()));
}
/**
* @Description 查询个人数据
* @param formDTO
* @Description 查询个人数据
* @author zxc
* @date 2021/11/3 9:21 上午
*/
@PostMapping("persondata")
public Result<PersonDataResultDTO> personData(@RequestBody PersonDataFormDTO formDTO){
public Result<PersonDataResultDTO> personData(@RequestBody PersonDataFormDTO formDTO) {
return new Result<PersonDataResultDTO>().ok(icResiUserService.personData(formDTO));
}
/**
* @Description 根据名字搜索
* @param formDTO
* @param tokenDto
* @Description 根据名字搜索
* @author zxc
* @date 2021/11/3 1:42 下午
*/
@PostMapping("searchbyname")
public Result<List<SearchByNameResultDTO>> searchByName(@RequestBody SearchByNameFormDTO formDTO, @LoginUser TokenDto tokenDto){
public Result<List<SearchByNameResultDTO>> searchByName(@RequestBody SearchByNameFormDTO formDTO, @LoginUser TokenDto tokenDto) {
ValidatorUtils.validateEntity(formDTO, SearchByNameFormDTO.SearchByNameForm.class);
return new Result<List<SearchByNameResultDTO>>().ok(icResiUserService.searchByName(formDTO,tokenDto));
return new Result<List<SearchByNameResultDTO>>().ok(icResiUserService.searchByName(formDTO, tokenDto));
}
@NotNull
private CustomerFormResultDTO getResiFormItems(String customerId) {
CustomerFormQueryDTO queryDTO = new CustomerFormQueryDTO();
queryDTO.setFormCode("resi_base_info");
queryDTO.setCustomerId(customerId);
Result<CustomerFormResultDTO> resultForm = operCustomizeOpenFeignClient.getCustomerForm(queryDTO);
if (resultForm == null || !resultForm.success() || resultForm.getData() == null) {
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
}
System.out.println(JSON.toJSONString(resultForm.getData()));
return resultForm.getData();
}
}

47
epmet-user/epmet-user-server/src/main/java/com/epmet/redis/IcResiUserRedis.java

@ -1,47 +0,0 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.redis;
import com.epmet.commons.tools.redis.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* 用户基础信息
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-10-26
*/
@Component
public class IcResiUserRedis {
@Autowired
private RedisUtils redisUtils;
public void delete(Object[] ids) {
}
public void set(){
}
public String get(String id){
return null;
}
}

60
epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java

@ -20,7 +20,6 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
import com.epmet.dto.IcResiUserDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.FormItem;
import com.epmet.dto.result.HomeUserResultDTO;
@ -39,65 +38,6 @@ import java.util.Map;
*/
public interface IcResiUserService extends BaseService<IcResiUserEntity> {
/**
* 默认分页
*
* @param params
* @return PageData<IcResiUserDTO>
* @author generator
* @date 2021-10-26
*/
PageData<IcResiUserDTO> page(Map<String, Object> params);
/**
* 默认查询
*
* @param params
* @return java.util.List<IcResiUserDTO>
* @author generator
* @date 2021-10-26
*/
List<IcResiUserDTO> list(Map<String, Object> params);
/**
* 单条查询
*
* @param id
* @return IcResiUserDTO
* @author generator
* @date 2021-10-26
*/
IcResiUserDTO get(String id);
/**
* 默认保存
*
* @param dto
* @return void
* @author generator
* @date 2021-10-26
*/
void save(IcResiUserDTO dto);
/**
* 默认更新
*
* @param dto
* @return void
* @author generator
* @date 2021-10-26
*/
void update(IcResiUserDTO dto);
/**
* 单个删除
*
* @return void
* @author generator
* @date 2021-10-26
*/
void delete(DelIcResiUserFormDTO formDTO);
/**
* @Author sun
* @Description 党建互联平台--保存居民信息

53
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java

@ -21,7 +21,6 @@ import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
@ -51,7 +50,6 @@ import com.epmet.feign.EpmetAdminOpenFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.GovOrgOpenFeignClient;
import com.epmet.feign.OperCustomizeOpenFeignClient;
import com.epmet.redis.IcResiUserRedis;
import com.epmet.service.IcResiUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@ -79,9 +77,6 @@ import java.util.stream.Collectors;
@Slf4j
@Service
public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResiUserEntity> implements IcResiUserService, ResultDataResolver {
private final Logger logger = LogManager.getLogger(IcResiUserServiceImpl.class);
@Autowired
private IcResiUserRedis icResiUserRedis;
@Autowired
private GovOrgOpenFeignClient govOrgOpenFeignClient;
@Autowired
@ -96,21 +91,7 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
@Autowired
private LoginUserUtil loginUserUtil;
@Override
public PageData<IcResiUserDTO> page(Map<String, Object> params) {
IPage<IcResiUserEntity> page = baseDao.selectPage(
getPage(params, FieldConstant.CREATED_TIME, false),
getWrapper(params)
);
return getPageData(page, IcResiUserDTO.class);
}
@Override
public List<IcResiUserDTO> list(Map<String, Object> params) {
List<IcResiUserEntity> entityList = baseDao.selectList(getWrapper(params));
return ConvertUtils.sourceToTarget(entityList, IcResiUserDTO.class);
}
private QueryWrapper<IcResiUserEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get(FieldConstant.ID_HUMP);
@ -121,39 +102,6 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
return wrapper;
}
@Override
public IcResiUserDTO get(String id) {
IcResiUserEntity entity = baseDao.selectById(id);
return ConvertUtils.sourceToTarget(entity, IcResiUserDTO.class);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void save(IcResiUserDTO dto) {
IcResiUserEntity entity = ConvertUtils.sourceToTarget(dto, IcResiUserEntity.class);
insert(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(IcResiUserDTO dto) {
IcResiUserEntity entity = ConvertUtils.sourceToTarget(dto, IcResiUserEntity.class);
updateById(entity);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(DelIcResiUserFormDTO formDTO) {
baseDao.updateToDel(formDTO.getIcResiUserId());
CustomerFormQueryDTO queryDTO = ConvertUtils.sourceToTarget(formDTO, CustomerFormQueryDTO.class);
Result<Set<String>> subTableRes = operCustomizeOpenFeignClient.queryIcResiSubTables(queryDTO);
if (subTableRes.success() && !CollectionUtils.isEmpty(subTableRes.getData())) {
for (String subTalbeName : subTableRes.getData()) {
baseDao.updateSubTableToDel(subTalbeName, formDTO.getIcResiUserId());
}
}
}
/**
* @Author sun
* @Description 党建互联平台--保存居民信息
@ -1099,7 +1047,6 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
@Override
public Map<String, Map<String, Object>> getDataForExport(Map<String, FormItem> formItemMap, String customerId, String formCode, String baseTableName, List<ResiUserQueryValueDTO> conditions) {
List<Map<String, Object>> mapList = this.dynamicQuery(customerId, formCode, baseTableName, conditions);
System.out.println("======remote:"+baseTableName+" "+JSON.toJSONString(formItemMap));
Map<String, Map<String, Object>> result = new LinkedHashMap<>();
mapList.stream().filter(Objects::nonNull).forEach(map -> {
String resiId = (String) map.getOrDefault(UserConstant.IC_RESI_USER, "");

183
epmet-user/epmet-user-server/src/test/java/com/epmet/epmetuser/test/IcResiUserControllerTest.java

@ -0,0 +1,183 @@
package com.epmet.epmetuser.test;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.export.ExcelExportService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.CustomerFormQueryDTO;
import com.epmet.dto.result.CustomerFormResultDTO;
import com.epmet.dto.result.FormGroupDTO;
import com.epmet.dto.result.FormItem;
import com.epmet.feign.OperCustomizeOpenFeignClient;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestParam;
import java.io.FileOutputStream;
import java.util.*;
@SpringBootTest
@RunWith(SpringRunner.class)
public class IcResiUserControllerTest {
private static final String BASE_TABLE_NAME = "BASE_TABLE_NAME";
@Autowired
private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient;
@Test
public void downloadTemplate(@RequestParam String customerId) throws Exception {
CustomerFormResultDTO resultForm = getResiFormItems(customerId);
XSSFWorkbook workbook = new XSSFWorkbook();
Map<String, List<ExcelExportEntity>> sheetHeaderMap = buildHeaderByItem(resultForm);
//Workbook workbook = null;
for (Map.Entry<String, List<ExcelExportEntity>> entry : sheetHeaderMap.entrySet()) {
String sheetName = entry.getKey();
List<ExcelExportEntity> headers = entry.getValue();
System.out.println("headers:"+sheetName+JSON.toJSONString(headers));
ExportParams exportParams = new ExportParams(null,sheetName);
//exportParams.setAutoSize(true);
List<Map<String,String>> dataSet = new ArrayList<>();
HashMap<String, String> map = new HashMap<>();
map.put("1","2");
dataSet.add(map);
new ExcelExportService().createSheetForMap(workbook, exportParams, headers, dataSet);
}
FileOutputStream fos = new FileOutputStream("//Users/liujianjun/Downloads/基础信息表/Dow.tt.xls");
workbook.write(fos);
fos.close();
}
@NotNull
private CustomerFormResultDTO getResiFormItems(String customerId) {
CustomerFormQueryDTO queryDTO = new CustomerFormQueryDTO();
queryDTO.setFormCode("resi_base_info");
queryDTO.setCustomerId(customerId);
Result<CustomerFormResultDTO> resultForm = operCustomizeOpenFeignClient.getCustomerForm(queryDTO);
if (resultForm == null || !resultForm.success() ||resultForm.getData() == null){
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode());
}
System.out.println(JSON.toJSONString(resultForm.getData()));
return resultForm.getData();
}
@NotNull
private Map<String,List<ExcelExportEntity>> buildHeaderByItem(CustomerFormResultDTO resultForm) {
//form中的itemlist 为一级表头 但是要排除每个item中含有childGroup的
List<FormItem> itemList = resultForm.getItemList();
List<FormGroupDTO> groupList = resultForm.getGroupList();
Map<String,List<ExcelExportEntity>> everySheetHeaderMap = new LinkedHashMap<>();
List<ExcelExportEntity> firstSheetHeaderList = new ArrayList<>();
//Map<String, String> groupNameMap = groupList.stream().collect(Collectors.toMap(FormGroupDTO::getGroupId,FormGroupDTO::getLabel));
itemList.forEach(item->{
if (StringUtils.isBlank(item.getColumnName())){
return;
}
if (item.getChildGroup() == null){
ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getColumnName().concat(String.valueOf(item.getColumnNum())),30);
header.setNeedMerge(true);
firstSheetHeaderList.add(header);
return;
}
everySheetHeaderMap.putIfAbsent(resultForm.getFormName(),firstSheetHeaderList);
//这些是动态的 formGroup
if (item.getChildGroup() != null){
//baseTableName单独的一个sheet
System.out.println("childGroup:"+item.getLabel());
if (BASE_TABLE_NAME.equals(item.getTableName())){
List<ExcelExportEntity> otherSheetHeaderList = new ArrayList<>();
//这里是设置除基础信息之外的sheet的表头
item.getChildGroup().getItemList().forEach(item2->{
if (!BASE_TABLE_NAME.equals(item2.getTableName())){
everySheetHeaderMap.putIfAbsent(item.getLabel(),otherSheetHeaderList);
}
ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum())));
otherSheetHeaderList.add(secondHeader);
if (!"radio".equals(item2.getItemType()) && CollectionUtils.isNotEmpty(item2.getOptions())){
secondHeader.setNeedMerge(true);
List<ExcelExportEntity> thirdHeaderList = new ArrayList<>();
item2.getOptions().forEach(child->{
ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel());
thirdHeaderList.add(thirdHeader);
});
secondHeader.setList(thirdHeaderList);
}
});
}
}
});
groupList.forEach(item->{
/* if (!"兴趣爱好".equals(item.getLabel()) && !"宗教信仰".equals(item.getLabel())){
return;
}*/
if (!BASE_TABLE_NAME.equals(item.getTableName())){
return;
}
ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getTableName());
header.setNeedMerge(true);
List<ExcelExportEntity> secondHeaderList = new ArrayList<>();
item.getItemList().forEach(item2->{
ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum())));
secondHeader.setNeedMerge(true);
secondHeaderList.add(secondHeader);
if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(item2.getOptions())){
List<ExcelExportEntity> thirdHeaderList = new ArrayList<>();
item2.getOptions().forEach(child->{
ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel(),child.getValue()+ new Random(1).nextInt(2));
thirdHeader.setNeedMerge(true);
thirdHeaderList.add(thirdHeader);
});
secondHeader.setList(thirdHeaderList);
}
});
header.setList(secondHeaderList);
firstSheetHeaderList.add(header);
System.out.println(JSON.toJSONString(firstSheetHeaderList));
});
return everySheetHeaderMap;
}
private void buildHeader(Map<String, List<ExcelExportEntity>> everySheetHeaderMap, FormItem item, ExcelExportEntity header) {
List<ExcelExportEntity> firstSheetHeaderList = new ArrayList<>();
List<ExcelExportEntity> secondHeaderList = new ArrayList<>();
item.getChildGroup().getItemList().forEach(item2->{
if (!BASE_TABLE_NAME.equals(item2.getTableName())){
everySheetHeaderMap.putIfAbsent(item.getLabel(),firstSheetHeaderList);
}
ExcelExportEntity secondHeader = new ExcelExportEntity(item2.getLabel(),item2.getColumnName().concat(String.valueOf(item2.getColumnNum())));
secondHeader.setNeedMerge(true);
secondHeaderList.add(secondHeader);
if (CollectionUtils.isNotEmpty(item2.getOptions())){
List<ExcelExportEntity> thirdHeaderList = new ArrayList<>();
item2.getOptions().forEach(child->{
ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel());
thirdHeaderList.add(thirdHeader);
});
secondHeader.setList(thirdHeaderList);
}
});
header.setList(secondHeaderList);
firstSheetHeaderList.add(header);
everySheetHeaderMap.putIfAbsent(item.getLabel(),firstSheetHeaderList);
}
}
Loading…
Cancel
Save