admin
2019-02-19 9192375a211cff2f91d1f65f932f97612d8dbcdb
系统框架整改
2个文件已删除
4 文件已重命名
6个文件已修改
74个文件已添加
8707 ■■■■■ 已修改文件
.settings/org.eclipse.core.resources.prefs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.settings/org.eclipse.jdt.core.prefs 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.settings/org.eclipse.m2e.core.prefs 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.settings/org.eclipse.wst.common.project.facet.core.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/entity/msg/SystemZnx.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/entity/msg/UserMsgUnReadNum.java 123 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/entity/msg/UserSystemMsg.java 140 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/entity/msg/UserSystemMsgTypeEnum.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/exception/msg/UserSystemMsgException.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/service/msg/SystemZnxService.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/service/msg/UserMsgReadStateService.java 102 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-system/src/main/java/org/fanli/facade/system/service/msg/UserSystemMsgService.java 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/dto/account/LoginResult.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/dto/wx/WeiXinUser.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/dto/wx/WeiXinUserParam.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/account/msg/MsgAccountDetail.java 121 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/account/msg/UserAccountMsgNotificationService.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/InviteGetMoney.java 116 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/SpreadImg.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/SpreadUserImg.java 92 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/ThreeSale.java 146 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/ThreeSaleExtraInfo.java 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/msg/MsgInviteDetail.java 123 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/taobao/UserExtraTaoBaoInfo.java 133 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/exception/account/msg/MsgAccountDetailException.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/exception/invite/ThreeSaleException.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/exception/invite/msg/MsgInviteDetailException.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/service/account/UserAccountService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/service/account/UserInfoService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/service/account/msg/MsgAccountDetailService.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/service/invite/QrCodeService.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/service/invite/SpreadUserImgService.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/service/invite/ThreeSaleSerivce.java 256 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/service/invite/msg/MsgInviteDetailService.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/service/invite/msg/UserInviteMsgNotificationService.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/service/taobao/UserExtraTaoBaoInfoService.java 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/util/InviteImageUtil.java 432 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/util/factory/MsgAccountDetailFactory.java 145 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/util/factory/MsgInviteDetailFactory.java 89 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/util/typehandler/MsgTypeAccountTypeEnumHandler.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/util/typehandler/MsgTypeInviteTypeEnumHandler.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/main/java/org/fanli/facade/user/util/wx/WXLoginUtil.java 170 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-facade-user/src/test/java/org/fanli/facade/user/AppTest.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-goods/src/main/java/com/yeshi/fanli/goods/service/impl/recommend/DynamicRecommendServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-goods/src/main/java/com/yeshi/fanli/goods/service/impl/recommend/RecommendDetailsServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-goods/src/main/java/com/yeshi/fanli/goods/service/impl/recommend/RecommendReplyServiceImpl.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-goods/src/main/java/com/yeshi/fanli/goods/service/impl/usergoods/ShareGoodsServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-goods/src/main/java/com/yeshi/fanli/goods/service/impl/usergoods/UserShareGoodsRecordServiceImpl.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-order/src/main/webapp/WEB-INF/web.xml 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/dao/msg/SystemZnxMapper.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/dao/msg/UserMsgUnReadNumMapper.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/dao/msg/UserSystemMsgMapper.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/msg/SystemZnxMapper.xml 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/msg/UserMsgUnReadNumMapper.xml 109 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/msg/UserSystemMsgMapper.xml 150 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/service/impl/msg/SystemZnxServiceImpl.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/service/impl/msg/UserMsgReadStateServiceImpl.java 169 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/service/impl/msg/UserSystemMsgServiceImpl.java 131 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-system/src/main/java/com/yeshi/fanli/system/utils/typehandler/UserSystemMsgTypeEnumHandler.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/pom.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/App.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/dao/account/UserInfoMapper.java 168 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/dao/account/msg/MsgAccountDetailMapper.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/dao/invite/SpreadImgMapper.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/dao/invite/SpreadUserImgMapper.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/dao/invite/ThreeSaleExtraInfoMapper.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/dao/invite/ThreeSaleMapper.java 251 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/dao/invite/msg/MsgInviteDetailMapper.java 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/dao/taobao/UserExtraTaoBaoInfoMapper.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/mapper/account/UserInfoMapper.xml 522 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/mapper/account/msg/MsgAccountDetailMapper.xml 117 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/mapper/invite/SpreadImgMapper.xml 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/mapper/invite/SpreadUserImgMapper.xml 89 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/mapper/invite/ThreeSaleExtraInfoMapper.xml 98 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/mapper/invite/ThreeSaleMapper.xml 513 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/mapper/invite/msg/MsgInviteDetailMapper.xml 159 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/mapper/taobao/UserExtraTaoBaoInfoMapper.xml 172 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/UserAccountServiceImpl.java 880 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/account/msg/MsgAccountDetailServiceImpl.java 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/account/msg/UserAccountMsgNotificationServiceImpl.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/invite/QrCodeServiceImpl.java 124 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/invite/SpreadUserImgServiceImpl.java 237 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/invite/ThreeSaleSerivceImpl.java 558 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/invite/msg/MsgInviteDetailServiceImpl.java 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/invite/msg/UserInviteMsgNotificationServiceImpl.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/taobao/UserExtraTaoBaoInfoServiceImpl.java 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.settings/org.eclipse.core.resources.prefs
New file
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
.settings/org.eclipse.jdt.core.prefs
New file
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
.settings/org.eclipse.m2e.core.prefs
New file
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
.settings/org.eclipse.wst.common.project.facet.core.xml
New file
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <installed facet="java" version="1.8"/>
</faceted-project>
fanli-facade-system/src/main/java/org/fanli/facade/system/entity/msg/SystemZnx.java
File was renamed from fanli-facade-system/src/main/java/org/fanli/facade/system/entity/common/SystemZnx.java
@@ -1,4 +1,4 @@
package org.fanli.facade.system.entity.common;
package org.fanli.facade.system.entity.msg;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -9,26 +9,31 @@
@Entity
@Table(name = "yeshi_ec_system_msg")
@org.yeshi.utils.mybatis.Table("yeshi_ec_system_msg")
public class SystemZnx {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private long id;
    @org.yeshi.utils.mybatis.Column(name="id")
    private Long id;
    
    @Column(name = "`title`", length = 128)
    @org.yeshi.utils.mybatis.Column(name="title")
    private String title;
    
    @Column(name = "`content`", length = 128)
    @org.yeshi.utils.mybatis.Column(name="content")
    private String content;
    
