|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
|
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
|
|
|
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.ExcelUtils;
|
|
|
|
import com.epmet.commons.tools.utils.Result;
|
|
|
|
import com.epmet.commons.tools.validator.AssertUtils;
|
|
|
|
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.CustomerFormQueryDTO;
|
|
|
|
import com.epmet.dto.form.IcResiUserFormDTO;
|
|
|
|
import com.epmet.dto.result.CustomerFormResultDTO;
|
|
|
|
import com.epmet.excel.IcResiUserExcel;
|
|
|
|
import com.epmet.feign.OperCustomizeOpenFeignClient;
|
|
|
|
import com.epmet.handler.ExcelDiceAddressListHandlerImpl;
|
|
|
|
import com.epmet.service.IcResiUserService;
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户基础信息
|
|
|
|
*
|
|
|
|
* @author generator generator@elink-cn.com
|
|
|
|
* @since v1.0.0 2021-10-26
|
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("icresiuser")
|
|
|
|
public class IcResiUserController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient;
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
|
|
|
|
@DeleteMapping
|
|
|
|
public Result delete(@RequestBody String[] ids){
|
|
|
|
//效验数据
|
|
|
|
AssertUtils.isArrayEmpty(ids, "id");
|
|
|
|
icResiUserService.delete(ids);
|
|
|
|
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 党建互联平台--保存居民信息
|
|
|
|
**/
|
|
|
|
@PostMapping("add")
|
|
|
|
public Result add(@LoginUser TokenDto tokenDto, @RequestBody List<IcResiUserFormDTO> formDTO) {
|
|
|
|
icResiUserService.add(tokenDto, formDTO);
|
|
|
|
return new Result();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author sun
|
|
|
|
* @Description 党建互联平台--修改居民信息
|
|
|
|
**/
|
|
|
|
@PostMapping("edit")
|
|
|
|
public Result edit(@LoginUser TokenDto tokenDto, @RequestBody List<IcResiUserFormDTO> formDTO) {
|
|
|
|
icResiUserService.edit(tokenDto, formDTO);
|
|
|
|
return new Result();
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("download/template")
|
|
|
|
public void downloadTemplate(@RequestParam String customerId) throws Exception {
|
|
|
|
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()));
|
|
|
|
|
|
|
|
List<ExcelExportEntity> firstHeaderList = new ArrayList<>();
|
|
|
|
|
|
|
|
resultForm.getData().getItemList().forEach(item->{
|
|
|
|
ExcelExportEntity header = new ExcelExportEntity(item.getLabel(),item.getColumnName().concat(String.valueOf(item.getColumnNum())));
|
|
|
|
header.setNeedMerge(true);
|
|
|
|
firstHeaderList.add(header);
|
|
|
|
String baseTableName = "resi_base_info";
|
|
|
|
|
|
|
|
if (item.getChildGroup() != null){
|
|
|
|
//baseTableName单独的一个sheet
|
|
|
|
if (baseTableName.equals(item.getTableName())){
|
|
|
|
header = new ExcelExportEntity(item.getChildGroup().getLabel(),item.getChildGroup().getTableName());
|
|
|
|
header.setNeedMerge(true);
|
|
|
|
}else{
|
|
|
|
header = new ExcelExportEntity(item.getChildGroup().getLabel(),item.getChildGroup().getTableName());
|
|
|
|
header.setNeedMerge(true);
|
|
|
|
}
|
|
|
|
if (item.getColumnName().equals("GENDER")){
|
|
|
|
header.setReplace(new String[]{"男_1","女_2"});
|
|
|
|
}
|
|
|
|
List<ExcelExportEntity> secondHeaderList = new ArrayList<>();
|
|
|
|
item.getChildGroup().getItemList().forEach(item2->{
|
|
|
|
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());
|
|
|
|
thirdHeader.setNeedMerge(true);
|
|
|
|
thirdHeaderList.add(thirdHeader);
|
|
|
|
});
|
|
|
|
secondHeader.setList(thirdHeaderList);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
header.setList(secondHeaderList);
|
|
|
|
firstHeaderList.add(header);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ExcelExportEntity desginGroup = new ExcelExportEntity("表头名称","键");
|
|
|
|
desginGroup.setNeedMerge(true);
|
|
|
|
List<ExcelExportEntity> paramCols = new ArrayList<>();
|
|
|
|
List<String> headerList = Arrays.asList("头1","头2","头3");
|
|
|
|
headerList.forEach(e->{
|
|
|
|
paramCols.add(new ExcelExportEntity(e,e,30));
|
|
|
|
});
|
|
|
|
|
|
|
|
desginGroup.setList(paramCols);
|
|
|
|
colList.add(desginGroup);*/
|
|
|
|
List<Map<String, String>> dataList =new ArrayList<>();
|
|
|
|
Map<String,String> dataMap = new HashMap<>();
|
|
|
|
dataMap.put("GENDER0","1");
|
|
|
|
dataMap.put("ID_CARD0","371888991");
|
|
|
|
|
|
|
|
dataList.add(dataMap);
|
|
|
|
ExportParams exportParams = new ExportParams();
|
|
|
|
exportParams.setDictHandler(new ExcelDiceAddressListHandlerImpl());
|
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, firstHeaderList, dataList);
|
|
|
|
//ExcelExportUtil.exportExcel
|
|
|
|
FileOutputStream fos = new FileOutputStream("//Users/liujianjun/Downloads/基础信息表/Dow.tt.xls");
|
|
|
|
workbook.write(fos);
|
|
|
|
fos.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|