日照智慧社区接口服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

366 lines
18 KiB

4 years ago
/**
* 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.controller;
4 years ago
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
4 years ago
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
4 years ago
import cn.afterturn.easypoi.excel.export.ExcelExportService;
4 years ago
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
4 years ago
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.RenException;
4 years ago
import com.epmet.commons.tools.page.PageData;
4 years ago
import com.epmet.commons.tools.security.dto.TokenDto;
4 years ago
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;
4 years ago
import com.epmet.dto.IcResiUserDTO;
4 years ago
import com.epmet.dto.form.*;
4 years ago
import com.epmet.dto.result.CustomerFormResultDTO;
4 years ago
import com.epmet.dto.result.FormGroupDTO;
import com.epmet.dto.result.FormItem;
import com.epmet.dto.result.HomeUserResultDTO;
4 years ago
import com.epmet.excel.IcResiUserExcel;
import com.epmet.feign.OperCustomizeOpenFeignClient;
4 years ago
import com.epmet.service.IcResiUserService;
4 years ago
import lombok.extern.slf4j.Slf4j;
4 years ago
import org.apache.commons.lang3.StringUtils;
4 years ago
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
4 years ago
import org.jetbrains.annotations.NotNull;
4 years ago
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
4 years ago
import java.io.IOException;
import java.net.URLEncoder;
4 years ago
import java.util.*;
4 years ago
/**
* 用户基础信息
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-10-26
*/
4 years ago
@Slf4j
4 years ago
@RestController
@RequestMapping("icresiuser")
public class IcResiUserController {
4 years ago
private static final String BASE_TABLE_NAME = "ic_resi_user";
@Autowired
private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient;
4 years ago
@Autowired
private IcResiUserService icResiUserService;
@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();
}
4 years ago
@PostMapping("delete")
public Result delete(@LoginUser TokenDto tokenDto,@RequestBody DelIcResiUserFormDTO formDTO){
formDTO.setCustomerId(tokenDto.getCustomerId());
ValidatorUtils.validateEntity(formDTO,DelIcResiUserFormDTO.IdGroup.class);
icResiUserService.delete(formDTO);
4 years ago
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);
}
4 years ago
/**
* @Author sun
* @Description 党建互联平台--保存居民信息
**/
@PostMapping("add")
4 years ago
public Result add(@LoginUser TokenDto tokenDto, @RequestBody List<IcResiUserFormDTO> formDTO) {
icResiUserService.add(tokenDto, formDTO);
4 years ago
return new Result();
}
/**
* @Author sun
* @Description 党建互联平台--修改居民信息
**/
@PostMapping("edit")
4 years ago
public Result edit(@LoginUser TokenDto tokenDto, @RequestBody List<IcResiUserFormDTO> formDTO) {
icResiUserService.edit(tokenDto, formDTO);
4 years ago
return new Result();
}
@GetMapping("download/template")
public void downloadTemplate(@RequestParam String customerId) throws Exception {
4 years ago
CustomerFormResultDTO resultForm = getResiFormItems(customerId);
XSSFWorkbook workbook = new XSSFWorkbook();
4 years ago
Map<String, List<ExcelExportEntity>> sheetHeaderMap = buildHeaderByItem(resultForm);
//Workbook workbook = null;
4 years ago
for (Map.Entry<String, List<ExcelExportEntity>> entry : sheetHeaderMap.entrySet()) {
String sheetName = entry.getKey();
List<ExcelExportEntity> headers = entry.getValue();
4 years ago
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);
4 years ago
}
FileOutputStream fos = new FileOutputStream("//Users/liujianjun/Downloads/基础信息表/Dow.tt.xls");
workbook.write(fos);
fos.close();
}
@NotNull
4 years ago
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的
4 years ago
4 years ago
List<FormItem> itemList = resultForm.getItemList();
List<FormGroupDTO> groupList = resultForm.getGroupList();
4 years ago
Map<String,List<ExcelExportEntity>> everySheetHeaderMap = new LinkedHashMap<>();
List<ExcelExportEntity> firstSheetHeaderList = new ArrayList<>();
4 years ago
//Map<String, String> groupNameMap = groupList.stream().collect(Collectors.toMap(FormGroupDTO::getGroupId,FormGroupDTO::getLabel));
4 years ago
itemList.forEach(item->{
if (StringUtils.isBlank(item.getColumnName())){
return;
}
4 years ago
if (item.getChildGroup() == null){
4 years ago
ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getColumnName().concat(String.valueOf(item.getColumnNum())),30);
header.setNeedMerge(true);
firstSheetHeaderList.add(header);
return;
}
4 years ago
everySheetHeaderMap.putIfAbsent(resultForm.getFormName(),firstSheetHeaderList);
4 years ago
4 years ago
//这些是动态的 formGroup
4 years ago
if (item.getChildGroup() != null){
//baseTableName单独的一个sheet
System.out.println("childGroup:"+item.getLabel());
4 years ago
if (BASE_TABLE_NAME.equals(item.getTableName())){
4 years ago
// 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())));
4 years ago
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);
}
});
4 years ago
//header.setList(secondHeaderList);
//otherSheetHeaderList.add(header);
4 years ago
}
}
4 years ago
});
4 years ago
groupList.forEach(item->{
/* if (!"兴趣爱好".equals(item.getLabel()) && !"宗教信仰".equals(item.getLabel())){
return;
}*/
4 years ago
if (!BASE_TABLE_NAME.equals(item.getTableName())){
4 years ago
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())));
4 years ago
secondHeader.setNeedMerge(true);
secondHeaderList.add(secondHeader);
if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(item2.getOptions())){
4 years ago
List<ExcelExportEntity> thirdHeaderList = new ArrayList<>();
item2.getOptions().forEach(child->{
ExcelExportEntity thirdHeader = new ExcelExportEntity(child.getLabel(),child.getValue()+ new Random(1).nextInt(2));
4 years ago
thirdHeader.setNeedMerge(true);
thirdHeaderList.add(thirdHeader);
});
secondHeader.setList(thirdHeaderList);
}
4 years ago
4 years ago
});
header.setList(secondHeaderList);
firstSheetHeaderList.add(header);
System.out.println(JSON.toJSONString(firstSheetHeaderList));
});
return everySheetHeaderMap;
}
4 years ago
4 years ago
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);
}
4 years ago
});
4 years ago
header.setList(secondHeaderList);
firstSheetHeaderList.add(header);
everySheetHeaderMap.putIfAbsent(item.getLabel(),firstSheetHeaderList);
}
/**
* @Description 根据房间号查人
* @Param formDTO
* @Return {@link Result<List<HomeUserResultDTO>>}
* @Author zhaoqifeng
* @Date 2021/11/1 11:04
*/
@PostMapping("getpeoplebyroom")
public Result<List<HomeUserResultDTO>> getPeopleByRoom(@RequestBody IcResiUserDTO formDTO) {
return new Result<List<HomeUserResultDTO>>().ok(icResiUserService.getPeopleByRoom(formDTO.getHomeId()));
}
4 years ago
@PostMapping("listresi")
public Result<PageData<Map<String,Object>>> queryListResi1(@LoginUser TokenDto tokenDto, @RequestBody IcResiUserPageFormDTO pageFormDTO){
//pageFormDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
pageFormDTO.setCustomerId(tokenDto.getCustomerId());
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
* @author yinzuomei
* @date 2021/10/28 10:29 上午
*/
@PostMapping("detail")
public Result queryIcResiDetail(@LoginUser TokenDto tokenDto,@RequestBody IcResiDetailFormDTO pageFormDTO){
//pageFormDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
pageFormDTO.setCustomerId(tokenDto.getCustomerId());
ValidatorUtils.validateEntity(pageFormDTO,IcResiDetailFormDTO.AddUserInternalGroup.class);
return new Result().ok(icResiUserService.queryIcResiDetail(pageFormDTO));
}
4 years ago
4 years ago
@RequestMapping(value = "/exportExcel")
public void exportExcel(/*@LoginUser TokenDto tokenDto,*/ @RequestBody IcResiUserPageFormDTO pageFormDTO, HttpServletResponse response) throws IOException {
pageFormDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
pageFormDTO.setPageFlag(false);
4 years ago
//PageData<Map<String, Object>> mapPageData = icResiUserService.pageResiMap(pageFormDTO);
//List<Map<String, Object>> list = mapPageData.getList();
List<Map<String, Object>> list = (List<Map<String, Object>>)JSON.parse("[{\"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\"}]"
);
4 years ago
Map<String, Object> mapData = new HashMap<>();
log.info("list:{}", JSON.toJSONString(list));
mapData.put("list", list);
4 years ago
CustomerFormResultDTO resiFormItems = getResiFormItems(pageFormDTO.getCustomerId());
String templatePath = "excel/ic_resi_info_cid.xls";
TemplateExportParams params = new TemplateExportParams(templatePath, 0,1);
4 years ago
Workbook workbook = ExcelExportUtil.exportExcel(new TemplateExportParams(templatePath), mapData);
//header
response.setHeader("content-Type", "application/vnd.ms-excel");
4 years ago
response.addHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode("继续追踪导出详情-" + ".xls", "UTF-8"));
4 years ago
workbook.write(response.getOutputStream());
4 years ago
/* //方式1 通过mv导出
4 years ago
ModelAndView mv = new ModelAndView(new EasypoiTemplateExcelView());
4 years ago
mv.addObject(TemplateExcelConstants.FILE_NAME, "继续追踪导出详情-"));
mv.addObject(TemplateExcelConstants.PARAMS, new TemplateExportParams(templatePath));
4 years ago
mv.addObject(TemplateExcelConstants.MAP_DATA, mapData);
4 years ago
return mv;*/
4 years ago
}
@PostMapping("import/excel")
public Result importExcelByEasyExcel() {
Object header = icResiUserService.importExcel();
return new Result().ok(header);
}
}