Commit 04b03e88 by wangnb

包活干V2.3.0开发--think.wang

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@30366 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent a31eaa70
package com.glsx.ordercenter.dto.req;
import lombok.Data;
import lombok.ToString;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import java.io.Serializable;
@Data
@ToString
public class MsCheBaseReq implements Serializable {
private static final long serialVersionUID = -3797872999933403874L;
@NotBlank(message = "type不能为空", groups={Default.class})
private String type;
@NotBlank(message = "appKey不能为空", groups={Default.class})
private String appKey;
@NotNull(message = "timestamp不能为空", groups={Default.class})
private Long timestamp;
@NotBlank(message = "sign不能为空", groups={Default.class})
private String sign;
@NotBlank(message = "data不能为空", groups={Default.class})
private String data;
}
package com.glsx.ordercenter.dto.resp;
import com.glsx.common.constants.ResultCodeEnum;
import java.io.Serializable;
public class MsResultObject implements Serializable {
private static final long serialVersionUID = 7310758466782300923L;
private Integer code = 0;
private String message;
private Object data;
public static MsResultObject of(ResultCodeEnum resultCodeEnum) {
return new MsResultObject(resultCodeEnum);
}
public static MsResultObject of(ResultCodeEnum resultCodeEnum, Object data) {
return new MsResultObject(resultCodeEnum, data);
}
public MsResultObject() {
}
/**
* @param code 返回码
*/
public MsResultObject(Integer code) {
super();
this.code = code;
}
/**
* @param code 返回码
* @param message 返回信息
*/
public MsResultObject(Integer code, String message) {
super();
this.code = code;
this.message = message;
}
/**
* @param code 返回码
* @param message 返回信息
* @param data 返回数据
*/
public MsResultObject(Integer code, String message, Object data) {
super();
this.code = code;
this.message = message;
this.data = data;
}
public MsResultObject(ResultCodeEnum resultCodeEnum) {
this.code = resultCodeEnum.getCode();
this.message = resultCodeEnum.getMsg();
}
public MsResultObject(ResultCodeEnum resultCodeEnum, Object data) {
this.code = resultCodeEnum.getCode();
this.message = resultCodeEnum.getMsg();
this.data = data;
}
public MsResultObject message(String msg) {
this.message = msg;
return this;
}
public static MsResultObject err(Integer returnCode) {
MsResultObject resultEntity = new MsResultObject();
resultEntity.setCode(returnCode);
resultEntity.setMessage("fail");
return resultEntity;
}
/**
* @param code 返回码
* @param message 返回信息
* @param data 返回数据
* @param error 服务器异常信息
*/
public MsResultObject(Integer code, String message, Object data, String error) {
super();
this.code = code;
this.message = message;
this.data = data;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
@Override
public String toString() {
return "MsResultObject{" +
"code=" + code +
", message='" + message + '\'' +
", data=" + data +
'}';
}
}
package com.glsx.ordercenter.utils;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.alibaba.fastjson.JSON;
import com.glsx.ordercenter.constants.BizConstants;
import com.glsx.ordercenter.constants.ResultCodeEnum;
import com.glsx.ordercenter.dto.req.DaSouCheBaseReq;
import com.glsx.ordercenter.dto.req.DaSouCheDevice;
import com.glsx.ordercenter.dto.req.DaSouCheInstallOrderReq;
import com.glsx.ordercenter.dto.req.DaSouCheRemoveDevice;
import com.glsx.ordercenter.dto.req.DaSouCheRemoveOrderReq;
import com.glsx.ordercenter.dto.req.DaSouCheRepairOrderReq;
import com.glsx.ordercenter.dto.req.MsFeedbackReq;
import com.glsx.ordercenter.dto.req.*;
import com.glsx.ordercenter.exception.DSCBusinessException;
import com.glsx.ordercenter.pojo.SysOrder;
import com.souche.api.SoucheApiException;
import com.souche.api.util.SoucheSignature;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
@Slf4j
public class MsSignUtil {
private static Logger logger = LoggerFactory.getLogger(MsSignUtil.class);
/**
* 同一批订单插入时间差,在此时间差内创建的订单认为是同一批
......@@ -54,13 +31,13 @@ public class MsSignUtil {
return msReq;
}
public static void checkSign(DaSouCheBaseReq msReq, String appSecret)
public static void checkSign(MsCheBaseReq msReq, String appSecret)
throws SoucheApiException {
Map<String, String> map = MsSignUtil.doGetSign(msReq);
String sign = SoucheSignature.sign(map, appSecret);
logger.info("saveOrder 系统签名#{}", sign);
if(!msReq.getSign().equals(sign)){
logger.info("saveOrder 系统签名错误");
log.info("民生易租传参系统签名: {}", sign);
if (!msReq.getSign().equals(sign)) {
log.info("民生易租传参系统签名错误");
throw DSCBusinessException.create(ResultCodeEnum.SING_ERROR.getCode(),
ResultCodeEnum.SING_ERROR.getMsg());
}
......@@ -68,13 +45,14 @@ public class MsSignUtil {
public static Map<String, String> doGetSign(Object base) {
Map<String, String> map = new HashMap<>();
javabeanToMap(base,map);
logger.info("======签名map=========" + map);
javabeanToMap(base, map);
log.info("============签名map=========" + map);
return map;
}
/**
* 把 java bean 转成 map
*
* @param bean
* @param result
* @return
......@@ -141,20 +119,17 @@ public class MsSignUtil {
result.put(key, String.valueOf(value));
}
}
} catch (Exception e) {
e.printStackTrace();
}
// 还原属性标识
field.setAccessible(accessible);
}
// 获取父类属性
fields = bean.getClass().getSuperclass().getDeclaredFields();
if (fields == null || fields.length == 0) {
return result;
}
for (Field field : fields) {
// 重置属性可见(而且一般属性都是私有的),否则操作无效
boolean accessible = field.isAccessible();
......@@ -184,196 +159,26 @@ public class MsSignUtil {
}
/**
* 比较两个时间的大小
* @param startDate
* @param endDate
* @param timeUnitType
* @return
*/
public static long getDifferenceBetweenTwoTime(Date startDate, Date endDate, MsSignUtil.TimeUnitType timeUnitType) {
long duration = endDate.getTime() - startDate.getTime();
if (timeUnitType != null) {
if (MsSignUtil.TimeUnitType.SECOND.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toSeconds(duration);
} else if (MsSignUtil.TimeUnitType.MINUTE.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toMinutes(duration);
} else if (MsSignUtil.TimeUnitType.HOUR.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toHours(duration);
} else if (MsSignUtil.TimeUnitType.DAY.value() == timeUnitType.value()) {
return TimeUnit.MILLISECONDS.toDays(duration);
}
}
return duration;
}
public enum TimeUnitType {
DAY(1), HOUR(2), MINUTE(3), SECOND(4);
private int value = 0;
TimeUnitType(int value) {
this.value = value;
}
public int value() {
return value;
}
}
public static String replaceBlank(String str) {
String dest = "";
if (str != null) {
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
Matcher m = p.matcher(str);
dest = m.replaceAll("");
}
return dest;
}
/**
* 复制属性,排除特殊字段(浅复制)
* @param source
* @param dest
* @param excludes
*/
public static void copyExclude(Object dest,Object source,String... excludes){
Class<?> sourceClass = source.getClass();
Class<?> destClass = dest.getClass();
try {
BeanInfo sourceBeanInfo = Introspector.getBeanInfo(sourceClass);
PropertyDescriptor[] propertyDescriptors = sourceBeanInfo.getPropertyDescriptors();
if(ArrayUtils.isEmpty(propertyDescriptors)) {
return ;
}
BeanInfo beanInfo = Introspector.getBeanInfo(destClass);
PropertyDescriptor[] destPropertyDescriptors = beanInfo.getPropertyDescriptors();
if(ArrayUtils.isEmpty(destPropertyDescriptors)){
return ;
}
//映射目标类属性和写方法
Map<String,PropertyDescriptor> destDescriptorMap = new HashMap<>();
for (PropertyDescriptor propertyDescriptor : destPropertyDescriptors) {
destDescriptorMap.put(propertyDescriptor.getName(), propertyDescriptor);
}
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
String name = propertyDescriptor.getName();
if(ArrayUtils.contains(excludes, name)){
continue;
}
Method readMethod = propertyDescriptor.getReadMethod();
if(readMethod == null){continue;}
readMethod.setAccessible(true);
//获取同名写方法
PropertyDescriptor destDescriptor = destDescriptorMap.get(name);
if(destDescriptor == null){
continue;
}
Method writeMethod = destDescriptor.getWriteMethod();
if(writeMethod == null){continue;}
writeMethod.setAccessible(true);
Object value = readMethod.invoke(source);
writeMethod.invoke(dest, value);
}
} catch (IntrospectionException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
/**
* 大搜车参数校验
* @param reqJsonStr
* @param object
* @return
*/
public static String validate(String reqJsonStr,Object object){
if(reqJsonStr==null||object==null){
}
Map<String, String> reqMap = (Map) JSON.parse(reqJsonStr);
StringBuffer res = new StringBuffer();
if(object instanceof String){
String param = (String)object;
String [] params = param.split(",");
for(int i=0;i<params.length;i++){
if(reqMap.get(params[i])==null){
res.append("参数"+params[i]+"不能为空;");
}
}
}else {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass(), Object.class);
Field[] fields = object.getClass().getFields();
for (Field field : fields){
Annotation[] fieldAnnotations= field.getAnnotations();
for (Annotation annotation : fieldAnnotations){
}
}
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
}
} catch (Exception e) {
e.printStackTrace();
}
}
return res.toString();
}
/**
* 通过键获取值的个数
* @param map
* @param value
* @return
*/
public static Integer getMapKey(Map map, Object value) {
List<Object> keyList = new ArrayList<>();
for (Object key : map.keySet()) {
if (map.get(key).equals(value)) {
keyList.add(key);
}
}
if (CollectionUtils.isNotEmpty(keyList)) {
return keyList.size();
}
return 0;
}
/**
* 验证安装单参数
*
* @param orderReq
* @return
*/
public static String valiateInstall(DaSouCheInstallOrderReq orderReq){
public static String validateInstall(DaSouCheInstallOrderReq orderReq) {
StringBuffer errorStr = new StringBuffer();
if(orderReq.getWirelessDevCount() == null){
if (orderReq.getWirelessDevCount() == null) {
errorStr.append("无源设备数量不能为空,");
}
if(orderReq.getWirelineDevCount() == null){
if (orderReq.getWirelineDevCount() == null) {
errorStr.append("有源设备数量不能为空,");
}
if(orderReq.getTinyWirelessDevCount() == null){
if (orderReq.getTinyWirelessDevCount() == null) {
errorStr.append("微型无源设备数量不能为空,");
}
if(orderReq.getOtherDevCount() == null){
if (orderReq.getOtherDevCount() == null) {
errorStr.append("其他设备数量不能为空,");
}
if(orderReq.getInstallMode() == null){
if (orderReq.getInstallMode() == null) {
errorStr.append("安装模式不能为空,");
}
return errorStr.toString();
......@@ -381,31 +186,32 @@ public class MsSignUtil {
/**
* 验证检修单参数
*
* @param repairOrderReq
* @return
*/
public static String valiateRepair(DaSouCheRepairOrderReq repairOrderReq) {
public static String validateRepair(DaSouCheRepairOrderReq repairOrderReq) {
List<DaSouCheDevice> devList = repairOrderReq.getDevList();
StringBuffer errorStr = new StringBuffer();
if(CollectionUtils.isNotEmpty(devList)){
for(DaSouCheDevice device : devList){
if(StringUtils.isBlank(device.getDevNo())){
if (CollectionUtils.isNotEmpty(devList)) {
for (DaSouCheDevice device : devList) {
if (StringUtils.isBlank(device.getDevNo())) {
errorStr.append("设备号不能为空,");
}
if(device.getDevType()==null){
if (device.getDevType() == null) {
errorStr.append("设备类型不能为空,");
}
if(device.getRepairType()==null){
if (device.getRepairType() == null) {
errorStr.append("检修类型不能为空,");
}
if(StringUtils.isBlank(device.getDevSupplier())){
if (StringUtils.isBlank(device.getDevSupplier())) {
errorStr.append("供应商不能为空,");
}
if(device.getRepairType()!= BizConstants.ORDER_REPAIR_ADD){
if(StringUtils.isBlank(device.getInstallConfirm())){
if (device.getRepairType() != BizConstants.ORDER_REPAIR_ADD) {
if (StringUtils.isBlank(device.getInstallConfirm())) {
errorStr.append("安装确认不能为空,");
}
if(StringUtils.isBlank(device.getDevPosition())){
if (StringUtils.isBlank(device.getDevPosition())) {
errorStr.append("安装位置不能为空,");
}
}
......@@ -416,27 +222,28 @@ public class MsSignUtil {
/**
* 验证拆除单参数
*
* @param removeOrderReq
* @return
*/
public static String valiateRemove(DaSouCheRemoveOrderReq removeOrderReq) {
public static String validateRemove(DaSouCheRemoveOrderReq removeOrderReq) {
List<DaSouCheRemoveDevice> devList = removeOrderReq.getDevList();
StringBuffer errorStr = new StringBuffer();
if(CollectionUtils.isNotEmpty(devList)){
for(DaSouCheRemoveDevice device : devList){
if(StringUtils.isBlank(device.getDevNo())){
if (CollectionUtils.isNotEmpty(devList)) {
for (DaSouCheRemoveDevice device : devList) {
if (StringUtils.isBlank(device.getDevNo())) {
errorStr.append("设备号不能为空,");
}
if(device.getDevType()==null){
if (device.getDevType() == null) {
errorStr.append("设备类型不能为空,");
}
if(StringUtils.isBlank(device.getDevPosition())){
if (StringUtils.isBlank(device.getDevPosition())) {
errorStr.append("安装位置不能为空,");
}
if(StringUtils.isBlank(device.getDevSupplier())){
if (StringUtils.isBlank(device.getDevSupplier())) {
errorStr.append("供应商不能为空,");
}
if(StringUtils.isBlank(device.getInstallConfirm())){
if (StringUtils.isBlank(device.getInstallConfirm())) {
errorStr.append("安装确认不能为空,");
}
}
......@@ -446,8 +253,8 @@ public class MsSignUtil {
/**
* <p>根据第三方工单号获取最新的一批订单。
* <p>大搜车生成审核驳回单的时候会生成新的工单,而大搜车传过来的工单号对应系统中的多个订单,
* 因此在检修、安装等完毕然后反馈给大搜车的时候,需要过滤掉之前被驳回的工单。
* <p>民生易租生成审核驳回单的时候会生成新的工单,而民生易租传过来的工单号对应系统中的多个订单,
* 因此在检修、安装等完毕然后反馈给民生易租的时候,需要过滤掉之前被驳回的工单。
* <p>过滤方法是工单号查出所有对应的订单,然后按照时间判断,如果某一批订单插入时间在20秒以内,
* 则认为是关联的订单。
*
......@@ -458,11 +265,9 @@ public class MsSignUtil {
List<SysOrder> filteredOrderList = new ArrayList<>();
// 按照生成时间倒序排列
orderList.sort(Comparator.comparing(SysOrder::getCreateTime).reversed());
if (CollectionUtils.isNotEmpty(orderList)) {
// 获取最新的订单生成时间
long latestMs = orderList.get(0).getCreateTime().getTime();
for (SysOrder order : orderList) {
long currentMs = order.getCreateTime().getTime();
// 判断当前订单生成时间和最新的时间相差是否不到20秒
......@@ -475,7 +280,6 @@ public class MsSignUtil {
}
}
}
return filteredOrderList;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!