Commit 97a38414 authored by liuChang's avatar liuChang

导出

parent d17ead35
......@@ -196,7 +196,7 @@ dsk:
# accessKeyId: aec7b3ff2y2q8x6t49a7e2c463ce21912
# accessKeySecret: ee8a53c7ea04eb3ac311406c8f56f95b
# protocol: https
exportBackUrl: https://szh-test.jiansheku.com/export/backUrl
exportBackUrl: http://47.104.91.229:9099/prod-api/export/backUrl
sa-token:
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
......
......@@ -196,7 +196,7 @@ dsk:
# accessKeyId: aec7b3ff2y2q8x6t49a7e2c463ce21912
# accessKeySecret: ee8a53c7ea04eb3ac311406c8f56f95b
# protocol: https
exportBackUrl: http://47.104.91.229:9099/export/backUrl
exportBackUrl: http://47.104.91.229:9099/prod-api/export/backUrl
sa-token:
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
......
......@@ -61,6 +61,8 @@ public class ComposeQueryDto extends BasePage {
JskBidWinListDto jskBidWinListDto;
//专项债项目
SpecialBondProjectDto specialBondProjectDto;
//重点项目清单
ImportantProjectDto importantProjectDto;
//投标计划
JskBidPlanDto jskBidPlanDto;
......
package com.dsk.jsk.domain.bo;
import lombok.Data;
/**
* 组合查询参数
* @author Administrator
*
*/
@Data
public class ImportantProjectDto {
Long id;
String md5;
String projectName;
//关键字
String keyword;
//关键字查询范围
String keywordStr;
String province;
String city;
String area;
String year;
String domicile;
Double startMoney;
Double endMoney;
//项目级别
String projectLevel;
//项目类型
String buildingProjectType;
//文件标题
String fileTitle;
String fileUrl;
//拟开工时间
String planStartDate;
//拟建成时间
String planCompletionDate;
//项目总投资
String projectTotalInvestment;
//已完成投资额(万元)
String completedInvestment;
//年度投资金额(万元)
String completedPlanInvestment;
//主管部门
String chargeDepartment;
//项目法人
String constructUnit;
//项目法人id
String constructUnitId;
//联系方式及联系人
String contactPersonAndTel;
//建设规模
String projectScale;
}
......@@ -9,8 +9,10 @@ import com.dsk.jsk.domain.JskCombineSearchDto;
import com.dsk.jsk.domain.bo.ComposeQueryDto;
import com.dsk.jsk.domain.bo.UrbanInvestmentPlatformDto;
import com.dsk.search.service.ExportService;
import com.dsk.search.util.ObjectUtils;
import com.dsk.system.service.ISysUserFileRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Arrays;
/**
* @author lc
......@@ -46,69 +49,83 @@ public class ExportController {
* 企业基本信息表导出
*/
@PostMapping("/enterprise/info")
public void enterpriseInfoExport(@RequestBody JSONObject object) {
ComposeQueryDto compose = com.alibaba.fastjson2.JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
public AjaxResult enterpriseInfoExport(@RequestBody JSONObject object) {
ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
if (null==compose.getAptitudeQueryDto()
||CollectionUtils.isEmpty(compose.getAptitudeQueryDto().getAptitudeDtoList())
|| !ObjectUtils.hasValueThroughObj(compose.getAptitudeQueryDto(), null, Arrays.asList("and", "or", "yes", "no", "level", "qualification", "new", "only"))) {
return AjaxResult.warn("导出筛选条件为空!");
}
if (StringUtils.isEmpty(compose.getExportExeclName())){
object.put("exportExeclName","企业基本信息导出");
}
exportService.enterpriseInfoExport(object);
return exportService.enterpriseInfoExport(object);
}
/*
* 企业资质表导出
*/
@PostMapping("/aptitude")
public void enterpriseAptitudeExport(@RequestBody JSONObject object) {
ComposeQueryDto compose = com.alibaba.fastjson2.JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
public AjaxResult enterpriseAptitudeExport(@RequestBody JSONObject object) {
ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
if (null==compose.getAptitudeQueryDto()
||CollectionUtils.isEmpty(compose.getAptitudeQueryDto().getAptitudeDtoList())
|| !ObjectUtils.hasValueThroughObj(compose.getAptitudeQueryDto().getAptitudeDtoList().get(0), null, Arrays.asList("and", "or", "yes", "no", "level", "qualification", "new", "only"))) {
return AjaxResult.warn("导出筛选条件为空!");
}
if (StringUtils.isEmpty(compose.getExportExeclName())){
object.put("exportExeclName","企业资质信息导出");
}
exportService.enterpriseAptitudeExport(object);
return exportService.enterpriseAptitudeExport(object);
}
/*
* 重点项目清单导出
*/
@RequestMapping("/important")
public void exportImportant(@RequestBody JSONObject object) {
ComposeQueryDto compose = com.alibaba.fastjson2.JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
public AjaxResult exportImportant(@RequestBody JSONObject object) {
ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
if (null==compose.getImportantProjectDto()
|| !ObjectUtils.hasValueThroughObj(compose.getImportantProjectDto(), null, Arrays.asList("and", "or", "yes", "no", "level", "qualification", "new", "only"))) {
return AjaxResult.warn("导出筛选条件为空!");
}
if (StringUtils.isEmpty(compose.getExportExeclName())){
object.put("exportExeclName","重点项目导出");
}
exportService.importantExport(object);
return exportService.importantExport(object);
}
/**
* 集团成员列表导出
*/
@PostMapping("/combine/memberList")
public void memberListExportPre(@RequestBody JskCombineSearchDto dto) throws Exception {
exportService.memberListExport(dto);
public AjaxResult memberListExportPre(@RequestBody JskCombineSearchDto dto) throws Exception {
return exportService.memberListExport(dto);
}
//集团中标业绩导出
@PostMapping("/combine/win/bid")
@SaCheckPermission("combine:info:export:win:bid")
public void exportWinBid(@RequestBody JskCombineSearchDto dto) {
exportService.exportWinBid(dto);
public AjaxResult exportWinBid(@RequestBody JskCombineSearchDto dto) {
return exportService.exportWinBid(dto);
}
//集团招标业绩导出
@PostMapping("/combine/bid")
@SaCheckPermission("combine:info:export:win:bid")
public void exportBid(@RequestBody JskCombineSearchDto dto) {
exportService.exportBid(dto);
public AjaxResult exportBid(@RequestBody JskCombineSearchDto dto) {
return exportService.exportBid(dto);
}
//查城投平台导出
@PostMapping(value = "/uipSerach")
public void uipSerachExport(@RequestBody @Valid EnterpriseUipSearchBody vo) throws Exception {
exportService.uipSerachExport(vo);
public AjaxResult uipSerachExport(@RequestBody @Valid EnterpriseUipSearchBody vo) throws Exception {
return exportService.uipSerachExport(vo);
}
//市场经济 城投平台导出
@PostMapping("/urbanInvestmentPlatform")
public void export(@RequestBody UrbanInvestmentPlatformDto dto) {
exportService.export(dto);
public AjaxResult export(@RequestBody UrbanInvestmentPlatformDto dto) {
return exportService.export(dto);
}
}
......@@ -6,6 +6,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.dsk.acc.openapi.client.util.CommonUtils;
import com.dsk.biz.utils.ExcelUtils;
import com.dsk.common.constant.Constants;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.utils.DskOpenApiUtil;
import com.dsk.component.UploadComponent;
import com.dsk.jsk.domain.EnterpriseUipSearchBody;
......@@ -43,8 +44,7 @@ public class ExportService {
private UploadComponent uploadComponent;
//企业基本信息导出
@Async
public void enterpriseInfoExport(JSONObject object) {
public AjaxResult enterpriseInfoExport(JSONObject object) {
SysUserFileRecord fileRecord = new SysUserFileRecord();
fileRecord.setFileName(object.get("exportExeclName").toString());
fileRecord.setType(1);
......@@ -56,11 +56,11 @@ public class ExportService {
//回调函数
object.put("exportBackUrl",EXPORT_BACK_URL);
dskOpenApiUtil.requestBody("/operate/export/enterprise", object);
return AjaxResult.success();
}
//企业资质导出
@Async
public void enterpriseAptitudeExport(JSONObject object) {
public AjaxResult enterpriseAptitudeExport(JSONObject object) {
SysUserFileRecord fileRecord = new SysUserFileRecord();
fileRecord.setFileName(object.get("exportExeclName").toString());
fileRecord.setType(1);
......@@ -72,11 +72,11 @@ public class ExportService {
//回调函数
object.put("exportBackUrl",EXPORT_BACK_URL);
dskOpenApiUtil.requestBody("/operate/export/aptitude", object);
return AjaxResult.success();
}
//重点项目清单
@Async
public void importantExport(JSONObject object) {
public AjaxResult importantExport(JSONObject object) {
SysUserFileRecord fileRecord = new SysUserFileRecord();
fileRecord.setFileName(object.get("exportExeclName").toString());
fileRecord.setType(1);
......@@ -88,12 +88,11 @@ public class ExportService {
//回调函数
object.put("exportBackUrl",EXPORT_BACK_URL);
dskOpenApiUtil.requestBody("/operate/export/important", object);
return AjaxResult.success();
}
//集团成员导出
@Async
public void memberListExport(JskCombineSearchDto dto) {
public AjaxResult memberListExport(JskCombineSearchDto dto) {
SysUserFileRecord fileRecord = new SysUserFileRecord();
fileRecord.setFileName(dto.getExportExeclName());
fileRecord.setType(1);
......@@ -105,11 +104,11 @@ public class ExportService {
//回调函数
dto.setExportBackUrl(EXPORT_BACK_URL);
dskOpenApiUtil.requestBody("/operate/export/member", BeanUtil.beanToMap(dto, false, false));
return AjaxResult.success();
}
//集团中标业绩导出
@Async
public void exportWinBid(JskCombineSearchDto dto) {
public AjaxResult exportWinBid(JskCombineSearchDto dto) {
SysUserFileRecord fileRecord = new SysUserFileRecord();
fileRecord.setFileName(dto.getExportExeclName());
fileRecord.setType(1);
......@@ -121,11 +120,11 @@ public class ExportService {
//回调函数
dto.setExportBackUrl(EXPORT_BACK_URL);
dskOpenApiUtil.requestBody("/operate/export/combineBid", BeanUtil.beanToMap(dto, false, false));
return AjaxResult.success();
}
//集团招标业绩
@Async
public void exportBid(JskCombineSearchDto dto) {
public AjaxResult exportBid(JskCombineSearchDto dto) {
SysUserFileRecord fileRecord = new SysUserFileRecord();
fileRecord.setFileName(dto.getExportExeclName());
fileRecord.setType(1);
......@@ -137,11 +136,12 @@ public class ExportService {
//回调函数
dto.setExportBackUrl(EXPORT_BACK_URL);
dskOpenApiUtil.requestBody("/operate/export/combine/tender", BeanUtil.beanToMap(dto, false, false));
return AjaxResult.success();
}
@Async
public void uipSerachExport(EnterpriseUipSearchBody pageDto) {
public AjaxResult uipSerachExport(EnterpriseUipSearchBody pageDto) {
// 分页参数
pageDto.setPageNum(1);
if (null==pageDto.getPageSize()||pageDto.getPageSize()>=2000){
......@@ -211,10 +211,11 @@ public class ExportService {
ExcelUtils<UrbanInvestmentExportVo> util = new ExcelUtils<>(UrbanInvestmentExportVo.class);
ByteArrayOutputStream ba = util.exportExcel(resultList, "查城投平台", title, true);
uploadComponent.upload(title, ba, Constants.SUFFIX_XLSX, Constants.CONTENT_TYPE_XLSX);
return AjaxResult.success();
}
@Async
public void export(UrbanInvestmentPlatformDto pageDto) {
public AjaxResult export(UrbanInvestmentPlatformDto pageDto) {
// 分页参数
pageDto.setPageNum(1);
......@@ -285,5 +286,6 @@ public class ExportService {
ExcelUtils<UrbanInvestmentExportVo> util = new ExcelUtils<>(UrbanInvestmentExportVo.class);
ByteArrayOutputStream ba = util.exportExcel(resultList, "城投平台", title, true);
uploadComponent.upload(title, ba, Constants.SUFFIX_XLSX, Constants.CONTENT_TYPE_XLSX);
return AjaxResult.success();
}
}
package com.dsk.search.util;
import com.alibaba.fastjson2.JSON;
import com.dsk.common.utils.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.util.CollectionUtils;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
/**
* @Author liujie
* @ClassName ObjectUtils
* @Date 2021年09月29日22:34
**/
public class ObjectUtils {
public static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<String>();
for (PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) emptyNames.add(pd.getName());
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
public static void copyPropertiesIgnoreNull(Object src, Object target) {
BeanUtils.copyProperties(src, target, getNullPropertyNames(src));
}
/**
* 方法一:利用递归遍历
* 用途:从复杂对象中递归遍历,判断对象是否有值
* @param object 复杂对象 不能是数组
* @param excludeProNames 排除的属性名
* @param excludeValues 排除的属性值
* @return
*/
public static Boolean hasValueThroughObj(Object object,List<String> excludeProNames,List<Object> excludeValues){
Boolean hasValue = false;
Class clazz = null;
try {
if (object==null ){
return hasValue;
}
clazz = object.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
String proType = field.getGenericType().toString();
String proName = field.getName();
// System.err.println("proName:" + proName + "----------proType:" + proType );
// System.out.println(excludeProNames+"---contains---:"+proName+"--"+excludeProNames.contains(proName));
if (!CollectionUtils.isEmpty(excludeProNames)&&excludeProNames.contains(proName)){
continue;
}
if ("class java.lang.String".equals(proType) ||"byte".equals(proType)||"class java.util.Date".equals(proType) || "short".equals(proType) || "int".equals(proType)
||"class java.lang.Byte".equals(proType) || "class java.lang.Short".equals(proType) || "class java.lang.Integer".equals(proType) || "class java.lang.Long".equals(proType) || "class java.lang.Double".equals(proType) || "class java.lang.Float".equals(proType) || "class java.lang.Boolean".equals(proType)
||"long".equals(proType)|| "double".equals(proType) || "float".equals(proType) || "boolean".equals(proType)){
field.setAccessible(true);
Object obj = field.get(object);
if (obj==null ){
continue;
}
String proValue = String.valueOf(obj);
if (StringUtils.isEmpty(proValue)){
continue;
}
if (!excludeValues.contains(proValue)){
hasValue = true;
return hasValue;
}
continue;
}else if (proType.startsWith("java.util")){
//属性是集合类型则遍历
if (proType.startsWith("java.util.List")){
//对List类型的属性遍历
PropertyDescriptor descriptor = new PropertyDescriptor(field.getName(), clazz);
Method method = descriptor.getReadMethod();
List list = (List)method.invoke(object);
if (list!=null && list.size()>0){
int len = list.size();
for (int i= 0;i<len;i++){
hasValue = hasValueThroughObj(list.get(i),excludeProNames,excludeValues);
if (hasValue) return hasValue;
}
continue;
}
}else if (proType.startsWith("java.util.Map")){
//对Map类型的属性遍历
PropertyDescriptor descriptor = new PropertyDescriptor(field.getName(), clazz);
Method method = descriptor.getReadMethod();
Map map = (Map)method.invoke(object);
if (map!=null && map.size()>0){
for (Object obj : map.values()){
if (hasValue) return hasValue;
}
continue;
}
}
}else if(field.getType().isArray()){
//属性是数组类型则遍历
field.setAccessible(true);
Object[] objArr = (Object[]) field.get(object);
Map<String,Object> objMap = new HashMap<>();
if (objArr!=null && objArr.length>0){
for (Object arr : objArr){
hasValue = hasValueThroughObj(arr,excludeProNames,excludeValues);
if (hasValue) return hasValue;
}
continue;
}
}else {
//class类型的遍历
PropertyDescriptor descriptor = new PropertyDescriptor(field.getName(), clazz);
Method method = descriptor.getReadMethod();
Object obj = method.invoke(object);
if (obj!= null){
hasValue = hasValueThroughObj(obj,excludeProNames,excludeValues);
if (hasValue) return hasValue;
continue;
}
}
}
} catch (Exception e) {
System.err.println("err:" + e);
}
return hasValue;
}
/**
* 用途:从复杂对象中递归遍历,判断对象中某些字段是否有值
* @param object 复杂对象 不能是数组
* @param excludeProNames 排除的属性名
* @return
*/
public static Boolean hasFieldValueThroughObj(Object object,List<String> excludeProNames){
Boolean hasValue = false;
Class clazz = null;
try {
if (object==null ){
return hasValue;
}
clazz = object.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
String proType = field.getGenericType().toString();
if ("class java.lang.String".equals(proType) ||"byte".equals(proType)||"class java.util.Date".equals(proType) || "short".equals(proType) || "int".equals(proType)
||"class java.lang.Byte".equals(proType) || "class java.lang.Short".equals(proType) || "class java.lang.Integer".equals(proType) || "class java.lang.Long".equals(proType) || "class java.lang.Double".equals(proType) || "class java.lang.Float".equals(proType) || "class java.lang.Boolean".equals(proType)
||"long".equals(proType)|| "double".equals(proType) || "float".equals(proType) || "boolean".equals(proType)){
field.setAccessible(true);
Object obj = field.get(object);
if (obj==null ){
continue;
}
String proName = field.getName();
if (!CollectionUtils.isEmpty(excludeProNames)&&excludeProNames.contains(proName)){
String proValue = String.valueOf(obj);
if (StringUtils.isEmpty(proValue)){
continue;
}
hasValue = true;
return hasValue;
}
continue;
}else if (proType.startsWith("java.util")){
//属性是集合类型则遍历
if (proType.startsWith("java.util.List")){
//对List类型的属性遍历
PropertyDescriptor descriptor = new PropertyDescriptor(field.getName(), clazz);
Method method = descriptor.getReadMethod();
List list = (List)method.invoke(object);
if (list!=null && list.size()>0){
int len = list.size();
for (int i= 0;i<len;i++){
hasValue = hasFieldValueThroughObj(list.get(i),excludeProNames);
if (hasValue) return hasValue;
}
continue;
}
}else if (proType.startsWith("java.util.Map")){
//对Map类型的属性遍历
PropertyDescriptor descriptor = new PropertyDescriptor(field.getName(), clazz);
Method method = descriptor.getReadMethod();
Map map = (Map)method.invoke(object);
if (map!=null && map.size()>0){
for (Object obj : map.values()){
if (hasValue) return hasValue;
}
continue;
}
}
}else if(field.getType().isArray()){
//属性是数组类型则遍历
field.setAccessible(true);
Object[] objArr = (Object[]) field.get(object);
Map<String,Object> objMap = new HashMap<>();
if (objArr!=null && objArr.length>0){
for (Object arr : objArr){
hasValue = hasFieldValueThroughObj(arr,excludeProNames);
if (hasValue) return hasValue;
}
continue;
}
}else {
//class类型的遍历
PropertyDescriptor descriptor = new PropertyDescriptor(field.getName(), clazz);
Method method = descriptor.getReadMethod();
Object obj = method.invoke(object);
if (obj!= null){
hasValue = hasFieldValueThroughObj(obj,excludeProNames);
if (hasValue) return hasValue;
continue;
}
}
}
} catch (Exception e) {
System.err.println("err:" + e);
}
return hasValue;
}
/**
* 方法一:利用递归遍历
* 用途:从复杂对象中递归遍历,获取string类型的目标属性名的值
* 适用条件:该复杂对象中如果存在多个目标属性targetProName,遍历到第一个atargetProName则退出遍历
* targetProName属性必须是string
* targetProName可以存在自定义对象中、list、map、数组中
* 如果复杂对象不包含目标属性则返回空字符串
* 复杂对象可以是复杂嵌套的BO/List<BO>/Map<Object,BO>,目标属性存在于BO中
* 对于复杂对象是list或map嵌套的不做支持。比如List<List<BO></BO>> /List<Map<object,BO>> / Map<object,List<BO>>
* @param object 复杂对象
* @param targetProName 目标属性名
* @return
*/
public static Map<String,Object> recursionLoopThroughObj(Object object,String targetProName){
Map<String,Object> resultMap = new HashMap<>();
Class clazz = null;
String proValue = "";
boolean loopFlag = true;
resultMap.put("loopFlag",loopFlag);
resultMap.put("proValue",proValue);
try {
if (object==null || checkObjectIsSysType(object)){
//如果object是null/基本数据类型/包装类/日期类型,则不需要在递归调用
resultMap.put("loopFlag",false);
resultMap.put("proValue","");
return resultMap;
}
if (object instanceof Map){
Map map = (Map)object;
Map<String,Object> objMap = new HashMap<>();
if (map!=null && map.size()>0){
Iterator iterator = map.values().iterator();
while (iterator.hasNext()){
objMap = recursionLoopThroughObj(iterator.next(),targetProName);
if (!(boolean)objMap.get("loopFlag")){
return objMap;
}
}
}
}
clazz = object.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
String proType = field.getGenericType().toString();
String proName = field.getName();
System.err.println("proName:" + proName + ",proType:" + proType );
if ("class java.lang.String".equals(proType) && targetProName.equals(proName)){
field.setAccessible(true);
proValue = (String)field.get(object);
resultMap.put("loopFlag",false);
resultMap.put("proValue",proValue);
return resultMap;
}else if ("byte".equals(proType) || "short".equals(proType) || "int".equals(proType)|| "long".equals(proType)|| "double".equals(proType) || "float".equals(proType) || "boolean".equals(proType) ){
//属性是基本类型跳过
continue;
}else if ("class java.lang.Byte".equals(proType) || "class java.lang.Short".equals(proType) || "class java.lang.Integer".equals(proType) || "class java.lang.Long".equals(proType) || "class java.lang.Double".equals(proType) || "class java.lang.Float".equals(proType) || "class java.lang.Boolean".equals(proType) || ("class java.lang.String".equals(proType) && !targetProName.equals(proName))){
//属性是包装类跳过
continue;
}else if (proType.startsWith("java.util")){
//属性是集合类型则遍历
if (proType.startsWith("java.util.List")){
//对List类型的属性遍历
PropertyDescriptor descriptor = new PropertyDescriptor(field.getName(), clazz);
Method method = descriptor.getReadMethod();
List list = (List)method.invoke(object);
Map<String,Object> objMap = new HashMap<>();
if (list!=null && list.size()>0){
int len = list.size();
for (int i= 0;i<len;i++){
objMap = recursionLoopThroughObj(list.get(i),targetProName);
if (!(boolean)objMap.get("loopFlag")){
return objMap;
}
}
}
}else if (proType.startsWith("java.util.Map")){
//对Map类型的属性遍历
PropertyDescriptor descriptor = new PropertyDescriptor(field.getName(), clazz);
Method method = descriptor.getReadMethod();
Map map = (Map)method.invoke(object);
Map<String,Object> objMap = new HashMap<>();
if (map!=null && map.size()>0){
for (Object obj : map.values()){
objMap = recursionLoopThroughObj(obj,targetProName);
if (!(boolean)objMap.get("loopFlag")){
return objMap;
}
}
}
}
}else if(field.getType().isArray()){
//属性是数组类型则遍历
field.setAccessible(true);
Object[] objArr = (Object[]) field.get(object);
Map<String,Object> objMap = new HashMap<>();
if (objArr!=null && objArr.length>0){
for (Object arr : objArr){
objMap = recursionLoopThroughObj(arr,targetProName);
if (!(boolean)objMap.get("loopFlag")){
return objMap;
}
}
}
}else {
//class类型的遍历
PropertyDescriptor descriptor = new PropertyDescriptor(field.getName(), clazz);
Method method = descriptor.getReadMethod();
Object obj = method.invoke(object);
Map<String,Object> objMap = new HashMap<>();
if (obj!= null){
objMap = recursionLoopThroughObj(obj,targetProName);
if (!(boolean)objMap.get("loopFlag")){
return objMap;
}
}else {
continue;
}
}
}
} catch (Exception e) {
System.err.println("err:" + e);
}
return resultMap;
}
/**
* 检查object是否为java的基本数据类型/包装类/java.util.Date/java.sql.Date
* @param object
* @return
*/
public static boolean checkObjectIsSysType(Object object){
String objType = object.getClass().toString();
if ("byte".equals(objType) || "short".equals(objType) || "int".equals(objType)|| "long".equals(objType)|| "double".equals(objType) || "float".equals(objType) || "boolean".equals(objType)){
return true;
}else if ("class java.lang.Byte".equals(objType) || "class java.lang.Short".equals(objType) || "class java.lang.Integer".equals(objType) || "class java.lang.Long".equals(objType) || "class java.lang.Double".equals(objType) || "class java.lang.Float".equals(objType) || "class java.lang.Boolean".equals(objType) || "class java.lang.String".equals(objType)){
return true;
}else {
return false;
}
}
/**
* 方法二:从复杂对象中获取string类型的目标属性targetProName的值
* 把对象转换成json字符串,然后截取第一次出现的targetProName的值
* 适用条件:同方法一
* @param object 复杂对象
* @param targetProName 目标属性
* @return
*/
public static String getBusinessNoFromArg(Object object,String targetProName){
String jsonString = JSON.toJSONString(object);
System.err.println("jsonString=" + jsonString);
jsonString = StringUtils.substringAfter(jsonString,"\""+targetProName + "\":\"");
jsonString = StringUtils.substringBefore(jsonString,"\"");
return jsonString;
}
}
......@@ -75,9 +75,9 @@ public class SysUserFileRecordServiceImpl implements ISysUserFileRecordService
return AjaxResult.error("回调参数异常:"+object.toString());
}
SysUserFileRecord fileRecord = new SysUserFileRecord();
fileRecord.setId((Long) object.get("uniqueCode"));
fileRecord.setId( Long.valueOf(object.get("uniqueCode").toString()));
fileRecord.setUrl(object.get("url").toString());
fileRecord.setType(0);
fileRecord.setStatus(0);
baseMapper.updateById(fileRecord);
log.info("导出回调成功:"+object.toString());
return AjaxResult.success();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment