<select id="queryRegThreeDaysNotCharge" parameterType="map" resultMap="BaseResultMap">
SELECT id FROM member m
where m.register_time >= to_date(concat(to_char(sysdate-3,'yyyy-mm-dd'),' 11:00:00'),'yyyy-mm-dd hh24:mi:ss')
<![CDATA[
and m.register_time < to_date(concat(to_char(sysdate-2,'yyyy-mm-dd'),' 11:00:00'),'yyyy-mm-dd hh24:mi:ss')
]]>
and BITAND(m.flag_bit,${memberFlagBit}) = 0
</select>
<update id="addMemberFlagBit" parameterType="map">
update member set flag_bit = (flag_bit + ${flagBit}) - bitand(flag_bit, ${flagBit}) where id = #{memberId}
</update>
<update id="clearMemberFlagBit" parameterType="map">
update member set flag_bit = bitand(flag_bit, ${flagBit}) where id = #{memberId}
</update>
[img]http://dl2.iteye.com/upload/attachment/0101/9485/d83c6465-1682-3f38-b0de-910e6c640cc6.jpg[/img]
[quote][/quote]
package com.xxx.dao.domain;
public interface ExtensionFeatures {
String getFeatures();
void setFeatures(String features);
int getFeaturesVersion();
void setupFeature(String columnName, String value);
void setupFeature(String columnName, Object value);
void removeFeature(String columnName);
String getFeature(String columnName);
<T> T getFeature(String columnName, Class<T> clz);
}
package com.xxx.dao.domain;
public interface ExtensionFlagBit {
long getFlagBit();
/**
* flagBit的乐观锁字段,最好要有对应的数据表字段,要不代码/sql配置写得很麻烦。
*
* 假设flagVersion没有数据表字段,而是用flagBit的旧值作为乐观锁:
* DO中有flagVersion存放从数据库刚取出时的值,
* 那就要setFlagBit()后手动调用setFlageVersion(),在setFlagBit()里隐藏地调用setFlagVersion()是不好的
* 或着mybatis中resultMap要配置多一行将同字段内容放进两个setter中。
*
* 如果取单条要手动调用setFlagVersion(),在取出是列表时,要在manager中手动加个循环手动setFlagVersion()
*
* 即使在mybatis中resultMap配置了多一行将同字段内容放进两个setter中,因为都是用自身的值作乐观锁,
* 处理不了超高频率并发交替改变这个bit的情形。
* 彩票行业比一些行业在这里多了一个乐观锁字段,因为我们行业会在"跟单"这业务领域在同一记录上的并发比较常见。
*
*/
int getFlagVersion();
}
package com.xxx.dao.domain;
/**
* <ul>
* <li>某个设置如果不用于where条件,选用flagBit和feature都行</li>
* <li>如果用于where条件,选用flagBit,用于where条件时用bitand()/bitor()/bitxor()函数</li>
* <li>如果是值选取比较少,比如1~4,可以选用flagBit,或4个bit内的组合能比较对应</li>
* <li>如果值的范围可能比较扩充,可用json表达的features</li>
* </ul>
*
* @author zhoufeng
*
*/
public interface ExtensionField extends ExtensionFlagBit, ExtensionFeatures {
}
package com.xxxpiao.common.entity.member;
import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Transient;
import org.hibernate.annotations.Type;
import com.xxx.dao.domain.ExtensionField;
import com.xxx.dao.domain.HasLoadedAttach;
import com.xxx.dao.util.HasLoadedAttachUtil;
import com.xxx.member.common.constant.MemberHasLoadedAttachBit;
import com.xxxpiao.common.entity.BaseEntity;
import com.xxxpiao.common.entity.enumerated.BindBankType;
import com.xxxpiao.common.entity.enumerated.CertType;
import com.xxxpiao.common.entity.enumerated.MemberStatus;
import com.xxxpiao.common.entity.enumerated.SellClient;
import com.xxxpiao.common.entity.enumerated.Sex;
import com.xxxpiao.common.entity.enumerated.ThirdType;
import com.xxxpiao.common.service.vo.RegisterType;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializerFeature;
/**
* 网站客户
*
* @author yaya
*
*/
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true)
@SequenceGenerator(name = "SEQ_MEMBER", sequenceName = "SEQ_MEMBER", allocationSize = 1, initialValue = 1)
public class Member extends BaseEntity implements HasLoadedAttach, ExtensionField {
private static final long serialVersionUID = 6014921986862506261L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_MEMBER")
private Long id;
@Column(nullable = false, unique = true)
private String account;
/** 昵称(屏蔽手机号,默认跟帐户名相同) */
@Column(nullable = false)
private String nickname;
@Column(nullable = false)
private String password;
/** 联系电话 */
@Column(name = "phone")
private String phone;
/** 电邮地址 */
private String email;
/** 用户状态 (0-正常,1-关闭) */
@Enumerated
@Column(nullable = false)
private MemberStatus status = MemberStatus.ENABLE;
/** 注册时间 */
@Column(nullable = false)
private Calendar registerTime;
/** 来源客户端 */
@Enumerated
@Column(nullable = false)
private SellClient sellClient;
/** 市场渠道 */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "sell_channel", nullable = false)
private MemberMarketChannel sellChannel;
/** 证件类型 (0-身份证,1-军官证 ,2-护照) */
@Enumerated
private CertType certType;
/** 证件号码 */
private String certNo;
/** */
private Calendar lastLoginTime;
/** */
private String name;
/** */
private Calendar birthday;
/** 性别 (0-男,1-女) */
@Enumerated
private Sex sex;
/** 用户所在地区 */
private Long areaId;
/** IM */
private String im;
/** 提款银行ID */
private Long bankId;
/** 开户行全称 */
private String bankName;
/** 银行帐号 */
private String bankCardNo;
/** 消费级别 */
private int userLevel = 0;
/** 头衔 */
private String title;
/** 推荐人 */
private String recoMember;
/** 用户资料完整度(0-快速注册,1-完整注册) */
@Column(name = "INFO_FULL_STATUS")
private int infoFullStatus;
@Type(type = "thirdType")
private ThirdType thirdType = ThirdType.LOCAL;
/** 用户在第三方系统的标识,如在支付宝的标识,一般会在共享注册时设置 */
private String thirdId;
/** 用户是本站注册的,但通过第三方绑定登陆的,有这个信息*/
private MemberThirdLogin thirdLogin;
/** 注册类型,暂时不保存到数据库中 */
@Transient
private RegisterType registerType;
/** 用户绑定类型 */
@Type(type = "bindBankType")
private BindBankType bindBankType = BindBankType.NORMAL;
/** 用户绑定银行卡信息 **/
private String bindBankInfo;
/** 会员信息更新时间 */
private Calendar updateTime = Calendar.getInstance();
/** 用户提款手机号码绑定 */
private String getMoneyPhone;
/**
* 出生月日
*/
private String birthdayMmdd;
@Transient
private long attachBit;
private Long flagBit = 0L;
private Integer flagVersion = 0;
private JSONObject features = new JSONObject();
private Integer featuresVersion = 0;
public Member() {
}
public Member(Long id) {
this.id = id;
}
/**
* 快速注册用户构造方法
*
* @param account
* @param password
* @param sellClient
* @param sellChannel
*/
public Member(String account, String password, SellClient sellClient, MemberMarketChannel sellChannel) {
this.account = account;
this.nickname = account;
this.password = password;
this.registerTime = Calendar.getInstance();
this.sellClient = sellClient;
this.sellChannel = sellChannel;
}
public Member(String account, String password) {
this.account = account;
this.password = password;
}
@Override
public Long getId() {
return id;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public MemberStatus getStatus() {
return status;
}
public void setStatus(MemberStatus status) {
this.status = status;
}
public Calendar getRegisterTime() {
return registerTime;
}
public void setRegisterTime(Calendar registerTime) {
this.registerTime = registerTime;
}
public SellClient getSellClient() {
return sellClient;
}
public void setSellClient(SellClient sellClient) {
this.sellClient = sellClient;
}
public MemberMarketChannel getSellChannel() {
return sellChannel;
}
public void setSellChannel(MemberMarketChannel sellChannel) {
this.sellChannel = sellChannel;
addAttachFlag(MemberHasLoadedAttachBit.sellChannel);
}
public void setSellChannelId(Long sellChannel) {
this.sellChannel = new MemberMarketChannel(sellChannel);
removeAttachFlag(MemberHasLoadedAttachBit.sellChannel);
}
public CertType getCertType() {
return certType;
}
public void setCertType(CertType certType) {
this.certType = certType;
}
public String getCertNo() {
return certNo;
}
public void setCertNo(String certNo) {
this.certNo = certNo;
}
public Calendar getLastLoginTime() {
return lastLoginTime;
}
public void setLastLoginTime(Calendar lastLoginTime) {
this.lastLoginTime = lastLoginTime;
}
public String getName() {
return name;
}
public void setName(String name) {
if(name!=null){
this.name = name.trim();
}else{
this.name = null;
}
}
public Calendar getBirthday() {
return birthday;
}
public void setBirthday(Calendar birthday) {
this.birthday = birthday;
}
public Sex getSex() {
return sex;
}
public void setSex(Sex sex) {
this.sex = sex;
}
public Long getAreaId() {
return areaId;
}
public void setAreaId(Long areaId) {
this.areaId = areaId;
}
public String getIm() {
return im;
}
public void setIm(String im) {
this.im = im;
}
public Long getBankId() {
return bankId;
}
public void setBankId(Long bankId) {
this.bankId = bankId;
}
public String getBankName() {
return bankName;
}
public void setBankName(String bankName) {
this.bankName = bankName;
}
public String getBankCardNo() {
return bankCardNo;
}
public void setBankCardNo(String bankCardNo) {
this.bankCardNo = bankCardNo;
}
public int getUserLevel() {
return userLevel;
}
public void setUserLevel(int userLevel) {
this.userLevel = userLevel;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getRecoMember() {
return recoMember;
}
public void setRecoMember(String recoMember) {
this.recoMember = recoMember;
}
public int getInfoFullStatus() {
if(this.name!=null && this.name.length()>0 &&
this.phone!=null && this.phone.length()>0 &&
this.certNo!=null && this.certNo.length()>0){
return 1;//完善资料
}
return infoFullStatus;
}
public void setInfoFullStatus(int infoFullStatus) {
this.infoFullStatus = infoFullStatus;
}
public String getThirdId() {
return thirdId;
}
public void setThirdId(String thirdId) {
this.thirdId = thirdId;
}
public MemberThirdLogin getThirdLogin() {
return thirdLogin;
}
public void setThirdLogin(MemberThirdLogin thirdLogin) {
this.thirdLogin = thirdLogin;
this.addAttachFlag(MemberHasLoadedAttachBit.thirdLogin);
}
public void setId(Long id) {
this.id = id;
}
public ThirdType getThirdType() {
return thirdType;
}
public void setThirdType(ThirdType thirdType) {
this.thirdType = thirdType;
}
public RegisterType getRegisterType() {
return registerType;
}
public void setRegisterType(RegisterType registerType) {
this.registerType = registerType;
}
public BindBankType getBindBankType() {
return bindBankType;
}
public void setBindBankType(BindBankType bindBankType) {
this.bindBankType = bindBankType;
}
public String getBindBankInfo() {
return bindBankInfo;
}
public void setBindBankInfo(String bindBankInfo) {
this.bindBankInfo = bindBankInfo;
}
public Calendar getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Calendar updateTime) {
this.updateTime = updateTime;
}
public String getGetMoneyPhone() {
return getMoneyPhone;
}
public void setGetMoneyPhone(String getMoneyPhone) {
this.getMoneyPhone = getMoneyPhone;
}
@Override
public boolean hasAttachLoaded(long bitForPart) {
return HasLoadedAttachUtil.hasAttachLoaded(attachBit, bitForPart);
}
private void removeAttachFlag(long flagBit) {
this.attachBit &= flagBit ^ Long.MAX_VALUE;
}
private void addAttachFlag(long flagBit) {
this.attachBit |= flagBit;
}
@Override
public long getFlagBit() {
return this.flagBit == null ? 0 : flagBit;
}
@Override
public int getFlagVersion() {
return this.flagVersion == null ? 0 : flagVersion;
}
@Override
public String getFeatures() {
return JSON.toJSONString(features,SerializerFeature.UseISO8601DateFormat);
}
@Override
public int getFeaturesVersion() {
return this.featuresVersion == null ? 0 : featuresVersion;
}
@Override
public void setupFeature(String columnName, String value) {
features.put(columnName, value);
}
@Override
public void setupFeature(String columnName, Object value) {
features.put(columnName, value);
}
@Override
public void removeFeature(String columnName) {
features.remove(columnName);
}
@Override
public String getFeature(String columnName) {
return features.getString(columnName);
}
@Override
public <T> T getFeature(String columnName, Class<T> clz) {
return features.getObject(columnName, clz);
}
public void addFlagBit(Long flagBit) {
this.flagBit |= flagBit.longValue();
}
public void removeFlagBit(long flagBit) {
this.flagBit &= flagBit ^ Long.MAX_VALUE;
}
public void setFlagBit(Long flagBit) {
this.flagBit = flagBit == null ? 0 : flagBit;
}
public void setFeatures(String features) {
this.features = JSONObject.parseObject(features,Feature.AllowISO8601DateFormat);
}
public void setFlagVersion(Integer flagVersion) {
this.flagVersion = flagVersion == null ? 0 : flagVersion;
}
public void setFeaturesVersion(Integer featuresVersion) {
this.featuresVersion = featuresVersion == null ? 0 : featuresVersion;
}
public String getBirthdayMmdd() {
return birthdayMmdd;
}
public void setBirthdayMmdd(String birthdayMmdd) {
this.birthdayMmdd = birthdayMmdd;
}
}
[quote]http://blog.csdn.net/hengyunabc/article/details/34623957[/quote]