风险项依赖治理

This commit is contained in:
anran.war 2021-12-10 13:00:39 +08:00 committed by anruence
parent f2c2b929e3
commit fa6f63948b
252 changed files with 5190 additions and 5590 deletions

View File

@ -4,7 +4,7 @@
有问题或者宝贵意见联系我的QQ,非常希望你的加入!
##要求:
1.lombook-- idea插件请大家下载 ,去除setget构造方法等,阿里巴巴代码规范插件请自行下载<br>
1.lombok-- idea插件请大家下载 ,去除setget构造方法等,阿里巴巴代码规范插件请自行下载<br>
2.**尽量将长的类名,方法名,变量名精简**<br>
1.长的类名会使开发者不易生命该类型的变量

View File

@ -10,54 +10,54 @@ import java.math.BigDecimal;
/**
* 用户的帐户信息账户 一个LoginInfo 对应一个UserInfo对应一个Account
*
*
* @author 邱润泽
*/
@Getter
@Setter
@Alias("Account")
public class Account extends BaseDomain {
private static final long serialVersionUID = 6760287512112252557L;
private int version;
private String tradePassword; // 交易密码
private BigDecimal usableAmount = BidConst.ZERO; // 可用余额
private BigDecimal freezedAmount = BidConst.ZERO; // 冻结金额
private BigDecimal unReceiveInterest = BidConst.ZERO; // 账户待收利息
private BigDecimal unReceivePrincipal = BidConst.ZERO; // 账户待收本金
private BigDecimal unReturnAmount = BidConst.ZERO; // 账户待还金额
private BigDecimal remainBorrowLimit = BidConst.ZERO; // 账户剩余授信额度
private BigDecimal borrowLimitAmount; // 授信额度当前还可以信用借款额度
private static final long serialVersionUID = 6760287512112252557L;
private int version;
private String tradePassword; // 交易密码
private BigDecimal usableAmount = BidConst.ZERO; // 可用余额
private BigDecimal freezedAmount = BidConst.ZERO; // 冻结金额
private BigDecimal unReceiveInterest = BidConst.ZERO; // 账户待收利息
private BigDecimal unReceivePrincipal = BidConst.ZERO; // 账户待收本金
private BigDecimal unReturnAmount = BidConst.ZERO; // 账户待还金额
private BigDecimal remainBorrowLimit = BidConst.ZERO; // 账户剩余授信额度
private BigDecimal borrowLimitAmount; // 授信额度当前还可以信用借款额度
private String abstractInfo;//摘要信息用于防篡改检查;
private String abstractInfo;//摘要信息用于防篡改检查;
public String getAbstractInfo() {//可用余额 + 冻结金额 + 账户神域的授权额度
return MD5Utils.MD5(usableAmount.add(freezedAmount)
.add(remainBorrowLimit).toString());
}
public static Account empty(Long id) {
Account account = new Account();
account.setId(id);
account.setBorrowLimitAmount(BidConst.DEFALUT_BORROWLIMITAMOUNT);
account.setRemainBorrowLimit(BidConst.DEFALUT_BORROWLIMITAMOUNT);
return account;
}
public boolean checkAbstractInfo() {//可用余额 + 冻结金额 + 账户神域的授权额度
return MD5Utils.MD5(
usableAmount.add(freezedAmount).add(remainBorrowLimit)
.toString()).equals(abstractInfo);
}
public String getAbstractInfo() {//可用余额 + 冻结金额 + 账户神域的授权额度
return MD5Utils.MD5(usableAmount.add(freezedAmount)
.add(remainBorrowLimit).toString());
}
public BigDecimal getTotalAmount() {
return usableAmount.add(freezedAmount).add(unReceivePrincipal);
}
public boolean checkAbstractInfo() {//可用余额 + 冻结金额 + 账户神域的授权额度
return MD5Utils.MD5(
usableAmount.add(freezedAmount).add(remainBorrowLimit)
.toString()).equals(abstractInfo);
}
public void addUseableAmount(BigDecimal amount) {
this.usableAmount = this.usableAmount.add(amount);
}
public BigDecimal getTotalAmount() {
return usableAmount.add(freezedAmount).add(unReceivePrincipal);
}
public void addFreezedAmount(BigDecimal amount) {
this.freezedAmount = this.freezedAmount.add(amount);
}
public void addUseableAmount(BigDecimal amount) {
this.usableAmount = this.usableAmount.add(amount);
}
public static Account empty(Long id) {
Account account = new Account();
account.setId(id);
account.setBorrowLimitAmount(BidConst.DEFALUT_BORROWLIMITAMOUNT);
account.setRemainBorrowLimit(BidConst.DEFALUT_BORROWLIMITAMOUNT);
return account;
}
public void addFreezedAmount(BigDecimal amount) {
this.freezedAmount = this.freezedAmount.add(amount);
}
}

View File

@ -12,6 +12,6 @@ import java.io.Serializable;
@Setter
public class BaseDomain implements Serializable {
protected Long id;
protected Long id;
}

View File

@ -8,39 +8,40 @@ import java.util.Date;
/**
* 登陆日志
*
* @author Administrator
*/
@Getter
@Setter
@Alias("IpLog")
public class IpLog extends BaseDomain {
public static int LOGINSTATE_FAILD = 0;//登陆失败
public static int LOGINSTATE_SUCCESS = 1;//登陆成功
public static int LOGINSTATE_FAILD = 0;//登陆失败
public static int LOGINSTATE_SUCCESS = 1;//登陆成功
private String username;
private Date loginTime;
private String ip;
private String username;
private Date loginTime;
private String ip;
private int loginState;
private int loginType;
private Long loginInfoId;
public String getDisplayState(){
return this.loginState==LOGINSTATE_FAILD?"登录失败":"登录成功";
}
private int loginState;
private int loginType;
private Long loginInfoId;
public IpLog() {
super();
}
public IpLog() {
super();
}
public IpLog(String username, Date loginTime, String ip, int loginType,
Long loginInfoId) {
super();
this.username = username;
this.loginTime = loginTime;
this.ip = ip;
this.loginState = IpLog.LOGINSTATE_FAILD;
this.loginType = loginType;
this.loginInfoId = loginInfoId;
}
public IpLog(String username, Date loginTime, String ip, int loginType,
Long loginInfoId) {
super();
this.username = username;
this.loginTime = loginTime;
this.ip = ip;
this.loginState = IpLog.LOGINSTATE_FAILD;
this.loginType = loginType;
this.loginInfoId = loginInfoId;
}
public String getDisplayState() {
return this.loginState == LOGINSTATE_FAILD ? "登录失败" : "登录成功";
}
}

View File

@ -15,13 +15,13 @@ import java.util.Date;
@NoArgsConstructor
public class Logininfo implements Serializable {
private Long id;
private String nickname;
private String password;
private String salt;
private Date registerDate;
private Date lastLoginDate;
private int state = Constants.STATE_NORMAL;
private int userType;//用户类型
private boolean admin = false;
private Long id;
private String nickname;
private String password;
private String salt;
private Date registerDate;
private Date lastLoginDate;
private int state = Constants.STATE_NORMAL;
private int userType;//用户类型
private boolean admin = false;
}

View File

@ -10,25 +10,24 @@ import java.util.Map;
/**
* 数据字典
*
*
* @author Stef
*
*/
@Getter
@Setter
@Alias("SystemDictionary")
public class SystemDictionary extends BaseDomain {
private static final long serialVersionUID = 3382007784095246946L;
private String sn; // 编码
private String title; // 名称
private String intro; // 简介
private static final long serialVersionUID = 3382007784095246946L;
private String sn; // 编码
private String title; // 名称
private String intro; // 简介
public String getJsonString() {
Map<String, Object> m = new HashMap<>();
m.put("id", getId());
m.put("sn", sn);
m.put("title", title);
m.put("intro", intro);
return JSONObject.toJSONString(m);
}
public String getJsonString() {
Map<String, Object> m = new HashMap<>();
m.put("id", getId());
m.put("sn", sn);
m.put("title", title);
m.put("intro", intro);
return JSONObject.toJSONString(m);
}
}

View File

@ -10,7 +10,7 @@ import java.util.Map;
/**
* 数据字典明细
*
*
* @author Stef
*/
@Getter
@ -18,21 +18,21 @@ import java.util.Map;
@Alias("SystemDictionaryItem")
public class SystemDictionaryItem extends BaseDomain {
private static final long serialVersionUID = 4520006109163647891L;
private Long parentId; // 系统目录
private String title; // 名称
private String tvalue; //
private Integer sequence; // 序列
private String intro; // 说明
private static final long serialVersionUID = 4520006109163647891L;
private Long parentId; // 系统目录
private String title; // 名称
private String tvalue; //
private Integer sequence; // 序列
private String intro; // 说明
public String getJsonString() {
Map<String, Object> m = new HashMap<>();
m.put("id", getId());
m.put("parentId", parentId);
m.put("title", title);
m.put("tvalue", tvalue);
m.put("sequence", sequence);
m.put("intro", intro);
return JSONObject.toJSONString(m);
}
public String getJsonString() {
Map<String, Object> m = new HashMap<>();
m.put("id", getId());
m.put("parentId", parentId);
m.put("title", title);
m.put("tvalue", tvalue);
m.put("sequence", sequence);
m.put("intro", intro);
return JSONObject.toJSONString(m);
}
}

View File

@ -36,7 +36,7 @@ public class Userinfo extends BaseDomain {
*/
private String email;
/**
* 手机号
* 手机号
*/
private String phoneNumber = "";
/**
@ -54,7 +54,7 @@ public class Userinfo extends BaseDomain {
*/
private SystemDictionaryItem incomeGrade;
/**
* 婚姻情况
* 婚姻情况
*/
private SystemDictionaryItem marriage;
/**
@ -72,68 +72,15 @@ public class Userinfo extends BaseDomain {
public static Userinfo empty(Long id) {
Userinfo userinfo = new Userinfo();
userinfo.setId(id);
userinfo.setBitState(BitStatesUtils.OP_BASIC_INFO);
userinfo.setId(id);
userinfo.setBitState(BitStatesUtils.OP_BASIC_INFO);
return userinfo;
}
public void addState(Long state) {
this.bitState = BitStatesUtils.addState(this.bitState, state);
}
public void removeState(Long state) {
this.bitState = BitStatesUtils.removeState(this.bitState, state);
}
public boolean getIsBindPhone() {
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_BIND_PHONE);
}
public boolean getIsBindEmail() {
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_BIND_EMAIL);
}
public boolean getBaseInfo() {
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_BASE_INFO);
}
public boolean getRealAuth() {
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_REAL_AUTH);
}
public boolean getVedioAuth() {
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_VEDIO_AUTH);
}
public boolean getHasBidRequest(){
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_HAS_BIDRQUEST);
}
/**
* 获取用户真实名字的隐藏字符串只显示姓氏
*
* @param 真实名字
* @return
*/
public String getAnonymousRealName() {
if (StringUtils.hasLength(realName)) {
int len = realName.length();
String replace = "";
replace += realName.charAt(0);
for (int i = 1; i < len; i++) {
replace += "*";
}
return replace;
}
return realName;
}
/**
* 获取用户真实名字的隐藏字符串只显示姓氏
*
* @param realName
* 真实名字
* @param realName 真实名字
* @return
*/
public static String getAnonymousRealName(String realName) {
@ -171,12 +118,10 @@ public class Userinfo extends BaseDomain {
return idNumber;
}
/**
* 获取用户手机号码的隐藏字符串
*
* @param phoneNumber
* 用户手机号码
* @param phoneNumber 用户手机号码
* @return
*/
public static String getAnonymousPhoneNumber(String phoneNumber) {
@ -198,8 +143,7 @@ public class Userinfo extends BaseDomain {
/**
* 获取用户住址的隐藏字符串
*
* @param currentAddress
* 用户住址
* @param currentAddress 用户住址
* @return
*/
public static String getAnonymousCurrentAddress(String currentAddress) {
@ -215,4 +159,56 @@ public class Userinfo extends BaseDomain {
}
return currentAddress;
}
public void addState(Long state) {
this.bitState = BitStatesUtils.addState(this.bitState, state);
}
public void removeState(Long state) {
this.bitState = BitStatesUtils.removeState(this.bitState, state);
}
public boolean getIsBindPhone() {
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_BIND_PHONE);
}
public boolean getIsBindEmail() {
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_BIND_EMAIL);
}
public boolean getBaseInfo() {
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_BASE_INFO);
}
public boolean getRealAuth() {
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_REAL_AUTH);
}
public boolean getVedioAuth() {
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_VEDIO_AUTH);
}
public boolean getHasBidRequest() {
return BitStatesUtils.hasState(bitState, BitStatesUtils.OP_HAS_BIDRQUEST);
}
/**
* 获取用户真实名字的隐藏字符串只显示姓氏
*
* @param 真实名字
* @return
*/
public String getAnonymousRealName() {
if (StringUtils.hasLength(realName)) {
int len = realName.length();
String replace = "";
replace += realName.charAt(0);
for (int i = 1; i < len; i++) {
replace += "*";
}
return replace;
}
return realName;
}
}

View File

