zero 1 سال پیش
والد
کامیت
5a3dbe3dc4
20فایلهای تغییر یافته به همراه1170 افزوده شده و 860 حذف شده
  1. 23 0
      src/main/java/com/example/xiaoshiweixinback/business/common/log/BusinessLogTypeEnum.java
  2. 213 0
      src/main/java/com/example/xiaoshiweixinback/business/common/log/LogHelper.java
  3. 40 0
      src/main/java/com/example/xiaoshiweixinback/business/common/response/BaseResponsePageDTO.java
  4. 49 0
      src/main/java/com/example/xiaoshiweixinback/business/common/response/ResponseData.java
  5. 31 26
      src/main/java/com/example/xiaoshiweixinback/business/exception/BusinessException.java
  6. 0 62
      src/main/java/com/example/xiaoshiweixinback/business/exception/BusinessExceptionErrorEnum.java
  7. 139 0
      src/main/java/com/example/xiaoshiweixinback/business/exception/ExceptionEnum.java
  8. 39 21
      src/main/java/com/example/xiaoshiweixinback/business/exception/GlobalExceptionHandler.java
  9. 2 2
      src/main/java/com/example/xiaoshiweixinback/business/jwt/JwtTokenUtil.java
  10. 3 1
      src/main/java/com/example/xiaoshiweixinback/business/jwt/JwtUserInfo.java
  11. 146 241
      src/main/java/com/example/xiaoshiweixinback/business/redis/RedisService.java
  12. 81 79
      src/main/java/com/example/xiaoshiweixinback/business/utils/BeanUtil.java
  13. 17 15
      src/main/java/com/example/xiaoshiweixinback/business/utils/CollectionKit.java
  14. 69 72
      src/main/java/com/example/xiaoshiweixinback/business/utils/DateUtil.java
  15. 42 42
      src/main/java/com/example/xiaoshiweixinback/business/utils/JSONUtil.java
  16. 180 233
      src/main/java/com/example/xiaoshiweixinback/business/utils/LogHelper.java
  17. 4 2
      src/main/java/com/example/xiaoshiweixinback/business/utils/PageKit.java
  18. 12 1
      src/main/java/com/example/xiaoshiweixinback/controller/LoginController.java
  19. 32 33
      src/main/java/com/example/xiaoshiweixinback/okhttp/RequestManager.java
  20. 48 30
      src/main/java/com/example/xiaoshiweixinback/service/LoginService.java

+ 23 - 0
src/main/java/com/example/xiaoshiweixinback/business/common/log/BusinessLogTypeEnum.java

@@ -0,0 +1,23 @@
+package com.example.xiaoshiweixinback.business.common.log;
+
+public enum BusinessLogTypeEnum {
+	ECOMMERCE("ecommerce","小世电商模块");
+	private String desc;
+	private String type;
+	private BusinessLogTypeEnum(String type, String desc) {
+		this.setType(type);
+		this.setDesc(desc);
+	}
+	public String getType() {
+		return type;
+	}
+	public void setType(String type) {
+		this.type = type;
+	}
+	public String getDesc() {
+		return desc;
+	}
+	public void setDesc(String desc) {
+		this.desc = desc;
+	}
+}

+ 213 - 0
src/main/java/com/example/xiaoshiweixinback/business/common/log/LogHelper.java

@@ -0,0 +1,213 @@
+package com.example.xiaoshiweixinback.business.common.log;
+
+
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * 日志工具类
+ * @author Peach
+ *
+ */
+public class LogHelper {
+	
+	private static Logger logger = null;
+
+	//------------------------------------------系统日志记录-------------------------
+	/**
+	 * @param info
+	 */
+	public static void log(Object...info) {
+		logger = LoggerFactory.getLogger("");
+		logger.info("info={}",info);
+	}
+	
+	public static void log(Throwable e,Object...info) {
+		logger = LoggerFactory.getLogger("");
+		logger.info("exception={} info={}",throwable2String(e),info);
+	}
+	
+	/**
+	 * @param clazz
+	 * @param info
+	 */
+	public static void log(Class clazz, String info) {
+		logger = LoggerFactory.getLogger(clazz);
+		logger.info(info);
+	}
+	
+	/**
+	 * @param clazz
+	 * @param e
+	 */
+	public static void log(Class clazz, Throwable e) {
+		log(clazz,throwable2String(e));
+	}
+	
+	/**
+	 * @param name
+	 * @param info
+	 */
+	@Deprecated
+	public static void log(String name, String info) {
+		logger = LoggerFactory.getLogger(name);
+		logger.info(name+"-"+info);
+	}
+	
+	/**
+	 * @param name
+	 * @param e
+	 */
+	@Deprecated
+	public static void log(String name, Throwable e) {
+		log(name,throwable2String(e));
+	}
+	
+	
+	/**
+	 * @param name
+	 * @param info
+	 * @param e
+	 */
+	@Deprecated
+	public static void log(String name, String info,Throwable e) {
+		log(name,info+"-"+throwable2String(e));
+	}
+	
+	
+	/**
+	 * @param clazz
+	 * @param info
+	 * @param e
+	 */
+	public static void log(Class clazz, String info,Throwable e) {
+		log(clazz,info+"-"+throwable2String(e));
+	}
+	
+	/**
+	 * 将异常信息转为string
+	 * @param e
+	 * @return
+	 */
+	private static String throwable2String(Throwable e){
+		if(checkBaseBusinessException(e)) {
+			BusinessException bbe = (BusinessException)e;
+			return "----->"+bbe.getErrorMessage();
+		}
+		PrintWriter pw = null;
+		StringWriter sw = null;
+		try{
+			sw = new StringWriter();
+			pw = new PrintWriter(sw);
+			e.printStackTrace(pw);
+			pw.flush();
+			sw.flush();
+		}catch (Exception e1) {
+			logger.info(e.getMessage());
+		}finally{
+			if(sw!=null){
+				try{
+					sw.close();
+				}catch (Exception e2) {
+					e2.printStackTrace();
+					return "";
+				}
+			}else{
+				return "";
+			}
+			if(pw!=null){
+				pw.close();
+			}
+			return sw.toString();
+		}
+		
+	}
+	
+	
+	/**
+	* @Title: checkBaseBusinessException
+	* @Description: 判断异常是否为系统异常
+	* @param @param e
+	* @param @return    参数
+	* @return boolean    返回类型
+	* @throws
+	* @author Orange
+	* @date 2019年1月23日
+	*/
+	private static boolean checkBaseBusinessException(Throwable e) {
+		return BusinessException.class.isInstance(e);
+	}
+	
+	
+	//------------------------------------------多业务日志记录-------------------------
+	
+	/**
+	* @Title: log
+	* @Description: 多业务动态日志
+	* @param @param businessLogTypeEnum
+	* @param @param info    参数
+	* @return void    返回类型
+	* @throws
+	* @author Orange
+	* @date 2019年1月21日
+	*/
+	public static void log(BusinessLogTypeEnum businessLogTypeEnum, Object...info) {
+		MDC.put("businessName", businessLogTypeEnum.getType());
+		Logger logger = LoggerFactory.getLogger("business_log");
+		logger.info("businessName={}, info={}", businessLogTypeEnum.getType(), info);
+		MDC.remove(businessLogTypeEnum.getType());
+	}
+	
+	
+	
+	/**
+	* @Title: log
+	* @Description: 多业务动态日志
+	* @param @param businessLogTypeEnum
+	* @param @param e
+	* @param @param info    参数
+	* @return void    返回类型
+	* @throws
+	* @author Orange
+	* @date 2019年1月21日
+	*/
+	public static void log(BusinessLogTypeEnum businessLogTypeEnum,Throwable e,Object...info) {
+		MDC.put("businessName", businessLogTypeEnum.getType());
+		Logger logger = LoggerFactory.getLogger("business_log");
+		logger.info("businessName={}, exception={} ,info={}", businessLogTypeEnum.getType(), throwable2String(e),info);
+		MDC.remove(businessLogTypeEnum.getType());
+	}
+	
+	
+	
+	/**
+	* @Title: warnLog
+	* @Description: 警告日志
+	* @param @param e
+	* @param @param info    参数
+	* @return void    返回类型
+	* @throws
+	* @author Orange
+	* @date 2019年1月26日
+	*/
+	public static void warnLog(Throwable e,Object...info) {
+		//系统级别日志不打印
+		if(checkBaseBusinessException(e)) {
+			log(e,info);
+		}else {
+			Logger logger = LoggerFactory.getLogger("error_log");
+			logger.warn("[System Exception] exception={} ,info={}", throwable2String(e),info);
+		}
+	}
+
+	public static void warnLog(String warnInfo){
+		Logger logger = LoggerFactory.getLogger("error_log");
+		logger.warn(warnInfo);
+	}
+
+}

+ 40 - 0
src/main/java/com/example/xiaoshiweixinback/business/common/response/BaseResponsePageDTO.java

@@ -0,0 +1,40 @@
+package com.example.xiaoshiweixinback.business.common.response;
+
+public class BaseResponsePageDTO {
+	private Long pageNo;
+	private Long pageSize;
+	private Long total;
+	private Long pages;
+
+	public Long getPageNo() {
+		return pageNo;
+	}
+
+	public void setPageNo(Long pageNo) {
+		this.pageNo = pageNo;
+	}
+
+	public Long getPageSize() {
+		return pageSize;
+	}
+
+	public void setPageSize(Long pageSize) {
+		this.pageSize = pageSize;
+	}
+
+	public Long getTotal() {
+		return total;
+	}
+
+	public void setTotal(Long total) {
+		this.total = total;
+	}
+
+	public Long getPages() {
+		return pages;
+	}
+
+	public void setPages(Long pages) {
+		this.pages = pages;
+	}
+}

+ 49 - 0
src/main/java/com/example/xiaoshiweixinback/business/common/response/ResponseData.java