    @Column(name = "`createTime`", length = 128)
    private long createTime;
    @org.yeshi.utils.mybatis.Column(name="createTime")
    private Long createTime;
    public long getId() {
    public Long getId() {
        return id;
    }
    public void setId(long id) {
    public void setId(Long id) {
        this.id = id;
    }
@@ -48,11 +53,11 @@
        this.content = content;
    }
    public long getCreateTime() {
    public Long getCreateTime() {
        return createTime;
    }
    public void setCreateTime(long createTime) {
    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }
fanli-facade-system/src/main/java/org/fanli/facade/system/entity/msg/UserMsgUnReadNum.java
New file
@@ -0,0 +1,123 @@
package org.fanli.facade.system.entity.msg;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
import com.google.gson.annotations.Expose;
import com.yeshi.fanli.base.entity.user.UserInfo;
/*
 * 用户消息已读状态存储
 */
@Table("yeshi_ec_msg_read_state")
public class UserMsgUnReadNum {
    @Column(name = "mrs_id")
    private Long id;
    @Column(name = "mrs_uid")
    private UserInfo user;
    @Expose
    @Column(name = "mrs_type_order")
    private Integer typeOrder;// 订单消息未读数
    @Expose
    @Column(name = "mrs_type_money")
    private Integer typeMoney;// 资金消息未读数
    @Expose
    @Column(name = "mrs_type_account")
    private Integer typeAccount;// 账户消息未读数
    @Expose
    @Column(name = "mrs_type_invite")
    private Integer typeInvite;// 邀请消息未读数
    @Expose
    @Column(name = "mrs_type_score")
    private Integer typeScore;// 积分消息未读数
    @Expose
    @Column(name = "mrs_type_system")
    private Integer typeSystem;// 系统消息未读数
    @Column(name = "mrs_create_time")
    private Date createTime;
    @Column(name = "mrs_update_time")
    private Date updateTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Integer getTypeOrder() {
        return typeOrder;
    }
    public void setTypeOrder(Integer typeOrder) {
        this.typeOrder = typeOrder;
    }
    public Integer getTypeMoney() {
        return typeMoney;
    }
    public void setTypeMoney(Integer typeMoney) {
        this.typeMoney = typeMoney;
    }
    public Integer getTypeSystem() {
        return typeSystem;
    }
    public void setTypeSystem(Integer typeSystem) {
        this.typeSystem = typeSystem;
    }
    public Integer getTypeAccount() {
        return typeAccount;
    }
    public void setTypeAccount(Integer typeAccount) {
        this.typeAccount = typeAccount;
    }
    public Integer getTypeInvite() {
        return typeInvite;
    }
    public void setTypeInvite(Integer typeInvite) {
        this.typeInvite = typeInvite;
    }
    public Integer getTypeScore() {
        return typeScore;
    }
    public void setTypeScore(Integer typeScore) {
        this.typeScore = typeScore;
    }
    public UserInfo getUser() {
        return user;
    }
    public void setUser(UserInfo user) {
        this.user = user;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
fanli-facade-system/src/main/java/org/fanli/facade/system/entity/msg/UserSystemMsg.java
New file
@@ -0,0 +1,140 @@
package org.fanli.facade.system.entity.msg;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
import com.google.gson.annotations.Expose;
import com.yeshi.fanli.base.entity.user.UserInfo;
/**
 * 用户系统消息
 *
 * @author Administrator
 *
 */
@Table("yeshi_ec_msg_system")
public class UserSystemMsg {
    public final static int TIME_TAG_COMMON = 0;// 普通
    public final static int TIME_TAG_EMERGENT = 1;// 紧急
    @Expose
    @Column(name = "ms_id")
    private Long id;
    @Column(name = "ms_uid")
    private UserInfo user;
    @Expose
    @Column(name = "ms_type")
    private UserSystemMsgTypeEnum type;// 消息类型
    @Column(name = "ms_system_znx_id")
    private SystemZnx systemZNX;// 系统统一广播的站内信,当有系统站内信时,标题内容等为空
    @Column(name = "ms_read")
    @Expose
    private Boolean read;// 是否已读
    @Expose
    @Column(name = "ms_solved")
    private Boolean solved;// 是否已经解决
    @Column(name = "ms_title")
    @Expose
    private String title;// 标题
    @Column(name = "ms_content")
    @Expose
    private String content;// 内容
    @Column(name = "ms_time_tag")
    @Expose
    private Integer timeTag;// 时间标识:1-紧急 0-普通
    @Expose
    @Column(name = "ms_create_time")
    private Date createTime;
    @Column(name = "ms_update_time")
    private Date updateTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public UserInfo getUser() {
        return user;
    }
    public void setUser(UserInfo user) {
        this.user = user;
    }
    public UserSystemMsgTypeEnum getType() {
        return type;
    }
    public void setType(UserSystemMsgTypeEnum type) {
        this.type = type;
    }
    public SystemZnx getSystemZNX() {
        return systemZNX;
    }
    public void setSystemZNX(SystemZnx systemZNX) {
        this.systemZNX = systemZNX;
    }
    public Boolean getRead() {
        return read;
    }
    public void setRead(Boolean read) {
        this.read = read;
    }
    public Boolean getSolved() {
        return solved;
    }
    public void setSolved(Boolean solved) {
        this.solved = solved;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public Integer getTimeTag() {
        return timeTag;
    }
    public void setTimeTag(Integer timeTag) {
        this.timeTag = timeTag;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
fanli-facade-system/src/main/java/org/fanli/facade/system/entity/msg/UserSystemMsgTypeEnum.java
New file
@@ -0,0 +1,22 @@
package org.fanli.facade.system.entity.msg;
/**
 * 用户系统消息的类型
 *
 * @author Administrator
 *
 */
public enum UserSystemMsgTypeEnum {
    // 普通消息-只是通知用户,不需要用户反馈
    // 问题消息-用户的账户有问题出现,需要用户协助解决的
    common("普通消息"), question("问题消息");
    private final String desc;
    private UserSystemMsgTypeEnum(String desc) {
        this.desc = desc;
    }
    public String getDesc() {
        return desc;
    }
}
fanli-facade-system/src/main/java/org/fanli/facade/system/exception/msg/UserSystemMsgException.java
New file
@@ -0,0 +1,32 @@
package org.fanli.facade.system.exception.msg;
public class UserSystemMsgException extends Exception {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    public int getCode() {
        return code;
    }
    public String getMsg() {
        return msg;
    }
    public UserSystemMsgException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public UserSystemMsgException() {
    }
    @Override
    public String getMessage() {
        return this.msg;
    }
}
fanli-facade-system/src/main/java/org/fanli/facade/system/service/msg/SystemZnxService.java
New file
@@ -0,0 +1,26 @@
package org.fanli.facade.system.service.msg;
import java.util.List;
import org.fanli.facade.system.entity.msg.SystemZnx;
public interface SystemZnxService {
    /**
     *
     * 方法说明:插入到system表
     *
     * @author mawurui createTime 2018年3月13日 上午9:24:43
     * @param systemZnx
     */
    public void save(SystemZnx systemZnx);
    /**
     * 根据最小时间查询
     *
     * @param createTime
     * @return
     */
    public List<SystemZnx> listByMinCreateTime(long createTime);
}
fanli-facade-system/src/main/java/org/fanli/facade/system/service/msg/UserMsgReadStateService.java
New file
@@ -0,0 +1,102 @@
package org.fanli.facade.system.service.msg;
import org.fanli.facade.system.entity.msg.UserMsgUnReadNum;
/**
 * 消息未读服务
 *
 * @author Administrator
 *
 */
public interface UserMsgReadStateService {
    /**
     * 增加订单消息未读数
     *
     * @param uid
     * @param count
     */
    public void addOrderMsgUnReadCount(Long uid, int count);
    /**
     * 增加账号消息未读数
     *
     * @param uid
     * @param count
     */
    public void addAccountMsgUnReadCount(Long uid, int count);
    /**
     * 增加资金消息未读数
     *
     * @param uid
     * @param count
     */
    public void addMoneyMsgUnReadCount(Long uid, int count);
    /**
     * 增加邀请消息未读数
     *
     * @param uid
     * @param count
     */
    public void addInviteMsgUnReadCount(Long uid, int count);
    /**
     * 增加系统消息未读数
     *
     * @param uid
     * @param count
     */
    public void addSystemMsgUnReadCount(Long uid, int count);
    /**
     * 获取用户所有未读消息数
     *
     * @param uid
     * @return
     */
    public UserMsgUnReadNum getReadStateByUid(Long uid);
    /**
     * 设置所有消息已读
     *
     * @param uid
     */
    public void setAllMsgRead(Long uid);
    /**
     * 读订单消息
     *
     * @param uid
     */
    public void readOrderMsg(Long uid);
    /**
     * 读账号消息
     *
     * @param uid
     */
    public void readAccountMsg(Long uid);
    /**
     * 读资金消息
     *
     * @param uid
     */
    public void readMoneyMsg(Long uid);
    /**
     * 读邀请消息
     *
     * @param uid
     */
    public void readInviteMsg(Long uid);
    /**
     * 读系统消息
     *
     * @param uid
     */
    public void readUserSystemMsg(Long uid);
}
fanli-facade-system/src/main/java/org/fanli/facade/system/service/msg/UserSystemMsgService.java
New file
@@ -0,0 +1,82 @@
package org.fanli.facade.system.service.msg;
import java.util.List;
import org.fanli.facade.system.entity.msg.SystemZnx;
import org.fanli.facade.system.entity.msg.UserSystemMsg;
import org.fanli.facade.system.entity.msg.UserSystemMsgTypeEnum;
import org.fanli.facade.system.exception.msg.UserSystemMsgException;
import com.yeshi.fanli.base.entity.user.UserInfo;
/**
 * 用户系统消息
 *
 * @author Administrator
 *
 */
public interface UserSystemMsgService {
    /**
     * 添加系统消息
     *
     * @param uid
     * @param title
     * @param content
     * @param timeLevel
     *            -是否紧急
     * @param sz
     *            -站内信对应表
     */
    public void addUserSystemMsg(Long uid, UserSystemMsgTypeEnum type, String title, String content, int timeTag,
            SystemZnx sz) throws UserSystemMsgException;
    /**
     * 同步系统站内信
     *
     * @param uid
     */
    public void syncSystemZNX(UserInfo user);
    /**
     * 获取最近一次的系统消息
     *
     * @param uid
     * @return
     */
    public UserSystemMsg getLatestUserSystemMsg(Long uid);
    /**
     * 用户系统消息列表
     *
     * @param uid
     * @param page
     * @param pageSize
     * @return
     */
    public List<UserSystemMsg> listUserSystemMsg(Long uid, int page, int pageSize);
    /**
     * 用户系统消息数
     *
     * @param uid
     * @return
     */
    public long countUserSystemMsg(Long uid);
    /**
     * 设置系统消息解决了
     *
     * @param uid
     * @param id
     * @throws UserSystemMsgException
     */
    public void setSystemMsgSolved(Long uid, Long id) throws UserSystemMsgException;
    /**
     * 设置所有消息已读
     *
     * @param uid
     */
    public void readMsgByUid(Long uid);
}
fanli-facade-user/src/main/java/org/fanli/facade/user/dto/account/LoginResult.java
File was renamed from fanli-facade-user/src/main/java/org/fanli/facade/user/dto/LoginResult.java
@@ -1,4 +1,4 @@
package org.fanli.facade.user.dto;
package org.fanli.facade.user.dto.account;
import com.yeshi.fanli.base.entity.user.UserInfo;
fanli-facade-user/src/main/java/org/fanli/facade/user/dto/wx/WeiXinUser.java
New file
@@ -0,0 +1,65 @@
package org.fanli.facade.user.dto.wx;
//微信用户解析
public class WeiXinUser {
    private String nickname;
    private int sex;
    private String province;
    private String city;
    private String country;
    private String headimgurl;
    private String openid;
    private String unionid;
    public String getNickname() {
        return nickname;
    }
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }
    public int getSex() {
        return sex;
    }
    public void setSex(int sex) {
        this.sex = sex;
    }
    public String getProvince() {
        return province;
    }
    public void setProvince(String province) {
        this.province = province;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getCountry() {
        return country;
    }
    public void setCountry(String country) {
        this.country = country;
    }
    public String getHeadimgurl() {
        return headimgurl;
    }
    public void setHeadimgurl(String headimgurl) {
        this.headimgurl = headimgurl;
    }
    public String getOpenid() {
        return openid;
    }
    public void setOpenid(String openid) {
        this.openid = openid;
    }
    public String getUnionid() {
        return unionid;
    }
    public void setUnionid(String unionid) {
        this.unionid = unionid;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/dto/wx/WeiXinUserParam.java
New file
@@ -0,0 +1,60 @@
package org.fanli.facade.user.dto.wx;
public class WeiXinUserParam {
    private String accessToken;
    private String refreshToken;
    private String openId;
    private String unionId;
    private String scope;
    private Integer expires;
    public String getAccessToken() {
        return accessToken;
    }
    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }
    public String getRefreshToken() {
        return refreshToken;
    }
    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }
    public String getOpenId() {
        return openId;
    }
    public void setOpenId(String openId) {
        this.openId = openId;
    }
    public String getScope() {
        return scope;
    }
    public void setScope(String scope) {
        this.scope = scope;
    }
    public Integer getExpires() {
        return expires;
    }
    public void setExpires(Integer expires) {
        this.expires = expires;
    }
    public String getUnionId() {
        return unionId;
    }
    public void setUnionId(String unionId) {
        this.unionId = unionId;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/account/msg/MsgAccountDetail.java
New file
@@ -0,0 +1,121 @@
package org.fanli.facade.user.entity.account.msg;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
import com.yeshi.fanli.base.entity.user.UserInfo;
/**
 * 账号
 *
 * @author Administrator
 *
 */
@Table("yeshi_ec_msg_account")
public class MsgAccountDetail {
    public enum MsgTypeAccountTypeEnum {
        bingding("账号绑定"), cancelBinding("取消绑定"), bingdingChange("绑定更换"), update("账号修改"), level("账号等级"), connect("账号合并");
        private final String desc;
        private MsgTypeAccountTypeEnum(String desc) {
            this.desc = desc;
        }
        public String getDesc() {
            return desc;
        }
    }
    @Column(name = "ma_id")
    private Long id;
    @Column(name = "ma_uid")
    private UserInfo user;
    @Column(name = "ma_type")
    private MsgTypeAccountTypeEnum type;// 类型
    @Column(name = "ma_title")
    private String title;// 事项
    @Column(name = "ma_content")
    private String content;// 状态
    @Column(name = "ma_beizhu")
    private String beiZhu;// 备注
    @Column(name = "ma_read")
    private Boolean read;
    @Column(name = "ma_create_time")
    private Date createTime;
    @Column(name = "ma_update_time")
    private Date updateTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public Boolean getRead() {
        return read;
    }
    public void setRead(Boolean read) {
        this.read = read;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public UserInfo getUser() {
        return user;
    }
    public void setUser(UserInfo user) {
        this.user = user;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public MsgTypeAccountTypeEnum getType() {
        return type;
    }
    public void setType(MsgTypeAccountTypeEnum type) {
        this.type = type;
    }
    public String getBeiZhu() {
        return beiZhu;
    }
    public void setBeiZhu(String beiZhu) {
        this.beiZhu = beiZhu;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/account/msg/UserAccountMsgNotificationService.java
New file
@@ -0,0 +1,54 @@
package org.fanli.facade.user.entity.account.msg;
/**
 * 用户账户消息通知
 *
 * @author Administrator
 *
 */
public interface UserAccountMsgNotificationService {
    /**
     * 绑定成功
     *
     * @param uid
     * @param type
     */
    public void bindingSuccess(Long uid, int type);
    /**
     * 解绑成功
     *
     * @param uid
     * @param type
     */
    public void unBindingSuccess(Long uid, int type);
    /**
     * 取消绑定成功
     *
     * @param uid
     * @param type
     */
    public void changeBindingSuccess(Long uid, int type);
    /**
     * 账号合并成功
     *
     * @param uid
     * @param lessUid
     */
    public void connectSuccess(Long uid, Long lessUid);
    /**
     * 用户等级变化
     *
     * @param uid
     * @param orderType
     *            -订单类型(邀请订单/返利订单/分享订单)
     * @param orderCount
     * @param rankName
     */
    public void userRank(Long uid, String orderType, int orderCount, String rankName);
}
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/InviteGetMoney.java
New file
@@ -0,0 +1,116 @@
package org.fanli.facade.user.entity.invite;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.google.gson.annotations.Expose;
@Entity
@Table(name = "yeshi_ec_invite_getmoney_demo")
public class InviteGetMoney {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "igd_id")
    @Expose
    private Long id;
    @Expose
    @Column(name = "igd_icon")
    private String icon;
    @Expose
    @Column(name = "igd_name")
    private String name;
    @Expose
    @Column(name = "igd_portrait")
    private String portrait;
    @Expose
    @Column(name = "igd_money")
    private BigDecimal money;
    @Column(name = "igd_createtime")
    private Date createTime;
    @Transient
    private String rankIcon;
    @Transient
    private String uid;
    public String getRankIcon() {
        return rankIcon;
    }
    public void setRankIcon(String rankIcon) {
        this.rankIcon = rankIcon;
    }
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getIcon() {
        return icon;
    }
    public void setIcon(String icon) {
        this.icon = icon;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPortrait() {
        return portrait;
    }
    public void setPortrait(String portrait) {
        this.portrait = portrait;
    }
    public BigDecimal getMoney() {
        return money;
    }
    public void setMoney(BigDecimal money) {
        this.money = money;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getUid() {
        return uid;
    }
    public void setUid(String uid) {
        this.uid = uid;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/SpreadImg.java
New file
@@ -0,0 +1,68 @@
package org.fanli.facade.user.entity.invite;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.google.gson.annotations.Expose;
@Entity
@Table(name = "yeshi_ec_spread_img")
public class SpreadImg {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "si_id")
    @Expose
    private long id;
    @Expose
    @Column(name="si_url")
    private String url;
    @Expose
    @Column(name="si_createtime")
    private Date createtime;
    @Transient
    private String md5;
    public String getMd5() {
        return md5;
    }
    public void setMd5(String md5) {
        this.md5 = md5;
    }
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public Date getCreatetime() {
        return createtime;
    }
    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/SpreadUserImg.java
New file
@@ -0,0 +1,92 @@
package org.fanli.facade.user.entity.invite;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.google.gson.annotations.Expose;
@Entity
@Table(name = "yeshi_ec_spread_user_img")
public class SpreadUserImg {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "si_id")
    @Expose
    private long id;
    @Column(name = "si_uid")
    @Expose
    private Long uid;
    @Column(name = "si_type")
    @Expose
    private Integer type;
    @Expose
    @Column(name="si_url")
    private String url;
    @Expose
    @Column(name="si_createtime")
    private Date createtime;
    @Transient
    private String md5;
    public String getMd5() {
        return md5;
    }
    public void setMd5(String md5) {
        this.md5 = md5;
    }
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public Long getUid() {
        return uid;
    }
    public void setUid(Long uid) {
        this.uid = uid;
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public Date getCreatetime() {
        return createtime;
    }
    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/ThreeSale.java
New file
@@ -0,0 +1,146 @@
package org.fanli.facade.user.entity.invite;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.yeshi.utils.mybatis.Column;
import com.yeshi.fanli.base.entity.user.UserInfo;
/**
 * 分销关系
 *
 * @author cxx
 *
 * @date 2018年1月29日
 */
@Entity
@Table(name = "yeshi_ec_threeSale")
@org.yeshi.utils.mybatis.Table("yeshi_ec_threeSale")
public class ThreeSale {
    public static int EXPIRE_NORMAL = 0;// 正常状态
    public static int EXPIRE_OUTOFDATE = 1;// 过期状态
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;
    public ThreeSale(Long id) {
        this.id = id;
    }
    public ThreeSale() {
    }
    @ManyToOne
    @JoinColumn(name = "boss_id")
    @Column(name = "boss_id")
    private UserInfo boss;// 邀请者
    @OneToOne
    @JoinColumn(name = "worker_id")
    @Column(name = "worker_id")
    private UserInfo worker; // 被邀请者
    @Column(name = "state")
    private Boolean state;// 状态:是否邀请成功 被邀请者登陆后才算邀请成功 1已成功、0还未成功
    @Column(name = "expire")
    // 是否过期: 是否过期:初始0 已过期1 (2018.10.22添加)
    private Integer expire;
    @Column(name = "createTime")
    private Long createTime;
    @Column(name = "succeedTime")
    private Long succeedTime;
    @Column(name = "updateTime")
    private Long updateTime;
    @Transient
    private ThreeSaleExtraInfo threeSaleExtraInfo;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public UserInfo getBoss() {
        return boss;
    }
    public void setBoss(UserInfo boss) {
        this.boss = boss;
    }
    public UserInfo getWorker() {
        return worker;
    }
    public void setWorker(UserInfo worker) {
        this.worker = worker;
    }
    public Long getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }
    public Boolean getState() {
        return state;
    }
    public void setState(Boolean state) {
        this.state = state;
    }
    public Integer getExpire() {
        return expire;
    }
    public void setExpire(Integer expire) {
        this.expire = expire;
    }
    public Long getSucceedTime() {
        return succeedTime;
    }
    public void setSucceedTime(Long succeedTime) {
        this.succeedTime = succeedTime;
    }
    public Long getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }
    public ThreeSaleExtraInfo getThreeSaleExtraInfo() {
        return threeSaleExtraInfo;
    }
    public void setThreeSaleExtraInfo(ThreeSaleExtraInfo threeSaleExtraInfo) {
        this.threeSaleExtraInfo = threeSaleExtraInfo;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/ThreeSaleExtraInfo.java
New file
@@ -0,0 +1,103 @@
package org.fanli.facade.user.entity.invite;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
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.Table;
import com.yeshi.fanli.base.entity.user.UserInfo;
/**
 * 队员备注信息
 *
 * @date 2018年11月20日
 */
@Entity
@Table(name = "yeshi_ec_threesale_extra_info")
@org.yeshi.utils.mybatis.Table("yeshi_ec_threesale_extra_info")
public class ThreeSaleExtraInfo {
    @Id
    @Column(name = "tf_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    @org.yeshi.utils.mybatis.Column(name = "tf_id")
    private Long id;
    @JoinColumn(name = "tf_boss_id")
    @ManyToOne(fetch = FetchType.EAGER)
    @org.yeshi.utils.mybatis.Column(name = "tf_boss_id")
    private UserInfo boss;//邀请者
    @JoinColumn(name = "tf_worker_id")
    @ManyToOne(fetch = FetchType.EAGER)
    @org.yeshi.utils.mybatis.Column(name = "tf_worker_id")
    private UserInfo worker; //被邀请者
    @JoinColumn(name = "tf_nickname")
    @org.yeshi.utils.mybatis.Column(name = "tf_nickname")
    private String nickname; // 备注名
    @JoinColumn(name = "tf_createtime")
    @org.yeshi.utils.mybatis.Column(name = "tf_createtime")
    private Date createTime; // 创建时间
    @JoinColumn(name = "tf_updatetime")
    @org.yeshi.utils.mybatis.Column(name = "tf_updatetime")
    private Date updateTime; // 更新时间
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public UserInfo getBoss() {
        return boss;
    }
    public void setBoss(UserInfo boss) {
        this.boss = boss;
    }
    public UserInfo getWorker() {
        return worker;
    }
    public void setWorker(UserInfo worker) {
        this.worker = worker;
    }
    public String getNickname() {
        return nickname;
    }
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/invite/msg/MsgInviteDetail.java
New file
@@ -0,0 +1,123 @@
package org.fanli.facade.user.entity.invite.msg;
import java.util.Date;
import org.fanli.facade.user.entity.invite.ThreeSale;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
import com.yeshi.fanli.base.entity.user.UserInfo;
/***
 * 邀请消息
 *
 * @author Administrator
 *
 */
@Table("yeshi_ec_msg_invite")
public class MsgInviteDetail {
    public enum MsgTypeInviteTypeEnum {
        invite("邀请消息");
        private final String desc;
        private MsgTypeInviteTypeEnum(String desc) {
            this.desc = desc;
        }
        public String getDesc() {
            return desc;
        }
    }
    @Column(name="mi_id")
    private Long id;
    @Column(name="mi_uid")
    private UserInfo user;
    @Column(name="mi_type")
    private MsgTypeInviteTypeEnum msgType;// 消息类型
    @Column(name="mi_invite_id")
    private ThreeSale inviteUser;// 邀请信息
    @Column(name="mi_desc")
    private String desc;// 说明
    @Column(name="mi_beizhu")
    private String beiZhu;// 备注
    @Column(name="mi_read")
    private Boolean read;// 是否已读
    @Column(name="mi_create_time")
    private Date createTime;
    @Column(name="mi_update_time")
    private Date updateTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public UserInfo getUser() {
        return user;
    }
    public void setUser(UserInfo user) {
        this.user = user;
    }
    public MsgTypeInviteTypeEnum getMsgType() {
        return msgType;
    }
    public void setMsgType(MsgTypeInviteTypeEnum msgType) {
        this.msgType = msgType;
    }
    public ThreeSale getInviteUser() {
        return inviteUser;
    }
    public void setInviteUser(ThreeSale inviteUser) {
        this.inviteUser = inviteUser;
    }
    public String getDesc() {
        return desc;
    }
    public void setDesc(String desc) {
        this.desc = desc;
    }
    public String getBeiZhu() {
        return beiZhu;
    }
    public void setBeiZhu(String beiZhu) {
        this.beiZhu = beiZhu;
    }
    public Boolean getRead() {
        return read;
    }
    public void setRead(Boolean read) {
        this.read = read;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/entity/taobao/UserExtraTaoBaoInfo.java
New file
@@ -0,0 +1,133 @@
package org.fanli.facade.user.entity.taobao;
import java.util.Date;
import org.yeshi.utils.mybatis.Column;
import org.yeshi.utils.mybatis.Table;
import com.yeshi.fanli.base.entity.user.UserInfo;
@Table("yeshi_ec_user_info_extra_taobao")
public class UserExtraTaoBaoInfo {
    @Column(name = "uiet_id")
    private Long id;
    @Column(name = "uiet_uid")
    private UserInfo user;
    @Column(name = "uiet_relation_id")
    private String relationId;
    @Column(name = "uiet_relation_valid")
    private Boolean relationValid;// 是否有效
    @Column(name = "uiet_relation_update_time")
    private Date relationUpdateTime;
    @Column(name = "uiet_special_id")
    private String specialId;
    @Column(name = "uiet_special_valid")
    private Boolean specialValid;// 是否有效
    @Column(name = "uiet_special_update_time")
    private Date specialUpdateTime;
    @Column(name = "uiet_taobao_uid")
    private String taoBaoUid;// 淘宝的用户ID
    @Column(name = "uiet_taobao_order_end_6_num")
    private String taoBaoOrderEnd6Num;// 订单结尾的6个数字
    @Column(name = "uiet_create_time")
    private Date createTime;
    @Column(name = "uiet_update_time")
    private Date updateTime;
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public UserInfo getUser() {
        return user;
    }
    public void setUser(UserInfo user) {
        this.user = user;
    }
    public String getRelationId() {
        return relationId;
    }
    public void setRelationId(String relationId) {
        this.relationId = relationId;
    }
    public Date getRelationUpdateTime() {
        return relationUpdateTime;
    }
    public void setRelationUpdateTime(Date relationUpdateTime) {
        this.relationUpdateTime = relationUpdateTime;
    }
    public String getTaoBaoOrderEnd6Num() {
        return taoBaoOrderEnd6Num;
    }
    public void setTaoBaoOrderEnd6Num(String taoBaoOrderEnd6Num) {
        this.taoBaoOrderEnd6Num = taoBaoOrderEnd6Num;
    }
    public String getSpecialId() {
        return specialId;
    }
    public void setSpecialId(String specialId) {
        this.specialId = specialId;
    }
    public Boolean getRelationValid() {
        return relationValid;
    }
    public void setRelationValid(Boolean relationValid) {
        this.relationValid = relationValid;
    }
    public Boolean getSpecialValid() {
        return specialValid;
    }
    public void setSpecialValid(Boolean specialValid) {
        this.specialValid = specialValid;
    }
    public String getTaoBaoUid() {
        return taoBaoUid;
    }
    public void setTaoBaoUid(String taoBaoUid) {
        this.taoBaoUid = taoBaoUid;
    }
    public Date getSpecialUpdateTime() {
        return specialUpdateTime;
    }
    public void setSpecialUpdateTime(Date specialUpdateTime) {
        this.specialUpdateTime = specialUpdateTime;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/exception/account/msg/MsgAccountDetailException.java
New file
@@ -0,0 +1,32 @@
package org.fanli.facade.user.exception.account.msg;
public class MsgAccountDetailException extends Exception {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    public int getCode() {
        return code;
    }
    public String getMsg() {
        return msg;
    }
    public MsgAccountDetailException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public MsgAccountDetailException() {
    }
    @Override
    public String getMessage() {
        return this.msg;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/exception/invite/ThreeSaleException.java
New file
@@ -0,0 +1,32 @@
package org.fanli.facade.user.exception.invite;
public class ThreeSaleException extends Exception {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    public int getCode() {
        return code;
    }
    public String getMsg() {
        return msg;
    }
    public ThreeSaleException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public ThreeSaleException() {
    }
    @Override
    public String getMessage() {
        return this.msg;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/exception/invite/msg/MsgInviteDetailException.java
New file
@@ -0,0 +1,32 @@
package org.fanli.facade.user.exception.invite.msg;
public class MsgInviteDetailException extends Exception {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    public int getCode() {
        return code;
    }
    public String getMsg() {
        return msg;
    }
    public MsgInviteDetailException(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public MsgInviteDetailException() {
    }
    @Override
    public String getMessage() {
        return this.msg;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/service/account/UserAccountService.java
File was renamed from fanli-facade-user/src/main/java/org/fanli/facade/user/service/UserAccountService.java
@@ -1,9 +1,9 @@
package org.fanli.facade.user.service;
package org.fanli.facade.user.service.account;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.fanli.facade.user.dto.LoginResult;
import org.fanli.facade.user.dto.account.LoginResult;
import org.fanli.facade.user.exception.UserAccountException;
import com.yeshi.fanli.base.entity.user.UserInfo;
fanli-facade-user/src/main/java/org/fanli/facade/user/service/account/UserInfoService.java
File was renamed from fanli-facade-user/src/main/java/org/fanli/facade/user/service/UserInfoService.java
@@ -1,4 +1,4 @@
package org.fanli.facade.user.service;
package org.fanli.facade.user.service.account;
import java.math.BigDecimal;
import java.util.Date;
fanli-facade-user/src/main/java/org/fanli/facade/user/service/account/msg/MsgAccountDetailService.java
New file
@@ -0,0 +1,42 @@
package org.fanli.facade.user.service.account.msg;
import java.util.List;
import org.fanli.facade.user.entity.account.msg.MsgAccountDetail;
import org.fanli.facade.user.exception.account.msg.MsgAccountDetailException;
public interface MsgAccountDetailService {
    /**
     * 添加到账户消息
     *
     * @param detail
     * @throws MsgAccountDetailException
     */
    public void addMsgAccountDetail(MsgAccountDetail detail) throws MsgAccountDetailException;
    /**
     * 账户消息列表
     *
     * @param uid
     * @param page
     * @return
     */
    public List<MsgAccountDetail> listMsgAccountDetail(Long uid, int page);
    /**
     * 账户消息数
     *
     * @param uid
     * @return
     */
    public long countMsgAccountDetail(Long uid);
    /**
     * 设置所有消息已读
     *
     * @param uid
     */
    public void readMsgByUid(Long uid);
}
fanli-facade-user/src/main/java/org/fanli/facade/user/service/invite/QrCodeService.java
New file
@@ -0,0 +1,37 @@
package org.fanli.facade.user.service.invite;
import java.io.IOException;
public interface QrCodeService {
    /**
     * 生成邀请赚的图片
     *
     * @param url
     * @param uid
     * @param portrait
     * @return
     * @throws IOException
     */
    String drawInviteQrCode(String url, Long uid, String portrait) throws IOException;
    /**
     * 绘制邀请二维码
     *
     * @param url
     *            -背景图链接
     * @param uid
     *            -用户ID
     * @param portrait
     *            -头像路径
     * @param erCodePostionX
     *            二维码坐标X
     * @param erCodePostionY
     *            二维码坐标Y
     * @param erCodeSize
     *            二维码尺寸
     * @return
     * @throws IOException
     */
    String drawInviteQrCode(String url, Long uid, String portrait, int erCodePostionX, int erCodePostionY,
            int erCodeSize) throws IOException;
}
fanli-facade-user/src/main/java/org/fanli/facade/user/service/invite/SpreadUserImgService.java
New file
@@ -0,0 +1,54 @@
package org.fanli.facade.user.service.invite;
import java.util.List;
import com.yeshi.fanli.base.entity.user.UserInfo;
public interface SpreadUserImgService {
    void addUserInviteImg(Long uid, String imgUrl);
    List<String> getImgUrlList(Long uid);
    int imgUrlCount(Long uid);
    void deleteImgUrl(Long uid);
    /**
     * 获取立即邀请的分享图
     *
     * @param uid
     * @return
     */
    List<String> getUserSpreadImg(UserInfo user);
    /**
     * 用户分享图的数量
     * @param uid
     * @return
     */
    int countUserSpreadImg(Long uid);
    /**
     * 获取以某张图片为背景的邀请分享图
     *
     * @param uid
     * @param bgImg
     *            -背景图片地址
     * @return
     */
    String getUserSpreadImg(UserInfo user, String bgImg);
    /**
     * 获取以某张图片为背景的邀请分享图( 指定二维码的位置以及尺寸)
     *
     * @param uid
     * @param bgImg
     * @param erCodePostionX
     * @param erCodePostionY
     * @param erCodeSize
     * @return
     */
    String getUserSpreadImg(Long uid, String bgImg, int erCodePostionX, int erCodePostionY, int erCodeSize);
}
fanli-facade-user/src/main/java/org/fanli/facade/user/service/invite/ThreeSaleSerivce.java
New file
@@ -0,0 +1,256 @@
package org.fanli.facade.user.service.invite;
import java.util.List;
import org.fanli.facade.user.entity.invite.ThreeSale;
import org.fanli.facade.user.exception.invite.ThreeSaleException;
import com.yeshi.fanli.base.entity.user.UserInfo;
import net.sf.json.JSONObject;
public interface ThreeSaleSerivce {
    /**
     * 获取该用户上级用户
     *
     * @param uid
     *            用户ID
     * @return
     */
    UserInfo getBoss(long uid);
    void bind(UserInfo invitee, UserInfo inviter) throws ThreeSaleException;
    void effective(UserInfo find);
    /**
     * 重新计算用户的等级
     *
     * @param uid
     */
    void reComputeUserRank(Long uid);
    // 获取下级用户
    List<UserInfo> getFirstUsers(Long uid, int page);
    // 获取一级用户数量
    long getFirstUsersCount(Long uid);
    // 获取下2级用户
    List<UserInfo> getSecondUsers(Long uid, int page);
    // 获取二级用户数量
    long getSecondUsersCount(Long uid);
    // 获取最近有效的分销列表
    List<ThreeSale> getLastestThreeSaleList(int i, String key);
    // 邀请关系
    int getLastestThreeSaleCount(String key);
    /**
     * 查询一度队员集合
     *
     * @param start
     * @param count
     * @param key
     * @param uid
     * @return
     */
    public List<ThreeSale> queryMyFirstTeamList(int start, int count, String key, Long bossId);
    public long queryCountMyFirstTeamList(String key, Long bossId);
    /**
     * 查询二度队员集合
     *
     * @param start
     * @param count
     * @param key
     * @param uid
     * @return
     */
    public List<ThreeSale> queryMySecondTeamList(int start, int count, String key, Long bossId);
    public long queryCountMySecondTeamList(String key, Long bossId);
    /**
     * 删除邀请关系id
     *
     * @param id
     * @return
     */
    public int deleteByPrimaryKey(Long id);
    /**
     * 长时间未邀请成功用户
     *
     * @param daysNum
     * @return
     */
    public List<Long> queryLongTimeFailed(int daysNum);
    /**
     * 长时间 邀请成功用户
     *
     * @param daysNum
     * @return
     */
    public List<ThreeSale> queryLongTimeSuccess(int daysNum);
    /**
     * 设置对应邀请过期
     *
     * @param list
     * @return
     */
    public int updateExpire(List<Long> list);
    /**
     * 一级查询
     *
     * @param start
     * @param count
     * @param uid
     * @param startTime
     * @param endTime
     * @return
     */
    public List<ThreeSale> listFirstTeamQuery(long start, int count, Long uid, Integer state, String startTime,
            String endTime);
    public long countFirstTeamQuery(Long uid, Integer state, String startTime, String endTime);
    /**
     * 二级查询
     *
     * @param start
     * @param count
     * @param uid
     * @param startTime
     * @param endTime
     * @return
     */
    public List<ThreeSale> listSecondTeamQuery(long start, int count, Long uid, Integer state, String startTime,
            String endTime);
    public long countSecondTeamQuery(Long uid, Integer state, String startTime, String endTime);
    /**
     * 上级查询
     *
     * @param start
     * @param count
     * @param uid
     * @return
     */
    public List<ThreeSale> listSuperiorQuery(long start, int count, Integer state, Long uid);
    public long countSuperiorQuery(Integer state, Long uid);
    /**
     * app端一级查询1.4.1
     *
     * @param start
     * @param count
     * @param uid
     * @return
     */
    public List<ThreeSale> listFirstTeam(long start, int count, Long uid);
    /**
     * 统计所有一级队员
     *
     * @param uid
     * @param state
     *            状态,值 为空时则统计所有
     * @return
     */
    public long countFirstTeam(Long uid, Integer state);
    /**
     * app端二级查询1.4.1
     *
     * @param start
     * @param count
     * @param uid
     * @return
     */
    public List<ThreeSale> listSecondTeam(long start, int count, Long uid);
    /**
     * 统计二级队员
     *
     * @param uid
     * @param state
     *            状态,值 为空时则统计所有
     * @return
     */
    public long countSecondTeam(Long uid, Integer state);
    /**
     * 前端查询一级队员
     *
     * @param start
     * @param count
     * @param uid
     * @return
     */
    public JSONObject getMyFirstTeam(long start, int count, Long uid);
    /**
     * 前端查询二级队员
     *
     * @param start
     * @param count
     * @param uid
     * @return
     */
    public JSONObject getMySecondTeam(long start, int count, Long uid);
    /**
     * 获取上级
     *
     * @param uid
     * @return
     */
    public ThreeSale getMyBoss(Long uid);
    public ThreeSale selectByPrimaryKey(Long id);
    /**
     * 查询队员记录 id+uid
     *
     * @param id
     * @param uid
     * @param expire
     *            是否失效状态
     * @return
     */
    public List<ThreeSale> listbyIdAndBossId(Long id, Long uid, Integer expire);
    /**
     * 根据邀请者查询关系
     *
     * @param workerId
     * @return
     */
    public List<ThreeSale> listByWorkerId(Long workerId);
    /**
     * 获取成功邀请关系数量
     * @param uid
     * @return
     */
    public int getSuccessRelationshipNum(Long uid);
    /**
     * 邀请码生成上下级关系
     * @param invitee
     * @param inviter
     * @throws ThreeSaleException
     */
    public void bindRelationshipByInviteCode(UserInfo invitee, UserInfo inviter) throws ThreeSaleException;
}
fanli-facade-user/src/main/java/org/fanli/facade/user/service/invite/msg/MsgInviteDetailService.java
New file
@@ -0,0 +1,48 @@
package org.fanli.facade.user.service.invite.msg;
import java.util.List;
import org.fanli.facade.user.entity.invite.ThreeSale;
import org.fanli.facade.user.entity.invite.msg.MsgInviteDetail;
import org.fanli.facade.user.exception.invite.msg.MsgInviteDetailException;
public interface MsgInviteDetailService {
    /**
     * 添加到邀请消息
     *
     * @param detail
     * @throws MsgInviteDetailException
     */
    public void addMsgInviteDetail(MsgInviteDetail detail) throws MsgInviteDetailException;
    /**
     * 账户消息列表
     *
     * @param uid
     * @param page
     * @return
     */
    public List<MsgInviteDetail> listMsgInviteDetail(Long uid, int page);
    /**
     * 账户消息数
     *
     * @param uid
     * @return
     */
    public long countMsgInviteDetail(Long uid);
    /**
     * 设置所有消息已读
     *
     * @param uid
     */
    public void readMsgByUid(Long uid);
    /**
     * 根据邀请关系ID删除
     *
     * @param sale
     */
    public void deleteByThreeSale(ThreeSale sale);
}
fanli-facade-user/src/main/java/org/fanli/facade/user/service/invite/msg/UserInviteMsgNotificationService.java
New file
@@ -0,0 +1,36 @@
package org.fanli.facade.user.service.invite.msg;
import org.fanli.facade.user.entity.invite.ThreeSale;
/**
 * 用户邀请消息通知
 *
 * @author Administrator
 *
 */
public interface UserInviteMsgNotificationService {
    /**
     * 二维码扫描
     *
     * @param uid
     * @param sale
     */
    public void inviteScan(Long uid, ThreeSale sale);
    /**
     * 邀请成功
     *
     * @param uid
     * @param sale
     */
    public void inviteSuccess(Long uid, ThreeSale sale);
    /**
     * 邀请失败
     *
     * @param uid
     * @param sale
     */
    public void inviteFail(Long uid, ThreeSale sale);
}
fanli-facade-user/src/main/java/org/fanli/facade/user/service/taobao/UserExtraTaoBaoInfoService.java
New file
@@ -0,0 +1,72 @@
package org.fanli.facade.user.service.taobao;
import org.fanli.facade.user.entity.taobao.UserExtraTaoBaoInfo;
/**
 * 用户淘宝联盟服务
 *
 * @author Administrator
 *
 */
public interface UserExtraTaoBaoInfoService {
    /**
     * 添加渠道ID
     *
     * @param uid
     * @param relationId
     */
    public void addRelationId(Long uid, String relationId, String taoBaoUid, boolean valid);
    /**
     * 添加会员ID
     *
     * @param uid
     * @param specialId
     */
    public void addSpecialId(Long uid, String specialId, String taoBaoUid, boolean valid);
    /**
     * 通过UID获取淘宝联盟渠道信息
     *
     * @param uid
     * @return
     */
    public UserExtraTaoBaoInfo getByUid(Long uid);
    /**
     * 选择性更新
     *
     * @param ue
     */
    public void updateSelective(UserExtraTaoBaoInfo ue);
    /**
     * 解绑用户
     *
     * @param uid
     */
    public void unBindUid(Long uid);
    /**
     * 绑定淘宝后6位
     *
     * @param taoBaoUid
     * @param orderId
     */
    public void bindTaoBaoOrderEnd6Num(String taoBaoUid, String orderId);
    /**
     * 通过渠道ID查询用户(用户信息不为空)
     * @param relationId
     * @return
     */
    public UserExtraTaoBaoInfo getByRelationId(String relationId);
    /**
     * 通过会员运营ID查询用户(用户信息不为空)
     * @param specialId
     * @return
     */
    public UserExtraTaoBaoInfo getBySpecialId(String specialId);
}
fanli-facade-user/src/main/java/org/fanli/facade/user/util/InviteImageUtil.java
New file
@@ -0,0 +1,432 @@
package org.fanli.facade.user.util;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.RenderingHints.Key;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import javax.imageio.ImageIO;
import org.yeshi.utils.FileUtil;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.MoneyBigDecimalUtil;
import org.yeshi.utils.StringUtil;
import com.yeshi.fanli.base.entity.goods.TaoBaoGoodsBrief;
import com.yeshi.fanli.base.log.LogHelper;
public class InviteImageUtil {
    // 画商品分享图
    public static InputStream drawGoodsShareImg(InputStream qrcodeStream, InputStream portrait,
            TaoBaoGoodsBrief goods) {
        String fontPath = "/usr/share/fonts/PingFang_Medium.ttf";
        String os = System.getProperty("os.name");
        if (os.toLowerCase().startsWith("win")) {
            fontPath = "D:/PingFang_Medium.ttf";
        }
        String fontBoldPath = "/usr/share/fonts/PingFang_Heavy_0.ttf";
        if (os.toLowerCase().startsWith("win")) {
            fontBoldPath = "D:/PingFang_Heavy_0.ttf";
        }
        final BufferedImage targetImg = new BufferedImage(720, 1280, BufferedImage.TYPE_INT_RGB);
        HashMap<Key, Object> mapH = new HashMap<Key, Object>();
        mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 抗锯齿 (抗锯齿总开关)  
        mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 文字抗锯齿 
        final Graphics2D g2d = (Graphics2D) targetImg.getGraphics();
        g2d.setRenderingHints(mapH);
        g2d.setColor(Color.WHITE);
        g2d.fillRect(0, 0, 720, 1280);
        Font font = null;
        try {
            font = Font.createFont(Font.PLAIN, new File(fontPath)).deriveFont(30.0f);
        } catch (FontFormatException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        g2d.setFont(font);
        try {
            g2d.setColor(new Color(153, 153, 153));
            // 画来源图标
            InputStream userTypeIcon = null;
            if (goods.getUserType() == 0)// 淘宝
            {
                userTypeIcon = InviteImageUtil.class.getClassLoader().getResourceAsStream("image/icon_tb.png");
            } else {
                userTypeIcon = InviteImageUtil.class.getClassLoader().getResourceAsStream("image/icon_tm.png");
            }
            g2d.drawImage(ImageIO.read(userTypeIcon), 50, 88, null);
            // 商品标题
            String title = goods.getTitle();
            int row = 0;
            int length = 0;
            // 画第一排
            length = getTextLengthByWidth(g2d, font, title, 500, 10);
            g2d.drawString(title.substring(0, length), 50 + 65, 112 + row * 40);
            title = title.substring(length);
            row++;
            // 判断是否画完,最多画2排
            while (title.length() > 0 && row < 2) {
                length = getTextLengthByWidth(g2d, font, title, 335, 10);
                g2d.drawString(title.substring(0, length), 50, 112 + row * 40);
                title = title.substring(length);
                row++;
            }
            // 画商品主图
            InputStream goodsPicture = HttpUtil.getAsInputStream(goods.getPictUrl());
            BufferedImage picImage = ImageIO.read(goodsPicture);
            picImage = zoomInImage(picImage, 620, 620);
            g2d.drawImage(picImage, 50, 190, null);
            Font boldFont = Font.createFont(Font.PLAIN, new File(fontBoldPath)).deriveFont(50.0f);
            // 画价格
            // 有券
            if (!StringUtil.isNullOrEmpty(goods.getCouponInfo())) {
                BigDecimal finalPrice = goods.getZkPrice();
                if (goods.getCouponStartFee().compareTo(goods.getZkPrice()) <= 0
                        && goods.getZkPrice().compareTo(goods.getCouponAmount()) >= 0) {
                    finalPrice = goods.getZkPrice().subtract(goods.getCouponAmount());
                }
                g2d.setColor(new Color(229, 0, 93));
                g2d.drawString("券后价  ¥", 57, 875);
                g2d.setColor(new Color(229, 0, 93));
                g2d.setFont(boldFont);
                g2d.drawString(finalPrice.toString(), 85 + 110, 875);
                // 画券右侧
                BufferedImage quanRight = ImageIO
                        .read(InviteImageUtil.class.getClassLoader().getResourceAsStream("image/fanli_quan_right.png"));
                g2d.setColor(new Color(241, 66, 66));
                g2d.drawImage(quanRight, 670 - quanRight.getWidth(), 852, null);
                // 画券的内容
                g2d.setColor(new Color(229, 0, 93));
                String quanString = " " + MoneyBigDecimalUtil.getWithNoZera(goods.getCouponAmount()) + "元券 ";
                boldFont = boldFont.deriveFont(44.0f);
                g2d.setFont(boldFont);
                FontMetrics fm = g2d.getFontMetrics(boldFont);
                int textLength = fm.stringWidth(quanString);
                g2d.fillRect(670 - quanRight.getWidth() - textLength, 852, textLength, 80);
                g2d.setColor(Color.WHITE);
                g2d.setFont(boldFont);
                g2d.drawString(quanString, 670 - quanRight.getWidth() - textLength, 927 - 19);
                // 画券左侧
                BufferedImage quanLeft = ImageIO
                        .read(InviteImageUtil.class.getClassLoader().getResourceAsStream("image/fanli_quan_left.png"));
                g2d.drawImage(quanLeft, 670 - quanRight.getWidth() - textLength - quanLeft.getWidth(), 852, null);
                String zkPriceName = "";
                if (goods.getUserType() == 0)
                    zkPriceName = "淘宝价  ¥ " + MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice());
                else
                    zkPriceName = "天猫价  ¥ " + MoneyBigDecimalUtil.getWithNoZera(goods.getZkPrice());
                g2d.setColor(new Color(153, 153, 153));
                font = font.deriveFont(30.0f);
                g2d.setFont(font);
                g2d.drawString(zkPriceName, 56, 930);
            } else// 无券
            {
                g2d.setColor(new Color(229, 0, 93));
                g2d.drawString("¥", 60, 870);
                g2d.setColor(new Color(229, 0, 93));
                BigDecimal finalPrice = goods.getZkPrice();
                g2d.setFont(boldFont);
                g2d.drawString(finalPrice.toString(), 85, 870);
            }
            g2d.setColor(new Color(247, 247, 247));
            g2d.fillRect(56, 1015, 608, 204);
            // 画二维码
            BufferedImage qrcodeImage = ImageIO.read(qrcodeStream);
            qrcodeImage = zoomInImage(qrcodeImage, 170, 170);
            g2d.drawImage(qrcodeImage, 56 + 17, 1015 + 17, null);
            // 画头像
            if (portrait != null) {
                BufferedImage portraitImg = ImageIO.read(portrait);
                portraitImg = zoomInImage(portraitImg, 40, 40);
                g2d.drawImage(portraitImg, 56 + 17 + (qrcodeImage.getWidth() - portraitImg.getWidth()) / 2,
                        1015 + 17 + (qrcodeImage.getHeight() - portraitImg.getHeight()) / 2, null);
            }
            font = font.deriveFont(30.0f);
            g2d.setFont(font);
            g2d.setColor(new Color(229, 0, 93));
            // g2d.drawString("返利券提醒您", 250 + 17, 1080 + 17);
            g2d.setColor(new Color(102, 102, 102));
            g2d.drawString("长按识别二维码领取优惠券", 250 + 17, 1130 + 17);
            g2d.dispose();
            // OutputStream out = new ByteArrayOutputStream(); new
            // FileOutputStream(new File(targetPath));
            // ImageIO.write(targetImg, "JPEG", out);
            // out.flush();
            // out.close();
            ByteArrayOutputStream aos = new ByteArrayOutputStream();
            ImageIO.write(targetImg, "JPEG", aos);
            InputStream is = new ByteArrayInputStream(aos.toByteArray());
            return is;
        } catch (Exception e) {
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
        return null;
    }
    private static int[] computeCropPosition(BufferedImage source, int width, int height) {
        int[] cropParams = new int[4];
        int owidth = source.getWidth();
        int oheight = source.getHeight();
        if (oheight * width - owidth * height > 0) {
            cropParams[0] = 0;
            cropParams[1] = (oheight - height) / 2;
            cropParams[2] = owidth;
            cropParams[3] = cropParams[2] * height / width;
        } else {
            cropParams[0] = (owidth - width) / 2;
            cropParams[1] = 0;
            cropParams[3] = oheight;
            cropParams[2] = cropParams[3] * width / height;
        }
        return cropParams;
    }
    public static BufferedImage crop(BufferedImage source, int startX, int startY, int w, int h) {
        int width = source.getWidth();
        int height = source.getHeight();
        if (startX <= -1) {
            startX = 0;
        }
        if (startY <= -1) {
            startY = 0;
        }
        if (w <= -1) {
            w = width - 1;
        }
        if (h <= -1) {
            h = height - 1;
        }
        BufferedImage result = new BufferedImage(w, h, source.getType());
        for (int y = startY; y < h + startY; y++) {
            for (int x = startX; x < w + startX; x++) {
                int rgb = source.getRGB(x, y);
                result.setRGB(x - startX, y - startY, rgb);
            }
        }
        return result;
    }
    public static BufferedImage zoomInImage(BufferedImage originalImage, int width, int height) {
        int type = originalImage.getType();
        if (type == 0)
            type = 5;
        BufferedImage newImage = new BufferedImage(width, height, type);
        Graphics g = newImage.getGraphics();
        g.drawImage(originalImage, 0, 0, width, height, null);
        g.dispose();
        return newImage;
    }
    // 邀请好友图片
    public static void inviteFriendImg(InputStream urlInputStream, InputStream portraitInputStream,
            InputStream erCodeInputStream, String targetPath) throws IOException {
        inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, 260, 908, 230);
    }
    /**
     *
     * @param urlInputStream
     * @param portraitInputStream
     * @param erCodeInputStream
     * @param targetPath
     * @param pX
     *            -二维码的横坐标
     * @param pY
     *            -二维码的纵坐标
     * @param size
     *            -二维码的尺寸
     * @throws IOException
     */
    // 邀请好友图片
    public static void inviteFriendImg(InputStream urlInputStream, InputStream portraitInputStream,
            InputStream erCodeInputStream, String targetPath, int pX, int pY, int size) throws IOException {
        BufferedImage bgImage = ImageIO.read(urlInputStream);
        final BufferedImage targetImg = new BufferedImage(bgImage.getWidth(), bgImage.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        HashMap<Key, Object> mapH = new HashMap<Key, Object>();
        mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 抗锯齿 (抗锯齿总开关)  
        mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 文字抗锯齿 
        // 画 背景图片
        final Graphics2D g2d = targetImg.createGraphics();
        g2d.drawImage(bgImage, 0, 0, bgImage.getWidth(), bgImage.getHeight(), null);
        // 画 二维码
        BufferedImage qrCodeImage = ImageIO.read(erCodeInputStream);
        qrCodeImage = InviteImageUtil.qrCodeImage(g2d, qrCodeImage, pX, pY, size, size); // 二维码长宽
        // 230*230
        // 画 头像
        BufferedImage portraitImg = ImageIO.read(portraitInputStream);
        int portraitSize = size * 5 / 23;
        int pPX = pX + size / 2 - portraitSize / 2;
        int pPY = pY + size / 2 - portraitSize / 2;
        portraitImg = InviteImageUtil.portraitImg(g2d, portraitImg, pPX, pPY, portraitSize, portraitSize);// 头像长宽
        OutputStream out = new FileOutputStream(new File(targetPath));
        ImageIO.write(targetImg, "JPEG", out);
        out.flush();
        out.close();
    }
    // 二维码
    public static BufferedImage qrCodeImage(Graphics2D g2d, BufferedImage originalImage, int pX, int pY, int width,
            int height) {
        g2d.drawImage(originalImage, pX, pY, width, height, null);
        return originalImage;
    }
    // 头像
    public static BufferedImage portraitImg(Graphics2D g2d, BufferedImage originalImage, int pX, int pY, int width,
            int height) {
        g2d.drawImage(originalImage, pX, pY, width, height, null);
        return originalImage;
    }
    static BufferedImage roundImage(BufferedImage srcImage, int cornerRadius) { // 半径
        int width = srcImage.getWidth();
        int height = srcImage.getHeight();
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D gs = image.createGraphics();
        HashMap<Key, Object> mapH = new HashMap<Key, Object>();
        mapH.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);// 抗锯齿 (抗锯齿总开关)  
        mapH.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);// 文字抗锯齿 
        gs.setRenderingHints(mapH);
        gs.setClip(new RoundRectangle2D.Double(0, 0, width, height, cornerRadius, cornerRadius));
        gs.drawImage(srcImage, 0, 0, null);
        gs.dispose();
        return image;
    }
    public static int saveToImgByInputStream(InputStream inputStream, String imgPath, String imgName) {
        int stateInt = 1;
        try {
            File file = new File(imgPath, imgName);// 可以是任何图片格式.jpg,.png等
            FileOutputStream fos = new FileOutputStream(file);
            FileInputStream fis = (FileInputStream) inputStream;
            byte[] b = new byte[1024];
            int nRead = 0;
            while ((nRead = fis.read(b)) != -1) {
                fos.write(b, 0, nRead);
            }
            fos.flush();
            fos.close();
            fis.close();
        } catch (Exception e) {
            stateInt = 0;
            e.printStackTrace();
        } finally {
        }
        return stateInt;
    }
    static int getTextLengthByWidth(Graphics2D g2d, Font font, String content, int maxWidth, int startPos) {
        FontMetrics fm = g2d.getFontMetrics(font);
        for (int i = startPos; i < content.length(); i++) {
            if (fm.stringWidth(content.substring(0, i)) >= maxWidth)
                return i + 1;
        }
        return content.length();
    }
    public static int[] getImgWidthAndHeight(String imgUrl) throws MalformedURLException, IOException {
        if (StringUtil.isNullOrEmpty(imgUrl))
            return new int[] { 0, 0 };
        if (imgUrl.toLowerCase().endsWith("webp"))
            return getImgWidthAndHeightWithWebp(imgUrl);
        else
            return getImgWidthAndHeightWithPngAndJpg(imgUrl);
    }
    public static int[] getImgWidthAndHeightWithPngAndJpg(String imgUrl) throws MalformedURLException, IOException {
        InputStream murl = new URL(imgUrl).openStream();
        BufferedImage sourceImg = ImageIO.read(murl);
        int width = sourceImg.getWidth();
        int height = sourceImg.getHeight();
        return new int[] { width, height };
    }
    public static int[] getImgWidthAndHeightWithWebp(String imgUrl) throws MalformedURLException, IOException {
        String cacheFile = FileUtil.getCacheDir();
        String targetPath = cacheFile + "/CACHE_DOWNLOAD_IMG_" + System.currentTimeMillis() + "_"
                + (long) (Math.random() * 1000000000L);
        HttpUtil.downloadFile(imgUrl, targetPath);
        FileInputStream file = new FileInputStream(targetPath);
        byte[] bytes = new byte[30];
        file.read(bytes, 0, bytes.length);
        int width = ((int) bytes[27] & 0xff) << 8 | ((int) bytes[26] & 0xff);
        int height = ((int) bytes[29] & 0xff) << 8 | ((int) bytes[28] & 0xff);
        file.close();
        return new int[] { width, height };
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/util/factory/MsgAccountDetailFactory.java
New file
@@ -0,0 +1,145 @@
package org.fanli.facade.user.util.factory;
import java.util.Date;
import org.fanli.facade.user.entity.account.msg.MsgAccountDetail;
import org.fanli.facade.user.entity.account.msg.MsgAccountDetail.MsgTypeAccountTypeEnum;
import org.yeshi.utils.StringUtil;
import com.yeshi.fanli.base.entity.user.UserInfo;
public class MsgAccountDetailFactory {
    public final static int TYPE_WX = 1;// 微信
    public final static int TYPE_TB = 2;// 淘宝
    public final static int TYPE_PHONE = 3;// 电话
    /**
     * 账号绑定成功
     *
     * @param uid
     * @param type
     * @return
     */
    public static MsgAccountDetail createBindingAccount(Long uid, int type) {
        String msg = "";
        if (type == TYPE_PHONE) {
            msg = "<highlight>恭喜你手机号绑定成功</highlight>";
        } else if (type == TYPE_TB) {
            msg = "<highlight>恭喜你淘宝绑定成功</highlight>";
        } else if (type == TYPE_WX) {
            msg = "<highlight>恭喜你微信绑定成功</highlight>";
        }
        if (StringUtil.isNullOrEmpty(msg))
            return null;
        MsgAccountDetail detail = new MsgAccountDetail();
        detail.setBeiZhu("无");
        detail.setContent(msg);
        detail.setTitle("绑定账号");
        detail.setType(MsgTypeAccountTypeEnum.bingding);
        detail.setUser(new UserInfo(uid));
        detail.setCreateTime(new Date());
        detail.setRead(false);
        return detail;
    }
    /**
     * 账号解绑成功
     *
     * @param uid
     * @param type
     * @return
     */
    public static MsgAccountDetail createUnBindingAccount(Long uid, int type) {
        String msg = "";
        if (type == TYPE_PHONE) {
            msg = "<highlight>手机号解绑成功</highlight>";
        } else if (type == TYPE_TB) {
            msg = "<highlight>淘宝解绑成功</highlight>";
        } else if (type == TYPE_WX) {
            msg = "<highlight>微信解绑成功</highlight>";
        }
        if (StringUtil.isNullOrEmpty(msg))
            return null;
        MsgAccountDetail detail = new MsgAccountDetail();
        detail.setBeiZhu("无");
        detail.setContent(msg);
        detail.setTitle("解绑账号");
        detail.setType(MsgTypeAccountTypeEnum.cancelBinding);
        detail.setUser(new UserInfo(uid));
        detail.setCreateTime(new Date());
        detail.setRead(false);
        return detail;
    }
    /**
     * 账号更换成功
     *
     * @param uid
     * @param type
     * @return
     */
    public static MsgAccountDetail createChangeBindingAccount(Long uid, int type) {
        String msg = "";
        if (type == TYPE_PHONE) {
            msg = "<highlight>手机号更换绑定成功</highlight>";
        } else if (type == TYPE_TB) {
            msg = "<highlight>淘宝更换绑定成功</highlight>";
        } else if (type == TYPE_WX) {
            msg = "<highlight>微信更换绑定成功</highlight>";
        }
        if (StringUtil.isNullOrEmpty(msg))
            return null;
        MsgAccountDetail detail = new MsgAccountDetail();
        detail.setBeiZhu("无");
        detail.setContent(msg);
        detail.setTitle("更换绑定账号");
        detail.setType(MsgTypeAccountTypeEnum.bingdingChange);
        detail.setUser(new UserInfo(uid));
        detail.setCreateTime(new Date());
        detail.setRead(false);
        return detail;
    }
    /**
     * 账号打通
     *
     * @param mainUid
     * @param lessUid
     * @return
     */
    public static MsgAccountDetail createConnectAccount(Long mainUid, Long lessUid) {
        if (mainUid == null || lessUid == null)
            return null;
        String msg = String.format("恭喜你账号合并成功,由“<highlight>%s</highlight>”合并到“<highlight>%s</highlight>”", lessUid + "",
                mainUid + "");
        MsgAccountDetail detail = new MsgAccountDetail();
        detail.setBeiZhu("无");
        detail.setContent(msg);
        detail.setTitle("账号合并");
        detail.setType(MsgTypeAccountTypeEnum.connect);
        detail.setUser(new UserInfo(mainUid));
        detail.setCreateTime(new Date());
        detail.setRead(false);
        return detail;
    }
    // 账号等级
    public static MsgAccountDetail createUserRank(Long uid, String orderType, int orderCount, String rankName) {
        if (uid == null || rankName == null)
            return null;
        String msg = String.format(
                "恭喜你,上月<highlight>%s</highlight>订单达到<highlight>%s</highlight>单,已为你升级为<highlight>%s</highlight>用户,将会获得对应的福利和特权。",
                orderType, orderCount + "", rankName);
        MsgAccountDetail detail = new MsgAccountDetail();
        detail.setBeiZhu("无");
        detail.setContent(msg);
        detail.setTitle("账号等级");
        detail.setType(MsgTypeAccountTypeEnum.level);
        detail.setUser(new UserInfo(uid));
        detail.setCreateTime(new Date());
        detail.setRead(false);
        return detail;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/util/factory/MsgInviteDetailFactory.java
New file
@@ -0,0 +1,89 @@
package org.fanli.facade.user.util.factory;
import java.util.Date;
import org.fanli.facade.user.entity.invite.ThreeSale;
import org.fanli.facade.user.entity.invite.msg.MsgInviteDetail;
import org.fanli.facade.user.entity.invite.msg.MsgInviteDetail.MsgTypeInviteTypeEnum;
import org.yeshi.utils.StringUtil;
import com.yeshi.fanli.base.entity.user.UserInfo;
public class MsgInviteDetailFactory {
    /**
     * 邀请成功
     *
     * @param threeSale
     * @param uid
     * @return
     */
    public static MsgInviteDetail createInviteSuccess(ThreeSale threeSale, Long uid, String beiZhu) {
        if (threeSale == null || uid == null)
            return null;
        MsgInviteDetail detail = new MsgInviteDetail();
        if (StringUtil.isNullOrEmpty(beiZhu))
            detail.setBeiZhu("无");
        else
            detail.setBeiZhu(beiZhu);
        detail.setCreateTime(new Date());
        detail.setDesc("恭喜你,成功邀请一个队员");
        detail.setInviteUser(threeSale);
        detail.setMsgType(MsgTypeInviteTypeEnum.invite);
        detail.setRead(false);
        detail.setUser(new UserInfo(uid));
        return detail;
    }
    /**
     * 扫描邀请二维码成功,但是未登录
     *
     * @param threeSale
     * @param uid
     * @return
     */
    public static MsgInviteDetail createInviteScanSuccess(ThreeSale threeSale, Long uid, String beiZhu) {
        if (threeSale == null || uid == null)
            return null;
        MsgInviteDetail detail = new MsgInviteDetail();
        if (StringUtil.isNullOrEmpty(beiZhu))
            detail.setBeiZhu("无");
        else
            detail.setBeiZhu(beiZhu);
        detail.setCreateTime(new Date());
        detail.setDesc("恭喜你,有新队员加入你的队列,若对方60天内未激活将会与你脱离邀请关系");
        detail.setInviteUser(threeSale);
        detail.setMsgType(MsgTypeInviteTypeEnum.invite);
        detail.setRead(false);
        detail.setUser(new UserInfo(uid));
        return detail;
    }
    /**
     * 邀请失败
     *
     * @param threeSale
     * @param uid
     * @return
     */
    public static MsgInviteDetail createInviteFail(ThreeSale threeSale, Long uid, String beiZhu) {
        if (threeSale == null || uid == null)
            return null;
        MsgInviteDetail detail = new MsgInviteDetail();
        if (StringUtil.isNullOrEmpty(beiZhu))
            detail.setBeiZhu("无");
        else
            detail.setBeiZhu(beiZhu);
        detail.setCreateTime(new Date());
        detail.setDesc("抱歉,该队员因60天内未激活,已脱离了你的队列,可以试着重新邀请");
        detail.setInviteUser(threeSale);
        detail.setMsgType(MsgTypeInviteTypeEnum.invite);
        detail.setRead(false);
        detail.setUser(new UserInfo(uid));
        return detail;
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/util/typehandler/MsgTypeAccountTypeEnumHandler.java
New file
@@ -0,0 +1,52 @@
package org.fanli.facade.user.util.typehandler;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.fanli.facade.user.entity.account.msg.MsgAccountDetail.MsgTypeAccountTypeEnum;
public class MsgTypeAccountTypeEnumHandler extends BaseTypeHandler<MsgTypeAccountTypeEnum> {
    @Override
    public MsgTypeAccountTypeEnum getNullableResult(ResultSet arg0, String arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            return MsgTypeAccountTypeEnum.valueOf(key);
        }
    }
    @Override
    public MsgTypeAccountTypeEnum getNullableResult(ResultSet arg0, int arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            // 根据数据库中的key值,定位SexEnum子类
            return MsgTypeAccountTypeEnum.valueOf(key);
        }
    }
    @Override
    public MsgTypeAccountTypeEnum getNullableResult(CallableStatement arg0, int arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            // 根据数据库中的key值,定位SexEnum子类
            return MsgTypeAccountTypeEnum.valueOf(key);
        }
    }
    @Override
    public void setNonNullParameter(PreparedStatement arg0, int arg1, MsgTypeAccountTypeEnum arg2, JdbcType arg3)
            throws SQLException {
        arg0.setString(arg1, arg2.name());
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/util/typehandler/MsgTypeInviteTypeEnumHandler.java
New file
@@ -0,0 +1,52 @@
package org.fanli.facade.user.util.typehandler;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.fanli.facade.user.entity.invite.msg.MsgInviteDetail.MsgTypeInviteTypeEnum;
public class MsgTypeInviteTypeEnumHandler extends BaseTypeHandler<MsgTypeInviteTypeEnum> {
    @Override
    public MsgTypeInviteTypeEnum getNullableResult(ResultSet arg0, String arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            return MsgTypeInviteTypeEnum.valueOf(key);
        }
    }
    @Override
    public MsgTypeInviteTypeEnum getNullableResult(ResultSet arg0, int arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            // 根据数据库中的key值,定位SexEnum子类
            return MsgTypeInviteTypeEnum.valueOf(key);
        }
    }
    @Override
    public MsgTypeInviteTypeEnum getNullableResult(CallableStatement arg0, int arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            // 根据数据库中的key值,定位SexEnum子类
            return MsgTypeInviteTypeEnum.valueOf(key);
        }
    }
    @Override
    public void setNonNullParameter(PreparedStatement arg0, int arg1, MsgTypeInviteTypeEnum arg2, JdbcType arg3)
            throws SQLException {
        arg0.setString(arg1, arg2.name());
    }
}
fanli-facade-user/src/main/java/org/fanli/facade/user/util/wx/WXLoginUtil.java
New file
@@ -0,0 +1,170 @@
package org.fanli.facade.user.util.wx;
import org.fanli.facade.user.dto.wx.WeiXinUser;
import org.fanli.facade.user.dto.wx.WeiXinUserParam;
import org.json.JSONException;
import org.json.JSONObject;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.entity.FileUploadResult;
import org.yeshi.utils.tencentcloud.COSManager;
import com.yeshi.fanli.base.Constant;
import com.yeshi.fanli.base.log.LogHelper;
public class WXLoginUtil {
    public static String WEXIN_APPID = "wx43617e2ed82c5b28";
    public static String WEXIN_SECRET = "f8a65908fb4681bdd181de70f6ab9a3b";
    static String APPID = "wx5c0d167c6e3ad726";
    static String SECRET = "0c79d5869bb0f2d7c13e43f9a18f440d";
    static {
        WEXIN_APPID = Constant.systemCommonConfig.getWxGZAppId();
        WEXIN_SECRET = Constant.systemCommonConfig.getWxGZAppSecret();
        APPID = Constant.systemCommonConfig.getWxOpenAppId();
        SECRET = Constant.systemCommonConfig.getWxOpenAppSecret();
    }
    // 通过code获取access_token openId
    private static String weiXinUrl1 = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code";
    public static String weiXinUrl2 = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN";
    public static WeiXinUserParam getWxParam(String code) {
        String wxUrl = String.format(weiXinUrl1, APPID, SECRET, code);
        String result = HttpUtil.get(wxUrl);
        WeiXinUserParam weiXinUserParam = getWeiXinUserParam(result);
        return weiXinUserParam;
    }
    public static WeiXinUserParam getWxWYParam(String code) {
        String wxUrl = String.format(weiXinUrl1, WEXIN_APPID, WEXIN_SECRET, code);
        String result = HttpUtil.get(wxUrl);
        WeiXinUserParam weiXinUserParam = getWeiXinUserParam(result);
        return weiXinUserParam;
    }
    public static WeiXinUser getWeiXinUser(WeiXinUserParam param) {
        String result = HttpUtil.getAsString(String.format(weiXinUrl2, param.getAccessToken(), param.getOpenId()),
                "ISO-8859-1", "UTF-8");
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        String nickname = jsonObject.optString("nickname");
        String province = jsonObject.optString("province");
        String city = jsonObject.optString("city");
        String country = jsonObject.optString("country");
        String headimgurl = jsonObject.optString("headimgurl");
        String unionid = jsonObject.optString("unionid");
        int sex = jsonObject.optInt("sex");
        WeiXinUser weiXinUser = new WeiXinUser();
        weiXinUser.setCity(city);
        weiXinUser.setCountry(country);
        weiXinUser.setHeadimgurl(headimgurl);
        weiXinUser.setNickname(nickname);
        weiXinUser.setOpenid(param.getOpenId());
        weiXinUser.setSex(sex);
        weiXinUser.setUnionid(unionid);
        weiXinUser.setProvince(province);
        return weiXinUser;
    }
    private static WeiXinUser getWeiXinUser(String code) {
        WeiXinUserParam param = getWxParam(code);
        if (param == null) {
            return null;
        }
        WeiXinUser weiXinUser = getWeiXinUser(param);
        if (weiXinUser != null && StringUtil.isNullOrEmpty(weiXinUser.getUnionid())
                && !StringUtil.isNullOrEmpty(param.getUnionId())) {
            weiXinUser.setUnionid(param.getUnionId());
        }
        return weiXinUser;
    }
    /**
     * 通过code获取用户信息(伴随头像缓存)
     *
     * @param code
     * @return
     */
    public static WeiXinUser getWeiXinUserWithSavePortrait(String code) {
        WeiXinUser user = getWeiXinUser(code);
        if (user != null) {
            if (!StringUtil.isNullOrEmpty(user.getHeadimgurl())) {
                FileUploadResult result = COSManager.getInstance().uploadFile(
                        HttpUtil.getAsInputStream(user.getHeadimgurl()),
                        String.format("/portrait/wx/%s_%s.jpg", user.getUnionid(), System.currentTimeMillis() + ""));
                if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) {
                    user.setHeadimgurl(result.getUrl());
                    // COS删除其余头像
                    // String prefix = String.format("/portrait/wx/%s_",
                    // user.getUnionid());
                    // ObjectListing list =
                    // COSManager.getInstance().getObjectList(prefix, null, 30);
                    // if (list != null && list.getObjectSummaries() != null)
                    // for (COSObjectSummary object : list.getObjectSummaries())
                    // {
                    // if (!result.getUrl().contains(object.getKey())) {
                    // COSManager.getInstance().deleteFile(object.getKey());
                    // }
                    // }
                }
            }
        }
        return user;
    }
    public static WeiXinUser getWeiXinWYUser(String code) {
        WeiXinUserParam param = getWxWYParam(code);
        if (param == null) {
            return null;
        }
        return getWeiXinUser(param);
    }
    private static WeiXinUserParam getWeiXinUserParam(String result) {
        LogHelper.test(result);
        WeiXinUserParam weiXinUserParam = new WeiXinUserParam();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(result);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        String openId = jsonObject.optString("openid");
        if ("".equals(openId)) {
            return null;
        }
        String accessToken = jsonObject.optString("access_token");
        String refreshToken = jsonObject.optString("refresh_token");
        String scope = jsonObject.optString("scope");
        int expires = jsonObject.optInt("expires_in");
        String unionId = jsonObject.optString("unionid");
        weiXinUserParam.setRefreshToken(refreshToken);
        weiXinUserParam.setOpenId(openId);
        weiXinUserParam.setExpires(expires);
        weiXinUserParam.setAccessToken(accessToken);
        weiXinUserParam.setScope(scope);
        weiXinUserParam.setUnionId(unionId);
        return weiXinUserParam;
    }
    /**
     * 初始化公众号自定义菜单
     */
    public static void initGZMenu() {
        JSONObject root = new JSONObject();
        // WXUtil.createMenu(accessToken, root);
    }
}
fanli-facade-user/src/test/java/org/fanli/facade/user/AppTest.java
File was deleted
fanli-service-goods/src/main/java/com/yeshi/fanli/goods/service/impl/recommend/DynamicRecommendServiceImpl.java
@@ -13,7 +13,7 @@
import org.fanli.facade.goods.service.recommend.DynamicRecommendService;
import org.fanli.facade.goods.service.recommend.RecommendDetailsService;
import org.fanli.facade.goods.service.recommend.RecommendLikeService;
import org.fanli.facade.user.service.UserInfoService;
import org.fanli.facade.user.service.account.UserInfoService;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
fanli-service-goods/src/main/java/com/yeshi/fanli/goods/service/impl/recommend/RecommendDetailsServiceImpl.java
@@ -10,7 +10,7 @@
import org.fanli.facade.goods.entity.recommend.RecommendDetails;
import org.fanli.facade.goods.entity.recommend.RecommendReply;
import org.fanli.facade.goods.service.recommend.RecommendDetailsService;
import org.fanli.facade.user.service.UserInfoService;
import org.fanli.facade.user.service.account.UserInfoService;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
fanli-service-goods/src/main/java/com/yeshi/fanli/goods/service/impl/recommend/RecommendReplyServiceImpl.java
@@ -11,7 +11,8 @@
import org.fanli.facade.goods.service.recommend.DynamicRecommendService;
import org.fanli.facade.goods.service.recommend.RecommendDetailsService;
import org.fanli.facade.goods.service.recommend.RecommendReplyService;
import org.fanli.facade.user.service.UserInfoService;
import org.fanli.facade.user.service.account.UserInfoService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;
fanli-service-goods/src/main/java/com/yeshi/fanli/goods/service/impl/usergoods/ShareGoodsServiceImpl.java
@@ -29,7 +29,7 @@
import org.fanli.facade.system.dto.taobao.TaoKeAppInfo;
import org.fanli.facade.system.service.common.ConfigService;
import org.fanli.facade.system.service.hongbao.HongBaoManageService;
import org.fanli.facade.user.service.UserAccountService;
import org.fanli.facade.user.service.account.UserAccountService;
import org.springframework.stereotype.Service;
import org.yeshi.utils.FileUtil;
import org.yeshi.utils.HttpUtil;
fanli-service-goods/src/main/java/com/yeshi/fanli/goods/service/impl/usergoods/UserShareGoodsRecordServiceImpl.java
@@ -30,8 +30,8 @@
import org.fanli.facade.system.exception.TaoKeApiException;
import org.fanli.facade.system.service.common.ConfigService;
import org.fanli.facade.system.service.hongbao.HongBaoManageService;
import org.fanli.facade.user.service.UserAccountService;
import org.fanli.facade.user.service.UserInfoService;
import org.fanli.facade.user.service.account.UserAccountService;
import org.fanli.facade.user.service.account.UserInfoService;
import org.springframework.core.task.TaskExecutor;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.HttpUtil;
fanli-service-order/src/main/webapp/WEB-INF/web.xml
New file
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:web="http://java.sun.com/xml/ns/javaee"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5" metadata-complete="true">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:/spring.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>enabled</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- druid -->
    <servlet>
        <servlet-name>DruidStatView</servlet-name>
        <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
        <init-param>
            <!-- 允许清空统计数据 -->
            <param-name>resetEnable</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <!-- 用户名 -->
            <param-name>loginUsername</param-name>
            <param-value>yeshi</param-value>
        </init-param>
        <init-param>
            <!-- 密码 -->
            <param-name>loginPassword</param-name>
            <param-value>yeshi2016</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>DruidStatView</servlet-name>
        <url-pattern>/druid/*</url-pattern>
    </servlet-mapping>
    <filter>
        <filter-name>DruidWebStatFilter</filter-name>
        <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
        <init-param>
            <param-name>exclusions</param-name>
            <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>DruidWebStatFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
fanli-service-system/src/main/java/com/yeshi/fanli/system/dao/msg/SystemZnxMapper.java
New file
@@ -0,0 +1,18 @@
package com.yeshi.fanli.system.dao.msg;
import java.util.List;
import org.fanli.facade.system.entity.msg.SystemZnx;
import com.yeshi.fanli.base.BaseMapper;
public interface SystemZnxMapper extends BaseMapper<SystemZnx> {
    /**
     * 根据最小创建时间获取列表
     * @param createTime
     * @return
     */
    List<SystemZnx> listByMinCreateTime(long createTime);
}
fanli-service-system/src/main/java/com/yeshi/fanli/system/dao/msg/UserMsgUnReadNumMapper.java
New file
@@ -0,0 +1,11 @@
package com.yeshi.fanli.system.dao.msg;
import org.fanli.facade.system.entity.msg.UserMsgUnReadNum;
import com.yeshi.fanli.base.BaseMapper;
public interface UserMsgUnReadNumMapper extends BaseMapper<UserMsgUnReadNum> {
    UserMsgUnReadNum selectByUid(Long uid);
}
fanli-service-system/src/main/java/com/yeshi/fanli/system/dao/msg/UserSystemMsgMapper.java
New file
@@ -0,0 +1,52 @@
package com.yeshi.fanli.system.dao.msg;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.fanli.facade.system.entity.msg.UserSystemMsg;
import com.yeshi.fanli.base.BaseMapper;
public interface UserSystemMsgMapper extends BaseMapper<UserSystemMsg> {
    /**
     * 用户系统消息列表
     *
     * @param uid
     * @param start
     * @param count
     * @return
     */
    List<UserSystemMsg> listByUid(@Param("uid") Long uid, @Param("start") long start, @Param("count") int count);
    /**
     * 用户系统消息数量
     *
     * @param uid
     * @return
     */
    Long countByUid(@Param("uid") Long uid);
    /**
     * 根据系统站内信的ID获取消息
     *
     * @param id
     * @return
     */
    UserSystemMsg selectBySystemZNXId(@Param("id") Long id);
    /**
     * 获取最近一条消息
     *
     * @param uid
     * @return
     */
    UserSystemMsg selectLatestUserSystemMsg(@Param("uid") Long uid);
    /**
     * 设置消息已读时
     *
     * @param uid
     */
    void setMsgReadByUid(Long uid);
}
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/msg/SystemZnxMapper.xml
New file
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeshi.fanli.system.dao.msg.SystemZnxMapper">
    <resultMap id="BaseResultMap" type="org.fanli.facade.system.entity.msg.SystemZnx">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="title" property="title" jdbcType="VARCHAR" />
        <result column="content" property="content" jdbcType="VARCHAR" />
        <result column="createTime" property="createTime" jdbcType="BIGINT" />
    </resultMap>
    <sql id="Base_Column_List">id,title,content,createTime</sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_system_msg where id = #{id,jdbcType=BIGINT}
    </select>
    <select id="listByMinCreateTime" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_system_msg where createTime >= #{0}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_system_msg where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="org.fanli.facade.system.entity.msg.SystemZnx"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_system_msg
        (id,title,content,createTime) values
        (#{id,jdbcType=BIGINT},#{title,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR},#{createTime,jdbcType=BIGINT})
    </insert>
    <insert id="insertSelective" parameterType="org.fanli.facade.system.entity.msg.SystemZnx"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_system_msg
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="createTime != null">createTime,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="title != null">#{title,jdbcType=VARCHAR},</if>
            <if test="content != null">#{content,jdbcType=VARCHAR},</if>
            <if test="createTime != null">#{createTime,jdbcType=BIGINT},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="org.fanli.facade.system.entity.msg.SystemZnx">update
        yeshi_ec_system_msg set title = #{title,jdbcType=VARCHAR},content =
        #{content,jdbcType=VARCHAR},createTime = #{createTime,jdbcType=BIGINT}
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.fanli.facade.system.entity.msg.SystemZnx">
        update yeshi_ec_system_msg
        <set>
            <if test="title != null">title=#{title,jdbcType=VARCHAR},</if>
            <if test="content != null">content=#{content,jdbcType=VARCHAR},</if>
            <if test="createTime != null">createTime=#{createTime,jdbcType=BIGINT},</if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/msg/UserMsgUnReadNumMapper.xml
New file
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeshi.fanli.system.dao.msg.UserMsgUnReadNumMapper">
    <resultMap id="BaseResultMap"
        type="org.fanli.facade.system.entity.msg.UserMsgUnReadNum">
        <id column="mrs_id" property="id" jdbcType="BIGINT" />
        <result column="mrs_type_order" property="typeOrder" jdbcType="INTEGER" />
        <result column="mrs_type_money" property="typeMoney" jdbcType="INTEGER" />
        <result column="mrs_type_account" property="typeAccount"
            jdbcType="INTEGER" />
        <result column="mrs_type_invite" property="typeInvite"
            jdbcType="INTEGER" />
        <result column="mrs_type_score" property="typeScore" jdbcType="INTEGER" />
        <result column="mrs_type_system" property="typeSystem"
            jdbcType="INTEGER" />
        <result column="mrs_create_time" property="createTime"
            jdbcType="TIMESTAMP" />
        <result column="mrs_update_time" property="updateTime"
            jdbcType="TIMESTAMP" />
        <association property="user" column="mrs_uid" javaType="com.yeshi.fanli.base.entity.user.UserInfo">
            <id column="mrs_uid" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    <sql id="Base_Column_List">mrs_id,mrs_uid,mrs_type_order,mrs_type_money,mrs_type_account,mrs_type_invite,mrs_type_score,mrs_type_system,mrs_create_time,mrs_update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_msg_read_state where mrs_id = #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByUid" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_msg_read_state where mrs_uid = #{uid,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_msg_read_state where mrs_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="org.fanli.facade.system.entity.msg.UserMsgUnReadNum"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_msg_read_state
        (mrs_id,mrs_uid,mrs_type_order,mrs_type_money,mrs_type_account,mrs_type_invite,mrs_type_score,mrs_type_system,mrs_create_time,mrs_update_time)
        values
        (#{id,jdbcType=BIGINT},#{user.id,jdbcType=BIGINT},#{typeOrder,jdbcType=INTEGER},#{typeMoney,jdbcType=INTEGER},#{typeAccount,jdbcType=INTEGER},#{typeInvite,jdbcType=INTEGER},#{typeScore,jdbcType=INTEGER},#{typeSystem,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="org.fanli.facade.system.entity.msg.UserMsgUnReadNum"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_msg_read_state
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">mrs_id,</if>
            <if test="user != null">mrs_uid,</if>
            <if test="typeOrder != null">mrs_type_order,</if>
            <if test="typeMoney != null">mrs_type_money,</if>
            <if test="typeAccount != null">mrs_type_account,</if>
            <if test="typeInvite != null">mrs_type_invite,</if>
            <if test="typeScore != null">mrs_type_score,</if>
            <if test="typeSystem != null">mrs_type_system,</if>
            <if test="createTime != null">mrs_create_time,</if>
            <if test="updateTime != null">mrs_update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="user != null">#{user.id,jdbcType=BIGINT},</if>
            <if test="typeOrder != null">#{typeOrder,jdbcType=INTEGER},</if>
            <if test="typeMoney != null">#{typeMoney,jdbcType=INTEGER},</if>
            <if test="typeAccount != null">#{typeAccount,jdbcType=INTEGER},</if>
            <if test="typeInvite != null">#{typeInvite,jdbcType=INTEGER},</if>
            <if test="typeScore != null">#{typeScore,jdbcType=INTEGER},</if>
            <if test="typeSystem != null">#{typeSystem,jdbcType=INTEGER},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="org.fanli.facade.system.entity.msg.UserMsgUnReadNum">update
        yeshi_ec_msg_read_state set mrs_uid =
        #{user.id,jdbcType=BIGINT},mrs_type_order =
        #{typeOrder,jdbcType=INTEGER},mrs_type_money =
        #{typeMoney,jdbcType=INTEGER},mrs_type_account =
        #{typeAccount,jdbcType=INTEGER},mrs_type_invite =
        #{typeInvite,jdbcType=INTEGER},mrs_type_score =
        #{typeScore,jdbcType=INTEGER},mrs_type_system =
        #{typeSystem,jdbcType=INTEGER},mrs_create_time =
        #{createTime,jdbcType=TIMESTAMP},mrs_update_time =
        #{updateTime,jdbcType=TIMESTAMP} where mrs_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.fanli.facade.system.entity.msg.UserMsgUnReadNum">
        update yeshi_ec_msg_read_state
        <set>
            <if test="user != null">mrs_uid=#{user.id,jdbcType=BIGINT},</if>
            <if test="typeOrder != null">mrs_type_order=#{typeOrder,jdbcType=INTEGER},</if>
            <if test="typeMoney != null">mrs_type_money=#{typeMoney,jdbcType=INTEGER},</if>
            <if test="typeAccount != null">mrs_type_account=#{typeAccount,jdbcType=INTEGER},</if>
            <if test="typeInvite != null">mrs_type_invite=#{typeInvite,jdbcType=INTEGER},</if>
            <if test="typeScore != null">mrs_type_score=#{typeScore,jdbcType=INTEGER},</if>
            <if test="typeSystem != null">mrs_type_system=#{typeSystem,jdbcType=INTEGER},</if>
            <if test="createTime != null">mrs_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">mrs_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where mrs_id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
fanli-service-system/src/main/java/com/yeshi/fanli/system/mapping/msg/UserSystemMsgMapper.xml
New file
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeshi.fanli.system.dao.msg.UserSystemMsgMapper">
    <resultMap id="BaseResultMap"
        type="org.fanli.facade.system.entity.msg.UserSystemMsg">
        <id column="ms_id" property="id" jdbcType="BIGINT" />
        <result column="ms_type" property="type"
            typeHandler="com.yeshi.fanli.system.utils.typehandler.UserSystemMsgTypeEnumHandler" />
        <result column="ms_read" property="read" jdbcType="BOOLEAN" />
        <result column="ms_solved" property="solved" jdbcType="BOOLEAN" />
        <result column="ms_title" property="title" jdbcType="VARCHAR" />
        <result column="ms_content" property="content" jdbcType="VARCHAR" />
        <result column="ms_time_tag" property="timeTag" jdbcType="INTEGER" />
        <result column="ms_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="ms_update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <association property="user" column="ms_uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="ms_uid" property="id" jdbcType="BIGINT" />
        </association>
        <association property="systemZNX" column="ms_system_znx_id"
            select="com.yeshi.fanli.dao.mybatis.msg.SystemZnxMapper.selectByPrimaryKey">
        </association>
    </resultMap>
    <sql id="Base_Column_List">ms_id,ms_uid,ms_type,ms_system_znx_id,ms_read,ms_solved,ms_title,ms_content,ms_time_tag,ms_create_time,ms_update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user_msg_system where ms_id = #{id,jdbcType=BIGINT}
    </select>
    <select id="listByUid" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user_msg_system where ms_uid = #{uid,jdbcType=BIGINT}
        order by ms_create_time desc limit #{start},#{count}
    </select>
    <select id="countByUid" resultType="java.lang.Long"
        parameterType="java.lang.Long">
        select
        count(ms_id)
        from yeshi_ec_user_msg_system where
        ms_uid =
        #{uid,jdbcType=BIGINT}
    </select>
    <select id="selectBySystemZNXId" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user_msg_system where ms_system_znx_id =
        #{id,jdbcType=BIGINT}
    </select>
    <select id="selectLatestUserSystemMsg" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user_msg_system where ms_uid = #{uid} order by
        ms_create_time desc limit 1
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_user_msg_system where ms_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="org.fanli.facade.system.entity.msg.UserSystemMsg"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_user_msg_system
        (ms_id,ms_uid,ms_type,ms_system_znx_id,ms_read,ms_solved,ms_title,ms_content,ms_time_tag,ms_create_time,ms_update_time)
        values
        (#{id,jdbcType=BIGINT},#{user.id,jdbcType=BIGINT},#{type,jdbcType=VARCHAR},#{systemZNX.id,jdbcType=BIGINT},#{read,jdbcType=BOOLEAN},#{solved,jdbcType=BOOLEAN},#{title,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR},#{timeTag,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="org.fanli.facade.system.entity.msg.UserSystemMsg"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_user_msg_system
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">ms_id,</if>
            <if test="user != null">ms_uid,</if>
            <if test="type != null">ms_type,</if>
            <if test="systemZNX != null">ms_system_znx_id,</if>
            <if test="read != null">ms_read,</if>
            <if test="solved != null">ms_solved,</if>
            <if test="title != null">ms_title,</if>
            <if test="content != null">ms_content,</if>
            <if test="timeTag != null">ms_time_tag,</if>
            <if test="createTime != null">ms_create_time,</if>
            <if test="updateTime != null">ms_update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="user != null">#{user.id,jdbcType=BIGINT},</if>
            <if test="type != null">#{type,jdbcType=VARCHAR},</if>
            <if test="systemZNX != null">#{systemZNX.id,jdbcType=BIGINT},</if>
            <if test="read != null">#{read,jdbcType=BOOLEAN},</if>
            <if test="solved != null">#{solved,jdbcType=BOOLEAN},</if>
            <if test="title != null">#{title,jdbcType=VARCHAR},</if>
            <if test="content != null">#{content,jdbcType=VARCHAR},</if>
            <if test="timeTag != null">#{timeTag,jdbcType=INTEGER},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="org.fanli.facade.system.entity.msg.UserSystemMsg">update
        yeshi_ec_user_msg_system set ms_uid =
        #{user.id,jdbcType=BIGINT},ms_type =
        #{type,jdbcType=VARCHAR},ms_system_znx_id =
        #{systemZNX.id,jdbcType=BIGINT},ms_read =
        #{read,jdbcType=BOOLEAN},ms_solved =
        #{solved,jdbcType=BOOLEAN},ms_title =
        #{title,jdbcType=VARCHAR},ms_content =
        #{content,jdbcType=VARCHAR},ms_time_tag =
        #{timeTag,jdbcType=INTEGER},ms_create_time =
        #{createTime,jdbcType=TIMESTAMP},ms_update_time =
        #{updateTime,jdbcType=TIMESTAMP} where ms_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.fanli.facade.system.entity.msg.UserSystemMsg">
        update yeshi_ec_user_msg_system
        <set>
            <if test="user != null">ms_uid=#{user.id,jdbcType=BIGINT},</if>
            <if test="type != null">ms_type=#{type,jdbcType=VARCHAR},</if>
            <if test="systemZNX != null">ms_system_znx_id=#{systemZNX.id,jdbcType=BIGINT},</if>
            <if test="read != null">ms_read=#{read,jdbcType=BOOLEAN},</if>
            <if test="solved != null">ms_solved=#{solved,jdbcType=BOOLEAN},</if>
            <if test="title != null">ms_title=#{title,jdbcType=VARCHAR},</if>
            <if test="content != null">ms_content=#{content,jdbcType=VARCHAR},</if>
            <if test="timeTag != null">ms_time_tag=#{timeTag,jdbcType=INTEGER},</if>
            <if test="createTime != null">ms_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">ms_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where ms_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="setMsgReadByUid" parameterType="java.lang.Long">
        update
        yeshi_ec_user_msg_system set ms_read=1 where ms_uid=#{0}
    </update>
</mapper>
fanli-service-system/src/main/java/com/yeshi/fanli/system/service/impl/msg/SystemZnxServiceImpl.java
New file
@@ -0,0 +1,32 @@
package com.yeshi.fanli.system.service.impl.msg;
import java.util.List;
import javax.annotation.Resource;
import org.fanli.facade.system.entity.msg.SystemZnx;
import org.fanli.facade.system.service.msg.SystemZnxService;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.system.dao.msg.SystemZnxMapper;
@Service
public class SystemZnxServiceImpl implements SystemZnxService {
    @Resource
    private SystemZnxMapper systemZnxMapper;
    /**
     * 插入数据
     */
    @Override
    public void save(SystemZnx systemZnx) {
        systemZnxMapper.insertSelective(systemZnx);
    }
    @Override
    public List<SystemZnx> listByMinCreateTime(long createTime) {
        return null;
    }
}
fanli-service-system/src/main/java/com/yeshi/fanli/system/service/impl/msg/UserMsgReadStateServiceImpl.java
New file
@@ -0,0 +1,169 @@
package com.yeshi.fanli.system.service.impl.msg;
import java.util.Date;
import javax.annotation.Resource;
import org.fanli.facade.system.entity.msg.UserMsgUnReadNum;
import org.fanli.facade.system.service.msg.UserMsgReadStateService;
import org.fanli.facade.system.service.msg.UserSystemMsgService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yeshi.fanli.base.entity.user.UserInfo;
import com.yeshi.fanli.system.dao.msg.UserMsgUnReadNumMapper;
@Service
public class UserMsgReadStateServiceImpl implements UserMsgReadStateService {
    @Resource
    private UserMsgUnReadNumMapper userMsgUnReadNumMapper;
    @Resource
    private UserSystemMsgService userSystemMsgService;
    private UserMsgUnReadNum getUserMsgUnReadNum(Long uid) {
        UserMsgUnReadNum userMsgUnReadNum = userMsgUnReadNumMapper.selectByUid(uid);
        if (userMsgUnReadNum == null) {
            UserMsgUnReadNum um = new UserMsgUnReadNum();
            um.setCreateTime(new Date());
            um.setUser(new UserInfo(uid));
            userMsgUnReadNumMapper.insertSelective(um);
            return userMsgUnReadNumMapper.selectByPrimaryKey(um.getId());
        }
        return userMsgUnReadNum;
    }
    @Override
    public void addOrderMsgUnReadCount(Long uid, int count) {
        UserMsgUnReadNum num = getUserMsgUnReadNum(uid);
        UserMsgUnReadNum update = new UserMsgUnReadNum();
        update.setId(num.getId());
        update.setTypeOrder(num.getTypeOrder() + count);
        update.setUpdateTime(new Date());
        userMsgUnReadNumMapper.updateByPrimaryKeySelective(update);
    }
    @Override
    public void addAccountMsgUnReadCount(Long uid, int count) {
        UserMsgUnReadNum num = getUserMsgUnReadNum(uid);
        UserMsgUnReadNum update = new UserMsgUnReadNum();
        update.setId(num.getId());
        update.setTypeAccount(num.getTypeAccount() + count);
        update.setUpdateTime(new Date());
        userMsgUnReadNumMapper.updateByPrimaryKeySelective(update);
    }
    @Override
    public void addMoneyMsgUnReadCount(Long uid, int count) {
        UserMsgUnReadNum num = getUserMsgUnReadNum(uid);
        UserMsgUnReadNum update = new UserMsgUnReadNum();
        update.setId(num.getId());
        update.setTypeMoney(num.getTypeMoney() + count);
        update.setUpdateTime(new Date());
        userMsgUnReadNumMapper.updateByPrimaryKeySelective(update);
    }
    @Override
    public void addInviteMsgUnReadCount(Long uid, int count) {
        UserMsgUnReadNum num = getUserMsgUnReadNum(uid);
        UserMsgUnReadNum update = new UserMsgUnReadNum();
        update.setId(num.getId());
        update.setTypeInvite(num.getTypeInvite() + count);
        update.setUpdateTime(new Date());
        userMsgUnReadNumMapper.updateByPrimaryKeySelective(update);
    }
    @Override
    public void addSystemMsgUnReadCount(Long uid, int count) {
        UserMsgUnReadNum num = getUserMsgUnReadNum(uid);
        UserMsgUnReadNum update = new UserMsgUnReadNum();
        update.setId(num.getId());
        update.setTypeSystem(num.getTypeSystem() + count);
        update.setUpdateTime(new Date());
        userMsgUnReadNumMapper.updateByPrimaryKeySelective(update);
    }
    @Override
    public UserMsgUnReadNum getReadStateByUid(Long uid) {
        return getUserMsgUnReadNum(uid);
    }
    @Transactional
    @Override
    public void readOrderMsg(Long uid) {
        UserMsgUnReadNum num = getUserMsgUnReadNum(uid);
        UserMsgUnReadNum update = new UserMsgUnReadNum();
        update.setId(num.getId());
        update.setTypeOrder(0);
        update.setUpdateTime(new Date());
        userMsgUnReadNumMapper.updateByPrimaryKeySelective(update);
    }
    @Transactional
    @Override
    public void readAccountMsg(Long uid) {
        UserMsgUnReadNum num = getUserMsgUnReadNum(uid);
        UserMsgUnReadNum update = new UserMsgUnReadNum();
        update.setId(num.getId());
        update.setTypeAccount(0);
        update.setUpdateTime(new Date());
        userMsgUnReadNumMapper.updateByPrimaryKeySelective(update);
    }
    @Transactional
    @Override
    public void readMoneyMsg(Long uid) {
        UserMsgUnReadNum num = getUserMsgUnReadNum(uid);
        UserMsgUnReadNum update = new UserMsgUnReadNum();
        update.setId(num.getId());
        update.setTypeMoney(0);
        update.setUpdateTime(new Date());
        userMsgUnReadNumMapper.updateByPrimaryKeySelective(update);
    }
    @Transactional
    @Override
    public void readInviteMsg(Long uid) {
        UserMsgUnReadNum num = getUserMsgUnReadNum(uid);
        UserMsgUnReadNum update = new UserMsgUnReadNum();
        update.setId(num.getId());
        update.setTypeInvite(0);
        update.setUpdateTime(new Date());
        userMsgUnReadNumMapper.updateByPrimaryKeySelective(update);
    }
    @Transactional
    @Override
    public void readUserSystemMsg(Long uid) {
        userSystemMsgService.readMsgByUid(uid);
        UserMsgUnReadNum num = getUserMsgUnReadNum(uid);
        UserMsgUnReadNum update = new UserMsgUnReadNum();
        update.setId(num.getId());
        update.setTypeSystem(0);
        update.setUpdateTime(new Date());
        userMsgUnReadNumMapper.updateByPrimaryKeySelective(update);
    }
    @Transactional
    @Override
    public void setAllMsgRead(Long uid) {
        UserMsgUnReadNum userMsgNum = getUserMsgUnReadNum(uid);
        UserMsgUnReadNum update = new UserMsgUnReadNum();
        update.setId(userMsgNum.getId());
        update.setTypeAccount(0);
        update.setTypeInvite(0);
        update.setTypeMoney(0);
        update.setTypeOrder(0);
        update.setTypeScore(0);
        update.setTypeSystem(0);
        update.setUpdateTime(new Date());
        userMsgUnReadNumMapper.updateByPrimaryKeySelective(update);
        readAccountMsg(uid);
        readOrderMsg(uid);
        readMoneyMsg(uid);
        readInviteMsg(uid);
        readUserSystemMsg(uid);
    }
}
fanli-service-system/src/main/java/com/yeshi/fanli/system/service/impl/msg/UserSystemMsgServiceImpl.java
New file
@@ -0,0 +1,131 @@
package com.yeshi.fanli.system.service.impl.msg;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.fanli.facade.system.entity.msg.SystemZnx;
import org.fanli.facade.system.entity.msg.UserSystemMsg;
import org.fanli.facade.system.entity.msg.UserSystemMsgTypeEnum;
import org.fanli.facade.system.exception.msg.UserSystemMsgException;
import org.fanli.facade.system.service.msg.SystemZnxService;
import org.fanli.facade.system.service.msg.UserMsgReadStateService;
import org.fanli.facade.system.service.msg.UserSystemMsgService;
import org.springframework.stereotype.Service;
import org.yeshi.utils.StringUtil;
import com.yeshi.fanli.base.entity.user.UserInfo;
import com.yeshi.fanli.system.dao.msg.UserSystemMsgMapper;
@Service
public class UserSystemMsgServiceImpl implements UserSystemMsgService {
    @Resource
    private UserSystemMsgMapper userSystemMsgMapper;
    @Resource
    private UserMsgReadStateService userMsgReadStateService;
    @Resource
    private SystemZnxService systemZnxService;
    @Override
    public void addUserSystemMsg(Long uid, UserSystemMsgTypeEnum type, String title, String content, int timeTag,
            SystemZnx sz) throws UserSystemMsgException {
        if (sz == null && (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content) || uid == null))
            throw new UserSystemMsgException(1, "信息不完整");
        UserSystemMsg msg = new UserSystemMsg();
        if (sz != null) {
            if (userSystemMsgMapper.selectBySystemZNXId(sz.getId()) == null) {
                msg.setCreateTime(new Date(sz.getCreateTime()));
                msg.setRead(false);
                msg.setSolved(false);
                msg.setSystemZNX(sz);
                msg.setUser(new UserInfo(uid));
                msg.setType(type);
                msg.setTimeTag(timeTag);
            } else
                throw new UserSystemMsgException(1, "消息已存在");
        } else {
            msg.setCreateTime(new Date());
            msg.setRead(false);
            msg.setSolved(false);
            msg.setContent(content);
            msg.setTitle(title);
            msg.setUser(new UserInfo(uid));
            msg.setType(type);
            msg.setTimeTag(timeTag);
        }
        userSystemMsgMapper.insertSelective(msg);
        userMsgReadStateService.addSystemMsgUnReadCount(uid, 1);
    }
    @Override
    public UserSystemMsg getLatestUserSystemMsg(Long uid) {
        UserSystemMsg msg = userSystemMsgMapper.selectLatestUserSystemMsg(uid);
        if (msg != null)
            if (msg.getSystemZNX() != null) {
                msg.setTitle(msg.getSystemZNX().getTitle());
                msg.setContent(msg.getSystemZNX().getContent());
            }
        return msg;
    }
    @Override
    public List<UserSystemMsg> listUserSystemMsg(Long uid, int page, int pageSize) {
        List<UserSystemMsg> list = userSystemMsgMapper.listByUid(uid, (page - 1) * pageSize, pageSize);
        if (list != null)
            for (UserSystemMsg msg : list) {
                if (msg.getSystemZNX() != null) {
                    msg.setTitle(msg.getSystemZNX().getTitle());
                    msg.setContent(msg.getSystemZNX().getContent());
                }
            }
        return list;
    }
    @Override
    public long countUserSystemMsg(Long uid) {
        return userSystemMsgMapper.countByUid(uid);
    }
    @Override
    public void setSystemMsgSolved(Long uid, Long id) throws UserSystemMsgException {
        UserSystemMsg msg = userSystemMsgMapper.selectByPrimaryKey(id);
        if (msg.getUser().getId() != uid.longValue())
            throw new UserSystemMsgException(2, "不是自己的消息");
        UserSystemMsg update = new UserSystemMsg();
        update.setId(id);
        update.setSolved(true);
        update.setUpdateTime(new Date());
        userSystemMsgMapper.updateByPrimaryKeySelective(update);
    }
    @Override
    public void readMsgByUid(Long uid) {
        userSystemMsgMapper.setMsgReadByUid(uid);
    }
    @Override
    public void syncSystemZNX(UserInfo user) {
        if (user == null)
            return;
        long createtTime = user.getCreatetime();
        List<SystemZnx> list = systemZnxService.listByMinCreateTime(createtTime);
        if (list != null && list.size() > 0) {
            for (SystemZnx znx : list) {
                UserSystemMsg msg = userSystemMsgMapper.selectBySystemZNXId(znx.getId());
                if (msg == null)
                    try {
                        addUserSystemMsg(user.getId(), UserSystemMsgTypeEnum.common, null, null,
                                UserSystemMsg.TIME_TAG_COMMON, znx);
                    } catch (UserSystemMsgException e) {
                        e.printStackTrace();
                    }
            }
        }
    }
}
fanli-service-system/src/main/java/com/yeshi/fanli/system/utils/typehandler/UserSystemMsgTypeEnumHandler.java
New file
@@ -0,0 +1,52 @@
package com.yeshi.fanli.system.utils.typehandler;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.fanli.facade.system.entity.msg.UserSystemMsgTypeEnum;
public class UserSystemMsgTypeEnumHandler extends BaseTypeHandler<UserSystemMsgTypeEnum> {
    @Override
    public UserSystemMsgTypeEnum getNullableResult(ResultSet arg0, String arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            return UserSystemMsgTypeEnum.valueOf(key);
        }
    }
    @Override
    public UserSystemMsgTypeEnum getNullableResult(ResultSet arg0, int arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            // 根据数据库中的key值,定位SexEnum子类
            return UserSystemMsgTypeEnum.valueOf(key);
        }
    }
    @Override
    public UserSystemMsgTypeEnum getNullableResult(CallableStatement arg0, int arg1) throws SQLException {
        String key = arg0.getString(arg1);
        if (arg0.wasNull()) {
            return null;
        } else {
            // 根据数据库中的key值,定位SexEnum子类
            return UserSystemMsgTypeEnum.valueOf(key);
        }
    }
    @Override
    public void setNonNullParameter(PreparedStatement arg0, int arg1, UserSystemMsgTypeEnum arg2, JdbcType arg3)
            throws SQLException {
        arg0.setString(arg1, arg2.name());
    }
}
fanli-service-user/pom.xml
@@ -28,5 +28,11 @@
            <artifactId>fanli-facade-user</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.yeshi.fanli</groupId>
            <artifactId>fanli-facade-system</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>
fanli-service-user/src/main/java/org/fanli/service/user/App.java
File was deleted
fanli-service-user/src/main/java/org/fanli/service/user/dao/account/UserInfoMapper.java
New file
@@ -0,0 +1,168 @@
package org.fanli.service.user.dao.account;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.yeshi.fanli.base.entity.user.UserInfo;
public interface UserInfoMapper {
    int deleteByPrimaryKey(Long id);
    int insert(UserInfo record);
    int insertSelective(UserInfo record);
    UserInfo selectByPrimaryKey(Long id);
    UserInfo selectByPKey(Long id);
    UserInfo selectByPrimaryKeyForUpdate(Long id);
    int updateByPrimaryKeySelective(UserInfo record);
    int updateByPrimaryKey(UserInfo record);
    // 减掉用户红包金额
    int subHongBaoByUid(@Param("uid") long uid, @Param("money") BigDecimal money);
    // 增加用户红包金额
    int addHongBaoByUid(@Param("uid") long uid, @Param("money") BigDecimal money);
    BigDecimal getNewPeopleHB(Long id);
    BigDecimal getMyHB(Long id);
    // 根据AppId与微信unionID获取用户
    UserInfo getUserInfoByAppIdAndWXUnionId(@Param("appId") String appId, @Param("unionId") String unionId);
    // 根据AppId与淘宝OpenId获取用户
    UserInfo getUserInfoByAppIdAndTaoBaoOpenId(@Param("appId") String appId, @Param("openId") String openId);
    // 根据AppId与电话号码获取用户
    UserInfo getUserInfoByAppIdAndPhone(@Param("appId") String appId, @Param("phone") String phone);
    Long getMaxUid();
    /**
     * 融合账号
     *
     * @param mainUid-主账号
     * @param lessUid-副账号
     */
    void connectUser(@Param("mainUid")Long mainUid,@Param("lessUid") Long lessUid);
    /**
     *
     * @param start
     * @param count
     * @param key  查询条件
     * @param userType  用户类型
     * @param days      天数
     * @param startTime  注册时间 -小
     * @param endTime    注册时间 -大
     * @param orderMode  排序方式
     * @return
     */
    List<UserInfo> query(@Param("start") long start, @Param("count") int count, @Param("key") String key,
            @Param("userType")Integer userType,    @Param("days")Integer days,
            @Param("startTime") String startTime, @Param("endTime") String endTime,
            @Param("orderField") Integer orderField, @Param("orderMode") Integer orderMode);
    long queryCount(@Param("key") String key, @Param("userType")Integer userType,    @Param("days")Integer days,
            @Param("startTime") String startTime, @Param("endTime") String endTime);
    /**
     * 统计当前查询结果总金额
     * @param title
     * @param userType
     * @param days
     * @param startTime
     * @param endTime
     * @return
     */
    double querySumMoney(@Param("key") String key, @Param("userType")Integer userType,    @Param("days")Integer days,
            @Param("startTime") String startTime, @Param("endTime") String endTime);
    /**
     * 统计用户数量
     * @param isToday  统计今日
     * @param isMonth  统计当月  二则不可同时存在
     * @return
     */
    long countNewUser(@Param("isToday") Integer isToday, @Param("isMonth") Integer isMonth);
    /**
     * 根据等级统计用户数量
     * @param rank
     * @return
     */
    long countRank(@Param("rank") Integer rank);
    /**
     * 统计所有用户总金额  或  可提现金额
     * @param minMoney
     * @return
     */
    BigDecimal countAllMoney(@Param("minMoney") Double minMoney);
    /**
     * 超过 daysNum  天未登陆的用户
     * @param minMoney
     * @return
     */
    List<Long> longTimeNoLogin(@Param("daysNum") int daysNum, @Param("list") List<Long> list);
    /**
     * 统计流失用户数量:( num 天未使用登录并且无任何资金流动的账号数量)
     * @param num 180
     * @return
     */
    long countLoseUser(@Param("num") int num);
    /**
     * 累计有购买用户数
     * @return
     */
    long countHasOrderUser();
    /**
     * 统计新增用户
     * @return
     */
    List<Map<String, Object>> countNewUserByDate(@Param("channel")String channel,@Param("type")Integer type, @Param("years") String years,
            @Param("startTime")String startTime, @Param("endTime")String endTime);
    /**
     * 统计新增用户当日产生订单用户数量
     * @return
     */
    List<Map<String, Object>> getTodayHasOrder(@Param("channel")String channel,@Param("type")Integer type, @Param("years") String years,
            @Param("startTime")String startTime, @Param("endTime")String endTime);
    /**
     * 统计新增用户一周产生订单用户数量
     * @return
     */
    Map<String, Object> getWeekHasOrder(@Param("channel")String channel, @Param("startTime")String startTime,
            @Param("endTime")String endTime, @Param("orderNum")Integer orderNum);
    /**
     * 根据电话号码、邀请码获取邀请用户
     * @param phone
     * @param inviteCode
     * @return
     */
    UserInfo getInfoByPhoneOrInviteCode(@Param("phone")String phone, @Param("inviteCode")String inviteCode);
}
fanli-service-user/src/main/java/org/fanli/service/user/dao/account/msg/MsgAccountDetailMapper.java
New file
@@ -0,0 +1,37 @@
package org.fanli.service.user.dao.account.msg;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.fanli.facade.user.entity.account.msg.MsgAccountDetail;
import com.yeshi.fanli.base.BaseMapper;
public interface MsgAccountDetailMapper extends BaseMapper<MsgAccountDetail> {
    /**
     * 根据用户查询消息,根据更新时间倒叙
     *
     * @param uid
     * @param start
     * @param count
     * @return
     */
    List<MsgAccountDetail> listByUid(@Param("uid") Long uid, @Param("start") long start, @Param("count") int count);
    /**
     * 根据用户查询数量
     *
     * @param uid
     * @return
     */
    Long countByUid(@Param("uid") Long uid);
    /**
     * 设置消息已读时
     *
     * @param uid
     */
    void setMsgReadByUid(Long uid);
}
fanli-service-user/src/main/java/org/fanli/service/user/dao/invite/SpreadImgMapper.java
New file
@@ -0,0 +1,18 @@
package org.fanli.service.user.dao.invite;
import java.util.List;
import org.fanli.facade.user.entity.invite.SpreadImg;
import com.yeshi.fanli.base.BaseMapper;
public interface SpreadImgMapper extends BaseMapper<SpreadImg> {
    /**
     * 获取所有
     *
     * @return
     */
    List<SpreadImg> listAll();
}
fanli-service-user/src/main/java/org/fanli/service/user/dao/invite/SpreadUserImgMapper.java
New file
@@ -0,0 +1,26 @@
package org.fanli.service.user.dao.invite;
import java.util.List;
import org.fanli.facade.user.entity.invite.SpreadUserImg;
import com.yeshi.fanli.base.BaseMapper;
public interface SpreadUserImgMapper extends BaseMapper<SpreadUserImg> {
    List<String> getImgUrlList(Long uid);
    int imgUrlCount(Long uid);
    void deleteImgUrl(Long uid);
    /**
     * 根据用户ID查询邀请图
     *
     * @param uid
     * @return
     */
    List<SpreadUserImg> listByUid(Long uid);
}
fanli-service-user/src/main/java/org/fanli/service/user/dao/invite/ThreeSaleExtraInfoMapper.java
New file
@@ -0,0 +1,38 @@
package org.fanli.service.user.dao.invite;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.fanli.facade.user.entity.invite.ThreeSaleExtraInfo;
public interface ThreeSaleExtraInfoMapper {
    int deleteByPrimaryKey(Long id);
    int insert(ThreeSaleExtraInfo record);
    int insertSelective(ThreeSaleExtraInfo record);
    ThreeSaleExtraInfo selectByPrimaryKey(Long id);
    int updateByPrimaryKeySelective(ThreeSaleExtraInfo record);
    int updateByPrimaryKey(ThreeSaleExtraInfo record);
    /**
     * 根据用户id、被邀请id 查询
     * @param bossId
     * @param workerId
     * @return
     */
    List<ThreeSaleExtraInfo> listbyBossIdAndWorkerId(@Param("bossId") Long bossId, @Param("workerId") Long workerId);
    /**
     * 根据用户id、被邀请id删除
     * @param bossId
     * @param workerId
     * @return
     */
    int deleteByBossIdAndWorkerId(@Param("bossId") Long bossId, @Param("workerId") Long workerId);
}
fanli-service-user/src/main/java/org/fanli/service/user/dao/invite/ThreeSaleMapper.java
New file
@@ -0,0 +1,251 @@
package org.fanli.service.user.dao.invite;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.fanli.facade.user.entity.invite.ThreeSale;
import com.yeshi.fanli.base.entity.user.UserInfo;
public interface ThreeSaleMapper {
    int deleteByPrimaryKey(Long id);
    int insert(ThreeSale record);
    int insertSelective(ThreeSale record);
    ThreeSale selectByPrimaryKey(Long id);
    UserInfo selectBoss(Long uid);
    List<ThreeSale> selectByUid(Long uid);
    int updateByPrimaryKeySelective(ThreeSale record);
    int updateByPrimaryKey(ThreeSale record);
    int effectThreeSale(Long workerUid);
    /**
     * 删除失效
     *
     * @param bossId
     * @param workerId
     * @return
     */
    int deleteExpireRecord(@Param("bossId") Long bossId, @Param("workerId") Long workerId);
    /**
     * 失效
     *
     * @param bossId
     * @param workerId
     * @return
     */
    List<ThreeSale> getExpireRecord(@Param("bossId") Long bossId, @Param("workerId") Long workerId);
    /**
     * 查询一度队员集合
     *
     * @param start
     * @param count
     * @param key
     * @param uid
     * @return
     */
    List<ThreeSale> queryMyFirstTeamList(@Param("start") int start, @Param("count") int count, @Param("key") String key,
            @Param("bossId") Long bossId);
    long queryCountMyFirstTeamList(@Param("key") String key, @Param("bossId") Long bossId);
    /**
     * 查询二度队员集合
     *
     * @param start
     * @param count
     * @param key
     * @param uid
     * @return
     */
    List<ThreeSale> queryMySecondTeamList(@Param("start") int start, @Param("count") int count,
            @Param("key") String key, @Param("bossId") Long bossId);
    long queryCountMySecondTeamList(@Param("key") String key, @Param("bossId") Long bossId);
    /**
     * 长时间未邀请成功用户
     *
     * @param daysNum
     * @return
     */
    List<Long> queryLongTimeFailed(@Param("daysNum") int daysNum);
    /**
     * 长时间 邀请成功用户
     *
     * @param daysNum
     * @return
     */
    List<ThreeSale> queryLongTimeSuccess(@Param("daysNum") int daysNum);
    /**
     * 设置对应邀请过期
     *
     * @param list
     * @return
     */
    int updateExpire(List<Long> list);
    /**
     * 一级查询
     *
     * @param start
     * @param count
     * @param key
     * @param startTime
     * @param endTime
     * @return
     */
    List<ThreeSale> listFirstTeamQuery(@Param("start") long start, @Param("count") int count, @Param("uid") Long uid,
            @Param("state") Integer state, @Param("startTime") String startTime, @Param("endTime") String endTime);
    long countFirstTeamQuery(@Param("uid") Long uid, @Param("state") Integer state,
            @Param("startTime") String startTime, @Param("endTime") String endTime);
    /**
     * 二级查询
     *
     * @param start
     * @param count
     * @param key
     * @param startTime
     * @param endTime
     * @return
     */
    List<ThreeSale> listSecondTeamQuery(@Param("start") long start, @Param("count") int count, @Param("uid") Long uid,
            @Param("state") Integer state, @Param("startTime") String startTime, @Param("endTime") String endTime);
    long countSecondTeamQuery(@Param("uid") Long uid, @Param("state") Integer state,
            @Param("startTime") String startTime, @Param("endTime") String endTime);
    /**
     * 上级查询
     *
     * @param start
     * @param count
     * @param uid
     * @return
     */
    List<ThreeSale> listSuperiorQuery(@Param("start") long start, @Param("count") int count,
            @Param("state") Integer state, @Param("uid") Long uid);
    long countSuperiorQuery(@Param("state") Integer state, @Param("uid") Long uid);
    /**
     * 查询一级队员
     *
     * @param paramLong
     * @param paramInt
     * @param paramLong1
     * @return
     */
    List<ThreeSale> listFirstTeam(@Param("start") long start, @Param("count") int count, @Param("uid") Long uid);
    /**
     * 统计一级队员
     *
     * @param uid
     * @param state
     * @return
     */
    long countFirstTeam(@Param("uid") Long uid, @Param("state") Integer state);
    /**
     * 查询二级队员
     *
     * @param start
     * @param count
     * @param uid
     * @return
     */
    List<ThreeSale> listSecondTeam(@Param("start") long start, @Param("count") int count, @Param("uid") Long uid);
    /**
     * 统计二级队员
     *
     * @param uid
     * @param state
     * @return
     */
    long countSecondTeam(@Param("uid") Long uid, @Param("state") Integer state);
    /**
     *
     * @param uid
     * @return
     */
    ThreeSale getMyBoss(@Param("uid") Long uid);
    /**
     * 根据id、uid查询
     *
     * @param id
     * @param uid
     * @return
     */
    List<ThreeSale> listbyIdAndBossId(@Param("id") Long id, @Param("uid") Long uid, @Param("expire") Integer expire);
    /**
     * 根据邀请者ID查询关系
     *
     * @param workerId
     * @return
     */
    List<ThreeSale> listByWorkerId(Long workerId);
    /**
     * 获取成功邀请关系数量
     *
     * @param uid
     * @return
     */
    int getSuccessRelationshipNum(@Param("uid") Long uid);
    /**
     * 根据邀请者ID、bossID查询 有效关系
     *
     * @param workerId
     * @return
     */
    ThreeSale getRelationshipByBossIdAndWorkerId(@Param("bossId") Long bossId, @Param("workerId") Long workerId);
    /**
     * 根据邀请者,邀请状态,过期状态查询列表
     *
     * @param workerId
     * @param state
     * @param expire
     * @return
     */
    List<ThreeSale> listByWorkerAndStateAndExpire(@Param("workerId") Long workerId, @Param("state") boolean state,
            @Param("expire") int expire);
    /**
     * 根据关键字模糊查询
     *
     * @param key
     * @param start
     * @param count
     * @return
     */
    List<ThreeSale> listByBossOrWorker(@Param("key") String key, @Param("start") long start, @Param("count") int count);
    /**
     * 根据关键字模糊查询数量
     * @param key
     * @return
     */
    Long countByBossOrWorker(@Param("key") String key);
}
fanli-service-user/src/main/java/org/fanli/service/user/dao/invite/msg/MsgInviteDetailMapper.java
New file
@@ -0,0 +1,53 @@
package org.fanli.service.user.dao.invite.msg;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.fanli.facade.user.entity.invite.msg.MsgInviteDetail;
import com.yeshi.fanli.base.BaseMapper;
public interface MsgInviteDetailMapper extends BaseMapper<MsgInviteDetail> {
    /**
     * 根据邀请ID获取数据
     *
     * @param threeSaleId
     * @return
     */
    MsgInviteDetail selectByThreeSaleId(Long threeSaleId);
    /**
     * 根据用户查询消息,根据更新时间倒叙
     *
     * @param uid
     * @param start
     * @param count
     * @return
     */
    List<MsgInviteDetail> listByUid(@Param("uid") Long uid, @Param("start") long start, @Param("count") int count);
    /**
     * 根据用户查询数量
     *
     * @param uid
     * @return
     */
    Long countByUid(@Param("uid") Long uid);
    /**
     * 设置消息已读时
     *
     * @param uid
     */
    void setMsgReadByUid(Long uid);
    /**
     * 根据邀请关系ID删除
     *
     * @param threeSaleId
     * @return
     */
    int deleteByThreeSaleId(Long threeSaleId);
}
fanli-service-user/src/main/java/org/fanli/service/user/dao/taobao/UserExtraTaoBaoInfoMapper.java
New file
@@ -0,0 +1,49 @@
package org.fanli.service.user.dao.taobao;
import org.fanli.facade.user.entity.taobao.UserExtraTaoBaoInfo;
import com.yeshi.fanli.base.BaseMapper;
public interface UserExtraTaoBaoInfoMapper extends BaseMapper<UserExtraTaoBaoInfo> {
    /**
     * 根据用户ID查询对象
     *
     * @param uid
     * @return
     */
    UserExtraTaoBaoInfo selectByUid(Long uid);
    /**
     * 根据淘宝UID查询
     *
     * @param taoBaoUid
     * @return
     */
    UserExtraTaoBaoInfo selectByTaoBaoUid(String taoBaoUid);
    /**
     * 清除用户ID
     *
     * @param uid
     * @return
     */
    int clearUid(Long uid);
    /**
     * 通过渠道ID查询
     *
     * @param relationId
     * @return
     */
    UserExtraTaoBaoInfo selectByRelationIdWithUidNotNull(String relationId);
    /**
     * 通过会员运营ID查询
     *
     * @param specialId
     * @return
     */
    UserExtraTaoBaoInfo selectBySpecialIdWithUidNotNull(String specialId);
}
fanli-service-user/src/main/java/org/fanli/service/user/mapper/account/UserInfoMapper.xml
New file
@@ -0,0 +1,522 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.fanli.service.user.dao.account.UserInfoMapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.base.entity.user.UserInfo">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="identifycode" property="openid" jdbcType="VARCHAR" />
        <result column="login_type" property="loginType" jdbcType="INTEGER" />
        <result column="wx_open_id" property="wxOpenId" jdbcType="VARCHAR" />
        <result column="wx_union_id" property="wxUnionId" jdbcType="VARCHAR" />
        <result column="nick_name" property="nickName" jdbcType="VARCHAR" />
        <result column="tbName" property="tbName" jdbcType="VARCHAR" />
        <result column="tbPic" property="tbPic" jdbcType="VARCHAR" />
        <result column="wxName" property="wxName" jdbcType="VARCHAR" />
        <result column="wxPic" property="wxPic" jdbcType="VARCHAR" />
        <result column="portrait" property="portrait" jdbcType="VARCHAR" />
        <result column="createtime" property="createtime" jdbcType="BIGINT" />
        <result column="last_logintime" property="lastLoginTime"
            jdbcType="BIGINT" />
        <result column="loginip" property="lastLoginIp" jdbcType="VARCHAR" />
        <result column="tuiguang_code" property="tuiGuangCode"
            jdbcType="VARCHAR" />
        <result column="appid" property="appId" jdbcType="VARCHAR" />
        <result column="my_hongBao" property="myHongBao" jdbcType="DECIMAL" />
        <result column="pay_password" property="payPassword" jdbcType="VARCHAR" />
        <result column="rank" property="rank" jdbcType="INTEGER" />
        <result column="phone" property="phone" jdbcType="VARCHAR" />
        <result column="state" property="state" jdbcType="INTEGER" />
        <result column="state_desc" property="stateDesc" jdbcType="VARCHAR" />
        <!-- <association property="system" column="sid" resultMap="com.yeshi.fanli.dao.mybatis.SystemMapper.BaseResultMap"
            /> -->
    </resultMap>
    <sql id="Base_Column_List">id,identifycode,login_type,wx_open_id,wx_union_id,nick_name,tbName,tbPic,wxName,wxPic,portrait,createtime,last_logintime,loginip,tuiguang_code,appid,my_hongBao,pay_password,sid,rank,phone,state,state_desc
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where id = #{id,jdbcType=BIGINT} and `state`=0
    </select>
    <select id="selectByPKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where id = #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where id = #{id,jdbcType=BIGINT} for update
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_user where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.base.entity.user.UserInfo"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_user
        (id,identifycode,login_type,wx_open_id,wx_union_id,nick_name,tbName,tbPic,wxName,wxPic,portrait,createtime,last_logintime,loginip,tuiguang_code,appid,my_hongBao,pay_password,sid,rank,phone,state,state_desc)
        values
        (#{id,jdbcType=BIGINT},#{openid,jdbcType=VARCHAR},#{loginType,jdbcType=INTEGER},#{wxOpenId,jdbcType=VARCHAR},#{wxUnionId,jdbcType=VARCHAR},#{nickName,jdbcType=VARCHAR},#{tbName,jdbcType=VARCHAR},#{tbPic,jdbcType=VARCHAR},#{wxName,jdbcType=VARCHAR},#{wxPic,jdbcType=VARCHAR},#{portrait,jdbcType=VARCHAR},#{createtime,jdbcType=BIGINT},#{lastLoginTime,jdbcType=BIGINT},#{lastLoginIp,jdbcType=VARCHAR},#{tuiGuangCode,jdbcType=VARCHAR},#{appId,jdbcType=VARCHAR},#{myHongBao,jdbcType=DECIMAL},#{payPassword,jdbcType=VARCHAR},#{system.id,jdbcType=BIGINT},#{rank,jdbcType=INTEGER},#{phone,jdbcType=VARCHAR},#{state,jdbcType=INTEGER},#{stateDesc,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.base.entity.user.UserInfo"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="openid != null">identifycode,</if>
            <if test="loginType != null">login_type,</if>
            <if test="wxOpenId != null">wx_open_id,</if>
            <if test="wxUnionId != null">wx_union_id,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="tbName != null">tbName,</if>
            <if test="tbPic != null">tbPic,</if>
            <if test="wxName != null">wxName,</if>
            <if test="wxPic != null">wxPic,</if>
            <if test="portrait != null">portrait,</if>
            <if test="createtime != null">createtime,</if>
            <if test="lastLoginTime != null">last_logintime,</if>
            <if test="lastLoginIp != null">loginip,</if>
            <if test="tuiGuangCode != null">tuiguang_code,</if>
            <if test="appId != null">appid,</if>
            <if test="myHongBao != null">my_hongBao,</if>
            <if test="payPassword != null">pay_password,</if>
            <if test="system != null">sid,</if>
            <if test="rank != null">rank,</if>
            <if test="phone != null">phone,</if>
            <if test="state != null">state,</if>
            <if test="stateDesc != null">state_desc,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="openid != null">#{openid,jdbcType=VARCHAR},</if>
            <if test="loginType != null">#{loginType,jdbcType=INTEGER},</if>
            <if test="wxOpenId != null">#{wxOpenId,jdbcType=VARCHAR},</if>
            <if test="wxUnionId != null">#{wxUnionId,jdbcType=VARCHAR},</if>
            <if test="nickName != null">#{nickName,jdbcType=VARCHAR},</if>
            <if test="tbName != null">#{tbName,jdbcType=VARCHAR},</if>
            <if test="tbPic != null">#{tbPic,jdbcType=VARCHAR},</if>
            <if test="wxName != null">#{wxName,jdbcType=VARCHAR},</if>
            <if test="wxPic != null">#{wxPic,jdbcType=VARCHAR},</if>
            <if test="portrait != null">#{portrait,jdbcType=VARCHAR},</if>
            <if test="createtime != null">#{createtime,jdbcType=BIGINT},</if>
            <if test="lastLoginTime != null">#{lastLoginTime,jdbcType=BIGINT},</if>
            <if test="lastLoginIp != null">#{lastLoginIp,jdbcType=VARCHAR},</if>
            <if test="tuiGuangCode != null">#{tuiGuangCode,jdbcType=VARCHAR},</if>
            <if test="appId != null">#{appId,jdbcType=VARCHAR},</if>
            <if test="myHongBao != null">#{myHongBao,jdbcType=DECIMAL},</if>
            <if test="payPassword != null">#{payPassword,jdbcType=VARCHAR},</if>
            <if test="system != null">#{system.id,jdbcType=BIGINT},</if>
            <if test="rank != null">#{rank,jdbcType=INTEGER},</if>
            <if test="phone != null">#{phone,jdbcType=VARCHAR},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="stateDesc != null">#{stateDesc,jdbcType=VARCHAR}</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.base.entity.user.UserInfo">update
        yeshi_ec_user set identifycode = #{openid,jdbcType=VARCHAR},login_type
        = #{loginType,jdbcType=INTEGER},wx_open_id =
        #{wxOpenId,jdbcType=VARCHAR},wx_union_id =
        #{wxUnionId,jdbcType=VARCHAR},nick_name =
        #{nickName,jdbcType=VARCHAR},tbName = #{tbName,jdbcType=VARCHAR},tbPic
        = #{tbPic,jdbcType=VARCHAR},wxName = #{wxName,jdbcType=VARCHAR},wxPic
        = #{wxPic,jdbcType=VARCHAR},portrait =
        #{portrait,jdbcType=VARCHAR},createtime =
        #{createtime,jdbcType=BIGINT},last_logintime =
        #{lastLoginTime,jdbcType=BIGINT},loginip =
        #{lastLoginIp,jdbcType=VARCHAR},tuiguang_code =
        #{tuiGuangCode,jdbcType=VARCHAR},appid =
        #{appId,jdbcType=VARCHAR},my_hongBao =
        #{myHongBao,jdbcType=DECIMAL},pay_password =
        #{payPassword,jdbcType=VARCHAR},sid =
        #{system.id,jdbcType=BIGINT},rank = #{rank,jdbcType=INTEGER} ,phone
        =#{phone,jdbcType=VARCHAR} ,state =#{state,jdbcType=INTEGER}
        ,state_desc =#{stateDesc,jdbcType=VARCHAR} where id =
        #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.base.entity.user.UserInfo">
        update yeshi_ec_user
        <set>
            <if test="openid != null">identifycode=#{openid,jdbcType=VARCHAR},</if>
            <if test="loginType != null">login_type=#{loginType,jdbcType=INTEGER},</if>
            <if test="wxOpenId != null">wx_open_id=#{wxOpenId,jdbcType=VARCHAR},</if>
            <if test="wxUnionId != null">wx_union_id=#{wxUnionId,jdbcType=VARCHAR},</if>
            <if test="nickName != null">nick_name=#{nickName,jdbcType=VARCHAR},</if>
            <if test="tbName != null">tbName=#{tbName,jdbcType=VARCHAR},</if>
            <if test="tbPic != null">tbPic=#{tbPic,jdbcType=VARCHAR},</if>
            <if test="wxName != null">wxName=#{wxName,jdbcType=VARCHAR},</if>
            <if test="wxPic != null">wxPic=#{wxPic,jdbcType=VARCHAR},</if>
            <if test="portrait != null">portrait=#{portrait,jdbcType=VARCHAR},</if>
            <if test="createtime != null">createtime=#{createtime,jdbcType=BIGINT},</if>
            <if test="lastLoginTime != null">last_logintime=#{lastLoginTime,jdbcType=BIGINT},</if>
            <if test="lastLoginIp != null">loginip=#{lastLoginIp,jdbcType=VARCHAR},</if>
            <if test="tuiGuangCode != null">tuiguang_code=#{tuiGuangCode,jdbcType=VARCHAR},</if>
            <if test="appId != null">appid=#{appId,jdbcType=VARCHAR},</if>
            <if test="myHongBao != null">my_hongBao=#{myHongBao,jdbcType=DECIMAL},</if>
            <if test="payPassword != null">pay_password=#{payPassword,jdbcType=VARCHAR},</if>
            <if test="system != null">sid=#{system.id,jdbcType=BIGINT},</if>
            <if test="rank != null">rank=#{rank,jdbcType=INTEGER},</if>
            <if test="phone !=null">phone =#{phone,jdbcType=VARCHAR},</if>
            <if test="state !=null">state =#{state,jdbcType=INTEGER},</if>
            <if test="stateDesc !=null">state_desc =#{stateDesc,jdbcType=VARCHAR},</if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="subHongBaoByUid">update yeshi_ec_user set my_hongBao=
        my_hongBao-#{money,jdbcType=DECIMAL} where id = #{uid,jdbcType=BIGINT}
    </update>
    <update id="addHongBaoByUid">update yeshi_ec_user set my_hongBao=
        my_hongBao+#{money,jdbcType=DECIMAL} where id = #{uid,jdbcType=BIGINT}
    </update>
    <!-- 查询新人红包 -->
    <select id="getNewPeopleHB" resultType="BigDecimal">SELECT sum(hb.`money`)
        FROM `yeshi_ec_hongbao` hb WHERE hb.`uid` = #{id} AND hb.`type` = '4';
    </select>
    <!-- 查询我的红包 -->
    <select id="getMyHB" resultType="BigDecimal">SELECT SUM(hb.`money`) FROM
        `yeshi_ec_hongbao` hb WHERE hb.`uid` = #{id};
    </select>
    <!-- 根据AppId与微信unionID获取用户 -->
    <select id="getUserInfoByAppIdAndWXUnionId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where appid=#{appId} and wx_union_id=#{unionId}
        limit 1
    </select>
    <!-- 根据AppId与淘宝OpenId获取用户 -->
    <select id="getUserInfoByAppIdAndTaoBaoOpenId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where appid=#{appId} and identifycode=#{openId}
        limit 1
    </select>
    <!-- 根据AppId与电话号码获取用户 -->
    <select id="getUserInfoByAppIdAndPhone" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user where appid=#{appId} and phone=#{phone} limit 1
    </select>
    <select id="getMaxUid" resultType="java.lang.Long">select max(id) from
        yeshi_ec_user
    </select>
    <!-- 两个账号的业务融合 -->
    <select id="connectUser">
        call procedure_connect_user(#{mainUid},#{lessUid})
    </select>
    <select id="query" resultMap="BaseResultMap">
        SELECT u.*
        <if test="orderField != null and orderField != 5 and orderField != 6">
            ,(SELECT COUNT(hb.hb_id) FROM `yeshi_ec_hongbao_v2` hb
            WHERE hb.hb_uid = u.id AND (hb.hb_type = 1 or hb.hb_type = 2)
            <if test="orderMode == 2">
                AND DATE_FORMAT(hb.`hb_create_time`,'%Y%m') =
                DATE_FORMAT(CURDATE(),'%Y%m')
            </if>
            )AS total
        </if>
        <if test="orderMode == 3">
            ,(SELECT COUNT(tr.`id`) FROM `yeshi_ec_threesale` tr
            WHERE tr.`boss_id`=u.id AND tr.state = 1) AS totalThree
        </if>
        FROM yeshi_ec_user u
        LEFT JOIN yeshi_ec_binding_account b ON u.`id` = b.`uid`
        where 1=1
        <if test="key != null and key !='' ">
            AND (u.id LIKE '%${key}%' OR u.`phone` LIKE '%${key}%' OR u.`wxName`
            LIKE '%${key}%'
            OR u.`nick_name` LIKE '%${key}%' OR u.`tbName` LIKE '%${key}%' OR
            b.`account` LIKE '%${key}%')
        </if>
        <if test="startTime != null and startTime !='' ">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) >= '${startTime}' ]]>
        </if>
        <if test="endTime != null and endTime !=''">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) < '${endTime}'  ]]>
        </if>
        <if test="userType != null">
            AND u.rank = #{userType}
        </if>
        <if test="days != null">
            <!-- 时间 -->
            AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) <= FROM_UNIXTIME(createtime/1000)]]>
        </if>
        ORDER BY
        <if test="orderField == 1">
            total,
        </if>
        <if test="orderField == 2">
            total DESC,
        </if>
        <if test="orderField == 3">
            total,
        </if>
        <if test="orderField == 4">
            total DESC,
        </if>
        <if test="orderField == 5">
            totalThree,
        </if>
        <if test="orderField == 6">
            totalThree DESC,
        </if>
        createtime DESC LIMIT ${start},${count}
    </select>
    <select id="queryCount" resultType="java.lang.Long">
        SELECT count(u.id) FROM yeshi_ec_user u
        LEFT JOIN yeshi_ec_binding_account b ON u.`id` = b.`uid`
        where <![CDATA[ 1>0 ]]>
        <if test="key != null and key !='' ">
            AND (u.id LIKE '%${key}%' OR u.`phone` LIKE '%${key}%' OR u.`wxName`
            LIKE '%${key}%'
            OR u.`nick_name` LIKE '%${key}%' OR u.`tbName` LIKE '%${key}%' OR
            b.`account` LIKE '%${key}%')
        </if>
        <if test="startTime != null and startTime !='' ">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) >= '${startTime}' ]]>
        </if>
        <if test="endTime != null and endTime !=''">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) < '${endTime}'  ]]>
        </if>
        <if test="userType != null">
            AND u.rank = #{userType}
        </if>
        <if test="days != null">
            <!-- 时间 -->
            AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) <= FROM_UNIXTIME(createtime/1000)]]>
        </if>
    </select>
    <select id="querySumMoney" resultType="java.lang.Double">
        SELECT COALESCE(sum(u.my_hongBao),0) FROM yeshi_ec_user u
        LEFT JOIN yeshi_ec_binding_account b ON u.`id` = b.`uid`
        where <![CDATA[ 1>0 ]]>
        <if test="key != null and key !='' ">
            AND (u.id LIKE '%${key}%' OR u.`phone` LIKE '%${key}%' OR u.`wxName`
            LIKE '%${key}%'
            OR u.`nick_name` LIKE '%${key}%' OR u.`tbName` LIKE '%${key}%' OR
            b.`account` LIKE '%${key}%')
        </if>
        <if test="startTime != null and startTime !='' ">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) >= '${startTime}' ]]>
        </if>
        <if test="endTime != null and endTime !=''">
                   <![CDATA[ AND FROM_UNIXTIME(createtime/1000) < '${endTime}'  ]]>
        </if>
        <if test="userType != null">
            AND u.rank = #{userType}
        </if>
        <if test="days != null">
            <!-- 时间 -->
            AND <![CDATA[DATE_SUB(CURDATE(), INTERVAL ${days} DAY) <= FROM_UNIXTIME(createtime/1000)]]>
        </if>
    </select>
    <select id="countNewUser" resultType="java.lang.Long">
        SELECT COALESCE(count(id),0) FROM `yeshi_ec_user`
        WHERE 1=1
        <if test="isToday != null and isToday == 1">
            AND TO_DAYS(FROM_UNIXTIME(createtime/1000)) = TO_DAYS(NOW())
        </if>
        <if test="isMonth != null and isMonth == 1">
            AND DATE_FORMAT( FROM_UNIXTIME(createtime/1000), '%Y%m' ) =
            DATE_FORMAT(CURDATE() , '%Y%m' )
        </if>
    </select>
    <select id="countRank" resultType="java.lang.Long">
        <!-- 等级统计 -->
        SELECT COALESCE(count(id),0) FROM `yeshi_ec_user` WHERE rank = #{rank}
    </select>
    <select id="countAllMoney" resultType="java.math.BigDecimal">
        <!-- 金额统计 -->
        SELECT CAST(SUM(my_hongBao)AS DECIMAL(19,2)) FROM `yeshi_ec_user`
        WHERE 1=1
        <if test="minMoney != null">
            AND <![CDATA[ my_hongBao >= #{minMoney}]]>
        </if>
    </select>
    <select id="countShareAndInviteMoney" resultMap="BaseResultMap">
        SELECT IFNULL(SUM(h.`money`),0),h.`uid` FROM `yeshi_ec_hongbao` h
        WHERE DATE_FORMAT(FROM_UNIXTIME(h.`createtime`/1000), '%Y-%m-%d' )=
        '2018-08-02'
        <![CDATA[AND h.state <>4]]>
        AND ( h.`type` =5 OR h.`type` =6 OR h.`type` =7 OR h.`type` =20 OR
        h.`type` =21 OR h.`type` =22 )
        GROUP BY h.`uid`
        ORDER BY SUM(h.`money`) DESC
        LIMIT ${start},${count}
    </select>
    <select id="longTimeNoLogin" resultType="java.lang.Long">
        SELECT u.`id` FROM `yeshi_ec_user` u
        WHERE u.`id` IN
        <foreach item="item" collection="list" open="(" separator=","
            close=")">#{item}</foreach>
        AND <![CDATA[ (DATE_SUB(CURDATE(), INTERVAL ${daysNum} DAY) > DATE(FROM_UNIXTIME(u.`last_logintime`/1000))
            OR (u.`last_logintime` IS NULL
                AND DATE_SUB(CURDATE(), INTERVAL ${daysNum} DAY) > DATE(FROM_UNIXTIME(u.`createTime`/1000)))) ]]>
    </select>
    <select id="countLoseUser" resultType="java.lang.Long">
        SELECT COUNT(DISTINCT t.`id` ) FROM `yeshi_ec_user` t
        LEFT JOIN `yeshi_ec_user_money_detail` d ON d.`umd_uid` = t.`id`
        WHERE DATE_SUB(CURDATE(), INTERVAL ${num} DAY)<![CDATA[> ]]>
        DATE(FROM_UNIXTIME( t.`last_logintime`/1000))
        AND DATE_SUB(CURDATE(), INTERVAL ${num} DAY) <![CDATA[> ]]>
        DATE(d.`umd_createtime`)
    </select>
    <select id="countHasOrderUser" resultType="java.lang.Long">
        SELECT COUNT(DISTINCT
        h.`hb_uid`) FROM yeshi_ec_hongbao_v2 h
        WHERE (h.`hb_type`=1 or h.`hb_type`=2 or h.`hb_type`= 20)
    </select>
    <select id="countNewUserByDate" resultType="java.util.HashMap">
        SELECT COUNT(DISTINCT h.`id`) AS showValue,
        <if test="type == 1">
            FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d') AS 'showDate'
        </if>
        <if test="type == 2">
            FROM_UNIXTIME(h.`createtime`/1000,'%m') AS 'showDate'
        </if>
        <if test="type == 3">
            FROM_UNIXTIME(h.`createtime`/1000,'%Y') AS 'showDate'
        </if>
        FROM yeshi_ec_user h
        <if test="channel != null and  channel != 'all' ">
            left join (SELECT a.`lua_uid` AS uid FROM `yeshi_ec_log_user_active` a
            WHERE a.`lua_channel`='${channel}' GROUP BY a.`lua_uid`)a ON
            h.`id`=a.uid
        </if>
        WHERE 1=1
        <if test="channel != null and  channel != 'all' ">
            AND a.uid is not null
        </if>
        <if test="startTime != null and startTime != '' ">
            AND FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
        </if>
        <if test="endTime != null and endTime != '' ">
            AND FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d') <![CDATA[ <= ]]>
            '${endTime}'
        </if>
        <if test="years != null and years != '' ">
            AND FROM_UNIXTIME(h.`createtime`/1000,'%Y') = '${years}'
        </if>
        <if test="type == 1">
            GROUP BY FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m-%d')
        </if>
        <if test="type == 2">
            GROUP BY FROM_UNIXTIME(h.`createtime`/1000,'%Y-%m')
        </if>
        <if test="type == 3">
            GROUP BY FROM_UNIXTIME(h.`createtime`/1000,'%Y')
        </if>
        ORDER BY h.`createtime`
    </select>
    <select id="getTodayHasOrder" resultType="java.util.HashMap">
        SELECT COALESCE(COUNT(DISTINCT u.`id`),0) AS 'showValue',
        <if test="type == 1">
            FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') AS 'showDate'
        </if>
        <if test="type == 2">
            FROM_UNIXTIME(u.`createtime`/1000,'%m') AS 'showDate'
        </if>
        <if test="type == 3">
            FROM_UNIXTIME(u.`createtime`/1000,'%Y') AS 'showDate'
        </if>
        FROM yeshi_ec_user u
        <if test="channel != null and channel != 'all' ">
            LEFT JOIN (SELECT a.`lua_uid` AS uid FROM
            `yeshi_ec_log_user_active` a
            WHERE a.`lua_channel`='${channel}' GROUP BY a.`lua_uid`) a ON u.`id`=a.uid
        </if>
        LEFT JOIN `yeshi_ec_hongbao_v2` h ON h.`hb_uid`= u.`id`
        WHERE
        (h.`hb_type`=1 OR h.`hb_type`=20)
        <if test="channel != null and  channel != 'all' ">
            AND a.uid is not null
        </if>
        <!-- 当日下单 -->
        AND FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') =
        DATE_FORMAT(h.hb_create_time,'%Y-%m-%d')
        <if test="startTime != null and startTime != '' ">
            AND FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d')<![CDATA[ >= ]]>'${startTime}'
        </if>
        <if test="endTime != null and endTime != '' ">
            AND FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') <![CDATA[ <= ]]>
            '${endTime}'
        </if>
        <if test="years != null and years != '' ">
            AND FROM_UNIXTIME(u.`createtime`/1000,'%Y') = '${years}'
        </if>
        <if test="type == 1">
            GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d')
        </if>
        <if test="type == 2">
            GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m')
        </if>
        <if test="type == 3">
            GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y')
        </if>
        ORDER BY u.`createtime`
    </select>
    <select id="getWeekHasOrder" resultType="java.util.HashMap">
        SELECT COUNT(DISTINCT hb.uid) AS
        showValue,FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') AS 'showDate'
        FROM (SELECT COUNT(v2.`hb_id`) AS num,v2.hb_uid AS uid
        FROM yeshi_ec_hongbao_v2 v2
        WHERE (v2.`hb_type`=1 OR v2.`hb_type`=20)
        AND DATE_FORMAT(v2.`hb_create_time`,'%Y-%m-%d') <![CDATA[ >= ]]>'${startTime}'
        AND DATE_FORMAT(v2.`hb_create_time`,'%Y-%m-%d') <![CDATA[ <= ]]>'${endTime}'
        GROUP BY v2.hb_uid HAVING num >= ${orderNum})hb
        LEFT JOIN yeshi_ec_user
        u ON u.id = hb.uid
        <if test="channel != null and channel != 'all' ">
            LEFT JOIN (SELECT a.`lua_uid` AS uid FROM
            `yeshi_ec_log_user_active` a
            WHERE a.`lua_channel`='${channel}' GROUP BY a.`lua_uid`) a ON u.`id`=a.uid
        </if>
        WHERE FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d') = '${startTime}'
        <if test="channel != null and  channel != 'all' ">
            AND a.uid is not null
        </if>
        GROUP BY FROM_UNIXTIME(u.`createtime`/1000,'%Y-%m-%d')
        ORDER BY u.`createtime`
    </select>
    <select id="getInfoByPhoneOrInviteCode" resultMap="BaseResultMap">
        SELECT * FROM
        yeshi_ec_user u
        LEFT JOIN yeshi_ec_user_info_extra uf ON uf.`uie_uid` = u.`id`
        WHERE
        uf.`uie_invite_code` IS NOT NULL
        AND (u.`phone` =#{phone} OR uf.`uie_invite_code` = #{inviteCode})
        LIMIT 1
    </select>
</mapper>
fanli-service-user/src/main/java/org/fanli/service/user/mapper/account/msg/MsgAccountDetailMapper.xml
New file
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.fanli.service.user.dao.account.msg.MsgAccountDetailMapper">
    <resultMap id="BaseResultMap"
        type="org.fanli.facade.user.entity.account.msg.MsgAccountDetail">
        <id column="ma_id" property="id" jdbcType="BIGINT" />
        <result column="ma_type" property="type"
            typeHandler="org.fanli.facade.user.util.typehandler.MsgTypeAccountTypeEnumHandler" />
        <result column="ma_title" property="title" jdbcType="VARCHAR" />
        <result column="ma_content" property="content" jdbcType="VARCHAR" />
        <result column="ma_beizhu" property="beiZhu" jdbcType="VARCHAR" />
        <result column="ma_read" property="read" jdbcType="BOOLEAN" />
        <result column="ma_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="ma_update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <association property="user" column="ma_uid"
            javaType="com.yeshi.fanli.base.entity.user.UserInfo">
            <id column="ma_uid" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    <sql id="Base_Column_List">ma_id,ma_uid,ma_type,ma_title,ma_content,ma_beizhu,ma_read,ma_create_time,ma_update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_msg_account where ma_id = #{id,jdbcType=BIGINT}
    </select>
    <select id="listByUid" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_msg_account where ma_uid = #{uid,jdbcType=BIGINT} order
        by ma_update_time desc limit #{start},#{count}
    </select>
    <select id="countByUid" resultType="java.lang.Long"
        parameterType="java.lang.Long">
        select
        count(ma_id)
        from yeshi_ec_msg_account where ma_uid
        = #{uid,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_msg_account where ma_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="org.fanli.facade.user.entity.account.msg.MsgAccountDetail"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_msg_account
        (ma_id,ma_uid,ma_type,ma_title,ma_content,ma_beizhu,ma_read,ma_create_time,ma_update_time)
        values
        (#{id,jdbcType=BIGINT},#{user.id,jdbcType=BIGINT},#{type,jdbcType=VARCHAR},#{title,jdbcType=VARCHAR},#{content,jdbcType=VARCHAR},#{beiZhu,jdbcType=VARCHAR},#{read,jdbcType=BOOLEAN},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="org.fanli.facade.user.entity.account.msg.MsgAccountDetail"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_msg_account
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">ma_id,</if>
            <if test="user != null">ma_uid,</if>
            <if test="type != null">ma_type,</if>
            <if test="title != null">ma_title,</if>
            <if test="content != null">ma_content,</if>
            <if test="beiZhu != null">ma_beizhu,</if>
            <if test="read != null">ma_read,</if>
            <if test="createTime != null">ma_create_time,</if>
            <if test="updateTime != null">ma_update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="user != null">#{user.id,jdbcType=BIGINT},</if>
            <if test="type != null">#{type,jdbcType=VARCHAR},</if>
            <if test="title != null">#{title,jdbcType=VARCHAR},</if>
            <if test="content != null">#{content,jdbcType=VARCHAR},</if>
            <if test="beiZhu != null">#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="read != null">#{read,jdbcType=BOOLEAN},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="org.fanli.facade.user.entity.account.msg.MsgAccountDetail">update
        yeshi_ec_msg_account set ma_uid = #{user.id,jdbcType=BIGINT},ma_type
        =
        #{type,jdbcType=VARCHAR},ma_title =
        #{title,jdbcType=VARCHAR},ma_content =
        #{content,jdbcType=VARCHAR},ma_beizhu =
        #{beiZhu,jdbcType=VARCHAR},ma_read =
        #{read,jdbcType=BOOLEAN},ma_create_time =
        #{createTime,jdbcType=TIMESTAMP},ma_update_time =
        #{updateTime,jdbcType=TIMESTAMP} where ma_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.fanli.facade.user.entity.account.msg.MsgAccountDetail">
        update yeshi_ec_msg_account
        <set>
            <if test="user != null">ma_uid=#{user.id,jdbcType=BIGINT},</if>
            <if test="type != null">ma_type=#{type,jdbcType=VARCHAR},</if>
            <if test="title != null">ma_title=#{title,jdbcType=VARCHAR},</if>
            <if test="content != null">ma_content=#{content,jdbcType=VARCHAR},</if>
            <if test="beiZhu != null">ma_beizhu=#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="read != null">ma_read=#{read,jdbcType=BOOLEAN},</if>
            <if test="createTime != null">ma_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">ma_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where ma_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="setMsgReadByUid" parameterType="java.lang.Long">
        update
        yeshi_ec_msg_account set ma_read=1 where ma_uid=#{0}
    </update>
</mapper>
fanli-service-user/src/main/java/org/fanli/service/user/mapper/invite/SpreadImgMapper.xml
New file
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.fanli.service.user.dao.invite.SpreadImgMapper">
    <resultMap id="BaseResultMap" type="org.fanli.facade.user.entity.invite.SpreadImg">
        <id column="si_id" property="id" jdbcType="VARCHAR" />
        <result column="si_url" property="url" jdbcType="VARCHAR" />
        <result column="si_createtime" property="createtime" jdbcType="TIMESTAMP" />
    </resultMap>
    <sql id="Base_Column_List">si_id,si_url,si_createtime</sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_spread_img where si_id = #{id,jdbcType=BIGINT}
    </select>
    <select id="listAll" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_spread_img
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_spread_img where si_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="org.fanli.facade.user.entity.invite.SpreadImg"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_spread_img
        (si_id,si_url,si_createtime) values
        (#{id,jdbcType=VARCHAR},#{url,jdbcType=VARCHAR},#{createtime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="org.fanli.facade.user.entity.invite.SpreadImg"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_spread_img
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">si_id,</if>
            <if test="url != null">si_url,</if>
            <if test="createtime != null">si_createtime,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=VARCHAR},</if>
            <if test="url != null">#{url,jdbcType=VARCHAR},</if>
            <if test="createtime != null">#{createtime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="org.fanli.facade.user.entity.invite.SpreadImg">update
        yeshi_ec_spread_img set si_url = #{url,jdbcType=VARCHAR},si_createtime
        = #{createtime,jdbcType=TIMESTAMP} where si_id =
        #{id,jdbcType=VARCHAR}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.fanli.facade.user.entity.invite.SpreadImg">
        update yeshi_ec_spread_img
        <set>
            <if test="url != null">si_url=#{url,jdbcType=VARCHAR},</if>
            <if test="createtime != null">si_createtime=#{createtime,jdbcType=TIMESTAMP},</if>
        </set>
        where si_id = #{id,jdbcType=VARCHAR}
    </update>
</mapper>
fanli-service-user/src/main/java/org/fanli/service/user/mapper/invite/SpreadUserImgMapper.xml
New file
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.fanli.service.user.dao.invite.SpreadUserImgMapper">
    <resultMap id="BaseResultMap"
        type="org.fanli.facade.user.entity.invite.SpreadUserImg">
        <id column="si_id" property="id" jdbcType="BIGINT" />
        <result column="si_uid" property="uid" jdbcType="BIGINT" />
        <result column="si_type" property="type" jdbcType="INTEGER" />
        <result column="si_url" property="url" jdbcType="VARCHAR" />
        <result column="si_createtime" property="createtime" jdbcType="TIMESTAMP" />
    </resultMap>
    <sql id="Base_Column_List">si_id,si_uid,si_type,si_url,si_createtime</sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_spread_user_img where si_id = #{id,jdbcType=BIGINT}
    </select>
    <select id="listByUid" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_spread_user_img where si_uid = #{0}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_spread_user_img where si_id = #{id,jdbcType=BIGINT}</delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.invite.SpreadUserImg"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_spread_user_img (si_id,si_uid,si_type,si_url,si_createtime)
        values
        (#{id,jdbcType=BIGINT},#{uid,jdbcType=BIGINT},#{type,jdbcType=INTEGER},#{url,jdbcType=VARCHAR},#{createtime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.invite.SpreadUserImg"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_spread_user_img
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">si_id,</if>
            <if test="uid != null">si_uid,</if>
            <if test="type != null">si_type,</if>
            <if test="url != null">si_url,</if>
            <if test="createtime != null">si_createtime,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="uid != null">#{uid,jdbcType=BIGINT},</if>
            <if test="type != null">#{type,jdbcType=INTEGER},</if>
            <if test="url != null">#{url,jdbcType=VARCHAR},</if>
            <if test="createtime != null">#{createtime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.invite.SpreadUserImg">update
        yeshi_ec_spread_user_img set si_uid = #{uid,jdbcType=BIGINT},si_type =
        #{type,jdbcType=INTEGER},si_url =
        #{url,jdbcType=VARCHAR},si_createtime =
        #{createtime,jdbcType=TIMESTAMP} where si_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.invite.SpreadUserImg">
        update yeshi_ec_spread_user_img
        <set>
            <if test="uid != null">si_uid=#{uid,jdbcType=BIGINT},</if>
            <if test="type != null">si_type=#{type,jdbcType=INTEGER},</if>
            <if test="url != null">si_url=#{url,jdbcType=VARCHAR},</if>
            <if test="createtime != null">si_createtime=#{createtime,jdbcType=TIMESTAMP},</if>
        </set>
        where si_id = #{id,jdbcType=BIGINT}
    </update>
    <select id="getImgUrlList" resultType="String">
        SELECT `si_url` FROM
        `yeshi_ec_spread_user_img` WHERE `si_uid` = #{uid};
    </select>
    <select id="imgUrlCount" resultType="Integer">
        SELECT COUNT(1) FROM
        `yeshi_ec_spread_user_img` WHERE `si_uid` = #{uid};
    </select>
    <delete id="deleteImgUrl">
        DELETE FROM `yeshi_ec_spread_user_img` WHERE `si_uid`
        = #{uid};
    </delete>
</mapper>
fanli-service-user/src/main/java/org/fanli/service/user/mapper/invite/ThreeSaleExtraInfoMapper.xml
New file
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.fanli.service.user.dao.invite.ThreeSaleExtraInfoMapper">
    <resultMap id="BaseResultMap"
        type="org.fanli.facade.user.entity.invite.ThreeSaleExtraInfo">
        <id column="tf_id" property="id" jdbcType="BIGINT" />
        <result column="tf_nickname" property="nickname" jdbcType="VARCHAR" />
        <result column="tf_createtime" property="createTime" jdbcType="TIMESTAMP" />
        <result column="tf_updatetime" property="updateTime" jdbcType="TIMESTAMP" />
        <association property="boss" column="tf_boss_id"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="tf_boss_id" property="id" jdbcType="BIGINT" />
        </association>
        <association property="worker" column="tf_worker_id"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="tf_worker_id" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    <sql id="Base_Column_List">tf_id,tf_boss_id,tf_worker_id,tf_nickname,tf_createtime,tf_updatetime
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_threesale_extra_info where tf_id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_threesale_extra_info where tf_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert"
        parameterType="org.fanli.facade.user.entity.invite.ThreeSaleExtraInfo"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_threesale_extra_info
        (tf_id,tf_boss_id,tf_worker_id,tf_nickname,tf_createtime,tf_updatetime)
        values
        (#{id,jdbcType=BIGINT},#{boss.id,jdbcType=BIGINT},#{worker.id,jdbcType=BIGINT},#{nickname,jdbcType=VARCHAR},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective"
        parameterType="org.fanli.facade.user.entity.invite.ThreeSaleExtraInfo"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_threesale_extra_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">tf_id,</if>
            <if test="boss != null">tf_boss_id,</if>
            <if test="worker != null">tf_worker_id,</if>
            <if test="nickname != null">tf_nickname,</if>
            <if test="createTime != null">tf_createtime,</if>
            <if test="updateTime != null">tf_updatetime,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="boss != null">#{boss.id,jdbcType=BIGINT},</if>
            <if test="worker != null">#{worker.id,jdbcType=BIGINT},</if>
            <if test="nickname != null">#{nickname,jdbcType=VARCHAR},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
        parameterType="org.fanli.facade.user.entity.invite.ThreeSaleExtraInfo">update
        yeshi_ec_threesale_extra_info set tf_boss_id =
        #{boss.id,jdbcType=BIGINT},tf_worker_id =
        #{worker.id,jdbcType=BIGINT},tf_nickname =
        #{nickname,jdbcType=VARCHAR},tf_createtime =
        #{createTime,jdbcType=TIMESTAMP},tf_updatetime =
        #{updateTime,jdbcType=TIMESTAMP} where tf_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective"
        parameterType="org.fanli.facade.user.entity.invite.ThreeSaleExtraInfo">
        update yeshi_ec_threesale_extra_info
        <set>
            <if test="boss != null">tf_boss_id=#{boss.id,jdbcType=BIGINT},</if>
            <if test="worker != null">tf_worker_id=#{worker.id,jdbcType=BIGINT},</if>
            <if test="nickname != null">tf_nickname=#{nickname,jdbcType=VARCHAR},</if>
            <if test="createTime != null">tf_createtime=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">tf_updatetime=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where tf_id = #{id,jdbcType=BIGINT}
    </update>
    <select id="listbyBossIdAndWorkerId" resultMap="BaseResultMap">
        SELECT * FROM
        `yeshi_ec_threesale_extra_info` t
        WHERE t.`tf_boss_id` = #{bossId} AND
        t.`tf_worker_id`= #{workerId}
    </select>
    <delete id="deleteByBossIdAndWorkerId" parameterType="java.lang.Long">
        delete from
        yeshi_ec_threesale_extra_info
        WHERE `tf_boss_id` = #{bossId} AND
        `tf_worker_id`= #{workerId}
    </delete>
</mapper>
fanli-service-user/src/main/java/org/fanli/service/user/mapper/invite/ThreeSaleMapper.xml
New file
@@ -0,0 +1,513 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.fanli.service.user.dao.invite.ThreeSaleMapper">
    <resultMap id="BaseResultMap" type="org.fanli.facade.user.entity.invite.ThreeSale">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="state" property="state" jdbcType="BOOLEAN" />
        <result column="succeedTime" property="succeedTime" jdbcType="BIGINT" />
        <result column="createTime" property="createTime" jdbcType="BIGINT" />
        <result column="updateTime" property="updateTime" jdbcType="BIGINT" />
        <result column="expire" property="expire" jdbcType="INTEGER" />
        <association property="boss" column="boss_id"
            resultMap="org.fanli.service.user.dao.account.UserInfoMapper.BaseResultMap" />
        <association property="worker" column="worker_id"
            javaType="com.yeshi.fanli.base.entity.user.UserInfo">
            <id column="worker_id" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    <resultMap id="AllResultMap" type="org.fanli.facade.user.entity.invite.ThreeSale">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="state" property="state" jdbcType="BOOLEAN" />
        <result column="succeedTime" property="succeedTime" jdbcType="BIGINT" />
        <result column="createTime" property="createTime" jdbcType="BIGINT" />
        <result column="updateTime" property="updateTime" jdbcType="BIGINT" />
        <result column="expire" property="expire" jdbcType="INTEGER" />
        <association property="boss" column="boss_id"
            select="org.fanli.service.user.dao.account.UserInfoMapper.selectByPKey" />
        <association property="worker" column="worker_id"
            select="org.fanli.service.user.dao.account.UserInfoMapper.selectByPKey" />
        <association property="threeSaleExtraInfo" column="tf_id"
            resultMap="com.yeshi.fanli.dao.mybatis.ThreeSaleExtraInfoMapper.BaseResultMap" />
    </resultMap>
    <sql id="Base_Column_List">id,boss_id,worker_id,state,expire,succeedTime,createTime,updateTime
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_threeSale where id = #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByUid" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_threeSale where boss_id = #{0} or worker_id=#{0}
    </select>
    <select id="selectBoss"
        resultMap="org.fanli.service.user.dao.account.UserInfoMapper.BaseResultMap"
        parameterType="java.lang.Long">
        select
        u.*
        from yeshi_ec_threeSale s left join
        yeshi_ec_user u on u.id=s.boss_id where worker_id = #{0}
    </select>
    <!-- 根据邀请者ID查询关系 -->
    <select id="listByWorkerId" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_threeSale s where worker_id = #{0}
    </select>
    <select id="listByWorkerAndStateAndExpire" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_threeSale where worker_id = #{workerId} and state
        =#{state} and expire=#{expire}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_threeSale where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="org.fanli.facade.user.entity.invite.ThreeSale"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_threeSale
        (id,boss_id,worker_id,state,expire,succeedTime,createTime,updateTime)
        values
        (#{id,jdbcType=BIGINT},#{boss.id,jdbcType=BIGINT},#{worker.id,jdbcType=BIGINT},#{state,jdbcType=BOOLEAN},#{expire,jdbcType=INTEGER},#{succeedTime,jdbcType=BIGINT},#{createTime,jdbcType=BIGINT},#{updateTime,jdbcType=BIGINT})
    </insert>
    <insert id="insertSelective" parameterType="org.fanli.facade.user.entity.invite.ThreeSale"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_threeSale
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="boss != null">boss_id,</if>
            <if test="worker != null">worker_id,</if>
            <if test="state != null">state,</if>
            <if test="expire != null">expire,</if>
            <if test="succeedTime != null">succeedTime,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateTime != null">updateTime,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="boss != null">#{boss.id,jdbcType=BIGINT},</if>
            <if test="worker != null">#{worker.id,jdbcType=BIGINT},</if>
            <if test="state != null">#{state,jdbcType=BOOLEAN},</if>
            <if test="expire != null">#{expire,jdbcType=INTEGER},</if>
            <if test="succeedTime != null">#{succeedTime,jdbcType=BIGINT},</if>
            <if test="createTime != null">#{createTime,jdbcType=BIGINT},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=BIGINT},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="org.fanli.facade.user.entity.invite.ThreeSale">update
        yeshi_ec_threeSale set boss_id = #{boss.id,jdbcType=BIGINT},worker_id
        = #{worker.id,jdbcType=BIGINT},state =
        #{state,jdbcType=BOOLEAN},
        expire = #{expire,jdbcType=INTEGER},
        succeedTime =
        #{succeedTime,jdbcType=BIGINT},
        createTime =
        #{createTime,jdbcType=BIGINT},
        updateTime =
        #{updateTime,jdbcType=BIGINT}
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.fanli.facade.user.entity.invite.ThreeSale">
        update yeshi_ec_threeSale
        <set>
            <if test="boss != null">boss_id=#{boss.id,jdbcType=BIGINT},</if>
            <if test="worker != null">worker_id=#{worker.id,jdbcType=BIGINT},</if>
            <if test="state != null">state=#{state,jdbcType=BOOLEAN},</if>
            <if test="expire != null">expire=#{expire,jdbcType=INTEGER},</if>
            <if test="succeedTime != null">succeedTime=#{succeedTime,jdbcType=BIGINT},</if>
            <if test="createTime != null">createTime=#{createTime,jdbcType=BIGINT},</if>
            <if test="updateTime != null">updateTime=#{updateTime,jdbcType=BIGINT},</if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="effectThreeSale" parameterType="java.lang.Long">
        update yeshi_ec_threeSale t set t.state=1,
        t.succeedTime = <![CDATA[UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) * 1000]]>,
        t.updateTime = <![CDATA[UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) * 1000]]>
        where t.state=0 and t.worker_id=#{0} AND (t.expire = 0 OR t.expire IS
        NULL)
    </update>
    <delete id="deleteExpireRecord" parameterType="java.lang.Long">
        DELETE FROM
        yeshi_ec_threesale
        WHERE expire = 1 AND boss_id = #{bossId} AND
        worker_id = #{workerId}
    </delete>
    <!-- 查询一度队员集合 -->
    <select id="queryMyFirstTeamList" resultMap="BaseResultMap">
        SELECT * FROM `yeshi_ec_threesale` yet
        WHERE yet.`state` = '1' AND
        yet.`boss_id` = #{bossId} AND (yet.expire = 0
        OR yet.expire IS NULL)
        <if test="key != null and key !='' ">
            and yet.`worker_id` like '%${key}%'
        </if>
        ORDER BY yet.createtime DESC LIMIT ${start},${count}
    </select>
    <select id="queryCountMyFirstTeamList" resultType="java.lang.Long">
        SELECT count(yet.id) FROM `yeshi_ec_threesale` yet
        WHERE yet.`state` =
        '1' AND yet.`boss_id` = #{bossId} AND (yet.expire = 0
        OR yet.expire IS
        NULL)
        <if test="key != null and key !='' ">
            and yet.`worker_id` like '%${key}%'
        </if>
    </select>
    <!-- 查询二度队员集合 -->
    <select id="queryMySecondTeamList" resultMap="BaseResultMap">
        SELECT yet.* FROM (
        SELECT DISTINCT(ts.`id`) AS id FROM
        `yeshi_ec_threesale` ts
        LEFT JOIN yeshi_ec_threesale tf ON
        ts.`boss_id`=tf.`worker_id`
        WHERE ts.`state` = '1' AND
        tf.`boss_id`=#{bossId} AND (ts.expire = 0 OR
        ts.expire IS NULL)
        <if test="key != null and key !='' ">
            and ts.`worker_id` like '%${key}%'
        </if>
        )A
        LEFT JOIN yeshi_ec_threesale yet ON yet.id = A.id
        ORDER BY
        yet.`createtime` DESC LIMIT ${start},${count}
    </select>
    <select id="queryCountMySecondTeamList" resultType="java.lang.Long">
        SELECT COUNT(A.id) FROM (
        SELECT DISTINCT(ts.`id`) AS id FROM
        `yeshi_ec_threesale` ts
        LEFT JOIN yeshi_ec_threesale tf ON
        ts.`boss_id`=tf.`worker_id`
        WHERE ts.`state` = '1' AND
        tf.`boss_id`=#{bossId} AND (ts.expire = 0 OR
        ts.expire IS NULL)
        <if test="key != null and key !='' ">
            and ts.`worker_id` like '%${key}%'
        </if>
        )A
    </select>
    <select id="queryLongTimeFailed" resultType="java.lang.Long">
        <!-- 长时间未邀请成功 -->
        SELECT h.`id` FROM `yeshi_ec_threesale` h
        WHERE h.`state` = 0 AND
        (h.expire = 0 OR h.expire IS NULL)
        <![CDATA[ AND DATE_SUB(CURDATE(), INTERVAL #{daysNum} DAY) > DATE(FROM_UNIXTIME(h.`createTime`/1000)) ]]>
    </select>
    <select id="queryLongTimeSuccess" resultMap="BaseResultMap">
        <!-- 长时间未邀请成功 -->
        SELECT * FROM `yeshi_ec_threesale` h
        WHERE h.`state` = 1 AND (h.expire
        = 0 OR h.expire IS NULL)
        <![CDATA[ AND DATE_SUB(CURDATE(), INTERVAL #{daysNum} DAY) > DATE(FROM_UNIXTIME(h.`createTime`/1000)) ]]>
    </select>
    <update id="updateExpire" parameterType="java.lang.Long">
        update
        yeshi_ec_threeSale t
        set t.expire = 1, t.updateTime = <![CDATA[UNIX_TIMESTAMP(CURRENT_TIMESTAMP()) * 1000]]>
        where t.`id` IN
        <foreach item="item" collection="list" open="(" separator=","
            close=")">#{item}</foreach>
    </update>
    <select id="listFirstTeamQuery" resultMap="AllResultMap">
        SELECT * FROM `yeshi_ec_threesale`
        WHERE 1=1
        <if test="uid != null">
            AND `boss_id` = #{uid}
        </if>
        <if test="state == 0">
            AND `state` = 0 AND (expire = 0 OR expire IS NULL)
        </if>
        <if test="state == 1">
            AND `state` = 1
        </if>
        <if test="state ==2">
            AND `expire` = 1  <!-- 失效 -->
        </if>
        <if test="startTime != null and startTime !='' ">
                <![CDATA[AND FROM_UNIXTIME(createTime/1000) >= #{startTime}]]>
        </if>
        <if test="endTime != null and  endTime !='' ">
                  <![CDATA[AND FROM_UNIXTIME(createTime/1000) <= #{endTime}]]>
        </if>
        ORDER BY createTime DESC
        LIMIT ${start},${count}
    </select>
    <select id="countFirstTeamQuery" resultType="java.lang.Long">
        SELECT count(id) FROM `yeshi_ec_threesale`
        WHERE 1=1
        <if test="uid != null">
            AND `boss_id` = #{uid}
        </if>
        <if test="state == 0">
            AND `state` = 0 AND (expire = 0 OR expire IS NULL)
        </if>
        <if test="state == 1">
            AND `state` = 1
        </if>
        <if test="state ==2">
            AND `expire` = 1  <!-- 失效 -->
        </if>
        <if test="startTime != null and startTime !='' ">
                <![CDATA[AND FROM_UNIXTIME(createTime/1000) >= #{startTime}]]>
        </if>
        <if test="endTime != null and  endTime !=''">
                  <![CDATA[AND FROM_UNIXTIME(createTime/1000) <= #{endTime}]]>
        </if>
    </select>
    <select id="listSecondTeamQuery" resultMap="AllResultMap">
        SELECT yet.* FROM (
        SELECT DISTINCT(ts.`id`) AS id FROM
        `yeshi_ec_threesale` ts
        LEFT JOIN yeshi_ec_threesale tf ON
        ts.`boss_id`=tf.`worker_id`
        WHERE 1=1
        <if test="uid != null">
            AND tf.`boss_id` = #{uid}
        </if>
        <if test="state == 0">
            AND ts.`state` = 0 AND (ts.expire = 0 OR ts.expire IS
            NULL)
        </if>
        <if test="state == 1">
            AND ts.`state` = 1
        </if>
        <if test="state ==2">
            AND ts.`expire` = 1  <!-- 失效 -->
        </if>
        <if test="startTime != null and startTime !='' ">
                    <![CDATA[AND FROM_UNIXTIME(ts.createTime/1000) >= #{startTime}]]>
        </if>
        <if test="endTime != null and  endTime !=''">
                      <![CDATA[AND FROM_UNIXTIME(ts.createTime/1000) <= #{endTime}]]>
        </if>
        )A LEFT JOIN yeshi_ec_threesale yet ON yet.id = A.id
        ORDER BY
        yet.`createtime` DESC
        LIMIT ${start},${count}
    </select>
    <select id="countSecondTeamQuery" resultType="java.lang.Long">
        SELECT COUNT(A.id) FROM (
        SELECT DISTINCT(ts.`id`) AS id FROM
        `yeshi_ec_threesale` ts
        LEFT JOIN yeshi_ec_threesale tf ON
        ts.`boss_id`=tf.`worker_id`
        WHERE 1=1
        <if test="uid != null">
            AND tf.`boss_id` = #{uid}
        </if>
        <if test="state == 0">
            AND ts.`state` = 0 AND (ts.expire = 0 OR ts.expire IS
            NULL)
        </if>
        <if test="state == 1">
            AND ts.`state` = 1
        </if>
        <if test="state ==2">
            AND ts.`expire` = 1  <!-- 失效 -->
        </if>
        <if test="startTime != null and startTime !='' ">
                    <![CDATA[AND FROM_UNIXTIME(ts.createTime/1000) >= #{startTime}]]>
        </if>
        <if test="endTime != null and endTime !=''">
                      <![CDATA[AND FROM_UNIXTIME(ts.createTime/1000) <= #{endTime}]]>
        </if>
        )A
    </select>
    <select id="listSuperiorQuery" resultMap="AllResultMap">
        SELECT * FROM `yeshi_ec_threesale` ts
        WHERE ts.`worker_id` = #{uid}
        <if test="state == 0">
            AND ts.`state` = 0 AND (ts.expire = 0 OR ts.expire IS
            NULL)
        </if>
        <if test="state == 1">
            AND ts.`state` = 1
        </if>
        <if test="state ==2">
            AND ts.`expire` = 1  <!-- 失效 -->
        </if>
        ORDER BY ts.`createtime` DESC
        LIMIT ${start},${count}
    </select>
    <select id="countSuperiorQuery" resultType="java.lang.Long">
        SELECT COUNT(ts.id) FROM `yeshi_ec_threesale` ts
        WHERE ts.`worker_id` =
        #{uid}
        <if test="state == 0">
            AND ts.`state` = 0 AND (ts.expire = 0 OR ts.expire IS
            NULL)
        </if>
        <if test="state == 1">
            AND ts.`state` = 1
        </if>
        <if test="state ==2">
            AND ts.`expire` = 1  <!-- 失效 -->
        </if>
    </select>
    <select id="listFirstTeam" resultMap="AllResultMap">
        SELECT * FROM
        `yeshi_ec_threesale` ts
        LEFT JOIN `yeshi_ec_threesale_extra_info` ff
        ON
        ts.`boss_id` = ff.`tf_boss_id` AND ts.`worker_id`=ff.`tf_worker_id`
        WHERE ts.`boss_id` = #{uid}
        ORDER BY ts.state DESC, ts.expire,
        ts.createTime DESC
        LIMIT ${start},${count}
    </select>
    <select id="countFirstTeam" resultType="java.lang.Long">
        SELECT count(id) FROM `yeshi_ec_threesale`
        WHERE `boss_id` = #{uid}
        <if test="state != null">
            AND `state` = #{state}
        </if>
    </select>
    <select id="listSecondTeam" resultMap="AllResultMap">
        SELECT yet.* FROM (
        SELECT
        DISTINCT(ts.`id`) AS id FROM `yeshi_ec_threesale` ts
        LEFT JOIN
        yeshi_ec_threesale tf ON ts.`boss_id`=tf.`worker_id`
        WHERE tf.`boss_id`
        = #{uid})A
        LEFT JOIN yeshi_ec_threesale yet ON yet.id =
        A.id
        LEFT JOIN
        `yeshi_ec_threesale_extra_info` ff
        ON yet.`boss_id` =
        ff.`tf_boss_id`
        AND yet.`worker_id` =ff.`tf_worker_id`
        ORDER BY
        yet.state DESC,
        yet.expire, yet.createTime DESC
        LIMIT ${start},${count}
    </select>
    <select id="countSecondTeam" resultType="java.lang.Long">
        SELECT COUNT(A.id) FROM (
        SELECT DISTINCT(ts.`id`) AS id FROM
        `yeshi_ec_threesale` ts
        LEFT JOIN yeshi_ec_threesale tf ON
        ts.`boss_id`=tf.`worker_id`
        WHERE tf.`boss_id` = #{uid}
        <if test="state != null">
            AND ts.`state` = #{state}
        </if>
        )A
    </select>
    <select id="getMyBoss" resultMap="AllResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_threeSale where
        state = 1 and worker_id=#{uid}
    </select>
    <select id="listbyIdAndBossId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List" />
        FROM yeshi_ec_threeSale
        WHERE id = #{id} AND boss_id=#{uid}
        <if test="expire != null and expire == 1">
            AND `expire` = 1  <!-- 失效 -->
        </if>
    </select>
    <select id="getSuccessRelationshipNum" resultType="java.lang.Integer">
        SELECT IFNULL
        (COUNT(*),0) FROM `yeshi_ec_threesale` t
        WHERE t.`state` = 1 AND
        (t.`worker_id` =${uid} OR t.`boss_id` = ${uid})
    </select>
    <select id="getRelationshipByBossIdAndWorkerId" resultMap="BaseResultMap">
        SELECT * FROM `yeshi_ec_threesale` t
        WHERE t.`boss_id` = ${bossId} AND
        t.`worker_id` = ${workerId}
        AND t.`state` = 0 AND (t.`expire` = 0 OR
        t.`expire`IS NULL)
        LIMIT 1
    </select>
    <select id="getExpireRecord" resultMap="BaseResultMap">
        SELECT * FROM
        `yeshi_ec_threesale`
        WHERE expire = 1 AND boss_id = #{bossId} AND
        worker_id = #{workerId}
    </select>
    <select id="listByBossOrWorker" resultMap="AllResultMap">
        SELECT t.* FROM
        `yeshi_ec_threesale` t LEFT JOIN yeshi_ec_user u1 ON
        t.`boss_id`=u1.`id` LEFT JOIN yeshi_ec_user u2 ON
        t.`worker_id`=u2.`id` WHERE t.`boss_id`=#{key} or t.`worker_id`=#{key}
        or u1.`nick_name` like '%#{key}%' or u2.`nick_name` like '%#{key}%'
        ORDER BY t.`createTime` DESC
    </select>
    <select id="countByBossOrWorker" resultType="java.lang.Long">
        SELECT count(t.id)
        FROM `yeshi_ec_threesale` t LEFT JOIN yeshi_ec_user u1 ON
        t.`boss_id`=u1.`id` LEFT JOIN yeshi_ec_user u2 ON
        t.`worker_id`=u2.`id` WHERE t.`boss_id`=#{key} or t.`worker_id`=#{key}
        or u1.`nick_name` like '%#{key}%' or u2.`nick_name` like '%#{key}%'
    </select>
</mapper>
fanli-service-user/src/main/java/org/fanli/service/user/mapper/invite/msg/MsgInviteDetailMapper.xml
New file
@@ -0,0 +1,159 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.fanli.service.user.dao.invite.msg.MsgInviteDetailMapper">
    <resultMap id="BaseResultMap"
        type="org.fanli.facade.user.entity.invite.msg.MsgInviteDetail">
        <id column="mi_id" property="id" jdbcType="BIGINT" />
        <result column="mi_type" property="msgType"
            typeHandler="org.fanli.facade.user.util.typehandler.MsgTypeInviteTypeEnumHandler" />
        <result column="mi_desc" property="desc" jdbcType="VARCHAR" />
        <result column="mi_beizhu" property="beiZhu" jdbcType="VARCHAR" />
        <result column="mi_read" property="read" jdbcType="BOOLEAN" />
        <result column="mi_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="mi_update_time" property="updateTime" jdbcType="TIMESTAMP" />
        <association property="inviteUser" column="mi_invite_id"
            javaType="org.fanli.facade.user.entity.invite.ThreeSale">
            <id column="mi_invite_id" property="id" jdbcType="BIGINT" />
            <id column="state" property="state" jdbcType="BOOLEAN" />
            <id column="expire" property="expire" jdbcType="INTEGER" />
            <association property="boss" column="boss_id"
                javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
                <id column="boss_id" property="id" jdbcType="BIGINT" />
            </association>
            <association property="worker" column="worker_id"
                javaType="com.yeshi.fanli.base.entity.user.UserInfo">
                <id column="worker_id" property="id" jdbcType="BIGINT" />
                <result column="nick_name" property="nickName" jdbcType="VARCHAR" />
                <result column="portrait" property="portrait" jdbcType="VARCHAR" />
            </association>
        </association>
        <association property="user" column="mi_uid"
            javaType="com.yeshi.fanli.base.entity.user.UserInfo">
            <id column="mi_uid" property="id" jdbcType="BIGINT" />
        </association>
    </resultMap>
    <sql id="Base_Column_List">mi_id,mi_uid,mi_type,mi_invite_id,mi_desc,mi_beizhu,mi_read,mi_create_time,mi_update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_msg_invite where mi_id = #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByThreeSaleId" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        ,
        t.*
        from yeshi_ec_msg_invite left join yeshi_ec_threesale t on
        t.id=mi_invite_id where mi_invite_id = #{0}
    </select>
    <select id="listByUid" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        ,u.`id`,u.`nick_name`,u.`portrait` FROM yeshi_ec_msg_invite i LEFT
        JOIN yeshi_ec_threesale t ON t.`id`=i.`mi_invite_id` LEFT JOIN
        yeshi_ec_user u ON u.`id`=t.`worker_id` where mi_uid = #{uid} order by
        mi_update_time desc limit #{start},#{count}
    </select>
    <select id="countByUid" resultType="java.lang.Long"
        parameterType="java.lang.Long">
        select
        count(mi_id)
        from yeshi_ec_msg_invite where mi_uid=
        #{uid}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_msg_invite where mi_id = #{id,jdbcType=BIGINT}
    </delete>
    <delete id="deleteByThreeSaleId">
        delete from
        yeshi_ec_msg_invite where mi_invite_id =
        #{0}
    </delete>
    <insert id="insert"
        parameterType="org.fanli.facade.user.entity.invite.msg.MsgInviteDetail"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_msg_invite
        (mi_id,mi_uid,mi_type,mi_invite_id,mi_desc,mi_beizhu,mi_read,mi_create_time,mi_update_time)
        values
        (#{id,jdbcType=BIGINT},#{user.id,jdbcType=BIGINT},#{msgType,jdbcType=VARCHAR},#{inviteUser.id,jdbcType=BIGINT},#{desc,jdbcType=VARCHAR},#{beiZhu,jdbcType=VARCHAR},#{read,jdbcType=BOOLEAN},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective"
        parameterType="org.fanli.facade.user.entity.invite.msg.MsgInviteDetail"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_msg_invite
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">mi_id,</if>
            <if test="user != null">mi_uid,</if>
            <if test="msgType != null">mi_type,</if>
            <if test="inviteUser != null">mi_invite_id,</if>
            <if test="desc != null">mi_desc,</if>
            <if test="beiZhu != null">mi_beizhu,</if>
            <if test="read != null">mi_read,</if>
            <if test="createTime != null">mi_create_time,</if>
            <if test="updateTime != null">mi_update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="user != null">#{user.id,jdbcType=BIGINT},</if>
            <if test="msgType != null">#{msgType,jdbcType=VARCHAR},</if>
            <if test="inviteUser != null">#{inviteUser.id,jdbcType=BIGINT},</if>
            <if test="desc != null">#{desc,jdbcType=VARCHAR},</if>
            <if test="beiZhu != null">#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="read != null">#{read,jdbcType=BOOLEAN},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
        parameterType="org.fanli.facade.user.entity.invite.msg.MsgInviteDetail">update
        yeshi_ec_msg_invite set mi_uid =
        #{user.id,jdbcType=BIGINT},mi_type =
        #{msgType,jdbcType=VARCHAR},mi_invite_id =
        #{inviteUser.id,jdbcType=BIGINT},mi_desc =
        #{desc,jdbcType=VARCHAR},mi_beizhu =
        #{beiZhu,jdbcType=VARCHAR},mi_read =
        #{read,jdbcType=BOOLEAN},mi_create_time =
        #{createTime,jdbcType=TIMESTAMP},mi_update_time =
        #{updateTime,jdbcType=TIMESTAMP} where mi_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective"
        parameterType="org.fanli.facade.user.entity.invite.msg.MsgInviteDetail">
        update yeshi_ec_msg_invite
        <set>
            <if test="user != null">mi_uid=#{user.id,jdbcType=BIGINT},</if>
            <if test="msgType != null">mi_type=#{msgType,jdbcType=VARCHAR},</if>
            <if test="inviteUser != null">mi_invite_id=#{inviteUser.id,jdbcType=BIGINT},</if>
            <if test="desc != null">mi_desc=#{desc,jdbcType=VARCHAR},</if>
            <if test="beiZhu != null">mi_beizhu=#{beiZhu,jdbcType=VARCHAR},</if>
            <if test="read != null">mi_read=#{read,jdbcType=BOOLEAN},</if>
            <if test="createTime != null">mi_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">mi_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where mi_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="setMsgReadByUid" parameterType="java.lang.Long">
        update
        yeshi_ec_msg_invite set mi_read=1 where mi_uid=#{0}
    </update>
</mapper>
fanli-service-user/src/main/java/org/fanli/service/user/mapper/taobao/UserExtraTaoBaoInfoMapper.xml
New file
@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.fanli.service.user.dao.taobao.UserExtraTaoBaoInfoMapper">
    <resultMap id="BaseResultMap"
        type="org.fanli.facade.user.entity.taobao.UserExtraTaoBaoInfo">
        <id column="uiet_id" property="id" jdbcType="BIGINT" />
        <result column="uiet_relation_id" property="relationId"
            jdbcType="VARCHAR" />
        <result column="uiet_relation_update_time" property="relationUpdateTime"
            jdbcType="TIMESTAMP" />
        <result column="uiet_special_id" property="specialId" jdbcType="VARCHAR" />
        <result column="uiet_special_update_time" property="specialUpdateTime"
            jdbcType="TIMESTAMP" />
        <result column="uiet_create_time" property="createTime"
            jdbcType="TIMESTAMP" />
        <result column="uiet_update_time" property="updateTime"
            jdbcType="TIMESTAMP" />
        <result column="uiet_relation_valid" property="relationValid"
            jdbcType="BOOLEAN" />
        <result column="uiet_special_valid" property="specialValid"
            jdbcType="BOOLEAN" />
        <result column="uiet_taobao_uid" property="taoBaoUid" jdbcType="VARCHAR" />
        <result column="uiet_taobao_order_end_6_num" property="taoBaoOrderEnd6Num"
            jdbcType="VARCHAR" />
        <association property="user" column="uiet_uid"
            javaType="com.yeshi.fanli.base.entity.user.UserInfo">
            <id column="uiet_uid" property="id" />
        </association>
    </resultMap>
    <sql id="Base_Column_List">uiet_id,uiet_uid,uiet_relation_id,uiet_relation_update_time,uiet_special_id,uiet_special_update_time,uiet_create_time,uiet_update_time,uiet_relation_valid,uiet_special_valid,uiet_taobao_uid,uiet_taobao_order_end_6_num
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user_info_extra_taobao where uiet_id =
        #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByUid" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user_info_extra_taobao where uiet_uid =
        #{0} limit 1
    </select>
    <select id="selectByTaoBaoUid" resultMap="BaseResultMap"
        parameterType="java.lang.String">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user_info_extra_taobao where uiet_taobao_uid =
        #{0} limit
        1
    </select>
    <select id="selectByRelationIdWithUidNotNull" resultMap="BaseResultMap"
        parameterType="java.lang.String">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user_info_extra_taobao where uiet_relation_id =
        #{0} and
        uiet_uid is not null limit 1
    </select>
    <select id="selectBySpecialIdWithUidNotNull" resultMap="BaseResultMap"
        parameterType="java.lang.String">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_user_info_extra_taobao where uiet_special_id =
        #{0} and
        uiet_uid is not null limit 1
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_user_info_extra_taobao where uiet_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="org.fanli.facade.user.entity.taobao.UserExtraTaoBaoInfo"
        useGeneratedKeys="true" keyProperty="id">insert into
        yeshi_ec_user_info_extra_taobao
        (uiet_id,uiet_uid,uiet_relation_id,uiet_relation_update_time,uiet_special_id,uiet_special_update_time,uiet_create_time,uiet_update_time,uiet_relation_valid,uiet_special_valid,uiet_taobao_uid,uiet_taobao_order_end_6_num)
        values
        (#{id,jdbcType=BIGINT},#{user.id,jdbcType=BIGINT},#{relationId,jdbcType=VARCHAR},#{relationUpdateTime,jdbcType=TIMESTAMP},#{specialId,jdbcType=VARCHAR},#{specialUpdateTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP},#{relationValid,jdbcType=BOOLEAN},#{specialValid,jdbcType=BOOLEAN},#{taoBaoUid,jdbcType=VARCHAR},#{taoBaoOrderEnd6Num,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="org.fanli.facade.user.entity.taobao.UserExtraTaoBaoInfo"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_user_info_extra_taobao
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">uiet_id,</if>
            <if test="user != null">uiet_uid,</if>
            <if test="relationId != null">uiet_relation_id,</if>
            <if test="relationUpdateTime != null">uiet_relation_update_time,</if>
            <if test="specialId != null">uiet_special_id,</if>
            <if test="specialUpdateTime != null">uiet_special_update_time,</if>
            <if test="createTime != null">uiet_create_time,</if>
            <if test="updateTime != null">uiet_update_time,</if>
            <if test="relationValid != null">uiet_relation_valid,</if>
            <if test="specialValid != null">uiet_special_valid,</if>
            <if test="taoBaoUid != null">uiet_taobao_uid,</if>
            <if test="taoBaoOrderEnd6Num != null">uiet_taobao_order_end_6_num,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="user != null">#{user.id,jdbcType=BIGINT},</if>
            <if test="relationId != null">#{relationId,jdbcType=VARCHAR},</if>
            <if test="relationUpdateTime != null">#{relationUpdateTime,jdbcType=TIMESTAMP},</if>
            <if test="specialId != null">#{specialId,jdbcType=VARCHAR},</if>
            <if test="specialUpdateTime != null">#{specialUpdateTime,jdbcType=TIMESTAMP},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="relationValid != null">#{relationValid,jdbcType=BOOLEAN},</if>
            <if test="specialValid != null">#{specialValid,jdbcType=BOOLEAN},</if>
            <if test="taoBaoUid != null">#{taoBaoUid,jdbcType=VARCHAR},</if>
            <if test="taoBaoOrderEnd6Num != null">#{taoBaoOrderEnd6Num,jdbcType=VARCHAR},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="org.fanli.facade.user.entity.taobao.UserExtraTaoBaoInfo">update
        yeshi_ec_user_info_extra_taobao set uiet_uid =
        #{user.id,jdbcType=BIGINT},uiet_relation_id =
        #{relationId,jdbcType=VARCHAR},uiet_relation_update_time =
        #{relationUpdateTime,jdbcType=TIMESTAMP},uiet_special_id =
        #{specialId,jdbcType=VARCHAR},uiet_special_update_time =
        #{specialUpdateTime,jdbcType=TIMESTAMP},uiet_create_time =
        #{createTime,jdbcType=TIMESTAMP},uiet_update_time =
        #{updateTime,jdbcType=TIMESTAMP} ,uiet_relation_valid
        =#{relationValid,jdbcType=BOOLEAN} ,uiet_special_valid
        =#{specialValid,jdbcType=BOOLEAN} ,uiet_taobao_uid
        =#{taoBaoUid,jdbcType=VARCHAR},uiet_taobao_order_end_6_num
        =#{taoBaoOrderEnd6Num,jdbcType=VARCHAR}
        where uiet_id =
        #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.fanli.facade.user.entity.taobao.UserExtraTaoBaoInfo">
        update yeshi_ec_user_info_extra_taobao
        <set>
            <if test="user != null">uiet_uid=#{user.id,jdbcType=BIGINT},</if>
            <if test="relationId != null">uiet_relation_id=#{relationId,jdbcType=VARCHAR},</if>
            <if test="relationUpdateTime != null">uiet_relation_update_time=#{relationUpdateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="specialId != null">uiet_special_id=#{specialId,jdbcType=VARCHAR},</if>
            <if test="specialUpdateTime != null">uiet_special_update_time=#{specialUpdateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createTime != null">uiet_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">uiet_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
            <if test="id !=null">uiet_id =#{id,jdbcType=BIGINT},</if>
            <if test="relationValid !=null">uiet_relation_valid =#{relationValid,jdbcType=BOOLEAN},
            </if>
            <if test="specialValid !=null">uiet_special_valid =#{specialValid,jdbcType=BOOLEAN},
            </if>
            <if test="taoBaoUid !=null">uiet_taobao_uid =#{taoBaoUid,jdbcType=VARCHAR},</if>
            <if test="taoBaoOrderEnd6Num !=null">uiet_taobao_order_end_6_num=#{taoBaoOrderEnd6Num,jdbcType=VARCHAR},
            </if>
        </set>
        where uiet_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="clearUid" parameterType="java.lang.Long">
        update
        yeshi_ec_user_info_extra_taobao set uiet_uid=null where uiet_uid=#{0}
    </update>
</mapper>
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/UserAccountServiceImpl.java
New file
@@ -0,0 +1,880 @@
package org.fanli.service.user.service.impl;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import javax.persistence.criteria.Order;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.fanli.facade.user.dto.account.LoginResult;
import org.fanli.facade.user.dto.wx.WeiXinUser;
import org.fanli.facade.user.entity.account.msg.UserAccountMsgNotificationService;
import org.fanli.facade.user.entity.invite.ThreeSale;
import org.fanli.facade.user.exception.UserAccountException;
import org.fanli.facade.user.service.account.UserAccountService;
import org.fanli.facade.user.service.invite.SpreadUserImgService;
import org.fanli.facade.user.service.taobao.UserExtraTaoBaoInfoService;
import org.fanli.facade.user.util.factory.MsgAccountDetailFactory;
import org.fanli.facade.user.util.wx.WXLoginUtil;
import org.fanli.service.user.dao.account.UserInfoMapper;
import org.fanli.service.user.dao.invite.ThreeSaleMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.FileUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.TimeUtil;
import org.yeshi.utils.tencentcloud.COSManager;
import com.google.gson.Gson;
import com.qcloud.cos.model.COSObjectSummary;
import com.qcloud.cos.model.ObjectListing;
import com.yeshi.fanli.base.Constant;
import com.yeshi.fanli.base.entity.user.UserInfo;
import com.yeshi.fanli.base.log.LogHelper;
import net.sf.json.JSONObject;
@Service
public class UserAccountServiceImpl implements UserAccountService {
    @Resource
    private UserInfoMapper userInfoMapper;
    @Resource
    private BindingAccountMapper bindingAccountMapper;
    @Resource
    private UserConnectHistoryMapper userConnectHistoryMapper;
    @Resource
    private AccountDetailsMapper accountDetailsMapper;
    @Resource
    private HongBaoMapper hongBaoMapper;
    @Resource
    private OrderMapper orderMapper;
    @Resource
    private OrderItemMapper orderItemMapper;
    @Resource
    private ThreeSaleMapper threeSaleMapper;
    @Resource
    private PidOrderMapper pidOrderMapper;
    @Resource
    private AccountMessageMapper accountMessageMapper;
    @Resource
    private MoneyRecordMapper moneyRecordMapper;
    @Resource
    private SpreadUserImgService spreadUserImgService;
    @Resource
    private UserAccountMsgNotificationService userAccountMsgNotificationService;
    @Resource
    private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
    @Transactional
    @Override
    public LoginResult login(HttpServletRequest request, Boolean first, String appId, String code, String phone,
            UserInfo tbUserInfo, boolean wxinstall, int loginType) throws UserAccountException {
        JSONObject logInfo = new JSONObject();
        logInfo.put("appId", appId);
        logInfo.put("code", code);
        logInfo.put("phone", phone);
        if (tbUserInfo != null)
            logInfo.put("tbUserInfo", tbUserInfo.getId());
        logInfo.put("loginType", loginType);
        LogHelper.lgoinInfo(logInfo.toString());
        HttpSession session = request.getSession();
        if (first != null && first == true)
            session.removeAttribute("LAST_LOGIN_USER");
        // 会话中上次登录的用户
        if (wxinstall) {// 安装了微信的状态
            UserInfo lastUser = (UserInfo) session.getAttribute("LAST_LOGIN_USER");
            UserInfo userInfo = null;
            WeiXinUser weiXinUser = null;
            switch (loginType) {
            case 1:// 淘宝
                userInfo = getUserInfoByTaoBaoOpenId(appId, tbUserInfo.getOpenid());
                if (userInfo == null) {// 原先的账号不存在
                    userInfo = new UserInfo();
                    userInfo.setAppId(appId);
                    userInfo.setTbName(tbUserInfo.getTbName());
                    userInfo.setOpenid(tbUserInfo.getOpenid());
                    userInfo.setTbPic(tbUserInfo.getTbPic());
                    userInfo.setNickName(tbUserInfo.getNickName());
                    userInfo.setPortrait(tbUserInfo.getPortrait());
                    userInfo.setLoginType(loginType);
                    session.setAttribute("LAST_LOGIN_USER", userInfo);
                    // 需要微信登录
                    return new LoginResult(LoginResult.TYPE_WX, userInfo);
                } else {// 原先的账号存在
                    // 判定是否绑定了微信
                    if (StringUtil.isNullOrEmpty(userInfo.getWxUnionId())) {// 没有绑定微信
                        userInfo.setLoginType(loginType);
                        session.setAttribute("LAST_LOGIN_USER", userInfo);
                        // 需要微信登录
                        return new LoginResult(LoginResult.TYPE_WX, userInfo);
                    } else {// 绑定了微信
                        updateLatestLoginTime(userInfo.getId());
                        return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
                    }
                }
            case 2:// 微信
                    // 通过Code换取信息
                weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code);
                if (weiXinUser == null)
                    throw new UserAccountException(1001, "无法获取到微信个人信息");
                LogHelper.test("微信授权用户信息:" + new Gson().toJson(weiXinUser));
                userInfo = getUserInfoByWXUnionId(appId, weiXinUser.getUnionid());
                // 直接用的微信登录
                if (lastUser == null) {
                    if (userInfo != null) {
                        // 使分销关系生效
                        threeSaleMapper.effectThreeSale(userInfo.getId());
                        // 更新头像与昵称
                        UserInfo updateUserInfo = new UserInfo(userInfo.getId());
                        updateUserInfo.setNickName(weiXinUser.getNickname());
                        if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl()))
                            updateUserInfo.setPortrait(weiXinUser.getHeadimgurl());
                        updateUserInfo.setWxPic(weiXinUser.getHeadimgurl());
                        updateUserInfo.setWxName(weiXinUser.getNickname());
                        // 设置登录时间与登录类型
                        updateUserInfo.setLastLoginTime(System.currentTimeMillis());
                        updateUserInfo.setLoginType(loginType);
                        updateUserInfo.setLastLoginIp(request.getRemoteHost());
                        userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
                        // 删除邀请图片
                        spreadUserImgService.deleteImgUrl(userInfo.getId());
                        return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
                    }
                    userInfo = new UserInfo();
                    userInfo.setPortrait(weiXinUser.getHeadimgurl());
                    userInfo.setAppId(appId);
                    userInfo.setNickName(weiXinUser.getNickname());
                    userInfo.setWxName(weiXinUser.getNickname());
                    userInfo.setWxOpenId(weiXinUser.getOpenid());
                    userInfo.setWxUnionId(weiXinUser.getUnionid());
                    userInfo.setWxPic(weiXinUser.getHeadimgurl());
                    userInfo.setLastLoginTime(System.currentTimeMillis());
                    userInfo.setLoginType(loginType);
                    userInfo.setLastLoginIp(request.getRemoteHost());
                    addUser(userInfo);
                    return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
                } else {
                    // 本会话采用过其他账号登录
                    if (userInfo != null)// 微信账号存在
                    {
                        if (lastUser.getLoginType() == 2) {
                            session.removeAttribute("LAST_LOGIN_USER");
                            throw new UserAccountException(1002, "微信不能绑定微信");
                        }
                        if (lastUser.getLoginType() == 1 && !StringUtil.isNullOrEmpty(userInfo.getOpenid())) {
                            session.removeAttribute("LAST_LOGIN_USER");
                            throw new UserAccountException(1003, "该微信已经绑定了淘宝账号,请先解绑");
                        }
                        if (lastUser.getLoginType() == 3 && !StringUtil.isNullOrEmpty(userInfo.getPhone())) {
                            session.removeAttribute("LAST_LOGIN_USER");
                            throw new UserAccountException(1003, "该微信已经绑定了电话号码,请先解绑");
                        }
                        // 删除邀请图片
                        spreadUserImgService.deleteImgUrl(userInfo.getId());
                        // 还没有绑定同类型的账号
                        // 两个账号没有同时有独立的UID
                        if (lastUser.getId() == null || lastUser.getId() == 0
                                || lastUser.getId() == userInfo.getId().longValue()) {
                            // 绑定关系
                            UserInfo updateUserInfo = new UserInfo(userInfo.getId());
                            if (!StringUtil.isNullOrEmpty(lastUser.getPhone())) {
                                updateUserInfo.setPhone(lastUser.getPhone());
                                userAccountMsgNotificationService.bindingSuccess(userInfo.getId(),
                                        MsgAccountDetailFactory.TYPE_PHONE);
                            }
                            if (!StringUtil.isNullOrEmpty(lastUser.getOpenid())) {
                                updateUserInfo.setOpenid(lastUser.getOpenid());
                                updateUserInfo.setTbName(lastUser.getTbName());
                                updateUserInfo.setTbPic(lastUser.getTbPic());
                                userAccountMsgNotificationService.bindingSuccess(userInfo.getId(),
                                        MsgAccountDetailFactory.TYPE_TB);
                            }
                            updateUserInfo.setLastLoginTime(System.currentTimeMillis());
                            userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
                            session.removeAttribute("LAST_LOGIN_USER");
                            // 使分销关系生效
                            threeSaleMapper.effectThreeSale(userInfo.getId());
                            return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
                        } else {// 两个账号拥有不同的UID
                            // 询问是否打通
                            // 暂存微信账号
                            // session.setAttribute("WEIXIN_USERINFO",
                            // userInfo);
                            session.removeAttribute("LAST_LOGIN_USER");
                            LoginResult result = new LoginResult(LoginResult.TYPE_CONNECT, lastUser);
                            result.setMainUser(userInfo);
                            result.setLessUser(lastUser);
                            // 使分销关系生效
                            threeSaleMapper.effectThreeSale(userInfo.getId());
                            return result;
                        }
                    } else {// 微信账号不存在
                        // 创建账号,绑定账号
                        userInfo = new UserInfo();
                        userInfo.setPortrait(weiXinUser.getHeadimgurl());
                        userInfo.setAppId(appId);
                        userInfo.setNickName(weiXinUser.getNickname());
                        userInfo.setWxName(weiXinUser.getNickname());
                        userInfo.setWxOpenId(weiXinUser.getOpenid());
                        userInfo.setWxUnionId(weiXinUser.getUnionid());
                        userInfo.setWxPic(weiXinUser.getHeadimgurl());
                        if (!StringUtil.isNullOrEmpty(lastUser.getPhone()))
                            userInfo.setPhone(lastUser.getPhone());
                        if (!StringUtil.isNullOrEmpty(lastUser.getOpenid())) {
                            userInfo.setOpenid(lastUser.getOpenid());
                            userInfo.setTbName(lastUser.getTbName());
                            userInfo.setTbPic(lastUser.getTbPic());
                        }
                        userInfo.setLastLoginTime(System.currentTimeMillis());
                        userInfo.setLoginType(loginType);
                        userInfo.setLastLoginIp(request.getRemoteHost());
                        addUser(userInfo);
                        session.removeAttribute("LAST_LOGIN_USER");
                        return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
                    }
                }
            case 3:// 手机号码
                userInfo = getUserInfoByPhone(appId, phone);
                if (userInfo == null) {// 原先的账号不存在
                    userInfo = new UserInfo();
                    userInfo.setAppId(appId);
                    userInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName());
                    userInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
                    userInfo.setPhone(phone);
                    userInfo.setLoginType(loginType);
                    session.setAttribute("LAST_LOGIN_USER", userInfo);
                    // 询问是否绑定微信
                    return new LoginResult(LoginResult.TYPE_WX, userInfo);
                } else {// 原先的账号存在
                    // 判定是否绑定了微信
                    if (StringUtil.isNullOrEmpty(userInfo.getWxUnionId())) {// 没有绑定微信
                        userInfo.setLoginType(loginType);
                        session.setAttribute("LAST_LOGIN_USER", userInfo);
                        // 需要微信登录
                        return new LoginResult(LoginResult.TYPE_WX, userInfo);
                    } else {// 绑定了微信
                        updateLatestLoginTime(userInfo.getId());
                        return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
                    }
                }
            default:
                return null;
            }
        } else {// 没有安装微信
            LoginResult result = loginNoInstallWX(appId, code, phone, tbUserInfo, loginType);
            if (result.getType() == LoginResult.TYPE_CREATE)
                session.setAttribute("LAST_LOGIN_USER", result.getUser());
            return result;
        }
    }
    @Transactional
    @Override
    public LoginResult loginNoInstallWX(String appId, String code, String phone, UserInfo tbUserInfo, int loginType)
            throws UserAccountException {
        JSONObject logInfo = new JSONObject();
        logInfo.put("appId", appId);
        logInfo.put("code", code);
        logInfo.put("phone", phone);
        if (tbUserInfo != null)
            logInfo.put("tbUserInfo", tbUserInfo.getId());
        logInfo.put("loginType", loginType);
        LogHelper.lgoinInfo(logInfo.toString());
        UserInfo userInfo = null;
        WeiXinUser weiXinUser = null;
        switch (loginType) {
        case 1:// 淘宝
            userInfo = getUserInfoByTaoBaoOpenId(appId, tbUserInfo.getOpenid());
            break;
        case 2:// 微信
                // 通过Code换取信息
            weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code);
            if (weiXinUser == null)
                throw new UserAccountException(1001, "无法获取到微信个人信息");
            userInfo = getUserInfoByWXUnionId(appId, weiXinUser.getUnionid());
            break;
        case 3:// 手机号码
            userInfo = getUserInfoByPhone(appId, phone);
            break;
        }
        if (userInfo != null) {
            UserInfo updateUserInfo = new UserInfo(userInfo.getId());
            updateUserInfo.setLastLoginTime(System.currentTimeMillis());
            userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
            return new LoginResult(LoginResult.TYPE_NORMAL, userInfo);
        } else {// 询问是否创建用户
            userInfo = new UserInfo();
            userInfo.setAppId(appId);
            switch (loginType) {
            case 1:// 淘宝
                userInfo.setTbName(tbUserInfo.getNickName());
                userInfo.setTbPic(tbUserInfo.getPortrait());
                userInfo.setNickName(tbUserInfo.getNickName());
                userInfo.setPortrait(tbUserInfo.getPortrait());
                break;
            case 2:// 微信
                userInfo.setPortrait(weiXinUser.getHeadimgurl());
                userInfo.setNickName(weiXinUser.getNickname());
                userInfo.setWxName(weiXinUser.getNickname());
                userInfo.setWxOpenId(weiXinUser.getOpenid());
                userInfo.setWxUnionId(weiXinUser.getUnionid());
                userInfo.setWxPic(weiXinUser.getHeadimgurl());
                break;
            case 3:// 手机号码
                    // 默认头像与昵称
                userInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
                userInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName());
                userInfo.setPhone(phone);
                break;
            }
            return new LoginResult(LoginResult.TYPE_CREATE, userInfo);
        }
    }
    @Override
    public void connectUsers(HttpSession session) throws UserAccountException {
        UserInfo mainUser = (UserInfo) session.getAttribute("WEIXIN_USERINFO");
        UserInfo lessUser = (UserInfo) session.getAttribute("LAST_LOGIN_USER");
        int lessUserLoginType = lessUser.getLoginType();
        if (mainUser == null || lessUser == null || mainUser.getId() == null || lessUser.getId() == null)
            throw new UserAccountException(30001, "缺少打通账号");
        mainUser = userInfoMapper.selectByPrimaryKeyForUpdate(mainUser.getId());
        lessUser = userInfoMapper.selectByPrimaryKeyForUpdate(lessUser.getId());
        session.removeAttribute("WEIXIN_USERINFO");
        session.removeAttribute("LAST_LOGIN_USER");
        if (mainUser == null || lessUser == null)
            throw new UserAccountException(30002, "缺少打通账号");
        // 判断是否有绑定相同类型的账号
        if (lessUserLoginType == 1) {// 次账号以淘宝登录
            if (!StringUtil.isNullOrEmpty(mainUser.getPhone()) && !StringUtil.isNullOrEmpty(lessUser.getPhone())
                    && !lessUser.getPhone().equalsIgnoreCase(mainUser.getPhone()))
                throw new UserAccountException(30003, "请先解除其中一个账号的手机绑定");
        } else if (lessUserLoginType == 3) {// 次账号以手机号登录
            if (!StringUtil.isNullOrEmpty(mainUser.getOpenid()) && !StringUtil.isNullOrEmpty(lessUser.getOpenid())
                    && !lessUser.getOpenid().equalsIgnoreCase(mainUser.getOpenid()))
                throw new UserAccountException(30003, "请先解除其中一个账号的淘宝绑定");
        }
        connectUsers(mainUser, lessUser);
    }
    @Transactional
    @Override
    public void connectUsers(UserInfo mainUser, UserInfo lessUser) throws UserAccountException {
        mainUser = userInfoMapper.selectByPrimaryKeyForUpdate(mainUser.getId());
        lessUser = userInfoMapper.selectByPrimaryKeyForUpdate(lessUser.getId());
        if (!StringUtil.isNullOrEmpty(mainUser.getOpenid()) && !StringUtil.isNullOrEmpty(lessUser.getOpenid()))
            throw new UserAccountException(9, "两个账号都绑定了淘宝,请解绑其中一个");
        if (!StringUtil.isNullOrEmpty(mainUser.getPhone()) && !StringUtil.isNullOrEmpty(lessUser.getPhone()))
            throw new UserAccountException(9, "两个账号都绑定了手机号码,请解绑其中一个");
        if (lessUser.getMyHongBao().compareTo(new BigDecimal("20")) >= 0
                && mainUser.getMyHongBao().compareTo(new BigDecimal("20")) > 0)
            throw new UserAccountException(10, String.format("账户ID:%s 的资金超过20元,为保证资金安全请联系客服打通", lessUser.getId() + ""));
        // 判定是否绑定了同一支付宝
        List<BindingAccount> mainUserAccountList = bindingAccountMapper.selectByUid(mainUser.getId());
        if (mainUserAccountList != null)
            for (int i = 0; i < mainUserAccountList.size(); i++) {
                if (mainUserAccountList.get(i).getType() == BindingAccount.TYPE_WXPAY) {
                    mainUserAccountList.remove(i);
                    i--;
                }
            }
        List<BindingAccount> lessUserAccountList = bindingAccountMapper.selectByUid(lessUser.getId());
        if (lessUserAccountList != null)
            for (int i = 0; i < lessUserAccountList.size(); i++) {
                if (lessUserAccountList.get(i).getType() == BindingAccount.TYPE_WXPAY) {
                    lessUserAccountList.remove(i);
                    i--;
                }
            }
        // 有不同的支付宝账号
        boolean hasDiffrentAlipayAccount = false;
        if (mainUserAccountList != null && mainUserAccountList.size() > 0 && lessUserAccountList != null
                && lessUserAccountList.size() > 0) {
            if (!mainUserAccountList.get(0).getAccount().equalsIgnoreCase(lessUserAccountList.get(0).getAccount()))
                hasDiffrentAlipayAccount = true;
        }
        if (hasDiffrentAlipayAccount)
            throw new UserAccountException(10, "两个账户都绑定了支付宝,请先解绑其中一个");
        // 判定是否有重叠的账号
        UserInfo updateUser = new UserInfo(mainUser.getId());
        if (!StringUtil.isNullOrEmpty(lessUser.getOpenid())) {
            updateUser.setOpenid(lessUser.getOpenid());
            updateUser.setTbName(lessUser.getTbName());
            updateUser.setTbPic(lessUser.getTbPic());
        }
        if (!StringUtil.isNullOrEmpty(lessUser.getPhone())) {
            updateUser.setPhone(lessUser.getPhone());
        }
        // 备份原来的用户信息
        String logUrl = backupUserImportantInfo(lessUser.getId());
        // 添加打通记录
        UserConnectHistory userConnectHistory = new UserConnectHistory();
        userConnectHistory.setCreateTime(new Date());
        userConnectHistory.setLessUser(lessUser);
        userConnectHistory.setMainUser(mainUser);
        userConnectHistory.setLogUrl(logUrl);
        userConnectHistoryMapper.insertSelective(userConnectHistory);
        userInfoMapper.updateByPrimaryKeySelective(updateUser);
        // 删除原来的账号
        UserInfo updateLessUser = new UserInfo(lessUser.getId());
        updateLessUser.setState(UserInfo.STATE_DELETE);
        updateLessUser.setStateDesc("账号被打通删除");
        userInfoMapper.updateByPrimaryKeySelective(updateLessUser);
        // 融合业务
        userInfoMapper.connectUser(mainUser.getId(), lessUser.getId());
        // 查询是否有多余的新人红包
        List<HongBao> list = hongBaoMapper.selectByUidAndType(mainUser.getId(), HongBao.TYPE_XINREN);
        int subCount = 0;
        int addCount = 0;
        for (HongBao hb : list) {
            if (hb.getMoney().compareTo(new BigDecimal(0)) > 0)
                addCount++;
            if (hb.getMoney().compareTo(new BigDecimal(0)) < 0)
                subCount++;
        }
        // 有2个或者2个以上的新人红包
        if (addCount - subCount > 1) {
            // 扣除一个新人红包
            AccountDetails accountDetails = new AccountDetails();
            accountDetails.setCreateTime(TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
            accountDetails.setExtract(null);
            accountDetails.setMoney("-" + list.get(1).getMoney().toString());
            accountDetails.setOrderItem(null);
            accountDetails.setTitle(" 账号合并扣除重复新人红包");
            accountDetails.setType(AccountDetailsFactory.TUIKUAN);
            accountDetails.setUserInfo(mainUser);
            accountDetailsMapper.insertSelective(accountDetails);
            AccountMessage accountMessage = new AccountMessage();
            accountMessage.setContent(" 账号合并扣除重复新人红包" + list.get(1).getMoney().toString() + "元");
            accountMessage.setCreateTime(System.currentTimeMillis());
            accountMessage.setIsOpen(false);
            accountMessage.setSystemMsgId(0);
            accountMessage.setTitle(" 账号合并扣除重复新人红包");
            accountMessage.setUserInfo(mainUser);
            accountMessageMapper.insertSelective(accountMessage);
            userInfoMapper.subHongBaoByUid(mainUser.getId(), list.get(1).getMoney());
            HongBao hongBao = new HongBao(mainUser, new BigDecimal(0).subtract(list.get(1).getMoney()), null,
                    HongBao.TYPE_XINREN, HongBao.STATE_YILINGQU, System.currentTimeMillis(), System.currentTimeMillis(),
                    System.currentTimeMillis(), null, "账号合并扣除");
            hongBaoMapper.insertSelective(hongBao);
            MoneyRecord moneyRecord = new MoneyRecord(mainUser, hongBao, list.get(1).getMoney(), "账号合并扣除重复新人红包", "账号合并",
                    System.currentTimeMillis(), 2);
            moneyRecordMapper.insertSelective(moneyRecord);
        }
        userAccountMsgNotificationService.connectSuccess(mainUser.getId(), lessUser.getId());
    }
    /**
     * 根据系统与unionid寻找用户
     *
     * @param appId
     * @param unionId
     * @return
     */
    public UserInfo getUserInfoByWXUnionId(String appId, String unionId) throws UserAccountException {
        if (StringUtil.isNullOrEmpty(appId))
            throw new UserAccountException(1, "appId为空");
        if (StringUtil.isNullOrEmpty(unionId))
            throw new UserAccountException(2, "unionId为空");
        return userInfoMapper.getUserInfoByAppIdAndWXUnionId(appId, unionId);
    }
    /**
     * 根据系统和淘宝的Openid寻找用户
     *
     * @param appId
     * @param openId
     * @return
     */
    public UserInfo getUserInfoByTaoBaoOpenId(String appId, String openId) throws UserAccountException {
        if (StringUtil.isNullOrEmpty(appId))
            throw new UserAccountException(1, "appId为空");
        if (StringUtil.isNullOrEmpty(openId))
            throw new UserAccountException(2, "openId为空");
        return userInfoMapper.getUserInfoByAppIdAndTaoBaoOpenId(appId, openId);
    }
    /**
     * 根据系统和电话号码寻找用户
     *
     * @param appId
     * @param phone
     * @return
     */
    public UserInfo getUserInfoByPhone(String appId, String phone) throws UserAccountException {
        if (StringUtil.isNullOrEmpty(appId))
            throw new UserAccountException(1, "appId为空");
        if (StringUtil.isNullOrEmpty(phone))
            throw new UserAccountException(2, "phone为空");
        return userInfoMapper.getUserInfoByAppIdAndPhone(appId, phone);
    }
    private void updateLatestLoginTime(Long uid) {
        UserInfo userInfo = new UserInfo(uid);
        userInfo.setLastLoginTime(System.currentTimeMillis());
        userInfoMapper.updateByPrimaryKeySelective(userInfo);
    }
    @Override
    public void register(UserInfo userInfo) throws UserAccountException {
        if (!StringUtil.isNullOrEmpty(userInfo.getPhone())) {
            UserInfo user = getUserInfoByPhone(userInfo.getAppId(), userInfo.getPhone());
            if (user != null)
                throw new UserAccountException(50001, "电话号码已经被绑定");
        }
        if (!StringUtil.isNullOrEmpty(userInfo.getOpenid())) {
            UserInfo user = getUserInfoByTaoBaoOpenId(userInfo.getAppId(), userInfo.getOpenid());
            if (user != null)
                throw new UserAccountException(50002, "淘宝号已经被绑定");
        }
        if (!StringUtil.isNullOrEmpty(userInfo.getWxUnionId())) {
            UserInfo user = getUserInfoByWXUnionId(userInfo.getAppId(), userInfo.getWxUnionId());
            if (user != null)
                throw new UserAccountException(50003, "微信号已经被注册");
        }
        addUser(userInfo);
    }
    @Override
    public void addUser(UserInfo user) {
        Long maxUid = userInfoMapper.getMaxUid();
        if (maxUid == null)
            maxUid = 100000L;
        long dd = (long) (Math.random() * 100);
        if (dd == 0) {
            dd = 1;
        }
        long uid = maxUid + dd;
        user.setId(uid);
        user.setCreatetime(System.currentTimeMillis());
        user.setRank(0);
        if (StringUtil.isNullOrEmpty(user.getPortrait()))
            user.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
        userInfoMapper.insertSelective(user);
        if (StringUtil.isNullOrEmpty(user.getNickName())) {
            UserInfo updateUserInfo = new UserInfo(user.getId());
            updateUserInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName() + user.getId());
            userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
        }
        // 添加新人红包
        // hongBaoService.setNewUserHongBaoMyBatis(user, 1);
    }
    @Override
    public void updateUserSelective(UserInfo user) {
        userInfoMapper.updateByPrimaryKeySelective(user);
    }
    @Override
    public void bindPhone(Long uid, String phone) throws UserAccountException {
        UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
        if (user == null)
            throw new UserAccountException(4, "用户不存在");
        if (!StringUtil.isNullOrEmpty(user.getPhone()))
            throw new UserAccountException(5, "当前账号已经绑定了手机号,请先解绑");
        UserInfo phoneUser = getUserInfoByPhone(user.getAppId(), phone);
        if (phoneUser != null)
            throw new UserAccountException(6, "当前电话号码已经被绑定");
        UserInfo update = new UserInfo(user.getId());
        update.setPhone(phone);
        userInfoMapper.updateByPrimaryKeySelective(update);
        userAccountMsgNotificationService.bindingSuccess(uid, MsgAccountDetailFactory.TYPE_PHONE);
    }
    @Override
    public void unBindPhone(Long uid, String phone) throws UserAccountException {
        UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
        if (user == null)
            throw new UserAccountException(4, "用户不存在");
        if (StringUtil.isNullOrEmpty(user.getPhone()))
            throw new UserAccountException(4, "尚未绑定电话号码");
        if (!user.getPhone().equalsIgnoreCase(phone))
            throw new UserAccountException(4, "原绑定手机号输入错误");
        if (StringUtil.isNullOrEmpty(user.getWxUnionId()) && StringUtil.isNullOrEmpty(user.getOpenid()))
            throw new UserAccountException(5, "不能解除绑定");
        UserInfo updateUserInfo = new UserInfo(uid);
        updateUserInfo.setPhone("");
        userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
        userAccountMsgNotificationService.unBindingSuccess(uid, MsgAccountDetailFactory.TYPE_PHONE);
    }
    @Override
    public void bindTaoBao(Long uid, String tbOpenId, String tbNickName, String tbPortrait)
            throws UserAccountException {
        UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
        if (user == null)
            throw new UserAccountException(4, "用户不存在");
        if (!StringUtil.isNullOrEmpty(user.getOpenid()) && !user.getOpenid().equalsIgnoreCase(tbOpenId))
            throw new UserAccountException(5, "当前账号已经绑定了淘宝,请先解绑");
        // 绑定同一个淘宝号
        if (!StringUtil.isNullOrEmpty(user.getOpenid()) && user.getOpenid().equalsIgnoreCase(tbOpenId))
            return;
        UserInfo taoBaoUser = getUserInfoByTaoBaoOpenId(user.getAppId(), tbOpenId);
        if (taoBaoUser != null)
            throw new UserAccountException(6, "当前淘宝号已经被绑定");
        UserInfo update = new UserInfo(user.getId());
        update.setOpenid(tbOpenId);
        update.setTbName(tbNickName);
        update.setTbPic(tbPortrait);
        // 如果没有绑定微信就以淘宝的头像和昵称作为用户的头像与昵称
        if (StringUtil.isNullOrEmpty(user.getWxUnionId())) {
            update.setNickName(tbNickName);
            update.setPortrait(tbPortrait);
        }
        userInfoMapper.updateByPrimaryKeySelective(update);
        userAccountMsgNotificationService.bindingSuccess(uid, MsgAccountDetailFactory.TYPE_TB);
    }
    @Override
    public void unBindTaoBao(Long uid) throws UserAccountException {
        UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
        if (user == null)
            throw new UserAccountException(4, "用户不存在");
        if (StringUtil.isNullOrEmpty(user.getOpenid()))
            throw new UserAccountException(5, "当前账号尚未绑定淘宝");
        if (StringUtil.isNullOrEmpty(user.getWxUnionId()) && StringUtil.isNullOrEmpty(user.getPhone()))
            throw new UserAccountException(5, "不能接触绑定");
        UserInfo update = new UserInfo(user.getId());
        update.setOpenid("");
        update.setTbName("");
        update.setTbPic("");
        // 判断是否有微信绑定
        if (StringUtil.isNullOrEmpty(user.getWxUnionId())) {
            update.setNickName(Constant.systemCommonConfig.getDefaultNickName() + user.getId());
            update.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
        }
        userInfoMapper.updateByPrimaryKeySelective(update);
        userExtraTaoBaoInfoService.unBindUid(uid);
        userAccountMsgNotificationService.unBindingSuccess(uid, MsgAccountDetailFactory.TYPE_TB);
    }
    @Override
    public void changeWXBind(Long uid, String code) throws UserAccountException {
        UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
        if (user == null)
            throw new UserAccountException(4, "用户不存在");
        WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code);
        if (weiXinUser == null)
            throw new UserAccountException(10, "获取微信用户信息失败");
        if (weiXinUser.getUnionid().equalsIgnoreCase(user.getWxUnionId()))
            throw new UserAccountException(12, "亲,请登录其它微信号进行更换绑定");
        UserInfo newUser = getUserInfoByWXUnionId(user.getAppId(), weiXinUser.getUnionid());
        if (newUser != null)
            throw new UserAccountException(13, "亲,你要更换绑定的微信号已被其他账号绑定");
        UserInfo updateUserInfo = new UserInfo(uid);
        updateUserInfo.setWxName(weiXinUser.getNickname());
        updateUserInfo.setWxOpenId(weiXinUser.getOpenid());
        updateUserInfo.setWxPic(weiXinUser.getHeadimgurl());
        updateUserInfo.setWxUnionId(weiXinUser.getUnionid());
        updateUserInfo.setNickName(weiXinUser.getNickname());
        updateUserInfo.setPortrait(weiXinUser.getHeadimgurl());
        if (StringUtil.isNullOrEmpty(weiXinUser.getNickname())) {
            updateUserInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName());
        }
        if (StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) {
            updateUserInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
        }
        userInfoMapper.updateByPrimaryKeySelective(updateUserInfo);
        userAccountMsgNotificationService.changeBindingSuccess(uid, MsgAccountDetailFactory.TYPE_WX);
    }
    @Override
    public String backupUserImportantInfo(Long uid) {
        String logPath = String.format(FileUtil.getCacheDir() + "/benfen_%s_" + uid + ".log",
                TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMddHHmmss"));
        // 备份用户信息
        UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
        // 备份资金明细
        List<AccountDetails> accountDetailsList = accountDetailsMapper.selectByUid(uid);
        // 备份红包信息
        List<HongBao> hongBaoList = hongBaoMapper.selectByUid(uid);
        // 备份订单,子订单信息
        List<Order> orderList = orderMapper.selectByUid(uid);
        List<OrderItem> orderItemList = orderItemMapper.selectByUid(uid);
        // 备份邀请关系
        List<ThreeSale> threeSaleList = threeSaleMapper.selectByUid(uid);
        // 备份分享赚
        List<PidOrder> pidOrderList = pidOrderMapper.selectByUid(uid);
        FileWriter fw = null;
        try {
            // 设置为:True,表示写入的时候追加数据
            fw = new FileWriter(new File(logPath), true);
            fw.write("#UserInfo" + "\r\n");
            fw.write(JsonUtil.getSimpleGsonWithDate().toJson(user) + "\r\n");
            fw.write("#AccountDetails" + "\r\n");
            fw.write(JsonUtil.getSimpleGsonWithDate().toJson(accountDetailsList) + "\r\n");
            fw.write("#HongBao" + "\r\n");
            fw.write(JsonUtil.getSimpleGsonWithDate().toJson(hongBaoList) + "\r\n");
            fw.write("#Order" + "\r\n");
            fw.write(JsonUtil.getSimpleGsonWithDate().toJson(orderList) + "\r\n");
            fw.write("#OrderItem" + "\r\n");
            fw.write(JsonUtil.getSimpleGsonWithDate().toJson(orderItemList) + "\r\n");
            fw.write("#ThreeSale" + "\r\n");
            fw.write(JsonUtil.getSimpleGsonWithDate().toJson(threeSaleList) + "\r\n");
            fw.write("#PidOrder" + "\r\n");
            fw.write(JsonUtil.getSimpleGsonWithDate().toJson(pidOrderList) + "\r\n");
            fw.close();
            String logUrl = COSManager.getInstance()
                    .uploadFile(new File(logPath), "beifen/" + new File(logPath).getName()).getUrl();
            return logUrl;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (new File(logPath).exists())
                new File(logPath).delete();
        }
        return null;
    }
    @Override
    public void clearUserPortrait(Long uid) {
        if (uid == null)
            return;
        UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
        String prefix = String.format("/portrait/wx/%s_", user.getWxUnionId());
        ObjectListing list = COSManager.getInstance().getObjectList(prefix, null, 30);
        if (list != null && list.getObjectSummaries() != null)
            for (COSObjectSummary object : list.getObjectSummaries()) {
                if (user.getWxPic() != null && !user.getWxPic().contains(object.getKey())) {
                    COSManager.getInstance().deleteFile(object.getKey());
                }
            }
    }
    @Override
    public String repairPortrait(Long uid) {
        if (uid == null)
            return null;
        UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
        if (user == null)
            return null;
        String prefix = String.format("/portrait/wx/%s_", user.getWxUnionId());
        ObjectListing list = COSManager.getInstance().getObjectList(prefix, null, 30);
        // 查询头像文件是否还存在
        boolean exist = false;
        if (list != null && list.getObjectSummaries() != null)
            for (COSObjectSummary object : list.getObjectSummaries()) {
                if (user.getPortrait().contains(object.getKey())) {
                    exist = true;
                    break;
                }
            }
        if (!exist && list.getObjectSummaries() != null && list.getObjectSummaries().size() > 0) {
            COSObjectSummary object = list.getObjectSummaries().get(list.getObjectSummaries().size() - 1);
            String portrait = String.format("https://%s.file.myqcloud.com/%s", object.getBucketName(), object.getKey());
            if (!StringUtil.isNullOrEmpty(portrait)) {
                UserInfo updateUser = new UserInfo(uid);
                updateUser.setPortrait(portrait);
                userInfoMapper.updateByPrimaryKeySelective(updateUser);
                return portrait;
            }
        }
        return user.getPortrait();
    }
}
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/account/msg/MsgAccountDetailServiceImpl.java
New file
@@ -0,0 +1,57 @@
package org.fanli.service.user.service.impl.account.msg;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.fanli.facade.system.service.msg.UserMsgReadStateService;
import org.fanli.facade.user.entity.account.msg.MsgAccountDetail;
import org.fanli.facade.user.exception.account.msg.MsgAccountDetailException;
import org.fanli.facade.user.service.account.msg.MsgAccountDetailService;
import org.fanli.service.user.dao.account.msg.MsgAccountDetailMapper;
import org.springframework.stereotype.Service;
import org.yeshi.utils.StringUtil;
import com.yeshi.fanli.base.Constant;
@Service
public class MsgAccountDetailServiceImpl implements MsgAccountDetailService {
    @Resource
    private MsgAccountDetailMapper msgAccountDetailMapper;
    @Resource
    private UserMsgReadStateService userMsgReadStateService;
    @Override
    public void addMsgAccountDetail(MsgAccountDetail detail) throws MsgAccountDetailException {
        if (detail == null)
            throw new MsgAccountDetailException(1, "消息为空");
        if (StringUtil.isNullOrEmpty(detail.getTitle()) || StringUtil.isNullOrEmpty(detail.getContent())
                || detail.getType() == null || detail.getUser() == null)
            throw new MsgAccountDetailException(2, "消息内容不完整");
        // 持久化到数据库
        detail.setCreateTime(new Date());
        detail.setUpdateTime(new Date());
        detail.setRead(false);
        msgAccountDetailMapper.insertSelective(detail);
        userMsgReadStateService.addAccountMsgUnReadCount(detail.getUser().getId(), 1);
    }
    @Override
    public List<MsgAccountDetail> listMsgAccountDetail(Long uid, int page) {
        return msgAccountDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
    }
    @Override
    public long countMsgAccountDetail(Long uid) {
        return msgAccountDetailMapper.countByUid(uid);
    }
    @Override
    public void readMsgByUid(Long uid) {
        msgAccountDetailMapper.setMsgReadByUid(uid);
    }
}
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/account/msg/UserAccountMsgNotificationServiceImpl.java
New file
@@ -0,0 +1,68 @@
package org.fanli.service.user.service.impl.account.msg;
import javax.annotation.Resource;
import org.fanli.facade.user.entity.account.msg.MsgAccountDetail;
import org.fanli.facade.user.entity.account.msg.UserAccountMsgNotificationService;
import org.fanli.facade.user.exception.account.msg.MsgAccountDetailException;
import org.fanli.facade.user.service.account.msg.MsgAccountDetailService;
import org.fanli.facade.user.util.factory.MsgAccountDetailFactory;
import org.springframework.stereotype.Service;
@Service
public class UserAccountMsgNotificationServiceImpl implements UserAccountMsgNotificationService {
    @Resource
    private MsgAccountDetailService msgAccountDetailService;
    @Override
    public void bindingSuccess(Long uid, int type) {
        MsgAccountDetail detail = MsgAccountDetailFactory.createBindingAccount(uid, type);
        try {
            msgAccountDetailService.addMsgAccountDetail(detail);
        } catch (MsgAccountDetailException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void unBindingSuccess(Long uid, int type) {
        MsgAccountDetail detail = MsgAccountDetailFactory.createUnBindingAccount(uid, type);
        try {
            msgAccountDetailService.addMsgAccountDetail(detail);
        } catch (MsgAccountDetailException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void changeBindingSuccess(Long uid, int type) {
        MsgAccountDetail detail = MsgAccountDetailFactory.createChangeBindingAccount(uid, type);
        try {
            msgAccountDetailService.addMsgAccountDetail(detail);
        } catch (MsgAccountDetailException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void connectSuccess(Long uid, Long lessUid) {
        MsgAccountDetail detail = MsgAccountDetailFactory.createConnectAccount(uid, lessUid);
        try {
            msgAccountDetailService.addMsgAccountDetail(detail);
        } catch (MsgAccountDetailException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void userRank(Long uid, String orderType, int orderCount, String rankName) {
        MsgAccountDetail detail = MsgAccountDetailFactory.createUserRank(uid, orderType, orderCount, rankName);
        try {
            msgAccountDetailService.addMsgAccountDetail(detail);
        } catch (MsgAccountDetailException e) {
            e.printStackTrace();
        }
    }
}
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/invite/QrCodeServiceImpl.java
New file
@@ -0,0 +1,124 @@
package org.fanli.service.user.service.impl.invite;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.annotation.Resource;
import org.fanli.facade.user.service.invite.QrCodeService;
import org.fanli.facade.user.service.invite.SpreadUserImgService;
import org.fanli.facade.user.util.InviteImageUtil;
import org.springframework.stereotype.Service;
import org.yeshi.utils.FileUtil;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.QRCodeUtil;
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.tencentcloud.COSManager;
import com.yeshi.fanli.base.Constant;
@Service
public class QrCodeServiceImpl implements QrCodeService {
    @Resource
    private SpreadUserImgService spreadUserImgService;
    @Override
    public String drawInviteQrCode(String url, Long uid, String portrait) throws IOException {
        if (url != null && !url.equals("")) {
            String targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg";
            String erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg";
            String erCode = HttpUtil.getShortLink("http://" + Constant.wxGZConfig.getLoginHost() + "/"
                    + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid);
            // 生成
            try {
                QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath);
            } catch (Exception e) {
                e.printStackTrace();
            }
            InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景
            InputStream portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像
            InputStream erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码
            // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片
            InviteImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath);
            if (new File(targetPath).exists() && new File(targetPath).length() > 0) {
                // 上传文件
                // 将url 转为 md5 让到下面中添加 在比较md5的值
                int index = url.lastIndexOf("/");
                String newUrl = url.substring(index + 1);
                String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf("."));
                String imgUrl = COSManager.getInstance()
                        .uploadFile(new File(targetPath),
                                "ercode/" + "ercode_" + uid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg")
                        .getUrl();
                if (new File(erCodeTempPath).exists())
                    new File(erCodeTempPath).delete();
                if (new File(targetPath).exists())
                    new File(targetPath).delete();
                return imgUrl;
            }
        }
        return null;
    }
    @Override
    public String drawInviteQrCode(String url, Long uid, String portrait, int erCodePostionX, int erCodePostionY,
            int erCodeSize) throws IOException {
        if (!StringUtil.isNullOrEmpty(url)) {
            String targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg";
            String erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg";
            String erCode = HttpUtil.getShortLink("http://" + Constant.wxGZConfig.getLoginHost() + "/"
                    + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid);
            // 生成
            try {
                QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath);
            } catch (Exception e) {
                e.printStackTrace();
            }
            InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景
            InputStream portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像
            InputStream erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码
            // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片
            InviteImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath,
                    erCodePostionX, erCodePostionY, erCodeSize);
            if (new File(targetPath).exists() && new File(targetPath).length() > 0) {
                // 上传文件
                // 将url 转为 md5 让到下面中添加 在比较md5的值
                int index = url.lastIndexOf("/");
                String newUrl = url.substring(index + 1);
                String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf("."));
                String imgUrl = COSManager.getInstance()
                        .uploadFile(new File(targetPath), "ercode/" + "ercode_" + uid + "_" + urlMd5 + ".jpg").getUrl();
                if (new File(erCodeTempPath).exists())
                    new File(erCodeTempPath).delete();
                if (new File(targetPath).exists())
                    new File(targetPath).delete();
                return imgUrl;
            }
        }
        return null;
    }
}
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/invite/SpreadUserImgServiceImpl.java
New file
@@ -0,0 +1,237 @@
package org.fanli.service.user.service.impl.invite;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.fanli.facade.user.entity.invite.SpreadImg;
import org.fanli.facade.user.entity.invite.SpreadUserImg;
import org.fanli.facade.user.service.invite.QrCodeService;
import org.fanli.facade.user.service.invite.SpreadUserImgService;
import org.fanli.service.user.dao.account.UserInfoMapper;
import org.fanli.service.user.dao.invite.SpreadImgMapper;
import org.fanli.service.user.dao.invite.SpreadUserImgMapper;
import org.springframework.stereotype.Service;
import org.yeshi.utils.ListUtil;
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.tencentcloud.COSManager;
import com.yeshi.fanli.base.Constant;
import com.yeshi.fanli.base.entity.user.UserInfo;
@Service
public class SpreadUserImgServiceImpl implements SpreadUserImgService {
    @Resource
    private SpreadUserImgMapper spreadUserImgMapper;
    @Resource
    private QrCodeService qrCodeService;
    @Resource
    private SpreadImgMapper spreadImgMapper;
    @Resource
    private UserInfoMapper userInfoMapper;
    @Override
    public void addUserInviteImg(Long uid, String imgUrl) {
        SpreadUserImg spreadUserImg = new SpreadUserImg();
        spreadUserImg.setUid(uid);
        spreadUserImg.setUrl(imgUrl); // 服务器上的url地址
        spreadUserImg.setType(0);
        spreadUserImg.setCreatetime(new Date());
        spreadUserImgMapper.insertSelective(spreadUserImg);
    }
    @Override
    public List<String> getImgUrlList(Long uid) {
        return spreadUserImgMapper.getImgUrlList(uid);
    }
    @Override
    public int imgUrlCount(Long uid) {
        return spreadUserImgMapper.imgUrlCount(uid);
    }
    @Override
    public void deleteImgUrl(Long uid) {
        // 先删除远程文件
        List<String> urlList = getImgUrlList(uid);
        spreadUserImgMapper.deleteImgUrl(uid);
        if (urlList != null)
            for (String img : urlList) {
                COSManager.getInstance().deleteFile(img);
            }
    }
    // 获取图片的MD5值
    private String getSpreadUserImgMD5(String url) {
        // https://ec-1255749512.file.myqcloud.com/ercode/ercode_578435_16a56f70b2b74aae9277f0e87a242f47.jpg
        String imgName = url.split("_")[url.split("_").length - 1];
        return imgName.replace(".jpg", "").replace(".png", "");
    }
    // 获取图片的MD5值
    private String getSpreadImgMD5(String url) {
        // https://ec-1255749512.file.myqcloud.com/16a56f70b2b74aae9277f0e87a242f47.png
        String imgName = url.split("/")[url.split("/").length - 1];
        return imgName.substring(0, imgName.indexOf("."));
    }
    @Override
    public List<String> getUserSpreadImg(UserInfo user) {
        List<String> imgList = new ArrayList<>();
        // 查询当前用户的推广图
        List<SpreadUserImg> spreadUserImgList = spreadUserImgMapper.listByUid(user.getId());
        // 查询系统的推广图
        List<SpreadImg> spreadImgList = spreadImgMapper.listAll();
        for (SpreadUserImg img : spreadUserImgList) {
            img.setMd5(getSpreadUserImgMD5(img.getUrl()));
        }
        for (SpreadImg img : spreadImgList) {
            img.setMd5(getSpreadImgMD5(img.getUrl()));
        }
        Comparator<SpreadImg> cmSpreadImg = new Comparator<SpreadImg>() {
            @Override
            public int compare(SpreadImg o1, SpreadImg o2) {
                return o1.getMd5().compareTo(o2.getMd5());
            }
        };
        Comparator<SpreadUserImg> cmUserSpreadImg = new Comparator<SpreadUserImg>() {
            @Override
            public int compare(SpreadUserImg o1, SpreadUserImg o2) {
                return o1.getMd5().compareTo(o2.getMd5());
            }
        };
        Collections.sort(spreadUserImgList, cmUserSpreadImg);
        Collections.sort(spreadImgList, cmSpreadImg);
        boolean equal = true;
        if (spreadUserImgList.size() == spreadImgList.size())
            for (int i = 0; i < spreadUserImgList.size(); i++) {
                if (!spreadUserImgList.get(i).getMd5().equalsIgnoreCase(spreadImgList.get(i).getMd5())) {
                    equal = false;
                    break;
                }
            }
        else
            equal = false;
        // 没有更改
        if (equal) {
            for (SpreadUserImg userImg : spreadUserImgList)
                imgList.add(userImg.getUrl());
            return imgList;
        }
        // 有过更改
        List<String> spreadUserMD5List = new ArrayList<>();
        for (SpreadUserImg userImg : spreadUserImgList)
            spreadUserMD5List.add(userImg.getMd5());
        List<String> spreadMD5List = new ArrayList<>();
        for (SpreadImg img : spreadImgList)
            spreadMD5List.add(img.getMd5());
        // 删除多余的
        // 获取交集
        List<String> ilist = ListUtil.getIntersection(spreadUserMD5List, spreadMD5List);
        // 获取多余的集合
        List<String> extraList = ListUtil.getDifference(spreadUserMD5List, ilist);
        for (String md5 : extraList) {
            for (SpreadUserImg img : spreadUserImgList)
                if (img.getMd5().equalsIgnoreCase(md5)) {
                    spreadUserImgMapper.deleteByPrimaryKey(img.getId());
                    break;
                }
        }
        List<String> dlist = ListUtil.getDifference(spreadMD5List, ilist);
        // 添加原来没有的
        if (dlist != null)
            for (String md5 : dlist) {
                for (SpreadImg img : spreadImgList)
                    if (img.getMd5().equalsIgnoreCase(md5)) {
                        // 画图
                        try {
                            String imgUrl = qrCodeService.drawInviteQrCode(img.getUrl(), user.getId(),
                                    StringUtil.isNullOrEmpty(user.getPortrait())
                                            ? Constant.systemCommonConfig.getDefaultPortrait() : user.getPortrait());
                            if (!StringUtil.isNullOrEmpty(imgUrl)) {
                                if (imgUrl != null) {
                                    addUserInviteImg(user.getId(), imgUrl);
                                }
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        } // 背景图
                        break;
                    }
            }
        // 重新查询
        spreadUserImgList = spreadUserImgMapper.listByUid(user.getId());
        imgList.clear();
        if (spreadUserImgList != null)
            for (SpreadUserImg img : spreadUserImgList)
                imgList.add(img.getUrl());
        return imgList;
    }
    @Override
    public String getUserSpreadImg(UserInfo user, String bgImg) {
        // 查询是否存在
        // String md5 = getSpreadImgMD5(bgImg);
        // List<SpreadUserImg> spreadUserImgList = spreadUserImgDao.list("from
        // SpreadUserImg su where su.uid=" + uid);
        // for (SpreadUserImg img : spreadUserImgList) {
        // img.setMd5(getSpreadUserImgMD5(img.getUrl()));
        // if (md5.equalsIgnoreCase(getSpreadUserImgMD5(img.getUrl())))
        // return img.getUrl();// 原来存在
        // }
        // 生成
        try {
            String imgUrl = qrCodeService.drawInviteQrCode(bgImg, user.getId(), user.getPortrait());
            return imgUrl;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    @Override
    public String getUserSpreadImg(Long uid, String bgImg, int erCodePostionX, int erCodePostionY, int erCodeSize) {
        UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
        try {
            String imgUrl = qrCodeService.drawInviteQrCode(bgImg, uid, user.getPortrait(), erCodePostionX,
                    erCodePostionY, erCodeSize);
            return imgUrl;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    @Override
    public int countUserSpreadImg(Long uid) {
        return spreadUserImgMapper.listByUid(uid).size();
    }
}
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/invite/ThreeSaleSerivceImpl.java
New file
@@ -0,0 +1,558 @@
package org.fanli.service.user.service.impl.invite;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.fanli.facade.system.service.hongbao.HongBaoManageService;
import org.fanli.facade.user.entity.invite.ThreeSale;
import org.fanli.facade.user.entity.invite.ThreeSaleExtraInfo;
import org.fanli.facade.user.exception.invite.ThreeSaleException;
import org.fanli.facade.user.service.account.UserInfoService;
import org.fanli.facade.user.service.invite.ThreeSaleSerivce;
import org.fanli.facade.user.service.invite.msg.MsgInviteDetailService;
import org.fanli.facade.user.service.invite.msg.UserInviteMsgNotificationService;
import org.fanli.service.user.dao.account.UserInfoMapper;
import org.fanli.service.user.dao.invite.ThreeSaleMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.StringUtil;
import com.yeshi.fanli.base.Constant;
import com.yeshi.fanli.base.entity.user.UserInfo;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Service
public class ThreeSaleSerivceImpl implements ThreeSaleSerivce {
    @Resource
    private HongBaoManageService hongBaoManageService;
    @Resource
    private UserInfoService userInfoService;
    @Resource
    private UserInfoMapper userInfoMapper;
    @Resource
    private ThreeSaleMapper threeSaleMapper;
    @Resource
    private UserInviteMsgNotificationService userInviteMsgNotificationService;
    @Resource
    private MsgInviteDetailService msgInviteDetailService;
    public UserInfo getBoss(long uid) {
        ThreeSale threeSale = threeSaleMapper.getMyBoss(uid);
        if (threeSale != null) {
            return threeSale.getBoss();
        }
        return null;
    }
    @Transactional
    public void bind(UserInfo invitee, UserInfo inviter) throws ThreeSaleException {
        if (invitee == null || inviter == null)
            throw new ThreeSaleException(1, "用户信息为空");
        if (invitee.getId() == null)// 该用户还不存在
        {
            // 保存用户
            UserInfo inviteeUser = userInfoService.addUser(invitee, Constant.APPID);
            if (inviteeUser == null)
                throw new ThreeSaleException(2, "创建用户失败");
            // 保存关系
            ThreeSale threeSale = new ThreeSale();
            threeSale.setBoss(inviter);
            threeSale.setCreateTime(java.lang.System.currentTimeMillis());
            threeSale.setExpire(ThreeSale.EXPIRE_NORMAL);
            threeSale.setState(false);
            threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
            threeSale.setWorker(inviteeUser);
            threeSaleMapper.insertSelective(threeSale);
            List<ThreeSale> listExpire = threeSaleMapper.getExpireRecord(inviter.getId(), inviteeUser.getId());
            if (listExpire != null && listExpire.size() > 0) {
                // 删除失效
                for (ThreeSale saleExpire : listExpire) {
                    msgInviteDetailService.deleteByThreeSale(saleExpire);
                }
                // 删除已失效关系
                threeSaleMapper.deleteExpireRecord(inviter.getId(), inviteeUser.getId());
            }
            // 创建通知
            userInviteMsgNotificationService.inviteScan(inviter.getId(), threeSale);
        } else {// 是已经存在的用户
            // 用户已经存在我们的用户库中
            if (invitee.getLastLoginTime() == null || invitee.getLastLoginTime() == 0L) {
                // 用户未登录
                int outOfDateCount = 0;// 过期数量
                // 查询邀请关系
                List<ThreeSale> list = listByWorkerId(invitee.getId());
                if (list != null && list.size() > 0) {
                    for (ThreeSale ts : list) {
                        if (!ts.getState() && ts.getExpire() == ThreeSale.EXPIRE_OUTOFDATE) {
                            outOfDateCount++;
                        }
                    }
                    // 全部是失效状态
                    if (outOfDateCount == list.size()) {
                        // 可以确定关系
                        ThreeSale threeSale = new ThreeSale();
                        threeSale.setBoss(inviter);
                        threeSale.setCreateTime(java.lang.System.currentTimeMillis());
                        threeSale.setExpire(ThreeSale.EXPIRE_NORMAL);
                        threeSale.setState(false);
                        threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
                        threeSale.setWorker(invitee);
                        threeSaleMapper.insertSelective(threeSale);
                        // 删除已失效关系
                        threeSaleMapper.deleteExpireRecord(inviter.getId(), invitee.getId());
                        List<ThreeSale> listExpire = threeSaleMapper.getExpireRecord(inviter.getId(), invitee.getId());
                        if (listExpire != null && listExpire.size() > 0) {
                            // 删除历史通知
                            for (ThreeSale saleExpire : listExpire) {
                                msgInviteDetailService.deleteByThreeSale(saleExpire);
                            }
                            // 删除已失效关系
                            threeSaleMapper.deleteExpireRecord(inviter.getId(), invitee.getId());
                        }
                        userInviteMsgNotificationService.inviteScan(inviter.getId(), threeSale);
                        // threeSaleSerivce.bind(invitee, inviter);
                    } else {
                        // 还存在有效的邀请,则不做处理
                    }
                } else {
                    // 用户未登录,又不存在邀请关系,不做处理
                }
            } else {
                // 已经登录,不做处理
            }
        }
    }
    @Transactional
    public void effective(UserInfo invitee) {
        List<ThreeSale> list = threeSaleMapper.listByWorkerAndStateAndExpire(invitee.getId(), false,
                ThreeSale.EXPIRE_NORMAL);
        if (list.size() > 0) {
            ThreeSale update = new ThreeSale(list.get(0).getId());
            UserInfo inviter = list.get(0).getBoss();
            update.setState(true);
            update.setSucceedTime(System.currentTimeMillis());
            threeSaleMapper.updateByPrimaryKeySelective(update);
            if (inviter != null)
                reComputeUserRank(inviter.getId());
            // 通知
            userInviteMsgNotificationService.inviteSuccess(inviter.getId(), list.get(0));
        }
    }
    @Override
    public List<UserInfo> getFirstUsers(Long uid, int page) {
        List<ThreeSale> list = threeSaleMapper.listFirstTeam((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid);
        List<UserInfo> userList = new ArrayList<>();
        for (ThreeSale threeSale : list)
            userList.add(threeSale.getWorker());
        return userList;
    }
    @Override
    public List<UserInfo> getSecondUsers(Long uid, int page) {
        List<ThreeSale> list = threeSaleMapper.listSecondTeam((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, uid);
        List<UserInfo> userList = new ArrayList<>();
        for (ThreeSale threeSale : list)
            userList.add(threeSale.getWorker());
        return userList;
    }
    @Override
    public List<ThreeSale> getLastestThreeSaleList(int page, String key) {
//        if (NumberUtil.isNumeric(key)) {
//            Long uid = Long.parseLong(key);
            int start = (page - 1) * Constant.PAGE_SIZE;
            List<ThreeSale> list = threeSaleMapper.listByBossOrWorker(key, start, Constant.PAGE_SIZE);
            return list;
//        }
//        int start = (page - 1) * Constant.PAGE_SIZE;
//        List<ThreeSale> list = dao.list(
//                "from ThreeSale ts where ts.boss.nickName like ? or ts.worker.nickName like ? order by ts.createTime desc",
//                start, Constant.PAGE_SIZE, new Serializable[] { "%" + key + "%", "%" + key + "%" });
//        return list;
    }
    @Override
    public int getLastestThreeSaleCount(String key) {
//        if (NumberUtil.isNumeric(key)) {
//            long lk = Long.parseLong(key);
//            return (int) dao.getCount(
//                    "select count(*) from ThreeSale ts where ts.boss.id = ? or ts.worker.id = ? or ts.boss.nickName like ? or ts.worker.nickName like ?",
//                    new Serializable[] { lk, lk, "%" + key + "%", "%" + key + "%" });
//        }
//        Long lcount = dao.getCount(
//                "select count(*) from ThreeSale ts where ts.boss.nickName like ? or ts.worker.nickName like ?",
//                new Serializable[] { "%" + key + "%", "%" + key + "%" });
        return threeSaleMapper.countByBossOrWorker(key).intValue();
    }
    @Override
    public long getFirstUsersCount(Long uid) {
        return threeSaleMapper.countFirstTeam(uid, null);
    }
    @Override
    public long getSecondUsersCount(Long uid) {
        return threeSaleMapper.countSecondTeam(uid, null);
    }
    @Deprecated
    @Override
    public void reComputeUserRank(Long uid) {
//        int myFirstTeamCount = inviteGetMoneyService.myFirstTeamCount(uid + "");
//        int mySecondTeamCount = inviteGetMoneyService.mySecondTeamCount(uid + "");
//        int count = myFirstTeamCount + mySecondTeamCount;
//        UserInfo user = userInfoService.getUserById(uid);
//        if (user == null)
//            return;
//
//        Map<String, String> convertMap = hongBaoManageService.convertMap();
//        int tong = Integer.parseInt(convertMap.get("sale_tong"));
//        int yin = Integer.parseInt(convertMap.get("sale_yin"));
//        int jin = Integer.parseInt(convertMap.get("sale_jin"));
//        int rank = user.getRank();
//        if (count >= jin) {
//            rank = 3;
//        } else if (count >= yin) {
//            rank = 2;
//        } else if (count >= tong) {
//            rank = 1;
//        }
//
//        if (rank > user.getRank()) {
//            // 更新Rank
//            UserInfo userInfo = new UserInfo(uid);
//            userInfo.setRank(rank);
//            userInfoMapper.updateByPrimaryKeySelective(userInfo);
//        }
    }
    @Override
    public List<ThreeSale> queryMyFirstTeamList(int start, int count, String key, Long bossId) {
        return threeSaleMapper.queryMyFirstTeamList(start, count, key, bossId);
    }
    @Override
    public long queryCountMyFirstTeamList(String key, Long bossId) {
        return threeSaleMapper.queryCountMyFirstTeamList(key, bossId);
    }
    @Override
    public List<ThreeSale> queryMySecondTeamList(int start, int count, String key, Long bossId) {
        return threeSaleMapper.queryMySecondTeamList(start, count, key, bossId);
    }
    @Override
    public long queryCountMySecondTeamList(String key, Long bossId) {
        return threeSaleMapper.queryCountMySecondTeamList(key, bossId);
    }
    @Override
    public int deleteByPrimaryKey(Long id) {
        return threeSaleMapper.deleteByPrimaryKey(id);
    }
    @Override
    public List<Long> queryLongTimeFailed(int daysNum) {
        return threeSaleMapper.queryLongTimeFailed(daysNum);
    }
    @Override
    public List<ThreeSale> queryLongTimeSuccess(int daysNum) {
        return threeSaleMapper.queryLongTimeSuccess(daysNum);
    }
    @Override
    public int updateExpire(List<Long> list) {
        return threeSaleMapper.updateExpire(list);
    }
    @Override
    public List<ThreeSale> listFirstTeamQuery(long start, int count, Long uid, Integer state, String startTime,
            String endTime) {
        return threeSaleMapper.listFirstTeamQuery(start, count, uid, state, startTime, endTime);
    }
    @Override
    public long countFirstTeamQuery(Long uid, Integer state, String startTime, String endTime) {
        return threeSaleMapper.countFirstTeamQuery(uid, state, startTime, endTime);
    }
    @Override
    public List<ThreeSale> listSecondTeamQuery(long start, int count, Long uid, Integer state, String startTime,
            String endTime) {
        return threeSaleMapper.listSecondTeamQuery(start, count, uid, state, startTime, endTime);
    }
    @Override
    public long countSecondTeamQuery(Long uid, Integer state, String startTime, String endTime) {
        return threeSaleMapper.countSecondTeamQuery(uid, state, startTime, endTime);
    }
    @Override
    public List<ThreeSale> listSuperiorQuery(long start, int count, Integer state, Long uid) {
        return threeSaleMapper.listSuperiorQuery(start, count, state, uid);
    }
    @Override
    public long countSuperiorQuery(Integer state, Long uid) {
        return threeSaleMapper.countSuperiorQuery(state, uid);
    }
    @Override
    public List<ThreeSale> listFirstTeam(long start, int count, Long uid) {
        return threeSaleMapper.listFirstTeam(start, count, uid);
    }
    @Override
    public long countFirstTeam(Long uid, Integer state) {
        return threeSaleMapper.countFirstTeam(uid, state);
    }
    @Override
    public List<ThreeSale> listSecondTeam(long start, int count, Long uid) {
        return threeSaleMapper.listSecondTeam(start, count, uid);
    }
    @Override
    public long countSecondTeam(Long uid, Integer state) {
        return threeSaleMapper.countSecondTeam(uid, state);
    }
    @Override
    public ThreeSale getMyBoss(Long uid) {
        return threeSaleMapper.getMyBoss(uid);
    }
    @Override
    public ThreeSale selectByPrimaryKey(Long id) {
        return threeSaleMapper.selectByPrimaryKey(id);
    }
    @Override
    public List<ThreeSale> listbyIdAndBossId(Long id, Long uid, Integer expire) {
        return threeSaleMapper.listbyIdAndBossId(id, uid, expire);
    }
    @Override
    public JSONObject getMyFirstTeam(long start, int count, Long uid) {
        List<ThreeSale> list = threeSaleMapper.listFirstTeam(start, count, uid);
        if (list == null) {
            list = new ArrayList<ThreeSale>();
        }
        long countTotal = threeSaleMapper.countFirstTeam(uid, null);
        return organizeTeam(countTotal, list);
    }
    @Override
    public JSONObject getMySecondTeam(long start, int count, Long uid) {
        List<ThreeSale> list = threeSaleMapper.listSecondTeam(start, count, uid);
        if (list == null) {
            list = new ArrayList<ThreeSale>();
        }
        long countTotal = threeSaleMapper.countSecondTeam(uid, null);
        return organizeTeam(countTotal, list);
    }
    public JSONObject organizeTeam(long count, List<ThreeSale> list) {
        JSONObject result = new JSONObject();
        JSONArray resultArray = new JSONArray();
        for (ThreeSale threeSale : list) {
            JSONObject object = new JSONObject();
            SimpleDateFormat sdf = new SimpleDateFormat("MM.dd HH:mm");
            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
            SimpleDateFormat formatYears = new SimpleDateFormat("yyyy");
            Date todayTime = new Date();
            // 邀请id
            object.put("inviteId", threeSale.getId());
            // 加入队列时间
            Long createTime = threeSale.getCreateTime();
            Date inviteTime = new Date(createTime);
            object.put("inviteTime", format.format(inviteTime) + " 加入");
            String memoName = "";
            ThreeSaleExtraInfo threeSaleExtraInfo = threeSale.getThreeSaleExtraInfo();
            if (threeSaleExtraInfo != null) {
                if (!StringUtil.isNullOrEmpty(threeSaleExtraInfo.getNickname())) {
                    memoName = threeSaleExtraInfo.getNickname();
                }
            }
            object.put("memoName", memoName);
            String nickName = "";
            String portrait = "";
            Long lastLoginTime = null;
            UserInfo worker = threeSale.getWorker();
            if (worker != null) {
                portrait = worker.getPortrait();
                lastLoginTime = worker.getLastLoginTime();
                nickName = worker.getNickName();
            }
            object.put("nickName", nickName);
            object.put("portrait", portrait);
            int state = 0;
            String fontColor1 = "#888888";
            String fontColor2 = "#F14242";
            JSONArray array = new JSONArray();
            if (threeSale.getState()) {
                state = 1;
                if (lastLoginTime == null) {
                    lastLoginTime = threeSale.getCreateTime();
                }
                JSONObject contentJson = new JSONObject();
                contentJson.put("color", fontColor1);
                if (formatYears.format(todayTime).equals(formatYears.format(lastLoginTime))) {
                    // 本年
                    contentJson.put("content", "最近登录 " + sdf.format(lastLoginTime));
                } else {
                    // 往年
                    contentJson.put("content", "最近登录 " + format.format(lastLoginTime));
                }
                array.add(contentJson);
            } else if (threeSale.getExpire() != null
                    && (threeSale.getExpire() == 1 || threeSale.getExpire().equals(1))) {
                state = 2;
                JSONObject contentJson = new JSONObject();
                contentJson.put("color", fontColor1);
                contentJson.put("content", "已经脱离邀请关系");
                array.add(contentJson);
            } else {
                state = 0;
                Calendar c = Calendar.getInstance();
                c.setTime(inviteTime);
                c.add(Calendar.DAY_OF_MONTH, 60);// 邀请不超过60天
                long days = (c.getTimeInMillis() - todayTime.getTime()) / (1000 * 3600 * 24);
                if (days < 0) {
                    days = 0;
                }
                JSONObject contentJson1 = new JSONObject();
                contentJson1.put("color", fontColor1);
                contentJson1.put("content", "将于");
                JSONObject contentJson2 = new JSONObject();
                contentJson2.put("color", fontColor2);
                contentJson2.put("content", days + "天");
                JSONObject contentJson3 = new JSONObject();
                contentJson3.put("color", fontColor1);
                contentJson3.put("content", "后脱离邀请关系");
                array.add(contentJson1);
                array.add(contentJson2);
                array.add(contentJson3);
            }
            object.put("state", state);
            object.put("recentMsg", array);
            resultArray.add(object);
        }
        result.put("count", count);
        result.put("result_list", resultArray);
        return result;
    }
    @Override
    public List<ThreeSale> listByWorkerId(Long workerId) {
        return threeSaleMapper.listByWorkerId(workerId);
    }
    @Override
    public int getSuccessRelationshipNum(Long uid) {
        return threeSaleMapper.getSuccessRelationshipNum(uid);
    }
    @Override
    @Transactional
    public void bindRelationshipByInviteCode(UserInfo invitee, UserInfo inviter) throws ThreeSaleException {
        if (invitee == null || inviter == null)
            throw new ThreeSaleException(1, "用户信息为空");
        // 获取有效的邀请关系
        ThreeSale threeSale = threeSaleMapper.getRelationshipByBossIdAndWorkerId(inviter.getId(), invitee.getId());
        if (threeSale != null) {
            // 有效关系--生效
            threeSale.setState(true);
            threeSale.setExpire(ThreeSale.EXPIRE_NORMAL);
            threeSale.setSucceedTime(java.lang.System.currentTimeMillis());
            threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
            threeSaleMapper.updateByPrimaryKeySelective(threeSale);
        } else {
            // 新建立确定关系
            threeSale = new ThreeSale();
            threeSale.setBoss(inviter);
            threeSale.setWorker(invitee);
            threeSale.setState(true);
            threeSale.setExpire(ThreeSale.EXPIRE_NORMAL);
            threeSale.setSucceedTime(java.lang.System.currentTimeMillis());
            threeSale.setCreateTime(java.lang.System.currentTimeMillis());
            threeSale.setUpdateTime(java.lang.System.currentTimeMillis());
            threeSaleMapper.insertSelective(threeSale);
        }
        List<ThreeSale> listExpire = threeSaleMapper.getExpireRecord(inviter.getId(), invitee.getId());
        if (listExpire != null && listExpire.size() > 0) {
            // 删除历史通知
            for (ThreeSale saleExpire : listExpire) {
                msgInviteDetailService.deleteByThreeSale(saleExpire);
            }
            // 删除已失效关系
            threeSaleMapper.deleteExpireRecord(inviter.getId(), invitee.getId());
        }
        // 邀请消息
        userInviteMsgNotificationService.inviteSuccess(inviter.getId(), threeSale);
    }
}
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/invite/msg/MsgInviteDetailServiceImpl.java
New file
@@ -0,0 +1,85 @@
package org.fanli.service.user.service.impl.invite.msg;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.fanli.facade.system.service.msg.UserMsgReadStateService;
import org.fanli.facade.user.entity.invite.ThreeSale;
import org.fanli.facade.user.entity.invite.msg.MsgInviteDetail;
import org.fanli.facade.user.exception.invite.msg.MsgInviteDetailException;
import org.fanli.facade.user.service.invite.msg.MsgInviteDetailService;
import org.fanli.service.user.dao.invite.msg.MsgInviteDetailMapper;
import org.springframework.stereotype.Service;
import com.yeshi.fanli.base.Constant;
@Service
public class MsgInviteDetailServiceImpl implements MsgInviteDetailService {
    @Resource
    private MsgInviteDetailMapper msgInviteDetailMapper;
    @Resource
    private UserMsgReadStateService userMsgReadStateService;
    @Override
    public void addMsgInviteDetail(MsgInviteDetail detail) throws MsgInviteDetailException {
        if (detail == null)
            throw new MsgInviteDetailException(1, "消息为空");
        if (detail.getInviteUser() == null || detail.getMsgType() == null || detail.getUser() == null
                || detail.getDesc() == null)
            throw new MsgInviteDetailException(2, "消息内容不完整");
        // 查询是否已存在该邀请ID
        MsgInviteDetail oldDetail = msgInviteDetailMapper.selectByThreeSaleId(detail.getInviteUser().getId());
        if (oldDetail == null) {
            detail.setCreateTime(new Date());
            detail.setUpdateTime(new Date());
            detail.setRead(false);
            msgInviteDetailMapper.insertSelective(detail);
        } else {
            MsgInviteDetail update = new MsgInviteDetail();
            update.setId(oldDetail.getId());
            if (!detail.getInviteUser().getState()) {
                if (detail.getInviteUser().getExpire() == ThreeSale.EXPIRE_NORMAL) {
                    update.setDesc("恭喜你,有新队员加入你的队列,若对方60天内未激活将会与你脱离邀请关系");
                } else {
                    update.setDesc("抱歉,该队员因60天内未激活,已脱离了你的队列,可以试着重新邀请");
                }
            } else {
                update.setDesc("恭喜你,成功邀请一个队员");
            }
            update.setUpdateTime(new Date());
            update.setRead(false);
            msgInviteDetailMapper.updateByPrimaryKeySelective(update);
        }
        userMsgReadStateService.addInviteMsgUnReadCount(detail.getUser().getId(), 1);
    }
    @Override
    public List<MsgInviteDetail> listMsgInviteDetail(Long uid, int page) {
        return msgInviteDetailMapper.listByUid(uid, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
    }
    @Override
    public long countMsgInviteDetail(Long uid) {
        return msgInviteDetailMapper.countByUid(uid);
    }
    @Override
    public void readMsgByUid(Long uid) {
        msgInviteDetailMapper.setMsgReadByUid(uid);
    }
    @Override
    public void deleteByThreeSale(ThreeSale sale) {
        if (sale == null)
            return;
        msgInviteDetailMapper.deleteByThreeSaleId(sale.getId());
    }
}
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/invite/msg/UserInviteMsgNotificationServiceImpl.java
New file
@@ -0,0 +1,49 @@
package org.fanli.service.user.service.impl.invite.msg;
import javax.annotation.Resource;
import org.fanli.facade.user.entity.invite.ThreeSale;
import org.fanli.facade.user.entity.invite.msg.MsgInviteDetail;
import org.fanli.facade.user.exception.invite.msg.MsgInviteDetailException;
import org.fanli.facade.user.service.invite.msg.MsgInviteDetailService;
import org.fanli.facade.user.service.invite.msg.UserInviteMsgNotificationService;
import org.fanli.facade.user.util.factory.MsgInviteDetailFactory;
import org.springframework.stereotype.Service;
@Service
public class UserInviteMsgNotificationServiceImpl implements UserInviteMsgNotificationService {
    @Resource
    private MsgInviteDetailService msgInviteDetailService;
    @Override
    public void inviteScan(Long uid, ThreeSale sale) {
        MsgInviteDetail detail = MsgInviteDetailFactory.createInviteScanSuccess(sale, uid, null);
        try {
            msgInviteDetailService.addMsgInviteDetail(detail);
        } catch (MsgInviteDetailException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void inviteSuccess(Long uid, ThreeSale sale) {
        MsgInviteDetail detail = MsgInviteDetailFactory.createInviteSuccess(sale, uid, null);
        try {
            msgInviteDetailService.addMsgInviteDetail(detail);
        } catch (MsgInviteDetailException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void inviteFail(Long uid, ThreeSale sale) {
        MsgInviteDetail detail = MsgInviteDetailFactory.createInviteFail(sale, uid, null);
        try {
            msgInviteDetailService.addMsgInviteDetail(detail);
        } catch (MsgInviteDetailException e) {
            e.printStackTrace();
        }
    }
}
fanli-service-user/src/main/java/org/fanli/service/user/service/impl/taobao/UserExtraTaoBaoInfoServiceImpl.java
New file
@@ -0,0 +1,112 @@
package org.fanli.service.user.service.impl.taobao;
import java.util.Date;
import javax.annotation.Resource;
import org.fanli.facade.user.entity.taobao.UserExtraTaoBaoInfo;
import org.fanli.facade.user.service.taobao.UserExtraTaoBaoInfoService;
import org.fanli.service.user.dao.taobao.UserExtraTaoBaoInfoMapper;
import org.springframework.stereotype.Service;
import org.yeshi.utils.StringUtil;
import com.yeshi.fanli.base.entity.user.UserInfo;
@Service
public class UserExtraTaoBaoInfoServiceImpl implements UserExtraTaoBaoInfoService {
    @Resource
    private UserExtraTaoBaoInfoMapper userExtraTaoBaoInfoMapper;
    @Override
    public void addRelationId(Long uid, String relationId, String taoBaoUid, boolean valid) {
        if (uid == null || relationId == null)
            return;
        UserExtraTaoBaoInfo info = getByUid(uid);
        if (info == null) {
            info = new UserExtraTaoBaoInfo();
            info.setUser(new UserInfo(uid));
            info.setCreateTime(new Date());
            info.setRelationId(relationId);
            info.setRelationUpdateTime(new Date());
            info.setRelationValid(valid);
            info.setTaoBaoUid(taoBaoUid);
            userExtraTaoBaoInfoMapper.insertSelective(info);
        } else {
            UserExtraTaoBaoInfo update = new UserExtraTaoBaoInfo();
            update.setId(info.getId());
            update.setRelationId(relationId);
            update.setRelationValid(valid);
            update.setRelationUpdateTime(new Date());
            update.setTaoBaoUid(taoBaoUid);
            userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(update);
        }
    }
    @Override
    public void addSpecialId(Long uid, String specialId, String taoBaoUid, boolean valid) {
        if (uid == null || specialId == null)
            return;
        UserExtraTaoBaoInfo info = getByUid(uid);
        if (info == null) {
            info = new UserExtraTaoBaoInfo();
            info.setUser(new UserInfo(uid));
            info.setCreateTime(new Date());
            info.setSpecialId(specialId);
            info.setSpecialUpdateTime(new Date());
            info.setSpecialValid(valid);
            info.setTaoBaoUid(taoBaoUid);
            userExtraTaoBaoInfoMapper.insertSelective(info);
        } else {
            UserExtraTaoBaoInfo update = new UserExtraTaoBaoInfo();
            update.setId(info.getId());
            update.setSpecialId(specialId);
            update.setSpecialUpdateTime(new Date());
            update.setSpecialValid(valid);
            update.setTaoBaoUid(taoBaoUid);
            userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(update);
        }
    }
    @Override
    public UserExtraTaoBaoInfo getByUid(Long uid) {
        return userExtraTaoBaoInfoMapper.selectByUid(uid);
    }
    @Override
    public void updateSelective(UserExtraTaoBaoInfo ue) {
        if (ue == null || ue.getId() == null)
            return;
        userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(ue);
    }
    @Override
    public void unBindUid(Long uid) {
        userExtraTaoBaoInfoMapper.clearUid(uid);
    }
    @Override
    public void bindTaoBaoOrderEnd6Num(String taoBaoUid, String orderId) {
        if (taoBaoUid == null || StringUtil.isNullOrEmpty(orderId))
            return;
        UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoMapper.selectByTaoBaoUid(taoBaoUid);
        if (extraInfo != null) {
            UserExtraTaoBaoInfo update = new UserExtraTaoBaoInfo();
            update.setId(extraInfo.getId());
            update.setTaoBaoOrderEnd6Num(orderId);
            update.setUpdateTime(new Date());
            userExtraTaoBaoInfoMapper.updateByPrimaryKeySelective(update);
        }
    }
    @Override
    public UserExtraTaoBaoInfo getByRelationId(String relationId) {
        return userExtraTaoBaoInfoMapper.selectByRelationIdWithUidNotNull(relationId);
    }
    @Override
    public UserExtraTaoBaoInfo getBySpecialId(String specialId) {
        return userExtraTaoBaoInfoMapper.selectBySpecialIdWithUidNotNull(specialId);
    }
}