@ -14,22 +14,22 @@ public class OrdersExample {
oredCriteria = new ArrayList<Criteria>();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public boolean isDistinct() {
return distinct;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
@ -339,38 +339,6 @@ public class OrdersExample {
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
@ -406,5 +374,37 @@ public class OrdersExample {
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
}
}

View File

@ -9,35 +9,35 @@ import java.util.Date;
/**
* IpLog查询对象
* @author 邱润泽
*
* @author 邱润泽
*/
@Setter
@Getter
public class IpLogQueryObject extends QueryObject {
private Date beginDate;
private Date endDate;
private String username;
private int userType=-1;
private boolean like;
private int state=-1;
private Date beginDate;
private Date endDate;
private String username;
private int userType = -1;
private boolean like;
private int state = -1;
@DateTimeFormat(pattern = "yyyy-MM-dd")
public void setBeginDate(Date beginDate) {
this.beginDate = beginDate;
}
@DateTimeFormat(pattern = "yyyy-MM-dd")
public void setBeginDate(Date beginDate) {
this.beginDate = beginDate;
}
@DateTimeFormat(pattern = "yyyy-MM-dd")
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public Date getEndDate() {
if (endDate != null) {
return DateUtil.endOfDay(endDate);
}
return null;
}
public Date getEndDate() {
if (endDate != null) {
return DateUtil.endOfDay(endDate);
}
return null;
}
@DateTimeFormat(pattern = "yyyy-MM-dd")
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
}

View File

@ -5,62 +5,62 @@ import java.util.List;
public class PageResult {
private Integer totalCount;
private Integer pageSize = 10;
private Integer currentPage = 1;
private List result;
private Integer totalCount;
private Integer pageSize = 10;
private Integer currentPage = 1;
private List result;
public PageResult() {
public PageResult() {
}
}
public static PageResult empty(int pageSize) {
return new PageResult(0, pageSize, 1, new ArrayList());
}
public PageResult(Integer totalCount, Integer pageSize,
Integer currentPage, List result) {
super();
this.totalCount = totalCount;
this.pageSize = pageSize;
this.currentPage = currentPage;
this.result = result;
}
public PageResult(Integer totalCount, Integer pageSize,
Integer currentPage, List result) {
super();
this.totalCount = totalCount;
this.pageSize = pageSize;
this.currentPage = currentPage;
this.result = result;
}
public static PageResult empty(int pageSize) {
return new PageResult(0, pageSize, 1, new ArrayList());
}
public Integer getTotalPage() {
return Math.max((totalCount + pageSize - 1) / pageSize, 1);
}
public Integer getTotalPage() {
return Math.max((totalCount + pageSize - 1) / pageSize, 1);
}
public Integer getPrev() {
return Math.max(currentPage - 1, 1);
}
public Integer getPrev() {
return Math.max(currentPage - 1, 1);
}
public Integer getNext() {
return Math.min(currentPage + 1, getTotalPage());
}
public Integer getNext() {
return Math.min(currentPage + 1, getTotalPage());
}
public Integer getTotalCount() {
return totalCount;
}
public Integer getTotalCount() {
return totalCount;
}
public List getResult() {
return result;
}
public List getResult() {
return result;
}
public Integer getCurrentPage() {
return currentPage;
}
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public Integer getPageSize() {
return pageSize;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
}

View File

@ -8,11 +8,11 @@ import lombok.Setter;
@Setter
public class QueryObject {
private Integer currentPage = 1;
private Integer pageSize = 10;
private Integer currentPage = 1;
private Integer pageSize = 10;
public int getStart() {
return (currentPage - 1) * pageSize;
}
public int getStart() {
return (currentPage - 1) * pageSize;
}
}

View File

@ -7,10 +7,10 @@ import org.springframework.util.StringUtils;
@Getter
@Setter
public class SystemDictionaryQueryObject extends QueryObject {
private String keyword;
private Long parentId;
private String keyword;
private Long parentId;
public String getKeyword() {
return StringUtils.hasLength(keyword) ? keyword : null;
}
public String getKeyword() {
return StringUtils.hasLength(keyword) ? keyword : null;
}
}

View File

@ -7,11 +7,11 @@ import java.util.List;
public interface IAccountService {
void update(Account account);
void update(Account account);
Account get(Long id);
void recreateAbstractInfo();
List<Account> listAll();
Account get(Long id);
void recreateAbstractInfo();
List<Account> listAll();
}

View File

@ -5,44 +5,49 @@ import com.geekq.common.utils.resultbean.ResultGeekQ;
import java.util.List;
import java.util.Map;
public interface ILogininfoService {
/**
* 注册
* @param username
* @param password
*/
void register(String username, String password);
/**
* 注册
*
* @param username
* @param password
*/
void register(String username, String password);
/**
* 检查是否有重复的用户名
*/
boolean checkUsername(String name, int userType);
/**
* 检查是否有重复的用户名
*/
boolean checkUsername(String name, int userType);
/**
* 用户登陆
* @param name
* @param password
* @return
*/
ResultGeekQ<Logininfo> login(String name, String password, int userType, String ip);
/**
* 用户登陆
*
* @param name
* @param password
* @return
*/
ResultGeekQ<Logininfo> login(String name, String password, int userType, String ip);
/**
* 是否有管理员
* @return
*/
boolean hasAdmin();
/**
* 是否有管理员
*
* @return
*/
boolean hasAdmin();
/**
* 创建默认的管理员
*/
void createDefaultAdmin();
/**
* 创建默认的管理员
*/
void createDefaultAdmin();
/**
* 查询用户的id和name
* @param word
* @param userType
* @return
*/
List<Map<String, Object>> autoComplate(String word, int userType);
/**
* 查询用户的id和name
*
* @param word
* @param userType
* @return
*/
List<Map<String, Object>> autoComplate(String word, int userType);
}

View File

@ -9,16 +9,16 @@ import java.util.List;
public interface ISystemDictionaryService {
PageResult queryDic(SystemDictionaryQueryObject qo);
PageResult queryDic(SystemDictionaryQueryObject qo);
void saveOrUpdate(SystemDictionary sd);
void saveOrUpdate(SystemDictionary sd);
PageResult queryDicItem(SystemDictionaryQueryObject qo);
PageResult queryDicItem(SystemDictionaryQueryObject qo);
void saveOrUpdateItem(SystemDictionaryItem item);
void saveOrUpdateItem(SystemDictionaryItem item);
List<SystemDictionary> listDics();
List<SystemDictionaryItem> queryBySn(String sn);
List<SystemDictionary> listDics();
List<SystemDictionaryItem> queryBySn(String sn);
}

View File

@ -5,15 +5,16 @@ import com.geekq.admin.entity.Userinfo;
public interface IUserService {
void update(Userinfo userinfo);
void update(Userinfo userinfo);
Userinfo get(Long id);
Userinfo get(Long id);
boolean bindPhone(String phoneNumber, String verifyCode);
boolean bindPhone(String phoneNumber, String verifyCode);
/**
* 修改基本信息
* @param userinfo
*/
void updateBasicInfo(Userinfo userinfo);
/**
* 修改基本信息
*
* @param userinfo
*/
void updateBasicInfo(Userinfo userinfo);
}

View File

@ -4,15 +4,15 @@ import com.geekq.admin.pojo.Orders;
public interface OrdersService {
/**
* @Description: 根据订单id查询订单
*/
public Orders getOrder(String orderId);
/**
* @Description: 下订单
*/
public boolean createOrder(String itemId);
/**
* @Description: 根据订单id查询订单
*/
public Orders getOrder(String orderId);
/**
* @Description: 下订单
*/
public boolean createOrder(String itemId);
}

View File

@ -2,8 +2,6 @@ package com.geekq.admin.service;
import com.geekq.admin.entity.Logininfo;
import java.util.Map;
public interface RedisCacheStorageService<K, V> {
/**
@ -16,6 +14,5 @@ public interface RedisCacheStorageService<K, V> {
boolean set(String key, V value);
Logininfo get(String key);
}

View File

@ -13,46 +13,19 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
</dependency>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- 校验处理工具包 -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.1.Final</version>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
@ -61,5 +34,9 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -4,7 +4,7 @@ package com.geekq.common.enums;
* @author 邱润泽
* 常用数据静态变量类型集合
*/
public class Constants {
public class Constants {
public static final int STATE_NORMAL = 0;
public static final int STATE_LOCK = 1;

View File

@ -2,17 +2,18 @@ package com.geekq.common.enums;
public class MessageStatus {
public static final Integer ZORE = 0;
public static final Integer ZORE = 0;
/**
* 消息类型
*/
public enum messageType {
public enum messageType {
maiosha_message("秒杀消息"),
buy_message("购买消息"),
system_message("系统消息");
private String message;
private messageType(String message){
private messageType(String message) {
this.message = message;
}
@ -24,10 +25,10 @@ public class MessageStatus {
/**
* 消息内容
*/
public enum ContentEnum {
system_message_register(7000,"尊敬的用户你好,你已经成功注册!"),
public enum ContentEnum {
system_message_register(7000, "尊敬的用户你好,你已经成功注册!"),
system_message_register_head(7001,"注册成功");
system_message_register_head(7001, "注册成功");
private int code;
private String message;
@ -45,10 +46,11 @@ public class MessageStatus {
return message;
}
}
/**
* 消息类型
*/
public enum sendType {
public enum sendType {
// maiosha_message("秒杀消息"),
// buy_message("购买消息"),
// system_message("系统消息");

View File

@ -1,40 +1,39 @@
package com.geekq.common.enums;
/**
*
* @Description: 订单状态
*/
public enum OrderStatusEnum {
WAIT_PAY(10, "待付款"), // 代付款
PAYING(20, "付款中"), // 付款中
PAID(30, "已付款"), // 已付款
PAID_FAILD(40, "付款失败"), // 付款失败
CANCELED(50, "已取消"), // 已取消
CLOSED(60, "交易关闭"); // 超时未支付, 交易关闭
public final int key;
public final String value;
OrderStatusEnum(int key, String value) {
this.key = key;
this.value = value;
}
WAIT_PAY(10, "待付款"), // 代付款
PAYING(20, "付款中"), // 付款中
PAID(30, "已付款"), // 已付款
PAID_FAILD(40, "付款失败"), // 付款失败
CANCELED(50, "已取消"), // 已取消
CLOSED(60, "交易关闭"); // 超时未支付, 交易关闭
public static String getName(int key) {
for (OrderStatusEnum status : OrderStatusEnum.values()) {
if (status.getKey() == key) {
return status.value;
}
}
return null;
}
public int getKey() {
return key;
}
public final int key;
public final String value;
public String getValue() {
return value;
}
OrderStatusEnum(int key, String value) {
this.key = key;
this.value = value;
}
public static String getName(int key) {
for (OrderStatusEnum status : OrderStatusEnum.values()) {
if (status.getKey() == key) {
return status.value;
}
}
return null;
}
public int getKey() {
return key;
}
public String getValue() {
return value;
}
}

View File

@ -8,6 +8,7 @@ package com.geekq.common.enums;
* 4 秒杀错误
* 5 商品错误
* 6 订单错误
*
* @author qiurunze
*/
public enum ResultStatus {
@ -28,38 +29,38 @@ public enum ResultStatus {
/**
* 注册登录
*/
RESIGETR_SUCCESS(20000,"注册成功!"),
RESIGETER_FAIL(200001,"注册失败!"),
CODE_FAIL(200002,"验证码不一致!"),
RESIGETER_NICKNAMEEXIST(200003,"用户名已经存在!"),
LOGIN_FIAL(200004,"登录失败!"),
RESIGETR_SUCCESS(20000, "注册成功!"),
RESIGETER_FAIL(200001, "注册失败!"),
CODE_FAIL(200002, "验证码不一致!"),
RESIGETER_NICKNAMEEXIST(200003, "用户名已经存在!"),
LOGIN_FIAL(200004, "登录失败!"),
/**
* check
*/
BIND_ERROR (30001,"参数校验异常:%s"),
ACCESS_LIMIT_REACHED (30002,"请求非法!"),
REQUEST_ILLEGAL (30004,"访问太频繁!"),
SESSION_ERROR (30005,"Session不存在或者已经失效!"),
PASSWORD_EMPTY (30006,"登录密码不能为空!"),
MOBILE_EMPTY (30007,"手机号不能为空!"),
MOBILE_ERROR (30008,"手机号格式错误!"),
MOBILE_NOT_EXIST (30009,"手机号不存在!"),
PASSWORD_ERROR (30010,"密码错误!"),
USER_NOT_EXIST(30011,"用户不存在!"),
BIND_ERROR(30001, "参数校验异常:%s"),
ACCESS_LIMIT_REACHED(30002, "请求非法!"),
REQUEST_ILLEGAL(30004, "访问太频繁!"),
SESSION_ERROR(30005, "Session不存在或者已经失效!"),
PASSWORD_EMPTY(30006, "登录密码不能为空!"),
MOBILE_EMPTY(30007, "手机号不能为空!"),
MOBILE_ERROR(30008, "手机号格式错误!"),
MOBILE_NOT_EXIST(30009, "手机号不存在!"),
PASSWORD_ERROR(30010, "密码错误!"),
USER_NOT_EXIST(30011, "用户不存在!"),
/**
* 订单模块
*/
ORDER_NOT_EXIST(60001,"订单不存在"),
ORDER_NOT_EXIST(60001, "订单不存在"),
/**
* 秒杀模块
*/
MIAO_SHA_OVER(40001,"商品已经秒杀完毕"),
REPEATE_MIAOSHA(40002,"不能重复秒杀"),
MIAOSHA_FAIL(40003,"秒杀失败");
MIAO_SHA_OVER(40001, "商品已经秒杀完毕"),
REPEATE_MIAOSHA(40002, "不能重复秒杀"),
MIAOSHA_FAIL(40003, "秒杀失败");
/**
* 商品模块
@ -72,6 +73,10 @@ public enum ResultStatus {
this.message = message;
}
private ResultStatus(Object... args) {
this.message = String.format(this.message, args);
}
public int getCode() {
return this.code;
}
@ -99,8 +104,4 @@ public enum ResultStatus {
public String toString() {
return this.getName();
}
private ResultStatus(Object... args) {
this.message = String.format(this.message, args);
}
}

View File

@ -1,23 +1,22 @@
package com.geekq.common.enums;
/**
*
* @Description: 男女枚举
*/
public enum SexEnum {
GIRL(0), //
BOY(1), //
SECRET(2); // 保密
public final int value;
SexEnum(int value) {
this.value = value;
}
public int getValue() {
return value;
}
GIRL(0), //
BOY(1), //
SECRET(2); // 保密
public final int value;
SexEnum(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}

View File

@ -1,22 +1,21 @@
package com.geekq.common.enums;
/**
*
* @Description: 是否枚举
*/
public enum YesOrNo {
YES(1), // 有错误
NO(0); // 无错误
public final int value;
YesOrNo(int value) {
this.value = value;
}
public int getValue() {
return value;
}
YES(1), // 有错误
NO(0); // 无错误
public final int value;
YesOrNo(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}

View File

@ -6,14 +6,14 @@ public class Constanst {
public static String COUNTLOGIN = "count:login";
public enum orderStaus{
public enum orderStaus {
ORDER_NOT_PAY("新建未支付");
orderStaus(String name){
this.name=name;
}
private String name;
private String name;
orderStaus(String name) {
this.name = name;
}
public String getName() {
return name;

View File

@ -2,17 +2,16 @@ package com.geekq.common.utils;
public class DBContextUtil {
private static ThreadLocal<String> dbPools = new ThreadLocal<>();
public static final String DBMASTER = "dbmaster";
public static final String DBREAD = "dbread";
private static ThreadLocal<String> dbPools = new ThreadLocal<>();
public static final String DBMASTER = "dbmaster";
public static final String DBREAD = "dbread";
public static String getDB() {
return dbPools.get();
}
public static void setDB(String db) {
dbPools.set(db);
}
public static String getDB() {
return dbPools.get();
}
public static void setDB(String db) {
dbPools.set(db);
}
}

View File

@ -8,12 +8,12 @@ import java.util.Date;
public class DateUtil {
public static Date endOfDay(Date d) {
return DateUtils.addSeconds(
DateUtils.addDays(DateUtils.truncate(d, Calendar.DATE), 1), -1);
}
public static Date endOfDay(Date d) {
return DateUtils.addSeconds(
DateUtils.addDays(DateUtils.truncate(d, Calendar.DATE), 1), -1);
}
public static long getSecondsBetweenDates(Date d1, Date d2) {
return Math.abs((d1.getTime() - d2.getTime()) / 1000);
}
public static long getSecondsBetweenDates(Date d1, Date d2) {
return Math.abs((d1.getTime() - d2.getTime()) / 1000);
}
}

View File

@ -1,13 +1,12 @@
package com.geekq.common.utils;
import java.util.List;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
/**
*
* @Description: 自定义响应结构, 转换类
*/
public class JsonUtils {
@ -19,24 +18,25 @@ public class JsonUtils {
* 将对象转换成json字符串
* <p>Title: pojoToJson</p>
* <p>Description: </p>
*
* @param data
* @return
*/
public static String objectToJson(Object data) {
try {
String string = MAPPER.writeValueAsString(data);
return string;
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
try {
String string = MAPPER.writeValueAsString(data);
return string;
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return null;
}
/**
* 将json结果集转化为对象
*
*
* @param jsonData json数据
* @param clazz 对象中的object类型
* @param clazz 对象中的object类型
* @return
*/
public static <T> T jsonToPojo(String jsonData, Class<T> beanType) {
@ -44,29 +44,30 @@ public class JsonUtils {
T t = MAPPER.readValue(jsonData, beanType);
return t;
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
}
return null;
}
/**
* 将json数据转换成pojo对象list
* <p>Title: jsonToList</p>
* <p>Description: </p>
*
* @param jsonData
* @param beanType
* @return
*/
public static <T>List<T> jsonToList(String jsonData, Class<T> beanType) {
JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, beanType);
try {
List<T> list = MAPPER.readValue(jsonData, javaType);
return list;
} catch (Exception e) {
e.printStackTrace();
}
return null;
public static <T> List<T> jsonToList(String jsonData, Class<T> beanType) {
JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, beanType);
try {
List<T> list = MAPPER.readValue(jsonData, javaType);
return list;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -1,10 +1,9 @@
package com.geekq.common.utils.MD5;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Random;
/**
* @author 邱润泽
@ -12,16 +11,17 @@ import java.util.Random;
public class MD5Utils {
public static final String getSaltT (){
private static String getSalt = getSaltT();
public static final String getSaltT() {
SecureRandom random = new SecureRandom();
byte bytes[] = new byte[15];
random.nextBytes(bytes);
String salt = org.apache.commons.codec.binary.Base64.encodeBase64String(bytes);
String salt = Base64.encodeBase64String(bytes);
return salt;
}
private static String getSalt = getSaltT();
public static String MD5( String keyName ){
public static String MD5(String keyName) {
/**
* 返回16
*/
@ -32,32 +32,35 @@ public class MD5Utils {
/**
* 测试使用
*
* @param inputPass
* @return
*/
public static String inputPassFormPass ( String inputPass ){
String str = "" + getSalt.charAt(0) + getSalt.charAt(2) + inputPass + getSalt.charAt(4) + getSalt.charAt(6) ;
public static String inputPassFormPass(String inputPass) {
String str = "" + getSalt.charAt(0) + getSalt.charAt(2) + inputPass + getSalt.charAt(4) + getSalt.charAt(6);
return MD5(str);
}
/**
* 盐值salt 随机 二次加密
*
* @param inputPass
* @return
*/
public static String formPassFormPass ( String inputPass ){
String str = "" + getSalt.charAt(0) + getSalt.charAt(2) +inputPass + getSalt.charAt(4) + getSalt.charAt(6) ;
public static String formPassFormPass(String inputPass) {
String str = "" + getSalt.charAt(0) + getSalt.charAt(2) + inputPass + getSalt.charAt(4) + getSalt.charAt(6);
return MD5(str);
}
/**
* 第二次md5--反解密 用户登录验证 --- salt 可随机 
* 第二次md5--反解密 用户登录验证 --- salt 可随机
*
* @param formPass
* @param salt
* @return
*/
public static String formPassToDBPass ( String formPass ,String salt ) {
String str = "" + salt.charAt(0) + salt.charAt(2)+ formPass + salt.charAt(4) + salt.charAt(6) ;
public static String formPassToDBPass(String formPass, String salt) {
String str = "" + salt.charAt(0) + salt.charAt(2) + formPass + salt.charAt(4) + salt.charAt(6);
return MD5(str);
}

View File

@ -1,4 +1,5 @@
package com.geekq.common.utils;
/**
* Twitter_Snowflake<br>
* SnowFlake的结构如下(每部分用-分开):<br>
@ -14,52 +15,82 @@ package com.geekq.common.utils;
public class SnowflakeIdWorker {
// ==============================Fields===========================================
/** 开始时间截 (2015-01-01) */
/**
* 开始时间截 (2015-01-01)
*/
private final long twepoch = 1420041600000L;
/** 机器id所占的位数 */
/**
* 机器id所占的位数
*/
private final long workerIdBits = 5L;
/** 数据标识id所占的位数 */
/**
* 数据标识id所占的位数
*/
private final long datacenterIdBits = 5L;
/** 支持的最大机器id结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) */
/**
* 支持的最大机器id结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数)
*/
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
/** 支持的最大数据标识id结果是31 */
/**
* 支持的最大数据标识id结果是31
*/
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
/** 序列在id中占的位数 */
/**
* 序列在id中占的位数
*/
private final long sequenceBits = 12L;
/** 机器ID向左移12位 */
/**
* 机器ID向左移12位
*/
private final long workerIdShift = sequenceBits;
/** 数据标识id向左移17位(12+5) */
/**
* 数据标识id向左移17位(12+5)
*/
private final long datacenterIdShift = sequenceBits + workerIdBits;
/** 时间截向左移22位(5+5+12) */
/**
* 时间截向左移22位(5+5+12)
*/
private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
/** 生成序列的掩码这里为4095 (0b111111111111=0xfff=4095) */
/**
* 生成序列的掩码这里为4095 (0b111111111111=0xfff=4095)
*/
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
/** 工作机器ID(0~31) */
/**
* 工作机器ID(0~31)
*/
private long workerId;
/** 数据中心ID(0~31) */
/**
* 数据中心ID(0~31)
*/
private long datacenterId;
/** 毫秒内序列(0~4095) */
/**
* 毫秒内序列(0~4095)
*/
private long sequence = 0L;
/** 上次生成ID的时间截 */
/**
* 上次生成ID的时间截
*/
private long lastTimestamp = -1L;
//==============================Constructors=====================================
/**
* 构造函数
* @param workerId 工作ID (0~31)
*
* @param workerId 工作ID (0~31)
* @param datacenterId 数据中心ID (0~31)
*/
public SnowflakeIdWorker(long workerId, long datacenterId) {
@ -75,18 +106,33 @@ public class SnowflakeIdWorker {
/**
* 生成订单唯一ID
*
* @param workerId
* @param datacenterId
* @return
*/
public static long getOrderId(long workerId, long datacenterId){
public static long getOrderId(long workerId, long datacenterId) {
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
return idWorker.nextId();
}
// ==============================Methods==========================================
/**
* 测试
*/
public static void main(String[] args) {
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
for (int i = 0; i < 1000; i++) {
long id = idWorker.nextId();
System.out.println(Long.toBinaryString(id));
System.out.println(id);
}
}
/**
* 获得下一个ID (该方法是线程安全的)
*
* @return SnowflakeId
*/
public synchronized long nextId() {
@ -124,6 +170,7 @@ public class SnowflakeIdWorker {
/**
* 阻塞到下一个毫秒直到获得新的时间戳
*
* @param lastTimestamp 上次生成ID的时间截
* @return 当前时间戳
*/
@ -135,29 +182,16 @@ public class SnowflakeIdWorker {
return timestamp;
}
//==============================Test=============================================
/**
* 返回以毫秒为单位的当前时间
*
* @return 当前时间(毫秒)
*/
protected long timeGen() {
return System.currentTimeMillis();
}
//==============================Test=============================================
/** 测试 */
public static void main(String[] args) {
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
for (int i = 0; i < 1000; i++) {
long id = idWorker.nextId();
System.out.println(Long.toBinaryString(id));
System.out.println(id);
}
}
}

View File

@ -6,16 +6,16 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ValidatorUtil {
private static final Pattern mobile_pattern = Pattern.compile("1\\d{10}");
public static boolean isMobile(String src) {
if(StringUtils.isEmpty(src)) {
return false;
}
Matcher m = mobile_pattern.matcher(src);
return m.matches();
}
private static final Pattern mobile_pattern = Pattern.compile("1\\d{10}");
public static boolean isMobile(String src) {
if (StringUtils.isEmpty(src)) {
return false;
}
Matcher m = mobile_pattern.matcher(src);
return m.matches();
}
}

View File

@ -4,69 +4,75 @@ import java.math.BigDecimal;
/**
* 系统需要的常量
* @author 邱润泽
*
* @author 邱润泽
*/
public class BidConst {
public static final int DISPLAY_SCALE = 2;//显示精度
public static final int CAL_SCALE = 8;//计算精度
public static final int STORE_SCALE = 4;//保存精度
public static final int DISPLAY_SCALE = 2;//显示精度
public static final int CAL_SCALE = 8;//计算精度
public static final int STORE_SCALE = 4;//保存精度
public static final BigDecimal ZERO = new BigDecimal("0.0000");//系统中需要的zero
public static final BigDecimal DEFALUT_BORROWLIMITAMOUNT = new BigDecimal(
"2000.0000");//初始用户授信额度
public static final BigDecimal ACCOUNT_MANAGER_CHARGE_RATE=new BigDecimal("0.0500");
public static final BigDecimal ZERO = new BigDecimal("0.0000");//系统中需要的zero
public static final BigDecimal DEFALUT_BORROWLIMITAMOUNT = new BigDecimal(
"2000.0000");//初始用户授信额度
public static final BigDecimal ACCOUNT_MANAGER_CHARGE_RATE = new BigDecimal("0.0500");
public static final String DEFAULT_ADMIN_NAME = "admin";
public static final String DEFAULT_ADMIN_PASSWORD = "1111";
public static final String DEFAULT_ADMIN_NAME = "admin";
public static final String DEFAULT_ADMIN_PASSWORD = "1111";
public static final int CREDIT_BORROW_SCORE = 30;//信用信用分数
public static final int CREDIT_BORROW_SCORE = 30;//信用信用分数
public final static int RETURN_TYPE_MONTH_INTEREST_PRINCIPAL = 0; // 还款方式 按月分期还款(等额本息)
public final static int RETURN_TYPE_MONTH_INTEREST = 1; // 还款方式 按月到期还款(每月还利息,到期还本息)
public final static int BIDREQUEST_TYPE_NORMAL = 0; // 普通信用标
public final static int BIDREQUEST_STATE_PUBLISH_PENDING = 0; // 待发布
public final static int BIDREQUEST_STATE_BIDDING = 1; // 招标中
public final static int BIDREQUEST_STATE_UNDO = 2; // 已撤销
public final static int BIDREQUEST_STATE_BIDDING_OVERDUE = 3; // 流标
public final static int BIDREQUEST_STATE_APPROVE_PENDING_1 = 4; // 满标1审
public final static int BIDREQUEST_STATE_APPROVE_PENDING_2 = 5; // 满标2审
public final static int BIDREQUEST_STATE_REJECTED = 6; // 满标审核被拒绝
public final static int BIDREQUEST_STATE_PAYING_BACK = 7; // 还款中
public final static int BIDREQUEST_STATE_COMPLETE_PAY_BACK = 8; // 已还清
public final static int BIDREQUEST_STATE_PAY_BACK_OVERDUE = 9; // 逾期
public final static int BIDREQUEST_STATE_PUBLISH_REFUSE = 10; // 发标审核拒绝状态
public static final BigDecimal SMALLEST_BID_AMOUNT = new BigDecimal("50.0000");//系统规定的最小投标金额
public static final BigDecimal SMALLEST_BIDREQUEST_AMOUNT = new BigDecimal("500.0000");//系统规定的最小借款金额
/**=============================账户流水类型================================ */
public final static int ACCOUNT_ACTIONTYPE_DEPOSIT_OFFLINE_LOCAL = 0;// 资金流水类别线下充值
public final static int ACCOUNT_ACTIONTYPE_WITHDRAW = 1;// 资金流水类别提现
public final static int ACCOUNT_ACTIONTYPE_BIDREQUEST_SUCCESSFUL = 2;// 资金流水类别成功借款
public final static int ACCOUNT_ACTIONTYPE_BID_SUCCESSFUL = 3;// 资金流水类别成功投标
public final static int ACCOUNT_ACTIONTYPE_RETURN_MONEY = 4;// 资金流水类别还款
public final static int ACCOUNT_ACTIONTYPE_CALLBACK_MONEY = 5;// 资金流水类别回款
public final static int ACCOUNT_ACTIONTYPE_CHARGE = 6;// 资金流水类别平台管理费
public final static int ACCOUNT_ACTIONTYPE_INTEREST_SHARE = 7;// 资金流水类别利息管理费
public final static int ACCOUNT_ACTIONTYPE_WITHDRAW_MANAGE_CHARGE = 8;// 资金流水类别提现手续费
public final static int ACCOUNT_ACTIONTYPE_RECHARGE_CHARGE = 9;// 资金流水类别充值手续费
public final static int ACCOUNT_ACTIONTYPE_BID_FREEZED = 10;// 资金流水类别投标冻结金额
public final static int ACCOUNT_ACTIONTYPE_BID_UNFREEZED = 11;// 资金流水类别取消投标冻结金额
public final static int ACCOUNT_ACTIONTYPE_WITHDRAW_FREEZED = 12;// 资金流水类别提现申请冻结金额
public final static int ACCOUNT_ACTIONTYPE_WITHDRAW_UNFREEZED = 13;// 资金流水类别:提现申请失败取消冻结金额
/**=========还款状态===============*/
public final static int PAYMENT_STATE_NORMAL = 0; //正常待还
public final static int PAYMENT_STATE_DONE = 1; //已还
public final static int PAYMENT_STATE_OVERDUE = 2; //逾期
/**============系统账户流水类型=============*/
public final static int SYSTEM_ACCOUNT_NONE = -1; //未指定
public final static int SYSTEM_ACCOUNT_ACTIONTYPE_MANAGE_CHARGE = 1;//系统账户收到账户管理费借款管理费
public final static int SYSTEM_ACCOUNT_ACTIONTYPE_INTREST_MANAGE_CHARGE = 2;//系统账户收到利息管理费
public final static int SYSTEM_ACCOUNT_ACTIONTYPE_WITHDRAW_MANAGE_CHARGE = 3;//系统账户收到提现手续费
public final static int RETURN_TYPE_MONTH_INTEREST_PRINCIPAL = 0; // 还款方式 按月分期还款(等额本息)
public final static int RETURN_TYPE_MONTH_INTEREST = 1; // 还款方式 按月到期还款(每月还利息,到期还本息)
public final static int BIDREQUEST_TYPE_NORMAL = 0; // 普通信用标
public final static int BIDREQUEST_STATE_PUBLISH_PENDING = 0; // 待发布
public final static int BIDREQUEST_STATE_BIDDING = 1; // 招标中
public final static int BIDREQUEST_STATE_UNDO = 2; // 已撤销
public final static int BIDREQUEST_STATE_BIDDING_OVERDUE = 3; // 流标
public final static int BIDREQUEST_STATE_APPROVE_PENDING_1 = 4; // 满标1审
public final static int BIDREQUEST_STATE_APPROVE_PENDING_2 = 5; // 满标2审
public final static int BIDREQUEST_STATE_REJECTED = 6; // 满标审核被拒绝
public final static int BIDREQUEST_STATE_PAYING_BACK = 7; // 还款中
public final static int BIDREQUEST_STATE_COMPLETE_PAY_BACK = 8; // 已还清
public final static int BIDREQUEST_STATE_PAY_BACK_OVERDUE = 9; // 逾期
public final static int BIDREQUEST_STATE_PUBLISH_REFUSE = 10; // 发标审核拒绝状态
public static final BigDecimal SMALLEST_BID_AMOUNT = new BigDecimal("50.0000");//系统规定的最小投标金额
public static final BigDecimal SMALLEST_BIDREQUEST_AMOUNT = new BigDecimal("500.0000");//系统规定的最小借款金额
/**
* =============================账户流水类型================================
*/
public final static int ACCOUNT_ACTIONTYPE_DEPOSIT_OFFLINE_LOCAL = 0;// 资金流水类别线下充值
public final static int ACCOUNT_ACTIONTYPE_WITHDRAW = 1;// 资金流水类别提现
public final static int ACCOUNT_ACTIONTYPE_BIDREQUEST_SUCCESSFUL = 2;// 资金流水类别成功借款
public final static int ACCOUNT_ACTIONTYPE_BID_SUCCESSFUL = 3;// 资金流水类别成功投标
public final static int ACCOUNT_ACTIONTYPE_RETURN_MONEY = 4;// 资金流水类别还款
public final static int ACCOUNT_ACTIONTYPE_CALLBACK_MONEY = 5;// 资金流水类别回款
public final static int ACCOUNT_ACTIONTYPE_CHARGE = 6;// 资金流水类别平台管理费
public final static int ACCOUNT_ACTIONTYPE_INTEREST_SHARE = 7;// 资金流水类别利息管理费
public final static int ACCOUNT_ACTIONTYPE_WITHDRAW_MANAGE_CHARGE = 8;// 资金流水类别提现手续费
public final static int ACCOUNT_ACTIONTYPE_RECHARGE_CHARGE = 9;// 资金流水类别充值手续费
public final static int ACCOUNT_ACTIONTYPE_BID_FREEZED = 10;// 资金流水类别投标冻结金额
public final static int ACCOUNT_ACTIONTYPE_BID_UNFREEZED = 11;// 资金流水类别取消投标冻结金额
public final static int ACCOUNT_ACTIONTYPE_WITHDRAW_FREEZED = 12;// 资金流水类别提现申请冻结金额
public final static int ACCOUNT_ACTIONTYPE_WITHDRAW_UNFREEZED = 13;// 资金流水类别:提现申请失败取消冻结金额
/**
* =========还款状态===============
*/
public final static int PAYMENT_STATE_NORMAL = 0; //正常待还
public final static int PAYMENT_STATE_DONE = 1; //已还
public final static int PAYMENT_STATE_OVERDUE = 2; //逾期
/**
* ============系统账户流水类型=============
*/
public final static int SYSTEM_ACCOUNT_NONE = -1; //未指定
public final static int SYSTEM_ACCOUNT_ACTIONTYPE_MANAGE_CHARGE = 1;//系统账户收到账户管理费借款管理费
public final static int SYSTEM_ACCOUNT_ACTIONTYPE_INTREST_MANAGE_CHARGE = 2;//系统账户收到利息管理费
public final static int SYSTEM_ACCOUNT_ACTIONTYPE_WITHDRAW_MANAGE_CHARGE = 3;//系统账户收到提现手续费
}

View File

@ -2,47 +2,48 @@ package com.geekq.common.utils.numcal;
/**
* 用户状态类记录用户在平台使用系统中所有的状态
*
* @author 邱润泽
*/
public class BitStatesUtils {
public final static Long OP_BASIC_INFO = 1L; //用户注册成功的标示,及为默认初始状态
public final static Long OP_BIND_PHONE = 2L << 0; //用户绑定手机状态码
public final static Long OP_BIND_EMAIL = 2L << 1;//用户绑定邮箱
public final static Long OP_BASE_INFO = 2L << 2;//填写基本资料
public final static Long OP_REAL_AUTH = 2L << 3;//用户实名认证
public final static Long OP_VEDIO_AUTH = 2L << 4;//视频认证
public final static Long OP_HAS_BIDRQUEST=2l<<5;//当前用户有一个借款还在借款流程当中
public final static Long OP_BASIC_INFO = 1L; //用户注册成功的标示,及为默认初始状态
public final static Long OP_BIND_PHONE = 2L << 0; //用户绑定手机状态码
public final static Long OP_BIND_EMAIL = 2L << 1;//用户绑定邮箱
public final static Long OP_BASE_INFO = 2L << 2;//填写基本资料
public final static Long OP_REAL_AUTH = 2L << 3;//用户实名认证
public final static Long OP_VEDIO_AUTH = 2L << 4;//视频认证
public final static Long OP_HAS_BIDRQUEST = 2l << 5;//当前用户有一个借款还在借款流程当中
/**
* @param states 所有状态值
* @param value 需要判断状态值
* @return 是否存在
*/
public static boolean hasState(long states, long value) {
return (states & value) != 0;
}
/**
* @param states 所有状态值
* @param value 需要判断状态值
* @return 是否存在
*/
public static boolean hasState(long states, long value) {
return (states & value) != 0;
}
/**
* @param states 已有状态值
* @param value 需要添加状态值
* @return 新的状态值
*/
public static long addState(long states, long value) {
if (hasState(states, value)) {
return states;
}
return (states | value);
}
/**
* @param states 已有状态值
* @param value 需要添加状态值
* @return 新的状态值
*/
public static long addState(long states, long value) {
if (hasState(states, value)) {
return states;
}
return (states | value);
}
/**
* @param states 已有状态值
* @param value 需要删除状态值
* @return 新的状态值
*/
public static long removeState(long states, long value) {
if (!hasState(states, value)) {
return states;
}
return states ^ value;
}
/**
* @param states 已有状态值
* @param value 需要删除状态值
* @return 新的状态值
*/
public static long removeState(long states, long value) {
if (!hasState(states, value)) {
return states;
}
return states ^ value;
}
}

View File

@ -7,254 +7,231 @@ import java.math.RoundingMode;
* 计算器Util
*
* @author 邱润泽
*
*/
public class CalculatetUtil {
public static final BigDecimal ONE_HUNDRED = new BigDecimal("100.0000");
public static final BigDecimal NUMBER_MONTHS_OF_YEAR = new BigDecimal(
"12.0000");
public static final BigDecimal ONE_HUNDRED = new BigDecimal("100.0000");
public static final BigDecimal NUMBER_MONTHS_OF_YEAR = new BigDecimal(
"12.0000");
/**
* 获取月利率
*/
public static BigDecimal getMonthlyRate(BigDecimal yearRate) {
if (yearRate == null)
return BigDecimal.ZERO;
return yearRate.divide(ONE_HUNDRED).divide(NUMBER_MONTHS_OF_YEAR,
BidConst.CAL_SCALE, RoundingMode.HALF_UP);
}
/**
* 获取月利率
*/
public static BigDecimal getMonthlyRate(BigDecimal yearRate) {
if (yearRate == null)
return BigDecimal.ZERO;
return yearRate.divide(ONE_HUNDRED).divide(NUMBER_MONTHS_OF_YEAR,
BidConst.CAL_SCALE, RoundingMode.HALF_UP);
}
/**
* 计算借款总利息
*
* @param returnType
* 还款类型
* @param bidRequestAmount
* 借款金额
* @param yearRate
* 年利率
* @param monthes2Return
* 还款期限
* @return
*/
public static BigDecimal calTotalInterest(int returnType,
BigDecimal bidRequestAmount, BigDecimal yearRate, int monthes2Return) {
BigDecimal totalInterest = BigDecimal.ZERO;
BigDecimal monthlyRate = getMonthlyRate(yearRate);
if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST_PRINCIPAL) {// 按月分期
// 只借款一个月
if (monthes2Return == 1) {
totalInterest = bidRequestAmount.multiply(monthlyRate)
.setScale(BidConst.CAL_SCALE, RoundingMode.HALF_UP);
} else {
BigDecimal temp1 = bidRequestAmount.multiply(monthlyRate);
BigDecimal temp2 = (BigDecimal.ONE.add(monthlyRate))
.pow(monthes2Return);
BigDecimal temp3 = (BigDecimal.ONE.add(monthlyRate)).pow(
monthes2Return).subtract(BigDecimal.ONE);
// 算出每月还款
BigDecimal monthToReturnMoney = temp1.multiply(temp2).divide(
temp3, BidConst.CAL_SCALE, RoundingMode.HALF_UP);
// 算出总还款
BigDecimal totalReturnMoney = monthToReturnMoney
.multiply(new BigDecimal(monthes2Return));
// 算出总利息
totalInterest = totalReturnMoney.subtract(bidRequestAmount);
}
} else if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST) {// 按月到期
BigDecimal monthlyInterest = DecimalFormatUtil
.amountFormat(bidRequestAmount.multiply(monthlyRate));
totalInterest = monthlyInterest.multiply(new BigDecimal(
monthes2Return));
}
return DecimalFormatUtil.formatBigDecimal(totalInterest,
BidConst.STORE_SCALE);
}
/**
* 计算借款总利息
*
* @param returnType 还款类型
* @param bidRequestAmount 借款金额
* @param yearRate 年利率
* @param monthes2Return 还款期限
* @return
*/
public static BigDecimal calTotalInterest(int returnType,
BigDecimal bidRequestAmount, BigDecimal yearRate, int monthes2Return) {
BigDecimal totalInterest = BigDecimal.ZERO;
BigDecimal monthlyRate = getMonthlyRate(yearRate);
if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST_PRINCIPAL) {// 按月分期
// 只借款一个月
if (monthes2Return == 1) {
totalInterest = bidRequestAmount.multiply(monthlyRate)
.setScale(BidConst.CAL_SCALE, RoundingMode.HALF_UP);
} else {
BigDecimal temp1 = bidRequestAmount.multiply(monthlyRate);
BigDecimal temp2 = (BigDecimal.ONE.add(monthlyRate))
.pow(monthes2Return);
BigDecimal temp3 = (BigDecimal.ONE.add(monthlyRate)).pow(
monthes2Return).subtract(BigDecimal.ONE);
// 算出每月还款
BigDecimal monthToReturnMoney = temp1.multiply(temp2).divide(
temp3, BidConst.CAL_SCALE, RoundingMode.HALF_UP);
// 算出总还款
BigDecimal totalReturnMoney = monthToReturnMoney
.multiply(new BigDecimal(monthes2Return));
// 算出总利息
totalInterest = totalReturnMoney.subtract(bidRequestAmount);
}
} else if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST) {// 按月到期
BigDecimal monthlyInterest = DecimalFormatUtil
.amountFormat(bidRequestAmount.multiply(monthlyRate));
totalInterest = monthlyInterest.multiply(new BigDecimal(
monthes2Return));
}
return DecimalFormatUtil.formatBigDecimal(totalInterest,
BidConst.STORE_SCALE);
}
/**
* 计算每期利息
*
* @param returnType
* 还款类型
* @param bidRequestAmount
* 借款金额
* @param yearRate
* 年利率
* @param monthIndex
* 第几期
* @param monthes2Return
* 还款期限
* @return
*/
public static BigDecimal calMonthlyInterest(int returnType,
BigDecimal bidRequestAmount, BigDecimal yearRate, int monthIndex,
int monthes2Return) {
BigDecimal monthlyInterest = BigDecimal.ZERO;
BigDecimal monthlyRate = getMonthlyRate(yearRate);
if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST_PRINCIPAL) {// 按月分期
// 只借款一个月
if (monthes2Return == 1) {
monthlyInterest = bidRequestAmount.multiply(monthlyRate)
.setScale(BidConst.CAL_SCALE, RoundingMode.HALF_UP);
} else {
BigDecimal temp1 = bidRequestAmount.multiply(monthlyRate);
BigDecimal temp2 = (BigDecimal.ONE.add(monthlyRate))
.pow(monthes2Return);
BigDecimal temp3 = (BigDecimal.ONE.add(monthlyRate)).pow(
monthes2Return).subtract(BigDecimal.ONE);
BigDecimal temp4 = (BigDecimal.ONE.add(monthlyRate))
.pow(monthIndex - 1);
// 算出每月还款
BigDecimal monthToReturnMoney = temp1.multiply(temp2).divide(
temp3, BidConst.CAL_SCALE, RoundingMode.HALF_UP);
// 算出总还款
BigDecimal totalReturnMoney = monthToReturnMoney
.multiply(new BigDecimal(monthes2Return));
// 算出总利息
BigDecimal totalInterest = totalReturnMoney
.subtract(bidRequestAmount);
/**
* 计算每期利息
*
* @param returnType 还款类型
* @param bidRequestAmount 借款金额
* @param yearRate 年利率
* @param monthIndex 第几期
* @param monthes2Return 还款期限
* @return
*/
public static BigDecimal calMonthlyInterest(int returnType,
BigDecimal bidRequestAmount, BigDecimal yearRate, int monthIndex,
int monthes2Return) {
BigDecimal monthlyInterest = BigDecimal.ZERO;
BigDecimal monthlyRate = getMonthlyRate(yearRate);
if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST_PRINCIPAL) {// 按月分期
// 只借款一个月
if (monthes2Return == 1) {
monthlyInterest = bidRequestAmount.multiply(monthlyRate)
.setScale(BidConst.CAL_SCALE, RoundingMode.HALF_UP);
} else {
BigDecimal temp1 = bidRequestAmount.multiply(monthlyRate);
BigDecimal temp2 = (BigDecimal.ONE.add(monthlyRate))
.pow(monthes2Return);
BigDecimal temp3 = (BigDecimal.ONE.add(monthlyRate)).pow(
monthes2Return).subtract(BigDecimal.ONE);
BigDecimal temp4 = (BigDecimal.ONE.add(monthlyRate))
.pow(monthIndex - 1);
// 算出每月还款
BigDecimal monthToReturnMoney = temp1.multiply(temp2).divide(
temp3, BidConst.CAL_SCALE, RoundingMode.HALF_UP);
// 算出总还款
BigDecimal totalReturnMoney = monthToReturnMoney
.multiply(new BigDecimal(monthes2Return));
// 算出总利息
BigDecimal totalInterest = totalReturnMoney
.subtract(bidRequestAmount);
if (monthIndex < monthes2Return) {
monthlyInterest = (temp1.subtract(monthToReturnMoney))
.multiply(temp4).add(monthToReturnMoney)
.setScale(BidConst.CAL_SCALE, RoundingMode.HALF_UP);
} else if (monthIndex == monthes2Return) {
BigDecimal temp6 = BigDecimal.ZERO;
// 汇总最后一期之前所有利息之和
for (int i = 1; i < monthes2Return; i++) {
BigDecimal temp5 = (BigDecimal.ONE.add(monthlyRate))
.pow(i - 1);
monthlyInterest = (temp1.subtract(monthToReturnMoney))
.multiply(temp5)
.add(monthToReturnMoney)
.setScale(BidConst.CAL_SCALE,
RoundingMode.HALF_UP);
temp6 = temp6.add(monthlyInterest);
}
monthlyInterest = totalInterest.subtract(temp6);
}
if (monthIndex < monthes2Return) {
monthlyInterest = (temp1.subtract(monthToReturnMoney))
.multiply(temp4).add(monthToReturnMoney)
.setScale(BidConst.CAL_SCALE, RoundingMode.HALF_UP);
} else if (monthIndex == monthes2Return) {
BigDecimal temp6 = BigDecimal.ZERO;
// 汇总最后一期之前所有利息之和
for (int i = 1; i < monthes2Return; i++) {
BigDecimal temp5 = (BigDecimal.ONE.add(monthlyRate))
.pow(i - 1);
monthlyInterest = (temp1.subtract(monthToReturnMoney))
.multiply(temp5)
.add(monthToReturnMoney)
.setScale(BidConst.CAL_SCALE,
RoundingMode.HALF_UP);
temp6 = temp6.add(monthlyInterest);
}
monthlyInterest = totalInterest.subtract(temp6);
}
}
} else if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST) {// 按月到期
monthlyInterest = DecimalFormatUtil.amountFormat(bidRequestAmount
.multiply(monthlyRate));
}
return monthlyInterest;
}
}
} else if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST) {// 按月到期
monthlyInterest = DecimalFormatUtil.amountFormat(bidRequestAmount
.multiply(monthlyRate));
}
return monthlyInterest;
}
/**
* 计算每期还款
*
* @param returnType
* 还款类型
* @param bidRequestAmount
* 借款金额
* @param yearRate
* 年利率
* @param monthIndex
* 第几期
* @param monthes2Return
* 还款期限
* @return
*/
public static BigDecimal calMonthToReturnMoney(int returnType,
BigDecimal bidRequestAmount, BigDecimal yearRate, int monthIndex,
int monthes2Return) {
BigDecimal monthToReturnMoney = BigDecimal.ZERO;
BigDecimal monthlyRate = getMonthlyRate(yearRate);
if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST_PRINCIPAL) {// 按月分期
if (monthes2Return == 1) {
monthToReturnMoney = bidRequestAmount.add(
bidRequestAmount.multiply(monthlyRate)).setScale(
BidConst.CAL_SCALE, RoundingMode.HALF_UP);
} else {
BigDecimal temp1 = bidRequestAmount.multiply(monthlyRate);
BigDecimal temp2 = (BigDecimal.ONE.add(monthlyRate))
.pow(monthes2Return);
BigDecimal temp3 = (BigDecimal.ONE.add(monthlyRate)).pow(
monthes2Return).subtract(BigDecimal.ONE);
// 算出每月还款
monthToReturnMoney = temp1.multiply(temp2).divide(temp3,
BidConst.CAL_SCALE, RoundingMode.HALF_UP);
}
} else if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST) {// 按月到期
BigDecimal monthlyInterest = bidRequestAmount.multiply(monthlyRate)
.setScale(BidConst.CAL_SCALE, RoundingMode.HALF_UP);
if (monthIndex == monthes2Return) {
monthToReturnMoney = bidRequestAmount.add(monthlyInterest)
.setScale(BidConst.CAL_SCALE, RoundingMode.HALF_UP);
} else if (monthIndex < monthes2Return) {
monthToReturnMoney = monthlyInterest;
}
}
return DecimalFormatUtil.formatBigDecimal(monthToReturnMoney,
BidConst.STORE_SCALE);
}
/**
* 计算每期还款
*
* @param returnType 还款类型
* @param bidRequestAmount 借款金额
* @param yearRate 年利率
* @param monthIndex 第几期
* @param monthes2Return 还款期限
* @return
*/
public static BigDecimal calMonthToReturnMoney(int returnType,
BigDecimal bidRequestAmount, BigDecimal yearRate, int monthIndex,
int monthes2Return) {
BigDecimal monthToReturnMoney = BigDecimal.ZERO;
BigDecimal monthlyRate = getMonthlyRate(yearRate);
if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST_PRINCIPAL) {// 按月分期
if (monthes2Return == 1) {
monthToReturnMoney = bidRequestAmount.add(
bidRequestAmount.multiply(monthlyRate)).setScale(
BidConst.CAL_SCALE, RoundingMode.HALF_UP);
} else {
BigDecimal temp1 = bidRequestAmount.multiply(monthlyRate);
BigDecimal temp2 = (BigDecimal.ONE.add(monthlyRate))
.pow(monthes2Return);
BigDecimal temp3 = (BigDecimal.ONE.add(monthlyRate)).pow(
monthes2Return).subtract(BigDecimal.ONE);
// 算出每月还款
monthToReturnMoney = temp1.multiply(temp2).divide(temp3,
BidConst.CAL_SCALE, RoundingMode.HALF_UP);
}
} else if (returnType == BidConst.RETURN_TYPE_MONTH_INTEREST) {// 按月到期
BigDecimal monthlyInterest = bidRequestAmount.multiply(monthlyRate)
.setScale(BidConst.CAL_SCALE, RoundingMode.HALF_UP);
if (monthIndex == monthes2Return) {
monthToReturnMoney = bidRequestAmount.add(monthlyInterest)
.setScale(BidConst.CAL_SCALE, RoundingMode.HALF_UP);
} else if (monthIndex < monthes2Return) {
monthToReturnMoney = monthlyInterest;
}
}
return DecimalFormatUtil.formatBigDecimal(monthToReturnMoney,
BidConst.STORE_SCALE);
}
/**
* 计算一次投标实际获得的利息=投标金额/借款金额 *总利息
*
* @param bidRequestAmount
* 借款金额
* @param monthes2Return
* 还款期数
* @param yearRate
* 年利率
* @param returnType
* 还款类型
* @param acturalBidAmount
* 投标金额
* @return
*/
public static BigDecimal calBidInterest(BigDecimal bidRequestAmount,
int monthes2Return, BigDecimal yearRate, int returnType,
BigDecimal acturalBidAmount) {
// 借款产生的总利息
BigDecimal totalInterest = calTotalInterest(returnType,
bidRequestAmount, yearRate, monthes2Return);
// 所占比例
BigDecimal proportion = acturalBidAmount.divide(bidRequestAmount,
BidConst.CAL_SCALE, RoundingMode.HALF_UP);
BigDecimal bidInterest = totalInterest.multiply(proportion);
return DecimalFormatUtil.formatBigDecimal(bidInterest,
BidConst.STORE_SCALE);
}
/**
* 计算一次投标实际获得的利息=投标金额/借款金额 *总利息
*
* @param bidRequestAmount 借款金额
* @param monthes2Return 还款期数
* @param yearRate 年利率
* @param returnType 还款类型
* @param acturalBidAmount 投标金额
* @return
*/
public static BigDecimal calBidInterest(BigDecimal bidRequestAmount,
int monthes2Return, BigDecimal yearRate, int returnType,
BigDecimal acturalBidAmount) {
// 借款产生的总利息
BigDecimal totalInterest = calTotalInterest(returnType,
bidRequestAmount, yearRate, monthes2Return);
// 所占比例
BigDecimal proportion = acturalBidAmount.divide(bidRequestAmount,
BidConst.CAL_SCALE, RoundingMode.HALF_UP);
BigDecimal bidInterest = totalInterest.multiply(proportion);
return DecimalFormatUtil.formatBigDecimal(bidInterest,
BidConst.STORE_SCALE);
}
/**
* 计算利息管理费
*
* @param interest
* 利息
* @param interestManagerChargeRate
* 利息管理费比例
* @return
*/
/**
public static BigDecimal calInterestManagerCharge(BigDecimal interest) {
return DecimalFormatUtil.formatBigDecimal(
interest.multiply(BidConst.INTEREST_MANAGER_CHARGE_RATE), BidConst.SCALE);
}
*/
/**
* 计算利息管理费
*
* @param interest
* 利息
* @param interestManagerChargeRate
* 利息管理费比例
* @return
*/
/**
public static BigDecimal calInterestManagerCharge(BigDecimal interest) {
return DecimalFormatUtil.formatBigDecimal(
interest.multiply(BidConst.INTEREST_MANAGER_CHARGE_RATE), BidConst.SCALE);
}
*/
/**
* 计算借款管理费
*
* @param bidRequestAmount
* 借款金额
* @param returnType
* 还款类型
* @param monthes2Return
* 还款期限
* @return
*/
public static BigDecimal calAccountManagementCharge(
BigDecimal bidRequestAmount) {
BigDecimal accountManagementCharge = DecimalFormatUtil
.formatBigDecimal(bidRequestAmount
.multiply(BidConst.ACCOUNT_MANAGER_CHARGE_RATE),
BidConst.CAL_SCALE);
return accountManagementCharge;
}
/**
* 计算借款管理费
*
* @param bidRequestAmount 借款金额
* @param returnType 还款类型
* @param monthes2Return 还款期限
* @return
*/
public static BigDecimal calAccountManagementCharge(
BigDecimal bidRequestAmount) {
BigDecimal accountManagementCharge = DecimalFormatUtil
.formatBigDecimal(bidRequestAmount
.multiply(BidConst.ACCOUNT_MANAGER_CHARGE_RATE),
BidConst.CAL_SCALE);
return accountManagementCharge;
}
}

View File

@ -5,35 +5,36 @@ import java.math.RoundingMode;
/**
* 大数字格式化工具类
*
* @author 邱润泽
* */
*/
public class DecimalFormatUtil {
//金额
public static BigDecimal amountFormat(BigDecimal number) {
number = number.setScale(BidConst.STORE_SCALE, RoundingMode.HALF_UP);
return number;
}
//金额
public static BigDecimal amountFormat(BigDecimal number) {
number = number.setScale(BidConst.STORE_SCALE, RoundingMode.HALF_UP);
return number;
}
//利率
public static BigDecimal rateFormat(BigDecimal number) {
number = number.setScale(BidConst.STORE_SCALE, RoundingMode.HALF_UP);
return number;
}
//利率
public static BigDecimal rateFormat(BigDecimal number) {
number = number.setScale(BidConst.STORE_SCALE, RoundingMode.HALF_UP);
return number;
}
public static BigDecimal decimalRateFormat(BigDecimal number) {
return number.multiply(BigDecimal.valueOf(100));
}
public static BigDecimal decimalRateFormat(BigDecimal number) {
return number.multiply(BigDecimal.valueOf(100));
}
//月利率
public static BigDecimal monthRateFormat(BigDecimal number) {
return number.multiply(BigDecimal.valueOf(100)).divide(
BigDecimal.valueOf(12), BidConst.CAL_SCALE,
RoundingMode.HALF_UP);
}
//月利率
public static BigDecimal monthRateFormat(BigDecimal number) {
return number.multiply(BigDecimal.valueOf(100)).divide(
BigDecimal.valueOf(12), BidConst.CAL_SCALE,
RoundingMode.HALF_UP);
}
public static BigDecimal formatBigDecimal(BigDecimal data, int scal) {
if (null == data)
return new BigDecimal(0.00);
return data.setScale(scal, BigDecimal.ROUND_HALF_UP);
}
public static BigDecimal formatBigDecimal(BigDecimal data, int scal) {
if (null == data)
return new BigDecimal(0.00);
return data.setScale(scal, BigDecimal.ROUND_HALF_UP);
}
}

View File

@ -8,7 +8,9 @@ public class AbstractResult {
private int code;
private String message;
AbstractResult() {}
AbstractResult() {
}
protected AbstractResult(ResultStatus status, String message) {
this.code = status.getCode();
this.status = status;
@ -47,6 +49,7 @@ public class AbstractResult {
this.status = ResultStatus.SUCCESS;
return this;
}
public ResultStatus getStatus() {
return this.status;
}

View File

@ -11,12 +11,15 @@ public class ResultGeekQ<T> extends AbstractResult implements Serializable {
protected ResultGeekQ() {
}
protected ResultGeekQ(ResultStatus status, String message) {
super(status, message);
}
protected ResultGeekQ(ResultStatus status) {
super(status);
}
public static <T> ResultGeekQ<T> build() {
return new ResultGeekQ(ResultStatus.SUCCESS, "构造函数");
}

View File

@ -4,27 +4,27 @@ import lombok.Getter;
import lombok.Setter;
/**
* @author 邱润泽
* @author 邱润泽
*/
@Getter
@Setter
public class ResultJSON {
private Boolean success = false;
private String msg;
private Boolean success = false;
private String msg;
public ResultJSON() {
super();
}
public ResultJSON() {
super();
}
public ResultJSON(Boolean success, String msg) {
super();
this.success = success;
this.msg = msg;
}
public ResultJSON(Boolean success, String msg) {
super();
this.success = success;
this.msg = msg;
}
public ResultJSON(String msg) {
super();
this.msg = msg;
}
public ResultJSON(String msg) {
super();
this.msg = msg;
}
}

View File

@ -9,7 +9,7 @@ import java.lang.annotation.*;
@Documented
@Constraint(validatedBy = {MobileValidator.class})
public @interface MobileCheck {
boolean required() default true ;
boolean required() default true;
String message() default "手机号码格式有误!";

View File

@ -8,22 +8,22 @@ import javax.validation.ConstraintValidatorContext;
public class MobileValidator implements ConstraintValidator<MobileCheck, String> {
private boolean require = false ;
private boolean require = false;
@Override
public void initialize(MobileCheck isMobile) {
require = isMobile.required() ;
require = isMobile.required();
}
@Override
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
if(require){
return ValidatorUtil.isMobile(value) ;
}else{
if(StringUtils.isEmpty(value)){
return true ;
}else {
return ValidatorUtil.isMobile(value) ;
if (require) {
return ValidatorUtil.isMobile(value);
} else {
if (StringUtils.isEmpty(value)) {
return true;
} else {
return ValidatorUtil.isMobile(value);
}
}
}

View File

@ -5,7 +5,6 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotNull;
@ -19,10 +18,9 @@ import javax.validation.constraints.NotNull;
public class LoginVo {
@NotNull
@MobileCheck
private String mobile ;
private String mobile;
@NotNull
@Length(min=32)
private String password;
@Override

View File

@ -23,7 +23,6 @@
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin-common</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
@ -81,57 +80,8 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.ini</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8082</port>
<path>/</path>
<useBodyEncodingForURI>true</useBodyEncodingForURI>
<uriEncoding>UTF-8</uriEncoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -6,13 +6,13 @@ import com.geekq.admin.entity.Account;
import java.util.List;
public interface AccountMapper {
int deleteByPrimaryKey(Long id);
int deleteByPrimaryKey(Long id);
int insert(Account record);
int insert(Account record);
Account selectByPrimaryKey(Long id);
Account selectByPrimaryKey(Long id);
List<Account> selectAll();
List<Account> selectAll();
int updateByPrimaryKey(Account record);
int updateByPrimaryKey(Account record);
}

View File

@ -16,7 +16,7 @@ public interface IpLogMapper {
int updateByPrimaryKey(IpLog record);
int queryForCount(IpLogQueryObject qo);
int queryForCount(IpLogQueryObject qo);
List<IpLog> query(IpLogQueryObject qo);
List<IpLog> query(IpLogQueryObject qo);
}

View File

@ -8,24 +8,24 @@ import java.util.Map;
public interface LogininfoMapper {
int deleteByPrimaryKey(Long id);
int deleteByPrimaryKey(Long id);
int insert(Logininfo record);
int insert(Logininfo record);
Logininfo selectByPrimaryKey(Long id);
Logininfo selectByPrimaryKey(Long id);
List<Logininfo> selectAll();
List<Logininfo> selectAll();
int updateByPrimaryKey(Logininfo record);
int updateByPrimaryKey(Logininfo record);
int getCountByNickname(@Param("nickname") String nickname,
int getCountByNickname(@Param("nickname") String nickname,
@Param("userType") int userType);
Logininfo getLoginInfoByNickname(@Param("nickname") String nickname,
@Param("userType") int userType);
Logininfo getLoginInfoByNickname(@Param("nickname") String nickname,
@Param("userType") int userType);
Logininfo login(@Param("name") String name,
Logininfo login(@Param("name") String name,
@Param("password") String password, @Param("userType") int userType);
List<Map<String, Object>> autoComplate(@Param("word") String word, @Param("userType") int userType);
List<Map<String, Object>> autoComplate(@Param("word") String word, @Param("userType") int userType);
}

View File

@ -1,11 +1,10 @@
package com.geekq.admin.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.geekq.admin.pojo.Orders;
import com.geekq.admin.pojo.OrdersExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface OrdersMapper {
int countByExample(OrdersExample example);

View File

@ -8,24 +8,25 @@ import java.util.List;
public interface SystemDictionaryItemMapper {
int deleteByPrimaryKey(Long id);
int deleteByPrimaryKey(Long id);
int insert(SystemDictionaryItem record);
int insert(SystemDictionaryItem record);
SystemDictionaryItem selectByPrimaryKey(Long id);
SystemDictionaryItem selectByPrimaryKey(Long id);
List<SystemDictionaryItem> selectAll();
List<SystemDictionaryItem> selectAll();
int updateByPrimaryKey(SystemDictionaryItem record);
int updateByPrimaryKey(SystemDictionaryItem record);
int queryForCount(SystemDictionaryQueryObject qo);
int queryForCount(SystemDictionaryQueryObject qo);
List<SystemDictionaryItem> query(SystemDictionaryQueryObject qo);
List<SystemDictionaryItem> query(SystemDictionaryQueryObject qo);
/**
* 按照数据字典的目录sn查所有明细
* @param sn
* @return
*/
List<SystemDictionaryItem> queryBySn(@Param("sn") String sn);
/**
* 按照数据字典的目录sn查所有明细
*
* @param sn
* @return
*/
List<SystemDictionaryItem> queryBySn(@Param("sn") String sn);
}

View File

@ -8,19 +8,19 @@ import java.util.List;
public interface SystemDictionaryMapper {
int deleteByPrimaryKey(Long id);
int deleteByPrimaryKey(Long id);
int insert(SystemDictionary record);
int insert(SystemDictionary record);
SystemDictionary selectByPrimaryKey(Long id);
SystemDictionary selectByPrimaryKey(Long id);
List<SystemDictionary> selectAll();
List<SystemDictionary> selectAll();
int updateByPrimaryKey(SystemDictionary record);
int updateByPrimaryKey(SystemDictionary record);
int queryForCount(SystemDictionaryQueryObject qo);
int queryForCount(SystemDictionaryQueryObject qo);
List<SystemDictionary> query(SystemDictionaryQueryObject qo);
List<SystemDictionary> query(SystemDictionaryQueryObject qo);
}

View File

@ -6,13 +6,13 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface UserinfoMapper {
int deleteByPrimaryKey(Long id);
int deleteByPrimaryKey(Long id);
int insert(Userinfo record);
int insert(Userinfo record);
Userinfo selectByPrimaryKey(@Param("id") Long id, @Param("salt") String salt);
Userinfo selectByPrimaryKey(@Param("id") Long id, @Param("salt") String salt);
List<Userinfo> selectAll(@Param("salt") String salt);
List<Userinfo> selectAll(@Param("salt") String salt);
int updateByPrimaryKey(@Param("ui") Userinfo record, @Param("salt") String salt);
int updateByPrimaryKey(@Param("ui") Userinfo record, @Param("salt") String salt);
}

View File

@ -9,136 +9,136 @@ import java.util.ResourceBundle;
public class RedisClient {
/**
* 池化管理jedis链接池
*/
public static JedisPool jedisPool;
/**
* 池化管理jedis链接池
*/
public static JedisPool jedisPool;
static {
static {
//读取相关的配置
ResourceBundle resourceBundle = ResourceBundle.getBundle("redis");
int maxActive = Integer.parseInt(resourceBundle.getString("redis.pool.maxActive"));
int maxIdle = Integer.parseInt(resourceBundle.getString("redis.pool.maxIdle"));
int maxWait = Integer.parseInt(resourceBundle.getString("redis.pool.maxWait"));
//读取相关的配置
ResourceBundle resourceBundle = ResourceBundle.getBundle("redis");
int maxActive = Integer.parseInt(resourceBundle.getString("redis.pool.maxActive"));
int maxIdle = Integer.parseInt(resourceBundle.getString("redis.pool.maxIdle"));
int maxWait = Integer.parseInt(resourceBundle.getString("redis.pool.maxWait"));
String ip = resourceBundle.getString("redis.ip");
int port = Integer.parseInt(resourceBundle.getString("redis.port"));
String ip = resourceBundle.getString("redis.ip");
int port = Integer.parseInt(resourceBundle.getString("redis.port"));
JedisPoolConfig config = new JedisPoolConfig();
//设置最大连接数
config.setMaxTotal(maxActive);
//设置最大空闲数
config.setMaxIdle(maxIdle);
//设置超时时间
config.setMaxWaitMillis(maxWait);
JedisPoolConfig config = new JedisPoolConfig();
//设置最大连接数
config.setMaxTotal(maxActive);
//设置最大空闲数
config.setMaxIdle(maxIdle);
//设置超时时间
config.setMaxWaitMillis(maxWait);
//初始化连接池
jedisPool = new JedisPool(config, ip, port);
//初始化连接池
jedisPool = new JedisPool(config, ip, port);
}
/**
* 向缓存中设置字符串内容
*
* @param key key
* @param value value
* @return
* @throws Exception
*/
public static boolean set(String key, String value) throws Exception {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
jedis.set(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
jedisPool.returnResource(jedis);
}
}
/**
* 向缓存中设置字符串内容
*
* @param key key
* @param value value
* @return
* @throws Exception
*/
public static boolean set(String key, String value) throws Exception {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
jedis.set(key, value);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
jedisPool.returnResource(jedis);
}
/**
* 向缓存中设置对象
*
* @param key
* @param value
* @return
*/
public static boolean set(String key, Object value) {
Jedis jedis = null;
try {
String objectJson = JSON.toJSONString(value);
jedis = jedisPool.getResource();
jedis.set(key, objectJson);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
jedisPool.returnResource(jedis);
}
}
/**
* 向缓存中设置对象
*
* @param key
* @param value
* @return
*/
public static boolean set(String key, Object value) {
Jedis jedis = null;
try {
String objectJson = JSON.toJSONString(value);
jedis = jedisPool.getResource();
jedis.set(key, objectJson);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
jedisPool.returnResource(jedis);
}
/**
* 删除缓存中得对象根据key
*
* @param key
* @return
*/
public static boolean del(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
jedis.del(key);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
jedisPool.returnResource(jedis);
}
}
/**
* 删除缓存中得对象根据key
*
* @param key
* @return
*/
public static boolean del(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
jedis.del(key);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
jedisPool.returnResource(jedis);
}
/**
* 根据key 获取内容
*
* @param key
* @return
*/
public static Object get(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
Object value = jedis.get(key);
return value;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
jedisPool.returnResource(jedis);
}
}
/**
* 根据key 获取内容
*
* @param key
* @return
*/
public static Object get(String key) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
Object value = jedis.get(key);
return value;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
jedisPool.returnResource(jedis);
}
}
/**
* 根据key 获取对象
*
* @param key
* @return
*/
public static <T> T get(String key, Class<T> clazz) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
String value = jedis.get(key);
return JSON.parseObject(value, clazz);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
jedisPool.returnResource(jedis);
}
/**
* 根据key 获取对象
*
* @param key
* @return
*/
public static <T> T get(String key, Class<T> clazz) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
String value = jedis.get(key);
return JSON.parseObject(value, clazz);
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
jedisPool.returnResource(jedis);
}
}
}

View File

@ -11,41 +11,41 @@ import java.util.List;
@Service("accountServiceImpl")
public class AccountServiceImpl implements IAccountService {
@Autowired
private AccountMapper accountMapper;
@Autowired
private AccountMapper accountMapper;
@Override
public void update(Account account) {
int ret = accountMapper.updateByPrimaryKey(account);
@Override
public void update(Account account) {
int ret = accountMapper.updateByPrimaryKey(account);
// if (ret <= 0) {
// throw new RuntimeException("Account对象:" + account.getId()
// + " 乐观锁失败!");
// }
}
}
@Override
public Account get(Long id) {
Account account = accountMapper.selectByPrimaryKey(id);
@Override
public Account get(Long id) {
Account account = accountMapper.selectByPrimaryKey(id);
// if (!account.checkAbstractInfo()) {
// throw new RuntimeException("账户信息被篡改:" + id);
// }
return account;
}
return account;
}
/**
* 重建account表的摘要信息
*/
@Override
public void recreateAbstractInfo() {
List<Account> accounts = this.accountMapper.selectAll();
for (Account account : accounts) {
this.accountMapper.updateByPrimaryKey(account);
}
}
/**
* 重建account表的摘要信息
*/
@Override
public void recreateAbstractInfo() {
List<Account> accounts = this.accountMapper.selectAll();
for (Account account : accounts) {
this.accountMapper.updateByPrimaryKey(account);
}
}
@Override
public List<Account> listAll() {
return this.accountMapper.selectAll();
}
@Override
public List<Account> listAll() {
return this.accountMapper.selectAll();
}
}

View File

@ -16,24 +16,24 @@ import java.util.List;
*/
@Service
public class IpLogServiceImpl implements IIpLogService {
@Autowired
private IpLogMapper ipLogMapper;
@Override
public PageResult query(IpLogQueryObject qo) {
DBContextUtil.setDB(DBContextUtil.DBREAD);
int count=this.ipLogMapper.queryForCount(qo);
if(count>0){
List<IpLog> list=this.ipLogMapper.query(qo);
return new PageResult(count, qo.getPageSize(),qo.getCurrentPage(),list);
}
return PageResult.empty(qo.getPageSize());
}
@Autowired
private IpLogMapper ipLogMapper;
@Override
public void insert(IpLog ipLog) {
this.ipLogMapper.insert(ipLog);
}
@Override
public PageResult query(IpLogQueryObject qo) {
DBContextUtil.setDB(DBContextUtil.DBREAD);
int count = this.ipLogMapper.queryForCount(qo);
if (count > 0) {
List<IpLog> list = this.ipLogMapper.query(qo);
return new PageResult(count, qo.getPageSize(), qo.getCurrentPage(), list);
}
return PageResult.empty(qo.getPageSize());
}
@Override
public void insert(IpLog ipLog) {
this.ipLogMapper.insert(ipLog);
}
}

View File

@ -10,7 +10,6 @@ import com.geekq.admin.mapper.LogininfoMapper;
import com.geekq.admin.mapper.UserinfoMapper;
import com.geekq.admin.service.ILogininfoService;
import com.geekq.admin.service.RedisCacheStorageService;
import com.geekq.admin.utils.UserContext;
import com.geekq.common.enums.Constants;
import com.geekq.common.enums.ResultStatus;
import com.geekq.common.utils.MD5.MD5Utils;
@ -30,94 +29,95 @@ import java.util.Map;
@Service("logininfoServiceImpl")
public class LogininfoServiceImpl implements ILogininfoService {
private static final Logger logger = LoggerFactory.getLogger(LogininfoServiceImpl.class);
@Autowired
private LogininfoMapper loginInfoMapper;
private static final Logger logger = LoggerFactory.getLogger(LogininfoServiceImpl.class);
@Autowired
private LogininfoMapper loginInfoMapper;
@Autowired
private IpLogMapper ipLogMapper;
@Autowired
private IpLogMapper ipLogMapper;
@Autowired
private UserinfoMapper userinfoMapper;
@Autowired
private UserinfoMapper userinfoMapper;
@Autowired
private AccountMapper accountMapper;
@Autowired
private AccountMapper accountMapper;
@Autowired
private RedisCacheStorageService redisService;
@Override
public void register(String username, String password) {
@Autowired
private RedisCacheStorageService redisService;
int count = loginInfoMapper.getCountByNickname(username, Constants.USERTYPE_NORMAL);
if(count <= 0) {
Logininfo logininfo =new Logininfo();
logininfo.setNickname(username);
//获取随机salt
String salt = MD5Utils.getSaltT();
//MD5(MD5(password)+salt)
logininfo.setPassword(MD5Utils.formPassToDBPass(password,salt));
logininfo.setState(Constants.STATE_NORMAL);
logininfo.setUserType(Constants.USERTYPE_NORMAL);
logininfo.setRegisterDate(new Date());
logininfo.setLastLoginDate(new Date());
logininfo.setSalt(salt);
this.loginInfoMapper.insert(logininfo);
@Override
public void register(String username, String password) {
//初始化一个account
Account account = Account.empty(logininfo.getId());
accountMapper.insert(account);
int count = loginInfoMapper.getCountByNickname(username, Constants.USERTYPE_NORMAL);
if (count <= 0) {
Logininfo logininfo = new Logininfo();
logininfo.setNickname(username);
//获取随机salt
String salt = MD5Utils.getSaltT();
//MD5(MD5(password)+salt)
logininfo.setPassword(MD5Utils.formPassToDBPass(password, salt));
logininfo.setState(Constants.STATE_NORMAL);
logininfo.setUserType(Constants.USERTYPE_NORMAL);
logininfo.setRegisterDate(new Date());
logininfo.setLastLoginDate(new Date());
logininfo.setSalt(salt);
this.loginInfoMapper.insert(logininfo);
//初始化一个account
Account account = Account.empty(logininfo.getId());
accountMapper.insert(account);
//初始化一个Userinfo
Userinfo userinfo = Userinfo.empty(logininfo.getId());
int result = this.userinfoMapper.insert(userinfo);
}else{
throw new RuntimeException("用户名已经存在!");
}
}
//初始化一个Userinfo
Userinfo userinfo = Userinfo.empty(logininfo.getId());
int result = this.userinfoMapper.insert(userinfo);
} else {
throw new RuntimeException("用户名已经存在!");
}
}
@Override
public boolean checkUsername(String name, int userType) {
return this.loginInfoMapper.getCountByNickname(name, userType)<=0;
}
@Override
public boolean checkUsername(String name, int userType) {
return this.loginInfoMapper.getCountByNickname(name, userType) <= 0;
}
@Override
public ResultGeekQ<Logininfo> login(String name, String password, int userType, String ip) {
ResultGeekQ<Logininfo> resultGeekQ = ResultGeekQ.build();
@Override
public ResultGeekQ<Logininfo> login(String name, String password, int userType, String ip) {
ResultGeekQ<Logininfo> resultGeekQ = ResultGeekQ.build();
try {
IpLog log = new IpLog(name,new Date(),ip,userType,null);
Logininfo logininfo = loginInfoMapper.getLoginInfoByNickname(name,Constants.USERTYPE_NORMAL);
String salt = logininfo.getSalt();
Logininfo current = this.loginInfoMapper.login(name,
MD5Utils.formPassToDBPass(password,salt), userType);
if(current != null){
redisService.set("Login"+current.getNickname(),current);
try {
IpLog log = new IpLog(name, new Date(), ip, userType, null);
Logininfo logininfo = loginInfoMapper.getLoginInfoByNickname(name, Constants.USERTYPE_NORMAL);
String salt = logininfo.getSalt();
Logininfo current = this.loginInfoMapper.login(name,
MD5Utils.formPassToDBPass(password, salt), userType);
if (current != null) {
redisService.set("Login" + current.getNickname(), current);
// RedisCacheStorageService.set("login"+current.getId().toString(),10000,current);
log.setLoginInfoId(current.getId());
log.setLoginState(IpLog.LOGINSTATE_SUCCESS);
}
ipLogMapper.insert(log);
resultGeekQ.setData(logininfo);
} catch (Exception e) {
logger.error("登录发生错误!",e);
resultGeekQ.withError(ResultStatus.LOGIN_FIAL);
}
return resultGeekQ;
}
log.setLoginInfoId(current.getId());
log.setLoginState(IpLog.LOGINSTATE_SUCCESS);
}
ipLogMapper.insert(log);
resultGeekQ.setData(logininfo);
} catch (Exception e) {
logger.error("登录发生错误!", e);
resultGeekQ.withError(ResultStatus.LOGIN_FIAL);
}
return resultGeekQ;
}
@Override
public boolean hasAdmin() {
return false;
}
@Override
public boolean hasAdmin() {
return false;
}
@Override
public void createDefaultAdmin() {
@Override
public void createDefaultAdmin() {
}
}
@Override
public List<Map<String, Object>> autoComplate(String word, int userType) {
return null;
}
@Override
public List<Map<String, Object>> autoComplate(String word, int userType) {
return null;
}
}

View File

@ -12,32 +12,32 @@ import java.util.UUID;
@Service("ordersService")
public class OrdersServiceImpl implements OrdersService {
final static Logger log = LoggerFactory.getLogger(OrdersServiceImpl.class);
@Autowired
private OrdersMapper ordersMapper;
@Override
public Orders getOrder(String orderId) {
return ordersMapper.selectByPrimaryKey(orderId);
}
@Override
public boolean createOrder(String itemId) {
// 创建订单
String oid = UUID.randomUUID().toString().replaceAll("-", "");
final static Logger log = LoggerFactory.getLogger(OrdersServiceImpl.class);
@Autowired
private OrdersMapper ordersMapper;
@Override
public Orders getOrder(String orderId) {
return ordersMapper.selectByPrimaryKey(orderId);
}
@Override
public boolean createOrder(String itemId) {
// 创建订单
String oid = UUID.randomUUID().toString().replaceAll("-", "");
// Orders o = new Orders();
// o.setId(oid);
// o.setOrderNum(oid);
// o.setItemId(itemId);
// ordersMapper.insert(o);
log.info("订单创建成功");
return true;
}
log.info("订单创建成功");
return true;
}
}

View File

@ -18,6 +18,23 @@ public class RedisCacheStorageServiceImpl implements RedisCacheStorageService {
@Autowired
private RedisCache redisCache;
@SuppressWarnings("unchecked")
public static <T> T stringToBean(String str, Class<T> clazz) {
if (str == null || str.length() <= 0 || clazz == null) {
return null;
}
if (clazz == int.class || clazz == Integer.class) {
return (T) Integer.valueOf(str);
} else if (clazz == String.class) {
return (T) str;
} else if (clazz == long.class || clazz == Long.class) {
return (T) Long.valueOf(str);
} else {
return JSON.toJavaObject(JSON.parseObject(str), clazz);
}
}
@Override
public boolean set(String key, Object value) {
Jedis jedis = null;
@ -34,7 +51,7 @@ public class RedisCacheStorageServiceImpl implements RedisCacheStorageService {
// 获取客户端对象
jedis = redisCache.getResource();
// 执行插入
jedis.set(key,jValue);
jedis.set(key, jValue);
} catch (Exception e) {
LOG.info("client can't connect server");
isSucess = false;
@ -56,32 +73,14 @@ public class RedisCacheStorageServiceImpl implements RedisCacheStorageService {
public Logininfo get(String key) {
Jedis jedis = null;
try {
jedis = redisCache.getResource();
jedis = redisCache.getResource();
//生成真正的key
String str = jedis.get(key);
Logininfo t = stringToBean(str, Logininfo.class);
String str = jedis.get(key);
Logininfo t = stringToBean(str, Logininfo.class);
return t;
}finally {
} finally {
redisCache.returnResource(jedis);
}
}
@SuppressWarnings("unchecked")
public static <T> T stringToBean(String str, Class<T> clazz) {
if(str == null || str.length() <= 0 || clazz == null) {
return null;
}
if(clazz == int.class || clazz == Integer.class) {
return (T)Integer.valueOf(str);
}else if(clazz == String.class) {
return (T)str;
}else if(clazz == long.class || clazz == Long.class) {
return (T)Long.valueOf(str);
}else {
return JSON.toJavaObject(JSON.parseObject(str), clazz);
}
}
}

View File

@ -14,61 +14,61 @@ import java.util.List;
@Service("iSystemDictionaryServiceImpl")
public class SystemDictionaryServiceImpl implements ISystemDictionaryService {
@Autowired
private SystemDictionaryMapper systemDictionaryMapper;
@Autowired
private SystemDictionaryMapper systemDictionaryMapper;
@Autowired
private SystemDictionaryItemMapper systemDictionaryItemMapper;
@Autowired
private SystemDictionaryItemMapper systemDictionaryItemMapper;
@Override
public List<SystemDictionary> listDics() {
return systemDictionaryMapper.selectAll();
}
@Override
public List<SystemDictionary> listDics() {
return systemDictionaryMapper.selectAll();
}
@Override
public PageResult queryDic(SystemDictionaryQueryObject qo) {
int count = this.systemDictionaryMapper.queryForCount(qo);
if (count > 0) {
List<SystemDictionary> list = this.systemDictionaryMapper.query(qo);
return new PageResult(count, qo.getPageSize(), qo.getCurrentPage(),
list);
}
return PageResult.empty(qo.getPageSize());
}
@Override
public PageResult queryDic(SystemDictionaryQueryObject qo) {
int count = this.systemDictionaryMapper.queryForCount(qo);
if (count > 0) {
List<SystemDictionary> list = this.systemDictionaryMapper.query(qo);
return new PageResult(count, qo.getPageSize(), qo.getCurrentPage(),
list);
}
return PageResult.empty(qo.getPageSize());
}
@Override
public void saveOrUpdate(SystemDictionary sd) {
if (sd.getId() != null) {
this.systemDictionaryMapper.updateByPrimaryKey(sd);
} else {
this.systemDictionaryMapper.insert(sd);
}
}
@Override
public void saveOrUpdate(SystemDictionary sd) {
if (sd.getId() != null) {
this.systemDictionaryMapper.updateByPrimaryKey(sd);
} else {
this.systemDictionaryMapper.insert(sd);
}
}
@Override
public PageResult queryDicItem(SystemDictionaryQueryObject qo) {
int count = this.systemDictionaryItemMapper.queryForCount(qo);
if (count > 0) {
List<SystemDictionaryItem> list = this.systemDictionaryItemMapper
.query(qo);
return new PageResult(count, qo.getPageSize(), qo.getCurrentPage(),
list);
}
return PageResult.empty(qo.getPageSize());
}
@Override
public PageResult queryDicItem(SystemDictionaryQueryObject qo) {
int count = this.systemDictionaryItemMapper.queryForCount(qo);
if (count > 0) {
List<SystemDictionaryItem> list = this.systemDictionaryItemMapper
.query(qo);
return new PageResult(count, qo.getPageSize(), qo.getCurrentPage(),
list);
}
return PageResult.empty(qo.getPageSize());
}
@Override
public void saveOrUpdateItem(SystemDictionaryItem item) {
if (item.getId() != null) {
this.systemDictionaryItemMapper.updateByPrimaryKey(item);
} else {
this.systemDictionaryItemMapper.insert(item);
}
}
@Override
public void saveOrUpdateItem(SystemDictionaryItem item) {
if (item.getId() != null) {
this.systemDictionaryItemMapper.updateByPrimaryKey(item);
} else {
this.systemDictionaryItemMapper.insert(item);
}
}
@Override
public List<SystemDictionaryItem> queryBySn(String sn) {
return this.systemDictionaryItemMapper.queryBySn(sn);
}
@Override
public List<SystemDictionaryItem> queryBySn(String sn) {
return this.systemDictionaryItemMapper.queryBySn(sn);
}
}

View File

@ -9,17 +9,17 @@ import java.util.List;
/**
* 数据字典工具类
* @author Administrator
*
* @author Administrator
*/
@Component
public class SystemDictionaryUtil {
@Autowired
private ISystemDictionaryService systemDictionaryService;
@Autowired
private ISystemDictionaryService systemDictionaryService;
public List<SystemDictionaryItem> list(String sn) {
return systemDictionaryService.queryBySn(sn);
}
public List<SystemDictionaryItem> list(String sn) {
return systemDictionaryService.queryBySn(sn);
}
}

View File

@ -3,17 +3,14 @@ package com.geekq.admin.service.impl;
import com.geekq.admin.entity.Userinfo;
import com.geekq.admin.mapper.UserinfoMapper;
import com.geekq.admin.service.IUserService;
import com.geekq.admin.utils.UserContext;
import com.geekq.common.utils.numcal.BitStatesUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service("userServiceImpl")
public class UserServiceImpl implements IUserService {
@Autowired
private UserinfoMapper userinfoMapper;
@Autowired
private UserinfoMapper userinfoMapper;
/*@Autowired
private ISendVerifyCodeService verifyCodeService;*/
@ -23,25 +20,25 @@ public class UserServiceImpl implements IUserService {
private String salt;
*/
@Override
public void update(Userinfo userinfo) {
@Override
public void update(Userinfo userinfo) {
/* int ret = userinfoMapper.updateByPrimaryKey(userinfo,salt);
if (ret <= 0) {
throw new RuntimeException("乐观锁失败");*/
/* throw new RuntimeException("Userinfo对象:" + userinfo.getId()
+ " 乐观锁失败!");*/
}
}
@Override
public Userinfo get(Long id) {
@Override
public Userinfo get(Long id) {
return null;/*userinfoMapper.selectByPrimaryKey(id,salt);*/
}
return null;/*userinfoMapper.selectByPrimaryKey(id,salt);*/
}
@Override
public boolean bindPhone(String phoneNumber, String verifyCode) {
return false;
}
@Override
public boolean bindPhone(String phoneNumber, String verifyCode) {
return false;
}
/*@Override
public boolean bindPhone(String phoneNumber, String verifyCode) {
@ -56,8 +53,8 @@ public class UserServiceImpl implements IUserService {
return false;
}*/
@Override
public void updateBasicInfo(Userinfo userinfo) {
@Override
public void updateBasicInfo(Userinfo userinfo) {
/* Userinfo current = this.userinfoMapper.selectByPrimaryKey(UserContext
.getCurrent().getId(),salt);*/
/* current.setEducationBackground(userinfo.getEducationBackground());
@ -69,6 +66,6 @@ public class UserServiceImpl implements IUserService {
current.addState(BitStatesUtils.OP_BASE_INFO);
}
this.update(current);*/
}
}
}

View File

@ -14,19 +14,13 @@ import javax.servlet.http.HttpSession;
public class UserContext {
@Autowired
private HttpSession session;
@Autowired
private HttpServletRequest request;
public static final String LOGIN_IN_SESSION = "logininfo";
public static final String VERIFYCODE_IN_SESSION = "VERIFYCODE_IN_SESSION";
@Bean
public RequestContextListener requestContextListener(){
return new RequestContextListener();
}
private static ThreadLocal<Logininfo> userHolder = new ThreadLocal<Logininfo>();
@Autowired
private HttpSession session;
@Autowired
private HttpServletRequest request;
/* @Autowired
private RedisService redisService;*/
@ -35,7 +29,10 @@ public class UserContext {
.getRequestAttributes()).getRequest();
}
private static ThreadLocal<Logininfo> userHolder = new ThreadLocal<Logininfo>();
public static void removeUser() {
userHolder.remove();
}
/* public static void putLogininfo(Logininfo user) {
@ -46,21 +43,22 @@ public class UserContext {
return userHolder.get();
}*/
public static void removeUser() {
userHolder.remove();
}
public static void putLogininfo(Logininfo logininfo) {
HttpServletRequest a = ((ServletRequestAttributes) RequestContextHolder
public static void putLogininfo(Logininfo logininfo) {
HttpServletRequest a = ((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getRequest();
HttpSession b = a.getSession();
b.setAttribute(LOGIN_IN_SESSION, logininfo);
}
b.setAttribute(LOGIN_IN_SESSION, logininfo);
}
public static Logininfo getCurrent() {
return (Logininfo) getRequest().getSession().getAttribute(
LOGIN_IN_SESSION);
}
public static Logininfo getCurrent() {
return (Logininfo) getRequest().getSession().getAttribute(
LOGIN_IN_SESSION);
}
@Bean
public RequestContextListener requestContextListener() {
return new RequestContextListener();
}
// public static void putVerifyCode(VerifyCode code) {
// getRequest().getSession().setAttribute(VERIFYCODE_IN_SESSION, code);

View File

@ -1,147 +1,71 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin</artifactId>
<version>${revision}</version>
</parent>
<artifactId>miaosha-admin-web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
</dependency>
<!-- zk 客户端依赖 -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin</artifactId>
<version>${revision}</version>
</parent>
<artifactId>miaosha-admin-web</artifactId>
<!-- xml freemarket 模板配置-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<packaging>war</packaging>
<!-- JSP相关 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin-api</artifactId>
</dependency>
<dependency>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin-common</artifactId>
</dependency>
<dependency>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin-service</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.ini</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8080</port>
<path>/</path>
<useBodyEncodingForURI>true</useBodyEncodingForURI>
<uriEncoding>UTF-8</uriEncoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin-service</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -3,7 +3,6 @@ package com.geekq.web.controller;
import com.geekq.web.interceptor.RequiredLogin;
import com.geekq.web.service.CulsterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@ -12,15 +11,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
*/
@Controller
public class PayController {
@Autowired
private CulsterService buyService;
@RequiredLogin
@RequestMapping("/index")
public String index() {
return "login";
}
@Autowired
private CulsterService buyService;
@RequiredLogin
@RequestMapping("/index")
public String index() {
return "login";
}
}

View File

@ -16,12 +16,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
* @author 邱润泽
*/
@Controller
public class RegisterController extends BaseController{
public class RegisterController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(RegisterController.class);
@Autowired
private ILogininfoService logininfoService ;
private ILogininfoService logininfoService;
@RequestMapping("/register")
@ResponseBody
@ -31,7 +31,7 @@ public class RegisterController extends BaseController{
this.logininfoService.register(username, password);
json.setSuccess(true);
} catch (RuntimeException e) {
logger.error("注册失败",e);
logger.error("注册失败", e);
json.setMsg("注册失败,请联系相关人员!");
}
return json;
@ -44,7 +44,7 @@ public class RegisterController extends BaseController{
try {
result.setData(this.logininfoService.checkUsername(username, Constants.USERTYPE_NORMAL));
} catch (RuntimeException e) {
logger.error("检查是否存在该用户名!",e);
logger.error("检查是否存在该用户名!", e);
result.withError(ResultStatus.SYSTEM_ERROR);
}
return result;

View File

@ -9,18 +9,18 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AddGlobalUtilInterceptor extends HandlerInterceptorAdapter {
@Autowired
private SystemDictionaryUtil systemDicUtil;
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
if (modelAndView != null) {
modelAndView.addObject("_DicUtil", systemDicUtil);
}
super.postHandle(request, response, handler, modelAndView);
}
@Autowired
private SystemDictionaryUtil systemDicUtil;
@Override
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
if (modelAndView != null) {
modelAndView.addObject("_DicUtil", systemDicUtil);
}
super.postHandle(request, response, handler, modelAndView);
}
}

View File

@ -2,37 +2,35 @@ package com.geekq.web.interceptor;
import com.geekq.admin.entity.Logininfo;
import com.geekq.admin.service.RedisCacheStorageService;
import com.geekq.admin.utils.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.jws.soap.SOAPBinding;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginInterceptor extends HandlerInterceptorAdapter {
@Autowired
private RedisCacheStorageService redisService;
@Autowired
private RedisCacheStorageService redisService;
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
if (handler instanceof HandlerMethod) {
HandlerMethod hm = (HandlerMethod) handler;
RequiredLogin rl = hm.getMethodAnnotation(RequiredLogin.class);
System.out.println(request.getParameter("username"));
String username =request.getParameter("username");
if (rl != null) {
Logininfo current = redisService.get("Login"+username);
if (current == null) {
response.sendRedirect("/login.html");
return false;
}
}
}
return super.preHandle(request, response, handler);
}
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
if (handler instanceof HandlerMethod) {
HandlerMethod hm = (HandlerMethod) handler;
RequiredLogin rl = hm.getMethodAnnotation(RequiredLogin.class);
System.out.println(request.getParameter("username"));
String username = request.getParameter("username");
if (rl != null) {
Logininfo current = redisService.get("Login" + username);
if (current == null) {
response.sendRedirect("/login.html");
return false;
}
}
}
return super.preHandle(request, response, handler);
}
}

View File

@ -2,11 +2,11 @@ package com.geekq.web.service;
public interface CulsterService {
/**
* @Description: 购买商品
*/
public void doBuyItem(String itemId);
public boolean displayBuy(String itemId);
/**
* @Description: 购买商品
*/
public void doBuyItem(String itemId);
public boolean displayBuy(String itemId);
}

View File

@ -1,38 +1,37 @@
package com.geekq.web.service.impl;
import com.geekq.admin.service.OrdersService;
import com.geekq.web.service.CulsterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.geekq.admin.service.OrdersService;
import com.geekq.web.service.CulsterService;
@Service("buyService")
public class CulsterServiceImpl implements CulsterService {
final static Logger log = LoggerFactory.getLogger(CulsterServiceImpl.class);
final static Logger log = LoggerFactory.getLogger(CulsterServiceImpl.class);
// @Autowired
// private ItemsService itemService;
@Autowired
private OrdersService ordersService;
@Override
public void doBuyItem(String itemId) {
// 减少库存
@Autowired
private OrdersService ordersService;
@Override
public void doBuyItem(String itemId) {
// 减少库存
// itemService.displayReduceCounts(itemId, 1);
// 创建订单
ordersService.createOrder(itemId);
}
@Override
public boolean displayBuy(String itemId) {
int buyCounts = 5;
// 创建订单
ordersService.createOrder(itemId);
}
@Override
public boolean displayBuy(String itemId) {
int buyCounts = 5;
// // 1. 判断库存
// int stockCounts = itemService.getItemCounts(itemId);
// if (stockCounts < buyCounts) {
@ -42,7 +41,7 @@ public class CulsterServiceImpl implements CulsterService {
// }
//
// // 2. 创建订单
boolean isOrderCreated = ordersService.createOrder(itemId);
boolean isOrderCreated = ordersService.createOrder(itemId);
//
// // 3. 创建订单成功后扣除库存
// if (isOrderCreated) {
@ -52,9 +51,9 @@ public class CulsterServiceImpl implements CulsterService {
// log.info("订单创建失败...");
// return false;
// }
return true;
}
return true;
}
}

View File

@ -1,164 +1,40 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<parent>
<groupId>com.geekq</groupId>
<artifactId>miaosha-parent</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<!-- 集中定义依赖版本号 -->
<properties>
<spring-data-redis.version>1.8.7.RELEASE</spring-data-redis.version>
<apache-commons-pool2>2.4.2</apache-commons-pool2>
<mybatis.version>3.2.8</mybatis.version>
<mybatis.spring.version>1.2.2</mybatis.spring.version>
<mybatis.paginator.version>1.2.15</mybatis.paginator.version>
<mysql.version>5.1.41</mysql.version>
<slf4j.version>1.7.21</slf4j.version>
<jackson.version>2.7.4</jackson.version>
<druid.version>1.1.0</druid.version>
<httpclient.version>4.3.5</httpclient.version>
<jstl.version>1.2</jstl.version>
<servlet-api.version>2.5</servlet-api.version>
<jsp-api.version>2.0</jsp-api.version>
<commons-lang3.version>3.3.2</commons-lang3.version>
<commons-net.version>3.3</commons-net.version>
<pagehelper.version>4.1.3</pagehelper.version>
<jsqlparser.version>0.9.1</jsqlparser.version>
<!-- 使用redisTamplate结合jedisPoolConifg 必须使用jedis版本2.9.0 -->
<jedis.version>2.9.0</jedis.version>
<commons.httpclient.version>3.1</commons.httpclient.version>
<dubbo.version>2.6.0</dubbo.version>
<zookeeper.version>3.4.11</zookeeper.version>
<zkclient.version>0.1</zkclient.version>
<apache.curator.version>4.0.0</apache.curator.version>
</properties>
<!-- 只定义依赖的版本,不会实际依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin-common</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin-service</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>${commons-net.version}</version>
</dependency>
<!-- Jackson Json处理工具包 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>com.github.miemiedev</groupId>
<artifactId>mybatis-paginator</artifactId>
<version>${mybatis.paginator.version}</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>${pagehelper.version}</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp-api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- 资源文件拷贝插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- java编译插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- 配置Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.geekq</groupId>
<artifactId>miaosha-parent</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<modules>
<module>miaosha-admin-common</module>
<module>miaosha-admin-api</module>
<module>miaosha-admin-service</module>
<module>miaosha-admin-web</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin-common</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>com.geekq</groupId>
<artifactId>miaosha-admin-service</artifactId>
<version>${revision}</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 配置sts插件 -->
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<modules>
<module>miaosha-admin-common</module>
<module>miaosha-admin-api</module>
<module>miaosha-admin-service</module>
<module>miaosha-admin-web</module>
</modules>
</project>

View File

@ -6,22 +6,8 @@
<groupId>com.geekq.api</groupId>
<artifactId>miaosha-order-api</artifactId>
<version>${revision}</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
<name>miaosha-order-api</name>
<description>Dubbo api for Spring Boot</description>
<parent>
<groupId>com.geekq.dubbo</groupId>
<artifactId>miaosha-order</artifactId>

View File

@ -10,11 +10,11 @@ import lombok.Setter;
@AllArgsConstructor
@NoArgsConstructor
public class Goods {
private Long id;
private String goodsName;
private String goodsTitle;
private String goodsImg;
private String goodsDetail;
private Double goodsPrice;
private Integer goodsStock;
private Long id;
private String goodsName;
private String goodsTitle;
private String goodsImg;
private String goodsDetail;
private Double goodsPrice;
private Integer goodsStock;
}

View File

@ -15,15 +15,15 @@ import java.util.Date;
@NoArgsConstructor
@Alias("goodsVoOrder")
public class GoodsVoOrder implements Serializable {
private Long id;
private String goodsName;
private String goodsTitle;
private String goodsImg;
private String goodsDetail;
private Double goodsPrice;
private Integer goodsStock;
private Double miaoshaPrice;
private Integer stockCount;
private Date startDate;
private Date endDate;
private Long id;
private String goodsName;
private String goodsTitle;
private String goodsImg;
private String goodsDetail;
private Double goodsPrice;
private Integer goodsStock;
private Double miaoshaPrice;
private Integer stockCount;
private Date startDate;
private Date endDate;
}

View File

@ -15,9 +15,9 @@ import java.util.Date;
@NoArgsConstructor
@Alias("MiaoshaGoods")
public class MiaoshaGoods implements Serializable {
private Long id;
private Long goodsId;
private Integer stockCount;
private Date startDate;
private Date endDate;
private Long id;
private Long goodsId;
private Integer stockCount;
private Date startDate;
private Date endDate;
}

View File

@ -12,12 +12,14 @@ public interface GoodsService {
/**
* 查询获取全部信息
*
* @return
*/
public ResultGeekQOrder<List<GoodsVoOrder>> listGoodsVo();
/**
* 根据商品id查询货物信息
*
* @param goodsId
* @return
*/
@ -25,7 +27,8 @@ public interface GoodsService {
/**
* 减库存
*
* @return
*/
public boolean reduceStock(GoodsVoOrder goods);
public boolean reduceStock(GoodsVoOrder goods);
}

View File

@ -1,7 +1,6 @@
package com.geekq.api.service;
import com.geekq.api.entity.GoodsVoOrder;
import com.geekq.api.service.GoodsService;
import com.geekq.api.utils.ResultGeekQOrder;
import org.springframework.stereotype.Service;

View File

@ -1,13 +1,14 @@
package com.geekq.api.utils;
public class AbstractResultOrder {
private ResultStatusOrder status;
private int code;
private String message;
protected AbstractResultOrder() {
}
protected AbstractResultOrder(ResultStatusOrder status, String message) {
this.code = status.getCode();
this.status = status;
@ -45,6 +46,7 @@ public class AbstractResultOrder {
this.status = ResultStatusOrder.SUCCESS;
return this;
}
public ResultStatusOrder getStatus() {
return this.status;
}

View File

@ -10,14 +10,17 @@ public class ResultGeekQOrder<T> extends AbstractResultOrder implements Serializ
protected ResultGeekQOrder() {
}
protected ResultGeekQOrder(ResultStatusOrder status, String message) {
super(status, message);
}
protected ResultGeekQOrder(ResultStatusOrder status) {
super(status);
}
public static <T> ResultGeekQOrder<T> build() {
return new ResultGeekQOrder(ResultStatusOrder.SUCCESS, (String)null);
return new ResultGeekQOrder(ResultStatusOrder.SUCCESS, (String) null);
}
public static <T> ResultGeekQOrder<T> build(String message) {

View File

@ -8,6 +8,7 @@ package com.geekq.api.utils;
* 4 秒杀错误
* 5 商品错误
* 6 订单错误
*
* @author qiurunze
*/
public enum ResultStatusOrder {
@ -28,36 +29,36 @@ public enum ResultStatusOrder {
/**
* 注册登录
*/
RESIGETR_SUCCESS(20000,"注册成功!"),
RESIGETER_FAIL(200001,"注册失败!"),
CODE_FAIL(200002,"验证码不一致!"),
RESIGETR_SUCCESS(20000, "注册成功!"),
RESIGETER_FAIL(200001, "注册失败!"),
CODE_FAIL(200002, "验证码不一致!"),
/**
* check
*/
BIND_ERROR (30001,"参数校验异常:%s"),
ACCESS_LIMIT_REACHED (30002,"请求非法!"),
REQUEST_ILLEGAL (30004,"访问太频繁!"),
SESSION_ERROR (30005,"Session不存在或者已经失效!"),
PASSWORD_EMPTY (30006,"登录密码不能为空!"),
MOBILE_EMPTY (30007,"手机号不能为空!"),
MOBILE_ERROR (30008,"手机号格式错误!"),
MOBILE_NOT_EXIST (30009,"账号不存在!"),
PASSWORD_ERROR (30010,"密码错误!"),
USER_NOT_EXIST(30011,"用户不存在!"),
BIND_ERROR(30001, "参数校验异常:%s"),
ACCESS_LIMIT_REACHED(30002, "请求非法!"),
REQUEST_ILLEGAL(30004, "访问太频繁!"),
SESSION_ERROR(30005, "Session不存在或者已经失效!"),
PASSWORD_EMPTY(30006, "登录密码不能为空!"),
MOBILE_EMPTY(30007, "手机号不能为空!"),
MOBILE_ERROR(30008, "手机号格式错误!"),
MOBILE_NOT_EXIST(30009, "账号不存在!"),
PASSWORD_ERROR(30010, "密码错误!"),
USER_NOT_EXIST(30011, "用户不存在!"),
/**
* 订单模块
*/
ORDER_NOT_EXIST(60001,"订单不存在"),
ORDER_NOT_EXIST(60001, "订单不存在"),
/**
* 秒杀模块
*/
MIAO_SHA_OVER(40001,"商品已经秒杀完毕"),
REPEATE_MIAOSHA(40002,"不能重复秒杀"),
MIAOSHA_FAIL(40003,"秒杀失败"),
ORDER_GET_FAIL(40004,"订单获取失败");
MIAO_SHA_OVER(40001, "商品已经秒杀完毕"),
REPEATE_MIAOSHA(40002, "不能重复秒杀"),
MIAOSHA_FAIL(40003, "秒杀失败"),
ORDER_GET_FAIL(40004, "订单获取失败");
/**
* 商品模块
@ -70,6 +71,10 @@ public enum ResultStatusOrder {
this.message = message;
}
private ResultStatusOrder(Object... args) {
this.message = String.format(this.message, args);
}
public int getCode() {
return this.code;
}
@ -97,8 +102,4 @@ public enum ResultStatusOrder {
public String toString() {
return this.getName();
}
private ResultStatusOrder(Object... args) {
this.message = String.format(this.message, args);
}
}

View File

@ -8,10 +8,11 @@ import org.springframework.context.annotation.ImportResource;
/**
* DubboProviderApplication
* 服务提供启动类
*
* @author geekq
* @date 2018/6/7
*/
@ImportResource(value={"classpath:provider.xml"})
@ImportResource(value = {"classpath:provider.xml"})
@SpringBootApplication
@MapperScan("com.geekq.provider.mapper")
public class DubboProviderApplication {

View File

@ -32,10 +32,10 @@ public class GoodsServiceImpl implements GoodsService {
try {
resultGeekQ.setData(goodsMapper.listGoodsVo());
} catch (Exception e) {
logger.error("获取订单数据失败!",e);
logger.error("获取订单数据失败!", e);
resultGeekQ.withError(ResultStatusOrder.ORDER_GET_FAIL);
}
return resultGeekQ;
return resultGeekQ;
}
@Override
@ -43,10 +43,10 @@ public class GoodsServiceImpl implements GoodsService {
ResultGeekQOrder<GoodsVoOrder> resultGeekQ = ResultGeekQOrder.build();
try {
GoodsVoOrder goodsVoOrder = goodsMapper.getGoodsVoByGoodsId(goodsId);
GoodsVoOrder goodsVoOrder = goodsMapper.getGoodsVoByGoodsId(goodsId);
resultGeekQ.setData(goodsVoOrder);
} catch (Exception e) {
logger.error("获取单个订单失败!",e);
logger.error("获取单个订单失败!", e);
resultGeekQ.withError(ResultStatusOrder.ORDER_GET_FAIL);
}
return resultGeekQ;

View File

@ -18,47 +18,30 @@
<module>miaosha-order-provider</module>
</modules>
<description>Dubbo springboot for Spring Boot</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<curator-framework.version>4.0.1</curator-framework.version>
<zookeeper.version>3.4.13</zookeeper.version>
<dubbo.starter.version>0.2.1.RELEASE</dubbo.starter.version>
<org.mybatis.version>2.2.0</org.mybatis.version>
<com.alibaba.druid>1.1.10</com.alibaba.druid>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${org.mybatis.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.starter.version}</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator-framework.version}</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -4,12 +4,12 @@ import java.io.Serializable;
import java.math.BigDecimal;
/**
* dto 不包含业务逻辑 pojo 对应表数据 vo 把指定页面的所有数据封装起来
* dto 不包含业务逻辑 pojo 对应表数据 vo 把指定页面的所有数据封装起来
*/
public class CapitalTradeOrderDto implements Serializable {
private static final long serialVersionUID = 6627401903410124642L;
private long selfUserId;
private long oppositeUserId;

View File

@ -1,20 +1,18 @@
package com.geekq.dubbo.springboot;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/**
* Unit test for simple App.
*/
public class AppTest
{
public class AppTest {
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
public void shouldAnswerWithTrue() {
assertTrue(true);
}
}

View File

@ -30,27 +30,19 @@
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -59,7 +51,6 @@
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@ -73,11 +64,6 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo-shaded</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
@ -85,18 +71,6 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.51</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -32,22 +32,15 @@
<dependency>
<groupId>com.alibaba.spring.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>0.10</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
@ -60,13 +53,6 @@
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@ -79,34 +65,14 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo-shaded</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.51</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -31,15 +31,4 @@
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -16,113 +16,50 @@
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
<!-- zk 客户端依赖 -->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--打包的时候可以不用包进去,别的设施会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。
相当于compile但是打包阶段做了exclude操作-->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--<dependency>-->
<!--<groupId>com.geekq.dubbo.springboot</groupId>-->
<!--<artifactId>miaosha-rely</artifactId>-->
<!--<version>${revision}</version>-->
<!--</dependency>-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
@ -151,45 +88,14 @@
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.13</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>miaosha-v1/src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>miaosha-v1/src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>application-local.properties</exclude>
<exclude>application-dev.properties</exclude>
<exclude>application-prod.properties</exclude>
<exclude>application-test.properties</exclude>
</excludes>
</resource>
<resource>
<directory>miaosha-v1/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application-${activatedProperties}.properties</include>
<include>application.properties</include>
</includes>
</resource>
</resources>
</build>
</project>

View File

@ -2,8 +2,6 @@ package com.geekq.miaosha;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableScheduling;
@ -16,44 +14,4 @@ public class GeekQMainApplication {
}
}

View File

@ -23,98 +23,98 @@ import static com.geekq.miaosha.common.enums.ResultStatus.ACCESS_LIMIT_REACHED;
import static com.geekq.miaosha.common.enums.ResultStatus.SESSION_ERROR;
@Service
public class AccessInterceptor extends HandlerInterceptorAdapter{
public class AccessInterceptor extends HandlerInterceptorAdapter {
private static Logger logger = LoggerFactory.getLogger(AccessInterceptor.class);
private static Logger logger = LoggerFactory.getLogger(AccessInterceptor.class);
@Autowired
MiaoShaUserService userService;
@Autowired
MiaoShaUserService userService;
@Autowired
RedisService redisService;
@Autowired
RedisService redisService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
/**
* 获取调用 获取主要方法
*/
if(handler instanceof HandlerMethod) {
logger.info("打印拦截方法handler {} ",handler);
HandlerMethod hm = (HandlerMethod)handler;
//方便mybatis 测试
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
/**
* 获取调用 获取主要方法
*/
if (handler instanceof HandlerMethod) {
logger.info("打印拦截方法handler {} ", handler);
HandlerMethod hm = (HandlerMethod) handler;
//方便mybatis 测试
// if(hm.getMethod().getName().startsWith("test")){
// return true;
// }
MiaoshaUser user = getUser(request, response);
UserContext.setUser(user);
AccessLimit accessLimit = hm.getMethodAnnotation(AccessLimit.class);
if(accessLimit == null) {
return true;
}
int seconds = accessLimit.seconds();
int maxCount = accessLimit.maxCount();
boolean needLogin = accessLimit.needLogin();
String key = request.getRequestURI();
if(needLogin) {
if(user == null) {
render(response, SESSION_ERROR);
return false;
}
key += "_" + user.getNickname();
}else {
//do nothing
}
AccessKey ak = AccessKey.withExpire(seconds);
Integer count = redisService.get(ak, key, Integer.class);
if(count == null) {
redisService.set(ak, key, 1);
}else if(count < maxCount) {
redisService.incr(ak, key);
}else {
render(response, ACCESS_LIMIT_REACHED);
return false;
}
}
return true;
}
MiaoshaUser user = getUser(request, response);
UserContext.setUser(user);
AccessLimit accessLimit = hm.getMethodAnnotation(AccessLimit.class);
if (accessLimit == null) {
return true;
}
int seconds = accessLimit.seconds();
int maxCount = accessLimit.maxCount();
boolean needLogin = accessLimit.needLogin();
String key = request.getRequestURI();
if (needLogin) {
if (user == null) {
render(response, SESSION_ERROR);
return false;
}
key += "_" + user.getNickname();
} else {
//do nothing
}
AccessKey ak = AccessKey.withExpire(seconds);
Integer count = redisService.get(ak, key, Integer.class);
if (count == null) {
redisService.set(ak, key, 1);
} else if (count < maxCount) {
redisService.incr(ak, key);
} else {
render(response, ACCESS_LIMIT_REACHED);
return false;
}
}
return true;
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
super.afterCompletion(request, response, handler, ex);
UserContext.removeUser();
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
super.afterCompletion(request, response, handler, ex);
UserContext.removeUser();
}
private void render(HttpServletResponse response, ResultStatus cm)throws Exception {
response.setContentType("application/json;charset=UTF-8");
OutputStream out = response.getOutputStream();
String str = JSON.toJSONString(ResultGeekQ.error(cm));
out.write(str.getBytes("UTF-8"));
out.flush();
out.close();
}
private void render(HttpServletResponse response, ResultStatus cm) throws Exception {
response.setContentType("application/json;charset=UTF-8");
OutputStream out = response.getOutputStream();
String str = JSON.toJSONString(ResultGeekQ.error(cm));
out.write(str.getBytes("UTF-8"));
out.flush();
out.close();
}
private MiaoshaUser getUser(HttpServletRequest request, HttpServletResponse response) {
String paramToken = request.getParameter(MiaoShaUserService.COOKIE_NAME_TOKEN);
String cookieToken = getCookieValue(request, MiaoShaUserService.COOKIE_NAME_TOKEN);
if(StringUtils.isEmpty(cookieToken) && StringUtils.isEmpty(paramToken)) {
return null;
}
String token = StringUtils.isEmpty(paramToken)?cookieToken:paramToken;
return userService.getByToken(response, token);
}
private MiaoshaUser getUser(HttpServletRequest request, HttpServletResponse response) {
String paramToken = request.getParameter(MiaoShaUserService.COOKIE_NAME_TOKEN);
String cookieToken = getCookieValue(request, MiaoShaUserService.COOKIE_NAME_TOKEN);
if (StringUtils.isEmpty(cookieToken) && StringUtils.isEmpty(paramToken)) {
return null;
}
String token = StringUtils.isEmpty(paramToken) ? cookieToken : paramToken;
return userService.getByToken(response, token);
}
private String getCookieValue(HttpServletRequest request, String cookiName) {
Cookie[] cookies = request.getCookies();
if(cookies == null || cookies.length <= 0){
return null;
}
for(Cookie cookie : cookies) {
if(cookie.getName().equals(cookiName)) {
return cookie.getValue();
}
}
return null;
}
private String getCookieValue(HttpServletRequest request, String cookiName) {
Cookie[] cookies = request.getCookies();
if (cookies == null || cookies.length <= 0) {
return null;
}
for (Cookie cookie : cookies) {
if (cookie.getName().equals(cookiName)) {
return cookie.getValue();
}
}
return null;
}
}

View File

@ -4,12 +4,12 @@ import com.geekq.miaosha.redis.BasePrefix;
public class AccessKey extends BasePrefix {
private AccessKey( int expireSeconds, String prefix) {
super(expireSeconds, prefix);
}
public static AccessKey withExpire(int expireSeconds) {
return new AccessKey(expireSeconds, "access");
}
private AccessKey(int expireSeconds, String prefix) {
super(expireSeconds, prefix);
}
public static AccessKey withExpire(int expireSeconds) {
return new AccessKey(expireSeconds, "access");
}
}

View File

@ -9,7 +9,9 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Retention(RUNTIME)
@Target(METHOD)
public @interface AccessLimit {
int seconds();
int maxCount();
boolean needLogin() default true;
int seconds();
int maxCount();
boolean needLogin() default true;
}

View File

@ -3,19 +3,19 @@ package com.geekq.miaosha.access;
import com.geekq.miaosha.domain.MiaoshaUser;
public class UserContext {
private static ThreadLocal<MiaoshaUser> userHolder = new ThreadLocal<MiaoshaUser>();
public static void setUser(MiaoshaUser user) {
userHolder.set(user);
}
public static MiaoshaUser getUser() {
return userHolder.get();
}
public static void removeUser() {
userHolder.remove();
}
private static ThreadLocal<MiaoshaUser> userHolder = new ThreadLocal<MiaoshaUser>();
public static MiaoshaUser getUser() {
return userHolder.get();
}
public static void setUser(MiaoshaUser user) {
userHolder.set(user);
}
public static void removeUser() {
userHolder.remove();
}
}

View File

@ -6,14 +6,14 @@ public class Constanst {
public static String COUNTLOGIN = "count:login";
public enum orderStaus{
public enum orderStaus {
ORDER_NOT_PAY("新建未支付");
orderStaus(String name){
this.name=name;
}
private String name;
private String name;
orderStaus(String name) {
this.name = name;
}
public String getName() {
return name;

View File

@ -1,4 +1,5 @@
package com.geekq.miaosha.common;
/**
* Twitter_Snowflake<br>
* SnowFlake的结构如下(每部分用-分开):<br>
@ -14,52 +15,82 @@ package com.geekq.miaosha.common;
public class SnowflakeIdWorker {
// ==============================Fields===========================================
/** 开始时间截 (2015-01-01) */
/**
* 开始时间截 (2015-01-01)
*/
private final long twepoch = 1420041600000L;
/** 机器id所占的位数 */
/**
* 机器id所占的位数
*/
private final long workerIdBits = 5L;
/** 数据标识id所占的位数 */
/**
* 数据标识id所占的位数
*/
private final long datacenterIdBits = 5L;
/** 支持的最大机器id结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) */
/**
* 支持的最大机器id结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数)
*/
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
/** 支持的最大数据标识id结果是31 */
/**
* 支持的最大数据标识id结果是31
*/
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
/** 序列在id中占的位数 */
/**
* 序列在id中占的位数
*/
private final long sequenceBits = 12L;
/** 机器ID向左移12位 */
/**
* 机器ID向左移12位
*/
private final long workerIdShift = sequenceBits;
/** 数据标识id向左移17位(12+5) */
/**
* 数据标识id向左移17位(12+5)
*/
private final long datacenterIdShift = sequenceBits + workerIdBits;
/** 时间截向左移22位(5+5+12) */
/**
* 时间截向左移22位(5+5+12)
*/
private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
/** 生成序列的掩码这里为4095 (0b111111111111=0xfff=4095) */
/**
* 生成序列的掩码这里为4095 (0b111111111111=0xfff=4095)
*/
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
/** 工作机器ID(0~31) */
/**
* 工作机器ID(0~31)
*/
private long workerId;
/** 数据中心ID(0~31) */
/**
* 数据中心ID(0~31)
*/
private long datacenterId;
/** 毫秒内序列(0~4095) */
/**
* 毫秒内序列(0~4095)
*/
private long sequence = 0L;
/** 上次生成ID的时间截 */
/**
* 上次生成ID的时间截
*/
private long lastTimestamp = -1L;
//==============================Constructors=====================================
/**
* 构造函数
* @param workerId 工作ID (0~31)
*
* @param workerId 工作ID (0~31)
* @param datacenterId 数据中心ID (0~31)
*/
public SnowflakeIdWorker(long workerId, long datacenterId) {
@ -75,18 +106,33 @@ public class SnowflakeIdWorker {
/**
* 生成订单唯一ID
*
* @param workerId
* @param datacenterId
* @return
*/
public static long getOrderId(long workerId, long datacenterId){
public static long getOrderId(long workerId, long datacenterId) {
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
return idWorker.nextId();
}
// ==============================Methods==========================================
/**
* 测试
*/
public static void main(String[] args) {
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
for (int i = 0; i < 1000; i++) {
long id = idWorker.nextId();
System.out.println(Long.toBinaryString(id));
System.out.println(id);
}
}
/**
* 获得下一个ID (该方法是线程安全的)
*
* @return SnowflakeId
*/
public synchronized long nextId() {
@ -124,6 +170,7 @@ public class SnowflakeIdWorker {
/**
* 阻塞到下一个毫秒直到获得新的时间戳
*
* @param lastTimestamp 上次生成ID的时间截
* @return 当前时间戳
*/
@ -135,29 +182,16 @@ public class SnowflakeIdWorker {
return timestamp;
}
//==============================Test=============================================
/**
* 返回以毫秒为单位的当前时间
*
* @return 当前时间(毫秒)
*/
protected long timeGen() {
return System.currentTimeMillis();
}
//==============================Test=============================================
/** 测试 */
public static void main(String[] args) {
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
for (int i = 0; i < 1000; i++) {
long id = idWorker.nextId();
System.out.println(Long.toBinaryString(id));
System.out.println(id);
}
}
}

View File

@ -2,17 +2,18 @@ package com.geekq.miaosha.common.enums;
public class MessageStatus {
public static final Integer ZORE = 0;
public static final Integer ZORE = 0;
/**
* 消息类型
*/
public enum messageType {
public enum messageType {
maiosha_message("秒杀消息"),
buy_message("购买消息"),
system_message("系统消息");
private String message;
private messageType(String message){
private messageType(String message) {
this.message = message;
}
@ -24,10 +25,10 @@ public class MessageStatus {
/**
* 消息内容
*/
public enum ContentEnum {
system_message_register(7000,"尊敬的用户你好,你已经成功注册!"),
public enum ContentEnum {
system_message_register(7000, "尊敬的用户你好,你已经成功注册!"),
system_message_register_head(7001,"注册成功");
system_message_register_head(7001, "注册成功");
private int code;
private String message;
@ -45,10 +46,11 @@ public class MessageStatus {
return message;
}
}
/**
* 消息类型
*/
public enum sendType {
public enum sendType {
// maiosha_message("秒杀消息"),
// buy_message("购买消息"),
// system_message("系统消息");

View File

@ -8,6 +8,7 @@ package com.geekq.miaosha.common.enums;
* 4 秒杀错误
* 5 商品错误
* 6 订单错误
*
* @author qiurunze
*/
public enum ResultStatus {
@ -28,35 +29,35 @@ public enum ResultStatus {
/**
* 注册登录
*/
RESIGETR_SUCCESS(20000,"注册成功!"),
RESIGETER_FAIL(200001,"注册失败!"),
CODE_FAIL(200002,"验证码不一致!"),
RESIGETR_SUCCESS(20000, "注册成功!"),
RESIGETER_FAIL(200001, "注册失败!"),
CODE_FAIL(200002, "验证码不一致!"),
/**
* check
*/
BIND_ERROR (30001,"参数校验异常:%s"),
ACCESS_LIMIT_REACHED (30002,"请求非法!"),
REQUEST_ILLEGAL (30004,"访问太频繁!"),
SESSION_ERROR (30005,"Session不存在或者已经失效!"),
PASSWORD_EMPTY (30006,"登录密码不能为空!"),
MOBILE_EMPTY (30007,"手机号不能为空!"),
MOBILE_ERROR (30008,"手机号格式错误!"),
MOBILE_NOT_EXIST (30009,"手机号不存在!"),
PASSWORD_ERROR (30010,"密码错误!"),
USER_NOT_EXIST(30011,"用户不存在!"),
BIND_ERROR(30001, "参数校验异常:%s"),
ACCESS_LIMIT_REACHED(30002, "请求非法!"),
REQUEST_ILLEGAL(30004, "访问太频繁!"),
SESSION_ERROR(30005, "Session不存在或者已经失效!"),
PASSWORD_EMPTY(30006, "登录密码不能为空!"),
MOBILE_EMPTY(30007, "手机号不能为空!"),
MOBILE_ERROR(30008, "手机号格式错误!"),
MOBILE_NOT_EXIST(30009, "手机号不存在!"),
PASSWORD_ERROR(30010, "密码错误!"),
USER_NOT_EXIST(30011, "用户不存在!"),
/**
* 订单模块
*/
ORDER_NOT_EXIST(60001,"订单不存在"),
ORDER_NOT_EXIST(60001, "订单不存在"),
/**
* 秒杀模块
*/
MIAO_SHA_OVER(40001,"商品已经秒杀完毕"),
REPEATE_MIAOSHA(40002,"不能重复秒杀"),
MIAOSHA_FAIL(40003,"秒杀失败");
MIAO_SHA_OVER(40001, "商品已经秒杀完毕"),
REPEATE_MIAOSHA(40002, "不能重复秒杀"),
MIAOSHA_FAIL(40003, "秒杀失败");
/**
* 商品模块
@ -69,6 +70,10 @@ public enum ResultStatus {
this.message = message;
}
private ResultStatus(Object... args) {
this.message = String.format(this.message, args);
}
public int getCode() {
return this.code;
}
@ -96,8 +101,4 @@ public enum ResultStatus {
public String toString() {
return this.getName();
}
private ResultStatus(Object... args) {
this.message = String.format(this.message, args);
}
}

View File

@ -44,6 +44,7 @@ public class AbstractResult {
this.status = ResultStatus.SUCCESS;
return this;
}
public ResultStatus getStatus() {
return this.status;
}

View File

@ -12,11 +12,13 @@ public class ResultGeekQ<T> extends AbstractResult implements Serializable {
protected ResultGeekQ(ResultStatus status, String message) {
super(status, message);
}
protected ResultGeekQ(ResultStatus status) {
super(status);
}
public static <T> ResultGeekQ<T> build() {
return new ResultGeekQ(ResultStatus.SUCCESS, (String)null);
return new ResultGeekQ(ResultStatus.SUCCESS, (String) null);
}
public static <T> ResultGeekQ<T> build(String message) {

View File

@ -11,174 +11,209 @@ import javax.sql.DataSource;
import java.sql.SQLException;
@Configuration
@ConfigurationProperties(prefix="spring.datasource")
@ConfigurationProperties(prefix = "spring.datasource")
public class DruidConfig {
private String url;
private String username;
private String password;
private String driverClassName;
private String type;
private String filters;
private int maxActive;
private int initialSize;
private int minIdle;
private long maxWait;
private long timeBetweenEvictionRunsMillis;
private long minEvictableIdleTimeMillis;
private String validationQuery;
private boolean testWhileIdle;
private boolean testOnBorrow;
private boolean testOnReturn;
private boolean poolPreparedStatements;
private int maxOpenPreparedStatements;
@Bean
public ServletRegistrationBean druidSverlet() {
ServletRegistrationBean reg = new ServletRegistrationBean();
reg.setServlet(new StatViewServlet());
reg.addUrlMappings("/druid/*");
reg.addInitParameter("loginUsername", "joshua");
reg.addInitParameter("loginPassword", "123456");
reg.addInitParameter("logSlowSql", "true");
reg.addInitParameter("slowSqlMillis", "1000");
return reg;
}
@Bean
public DataSource druidDataSource() {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(url);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
datasource.setInitialSize(initialSize);
datasource.setMinIdle(minIdle);
datasource.setMaxActive(maxActive);
datasource.setMaxWait(maxWait);
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setValidationQuery(validationQuery);
datasource.setTestWhileIdle(testWhileIdle);
datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn);
datasource.setPoolPreparedStatements(poolPreparedStatements);
datasource.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
try {
datasource.setFilters(filters);
} catch (SQLException e) {
e.printStackTrace();
}
return datasource;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDriverClassName() {
return driverClassName;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getFilters() {
return filters;
}
public void setFilters(String filters) {
this.filters = filters;
}
public int getMaxActive() {
return maxActive;
}
public void setMaxActive(int maxActive) {
this.maxActive = maxActive;
}
public int getInitialSize() {
return initialSize;
}
public void setInitialSize(int initialSize) {
this.initialSize = initialSize;
}
public int getMinIdle() {
return minIdle;
}
public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}
public long getMaxWait() {
return maxWait;
}
public void setMaxWait(long maxWait) {
this.maxWait = maxWait;
}
public long getTimeBetweenEvictionRunsMillis() {
return timeBetweenEvictionRunsMillis;
}
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
}
public long getMinEvictableIdleTimeMillis() {
return minEvictableIdleTimeMillis;
}
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
}
public String getValidationQuery() {
return validationQuery;
}
public void setValidationQuery(String validationQuery) {
this.validationQuery = validationQuery;
}
public boolean isTestWhileIdle() {
return testWhileIdle;
}
public void setTestWhileIdle(boolean testWhileIdle) {
this.testWhileIdle = testWhileIdle;
}
public boolean isTestOnBorrow() {
return testOnBorrow;
}
public void setTestOnBorrow(boolean testOnBorrow) {
this.testOnBorrow = testOnBorrow;
}
public boolean isTestOnReturn() {
return testOnReturn;
}
public void setTestOnReturn(boolean testOnReturn) {
this.testOnReturn = testOnReturn;
}
public boolean isPoolPreparedStatements() {
return poolPreparedStatements;
}
public void setPoolPreparedStatements(boolean poolPreparedStatements) {
this.poolPreparedStatements = poolPreparedStatements;
}
public int getMaxOpenPreparedStatements() {
return maxOpenPreparedStatements;
}
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
this.maxOpenPreparedStatements = maxOpenPreparedStatements;
}
private String url;
private String username;
private String password;
private String driverClassName;
private String type;
private String filters;
private int maxActive;
private int initialSize;
private int minIdle;
private long maxWait;
private long timeBetweenEvictionRunsMillis;
private long minEvictableIdleTimeMillis;
private String validationQuery;
private boolean testWhileIdle;
private boolean testOnBorrow;
private boolean testOnReturn;
private boolean poolPreparedStatements;
private int maxOpenPreparedStatements;
@Bean
public ServletRegistrationBean druidSverlet() {
ServletRegistrationBean reg = new ServletRegistrationBean();
reg.setServlet(new StatViewServlet());
reg.addUrlMappings("/druid/*");
reg.addInitParameter("loginUsername", "joshua");
reg.addInitParameter("loginPassword", "123456");
reg.addInitParameter("logSlowSql", "true");
reg.addInitParameter("slowSqlMillis", "1000");
return reg;
}
@Bean
public DataSource druidDataSource() {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(url);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
datasource.setInitialSize(initialSize);
datasource.setMinIdle(minIdle);
datasource.setMaxActive(maxActive);
datasource.setMaxWait(maxWait);
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
datasource.setValidationQuery(validationQuery);
datasource.setTestWhileIdle(testWhileIdle);
datasource.setTestOnBorrow(testOnBorrow);
datasource.setTestOnReturn(testOnReturn);
datasource.setPoolPreparedStatements(poolPreparedStatements);
datasource.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
try {
datasource.setFilters(filters);
} catch (SQLException e) {
e.printStackTrace();
}
return datasource;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getDriverClassName() {
return driverClassName;
}
public void setDriverClassName(String driverClassName) {
this.driverClassName = driverClassName;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getFilters() {
return filters;
}
public void setFilters(String filters) {
this.filters = filters;
}
public int getMaxActive() {
return maxActive;
}
public void setMaxActive(int maxActive) {
this.maxActive = maxActive;
}
public int getInitialSize() {
return initialSize;
}
public void setInitialSize(int initialSize) {
this.initialSize = initialSize;
}
public int getMinIdle() {
return minIdle;
}
public void setMinIdle(int minIdle) {
this.minIdle = minIdle;
}
public long getMaxWait() {
return maxWait;
}
public void setMaxWait(long maxWait) {
this.maxWait = maxWait;
}
public long getTimeBetweenEvictionRunsMillis() {
return timeBetweenEvictionRunsMillis;
}
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
}
public long getMinEvictableIdleTimeMillis() {
return minEvictableIdleTimeMillis;
}
public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
}
public String getValidationQuery() {
return validationQuery;
}
public void setValidationQuery(String validationQuery) {
this.validationQuery = validationQuery;
}
public boolean isTestWhileIdle() {
return testWhileIdle;
}
public void setTestWhileIdle(boolean testWhileIdle) {
this.testWhileIdle = testWhileIdle;
}
public boolean isTestOnBorrow() {
return testOnBorrow;
}
public void setTestOnBorrow(boolean testOnBorrow) {
this.testOnBorrow = testOnBorrow;
}
public boolean isTestOnReturn() {
return testOnReturn;
}
public void setTestOnReturn(boolean testOnReturn) {
this.testOnReturn = testOnReturn;
}
public boolean isPoolPreparedStatements() {
return poolPreparedStatements;
}
public void setPoolPreparedStatements(boolean poolPreparedStatements) {
this.poolPreparedStatements = poolPreparedStatements;
}
public int getMaxOpenPreparedStatements() {
return maxOpenPreparedStatements;
}
public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) {
this.maxOpenPreparedStatements = maxOpenPreparedStatements;
}
}

View File

@ -16,10 +16,11 @@ public class UserArgumentResolver implements HandlerMethodArgumentResolver {
@Autowired
private MiaoShaUserService userService;
@Override
public boolean supportsParameter(MethodParameter methodParameter) {
Class<?> clazz = methodParameter.getParameterType() ;
return clazz == MiaoshaUser.class ;
Class<?> clazz = methodParameter.getParameterType();
return clazz == MiaoshaUser.class;
}
@Override

Some files were not shown because too many files have changed in this diff Show More