/**
* Copyright 2018 人人开源 https://www.renren.io
*
* 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.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.epmet.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.alibaba.fastjson.JSON;
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.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.IcResiUserDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
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.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 用户基础信息
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2021-10-26
*/
@Slf4j
@RestController
@RequestMapping("icresiuser")
public class IcResiUserController {
private static final String BASE_TABLE_NAME = "ic_resi_user";
@Autowired
private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient;
@Autowired
private IcResiUserService icResiUserService;
@Autowired
private EpmetUserOpenFeignClient epmetUserOpenFeignClient;
/**
* @Author sun
* @Description 党建互联平台--保存居民信息
**/
@PostMapping("add")
public Result add(@LoginUser TokenDto tokenDto, @RequestBody List formDTO) {
icResiUserService.add(tokenDto, formDTO);
return new Result();
}
/**
* @Author sun
* @Description 党建互联平台--修改居民信息
**/
@PostMapping("edit")
public Result edit(@LoginUser TokenDto tokenDto, @RequestBody List formDTO) {
icResiUserService.edit(tokenDto, formDTO);
return new Result();
}
/**
* @Description 根据房间号查人
* @Param formDTO
* @Return {@link Result>}
* @Author zhaoqifeng
* @Date 2021/11/1 11:04
*/
@PostMapping("getpeoplebyroom")
public Result> getPeopleByRoom(@RequestBody IcResiUserDTO formDTO) {
return new Result>().ok(icResiUserService.getPeopleByRoom(formDTO.getHomeId()));
}
@PostMapping("listresi")
public Result>> 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>>().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));
}
@RequestMapping(value = "/exportExcel")
public void exportExcel(@RequestHeader String customerId, @RequestBody IcResiUserPageFormDTO pageFormDTO, HttpServletResponse response) throws IOException {
pageFormDTO.setCustomerId(customerId);
pageFormDTO.setPageFlag(false);
CustomerFormResultDTO resiFormItems = getResiFormItems(pageFormDTO.getCustomerId());
Map> otherSheetItems = new HashMap<>();
//主表的
for (FormItem formItem : resiFormItems.getItemList()) {
if (StringUtils.isBlank(formItem.getColumnName())) {
continue;
}
Map 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);
for (FormItem2 item2 : formItem.getChildGroup().getItemList()) {
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));
}
}
}
}
//其他sheet
for (FormGroupDTO groupItem : resiFormItems.getGroupList()) {
if (groupItem.getItemList() == null) {
continue;
}
Map 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")) {
itemMap.put(formItem2.getColumnName().concat(formItem2.getColumnNum() == 0 ? "" : formItem2.getColumnNum().toString()), ConvertUtils.sourceToTarget(formItem2, FormItem.class));
}
}
}
Map> resiMainList = icResiUserService.getDataForExport(otherSheetItems.get(BASE_TABLE_NAME), pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), BASE_TABLE_NAME, pageFormDTO.getConditions());
//resiMainList = (List