com.luues.util.datawrap.ResultCode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-util Show documentation
Show all versions of commons-util Show documentation
A Simple Tool Operations Class
package com.luues.util.datawrap;
import com.alibaba.fastjson.JSONObject;
import com.luues.util.encryption.AESUtil;
import com.luues.util.encryption.RSAUtil_back;
import com.luues.util.TypeConvert;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 返回码
*
* @author wg
*
*/
public class ResultCode {
private ResultCode(){}
/** 无相关权限 */
public static int c_401 = 401;
/** 系统繁忙,操作失败 */
public static int c_100 = 100;
/** 通过、合法、允许、正常 等非错误标志 */
public static int c_200 = 200;
/** 请先登录 */
public static int c_400 = 400;
/** 系统错误 */
public static int c_500 = 500;
/** 重复提交 */
public static int c_403 = 403;
/** 未中奖 */
public static int c_414 = 414;
/** 抽奖次数不足 */
public static int c_415 = 415;
/** 推荐码不存在 */
public static int c_416 = 416;
/** 微信支付错误 */
public static int c_505 = 505;
/** 用户已存在 */
public static int c_601 = 601;
/** 未查到认证信息 */
public static int c_602 = 602;
/** 未查到用户 */
public static int c_603 = 603;
/** 账号或密码错误 */
public static int c_604 = 604;
/** 格式有误 */
public static int c_300 = 300;
/** 参数缺失 */
public static int c_301 = 301;
/** 请勿重复关注 */
public static int c_302 = 302;
/** 取消关注失败,未找到关注信息 */
public static int c_303 = 303;
/** 该机构认证信息审核中或已认证通过 */
public static int c_304 = 304;
/** 请先资料认证 */
public static int c_305 = 305;
/** 认证信息审核中 */
public static int c_306 = 306;
/** 用户不存在 */
public static int c_307 = 307;
/** 密码错误 */
public static int c_308 = 308;
/** 该机构已认证通过 */
public static int c_309 = 309;
/** 该投资人已认证通过 */
public static int c_310 = 310;
/** 文件上传失败 */
public static int c_311 = 311;
/** 文件类型有误 */
public static int c_312 = 312;
/** 文件超出限制大小 */
public static int c_313 = 313;
/** 上传方式有误 */
public static int c_314 = 314;
/** 还有阶段审核未处理 */
public static int c_315 = 315;
/** 该申请已有成功融资记录 */
public static int c_316 = 316;
/** 重复推荐 */
public static int c_317 = 317;
/** 操作失败,流程错误 */
public static int c_318 = 318;
/** 请勿重复提交 */
public static int c_319 = 319;
/** 验证码已失效 */
public static int c_101 = 101;
/** 验证码有误 */
public static int c_102 = 102;
/** 没有找到相关数据 */
public static int c_103 = 103;
/** 短信发送失败 */
public static int c_201 = 201;
/** 网络请求失败,请刷新重试 */
public static int c_202 = 202;
/** 数据库错误 */
public static int c_203 = 203;
/** 邮件发送失败 */
public static int c_204 = 204;
/**
*
*/
public static int c_101_h = 101; //参数缺失
public static int c_102_h = 102; //参数不合法 (可能是包封装错误、空参、参数类型不正确、找不到参数对应值等)
public static int c_103_h = 103; //无相关信息
public static int c_104 = 104; //身份证,手机号,时间等格式错误
public static int c_105 = 105; //重复提交
public static int c_106 = 106; //信息已被处理,重复处理
public static int c_107 = 107; //该状态不能该操作
public static int c_108 = 108; //信息已存在
public static int c_404 = 404; //下载找不到路径
public static int c_600 = 600; //异常
public static int c_109 = 109; //验证码错误
public static int c_110 = 110; //企业不合法
public static int c_111 = 111; //企业不诚信
public static int c_112 = 112; //超过申请次数2次
public static int c_113 = 113; //一年只能一次
public static int c_114 = 114; //当前已有申请,无需重复提交
public static int c_115 = 115; //导出文件失败
public static int c_116 = 116; //企业信息已变更
public static int c_117 = 117; //非法请求,需要先验证是否能申请后续扶持
public static int c_118 = 118; //找不到对应企业
public static int c_119 = 119; //该申请被举报
public static int c_120 = 120; //超过最大补助金额
public static int c_121 = 121; //补助金额必须大于0
public static int c_122 = 122; //输入金额格式不正确
public static int c_123 = 123; //超过申请次数1次
public static int c_124 = 124; //总申请补助次数不能超过3次
public static int c_125 = 125; //总补助金额不能超过50万
public static int c_126 = 126; //企业成立时间必须超过半年
public static int c_127 = 127; //企业成立时间必须超过1年
public static int c_129 = 129; //企业注册资金获取失败
public static int c_130 = 130; //您的企业被加入停业歇业库,不能申请补助
public static int c_131 = 131; //您的企业存在经营异常,不能申请补助
public static int c_132 = 132; //企业成立时间获取失败
public static int c_133 = 133; //您的企业年报信息不完整,不能申请补助
public static int c_134 = 134; //当前企业没有资格申请后续扶持补助
public static int c_135 = 135; //非微企
public static int c_137 = 137; //法人存在的其他企业已申请或享受过此类补助,不能再申请
public static int c_138 = 138; //您已享受此补助,不能再次申请
public static int c_300_h = 300; //账号或者密码错误
public static int c_301_h = 301; //账号已被锁定
public static int c_312_h = 312; //密码错误
public static int c_306_h = 306; //上传方式有误,无法获取
public static int c_302_h = 302; //上传文件类型错误
public static int c_303_h = 303; //上传文件大小超过限制
public static int c_304_h = 304; //上传失败
public static int c_305_h = 305; //文件路径不匹配
public static int c_201_h = 201; //企业类型错误
public static int c_202_h = 202; //memberid与carve_out_user_id 不能都为空
public static int c_203_h = 203; //区域未查询到对应微企科
public static int c_204_h = 204; //登录用户获取失败
public static int c_205 = 205; //已存在培训合格结果或正在培训中,不能继续申请培训
public static int c_206 = 206; //该身份证号不能再次申请培训
public static int c_207 = 207; //区域获取失败,没有该数据
public static int c_208 = 208; //获取所属微企用户id失败
public static int c_209 = 209; //满意度必须为大于0的整数
public static int c_210 = 210; //补贴必须为大于0的数字
public static int c_211 = 211; //结束时间必须大于开始时间
public static int c_212 = 212; //培训机构修改or新增,提示:全称重名了
public static int c_213 = 213; //培训机构修改or新增,提示:简称重名了
public static int c_214 = 214; //选择培训班不符合
public static int c_215 = 215; //开班时间异常,无法分配
public static int c_216 = 216; //开班时间超过60天不能再分配
public static int c_217 = 217; //时间判断异常
public static int c_218 = 218; //人数规模异常,无法分配
public static int c_219 = 219; //人数超过班级上限则不能分配
public static int c_220 = 220; //创业补助申请-pripid匹配不到企业、法人相关数据
public static int c_221 = 221; //创业补助申请-未匹配到对应工商所
public static int c_222 = 222; //特色效益农业必须要上传创业回访表
public static int c_223 = 223; //创业补助申请-该企业已享受补助
public static int c_224 = 224; //培训通过才能申请补助
public static int c_225 = 225; //创业补助申请-该身份证的补助申请正在处理中
public static int c_226 = 226; //创业补助申请-该身份证的补助申请正在处理中
public static int c_227 = 227; //创业补助申请-成立时间格式错误
public static int c_228 = 228; //创业补助申请-成立时间2个月内-1年以外不能申请
public static int c_229 = 229; //创业补助申请-时间比较失败
public static int c_230 = 230; //原始密码错误
public static int c_231 = 231; //流程或状态获取为空
public static int c_232 = 232; //所选评审单位不符合
public static int c_233 = 233; //还有评审单位未处理,操作失败
public static int c_234 = 234; //法人身份证有误
public static int c_235 = 235; //登陆失败,原因:当月已新增定点监测数据
public static int c_236 = 236; //已经是其他公司的股东或法人
public static int c_237 = 237; //微信二维码获取失败
public static int c_238 = 238; //微信二维码解析失败
public static int c_239 = 239; //账号已存在
public static final String code_key = "resultCode";
public static final String default_currPage = "1";
public static final String default_pageSize = "10";
/**
* 获取请求来源设备信息
*/
public static String getUserAgent(HttpServletRequest request) {
return request.getHeader("USER-AGENT");
}
/**
* 是否移动端
*
* @param request
* @return
*/
public static boolean checkMobile(HttpServletRequest request) {
return CheckMobile.check(getUserAgent(request));
}
/**
* 获取ip地址
*
* @param request
* @return
*/
public static String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
ip = request.getHeader("Proxy-Client-IP");
}
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if ((ip == null) || (ip.length() == 0) || ("unknown".equalsIgnoreCase(ip))) {
ip = request.getRemoteAddr();
}
return ip;
}
/**
* 获取分页信息
*
* @return
*/
public static Map getPager(HttpServletRequest request, JSONObject json, String key) {
try {
String currPage = default_currPage;
String pageSize = default_pageSize;
Map pagerMap = new HashMap();
if (!TypeConvert.isNull(request) && !TypeConvert.isNull(request.getParameter("currPage"))) {
currPage = request.getParameter("currPage");
}
if (!TypeConvert.isNull(json) && !TypeConvert.isNull(json.getString("currPage"))) {
currPage = json.getString("currPage");
try {
Integer.valueOf(currPage);
}catch (Exception e){
currPage = RSAUtil_back.decode(currPage, key);
}
}
if (!TypeConvert.isNull(request) && !TypeConvert.isNull(request.getParameter("pageSize"))) {
pageSize = request.getParameter("pageSize");
}
if (!TypeConvert.isNull(json) && !TypeConvert.isNull(json.getString("pageSize"))) {
pageSize = json.getString("pageSize");
try {
Integer.valueOf(pageSize);
}catch (Exception e){
try{
String pageSizes = RSAUtil_back.decode(pageSize, key);
try{
Integer.valueOf(pageSizes);
pageSize = pageSizes;
}catch (Exception e2){
pageSize = AESUtil.decrypt(pageSize, null);
}
}catch (Exception e1){
pageSize = AESUtil.decrypt(pageSize, null);
}
}
}
try {
pagerMap.put("currPage", (Integer.valueOf(currPage) - 1) * Integer.valueOf(pageSize));
} catch (Exception e) {
pagerMap.put("currPage", Integer.valueOf(default_currPage) - 1);
}
try {
pagerMap.put("pageSize", Integer.valueOf(pageSize) > 20 ? 20 : Integer.valueOf(pageSize));
} catch (Exception e) {
pagerMap.put("pageSize", Integer.valueOf(default_pageSize));
}
/*if(!TypeConvert.isNull(request)){
RedisTemplate.setExString(SourceType.Redis, "wdypagerMap&" + request, 60, Integer.valueOf(currPage) - 1 + "&" + pagerMap.get("pageSize").toString());
}*/
return pagerMap;
}catch (Exception e){
e.printStackTrace();
return null;
}
}
/*public static int getCurrPage(){
try {
if(RedisTemplate.isExistKey(SourceType.Redis, "wdypagerMap&" + request)){
return Integer.valueOf(RedisTemplate.getString(SourceType.Redis, "wdypagerMap&" + request).split("&")[0]) + 1;
}else{
return Integer.valueOf(default_currPage);
}
}catch (Exception e){
return Integer.valueOf(default_currPage);
}
}
public static int getPageSize(){
try {
if(RedisTemplate.isExistKey(SourceType.Redis, "wdypagerMap&" + request)){
return Integer.valueOf(RedisTemplate.getString(SourceType.Redis, "wdypagerMap&" + request).split("&")[1]);
}else{
return Integer.valueOf(default_pageSize);
}
}catch (Exception e){
return Integer.valueOf(default_pageSize);
}
}*/
/**
* 将汉字转成编码
*
* @param str
* @return
*/
public static String chinaToUnicode(String str) {
String result = "";
for (int i = 0; i < str.length(); i++) {
int chr1 = str.charAt(i);
if ((chr1 >= 19968) && (chr1 <= 171941))
result = result + "\\u" + Integer.toHexString(chr1);
else {
result = result + str.charAt(i);
}
}
return result;
}
}
class CheckMobile {
// \b 是单词边界(连着的两个(字母字符 与 非字母字符) 之间的逻辑上的间隔),
// 字符串在编译时会被转码一次,所以是 "\\b"
// \B 是单词内部逻辑间隔(连着的两个字母字符之间的逻辑上的间隔)
static String phoneReg = "\\b(ip(hone|od)|android|opera m(ob|in)i" + "|windows (phone|ce)|blackberry"
+ "|s(ymbian|eries60|amsung)|p(laybook|alm|rofile/midp" + "|laystation portable)|nokia|fennec|htc[-_]"
+ "|mobile|up.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";
static String tableReg = "\\b(ipad|tablet|(Nexus 7)|up.browser" + "|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";
// 移动设备正则匹配:手机端、平板
static Pattern phonePat = Pattern.compile(phoneReg, Pattern.CASE_INSENSITIVE);
static Pattern tablePat = Pattern.compile(tableReg, Pattern.CASE_INSENSITIVE);
/**
* 检测是否是移动设备访问
*
* @Title: check
* @Date : 2014-7-7 下午01:29:07
* @param userAgent
* 浏览器标识
* @return true:移动设备接入,false:pc端接入
*/
public static boolean check(String userAgent) {
if (null == userAgent) {
userAgent = "";
}
// 匹配
Matcher matcherPhone = phonePat.matcher(userAgent);
Matcher matcherTable = tablePat.matcher(userAgent);
if (matcherPhone.find() || matcherTable.find()) {
return true;
} else {
return false;
}
}
}