Commit 3d49e13a authored by 周健威's avatar 周健威

修改问题

parent e77b9fb8
package com.github.wxiaoqi.security.common.util;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.mockito.internal.util.collections.Sets;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_FALSE;
import static com.github.wxiaoqi.security.common.constant.CommonConstants.SYS_JSON_TRUE;
@Slf4j
public class AssertUtils {
public static<T> T isBlank(T object, BaseException baseException, String name) throws BaseException {
log.info(" AssertUtils.isBlank : {}", object);
if(object instanceof Collection) {
if (CollUtil.isEmpty((List)object)) {
throwException(baseException, name);
}
}else if (object == null) {
throwException(baseException, name);
}
return object;
}
public static<T> T isNotBlank(T object, BaseException baseException, String name) throws BaseException {
log.info(" AssertUtils.isNotBlank : {}", object);
if (object != null ) {
//如果是集合 并且 为空 着不抛异常
if (object instanceof Collection && CollUtil.isEmpty((List)object)) {
return object;
}else {
throwException(baseException, name);
}
}
return object;
}
public static<T> T isBlank(T object, BaseException baseException) throws BaseException {
return isBlank(object, baseException, null);
}
public static<T> T isNotBlank(T object, BaseException baseException) throws BaseException {
return isNotBlank(object, baseException, null);
}
public static void isBlankMulti(Object... objects) throws BaseException {
log.info(" AssertUtils.isBlank : {}", objects);
isBlank(objects);
for (Object object : objects) {
isBlank(object);
}
}
// public static void isEqual(Object a, Object b, BaseException bex) throws BaseException {
// log.info(" AssertUtils.isEqual : {} {}", a, b);
// if(a.equals(b)) {
// if(null != bex) {
// throw new BaseException(ResultCode.DB_OPERATION_FAIL_CODE);
// }else {
// throw bex;
// }
// }
// }
public static<T> T isBlank(T object) throws BaseException {
return isBlank(object, null, null);
}
public static<T> T isBlankBean(T object) throws BaseException {
Map<String, Object> beanMap = BeanUtil.beanToMap(object);
isBlank(object);
for(String key : beanMap.keySet()) {
isBlank(beanMap.get(key), null, null);
}
return object;
}
public static<T> T isBlank(T object, String attrName) throws BaseException {
return isBlank(object, null, attrName);
}
public static Integer isDBSucc(Integer flag, BaseException baseException) throws BaseException {
log.info(" AssertUtils.isDBSucc : {}", flag);
if(SYS_FALSE.equals(flag)) {
throwDBException(baseException);
}
return flag;
}
public static Integer isDBSucc(Integer flag) throws BaseException {
return isDBSucc(flag, null);
}
public static<T> ObjectRestResponse<T> isFeignSucc(ObjectRestResponse<T> orr) throws BaseException {
log.info(" AssertUtils.isFeignSucc : {}", orr);
if(!SYS_JSON_TRUE.equals(orr.getStatus())) {
throw new BaseException(orr.getMessage(), orr.getStatus());
}
return orr;
}
public static<T,E> ObjectRestResponse<T> isFeignSuccGetObj(E dto, Function<Map, ObjectRestResponse<T>> function) throws BaseException {
log.info(" AssertUtils.isFeignSucc : {}", dto);
ObjectRestResponse<T> orr = function.apply(DepthBeanToMap.objectToMap(dto));
//ObjectRestResponse<T> orr = function.apply( BeanUtil.beanToMap(dto, false, false));
if(!SYS_JSON_TRUE.equals(orr.getStatus())) {
throw new BaseException(orr.getMessage(), orr.getStatus());
}
return orr;
}
public static<T,E> List<T> isFeignSuccGetDataList(E dto, Function<Map, ObjectRestResponse<List<T>>> function, Class<T> tClass) throws BaseException {
log.info(" AssertUtils.isFeignSucc : {}", dto);
ObjectRestResponse<List<T>> orr = function.apply(DepthBeanToMap.objectToMap(dto));
//ObjectRestResponse<List<T>> orr = function.apply(BeanUtil.beanToMap(dto, false, false));
if(!SYS_JSON_TRUE.equals(orr.getStatus())) {
throw new BaseException(orr.getMessage(), orr.getStatus());
}
orr.setData(orr.getData().parallelStream().map(t -> BeanUtil.toBean(t, tClass)).collect(Collectors.toList()));
return orr.getData();
}
public static<T,E> T isFeignSuccGetData(E dto, Function<Map, ObjectRestResponse<T>> function) throws BaseException {
return isFeignSuccGetObj(dto, function).getData();
}
private static void throwException(BaseException baseException, String name) {
if(null != baseException) {
throw baseException;
}else {
throw new BaseException(ResultCode.NOTEXIST_CODE, Sets.newSet(name));
}
}
private static void throwDBException(BaseException baseException) {
if(null != baseException) {
throw baseException;
}else {
throw new BaseException(ResultCode.DB_OPERATION_FAIL_CODE);
}
}
}
\ No newline at end of file
package com.github.wxiaoqi.security.common.util;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class DepthBeanToMap {
public static Map objectToMap(Object obj){
try{
Class type = obj.getClass();
Map returnMap = new HashMap();
BeanInfo beanInfo = Introspector.getBeanInfo(type);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i< propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i];
String propertyName = descriptor.getName();
if (!propertyName.equals("class")) {
Method readMethod = descriptor.getReadMethod();
Object result = readMethod.invoke(obj, new Object[0]);
if(result == null){
continue;
}
//判断是否为 基础类型 String,Boolean,Byte,Short,Integer,Long,Float,Double
//判断是否集合类,COLLECTION,MAP
if(result instanceof String
|| result instanceof Boolean
|| result instanceof Byte
|| result instanceof Short
|| result instanceof Integer
|| result instanceof Long
|| result instanceof Float
|| result instanceof Double
|| result instanceof Enum
){
if (result != null) {
returnMap.put(propertyName, result);
}
}else if(result instanceof Collection){
Collection<?> lstObj = arrayToMap((Collection<?>)result);
returnMap.put(propertyName, lstObj);
}else if(result instanceof Map){
Map<Object,Object> lstObj = mapToMap((Map<Object,Object>)result);
returnMap.put(propertyName, lstObj);
} else {
Map mapResult = objectToMap(result);
returnMap.put(propertyName, mapResult);
}
}
}
return returnMap;
}catch(Exception e){
throw new RuntimeException(e);
}
}
private static Map<Object, Object> mapToMap(Map<Object, Object> orignMap) {
Map<Object,Object> resultMap = new HashMap<Object,Object>();
for(Map.Entry<Object, Object> entry:orignMap.entrySet()){
Object key = entry.getKey();
Object resultKey = null;
if(key instanceof Collection){
resultKey = arrayToMap((Collection)key);
}else if(key instanceof Map){
resultKey = mapToMap((Map)key);
}
else{
if(key instanceof String
|| key instanceof Boolean
|| key instanceof Byte
|| key instanceof Short
|| key instanceof Integer
|| key instanceof Long
|| key instanceof Float
|| key instanceof Double
|| key instanceof Enum
){
if (key != null) {
resultKey = key;
}
}else{
resultKey = objectToMap(key);
}
}
Object value = entry.getValue();
Object resultValue = null;
if(value instanceof Collection){
resultValue = arrayToMap((Collection)value);
}else if(value instanceof Map){
resultValue = mapToMap((Map)value);
}
else{
if(value instanceof String
|| value instanceof Boolean
|| value instanceof Byte
|| value instanceof Short
|| value instanceof Integer
|| value instanceof Long
|| value instanceof Float
|| value instanceof Double
|| value instanceof Enum
){
if (value != null) {
resultValue = value;
}
}else{
resultValue = objectToMap(value);
}
}
resultMap.put(resultKey, resultValue);
}
return resultMap;
}
private static Collection arrayToMap(Collection lstObj){
ArrayList arrayList = new ArrayList();
for (Object t : lstObj) {
if(t instanceof Collection){
Collection result = arrayToMap((Collection)t);
arrayList.add(result);
}else if(t instanceof Map){
Map result = mapToMap((Map)t);
arrayList.add(result);
} else {
if(t instanceof String
|| t instanceof Boolean
|| t instanceof Byte
|| t instanceof Short
|| t instanceof Integer
|| t instanceof Long
|| t instanceof Float
|| t instanceof Double
|| t instanceof Enum
){
if (t != null) {
arrayList.add(t);
}
}else{
Object result = objectToMap(t);
arrayList.add(result);
}
}
}
return arrayList;
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.upyuns.platform.rs</groupId>
<artifactId>rs-datacenter-api</artifactId>
<version>2.0-rscp-SNAPSHOT</version>
......
......@@ -9,11 +9,12 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.upyuns.platform.rs</groupId>
<artifactId>rs-datacenter-server</artifactId>
<dependencies>
<dependency>
<groupId>com.upyuns.common</groupId>
<groupId>com.upyuns.platform.rs</groupId>
<artifactId>rs-datacenter-api</artifactId>
<version>2.0-rscp-SNAPSHOT</version>
<scope>compile</scope>
......
......@@ -2,6 +2,7 @@ package com.upyuns.platform.rs.datacenter.biz;
import cn.hutool.core.collection.CollUtil;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.upyuns.platform.rs.datacenter.entity.RscpAreaImageTotal;
import com.upyuns.platform.rs.datacenter.entity.RscpImageDataTotal;
import com.upyuns.platform.rs.datacenter.mapper.RscpImageDataTotalMapper;
import com.upyuns.platform.rs.datacenter.rest.RscpImageDataTotalController;
......@@ -16,5 +17,17 @@ public class RscpImageDataTotalBiz extends BaseBiz<RscpImageDataTotalMapper, Rsc
return mapper.queryDataList(dto);
}
// public List<RscpAreaImageTotal> queryDataList(RscpImageDataTotalController.QueryDTO dto) {
// List<RscpImageDataTotal> list = mapper.queryDataList(dto);
// List<RscpAreaImageTotal> list2 = CollUtil.newArrayList();
// if(CollUtil.isNotEmpty(list)) {
// list.forEach(to -> {
// to.getC
// return ;
// });
// }
// return mapper.queryDataList(dto);
// }
}
......@@ -36,4 +36,10 @@ public class RscpAreaInfoController extends BaseController<RscpAreaInfoBiz, Rscp
public ObjectRestResponse<RscpAreaInfo> queryAreaInfoByAreaId(String areaCode) {
return ObjectRestResponse.succ( baseBiz.queryAreaInfoByAreaId(areaCode));
}
@RequestMapping(value = "/app/unauth/Fegin/queryByCodeFegin", method = RequestMethod.GET)
@IgnoreUserToken
public ObjectRestResponse<RscpAreaInfo> queryByCode(String areaCode) {
return ObjectRestResponse.succ( baseBiz.queryAreaInfoByAreaId(areaCode));
}
}
\ No newline at end of file
......@@ -64,7 +64,7 @@
</foreach>
</if>
<if test="resolution != null">
and #{image_resolution} = any(image_resolution)
and #{resolution} = any(image_resolution)
</if>
<if test="startDateTime != null">
and begin_time &gt;= #{startDateTime}
......
......@@ -113,7 +113,7 @@
</foreach>
</if>
<if test="resolution != null">
and #{image_resolution} = any(image_resolution)
and #{resolution} = any(image_resolution)
</if>
<if test="startDateTime != null">
and image_take_time &gt;= #{startDateTime}
......
......@@ -24,6 +24,13 @@
<version>2.0-rscp-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.upyuns.platform.rs</groupId>
<artifactId>rs-datacenter-api</artifactId>
<version>2.0-rscp-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
......
package com.upyuns.platform.rs.website.controller.web;
import cn.hutool.core.util.StrUtil;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.util.AssertUtils;
import com.upyuns.platform.rs.datacenter.fegin.DatacenterFeign;
import com.upyuns.platform.rs.website.biz.CustomFormBiz;
import com.upyuns.platform.rs.website.entity.CustomForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -13,8 +17,14 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("customForm/web")
public class CustomFormWebController extends BaseController<CustomFormBiz,CustomForm> {
@Autowired
DatacenterFeign datacenterFegin;
@RequestMapping(value = "customIndustry",method = RequestMethod.POST)
public ObjectRestResponse customIndustry(@RequestBody CustomForm entity) {
// if(StrUtil.isNotBlank(entity.getProvinceCode())) {
// entity.setProvinceName(AssertUtils.isFeignSucc(datacenterFegin.queryByCode(entity.getProvinceCode()).getData());
// }
baseBiz.insertSelective(entity);
return ObjectRestResponse.succ();
}
......
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