优化
This commit is contained in:
parent
d171bff036
commit
f3cc6ca645
@ -11,12 +11,11 @@ import com.xkrs.straw.model.qo.SysUserQo;
|
||||
import com.xkrs.straw.model.qo.SysUserReceiveSmsQo;
|
||||
import com.xkrs.straw.model.qo.SysUserRemarkQo;
|
||||
import com.xkrs.straw.model.qo.SysUserVipLevelQo;
|
||||
import com.xkrs.straw.model.vo.SysUserVo;
|
||||
import com.xkrs.straw.service.SysUserService;
|
||||
import com.xkrs.straw.utils.SysUserConvertUtils;
|
||||
import com.xkrs.straw.utils.VipTimeRangeUtils;
|
||||
import com.xkrs.utils.AliYunSmsUtils;
|
||||
import com.xkrs.utils.ListUtils;
|
||||
import com.xkrs.utils.RandomUtil;
|
||||
import com.xkrs.utils.TokenUtil;
|
||||
import com.xkrs.utils.*;
|
||||
import org.apache.hc.core5.util.TextUtils;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@ -80,7 +79,7 @@ public class SysUserController {
|
||||
SysUserEntity targetEntity = targetEntityOptional.get();
|
||||
if (!TextUtils.isEmpty(overTime)) {
|
||||
//获取LocalDateTime格式的过期时间
|
||||
LocalDateTime newLocalDateTime = VipTimeRangeUtils.convert(overTime);
|
||||
LocalDateTime newLocalDateTime = LocalDateTime.parse(overTime, DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
//生成新的VIP时间范围Json内容
|
||||
String newVipTimeRangeJson = VipTimeRangeUtils.obtainNewVipTimeRangeJson(targetEntity.getVipTimeRangeJson(), newLocalDateTime);
|
||||
//更新字段
|
||||
@ -262,10 +261,11 @@ public class SysUserController {
|
||||
return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
|
||||
}
|
||||
List<SysUserEntity> sysUserEntityList = sysUserService.selectAllUser();
|
||||
if (sysUserEntityList == null || sysUserEntityList.size() == 0) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有任何用户数据", locale);
|
||||
List<SysUserVo> sysUserVoList = new ArrayList<>();
|
||||
for (SysUserEntity sysUser : sysUserEntityList) {
|
||||
sysUserVoList.add(SysUserConvertUtils.convert(sysUser));
|
||||
}
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, sysUserEntityList, locale);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, sysUserVoList, locale);
|
||||
}
|
||||
|
||||
/**
|
||||
|
212
src/main/java/com/xkrs/straw/model/vo/SysUserVo.java
Normal file
212
src/main/java/com/xkrs/straw/model/vo/SysUserVo.java
Normal file
@ -0,0 +1,212 @@
|
||||
package com.xkrs.straw.model.vo;
|
||||
|
||||
public class SysUserVo {
|
||||
|
||||
/**
|
||||
* 指定主键,建立自增序列,主键值取自序列
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户真实姓名
|
||||
*/
|
||||
private String reallyName;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String telephone;
|
||||
|
||||
private String countyCode;
|
||||
|
||||
private String countyName;
|
||||
|
||||
/**
|
||||
* 0:正常用户
|
||||
* 1:被禁用的用户
|
||||
*/
|
||||
private Integer activeFlag;
|
||||
|
||||
private String addTime;
|
||||
|
||||
/**
|
||||
* 账号类别
|
||||
*/
|
||||
private String accountType;
|
||||
|
||||
/**
|
||||
* 登录次数
|
||||
*/
|
||||
private Integer loginNum;
|
||||
|
||||
/**
|
||||
* 用户最新登录时间
|
||||
*/
|
||||
private String loginLastTime;
|
||||
|
||||
/**
|
||||
* vip等级
|
||||
*/
|
||||
private Integer vipLevel;
|
||||
|
||||
/**
|
||||
* 是否接收短信
|
||||
*/
|
||||
private Integer receiveSms;
|
||||
|
||||
/**
|
||||
* 一共接收了多少条短信
|
||||
*/
|
||||
private Long receiveSmsCount;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private String overTime;
|
||||
|
||||
public SysUserVo() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getReallyName() {
|
||||
return reallyName;
|
||||
}
|
||||
|
||||
public void setReallyName(String reallyName) {
|
||||
this.reallyName = reallyName;
|
||||
}
|
||||
|
||||
public String getTelephone() {
|
||||
return telephone;
|
||||
}
|
||||
|
||||
public void setTelephone(String telephone) {
|
||||
this.telephone = telephone;
|
||||
}
|
||||
|
||||
public String getCountyCode() {
|
||||
return countyCode;
|
||||
}
|
||||
|
||||
public void setCountyCode(String countyCode) {
|
||||
this.countyCode = countyCode;
|
||||
}
|
||||
|
||||
public String getCountyName() {
|
||||
return countyName;
|
||||
}
|
||||
|
||||
public void setCountyName(String countyName) {
|
||||
this.countyName = countyName;
|
||||
}
|
||||
|
||||
public Integer getActiveFlag() {
|
||||
return activeFlag;
|
||||
}
|
||||
|
||||
public void setActiveFlag(Integer activeFlag) {
|
||||
this.activeFlag = activeFlag;
|
||||
}
|
||||
|
||||
public String getAddTime() {
|
||||
return addTime;
|
||||
}
|
||||
|
||||
public void setAddTime(String addTime) {
|
||||
this.addTime = addTime;
|
||||
}
|
||||
|
||||
public String getAccountType() {
|
||||
return accountType;
|
||||
}
|
||||
|
||||
public void setAccountType(String accountType) {
|
||||
this.accountType = accountType;
|
||||
}
|
||||
|
||||
public Integer getLoginNum() {
|
||||
return loginNum;
|
||||
}
|
||||
|
||||
public void setLoginNum(Integer loginNum) {
|
||||
this.loginNum = loginNum;
|
||||
}
|
||||
|
||||
public String getLoginLastTime() {
|
||||
return loginLastTime;
|
||||
}
|
||||
|
||||
public void setLoginLastTime(String loginLastTime) {
|
||||
this.loginLastTime = loginLastTime;
|
||||
}
|
||||
|
||||
public Integer getVipLevel() {
|
||||
return vipLevel;
|
||||
}
|
||||
|
||||
public void setVipLevel(Integer vipLevel) {
|
||||
this.vipLevel = vipLevel;
|
||||
}
|
||||
|
||||
public Integer getReceiveSms() {
|
||||
return receiveSms;
|
||||
}
|
||||
|
||||
public void setReceiveSms(Integer receiveSms) {
|
||||
this.receiveSms = receiveSms;
|
||||
}
|
||||
|
||||
public Long getReceiveSmsCount() {
|
||||
return receiveSmsCount;
|
||||
}
|
||||
|
||||
public void setReceiveSmsCount(Long receiveSmsCount) {
|
||||
this.receiveSmsCount = receiveSmsCount;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public String getOverTime() {
|
||||
return overTime;
|
||||
}
|
||||
|
||||
public void setOverTime(String overTime) {
|
||||
this.overTime = overTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysUserVo{" + "id=" + id + ", userName='" + userName + '\'' + ", reallyName='" + reallyName + '\'' + ", telephone='" + telephone + '\'' + ", countyCode='" + countyCode + '\'' + ", countyName='" + countyName + '\'' + ", activeFlag=" + activeFlag + ", addTime='" + addTime + '\'' + ", accountType='" + accountType + '\'' + ", loginNum=" + loginNum + ", loginLastTime='" + loginLastTime + '\'' + ", vipLevel=" + vipLevel + ", receiveSms=" + receiveSms + ", receiveSmsCount=" + receiveSmsCount + ", remark='" + remark + '\'' + ", overTime='" + overTime + '\'' + '}';
|
||||
}
|
||||
}
|
32
src/main/java/com/xkrs/straw/utils/SysUserConvertUtils.java
Normal file
32
src/main/java/com/xkrs/straw/utils/SysUserConvertUtils.java
Normal file
@ -0,0 +1,32 @@
|
||||
package com.xkrs.straw.utils;
|
||||
|
||||
import com.xkrs.straw.model.entity.SysUserEntity;
|
||||
import com.xkrs.straw.model.vo.SysUserVo;
|
||||
|
||||
public class SysUserConvertUtils {
|
||||
|
||||
private SysUserConvertUtils() {
|
||||
}
|
||||
|
||||
public static SysUserVo convert(SysUserEntity entity) {
|
||||
SysUserVo sysUserVo = new SysUserVo();
|
||||
sysUserVo.setId(entity.getId());
|
||||
sysUserVo.setUserName(entity.getUserName());
|
||||
sysUserVo.setReallyName(entity.getReallyName());
|
||||
sysUserVo.setTelephone(entity.getTelephone());
|
||||
sysUserVo.setCountyCode(entity.getCountyCode());
|
||||
sysUserVo.setCountyName(entity.getCountyName());
|
||||
sysUserVo.setActiveFlag(entity.getActiveFlag());
|
||||
sysUserVo.setAddTime(entity.getAddTime());
|
||||
sysUserVo.setAccountType(entity.getAccountType());
|
||||
sysUserVo.setLoginNum(entity.getLoginNum());
|
||||
sysUserVo.setLoginLastTime(entity.getLoginLastTime());
|
||||
sysUserVo.setVipLevel(entity.getVipLevel());
|
||||
sysUserVo.setReceiveSms(entity.getReceiveSms());
|
||||
sysUserVo.setReceiveSmsCount(entity.getReceiveSmsCount());
|
||||
sysUserVo.setRemark(entity.getRemark());
|
||||
sysUserVo.setOverTime(VipTimeRangeUtils.obtainLastOverTime(entity.getVipTimeRangeJson()));
|
||||
return sysUserVo;
|
||||
}
|
||||
|
||||
}
|
@ -99,6 +99,48 @@ public class VipTimeRangeUtils {
|
||||
return vipLocalDateTimeRangePairList;
|
||||
}
|
||||
|
||||
public static String obtainLastOverTime(String oldVipTimeRangeJson) {
|
||||
//oldVipTimeRangeJson不为空说明不是新注册用户,解析该用户的VIP时间范围
|
||||
VipTimeRangeBean vipTimeRangeBean = JsonUtils.deserialize(oldVipTimeRangeJson, VipTimeRangeBean.class);
|
||||
if (vipTimeRangeBean == null || vipTimeRangeBean.getList() == null || vipTimeRangeBean.getList().size() == 0) {
|
||||
throw new RuntimeException("已保存的VIP时间范围反序列化失败");
|
||||
}
|
||||
List<VipTimeRangeBean.VipTimeRangeItemBean> list = vipTimeRangeBean.getList();
|
||||
if (list == null || list.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
//校验数据合法性
|
||||
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemBeanA : list) {
|
||||
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemBeanB : list) {
|
||||
if (vipTimeRangeItemBeanA != vipTimeRangeItemBeanB) {
|
||||
LocalDateTime startLocalDateTimeA = LocalDateTime.parse(vipTimeRangeItemBeanA.getStartTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime endLocalDateTimeA = LocalDateTime.parse(vipTimeRangeItemBeanA.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime startLocalDateTimeB = LocalDateTime.parse(vipTimeRangeItemBeanB.getStartTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime endLocalDateTimeB = LocalDateTime.parse(vipTimeRangeItemBeanB.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
if (startLocalDateTimeB.isBefore(startLocalDateTimeA) && endLocalDateTimeB.isAfter(startLocalDateTimeA)) {
|
||||
throw new RuntimeException("VIP开始结束时间存在交叉现象1,系统数据错误");
|
||||
}
|
||||
if (startLocalDateTimeB.isBefore(endLocalDateTimeA) && endLocalDateTimeB.isAfter(endLocalDateTimeA)) {
|
||||
throw new RuntimeException("VIP开始结束时间存在交叉现象2,系统数据错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//获取结束时间最大的那个Pair
|
||||
VipTimeRangeBean.VipTimeRangeItemBean lastVipTimeRangeItemBean = list.get(0);
|
||||
for (VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemBean : list) {
|
||||
if (lastVipTimeRangeItemBean != vipTimeRangeItemBean) {
|
||||
LocalDateTime endLocalDateTime = LocalDateTime.parse(vipTimeRangeItemBean.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
LocalDateTime lastEndLocalDateTime = LocalDateTime.parse(lastVipTimeRangeItemBean.getEndTime(), DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
if (endLocalDateTime.isAfter(lastEndLocalDateTime)) {
|
||||
lastVipTimeRangeItemBean = vipTimeRangeItemBean;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lastVipTimeRangeItemBean.getEndTime();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成一个新的 VipTimeRangeJson
|
||||
*/
|
||||
@ -181,10 +223,6 @@ public class VipTimeRangeUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static LocalDateTime convert(String formattedTime) {
|
||||
return LocalDateTime.parse(formattedTime, DateTimeUtils.DATE_TIME_FORMATTER_1);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
VipTimeRangeBean.VipTimeRangeItemBean vipTimeRangeItemBean1 = new VipTimeRangeBean.VipTimeRangeItemBean();
|
||||
vipTimeRangeItemBean1.setStartTime("2022-06-27 11:15:00");
|
||||
|
Loading…
Reference in New Issue
Block a user