Commit 3399be45 authored by xiaoguang.xu's avatar xiaoguang.xu

非关键代码,使用 baseEntity 生成createdAt&updatedAt

parent 88f90166
......@@ -519,9 +519,6 @@ public class InnerController implements IBaseController {
Address addressObj = addressService.findByUserId(userId);
if (addressObj == null) {
addressObj = new Address();
Timestamp now = new Timestamp(System.currentTimeMillis());
addressObj.setCreatedAt(now);
addressObj.setUpdateAt(now);
}
addressObj.setUserId(userId);
addressObj.setProvince(province);
......@@ -546,13 +543,10 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("用户ID不能为空", null);
}
UserExtInfo info = userExtInfoService.findByUserId(userId);
Timestamp now = new Timestamp(System.currentTimeMillis());
if (info == null) {
info = new UserExtInfo();
info.setUserId(userId);
info.setCreatedAt(now);
}
info.setUpdateAt(now);
if (incomeEnum != null) {
info.setIncomeEnum(cn.quantgroup.user.enums.IncomeEnum.valueOf(incomeEnum.name()));
}
......@@ -946,12 +940,10 @@ public class InnerController implements IBaseController {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
if (userSpouse == null) {
userSpouse = new UserSpouse(userId);
userSpouse.setCreatedAt(timestamp);
}
userSpouse.setSpouseName(status == MaritalStatus.MARRIED ? spouseName : "");
userSpouse.setSpousePhone(status == MaritalStatus.MARRIED ? spousePhone : "");
userSpouse.setStatus(cn.quantgroup.user.enums.MaritalStatus.valueOf(status.name()));
userSpouse.setUpdateAt(timestamp);
userSpouse = userSpouseService.save(userSpouse);
return JsonResult.buildSuccessResult(null, UserSpouseRet.getUserSpouseRet(userSpouse));
}
......
......@@ -253,10 +253,8 @@ public class UserCenterController {
}
//查询用户是否有保存地址信息
Address addressInfo = addressService.findByUserId(userId);
Timestamp now = new Timestamp(System.currentTimeMillis());
if (null == addressInfo) {
addressInfo = new Address();
addressInfo.setCreatedAt(now);
}
addressInfo.setUserId(userId);
addressInfo.setProvince(province);
......@@ -266,7 +264,6 @@ public class UserCenterController {
addressInfo.setDistrictCode(districtCode);
addressInfo.setDistrict(district);
addressInfo.setAddress(address);
addressInfo.setUpdateAt(now);
addressService.save(addressInfo);
return JsonResult.buildSuccessResult(null, addressInfo);
}
......@@ -336,13 +333,10 @@ public class UserCenterController {
}
//查询用户是否保存过.
UserExtInfo userExtInfo = userExtInfoService.findByUserId(userId);
Timestamp now = new Timestamp(System.currentTimeMillis());
if (null == userExtInfo) {
userExtInfo = new UserExtInfo();
userExtInfo.setUserId(userId);
}
userExtInfo.setCreatedAt(now);
userExtInfo.setUpdateAt(now);
userExtInfo.setEducationEnum(educationEnum);
userExtInfo.setMarryStatus(maritalStatus);
userExtInfo.setOccupationEnum(occupationEnum);
......
......@@ -65,9 +65,6 @@ public class Step1Req implements Serializable {
public static ModifyPhoneNo adapt(Step1Req step1Req) {
ModifyPhoneNo modifyPhoneNo = new ModifyPhoneNo();
BeanUtils.copyProperties(step1Req, modifyPhoneNo);
Date date = new Date();
modifyPhoneNo.setCreatedAt(date);
modifyPhoneNo.setUpdatedAt(date);
return modifyPhoneNo ;
}
}
......@@ -13,14 +13,10 @@ import java.sql.Timestamp;
@Data
@Entity
@Table(name = "address", uniqueConstraints = @UniqueConstraint(columnNames = "user_id"))
public class Address implements Serializable {
public class Address extends BaseEntity implements Serializable {
private static final long serialVersionUID = -1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id")
private Long userId;
@Column(name = "province_code")
......@@ -37,15 +33,7 @@ public class Address implements Serializable {
private String district;
@Column(name = "address")
private String address;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updateAt;
@PreUpdate
public void preUpdate() {
this.updateAt = new Timestamp(System.currentTimeMillis());
}
public String toString() {
return province + "(省)" + city + "(市)" + district + "(区/县)" + address;
......
package cn.quantgroup.xyqb.entity;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* 所有数据库实体,都要继承 BaseEntity
* 1. 统一的 ID 设计。
* 2. 统一的创建和更新时间。
*/
@MappedSuperclass
@Data
public abstract class BaseEntity implements Serializable {
private static final long serialVersionUID = -1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
private Long id;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updatedAt;
@PrePersist
public void prePersist() {
Timestamp now = new Timestamp(System.currentTimeMillis());
this.createdAt = now;
this.updatedAt = now;
}
@PreUpdate
public void preUpdate() {
this.updatedAt = new Timestamp(System.currentTimeMillis());
}
}
......@@ -16,15 +16,9 @@ import java.util.Date;
@Data
@Entity
@Table(name = "user_modify_phone_no")
public class ModifyPhoneNo implements Serializable {
public class ModifyPhoneNo extends BaseEntity implements Serializable {
private static final long serialVersionUID = -7797532159380593454L;
/**
* id
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
/**
* user.id
......@@ -90,18 +84,4 @@ public class ModifyPhoneNo implements Serializable {
*/
@Column(name = "processing_status")
private Integer processingStatus;
/**
*
*/
@Column(name = "created_at")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createdAt;
/**
*
*/
@Column(name = "updated_at")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updatedAt;
}
......@@ -12,19 +12,11 @@ import java.sql.Timestamp;
@Data
@Entity
@Table(name = "user_attached")
public class UserAttached implements Serializable {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
public class UserAttached extends BaseEntity implements Serializable {
@Column(name = "user_id")
private Long userId;
@Column(name = "avatar")
private String avatar;
@Column(name = "nick")
private String nick;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updatedAt;
}
......@@ -14,13 +14,9 @@ import java.sql.Timestamp;
@Data
@Entity
@Table(name = "user_ext_info")
public class UserExtInfo implements Serializable {
public class UserExtInfo extends BaseEntity implements Serializable {
private static final long serialVersionUID = -1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "user_id")
private Long userId;
@Column(name = "means_of_income_payment")
......@@ -41,14 +37,10 @@ public class UserExtInfo implements Serializable {
private Boolean hasCreditCard = false;
@Column(name = "marry_status")
private MaritalStatus marryStatus = MaritalStatus.UNKNOWN;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updateAt;
public XUserExtInfo toXUserExtInfo() {
XUserExtInfo xUserExtInfo = new XUserExtInfo();
xUserExtInfo.setId(this.id);
xUserExtInfo.setId(getId());
xUserExtInfo.setUserId(this.userId);
xUserExtInfo.setEducationEnum(cn.quantgroup.motan.enums.EducationEnum.valueOf(this.educationEnum.name()));
xUserExtInfo.setIncomeEnum(cn.quantgroup.motan.enums.IncomeEnum.valueOf(this.incomeEnum.name()));
......@@ -58,8 +50,8 @@ public class UserExtInfo implements Serializable {
xUserExtInfo.setHasSocialSecurity(this.hasSocialSecurity);
xUserExtInfo.setHasCreditCard(this.hasCreditCard);
xUserExtInfo.setMarryStatus(cn.quantgroup.motan.enums.MaritalStatus.valueOf(this.marryStatus.name()));
xUserExtInfo.setCreatedAt(this.createdAt);
xUserExtInfo.setUpdateAt(this.updateAt);
xUserExtInfo.setCreatedAt(getCreatedAt());
xUserExtInfo.setUpdateAt(getUpdatedAt());
return xUserExtInfo;
}
}
......@@ -12,18 +12,13 @@ import java.sql.Timestamp;
@Entity
@Table(name = "user_hash_mapping")
@NoArgsConstructor
public class UserHashMapping implements Serializable {
public class UserHashMapping extends BaseEntity implements Serializable {
private static final long serialVersionUID = -1L;
public UserHashMapping(Long userId) {
this.userId = userId;
}
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id")
private Long userId;
......@@ -39,25 +34,6 @@ public class UserHashMapping implements Serializable {
@Column(name = "id_no_md5_short")
private Long idNoMd5Short;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updatedAt;
@PrePersist
public void prePersist() {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
createdAt = timestamp;
updatedAt = timestamp;
}
@PreUpdate
public void preUpdate() {
updatedAt = new Timestamp(System.currentTimeMillis());
}
public void setPhoneNoMd5(String phoneNoMd5) {
this.phoneNoMd5 = phoneNoMd5;
this.phoneNoMd5Short = HashUtil.crc32(phoneNoMd5);
......
......@@ -8,19 +8,12 @@ import java.sql.Timestamp;
@Data
@Entity
@Table(name = "user_hash_phone_no_id_no_mapping")
public class UserHashPhoneNoIdNoMapping {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
public class UserHashPhoneNoIdNoMapping extends BaseEntity {
@Column(name = "user_id")
private Long userId;
@Column(name = "phone_no_id_no_md5")
private String phoneNoIdNoMd5;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updatedAt;
public UserHashPhoneNoIdNoMapping() {
}
......@@ -28,16 +21,4 @@ public class UserHashPhoneNoIdNoMapping {
public UserHashPhoneNoIdNoMapping(Long userId) {
this.userId = userId;
}
@PrePersist
public void prePersist() {
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
createdAt = timestamp;
updatedAt = timestamp;
}
@PreUpdate
public void preUpdate() {
updatedAt = new Timestamp(System.currentTimeMillis());
}
}
......@@ -17,15 +17,10 @@ import java.sql.Timestamp;
@Getter
@Setter
@ToString
public class UserJr58 implements Serializable {
public class UserJr58 extends BaseEntity implements Serializable {
private static final long serialVersionUID = -1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id")
private Long userId;
......@@ -68,12 +63,6 @@ public class UserJr58 implements Serializable {
@Column(name = "app_id")
private String appId;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updatedAt;
@Column(name = "edu")
private String edu;
@Column(name = "income")
......
......@@ -16,13 +16,9 @@ import java.sql.Timestamp;
@Setter
@ToString
@NoArgsConstructor
public class UserSpouse implements Serializable {
public class UserSpouse extends BaseEntity implements Serializable {
private static final long serialVersionUID = -1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id")
private Long userId;
......@@ -33,12 +29,6 @@ public class UserSpouse implements Serializable {
@Column(name = "spouse_name")
private String spouseName;
@Column(name = "created_at")
private Timestamp createdAt;
@Column(name = "updated_at")
private Timestamp updateAt;
@Column(name = "status")
private MaritalStatus status;
......
......@@ -15,13 +15,9 @@ import java.sql.Timestamp;
@Entity
@Table(name = "wechat_userinfo")
@Data
public class WechatUserInfo implements Serializable {
public class WechatUserInfo extends BaseEntity implements Serializable {
private static final long serialVersionUID = -1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id")
private Long userId;
@Column(name = "open_id")
......@@ -42,10 +38,6 @@ public class WechatUserInfo implements Serializable {
private String country;
@Column(name = "head_img_url")
private String headImgUrl;
@Column(name = "created_at")
private Timestamp createdAt = new Timestamp(System.currentTimeMillis());
@Column(name = "updated_at")
private Timestamp updatedAt = new Timestamp(System.currentTimeMillis());
public WechatUserInfo convertEmoji() {
......
......@@ -30,9 +30,6 @@ public class AddressRegisteredEventListener implements ApplicationListener<Regis
}
User user = userRegisterParam.getUser();
address.setUserId(user.getId());
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
address.setCreatedAt(currentTime);
address.setUpdateAt(currentTime);
addressRepository.save(address);
}
}
......@@ -37,7 +37,7 @@ public class AddressRet {
ret.setCity(address.getCity());
ret.setAddress(address.getAddress());
ret.setCreatedAt(address.getCreatedAt().getTime());
ret.setUpdateAt(address.getUpdateAt().getTime());
ret.setUpdateAt(address.getUpdatedAt().getTime());
return ret;
}
}
......@@ -46,7 +46,7 @@ public class UserExtInfoRet {
ret.setHasCreditCard(defaultBoolean(extInfo.getHasCreditCard()));
ret.setMarryStatus(extInfo.getMarryStatus());
ret.setCreatedAt(extInfo.getCreatedAt().getTime());
ret.setUpdateAt(extInfo.getUpdateAt().getTime());
ret.setUpdateAt(extInfo.getUpdatedAt().getTime());
return ret;
}
}
......@@ -30,8 +30,8 @@ public class UserSpouseRet {
ret.setUserId(userSpouse.getUserId());
ret.setSpouseName(userSpouse.getSpouseName());
ret.setSpousePhone(userSpouse.getSpousePhone());
if (userSpouse.getUpdateAt() != null) {
ret.setUpdateAt(userSpouse.getUpdateAt().getTime());
if (userSpouse.getUpdatedAt() != null) {
ret.setUpdateAt(userSpouse.getUpdatedAt().getTime());
}
if (userSpouse.getCreatedAt() != null) {
ret.setCreatedAt(userSpouse.getCreatedAt().getTime());
......
......@@ -191,7 +191,6 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
throw new DataException("数据不存在。");
}
modifyPhoneNo.setProcessingStatus(ModifyPhoneNoProcessingStatusEnum.DONE.ordinal());
modifyPhoneNo.setUpdatedAt(new Date());
}
@Override
......@@ -205,7 +204,6 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
modifyPhoneNo.setApplyStatus(ModifyPhoneNoApplyStatusEnum.NO_ALLOW.ordinal());
modifyPhoneNo.setApplyStatusReason(auditReq.getApplyStatusReason());
modifyPhoneNo.setProcessingStatus(ModifyPhoneNoProcessingStatusEnum.WAIT_4_USER_FEEDBACK.ordinal());
modifyPhoneNo.setUpdatedAt(new Date());
}
if (ModifyPhoneNoApplyStatusEnum.DONE == auditReq.getApplyStatus()) {
log.info("audit userId = 【{}】, name = 【{}】, idCard = 【{}】, prevPhoneNo = 【{}】, " +
......@@ -220,7 +218,6 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
userService.modifyPhoneNo(modifyPhoneNo.getPrevPhoneNo(), modifyPhoneNo.getCurPhoneNo());
modifyPhoneNo.setApplyStatus(ModifyPhoneNoApplyStatusEnum.DONE.ordinal());
modifyPhoneNo.setProcessingStatus(ModifyPhoneNoProcessingStatusEnum.WAIT_4_USER_FEEDBACK.ordinal());
modifyPhoneNo.setUpdatedAt(new Date());
}
}
......
......@@ -41,7 +41,6 @@ public class UserCenterServiceImpl implements UserCenterService {
}
if(!Objects.equals(avatar, userAttached.getAvatar())){
userAttached.setAvatar(avatar);
userAttached.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
userAttached = userAttachedRepository.save(userAttached);
}
return userAttached;
......@@ -58,7 +57,6 @@ public class UserCenterServiceImpl implements UserCenterService {
}
if(!Objects.equals(nick, userAttached.getNick())){
userAttached.setNick(nick);
userAttached.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
try {
userAttached = userAttachedRepository.save(userAttached);
}catch (ConstraintViolationException e){
......@@ -81,7 +79,6 @@ public class UserCenterServiceImpl implements UserCenterService {
UserAttached userAttached = userAttachedRepository.findByUserId(userId);
// 更新实例
userAttached = Optional.ofNullable(userAttached).orElse(new UserAttached());
Timestamp now = new Timestamp(System.currentTimeMillis());
userAttached.setUserId(userId);
if(StringUtils.isBlank(userAttached.getAvatar())){
userAttached.setAvatar(avatar);
......@@ -89,10 +86,6 @@ public class UserCenterServiceImpl implements UserCenterService {
if(StringUtils.isBlank(userAttached.getNick())){
userAttached.setNick(nick);
}
if(Objects.isNull(userAttached.getCreatedAt())){
userAttached.setCreatedAt(now);
}
userAttached.setUpdatedAt(now);
return userAttachedRepository.save(userAttached);
}
}
......@@ -84,7 +84,6 @@ public class UserDetailVO {
xUserDetail.setUpdatedAt(new Timestamp(this.getUpdatedAt()));
}
xUserDetail.setIsAuthenticated(this.getIsAuthenticated());
xUserDetail.setEnable(this.getEnable());
return xUserDetail;
......
......@@ -66,9 +66,6 @@ public class UserServiceTest {
addressObj.setProvince("悉尼");
addressObj.setProvinceCode(1L);
addressObj.setAddress("嘻哈");
Timestamp timestamp=Timestamp.valueOf( LocalDateTime.now());
addressObj.setCreatedAt(timestamp);
addressObj.setUpdateAt(timestamp);
return Arrays.asList(new Object[][]{{addressObj}});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment