Commit 343853dc by huzhenkun

Merge branch 'master' of http://begitlab.chubanyun.me/rays/pcloud-common-parent into hzk

parents fb4b6933 d45e4c47
...@@ -94,4 +94,7 @@ product.parentTutor.proLabelId = 7461 ...@@ -94,4 +94,7 @@ product.parentTutor.proLabelId = 7461
book.group.qrcode.domain = https://qrcode.5rs.me book.group.qrcode.domain = https://qrcode.5rs.me
ownAgentIds = 2,1362 ownAgentIds = 2,1362
\ No newline at end of file
## \u9519\u9898\u672C\u73AF\u5883\u57DF\u540D
papercut.domain = papercut.5rs.me
\ No newline at end of file
...@@ -95,4 +95,7 @@ product.parentTutor.proLabelId = 812 ...@@ -95,4 +95,7 @@ product.parentTutor.proLabelId = 812
book.group.qrcode.domain = https://qrcode.raysyun.com book.group.qrcode.domain = https://qrcode.raysyun.com
ownAgentIds = 12829 ownAgentIds = 12829
\ No newline at end of file
## \u9519\u9898\u672C\u73AF\u5883\u57DF\u540D
papercut.domain = papercut.raysyun.com
\ No newline at end of file
/** /**
* *
*/ */
package com.pcloud.common.core.aspect; package com.pcloud.common.core.aspect;
...@@ -20,7 +20,6 @@ import com.alibaba.fastjson.JSON; ...@@ -20,7 +20,6 @@ import com.alibaba.fastjson.JSON;
import com.pcloud.common.utils.string.StringUtil; import com.pcloud.common.utils.string.StringUtil;
/** /**
*
* @author:songx * @author:songx
* @date:2018年4月26日,下午2:32:36 * @date:2018年4月26日,下午2:32:36
*/ */
...@@ -28,79 +27,80 @@ import com.pcloud.common.utils.string.StringUtil; ...@@ -28,79 +27,80 @@ import com.pcloud.common.utils.string.StringUtil;
@Configuration @Configuration
public class ParamLogAspect { public class ParamLogAspect {
/** /**
* *
*/ */
private final static Logger LOGGER = LoggerFactory.getLogger(""); private final static Logger LOGGER = LoggerFactory.getLogger("");
@Pointcut("execution(* com.pcloud..*(..))") @Pointcut("execution(* com.pcloud..*(..))")
public void bizPoint() { public void bizPoint() {
} }
/** /**
* 方法执行前以后执行 * 方法执行前以后执行
* *
* @param joinPoint * @param joinPoint
*/ */
@Before("bizPoint()") @Before("bizPoint()")
public void doBefore(JoinPoint joinPoint) { public void doBefore(JoinPoint joinPoint) {
ParamLog paramLog = checkAnnotation(joinPoint); ParamLog paramLog = checkAnnotation(joinPoint);
if (paramLog == null) { if (paramLog == null) {
return; return;
} }
Signature signature = joinPoint.getSignature(); Signature signature = joinPoint.getSignature();
String methodName = signature.getName(); String methodName = signature.getName();
String description = paramLog.description(); String description = paramLog.description();
description = StringUtil.isEmpty(description) ? paramLog.value() : description; description = StringUtil.isEmpty(description) ? paramLog.value() : description;
StringBuffer msg = new StringBuffer(signature.getDeclaringTypeName()).append(" 【" + methodName + " before】"); StringBuffer msg = new StringBuffer(signature.getDeclaringTypeName()).append(" 【" + methodName + " before】");
if (!StringUtil.isEmpty(description)) { if (!StringUtil.isEmpty(description)) {
msg.append(description); msg.append(description);
} }
if (!paramLog.isBefore()) { if (!paramLog.isBefore()) {
LOGGER.info(msg.toString()); LOGGER.info(msg.toString());
} else { } else {
String argsJson = JSON.toJSONString(joinPoint.getArgs()); String argsJson = JSON.toJSONString(joinPoint.getArgs());
LOGGER.info(msg.append(",[Args]=").append(argsJson).toString()); LOGGER.info(msg.append(",[Args]=").append(argsJson).toString());
} }
} }
/** /**
* 方法执行完以后执行 * 方法执行完以后执行
* *
* @param object * @param joinPoint
*/ * @param result
@AfterReturning(pointcut = "bizPoint()", returning = "result") */
public void doAfterReturn(JoinPoint joinPoint, Object result) { @AfterReturning(pointcut = "bizPoint()", returning = "result")
ParamLog paramLog = checkAnnotation(joinPoint); public void doAfterReturn(JoinPoint joinPoint, Object result) {
if (paramLog == null) { ParamLog paramLog = checkAnnotation(joinPoint);
return; if (paramLog == null) {
} return;
Signature signature = joinPoint.getSignature(); }
String methodName = signature.getName(); Signature signature = joinPoint.getSignature();
String description = paramLog.description(); String methodName = signature.getName();
description = StringUtil.isEmpty(description) ? paramLog.value() : description; String description = paramLog.description();
StringBuffer msg = new StringBuffer(signature.getDeclaringTypeName()) description = StringUtil.isEmpty(description) ? paramLog.value() : description;
.append(" 【" + methodName + " afterReturn】"); StringBuffer msg = new StringBuffer(signature.getDeclaringTypeName())
if (!StringUtil.isEmpty(description)) { .append(" 【" + methodName + " afterReturn】");
msg.append(description); if (!StringUtil.isEmpty(description)) {
} msg.append(description);
if (!paramLog.isAfterReturn()) { }
LOGGER.info(msg.toString()); if (!paramLog.isAfterReturn()) {
} else { LOGGER.info(msg.toString());
String resultJson = JSON.toJSONString(result); } else {
LOGGER.info(msg.append(",[result]=").append(resultJson).toString()); String resultJson = JSON.toJSONString(result);
} LOGGER.info(msg.append(",[result]=").append(resultJson).toString());
} }
}
private static ParamLog checkAnnotation(JoinPoint joinPoint) { private static ParamLog checkAnnotation(JoinPoint joinPoint) {
// 获取方法签名 // 获取方法签名
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); MethodSignature signature = (MethodSignature) joinPoint.getSignature();
// java reflect相关类,通过反射得到注解 // java reflect相关类,通过反射得到注解
Method method = signature.getMethod(); Method method = signature.getMethod();
if (!method.isAnnotationPresent(ParamLog.class)) { if (!method.isAnnotationPresent(ParamLog.class)) {
return null; return null;
} }
return method.getAnnotation(ParamLog.class); return method.getAnnotation(ParamLog.class);
} }
} }
...@@ -72,7 +72,7 @@ public enum AppTypeEnum { ...@@ -72,7 +72,7 @@ public enum AppTypeEnum {
/** /**
* 直播 * 直播
*/ */
LIVE("live", com.pcloud.common.core.enums.AppTypeEnum.LIVE.value), LIVE("live", com.pcloud.common.core.enums.AppTypeEnum.LIVE_TIMETABLE.value),
/** /**
* 打卡 * 打卡
...@@ -147,7 +147,13 @@ public enum AppTypeEnum { ...@@ -147,7 +147,13 @@ public enum AppTypeEnum {
/** /**
* 英语随身听 * 英语随身听
*/ */
ENGLISH_WALKMAN("wm", com.pcloud.common.core.enums.AppTypeEnum.ENGLISH_WALKMAN.value); ENGLISH_WALKMAN("wm", com.pcloud.common.core.enums.AppTypeEnum.ENGLISH_WALKMAN.value),
/**
* 口语评测
*/
ORAL_EVALUATION("speak", com.pcloud.common.core.enums.AppTypeEnum.ORAL_EVALUATION.value);
/** /**
* 值 * 值
......
...@@ -11,10 +11,10 @@ package com.pcloud.common.core.constant; ...@@ -11,10 +11,10 @@ package com.pcloud.common.core.constant;
*/ */
public class MQTopicProducer { public class MQTopicProducer {
/** /**
* 文件转码结束(PDF、EXCEL) * 文件转码结束(PDF、EXCEL)
*/ */
public static final String FILE_TRANSCODE = "topic.fileTranscode"; public static final String FILE_TRANSCODE = "topic.fileTranscode";
/** /**
* 音频配音结束(MP3) * 音频配音结束(MP3)
...@@ -26,257 +26,259 @@ public class MQTopicProducer { ...@@ -26,257 +26,259 @@ public class MQTopicProducer {
*/ */
public static final String BM_ADD_USER = "topic.bmAddUser"; public static final String BM_ADD_USER = "topic.bmAddUser";
/** /**
* 应用新增 * 应用新增
*/ */
public static final String APP_ADD = "topic.appAdd"; public static final String APP_ADD = "topic.appAdd";
/** /**
* 应用修改 * 应用修改
*/ */
public static final String APP_UPDATE = "topic.appUpdate"; public static final String APP_UPDATE = "topic.appUpdate";
/** /**
* 应用删除 * 应用删除
*/ */
public static final String APP_DELETE = "topic.appDelete"; public static final String APP_DELETE = "topic.appDelete";
/** /**
* 应用删除(新) * 应用删除(新)
*/ */
public static final String APP_DELETE_NEW = "topic.appDeleteNew"; public static final String APP_DELETE_NEW = "topic.appDeleteNew";
/** /**
* 应用审核 * 应用审核
*/ */
public static final String APP_AUDIT = "topic.appAudit"; public static final String APP_AUDIT = "topic.appAudit";
/** /**
* 选择默认渠道 * 选择默认渠道
*/ */
public static final String CHOOSE_DEFAULT_CHANNEL = "topic.chooseDefaultChannel"; public static final String CHOOSE_DEFAULT_CHANNEL = "topic.chooseDefaultChannel";
/** /**
* 删除视频 * 删除视频
*/ */
public static final String DELETE_VIDEO = "topic.deleteVideo"; public static final String DELETE_VIDEO = "topic.deleteVideo";
/** /**
* 标签修改 * 标签修改
*/ */
public static final String LABEL_UPDATE = "topic.labelUpdate"; public static final String LABEL_UPDATE = "topic.labelUpdate";
/** /**
* 支付 * 支付
*/ */
public static final String PAYMENT = "topic.payment"; public static final String PAYMENT = "topic.payment";
/** /**
* TIP * TIP
*/ */
public static final String TIP = "topic.tip"; public static final String TIP = "topic.tip";
/** /**
* 打赏给读者 * 给读者的打赏
*/ */
public static final String TIP_FOR_WECHAT_USER = "topic.tipForWechatUser"; public static final String TIP_FOR_WECHAT_USER = "topic.tipForWechatUser";
/** /**
* GENUINE * GENUINE
*/ */
public static final String GENUINE = "topic.genuine"; public static final String GENUINE = "topic.genuine";
/**
* 订单完成
*/
public static final String FINISH_ORDER = "topic.finishOrder";
/**
* 资源修改
*/
public static final String RESOURCE_UPDATE = "topic.resourceUpdate";
/**
* 资源删除
*/
public static final String RESOURCE_DELETE = "topic.resourceDelete";
/**
* 扫码记录
*/
public static final String SCAN_RECORD = "topic.scanRecord";
/**
* 图书删除
*/
public static final String BOOK_DELETE = "topic.bookDelete";
/**
* BOOKTHAW
*/
public static final String BOOK_THAW = "topic.bookThaw";
/**
* TEMPLETAPPCREATE
*/
public static final String TEMPLET_APP_CREATE = "topic.templetAppCreate";
/**
* PERMISSION
*/
public static final String PERMISSION = "topic.permission";
/**
* PROMOTION_EXPIRE
*/
public static final String PROMOTION_EXPIRE = "topic.promotionExpire";
/**
* 商品修改
*/
public static final String PRODUCT_UPDATE = "topic.productUpdate";
/**
* 商品删除
*/
public static final String PRODUCT_DELETE = "topic.productDelete";
/**
* 商品审核
*/
public static final String PRODUCT_AUDIT = "topic.productAudit";
/**
* 商品图片1修改
*/
public static final String PRODUCT_PIC1_UPDATE = "topic.productPic1Update";
/**
* 用户注册
*/
public static final String REGISTER_PARTY = "topic.registerParty";
/**
* 用户修改
*/
public static final String UPDATE_PARTY = "topic.updateParty";
/**
* 问答确认
*/
public static final String QA_ASK = "topic.qaAsk";
/** /**
* 订单完成 * 问答完成
*/ */
public static final String FINISH_ORDER = "topic.finishOrder"; public static final String QA_FINISH = "topic.qaFinish";
/** /**
* 资源修改 * 问答答案
*/ */
public static final String RESOURCE_UPDATE = "topic.resourceUpdate"; public static final String QA_ANSWER = "topic.qaAnswer";
/** /**
* 资源删除 * 问答取消
*/ */
public static final String RESOURCE_DELETE = "topic.resourceDelete"; public static final String QA_REFUSE = "topic.qaRefuse";
/** /**
* 扫码记录 * QR_MESSAGE_UPDATE
*/ */
public static final String SCAN_RECORD = "topic.scanRecord"; public static final String QR_MESSAGE_UPDATE = "topic.qrMessageUpdate";
/** /**
* 图书删除 * GIVE_GIFT
*/ */
public static final String BOOK_DELETE = "topic.bookDelete"; public static final String GIVE_GIFT = "topic.giveGift";
/** /**
* BOOKTHAW * 修改密码
*/ */
public static final String BOOK_THAW = "topic.bookThaw"; public static final String UPDATE_PWD = "topic.updatePwd";
/** /**
* TEMPLETAPPCREATE * 管理消息
*/ */
public static final String TEMPLET_APP_CREATE = "topic.templetAppCreate"; public static final String MANAGE_MESSAGE = "topic.manageMessage";
/** /**
* PERMISSION * RETURN_4_ADVISER
*/ */
public static final String PERMISSION = "topic.permission"; public static final String RETURN_4_ADVISER = "topic.return4adviser";
/** /**
* PROMOTION_EXPIRE * 退款
*/ */
public static final String PROMOTION_EXPIRE = "topic.promotionExpire"; public static final String REFUND = "topic.refund";
/** /**
* 商品修改 * 退货
*/ */
public static final String PRODUCT_UPDATE = "topic.productUpdate"; public static final String REFUND_PRODUCT = "topic.refundProduct";
/** /**
* 商品删除 * 发货
*/ */
public static final String PRODUCT_DELETE = "topic.productDelete"; public static final String SEND_PRODUCT = "topic.sendProduct";
/** /**
* 商品审核 * 确认收货
*/ */
public static final String PRODUCT_AUDIT = "topic.productAudit"; public static final String CONFIRM_ORDER = "topic.confirmOrder";
/** /**
* 商品图片1修改 * 申请退货
*/ */
public static final String PRODUCT_PIC1_UPDATE = "topic.productPic1Update"; public static final String APPLY_REFUND_PRODUCT = "topic.applyRefundProduct";
/** /**
* 用户注册 * 取消订单
*/ */
public static final String REGISTER_PARTY = "topic.registerParty"; public static final String CANCEL_ORDER = "topic.cancelOrder";
/** /**
* 用户修改 * 模板二维码扫描
*/ */
public static final String UPDATE_PARTY = "topic.updateParty"; public static final String TEMP_QRCODE_SCAN = "topic.tempQrcodeScan";
/** /**
* 问答确认 * 删除二维码
*/ */
public static final String QA_ASK = "topic.qaAsk"; public static final String DELETE_QRCODE = "topic.deleteQrcode";
/** /**
* 问答完成 * 二维码图书修改
*/ */
public static final String QA_FINISH = "topic.qaFinish"; public static final String QRCODE_BOOK_UPDATE = "topic.qrcodeBookUpdate";
/** /**
* 问答答案 * 重置
*/ */
public static final String QA_ANSWER = "topic.qaAnswer"; public static final String RECHARGE = "topic.recharge";
/** /**
* 问答取消 * 改变显示状态
*/ */
public static final String QA_REFUSE = "topic.qaRefuse"; public static final String CHANGE_SHOW_STATE = "topic.changeShowState";
/** /**
* QR_MESSAGE_UPDATE * 删除合作出版社
*/ */
public static final String QR_MESSAGE_UPDATE = "topic.qrMessageUpdate"; public static final String DELETE_COOPERATIVE_AGENT = "topic.deleteCooperativeAgent";
/** /**
* GIVE_GIFT * TASK_BONUS
*/ */
public static final String GIVE_GIFT = "topic.giveGift"; public static final String TASK_BONUS = "topic.taskBonus";
/** /**
* 修改密码 * 读者消息
*/ */
public static final String UPDATE_PWD = "topic.updatePwd"; public static final String READER_MESSAGE = "topic.readerMessage";
/** /**
* 管理消息 * 记录用户习惯
*/ */
public static final String MANAGE_MESSAGE = "topic.manageMessage"; public static final String RECORD_USER_HABIT = "topic.recordUserHabit";
/**
* RETURN_4_ADVISER
*/
public static final String RETURN_4_ADVISER = "topic.return4adviser";
/**
* 退款
*/
public static final String REFUND = "topic.refund";
/**
* 退货
*/
public static final String REFUND_PRODUCT = "topic.refundProduct";
/**
* 发货
*/
public static final String SEND_PRODUCT = "topic.sendProduct";
/**
* 确认收货
*/
public static final String CONFIRM_ORDER = "topic.confirmOrder";
/**
* 申请退货
*/
public static final String APPLY_REFUND_PRODUCT = "topic.applyRefundProduct";
/**
* 取消订单
*/
public static final String CANCEL_ORDER = "topic.cancelOrder";
/**
* 模板二维码扫描
*/
public static final String TEMP_QRCODE_SCAN = "topic.tempQrcodeScan";
/**
* 删除二维码
*/
public static final String DELETE_QRCODE = "topic.deleteQrcode";
/**
* 二维码图书修改
*/
public static final String QRCODE_BOOK_UPDATE = "topic.qrcodeBookUpdate";
/**
* 重置
*/
public static final String RECHARGE = "topic.recharge";
/**
* 改变显示状态
*/
public static final String CHANGE_SHOW_STATE = "topic.changeShowState";
/**
* 删除合作出版社
*/
public static final String DELETE_COOPERATIVE_AGENT = "topic.deleteCooperativeAgent";
/**
* TASK_BONUS
*/
public static final String TASK_BONUS = "topic.taskBonus";
/**
* 读者消息
*/
public static final String READER_MESSAGE = "topic.readerMessage";
/**
* 记录用户习惯
*/
public static final String RECORD_USER_HABIT = "topic.recordUserHabit";
/** /**
* 扫码 * 扫码
...@@ -288,23 +290,43 @@ public class MQTopicProducer { ...@@ -288,23 +290,43 @@ public class MQTopicProducer {
*/ */
public static final String EXCHAGE = "rays.topic"; public static final String EXCHAGE = "rays.topic";
/** /**
* 更新图书封面图 * 更新图书封面图
*/ */
public static final String UPDATE_BOOK_COVERIMG = "topic.updateBookCoverImg"; public static final String UPDATE_BOOK_COVERIMG = "topic.updateBookCoverImg";
/** /**
* 更新图书名称 * 更新图书名称
*/ */
public static final String UPDATE_BOOK_NAME = "topic.updateBookName"; public static final String UPDATE_BOOK_NAME = "topic.updateBookName";
/** /**
* 微信用户关系 * 微信用户关系
*/ */
public static final String WECHAT_RELATE_INFO = "topic.wechatRelateInfo"; public static final String WECHAT_RELATE_INFO = "topic.wechatRelateInfo";
/** /**
* 更新用户头像 * 更新用户头像
*/ */
public static final String UPDATE_USER_HEADURL = "topic.updateUserHeadUrl"; public static final String UPDATE_USER_HEADURL = "topic.updateUserHeadUrl";
/**
* 入群
*/
public static final String ADD_WXGROUP = "topic.addWXGroup";
/**
* 微信群发送文字消息
*/
public static final String WXGROUP_SEND_TEXT = "topic.WXGroupSendText";
/**
* 新用户消息
*/
public static final String PUSH_ADD_USER_MESSAGE = "topic.pushAddUserMessage";
/**
* 签到打卡作者返现TOPIC
*/
public static final String ATTENDANCETASK_CASHBACK_MERCHANT = "topic.attendancetaskCashbackMerchant";
} }
...@@ -308,6 +308,22 @@ public class ProductTypeConstant { ...@@ -308,6 +308,22 @@ public class ProductTypeConstant {
public static final String PDF_APP = "PDF_APP"; public static final String PDF_APP = "PDF_APP";
/** /**
* 背单词
*/
public static final String WORD_APP = "WORD_APP";
/**
* 签到打卡
*/
public static final String ATTENDANCE_TASK = "ATTENDANCE_TASK";
/**
* 资源外链
*/
public static final String LINK = "LINK";
/**
* 热门作品类型 * 热门作品类型
*/ */
public static final String[] HOT_PRODUCT_TYPE = {QA, PDF, VIDEO, PRETEST}; public static final String[] HOT_PRODUCT_TYPE = {QA, PDF, VIDEO, PRETEST};
...@@ -316,7 +332,7 @@ public class ProductTypeConstant { ...@@ -316,7 +332,7 @@ public class ProductTypeConstant {
* 资源型作品(免费即可体验) * 资源型作品(免费即可体验)
*/ */
public static final String[] RESOURCE_PRODUCT = {AUDIO, VIDEO, PDF, EBOOK, ALBUM, PRETEST, QANEWS, public static final String[] RESOURCE_PRODUCT = {AUDIO, VIDEO, PDF, EBOOK, ALBUM, PRETEST, QANEWS,
FORMAT, WORD, ARTICLE, LISTEN, SCHEDULE, PBMUSIC, TUTORIAL, VIDEO_SCHEDULE, AUDIO_SCHEDULE}; FORMAT, WORD, ARTICLE, LISTEN, SCHEDULE, PBMUSIC, TUTORIAL, VIDEO_SCHEDULE, AUDIO_SCHEDULE, LINK};
/** /**
* 参与促销激励作品 * 参与促销激励作品
...@@ -335,7 +351,7 @@ public class ProductTypeConstant { ...@@ -335,7 +351,7 @@ public class ProductTypeConstant {
public static final String[] APP_PRODUCT = {LOOK, LIVE, TUTOR, GROUP, ZSCORE, VOTE, CLOCK, TEST, AUDIOAPP, ANSWER, public static final String[] APP_PRODUCT = {LOOK, LIVE, TUTOR, GROUP, ZSCORE, VOTE, CLOCK, TEST, AUDIOAPP, ANSWER,
EF, VIDEO_COURSE, PRETESTAPP, AUDIO_RESOURCE, QA_APP, EBOOK_APP, AUDIO_MAGIC, TEACH_RESOURCE_APP, EF, VIDEO_COURSE, PRETESTAPP, AUDIO_RESOURCE, QA_APP, EBOOK_APP, AUDIO_MAGIC, TEACH_RESOURCE_APP,
COURSE_WARE, TEST_PAPER_APP, MATCH_LISTEN, WORD_DICTATION, STROKE_ORDER_APP, IMAGE_APP, MEMBER_APP, COURSE_WARE, TEST_PAPER_APP, MATCH_LISTEN, WORD_DICTATION, STROKE_ORDER_APP, IMAGE_APP, MEMBER_APP,
ARTICLE_READING, ENGLISH_WALKMAN, ORAL_EVALUATION, PBSTORY, PDF_APP}; ARTICLE_READING, ENGLISH_WALKMAN, ORAL_EVALUATION, PBSTORY, PDF_APP, WORD_APP};
/** /**
* 数据平台埋点型作品 * 数据平台埋点型作品
......
...@@ -34,7 +34,8 @@ public enum AppProductTypeEnum { ...@@ -34,7 +34,8 @@ public enum AppProductTypeEnum {
ARTICLE_READING(AppTypeEnum.ARTICLE_READING.value, ProductTypeConstant.ARTICLE_READING), ARTICLE_READING(AppTypeEnum.ARTICLE_READING.value, ProductTypeConstant.ARTICLE_READING),
ENGLISH_WALKMAN(AppTypeEnum.ENGLISH_WALKMAN.value, ProductTypeConstant.ENGLISH_WALKMAN), ENGLISH_WALKMAN(AppTypeEnum.ENGLISH_WALKMAN.value, ProductTypeConstant.ENGLISH_WALKMAN),
ORAL_EVALUATION(AppTypeEnum.ORAL_EVALUATION.value, ProductTypeConstant.ORAL_EVALUATION), ORAL_EVALUATION(AppTypeEnum.ORAL_EVALUATION.value, ProductTypeConstant.ORAL_EVALUATION),
PDF(AppTypeEnum.PDF.value, ProductTypeConstant.PDF_APP); PDF(AppTypeEnum.PDF.value, ProductTypeConstant.PDF_APP),
RECITE_WORD(AppTypeEnum.RECITE_WORD.value, ProductTypeConstant.WORD_APP);
public final String appTypeCode; public final String appTypeCode;
......
...@@ -59,7 +59,8 @@ public enum AppTypeEnum { ...@@ -59,7 +59,8 @@ public enum AppTypeEnum {
ENGLISH_WALKMAN("ENGLISH_WALKMAN"), //英语随身听 ENGLISH_WALKMAN("ENGLISH_WALKMAN"), //英语随身听
ORAL_EVALUATION("ORAL_EVALUATION"), //口语评测 ORAL_EVALUATION("ORAL_EVALUATION"), //口语评测
WISH("WISH"),//愿望单 WISH("WISH"),//愿望单
DRAW("DRAW");//抽奖 DRAW("DRAW"),//抽奖
LIVE_TIMETABLE("LIVE_TIMETABLE");//直播
/** /**
* 值 * 值
*/ */
......
...@@ -20,7 +20,12 @@ public enum NotifyOriginTypeEnum { ...@@ -20,7 +20,12 @@ public enum NotifyOriginTypeEnum {
/** /**
* 订单 * 订单
*/ */
ORDERNUM("ORDERNUM"); ORDERNUM("ORDERNUM"),
/**
* 社群书
*/
BOOK_GROUP("BOOK_GROUP");
/** /**
* 值 * 值
......
...@@ -9,62 +9,72 @@ package com.pcloud.common.core.enums; ...@@ -9,62 +9,72 @@ package com.pcloud.common.core.enums;
*/ */
public enum TranscodeFromEnum { public enum TranscodeFromEnum {
/** /**
* 内容中心,office * 内容中心,office
*/ */
CONTENT_OFFICE("CONTENT_OFFICE"), CONTENT_OFFICE("CONTENT_OFFICE"),
/** /**
* 内容中心,PDF * 内容中心,PDF
*/ */
CONTENT_PDF("CONTENT_PDF"), CONTENT_PDF("CONTENT_PDF"),
/** /**
* 内容中心,好文PDF * 内容中心,好文PDF
*/ */
CONTENT_ARTICLE_PDF("CONTENT_ARTICLE_PDF"), CONTENT_ARTICLE_PDF("CONTENT_ARTICLE_PDF"),
/** /**
* 圈子应用 * 圈子应用
*/ */
GROUPAPP_PDF_OR_OFFICE("GROUPAPP_PDF_OR_OFFICE"), GROUPAPP_PDF_OR_OFFICE("GROUPAPP_PDF_OR_OFFICE"),
/** /**
* 帮助中心 * 帮助中心
*/ */
HELPCENTER_PDF("HELPCENTER_PDF"), HELPCENTER_PDF("HELPCENTER_PDF"),
/** /**
* 直播 * 直播
*/ */
LIVE_PPT("LIVE_PPT"), LIVE_PPT("LIVE_PPT"),
/** /**
* 直播 * 直播
*/ */
LIVE_HOMEWORD("LIVE_HOMEWORD"), LIVE_HOMEWORD("LIVE_HOMEWORD"),
/** /**
* 音频 * 音频
*/ */
AUDIOAPP_PDF("AUDIOAPP_PDF"), AUDIOAPP_PDF("AUDIOAPP_PDF"),
/** /**
* 文件管理中心 * 文件管理中心
*/ */
CONVERT_PDF("CONVERT_PDF"); CONVERT_PDF("CONVERT_PDF"),
/** /**
* 值 * 错题本-题目
*/ */
public final String code; NOTE_SUBJECT("NOTE_SUBJECT"),
/** /**
* 构造 * 错题本-答案
* */
* @param code NOTE_ANSWER("NOTE_ANSWER");
*/
private TranscodeFromEnum(String code) { /**
this.code = code; * 值
} */
public final String code;
/**
* 构造
*
* @param code
*/
private TranscodeFromEnum(String code) {
this.code = code;
}
} }
/**
*
*/
package com.pcloud.common.dto;
import com.alibaba.fastjson.JSON;
/**
* @author:songx
* @date:2019年1月14日,上午9:51:21
*/
public class OssImageCropDTO {
/**
* bucket名称
*/
private String bucket;
/**
* OSS object key
*/
private String object;
/**
* 文件大小
*/
private Long fileSize;
/**
* 文件地址
*/
private String fileUrl;
/**
* 状态,OK
*/
private String status;
public String getFileUrl() {
return fileUrl;
}
public void setFileUrl(String fileUrl) {
this.fileUrl = fileUrl;
}
public String getBucket() {
return bucket;
}
public String getObject() {
return object;
}
public String getStatus() {
return status;
}
public void setBucket(String bucket) {
this.bucket = bucket;
}
public void setObject(String object) {
this.object = object;
}
public void setStatus(String status) {
this.status = status;
}
public Long getFileSize() {
return fileSize;
}
public void setFileSize(Long fileSize) {
this.fileSize = fileSize;
}
@Override
public String toString() {
return "OssImageCropDTO -> " + JSON.toJSONString(this);
}
}
/**
*
*/
package com.pcloud.common.dto;
import com.alibaba.fastjson.JSON;
/**
*
* @author:songx
* @date:2019年1月14日,上午9:51:21
*/
public class OssImageDTO {
/**
* 图片所在的OSS路径
*/
private String fileUrl;
/**
* 水印内容
*/
private String text;
/**
* 水印字体大小(px),取值范围:(0,1000]默认值:40
*/
private int size;
/**
* 水印文字颜色
*
* 参数的构成必须是:六个十六进制数,默认值:000000黑色
*/
private String color;
/**
* 水印文字的透明度,默认值:100, 表示 100%(不透明)取值范围: [0-100]
*/
private int t;
/**
* 水印X轴坐标,默认值:10
*
* 取值范围:[0 – 4096]
*
* 单位:像素(px)
*/
private int x;
/**
* 水印Y轴坐标,默认值:10
*
* 取值范围:[0 – 4096]
*
* 单位:像素(px)
*/
private int y;
/**
* 水印所在的位置,取值范围:[nw,north,ne,west,center,east,sw,south,se]
*/
private String g;
/**
* 水印文字的阴影透明度
*/
private int shadow;
public int getShadow() {
return shadow;
}
public void setShadow(int shadow) {
this.shadow = shadow;
}
public String getFileUrl() {
return fileUrl;
}
public void setFileUrl(String fileUrl) {
this.fileUrl = fileUrl;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getT() {
return t;
}
public void setT(int t) {
this.t = t;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public String getG() {
return g;
}
public void setG(String g) {
this.g = g;
}
@Override
public String toString() {
return "OssImageDTO -> " + JSON.toJSONString(this);
}
}
...@@ -290,151 +290,151 @@ public class FileUtils { ...@@ -290,151 +290,151 @@ public class FileUtils {
return false; return false;
} }
/** /**
* 该方法用来判断文件夹是否存在,如果不存在则创建,存在则什么都不做 * 该方法用来判断文件夹是否存在,如果不存在则创建,存在则什么都不做
* *
* @param filePath * @param filePath
*/ */
public static boolean creatDir(String filePath) { public static boolean creatDir(String filePath) {
if (StringUtil.isEmpty(filePath)) { if (StringUtil.isEmpty(filePath)) {
return false; return false;
} }
File file = new File(filePath); File file = new File(filePath);
if (!file.exists()) { if (!file.exists()) {
file.mkdir(); file.mkdir();
return true; return true;
} }
return false; return false;
} }
/** /**
* 该方法用来判断文件夹是否存在,如果不存在则创建,存在则什么都不做 该方法能够实现创建整个路径 * 该方法用来判断文件夹是否存在,如果不存在则创建,存在则什么都不做 该方法能够实现创建整个路径
* *
* @param filePath * @param filePath
*/ */
public static boolean creatDirs(String filePath) { public static boolean creatDirs(String filePath) {
if (StringUtil.isEmpty(filePath)) { if (StringUtil.isEmpty(filePath)) {
return false; return false;
} }
File file = new File(filePath); File file = new File(filePath);
if (!file.exists()) { if (!file.exists()) {
file.mkdirs(); file.mkdirs();
return true; return true;
} }
return false; return false;
} }
/** /**
* 获取文件类型 * 获取文件类型
* *
* @param filePath * @param filePath
*/ */
public static String getFileType(String filePath) { public static String getFileType(String filePath) {
if (StringUtil.isEmpty(filePath)) { if (StringUtil.isEmpty(filePath)) {
return null; return null;
} }
int index1 = filePath.lastIndexOf("."); int index1 = filePath.lastIndexOf(".");
if (index1 < 1) { if (index1 < 1) {
return null; return null;
} }
int index2 = filePath.lastIndexOf("?"); int index2 = filePath.lastIndexOf("?");
if (index2 > index1) { if (index2 > index1) {
filePath = filePath.substring(0, filePath.lastIndexOf("?")); filePath = filePath.substring(0, filePath.lastIndexOf("?"));
} }
filePath = filePath.replace("/", OSConstant.SEPARATOR); filePath = filePath.replace("/", OSConstant.SEPARATOR);
int index3 = filePath.lastIndexOf(OSConstant.SEPARATOR); int index3 = filePath.lastIndexOf(OSConstant.SEPARATOR);
if (index3 > index1) { if (index3 > index1) {
return null; return null;
} }
return filePath.substring(filePath.lastIndexOf(".") + 1, filePath.length()).toLowerCase(); return filePath.substring(filePath.lastIndexOf(".") + 1, filePath.length()).toLowerCase();
} }
/** /**
* 获取文件名称 * 获取文件名称
* *
* @param filePath * @param filePath
*/ */
public static String getFileName(String filePath) { public static String getFileName(String filePath) {
if (StringUtil.isEmpty(filePath)) { if (StringUtil.isEmpty(filePath)) {
return null; return null;
} }
String fileName = null; String fileName = null;
filePath = filePath.replace("/", OSConstant.SEPARATOR); filePath = filePath.replace("/", OSConstant.SEPARATOR);
int index1 = filePath.lastIndexOf("."); int index1 = filePath.lastIndexOf(".");
if (index1 > -1) { if (index1 > -1) {
int index2 = filePath.lastIndexOf("?"); int index2 = filePath.lastIndexOf("?");
if (index2 > index1) { if (index2 > index1) {
filePath = filePath.substring(0, filePath.lastIndexOf("?")); filePath = filePath.substring(0, filePath.lastIndexOf("?"));
} }
int index3 = filePath.lastIndexOf(OSConstant.SEPARATOR); int index3 = filePath.lastIndexOf(OSConstant.SEPARATOR);
if (index3 > index1) { if (index3 > index1) {
fileName = filePath.substring(filePath.lastIndexOf(OSConstant.SEPARATOR) + 1); fileName = filePath.substring(filePath.lastIndexOf(OSConstant.SEPARATOR) + 1);
} else { } else {
fileName = filePath.substring(filePath.lastIndexOf(OSConstant.SEPARATOR) + 1, fileName = filePath.substring(filePath.lastIndexOf(OSConstant.SEPARATOR) + 1,
filePath.lastIndexOf(".")); filePath.lastIndexOf("."));
} }
} else { } else {
fileName = filePath.substring(filePath.lastIndexOf(OSConstant.SEPARATOR) + 1); fileName = filePath.substring(filePath.lastIndexOf(OSConstant.SEPARATOR) + 1);
} }
return formatName(fileName); return formatName(fileName);
} }
/** /**
* 获取文件名称包括后缀 * 获取文件名称包括后缀
* *
* @param filePath * @param filePath
* @return * @return
*/ */
public static String getFileNameAll(String filePath) { public static String getFileNameAll(String filePath) {
if (StringUtil.isEmpty(filePath)) { if (StringUtil.isEmpty(filePath)) {
return null; return null;
} }
String fileName = getFileName(filePath); String fileName = getFileName(filePath);
if (StringUtil.isEmpty(fileName)) { if (StringUtil.isEmpty(fileName)) {
return null; return null;
} }
String fileType = getFileType(filePath); String fileType = getFileType(filePath);
return StringUtil.isEmpty(fileType) ? fileName : fileName + "." + fileType; return StringUtil.isEmpty(fileType) ? fileName : fileName + "." + fileType;
} }
/** /**
* 格式化文件名称,过滤特殊字符(名称太长进行截断) * 格式化文件名称,过滤特殊字符(名称太长进行截断)
* *
* @param fileName * @param fileName
*/ */
public static String formatName(String fileName) { public static String formatName(String fileName) {
if (StringUtil.isEmpty(fileName)) { if (StringUtil.isEmpty(fileName)) {
return null; return null;
} }
try { try {
String regEx = "[*/\\\\:?\"<|>\\s+%#&=.()]"; String regEx = "[*/\\\\:?\"<|>\\s+%#&=.()]";
Pattern p = Pattern.compile(regEx); Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(fileName); Matcher m = p.matcher(fileName);
String result = m.replaceAll("").trim(); String result = m.replaceAll("").trim();
// 文件名称过长的话,限制40个字 // 文件名称过长的话,限制40个字
return result.length() > 40 ? result.substring(0, 40) : result; return result.length() > 40 ? result.substring(0, 40) : result;
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("【文件API】格式化文件名称.[formatName]:" + e.getMessage(), e); LOGGER.error("【文件API】格式化文件名称.[formatName]:" + e.getMessage(), e);
return UUIDUitl.taskName(); return UUIDUitl.taskName();
} }
} }
/** /**
* 获取文件所在的目录 * 获取文件所在的目录
* *
* @param filePath * @param filePath
* @return * @return
*/ */
public static String getFileFolder(String filePath) { public static String getFileFolder(String filePath) {
if (StringUtil.isEmpty(filePath)) { if (StringUtil.isEmpty(filePath)) {
return null; return null;
} }
return filePath.substring(0, filePath.lastIndexOf(OSConstant.SEPARATOR)); return filePath.substring(0, filePath.lastIndexOf(OSConstant.SEPARATOR));
} }
/** /**
* 获取http文件路径的域名 * 获取http文件路径的域名
* *
* @param fileUrl * @param fileUrl
* @return * @return
*/ */
...@@ -450,415 +450,425 @@ public class FileUtils { ...@@ -450,415 +450,425 @@ public class FileUtils {
return null; return null;
} }
/** /**
* FileUtils工具 File @throws * FileUtils工具 File @throws
*/ */
public static File copyURLToFile(String url, String dir) throws Exception { public static File copyURLToFile(String url, String dir) throws Exception {
try { try {
URL httpurl = new URL(url); URL httpurl = new URL(url);
File f = new File(dir); File f = new File(dir);
org.apache.commons.io.FileUtils.copyURLToFile(httpurl, f); org.apache.commons.io.FileUtils.copyURLToFile(httpurl, f);
return f; return f;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
/** /**
* 根据路径删除指定的目录或文件,无论存在与否 * 根据路径删除指定的目录或文件,无论存在与否
* *
* @param sPath 要删除的目录或文件 * @param sPath
* @return 删除成功返回 true,否则返回 false。 * 要删除的目录或文件
*/ * @return 删除成功返回 true,否则返回 false。
public static boolean deleteFolder(String sPath) { */
if (StringUtil.isEmpty(sPath)) { public static boolean deleteFolder(String sPath) {
return false; if (StringUtil.isEmpty(sPath)) {
} return false;
boolean flag = false; }
File file = new File(sPath); boolean flag = false;
// 判断目录或文件是否存在 File file = new File(sPath);
if (!file.exists()) { // 不存在返回 false // 判断目录或文件是否存在
return flag; if (!file.exists()) { // 不存在返回 false
} else { return flag;
// 判断是否为文件 } else {
if (file.isFile()) { // 为文件时调用删除文件方法 // 判断是否为文件
return deleteFile(sPath); if (file.isFile()) { // 为文件时调用删除文件方法
} else { // 为目录时调用删除目录方法 return deleteFile(sPath);
return deleteDirectory(sPath); } else { // 为目录时调用删除目录方法
} return deleteDirectory(sPath);
} }
} }
}
/**
* 删除单个文件 /**
* * 删除单个文件
* @param sPath 被删除文件的文件名 *
* @return 单个文件删除成功返回true,否则返回false * @param sPath
*/ * 被删除文件的文件名
public static boolean deleteFile(String sPath) { * @return 单个文件删除成功返回true,否则返回false
if (StringUtil.isEmpty(sPath)) { */
return false; public static boolean deleteFile(String sPath) {
} if (StringUtil.isEmpty(sPath)) {
boolean flag = false; return false;
File file = new File(sPath); }
// 路径为文件且不为空则进行删除 boolean flag = false;
if (file.isFile() && file.exists()) { File file = new File(sPath);
file.delete(); // 路径为文件且不为空则进行删除
flag = true; if (file.isFile() && file.exists()) {
} file.delete();
return flag; flag = true;
} }
return flag;
/** }
* 删除目录(文件夹)以及目录下的文件
* /**
* @param sPath 被删除目录的文件路径 * 删除目录(文件夹)以及目录下的文件
* @return 目录删除成功返回true,否则返回false *
*/ * @param sPath
public static boolean deleteDirectory(String sPath) { * 被删除目录的文件路径
if (StringUtil.isEmpty(sPath)) { * @return 目录删除成功返回true,否则返回false
return false; */
} public static boolean deleteDirectory(String sPath) {
// 如果sPath不以文件分隔符结尾,自动添加文件分隔符 if (StringUtil.isEmpty(sPath)) {
if (!sPath.endsWith(File.separator)) { return false;
sPath = sPath + File.separator; }
} // 如果sPath不以文件分隔符结尾,自动添加文件分隔符
File dirFile = new File(sPath); if (!sPath.endsWith(File.separator)) {
// 如果dir对应的文件不存在,或者不是一个目录,则退出 sPath = sPath + File.separator;
if (!dirFile.exists() || !dirFile.isDirectory()) { }
return false; File dirFile = new File(sPath);
} // 如果dir对应的文件不存在,或者不是一个目录,则退出
boolean flag = true; if (!dirFile.exists() || !dirFile.isDirectory()) {
// 删除文件夹下的所有文件(包括子目录) return false;
File[] files = dirFile.listFiles(); }
for (int i = 0; i < files.length; i++) { boolean flag = true;
// 删除子文件 // 删除文件夹下的所有文件(包括子目录)
if (files[i].isFile()) { File[] files = dirFile.listFiles();
flag = deleteFile(files[i].getAbsolutePath()); for (int i = 0; i < files.length; i++) {
if (!flag) // 删除子文件
break; if (files[i].isFile()) {
} // 删除子目录 flag = deleteFile(files[i].getAbsolutePath());
else { if (!flag)
flag = deleteDirectory(files[i].getAbsolutePath()); break;
if (!flag) } // 删除子目录
break; else {
} flag = deleteDirectory(files[i].getAbsolutePath());
} if (!flag)
if (!flag) break;
return false; }
// 删除当前目录 }
if (dirFile.delete()) { if (!flag)
return true; return false;
} else { // 删除当前目录
return false; if (dirFile.delete()) {
} return true;
} } else {
return false;
/** }
* 检查文件是否存在 }
*
* @param filePath /**
* @return * 检查文件是否存在
*/ *
public static boolean checkFile(String filePath) { * @param filePath
if (StringUtil.isEmpty(filePath)) { * @return
return false; */
} public static boolean checkFile(String filePath) {
File file = new File(filePath); if (StringUtil.isEmpty(filePath)) {
if (!file.isFile()) { return false;
return false; }
} File file = new File(filePath);
return true; if (!file.isFile()) {
} return false;
}
/** return true;
* | FileUtils工具 }
*/
public static void downloadFileFromUrl(String url, String localFilePath) throws FileException { /**
LOGGER.info("【文件API】下载文件[本地文件].<START>.[url]=" + url + ",[localFilePath]=" + localFilePath); * | FileUtils工具
creatFiles(localFilePath); */
try { public static void downloadFileFromUrl(String url, String localFilePath) throws FileException {
if (StringTools.contains(url, AliyunConstant.OSS_CDN_URLS)) { LOGGER.info("【文件API】下载文件[本地文件].<START>.[url]=" + url + ",[localFilePath]=" + localFilePath);
OssUtils.downloadFile(url, localFilePath); creatFiles(localFilePath);
// } else if (url.contains("/group")) { try {
// Map<String, String> paramMap = FdfsUtils.splitFilePath(url); if (StringTools.contains(url, AliyunConstant.OSS_CDN_URLS)) {
// FdfsUtils.download(paramMap.get(FdfsEnum.GROUP_NAME.value), OssUtils.downloadFile(url, localFilePath);
// paramMap.get(FdfsEnum.FILE_ID.value), localFilePath); // } else if (url.contains("/group")) {
} else { // Map<String, String> paramMap = FdfsUtils.splitFilePath(url);
File f = new File(localFilePath); // FdfsUtils.download(paramMap.get(FdfsEnum.GROUP_NAME.value),
URL httpurl = new URL(url); // paramMap.get(FdfsEnum.FILE_ID.value), localFilePath);
org.apache.commons.io.FileUtils.copyURLToFile(httpurl, f); } else {
} File f = new File(localFilePath);
} catch (Exception e) { URL httpurl = new URL(url);
LOGGER.error("【文件API】下载文件.[copyURLToFile]:" + e.getMessage(), e); org.apache.commons.io.FileUtils.copyURLToFile(httpurl, f);
throw new FileException(FileException.FILE_DOWNLOAD_FAILURE, "下载文件失败"); }
} } catch (Exception e) {
} LOGGER.error("【文件API】下载文件.[copyURLToFile]:" + e.getMessage(), e);
throw new FileException(FileException.FILE_DOWNLOAD_FAILURE, "下载文件失败");
/** }
* IOUtils工具 }
*/
public static byte[] downloadByteFromUrl(String url) throws FileException { /**
LOGGER.info("【文件API】下载文件[byte].<START>.[url]=" + url); * IOUtils工具
if (StringUtil.isEmpty(url)) { */
return null; public static byte[] downloadByteFromUrl(String url) throws FileException {
} LOGGER.info("【文件API】下载文件[byte].<START>.[url]=" + url);
byte[] data = null; if (StringUtil.isEmpty(url)) {
try { return null;
if (StringTools.contains(url, AliyunConstant.OSS_CDN_URLS)) { }
data = OssUtils.downloadFile2Byte(url); byte[] data = null;
// } else if (url.contains("/group")) { try {
// Map<String, String> paramMap = FdfsUtils.splitFilePath(url); if (StringTools.contains(url, AliyunConstant.OSS_CDN_URLS)) {
// data = data = OssUtils.downloadFile2Byte(url);
// FdfsUtils.download(paramMap.get(FdfsEnum.GROUP_NAME.value), // } else if (url.contains("/group")) {
// paramMap.get(FdfsEnum.FILE_ID.value)); // Map<String, String> paramMap = FdfsUtils.splitFilePath(url);
} else { // data =
URL httpurl = new URL(url); // FdfsUtils.download(paramMap.get(FdfsEnum.GROUP_NAME.value),
data = IOUtils.toByteArray(httpurl); // paramMap.get(FdfsEnum.FILE_ID.value));
} } else {
} catch (Exception e) { URL httpurl = new URL(url);
LOGGER.error("【文件API】下载文件.[toByteArray]:" + e.getMessage(), e); data = IOUtils.toByteArray(httpurl);
throw new FileException(FileException.FILE_DOWNLOAD_FAILURE, "下载文件失败"); }
} } catch (Exception e) {
return data; LOGGER.error("【文件API】下载文件.[toByteArray]:" + e.getMessage(), e);
} throw new FileException(FileException.FILE_DOWNLOAD_FAILURE, "下载文件失败");
}
/** return data;
* InputStream }
*/
@Deprecated /**
public static InputStream downloadStreamFromUrl(String url) throws FileException { * InputStream
try { */
URL httpurl = new URL(url); @Deprecated
return httpurl.openStream(); public static InputStream downloadStreamFromUrl(String url) throws FileException {
} catch (Exception e) { try {
LOGGER.error("【文件API】下载文件.[openStream]:" + e.getMessage(), e); URL httpurl = new URL(url);
throw new FileException(FileException.FILE_DOWNLOAD_FAILURE, "下载文件失败"); return httpurl.openStream();
} } catch (Exception e) {
} LOGGER.error("【文件API】下载文件.[openStream]:" + e.getMessage(), e);
throw new FileException(FileException.FILE_DOWNLOAD_FAILURE, "下载文件失败");
/** }
* 普通情况下保存字节数据到本地文件 }
*/
public synchronized static boolean saveBytesTofile(File file, byte[] data) throws BizException { /**
FileOutputStream fos = null; * 普通情况下保存字节数据到本地文件
// 建立输出字节流 */
try { public synchronized static boolean saveBytesTofile(File file, byte[] data) throws BizException {
fos = new FileOutputStream(file); FileOutputStream fos = null;
fos.write(data); // 用FileOutputStream 的write方法写入字节数组 // 建立输出字节流
return true; try {
} catch (Exception e) { fos = new FileOutputStream(file);
e.printStackTrace(); fos.write(data); // 用FileOutputStream 的write方法写入字节数组
return false; return true;
} finally { } catch (Exception e) {
try { e.printStackTrace();
fos.close(); return false;
} catch (IOException e) { } finally {
e.printStackTrace(); try {
} fos.close();
} } catch (IOException e) {
} e.printStackTrace();
}
/** }
* 复制一个文件到另一个目录下 }
*
* @throws BizException /**
*/ * 复制一个文件到另一个目录下
public static void copyFileToFolder(File inputFile, File outputFile) throws BizException { *
FileInputStream fis = null; * @throws BizException
FileOutputStream fos = null; */
public static void copyFileToFolder(File inputFile, File outputFile) throws BizException {
try { FileInputStream fis = null;
fis = new FileInputStream(inputFile); FileOutputStream fos = null;
fos = new FileOutputStream(outputFile);
int len = 0; try {
byte[] buf = new byte[1024]; fis = new FileInputStream(inputFile);
while ((len = fis.read(buf)) != -1) { fos = new FileOutputStream(outputFile);
fos.write(buf, 0, len); int len = 0;
} byte[] buf = new byte[1024];
fis.close(); while ((len = fis.read(buf)) != -1) {
fos.close(); fos.write(buf, 0, len);
} catch (IOException ioe) { }
ioe.printStackTrace(); fis.close();
} fos.close();
} } catch (IOException ioe) {
ioe.printStackTrace();
/** }
* 合并两个文件 }
*
* @param outFile 目标文件 /**
* @param leafFile 源文件 * 合并两个文件
*/ *
public static void mergeFiles(File outFile, File leafFile) { * @param outFile
FileOutputStream fos = null; * 目标文件
FileInputStream fis = null; * @param leafFile
if (!outFile.exists()) { * 源文件
try { */
outFile.createNewFile(); public static void mergeFiles(File outFile, File leafFile) {
} catch (Exception e) { FileOutputStream fos = null;
throw new FileException(FileException.FILE_NOT_EXIST, "创建临时存储文件失败"); FileInputStream fis = null;
} if (!outFile.exists()) {
} try {
try { outFile.createNewFile();
// 合并其实就是文件的续写,写成true } catch (Exception e) {
fos = new FileOutputStream(outFile, true); throw new FileException(FileException.FILE_NOT_EXIST, "创建临时存储文件失败");
fis = new FileInputStream(leafFile); }
int len = 0; }
for (byte[] buf = new byte[1024 * 1024]; (len = fis.read(buf)) != -1; ) { try {
fos.write(buf, 0, len); // 合并其实就是文件的续写,写成true
} fos = new FileOutputStream(outFile, true);
} catch (IOException ioe) { fis = new FileInputStream(leafFile);
ioe.printStackTrace(); int len = 0;
} finally { for (byte[] buf = new byte[1024 * 1024]; (len = fis.read(buf)) != -1;) {
try { fos.write(buf, 0, len);
if (fis != null) }
fis.close(); } catch (IOException ioe) {
if (fos != null) ioe.printStackTrace();
fos.close(); } finally {
} catch (Exception e) { try {
} if (fis != null)
} fis.close();
} if (fos != null)
fos.close();
/** } catch (Exception e) {
* 合并多个文件 }
* }
* @param outFile 输出文件, }
* @param leafFiles 文件碎片集
*/ /**
public static void mergeFileList(File outFile, List<File> leafFiles) { * 合并多个文件
FileOutputStream fos = null; *
FileInputStream fis = null; * @param outFile
if (!outFile.exists()) { * 输出文件,
try { * @param leafFiles
outFile.createNewFile(); * 文件碎片集
} catch (Exception e) { */
throw new FileException(FileException.FILE_NOT_EXIST, "创建临时存储文件失败"); public static void mergeFileList(File outFile, List<File> leafFiles) {
} FileOutputStream fos = null;
} FileInputStream fis = null;
try { if (!outFile.exists()) {
// 合并其实就是文件的续写,写成true try {
fos = new FileOutputStream(outFile, true); outFile.createNewFile();
byte[] buf = new byte[1024 * 1024]; } catch (Exception e) {
for (File leafFile : leafFiles) { throw new FileException(FileException.FILE_NOT_EXIST, "创建临时存储文件失败");
fis = new FileInputStream(leafFile); }
int len = 0; }
while ((len = fis.read(buf)) != -1) { try {
fos.write(buf, 0, len); // 合并其实就是文件的续写,写成true
} fos = new FileOutputStream(outFile, true);
} byte[] buf = new byte[1024 * 1024];
} catch (IOException ioe) { for (File leafFile : leafFiles) {
ioe.printStackTrace(); fis = new FileInputStream(leafFile);
} finally { int len = 0;
try { while ((len = fis.read(buf)) != -1) {
if (fis != null) fos.write(buf, 0, len);
fis.close(); }
if (fos != null) }
fos.close(); } catch (IOException ioe) {
} catch (Exception e) { ioe.printStackTrace();
} } finally {
} try {
} if (fis != null)
fis.close();
/** if (fos != null)
* 音频文件转换 fos.close();
* } catch (Exception e) {
* @param data 音频byte数组 }
* @param sourExt 原始后缀 }
* @param ext 新后缀 }
* @return
* @author PENG /**
*/ * 音频文件转换
public static String audioFormatConvert(byte[] data, String sourExt, String ext) { *
File tmpdir = new File("tempdir/local"); * @param data
if (!tmpdir.exists()) { * 音频byte数组
try { * @param sourExt
tmpdir.mkdirs(); * 原始后缀
} catch (SecurityException ex) { * @param ext
System.out.println("无法创建临时文件夹"); * 新后缀
ex.printStackTrace(); * @return
} * @author PENG
} */
public static String audioFormatConvert(byte[] data, String sourExt, String ext) {
String name = UUID.randomUUID().toString(); File tmpdir = new File("tempdir/local");
File source = new File(tmpdir, name + "." + sourExt); if (!tmpdir.exists()) {
boolean creat = saveBytesTofile(source, data); try {
if (creat) { tmpdir.mkdirs();
File target = new File(tmpdir, name + "." + ext); } catch (SecurityException ex) {
AudioAttributes audio = new AudioAttributes(); System.out.println("无法创建临时文件夹");
Encoder encoder = new Encoder(); ex.printStackTrace();
audio.setCodec("libmp3lame"); }
}
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat(ext.toLowerCase()); String name = UUID.randomUUID().toString();
attrs.setAudioAttributes(audio); File source = new File(tmpdir, name + "." + sourExt);
boolean creat = saveBytesTofile(source, data);
try { if (creat) {
encoder.encode(source, target, attrs); File target = new File(tmpdir, name + "." + ext);
return target.getPath(); AudioAttributes audio = new AudioAttributes();
} catch (IllegalArgumentException e) { Encoder encoder = new Encoder();
e.printStackTrace(); audio.setCodec("libmp3lame");
return null;
} catch (InputFormatException e) { EncodingAttributes attrs = new EncodingAttributes();
e.printStackTrace(); attrs.setFormat(ext.toLowerCase());
return null; attrs.setAudioAttributes(audio);
} catch (EncoderException e) {
e.printStackTrace(); try {
return target.getPath(); encoder.encode(source, target, attrs);
} return target.getPath();
} else { } catch (IllegalArgumentException e) {
return null; e.printStackTrace();
} return null;
} } catch (InputFormatException e) {
e.printStackTrace();
/** return null;
* 获取文本的内容 } catch (EncoderException e) {
* e.printStackTrace();
* @param url return target.getPath();
* @return }
*/ } else {
public static String getTextString(String url) { return null;
LOGGER.info("【文件API】获取文本的内容.<START>.[url]=" + url); }
if (StringUtil.isEmpty(url)) { }
return null;
} /**
StringBuilder lrcString = new StringBuilder(); * 获取文本的内容
InputStream is = null; *
InputStreamReader isr = null; * @param url
try { * @return
byte[] bt = downloadByteFromUrl(url); */
is = new ByteArrayInputStream(bt); public static String getTextString(String url) {
boolean isUTF8Bom = CpdetectorEncoding.isUTF8Bom(is); LOGGER.info("【文件API】获取文本的内容.<START>.[url]=" + url);
if (isUTF8Bom) { if (StringUtil.isEmpty(url)) {
isr = new InputStreamReader(is, "UTF-8"); return null;
} else { }
Object charSet = CpdetectorEncoding.getEncoding(bt, false); StringBuilder lrcString = new StringBuilder();
if (charSet.toString().equals("UTF-8")) { InputStream is = null;
isr = new InputStreamReader(is, "UTF-8"); InputStreamReader isr = null;
} else { try {
isr = new InputStreamReader(new ByteArrayInputStream(bt), "GBK"); byte[] bt = downloadByteFromUrl(url);
} is = new ByteArrayInputStream(bt);
} boolean isUTF8Bom = CpdetectorEncoding.isUTF8Bom(is);
BufferedReader br = new BufferedReader(isr);// 构造一个BufferedReader类来读取文件 if (isUTF8Bom) {
String s; isr = new InputStreamReader(is, "UTF-8");
while ((s = br.readLine()) != null) {// 使用readLine方法,一次读一行 } else {
lrcString.append(System.lineSeparator() + s); Object charSet = CpdetectorEncoding.getEncoding(bt, false);
} if (charSet.toString().equals("UTF-8")) {
} catch (Exception e) { isr = new InputStreamReader(is, "UTF-8");
LOGGER.error("【文件工具】读取文件内容.<ERROR>:" + e.getMessage(), e); } else {
} finally { isr = new InputStreamReader(new ByteArrayInputStream(bt), "GBK");
try { }
if (isr != null) }
isr.close(); BufferedReader br = new BufferedReader(isr);// 构造一个BufferedReader类来读取文件
if (is != null) String s;
is.close(); while ((s = br.readLine()) != null) {// 使用readLine方法,一次读一行
} catch (Exception e2) { lrcString.append(System.lineSeparator() + s);
} }
} } catch (Exception e) {
LOGGER.info("【文件API】获取文本的内容.<END>"); LOGGER.error("【文件工具】读取文件内容.<ERROR>:" + e.getMessage(), e);
return lrcString.toString(); } finally {
} try {
if (isr != null)
isr.close();
if (is != null)
is.close();
} catch (Exception e2) {
}
}
LOGGER.info("【文件API】获取文本的内容.<END>");
return lrcString.toString();
}
/** /**
* java 8 读取文本内容 * java 8 读取文本内容
...@@ -1004,113 +1014,114 @@ public class FileUtils { ...@@ -1004,113 +1014,114 @@ public class FileUtils {
return outFilePath; return outFilePath;
} }
/** /**
* 将文件转成base64 字符串 * 将文件转成base64 字符串
* *
* @param data * @param data
* @return * * @return *
* @throws Exception * @throws Exception
*/ */
public static String encodeBase64File(byte[] data) throws BizException { public static String encodeBase64File(byte[] data) throws BizException {
try { try {
return new String(Base64.encodeBase64(data)); return new String(Base64.encodeBase64(data));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("【文件工具】将base64字符解码保存文件失败:" + e.getMessage(), e); LOGGER.error("【文件工具】将base64字符解码保存文件失败:" + e.getMessage(), e);
return null; return null;
} }
} }
/** /**
* 将base64字符解码保存文件 * 将base64字符解码保存文件
* *
* @param base64Code * @param base64Code
* @param targetPath * @param targetPath
* @throws Exception * @throws Exception
*/ */
public static boolean decoderBase64File(String base64Code, String targetPath) throws BizException { public static boolean decoderBase64File(String base64Code, String targetPath) throws BizException {
if (base64Code == null) if (base64Code == null)
return false; return false;
OutputStream out = null; OutputStream out = null;
try { try {
// Base64解码 // Base64解码
byte[] b = Base64.decodeBase64(targetPath); byte[] b = Base64.decodeBase64(targetPath);
for (int i = 0; i < b.length; ++i) { for (int i = 0; i < b.length; ++i) {
if (b[i] < 0) {// 调整异常数据 if (b[i] < 0) {// 调整异常数据
b[i] += 256; b[i] += 256;
} }
} }
// 生成jpeg图片 // 生成jpeg图片
out = new FileOutputStream(targetPath); out = new FileOutputStream(targetPath);
out.write(b); out.write(b);
out.flush(); out.flush();
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("【文件工具】将base64字符解码保存文件失败:" + e.getMessage(), e); LOGGER.error("【文件工具】将base64字符解码保存文件失败:" + e.getMessage(), e);
return false; return false;
} finally { } finally {
try { try {
if (out != null) if (out != null)
out.close(); out.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
return true; return true;
} }
/** /**
* 本地文件到byte数组 * 本地文件到byte数组
* *
* @param path * @param path
* @return * @return
*/ */
public static byte[] file2byte(String path) { public static byte[] file2byte(String path) {
byte[] data = null; byte[] data = null;
FileInputStream fis = null; FileInputStream fis = null;
ByteArrayOutputStream os = null; ByteArrayOutputStream os = null;
try { try {
fis = new FileInputStream(new File(path)); fis = new FileInputStream(new File(path));
os = new ByteArrayOutputStream(); os = new ByteArrayOutputStream();
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int numBytesRead = 0; int numBytesRead = 0;
while ((numBytesRead = fis.read(buf)) != -1) { while ((numBytesRead = fis.read(buf)) != -1) {
os.write(buf, 0, numBytesRead); os.write(buf, 0, numBytesRead);
} }
data = os.toByteArray(); data = os.toByteArray();
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("【文件工具】文件到byte数组:" + e.getMessage(), e); LOGGER.error("【文件工具】文件到byte数组:" + e.getMessage(), e);
} finally { } finally {
try { try {
if (fis != null) if (fis != null)
fis.close(); fis.close();
if (os != null) if (os != null)
os.close(); os.close();
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("【文件工具】文件流关闭失败:" + e.getMessage(), e); LOGGER.error("【文件工具】文件流关闭失败:" + e.getMessage(), e);
} }
} }
return data; return data;
} }
/** /**
* 从输入流中获取数据 * 从输入流中获取数据
* *
* @param inStream 输入流 * @param inStream
* @return * 输入流
* @throws Exception * @return
*/ * @throws Exception
public static byte[] readInputStream(InputStream inStream) throws Exception { */
ByteArrayOutputStream outStream = new ByteArrayOutputStream(); public static byte[] readInputStream(InputStream inStream) throws Exception {
byte[] buffer = new byte[1024]; ByteArrayOutputStream outStream = new ByteArrayOutputStream();
int len = 0; byte[] buffer = new byte[1024];
try { int len = 0;
while ((len = inStream.read(buffer)) != -1) { try {
outStream.write(buffer, 0, len); while ((len = inStream.read(buffer)) != -1) {
} outStream.write(buffer, 0, len);
} catch (Exception e) { }
LOGGER.error("【文件工具】文件流到byte数组:" + e.getMessage(), e); } catch (Exception e) {
} finally { LOGGER.error("【文件工具】文件流到byte数组:" + e.getMessage(), e);
inStream.close(); } finally {
} inStream.close();
return outStream.toByteArray(); }
} return outStream.toByteArray();
}
} }
...@@ -11,10 +11,11 @@ import java.math.BigDecimal; ...@@ -11,10 +11,11 @@ import java.math.BigDecimal;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.dcg.util.StringUtils;
import com.itextpdf.text.Image; import com.itextpdf.text.Image;
import com.pcloud.common.constant.AliyunConstant; import com.pcloud.common.constant.AliyunConstant;
import com.pcloud.common.constant.FilePathConst; import com.pcloud.common.constant.FilePathConst;
...@@ -440,6 +441,43 @@ public class ImageUtils { ...@@ -440,6 +441,43 @@ public class ImageUtils {
} }
/** /**
* 获取图片的宽度和高度(考虑了图片旋转的情况。也就是说,获得的宽就是宽,高就是高)
*
* @param img
* 图片文件
* @return
*/
public static float[] getWidthHeightSize(String fileUrl) {
Image image = null;
String localFile = null;
float[] size = new float[2];
try {
if (StringTools.contains(fileUrl, AliyunConstant.OSS_CDN_URLS)) {
localFile = OssUtils.imageAutoOrient(fileUrl, 0);
image = Image.getInstance(localFile);
} else if (fileUrl.startsWith("http")) {
image = Image.getInstance(FileUtils.downloadByteFromUrl(fileUrl));
} else {
image = Image.getInstance(fileUrl);
}
} catch (Exception e) {
LOGGER.error("【IMAGE API】获取图片的宽度和高度[getWidthHeightSize]:" + e.getMessage(), e);
} finally {
if (!StringUtil.isEmpty(localFile)) {
FileUtils.deleteFile(localFile);
}
}
if (image == null) {
size[0] = 0;
size[1] = 0;
} else {
size[0] = image.getWidth();
size[1] = image.getHeight();
}
return size;
}
/**
* 获取对比比例 * 获取对比比例
* *
* @param num1 * @param num1
...@@ -653,29 +691,30 @@ public class ImageUtils { ...@@ -653,29 +691,30 @@ public class ImageUtils {
LOGGER.error("【图片】输出文件流关闭失败:" + e.getMessage(), e); LOGGER.error("【图片】输出文件流关闭失败:" + e.getMessage(), e);
} }
} }
/** /**
* 获取图片的宽度和高度 * 获取图片的宽度和高度(未考虑图片旋转的情况。也就是说,获得的宽可能是宽也可能是高,高可能是高也肯是宽)
* *
* @param img * @param fileUrl
* 图片文件
* @return * @return
*/ */
public static float[] getWidthHeightSize(String fileUrl) { public static float[] getWidthHeightNoOrient(String fileUrl) {
Image image = null; Image image = null;
String localFile = null; String localFile = null;
float[] size = new float[2]; float[] size = new float[2];
try { try {
if (StringTools.contains(fileUrl, AliyunConstant.OSS_CDN_URLS)) { /*
localFile = OssUtils.imageAutoOrient(fileUrl, 0); * if (StringTools.contains(fileUrl, AliyunConstant.OSS_CDN_URLS)) { localFile =
image = Image.getInstance(localFile); * OssUtils.imageAutoOrient(fileUrl); image = Image.getInstance(localFile); }
} else if (fileUrl.startsWith("http")) { * else
*/
if (fileUrl.startsWith("http")) {
image = Image.getInstance(FileUtils.downloadByteFromUrl(fileUrl)); image = Image.getInstance(FileUtils.downloadByteFromUrl(fileUrl));
} else { } else {
image = Image.getInstance(fileUrl); image = Image.getInstance(fileUrl);
} }
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("【IMAGE API】获取图片的宽度和高度:" + e.getMessage(), e); LOGGER.error("【IMAGE API】获取图片的宽度和高度[getWidthHeightNoOrient]:" + e.getMessage(), e);
} finally { } finally {
if (!StringUtil.isEmpty(localFile)) { if (!StringUtil.isEmpty(localFile)) {
FileUtils.deleteFile(localFile); FileUtils.deleteFile(localFile);
...@@ -692,6 +731,82 @@ public class ImageUtils { ...@@ -692,6 +731,82 @@ public class ImageUtils {
} }
/** /**
* image transcode to webp
*
* 注意:使用此方法转图片格式,机器上必须安装有谷歌cwebp工具
*
* @param fileUrl
* @return
*/
// public static UploadResultInfo transcodeToWebp(String fileUrl, int quality) {
// LOGGER.info("【IMAGE API】image transcode to webp.<START>.[fileUrl]=" + fileUrl
// + ",[quality]=" + quality);
// String fileNameAll = FileUtils.getFileNameAll(fileUrl);
// String localFilePath = FilePathConst.DOWNLOAD_PATH + fileNameAll;
// FileUtils.downloadFileFromUrl(fileUrl, localFilePath);
// String outputFilePath = FilePathConst.IMAGE_PATH + "webp/" + fileNameAll +
// ".webp";
// FileUtils.creatFiles(outputFilePath);
// UploadResultInfo uploadResultInfo = null;
// try {
// String os = System.getProperty("os.name");
// if (os.toLowerCase().startsWith("win")) {
// executeCwebp4Win(localFilePath, outputFilePath, quality);
// } else {
// executeCwebp4Linux(localFilePath, outputFilePath, quality);
// }
// uploadResultInfo = OssUtils.uploadLocalFile4Child(outputFilePath, fileUrl);
// } catch (Exception e) {
// LOGGER.error("An error happend when convert to webp. Img is: " +
// e.getMessage(), e);
// throw new FileException(FileException.FILE_CONVERT_FAIL, "transcode to webp
// is fail!");
// } finally {
// FileUtils.deleteFile(localFilePath);
// FileUtils.deleteFile(outputFilePath);
// }
// LOGGER.info("【IMAGE API】image transcode to webp.<START>.[uploadResultInfo]="
// + uploadResultInfo);
// return uploadResultInfo;
// }
/**
* execute cwebp command:cwebp [options] input_file -o output_file.webp
*
* @param inputFilePath
* @param outputFilePath
* @param quality
* @throws Exception
*/
// private static void executeCwebp4Win(String inputFilePath, String
// outputFilePath, int quality) throws Exception {
// Process process = new ProcessBuilder("cwebp", "-q", (quality == 0 ? 80 :
// quality) + "", inputFilePath, "-o",
// outputFilePath).redirectErrorStream(true).start();
// if (0 != process.waitFor()) {
// throw new Exception("process wait for fail!");
// }
// }
/**
* execute cwebp command:cwebp [options] input_file -o output_file.webp
*
* @param inputFilePath
* @param outputFilePath
* @param quality
* @throws Exception
*/
// private static void executeCwebp4Linux(String inputFilePath, String
// outputFilePath, int quality) throws Exception {
// Process process = new ProcessBuilder("/usr/local/bin/cwebp", "-q", (quality
// == 0 ? 80 : quality) + "",
// inputFilePath, "-o", outputFilePath).redirectErrorStream(true).start();
// if (0 != process.waitFor()) {
// throw new Exception("process wait for fail!");
// }
// }
/**
* 上传的图片转换成webpO * 上传的图片转换成webpO
* *
* @param localFilePath * @param localFilePath
......
This source diff could not be displayed because it is too large. You can view the blob instead.
package com.pcloud.common.utils.bean;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.utils.ListUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
/**
* @author:songx
* @date:2018年8月24日,下午2:18:40
*/
public class BeanUtils extends org.springframework.beans.BeanUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(BeanUtils.class);
/**
* 实体类之间的转换
*
* @param source 来源
* @param clazz 目标对象
* @return
*/
public static <T> T copy(Object source, Class<T> clazz) {
if (source == null) {
return null;
}
T t = null;
try {
t = clazz.newInstance();
} catch (Exception e) {
LOGGER.error("clazz newInstance is error:" + e.getMessage(), e);
}
copyProperties(source, t);
return t;
}
/**
* 实体类之间的转换
*
* @param sources 来源
* @param clazz 目标对象
* @return
*/
public static <T> List<T> copy(List<?> sources, Class<T> clazz) {
if (ListUtils.isEmpty(sources)) {
return null;
}
List<T> results = new ArrayList<>();
for (Object source : sources) {
results.add(copy(source, clazz));
}
return results;
}
/**
* 分页结果的实体类之间的转换
*
* @param source
* @param clazz
* @param <T>
* @return
*/
public static <T> PageBeanNew<T> copy(PageBeanNew<?> source, Class<T> clazz) {
if (source == null) {
return null;
}
PageBeanNew<T> result = new PageBeanNew<>();
copyProperties(source, result);
List<?> recordList = source.getRecordList();
if (ListUtils.isEmpty(recordList)) {
result.setRecordList(new ArrayList<>());
} else {
result.setRecordList(copy(recordList, clazz));
}
return result;
}
}
/**
*
*/
package com.pcloud.common.utils.bean;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.utils.ListUtils;
import org.apache.commons.collections.MapUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author:songx
* @date:2019年3月28日,下午2:47:41
*/
public class ResponesUtils {
/**
* 单个对象实例化
*
* @param object
* @param clazz
* @return
* @author songx
* @date 2019年1月14日, 下午7:32:35
*/
public static <T> T object(Object object, Class<T> clazz) {
if (object == null) {
try {
return clazz.newInstance();
} catch (Exception e) {
}
}
return BeanUtils.copy(object, clazz);
}
/**
* 集合查询结果判断
*
* @param lists
* @return
*/
public static <T> List<T> list(List<T> lists) {
if (!ListUtils.isEmpty(lists)) {
return lists;
}
return Lists.newArrayList();
}
/**
* map查询结果判断
*
* @param map
* @return
*/
public static <K, V> Map<K, V> map(Map<K, V> map) {
if (!MapUtils.isEmpty(map)) {
return map;
}
return Maps.newHashMap();
}
/**
* list集合结果转换
*
* @param lists
* @param clazz
* @return
* @author songx
* @date 2019年4月23日, 下午4:13:19
*/
public static <T> List<T> list(List<?> lists, Class<T> clazz) {
if (ListUtils.isEmpty(lists)) {
return new ArrayList<>();
}
return BeanUtils.copy(lists, clazz);
}
/**
* 分页查询结果判断
*
* @param pageBean
* @return
*/
public static <T> PageBeanNew<T> pageBean(PageBeanNew<T> pageBean) {
if (pageBean != null) {
return pageBean;
}
return new PageBeanNew<T>(0, 15, 0, new ArrayList<>());
}
/**
* 分页查询结果转换
*
* @param pageBean
* @param clazz
* @return
* @author songx
* @date 2019年4月23日, 下午4:03:11
*/
public static <T> PageBeanNew<T> pageBean(PageBeanNew<?> pageBean, Class<T> clazz) {
if (pageBean == null) {
return new PageBeanNew<>(0, 15, 0, new ArrayList<>());
}
return pageBean(BeanUtils.copy(pageBean, clazz));
}
}
...@@ -99,6 +99,21 @@ public class Cookie { ...@@ -99,6 +99,21 @@ public class Cookie {
public static final String SECOND_TD = "secondTd"; public static final String SECOND_TD = "secondTd";
/** /**
* 社群码ID
*/
public static final String BOOK_GROUP_ID = "bookGroupId";
/**
* 群分类ID
*/
public static final String CLASSIFY_ID = "classifyId";
/**
* 微信群ID
*/
public static final String QRCODE_ID = "qrcodeId";
/**
* cookie 信息處理 * cookie 信息處理
* @param userInfo * @param userInfo
* @return * @return
...@@ -214,6 +229,26 @@ public class Cookie { ...@@ -214,6 +229,26 @@ public class Cookie {
userInfos.put(SECOND_TD, StringUtil.isEmpty(code) || "undefined".equalsIgnoreCase(code) || "null".equalsIgnoreCase(code) ? null userInfos.put(SECOND_TD, StringUtil.isEmpty(code) || "undefined".equalsIgnoreCase(code) || "null".equalsIgnoreCase(code) ? null
: NumberUtil.toLong(code)); : NumberUtil.toLong(code));
} }
// add by gaop at 2019年5月6日16:23:32
if (userInfoArry[i].contains(BOOK_GROUP_ID)) {
String[] bookGroupId = userInfoArry[i].split("=");
String code = bookGroupId[bookGroupId.length - 1];
userInfos.put(BOOK_GROUP_ID, StringUtil.isEmpty(code) || "undefined".equalsIgnoreCase(code) || "null".equalsIgnoreCase(code) ? null
: NumberUtil.toLong(code));
}
if (userInfoArry[i].contains(CLASSIFY_ID)) {
String[] classifyId = userInfoArry[i].split("=");
String code = classifyId[classifyId.length - 1];
userInfos.put(CLASSIFY_ID, StringUtil.isEmpty(code) || "undefined".equalsIgnoreCase(code) || "null".equalsIgnoreCase(code) ? null
: NumberUtil.toLong(code));
}
if (userInfoArry[i].contains(QRCODE_ID)) {
String[] qrcodeId = userInfoArry[i].split("=");
String code = qrcodeId[qrcodeId.length - 1];
userInfos.put(QRCODE_ID, StringUtil.isEmpty(code) || "undefined".equalsIgnoreCase(code) || "null".equalsIgnoreCase(code) ? null
: NumberUtil.toLong(code));
}
} }
return userInfos; return userInfos;
} }
......
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