@@ -0,0 +1,49 @@
+package com.example.xiaoshiweixinback.business.common.response;
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
+import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
+
+
+public class ResponseData<T> {
+	private String code;//结果代码
+	private String message;//结果信息
+	private T data;//数据集
+	
+	public ResponseData() throws BusinessException {
+		this(ExceptionEnum.SUCCESS.getCode(), ExceptionEnum.SUCCESS.getMessage(),null);
+	}
+
+	public ResponseData(T data) throws BusinessException {
+		this(ExceptionEnum.SUCCESS.getCode(),ExceptionEnum.SUCCESS.getMessage(),data);
+	}
+	
+	public ResponseData(String code, String message) throws BusinessException {
+		this(code,message,null);
+	}
+	
+	public ResponseData(String code, String message, T data) throws BusinessException {
+		this.code = code;
+		this.message = message;
+		this.data = data;
+	}
+
+
+	public String getCode() {
+		return code;
+	}
+	public void setCode(String code) {
+		this.code = code;
+	}
+	public String getMessage() {
+		return message;
+	}
+	public void setMessage(String message) {
+		this.message = message;
+	}
+	public T getData() {
+		return data;
+	}
+	public void setData(T data) {
+		this.data = data;
+	}
+
+}

+ 31 - 26
src/main/java/com/example/xiaoshiweixinback/business/exception/BusinessException.java

@@ -1,43 +1,48 @@
 package com.example.xiaoshiweixinback.business.exception;
 
 
