|
|
@ -17,6 +17,7 @@ |
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
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; |
|
|
@ -24,10 +25,13 @@ 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; |
|
|
|
import com.epmet.commons.tools.constant.ServiceConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.enums.GenderEnum; |
|
|
|
import com.epmet.commons.tools.enums.HouseTypeEnum; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.feign.ResultDataResolver; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
@ -37,17 +41,16 @@ import com.epmet.dao.IcResiUserDao; |
|
|
|
import com.epmet.dto.CustomerAgencyDTO; |
|
|
|
import com.epmet.dto.IcResiUserDTO; |
|
|
|
import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.result.AllGridsByUserIdResultDTO; |
|
|
|
import com.epmet.dto.result.HomeUserResultDTO; |
|
|
|
import com.epmet.dto.result.HouseInfoDTO; |
|
|
|
import com.epmet.dto.result.IcFormResColumnDTO; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.entity.IcResiUserEntity; |
|
|
|
import com.epmet.excel.handler.DynamicEasyExcelListener; |
|
|
|
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; |
|
|
|
import lombok.Data; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
@ -57,6 +60,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.util.*; |
|
|
|
import java.util.function.Function; |
|
|
|
import java.util.stream.Collectors; |
|
|
@ -69,7 +73,7 @@ import java.util.stream.Collectors; |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResiUserEntity> implements IcResiUserService { |
|
|
|
public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResiUserEntity> implements IcResiUserService, ResultDataResolver { |
|
|
|
private Logger logger = LogManager.getLogger(IcResiUserServiceImpl.class); |
|
|
|
@Autowired |
|
|
|
private IcResiUserRedis icResiUserRedis; |
|
|
@ -417,4 +421,315 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi |
|
|
|
return resultMap; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Object importExcel() { |
|
|
|
DynamicEasyExcelListener readListener = new DynamicEasyExcelListener(); |
|
|
|
EasyExcelFactory.read(new File("/opt/test/基础信息表/resi_info.xls")).registerReadListener(readListener).headRowNumber(3).sheet(0).doRead(); |
|
|
|
|
|
|
|
List<Map<Integer, String>> headList = readListener.getHeadList(); |
|
|
|
List<Map<Integer, String>> dataList = readListener.getDataList(); |
|
|
|
|
|
|
|
Map<Integer, List<String>> headers = mergeHead(headList); |
|
|
|
|
|
|
|
// 查询form相关信息
|
|
|
|
CustomerFormQueryDTO form = new CustomerFormQueryDTO(); |
|
|
|
form.setFormCode("resi_base_info"); |
|
|
|
Result<List<FormItem>> result = operCustomizeOpenFeignClient.listItems(form); |
|
|
|
List<FormItem> customerItems = getResultDataOrThrowsException(result, ServiceConstant.OPER_CUSTOMIZE_SERVER, EpmetErrorCode.SERVER_ERROR.getCode(), "【居民信息excel导入】查询表单相关信息失败"); |
|
|
|
|
|
|
|
// 清洗表头数据
|
|
|
|
Map<Integer, String> abandonedHeaders = washHeaders(headers, customerItems); |
|
|
|
|
|
|
|
//合并多级表头
|
|
|
|
HashMap<String, List<Integer>> combinedHeaders = combineHeaders(headers); |
|
|
|
|
|
|
|
// 得到客户配置item数据
|
|
|
|
Map<String, FormItem> formItemMap = customerItems.stream().collect( |
|
|
|
Collectors.toMap(formItem -> { |
|
|
|
String groupLabel = formItem.getGroupLabel(); |
|
|
|
String label = formItem.getLabel(); |
|
|
|
if (StringUtils.isNotBlank(groupLabel)) { |
|
|
|
return groupLabel.concat(":").concat(label); |
|
|
|
} else { |
|
|
|
return label; |
|
|
|
} |
|
|
|
}, formItem -> formItem) |
|
|
|
); |
|
|
|
HashMap<String, List<ColumnWrapper>> headerColumnWrapper = integrate(formItemMap, combinedHeaders, dataList, abandonedHeaders); |
|
|
|
|
|
|
|
return headerColumnWrapper; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 合并头 |
|
|
|
* |
|
|
|
* @param headers |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.10.28 21:27:18 |
|
|
|
*/ |
|
|
|
private HashMap<String, List<Integer>> combineHeaders(Map<Integer, List<String>> headers) { |
|
|
|
HashMap<String, List<Integer>> itemAndColIndexs = new HashMap<>(); |
|
|
|
|
|
|
|
headers.forEach((k, v) -> { |
|
|
|
String tempKey = String.join(":", v); |
|
|
|
List<Integer> colIndexs = itemAndColIndexs.get(tempKey); |
|
|
|
if (colIndexs == null) { |
|
|
|
colIndexs = new ArrayList<>(); |
|
|
|
itemAndColIndexs.put(tempKey, colIndexs); |
|
|
|
} |
|
|
|
colIndexs.add(k); |
|
|
|
}); |
|
|
|
|
|
|
|
return itemAndColIndexs; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 清洗headers |
|
|
|
* |
|
|
|
* @param headers |
|
|
|
* @param items |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.10.28 21:07:12 |
|
|
|
*/ |
|
|
|
private Map<Integer, String> washHeaders(Map<Integer, List<String>> headers, List<FormItem> items) { |
|
|
|
List<String> itemLabels = items.stream().map(i -> i.getLabel()).collect(Collectors.toList()); |
|
|
|
Map<Integer, String> abandonedHeaders = new HashMap<>(); |
|
|
|
for (Map.Entry<Integer, List<String>> entry:headers.entrySet()) { |
|
|
|
Integer colIdx = entry.getKey(); |
|
|
|
List<String> v = entry.getValue(); |
|
|
|
int lastPartIndex = v.size() - 1; |
|
|
|
String lastValuePart = v.get(lastPartIndex); |
|
|
|
if (itemLabels.indexOf(lastValuePart) == -1) { |
|
|
|
// 该部分为options,它的上一级是item,那么去掉options这一级
|
|
|
|
v.remove(lastPartIndex); |
|
|
|
abandonedHeaders.put(colIdx, lastValuePart); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return abandonedHeaders; |
|
|
|
//headers.forEach((k, v) -> {
|
|
|
|
//
|
|
|
|
//});
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 数据整合 |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.10.28 17:08:51 |
|
|
|
*/ |
|
|
|
private HashMap<String, List<ColumnWrapper>> integrate(Map<String, FormItem> formItemMap, Map<String, List<Integer>> combinedHeaders, |
|
|
|
List<Map<Integer, String>> datas, Map<Integer, String> abandonedHeaders) { |
|
|
|
HashMap<String, List<ColumnWrapper>> data = new HashMap<>(); |
|
|
|
|
|
|
|
for (Map.Entry<String, List<Integer>> entry : combinedHeaders.entrySet()) { |
|
|
|
String combinedHeader = entry.getKey(); |
|
|
|
|
|
|
|
FormItem item = formItemMap.get(combinedHeader); |
|
|
|
|
|
|
|
if (item == null) { |
|
|
|
// 如果数据库中没有该项,可能是用户自己定义的项,忽略
|
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
ColumnWrapper columnWrapper = new ColumnWrapper(); |
|
|
|
|
|
|
|
// 填充options
|
|
|
|
columnWrapper.setItemType(item.getItemType()); |
|
|
|
String groupLabel = item.getGroupLabel(); |
|
|
|
String combinedLabel = StringUtils.isBlank(groupLabel) ? item.getLabel() : groupLabel.concat(":").concat(item.getLabel()); |
|
|
|
columnWrapper.setCombinedLabel(combinedLabel); |
|
|
|
columnWrapper.setColumnName(item.getColumnName()); |
|
|
|
columnWrapper.setColIndexs(entry.getValue()); |
|
|
|
|
|
|
|
if ("remote".equals(item.getOptionSourceType())) { |
|
|
|
Map<String, String> options = listRemoteOptions(item.getOptionSourceValue()); |
|
|
|
columnWrapper.setOptions(options); |
|
|
|
} else { |
|
|
|
Map<String, String> options = item.getOptions().stream().collect(Collectors.toMap(OptionDTO::getLabel, OptionDTO::getValue)); |
|
|
|
columnWrapper.setOptions(options); |
|
|
|
} |
|
|
|
|
|
|
|
/*switch (item.getItemType()) { |
|
|
|
case "input": |
|
|
|
case "textarea": |
|
|
|
case "datepicker": |
|
|
|
case "timerange": |
|
|
|
//输入性的
|
|
|
|
break; |
|
|
|
case "checkbox": |
|
|
|
break; |
|
|
|
}*/ |
|
|
|
|
|
|
|
} |
|
|
|
return data; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取checkbox列值 |
|
|
|
* @param options |
|
|
|
* @param writedColIdxs |
|
|
|
* @param abandonedHeaders |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String getCheckBoxColValue(List<OptionDTO> options, List<Integer> writedColIdxs, Map<Integer, String> abandonedHeaders) { |
|
|
|
|
|
|
|
Map<String, String> optionMap = options.stream().collect(Collectors.toMap(OptionDTO::getLabel, OptionDTO::getValue)); |
|
|
|
|
|
|
|
List<String> optionValues = writedColIdxs.stream().map(i -> { |
|
|
|
String optionName = abandonedHeaders.get(i); |
|
|
|
return optionMap.get(optionName); |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
return String.join(",", optionValues); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 远程获取options |
|
|
|
* @param uri |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private Map<String, String> listRemoteOptions(String uri) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
// 通用api调用,无法实现
|
|
|
|
/*if (!uri.startsWith("/api")) uri = "/api".concat(uri); |
|
|
|
|
|
|
|
NamingService namingService = discoveryProperties.namingServiceInstance(); |
|
|
|
ResponseEntity<Result<List<OptionResultDTO>>> response = null; |
|
|
|
try { |
|
|
|
// 调用gateway服务,查询相关接口
|
|
|
|
Instance gatewayInstance = namingService.getAllInstances(ServiceConstant.EPMET_GATEWAY).get(0); |
|
|
|
String ip = gatewayInstance.getIp(); |
|
|
|
int port = gatewayInstance.getPort(); |
|
|
|
|
|
|
|
String url = String.format("http://%s:%s%s", ip, port, uri); |
|
|
|
|
|
|
|
ParameterizedTypeReference<Result<List<OptionResultDTO>>> tr = new ParameterizedTypeReference<Result<List<OptionResultDTO>>>() {}; |
|
|
|
response = new RestTemplate().exchange(url, HttpMethod.POST, null, tr); |
|
|
|
} catch (NacosException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
|
|
|
|
if (response != null && (response.getStatusCode() == HttpStatus.OK)) { |
|
|
|
List<OptionResultDTO> options = response.getBody().getData(); |
|
|
|
if (options == null) { |
|
|
|
System.out.println(6); |
|
|
|
} |
|
|
|
return options.stream().collect(Collectors.toMap(OptionResultDTO::getLabel, OptionResultDTO::getValue)); |
|
|
|
} else { |
|
|
|
throw new RenException(EpmetErrorCode.SERVER_ERROR.getCode()); |
|
|
|
}*/ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 合并表头 |
|
|
|
* |
|
|
|
* @param headList |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.10.27 16:17:34 |
|
|
|
*/ |
|
|
|
private Map<Integer, List<String>> mergeHead(List<Map<Integer, String>> headList) { |
|
|
|
Map<Integer, String> l1 = headList.get(0); |
|
|
|
Map<Integer, String> l2 = headList.get(1); |
|
|
|
Map<Integer, String> l3 = headList.get(2); |
|
|
|
|
|
|
|
String l1LastHeadName = ""; |
|
|
|
String l2LastHeadName = ""; |
|
|
|
|
|
|
|
//Map<Integer, String> resultMap = new HashMap<>();
|
|
|
|
HashMap<Integer, List<String>> result = new HashMap<>(); |
|
|
|
|
|
|
|
for (Map.Entry<Integer, String> entry : l1.entrySet()) { |
|
|
|
|
|
|
|
StringBuilder headerNameConcatStr = new StringBuilder(); |
|
|
|
|
|
|
|
Integer key = entry.getKey(); |
|
|
|
String l1TempValue = entry.getValue(); |
|
|
|
|
|
|
|
String l2TempValue = l2.get(key); |
|
|
|
String l3TempValue = l3.get(key); |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(l1TempValue)) { |
|
|
|
l1LastHeadName = l1TempValue; |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(l2TempValue)) { |
|
|
|
l2LastHeadName = l2TempValue; |
|
|
|
} |
|
|
|
|
|
|
|
// 开始拼接
|
|
|
|
if (StringUtils.isNotBlank(l3TempValue)) { |
|
|
|
//headerNameConcatStr.append(l1LastHeadName).append(":").append(l2LastHeadName).append(":").append(l3TempValue);
|
|
|
|
//resultMap.put(key, headerNameConcatStr.toString());
|
|
|
|
ArrayList<String> parts = new ArrayList<>(); |
|
|
|
parts.add(l1LastHeadName); |
|
|
|
parts.add(l2LastHeadName); |
|
|
|
parts.add(l3TempValue); |
|
|
|
result.put(key, parts); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(l2TempValue)) { |
|
|
|
//headerNameConcatStr.append(l1LastHeadName).append(":").append(l2LastHeadName);
|
|
|
|
//resultMap.put(key, headerNameConcatStr.toString());
|
|
|
|
ArrayList<String> parts = new ArrayList<>(); |
|
|
|
parts.add(l1LastHeadName); |
|
|
|
parts.add(l2LastHeadName); |
|
|
|
result.put(key, parts); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(l1TempValue)) { |
|
|
|
//headerNameConcatStr.append(l1LastHeadName);
|
|
|
|
//resultMap.put(key, headerNameConcatStr.toString());
|
|
|
|
ArrayList<String> parts = new ArrayList<>(); |
|
|
|
parts.add(l1LastHeadName); |
|
|
|
result.put(key, parts); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @description 列信息封装 |
|
|
|
* |
|
|
|
* @return |
|
|
|
* @author wxz |
|
|
|
* @date 2021.10.28 22:18:05 |
|
|
|
*/ |
|
|
|
@Data |
|
|
|
public static class ColumnWrapper { |
|
|
|
private String combinedLabel; |
|
|
|
private String columnName; |
|
|
|
private String itemType; |
|
|
|
private List<Integer> colIndexs; |
|
|
|
//private List<String> colContents;
|
|
|
|
private String colValue; |
|
|
|
|
|
|
|
// key:label,value:value
|
|
|
|
private Map<String, String> options; |
|
|
|
} |
|
|
|
public List<Map<String,Object>> dynamicQuery(String customerId, |
|
|
|
String formCode, |
|
|
|
String resultTableName, |
|
|
|
List<ResiUserQueryValueDTO> conditions){ |
|
|
|
CustomerFormQueryDTO queryDTO=new CustomerFormQueryDTO(); |
|
|
|
queryDTO.setCustomerId(customerId); |
|
|
|
queryDTO.setFormCode(formCode); |
|
|
|
Result<List<String>> subTablesRes=operCustomizeOpenFeignClient.querySubTables(queryDTO); |
|
|
|
List<String> subTables=new ArrayList<>(); |
|
|
|
if(subTablesRes.success()&&CollectionUtils.isNotEmpty(subTablesRes.getData())){ |
|
|
|
subTables =subTablesRes.getData(); |
|
|
|
} |
|
|
|
return baseDao.dynamicQuery(customerId,resultTableName,conditions,subTables); |
|
|
|
} |
|
|
|
} |