-import com.bjbz.core.exception.BaseBusinessException;
-import com.bjbz.core.log.tools.LogHelper;
-
-
-public class BusinessException extends BaseBusinessException {
-
-
-	private static final long serialVersionUID = 465630095603311090L;
+/**
+ * @ClassName
+ * @Description 业务异常
+ * @Author 陈凯裕
+ * @Date 2022/6/27 18:02
+ * @Version TODO
+ **/
+public class BusinessException extends RuntimeException {
+
+	private static final long serialVersionUID = 3200004685293133433L;
+	private String errorCode;// 异常代码
+	private String errorMessage;// 异常信息
+
+	public BusinessException(String errorCode, String errorMessage) {
+		this.errorCode = errorCode;
+		this.errorMessage = errorMessage;
+	}
 
-	public BusinessException(Throwable throwable, BusinessExceptionErrorEnum e) {
-		LogHelper.log(BusinessException.class, throwable);
+	public BusinessException(ExceptionEnum e) {
 		this.errorMessage = e.getMessage();
 		this.errorCode = e.getCode();
 	}
 
-	public BusinessException(Throwable throwable, BusinessExceptionErrorEnum e, String errorMessage) {
-		LogHelper.log(BusinessException.class, throwable);
-		this.errorMessage = e.getMessage();
-		this.errorCode = e.getCode();
-		this.extraMessage = errorMessage;
+
+	public String getErrorCode() {
+		return errorCode;
 	}
 
-	public BusinessException(BusinessExceptionErrorEnum e) {
-		this.errorMessage = e.getMessage();
-		this.errorCode = e.getCode();
+	public void setErrorCode(String errorCode) {
+		this.errorCode = errorCode;
 	}
 
-	public BusinessException(BusinessExceptionErrorEnum e, String errorMessage) {
-		this.errorMessage = e.getMessage();
-		this.errorCode = e.getCode();
-		this.extraMessage = errorMessage;
+	public String getErrorMessage() {
+		return errorMessage;
 	}
 
-	public BusinessException(BusinessExceptionErrorEnum e, Object extraMessage) {
-		this.errorMessage = e.getMessage();
-		this.extraMessage = extraMessage;
-		this.errorCode = e.getCode();
+	public void setErrorMessage(String errorMessage) {
+		this.errorMessage = errorMessage;
+	}
+
+	public static long getSerialversionuid() {
+		return serialVersionUID;
 	}
 
 }

+ 0 - 62
src/main/java/com/example/xiaoshiweixinback/business/exception/BusinessExceptionErrorEnum.java

@@ -1,62 +0,0 @@
-package com.example.xiaoshiweixinback.business.exception;
-
-public enum BusinessExceptionErrorEnum {
-	//1000 系统异常
-	TOKEN_EXPIRED(1001,"TOKE过期!"),
-	TOKEN_PARSE_ERROR(1002,"TOKE解析错误!"),
-	TOKEN_SECRET_ERROR(1003,"没有访问权限!"),
-	LOGIN_USER_PASSWORD_ERROR(1004,"用户名密码错误!"),
-	LOGIN_USER_FORBIDDEN(1005,"用户被停用!"),
-	LOGIN_USER_DELETE(1006,"用户被删除!"),
-	API_AUTHORITY_ERROR(1007,"API调用权限异常!"),
-	UPLOAD_IMAGE_TYPE_ERROR(1010,"上传图片格式错误!"),
-	FILE_TOO_BIG(1011,"上传文件大小不能超过100M"),
-	FILE_NO_HAVE_NAME(1012,"未传文件名或文件名为空"),
-	NO_DATA_AUTH(1013,"暂无数据权限,请联系管理员"),
-	SIGNIN_ACCOUNT_HAVE_ALREADY_REGISTER(1014,"登录账号已存在"),
-	OLD_PASSWORD_ERROR(1015,"原密码错误"),
-	EXCEL_READ_ERROR(1016,"excel有错误,请先处理"),
-	PARAM_ERROR(1017,"参数错误"),
-	NO_AUTH_ROLE(1018,"暂无操作权限"),
-	NO_ATTACHMENT(1019,"无附件信息"),
-	REMOTE_FILE_READ_ERROR(1020,"远程文件读取失败"),
-	DOWNLOAD_ERROR(1021,"文件下载失败"),
-	INTERFACE_IS_STOP(1022,"接口已停用"),
-	CALL_API_ERROR(1023,"接口调用失败"),
-    TEMPLATE_EXCEL_DOWNLOAD_ERROR(1024,"模板下载失败"),
-	REQUEST_ERROR(1025,"请求错误"),
-	IMAGE_SIZE_ERROR(1026, "图片格式错误"),
-	IMAGE_SEIZE_ERROR(1027, "图片大小不能超过4M"),
-	IDCARD_NOT_FOUND_ERROR(1028,"身份证无法识别"),
-	SYSTEM_BUSY(1029,"系统繁忙,请稍后重试"),
-	RECOGNIZE_ERROR(1030, "识别错误"),
-	NO_DATA_EXPORT(1031,"暂无可导出数据"),
-	UPLOAD_ERROR(1032,"上传失败"),
-
-	THE_COMPANY_NAME_HAS_EXIST(110001, "企业名称已存在"),
-	THE_COMPANY_STATUS_NOT_APPROVE_PASS(110002,"该企业审核未通过,不可发布职位需求"),
-	THE_ACCOUNT_HAS_EXISTS(110003, "账号已存在"),
-	THE_PHONE_HAS_EXISTS(110005, "手机号已存在"),
-	THE_FEEDBACK_CONTENT_IS_NOT_EMPTY(110004, "反馈内容不得为空"),
-
-	;
-
-	private int code;
-	private String message;
-	private BusinessExceptionErrorEnum(int code, String desc) {
-		this.setCode(code);
-		this.setMessage(desc);
-	}
-	public String getMessage() {
-		return message;
-	}
-	public void setMessage(String message) {
-		this.message = message;
-	}
-	public int getCode() {
-		return code;
-	}
-	public void setCode(int code) {
-		this.code = code;
-	}
-}

+ 139 - 0
src/main/java/com/example/xiaoshiweixinback/business/exception/ExceptionEnum.java

@@ -0,0 +1,139 @@
+package com.example.xiaoshiweixinback.business.exception;
+
+public enum ExceptionEnum {
+
+    /*APP端 100000-300000*/
+    SUCCESS("000000", "调用成功"),
+    SYSTEM_ERROR("999999", "系统异常"),
+    PARAMETER_VERIFICATION_ERROR("000001", "数据参数校验异常"),
+    PHONE_FORMAT_ERROR("000002","手机号格式错误"),
+    TOKEN_INVALID("000003","token无效"),
+    LANGUAGE_CODE_NULL("000004","languageCode不能为空"),
+    LANGUAGES_CODE_INVALID("000005","languageCode无效"),
+    VERIFICATION_CODE_INVALID("10001","当前验证码失效,请重新获取"),
+    CODE_WRONG("10002","验证码错误"),
+
+    EXCEL_READ_ERROR("10016","excel有错误,请先处理"),
+    INIT_GENERICITY_BEAN_ERROR("10003","泛型实例化异常"),
+    THE_PHONE_CANNOT_BE_EMPTY("10004","手机号不能为空"),
+    THE_STUDENT_IS_NOT_EXIST("10005","该学生不存在"),
+    THE_CODE_IS_NOT_NULL("10006","验证码不能为空"),
+    OPERATIONS_ARE_TOO_FREQUENT("10007","操作频繁"),
+    THE_STUDENT_HAS_EXIST("10008","很抱歉,该实名身份已被其他用户关联"),
+    ID_CARD_FORMAT_ERROR("10009","身份证格式错误"),
+    THE_RELATIONSHIP_ALREADY_ASSOCIATED("10010","您的孩子已经和您关联"),
+    DO_NOT_FIT_STUDENT_REQUIRE("10011","很抱歉,您不符合学员要求"),
+    THE_USER_IS_EXIST("10012","该用户已实名"),
+    REAL_NAME_AND_ID_CARD_NOT_MATCH("10013", "实名认证失败,请核对姓名与证件号码"),
+    PLEASE_CONTACT_YOUR_CHILD_FIRST("10014", "请先关联你的孩子"),
+    WX_REQUEST_EXCEPTION("10015","微信请求异常"),
+    WX_OPEN_ID_TOKEN_NOT_VALID("10016","openIdToken无效"),
+
+
+    USER_NOT_REAL_NAME("10020","未实名用户无法查看订单"),
+    TOURIST_DOES_NOT_HAVE_ORDER("10021","游客无法查看订单"),
+
+
+    /*海外学校端 400000-600000*/
+    SCHOOL_ACCOUNT_NOT_EXIST("400001","账号不存在"),
+    SCHOOL_PASSWORD_INVALID("400002","密码错误"),
+
+    /*后台管理  600000-900000*/
+    SYNC_HRS7_ERROR("600001","连接其他业务系统失败"),
+    REQUEST_WAS_ABORTED("600002","请求失败"),
+    THE_STUDENT_IS_EXIST("600003","该学员已存在"),
+    THE_RECORD_METHOD_MUST_TO_BE_MANUAL("600004", "记录方式必须为手工记录"),
+    THE_CUSTODIAN_HAS_RELATED_USER("600005", "该家长已经关联过用户,不可重复"),
+    THE_CUSTODIAN_HAS_EXISTED("600005", "家长已存在"),
+    PROPERTY_VALUE_ALREADY_EXIST("600006","可选项已存在"),
+    MANAGE_USER_EXIST("600007","手机号已经存在"),
+    MANAGE_POSITION_CODE_EXIST("600008","职位code已经存在"),
+    MANAGE_POSITION_EXIST("600009","职位已经存在"),
+    MANAGE_ROLE_EXIST("600009","角色已经存在"),
+    MANAGE_ROLE_CODE_EXIST("600010","角色code已经存在"),
+    MANAGE_RESOURCE_CODE_EXIST("600011","权限code已经存在"),
+    MANAGE_MENU_LIMIT("600012","菜单层级超出限制"),
+    MANAGE_RESOURCE_HAVE_CHILD("600013","资源存在子级资源,无法删除"),
+    MANAGE_USER_ACCOUNT_NOT_EXIST("600014","账号不存在"),
+    MANAGE_USER_FORBIDDEN("600015","账号已被封禁"),
+    MANAGE_USER_PASSWORD_ERROR("600016","密码错误"),
+    ACCOUNT_NOT_EXIST("600014", "账号不存在,请联系管理员开通账号"),
+    //产品相关
+    PRODUCT_DOES_NOT_HAVE_FAT_NODE("600050", "产品未配置流程大节点"),
+    PRODUCT_DOES_NOT_HAVE_SMALL_NODE("600051", "产品未配置流程小节点"),
+    SMALL_NODE_NOT_EXIST("600052", "节点不存在"),
+    ORDER_DOES_NOT_HAVE_NODE("600053", "订单没有节点"),
+    ORDER_NOT_EXIST("600054", "订单不存在"),
+    PAY_CAN_NOT_CLOSE("600055", "缴费单无法关闭,请检查缴费单状态"),
+    AMOUNT_CAN_NOT_LESS_THAN_ZERO("600056", "金额不可小于0"),
+    ORDER_TREATY_REAPEATABLE_INITIATE("600057","同类型合同不可重复发起"),
+    TREATY_ALREADY_SIGNED("600058","合同未签订,不可审核"),
+    TREATY_ALREADY_PASS("600059","合同已经审核,不可取消"),
+    TREATY_NOT_EXIST("600060","合同不存在"),
+    APP_NEWS_NOT_EXIST("600061","app信息不存在"),
+    PROCESS_NOT_EXIST("600062","流程不存在"),
+    PROCESS_IS_OVER("600063","流程已结束"),
+    PROCESS_CAN_NOT_RETURN_BACK("600064","流程不可回退到指定节点"),
+    NODE_CAN_NOT_REFUSE("600065","节点不可驳回"),
+    PROCESS_PARAM_NOT_VALID("600066","发起流程参数无效"),
+    DATA_NOT_ALL_COMPLETE("600067","有资料未确认,无法通过流程"),
+    REPEATED_INITIATION("600068","请勿重复发起流程"),
+    ORDER_CANT_CANCEL("600069","存在未完成缴费单或者未完成流程,订单不可关闭"),
+    POPUP_ALREADY_EXIST("600070","弹窗已经存在"),
+    STUDENT_STATUS_CANT_CHANGE("600071","学员状态不可更改"),
+    STUDENT_ORDER_REPEAT("600072","请勿重复添加同一订单"),
+    ROOT_ALREADY_EXIST("600073","服务机构下已有管理员"),
+    PHONE_ALREADY_EXIST("600074","手机号重复"),
+
+    /*文件服务*/
+    UPLOAD_IMAGE_TYPE_ERROR("900010","上传图片格式错误!"),
+    FILE_TOO_BIG("900011","上传文件大小不能超过100M"),
+    FILE_NO_HAVE_NAME("900012","未传文件名或文件名为空"),
+    REMOTE_FILE_READ_ERROR("900020","远程文件读取失败"),
+
+    /*海外用工端*/
+    ENTERPRISE_ACCOUNT_NOT_EXIST("700001","账号不存在"),
+    ENTERPRISE_PASSWORD_INVALID("700002","密码错误"),
+    WX_APPLY_ACCESS_TOKEN_ERROR("800001", "获取微信token失败"),
+    WX_PHONE_REQUIRE_ERROR("800001", "获取手机号失败"),
+
+    ALREADY_REAL_NAMED("1000001", "用户已实名,无法获取此积分"),
+    HAS_CONSULT_WITH_VOCATION_TEACHER_JOB("1000002", "已经咨询过职业导师"),
+    POINT_JOB_NOT_EXISTS("1000003", "积分任务不存在"),
+
+
+    /*学员池*/
+    STUDENT_POOL_ALREADY_EXISTS("1000004", "学员池已存在"),
+    STUDENT_IMPORT_FILE_HAS_NO_DATA("1000005", "文件无数据"),
+    TEMPLATE_FILE_FORMAT_ERROR("1000006", "文件格式错误"),
+    CANT_IMPORT_EMPTY("1000007", "不能导入空文件"),
+
+    /*服务机构*/
+    SERVICE_ORG_ALREADY_EXISTS("2000001", "服务机构已存在"),
+
+    CRM_USER_DO_NOT_LOGIN("2000021", "CRM用户未登录");
+
+    private String code;// 异常代码
+    private String message;// 异常信息
+
+    ExceptionEnum(String code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+}

+ 39 - 21
src/main/java/com/example/xiaoshiweixinback/business/exception/GlobalExceptionHandler.java

@@ -1,31 +1,49 @@
-/*
 package com.example.xiaoshiweixinback.business.exception;
 
+import com.example.xiaoshiweixinback.business.common.log.LogHelper;
+import com.example.xiaoshiweixinback.business.common.response.ResponseData;
+import jakarta.servlet.http.HttpServletResponse;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.converter.HttpMessageNotReadableException;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
 
-import com.example.xiaoshiweixinback.business.utils.ToolUtil;
 
-@ControllerAdvice
-public class GlobalExceptionHandler extends BaseGlobalExceptionHandler{
-    @SuppressWarnings("deprecation")
+@RestControllerAdvice
+public class GlobalExceptionHandler {
+
+    @ExceptionHandler(Exception.class)
+    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)//500
+    public ResponseData<String> exceptionHandler(Exception e, HttpServletResponse response) {
+        LogHelper.warnLog(e);
+        return new ResponseData<>(ExceptionEnum.SYSTEM_ERROR.getCode(), ExceptionEnum.SYSTEM_ERROR.getMessage());
+    }
+
     @ExceptionHandler(BusinessException.class)
-    @ResponseStatus(HttpStatus.OK)
-    @ResponseBody //在返回自定义相应类的情况下必须有,这是@ControllerAdvice注解的规定
+    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)//500
     public ResponseData<Object> exceptionHandler(BusinessException e, HttpServletResponse response) {
-        ResponseData<Object> rd;
-        try {
-            rd = new ResponseData<Object>();
-        } catch (BusinessException e1) {
-            return new ResponseData<Object>(e.getErrorCode(), e.getErrorMessage());
-        }
-        rd.setCode(e.getErrorCode());
-        rd.setMessage(e.getErrorMessage()+""+ (ToolUtil.isNotEmpty(e.getExtraMessage())?":"+e.getExtraMessage():""));
-        if (e.getExtraMessage() != null) {
-            rd.setData(e.getExtraMessage());
-        }
-//        LogHelper.log(GlobalExceptionHandler.class, e);
         LogHelper.warnLog(e);
-        return rd;
+        return new ResponseData<>(e.getErrorCode(),e.getErrorMessage());
+    }
+
+    @ExceptionHandler(MethodArgumentNotValidException.class)
+    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)//500
+    public ResponseData<Object> exceptionHandler(MethodArgumentNotValidException e, HttpServletResponse response) {
+        LogHelper.warnLog(e,"数据参数校验异常");
+        if(StringUtils.isEmpty(e.getBindingResult().getFieldError().getDefaultMessage()))
+            return new ResponseData<>(ExceptionEnum.PARAMETER_VERIFICATION_ERROR.getCode(),ExceptionEnum.PARAMETER_VERIFICATION_ERROR.getMessage());
+        else
+            return new ResponseData<>(ExceptionEnum.PARAMETER_VERIFICATION_ERROR.getCode(),e.getBindingResult().getFieldError().getDefaultMessage());
+    }
+
+    @ExceptionHandler(HttpMessageNotReadableException.class)
+    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)//500
+    public ResponseData<Object> exceptionHandler(HttpMessageNotReadableException e, HttpServletResponse response) {
+        LogHelper.warnLog(e,"数据参数校验异常");
+        return new ResponseData<>(ExceptionEnum.PARAMETER_VERIFICATION_ERROR.getCode(),ExceptionEnum.PARAMETER_VERIFICATION_ERROR.getMessage());
     }
 
 }
-*/

+ 2 - 2
src/main/java/com/example/xiaoshiweixinback/business/jwt/JwtTokenUtil.java

@@ -1,7 +1,7 @@
 package com.example.xiaoshiweixinback.business.jwt;
 
-import com.bjbz.common.jwt.properties.JwtProperties;
-import com.bjbz.common.util.ToolUtil;
+import com.example.xiaoshiweixinback.business.jwt.properties.JwtProperties;
+import com.example.xiaoshiweixinback.business.utils.ToolUtil;
 import io.jsonwebtoken.Claims;
 import io.jsonwebtoken.JwtException;
 import io.jsonwebtoken.Jwts;

+ 3 - 1
src/main/java/com/example/xiaoshiweixinback/business/jwt/JwtUserInfo.java

@@ -1,6 +1,8 @@
 package com.bjbz.common.jwt;
 
 
+import com.alibaba.fastjson2.JSON;
+
 public class JwtUserInfo {
     private String token;
 
@@ -15,7 +17,7 @@ public class JwtUserInfo {
      * @date 2018年1月28日
      */
     public String toJsonString() {
-        return JSONUtil.toJSONString(this);
+        return JSON.toJSONString(this);
     }
 
 

+ 146 - 241
src/main/java/com/example/xiaoshiweixinback/business/redis/RedisService.java

@@ -1,7 +1,11 @@
-/*
+
 package com.example.xiaoshiweixinback.business.redis;
 
 
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.support.atomic.RedisAtomicLong;
+import org.springframework.stereotype.Component;
+
 import javax.annotation.Resource;
 import java.util.Collection;
 import java.util.List;
@@ -9,14 +13,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
-*/
-/**
- * @ClassName
- * @Description TODO
- * @Author 陈凯裕
- * @Date 2022/7/15 14:02
- * @Version TODO
- **//*
 
 @Component
 public class RedisService {
@@ -24,524 +20,433 @@ public class RedisService {
     @Resource
     RedisTemplate redisTemplate;
 
-    */
-/** -------------------key相关操作--------------------- *//*
 
+/** -------------------key相关操作--------------------- */
 
 
-    */
-/**
+    /**
      * 删除key
-     *//*
-
+     */
     public void delete(String key) {
         redisTemplate.delete(key);
     }
 
-    */
-/**
+    /**
      * 批量删除key
-     *//*
-
+     */
     public void delete(Collection<String> keys) {
         redisTemplate.delete(keys);
     }
 
 
-    */
-/**
+    /**
      * 是否存在key
-     *//*
-
+     */
     public Boolean hasKey(String key) {
         return redisTemplate.hasKey(key);
     }
 
-    */
-/**
-     * 设置过期时间
-     *//*
 
+    /**
+     * 设置过期时间
+     */
     public Boolean expire(String key, CacheTTLEnum ttlEnum) {
         return redisTemplate.expire(key, ttlEnum.getTime(), ttlEnum.getUnit());
     }
 
 
-    */
-/**
+    /**
      * 移除 key 的过期时间,key 将持久保持
-     *//*
-
+     */
     public Boolean persist(String key) {
         return redisTemplate.persist(key);
     }
 
 
-    */
-/**
+    /**
      * 返回 key 的剩余的过期时间
-     *//*
-
+     */
     public Long getExpire(String key, TimeUnit unit) {
         return redisTemplate.getExpire(key, unit);
     }
 
-    */
-/**
-     * 修改 key 的名称
-     *//*
 
+    /**
+     * 修改 key 的名称
+     */
     public void rename(String oldKey, String newKey) {
         redisTemplate.rename(oldKey, newKey);
     }
 
-    */
-/** -------------------string相关操作--------------------- *//*
+
+/** -------------------string相关操作--------------------- */
 
 
-    */
-/**
+    /**
      * 设置指定 key 的值
-     *//*
+     */
 
     public void set(String key, Object value) {
         redisTemplate.opsForValue().set(key, value);
     }
 
-    */
-/**
-     * 获取指定 key 的值
-     *//*
 
+    /**
+     * 获取指定 key 的值
+     */
     public Object get(String key) {
         return redisTemplate.opsForValue().get(key);
     }
 
-    public <T> T get(String key,Class<T> clazz){
-        return (T)get(key);
+    public <T> T get(String key, Class<T> clazz) {
+        return (T) get(key);
     }
 
 
-    */
-/**
+    /**
      * 将给定 key 的值设为 value ,并返回 key 的旧值(old value)
-     *//*
-
+     */
     public Object getAndSet(String key, Object value) {
         return redisTemplate.opsForValue().getAndSet(key, value);
     }
 
-    public <T> T getAndSet(String key,Object value,Class<T> clazz){
-        return (T)getAndSet(key,value);
+    public <T> T getAndSet(String key, Object value, Class<T> clazz) {
+        return (T) getAndSet(key, value);
     }
 
 
-    */
-/**
+    /**
      * 批量获取
-     *//*
-
+     */
     public List<Object> multiGet(Collection<String> keys) {
         return redisTemplate.opsForValue().multiGet(keys);
     }
 
 
-    */
-/**
+    /**
      * 只有在 key 不存在时设置 key 的值
-     *//*
-
+     */
     public boolean setIfAbsent(String key, Object value) {
         return redisTemplate.opsForValue().setIfAbsent(key, value);
     }
 
 
-    */
-/**
+    /**
      * 设置一个key,值为自增的LONG类型,每调用一次+1并且返回值自增后的值
-     *//*
-
+     */
     public Long incrBy(String key) {
-        RedisAtomicLong redisAtomicLong = new RedisAtomicLong(key,redisTemplate.getConnectionFactory());
+        RedisAtomicLong redisAtomicLong = new RedisAtomicLong(key, redisTemplate.getConnectionFactory());
         return redisAtomicLong.incrementAndGet();
     }
 
 
-    */
-/** -------------------hash相关操作------------------------- *//*
+/** -------------------hash相关操作------------------------- */
 
 
-    */
-/**
+    /**
      * 获取存储在hash表中指定字段的值
-     *//*
-
+     */
     public Object hGet(String key, String field) {
         return redisTemplate.opsForHash().get(key, field);
     }
 
-    */
-/*
-     * 存储指定键值对至hash表中
-     * *//*
 
+    /*
+     * 存储指定键值对至hash表中
+     **/
     public void hPut(String key, String hashKey, Object value) {
         redisTemplate.opsForHash().put(key, hashKey, value);
     }
 
-    */
-/**
+    /**
      * 获取hash表中所有的键值对
-     *//*
-
+     */
     public Map<String, Object> hGetAll(String key) {
         return redisTemplate.opsForHash().entries(key);
     }
 
-    */
-/**
-     * 获取hash表中所有给定字段的值
-     *//*
 
+    /**
+     * 获取hash表中所有给定字段的值
+     */
     public List<Object> hMultiGet(String key, Collection<String> fields) {
         return redisTemplate.opsForHash().multiGet(key, fields);
     }
 
-    */
-/*
-    * 批量插入到hash表中
-    * *//*
 
+    /*
+     * 批量插入到hash表中
+     * */
     public void hPutAll(String key, Map<String, Object> maps) {
         redisTemplate.opsForHash().putAll(key, maps);
     }
 
 
-    */
-/**
+    /**
      * 删除一个或多个hash表字段
-     *//*
-
+     */
     public Long hDelete(String key, String... fields) {
         return redisTemplate.opsForHash().delete(key, fields);
     }
 
-    */
-/**
-     * 查看hash表 key 中,指定的字段是否存在
-     *//*
 
+    /**
+     * 查看hash表 key 中,指定的字段是否存在
+     */
     public boolean hExists(String key, String field) {
         return redisTemplate.opsForHash().hasKey(key, field);
     }
 
 
-    */
-/**
+    /**
      * 获取所有hash表中的字段
-     *//*
-
+     */
     public Set<String> hKeys(String key) {
         return redisTemplate.opsForHash().keys(key);
     }
 
-    */
-/**
-     * 获取hash表中字段的数量
-     *//*
 
+    /**
+     * 获取hash表中字段的数量
+     */
     public Long hSize(String key) {
         return redisTemplate.opsForHash().size(key);
     }
 
 
-    */
-/** ------------------------list相关操作---------------------------- *//*
+/** ------------------------list相关操作---------------------------- */
 
 
-    */
-/**
+    /**
      * 通过索引获取列表中的元素
-     *//*
-
+     */
     public Object lIndex(String key, long index) {
         return redisTemplate.opsForList().index(key, index);
     }
 
-    */
-/**
-     * 通过索引设置列表元素的值
-     *//*
 
+    /**
+     * 通过索引设置列表元素的值
+     */
     public void lSet(String key, long index, String value) {
         redisTemplate.opsForList().set(key, index, value);
     }
 
-    */
-/**
-     * 获取列表指定范围内的元素
-     *//*
-
-    public List<JpCityPO> lRange(String key, long start, long end) {
-        return redisTemplate.opsForList().range(key, start, end);
-    }
-
-    */
-/**
+    /**
      * 列表队列左push
-     *//*
-
+     */
     public Long lLeftPush(String key, Object value) {
         return redisTemplate.opsForList().leftPush(key, value);
     }
 
-    */
-/**
-     * 列表队列批量左push
-     *//*
 
+    /**
+     * 列表队列批量左push
+     */
     public Long lLeftPushAll(String key, Object... value) {
-        if(value.length==0)
+        if (value.length == 0)
             return 0L;
         return redisTemplate.opsForList().leftPushAll(key, value);
     }
 
 
-    */
-/**
+    /**
      * 列表队列右push
-     *//*
-
+     */
     public Long lRightPush(String key, Object value) {
         return redisTemplate.opsForList().rightPush(key, value);
     }
 
-    */
-/**
-     * 列表队列批量右push
-     *//*
 
+    /**
+     * 列表队列批量右push
+     */
     public Long lRightPushAll(String key, Object... value) {
-        if(value.length==0)
+        if (value.length == 0)
             return 0L;
         return redisTemplate.opsForList().rightPushAll(key, value);
     }
 
-    */
-/**
-     * 弹出列表左侧的第一个元素
-     *//*
 
+    /**
+     * 弹出列表左侧的第一个元素
+     */
     public Object lLeftPop(String key) {
         return redisTemplate.opsForList().leftPop(key);
     }
 
-
-    */
-/**
+    /**
      * 弹出列表右侧的第一个元素
      *
      * @param key
      * @return 删除的元素
-     *//*
-
+     */
     public Object lRightPop(String key) {
         return redisTemplate.opsForList().rightPop(key);
     }
 
-    */
-/**
-     * 获取列表长度
-     *//*
 
+    /**
+     * 获取列表长度
+     */
     public Long lLen(String key) {
         return redisTemplate.opsForList().size(key);
     }
 
-    */
-/** --------------------set相关操作-------------------------- *//*
 
+/** --------------------set相关操作-------------------------- */
 
-    */
-/**
-     * set添加元素
-     *//*
 
+    /**
+     * set添加元素
+     */
     public Long sAdd(String key, Object... values) {
         return redisTemplate.opsForSet().add(key, values);
     }
 
-    */
-/**
+    /**
      * set移除元素
-     *//*
-
+     */
     public Long sRemove(String key, Object... values) {
         return redisTemplate.opsForSet().remove(key, values);
     }
 
-    */
-/**
+
+    /**
      * 获取集合的大小
      *
      * @param key
      * @return
-     *//*
-
+     */
     public Long sSize(String key) {
         return redisTemplate.opsForSet().size(key);
     }
 
-    */
-/**
-     * 获取集合所有元素
-     *//*
 
+    /**
+     * 获取集合所有元素
+     */
     public Set<String> sGetMembers(String key) {
         return redisTemplate.opsForSet().members(key);
     }
 
-    */
-/**
-     * 判断集合是否包含元素
-     *//*
 
-    public boolean sContains(String key,Object value){
-        return redisTemplate.opsForSet().isMember(key,value);
+    /**
+     * 判断集合是否包含元素
+     */
+    public boolean sContains(String key, Object value) {
+        return redisTemplate.opsForSet().isMember(key, value);
     }
 
-    */
-/**------------------zSet相关操作--------------------------------*//*
 
+/**------------------zSet相关操作--------------------------------*/
 
-    */
-/**
-     * 添加元素,有序集合是按照元素的score值由小到大排列
-     *//*
 
+    /**
+     * 添加元素,有序集合是按照元素的score值由小到大排列
+     */
     public Boolean zAdd(String key, Object value, double score) {
         return redisTemplate.opsForZSet().add(key, value, score);
     }
 
 
-    */
-/**
+    /**
      * 移除指定value的值
-     *//*
-
+     */
     public Long zRemove(String key, Object... values) {
         return redisTemplate.opsForZSet().remove(key, values);
     }
 
-    */
-/**
+    /**
      * 增加元素的score值,并返回增加后的值
-     *//*
-
+     */
     public Double zIncrementScore(String key, Object value, double delta) {
         return redisTemplate.opsForZSet().incrementScore(key, value, delta);
     }
 
-    */
-/**
+    /**
      * 返回元素在集合的排名,按Score升序排名
-     *//*
-
+     */
     public Long zRank(String key, Object value) {
         return redisTemplate.opsForZSet().rank(key, value);
     }
 
-    */
-/**
+    /**
      * 返回元素在集合的排名,按Score倒序排名
-     *//*
-
+     */
     public Long zReverseRank(String key, Object value) {
         return redisTemplate.opsForZSet().reverseRank(key, value);
     }
 
-    */
-/**
+    /**
      * 获取集合的元素, 升序
-     *//*
-
+     */
     public Set<String> zRange(String key, long start, long end) {
         return redisTemplate.opsForZSet().range(key, start, end);
     }
 
-
-    */
-/**
+    /**
      * 获取集合的元素, 倒序
-     *//*
-
+     */
     public Set<String> zReverseRange(String key, long start, long end) {
         return redisTemplate.opsForZSet().reverseRange(key, start, end);
     }
 
-    */
-/**
+    /**
      * 根据Score值查询集合元素,升序
-     *//*
-
+     */
     public Set<String> zRangeByScore(String key, double min, double max) {
         return redisTemplate.opsForZSet().rangeByScore(key, min, max);
     }
 
-    */
-/**
-     * 根据Score值查询集合元素, 倒序
-     *//*
 
+    /**
+     * 根据Score值查询集合元素, 倒序
+     */
     public Set<Object> zReverseRangeByScore(String key, double min,
                                             double max) {
         return redisTemplate.opsForZSet().reverseRangeByScore(key, min, max);
     }
 
-    */
-/**
-     * 根据score值获取集合元素数量
-     *//*
 
+    /**
+     * 根据score值获取集合元素数量
+     */
     public Long zCount(String key, double min, double max) {
         return redisTemplate.opsForZSet().count(key, min, max);
     }
 
-    */
-/**
+
+    /**
      * 获取集合大小
      *
      * @param key
      * @return
-     *//*
-
+     */
     public Long zSize(String key) {
         return redisTemplate.opsForZSet().size(key);
     }
 
-    */
-/**
-     * 获取集合中value元素的score值
-     *//*
 
+    /**
+     * 获取集合中value元素的score值
+     */
     public Double zScore(String key, Object value) {
         return redisTemplate.opsForZSet().score(key, value);
     }
 
-    */
-/**
-     * 移除指定索引位置的成员
-     *//*
 
+    /**
+     * 移除指定索引位置的成员
+     */
     public Long zRemoveRange(String key, long start, long end) {
         return redisTemplate.opsForZSet().removeRange(key, start, end);
     }
 
-    */
-/**
-     * 根据指定的score值的范围来移除成员
-     *//*
 
+    /**
+     * 根据指定的score值的范围来移除成员
+     */
     public Long zRemoveRangeByScore(String key, double min, double max) {
         return redisTemplate.opsForZSet().removeRangeByScore(key, min, max);
     }
@@ -550,4 +455,4 @@ public class RedisService {
 }
 
 
-*/
+

+ 81 - 79
src/main/java/com/example/xiaoshiweixinback/business/utils/BeanUtil.java

@@ -1,80 +1,82 @@
-//package com.example.xiaoshiweixinback.business.utils;
+package com.example.xiaoshiweixinback.business.utils;
 
-//public  class BeanUtil {
-//
-//
-//	/**
-//	* @Title: copy
-//	* @Description: 类属性复制
-//	* @param @param source
-//	* @param @param target    参数
-//	* @return void    返回类型
-//	* @throws
-//	* @author Orange
-//	* @date 2019年4月3日
-//	*/
-//	public static void copy(Object source,Object target){
-//		org.springframework.beans.BeanUtils.copyProperties(source, target);
-//	}
-//
-//	/**
-//	 * @name: 克隆source为新对象
-//	 * @author Peach
-//	 * @date:2018/9/4
-//	 */
-//	public static <T> T cloneNewObject(Object source,Class<T> clazz){
-//		T t = null;
-//		try {
-//			t = clazz.newInstance();
-//		} catch (Exception e) {
-//			LogHelper.log(BeanUtil.class, "泛型实例化异常:" + clazz.getName(), e);
-//			throw new BaseBusinessException(BaseExceptionErrorEnum.INIT_GENERICITY_BEAN_ERROR);
-//		}
-//		BeanUtil.copy(source,t);
-//		return t;
-//	}
-//
-//
-//	/**
-//	 * @Title: newTclass
-//	 * @Description: 实例化泛型类
-//	 * @param @param
-//	 *            clazz
-//	 * @param @return
-//	 * @param @throws
-//	 *            InstantiationException
-//	 * @param @throws
-//	 *            IllegalAccessException 参数
-//	 * @return T 返回类型
-//	 * @throws @author
-//	 *             Orange
-//	 * @date 2018年1月16日
-//	 */
-//	public static <T> T newTclass(Class<T> clazz) {
-//		T a = null;
-//		try {
-//			a = clazz.newInstance();
-//		} catch (Exception e) {
-//			LogHelper.log(BeanUtil.class, "泛型实例化异常:" + clazz.getName(), e);
-//			throw new BaseBusinessException(BaseExceptionErrorEnum.INIT_GENERICITY_BEAN_ERROR);
-//		}
-//		return a;
-//	}
-//
-//	public static Object[] getEntities(Object target, Class<?>[] objs) {
-//		Object[] entities = new Object[objs.length];
-//		int count = 0;
-//		for (Class<?> o : objs) {
-//			Object entity = null;
-//			try {
-//				entity = o.newInstance();
-//			} catch (Exception e) {
-//				continue;
-//			}
-//			if (target != null)
-//				copy(target, entity);
-//			entities[count ++] = entity;
-//		}
-//		return entities;
-//	}
-//}
+import com.example.xiaoshiweixinback.business.common.log.LogHelper;
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
+import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
+
+public  class BeanUtil {
+
+
+	/**
+	* @Title: copy
+	* @Description: 类属性复制
+	* @param @param source
+	* @param @param target    参数
+	* @return void    返回类型
+	* @throws
+	*/
+	public static void copy(Object source,Object target){
+		org.springframework.beans.BeanUtils.copyProperties(source, target);
+	}
+
+	/**
+	 * @name: 克隆source为新对象
+	 * @author Peach
+	 * @date:2018/9/4
+	 */
+	public static <T> T cloneNewObject(Object source,Class<T> clazz){
+		T t = null;
+		try {
+			t = clazz.newInstance();
+		} catch (Exception e) {
+			LogHelper.log(BeanUtil.class, "泛型实例化异常:" + clazz.getName(), e);
+			throw new BusinessException(ExceptionEnum.INIT_GENERICITY_BEAN_ERROR);
+		}
+		BeanUtil.copy(source,t);
+		return t;
+	}
+
+
+	/**
+	 * @Title: newTclass
+	 * @Description: 实例化泛型类
+	 * @param @param
+	 *            clazz
+	 * @param @return
+	 * @param @throws
+	 *            InstantiationException
+	 * @param @throws
+	 *            IllegalAccessException 参数
+	 * @return T 返回类型
+	 * @throws @author
+	 *             Orange
+	 * @date 2018年1月16日
+	 */
+	public static <T> T newTclass(Class<T> clazz) {
+		T a = null;
+		try {
+			a = clazz.newInstance();
+		} catch (Exception e) {
+			LogHelper.log(BeanUtil.class, "泛型实例化异常:" + clazz.getName(), e);
+			throw new BusinessException(ExceptionEnum.INIT_GENERICITY_BEAN_ERROR);
+		}
+		return a;
+	}
+
+	public static Object[] getEntities(Object target, Class<?>[] objs) {
+		Object[] entities = new Object[objs.length];
+		int count = 0;
+		for (Class<?> o : objs) {
+			Object entity = null;
+			try {
+				entity = o.newInstance();
+			} catch (Exception e) {
+				continue;
+			}
+			if (target != null)
+				copy(target, entity);
+			entities[count ++] = entity;
+		}
+		return entities;
+	}
+}

+ 17 - 15
src/main/java/com/example/xiaoshiweixinback/business/utils/CollectionKit.java

@@ -1,5 +1,7 @@
 package com.example.xiaoshiweixinback.business.utils;
 
+import cn.hutool.core.collection.BoundedPriorityQueue;
+
 import java.lang.reflect.Array;
 import java.util.*;
 import java.util.Map.Entry;
@@ -94,21 +96,21 @@ public class CollectionKit {
 	 * @param colls 集合数组
 	 * @return 分业后的段落内容
 	 */
-//	@SafeVarargs
-//	public static <T> List<T> sortPageAll2(int pageNo, int numPerPage, Comparator<T> comparator, Collection<T>... colls) {
-//		BoundedPriorityQueue<T> queue = new BoundedPriorityQueue<T>(pageNo * numPerPage);
-//		for (Collection<T> coll : colls) {
-//			queue.addAll(coll);
-//		}
-//
-//		//第一页且数目少于第一页显示的数目
-//		if(pageNo <=1 && queue.size() <= numPerPage) {
-//			return queue.toList();
-//		}
-//
-//		final int[] startEnd = PageKit.transToStartEnd(pageNo, numPerPage);
-//		return queue.toList().subList(startEnd[0], startEnd[1]);
-//	}
+	@SafeVarargs
+	public static <T> List<T> sortPageAll2(int pageNo, int numPerPage, Comparator<T> comparator, Collection<T>... colls) {
+		BoundedPriorityQueue<T> queue = new BoundedPriorityQueue<T>(pageNo * numPerPage);
+		for (Collection<T> coll : colls) {
+			queue.addAll(coll);
+		}
+
+		//第一页且数目少于第一页显示的数目
+		if(pageNo <=1 && queue.size() <= numPerPage) {
+			return queue.toList();
+		}
+
+		final int[] startEnd = PageKit.transToStartEnd(pageNo, numPerPage);
+		return queue.toList().subList(startEnd[0], startEnd[1]);
+	}
 
 	/**
 	 * 将Set排序(根据Entry的值)

+ 69 - 72
src/main/java/com/example/xiaoshiweixinback/business/utils/DateUtil.java

@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *//*
+ */
 
 package com.example.xiaoshiweixinback.business.utils;
 
@@ -32,23 +32,23 @@ import java.util.Map;
 public class DateUtil {
 
 
-	*/
-/**
+
+	/**
 	 * 获取YYYY格式
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static String getYear() {
 		return formatDate(new Date(), "yyyy");
 	}
 
-	*/
-/**
+
+	/**
 	 * 获取YYYY格式
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static String getYear(Date date) {
 		return formatDate(date, "yyyy");
@@ -58,89 +58,87 @@ public class DateUtil {
 		return formatDate(new Date(), format);
 	}
 	
-	*/
-/**
+
+	/**
 	 * 获取YYYY-MM-DD格式
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static String getDay() {
 		return formatDate(new Date(), "yyyy-MM-dd");
 	}
 
-	*/
-/**
+
+	/**
 	 * 获取YYYY-MM-DD格式
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static String getDay(Date date) {
 		return formatDate(date, "yyyy-MM-dd");
 	}
 
-	*/
-/**
+
+	/**
 	 * 获取YYYYMMDD格式
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static String getDays() {
 		return formatDate(new Date(), "yyyyMMdd");
 	}
 
-	*/
-/**
+
+	/**
 	 * 获取YYYYMMDD格式
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static String getDays(Date date) {
 		return formatDate(date, "yyyyMMdd");
 	}
 
-	*/
-/**
+	/**
 	 * 获取YYYY-MM-DD HH:mm:ss格式
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static String getTime() {
 		return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
 	}
 
-	*/
-/**
+
+ 	/**
 	 * 获取YYYY-MM-DD HH:mm:ss.SSS格式
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static String getMsTime() {
 		return formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
 	}
 
-	*/
-/**
+
+	/**
 	 * 获取YYYYMMDDHHmmss格式
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static String getAllTime() {
 		return formatDate(new Date(), "yyyyMMddHHmmss");
 	}
 
-	*/
-/**
+	/**
 	 * 获取YYYY-MM-DD HH:mm:ss格式
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static String getTime(Date date) {
 		return formatDate(date, "yyyy-MM-dd HH:mm:ss");
@@ -156,8 +154,8 @@ public class DateUtil {
 		return formatDate;
 	}
 
-	*/
-/**
+
+	/**
 	 * @Title: compareDate
 	 * @Description:(日期比较,如果s>=e 返回true 否则返回false)
 	 * @param s
@@ -165,7 +163,7 @@ public class DateUtil {
 	 * @return boolean
 	 * @throws
 	 * @author luguosui
-	 *//*
+	 */
 
 	public static boolean compareDate(String s, String e) {
 		if (parseDate(s) == null || parseDate(e) == null) {
@@ -174,34 +172,34 @@ public class DateUtil {
 		return parseDate(s).getTime() >= parseDate(e).getTime();
 	}
 
-	*/
-/**
+
+	/**
 	 * 格式化日期
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static Date parseDate(String date) {
 		return parse(date,"yyyy-MM-dd");
 	}
 
-	*/
-/**
+
+	/**
 	 * 格式化日期
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static Date parseTime(String date) {
 		return parse(date,"yyyy-MM-dd HH:mm:ss");
 	}
 
-	*/
-/**
+
+	/**
 	 * 格式化日期
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static Date parse(String date, String pattern) {
 		try {
@@ -212,46 +210,46 @@ public class DateUtil {
 		}
 	}
 
-	*/
-/**
+
+	/**
 	 * 格式化日期
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static String format(Date date, String pattern) {
 		return DateFormatUtils.format(date, pattern);
 	}
 
-	*/
-/**
+
+	/**
 	 * 把日期转换为Timestamp
 	 *
 	 * @param date
 	 * @return
-	 *//*
+	 */
 
 	public static Timestamp format(Date date) {
 		return new Timestamp(date.getTime());
 	}
 
-	*/
-/**
+
+	/**
 	 * 校验日期是否合法
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static boolean isValidDate(String s) {
 		return parse(s, "yyyy-MM-dd HH:mm:ss") != null;
 	}
 
-	*/
-/**
+
+	/**
 	 * 校验日期是否合法
 	 *
 	 * @return
-	 *//*
+	 */
 
 	public static boolean isValidDate(String s, String pattern) {
         return parse(s, pattern) != null;
@@ -269,15 +267,15 @@ public class DateUtil {
 		}
 	}
 
-	*/
-/**
+
+	/**
 	 * <li>功能描述:时间相减得到天数
 	 *
 	 * @param beginDateStr
 	 * @param endDateStr
 	 * @return long
 	 * @author Administrator
-	 *//*
+	 */
 
 	public static long getDaySub(String beginDateStr, String endDateStr) {
 		long day = 0;
@@ -298,13 +296,13 @@ public class DateUtil {
 		return day;
 	}
 
-	*/
-/**
+
+	/**
 	 * 得到n天之后的日期
 	 *
 	 * @param days
 	 * @return
-	 *//*
+	 */
 
 	public static String getAfterDayDate(String days) {
 		int daysInt = Integer.parseInt(days);
@@ -319,13 +317,13 @@ public class DateUtil {
 		return dateStr;
 	}
 
-	*/
-/**
+
+	/**
 	 * 得到n天之后是周几
 	 *
 	 * @param days
 	 * @return
-	 *//*
+	 */
 
 	public static String getAfterDayWeek(String days) {
 		int daysInt = Integer.parseInt(days);
@@ -340,12 +338,12 @@ public class DateUtil {
 		return dateStr;
 	}
 
-	*/
-/**
+
+	/**
 	 * 格式化Oracle Date
 	 * @param value
 	 * @return
-	 *//*
+	 */
 
 //	public static String buildDateValue(Object value){
 //		if(Func.isOracle()){
@@ -354,15 +352,14 @@ public class DateUtil {
 //			return Func.toStr(value);
 //		}
 //	}
-	*/
-/**
+
+	/**
 	 * @Description: 获取当前时间的周一及周日
 	 * @Param: Date
 	 * @Author: LHX
 	 * @Date: 9:59 2018/11/19
 	 * @return: java.util.Map<java.lang.String,java.lang.String>
-
-	 *//*
+	 */
 
 	public static Map<String,String> getWeekDate(Date date) {
 		Map<String,String> map = new HashMap();
@@ -396,4 +393,4 @@ public class DateUtil {
 	}
 
 }
-*/
+

+ 42 - 42
src/main/java/com/example/xiaoshiweixinback/business/utils/JSONUtil.java

@@ -1,42 +1,42 @@
-//package com.example.xiaoshiweixinback.business.utils;
-//
-//import com.alibaba.fastjson.JSON;
-//
-//
-///**
-//* @Description: JSON工具
-//* @author Orange
-//* @date 2018年1月28日
-//*
-//*/
-//public class JSONUtil {
-//
-//    /**
-//    * @Title: toJSONString
-//    * @Description: 转JSON字符串
-//    * @param @param obj
-//    * @param @return    参数
-//    * @return String    返回类型
-//    * @throws
-//    * @author Orange
-//    * @date 2018年1月28日
-//    */
-//    public static String toJSONString(Object obj){
-//        return JSON.toJSONString(obj);
-//    }
-//
-//    /**
-//    * @Title: parseObject
-//    * @Description: JSON字符串转实体
-//    * @param @param json
-//    * @param @param t
-//    * @param @return    参数
-//    * @return T    返回类型
-//    * @throws
-//    * @author Orange
-//    * @date 2018年1月28日
-//    */
-//    public static <T> T parseObject(String json,Class<T> t){
-//        return JSON.parseObject(json,t);
-//    }
-//}
+package com.example.xiaoshiweixinback.business.utils;
+
+import com.alibaba.fastjson.JSON;
+
+
+/**
+* @Description: JSON工具
+* @author Orange
+* @date 2018年1月28日
+*
+*/
+public class JSONUtil {
+
+    /**
+    * @Title: toJSONString
+    * @Description: 转JSON字符串
+    * @param @param obj
+    * @param @return    参数
+    * @return String    返回类型
+    * @throws
+    * @author Orange
+    * @date 2018年1月28日
+    */
+    public static String toJSONString(Object obj){
+        return JSON.toJSONString(obj);
+    }
+
+    /**
+    * @Title: parseObject
+    * @Description: JSON字符串转实体
+    * @param @param json
+    * @param @param t
+    * @param @return    参数
+    * @return T    返回类型
+    * @throws
+    * @author Orange
+    * @date 2018年1月28日
+    */
+    public static <T> T parseObject(String json,Class<T> t){
+        return JSON.parseObject(json,t);
+    }
+}

+ 180 - 233
src/main/java/com/example/xiaoshiweixinback/business/utils/LogHelper.java

@@ -1,233 +1,180 @@
-/*
-package com.example.xiaoshiweixinback.business.utils;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-*/
-/**
- * 日志工具类
- * @author Peach
- *
- *//*
-
-public class LogHelper {
-	
-	private static Logger logger = null;
-
-	//------------------------------------------系统日志记录-------------------------
-	*/
-/**
-	 * @param info
-	 *//*
-
-	public static void log(Object...info) {
-		logger = LoggerFactory.getLogger("");
-		logger.info("info={}",info);
-	}
-	
-	public static void log(Throwable e,Object...info) {
-		logger = LoggerFactory.getLogger("");
-		logger.info("exception={} info={}",throwable2String(e),info);
-	}
-	
-	*/
-/**
-	 * @param clazz
-	 * @param info
-	 *//*
-
-	public static void log(Class clazz, String info) {
-		logger = LoggerFactory.getLogger(clazz);
-		logger.info(info);
-	}
-	
-	*/
-/**
-	 * @param clazz
-	 * @param e
-	 *//*
-
-	public static void log(Class clazz, Throwable e) {
-		log(clazz,throwable2String(e));
-	}
-	
-	*/
-/**
-	 * @param name
-	 * @param info
-	 *//*
-
-	@Deprecated
-	public static void log(String name, String info) {
-		logger = LoggerFactory.getLogger(name);
-		logger.info(name+"-"+info);
-	}
-	
-	*/
-/**
-	 * @param name
-	 * @param e
-	 *//*
-
-	@Deprecated
-	public static void log(String name, Throwable e) {
-		log(name,throwable2String(e));
-	}
-	
-	
-	*/
-/**
-	 * @param name
-	 * @param info
-	 * @param e
-	 *//*
-
-	@Deprecated
-	public static void log(String name, String info,Throwable e) {
-		log(name,info+"-"+throwable2String(e));
-	}
-	
-	
-	*/
-/**
-	 * @param clazz
-	 * @param info
-	 * @param e
-	 *//*
-
-	public static void log(Class clazz, String info,Throwable e) {
-		log(clazz,info+"-"+throwable2String(e));
-	}
-	
-	*/
-/**
-	 * 将异常信息转为string
-	 * @param e
-	 * @return
-	 *//*
-
-	private static String throwable2String(Throwable e){
-		if(checkBaseBusinessException(e)) {
-			BaseBusinessException bbe = (BaseBusinessException)e;
-			return "----->"+bbe.getErrorMessage()+(bbe.getExtraMessage()==null?"":bbe.getExtraMessage());
-		}
-		PrintWriter pw = null;
-		StringWriter sw = null;
-		try{
-			sw = new StringWriter();
-			pw = new PrintWriter(sw);
-			e.printStackTrace(pw);
-			pw.flush();
-			sw.flush();
-		}catch (Exception e1) {
-			logger.info(e.getMessage());
-		}finally{
-			if(sw!=null){
-				try{
-					sw.close();
-				}catch (Exception e2) {
-					e2.printStackTrace();
-					return "";
-				}
-			}else{
-				return "";
-			}
-			if(pw!=null){
-				pw.close();
-			}
-			return sw.toString();
-		}
-		
-	}
-	
-	
-	*/
-/**
-	* @Title: checkBaseBusinessException
-	* @Description: 判断异常是否为系统异常
-	* @param @param e
-	* @param @return    参数
-	* @return boolean    返回类型
-	* @throws
-	* @author Orange
-	* @date 2019年1月23日
-	*//*
-
-	private static boolean checkBaseBusinessException(Throwable e) {
-		return BaseBusinessException.class.isInstance(e);
-	}
-	
-	
-	//------------------------------------------多业务日志记录-------------------------
-	
-	*/
-/**
-	* @Title: log
-	* @Description: 多业务动态日志
-	* @param @param businessLogTypeEnum
-	* @param @param info    参数
-	* @return void    返回类型
-	* @throws
-	* @author Orange
-	* @date 2019年1月21日
-	*//*
-
-	public static void log(BusinessLogTypeEnum businessLogTypeEnum,Object...info) {
-		MDC.put("businessName", businessLogTypeEnum.getType());
-		Logger logger = LoggerFactory.getLogger("business_log");
-		logger.info("businessName={}, info={}", businessLogTypeEnum.getType(), info);
-		MDC.remove(businessLogTypeEnum.getType());
-	}
-	
-	
-	
-	*/
-/**
-	* @Title: log
-	* @Description: 多业务动态日志
-	* @param @param businessLogTypeEnum
-	* @param @param e
-	* @param @param info    参数
-	* @return void    返回类型
-	* @throws
-	* @author Orange
-	* @date 2019年1月21日
-	*//*
-
-	public static void log(BusinessLogTypeEnum businessLogTypeEnum,Throwable e,Object...info) {
-		MDC.put("businessName", businessLogTypeEnum.getType());
-		Logger logger = LoggerFactory.getLogger("business_log");
-		logger.info("businessName={}, exception={} ,info={}", businessLogTypeEnum.getType(), throwable2String(e),info);
-		MDC.remove(businessLogTypeEnum.getType());
-	}
-	
-	
-	
-	*/
-/**
-	* @Title: warnLog
-	* @Description: 警告日志
-	* @param @param e
-	* @param @param info    参数
-	* @return void    返回类型
-	* @throws
-	* @author Orange
-	* @date 2019年1月26日
-	*//*
-
-	public static void warnLog(Throwable e,Object...info) {
-		//系统级别日志不打印
-		if(checkBaseBusinessException(e)) {
-			log(e,info);
-		}else {
-			Logger logger = LoggerFactory.getLogger("error_log");
-			logger.warn("[System Exception] exception={} ,info={}", throwable2String(e),info);
-		}
-	}
-}
-*/
+//package com.example.xiaoshiweixinback.business.utils;
+//
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.slf4j.MDC;
+//
+//import java.io.PrintWriter;
+//import java.io.StringWriter;
+//
+//
+///**
+// * 日志工具类
+// *
+// * @author Peach
+// */
+//
+//public class LogHelper {
+//
+//    private static Logger logger = null;
+//
+//    //------------------------------------------系统日志记录-------------------------
+//
+//    /**
+//     * @param info
+//     */
+//
+//    public static void log(Object... info) {
+//        logger = LoggerFactory.getLogger("");
+//        logger.info("info={}", info);
+//    }
+//
+//    public static void log(Throwable e, Object... info) {
+//        logger = LoggerFactory.getLogger("");
+//        logger.info("exception={} info={}", throwable2String(e), info);
+//    }
+//
+//
+//    /**
+//     * @param clazz
+//     * @param info
+//     */
+//
+//    public static void log(Class clazz, String info) {
+//        logger = LoggerFactory.getLogger(clazz);
+//        logger.info(info);
+//    }
+//
+//
+//    /**
+//     * @param clazz
+//     * @param e
+//     */
+//
+//    public static void log(Class clazz, Throwable e) {
+//        log(clazz, throwable2String(e));
+//    }
+//
+//    /**
+//     * @param name
+//     * @param info
+//     */
+//
+//    @Deprecated
+//    public static void log(String name, String info) {
+//        logger = LoggerFactory.getLogger(name);
+//        logger.info(name + "-" + info);
+//    }
+//
+//
+//    /**
+//     * @param name
+//     * @param e
+//     */
+//
+//    @Deprecated
+//    public static void log(String name, Throwable e) {
+//        log(name, throwable2String(e));
+//    }
+//
+//
+//    /**
+//     * @param name
+//     * @param info
+//     * @param e
+//     */
+//    @Deprecated
+//    public static void log(String name, String info, Throwable e) {
+//        log(name, info + "-" + throwable2String(e));
+//    }
+//
+//
+//    /**
+//     * @param clazz
+//     * @param info
+//     * @param e
+//     */
+//    public static void log(Class clazz, String info, Throwable e) {
+//        log(clazz, info + "-" + throwable2String(e));
+//    }
+//
+//
+//    /**
+//     * 将异常信息转为string
+//     *
+//     * @param e
+//     * @return
+//     */
+//
+//    private static String throwable2String(Throwable e) {
+//        if (checkBaseBusinessException(e)) {
+//            BaseBusinessException bbe = (BaseBusinessException) e;
+//            return "----->" + bbe.getErrorMessage() + (bbe.getExtraMessage() == null ? "" : bbe.getExtraMessage());
+//        }
+//        PrintWriter pw = null;
+//        StringWriter sw = null;
+//        try {
+//            sw = new StringWriter();
+//            pw = new PrintWriter(sw);
+//            e.printStackTrace(pw);
+//            pw.flush();
+//            sw.flush();
+//        } catch (Exception e1) {
+//            logger.info(e.getMessage());
+//        } finally {
+//            if (sw != null) {
+//                try {
+//                    sw.close();
+//                } catch (Exception e2) {
+//                    e2.printStackTrace();
+//                    return "";
+//                }
+//            } else {
+//                return "";
+//            }
+//            if (pw != null) {
+//                pw.close();
+//            }
+//            return sw.toString();
+//        }
+//
+//    }
+//
+//
+//    /**
+//     * @param @param  e
+//     * @param @return 参数
+//     * @return boolean    返回类型
+//     * @throws
+//     * @Title: checkBaseBusinessException
+//     * @Description: 判断异常是否为系统异常
+//     * @author Orange
+//     * @date 2019年1月23日
+//     */
+//
+//    private static boolean checkBaseBusinessException(Throwable e) {
+//        return BaseBusinessException.class.isInstance(e);
+//    }
+//
+//
+//    //------------------------------------------多业务日志记录-------------------------
+//    /**
+//     * @param @param e
+//     * @param @param info    参数
+//     * @return void    返回类型
+//     * @throws
+//     * @Title: warnLog
+//     * @Description: 警告日志
+//     * @author Orange
+//     * @date 2019年1月26日
+//     */
+//    public static void warnLog(Throwable e, Object... info) {
+//        //系统级别日志不打印
+//        if (checkBaseBusinessException(e)) {
+//            log(e, info);
+//        } else {
+//            Logger logger = LoggerFactory.getLogger("error_log");
+//            logger.warn("[System Exception] exception={} ,info={}", throwable2String(e), info);
+//        }
+//    }
+//}

+ 4 - 2
src/main/java/com/example/xiaoshiweixinback/business/utils/PageKit.java

@@ -1,6 +1,8 @@
 package com.example.xiaoshiweixinback.business.utils;
 
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
 import java.util.List;
 
 /**
@@ -58,7 +60,7 @@ public class PageKit {
 				: (totalCount / numPerPage + 1);
 	}
 
-/*	public static <T> Page<T> paged(List<T> list) {
+	public static <T> Page<T> paged(List<T> list) {
 		int current = 1;
 		int size = 10;
 		Page<T> page = new Page<>(current, size);
@@ -69,5 +71,5 @@ public class PageKit {
 		page.setPages(count % 10 == 0 ? count / 10 : count /10 + 1);
 		page.setRecords(list);
 		return page;
-	}*/
+	}
 }

+ 12 - 1
src/main/java/com/example/xiaoshiweixinback/controller/LoginController.java

@@ -2,7 +2,18 @@ package com.example.xiaoshiweixinback.controller;
 
 
 import com.example.xiaoshiweixinback.entity.dto.LoginDTO;
+import com.example.xiaoshiweixinback.entity.dto.WXLoginDTO;
 import com.example.xiaoshiweixinback.entity.vo.LoginVO;
+import com.example.xiaoshiweixinback.entity.vo.SendCodeVO;
+import com.example.xiaoshiweixinback.entity.vo.WXLoginVO;
+import com.example.xiaoshiweixinback.service.LoginService;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.validation.Valid;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 /**
  * 登录相关接口
@@ -28,6 +39,6 @@ public class LoginController {
     //发送验证码
     @PostMapping("/sendCode")
     public boolean sendCode(@RequestBody @Valid SendCodeVO vo, HttpServletRequest request) {
-        return appLoginService.sendCode(vo,request);
+        return true;
     }
 }

+ 32 - 33
src/main/java/com/example/xiaoshiweixinback/okhttp/RequestManager.java

@@ -1,11 +1,11 @@
 package com.example.xiaoshiweixinback.okhttp;
 
-import com.bjbz.common.exception.BusinessException;
-import com.bjbz.common.exception.BusinessExceptionErrorEnum;
-import com.bjbz.common.filter.AuthFilter;
-import com.bjbz.common.util.JSONUtil;
-import com.bjbz.core.log.tools.LogHelper;
+import com.example.xiaoshiweixinback.business.common.log.LogHelper;
+import com.example.xiaoshiweixinback.business.exception.BusinessException;
+import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
+import com.example.xiaoshiweixinback.business.utils.JSONUtil;
 import okhttp3.*;
+import sun.net.httpserver.AuthFilter;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -62,36 +62,35 @@ public class RequestManager {
      * @param token
      * @return
      */
-	public String postJsonInnerAppByToken(String url, Object object, String token) {
-		RequestBody body = RequestBody.create(MEDIA_TYPE_JSON,JSONUtil.toJSONString(object));
-		Request request = new Request.Builder()
-				.url(url)
-				.post(body)
-				.addHeader(AuthFilter.HEADER, token)
-				.build();
-		String result=null;
-		try {
-			LogHelper.log(RequestManager.class,url+":调用请求->"+JSONUtil.toJSONString(object));
-			Response response = mOkHttpClient.newCall(request).execute();
-			if (response.isSuccessful()) {
-				result = response.body().string();
-				LogHelper.log(RequestManager.class,url+":调用成功->"+result);
-			}else{
-				LogHelper.log(RequestManager.class,url+":调用失败->"+response.message());
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-			LogHelper.log(e,url+":调用异常");
-			throw new BusinessException(BusinessExceptionErrorEnum.SYSTEM_HTTP_ERROR);
-		}
-		return result;
-	}
+//	public String postJsonInnerAppByToken(String url, Object object, String token) {
+//		RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, JSONUtil.toJSONString(object));
+//		Request request = new Request.Builder()
+//				.url(url)
+//				.post(body)
+//				.addHeader(AuthFilter.HEADER, token)
+//				.build();
+//		String result=null;
+//		try {
+//			LogHelper.log(RequestManager.class,url+":调用请求->"+JSONUtil.toJSONString(object));
+//			Response response = mOkHttpClient.newCall(request).execute();
+//			if (response.isSuccessful()) {
+//				result = response.body().string();
+//				LogHelper.log(RequestManager.class,url+":调用成功->"+result);
+//			}else{
+//				LogHelper.log(RequestManager.class,url+":调用失败->"+response.message());
+//			}
+//		} catch (Exception e) {
+//			e.printStackTrace();
+//			LogHelper.log(e,url+":调用异常");
+//			throw new BusinessException(ExceptionEnum.SYSTEM_ERROR);
+//		}
+//		return result;
+//	}
 
 	/**
 	 * 向内部应用发送JSON请求通过token
 	 * @param url
-	 * @param object
-	 * @param token
+	 * @param params
 	 * @return
 	 */
 	public String postNormalInnerAppByToken(String url, Map<String,String> params) {
@@ -120,7 +119,7 @@ public class RequestManager {
 		} catch (Exception e) {
 			e.printStackTrace();
 			LogHelper.log(e,url+":调用异常");
-			throw new BusinessException(BusinessExceptionErrorEnum.SYSTEM_HTTP_ERROR);
+			throw new BusinessException(ExceptionEnum.SYSTEM_ERROR);
 		}
 		return result;
 	}
@@ -156,7 +155,7 @@ public class RequestManager {
 			LogHelper.log("response ----->" + result);
 		}
 		else {
-			throw new BusinessException(BusinessExceptionErrorEnum.REQUEST_ERROR,response.code());
+			throw new BusinessException(ExceptionEnum.SYSTEM_ERROR);
 		}
 		return result;
 	}

+ 48 - 30
src/main/java/com/example/xiaoshiweixinback/service/LoginService.java

@@ -1,16 +1,31 @@
 package com.example.xiaoshiweixinback.service;
 
 
+import com.alibaba.fastjson2.JSONObject;
+import com.example.xiaoshiweixinback.business.common.log.LogHelper;
 import com.example.xiaoshiweixinback.business.exception.BusinessException;
-import com.example.xiaoshiweixinback.business.exception.BusinessExceptionErrorEnum;
+import com.example.xiaoshiweixinback.business.exception.ExceptionEnum;
 import com.example.xiaoshiweixinback.business.jwt.JwtTokenUtil;
+import com.example.xiaoshiweixinback.business.redis.CacheTTLEnum;
+import com.example.xiaoshiweixinback.business.redis.RedisService;
 import com.example.xiaoshiweixinback.business.utils.RandomUtil;
 import com.example.xiaoshiweixinback.business.utils.RegexUtil;
 import com.example.xiaoshiweixinback.business.utils.ToolUtil;
+import com.example.xiaoshiweixinback.domain.Person;
+import com.example.xiaoshiweixinback.entity.dto.LoginDTO;
+import com.example.xiaoshiweixinback.entity.dto.WXLoginDTO;
 import com.example.xiaoshiweixinback.entity.vo.Jscode2SessionWo;
+import com.example.xiaoshiweixinback.entity.vo.LoginVO;
 import com.example.xiaoshiweixinback.entity.vo.SendCodeVO;
+import com.example.xiaoshiweixinback.entity.vo.WXLoginVO;
 import com.example.xiaoshiweixinback.okhttp.RequestManager;
 import com.example.xiaoshiweixinback.okhttp.ResponseManager;
+import jakarta.servlet.http.HttpServletRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.crypto.Cipher;
 import javax.crypto.spec.IvParameterSpec;
@@ -26,11 +41,14 @@ public class LoginService {
     @Autowired
     private JwtTokenUtil jwtTokenUtil;
 
+    @Autowired
+    private RedisService redisService;
+
 
     @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Throwable.class)
-    public LoginDTO login(LoginVO vo) {
+    public LoginVO login(LoginDTO vo) {
         LogHelper.log("登录开始");
-        LoginDTO loginDTO = new LoginDTO();
+        LoginVO loginDTO = new LoginVO();
         //查询用户
         LogHelper.log("登陆结束");
         return loginDTO;
@@ -66,25 +84,25 @@ public class LoginService {
             //2.查询数据表
             Person person = new Person();
             if (ToolUtil.isNotEmpty(person)) {
-                wxLoginDTO.setOpenId();
+//                wxLoginDTO.setOpenId();
                 wxLoginDTO.setToken(this.getToken());
             } else {
                 // 3. 解密用户数据
-                String decryptedData = decrypt(encryptedData, jscode2SessionWo.getSession_key(), iv);
+//                String decryptedData = decrypt(encryptedData, jscode2SessionWo.getSession_key(), iv);
 
                 // 4. 获取用户手机号(需要用户授权)
                 String phoneNumber = "";
-                JSONObject userData = JSONObject.parseObject(decryptedData);
-                if (ToolUtil.isNotEmpty(userData) && userData.containsKey("purePhoneNumber")) {
-                    phoneNumber = userData.getString("purePhoneNumber");
-                }
+//                JSONObject userData = JSONObject.parseObject(decryptedData);
+//                if (ToolUtil.isNotEmpty(userData) && userData.containsKey("purePhoneNumber")) {
+//                    phoneNumber = userData.getString("purePhoneNumber");
+//                }
 
                 if (jscode2SessionWo.getOpenid() != null) {
                     //添加用户表中
                     wxLoginDTO.setOpenId(jscode2SessionWo.getOpenid());
-                    wxLoginDTO.setToken(this.getToken(user));
+                    wxLoginDTO.setToken(this.getToken());
                 } else {
-                    throw new BusinessException(BusinessExceptionErrorEnum.SYSTEM_ERROR);
+                    throw new BusinessException(ExceptionEnum.SYSTEM_ERROR);
                 }
             }
         }
@@ -103,7 +121,7 @@ public class LoginService {
         String random = RandomUtil.getSixRandom();
 
         //手机号和验证码放进缓存 设置过期时间15m
-        redisService.set(vo.getPhoneNo(), random);
+        redisService. set(vo.getPhoneNo(), random);
         redisService.expire(vo.getPhoneNo(), CacheTTLEnum.FIFTEEN_MINUTE);
         //发送短信
 //        smsService.sendMessage(vo.getPhoneNo(), random);
@@ -126,24 +144,24 @@ public class LoginService {
      * @param iv            加密算法的初始向量
      * @return 解密后的用户数据
      */
-    private static String decrypt(String encryptedData, String sessionKey, String iv) {
-        byte[] encryptedDataByte = Base64.decodeBase64(encryptedData);
-        byte[] sessionKeyByte = Base64.decodeBase64(sessionKey);
-        byte[] ivByte = Base64.decodeBase64(iv);
-
-        try {
-            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
-            SecretKeySpec secretKeySpec = new SecretKeySpec(sessionKeyByte, "AES");
-            IvParameterSpec ivParameterSpec = new IvParameterSpec(ivByte);
-            cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);
-
-            byte[] decryptedDataByte = cipher.doFinal(encryptedDataByte);
-            return new String(decryptedDataByte);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
+//    private static String decrypt(String encryptedData, String sessionKey, String iv) {
+//        byte[] encryptedDataByte = Base64.decodeBase64(encryptedData);
+//        byte[] sessionKeyByte = Base64.decodeBase64(sessionKey);
+//        byte[] ivByte = Base64.decodeBase64(iv);
+//
+//        try {
+//            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+//            SecretKeySpec secretKeySpec = new SecretKeySpec(sessionKeyByte, "AES");
+//            IvParameterSpec ivParameterSpec = new IvParameterSpec(ivByte);
+//            cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec);
+//
+//            byte[] decryptedDataByte = cipher.doFinal(encryptedDataByte);
+//            return new String(decryptedDataByte);
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//        return null;
+//    }
 
 
     /*public String getAccessToken() {